1 /* 2 SPDX-FileCopyrightText: 2016 Elvis Angelaccio <elvis.angelaccio@kde.org> 3 4 SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7 #ifndef PLUGIN_H 8 #define PLUGIN_H 9 10 #include "kerfuffle_export.h" 11 12 #include <QObject> 13 14 #include <KPluginMetaData> 15 16 namespace Kerfuffle 17 { 18 19 class KERFUFFLE_EXPORT Plugin : public QObject 20 { 21 Q_OBJECT 22 23 /** 24 * The priority of the plugin. The higher the better. 25 */ 26 Q_PROPERTY(int priority READ priority CONSTANT) 27 28 /** 29 * Whether the plugin has been enabled in the settings. 30 */ 31 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged MEMBER m_enabled) 32 33 /** 34 * Whether the plugin is read-write *at runtime*. 35 * A plugin could be declared read-write at build-time but "downgraded" to read-only at runtime. 36 */ 37 Q_PROPERTY(bool readWrite READ isReadWrite CONSTANT) 38 39 /** 40 * The list of executables required by the plugin to operate in read-only mode. 41 */ 42 Q_PROPERTY(QStringList readOnlyExecutables READ readOnlyExecutables CONSTANT) 43 44 /** 45 * The list of executables required by the plugin to operate in read-write mode. 46 * This is an empty list if the plugin is declared as read-only. 47 */ 48 Q_PROPERTY(QStringList readWriteExecutables READ readWriteExecutables CONSTANT) 49 50 /** 51 * The plugin's JSON metadata. This provides easy access to the supported mimetypes list. 52 */ 53 Q_PROPERTY(KPluginMetaData metaData READ metaData MEMBER m_metaData CONSTANT) 54 55 public: 56 explicit Plugin(QObject *parent = nullptr, const KPluginMetaData& metaData = KPluginMetaData()); 57 58 59 int priority() const; 60 bool isEnabled() const; 61 void setEnabled(bool enabled); 62 bool isReadWrite() const; 63 QStringList readOnlyExecutables() const; 64 QStringList readWriteExecutables() const; 65 KPluginMetaData metaData() const; 66 67 /** 68 * @return Whether the executables required for a functional plugin are installed. 69 * This is true if all the read-only executables are found in the path. 70 */ 71 bool hasRequiredExecutables() const; 72 73 /** 74 * @return Whether the plugin is ready to be used. 75 * This implies isEnabled(), while an enabled plugin may not be valid. 76 * A read-write plugin downgraded to read-only is still valid. 77 */ 78 bool isValid() const; 79 80 Q_SIGNALS: 81 void enabledChanged(); 82 83 private: 84 85 /** 86 * @return Whether all the given executables are found in $PATH. 87 */ 88 static bool findExecutables(const QStringList &executables); 89 90 bool m_enabled; 91 KPluginMetaData m_metaData; 92 }; 93 94 } 95 96 #endif 97