Akonadi

collectionmovejob.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "collectionmovejob.h"
8 #include "changemediator_p.h"
9 #include "collection.h"
10 #include "job_p.h"
11 #include "protocolhelper_p.h"
12 #include "private/protocol_p.h"
13 
14 #include <KLocalizedString>
15 
16 using namespace Akonadi;
17 
18 class Akonadi::CollectionMoveJobPrivate : public JobPrivate
19 {
20 public:
21  explicit CollectionMoveJobPrivate(CollectionMoveJob *parent)
22  : JobPrivate(parent)
23  {
24  }
25 
26  QString jobDebuggingString() const override;
27  Collection destination;
28  Collection collection;
29 
30  Q_DECLARE_PUBLIC(CollectionMoveJob)
31 
32 };
33 
34 QString Akonadi::CollectionMoveJobPrivate::jobDebuggingString() const
35 {
36  return QStringLiteral("Move collection from %1 to %2").arg(collection.id()).arg(destination.id());
37 }
38 
39 CollectionMoveJob::CollectionMoveJob(const Collection &collection, const Collection &destination, QObject *parent)
40  : Job(new CollectionMoveJobPrivate(this), parent)
41 {
42  Q_D(CollectionMoveJob);
43  d->destination = destination;
44  d->collection = collection;
45 }
46 
48 {
49  Q_D(CollectionMoveJob);
50 
51  if (!d->collection.isValid()) {
53  setErrorText(i18n("No objects specified for moving"));
54  emitResult();
55  return;
56  }
57 
58  if (!d->destination.isValid() && d->destination.remoteId().isEmpty()) {
60  setErrorText(i18n("No valid destination specified"));
61  emitResult();
62  return;
63  }
64 
65  const Scope colScope = ProtocolHelper::entitySetToScope(Collection::List() << d->collection);
66  const Scope destScope = ProtocolHelper::entitySetToScope(Collection::List() << d->destination);
67 
68  d->sendCommand(Protocol::MoveCollectionCommandPtr::create(colScope, destScope));
69 
70  ChangeMediator::invalidateCollection(d->collection);
71 }
72 
74 {
75  if (!response->isResponse() || response->type() != Protocol::Command::MoveCollection) {
76  return Job::doHandleResponse(tag, response);
77  }
78 
79  return true;
80 }
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
Job that moves a collection in the Akonadi storage to a new parent collection.
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
void setErrorText(const QString &errorText)
QString i18n(const char *text, const TYPE &arg...)
CollectionMoveJob(const Collection &collection, const Collection &destination, QObject *parent=nullptr)
Creates a new collection move job for the given collection and destination.
Helper integration between Akonadi and Qt.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
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 doStart() override
This method must be reimplemented in the concrete jobs.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 3 2020 23:15:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.