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

0001 /*
0002   SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #pragma once
0009 #include "ksieveui_export.h"
0010 
0011 #include <QWidget>
0012 class QStackedWidget;
0013 class QLineEdit;
0014 class QAction;
0015 namespace KSieveCore
0016 {
0017 class SieveImapAccountSettings;
0018 }
0019 namespace KSieveUi
0020 {
0021 class SieveEditorTextModeWidget;
0022 class SieveEditorGraphicalModeWidget;
0023 /**
0024  * @brief The SieveEditorWidget class
0025  * @author Laurent Montel <montel@kde.org>
0026  */
0027 class KSIEVEUI_EXPORT SieveEditorWidget : public QWidget
0028 {
0029     Q_OBJECT
0030 public:
0031     explicit SieveEditorWidget(bool useMenuBar, QWidget *parent = nullptr);
0032     ~SieveEditorWidget() override;
0033     enum EditorMode { Unknown = -1, TextMode = 0, GraphicMode = 1 };
0034 
0035     void setReadOnly(bool b);
0036     [[nodiscard]] QString script() const;
0037     [[nodiscard]] QString originalScript() const;
0038     void setScript(const QString &script, bool clearUndoRedo = false);
0039     void setDebugScript(const QString &debug);
0040     void setScriptName(const QString &name);
0041 
0042     void resultDone();
0043 
0044     void setSieveCapabilities(const QStringList &capabilities);
0045     void setSieveImapAccountSettings(const KSieveCore::SieveImapAccountSettings &sieveImapAccountSettings);
0046     void setListOfIncludeFile(const QStringList &listOfIncludeFile);
0047 
0048     void addFailedMessage(const QString &err);
0049     void addOkMessage(const QString &msg);
0050     void addNormalMessage(const QString &msg);
0051 
0052     void setModified(bool b);
0053     [[nodiscard]] bool isModified() const;
0054 
0055     [[nodiscard]] EditorMode mode() const;
0056 
0057     [[nodiscard]] bool isRedoAvailable() const;
0058     [[nodiscard]] bool isUndoAvailable() const;
0059     [[nodiscard]] bool hasSelection() const;
0060 
0061     void checkSpelling();
0062     void import();
0063     void lowerCase();
0064     void upperCase();
0065     void sentenceCase();
0066     void reverseCase();
0067     void zoomOut();
0068     void zoomIn();
0069     [[nodiscard]] QString currentHelpTitle() const;
0070     [[nodiscard]] QUrl currentHelpUrl() const;
0071     void openBookmarkUrl(const QUrl &url);
0072     void debugSieveScript();
0073     void zoomReset();
0074     bool isWordWrap() const;
0075 
0076     void updateOriginalScript();
0077     void print();
0078     void printPreview();
0079 
0080     bool printSupportEnabled() const;
0081     bool isTextEditor() const;
0082 public Q_SLOTS:
0083     void find();
0084     void replace();
0085     void undo();
0086     void redo();
0087     void paste();
0088     void copy();
0089     void cut();
0090     void selectAll();
0091     void goToLine();
0092     void slotSaveAs();
0093     void slotImport();
0094     void slotCreateRulesGraphically();
0095     void slotCheckSyntax();
0096     void comment();
0097     void uncomment();
0098     void setWordWrap(bool state);
0099 
0100 Q_SIGNALS:
0101     void checkSyntax();
0102     void enableButtonOk(bool b);
0103     void valueChanged(bool b);
0104     void modeEditorChanged(KSieveUi::SieveEditorWidget::EditorMode);
0105     void undoAvailable(bool);
0106     void redoAvailable(bool);
0107     void copyAvailable(bool);
0108     void changeModeEditor(bool);
0109     void sieveEditorTabCurrentChanged();
0110 
0111 private:
0112     KSIEVEUI_NO_EXPORT void slotEnableButtonOk(bool b);
0113     KSIEVEUI_NO_EXPORT void slotGenerateXml();
0114     KSIEVEUI_NO_EXPORT void slotSwitchMode();
0115     KSIEVEUI_NO_EXPORT void slotSwitchTextMode(const QString &script);
0116     KSIEVEUI_NO_EXPORT void slotSwitchToGraphicalMode();
0117     KSIEVEUI_NO_EXPORT void slotModified();
0118     KSIEVEUI_NO_EXPORT void changeSwitchButtonText();
0119     KSIEVEUI_NO_EXPORT void changeMode(EditorMode mode);
0120     KSIEVEUI_NO_EXPORT void addMessageEntry(const QString &errorMsg, const QColor &color);
0121     KSIEVEUI_NO_EXPORT void slotServerInfo();
0122     QString mOriginalScript;
0123     SieveEditorTextModeWidget *mTextModeWidget = nullptr;
0124     SieveEditorGraphicalModeWidget *mGraphicalModeWidget = nullptr;
0125     QStackedWidget *mStackedWidget = nullptr;
0126     QLineEdit *mScriptName = nullptr;
0127     QAction *mCheckSyntax = nullptr;
0128     QAction *mSwitchMode = nullptr;
0129     QAction *mCreateRulesGraphically = nullptr;
0130     QAction *mSaveAs = nullptr;
0131     QAction *mGenerateXml = nullptr;
0132     QAction *mServerInfo = nullptr;
0133     EditorMode mMode = EditorMode::TextMode;
0134     bool mModified = false;
0135     bool mDebug = false;
0136 };
0137 }