Akonadi

itemretrievaljob.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 "itemretrievaljob.h"
8#include "akonadiserver_debug.h"
9#include "resourceinterface.h"
10
11#include <QDBusPendingCallWatcher>
12
13using namespace Akonadi::Server;
14
15AbstractItemRetrievalJob::AbstractItemRetrievalJob(ItemRetrievalRequest req, QObject *parent)
16 : QObject(parent)
17 , m_result(std::move(req))
18{
19}
20
21ItemRetrievalJob::~ItemRetrievalJob()
22{
23 Q_ASSERT(!m_active);
24}
25
26void ItemRetrievalJob::start()
27{
28 qCDebug(AKONADISERVER_LOG) << "processing retrieval request for item" << request().ids << " parts:" << request().parts
29 << " of resource:" << request().resourceId;
30
31 // call the resource
32 if (m_interface) {
33 m_active = true;
34 auto reply = m_interface->requestItemDelivery(request().ids, request().parts);
35 auto watcher = new QDBusPendingCallWatcher(reply, this);
36 connect(watcher, &QDBusPendingCallWatcher::finished, this, &ItemRetrievalJob::callFinished);
37 } else {
38 m_result.errorMsg = QStringLiteral("Unable to contact resource");
39 Q_EMIT requestCompleted(this);
41 }
42}
43
44void ItemRetrievalJob::kill()
45{
46 m_active = false;
47 m_result.errorMsg = QStringLiteral("Request cancelled");
48 Q_EMIT requestCompleted(this);
49}
50
51void ItemRetrievalJob::callFinished(QDBusPendingCallWatcher *watcher)
52{
53 watcher->deleteLater();
54 QDBusPendingReply<void> reply = *watcher;
55 if (m_active) {
56 m_active = false;
57 if (reply.isError()) {
58 m_result.errorMsg = QStringLiteral("Unable to retrieve item from resource: %1").arg(reply.error().message());
59 }
60 Q_EMIT requestCompleted(this);
61 }
63}
64
65#include "moc_itemretrievaljob.cpp"
Details of a single item retrieval request.
KIOCORE_EXPORT CopyJob * move(const QList< QUrl > &src, const QUrl &dest, JobFlags flags=DefaultFlags)
QString message() const const
void finished(QDBusPendingCallWatcher *self)
QDBusError error() const const
bool isError() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
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.