KParts

partbase.h
1 /*
2  This file is part of the KDE project
3  SPDX-FileCopyrightText: 1999 Simon Hausmann <[email protected]>
4  SPDX-FileCopyrightText: 1999 David Faure <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef _KPARTS_PARTBASE_H
10 #define _KPARTS_PARTBASE_H
11 
12 #include <kparts/kparts_export.h>
13 
14 #include <QObject>
15 
16 #include <KXMLGUIClient>
17 #include <memory>
18 
19 // Internal:
20 // As KParts::PartBase is inherited by KParts::Part which also inheriting from QObject,
21 // which already has a protected d_ptr member, the macro Q_DECLARE_PRIVATE cannot be used
22 // as it references d_ptr without any class qualifier, which is ambiguous then.
23 #define KPARTS_DECLARE_PRIVATE(Class) Q_DECLARE_PRIVATE_D(PartBase::d_ptr, Class)
24 
25 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
26 class KAboutData;
27 #endif
28 
29 namespace KParts
30 {
31 class PartBasePrivate;
32 
33 /**
34  * @class PartBase partbase.h <KParts/PartBase>
35  *
36  * @short Base class for all parts.
37  */
38 class KPARTS_EXPORT PartBase : virtual public KXMLGUIClient
39 {
40  KPARTS_DECLARE_PRIVATE(PartBase)
41 
42 public:
43  /**
44  * Constructor.
45  */
46  PartBase();
47 
48  /**
49  * Destructor.
50  */
51  virtual ~PartBase();
52 
53  /**
54  * Internal method. Called by KParts::Part to specify the parent object for plugin objects.
55  *
56  * @internal
57  */
58  void setPartObject(QObject *object);
59  QObject *partObject() const;
60 
61 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 77)
62  /**
63  * @deprecated Since 5.77, use Part::metaData() or KXMLGUIClient::componentName() instead.
64  */
65  KPARTS_DEPRECATED_VERSION(5, 77, "Use Part::metaData() or KXMLGUIClient::componentName() instead")
66  KAboutData componentData() const;
67 #endif
68 
69 protected:
70 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
71  /**
72  * Set the componentData(KAboutData) for this part.
73  *
74  * Call this *first* in the inherited class constructor.
75  * @deprecated Since 5.77, use Part::setMetaData(const KPluginMetaData&)
76  * or KXMLGUIClient::setComponentName(const QString &, const QString &) instead.
77  */
78  KPARTS_DEPRECATED_VERSION(5,
79  77,
80  "Use Part::setMetaData(const KPluginMetaData&) or KXMLGUIClient::setComponentName(const QString &, const QString &) instead")
81  virtual void setComponentData(const KAboutData &componentData);
82 #endif
83 
84 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
85  /**
86  * Set the componentData(KAboutData) for this part.
87  *
88  * Call this *first* in the inherited class constructor.
89  *
90  * It is recommended to call setComponentData with loadPlugins set to false,
91  * and to load plugins at the end of your part constructor (in the case of
92  * KParts::MainWindow, plugins are automatically loaded in createGUI anyway,
93  * so set loadPlugins to false for KParts::MainWindow as well).
94  * @deprecated Since 5.77, use Part::setMetaData(const KPluginMetaData&)
95  * or KXMLGUIClient::setComponentName(const QString &, const QString &) instead.
96  */
97  KPARTS_DEPRECATED_VERSION(5,
98  77,
99  "Use Part::setMetaData(const KPluginMetaData&) or KXMLGUIClient::setComponentName(const QString &, const QString &) instead")
100  virtual void setComponentData(const KAboutData &pluginData, bool loadPlugins);
101 #endif
102 
103  /**
104  * We have three different policies, whether to load new plugins or not. The
105  * value in the KConfig object of the KAboutData object always overrides
106  * LoadPlugins and LoadPluginsIfEnabled.
107  */
109  /**
110  * Don't load any plugins at all.
111  */
112  DoNotLoadPlugins = 0,
113  /**
114  * Load new plugins automatically. Can be
115  * overridden by the plugin if it sets
116  * EnabledByDefault=false in the corresponding
117  * .desktop file.
118  */
119  LoadPlugins = 1,
120  /**
121  * New plugins are disabled by default. Can be
122  * overridden by the plugin if it sets
123  * EnabledByDefault=true in the corresponding
124  * .desktop file.
125  */
126  LoadPluginsIfEnabled = 2,
127  };
128 
129 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 77)
130  /**
131  * Load the Plugins honoring the PluginLoadingMode.
132  *
133  * If you call this method in an already constructed GUI (like when the user
134  * has changed which plugins are enabled) you need to add the new plugins to
135  * the KXMLGUIFactory:
136  * \code
137  * if( factory() )
138  * {
139  * const QList<KParts::Plugin *> plugins = KParts::Plugin::pluginObjects(this);
140  * for (auto *plugin : plugins) {
141  * factory()->addClient(plugin);
142  * }
143  * }
144  * \endcode
145  * @deprecated Since 5.77, use loadPlugins(QObject *parent, KXMLGUIClient *, const QString &) instead.
146  */
147  KPARTS_DEPRECATED_VERSION(5, 77, "Use loadPlugins(QObject *parent, KXMLGUIClient *, const QString &) instead")
148  void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const KAboutData &aboutData);
149 #endif
150 
151  /**
152  * Load the Plugins honoring the PluginLoadingMode.
153  *
154  * If you call this method in an already constructed GUI (like when the user
155  * has changed which plugins are enabled) you need to add the new plugins to
156  * the KXMLGUIFactory:
157  * \code
158  * if( factory() )
159  * {
160  * const QList<KParts::Plugin *> plugins = KParts::Plugin::pluginObjects(this);
161  * for (auto *plugin : plugins) {
162  * factory()->addClient(plugin);
163  * }
164  * }
165  * \endcode
166  *
167  * @since 5.77
168  */
169  void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const QString &parentInstanceName);
170 
171  /**
172  * Set how plugins should be loaded
173  * @param loadingMode see PluginLoadingMode
174  *
175  * For a KParts::Part: call this before setComponentData.
176  * For a KParts::MainWindow: call this before createGUI.
177  */
178  void setPluginLoadingMode(PluginLoadingMode loadingMode);
179 
180  /**
181  * If you change the binary interface offered by your part, you can avoid crashes
182  * from old plugins lying around by setting X-KDE-InterfaceVersion=2 in the
183  * .desktop files of the plugins, and calling setPluginInterfaceVersion( 2 ), so that
184  * the old plugins are not loaded. Increase both numbers every time a
185  * binary incompatible change in the application's plugin interface is made.
186  *
187  * @param version the interface version that plugins must have in order to be loaded.
188  *
189  * For a KParts::Part: call this before setComponentData.
190  * For a KParts::MainWindow: call this before createGUI.
191  */
192  void setPluginInterfaceVersion(int version);
193 
194 protected:
195  PartBase(PartBasePrivate &dd);
196 
197  std::unique_ptr<PartBasePrivate> const d_ptr;
198 
199 private:
200  Q_DISABLE_COPY(PartBase)
201 };
202 
203 } // namespace
204 
205 #endif
Base class for all parts.
Definition: partbase.h:38
PluginLoadingMode
We have three different policies, whether to load new plugins or not.
Definition: partbase.h:108
The KParts namespace,.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 19 2021 22:56:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.