#ifndef __PLUGINMANAGER_H__
#define __PLUGINMANAGER_H__


#include <QObject>
#include <QMap>
#include <QDesignerCustomWidgetInterface>
#include "pluginloader.h"

typedef struct
{
    QString fileName;
    QString filePath;
    bool isEnabled;
}plugin_info_st;

class PluginManager : public QObject
{
    Q_OBJECT

public:
    explicit PluginManager(QObject *parent = nullptr);
    ~PluginManager();

    void initPluginInfo();
    void savePluginInfo();
    void loadPlugins();
    void loadPlugin(QString fileName);
    void unloadPlugin(QString fileName);
    bool delPlugin(QString fileName, bool kepInfo = false);
    bool upgradePlugin(QString fileName, QString srcFile);
    bool addPlugin(QString srcFile);
    bool contains(QString fileName);
    void clear();

    QList<plugin_info_st> pluginInfoList() const;
    QList<QDesignerCustomWidgetInterface *> customWidgets() const;

private:
    QMap<QString, plugin_info_st> m_pluginInfoMap;
    QMap<QString, PluginLoader *> m_pluginLoaderMap;
    QList<QDesignerCustomWidgetInterface*> m_customWidgets;     // 插件控件列表
};

#endif  // PLUGINMANAGER_H