Akonadi

itemcopyjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "itemcopyjob.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::ItemCopyJobPrivate : public JobPrivate
17 {
18 public:
19  explicit ItemCopyJobPrivate(ItemCopyJob *parent)
20  : JobPrivate(parent)
21  {
22  }
23  QString jobDebuggingString() const override;
24 
25  Item::List mItems;
26  Collection mTarget;
27 };
28 
29 QString Akonadi::ItemCopyJobPrivate::jobDebuggingString() const
30 {
31  QString str = QStringLiteral("Copy items : ");
32  const int nbItems = mItems.count();
33  for (int i = 0; i < nbItems; ++i) {
34  if (i != 0) {
35  str += QLatin1Char(',');
36  }
37  str += QString::number(mItems.at(i).id());
38  }
39  return str + QStringLiteral(" to collection %1").arg(mTarget.id());
40 }
41 
42 ItemCopyJob::ItemCopyJob(const Item &item, const Collection &target, QObject *parent)
43  : Job(new ItemCopyJobPrivate(this), parent)
44 {
46 
47  d->mItems << item;
48  d->mTarget = target;
49 }
50 
51 ItemCopyJob::ItemCopyJob(const Item::List &items, const Collection &target, QObject *parent)
52  : Job(new ItemCopyJobPrivate(this), parent)
53 {
55 
56  d->mItems = items;
57  d->mTarget = target;
58 }
59 
61 {
62 }
63 
65 {
67 
68  try {
69  d->sendCommand(Protocol::CopyItemsCommandPtr::create(ProtocolHelper::entitySetToScope(d->mItems), ProtocolHelper::entityToScope(d->mTarget)));
70  } catch (std::exception &e) {
73  emitResult();
74  }
75 }
76 
77 bool ItemCopyJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
78 {
79  if (!response->isResponse() || response->type() != Protocol::Command::CopyItems) {
80  return Job::doHandleResponse(tag, response);
81  }
82 
83  return true;
84 }
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)
Represents a collection of PIM items.
Definition: collection.h:61
QVector< Item > List
Describes a list of items.
Definition: item.h:115
void doStart() override
This method must be reimplemented in the concrete jobs.
Definition: itemcopyjob.cpp:64
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
Job that copies a set of items to a target collection in the Akonadi storage.
Definition: itemcopyjob.h:47
void emitResult()
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.
Definition: itemcopyjob.cpp:77
void setError(int errorCode)
~ItemCopyJob() override
Destroys the item copy job.
Definition: itemcopyjob.cpp:60
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
Q_D(Todo)
ItemCopyJob(const Item &item, const Collection &target, QObject *parent=nullptr)
Creates a new item copy job.
Definition: itemcopyjob.cpp:42
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:48 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.