Akonadi

subscriptionjob.cpp
1 /*
2  Copyright (c) 2007 Volker Krause <[email protected]>
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 "subscriptionjob_p.h"
21 
22 #include "job_p.h"
23 
24 #include "collectionmodifyjob.h"
25 
26 using namespace Akonadi;
27 
28 class Akonadi::SubscriptionJobPrivate : public JobPrivate
29 {
30 public:
31  SubscriptionJobPrivate(SubscriptionJob *parent)
32  : JobPrivate(parent)
33  {
34  }
35 
36  Q_DECLARE_PUBLIC(SubscriptionJob)
37 
38  Collection::List mSub, mUnsub;
39 };
40 
41 SubscriptionJob::SubscriptionJob(QObject *parent)
42  : Job(new SubscriptionJobPrivate(this), parent)
43 {
44 }
45 
46 SubscriptionJob::~SubscriptionJob()
47 {
48 }
49 
50 void SubscriptionJob::subscribe(const Collection::List &list)
51 {
52  Q_D(SubscriptionJob);
53 
54  d->mSub = list;
55 }
56 
57 void SubscriptionJob::unsubscribe(const Collection::List &list)
58 {
59  Q_D(SubscriptionJob);
60 
61  d->mUnsub = list;
62 }
63 
64 void SubscriptionJob::doStart()
65 {
66  Q_D(SubscriptionJob);
67 
68  if (d->mSub.isEmpty() && d->mUnsub.isEmpty()) {
69  emitResult();
70  return;
71  }
72 
73  for (Collection col : qAsConst(d->mSub)) {
74  col.setEnabled(true);
75  new CollectionModifyJob(col, this);
76  }
77  for (Collection col : qAsConst(d->mUnsub)) {
78  col.setEnabled(false);
79  new CollectionModifyJob(col, this);
80  }
81 }
82 
83 void SubscriptionJob::slotResult(KJob *job)
84 {
85  if (job->error()) {
86  setError(job->error());
87  setErrorText(job->errorText());
88  Q_FOREACH (KJob *subjob, subjobs()) {
89  removeSubjob(subjob);
90  }
91  emitResult();
92  } else {
93  Job::slotResult(job);
94 
95  if (!hasSubjobs()) {
96  emitResult();
97  }
98  }
99 }
100 
101 #include "moc_subscriptionjob_p.cpp"
Job that modifies a collection in the Akonadi storage.
Represents a collection of PIM items.
Definition: collection.h:76
Base class for all actions in the Akonadi storage.
Definition: job.h:93
Helper integration between Akonadi and Qt.
QString errorText() const
int error() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 30 2020 22:46:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.