Warning, file /frameworks/kdeclarative/src/quickaddons/managedconfigmodule.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2019 Kevin Ottens <kevin.ottens@enioka.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef MANAGEDCONFIGMODULE_H 0009 #define MANAGEDCONFIGMODULE_H 0010 0011 #include <KQuickAddons/ConfigModule> 0012 0013 class KCoreConfigSkeleton; 0014 0015 namespace KQuickAddons 0016 { 0017 class ManagedConfigModulePrivate; 0018 0019 /** 0020 * @class KQuickAddons::ManagedConfigModule managedconfigmodule.h KQuickAddons/ManagedConfigModule 0021 * 0022 * The base class for configuration modules using KConfigXT settings. 0023 * 0024 * Configuration modules are realized as plugins that are loaded only when 0025 * needed. 0026 * 0027 * The module in principle is a simple widget displaying the 0028 * item to be changed. The module has a very small interface. 0029 * 0030 * All the necessary glue logic and the GUI bells and whistles 0031 * are provided by the control center and must not concern 0032 * the module author. 0033 * 0034 * To write a config module, you have to create a C++ library 0035 * and an accompaning QML user interface. 0036 * The library must contain a factory function like the following: 0037 * 0038 * \code 0039 * #include <KPluginFactory> 0040 * 0041 * K_PLUGIN_CLASS_WITH_JSON(MyConfigModule, "myconfigmodule.json") 0042 * \endcode 0043 * 0044 * The constructor of the ManagedConfigModule then looks like this: 0045 * \code 0046 * MyConfigModule::MyConfigModule(QObject* parent, const KPluginMetaData &metaData, const QVariantList &args) 0047 * : ManagedConfigModule(parent, metaData, args) 0048 * { 0049 * . 0050 * . 0051 * . 0052 * } 0053 * \endcode 0054 * 0055 * The QML part must be in the KPackage format, installed under share/kpackage/kcms. 0056 * @see KPackage::Package 0057 * 0058 * The package must have the same name as the C++ plugin, to be installed 0059 * by CMake with the command: 0060 * \code 0061 * kpackage_install_package(packagedir kcm_componentName kcms) 0062 * \endcode 0063 * The "packagedir" is the subdirectory in the source tree where the package sources are 0064 * located, and "kcm_componentName" is the name of the C++ plugin. Finally "kcms" is the literal string "kcms", 0065 * so that the package is 0066 * installed as a configuration module (and not some other kind of package). 0067 * The main config dialog UI will be the file 0068 * ui/main.qml from the package (or what X-KPackage-MainScript value is in the 0069 * package metadata desktop file). 0070 * 0071 * The QML part can access all the properties of ConfigModule (together with the properties 0072 * defined in its subclass) by accessing to the global object "kcm", or with the 0073 * import of "org.kde.kcm 1.0" the ConfigModule attached property. 0074 * 0075 * \code 0076 * import QtQuick 2.1 0077 * import QtQuick.Controls 1.0 as QtControls 0078 * import org.kde.kcm 1.0 0079 * import org.kde.plasma.core 2.0 as PlasmaCore 0080 * 0081 * Item { 0082 * //implicitWidth and implicitHeight will be used as initial size 0083 * //when loaded in kcmshell5 0084 * implicitWidth: units.gridUnit * 20 0085 * implicitHeight: units.gridUnit * 20 0086 * 0087 * ConfigModule.buttons: ConfigModule.Help|ConfigModule.Apply 0088 * Label { 0089 * text: kcm.needsSave 0090 * } 0091 * } 0092 * \endcode 0093 * 0094 * See https://develop.kde.org/docs/extend/kcm/ 0095 * for more detailed documentation. 0096 * 0097 * @since 5.65 0098 */ 0099 class QUICKADDONS_EXPORT ManagedConfigModule : public ConfigModule 0100 { 0101 Q_OBJECT 0102 public: 0103 #if QUICKADDONS_ENABLE_DEPRECATED_SINCE(5, 88) 0104 /** 0105 * Base class for all modules which manage automatically some of their state. 0106 * 0107 * @param aboutData becomes owned by the ManagedConfigModule 0108 * @deprecated since 5.88, use ManagedConfigModule(QObject*, KPluginMetaData, QVariantList) 0109 */ 0110 QUICKADDONS_DEPRECATED_VERSION(5, 88, "Use ManagedConfigModule(QObject*, KPluginMetaData, QVariantList)") 0111 explicit ManagedConfigModule(const KAboutData *aboutData, QObject *parent = nullptr, const QVariantList &args = QVariantList()); 0112 #endif 0113 0114 #if QUICKADDONS_ENABLE_DEPRECATED_SINCE(5, 88) 0115 /** 0116 * @param metaData description for the plugin: it will generate a KAboutData from that 0117 * @deprecated since 5.88, use ManagedConfigModule(QObject*, KPluginMetaData, QVariantList) 0118 */ 0119 QUICKADDONS_DEPRECATED_VERSION(5, 88, "Use ManagedConfigModule(QObject*, KPluginMetaData, QVariantList)") 0120 explicit ManagedConfigModule(const KPluginMetaData &metaData, QObject *parent = nullptr, const QVariantList &args = QVariantList()); 0121 #endif 0122 0123 /** 0124 * Base class for all KControlModules. 0125 * 0126 * @note do not emit changed signals here, since they are not yet connected 0127 * to any slot. 0128 * @since 5.88 0129 */ 0130 explicit ManagedConfigModule(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args = QVariantList()); 0131 0132 #if QUICKADDONS_ENABLE_DEPRECATED_SINCE(5, 104) 0133 /** 0134 * Base class for all KControlModules. 0135 * 0136 * @note do not emit changed signals here, since they are not yet connected 0137 * to any slot. 0138 * 0139 * @deprecated since 5.104, use ManagedConfigModule(QObject*, KPluginMetaData, QVariantList) 0140 */ 0141 QUICKADDONS_DEPRECATED_VERSION(5, 104, "Use ManagedConfigModule(QObject*, KPluginMetaData, QVariantList)") 0142 explicit ManagedConfigModule(QObject *parent = nullptr, const QVariantList &args = QVariantList()); 0143 #endif 0144 0145 /** 0146 * Destroys the module. 0147 */ 0148 ~ManagedConfigModule() override; 0149 0150 public Q_SLOTS: 0151 /** 0152 * Load the configuration data into the module. 0153 * 0154 * This method is invoked whenever the module should read its configuration 0155 * (most of the times from a config file) and update the user interface. 0156 * This happens when the user clicks the "Reset" button in the control 0157 * center, to undo all of his changes and restore the currently valid 0158 * settings. It is also called right after construction. 0159 * 0160 * By default this will load the settings from the child setting objects 0161 * of this module. 0162 */ 0163 void load() override; 0164 0165 /** 0166 * Save the configuration data. 0167 * 0168 * The save method stores the config information as shown 0169 * in the user interface in the config files. 0170 * It is called when the user clicks "Apply" or "Ok". 0171 * 0172 * By default this will save the child setting objects 0173 * of this module. 0174 */ 0175 void save() override; 0176 0177 /** 0178 * Sets the configuration to sensible default values. 0179 * 0180 * This method is called when the user clicks the "Default" 0181 * button. It should set the display to useful values. 0182 * 0183 * By default this will reset to defaults the child setting objects 0184 * of this module. 0185 */ 0186 void defaults() override; 0187 0188 protected Q_SLOTS: 0189 /** 0190 * Forces the module to reevaluate the saveNeeded and 0191 * representsDefault state. 0192 * 0193 * This is required for some modules which might have 0194 * some settings managed outside of KConfigXT objects. 0195 */ 0196 void settingsChanged(); 0197 0198 /** 0199 * Allow to register manually settings class generated from a kcfg file. 0200 * Used by derived class when automatic discovery is not possible. 0201 * After skeleton is registered it will automatically call settingsChanged(). 0202 * 0203 * @since 5.67 0204 */ 0205 void registerSettings(KCoreConfigSkeleton *skeleton); 0206 0207 private: 0208 /** 0209 * Allows to indicate if the module requires saving. 0210 * 0211 * By default this returns false, it needs to be overridden only 0212 * if the module has state outside of the settings declared in 0213 * the KConfigXT classes it uses. 0214 */ 0215 virtual bool isSaveNeeded() const; 0216 0217 /** 0218 * Allows to indicate if the module state is representing its defaults. 0219 * 0220 * By default this returns true, it needs to be overridden only 0221 * if the module has state outside of the settings declared in 0222 * the KConfigXT classes it uses. 0223 */ 0224 virtual bool isDefaults() const; 0225 0226 Q_PRIVATE_SLOT(d, void _k_registerSettings()) 0227 ManagedConfigModulePrivate *const d; 0228 friend class ManagedConfigModulePrivate; 0229 }; 0230 0231 } 0232 0233 #endif // MANAGEDCONFIGMODULE_H