KontactInterface

plugin.h
1/*
2 This file is part of the KDE Kontact Plugin Interface Library.
3
4 SPDX-FileCopyrightText: 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org>
5 SPDX-FileCopyrightText: 2002-2003 Daniel Molkentin <molkentin@kde.org>
6 SPDX-FileCopyrightText: 2003 Cornelius Schumacher <schumacher@kde.org>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#pragma once
12
13#include "kontactinterface_export.h"
14
15#include <KPluginFactory>
16#include <KXMLGUIClient>
17
18#include <QList>
19#include <QObject>
20#include <QStringList>
21
22class KAboutData;
23class QAction;
24class KConfig;
25class KConfigGroup;
26class QDropEvent;
27class QMimeData;
28class QWidget;
29namespace KParts
30{
31class Part;
32}
33
34/**
35 Increase this version number whenever you make a change in the API.
36 */
37#define KONTACT_PLUGIN_VERSION 11
38
39/**
40 Exports Kontact plugin.
41 @param pluginclass the class to instantiate (must derive from KontactInterface::Plugin)
42 @param jsonFile filename of the JSON file, generated from a .desktop file
43 */
44#define EXPORT_KONTACT_PLUGIN_WITH_JSON(pluginclass, jsonFile) \
45 class Instance \
46 { \
47 public: \
48 static QObject *createInstance(QWidget *, QObject *parent, const KPluginMetaData &data, const QVariantList &list) \
49 { \
50 return new pluginclass(static_cast<KontactInterface::Core *>(parent), data, list); \
51 } \
52 }; \
53 K_PLUGIN_FACTORY_WITH_JSON(KontactPluginFactory, jsonFile, registerPlugin<pluginclass>(Instance::createInstance);)
54
55namespace KontactInterface
56{
57class Core;
58class Summary;
59/**
60 * @short Base class for all Plugins in Kontact.
61 *
62 * Inherit from it to get a plugin. It can insert an icon into the sidepane,
63 * add widgets to the widgetstack and add menu items via XMLGUI.
64 */
65class KONTACTINTERFACE_EXPORT Plugin : public QObject, virtual public KXMLGUIClient
66{
67 Q_OBJECT
68
69public:
70 /**
71 * Creates a new plugin.
72 *
73 * @param core The core object that manages the plugin.
74 * @param parent The parent object.
75 * @param appName The name of the application that
76 * provides the part. This is the name used for DBus registration.
77 * It's ok to have several plugins using the same application name.
78 * @param pluginName The unique name of the plugin. Defaults to appName if not set.
79 */
80 Plugin(Core *core, QObject *parent, const KPluginMetaData &data, const char *appName, const char *pluginName = nullptr);
81 /**
82 * Destroys the plugin.
83 */
84 ~Plugin() override;
85
86 /**
87 * Sets the @p identifier of the plugin.
88 */
89 void setIdentifier(const QString &identifier);
90
91 /**
92 * Returns the identifier of the plugin.
93 */
94 [[nodiscard]] QString identifier() const;
95
96 /**
97 * Sets the localized @p title of the plugin.
98 */
99 void setTitle(const QString &title);
100
101 /**
102 * Returns the localized title of the plugin.
103 */
104 [[nodiscard]] QString title() const;
105
106 /**
107 * Sets the @p icon name that is used for the plugin.
108 */
109 void setIcon(const QString &icon);
110
111 /**
112 * Returns the icon name that is used for the plugin.
113 */
114 [[nodiscard]] QString icon() const;
115
116 /**
117 * Sets the @p name of executable (if existent).
118 */
119 void setExecutableName(const QString &name);
120
121 /**
122 * Returns the name of the executable (if existent).
123 */
124 [[nodiscard]] QString executableName() const;
125
126 /**
127 * Set @p name of library which contains the KPart used by this plugin.
128 */
129 void setPartLibraryName(const QByteArray &name);
130
131 /**
132 * Reimplement this method and return whether a standalone application
133 * is still running. This is only required if your part is also available
134 * as standalone application.
135 */
136 [[nodiscard]] virtual bool isRunningStandalone() const;
137
138 /**
139 * Reimplement this method if your application needs a different approach to be brought
140 * in the foreground. The default behaviour is calling the binary.
141 * This is only required if your part is also available as standalone application.
142 */
143 virtual void bringToForeground();
144
145 /**
146 * Reimplement this method if you want to add your credits to the Kontact
147 * about dialog.
148 */
149 [[nodiscard]] virtual const KAboutData aboutData();
150
151 /**
152 * You can use this method if you need to access the current part. You can be
153 * sure that you always get the same pointer as long as the part has not been
154 * deleted.
155 */
156 [[nodiscard]] KParts::Part *part();
157
158 /**
159 * This function is called when the plugin is selected by the user before the
160 * widget of the KPart belonging to the plugin is raised.
161 */
162 virtual void select();
163
164 /**
165 * Called by kontact when the plugin is selected by the user.
166 * Calls the virtual method select(), but also handles some standard behavior
167 * like "invisible toolbar actions".
168 */
169 void aboutToSelect();
170
171 /**
172 * This function is called whenever the config dialog has been closed
173 * successfully.
174 */
175 virtual void configUpdated();
176
177 /**
178 * Reimplement this method if you want to add a widget for your application
179 * to Kontact's summary page.
180 *
181 * @param parent The parent widget of the summary widget.
182 */
183 [[nodiscard]] virtual Summary *createSummaryWidget(QWidget *parent);
184
185 /**
186 * Returns whether the plugin provides a part that should be shown in the sidebar.
187 */
188 [[nodiscard]] virtual bool showInSideBar() const;
189
190 /**
191 * Set if the plugin provides a part that should be shown in the sidebar.
192 * @param hasPart shows part in sidebar if set as @c true
193 */
194 void setShowInSideBar(bool hasPart);
195
196 /**
197 * Reimplement this method if you want to add checks before closing the
198 * main kontact window. Return true if it's OK to close the window.
199 * If any loaded plugin returns false from this method, then the
200 * main kontact window will not close.
201 */
202 [[nodiscard]] virtual bool queryClose() const;
203
204 /**
205 * Registers the client at DBus and returns the dbus identifier.
206 */
207 QString registerClient();
208
209 /**
210 * Return the weight of the plugin. The higher the weight the lower it will
211 * be displayed in the sidebar. The default implementation returns 0.
212 */
213 virtual int weight() const;
214
215 /**
216 * Inserts a custom "New" @p action.
217 * @param action the new action to insert
218 */
219 void insertNewAction(QAction *action);
220
221 /**
222 * Inserts a custom "Sync" @p action.
223 * @param action the custom Sync action to insert
224 */
225 void insertSyncAction(QAction *action);
226
227 /**
228 * Returns the list of custom "New" actions.
229 */
230 [[nodiscard]] QList<QAction *> newActions() const;
231
232 /**
233 * Returns the list of custom "Sync" actions.
234 */
235 [[nodiscard]] QList<QAction *> syncActions() const;
236
237 /**
238 * Returns a list of action names that shall be hidden in the main toolbar.
239 */
240 [[nodiscard]] virtual QStringList invisibleToolbarActions() const;
241
242 /**
243 * Returns whether the plugin can handle the drag object of the given mime type.
244 */
245 [[nodiscard]] virtual bool canDecodeMimeData(const QMimeData *data) const;
246
247 /**
248 * Process drop event.
249 */
250 virtual void processDropEvent(QDropEvent *);
251
252 /**
253 * Session management: read properties
254 */
255 virtual void readProperties(const KConfigGroup &);
256
257 /**
258 * Session management: save properties
259 */
260 virtual void saveProperties(KConfigGroup &);
261
262 /**
263 * Returns a pointer to the kontact core object.
264 */
265 [[nodiscard]] Core *core() const;
266
267 /**
268 * Sets whether the plugin shall be disabled.
269 */
270 void setDisabled(bool value);
271
272 /**
273 * Returns whether the plugin is disabled.
274 */
275 [[nodiscard]] bool disabled() const;
276
277 /**
278 * @since 4.13
279 */
280 virtual void shortcutChanged();
281
282public Q_SLOTS:
283 /**
284 * @internal usage
285 *
286 * This slot is called whenever the configuration has been changed.
287 */
288 void slotConfigUpdated();
289
290protected:
291 /**
292 * Reimplement and return the part here. Reimplementing createPart() is
293 * mandatory!
294 */
295 virtual KParts::Part *createPart() = 0;
296
297 /**
298 * Returns the loaded part.
299 */
300 KParts::Part *loadPart();
301
302 /**
303 * Virtual hook for BC extension.
304 */
305 void virtual_hook(int id, void *data) override;
306
307private:
308 //@cond PRIVATE
309 class PluginPrivate;
310 std::unique_ptr<PluginPrivate> const d;
311 //@endcond
312};
313
314}
The abstract interface that represents the Kontact core.
Definition core.h:27
Base class for all Plugins in Kontact.
Definition plugin.h:66
virtual KParts::Part * createPart()=0
Reimplement and return the part here.
Base class for summary widgets in Kontact.
Definition summary.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:49:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.