Akonadi

itemretrievaljob.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Volker Krause <[email protected]>
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 
13 using namespace Akonadi::Server;
14 
15 AbstractItemRetrievalJob::AbstractItemRetrievalJob(ItemRetrievalRequest req, QObject *parent)
16  : QObject(parent)
17  , m_result(std::move(req))
18 {
19 }
20 
21 ItemRetrievalJob::~ItemRetrievalJob()
22 {
23  Q_ASSERT(!m_active);
24 }
25 
26 void 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);
40  deleteLater();
41  }
42 }
43 
44 void ItemRetrievalJob::kill()
45 {
46  m_active = false;
47  m_result.errorMsg = QStringLiteral("Request cancelled");
48  Q_EMIT requestCompleted(this);
49 }
50 
51 void 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  }
62  deleteLater();
63 }
void finished(QDBusPendingCallWatcher *self)
Q_EMITQ_EMIT
QString message() const const
bool isError() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void deleteLater()
QDBusError error() const const
KIOCORE_EXPORT CopyJob * move(const QList< QUrl > &src, const QUrl &dest, JobFlags flags=DefaultFlags)
Details of a single item retrieval request.
A glue between Qt and the standard library.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.