File indexing completed on 2025-01-05 04:46:59
0001 /* 0002 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "itemretrievaljob.h" 0008 #include "akonadiserver_debug.h" 0009 #include "resourceinterface.h" 0010 0011 #include <QDBusPendingCallWatcher> 0012 0013 using namespace Akonadi::Server; 0014 0015 AbstractItemRetrievalJob::AbstractItemRetrievalJob(ItemRetrievalRequest req, QObject *parent) 0016 : QObject(parent) 0017 , m_result(std::move(req)) 0018 { 0019 } 0020 0021 ItemRetrievalJob::~ItemRetrievalJob() 0022 { 0023 Q_ASSERT(!m_active); 0024 } 0025 0026 void ItemRetrievalJob::start() 0027 { 0028 qCDebug(AKONADISERVER_LOG) << "processing retrieval request for item" << request().ids << " parts:" << request().parts 0029 << " of resource:" << request().resourceId; 0030 0031 // call the resource 0032 if (m_interface) { 0033 m_active = true; 0034 auto reply = m_interface->requestItemDelivery(request().ids, request().parts); 0035 auto watcher = new QDBusPendingCallWatcher(reply, this); 0036 connect(watcher, &QDBusPendingCallWatcher::finished, this, &ItemRetrievalJob::callFinished); 0037 } else { 0038 m_result.errorMsg = QStringLiteral("Unable to contact resource"); 0039 Q_EMIT requestCompleted(this); 0040 deleteLater(); 0041 } 0042 } 0043 0044 void ItemRetrievalJob::kill() 0045 { 0046 m_active = false; 0047 m_result.errorMsg = QStringLiteral("Request cancelled"); 0048 Q_EMIT requestCompleted(this); 0049 } 0050 0051 void ItemRetrievalJob::callFinished(QDBusPendingCallWatcher *watcher) 0052 { 0053 watcher->deleteLater(); 0054 QDBusPendingReply<void> reply = *watcher; 0055 if (m_active) { 0056 m_active = false; 0057 if (reply.isError()) { 0058 m_result.errorMsg = QStringLiteral("Unable to retrieve item from resource: %1").arg(reply.error().message()); 0059 } 0060 Q_EMIT requestCompleted(this); 0061 } 0062 deleteLater(); 0063 } 0064 0065 #include "moc_itemretrievaljob.cpp"