#ifndef SH_plugins_manager_H
#define SH_plugins_manager_H

#include "SH_plugins_web.h"
#include "SH_plugins_loader.h"


class SHPluginsManager: public QObject {
	Q_OBJECT
public:
	SHPluginsManager();
	~SHPluginsManager();

	struct Plugin {
		enum Flag {
			Installed    = 0x01,
			Available    = 0x02,
			Loaded       = 0x04,
			Error        = 0x08,
			UpToDate     = 0x10,
			Upgradable   = 0x20,
			Downgradable = 0x40,
			Disabled     = 0x80,
		};
		void check(const SHPluginsLoader & loader);
		QString displayVersion() const;
		SHPluginManifest validManifest() const;
		SHPluginManifest web;
		SHPluginManifest local;
		QString plugins_list, error;
		PIFlags<Flag> flags;
	};

	SHPluginsWeb & webInterface() {return web;}
	SHPluginsLoader & localInterface() {return loader;}
	QStringList notLoadedPlugins() const {return remain_plugins;}

	PIVector<SHPluginsManager::Plugin> allPlugins() const {return plugin_by_name.values();}

	void update(const QStringList & names);
	void remove(const QStringList & names);
	void load(const QStringList & names);
	void unload(const QStringList & names);
	void enable(const QStringList & names);
	void disable(const QStringList & names);
	bool loadMandatory(const QStringList & names);
	void updateAll();
	
private:
	static QString pluginsStat(const PIVector<SHPluginsLoader::PluginInfo> & list);
	void updateInfo();

	SHPluginsWeb web;
	SHPluginsLoader loader;
	PIMap<QString, Plugin> plugin_by_name;
	QStringList remain_plugins;

public slots:
	
signals:
	void infoChanged();
	
};

#endif
