File indexing completed on 2024-11-17 04:45:07
0001 /* 0002 SPDX-FileCopyrightText: 2007 Till Adam <adam@kde.org> 0003 SPDX-FileCopyrightText: 2008 Omat Holding B.V. <info@omat.nl> 0004 SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org> 0005 0006 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> 0007 SPDX-FileContributor: Kevin Ottens <kevin@kdab.com> 0008 0009 SPDX-License-Identifier: LGPL-2.0-or-later 0010 */ 0011 0012 #pragma once 0013 0014 #include "resourcestate.h" 0015 #include "resourcestateinterface.h" 0016 #include <Akonadi/AgentSearchInterface> 0017 #include <Akonadi/ResourceBase> 0018 class QDialog; 0019 0020 class QTimer; 0021 0022 class ResourceTask; 0023 namespace KIMAP 0024 { 0025 class Session; 0026 } 0027 0028 class ImapIdleManager; 0029 class SessionPool; 0030 class ResourceState; 0031 class SubscriptionDialog; 0032 class Settings; 0033 0034 class ImapResourceBase : public Akonadi::ResourceBase, public Akonadi::AgentBase::ObserverV4, public Akonadi::AgentSearchInterface 0035 { 0036 Q_OBJECT 0037 Q_CLASSINFO("D-Bus Interface", "org.kde.Akonadi.ImapResourceBase") 0038 protected: 0039 using Akonadi::AgentBase::Observer::collectionChanged; 0040 0041 public: 0042 explicit ImapResourceBase(const QString &id); 0043 ~ImapResourceBase() override; 0044 0045 virtual QDialog *createConfigureDialog(WId windowId) = 0; 0046 0047 void cleanup() override; 0048 0049 virtual Settings *settings() const; 0050 0051 public Q_SLOTS: 0052 void configure(WId windowId) override; 0053 0054 // DBus methods 0055 Q_SCRIPTABLE void requestManualExpunge(qint64 collectionId); 0056 Q_SCRIPTABLE int configureSubscription(qlonglong windowId = 0); 0057 Q_SCRIPTABLE QStringList serverCapabilities() const; 0058 0059 // pseudo-virtual called by ResourceBase 0060 QString dumpResourceToString() const override; 0061 0062 protected: 0063 using ResourceBase::retrieveItems; // suppress -Woverload-virtual 0064 0065 protected Q_SLOTS: 0066 void startIdleIfNeeded(); 0067 void startIdle(); 0068 0069 void abortActivity() override; 0070 0071 void retrieveCollections() override; 0072 void retrieveCollectionAttributes(const Akonadi::Collection &col) override; 0073 0074 void retrieveItems(const Akonadi::Collection &col) override; 0075 bool retrieveItem(const Akonadi::Item &item, const QSet<QByteArray> &parts) override; 0076 0077 protected: 0078 void itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection) override; 0079 void itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &parts) override; 0080 void itemsFlagsChanged(const Akonadi::Item::List &items, const QSet<QByteArray> &addedFlags, const QSet<QByteArray> &removedFlags) override; 0081 void itemsRemoved(const Akonadi::Item::List &items) override; 0082 void itemsMoved(const Akonadi::Item::List &item, const Akonadi::Collection &source, const Akonadi::Collection &destination) override; 0083 0084 void collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent) override; 0085 void collectionChanged(const Akonadi::Collection &collection, const QSet<QByteArray> &parts) override; 0086 void collectionRemoved(const Akonadi::Collection &collection) override; 0087 void collectionMoved(const Akonadi::Collection &collection, const Akonadi::Collection &source, const Akonadi::Collection &destination) override; 0088 0089 void addSearch(const QString &query, const QString &queryLanguage, const Akonadi::Collection &resultCollection) override; 0090 void removeSearch(const Akonadi::Collection &resultCollection) override; 0091 void search(const QString &query, const Akonadi::Collection &collection) override; 0092 0093 void doSetOnline(bool online) override; 0094 0095 [[nodiscard]] QChar separatorCharacter() const; 0096 void setSeparatorCharacter(QChar separator); 0097 0098 void aboutToQuit() override; 0099 0100 virtual ResourceStateInterface::Ptr createResourceState(const TaskArguments &); 0101 virtual QString defaultName() const = 0; 0102 virtual QByteArray clientId() const = 0; 0103 0104 protected Q_SLOTS: 0105 void delayedInit(); 0106 0107 private Q_SLOTS: 0108 void doSearch(const QVariant &arg); 0109 0110 void reconnect(); 0111 0112 void scheduleConnectionAttempt(); 0113 void startConnect(const QVariant &); // the parameter is necessary, since this method is used by the task scheduler 0114 void onConnectDone(int errorCode, const QString &errorMessage); 0115 void onConnectionLost(KIMAP::Session *session); 0116 0117 void onIdleCollectionFetchDone(KJob *job); 0118 0119 void onExpungeCollectionFetchDone(KJob *job); 0120 void triggerCollectionExpunge(const QVariant &collectionVariant); 0121 0122 void taskDestroyed(QObject *task); 0123 0124 void showError(const QString &message); 0125 void clearStatusMessage(); 0126 0127 void updateResourceName(); 0128 0129 void onCollectionModifyDone(KJob *job); 0130 0131 protected: 0132 // Starts and queues a task 0133 void startTask(ResourceTask *task); 0134 void queueTask(ResourceTask *task); 0135 SessionPool *m_pool = nullptr; 0136 mutable Settings *m_settings; 0137 0138 private: 0139 friend class ResourceState; 0140 0141 bool needsNetwork() const; 0142 void modifyCollection(const Akonadi::Collection &); 0143 0144 friend class ImapIdleManager; 0145 0146 QList<ResourceTask *> m_taskList; // used to be able to kill tasks 0147 QScopedPointer<SubscriptionDialog, QScopedPointerDeleteLater> mSubscriptions; 0148 ImapIdleManager *m_idle = nullptr; 0149 QTimer *m_statusMessageTimer = nullptr; 0150 QChar m_separatorCharacter; 0151 };