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  ~PartBase() override;
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 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 77)
104  /**
105  * Load the Plugins honoring the PluginLoadingMode.
106  *
107  * If you call this method in an already constructed GUI (like when the user
108  * has changed which plugins are enabled) you need to add the new plugins to
109  * the KXMLGUIFactory:
110  * \code
111  * if( factory() )
112  * {
113  * const QList<KParts::Plugin *> plugins = KParts::Plugin::pluginObjects(this);
114  * for (auto *plugin : plugins) {
115  * factory()->addClient(plugin);
116  * }
117  * }
118  * \endcode
119  * @deprecated Since 5.77, use loadPlugins(QObject *parent, KXMLGUIClient *, const QString &) instead.
120  */
121  KPARTS_DEPRECATED_VERSION(5, 77, "Use loadPlugins(QObject *parent, KXMLGUIClient *, const QString &) instead")
122  void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const KAboutData &aboutData);
123 #endif
124 
125 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 90)
126  /**
127  * Load the Plugins honoring the PluginLoadingMode.
128  *
129  * If you call this method in an already constructed GUI (like when the user
130  * has changed which plugins are enabled) you need to add the new plugins to
131  * the KXMLGUIFactory:
132  * \code
133  * if( factory() )
134  * {
135  * const QList<KParts::Plugin *> plugins = KParts::Plugin::pluginObjects(this);
136  * for (auto *plugin : plugins) {
137  * factory()->addClient(plugin);
138  * }
139  * }
140  * \endcode
141  *
142  * @since 5.77
143  * @deprecated Since 5.90, the concept of KPart plugins is deprecated, see docs of @ref KParts::Plugin class
144  */
145  KPARTS_DEPRECATED_VERSION(5, 90, "The concept of KPart plugins is deprecated, see docs of KParts::Plugin class")
146  void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const QString &parentInstanceName);
147 #endif
148 
149 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 90)
150  /**
151  * We have three different policies, whether to load new plugins or not. The
152  * value in the KConfig object of the KAboutData object always overrides
153  * LoadPlugins and LoadPluginsIfEnabled.
154  */
156  /**
157  * Don't load any plugins at all.
158  */
159  DoNotLoadPlugins = 0,
160  /**
161  * Load new plugins automatically. Can be
162  * overridden by the plugin if it sets
163  * EnabledByDefault=false in the corresponding
164  * .desktop file.
165  */
166  LoadPlugins = 1,
167  /**
168  * New plugins are disabled by default. Can be
169  * overridden by the plugin if it sets
170  * EnabledByDefault=true in the corresponding
171  * .desktop file.
172  */
173  LoadPluginsIfEnabled = 2,
174  };
175 
176  /**
177  * Set how plugins should be loaded
178  * @param loadingMode see PluginLoadingMode
179  *
180  * For a KParts::Part: call this before setComponentData.
181  * For a KParts::MainWindow: call this before createGUI.
182  * @deprecated Since 5.90, the concept of KPart plugins is deprecated, see docs of @ref KParts::Plugin class
183  */
184  KPARTS_DEPRECATED_VERSION(5, 90, "The concept of KPart plugins is deprecated, see docs of KParts::Plugin class")
185  void setPluginLoadingMode(PluginLoadingMode loadingMode);
186 #endif
187 
188  /**
189  * If you change the binary interface offered by your part, you can avoid crashes
190  * from old plugins lying around by setting X-KDE-InterfaceVersion=2 in the
191  * .desktop files of the plugins, and calling setPluginInterfaceVersion( 2 ), so that
192  * the old plugins are not loaded. Increase both numbers every time a
193  * binary incompatible change in the application's plugin interface is made.
194  *
195  * @param version the interface version that plugins must have in order to be loaded.
196  *
197  * For a KParts::Part: call this before setComponentData.
198  * For a KParts::MainWindow: call this before createGUI.
199  */
200  void setPluginInterfaceVersion(int version);
201 
202 protected:
203  PartBase(PartBasePrivate &dd);
204 
205  std::unique_ptr<PartBasePrivate> const d_ptr;
206 
207 private:
208  Q_DISABLE_COPY(PartBase)
209 };
210 
211 } // namespace
212 
213 #endif
PluginLoadingMode
We have three different policies, whether to load new plugins or not.
Definition: partbase.h:155
Base class for all parts.
Definition: partbase.h:38
The KParts namespace,.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 03:55:25 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.