#ifndef SERVER_MANAGER_H
#define SERVER_MANAGER_H

#include <QWidget>
#include "ui_server_manager.h"
#include "serverdesigner_core.h"
#include "SH_client_channel.h"


class ServerManager: public QWidget, public PIObject, public Ui::ServerManager {
	Q_OBJECT
	PIOBJECT(ServerManager)
public:
	explicit ServerManager(QWidget * parent = 0);
	~ServerManager();


private:
	void timerEvent(QTimerEvent * e) override;
	void sendIdentification();
	void setVariables(const PIVector<ServerVariable> & variables);
	void waitForReconnect(QString msg);
	bool askPassword(PIString server_name);
	EVENT_HANDLER(void, connected);
	EVENT_HANDLER(void, disconnected);
	EVENT_HANDLER1(void, receiveEvent, PIByteArray, data);

	int timer_pip;
	bool need_reconnect = false;
	SHClientChannel channel;
	PacketServerInfo last_server;
	PacketIdentification last_ident;
	QMap<PIString, PIByteArray> passwords;
	PropertyStorage parameters;
	QMap<int, QString> log_category;
	QMap<QString, int> param_id;

public slots:
	void disconnect();

private slots:
	void on_buttonUploadBAF_clicked();
	void on_buttonRestart_clicked();
	void on_buttonParametersApply_clicked();
	void on_buttonWaitCancel_clicked();
	void on_treeServers_serverSelected(PacketServerInfo info);

signals:
	void requestBAF(QByteArray *);
	void scriptError(int, QString, QString, QString);

};


#endif
