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

akonadi

  • 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
28using namespace Akonadi;
29
30namespace Akonadi {
31
32class InvalidateCacheJobPrivate : JobPrivate
33{
34public:
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
50void 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
74void 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
95void InvalidateCacheJobPrivate::itemStoreResult(KJob *job)
96{
97 Q_Q(InvalidateCacheJob);
98 if (job->error()) {
99 return;
100 }
101 q->emitResult();
102}
103
104InvalidateCacheJob::InvalidateCacheJob(const Collection &collection, QObject *parent)
105 : Job(new InvalidateCacheJobPrivate(this), parent)
106{
107 Q_D(InvalidateCacheJob);
108 d->collection = collection;
109}
110
111void 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
Job that fetches collections from the Akonadi storage.
Definition collectionfetchjob.h:54
Akonadi::CollectionFetchJob::Base
@ Base
Only fetch the base collection.
Definition collectionfetchjob.h:62
Akonadi::CollectionFetchJob::collections
Collection::List collections() const
Returns the list of fetched collection.
Definition collectionfetchjob.cpp:169
Akonadi::Collection
Represents a collection of PIM items.
Definition collection.h:76
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition entity.cpp:97
Akonadi::InvalidateCacheJob
Helper job to invalidate item cache for an entire collection.
Definition invalidatecachejob_p.h:35
Akonadi::InvalidateCacheJob::doStart
virtual void doStart()
This method must be reimplemented in the concrete jobs.
Definition invalidatecachejob.cpp:111
Akonadi::InvalidateCacheJob::InvalidateCacheJob
InvalidateCacheJob(const Collection &collection, QObject *parent)
Create a job to invalidate all cached content in collection.
Definition invalidatecachejob.cpp:104
Akonadi::ItemFetchJob
Job that fetches items from the Akonadi storage.
Definition itemfetchjob.h:83
Akonadi::ItemFetchJob::items
Item::List items() const
Returns the fetched items.
Definition itemfetchjob.cpp:233
Akonadi::ItemModifyJob
Job that modifies an existing item in the Akonadi storage.
Definition itemmodifyjob.h:98
Akonadi::JobPrivate
Definition job_p.h:32
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition job.h:87
Akonadi::Job::Unknown
@ Unknown
Unknown error.
Definition job.h:108
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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
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