#ifndef DEVICE_WATCHER_H
#define DEVICE_WATCHER_H

#include <QSystemTrayIcon>
#include <QMenu>
#include <pithread.h>
#include "SH_builtin.h"
#include "SH_plugins.h"
#include "SH_plugins_loader.h"


class DeviceWatcher: public QObject, public PIThread {
	Q_OBJECT
	PIOBJECT_SUBCLASS(DeviceWatcher, PIThread)
public:
	explicit DeviceWatcher();
	~DeviceWatcher();
	
private:
	struct DeviceType {
		QIcon icon;
		QString designer_path;
		QString designer_name;
		QString str_request;
		QString str_answer;
		PIByteArray request;
		SHS::Command answer;
	};

	void run() override;
	void checkDevice(const PIString & path);
	void collectDeviceTypes();

	QSystemTrayIcon tray;
	QMenu menu;
	QAction * sep, * last;
	SHPluginBasePacket * hexplugin;
	QList<QAction*> actions;
	PIVector<DeviceType> devices;
	PISet<PIString> prev_ser;
	
private slots:
	void addAction(QAction * a);
	void removeAction(QAction * a);
	void actionTriggered();
	void messageTriggered();
	void pluginsTriggered();
	
};

#endif // DEVICE_WATCHER_H
