File indexing completed on 2024-05-05 05:50:42
0001 /* 0002 SPDX-FileCopyrightText: 2016 Elvis Angelaccio <elvis.angelaccio@kde.org> 0003 0004 SPDX-License-Identifier: BSD-2-Clause 0005 */ 0006 0007 #ifndef PLUGIN_H 0008 #define PLUGIN_H 0009 0010 #include "kerfuffle_export.h" 0011 0012 #include <QObject> 0013 0014 #include <KPluginMetaData> 0015 0016 namespace Kerfuffle 0017 { 0018 class KERFUFFLE_EXPORT Plugin : public QObject 0019 { 0020 Q_OBJECT 0021 0022 /** 0023 * The priority of the plugin. The higher the better. 0024 */ 0025 Q_PROPERTY(int priority READ priority CONSTANT) 0026 0027 /** 0028 * Whether the plugin has been enabled in the settings. 0029 */ 0030 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged MEMBER m_enabled) 0031 0032 /** 0033 * Whether the plugin is read-write *at runtime*. 0034 * A plugin could be declared read-write at build-time but "downgraded" to read-only at runtime. 0035 */ 0036 Q_PROPERTY(bool readWrite READ isReadWrite CONSTANT) 0037 0038 /** 0039 * The list of executables required by the plugin to operate in read-only mode. 0040 */ 0041 Q_PROPERTY(QStringList readOnlyExecutables READ readOnlyExecutables CONSTANT) 0042 0043 /** 0044 * The list of executables required by the plugin to operate in read-write mode. 0045 * This is an empty list if the plugin is declared as read-only. 0046 */ 0047 Q_PROPERTY(QStringList readWriteExecutables READ readWriteExecutables CONSTANT) 0048 0049 /** 0050 * The plugin's JSON metadata. This provides easy access to the supported mimetypes list. 0051 */ 0052 Q_PROPERTY(KPluginMetaData metaData READ metaData MEMBER m_metaData CONSTANT) 0053 0054 public: 0055 explicit Plugin(QObject *parent = nullptr, const KPluginMetaData &metaData = KPluginMetaData()); 0056 0057 int priority() const; 0058 bool isEnabled() const; 0059 void setEnabled(bool enabled); 0060 bool isReadWrite() const; 0061 QStringList readOnlyExecutables() const; 0062 QStringList readWriteExecutables() const; 0063 KPluginMetaData metaData() const; 0064 0065 /** 0066 * @return Whether the executables required for a functional plugin are installed. 0067 * This is true if all the read-only executables are found in the path. 0068 */ 0069 bool hasRequiredExecutables() const; 0070 0071 /** 0072 * @return Whether the plugin is ready to be used. 0073 * This implies isEnabled(), while an enabled plugin may not be valid. 0074 * A read-write plugin downgraded to read-only is still valid. 0075 */ 0076 bool isValid() const; 0077 0078 Q_SIGNALS: 0079 void enabledChanged(); 0080 0081 private: 0082 /** 0083 * @return Whether all the given executables are found in $PATH. 0084 */ 0085 static bool findExecutables(const QStringList &executables); 0086 0087 bool m_enabled; 0088 KPluginMetaData m_metaData; 0089 }; 0090 0091 } 0092 0093 #endif