Akonadi

itemdeletejob.cpp
1 /*
2  SPDX-FileCopyrightText: 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 "job_p.h"
11 #include "private/protocol_p.h"
12 #include "protocolhelper_p.h"
13 
14 using namespace Akonadi;
15 
16 class Akonadi::ItemDeleteJobPrivate : public JobPrivate
17 {
18 public:
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 
32 QString 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 
64 ItemDeleteJob::ItemDeleteJob(const Collection &collection, QObject *parent)
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 
81 {
82 }
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 
106 bool ItemDeleteJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
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"
~ItemDeleteJob() override
Destroys the item delete job.
QString number(int n, int base)
Job that deletes items from the Akonadi storage.
Definition: itemdeletejob.h:47
QString fromUtf8(const char *str, int size)
@ Unknown
Unknown error.
Definition: job.h:102
void setErrorText(const QString &errorText)
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.
An Akonadi Tag.
Definition: tag.h:25
Represents a collection of PIM items.
Definition: collection.h:61
Item::List deletedItems() const
Returns the items passed on in the constructor.
QVector< Item > List
Describes a list of items.
Definition: item.h:115
void doStart() override
This method must be reimplemented in the concrete jobs.
const char * what() const noexcept override
Returns the error message associated with this exception.
Definition: exception.cpp:65
Base class for exceptions used by the Akonadi library.
Definition: exceptionbase.h:29
Base class for all actions in the Akonadi storage.
Definition: job.h:80
ItemDeleteJob(const Item &item, QObject *parent=nullptr)
Creates a new item delete job that deletes item.
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
void emitResult()
void setError(int errorCode)
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
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:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.