/***************************************************************************
*                                                                          *
*   This program is free software; you can redistribute it and/or modify   *
*   it under the terms of the GNU General Public License as published by   *
*   the Free Software Foundation; either version 3 of the License, or      *
*   (at your option) any later version.                                    *
*                                                                          *
***************************************************************************/


#ifndef GLOBALHOTKEYS_H
	#define GLOBALHOTKEYS_H


#include <qguardedptr.h>
#include <qmap.h>
#include <qstring.h>
#include <qtimer.h>
#include <qvaluelist.h>

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

#include "hotkey.h"
#include "hotkeyedit.h"

#include <X11/Xlib.h>
#include <X11/keysym.h>

#include "defines.h"


static int messageshandled;
void EmptyMsgHandler( QtMsgType type, const char *msg );


struct ContactsMenuItemData
{
	bool currentchats;
	bool recentchats;
	bool onlinecontacts;
	QStringList onlinecontactsgroups;
	bool onlinecontactsincludeblocking;
	QStringList contacts;
	QStringList groups;
};


class GlobalHotkeys : public ConfigurationUiHandler, ConfigurationAwareObject
{
	Q_OBJECT
	public:
		GlobalHotkeys();
		~GlobalHotkeys();
		void mainConfigurationWindowCreated( MainConfigurationWindow *mainConfigurationWindow );
	protected:
		void configurationUpdated();
	private slots:
		void contactsAddNewButtonPressed();
		void contactsmenusAddNewButtonPressed();
		void checkPendingHotkeys();
		void showAndActivateToplevel();
		void openContactsMenuChat( int n );
		void contactsmenuinactivitytimerTimeout();
	private:
		void createDefaultConfiguration();
		void grabHotkeys( QMap<QString,Hotkey*> hotkeys );
		QIconSet contactsMenuIcon( QIconSet chaticon, QIconSet statusicon );
		void createContactsMenuIcons();
		QTimer *hotkeysTimer;
		Display *display;
		QMap<QString,Hotkey*> hotkeys;
		QGuardedPtr<OpenChatWith> openchatwithwindow;
		QPopupMenu *contactsmenu;
		QMap<QString,QIconSet> contactsmenuicons;
		QValueList<UserListElements> contactsmenuusers;
		QValueList<QWidget*> contactsmenuwindows;
		QTimer *contactsmenuinactivitytimer;
		bool contactsmenushown;
		QString lastcontactsmenushortcut;
		ConfigGroupBox *groupKadu, *groupChats, *groupContacts, *groupContactsMenus;
		QGuardedPtr<HotkeyEdit> HEshowKadusMainWindow, HEhideKadusMainWindow, HEshowHideKadusMainWindow,
			HEopenIncomingChatWindow, HEopenAllIncomingChatWindows, HEminimizeOpenedChatWindows,
			HErestoreMinimizedChatWindows, HEminimizeRestoreChatWindows, HEcloseAllChatWindows,
			HEopenChatWith;
		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 minimizeRestoreChatWindows;    // configuration value
		QString closeAllChatWindows;           // configuration value
		QString openChatWith;                  // configuration value
		// <---
		QGuardedPtr<ConfigActionButton>           contactsAddNewButton;
		QValueList< QGuardedPtr<ConfigLineEdit> > contactsNamesEditList;
		QValueList< QGuardedPtr<HotkeyEdit> >     contactsHotkeyEditList;
		QValueList< QPair<QStringList,QString> >  contactsshortcuts;
		QGuardedPtr<ConfigActionButton>                   contactsmenusAddNewButton;
		QValueList< QGuardedPtr<HotkeyEdit> >             contactsmenusHotkeyEditList;
		QValueList< QGuardedPtr<ConfigCheckBox> >         contactsmenusCurrentChatsCheckboxList;
		QValueList< QGuardedPtr<ConfigCheckBox> >         contactsmenusRecentChatsCheckboxList;
		QValueList< QGuardedPtr<ConfigCheckBox> >         contactsmenusOnlineContactsCheckboxList;
		QValueList< QGuardedPtr<ConfigLineEdit> >         contactsmenusOnlineContactsGroupsEditList;
		QValueList< QGuardedPtr<ConfigCheckBox> >         contactsmenusOnlineContactsIncludeBlockingCheckboxList;
		QValueList< QGuardedPtr<ConfigLineEdit> >         contactsmenusContactsEditList;
		QValueList< QGuardedPtr<ConfigLineEdit> >         contactsmenusGroupsEditList;
		QValueList< QPair<ContactsMenuItemData,QString> > contactsmenusshortcuts;
		// <---
};


extern GlobalHotkeys *globalHotkeys;


#endif
