File indexing completed on 2024-05-12 05:25:41

0001 /*
0002    SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 #include <KSieveUi/ManageSieveWidget>
0009 #include <KSieveUi/SieveEditorWidget>
0010 #include <QUrl>
0011 #include <QWidget>
0012 namespace KManageSieve
0013 {
0014 class SieveJob;
0015 }
0016 namespace KSieveUi
0017 {
0018 class SieveEditorWidget;
0019 }
0020 
0021 class SieveEditorPageWidget : public QWidget
0022 {
0023     Q_OBJECT
0024 public:
0025     explicit SieveEditorPageWidget(QWidget *parent = nullptr);
0026     ~SieveEditorPageWidget() override;
0027 
0028     void loadScript(const KSieveUi::ManageSieveWidget::ScriptInfo &info);
0029     [[nodiscard]] QUrl currentUrl() const;
0030     void setCurrentUrl(const QUrl &url);
0031     void setIsNewScript(bool isNewScript);
0032     void uploadScript(bool showInformation = true, bool forceSave = false);
0033     [[nodiscard]] bool needToSaveScript();
0034 
0035     [[nodiscard]] bool isModified() const;
0036     void goToLine();
0037     [[nodiscard]] KSieveUi::SieveEditorWidget::EditorMode pageMode() const;
0038 
0039     void find();
0040     void replace();
0041     void redo();
0042     void undo();
0043     [[nodiscard]] bool isUndoAvailable() const;
0044     [[nodiscard]] bool isRedoAvailable() const;
0045     void paste();
0046     void cut();
0047     void copy();
0048     [[nodiscard]] bool hasSelection() const;
0049 
0050     void selectAll();
0051     void saveAs();
0052     void checkSpelling();
0053     void import();
0054     void createRulesGraphically();
0055     void checkSyntax();
0056     void comment();
0057     void uncomment();
0058     void lowerCase();
0059     void upperCase();
0060     void sentenceCase();
0061     void reverseCase();
0062     void zoomIn();
0063     void zoomOut();
0064     [[nodiscard]] QString currentText() const;
0065     [[nodiscard]] QString currentHelpTitle() const;
0066     [[nodiscard]] QUrl currentHelpUrl() const;
0067     void openBookmarkUrl(const QUrl &url);
0068     void debugSieveScript();
0069     void zoomReset();
0070     void setWordWrap(bool state);
0071     [[nodiscard]] bool isWordWrap() const;
0072     void print();
0073     void printPreview();
0074     bool printSupportEnabled() const;
0075     bool isTextEditor() const;
0076     void renameScriptName(const QString &newName);
0077     [[nodiscard]] bool uploadScriptAndCloseTab(int index);
0078 Q_SIGNALS:
0079     void refreshList();
0080     void scriptModified(bool, SieveEditorPageWidget *);
0081     void modeEditorChanged(KSieveUi::SieveEditorWidget::EditorMode);
0082     void undoAvailable(bool);
0083     void redoAvailable(bool);
0084     void copyAvailable(bool);
0085     void sieveEditorTabCurrentChanged();
0086     void requestCloseTab(int index);
0087 
0088 private:
0089     void slotGetResult(KManageSieve::SieveJob *, bool success, const QString &script, bool isActive);
0090     void slotCheckSyntaxClicked();
0091     void slotPutResult(KManageSieve::SieveJob *, bool success);
0092     void slotValueChanged(bool b);
0093     void slotCheckScriptJobFinished(const QString &errorMsg, bool success);
0094 
0095 private:
0096     void setModified(bool b);
0097     QUrl mCurrentURL;
0098     KSieveUi::SieveEditorWidget *mSieveEditorWidget = nullptr;
0099     bool mWasActive = false;
0100     bool mIsNewScript = false;
0101 };