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 "collectionfetchjob.h"
9 #include "collectionfetchscope.h"
10 #include "specialcollectionattribute.h"
11 #include <QStringList>
12 
13 #include "akonadicore_debug.h"
14 
15 using namespace Akonadi;
16 
17 /**
18  @internal
19 */
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 *const mSpecialCollections;
30  const QStringList mMimeTypes;
31 };
32 
34  : KCompositeJob(parent)
35  , d(new SpecialCollectionsDiscoveryJobPrivate(collections, mimeTypes))
36 {
37 }
38 
40 
41 void Akonadi::SpecialCollectionsDiscoveryJob::start()
42 {
44  job->fetchScope().setContentMimeTypes(d->mMimeTypes);
45  addSubjob(job);
46 }
47 
48 void Akonadi::SpecialCollectionsDiscoveryJob::slotResult(KJob *job)
49 {
50  if (job->error()) {
51  qCWarning(AKONADICORE_LOG) << job->errorString();
52  return;
53  }
54  auto fetchJob = qobject_cast<Akonadi::CollectionFetchJob *>(job);
55  const Akonadi::Collection::List lstCollections = fetchJob->collections();
56  for (const Akonadi::Collection &collection : lstCollections) {
57  if (collection.hasAttribute<SpecialCollectionAttribute>()) {
58  d->mSpecialCollections->registerCollection(collection.attribute<SpecialCollectionAttribute>()->collectionType(), collection);
59  }
60  }
61  emitResult();
62 }
SpecialCollectionsDiscoveryJob(SpecialCollections *collections, const QStringList &mimeTypes, QObject *parent=nullptr)
Creates a new special collections request job.
Represents a collection of PIM items.
Definition: collection.h:61
QByteArray collectionType() const
Returns the special collections type of the collection.
Job that fetches collections from the Akonadi storage.
An Attribute that stores the special collection type of a collection.
~SpecialCollectionsDiscoveryJob() override
Destroys the special collections request job.
static Collection root()
Returns the root collection.
Definition: collection.cpp:287
An interface to special collections.
QStringList mimeTypes(Mode mode=Writing)
@ Recursive
List all sub-collections.
virtual QString errorString() const
int error() const
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.