• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
invalidatecachejob.cpp
1 /*
2  Copyright (c) 2011 Volker Krause <vkrause@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "invalidatecachejob_p.h"
21 #include "job_p.h"
22 #include "collectionfetchjob.h"
23 #include "itemfetchjob.h"
24 #include "itemmodifyjob.h"
25 
26 #include <klocalizedstring.h>
27 
28 using namespace Akonadi;
29 
30 namespace Akonadi {
31 
32 class InvalidateCacheJobPrivate : JobPrivate
33 {
34  public:
35  InvalidateCacheJobPrivate( InvalidateCacheJob* qq ) : JobPrivate( qq ) {}
36  Collection collection;
37 
38  void collectionFetchResult( KJob *job );
39  void itemFetchResult( KJob *job );
40  void itemStoreResult( KJob *job );
41 
42  Q_DECLARE_PUBLIC( InvalidateCacheJob )
43 };
44 
45 }
46 
47 void InvalidateCacheJobPrivate::collectionFetchResult(KJob* job)
48 {
49  Q_Q( InvalidateCacheJob );
50  if ( job->error() )
51  return; // handled by KCompositeJob
52 
53  CollectionFetchJob* fetchJob = qobject_cast<CollectionFetchJob*>( job );
54  Q_ASSERT( fetchJob );
55  if ( fetchJob->collections().size() == 1 )
56  collection = fetchJob->collections().first();
57 
58  if ( !collection.isValid() ) {
59  q->setError( Job::Unknown );
60  q->setErrorText( i18n( "Invalid collection." ) );
61  q->emitResult();
62  return;
63  }
64 
65  ItemFetchJob *itemFetch = new ItemFetchJob( collection, q );
66  QObject::connect( itemFetch, SIGNAL(result(KJob*)), q, SLOT(itemFetchResult(KJob*)) );
67 }
68 
69 void InvalidateCacheJobPrivate::itemFetchResult(KJob* job)
70 {
71  Q_Q( InvalidateCacheJob );
72  if ( job->error() )
73  return;
74  ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob*>( job );
75  Q_ASSERT( fetchJob );
76  if ( fetchJob->items().size() == 0 ) {
77  q->emitResult();
78  return;
79  }
80 
81  ItemModifyJob *modJob = 0;
82  foreach ( Item item, fetchJob->items() ) { //krazy:exclude=foreach, item cannot be const
83  item.clearPayload();
84  modJob = new ItemModifyJob( item, q );
85  }
86  QObject::connect( modJob, SIGNAL(result(KJob*)), q, SLOT(itemStoreResult(KJob*)) );
87 }
88 
89 void InvalidateCacheJobPrivate::itemStoreResult(KJob* job)
90 {
91  Q_Q( InvalidateCacheJob );
92  if ( job->error() )
93  return;
94  q->emitResult();
95 }
96 
97 InvalidateCacheJob::InvalidateCacheJob( const Collection &collection, QObject *parent ) :
98  Job( new InvalidateCacheJobPrivate( this ), parent )
99 {
100  Q_D( InvalidateCacheJob );
101  d->collection = collection;
102 }
103 
104 void InvalidateCacheJob::doStart()
105 {
106  Q_D( InvalidateCacheJob );
107  // resolve RID-only collections
108  CollectionFetchJob *job = new CollectionFetchJob( d->collection, Akonadi::CollectionFetchJob::Base, this );
109  connect( job, SIGNAL(result(KJob*)), SLOT(collectionFetchResult(KJob*)) );
110 }
111 
112 #include "moc_invalidatecachejob_p.cpp"
Akonadi::CollectionFetchJob::collections
Collection::List collections() const
Returns the list of fetched collection.
Definition: collectionfetchjob.cpp:175
Akonadi::Job::Unknown
Unknown error.
Definition: job.h:109
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::CollectionFetchJob
Job that fetches collections from the Akonadi storage.
Definition: collectionfetchjob.h:53
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition: job.h:86
Akonadi::ItemFetchJob::items
Item::List items() const
Returns the fetched items.
Definition: itemfetchjob.cpp:228
Akonadi::CollectionFetchJob::Base
Only fetch the base collection.
Definition: collectionfetchjob.h:62
Akonadi::InvalidateCacheJob
Helper job to invalidate item cache for an entire collection.
Definition: invalidatecachejob_p.h:34
Akonadi::ItemModifyJob
Job that modifies an existing item in the Akonadi storage.
Definition: itemmodifyjob.h:97
Akonadi::ItemFetchJob
Job that fetches items from the Akonadi storage.
Definition: itemfetchjob.h:82
Akonadi::JobPrivate
Definition: job_p.h:31
Akonadi::InvalidateCacheJob::doStart
virtual void doStart()
This method must be reimplemented in the concrete jobs.
Definition: invalidatecachejob.cpp:104
Akonadi::InvalidateCacheJob::InvalidateCacheJob
InvalidateCacheJob(const Collection &collection, QObject *parent)
Create a job to invalidate all cached content in collection.
Definition: invalidatecachejob.cpp:97
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal