• 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
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 
30 using namespace Akonadi;
31 
32 class RecursiveItemFetchJob::Private
33 {
34 public:
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 
97 RecursiveItemFetchJob::RecursiveItemFetchJob(const Collection &collection, const QStringList &mimeTypes, QObject *parent)
98  : KJob(parent)
99  , d(new Private(collection, mimeTypes, this))
100 {
101 }
102 
103 RecursiveItemFetchJob::~RecursiveItemFetchJob()
104 {
105  delete d;
106 }
107 
108 void RecursiveItemFetchJob::setFetchScope(const ItemFetchScope &fetchScope)
109 {
110  d->mFetchScope = fetchScope;
111 }
112 
113 ItemFetchScope &RecursiveItemFetchJob::fetchScope()
114 {
115  return d->mFetchScope;
116 }
117 
118 void 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 
129 Akonadi::Item::List RecursiveItemFetchJob::items() const
130 {
131  return d->mItems;
132 }
133 
134 #include "moc_recursiveitemfetchjob.cpp"
Akonadi::RecursiveItemFetchJob::start
virtual void start()
Starts the recursive item fetch job.
Definition: recursiveitemfetchjob.cpp:118
Akonadi::CollectionFetchJob::collections
Collection::List collections() const
Returns the list of fetched collection.
Definition: collectionfetchjob.cpp:169
Akonadi::CollectionFetchJob::fetchScope
CollectionFetchScope & fetchScope()
Returns the collection fetch scope.
Definition: collectionfetchjob.cpp:439
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::RecursiveItemFetchJob::setFetchScope
void setFetchScope(const Akonadi::ItemFetchScope &fetchScope)
Sets the item fetch scope.
Definition: recursiveitemfetchjob.cpp:108
Akonadi::ItemFetchJob::items
Item::List items() const
Returns the fetched items.
Definition: itemfetchjob.cpp:233
Akonadi::ItemFetchJob::setFetchScope
void setFetchScope(ItemFetchScope &fetchScope)
Sets the item fetch scope.
Definition: itemfetchjob.cpp:247
QObject
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::RecursiveItemFetchJob::fetchScope
Akonadi::ItemFetchScope & fetchScope()
Returns the item fetch scope.
Definition: recursiveitemfetchjob.cpp:113
QList
QStringList
Akonadi::ItemFetchScope
Specifies which parts of an item should be fetched from the Akonadi storage.
Definition: itemfetchscope.h:69
Akonadi::ItemFetchJob
Job that fetches items from the Akonadi storage.
Definition: itemfetchjob.h:82
Akonadi::RecursiveItemFetchJob
Job that fetches all items of a collection recursive.
Definition: recursiveitemfetchjob.h:84
Akonadi::RecursiveItemFetchJob::~RecursiveItemFetchJob
~RecursiveItemFetchJob()
Destroys the recursive item fetch job.
Definition: recursiveitemfetchjob.cpp:103
QList::prepend
void prepend(const T &value)
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::CollectionFetchJob::Recursive
List all sub-collections.
Definition: collectionfetchjob.h:64
Akonadi::RecursiveItemFetchJob::items
Akonadi::Item::List items() const
Returns the list of fetched items.
Definition: recursiveitemfetchjob.cpp:129
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