Akonadi

itemcopyjob.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 "itemcopyjob.h"
8
9#include "collection.h"
10#include "job_p.h"
11#include "private/protocol_p.h"
12#include "protocolhelper_p.h"
13
14using namespace Akonadi;
15
16class Akonadi::ItemCopyJobPrivate : public JobPrivate
17{
18public:
19 explicit ItemCopyJobPrivate(ItemCopyJob *parent)
20 : JobPrivate(parent)
21 {
22 }
23 QString jobDebuggingString() const override;
24
25 Item::List mItems;
26 Collection mTarget;
27};
28
29QString Akonadi::ItemCopyJobPrivate::jobDebuggingString() const
30{
31 QString str = QStringLiteral("Copy items : ");
32 const int nbItems = mItems.count();
33 for (int i = 0; i < nbItems; ++i) {
34 if (i != 0) {
35 str += QLatin1Char(',');
36 }
37 str += QString::number(mItems.at(i).id());
38 }
39 return str + QStringLiteral(" to collection %1").arg(mTarget.id());
40}
41
42ItemCopyJob::ItemCopyJob(const Item &item, const Collection &target, QObject *parent)
43 : Job(new ItemCopyJobPrivate(this), parent)
44{
46
47 d->mItems << item;
48 d->mTarget = target;
49}
50
51ItemCopyJob::ItemCopyJob(const Item::List &items, const Collection &target, QObject *parent)
52 : Job(new ItemCopyJobPrivate(this), parent)
53{
55
56 d->mItems = items;
57 d->mTarget = target;
58}
59
63
65{
67
68 try {
69 d->sendCommand(Protocol::CopyItemsCommandPtr::create(ProtocolHelper::entitySetToScope(d->mItems), ProtocolHelper::entityToScope(d->mTarget)));
70 } catch (std::exception &e) {
73 emitResult();
74 }
75}
76
77bool ItemCopyJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
78{
79 if (!response->isResponse() || response->type() != Protocol::Command::CopyItems) {
80 return Job::doHandleResponse(tag, response);
81 }
82
83 return true;
84}
85
86#include "moc_itemcopyjob.cpp"
Represents a collection of PIM items.
Definition collection.h:62
Job that copies a set of items to a target collection in the Akonadi storage.
Definition itemcopyjob.h:48
void doStart() override
This method must be reimplemented in the concrete jobs.
~ItemCopyJob() override
Destroys the item copy job.
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.
ItemCopyJob(const Item &item, const Collection &target, QObject *parent=nullptr)
Creates a new item copy job.
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
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
Helper integration between Akonadi and Qt.
const_reference at(qsizetype i) const const
qsizetype count() 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 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.