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

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2007, 2006 Rafael Fernández López <ereslibre@kde.org>
0004     SPDX-FileCopyrightText: 2002-2003 Matthias Kretz <kretz@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef KPLUGINSELECTOR_H
0010 #define KPLUGINSELECTOR_H
0011 
0012 #include <kcmutils_export.h>
0013 
0014 #if KCMUTILS_ENABLE_DEPRECATED_SINCE(5, 90)
0015 
0016 #include <QWidget>
0017 
0018 #include <QList>
0019 
0020 #include <KSharedConfig>
0021 
0022 class KPluginInfo;
0023 class QPushButton;
0024 
0025 /**
0026  * @short A widget to select what plugins to load and configure the plugins.
0027  *
0028  * It shows the list of available plugins
0029  *
0030  * Since the user needs a way to know what a specific plugin does every plugin
0031  * should install a desktop file containing a name, comment and category field.
0032  * The category is useful for applications that can use different kinds of
0033  * plugins like a playlist, skin or visualization
0034  *
0035  * The location of these desktop files is the
0036  * share/apps/&lt;instancename&gt;/&lt;plugindir&gt; directory. But if you need
0037  * you may use a different directory
0038  *
0039  * You can add plugins from different KConfig[group], by just calling all times
0040  * you want addPlugins method with the correct parameters
0041  *
0042  * Additionally, calls to constructor with same @p categoryName, will add new
0043  * items to the same category, even if plugins are from different categories
0044  *
0045  * @author Matthias Kretz <kretz@kde.org>
0046  * @author Rafael Fernández López <ereslibre@kde.org>
0047  * @deprecated Since 5.90, use KPluginWidget instead
0048  */
0049 class KCMUTILS_EXPORT KPluginSelector : public QWidget
0050 {
0051     Q_OBJECT
0052     Q_PROPERTY(QStringList configurationArguments READ configurationArguments WRITE setConfigurationArguments)
0053 
0054 public:
0055     enum PluginLoadMethod {
0056         ReadConfigFile = 0,
0057         IgnoreConfigFile,
0058     };
0059 
0060     /**
0061      * Create a new KPluginSelector
0062      */
0063     KCMUTILS_DEPRECATED_VERSION(5, 90, "Use KPluginWidget instead")
0064     KPluginSelector(QWidget *parent = nullptr);
0065 
0066     /**
0067      * Destructor
0068      */
0069     ~KPluginSelector() override;
0070 
0071     /**
0072      * Add a list of KParts plugins
0073      *
0074      * The information about the plugins will be loaded from the
0075      * share/apps/&lt;instancename&gt;/kpartplugins directory
0076      *
0077      * @param componentName The name of the component of the plugin's parent.
0078      * @param categoryName  The translated name of the category. This is the
0079      *                      name that is shown in the title. If the category
0080      *                      did exist before because of another call to
0081      *                      addPlugins, then they will be shown in that
0082      *                      category. If @p categoryName is a new one, then
0083      *                      a new category will be shown on the plugin window,
0084      *                      and the list of plugins added to it
0085      * @param categoryKey   When you have different categories of KParts
0086      *                      plugins you distinguish between the plugins using
0087      *                      the Category key in the .desktop file. Use this
0088      *                      parameter to select only those KParts plugins
0089      *                      with the Category key == @p categoryKey. If
0090      *                      @p categoryKey is not set the Category key is
0091      *                      ignored and all plugins are shown. Not match case
0092      * @param config        The KConfig object that holds the state of the
0093      *                      plugins being enabled or not. By default it will be
0094      *                      set to KSharedConfig::openConfig(componentName + "rc").
0095      */
0096     void addPlugins(const QString &componentName,
0097                     const QString &categoryName = QString(),
0098                     const QString &categoryKey = QString(),
0099                     KSharedConfig::Ptr config = KSharedConfig::Ptr());
0100 
0101     /**
0102      * Add a list of non-KParts plugins
0103      *
0104      * @param pluginInfoList   A list of KPluginInfo objects containing the
0105      *                         necessary information for the plugins you want to
0106      *                         add to the list
0107      * @param pluginLoadMethod If KPluginSelector will try to load the
0108      *                         state of the plugin when loading the
0109      *                         dialog from the configuration file or not.
0110      *                         This is useful if for some reason you
0111      *                         called the setPluginEnabled() for each plugin
0112      *                         individually before loading the dialog, and
0113      *                         don't want KPluginSelector to override them
0114      *                         when loading
0115      * @param categoryName     The translated name of the category. This is the
0116      *                         name that is shown in the title. If the category
0117      *                         did exist before because of another call to
0118      *                         addPlugins, then they will be shown in that
0119      *                         category. If @p categoryName is a new one, then
0120      *                         a new category will be shown on the plugin window,
0121      *                         and the list of plugins added to it
0122      * @param categoryKey      When you have different categories of KParts
0123      *                         plugins you distinguish between the plugins using
0124      *                         the Category key in the .desktop file. Use this
0125      *                         parameter to select only those KParts plugins
0126      *                         with the Category key == @p categoryKey. If
0127      *                         @p categoryKey is not set the Category key is
0128      *                         ignored and all plugins are shown. Not match case
0129      * @param config           The KConfig object that holds the state of the
0130      *                         plugins being enabled or not. By default it will
0131      *                         use KSharedConfig::openConfig(). It is recommended to
0132      *                         always pass a KConfig object if you use
0133      *                         KSettings::PluginPage since you never know from
0134      *                         where the page will be called (think global
0135      *                         config app). For example KViewCanvas passes
0136      *                         KConfig("kviewcanvas")
0137      *
0138      * @note   All plugins that were set a config group using setConfig() method
0139      *         will load and save their information from there. For those that
0140      *         weren't any config object, @p config will be used
0141      */
0142     void addPlugins(const QList<KPluginInfo> &pluginInfoList,
0143                     PluginLoadMethod pluginLoadMethod = ReadConfigFile,
0144                     const QString &categoryName = QString(),
0145                     const QString &categoryKey = QString(),
0146                     const KSharedConfig::Ptr &config = KSharedConfig::Ptr());
0147 
0148     /**
0149      * Remove all plugins from the entry list.
0150      * @since 5.73
0151      */
0152     void clearPlugins();
0153 
0154     /**
0155      * Load the state of the plugins (selected or not) from the KPluginInfo
0156      * objects
0157      */
0158     void load();
0159 
0160     /**
0161      * Save the configuration
0162      */
0163     void save();
0164 
0165     /**
0166      * Returns true if the plugin selector has any changes that are not yet saved to configuration.
0167      * @see save()
0168      * @since 5.78
0169      */
0170     bool isSaveNeeded() const;
0171 
0172     /**
0173      * Change to applications defaults
0174      * @see isDefault()
0175      */
0176     void defaults();
0177 
0178     /**
0179      * Returns true if the plugin selector does not have any changes to application defaults
0180      * @see defaults()
0181      * @since 4.3
0182      */
0183     bool isDefault() const;
0184 
0185     /**
0186      * Updates plugins state (enabled or not)
0187      *
0188      * This method won't save anything on any configuration file. It will just
0189      * be useful if you added plugins with the method:
0190      *
0191      * \code
0192      * void addPlugins(const QList<KPluginInfo> &pluginInfoList,
0193      *                 const QString &categoryName = QString(),
0194      *                 const QString &categoryKey = QString(),
0195      *                 const KSharedConfig::Ptr &config = KSharedConfig::Ptr());
0196      * \endcode
0197      *
0198      * To sum up, this method will update your plugins state depending if plugins
0199      * are ticked or not on the KPluginSelector dialog, without saving anything
0200      * anywhere
0201      */
0202     void updatePluginsState();
0203 
0204     /**
0205      * Sets the @p arguments with which the configuration modules will be initialized
0206      *
0207      * @since 5.9
0208      */
0209     void setConfigurationArguments(const QStringList &arguments);
0210 
0211     /**
0212      * Returns the configuration arguments that will be used
0213      *
0214      * @since 5.9
0215      */
0216     QStringList configurationArguments() const;
0217 
0218     /**
0219      * Shows the configuration dialog for the plugin @p pluginId if it's available
0220      *
0221      * @since 5.45
0222      */
0223     void showConfiguration(const QString &pluginId);
0224 
0225     /**
0226      * Add additional widgets to each row of the plugin selector
0227      * @param handler returns the additional button that should be displayed in the row
0228      * the handler can return a null pointer if no button should be displayed
0229      * @since 5.74
0230      */
0231     void setAdditionalButtonHandler(std::function<QPushButton *(const KPluginInfo &)> handler);
0232 
0233     /**
0234      * Show an indicator when a plugin status is different from default
0235      *
0236      * @since 5.78
0237      */
0238     void setDefaultsIndicatorsVisible(bool isVisible);
0239 
0240 Q_SIGNALS:
0241     /**
0242      * Tells you whether the configuration is changed or not.
0243      */
0244     void changed(bool hasChanged);
0245 
0246     /**
0247      * Emitted after the config of an embedded KCM has been saved. The
0248      * argument is the name of the parent component that needs to reload
0249      * its config
0250      */
0251     void configCommitted(const QByteArray &componentName);
0252 
0253     /**
0254      * Emitted after configuration is changed, tell if configuration represent default or not
0255      * @since 5.67
0256      */
0257     void defaulted(bool isDefault);
0258 
0259     /**
0260      * Emitted when show defaults indicators changed
0261      * @see setDefaultsIndicatorsVisible
0262      *
0263      * @since 5.78
0264      */
0265     void defaultsIndicatorsVisible();
0266 
0267 private:
0268     class Private;
0269     Private *const d;
0270 };
0271 
0272 #endif
0273 #endif