File indexing completed on 2024-12-29 04:54:51

0001 /*
0002   SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #pragma once
0008 #include "ksieveui_export.h"
0009 #include <KSieveCore/SieveImapAccountSettings>
0010 #include <QMap>
0011 #include <QUrl>
0012 #include <QWidget>
0013 #include <memory>
0014 
0015 class QTreeWidgetItem;
0016 
0017 namespace KManageSieve
0018 {
0019 class SieveJob;
0020 }
0021 namespace KSieveCore
0022 {
0023 class ParseUserScriptJob;
0024 }
0025 namespace KSieveUi
0026 {
0027 class ManageSieveTreeView;
0028 class ManageSieveWidgetPrivate;
0029 /**
0030  * @brief The ManageSieveWidget class
0031  * @author Laurent Montel <montel@kde.org>
0032  */
0033 class KSIEVEUI_EXPORT ManageSieveWidget : public QWidget
0034 {
0035     Q_OBJECT
0036 public:
0037     enum SieveEditorMode { NormalEditorMode = 0, Kep14EditorMode };
0038 
0039     struct ScriptInfo {
0040         QUrl currentUrl;
0041         QStringList currentCapabilities;
0042         KSieveCore::SieveImapAccountSettings sieveImapAccountSettings;
0043         QStringList scriptList;
0044     };
0045 
0046     explicit ManageSieveWidget(QWidget *parent = nullptr);
0047     ~ManageSieveWidget() override;
0048 
0049     ManageSieveTreeView *treeView() const;
0050     void enableDisableActions(bool &newScriptAction, bool &editScriptAction, bool &deleteScriptAction, bool &desactivateScriptAction);
0051 
0052 Q_SIGNALS:
0053     void updateButtons(QTreeWidgetItem *item);
0054     void newScript(const KSieveUi::ManageSieveWidget::ScriptInfo &info);
0055     void editScript(const KSieveUi::ManageSieveWidget::ScriptInfo &info);
0056     void scriptDeleted(const QUrl &u);
0057     void serverSieveFound(bool imapFound);
0058     void scriptRenamed(const QUrl &oldUrl, const QUrl &newUrl);
0059     void updateSieveSettingsDone();
0060 
0061 protected:
0062     virtual bool refreshList() = 0;
0063     virtual void updateSieveSettings() = 0;
0064 
0065 private Q_SLOTS:
0066     KSIEVEUI_NO_EXPORT void slotItemChanged(QTreeWidgetItem *item, int col);
0067     KSIEVEUI_NO_EXPORT void slotContextMenuRequested(const QPoint &p);
0068     KSIEVEUI_NO_EXPORT void slotUpdateButtons();
0069     KSIEVEUI_NO_EXPORT void slotDoubleClicked(QTreeWidgetItem *item);
0070     KSIEVEUI_NO_EXPORT void slotSystemNetworkOnlineStateChanged(bool state);
0071     KSIEVEUI_NO_EXPORT void slotCheckNetworkStatus();
0072     KSIEVEUI_NO_EXPORT void setActiveScripts(KSieveCore::ParseUserScriptJob *job);
0073 
0074     KSIEVEUI_NO_EXPORT void slotCancelFetch();
0075     KSIEVEUI_NO_EXPORT void slotRenameResult(KManageSieve::SieveJob *job, bool success);
0076     KSIEVEUI_NO_EXPORT void slotRenameFinished(const QUrl &oldUrl, const QUrl &newUrl, const QString &errorStr, bool success);
0077 
0078 public Q_SLOTS:
0079     void slotRenameScript();
0080     void slotGotList(KManageSieve::SieveJob *job, bool success, const QStringList &listScript, const QString &activeScript);
0081     void slotNewScript();
0082     void slotEditScript();
0083     void slotDeleteScript();
0084     void slotDeactivateScript();
0085     void slotDeleteResult(KManageSieve::SieveJob *job, bool success);
0086     void slotRefresh();
0087 
0088 protected:
0089     QMap<KManageSieve::SieveJob *, QTreeWidgetItem *> mJobs;
0090     QMap<QTreeWidgetItem *, QUrl> mUrls;
0091 
0092 private:
0093     void updateSieveSettingsFinished();
0094     enum sieveServerStatus {
0095         SIEVE_SERVER_ERROR = Qt::UserRole + 1,
0096         SIEVE_SERVER_CAPABILITIES = Qt::UserRole + 2,
0097         SIEVE_SERVER_MODE = Qt::UserRole + 3,
0098         SIEVE_SERVER_IMAP_SETTINGS = Qt::UserRole + 4,
0099         SIEVE_SERVER_LIST_SCRIPT = Qt::UserRole + 5
0100     };
0101     KSIEVEUI_NO_EXPORT bool canAddNewScript(QTreeWidgetItem *item, bool jobsListIsEmpty);
0102     KSIEVEUI_NO_EXPORT bool serverHasError(QTreeWidgetItem *item) const;
0103     KSIEVEUI_NO_EXPORT void killAllJobs();
0104     KSIEVEUI_NO_EXPORT void clear();
0105     [[nodiscard]] KSIEVEUI_NO_EXPORT bool isFileNameItem(QTreeWidgetItem *item) const;
0106     [[nodiscard]] KSIEVEUI_NO_EXPORT bool itemIsActived(QTreeWidgetItem *item) const;
0107     KSIEVEUI_NO_EXPORT void changeActiveScript(QTreeWidgetItem *item, bool activate, bool deleteScript = false);
0108     [[nodiscard]] KSIEVEUI_NO_EXPORT bool updateGlobalScript(QTreeWidgetItem *item, const QUrl &u);
0109     KSIEVEUI_NO_EXPORT void slotGenerateGlobalScriptError(const QString &errorStr);
0110     std::unique_ptr<ManageSieveWidgetPrivate> const d;
0111 };
0112 }