akonadi
invalidatecachejob.cpp
00001 /* 00002 Copyright (c) 2011 Volker Krause <vkrause@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #include "invalidatecachejob_p.h" 00021 #include "job_p.h" 00022 #include "collectionfetchjob.h" 00023 #include "itemfetchjob.h" 00024 #include "itemmodifyjob.h" 00025 00026 #include <klocalizedstring.h> 00027 00028 using namespace Akonadi; 00029 00030 namespace Akonadi { 00031 00032 class InvalidateCacheJobPrivate : JobPrivate 00033 { 00034 public: 00035 InvalidateCacheJobPrivate( InvalidateCacheJob* qq ) : JobPrivate( qq ) {} 00036 Collection collection; 00037 00038 void collectionFetchResult( KJob *job ); 00039 void itemFetchResult( KJob *job ); 00040 void itemStoreResult( KJob *job ); 00041 00042 Q_DECLARE_PUBLIC( InvalidateCacheJob ) 00043 }; 00044 00045 } 00046 00047 void InvalidateCacheJobPrivate::collectionFetchResult(KJob* job) 00048 { 00049 Q_Q( InvalidateCacheJob ); 00050 if ( job->error() ) 00051 return; // handled by KCompositeJob 00052 00053 CollectionFetchJob* fetchJob = qobject_cast<CollectionFetchJob*>( job ); 00054 Q_ASSERT( fetchJob ); 00055 if ( fetchJob->collections().size() == 1 ) 00056 collection = fetchJob->collections().first(); 00057 00058 if ( !collection.isValid() ) { 00059 q->setError( Job::Unknown ); 00060 q->setErrorText( i18n( "Invalid collection." ) ); 00061 q->emitResult(); 00062 return; 00063 } 00064 00065 00066 ItemFetchJob *itemFetch = new ItemFetchJob( collection, q ); 00067 QObject::connect( itemFetch, SIGNAL(result(KJob*)), q, SLOT(itemFetchResult(KJob*)) ); 00068 } 00069 00070 void InvalidateCacheJobPrivate::itemFetchResult(KJob* job) 00071 { 00072 Q_Q( InvalidateCacheJob ); 00073 if ( job->error() ) 00074 return; 00075 ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob*>( job ); 00076 Q_ASSERT( fetchJob ); 00077 if ( fetchJob->items().size() == 0 ) { 00078 q->emitResult(); 00079 return; 00080 } 00081 00082 ItemModifyJob *modJob = 0; 00083 foreach ( Item item, fetchJob->items() ) { //krazy:exclude=foreach, item cannot be const 00084 item.clearPayload(); 00085 modJob = new ItemModifyJob( item, q ); 00086 } 00087 QObject::connect( modJob, SIGNAL(result(KJob*)), q, SLOT(itemStoreResult(KJob*)) ); 00088 } 00089 00090 void InvalidateCacheJobPrivate::itemStoreResult(KJob* job) 00091 { 00092 Q_Q( InvalidateCacheJob ); 00093 if ( job->error() ) 00094 return; 00095 q->emitResult(); 00096 } 00097 00098 00099 InvalidateCacheJob::InvalidateCacheJob( const Collection &collection, QObject *parent ) : 00100 Job( new InvalidateCacheJobPrivate( this ), parent ) 00101 { 00102 Q_D( InvalidateCacheJob ); 00103 d->collection = collection; 00104 } 00105 00106 void InvalidateCacheJob::doStart() 00107 { 00108 Q_D( InvalidateCacheJob ); 00109 // resolve RID-only collections 00110 CollectionFetchJob *job = new CollectionFetchJob( d->collection, Akonadi::CollectionFetchJob::Base, this ); 00111 connect( job, SIGNAL(result(KJob*)), SLOT(collectionFetchResult(KJob*)) ); 00112 } 00113 00114 #include "invalidatecachejob_p.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:15 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:15 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.