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 #pragma once
0008 
0009 #include <QObject>
0010 
0011 #include "itemretrievalrequest.h"
0012 
0013 class QDBusPendingCallWatcher;
0014 class OrgFreedesktopAkonadiResourceInterface;
0015 
0016 namespace Akonadi
0017 {
0018 namespace Server
0019 {
0020 class ItemRetrievalRequest;
0021 
0022 class AbstractItemRetrievalJob : public QObject
0023 {
0024     Q_OBJECT
0025 public:
0026     AbstractItemRetrievalJob(ItemRetrievalRequest req, QObject *parent);
0027     ~AbstractItemRetrievalJob() override = default;
0028 
0029     virtual void start() = 0;
0030     virtual void kill() = 0;
0031 
0032     const ItemRetrievalRequest &request() const
0033     {
0034         return m_result.request;
0035     }
0036     const ItemRetrievalResult &result() const
0037     {
0038         return m_result;
0039     }
0040 
0041 Q_SIGNALS:
0042     void requestCompleted(Akonadi::Server::AbstractItemRetrievalJob *job);
0043 
0044 protected:
0045     ItemRetrievalResult m_result;
0046 };
0047 
0048 /// Async D-Bus retrieval, no modification of the request (thus no need for locking)
0049 class ItemRetrievalJob : public AbstractItemRetrievalJob
0050 {
0051     Q_OBJECT
0052 public:
0053     ItemRetrievalJob(ItemRetrievalRequest req, QObject *parent)
0054         : AbstractItemRetrievalJob(std::move(req), parent)
0055     {
0056     }
0057 
0058     void setInterface(OrgFreedesktopAkonadiResourceInterface *interface)
0059     {
0060         m_interface = interface;
0061     }
0062 
0063     ~ItemRetrievalJob() override;
0064     void start() override;
0065     void kill() override;
0066 
0067 private Q_SLOTS:
0068     void callFinished(QDBusPendingCallWatcher *watcher);
0069 
0070 private:
0071     bool m_active = false;
0072     OrgFreedesktopAkonadiResourceInterface *m_interface = nullptr;
0073 };
0074 
0075 } // namespace Server
0076 } // namespace Akonadi