#ifndef GLOBALHOTKEYS_H
	#define GLOBALHOTKEYS_H


#include <qmap.h>
#include <qthread.h>

#include "configuration_aware_object.h"
#include "main_configuration_window.h"

#include "globalhotkeys.h"

#include <X11/Xlib.h>


#define  GLOBALHOTKEYS_X11SHIFTMASK        ShiftMask
#define  GLOBALHOTKEYS_X11CONTROLMASK    ControlMask
#define  GLOBALHOTKEYS_X11ALTMASK           Mod1Mask
#define  GLOBALHOTKEYS_X11ALTGRMASK         Mod5Mask
#define  GLOBALHOTKEYS_X11SUPERMASK         Mod4Mask
#define  GLOBALHOTKEYS_X11CAPSLOCKMASK      LockMask
#define  GLOBALHOTKEYS_X11NUMLOCKMASK       Mod2Mask


class Hotkey
{
	public:
		Hotkey( bool _shift, bool _control, bool _alt, bool _altgr, bool _super, int _keycode, QString _comment = "" );
		Hotkey( QString hotkeystring );
		bool equals( Hotkey *h );
		bool shift;
		bool control;
		bool alt;
		bool altgr;
		bool super;
		int keycode;
		QString comment;
};


class HotkeyThread : public QThread
{
	public:
		void setDisplay( Display *_display );
		void setHotkeys( QMap<QString,Hotkey*> _hotkeys );
		void run();
	private:
		Display *display;
		QMap<QString,Hotkey*> hotkeys;
};


class GlobalHotkeys : public ConfigurationUiHandler, ConfigurationAwareObject
{
	Q_OBJECT
	public:
		GlobalHotkeys();
		~GlobalHotkeys();
		void mainConfigurationWindowCreated( MainConfigurationWindow *mainConfigurationWindow );
	protected:
		void configurationUpdated();
	private:
		void createDefaultConfiguration();
		int grabHotkeys( QMap<QString,Hotkey*> hotkeys );
		HotkeyThread hotkeyThread;
		Display *display;
		QString showKadusMainWindow;           // configuration value
		QString hideKadusMainWindow;           // configuration value
		QString showHideKadusMainWindow;       // configuration value
		QString openIncomingChatWindow;        // configuration value
		QString openAllIncomingChatWindows;    // configuration value
		QString minimizeOpenedChatWindows;     // configuration value
		QString restoreMinimizedChatWindows;   // configuration value
		QString closeAllChatWindows;           // configuration value
		QString openChatWith;                  // configuration value
};


extern GlobalHotkeys *globalHotkeys;


#endif
