File indexing completed on 2024-04-21 14:53:50

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2004 Frans Englich <frans.englich@telia.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KCMODULECONTAINER_H
0009 #define KCMODULECONTAINER_H
0010 
0011 #include <QString>
0012 #include <QStringList>
0013 
0014 #include <KCModule>
0015 #include <kcmutils_export.h>
0016 
0017 class QWidget;
0018 
0019 class KCModuleProxy;
0020 
0021 #if KCMUTILS_ENABLE_DEPRECATED_SINCE(5, 66)
0022 /**
0023  * @brief KCModuleContainer is a convenience class encapsulating several KCModules.
0024  *
0025  * The KCModuleContainer class is a convenience class for organizing a multiple set
0026  * of KCModule. KCModuleContainer is a sub class of KCModule and builds an interface mainly
0027  * consisting of a tab widget where each tab contains one of the modules specified via one of the
0028  * constructors. KCModuleContainer can handle modules which requires root permissions. What you
0029  * most likely want is the KCMODULECONTAINER macro. \n
0030  * Sometimes it is of interest to detect in runtime whether a module should be loaded or not. This
0031  * can be achieved by sub classing KCModuleContainer, doing the probing/testing checks and then manually
0032  * call addModule for each module which should be displayed. When all calls to addModule is done, call
0033  * finalize() which performs some necessary final steps.
0034  *
0035  * @deprecated since 5.66, no known users.
0036  *
0037  * @author Frans Englich <frans.englich@telia.com>
0038  */
0039 class KCMUTILS_EXPORT KCModuleContainer : public KCModule
0040 {
0041     Q_OBJECT
0042 public:
0043     /**
0044      * Creates a KCModuleContainer with tabs, each one containing one of the
0045      * specified modules in @p mods.
0046      *
0047      * @param parent the parent QWidget.
0048      * @param mods The list of KCModules to be loaded. The name of each
0049      * KCModule is its service name, that is the name of the desktop file without
0050      * the ".desktop" part
0051      *
0052      * @deprecated since 5.66, no known users.
0053      */
0054     KCMUTILS_DEPRECATED_VERSION(5, 66, "No known users")
0055     KCModuleContainer(QWidget *parent, const QStringList &mods);
0056 
0057     /**
0058      * This is a convenience function, instead of building a QStringList you
0059      * can specify the modules in a comma separated QString. For example;
0060      * \code
0061      * KCModuleContainer* cont = KCModuleContainer( this, "kcm_misc", QString("kcm_energy, kcm_keyboard ,kcm_useraccount, kcm_mouse") );
0062      * \endcode
0063      * The other constructor takes its modules in a QStringlist which also can be constructed from a
0064      * string and thus you will have to be explicit on the data type.
0065      *
0066      * What you probably want is the KCMODULECONTAINER macro which builds an KCModule
0067      * for you, taking the modules you want as argument.
0068      *
0069      * @param parent The parent widget
0070      * @param mods The modules to load
0071      * @return The KCModule containing the requested modules.
0072      *
0073      * @deprecated since 5.66, no known users.
0074      */
0075     KCMUTILS_DEPRECATED_VERSION(5, 66, "No known users")
0076     explicit KCModuleContainer(QWidget *parent, const QString &mods = QString());
0077 
0078     /**
0079      * Adds the specified module to the tab widget. Setting the tab icon, text,
0080      * tool tip, connecting the signals is what it does.
0081      *
0082      * @param module the name of the module to add. The name is the desktop file's name
0083      * without the ".desktop" part.
0084      *
0085      * @deprecated since 5.66, no known users.
0086      */
0087     KCMUTILS_DEPRECATED_VERSION(5, 66, "No known users")
0088     void addModule(const QString &module);
0089 
0090     /**
0091      * Default destructor.
0092      */
0093     ~KCModuleContainer() override;
0094 
0095     /**
0096      * @reimp
0097      */
0098     void save() override;
0099 
0100     /**
0101      * @reimp
0102      */
0103     void load() override;
0104 
0105     /**
0106      * @reimp
0107      */
0108     void defaults() override;
0109 
0110 private Q_SLOTS:
0111 
0112     /**
0113      * Enables/disables the Admin Mode button, as appropriate.
0114      */
0115     void tabSwitched(int);
0116 
0117     void moduleChanged(KCModuleProxy *proxy);
0118 
0119 private:
0120     void init();
0121 
0122     class KCModuleContainerPrivate;
0123     KCModuleContainerPrivate *const d;
0124 };
0125 
0126 /**
0127  * This macro creates an factory declaration which when run creates an KCModule with specified
0128  * modules. For example:
0129  * \code
0130  * KCMODULECONTAINER("kcm_fonts,kcm_keyboard,kcm_foo", misc_modules)
0131  * \endcode
0132  * would create a KCModule with three tabs, each containing one of the specified KCMs. Each
0133  * use of the macro must be accompanied by a desktop file where the factory name equals
0134  * the second argument in the macro(in this example, misc_modules). \n
0135  * The module container takes care of testing the contained modules when being shown, as well
0136  * as when the module itself is asked whether it should be shown.
0137  *
0138  * @param modules the modules to put in the container
0139  * @param factoryName what factory name the module should have
0140  *
0141  * @deprecated since 5.66, no known users.
0142  */
0143 // clang-format off
0144 #define KCMODULECONTAINER(modules, factoryName) \
0145     class KCModuleContainer##factoryName : public KCModuleContainer \
0146     { \
0147     public: \
0148         KCModuleContainer##factoryName(QWidget *parent, const QVariantList &) \
0149             : KCModuleContainer(parent, QLatin1String(modules)) \
0150         { \
0151         } \
0152     }; \
0153     K_PLUGIN_FACTORY(KCModuleContainer##factoryName##Factory, \
0154                      registerPlugin<KCModuleContainer#factoryName>(); \
0155                     )
0156 // clang-format on
0157 #endif
0158 #endif // KCMODULECONTAINER_H