Akonadi

itemdeletejob.cpp
1 /*
2  Copyright (c) 2006 - 2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "itemdeletejob.h"
8 
9 #include "collection.h"
10 #include "item.h"
11 #include "job_p.h"
12 #include "protocolhelper_p.h"
13 #include "private/protocol_p.h"
14 
15 
16 using namespace Akonadi;
17 
18 class Akonadi::ItemDeleteJobPrivate : public JobPrivate
19 {
20 public:
21  explicit ItemDeleteJobPrivate(ItemDeleteJob *parent)
22  : JobPrivate(parent)
23  {
24  }
25 
26  Q_DECLARE_PUBLIC(ItemDeleteJob)
27  QString jobDebuggingString() const override;
28 
29  Item::List mItems;
30  Collection mCollection;
31  Tag mCurrentTag;
32 
33 };
34 
35 QString Akonadi::ItemDeleteJobPrivate::jobDebuggingString() const
36 {
37  QString itemStr = QStringLiteral("items id: ");
38  bool firstItem = true;
39  for (const Akonadi::Item &item : qAsConst(mItems)) {
40  if (firstItem) {
41  firstItem = false;
42  } else {
43  itemStr += QStringLiteral(", ");
44  }
45  itemStr += QString::number(item.id());
46  }
47 
48  return QStringLiteral("Remove %1 from collection id %2").arg(itemStr).arg(mCollection.id());
49 }
50 
51 ItemDeleteJob::ItemDeleteJob(const Item &item, QObject *parent)
52  : Job(new ItemDeleteJobPrivate(this), parent)
53 {
54  Q_D(ItemDeleteJob);
55 
56  d->mItems << item;
57 }
58 
59 ItemDeleteJob::ItemDeleteJob(const Item::List &items, QObject *parent)
60  : Job(new ItemDeleteJobPrivate(this), parent)
61 {
62  Q_D(ItemDeleteJob);
63 
64  d->mItems = items;
65 }
66 
68  : Job(new ItemDeleteJobPrivate(this), parent)
69 {
70  Q_D(ItemDeleteJob);
71 
72  d->mCollection = collection;
73 }
74 
76  : Job(new ItemDeleteJobPrivate(this), parent)
77 {
78  Q_D(ItemDeleteJob);
79 
80  d->mCurrentTag = tag;
81 }
82 
84 {
85 }
86 
87 Item::List ItemDeleteJob::deletedItems() const
88 {
89  Q_D(const ItemDeleteJob);
90 
91  return d->mItems;
92 }
93 
95 {
96  Q_D(ItemDeleteJob);
97 
98  try {
99  d->sendCommand(Protocol::DeleteItemsCommandPtr::create(
100  d->mItems.isEmpty() ? Scope() : ProtocolHelper::entitySetToScope(d->mItems),
101  ProtocolHelper::commandContextToProtocol(d->mCollection, d->mCurrentTag, d->mItems)));
102  } catch (const Akonadi::Exception &e) {
105  emitResult();
106  return;
107  }
108 }
109 
110 bool ItemDeleteJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
111 {
112  if (!response->isResponse() || response->type() != Protocol::Command::DeleteItems) {
113  return Job::doHandleResponse(tag, response);
114  }
115 
116  return true;
117 }
118 
119 #include "moc_itemdeletejob.cpp"
void doStart() override
This method must be reimplemented in the concrete jobs.
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:372
void emitResult()
Unknown error.
Definition: job.h:102
Represents a collection of PIM items.
Definition: collection.h:63
void setError(int errorCode)
Base class for all actions in the Akonadi storage.
Definition: job.h:80
Job that deletes items from the Akonadi storage.
Definition: itemdeletejob.h:49
void setErrorText(const QString &errorText)
QString number(int n, int base)
QString fromUtf8(const char *str, int size)
~ItemDeleteJob() override
Destroys the item delete job.
const char * what() const noexcept override
Returns the error message associated with this exception.
Definition: exception.cpp:62
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...
Id id() const
Returns the unique identifier of the collection.
Definition: collection.cpp:99
Helper integration between Akonadi and Qt.
Base class for exceptions used by the Akonadi library.
Definition: exceptionbase.h:30
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
ItemDeleteJob(const Item &item, QObject *parent=nullptr)
Creates a new item delete job that deletes item.
An Akonadi Tag.
Definition: tag.h:26
QObject * parent() const const
Item::List deletedItems() const
Returns the items passed on in the constructor.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Aug 6 2020 23:15:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.