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 "job_p.h"
11 #include "private/protocol_p.h"
12 #include "protocolhelper_p.h"
13 
14 #include <KLocalizedString>
15 
16 using namespace Akonadi;
17 
18 class Akonadi::ItemMoveJobPrivate : public Akonadi::JobPrivate
19 {
20 public:
21  explicit ItemMoveJobPrivate(ItemMoveJob *parent)
22  : JobPrivate(parent)
23  {
24  }
25 
26  QString jobDebuggingString() const override
27  {
28  QString str = QStringLiteral("Move item");
29  if (source.isValid()) {
30  str += QStringLiteral("from collection %1").arg(source.id());
31  }
32  str += QStringLiteral(" to collection %1. ").arg(destination.id());
33  if (items.isEmpty()) {
34  str += QStringLiteral("No Items defined.");
35  } else {
36  str += QStringLiteral("Items: ");
37  const int nbItems = items.count();
38  for (int i = 0; i < nbItems; ++i) {
39  if (i != 0) {
40  str += QStringLiteral(", ");
41  }
42  str += QString::number(items.at(i).id());
43  }
44  }
45  return str;
46  }
47 
48  Item::List items;
49  Collection destination;
50  Collection source;
51 
52  Q_DECLARE_PUBLIC(ItemMoveJob)
53 };
54 
55 ItemMoveJob::ItemMoveJob(const Item &item, const Collection &destination, QObject *parent)
56  : Job(new ItemMoveJobPrivate(this), parent)
57 {
59  d->destination = destination;
60  d->items.append(item);
61 }
62 
63 ItemMoveJob::ItemMoveJob(const Item::List &items, const Collection &destination, QObject *parent)
64  : Job(new ItemMoveJobPrivate(this), parent)
65 {
67  d->destination = destination;
68  d->items = items;
69 }
70 
71 ItemMoveJob::ItemMoveJob(const Item::List &items, const Collection &source, const Collection &destination, QObject *parent)
72  : Job(new ItemMoveJobPrivate(this), parent)
73 {
75  d->source = source;
76  d->destination = destination;
77  d->items = items;
78 }
79 
81 {
82 }
83 
85 {
87 
88  if (d->items.isEmpty()) {
90  setErrorText(i18n("No objects specified for moving"));
91  emitResult();
92  return;
93  }
94 
95  if (!d->destination.isValid() && d->destination.remoteId().isEmpty()) {
97  setErrorText(i18n("No valid destination specified"));
98  emitResult();
99  return;
100  }
101 
102  try {
103  d->sendCommand(Protocol::MoveItemsCommandPtr::create(ProtocolHelper::entitySetToScope(d->items),
104  ProtocolHelper::commandContextToProtocol(d->source, Tag(), d->items),
105  ProtocolHelper::entityToScope(d->destination)));
106  } catch (const Akonadi::Exception &e) {
109  emitResult();
110  return;
111  }
112 }
113 
114 bool ItemMoveJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
115 {
116  if (!response->isResponse() || response->type() != Protocol::Command::MoveItems) {
117  return Job::doHandleResponse(tag, response);
118  }
119 
120  return true;
121 }
122 
124 {
125  Q_D(const ItemMoveJob);
126  return d->destination;
127 }
128 
130 {
131  Q_D(const ItemMoveJob);
132  return d->items;
133 }
QString number(int n, int base)
QString fromUtf8(const char *str, int size)
@ Unknown
Unknown error.
Definition: job.h:102
void setErrorText(const QString &errorText)
An Akonadi Tag.
Definition: tag.h:25
Represents a collection of PIM items.
Definition: collection.h:61
QVector< Item > List
Describes a list of items.
Definition: item.h:115
Collection destinationCollection() const
Returns the destination collection.
Job that moves an item into a different collection in the Akonadi storage.
Definition: itemmovejob.h:34
~ItemMoveJob() override
Destroys the item move job.
Definition: itemmovejob.cpp:80
const char * what() const noexcept override
Returns the error message associated with this exception.
Definition: exception.cpp:65
QString i18n(const char *text, const TYPE &arg...)
Akonadi::Item::List items() const
Returns the list of items that where passed in the constructor.
Base class for exceptions used by the Akonadi library.
Definition: exceptionbase.h:29
ItemMoveJob(const Item &item, const Collection &destination, QObject *parent=nullptr)
Move the given item into the given collection.
Definition: itemmovejob.cpp:55
Base class for all actions in the Akonadi storage.
Definition: job.h:80
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
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
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.
void emitResult()
void doStart() override
This method must be reimplemented in the concrete jobs.
Definition: itemmovejob.cpp:84
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 Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.