File indexing completed on 2024-12-22 04:31:09
0001 #ifndef PLUGINMANAGER_H 0002 #define PLUGINMANAGER_H 0003 0004 #include "fmh.h" 0005 #include "mauilist.h" 0006 #include <QObject> 0007 #include <QQmlEngine> 0008 0009 namespace MauiKitPlugin 0010 { 0011 class Plugin : public QObject 0012 { 0013 Q_OBJECT 0014 }; 0015 0016 class Interface : public QObject 0017 { 0018 Q_OBJECT 0019 public: 0020 Interface(const QString &id, QObject *interface, QObject *parent = nullptr) 0021 : QObject(parent) 0022 , m_id(id) 0023 , m_interface(interface) 0024 { 0025 } 0026 0027 private: 0028 QString m_id; 0029 QObject *m_interface; 0030 }; 0031 0032 class PluginInterfacesModel : public QAbstractListModel 0033 { 0034 Q_OBJECT 0035 public: 0036 PluginInterfacesModel(QObject *parent = nullptr); 0037 void append(Interface *interface); 0038 bool contains(const QString &id); 0039 int rowCount(const QModelIndex &parent) const override; 0040 QVariant data(const QModelIndex &index, int role) const override; 0041 QHash<int, QByteArray> roleNames() const override; 0042 0043 private: 0044 QVector<Interface *> m_interfaces; // id 0045 }; 0046 0047 class PluginsModel : public MauiList 0048 { 0049 Q_OBJECT 0050 public: 0051 PluginsModel(QObject *parent = nullptr); 0052 FMH::MODEL_LIST items() const final override; 0053 void append(Plugin *plugin); 0054 0055 private: 0056 FMH::MODEL_LIST m_plugins; 0057 signals: 0058 }; 0059 0060 class PluginInterface : public QObject 0061 { 0062 Q_OBJECT 0063 Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) 0064 Q_PROPERTY(int type READ type WRITE setType NOTIFY typeChanged) 0065 Q_PROPERTY(int target READ target WRITE setTarget NOTIFY targetChanged) 0066 0067 public: 0068 static PluginInterface *qmlAttachedProperties(QObject *object) 0069 { 0070 return new PluginInterface(object); 0071 } 0072 void setOrientation(const uint &value); 0073 uint orintation() const 0074 { 0075 return m_orientation; 0076 } 0077 0078 void setType(const uint &value); 0079 uint type() const 0080 { 0081 return m_orientation; 0082 } 0083 0084 void setTarget(const uint &value); 0085 uint target() const 0086 { 0087 return m_orientation; 0088 } 0089 0090 private: 0091 using QObject::QObject; 0092 QObject m_interface; 0093 uint m_orientation; 0094 uint m_type; 0095 uint m_target; 0096 0097 signals: 0098 void orientationChanged(); 0099 void typeChanged(); 0100 void targetChanged(); 0101 }; 0102 0103 class PluginManager : public QObject 0104 { 0105 Q_OBJECT 0106 Q_PROPERTY(PluginsModel *plugins READ plugins FINAL CONSTANT) 0107 Q_PROPERTY(PluginInterfacesModel *interfaces READ interfaces FINAL CONSTANT) 0108 public: 0109 static PluginManager *instance() 0110 { 0111 static PluginManager manager; 0112 return &manager; 0113 } 0114 0115 PluginManager(const PluginManager &) = delete; 0116 PluginManager &operator=(const PluginManager &) = delete; 0117 PluginManager(PluginManager &&) = delete; 0118 PluginManager &operator=(PluginManager &&) = delete; 0119 0120 void registerInterface(QObject *interface, const QString &id); 0121 PluginsModel *plugins() const 0122 { 0123 return m_plugins; 0124 } 0125 PluginInterfacesModel *interfaces() const 0126 { 0127 return m_interfaces; 0128 } 0129 0130 private: 0131 PluginManager(QObject *parent = nullptr); 0132 QObject m_interface; 0133 PluginsModel *m_plugins; 0134 PluginInterfacesModel *m_interfaces; 0135 0136 signals: 0137 void interfacesChanged(); 0138 }; 0139 } 0140 0141 #endif // PLUGINMANAGER_H