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 "private/protocol_p.h"
11 #include "protocolhelper_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 {
40 
41  d->mSource = source;
42  d->mTarget = target;
43 }
44 
46 {
47 }
48 
50 {
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 }
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.
@ Unknown
Unknown error.
Definition: job.h:102
void setErrorText(const QString &errorText)
Represents a collection of PIM items.
Definition: collection.h:61
void doStart() override
This method must be reimplemented in the concrete jobs.
Job that copies a collection into another collection in the Akonadi storage.
QString i18n(const char *text, const TYPE &arg...)
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
~CollectionCopyJob() override
Destroys the collection copy job.
void emitResult()
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 setError(int errorCode)
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 Sat Jun 25 2022 06:00:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.