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

akonadi

  • akonadi
recursiveitemfetchjob.cpp
1/*
2 Copyright (c) 2009 Tobias Koenig <tokoe@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 "recursiveitemfetchjob.h"
21
22#include <akonadi/collectionfetchjob.h>
23#include <akonadi/collectionfetchscope.h>
24#include <akonadi/itemfetchjob.h>
25#include <akonadi/itemfetchscope.h>
26
27#include <QtCore/QStringList>
28#include <QtCore/QVariant>
29
30using namespace Akonadi;
31
32class RecursiveItemFetchJob::Private
33{
34public:
35 Private(const Collection &collection, const QStringList &mimeTypes, RecursiveItemFetchJob *parent)
36 : mParent(parent)
37 , mCollection(collection)
38 , mMimeTypes(mimeTypes)
39 , mFetchCount(0)
40 {
41 }
42
43 void collectionFetchResult(KJob *job)
44 {
45 if (job->error()) {
46 mParent->emitResult();
47 return;
48 }
49
50 const CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob *>(job);
51
52 Collection::List collections = fetchJob->collections();
53 collections.prepend(mCollection);
54
55 foreach (const Collection &collection, collections) {
56 ItemFetchJob *itemFetchJob = new ItemFetchJob(collection, mParent);
57 itemFetchJob->setFetchScope(mFetchScope);
58 mParent->connect(itemFetchJob, SIGNAL(result(KJob*)),
59 mParent, SLOT(itemFetchResult(KJob*)));
60
61 mFetchCount++;
62 }
63 }
64
65 void itemFetchResult(KJob *job)
66 {
67 if (!job->error()) {
68 const ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob *>(job);
69
70 if (!mMimeTypes.isEmpty()) {
71 foreach (const Item &item, fetchJob->items()) {
72 if (mMimeTypes.contains(item.mimeType())) {
73 mItems << item;
74 }
75 }
76 } else {
77 mItems << fetchJob->items();
78 }
79 }
80
81 mFetchCount--;
82
83 if (mFetchCount == 0) {
84 mParent->emitResult();
85 }
86 }
87
88 RecursiveItemFetchJob *mParent;
89 Collection mCollection;
90 Item::List mItems;
91 ItemFetchScope mFetchScope;
92 QStringList mMimeTypes;
93
94 int mFetchCount;
95};
96
97RecursiveItemFetchJob::RecursiveItemFetchJob(const Collection &collection, const QStringList &mimeTypes, QObject *parent)
98 : KJob(parent)
99 , d(new Private(collection, mimeTypes, this))
100{
101}
102
103RecursiveItemFetchJob::~RecursiveItemFetchJob()
104{
105 delete d;
106}
107
108void RecursiveItemFetchJob::setFetchScope(const ItemFetchScope &fetchScope)
109{
110 d->mFetchScope = fetchScope;
111}
112
113ItemFetchScope &RecursiveItemFetchJob::fetchScope()
114{
115 return d->mFetchScope;
116}
117
118void RecursiveItemFetchJob::start()
119{
120 CollectionFetchJob *job = new CollectionFetchJob(d->mCollection, CollectionFetchJob::Recursive, this);
121
122 if (!d->mMimeTypes.isEmpty()) {
123 job->fetchScope().setContentMimeTypes(d->mMimeTypes);
124 }
125
126 connect(job, SIGNAL(result(KJob*)), this, SLOT(collectionFetchResult(KJob*)));
127}
128
129Akonadi::Item::List RecursiveItemFetchJob::items() const
130{
131 return d->mItems;
132}
133
134#include "moc_recursiveitemfetchjob.cpp"
Akonadi::CollectionFetchJob
Job that fetches collections from the Akonadi storage.
Definition: collectionfetchjob.h:54
Akonadi::CollectionFetchJob::fetchScope
CollectionFetchScope & fetchScope()
Returns the collection fetch scope.
Definition: collectionfetchjob.cpp:439
Akonadi::CollectionFetchJob::Recursive
@ Recursive
List all sub-collections.
Definition: collectionfetchjob.h:64
Akonadi::CollectionFetchJob::collections
Collection::List collections() const
Returns the list of fetched collection.
Definition: collectionfetchjob.cpp:169
Akonadi::CollectionFetchScope::setContentMimeTypes
void setContentMimeTypes(const QStringList &mimeTypes)
Sets a content mimetypes filter, that is only collections that contain at least one of the given mime...
Definition: collectionfetchscope.cpp:128
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:76
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
Akonadi::ItemFetchJob
Job that fetches items from the Akonadi storage.
Definition: itemfetchjob.h:83
Akonadi::ItemFetchJob::setFetchScope
void setFetchScope(ItemFetchScope &fetchScope)
Sets the item fetch scope.
Definition: itemfetchjob.cpp:247
Akonadi::ItemFetchJob::items
Item::List items() const
Returns the fetched items.
Definition: itemfetchjob.cpp:233
Akonadi::ItemFetchScope
Specifies which parts of an item should be fetched from the Akonadi storage.
Definition: itemfetchscope.h:70
Akonadi::RecursiveItemFetchJob
Job that fetches all items of a collection recursive.
Definition: recursiveitemfetchjob.h:85
Akonadi::RecursiveItemFetchJob::fetchScope
Akonadi::ItemFetchScope & fetchScope()
Returns the item fetch scope.
Definition: recursiveitemfetchjob.cpp:113
Akonadi::RecursiveItemFetchJob::~RecursiveItemFetchJob
~RecursiveItemFetchJob()
Destroys the recursive item fetch job.
Definition: recursiveitemfetchjob.cpp:103
Akonadi::RecursiveItemFetchJob::start
virtual void start()
Starts the recursive item fetch job.
Definition: recursiveitemfetchjob.cpp:118
Akonadi::RecursiveItemFetchJob::setFetchScope
void setFetchScope(const Akonadi::ItemFetchScope &fetchScope)
Sets the item fetch scope.
Definition: recursiveitemfetchjob.cpp:108
Akonadi::RecursiveItemFetchJob::RecursiveItemFetchJob
RecursiveItemFetchJob(const Akonadi::Collection &collection, const QStringList &mimeTypes, QObject *parent=0)
Creates a new recursive item fetch job.
Definition: recursiveitemfetchjob.cpp:97
Akonadi::RecursiveItemFetchJob::items
Akonadi::Item::List items() const
Returns the list of fetched items.
Definition: recursiveitemfetchjob.cpp:129
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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-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