File indexing completed on 2022-09-27 16:29:26

0001 /**
0002  * SPDX-FileCopyrightText: (C) 2003 Sébastien Laoût <slaout@linux62.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef SETTINGS_H
0008 #define SETTINGS_H
0009 
0010 #include <KCModule>
0011 #include <KMainWindow> //For Global::mainWindow()
0012 #include <KCMultiDialog>
0013 
0014 #include <QAction> //For UseSysTray
0015 #include <QtCore/QDate>
0016 
0017 #include "basket_export.h"
0018 #include "bnpview.h"
0019 
0020 class KComboBox;
0021 
0022 class QString;
0023 class QCheckBox;
0024 class QPushButton;
0025 class QPoint;
0026 class QSize;
0027 class QSpinBox;
0028 
0029 class LinkLook;
0030 class LinkLookEditWidget;
0031 class RunCommandRequester;
0032 
0033 class BASKET_EXPORT GeneralPage : public KCModule
0034 {
0035     Q_OBJECT
0036 public:
0037     explicit GeneralPage(QWidget *parent = nullptr, const QVariantList &args = {});
0038     ~GeneralPage() override
0039     {
0040     }
0041 
0042     void load() override;
0043     void save() override;
0044     void defaults() override;
0045 
0046 private:
0047     // General
0048     KComboBox *m_treeOnLeft;
0049     KComboBox *m_filterOnTop;
0050 };
0051 
0052 class BASKET_EXPORT BasketsPage : public KCModule
0053 {
0054     Q_OBJECT
0055 public:
0056     explicit BasketsPage(QWidget *parent = nullptr, const QVariantList &args = {});
0057 
0058     void load() override;
0059     void save() override;
0060     void defaults() override;
0061 
0062 private:
0063     // Appearance
0064     QCheckBox *m_playAnimations;
0065     QCheckBox *m_showNotesToolTip;
0066     QCheckBox *m_bigNotes;
0067 
0068     // Behavior
0069     QCheckBox *m_autoBullet;
0070     QCheckBox *m_confirmNoteDeletion;
0071     QCheckBox *m_exportTextTags;
0072     QCheckBox *m_detectTextTags;
0073     QWidget *m_groupOnInsertionLineWidget;
0074     QCheckBox *m_groupOnInsertionLine;
0075     KComboBox *m_middleAction;
0076     QCheckBox *m_pasteAsPlainText;
0077 
0078     // Protection
0079     QCheckBox *m_useGnuPGAgent;
0080     QCheckBox *m_enableReLockTimeoutMinutes;
0081     QSpinBox *m_reLockTimeoutMinutes;
0082 };
0083 
0084 class BASKET_EXPORT NewNotesPage : public KCModule
0085 {
0086     Q_OBJECT
0087 public:
0088     explicit NewNotesPage(QWidget *parent = nullptr, const QVariantList &args = {});
0089 
0090     void load() override;
0091     void save() override;
0092     void defaults() override;
0093 
0094 private Q_SLOTS:
0095     void visualize();
0096 
0097 private:
0098     // Notes Image Size
0099     QSpinBox *m_imgSizeX;
0100     QSpinBox *m_imgSizeY;
0101     QPushButton *m_pushVisualize;
0102 
0103     // Note Addition
0104     KComboBox *m_newNotesPlace;
0105     QCheckBox *m_viewTextFileContent;
0106     QCheckBox *m_viewHtmlFileContent;
0107     QCheckBox *m_viewImageFileContent;
0108     QCheckBox *m_viewSoundFileContent;
0109 };
0110 
0111 class BASKET_EXPORT NotesAppearancePage : public KCModule
0112 {
0113     Q_OBJECT
0114 public:
0115     explicit NotesAppearancePage(QWidget *parent = nullptr, const QVariantList &args = {});
0116 
0117     void load() override;
0118     void save() override;
0119     void defaults() override;
0120 
0121 private:
0122     // Link Looks
0123     LinkLookEditWidget *m_soundLook;
0124     LinkLookEditWidget *m_fileLook;
0125     LinkLookEditWidget *m_localLinkLook;
0126     LinkLookEditWidget *m_networkLinkLook;
0127     LinkLookEditWidget *m_launcherLook;
0128     LinkLookEditWidget *m_crossReferenceLook;
0129 };
0130 
0131 class BASKET_EXPORT ApplicationsPage : public KCModule
0132 {
0133     Q_OBJECT
0134 public:
0135     explicit ApplicationsPage(QWidget *parent = nullptr, const QVariantList &args = {});
0136 
0137     void load() override;
0138     void save() override;
0139     void defaults() override;
0140 
0141 private:
0142     // Applications
0143     QCheckBox *m_htmlUseProg;
0144     QCheckBox *m_imageUseProg;
0145     QCheckBox *m_animationUseProg;
0146     QCheckBox *m_soundUseProg;
0147     RunCommandRequester *m_htmlProg;
0148     RunCommandRequester *m_imageProg;
0149     RunCommandRequester *m_animationProg;
0150     RunCommandRequester *m_soundProg;
0151 };
0152 
0153 /**
0154  * KSettings::Dialog wrapper to properly calculate appropriate window size
0155  */
0156 class BASKET_EXPORT SettingsDialog : public KCMultiDialog
0157 {
0158     Q_OBJECT
0159 public:
0160     explicit SettingsDialog(QWidget *parent = nullptr);
0161     ~SettingsDialog() override;
0162     virtual int exec() override;
0163 
0164 private Q_SLOTS:
0165     void adjustSize();
0166 };
0167 
0168 /** Handle all global variables (to avoid lot of extern declarations)
0169  * @author Sébastien Laoût
0170  */
0171 class BASKET_EXPORT Settings // FIXME: Dispatch new config events ?
0172 {
0173 protected:
0174     /** Main window */
0175     static bool s_treeOnLeft;
0176     static bool s_filterOnTop;
0177     static bool s_showNotesToolTip;
0178     static bool s_confirmNoteDeletion;
0179     static bool s_bigNotes;
0180     static bool s_autoBullet;
0181     static bool s_pasteAsPlainText;
0182     static bool s_exportTextTags;
0183     static bool s_detectTextTags;
0184     static bool s_useGnuPGAgent;
0185     static int s_middleAction; // O:Nothing ; 1:Paste ; 2:Text ; 3:Html ; 4:Image ; 5:Link ; 6:Launcher ; 7:Color
0186     static bool s_groupOnInsertionLine;
0187     static bool s_spellCheckTextNotes;
0188     static int s_basketTreeWidth;
0189     static bool s_welcomeBasketsAdded;
0190     static QString s_dataFolder;
0191     static QDate s_lastBackup;
0192     static QPoint s_mainWindowPosition;
0193     static QSize s_mainWindowSize;
0194     static bool s_showEmptyBasketInfo;
0195     static bool s_blinkedFilter;
0196     static bool s_enableReLockTimeout;
0197     static int s_reLockTimeoutMinutes;
0198     /** Note Addition */
0199     static int s_newNotesPlace; // 0:OnTop ; 1:OnBottom ; 2:AtCurrentNote
0200     static int s_viewTextFileContent;
0201     static int s_viewHtmlFileContent;
0202     static int s_viewImageFileContent;
0203     static int s_viewSoundFileContent;
0204     /** Programs */
0205     static bool s_htmlUseProg;
0206     static bool s_imageUseProg;
0207     static bool s_animationUseProg;
0208     static bool s_soundUseProg;
0209     static QString s_htmlProg;
0210     static QString s_imageProg;
0211     static QString s_animationProg;
0212     static QString s_soundProg;
0213     /** Insert Note Default Values */
0214     static int s_defImageX;
0215     static int s_defImageY;
0216     static int s_defIconSize;
0217     /** Version Sync */
0218     static bool s_versionSyncEnabled;
0219 
0220 public: /* And the following methods are just getter / setters */
0221     /** App settings GET */
0222     static inline bool treeOnLeft()
0223     {
0224         return s_treeOnLeft;
0225     }
0226     static inline bool filterOnTop()
0227     {
0228         return s_filterOnTop;
0229     }
0230     static inline bool showNotesToolTip()
0231     {
0232         return s_showNotesToolTip;
0233     }
0234     static inline bool confirmNoteDeletion()
0235     {
0236         return s_confirmNoteDeletion;
0237     }
0238     static inline bool bigNotes()
0239     {
0240         return s_bigNotes;
0241     }
0242     static inline bool autoBullet()
0243     {
0244         return s_autoBullet;
0245     }
0246     static inline bool pasteAsPlainText()
0247     {
0248         return s_pasteAsPlainText;
0249     }
0250     static inline bool exportTextTags()
0251     {
0252         return s_exportTextTags;
0253     }
0254     static inline bool detectTextTags()
0255     {
0256         return s_detectTextTags;
0257     }
0258     static inline bool useGnuPGAgent()
0259     {
0260         return s_useGnuPGAgent;
0261     }
0262     static inline bool blinkedFilter()
0263     {
0264         return s_blinkedFilter;
0265     }
0266     static inline bool enableReLockTimeout()
0267     {
0268         return s_enableReLockTimeout;
0269     }
0270     static inline int reLockTimeoutMinutes()
0271     {
0272         return s_reLockTimeoutMinutes;
0273     }
0274     static inline int middleAction()
0275     {
0276         return s_middleAction;
0277     }
0278     static inline bool groupOnInsertionLine()
0279     {
0280         return s_groupOnInsertionLine;
0281     }
0282     static inline bool spellCheckTextNotes()
0283     {
0284         return s_spellCheckTextNotes;
0285     }
0286     static inline int basketTreeWidth()
0287     {
0288         return s_basketTreeWidth;
0289     }
0290     static inline int dropTimeToShow()
0291     {
0292         return 7;
0293     } // TODO: 700 ; TODO: There is certainly a KGlobalConfig ???
0294     static inline bool welcomeBasketsAdded()
0295     {
0296         return s_welcomeBasketsAdded;
0297     }
0298     static inline QString dataFolder()
0299     {
0300         return s_dataFolder;
0301     }
0302     static inline QDate lastBackup()
0303     {
0304         return s_lastBackup;
0305     }
0306     static inline QPoint mainWindowPosition()
0307     {
0308         return s_mainWindowPosition;
0309     }
0310     static inline QSize mainWindowSize()
0311     {
0312         return s_mainWindowSize;
0313     }
0314     static inline bool showEmptyBasketInfo()
0315     {
0316         return s_showEmptyBasketInfo;
0317     }
0318     /** Programs */
0319     static inline bool isHtmlUseProg()
0320     {
0321         return s_htmlUseProg;
0322     }
0323     static inline bool isImageUseProg()
0324     {
0325         return s_imageUseProg;
0326     }
0327     static inline bool isAnimationUseProg()
0328     {
0329         return s_animationUseProg;
0330     }
0331     static inline bool isSoundUseProg()
0332     {
0333         return s_soundUseProg;
0334     }
0335     static inline QString htmlProg()
0336     {
0337         return s_htmlProg;
0338     }
0339     static inline QString imageProg()
0340     {
0341         return s_imageProg;
0342     }
0343     static inline QString animationProg()
0344     {
0345         return s_animationProg;
0346     }
0347     static inline QString soundProg()
0348     {
0349         return s_soundProg;
0350     }
0351     /** Insert Note Default Values */
0352     static inline int defImageX()
0353     {
0354         return s_defImageX;
0355     }
0356     static inline int defImageY()
0357     {
0358         return s_defImageY;
0359     }
0360     static inline int defIconSize()
0361     {
0362         return s_defIconSize;
0363     }
0364     /** Note Addition */
0365     static inline int newNotesPlace()
0366     {
0367         return s_newNotesPlace;
0368     }
0369     static inline int viewTextFileContent()
0370     {
0371         return s_viewTextFileContent;
0372     }
0373     static inline int viewHtmlFileContent()
0374     {
0375         return s_viewHtmlFileContent;
0376     }
0377     static inline int viewImageFileContent()
0378     {
0379         return s_viewImageFileContent;
0380     }
0381     static inline int viewSoundFileContent()
0382     {
0383         return s_viewSoundFileContent;
0384     }
0385     /** Version Sync */
0386     static inline bool versionSyncEnabled()
0387     {
0388         return s_versionSyncEnabled;
0389     }
0390 
0391     /** App settings SET */
0392     static void setTreeOnLeft(bool onLeft)
0393     {
0394         s_treeOnLeft = onLeft;
0395         if (Global::bnpView)
0396             Global::bnpView->setTreePlacement(onLeft);
0397     }
0398     static void setFilterOnTop(bool onTop)
0399     {
0400         if (s_filterOnTop != onTop) {
0401             s_filterOnTop = onTop;
0402             if (Global::bnpView)
0403                 Global::bnpView->filterPlacementChanged(onTop);
0404         }
0405     }
0406     static void setShowNotesToolTip(bool show)
0407     {
0408         s_showNotesToolTip = show;
0409     }
0410     static inline void setConfirmNoteDeletion(bool confirm)
0411     {
0412         s_confirmNoteDeletion = confirm;
0413     }
0414     static inline void setPasteAsPlainText(bool yes)
0415     {
0416         s_pasteAsPlainText = yes;
0417     }
0418     static void setBigNotes(bool big);
0419     static void setAutoBullet(bool yes);
0420     static inline void setExportTextTags(bool yes)
0421     {
0422         s_exportTextTags = yes;
0423     }
0424     static inline void setDetectTextTags(bool yes)
0425     {
0426         s_detectTextTags = yes;
0427     }
0428     static inline void setUseGnuPGAgent(bool yes)
0429     {
0430         s_useGnuPGAgent = yes;
0431     }
0432     static inline void setBlinkedFilter(bool blinked)
0433     {
0434         s_blinkedFilter = blinked;
0435     }
0436     static inline void setEnableReLockTimeout(bool yes)
0437     {
0438         s_enableReLockTimeout = yes;
0439     }
0440     static inline void setReLockTimeoutMinutes(int minutes)
0441     {
0442         s_reLockTimeoutMinutes = minutes;
0443     }
0444     static inline void setMiddleAction(int action)
0445     {
0446         s_middleAction = action;
0447     }
0448     static inline void setGroupOnInsertionLine(bool yes)
0449     {
0450         s_groupOnInsertionLine = yes;
0451     }
0452     static inline void setSpellCheckTextNotes(bool yes)
0453     {
0454         s_spellCheckTextNotes = yes;
0455     }
0456     static inline void setBasketTreeWidth(int width)
0457     {
0458         s_basketTreeWidth = width;
0459     }
0460     static inline void setWelcomeBasketsAdded(bool added)
0461     {
0462         s_welcomeBasketsAdded = added;
0463     }
0464     static inline void setDataFolder(const QString &folder)
0465     {
0466         s_dataFolder = folder;
0467     }
0468     static inline void setLastBackup(const QDate &date)
0469     {
0470         s_lastBackup = date;
0471     }
0472     static inline void setMainWindowPosition(const QPoint &pos)
0473     {
0474         s_mainWindowPosition = pos;
0475     }
0476     static inline void setMainWindowSize(const QSize &size)
0477     {
0478         s_mainWindowSize = size;
0479     }
0480     static inline void setShowEmptyBasketInfo(bool show)
0481     {
0482         s_showEmptyBasketInfo = show;
0483     }
0484     // Programs :
0485     static inline void setIsHtmlUseProg(bool useProg)
0486     {
0487         s_htmlUseProg = useProg;
0488     }
0489     static inline void setIsImageUseProg(bool useProg)
0490     {
0491         s_imageUseProg = useProg;
0492     }
0493     static inline void setIsAnimationUseProg(bool useProg)
0494     {
0495         s_animationUseProg = useProg;
0496     }
0497     static inline void setIsSoundUseProg(bool useProg)
0498     {
0499         s_soundUseProg = useProg;
0500     }
0501     static inline void setHtmlProg(const QString &prog)
0502     {
0503         s_htmlProg = prog;
0504     }
0505     static inline void setImageProg(const QString &prog)
0506     {
0507         s_imageProg = prog;
0508     }
0509     static inline void setAnimationProg(const QString &prog)
0510     {
0511         s_animationProg = prog;
0512     }
0513     static inline void setSoundProg(const QString &prog)
0514     {
0515         s_soundProg = prog;
0516     }
0517     // Insert Note Default Values :
0518     static inline void setDefImageX(int val)
0519     {
0520         s_defImageX = val;
0521     }
0522     static inline void setDefImageY(int val)
0523     {
0524         s_defImageY = val;
0525     }
0526     static inline void setDefIconSize(int val)
0527     {
0528         s_defIconSize = val;
0529     }
0530     // Note Addition
0531     static inline void setNewNotesPlace(int val)
0532     {
0533         s_newNotesPlace = val;
0534     }
0535     static inline void setViewTextFileContent(bool view)
0536     {
0537         s_viewTextFileContent = view;
0538     }
0539     static inline void setViewHtmlFileContent(bool view)
0540     {
0541         s_viewHtmlFileContent = view;
0542     }
0543     static inline void setViewImageFileContent(bool view)
0544     {
0545         s_viewImageFileContent = view;
0546     }
0547     static inline void setViewSoundFileContent(bool view)
0548     {
0549         s_viewSoundFileContent = view;
0550     }
0551     // Version Sync
0552     static inline void setVersionSyncEnabled(bool enable)
0553     {
0554         s_versionSyncEnabled = enable;
0555     }
0556 
0557 public:
0558     /* Save and load config */
0559     static void loadConfig();
0560     static void saveConfig();
0561 
0562 protected:
0563     static void loadLinkLook(LinkLook *look, const QString &name, const LinkLook &defaultLook);
0564     static void saveLinkLook(LinkLook *look, const QString &name);
0565 };
0566 
0567 #endif // SETTINGS_H