Akonadi

itemmovejob.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "itemmovejob.h"
8
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::ItemMoveJobPrivate : public Akonadi::JobPrivate
19{
20public:
21 explicit ItemMoveJobPrivate(ItemMoveJob *parent)
22 : JobPrivate(parent)
23 {
24 }
25
26 QString jobDebuggingString() const override
27 {
28 QString str = QStringLiteral("Move item");
29 if (source.isValid()) {
30 str += QStringLiteral("from collection %1").arg(source.id());
31 }
32 str += QStringLiteral(" to collection %1. ").arg(destination.id());
33 if (items.isEmpty()) {
34 str += QStringLiteral("No Items defined.");
35 } else {
36 str += QStringLiteral("Items: ");
37 const int nbItems = items.count();
38 for (int i = 0; i < nbItems; ++i) {
39 if (i != 0) {
40 str += QStringLiteral(", ");
41 }
42 str += QString::number(items.at(i).id());
43 }
44 }
45 return str;
46 }
47
48 Item::List items;
49 Collection destination;
50 Collection source;
51
52 Q_DECLARE_PUBLIC(ItemMoveJob)
53};
54
55ItemMoveJob::ItemMoveJob(const Item &item, const Collection &destination, QObject *parent)
56 : Job(new ItemMoveJobPrivate(this), parent)
57{
59 d->destination = destination;
60 d->items.append(item);
61}
62
63ItemMoveJob::ItemMoveJob(const Item::List &items, const Collection &destination, QObject *parent)
64 : Job(new ItemMoveJobPrivate(this), parent)
65{
67 d->destination = destination;
68 d->items = items;
69}
70
71ItemMoveJob::ItemMoveJob(const Item::List &items, const Collection &source, const Collection &destination, QObject *parent)
72 : Job(new ItemMoveJobPrivate(this), parent)
73{
75 d->source = source;
76 d->destination = destination;
77 d->items = items;
78}
79
83
85{
87
88 if (d->items.isEmpty()) {
90 setErrorText(i18n("No objects specified for moving"));
91 emitResult();
92 return;
93 }
94
95 if (!d->destination.isValid() && d->destination.remoteId().isEmpty()) {
97 setErrorText(i18n("No valid destination specified"));
98 emitResult();
99 return;
100 }
101
102 try {
103 d->sendCommand(Protocol::MoveItemsCommandPtr::create(ProtocolHelper::entitySetToScope(d->items),
104 ProtocolHelper::commandContextToProtocol(d->source, Tag(), d->items),
105 ProtocolHelper::entityToScope(d->destination)));
106 } catch (const Akonadi::Exception &e) {
109 emitResult();
110 return;
111 }
112}
113
115{
116 if (!response->isResponse() || response->type() != Protocol::Command::MoveItems) {
117 return Job::doHandleResponse(tag, response);
118 }
119
120 return true;
121}
122
124{
125 Q_D(const ItemMoveJob);
126 return d->destination;
127}
128
130{
131 Q_D(const ItemMoveJob);
132 return d->items;
133}
134
135#include "moc_itemmovejob.cpp"
Represents a collection of PIM items.
Definition collection.h:62
Base class for exceptions used by the Akonadi library.
const char * what() const noexcept override
Returns the error message associated with this exception.
Definition exception.cpp:65
Job that moves an item into a different collection in the Akonadi storage.
Definition itemmovejob.h:35
ItemMoveJob(const Item &item, const Collection &destination, QObject *parent=nullptr)
Move the given item into the given collection.
~ItemMoveJob() override
Destroys the item move job.
Akonadi::Item::List items() const
Returns the list of items that where passed in the constructor.
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.
Collection destinationCollection() const
Returns the destination collection.
void doStart() override
This method must be reimplemented in the concrete jobs.
Represents a PIM item stored in Akonadi storage.
Definition item.h:100
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
An Akonadi Tag.
Definition tag.h:26
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.
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
QString arg(Args &&... args) const const
QString fromUtf8(QByteArrayView str)
QString number(double n, char format, int precision)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.