Akonadi

specialcollectionsdiscoveryjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2013 David Faure <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "specialcollectionsdiscoveryjob.h"
8 #include "specialcollectionattribute.h"
9 #include "collectionfetchscope.h"
10 #include "collectionfetchjob.h"
11 #include <QStringList>
12 
13 #include "akonadicore_debug.h"
14 
15 using namespace Akonadi;
16 
20 class Akonadi::SpecialCollectionsDiscoveryJobPrivate
21 {
22 public:
23  SpecialCollectionsDiscoveryJobPrivate(SpecialCollections *collections, const QStringList &mimeTypes)
24  : mSpecialCollections(collections)
25  , mMimeTypes(mimeTypes)
26  {
27  }
28 
29  SpecialCollections *mSpecialCollections = nullptr;
30  QStringList mMimeTypes;
31 };
32 
34  : KCompositeJob(parent)
35  , d(new SpecialCollectionsDiscoveryJobPrivate(collections, mimeTypes))
36 {
37 }
38 
40 {
41  delete d;
42 }
43 
44 void Akonadi::SpecialCollectionsDiscoveryJob::start()
45 {
47  job->fetchScope().setContentMimeTypes(d->mMimeTypes);
48  addSubjob(job);
49 }
50 
51 void Akonadi::SpecialCollectionsDiscoveryJob::slotResult(KJob *job)
52 {
53  if (job->error()) {
54  qCWarning(AKONADICORE_LOG) << job->errorString();
55  return;
56  }
58  const Akonadi::Collection::List lstCollections = fetchJob->collections();
59  for (const Akonadi::Collection &collection : lstCollections) {
60  if (collection.hasAttribute<SpecialCollectionAttribute>()) {
61  d->mSpecialCollections->registerCollection(collection.attribute<SpecialCollectionAttribute>()->collectionType(), collection);
62  }
63  }
64  emitResult();
65 }
virtual bool addSubjob(KJob *job)
An interface to special collections.
Collection::List collections() const
Returns the list of fetched collection.
void emitResult()
SpecialCollectionsDiscoveryJob(SpecialCollections *collections, const QStringList &mimeTypes, QObject *parent=nullptr)
Creates a new special collections request job.
virtual QString errorString() const
CollectionFetchScope & fetchScope()
Returns the collection fetch scope.
Represents a collection of PIM items.
Definition: collection.h:63
Job that fetches collections from the Akonadi storage.
An Attribute that stores the special collection type of a collection.
void setContentMimeTypes(const QStringList &mimeTypes)
Sets a content mimetypes filter, that is only collections that contain at least one of the given mime...
static Collection root()
Returns the root collection.
Definition: collection.cpp:290
~SpecialCollectionsDiscoveryJob() override
Destroys the special collections request job.
Helper integration between Akonadi and Qt.
QByteArray collectionType() const
Returns the special collections type of the collection.
T qobject_cast(QObject *object)
int error() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Aug 8 2020 23:14:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.