#ifndef PatchServer_H
#define PatchServer_H

#include "..\..\Basic\Abschnitt.h"
#include "..\..\..\Netzwerk\Main\MSKlient.h"
#include "..\..\..\Netzwerk\Patch\PSKlient.h"
#include "..\..\..\Ressourcen\Ressourcen.h"
#include <InitDatei.h>
#include <Knopf.h>
#include <Tabelle.h>
#include <Thread.h>
#include <Fortschritt.h>

class AdminAccount; // Login.h
class PatchServer; // PatchServer.h

class PSUpdate : public Thread
{
private:
	PatchServer *zPSA;
	AdminAccount *account;
	PSKlient *psc;
	int gruppeAnzahl;
	int *gruppeId;
	int id;
	int ref;

public:
	// Kontruktor
	PSUpdate( PatchServer *zPSA, AdminAccount *account );
	// Destruktor
	~PSUpdate();
	// nicht constant
	void setServer( const char *ip, unsigned short port );
	void setUpdateListe( int gAnzahl, Array< int > *gId );
	virtual void thread();
	// constant

	// Reference Counting
	PSUpdate *getThis();
	PSUpdate *release();
};

class PSDetails : public Thread
{
private:
	PatchServer *zPSA;
    MSKlient *mk;
	int id;
	int ref;

public:
	// Konstruktor
	PSDetails( PatchServer *zPSA, MSKlient *mk );
	// Destruktor
	~PSDetails();
	// nicht constant
	void setServerId( int id );
	virtual void thread();
	// constant

	// Reference Counting
	PSDetails *getThis();
	PSDetails *release();
};

class PSSuche : public Thread
{
private:
	PatchServer *zPSA;
	MSKlient *mk;
	int ref;

public:
	// Konstruktor
	PSSuche( PatchServer *zPSA, MSKlient *mk );
	// Destruktor
	~PSSuche();
	// nicht constant
	virtual void thread();
	// constant

	// Reference Counting
	PSSuche *getThis();
	PSSuche *release();
};

class PatchServer : public Abschnitt
{
private:
	Fenster *fenster;
	Fenster *liste;
	Fenster *details;
	Fenster *updateF;
	MSKlient *msk;
	InitDatei *iD;
	Fenster *f;
	AdminAccount *account;
	Knopf *aktualisieren;
	Knopf *weiter;
	Knopf *zur�ck;
	ObjTabelle *tabelle;
	ObjTabelle *updateT;
	PSSuche *suchen;
	PSDetails *getDetails;
	PSUpdate *updateTh;
	Schrift *schrift;
	PSKlient *psc;
	TextFeld *serverId;
	TextFeld *serverName;
	TextFeld *serverIp;
	TextFeld *serverPort;
	TextFeld *serverAPort;
	TextFeld *serverClients;
	TextFeld *serverMaxClients;
	TextFeld *maxClients;
	TextFeld *serverStatus;
	TextFeld *serverFehler;
	Knopf *updateStarten;
	Knopf *update;
	Knopf *pausieren;
	Knopf *stoppen;
	Knopf *beenden;
	Knopf *terminieren;
	Knopf *setMaxClients;
	Zeichnung *obj;
	int ref;

public:
	// Konstruktor
	PatchServer( Schrift *s, InitDatei *d, MSKlient *msk, RessourceBild *rb, AdminAccount *acc, Bildschirm *b );
	// Destruktor
	~PatchServer();
	// nicht constant
	virtual void setFenster( Fenster *f );
	virtual void setSichtbar( bool s );
	void addServer( int id, char *name, char *ip, int port, int adminPort, char *status );
	void sucheAbgeschlossen();
	void setServerDetails( int id, char *name, char *ip, int port, int adminPort, int clients, int maxClients, int status, Text *error );
	void setUpdateProzent( int prozent, int gruppe );
	void setUpdateFertig( bool error, int gruppe );
	bool aktualisierenMausEreignis( void *o, MausEreignis me );
	bool auswahlKnopfMausEreignis( void *o, MausEreignis me );
	bool weiterMausEreignis( void *o, MausEreignis me );
	bool zur�ckMausEreignis( void *o, MausEreignis me );
	bool updateMausEreignis( void *o, MausEreignis me );
	bool pausierenMausEreignis( void *o, MausEreignis me );
	bool stoppenMausEreignis( void *o, MausEreignis me );
	bool beendenMausEreignis( void *o, MausEreignis me );
	bool terminierenMausEreignis( void *o, MausEreignis me );
	bool setMaxClientsMausEreignis( void *o, MausEreignis me );
	bool updateStartenMausEreignis( void *o, MausEreignis me );
	bool maxClientsTastaturEreignis( void *o, TastaturEreignis te );
	// constant

	// Reference Counting
	virtual Abschnitt *getThis();
	virtual Abschnitt *release();
};

// Ereignisse
bool patchServerAktualisierenMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerAuswahlKnopfMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerWeiterMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerZur�ckMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerUpdateMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerPausierenMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerStoppenMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerBeendenMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerTerminierenMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerSetMaxClientsMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerUpdateStartenMausEreignis( void *p, void *o, MausEreignis me );
bool patchServerMaxClientsTastaturEreignis( void *p, void *o, TastaturEreignis te );

#endif