Akonadi

itemmovejob.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "itemmovejob.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 #include <KLocalizedString>
16 
17 using namespace Akonadi;
18 
19 class Akonadi::ItemMoveJobPrivate : public Akonadi::JobPrivate
20 {
21 public:
22  explicit ItemMoveJobPrivate(ItemMoveJob *parent)
23  : JobPrivate(parent)
24  {
25  }
26 
27  QString jobDebuggingString() const override
28  {
29  QString str = QStringLiteral("Move item");
30  if (source.isValid()) {
31  str += QStringLiteral("from collection %1").arg(source.id());
32  }
33  str += QStringLiteral(" to collection %1. ").arg(destination.id());
34  if (items.isEmpty()) {
35  str += QStringLiteral("No Items defined.");
36  } else {
37  str += QStringLiteral("Items: ");
38  const int nbItems = items.count();
39  for (int i = 0; i < nbItems; ++i) {
40  if (i != 0) {
41  str += QStringLiteral(", ");
42  }
43  str += QString::number(items.at(i).id());
44  }
45  }
46  return str;
47  }
48 
49  Item::List items;
50  Collection destination;
51  Collection source;
52 
53  Q_DECLARE_PUBLIC(ItemMoveJob)
54 };
55 
56 ItemMoveJob::ItemMoveJob(const Item &item, const Collection &destination, QObject *parent)
57  : Job(new ItemMoveJobPrivate(this), parent)
58 {
59  Q_D(ItemMoveJob);
60  d->destination = destination;
61  d->items.append(item);
62 }
63 
64 ItemMoveJob::ItemMoveJob(const Item::List &items, const Collection &destination, QObject *parent)
65  : Job(new ItemMoveJobPrivate(this), parent)
66 {
67  Q_D(ItemMoveJob);
68  d->destination = destination;
69  d->items = items;
70 }
71 
72 ItemMoveJob::ItemMoveJob(const Item::List &items, const Collection &source, const Collection &destination, QObject *parent)
73  : Job(new ItemMoveJobPrivate(this), parent)
74 {
75  Q_D(ItemMoveJob);
76  d->source = source;
77  d->destination = destination;
78  d->items = items;
79 }
80 
82 {
83 }
84 
86 {
87  Q_D(ItemMoveJob);
88 
89  if (d->items.isEmpty()) {
91  setErrorText(i18n("No objects specified for moving"));
92  emitResult();
93  return;
94  }
95 
96  if (!d->destination.isValid() && d->destination.remoteId().isEmpty()) {
98  setErrorText(i18n("No valid destination specified"));
99  emitResult();
100  return;
101  }
102 
103  try {
104  d->sendCommand(Protocol::MoveItemsCommandPtr::create(
105  ProtocolHelper::entitySetToScope(d->items),
106  ProtocolHelper::commandContextToProtocol(d->source, Tag(), d->items),
107  ProtocolHelper::entityToScope(d->destination)));
108  } catch (const Akonadi::Exception &e) {
111  emitResult();
112  return;
113  }
114 }
115 
116 bool ItemMoveJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
117 {
118  if (!response->isResponse() || response->type() != Protocol::Command::MoveItems) {
119  return Job::doHandleResponse(tag, response);
120  }
121 
122  return true;
123 }
124 
126 {
127  Q_D(const ItemMoveJob);
128  return d->destination;
129 }
130 
131 Item::List ItemMoveJob::items() const
132 {
133  Q_D(const ItemMoveJob);
134  return d->items;
135 }
136 
Akonadi::Item::List items() const
Returns the list of items that where passed in the constructor.
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)
Collection destinationCollection() const
Returns the destination collection.
Base class for all actions in the Akonadi storage.
Definition: job.h:80
ItemMoveJob(const Item &item, const Collection &destination, QObject *parent=nullptr)
Move the given item into the given collection.
Definition: itemmovejob.cpp:56
void setErrorText(const QString &errorText)
QString number(int n, int base)
QString fromUtf8(const char *str, int size)
~ItemMoveJob() override
Destroys the item move job.
Definition: itemmovejob.cpp:81
QString i18n(const char *text, const TYPE &arg...)
const char * what() const noexcept override
Returns the error message associated with this exception.
Definition: exception.cpp:62
Job that moves an item into a different collection in the Akonadi storage.
Definition: itemmovejob.h:36
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
void doStart() override
This method must be reimplemented in the concrete jobs.
Definition: itemmovejob.cpp:85
An Akonadi Tag.
Definition: tag.h:26
QObject * parent() const const
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...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 23:16:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.