Akonadi

collectioncopyjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "collectioncopyjob.h"
8 #include "collection.h"
9 #include "job_p.h"
10 #include "protocolhelper_p.h"
11 #include "private/protocol_p.h"
12 
13 #include <KLocalizedString>
14 
15 using namespace Akonadi;
16 
17 class Akonadi::CollectionCopyJobPrivate : public JobPrivate
18 {
19 public:
20  explicit CollectionCopyJobPrivate(CollectionCopyJob *parent)
21  : JobPrivate(parent)
22  {
23  }
24 
25  Collection mSource;
26  Collection mTarget;
27 
28  QString jobDebuggingString() const override;
29 };
30 
31 QString Akonadi::CollectionCopyJobPrivate::jobDebuggingString() const
32 {
33  return QStringLiteral("copy collection from %1 to %2").arg(mSource.id()).arg(mTarget.id());
34 }
35 
36 CollectionCopyJob::CollectionCopyJob(const Collection &source, const Collection &target, QObject *parent)
37  : Job(new CollectionCopyJobPrivate(this), parent)
38 {
39  Q_D(CollectionCopyJob);
40 
41  d->mSource = source;
42  d->mTarget = target;
43 }
44 
46 {
47 }
48 
50 {
51  Q_D(CollectionCopyJob);
52 
53  if (!d->mSource.isValid() && d->mSource.remoteId().isEmpty()) {
55  setErrorText(i18n("Invalid collection to copy"));
56  emitResult();
57  return;
58  }
59  if (!d->mTarget.isValid() && d->mTarget.remoteId().isEmpty()) {
61  setErrorText(i18n("Invalid destination collection"));
62  emitResult();
63  return;
64  }
65  d->sendCommand(Protocol::CopyCollectionCommandPtr::create(d->mSource.id(), d->mTarget.id()));
66 }
67 
69 {
70  if (!response->isResponse() || response->type() != Protocol::Command::CopyCollection) {
71  return Job::doHandleResponse(tag, response);
72  }
73 
74  return true;
75 }
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)
Base class for all actions in the Akonadi storage.
Definition: job.h:80
~CollectionCopyJob() override
Destroys the collection copy job.
CollectionCopyJob(const Collection &source, const Collection &target, QObject *parent=nullptr)
Creates a new collection copy job to copy the given source collection into target.
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...
Job that copies a collection into another collection in the Akonadi storage.
QString i18n(const char *text, const TYPE &arg...)
void doStart() override
This method must be reimplemented in the concrete jobs.
Helper integration between Akonadi and Qt.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 5 2020 23:14:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.