Akonadi

itemcopyjob.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "itemcopyjob.h"
21 
22 #include "collection.h"
23 #include "job_p.h"
24 #include "protocolhelper_p.h"
25 #include "private/protocol_p.h"
26 
27 using namespace Akonadi;
28 
29 class Akonadi::ItemCopyJobPrivate : public JobPrivate
30 {
31 public:
32  ItemCopyJobPrivate(ItemCopyJob *parent)
33  : JobPrivate(parent)
34  {
35  }
36  QString jobDebuggingString() const override;
37 
38  Item::List mItems;
39  Collection mTarget;
40 };
41 
42 QString Akonadi::ItemCopyJobPrivate::jobDebuggingString() const
43 {
44  QString str = QStringLiteral("Copy items : ");
45  const int nbItems = mItems.count();
46  for (int i = 0; i < nbItems; ++i) {
47  if (i != 0) {
48  str += QLatin1Char(',');
49  }
50  str += QString::number(mItems.at(i).id());
51  }
52  return str + QStringLiteral(" to collection %1").arg(mTarget.id());
53 }
54 
55 ItemCopyJob::ItemCopyJob(const Item &item, const Collection &target, QObject *parent)
56  : Job(new ItemCopyJobPrivate(this), parent)
57 {
58  Q_D(ItemCopyJob);
59 
60  d->mItems << item;
61  d->mTarget = target;
62 }
63 
64 ItemCopyJob::ItemCopyJob(const Item::List &items, const Collection &target, QObject *parent)
65  : Job(new ItemCopyJobPrivate(this), parent)
66 {
67  Q_D(ItemCopyJob);
68 
69  d->mItems = items;
70  d->mTarget = target;
71 }
72 
74 {
75 }
76 
78 {
79  Q_D(ItemCopyJob);
80 
81  try {
82  d->sendCommand(Protocol::CopyItemsCommandPtr::create(ProtocolHelper::entitySetToScope(d->mItems),
83  ProtocolHelper::entityToScope(d->mTarget)));
84  } catch (std::exception &e) {
87  emitResult();
88  }
89 }
90 
91 bool ItemCopyJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
92 {
93  if (!response->isResponse() || response->type() != Protocol::Command::CopyItems) {
94  return Job::doHandleResponse(tag, response);
95  }
96 
97  return true;
98 }
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:385
void emitResult()
void doStart() override
This method must be reimplemented in the concrete jobs.
Definition: itemcopyjob.cpp:77
Unknown error.
Definition: job.h:115
Job that copies a set of items to a target collection in the Akonadi storage.
Definition: itemcopyjob.h:62
Represents a collection of PIM items.
Definition: collection.h:76
void setError(int errorCode)
Base class for all actions in the Akonadi storage.
Definition: job.h:93
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:91
void setErrorText(const QString &errorText)
QString number(int n, int base)
QString fromUtf8(const char *str, int size)
ItemCopyJob(const Item &item, const Collection &target, QObject *parent=nullptr)
Creates a new item copy job.
Definition: itemcopyjob.cpp:55
~ItemCopyJob() override
Destroys the item copy job.
Definition: itemcopyjob.cpp:73
Helper integration between Akonadi and Qt.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.