File indexing completed on 2024-10-27 04:50:49

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QQueue>
0011 
0012 #include <Akonadi/Item>
0013 
0014 #include <KSharedConfig>
0015 
0016 namespace MessageComposer
0017 {
0018 class AkonadiSender;
0019 class SendLaterInfo;
0020 }
0021 
0022 class QTimer;
0023 class SendLaterJob;
0024 class SendLaterManager : public QObject
0025 {
0026     Q_OBJECT
0027 public:
0028     enum ErrorType {
0029         ItemNotFound = 0,
0030         TooManyItemFound = 1,
0031         CanNotFetchItem = 2,
0032         MailDispatchDoesntWork = 3,
0033         CanNotCreateTransport = 4,
0034         UnknownError = 5,
0035     };
0036 
0037     explicit SendLaterManager(QObject *parent);
0038     ~SendLaterManager() override;
0039 
0040     void sendDone(MessageComposer::SendLaterInfo *info);
0041     void sendError(MessageComposer::SendLaterInfo *info, ErrorType type);
0042     [[nodiscard]] QString printDebugInfo() const;
0043 
0044     void stopAll();
0045     [[nodiscard]] bool itemRemoved(Akonadi::Item::Id id);
0046 
0047     [[nodiscard]] MessageComposer::AkonadiSender *sender() const;
0048 
0049     void sendNow(Akonadi::Item::Id id);
0050 
0051 Q_SIGNALS:
0052     void needUpdateConfigDialogBox();
0053 
0054 public Q_SLOTS:
0055     void load(bool forcereload = false);
0056 
0057 private:
0058     void slotCreateJob();
0059     void createSendInfoList();
0060     [[nodiscard]] QString infoToStr(MessageComposer::SendLaterInfo *info) const;
0061     void removeLaterInfo(MessageComposer::SendLaterInfo *info);
0062     [[nodiscard]] MessageComposer::SendLaterInfo *searchInfo(Akonadi::Item::Id id);
0063     void recreateSendList();
0064     void stopTimer();
0065     void removeInfo(Akonadi::Item::Id id);
0066     KSharedConfig::Ptr mConfig;
0067     QList<MessageComposer::SendLaterInfo *> mListSendLaterInfo;
0068     MessageComposer::SendLaterInfo *mCurrentInfo = nullptr;
0069     SendLaterJob *mCurrentJob = nullptr;
0070     QTimer *const mTimer;
0071     MessageComposer::AkonadiSender *const mSender;
0072     QQueue<Akonadi::Item::Id> mSendLaterQueue;
0073 };