File indexing completed on 2024-04-28 15:29:21

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
0004     SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef _KPARTS_PARTBASE_H
0010 #define _KPARTS_PARTBASE_H
0011 
0012 #include <kparts/kparts_export.h>
0013 
0014 #include <QObject>
0015 
0016 #include <KXMLGUIClient>
0017 #include <memory>
0018 
0019 // Internal:
0020 // As KParts::PartBase is inherited by KParts::Part which also inheriting from QObject,
0021 // which already has a protected d_ptr member, the macro Q_DECLARE_PRIVATE cannot be used
0022 // as it references d_ptr without any class qualifier, which is ambiguous then.
0023 #define KPARTS_DECLARE_PRIVATE(Class) Q_DECLARE_PRIVATE_D(PartBase::d_ptr, Class)
0024 
0025 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
0026 class KAboutData;
0027 #endif
0028 
0029 namespace KParts
0030 {
0031 class PartBasePrivate;
0032 
0033 /**
0034  * @class PartBase partbase.h <KParts/PartBase>
0035  *
0036  * @short Base class for all parts.
0037  */
0038 class KPARTS_EXPORT PartBase : virtual public KXMLGUIClient
0039 {
0040     KPARTS_DECLARE_PRIVATE(PartBase)
0041 
0042 public:
0043     /**
0044      *  Constructor.
0045      */
0046     PartBase();
0047 
0048     /**
0049      *  Destructor.
0050      */
0051     ~PartBase() override;
0052 
0053     /**
0054      *  Internal method. Called by KParts::Part to specify the parent object for plugin objects.
0055      *
0056      * @internal
0057      */
0058     void setPartObject(QObject *object);
0059     QObject *partObject() const;
0060 
0061 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 77)
0062     /**
0063      * @deprecated Since 5.77, use Part::metaData() or KXMLGUIClient::componentName() instead.
0064      */
0065     KPARTS_DEPRECATED_VERSION(5, 77, "Use Part::metaData() or KXMLGUIClient::componentName() instead")
0066     KAboutData componentData() const;
0067 #endif
0068 
0069 protected:
0070 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
0071     /**
0072      * Set the componentData(KAboutData) for this part.
0073      *
0074      * Call this *first* in the inherited class constructor.
0075      * @deprecated Since 5.77, use Part::setMetaData(const KPluginMetaData&)
0076      *             or KXMLGUIClient::setComponentName(const QString &, const QString &) instead.
0077      */
0078     KPARTS_DEPRECATED_VERSION(5,
0079                               77,
0080                               "Use Part::setMetaData(const KPluginMetaData&) or KXMLGUIClient::setComponentName(const QString &, const QString &) instead")
0081     virtual void setComponentData(const KAboutData &componentData);
0082 #endif
0083 
0084 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
0085     /**
0086      * Set the componentData(KAboutData) for this part.
0087      *
0088      * Call this *first* in the inherited class constructor.
0089      *
0090      * It is recommended to call setComponentData with loadPlugins set to false,
0091      * and to load plugins at the end of your part constructor (in the case of
0092      * KParts::MainWindow, plugins are automatically loaded in createGUI anyway,
0093      * so set loadPlugins to false for KParts::MainWindow as well).
0094      * @deprecated Since 5.77, use Part::setMetaData(const KPluginMetaData&)
0095      *             or KXMLGUIClient::setComponentName(const QString &, const QString &) instead.
0096      */
0097     KPARTS_DEPRECATED_VERSION(5,
0098                               77,
0099                               "Use Part::setMetaData(const KPluginMetaData&) or KXMLGUIClient::setComponentName(const QString &, const QString &) instead")
0100     virtual void setComponentData(const KAboutData &pluginData, bool loadPlugins);
0101 #endif
0102 
0103 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 77)
0104     /**
0105      * Load the Plugins honoring the PluginLoadingMode.
0106      *
0107      * If you call this method in an already constructed GUI (like when the user
0108      * has changed which plugins are enabled) you need to add the new plugins to
0109      * the KXMLGUIFactory:
0110      * \code
0111      * if( factory() )
0112      * {
0113      *   const QList<KParts::Plugin *> plugins = KParts::Plugin::pluginObjects(this);
0114      *   for (auto *plugin : plugins) {
0115      *      factory()->addClient(plugin);
0116      *   }
0117      * }
0118      * \endcode
0119      * @deprecated Since 5.77, use loadPlugins(QObject *parent, KXMLGUIClient *, const QString &) instead.
0120      */
0121     KPARTS_DEPRECATED_VERSION(5, 77, "Use loadPlugins(QObject *parent, KXMLGUIClient *, const QString &) instead")
0122     void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const KAboutData &aboutData);
0123 #endif
0124 
0125 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 90)
0126     /**
0127      * Load the Plugins honoring the PluginLoadingMode.
0128      *
0129      * If you call this method in an already constructed GUI (like when the user
0130      * has changed which plugins are enabled) you need to add the new plugins to
0131      * the KXMLGUIFactory:
0132      * \code
0133      * if( factory() )
0134      * {
0135      *   const QList<KParts::Plugin *> plugins = KParts::Plugin::pluginObjects(this);
0136      *   for (auto *plugin : plugins) {
0137      *      factory()->addClient(plugin);
0138      *   }
0139      * }
0140      * \endcode
0141      *
0142      * @since 5.77
0143      * @deprecated Since 5.90, the concept of KPart plugins is deprecated, see docs of @ref KParts::Plugin class
0144      */
0145     KPARTS_DEPRECATED_VERSION(5, 90, "The concept of KPart plugins is deprecated, see docs of KParts::Plugin class")
0146     void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const QString &parentInstanceName);
0147 #endif
0148 
0149 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 90)
0150     /**
0151      * We have three different policies, whether to load new plugins or not. The
0152      * value in the KConfig object of the KAboutData object always overrides
0153      * LoadPlugins and LoadPluginsIfEnabled.
0154      */
0155     enum PluginLoadingMode {
0156         /**
0157          * Don't load any plugins at all.
0158          */
0159         DoNotLoadPlugins = 0,
0160         /**
0161          * Load new plugins automatically. Can be
0162          * overridden by the plugin if it sets
0163          * EnabledByDefault=false in the corresponding
0164          * .desktop file.
0165          */
0166         LoadPlugins = 1,
0167         /**
0168          * New plugins are disabled by default. Can be
0169          * overridden by the plugin if it sets
0170          * EnabledByDefault=true in the corresponding
0171          * .desktop file.
0172          */
0173         LoadPluginsIfEnabled = 2,
0174     };
0175 
0176     /**
0177      * Set how plugins should be loaded
0178      * @param loadingMode see PluginLoadingMode
0179      *
0180      * For a KParts::Part: call this before setComponentData.
0181      * For a KParts::MainWindow: call this before createGUI.
0182      * @deprecated Since 5.90, the concept of KPart plugins is deprecated, see docs of @ref KParts::Plugin class
0183      */
0184     KPARTS_DEPRECATED_VERSION(5, 90, "The concept of KPart plugins is deprecated, see docs of KParts::Plugin class")
0185     void setPluginLoadingMode(PluginLoadingMode loadingMode);
0186 #endif
0187 
0188 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 103)
0189     /**
0190      * If you change the binary interface offered by your part, you can avoid crashes
0191      * from old plugins lying around by setting X-KDE-InterfaceVersion=2 in the
0192      * .desktop files of the plugins, and calling setPluginInterfaceVersion( 2 ), so that
0193      * the old plugins are not loaded. Increase both numbers every time a
0194      * binary incompatible change in the application's plugin interface is made.
0195      *
0196      * @param version the interface version that plugins must have in order to be loaded.
0197      *
0198      * For a KParts::Part: call this before setComponentData.
0199      * For a KParts::MainWindow: call this before createGUI.
0200      * @deprecated Since 5.90, the concept of KPart plugins is deprecated, see docs of @ref KParts::Plugin class
0201      */
0202     KPARTS_DEPRECATED_VERSION_BELATED(5, 103, 5, 90, "The concept of KPart plugins is deprecated, see docs of KParts::Plugin class")
0203     void setPluginInterfaceVersion(int version);
0204 #endif
0205 
0206 protected:
0207     KPARTS_NO_EXPORT explicit PartBase(PartBasePrivate &dd);
0208 
0209     std::unique_ptr<PartBasePrivate> const d_ptr;
0210 
0211 private:
0212     Q_DISABLE_COPY(PartBase)
0213 };
0214 
0215 } // namespace
0216 
0217 #endif