summary refs log tree commit diff stats
path: root/plugins
diff options
context:
space:
mode:
authorBerke Viktor <bviktor@hexchat.org>2012-10-29 00:32:59 +0100
committerBerke Viktor <bviktor@hexchat.org>2012-10-29 00:32:59 +0100
commit15c2ff2d549fad936789ea29455d3ae8ef665c59 (patch)
tree9b8ed5de539b8e9935bb6821de5c658340644dd8 /plugins
parent9a57ca41b1629c239301d9b65563f6acb169ead1 (diff)
Convert HexTray to the plugin config API
Diffstat (limited to 'plugins')
-rw-r--r--plugins/hextray/hextray-xp.vcxproj4
-rw-r--r--plugins/hextray/hextray.cpp35
-rw-r--r--plugins/hextray/hextray.h6
-rw-r--r--plugins/hextray/hextray.vcxproj4
-rw-r--r--plugins/hextray/resource.rc2
-rw-r--r--plugins/hextray/utility.cpp216
-rw-r--r--plugins/hextray/utility.h9
7 files changed, 52 insertions, 224 deletions
diff --git a/plugins/hextray/hextray-xp.vcxproj b/plugins/hextray/hextray-xp.vcxproj
index 72d1599e..02d9333a 100644
--- a/plugins/hextray/hextray-xp.vcxproj
+++ b/plugins/hextray/hextray-xp.vcxproj
@@ -21,14 +21,14 @@
     <ConfigurationType>DynamicLibrary</ConfigurationType>

     <UseDebugLibraries>false</UseDebugLibraries>

     <WholeProgramOptimization>true</WholeProgramOptimization>

-    <CharacterSet>Unicode</CharacterSet>

+    <CharacterSet>MultiByte</CharacterSet>

     <PlatformToolset>WDK7</PlatformToolset>

   </PropertyGroup>

   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">

     <ConfigurationType>DynamicLibrary</ConfigurationType>

     <UseDebugLibraries>false</UseDebugLibraries>

     <WholeProgramOptimization>true</WholeProgramOptimization>

-    <CharacterSet>Unicode</CharacterSet>

+    <CharacterSet>MultiByte</CharacterSet>

     <PlatformToolset>WDK7</PlatformToolset>

   </PropertyGroup>

   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

diff --git a/plugins/hextray/hextray.cpp b/plugins/hextray/hextray.cpp
index 9741e5f7..e18c973e 100644
--- a/plugins/hextray/hextray.cpp
+++ b/plugins/hextray/hextray.cpp
@@ -75,15 +75,42 @@ int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name, char **pl
 

 	*plugin_name	= "HexTray";

 	*plugin_desc	= "Minimize HexChat to the Windows system tray";

-	*plugin_version = "1.2.4";

+	*plugin_version = "1.3.0";

+

+	char buffer[256];

+

+	/***************************************************************************************************************************/

+	/************************* Initialize our preferences if they don't exist yet **********************************************/

+	/***************************************************************************************************************************/

+

+	if (xchat_pluginpref_get_int (ph, "settings") == -1)

+	{

+		xchat_pluginpref_set_int (ph, "settings", HT_DEF_SET);

+	}

+	if (xchat_pluginpref_get_int (ph, "aot") == -1)

+	{

+		xchat_pluginpref_set_int (ph, "aot", HT_DEF_AOT);

+	}

+	if (xchat_pluginpref_get_int (ph, "key") == -1)

+	{

+		xchat_pluginpref_set_int (ph, "key", HT_DEF_KEY);

+	}

+	if (xchat_pluginpref_get_int (ph, "mod") == -1)

+	{

+		xchat_pluginpref_set_int (ph, "mod", HT_DEF_MOD);

+	}

+	if (xchat_pluginpref_get_str (ph, "away", buffer) == 0)

+	{

+		xchat_pluginpref_set_str (ph, "away", "");

+	}

 

 	/***************************************************************************************************************************/

-	/************************* Load our preferances from xTray.ini *************************************************************/

+	/************************* Load our preferences ****************************************************************************/

 	/***************************************************************************************************************************/

 	LoadPrefs();

 

 	/***************************************************************************************************************************/

-	/************************* Finds the xChat window and saves it for later use ***********************************************/

+	/************************* Finds the HexChat window and saves it for later use *********************************************/

 	/***************************************************************************************************************************/

 	g_hXchatWnd = (HWND)xchat_get_info(ph, "win_ptr");

 

@@ -96,7 +123,7 @@ int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name, char **pl
 	SetWindowLongPtr(g_hXchatWnd, GWLP_WNDPROC, (LONG_PTR)WindowProc);

 

 	/***************************************************************************************************************************/	

-	/************************* Grab the xChat Icon, Load our menu, create the window to receive the hotkey messages  ***********/

+	/************************* Grab the HexChat Icon, Load our menu, create the window to receive the hotkey messages  *********/

 	/************************* and register the windows message so we know if explorer crashes                       ***********/

 	/***************************************************************************************************************************/

 	g_hTrayMenu		= GetSubMenu(LoadMenu((HINSTANCE)g_hInstance, MAKEINTRESOURCE(IDR_TRAY_MENU)), 0);

diff --git a/plugins/hextray/hextray.h b/plugins/hextray/hextray.h
index 0bd8a990..2c244d8f 100644
--- a/plugins/hextray/hextray.h
+++ b/plugins/hextray/hextray.h
@@ -19,6 +19,12 @@
 #ifndef _XTRAY_H

 #define _XTRAY_H

 

+/******************** Default settings*****************/

+#define HT_DEF_SET		13814

+#define HT_DEF_AOT		5

+#define HT_DEF_KEY		84

+#define HT_DEF_MOD		6

+

 /******************** Globals *************************/

 extern HWND				g_hXchatWnd;

 extern HWND				g_hHotkeyWnd;

diff --git a/plugins/hextray/hextray.vcxproj b/plugins/hextray/hextray.vcxproj
index fd28aae3..7b1e4c6b 100644
--- a/plugins/hextray/hextray.vcxproj
+++ b/plugins/hextray/hextray.vcxproj
@@ -20,13 +20,13 @@
     <ConfigurationType>DynamicLibrary</ConfigurationType>

     <UseDebugLibraries>false</UseDebugLibraries>

     <WholeProgramOptimization>true</WholeProgramOptimization>

-    <CharacterSet>Unicode</CharacterSet>

+    <CharacterSet>MultiByte</CharacterSet>

   </PropertyGroup>

   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">

     <ConfigurationType>DynamicLibrary</ConfigurationType>

     <UseDebugLibraries>false</UseDebugLibraries>

     <WholeProgramOptimization>true</WholeProgramOptimization>

-    <CharacterSet>Unicode</CharacterSet>

+    <CharacterSet>MultiByte</CharacterSet>

   </PropertyGroup>

   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

   <ImportGroup Label="ExtensionSettings">

diff --git a/plugins/hextray/resource.rc b/plugins/hextray/resource.rc
index 01899ac7..d01642df 100644
--- a/plugins/hextray/resource.rc
+++ b/plugins/hextray/resource.rc
@@ -97,7 +97,7 @@ BEGIN
                     15,103,64,33

     GROUPBOX        "Special Thanks To:",IDC_STATIC,3,91,89,50

     GROUPBOX        "Version Information:",IDC_STATIC,101,92,109,49

-    LTEXT           "1.2.4",IDC_STATIC,170,105,33,8,0,WS_EX_RIGHT

+    LTEXT           "1.3.0",IDC_STATIC,170,105,33,8,0,WS_EX_RIGHT

     LTEXT           "Compiled In: ",IDC_STATIC,110,117,54,8

     LTEXT           "2012",IDC_STATIC,170,117,33,8,0,WS_EX_RIGHT

     LTEXT           "Version Number:",IDC_STATIC,110,105,54,8

diff --git a/plugins/hextray/utility.cpp b/plugins/hextray/utility.cpp
index 9cc421a6..30222602 100644
--- a/plugins/hextray/utility.cpp
+++ b/plugins/hextray/utility.cpp
@@ -75,95 +75,11 @@ WORD ModToHotkeyf(WORD modifiers)
 

 void SavePrefs(int iDlg)

 {

-	/**************************************************************************************************/

-	/********** allocate space for our string, and then set it to the currently logged on user ********/

-	/**************************************************************************************************/

-	DWORD dBuff = 257;

-	TCHAR szUser[257];

-

-	GetUserName(szUser, &dBuff);

-

-	/**************************************************************************************************/

-	/*********************** Test if the file exists, If it doesn't, Create It ************************/

-	/**************************************************************************************************/

-	TCHAR XTRAY_INI_FILE[1024];

-	

-#ifdef UNICODE

-	char temp[1024];

-    TCHAR TEMP_INI_FILE[1024];

-	

-	_snprintf(temp, 1024, "%s\\addon_hextray.conf", xchat_get_info(ph, "xchatdir"));

-	ConvertString(temp, TEMP_INI_FILE, 1024);

-

-	// ok this one is really ugly

-	// it checks to see if the file exists in two locations

-	// HexChat default config dir, if that fails it tries hexchat\plugins\config

-	// if neither one exists it tries to create it in

-	// HexChat default config dir, if that fails it tries hexchat\plugins\config

-	// In either case it writes \xFF\xFE to the file ( on creation )

-	// so that we can save unicode away messages WritePrivateProfile doesn't 

-	// do this for us, though I think it really should

-

-	if(FileExists(TEMP_INI_FILE))

-	{

-		_tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE);

-	}

-	else

-	{

-		if(FileExists(BACKUP_INI_FILE))

-		{

-			_tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE);

-		}

-		else

-		{

-			HANDLE xTemp;

-			DWORD dwBytesTemp;

-

-			if(xTemp = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL))

-			{

-				if(GetLastError() != ERROR_ALREADY_EXISTS)

-				{

-					WriteFile(xTemp, _T("\xFF\xFE"), 4, &dwBytesTemp, NULL);

-				}

-				CloseHandle(xTemp);

-			}

-

-			if(FileExists(TEMP_INI_FILE))

-			{

-				_tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE);

-			}

-			else

-			{

-				HANDLE xBackup;

-				DWORD dwBytesBackup;

-

-				if(xBackup = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL))

-				{

-					if(GetLastError() != ERROR_ALREADY_EXISTS)

-					{

-						WriteFile(xBackup, _T("\xFF\xFE"), 4, &dwBytesBackup, NULL);

-					}

-

-					CloseHandle(xBackup);

-				}

-

-				if(FileExists(BACKUP_INI_FILE))

-				{

-					_tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE);

-				}

-			}

-		}

-	}

-

-#else

-	_tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE);

-#endif

-

-	WritePrivateProfileInt(szUser, _T("SETTINGS"),		g_dwPrefs,		XTRAY_INI_FILE);

-	WritePrivateProfileInt(szUser, _T("AOT"),			g_iTime,		XTRAY_INI_FILE);

-	WritePrivateProfileInt(szUser, _T("KEY"),			g_hHotKey.key,	XTRAY_INI_FILE);

-	WritePrivateProfileInt(szUser, _T("MOD"),			g_hHotKey.mod,	XTRAY_INI_FILE);

-	WritePrivateProfileString(szUser, _T("AWAY"),		g_szAway,		XTRAY_INI_FILE);

+	xchat_pluginpref_set_int (ph, "settings", g_dwPrefs);

+	xchat_pluginpref_set_int (ph, "aot", g_iTime);

+	xchat_pluginpref_set_int (ph, "key", g_hHotKey.key);

+	xchat_pluginpref_set_int (ph, "mod", g_hHotKey.mod);

+	xchat_pluginpref_set_str (ph, "away", (const char*) g_szAway);

 }

 

 void LoadPrefs()

@@ -171,115 +87,17 @@ void LoadPrefs()
 	/**************************************************************************************************/

 	/*********************** Our Settings Section *****************************************************/

 	/**************************************************************************************************/

-	DWORD dBuff = 257;

-	TCHAR szUser[257];

-

-	GetUserName(szUser, &dBuff);

-

-	/**************************************************************************************************/

-	/*********************** Test if the file exists, If it doesn't, Create It ************************/

-	/**************************************************************************************************/

-	TCHAR XTRAY_INI_FILE[1024];

-

-#ifdef UNICODE

-	char temp[1024];

-	TCHAR TEMP_INI_FILE[1024];

-

-	_snprintf(temp, 1024, "%s\\addon_hextray.conf", xchat_get_info(ph, "xchatdir"));

-	ConvertString(temp, TEMP_INI_FILE, 1024);

-

-	if(FileExists(TEMP_INI_FILE))

-	{

-		_tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE);

-	}

-	else

-	{

-		if(FileExists(BACKUP_INI_FILE))

-		{

-			_tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE);

-		}

-		else

-		{

-			HANDLE xTemp;

-			DWORD dwBytesTemp;

-

-			if(xTemp = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL))

-			{

-				if(GetLastError() != ERROR_ALREADY_EXISTS)

-				{

-					WriteFile(xTemp, _T("\xFF\xFE"), 4, &dwBytesTemp, NULL);

-				}

-

-				CloseHandle(xTemp);

-			}

-

-			if(FileExists(TEMP_INI_FILE))

-			{

-				_tcscpy(XTRAY_INI_FILE, TEMP_INI_FILE);

-			}

-			else

-			{

-				HANDLE xBackup;

-				DWORD dwBytesBackup;

-

-				if(xBackup = CreateFile(TEMP_INI_FILE, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL))

-				{

-					if(GetLastError() != ERROR_ALREADY_EXISTS)

-					{

-						WriteFile(xBackup, _T("\xFF\xFE"), 4, &dwBytesBackup, NULL);

-					}

-

-					CloseHandle(xBackup);

-				}

-

-				if(FileExists(BACKUP_INI_FILE))

-				{

-					_tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE);

-				}

-			}

-		}

-	}

-

-#else

-	_tcscpy(XTRAY_INI_FILE, BACKUP_INI_FILE);

-#endif

 

 	/**************************************************************************************************/

 	/*************************** Get the value for each of our preferances ****************************/

 	/**************************************************************************************************/

-	g_dwPrefs = GetPrivateProfileInt(szUser, _T("SETTINGS"),	0,  XTRAY_INI_FILE);

 

-	// backwards compatability

-	// also allows us to set defaults if its a new installation

-	// disable topic change, channel message and server notice by default

-	if(g_dwPrefs == 0)

-	{

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("HILIGHT"),		1,  XTRAY_INI_FILE)<<1);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("INVITE"),		1,  XTRAY_INI_FILE)<<2);

-		/* g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("TOPIC"),		1,  XTRAY_INI_FILE)<<3); */

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("BANNED"),		1,  XTRAY_INI_FILE)<<4);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("KICKED"),		1,  XTRAY_INI_FILE)<<5);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("CTCP"),		1,  XTRAY_INI_FILE)<<6);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("PMSG"),		1,  XTRAY_INI_FILE)<<7);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("KILLED"),		1,  XTRAY_INI_FILE)<<8);

-		/* g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("NOTICE"),		1,  XTRAY_INI_FILE)<<9); */

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("DISCONNECT"),	1,  XTRAY_INI_FILE)<<10);

-

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("AOM"),			0,  XTRAY_INI_FILE)<<11);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("TOT"),			1,  XTRAY_INI_FILE)<<12);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("AMAE"),		1,  XTRAY_INI_FILE)<<13);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("OSBWM"),		0,  XTRAY_INI_FILE)<<14);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("UWIOB"),		0,  XTRAY_INI_FILE)<<15);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("KAOI"),		0,  XTRAY_INI_FILE)<<16);

-		g_dwPrefs	|= (GetPrivateProfileInt(szUser, _T("MIOC"),		0,  XTRAY_INI_FILE)<<17);

-	}

-	

-	g_hHotKey.key	= GetPrivateProfileInt(szUser, _T("KEY"),	84, XTRAY_INI_FILE);

-	g_hHotKey.mod	= GetPrivateProfileInt(szUser, _T("MOD"),	(MOD_CONTROL | MOD_SHIFT),  XTRAY_INI_FILE);

-	g_iTime			= GetPrivateProfileInt(szUser, _T("AOT"),	5,  XTRAY_INI_FILE);

+	g_dwPrefs = xchat_pluginpref_get_int (ph, "settings");

+	g_iTime = xchat_pluginpref_get_int (ph, "aot");

+	g_hHotKey.key = xchat_pluginpref_get_int (ph, "key");

+	g_hHotKey.mod = xchat_pluginpref_get_int (ph, "mod");

+	xchat_pluginpref_get_str (ph, "away", (char *) g_szAway);

 

-	GetPrivateProfileString(szUser, _T("AWAY"), _T(""),	g_szAway, 1024, XTRAY_INI_FILE);

-	

 	/**************************************************************************************************/

 	/******************************** Register our hotkey with windows ********************************/

 	/**************************************************************************************************/

@@ -519,20 +337,6 @@ int SetOption(HWND hDialog, unsigned int uiCheckBox, unsigned int uiPref)
 	return (g_dwPrefs & (1<<uiPref));

 }

 

-int WritePrivateProfileIntA(char *szSection, char *szItem, int iData, char *szPath)

-{

-	char szData[33];

-	itoa(iData, szData, 10);

-	return WritePrivateProfileStringA(szSection, szItem, szData, szPath);

-}

-

-int WritePrivateProfileIntW(wchar_t *wszSection, wchar_t *wszItem, int iData, wchar_t *wszPath)

-{

-	wchar_t wszData[33];

-	_itow(iData, wszData, 10);

-	return WritePrivateProfileStringW(wszSection, wszItem, wszData, wszPath);

-}

-

 // For cleanup ( Closing windows and the such )

 void HoldClose()

 {

diff --git a/plugins/hextray/utility.h b/plugins/hextray/utility.h
index 6bee8aed..bc8a8bfd 100644
--- a/plugins/hextray/utility.h
+++ b/plugins/hextray/utility.h
@@ -38,15 +38,6 @@ void ConvertString(const char *in,		wchar_t *out,	int size);
 void ConvertString(const wchar_t *in,	char *out,		int size);

 void ConvertString(const char *in,		char *out,		int size);

 

-int WritePrivateProfileIntA(char *, char *, int, char *);

-int WritePrivateProfileIntW(wchar_t *, wchar_t *, int, wchar_t *);

-

-#ifdef UNICODE

-#define WritePrivateProfileInt WritePrivateProfileIntW

-#else

-#define WritePrivateProfileInt WritePrivateProfileIntA

-#endif

-

 struct HOTKEY

 {

 	WORD key;