KCoreAddons

kpluginmetadata.h
1 /*
2  This file is part of the KDE project
3 
4  SPDX-FileCopyrightText: 2014 Alex Richardson <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-only
7 */
8 
9 #ifndef KPLUGINMETADATA_H
10 #define KPLUGINMETADATA_H
11 
12 #include "kcoreaddons_export.h"
13 
14 #include <QExplicitlySharedDataPointer>
15 #include <QJsonObject>
16 #include <QString>
17 #include <QStringList>
18 #include <QMetaType>
19 
20 #include <functional>
21 
22 class KPluginLoader;
23 class QPluginLoader;
24 class QStringList;
25 class KPluginMetaDataPrivate;
26 class KAboutPerson;
27 class QObject;
28 
29 
88 class KCOREADDONS_EXPORT KPluginMetaData
89 {
90  Q_GADGET
91  Q_PROPERTY(bool isValid READ isValid CONSTANT)
92  Q_PROPERTY(bool isHidden READ isHidden CONSTANT)
93  Q_PROPERTY(QString fileName READ fileName CONSTANT)
94  Q_PROPERTY(QString metaDataFileName READ metaDataFileName CONSTANT)
95  Q_PROPERTY(QJsonObject rawData READ rawData CONSTANT)
96  Q_PROPERTY(QString name READ name CONSTANT)
97  Q_PROPERTY(QString description READ description CONSTANT)
98  Q_PROPERTY(QString extraInformation READ extraInformation CONSTANT)
99  Q_PROPERTY(QVariantList authors READ authorsVariant CONSTANT)
100  Q_PROPERTY(QVariantList translators READ translatorsVariant CONSTANT)
101  Q_PROPERTY(QVariantList otherContributors READ otherContributorsVariant CONSTANT)
102  Q_PROPERTY(QString category READ category CONSTANT)
103  Q_PROPERTY(QString iconName READ iconName CONSTANT)
104  Q_PROPERTY(QString license READ license CONSTANT)
105  Q_PROPERTY(QString licenseText READ licenseText CONSTANT)
106  Q_PROPERTY(QString copyrightText READ copyrightText CONSTANT)
107  Q_PROPERTY(QString pluginId READ pluginId CONSTANT)
108  Q_PROPERTY(QString version READ version CONSTANT)
109  Q_PROPERTY(QString website READ website CONSTANT)
110  Q_PROPERTY(QStringList dependencies READ dependencies CONSTANT)
111  Q_PROPERTY(QStringList serviceTypes READ serviceTypes CONSTANT)
112  Q_PROPERTY(QStringList mimeTypes READ mimeTypes CONSTANT)
113  Q_PROPERTY(QStringList formFactors READ formFactors CONSTANT)
114  Q_PROPERTY(bool isEnabledByDefault READ isEnabledByDefault CONSTANT)
115  Q_PROPERTY(int initialPreference READ isEnabledByDefault CONSTANT)
116 
117 public:
118 
120  KPluginMetaData();
121 
126  KPluginMetaData(const KPluginLoader &loader);
127 
132  KPluginMetaData(const QPluginLoader &loader);
133 
149  KPluginMetaData(const QString &file);
150 
157  KPluginMetaData(const QJsonObject &metaData, const QString &file);
158 
159  // TODO: KF6: merge with the above and make metaDataFile default to QString()
171  KPluginMetaData(const QJsonObject &metaData, const QString &pluginFile, const QString &metaDataFile);
172 
180  KPluginMetaData &operator=(const KPluginMetaData &);
184  ~KPluginMetaData();
185 
204  static KPluginMetaData fromDesktopFile(const QString &file, const QStringList &serviceTypes = QStringList());
205 
210  bool isValid() const;
211 
219  bool isHidden() const;
220 
227  QString fileName() const;
228 
236  QString metaDataFileName() const;
237 
241  QJsonObject rawData() const;
242 
243 
252  QObject *instantiate() const;
253 
257  QString name() const;
258 
262  QString description() const;
263 
269  QString extraInformation() const;
270 
274  QList<KAboutPerson> authors() const;
275 
281  QList<KAboutPerson> translators() const;
282 
288  QList<KAboutPerson> otherContributors() const;
289 
293  QString category() const;
294 
299  QString iconName() const;
300 
305  QString license() const;
306 
311  QString licenseText() const;
312 
318  QString copyrightText() const;
319 
325  QString pluginId() const;
326 
330  QString version() const;
331 
335  QString website() const;
336 
341  QStringList dependencies() const;
342 
355  QStringList serviceTypes() const;
356 
361  QStringList mimeTypes() const;
362 
369  bool supportsMimeType(const QString &mimeType) const;
370 
378  QStringList formFactors() const;
379 
384  bool isEnabledByDefault() const;
385 
393  int initialPreference() const;
394 
401  QString value(const QString &key, const QString &defaultValue = QString()) const;
402 
407  static QStringList readStringList(const QJsonObject &jo, const QString &key);
408 
416  static QJsonValue readTranslatedValue(const QJsonObject &jo, const QString &key, const QJsonValue &defaultValue = QJsonValue());
417 
423  static QString readTranslatedString(const QJsonObject &jo, const QString &key, const QString &defaultValue = QString());
424 
428  bool operator==(const KPluginMetaData &other) const;
429 
433  inline bool operator!=(const KPluginMetaData &other) const
434  {
435  return !(*this == other);
436  }
437 private:
438  QJsonObject rootObject() const;
439  void loadFromDesktopFile(const QString &file, const QStringList &serviceTypes);
440 private:
441  QVariantList authorsVariant() const;
442  QVariantList translatorsVariant() const;
443  QVariantList otherContributorsVariant() const;
444 
445  QJsonObject m_metaData;
446  QString m_fileName;
447  QExplicitlySharedDataPointer<KPluginMetaDataPrivate> d; // for future binary compatible extensions
448 };
449 
450 inline uint qHash(const KPluginMetaData &md, uint seed)
451 {
452  return qHash(md.pluginId(), seed);
453 }
454 
455 Q_DECLARE_METATYPE(KPluginMetaData)
456 
457 #endif // KPLUGINMETADATA_H
This class behaves largely like QPluginLoader (and, indeed, uses it internally), but additionally rea...
Definition: kpluginloader.h:60
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
This class is used to store information about a person or developer.
Definition: kaboutdata.h:55
bool operator!=(const KPluginMetaData &other) const
This class allows easily accessing some standardized values from the JSON metadata that can be embedd...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Dec 4 2020 23:02:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.