File indexing completed on 2024-04-21 09:27:15

0001 /*
0002  *   SPDX-FileCopyrightText: 2009 Ben Cooksley <bcooksley@kde.org>
0003  *   SPDX-FileCopyrightText: 2009 Mathias Soeken <msoeken@informatik.uni-bremen.de>
0004  *
0005  *   SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #ifndef MODULE_VIEW_H
0009 #define MODULE_VIEW_H
0010 
0011 #include <KAuth/Action>
0012 #include <KPageView>
0013 
0014 #include <QModelIndex>
0015 #include <QWidget>
0016 
0017 #include "systemsettingsview_export.h"
0018 
0019 class KCModule;
0020 class KPageWidgetItem;
0021 class KPluginMetaData;
0022 class MenuItem;
0023 
0024 /**
0025  * @brief Provides a convenient way to display modules
0026  *
0027  * Provides a standardised interface for displaying multiple modules simultaneously
0028  * and provides facilities to access the current module, and to load its help, restore
0029  * default settings, save new settings and revert changes to settings
0030  *
0031  * It also provides checking for when a module has changed its configuration, and will prompt
0032  * if the user tries to change module or view if BaseMode is reimplemented correctly
0033  *
0034  * It also provides signals for active module changes, configuration changes and for when it has
0035  * been requested to close by button press
0036  *
0037  * @author Mathias Soeken <msoeken@informatik.uni-bremen.de>
0038  * @author Ben Cooksley <bcooksley@kde.org>
0039  */
0040 class SYSTEMSETTINGSVIEW_EXPORT ModuleView : public QWidget
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     /**
0046      * Constructs a ModuleView, with the parent specified.
0047      */
0048     explicit ModuleView(QWidget *parent = nullptr);
0049 
0050     /**
0051      * Destroys the module view, along with all modules loaded, and any changes present in them.
0052      *
0053      * @warning The user will not be prompted to save changes if any exist.
0054      */
0055     ~ModuleView() override;
0056 
0057     /**
0058      * Provides the module information, which is used to set the caption of the window when either the
0059      * active module or configuration changes.
0060      */
0061     QString activeModuleName() const;
0062 
0063     /**
0064      * Resolves any changes in the currently active module by prompting the user if they exist.
0065      *
0066      * @returns true if the user saved or discarded changes, or there were no changes at all.
0067      * @returns false if the user canceled the module change.
0068      */
0069     bool resolveChanges();
0070 
0071     /**
0072      * Closes all active modules, after checking there are no active changes.
0073      *
0074      * @warning This forces all modules to be destroyed regardless of if changes exist or not
0075      * If possible, always check with resolveChanges() first.
0076      */
0077     void closeModules();
0078 
0079     void setFaceType(KPageView::FaceType type);
0080 
0081     KPageView::FaceType faceType() const;
0082 
0083     /**
0084      * Sets whether Systemsettings should save statisctics about
0085      * most used modules using KActivities::Stats
0086      */
0087     void setSaveStatistics(bool save);
0088 
0089     /**
0090      * @returns whether Systemsettings should save statisctics about
0091      * most used module
0092      */
0093     bool saveStatistics() const;
0094 
0095     /**
0096      * Shows or hides the Apply button.
0097      */
0098     void setApplyVisible(bool visible);
0099 
0100     /**
0101      * @returns True if the Apply button is visible.
0102      */
0103     bool isApplyVisible() const;
0104 
0105     /**
0106      * Shows or hides the Defaults button.
0107      */
0108     void setDefaultsVisible(bool visible);
0109 
0110     /**
0111      * @returns True if the Defaults button is visible.
0112      */
0113     bool isDefaultsVisible() const;
0114 
0115     /**
0116      * @returns True if the Reset button is visible.
0117      */
0118     bool isResetVisible() const;
0119 
0120     /**
0121      * Show or hide defaults indicators (field level)
0122      */
0123     void moduleShowDefaultsIndicators(bool show);
0124 
0125     qreal headerHeight() const;
0126     void setHeaderHeight(qreal height);
0127 
0128     void setActiveModule(const QString &pluginId);
0129 
0130     void requestActivation(const QVariantList &args);
0131 
0132     /**
0133      * The active module's KPluginMetaData.
0134      */
0135     KPluginMetaData activeModuleMetadata() const;
0136 
0137 public Q_SLOTS:
0138     /**
0139      * Loads the module specified by menuItem.\n
0140      * If the module has children, they will all be loaded instead of the module.
0141      *
0142      * @param menuItem the QModelIndex that you want to load. Must be sourced from either MenuModel or MenuProxyModel
0143      */
0144     void loadModule(const QModelIndex &menuItem, const QStringList &args);
0145 
0146     /**
0147      * Will open KHelpCenter, and load the help for the active module.
0148      */
0149     void moduleHelp();
0150 
0151     /**
0152      * Causes the active module to reload its configuration, reverting all changes.
0153      */
0154     void moduleLoad();
0155 
0156     /**
0157      * Causes the active module to save its configuration, applying all changes.
0158      */
0159     bool moduleSave();
0160 
0161     /**
0162      * Causes the active module to revert all changes to the configuration, and return to defaults.
0163      */
0164     void moduleDefaults();
0165 
0166     /**
0167      * Reimplemented for internal reasons.\n
0168      */
0169     void keyPressEvent(QKeyEvent *event) override;
0170 
0171 private:
0172     bool resolveChanges(KCModule *currentProxy);
0173     void addModule(MenuItem *item, const QStringList &args);
0174     bool moduleSave(KCModule *module);
0175     void updatePageIconHeader(KPageWidgetItem *page);
0176     void updateButtons();
0177 
0178 private Q_SLOTS:
0179     void activeModuleChanged(KPageWidgetItem *current, KPageWidgetItem *previous);
0180     void stateChanged();
0181     void authStatusChanged(KAuth::Action::AuthStatus status);
0182 
0183 Q_SIGNALS:
0184     /**
0185      * Emitted when the currently active module is changed. This occurs whenever the active module or
0186      * its configuration changes. This causes the window caption to update.
0187      */
0188     void moduleChanged(bool state);
0189 
0190     /**
0191      * Emitted after the currently active module was saved.
0192      */
0193     void moduleSaved();
0194 
0195     /**
0196      * Emitted when the ModuleView is asked to close.\n
0197      */
0198     void closeRequest();
0199 
0200     /**
0201      * Emitted when showDefaultsIndicators state changed
0202      */
0203     void showDefaultsIndicatorsChanged(bool show);
0204 
0205 private:
0206     class Private;
0207     Private *const d;
0208 };
0209 
0210 #endif