Akonadi

subscriptionjob.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
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
13using namespace Akonadi;
14
15class Akonadi::SubscriptionJobPrivate : public JobPrivate
16{
17public:
18 explicit SubscriptionJobPrivate(SubscriptionJob *parent)
19 : JobPrivate(parent)
20 {
21 }
22
23 Q_DECLARE_PUBLIC(SubscriptionJob)
24
25 Collection::List mSub, mUnsub;
26};
27
28SubscriptionJob::SubscriptionJob(QObject *parent)
29 : Job(new SubscriptionJobPrivate(this), parent)
30{
31}
32
33SubscriptionJob::~SubscriptionJob()
34{
35}
36
37void SubscriptionJob::subscribe(const Collection::List &list)
38{
39 Q_D(SubscriptionJob);
40
41 d->mSub = list;
42}
43
44void SubscriptionJob::unsubscribe(const Collection::List &list)
45{
46 Q_D(SubscriptionJob);
47
48 d->mUnsub = list;
49}
50
51void 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
70void 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:62
Base class for all actions in the Akonadi storage.
Definition job.h:81
int error() const
QString errorText() const
Helper integration between Akonadi and Qt.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.