Akonadi

itemretrievaljob.cpp
1 /*
2  Copyright (c) 2009 Volker Krause <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "itemretrievaljob.h"
21 #include "itemretrievalrequest.h"
22 #include "resourceinterface.h"
23 #include "akonadiserver_debug.h"
24 
25 #include <QDBusPendingCallWatcher>
26 
27 using namespace Akonadi::Server;
28 
29 AbstractItemRetrievalJob::AbstractItemRetrievalJob(ItemRetrievalRequest req, QObject *parent)
30  : QObject(parent)
31  , m_result(std::move(req))
32 {}
33 
34 ItemRetrievalJob::~ItemRetrievalJob()
35 {
36  Q_ASSERT(!m_active);
37 }
38 
39 void ItemRetrievalJob::start()
40 {
41  qCDebug(AKONADISERVER_LOG) << "processing retrieval request for item" << request().ids << " parts:" << request().parts << " of resource:" << request().resourceId;
42 
43  // call the resource
44  if (m_interface) {
45  m_active = true;
46  auto reply = m_interface->requestItemDelivery(request().ids, request().parts);
47  QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
48  connect(watcher, &QDBusPendingCallWatcher::finished,
49  this, &ItemRetrievalJob::callFinished);
50  } else {
51  m_result.errorMsg = QStringLiteral("Unable to contact resource");
52  Q_EMIT requestCompleted(this);
53  deleteLater();
54  }
55 }
56 
57 void ItemRetrievalJob::kill()
58 {
59  m_active = false;
60  m_result.errorMsg = QStringLiteral("Request cancelled");
61  Q_EMIT requestCompleted(this);
62 }
63 
64 void ItemRetrievalJob::callFinished(QDBusPendingCallWatcher *watcher)
65 {
66  watcher->deleteLater();
67  QDBusPendingReply<void> reply = *watcher;
68  if (m_active) {
69  m_active = false;
70  if (reply.isError()) {
71  m_result.errorMsg = QStringLiteral("Unable to retrieve item from resource: %1").arg(reply.error().message());
72  }
73  Q_EMIT requestCompleted(this);
74  }
75  deleteLater();
76 }
void finished(QDBusPendingCallWatcher *self)
QString message() const const
A glue between Qt and the standard library.
void deleteLater()
QDBusError error() const const
Details of a single item retrieval request.
KIOCORE_EXPORT CopyJob * move(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
bool isError() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon May 25 2020 22:46:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.