KCoreAddons

kpluginmetadata.h
1 /*
2  This file is part of the KDE project
3 
4  SPDX-FileCopyrightText: 2014 Alex Richardson <[email protected]>
5  SPDX-FileCopyrightText: 2021 Alexander Lohnau <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef KPLUGINMETADATA_H
11 #define KPLUGINMETADATA_H
12 
13 #include "kcoreaddons_export.h"
14 
15 #include <QExplicitlySharedDataPointer>
16 #include <QJsonObject>
17 #include <QMetaType>
18 #include <QString>
19 #include <QStringList>
20 
21 #include <functional>
22 
23 class KPluginLoader;
24 class KPluginFactory;
25 class QPluginLoader;
26 class KPluginMetaDataPrivate;
27 class KAboutPerson;
28 class QObject;
29 class QStaticPlugin;
30 /**
31  * @class KPluginMetaData kpluginmetadata.h KPluginMetaData
32  *
33  * This class allows easily accessing some standardized values from the JSON metadata that
34  * can be embedded into Qt plugins. Additional plugin-specific metadata can be retrieved by
35  * directly reading from the QJsonObject returned by KPluginMetaData::rawData().
36  *
37  * This class can be used instead of KPluginInfo from KService for applications that only load
38  * Qt C++ plugins.
39  *
40  * The following keys will be read from an object "KPlugin" inside the metadata JSON:
41  *
42  * Key | Accessor function | JSON Type
43  * -------------------| -------------------- | ---------------------
44  * Name | name() | string
45  * Description | description() | string
46  * ExtraInformation | extraInformation() | string
47  * Icon | iconName() | string
48  * Authors | authors() | object array (KAboutPerson)
49  * Category | category() | string
50  * License | license() | string
51  * Copyright | copyrightText() | string
52  * Id | pluginId() | string
53  * Version | version() | string
54  * Website | website() | string
55  * BugReportUrl | bugReportUrl() | string
56  * EnabledByDefault | isEnabledByDefault() | bool
57  * ServiceTypes | serviceTypes() | string array
58  * MimeTypes | mimeTypes() | string array
59  * FormFactors | formFactors() | string array
60  * Translators | translators() | object array (KAboutPerson)
61  * OtherContributors | otherContributors() | object array (KAboutPerson)
62  *
63  * The Authors, Translators and OtherContributors keys are expected to be
64  * list of objects that match the structure expected by KAboutPerson::fromJSON().
65  *
66  * An example metadata json file could look like this:
67  * @verbatim
68  {
69  "KPlugin": {
70  "Name": "Date and Time",
71  "Description": "Date and time by timezone",
72  "Icon": "preferences-system-time",
73  "Authors": [ { "Name": "Aaron Seigo", "Email": "[email protected]" } ],
74  "Category": "Date and Time",
75  "EnabledByDefault": "true",
76  "License": "LGPL",
77  "Id": "time",
78  "Version": "1.0",
79  "Website": "https://plasma.kde.org/"
80  }
81  }
82  @endverbatim
83  *
84  * @sa KAboutPerson::fromJSON()
85  * @since 5.1
86  */
87 class KCOREADDONS_EXPORT KPluginMetaData
88 {
89  Q_GADGET
90  Q_PROPERTY(bool isValid READ isValid CONSTANT)
91  Q_PROPERTY(bool isHidden READ isHidden CONSTANT)
92  Q_PROPERTY(QString fileName READ fileName CONSTANT)
93  Q_PROPERTY(QString metaDataFileName READ metaDataFileName CONSTANT)
94  Q_PROPERTY(QJsonObject rawData READ rawData CONSTANT)
95  Q_PROPERTY(QString name READ name CONSTANT)
96  Q_PROPERTY(QString description READ description CONSTANT)
97 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 87)
98  Q_PROPERTY(QString extraInformation READ extraInformation CONSTANT)
99 #endif
100  Q_PROPERTY(QVariantList authors READ authorsVariant CONSTANT)
101  Q_PROPERTY(QVariantList translators READ translatorsVariant CONSTANT)
102  Q_PROPERTY(QVariantList otherContributors READ otherContributorsVariant CONSTANT)
103  Q_PROPERTY(QString category READ category CONSTANT)
104  Q_PROPERTY(QString iconName READ iconName CONSTANT)
105  Q_PROPERTY(QString license READ license CONSTANT)
106  Q_PROPERTY(QString licenseText READ licenseText CONSTANT)
107  Q_PROPERTY(QString copyrightText READ copyrightText CONSTANT)
108  Q_PROPERTY(QString pluginId READ pluginId CONSTANT)
109  Q_PROPERTY(QString version READ version CONSTANT)
110  Q_PROPERTY(QString website READ website CONSTANT)
111  Q_PROPERTY(QString bugReportUrl READ bugReportUrl CONSTANT)
112 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 79)
113  Q_PROPERTY(QStringList dependencies READ dependencies CONSTANT)
114 #endif
115 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 89)
116  Q_PROPERTY(QStringList serviceTypes READ serviceTypes CONSTANT)
117 #endif
118  Q_PROPERTY(QStringList mimeTypes READ mimeTypes CONSTANT)
119  Q_PROPERTY(QStringList formFactors READ formFactors CONSTANT)
120  Q_PROPERTY(bool isEnabledByDefault READ isEnabledByDefault CONSTANT)
121 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 104)
122  Q_PROPERTY(int initialPreference READ isEnabledByDefault CONSTANT)
123 #endif
124 
125 public:
126  /**
127  * Options for creating a KPluginMetaData object.
128  * @since 5.91
129  */
131  DoNotAllowEmptyMetaData, ///< Plugins with empty metaData are considered invalid
132  AllowEmptyMetaData, ///< Plugins with empty metaData are considered valid
133  };
134 
135  /** Creates an invalid KPluginMetaData instance */
136  KPluginMetaData();
137 
138 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 86)
139  /**
140  * Reads the plugin metadata from a KPluginLoader instance. You must call KPluginLoader::setFileName()
141  * or use the appropriate constructor on @p loader before calling this.
142  */
143  KCOREADDONS_DEPRECATED_VERSION(5, 86, "Use KPluginMetaData(QPluginLoader) instead")
144  KPluginMetaData(const KPluginLoader &loader);
145 #endif
146 
147  /**
148  * Reads the plugin metadata from a QPluginLoader instance. You must call QPluginLoader::setFileName()
149  * or use the appropriate constructor on @p loader before calling this.
150  */
151  KPluginMetaData(const QPluginLoader &loader);
152 
153  /**
154  * Reads the plugin metadata from a plugin or .desktop which can be loaded from @p file.
155  *
156  * For plugins, platform-specific library suffixes may be omitted since @p file will be resolved
157  * using the same logic as QPluginLoader.
158  *
159  * If the file name ends with ".desktop", the .desktop file will be parsed instead of
160  * reading the metadata from the QPluginLoader. This is the same as calling
161  * KPluginMetaData::fromDesktopFile() without the serviceTypes parameter.
162  *
163  * If @p file ends with .json, the file will be loaded as the QJsonObject metadata.
164  *
165  * @note Using this constructor for metadata files is deprecated..
166  * Use KPluginMetaData::fromDesktopFile or KPluginMetaData::fromJsonFile instead.
167  *
168  * @see QPluginLoader::setFileName()
169  * @see KPluginMetaData::fromDesktopFile()
170  * @see KPluginMetaData::fromJsonFile()
171  */
172  KPluginMetaData(const QString &file);
173 
174  /**
175  * Overload which takes an option parameter that gets used when creating the KPluginMetaData instances
176  * @since 5.91
177  */
178  KPluginMetaData(const QString &file, KPluginMetaDataOption option);
179 
180  /**
181  * Creates a KPluginMetaData from a QJsonObject holding the metadata and a file name
182  * This can be used if the data is not retrieved from a Qt C++ plugin library but from some
183  * other source.
184  * @see KPluginMetaData(const QJsonObject &, const QString &, const QString &)
185  */
186  KPluginMetaData(const QJsonObject &metaData, const QString &file);
187 
188  // TODO: KF6: merge with the above and make metaDataFile default to QString()
189  /**
190  * Creates a KPluginMetaData
191  * @param metaData the JSON metadata to use for this object
192  * @param pluginFile the file that the plugin can be loaded from
193  * @param metaDataFile the file that the JSON metadata was read from
194  *
195  * This can be used if the data is not retrieved from a Qt C++ plugin library but from some
196  * other source.
197  *
198  * @since 5.5
199  */
200  KPluginMetaData(const QJsonObject &metaData, const QString &pluginFile, const QString &metaDataFile);
201 
202  /*
203  * Constructs a KPluginMetaData from the static plugin.
204  * If it does not have any meta data the @p metaData value is used
205  *
206  * @see KPluginFactory::loadFactory
207  * @see KPluginFactory::instantiatePlugin
208  *
209  * @since 5.89
210  */
211  KPluginMetaData(QStaticPlugin plugin, const QJsonObject &metaData = {});
212 
213  /**
214  * Copy contructor
215  */
217  /**
218  * Copy assignment
219  */
220  KPluginMetaData &operator=(const KPluginMetaData &);
221  /**
222  * Destructor
223  */
224  ~KPluginMetaData();
225 
226 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 92)
227  /**
228  * Load a KPluginMetaData instance from a .desktop file. Unlike the constructor which takes
229  * a single file parameter this method allows you to specify which service type files should
230  * be parsed to determine the correct type for a given .desktop property.
231  * This ensures that a e.g. comma-separated string list field in the .desktop file will correctly
232  * be converted to a JSON string array.
233  *
234  * @note This function mostly exists for backwards-compatibility. It is recommended
235  * that new applications load JSON files directly instead of using .desktop files for plugin metadata.
236  *
237  * @param file the .desktop file to load
238  * @param serviceTypes a list of files to parse If one of these paths is a relative path it
239  * will be resolved relative to the "kservicetypes5" subdirectory in QStandardPaths::GenericDataLocation.
240  * If the list is empty only the default set of properties will be treated specially and all other entries
241  * will be read as the JSON string type.
242  *
243  * @since 5.16
244  * @deprecated Since 5.92, use json files or embedded json metadata directly.
245  */
246  KCOREADDONS_DEPRECATED_VERSION(5, 92, "Use json files or embedded json metadata directly")
247  static KPluginMetaData fromDesktopFile(const QString &file, const QStringList &serviceTypes = QStringList());
248 #endif
249 
250  /**
251  * Load a KPluginMetaData instance from a .json file. Unlike the constructor with a single file argument,
252  * this ensure that only JSON format plugins are loaded and any other type is rejected.
253  *
254  * @param jsonFile the .json file to load
255  * @since 5.91
256  */
257  static KPluginMetaData fromJsonFile(const QString &jsonFile);
258 
259  /**
260  * @param directory The directory to search for plugins. If a relative path is given for @p directory,
261  * all entries of QCoreApplication::libraryPaths() will be checked with @p directory appended as a
262  * subdirectory. If an absolute path is given only that directory will be searched.
263  * @note Check if the returned KPluginMetaData is valid before continuing to use it.
264  *
265  * @param pluginId The Id of the plugin. The id should be the same as the filename, see KPluginMetaData::pluginId()
266  * @since 5.84
267  */
268  static KPluginMetaData findPluginById(const QString &directory, const QString &pluginId);
269 
270  /**
271  * Find all plugins inside @p directory. Only plugins which have JSON metadata will be considered.
272  *
273  * @param directory The directory to search for plugins. If a relative path is given for @p directory,
274  * all entries of QCoreApplication::libraryPaths() will be checked with @p directory appended as a
275  * subdirectory. If an absolute path is given only that directory will be searched.
276  *
277  * @param filter a callback function that returns @c true if the found plugin should be loaded
278  * and @c false if it should be skipped. If this argument is omitted all plugins will be loaded
279  *
280  * @return all plugins found in @p directory that fulfil the constraints of @p filter
281  * @since 5.86
282  */
283  static QVector<KPluginMetaData> findPlugins(const QString &directory, std::function<bool(const KPluginMetaData &)> filter = {});
284 
285  /**
286  * @since 5.91
287  */
288  static QVector<KPluginMetaData> findPlugins(const QString &directory, std::function<bool(const KPluginMetaData &)> filter, KPluginMetaDataOption option);
289 
290  /**
291  * @return whether this object holds valid information about a plugin.
292  * If this is @c true pluginId() will return a non-empty string.
293  */
294  bool isValid() const;
295 
296  /**
297  * @return whether this object should be hidden, this is usually not used for binary
298  * plugins, when loading a KPluginMetaData from a .desktop file, this will reflect
299  * the value of the "Hidden" key.
300  *
301  * @since 5.8
302  */
303  bool isHidden() const;
304 
305  /**
306  * @return the path to the plugin. This string can be passed to the KPluginLoader
307  * or QPluginLoader constructors in order to attempt to load this plugin.
308  * @note It is not guaranteed that this is a valid path to a shared library (i.e. loadable
309  * by QPluginLoader) since the metadata could also refer to a non-C++ plugin.
310  */
311  QString fileName() const;
312 
313  /**
314  * @return the file that the metadata was read from. This is not necessarily the same as
315  * fileName(), since not all plugins have the metadata embedded. The metadata could also be
316  * stored in a separate .desktop file.
317  *
318  * @since 5.5
319  */
320  QString metaDataFileName() const;
321 
322  /**
323  * @return the full metadata stored inside the plugin file.
324  */
325  QJsonObject rawData() const;
326 
327 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 86)
328  /**
329  * Tries to instantiate this plugin using KPluginMetaData::fileName().
330  * @note The value of KPluginMetaData::dependencies() is not used here, dependencies must be
331  * resolved manually.
332  *
333  * @return The plugin root object or @c nullptr if it could not be loaded
334  * @see QPluginLoader::instance(), KPluginFactory::loadFactory, KPluginFactory::instantiatePlugin
335  * @deprecated Since 5.86, use @ref KPluginFactory::loadFactory or @ref KPluginFactory::instantiatePlugin when using
336  * KPluginFactory. Otherwise use QPluginLoader::instance() instead.
337  */
338  KCOREADDONS_DEPRECATED_VERSION(5, 86, "See API docs")
339  QObject *instantiate() const;
340 #endif
341 
342  /**
343  * @return the user visible name of the plugin.
344  */
345  QString name() const;
346 
347  /**
348  * @return a short description of the plugin.
349  */
350  QString description() const;
351 
352 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 87)
353  /**
354  * @return additional information about this plugin (e.g. for use in an "about plugin" dialog)
355  *
356  * @since 5.18
357  * @deprecated Since 5.87, deprecate for lack of usage. Use a meaningful custom key in the json metadata instead
358  */
359  KCOREADDONS_DEPRECATED_VERSION(5, 87, "Deprecate for lack of usage, use a meaningful custom key in the json metadata instead")
360  QString extraInformation() const;
361 #endif
362 
363  /**
364  * @return the author(s) of this plugin.
365  */
366  QList<KAboutPerson> authors() const;
367 
368  /**
369  * @return the translator(s) of this plugin.
370  *
371  * @since 5.18
372  */
373  QList<KAboutPerson> translators() const;
374 
375  /**
376  * @return a list of people that contributed to this plugin (other than the authors and translators).
377  *
378  * @since 5.18
379  */
380  QList<KAboutPerson> otherContributors() const;
381 
382  /**
383  * @return the categories of this plugin (e.g. "playlist/skin").
384  */
385  QString category() const;
386 
387  /**
388  * @return the icon name for this plugin
389  * @see QIcon::fromTheme()
390  */
391  QString iconName() const;
392 
393  /**
394  * @return the short license identifier (e.g. LGPL).
395  * @see KAboutLicense::byKeyword() for retrieving the full license information
396  */
397  QString license() const;
398 
399  /**
400  * @return the text of the license, equivalent to KAboutLicense::byKeyword(license()).text()
401  * @since 5.73
402  */
403  QString licenseText() const;
404 
405  /**
406  * @return a short copyright statement
407  *
408  * @since 5.18
409  */
410  QString copyrightText() const;
411 
412  /**
413  * @return the internal name of the plugin
414  * If the Id property is not set in the metadata, this will return the
415  * plugin file name without the file extension.
416  */
417  QString pluginId() const;
418 
419  /**
420  * @return the version of the plugin.
421  */
422  QString version() const;
423 
424  /**
425  * @return the website of the plugin.
426  */
427  QString website() const;
428 
429  /**
430  * @return the website where people can report a bug found in this plugin
431  * @since 5.99
432  */
433  QString bugReportUrl() const;
434 
435 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 79)
436  /**
437  * @return a list of plugins that this plugin depends on so that it can function properly
438  * @see KJsonPluginInfo::pluginId()
439  * @deprecated Since 5.79, plugin dependencies are deprecated and will be removed in KF6
440  */
441  KCOREADDONS_DEPRECATED_VERSION(5, 79, "Plugin dependencies are deprecated and will be removed in KF6")
442  QStringList dependencies() const;
443 #endif
444 
445 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 89)
446  /**
447  * Returns the service types that this plugin implements.
448  *
449  * This is mostly for historical / compatibility purposes.
450  * As a general rule, instead of opening many plugins to then filter by servicetype,
451  * put all plugins of the same type in a subdirectory, that you can pass to findPlugins directly.
452  * No point in opening 20 plugins to pick out only 3, when the filesystem can do that filtering for you.
453  *
454  * @note Unlike KService this does not contain the MIME types. To get the handled MIME types
455  * use the KPluginMetaData::mimeTypes() function.
456  * @return a list of service types this plugin implements (e.g. "Plasma/DataEngine")
457  * @dprecated Since 5.89, use dedicated plugin namespaces instead to filter plugins of a specific type
458  */
459  KCOREADDONS_DEPRECATED_VERSION(5, 89, "See API docs")
460  QStringList serviceTypes() const;
461 #endif
462 
463  /**
464  * @return a list of MIME types this plugin can handle (e.g. "application/pdf", "image/png", etc.)
465  * @since 5.16
466  */
467  QStringList mimeTypes() const;
468 
469  /**
470  * @return true if this plugin can handle the given mimetype
471  * This is more accurate than mimeTypes().contains(mimeType) because it also
472  * takes MIME type inheritance into account.
473  * @since 5.66
474  */
475  bool supportsMimeType(const QString &mimeType) const;
476 
477  /**
478  * @return A string list of formfactors this plugin is useful for, e.g. desktop, tablet,
479  * handset, mediacenter, etc.
480  * The keys for this are not formally defined.
481  *
482  * @since 5.12
483  */
484  QStringList formFactors() const;
485 
486  /**
487  * @return whether the plugin should be enabled by default.
488  * This is only a recommendation, applications can ignore this value if they want to.
489  */
490  bool isEnabledByDefault() const;
491 
492 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 104)
493  /**
494  * @return the initial preference of the plugin.
495  * This is the preference to associate with this plugin initially (before
496  * the user has had any chance to define preferences for it).
497  * Higher values indicate stronger preference.
498  * @since 5.67
499  * @deprecated Since 5.104, this feature is only used in KParts, read the key manually if needed
500  */
501  KCOREADDONS_DEPRECATED_VERSION(5, 104, "This feature is only used in KParts, read the key manually if needed")
502  int initialPreference() const;
503 #endif
504 
505  /**
506  * Returns @c true if the plugin is enabled in @p config, otherwise returns isEnabledByDefault().
507  * This can be used in conjunctionwith KPluginWidget/KPluginSelector.
508  *
509  * The @p config param should be a KConfigGroup object, because KCoreAddons can not depend
510  * on KConfig directly, this parameter is a template.
511  * @param config KConfigGroup where the enabled state is stored
512  * @since 5.89
513  */
514  template<typename T>
515  bool isEnabled(const T &config) const
516  {
517  Q_ASSERT(config.isValid());
518  return config.readEntry(pluginId() + QLatin1String("Enabled"), isEnabledByDefault());
519  }
520 
521  /**
522  * @return the value for @p key from the metadata or @p defaultValue if the key does not exist
523  * or the value for @p key is not of type string
524  *
525  * @see KPluginMetaData::rawData() if QString is not the correct type for @p key
526  */
527  QString value(const QString &key, const QString &defaultValue = QString()) const;
528 
529 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 88)
530  /**
531  * Overload to make sure the bool overload is not taken by accident
532  * @overload
533  * @since 5.88
534  */
535  KCOREADDONS_DEPRECATED_VERSION(5, 88, "Construct a QString instead of using a char array, otherwise there the bool overload could be chosen by accident")
536  QString value(const QString &key, const char *ch) const
537  {
538  return value(key, QString::fromLatin1(ch));
539  }
540 #else
541  QString value(const QString &key, const char *ch) const = delete;
542 #endif
543 
544  /**
545  * @overload
546  * @since 5.88
547  */
548  bool value(const QString &key, bool defaultValue) const;
549 
550  /**
551  * @overload
552  * @since 5.88
553  */
554  int value(const QString &key, int defaultValue) const;
555 
556  /** @return the value for @p key from the metadata or @p defaultValue if the key does not exist.
557  * If the type of @p key is string, a list containing just that string will be returned.
558  * If the type is array, the list will contain one entry for each array member.
559  * @overload
560  * @since 5.88
561  */
562  QStringList value(const QString &key, const QStringList &defaultValue) const;
563 
564 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 88)
565  /** @return the value for @p key inside @p jo as a string list. If the type of @p key is string, a list with containing
566  * just that string will be returned, if it is an array the list will contain one entry for each array member.
567  * If the key cannot be found an empty list will be returned.
568  * @deprecated Since 5.88, use @p value(QString, QStringList) on KPluginMetaData instance instead
569  */
570  KCOREADDONS_DEPRECATED_VERSION(5, 88, "Use value(QString, QStringList) on KPluginMetaData instance instead")
571  static QStringList readStringList(const QJsonObject &jo, const QString &key);
572 #endif
573 
574 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 88)
575  /**
576  * Reads a value from @p jo but unlike QJsonObject::value() it allows different entries for each locale
577  * This is done by appending the locale identifier in brackets to the key (e.g. "[de_DE]" or "[es]")
578  * When looking for a key "foo" with German (Germany) locale we will first attempt to read "foo[de_DE]",
579  * if that does not exist "foo[de]", finally falling back to "foo" if that also doesn't exist.
580  * @return the translated value for @p key from @p jo or @p defaultValue if @p key was not found
581  * @deprecated Since 5.88, use KJsonUtils::readTranslatedValue instead
582  */
583  KCOREADDONS_DEPRECATED_VERSION(5, 88, "Use KJsonUtils::readTranslatedValue instead")
584  static QJsonValue readTranslatedValue(const QJsonObject &jo, const QString &key, const QJsonValue &defaultValue = QJsonValue());
585 #endif
586 
587 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 88)
588  /**
589  * @return the translated value of @p key from @p jo as a string or @p defaultValue if @p key was not found
590  * or the value for @p key is not of type string
591  * @see KPluginMetaData::readTranslatedValue(const QJsonObject &jo, const QString &key)
592  * @deprecated Since 5.88, use KJsonUtils::readTranslatedString instead
593  */
594  KCOREADDONS_DEPRECATED_VERSION(5, 88, "Use KJsonUtils::readTranslatedString instead")
595  static QString readTranslatedString(const QJsonObject &jo, const QString &key, const QString &defaultValue = QString());
596 #endif
597 
598  /**
599  * @return @c true if this object is equal to @p other, otherwise @c false
600  */
601  bool operator==(const KPluginMetaData &other) const;
602 
603  /**
604  * @return @c true if this object is not equal to @p other, otherwise @c false.
605  */
606  inline bool operator!=(const KPluginMetaData &other) const
607  {
608  return !(*this == other);
609  }
610 
611  /**
612  * @note for loading plugin the plugin independently of it being static/dynamic
613  * use @ref KPluginFactory::loadFactory or @ref KPluginFactory::instantiatePlugin.
614  * @return true if the instance represents a static plugin
615  * @since 5.89
616  */
617  bool isStaticPlugin() const;
618 
619 private:
620  KCOREADDONS_NO_EXPORT QJsonObject rootObject() const;
621 #if KCOREADDONS_BUILD_DEPRECATED_SINCE(5, 92)
622  KCOREADDONS_NO_EXPORT void loadFromDesktopFile(const QString &file, const QStringList &serviceTypes);
623 #endif
624  KCOREADDONS_NO_EXPORT void loadFromJsonFile(const QString &file);
625 
626 private:
627  KCOREADDONS_NO_EXPORT QVariantList authorsVariant() const;
628  KCOREADDONS_NO_EXPORT QVariantList translatorsVariant() const;
629  KCOREADDONS_NO_EXPORT QVariantList otherContributorsVariant() const;
630  KCOREADDONS_NO_EXPORT QStaticPlugin staticPlugin() const;
631  KCOREADDONS_NO_EXPORT QString requestedFileName() const;
632 
633  QJsonObject m_metaData;
634  QString m_fileName;
635  QExplicitlySharedDataPointer<KPluginMetaDataPrivate> d; // for future binary compatible extensions
636  friend class KPluginFactory;
637 };
638 
639 inline uint qHash(const KPluginMetaData &md, uint seed)
640 {
641  return qHash(md.pluginId(), seed);
642 }
643 
644 Q_DECLARE_METATYPE(KPluginMetaData)
645 
646 #endif // KPLUGINMETADATA_H
bool operator!=(const KPluginMetaData &other) const
KPluginMetaDataOption
Options for creating a KPluginMetaData object.
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
virtual QVariant rootObject()
KSharedConfigPtr config()
This class is used to store information about a person or developer.
Definition: kaboutdata.h:61
@ AllowEmptyMetaData
Plugins with empty metaData are considered valid.
unsigned int version()
Returns a numerical version number of KCoreAddons at run-time in the form 0xMMNNPP (MM = major,...
Definition: kcoreaddons.cpp:18
QString fromLatin1(const char *str, int size)
bool isValid(QStringView ifopt)
QString name(StandardShortcut id)
QStringList mimeTypes(Mode mode=Writing)
@ DoNotAllowEmptyMetaData
Plugins with empty metaData are considered invalid.
Category category(StandardShortcut id)
bool isEnabled(const T &config) const
Returns true if the plugin is enabled in config, otherwise returns isEnabledByDefault().
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Nov 28 2023 04:05:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.