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

akonadi

  • sources
  • kde-4.14
  • 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)
36  : JobPrivate(qq)
37  {
38  }
39  Collection collection;
40 
41  void collectionFetchResult(KJob *job);
42  void itemFetchResult(KJob *job);
43  void itemStoreResult(KJob *job);
44 
45  Q_DECLARE_PUBLIC(InvalidateCacheJob)
46 };
47 
48 }
49 
50 void InvalidateCacheJobPrivate::collectionFetchResult(KJob *job)
51 {
52  Q_Q(InvalidateCacheJob);
53  if (job->error()) {
54  return; // handled by KCompositeJob
55  }
56 
57  CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob *>(job);
58  Q_ASSERT(fetchJob);
59  if (fetchJob->collections().size() == 1) {
60  collection = fetchJob->collections().first();
61  }
62 
63  if (!collection.isValid()) {
64  q->setError(Job::Unknown);
65  q->setErrorText(i18n("Invalid collection."));
66  q->emitResult();
67  return;
68  }
69 
70  ItemFetchJob *itemFetch = new ItemFetchJob(collection, q);
71  QObject::connect(itemFetch, SIGNAL(result(KJob*)), q, SLOT(itemFetchResult(KJob*)));
72 }
73 
74 void InvalidateCacheJobPrivate::itemFetchResult(KJob *job)
75 {
76  Q_Q(InvalidateCacheJob);
77  if (job->error()) {
78  return;
79  }
80  ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob *>(job);
81  Q_ASSERT(fetchJob);
82  if (fetchJob->items().size() == 0) {
83  q->emitResult();
84  return;
85  }
86 
87  ItemModifyJob *modJob = 0;
88  foreach (Item item, fetchJob->items()) { //krazy:exclude=foreach, item cannot be const
89  item.clearPayload();
90  modJob = new ItemModifyJob(item, q);
91  }
92  QObject::connect(modJob, SIGNAL(result(KJob*)), q, SLOT(itemStoreResult(KJob*)));
93 }
94 
95 void InvalidateCacheJobPrivate::itemStoreResult(KJob *job)
96 {
97  Q_Q(InvalidateCacheJob);
98  if (job->error()) {
99  return;
100  }
101  q->emitResult();
102 }
103 
104 InvalidateCacheJob::InvalidateCacheJob(const Collection &collection, QObject *parent)
105  : Job(new InvalidateCacheJobPrivate(this), parent)
106 {
107  Q_D(InvalidateCacheJob);
108  d->collection = collection;
109 }
110 
111 void InvalidateCacheJob::doStart()
112 {
113  Q_D(InvalidateCacheJob);
114  // resolve RID-only collections
115  CollectionFetchJob *job = new CollectionFetchJob(d->collection, Akonadi::CollectionFetchJob::Base, this);
116  connect(job, SIGNAL(result(KJob*)), SLOT(collectionFetchResult(KJob*)));
117 }
118 
119 #include "moc_invalidatecachejob_p.cpp"
Akonadi::CollectionFetchJob::collections
Collection::List collections() const
Returns the list of fetched collection.
Definition: collectionfetchjob.cpp:169
Akonadi::Job::Unknown
Unknown error.
Definition: job.h:108
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
QList::size
int size() const
Akonadi::ItemFetchJob::items
Item::List items() const
Returns the fetched items.
Definition: itemfetchjob.cpp:233
Akonadi::CollectionFetchJob::Base
Only fetch the base collection.
Definition: collectionfetchjob.h:62
QObject
QList::first
T & first()
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:111
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Akonadi::InvalidateCacheJob::InvalidateCacheJob
InvalidateCacheJob(const Collection &collection, QObject *parent)
Create a job to invalidate all cached content in collection.
Definition: invalidatecachejob.cpp:104
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 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
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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