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 "private/protocol_p.h"
12 #include "protocolhelper_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 QString Akonadi::CollectionMoveJobPrivate::jobDebuggingString() const
34 {
35  return QStringLiteral("Move collection from %1 to %2").arg(collection.id()).arg(destination.id());
36 }
37 
38 CollectionMoveJob::CollectionMoveJob(const Collection &collection, const Collection &destination, QObject *parent)
39  : Job(new CollectionMoveJobPrivate(this), parent)
40 {
42  d->destination = destination;
43  d->collection = collection;
44 }
45 
47 {
49 
50  if (!d->collection.isValid()) {
52  setErrorText(i18n("No objects specified for moving"));
53  emitResult();
54  return;
55  }
56 
57  if (!d->destination.isValid() && d->destination.remoteId().isEmpty()) {
59  setErrorText(i18n("No valid destination specified"));
60  emitResult();
61  return;
62  }
63 
64  const Scope colScope = ProtocolHelper::entitySetToScope(Collection::List() << d->collection);
65  const Scope destScope = ProtocolHelper::entitySetToScope(Collection::List() << d->destination);
66 
67  d->sendCommand(Protocol::MoveCollectionCommandPtr::create(colScope, destScope));
68 
69  ChangeMediator::invalidateCollection(d->collection);
70 }
71 
73 {
74  if (!response->isResponse() || response->type() != Protocol::Command::MoveCollection) {
75  return Job::doHandleResponse(tag, response);
76  }
77 
78  return true;
79 }
@ Unknown
Unknown error.
Definition: job.h:102
void setErrorText(const QString &errorText)
Represents a collection of PIM items.
Definition: collection.h:61
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.
Base class for all actions in the Akonadi storage.
Definition: job.h:80
Job that moves a collection in the Akonadi storage to a new parent collection.
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.
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
void doStart() override
This method must be reimplemented in the concrete jobs.
void emitResult()
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 Thu Jun 30 2022 03:51:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.