File indexing completed on 2024-11-17 04:45:08
0001 /* 0002 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> 0003 SPDX-FileContributor: Kevin Ottens <kevin@kdab.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QObject> 0011 0012 #include <Akonadi/Collection> 0013 #include <Akonadi/Item> 0014 0015 #include <KIMAP/Acl> 0016 0017 #include "resourcestateinterface.h" 0018 0019 namespace KIMAP 0020 { 0021 class Session; 0022 } 0023 0024 class SessionPool; 0025 0026 class ResourceTask : public QObject 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 enum ActionIfNoSession { 0032 CancelIfNoSession, 0033 DeferIfNoSession, 0034 }; 0035 Q_ENUM(ActionIfNoSession) 0036 0037 explicit ResourceTask(ActionIfNoSession action, ResourceStateInterface::Ptr resource, QObject *parent = nullptr); 0038 ~ResourceTask() override; 0039 0040 void start(SessionPool *pool); 0041 0042 void kill(); 0043 0044 static QList<QByteArray> fromAkonadiToSupportedImapFlags(const QList<QByteArray> &flags, const Akonadi::Collection &collection); 0045 0046 static QSet<QByteArray> toAkonadiFlags(const QList<QByteArray> &flags); 0047 0048 Q_SIGNALS: 0049 void status(int status, const QString &message = QString()); 0050 0051 protected: 0052 virtual void doStart(KIMAP::Session *session) = 0; 0053 0054 protected: 0055 QString userName() const; 0056 QString resourceName() const; 0057 QStringList serverCapabilities() const; 0058 QList<KIMAP::MailBoxDescriptor> serverNamespaces() const; 0059 0060 bool isAutomaticExpungeEnabled() const; 0061 bool isSubscriptionEnabled() const; 0062 bool isDisconnectedModeEnabled() const; 0063 int intervalCheckTime() const; 0064 0065 Akonadi::Collection collection() const; 0066 Akonadi::Item item() const; 0067 Akonadi::Item::List items() const; 0068 0069 Akonadi::Collection parentCollection() const; 0070 0071 Akonadi::Collection sourceCollection() const; 0072 Akonadi::Collection targetCollection() const; 0073 0074 QSet<QByteArray> parts() const; 0075 QSet<QByteArray> addedFlags() const; 0076 QSet<QByteArray> removedFlags() const; 0077 0078 QString rootRemoteId() const; 0079 QString mailBoxForCollection(const Akonadi::Collection &collection) const; 0080 0081 void setIdleCollection(const Akonadi::Collection &collection); 0082 void applyCollectionChanges(const Akonadi::Collection &collection); 0083 0084 void itemRetrieved(const Akonadi::Item &item); 0085 0086 void itemsRetrieved(const Akonadi::Item::List &items); 0087 void itemsRetrievedIncremental(const Akonadi::Item::List &changed, const Akonadi::Item::List &removed); 0088 void itemsRetrievalDone(); 0089 0090 void setTotalItems(int); 0091 0092 void changeCommitted(const Akonadi::Item &item); 0093 void changesCommitted(const Akonadi::Item::List &items); 0094 0095 void collectionsRetrieved(const Akonadi::Collection::List &collections); 0096 0097 void collectionAttributesRetrieved(const Akonadi::Collection &col); 0098 0099 void changeCommitted(const Akonadi::Collection &collection); 0100 0101 void changeCommitted(const Akonadi::Tag &tag); 0102 0103 void changeProcessed(); 0104 0105 void searchFinished(const QList<qint64> &result, bool isRid = true); 0106 0107 void cancelTask(const QString &errorString); 0108 void deferTask(); 0109 void restartItemRetrieval(Akonadi::Collection::Id col); 0110 void taskDone(); 0111 void emitPercent(int percent); 0112 void emitError(const QString &message); 0113 void emitWarning(const QString &message); 0114 0115 void synchronizeCollectionTree(); 0116 0117 void showInformationDialog(const QString &message, const QString &title, const QString &dontShowAgainName); 0118 0119 const QChar separatorCharacter() const; 0120 void setSeparatorCharacter(QChar separator); 0121 0122 virtual bool serverSupportsAnnotations() const; 0123 virtual bool serverSupportsCondstore() const; 0124 0125 int batchSize() const; 0126 void setItemMergingMode(Akonadi::ItemSync::MergeMode mode); 0127 0128 ResourceStateInterface::Ptr resourceState(); 0129 0130 KIMAP::Acl::Rights myRights(const Akonadi::Collection &); 0131 0132 private: 0133 void abortTask(const QString &errorString); 0134 0135 static QList<QByteArray> fromAkonadiFlags(const QList<QByteArray> &flags); 0136 0137 private Q_SLOTS: 0138 void onSessionRequested(qint64 requestId, KIMAP::Session *session, int errorCode, const QString &errorString); 0139 void onConnectionLost(KIMAP::Session *session); 0140 void onPoolDisconnect(); 0141 0142 private: 0143 SessionPool *m_pool = nullptr; 0144 qint64 m_sessionRequestId = 0; 0145 0146 KIMAP::Session *m_session = nullptr; 0147 ActionIfNoSession m_actionIfNoSession; 0148 ResourceStateInterface::Ptr m_resource; 0149 bool mCancelled = false; 0150 };