Akonadi

itemdeletejob.cpp
1/*
2 SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "itemdeletejob.h"
8
9#include "collection.h"
10#include "job_p.h"
11#include "private/protocol_p.h"
12#include "protocolhelper_p.h"
13
14using namespace Akonadi;
15
16class Akonadi::ItemDeleteJobPrivate : public JobPrivate
17{
18public:
19 explicit ItemDeleteJobPrivate(ItemDeleteJob *parent)
20 : JobPrivate(parent)
21 {
22 }
23
24 Q_DECLARE_PUBLIC(ItemDeleteJob)
25 QString jobDebuggingString() const override;
26
27 Item::List mItems;
28 Collection mCollection;
29 Tag mCurrentTag;
30};
31
32QString Akonadi::ItemDeleteJobPrivate::jobDebuggingString() const
33{
34 QString itemStr = QStringLiteral("items id: ");
35 bool firstItem = true;
36 for (const Akonadi::Item &item : std::as_const(mItems)) {
37 if (firstItem) {
38 firstItem = false;
39 } else {
40 itemStr += QStringLiteral(", ");
41 }
42 itemStr += QString::number(item.id());
43 }
44
45 return QStringLiteral("Remove %1 from collection id %2").arg(itemStr).arg(mCollection.id());
46}
47
49 : Job(new ItemDeleteJobPrivate(this), parent)
50{
52
53 d->mItems << item;
54}
55
57 : Job(new ItemDeleteJobPrivate(this), parent)
58{
60
61 d->mItems = items;
62}
63
65 : Job(new ItemDeleteJobPrivate(this), parent)
66{
68
69 d->mCollection = collection;
70}
71
73 : Job(new ItemDeleteJobPrivate(this), parent)
74{
76
77 d->mCurrentTag = tag;
78}
79
83
85{
86 Q_D(const ItemDeleteJob);
87
88 return d->mItems;
89}
90
92{
94
95 try {
96 d->sendCommand(Protocol::DeleteItemsCommandPtr::create(d->mItems.isEmpty() ? Scope() : ProtocolHelper::entitySetToScope(d->mItems),
97 ProtocolHelper::commandContextToProtocol(d->mCollection, d->mCurrentTag, d->mItems)));
98 } catch (const Akonadi::Exception &e) {
101 emitResult();
102 return;
103 }
104}
105
107{
108 if (!response->isResponse() || response->type() != Protocol::Command::DeleteItems) {
109 return Job::doHandleResponse(tag, response);
110 }
111
112 return true;
113}
114
115#include "moc_itemdeletejob.cpp"
Represents a collection of PIM items.
Definition collection.h:62
Base class for exceptions used by the Akonadi library.
const char * what() const noexcept override
Returns the error message associated with this exception.
Definition exception.cpp:65
Job that deletes items from the Akonadi storage.
Item::List deletedItems() const
Returns the items passed on in the constructor.
void doStart() override
This method must be reimplemented in the concrete jobs.
bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override
This method should be reimplemented in the concrete jobs in case you want to handle incoming data.
ItemDeleteJob(const Item &item, QObject *parent=nullptr)
Creates a new item delete job that deletes item.
~ItemDeleteJob() override
Destroys the item delete job.
Represents a PIM item stored in Akonadi storage.
Definition item.h:100
Base class for all actions in the Akonadi storage.
Definition job.h:81
virtual bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
This method should be reimplemented in the concrete jobs in case you want to handle incoming data.
Definition job.cpp:381
@ Unknown
Unknown error.
Definition job.h:102
An Akonadi Tag.
Definition tag.h:26
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
Helper integration between Akonadi and Qt.
QString fromUtf8(QByteArrayView str)
QString number(double n, char format, int precision)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.