Akonadi

collectionmovejob.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
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
16using namespace Akonadi;
17
18class Akonadi::CollectionMoveJobPrivate : public JobPrivate
19{
20public:
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
33QString Akonadi::CollectionMoveJobPrivate::jobDebuggingString() const
34{
35 return QStringLiteral("Move collection from %1 to %2").arg(collection.id()).arg(destination.id());
36}
37
38CollectionMoveJob::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}
80
81#include "moc_collectionmovejob.cpp"
Job that moves a collection in the Akonadi storage to a new parent collection.
void doStart() override
This method must be reimplemented in the concrete jobs.
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.
CollectionMoveJob(const Collection &collection, const Collection &destination, QObject *parent=nullptr)
Creates a new collection move job for the given collection and destination.
Represents a collection of PIM items.
Definition collection.h:62
Base class for all actions in the Akonadi storage.
Definition job.h:81
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
@ Unknown
Unknown error.
Definition job.h:102
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
QString i18n(const char *text, const TYPE &arg...)
Helper integration between Akonadi and Qt.
QString arg(Args &&... args) const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.