Akonadi

subscriptionjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "subscriptionjob_p.h"
8 
9 #include "job_p.h"
10 
11 #include "collectionmodifyjob.h"
12 
13 using namespace Akonadi;
14 
15 class Akonadi::SubscriptionJobPrivate : public JobPrivate
16 {
17 public:
18  explicit SubscriptionJobPrivate(SubscriptionJob *parent)
19  : JobPrivate(parent)
20  {
21  }
22 
23  Q_DECLARE_PUBLIC(SubscriptionJob)
24 
25  Collection::List mSub, mUnsub;
26 };
27 
28 SubscriptionJob::SubscriptionJob(QObject *parent)
29  : Job(new SubscriptionJobPrivate(this), parent)
30 {
31 }
32 
33 SubscriptionJob::~SubscriptionJob()
34 {
35 }
36 
37 void SubscriptionJob::subscribe(const Collection::List &list)
38 {
39  Q_D(SubscriptionJob);
40 
41  d->mSub = list;
42 }
43 
44 void SubscriptionJob::unsubscribe(const Collection::List &list)
45 {
46  Q_D(SubscriptionJob);
47 
48  d->mUnsub = list;
49 }
50 
51 void SubscriptionJob::doStart()
52 {
53  Q_D(SubscriptionJob);
54 
55  if (d->mSub.isEmpty() && d->mUnsub.isEmpty()) {
56  emitResult();
57  return;
58  }
59 
60  for (Collection col : std::as_const(d->mSub)) {
61  col.setEnabled(true);
62  new CollectionModifyJob(col, this);
63  }
64  for (Collection col : std::as_const(d->mUnsub)) {
65  col.setEnabled(false);
66  new CollectionModifyJob(col, this);
67  }
68 }
69 
70 void SubscriptionJob::slotResult(KJob *job)
71 {
72  if (job->error()) {
73  setError(job->error());
74  setErrorText(job->errorText());
75  const auto subJobs = this->subjobs();
76  for (KJob *subjob : subJobs) {
77  removeSubjob(subjob);
78  }
79  emitResult();
80  } else {
81  Job::slotResult(job);
82 
83  if (!hasSubjobs()) {
84  emitResult();
85  }
86  }
87 }
88 
89 #include "moc_subscriptionjob_p.cpp"
Job that modifies a collection in the Akonadi storage.
Represents a collection of PIM items.
Definition: collection.h:61
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
QString errorText() const
Base class for all actions in the Akonadi storage.
Definition: job.h:80
int error() const
Q_D(Todo)
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.