summaryrefslogtreecommitdiff
path: root/splashscreen/src/options.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'splashscreen/src/options.cpp')
-rw-r--r--splashscreen/src/options.cpp282
1 files changed, 146 insertions, 136 deletions
diff --git a/splashscreen/src/options.cpp b/splashscreen/src/options.cpp
index 16e0d66..94aaaaa 100644
--- a/splashscreen/src/options.cpp
+++ b/splashscreen/src/options.cpp
@@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
File name : $URL: http://svn.miranda.im/mainrepo/splashscreen/trunk/src/options.cpp $
Revision : $Rev: 951 $
-Last change on : $Date: 2007-10-16 16:46:53 +0200 (Вт, 16 окт 2007) $
+Last change on : $Date: 2007-10-16 18:46:53 +0400 (Вт, 16 окт 2007) $
Last change by : $Author: Thief $
DESCRIPTION: Options dialog handling code
@@ -27,58 +27,30 @@ DESCRIPTION: Options dialog handling code
#include "headers.h"
-extern HINSTANCE hInst;
-extern bool ShowSplash(bool preview);
-extern bool png2dibavail;
-extern char szMirDir[MAX_PATH], szIniFile[MAX_PATH], szSplashFile[MAX_PATH], szSoundFile[MAX_PATH];
-extern char szPrefix[128];
-static char szPath2Spash [MAX_PATH], szSoundFilePath[MAX_PATH];
+TCHAR szPath2Spash [MAX_PATH], szSoundFilePath[MAX_PATH];
-// Reads values from ini file
+// Reads values from db
void ReadIniConfig()
{
- static char inBuf[80];
-
- GetPrivateProfileString("Splash","Active","1",inBuf,sizeof(inBuf),szIniFile);
- options.active = atoi(inBuf);
-
- GetPrivateProfileString("Splash","PlaySound","0",inBuf,sizeof(inBuf),szIniFile);
- options.playsnd = atoi(inBuf);
-
- GetPrivateProfileString("Splash","FadeIn","1",inBuf,sizeof(inBuf),szIniFile);
- options.fadein = atoi(inBuf);
-
- GetPrivateProfileString("Splash","FadeOut","1",inBuf,sizeof(inBuf),szIniFile);
- options.fadeout = atoi(inBuf);
-
- GetPrivateProfileString("Splash","TimeToShow","0",inBuf,sizeof(inBuf),szIniFile);
- options.showtime = atoi(inBuf);
-
- GetPrivateProfileString("Splash","FadeinSpeed","1",inBuf,sizeof(inBuf),szIniFile);
- options.fisteps = atoi(inBuf);
-
- GetPrivateProfileString("Splash","FadeoutSpeed","1",inBuf,sizeof(inBuf),szIniFile);
- options.fosteps = atoi(inBuf);
-
- GetPrivateProfileString("Splash","InheritGlobalSound","1",inBuf,sizeof(inBuf),szIniFile);
- options.inheritGS = atoi(inBuf);
-
- /*
- GetPrivateProfileString("Splash","LoopSound","0",inBuf,sizeof(inBuf),szIniFile);
- options.loopsnd = atoi(inBuf);
- */
-
- GetPrivateProfileString("Splash","ShowVersion","0",inBuf,sizeof(inBuf),szIniFile);
- options.showversion = atoi(inBuf);
-
- GetPrivateProfileString("Splash","Random","0",inBuf,sizeof(inBuf),szIniFile);
- options.random = atoi(inBuf);
+ options.active = DBGetContactSettingByte(NULL, MODNAME, "Active", 1);
+ options.playsnd = DBGetContactSettingByte(NULL, MODNAME, "PlaySound", 0);
+ options.fadein = DBGetContactSettingByte(NULL, MODNAME, "FadeIn", 1);
+ options.fadeout = DBGetContactSettingByte(NULL, MODNAME, "FadeOut", 1);
+ options.showtime = DBGetContactSettingDword(NULL, MODNAME, "TimeToShow", 2000);
+ options.fisteps = DBGetContactSettingDword(NULL, MODNAME, "FadeinSpeed", 5);
+ options.fosteps = DBGetContactSettingDword(NULL, MODNAME, "FadeoutSpeed", 5);
+ options.inheritGS = DBGetContactSettingByte(NULL, MODNAME, "InheritGlobalSound", 1);
+ options.showversion = DBGetContactSettingByte(NULL, MODNAME, "ShowVersion", 0);
+ options.random = DBGetContactSettingByte(NULL, MODNAME, "Random", 0);
+ options.runonce = DBGetContactSettingByte(NULL, MODNAME, "DisableAfterStartup", 0);
+}
- GetPrivateProfileString("Splash","DisableAfterStartup","0",inBuf,sizeof(inBuf),szIniFile);
- options.runonce = atoi(inBuf);
+BOOL Exists(LPCTSTR strName)
+{
+ return GetFileAttributes(strName) != INVALID_FILE_ATTRIBUTES;
}
-BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
@@ -94,13 +66,38 @@ BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSESPLASH), false);
}
ReadIniConfig();
- char inBuf[80];
- GetPrivateProfileString("Splash","Path","splash\\splash.png",inBuf,sizeof(inBuf),szIniFile);
+ TCHAR inBuf[80];
+ DBVARIANT dbv = {0};
+ DBGetContactSettingTString(NULL, MODNAME, "Path", &dbv);
+ if (lstrcmp(dbv.ptszVal, NULL) == 0)
+ {
+ _tcscpy_s(inBuf, _T("splash\\splash.png"));
+ DBFreeVariant(&dbv);
+ }
+ else
+ _tcscpy_s(inBuf, dbv.ptszVal);
+ dbv.ptszVal = NULL;
SetWindowText(GetDlgItem(hwndDlg, IDC_SPLASHPATH),inBuf);
- GetPrivateProfileString("Splash","Sound","sounds\\startup.wav",inBuf,sizeof(inBuf),szIniFile);
+ DBGetContactSettingTString(NULL, MODNAME, "Sound", &dbv);
+ if (lstrcmp(dbv.ptszVal, NULL) == 0)
+ {
+ _tcscpy_s(inBuf, _T("sounds\\startup.wav"));
+ DBFreeVariant(&dbv);
+ }
+ else
+ _tcscpy_s(inBuf, dbv.ptszVal);
+ dbv.ptszVal = NULL;
SetWindowText(GetDlgItem(hwndDlg, IDC_SNDPATH),inBuf);
- GetPrivateProfileString("Splash","VersionPrefix","",inBuf,sizeof(inBuf),szIniFile);
- SetWindowText(GetDlgItem(hwndDlg, IDC_VERSIONPREFIX),inBuf);
+ DBGetContactSettingTString(NULL, MODNAME, "VersionPrefix", &dbv);
+ if (lstrcmp(dbv.ptszVal, NULL) == 0)
+ {
+ _tcscpy_s(inBuf, _T(""));
+ DBFreeVariant(&dbv);
+ }
+ else
+ _tcscpy_s(inBuf, dbv.ptszVal);
+ dbv.ptszVal = NULL;
+ SetWindowText(GetDlgItem(hwndDlg, IDC_VERSIONPREFIX), inBuf);
if (options.active) CheckDlgButton(hwndDlg, IDC_ACTIVE, BST_CHECKED);
if (options.playsnd && !options.inheritGS) CheckDlgButton(hwndDlg, IDC_PLAYSND, BST_INDETERMINATE);
else if (options.playsnd) CheckDlgButton(hwndDlg, IDC_PLAYSND, BST_CHECKED);
@@ -111,12 +108,9 @@ BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
if (options.random) CheckDlgButton(hwndDlg, IDC_RANDOM, BST_CHECKED);
if (options.showversion) CheckDlgButton(hwndDlg, IDC_SHOWVERSION, BST_CHECKED);
- GetPrivateProfileString("Splash","TimeToShow","2000",inBuf,sizeof(inBuf),szIniFile);
- SetWindowText(GetDlgItem(hwndDlg, IDC_SHOWTIME),inBuf);
- GetPrivateProfileString("Splash","FadeinSpeed","5",inBuf,sizeof(inBuf),szIniFile);
- SetWindowText(GetDlgItem(hwndDlg, IDC_FISTEP),inBuf);
- GetPrivateProfileString("Splash","FadeoutSpeed","5",inBuf,sizeof(inBuf),szIniFile);
- SetWindowText(GetDlgItem(hwndDlg, IDC_FOSTEP),inBuf);
+ SetWindowText(GetDlgItem(hwndDlg, IDC_SHOWTIME), _itot(options.showtime, inBuf, 10));
+ SetWindowText(GetDlgItem(hwndDlg, IDC_FISTEP), _itot(options.fisteps, inBuf, 10));
+ SetWindowText(GetDlgItem(hwndDlg, IDC_FOSTEP), _itot(options.fosteps, inBuf, 10));
SendDlgItemMessage(hwndDlg, IDC_SHOWTIME, EM_LIMITTEXT, 5, 0);
/*
@@ -181,16 +175,27 @@ BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
case IDC_CHOOSESPLASH:
{
- static char szTempPath[MAX_PATH], initDir[MAX_PATH];
- char *pos;
+ TCHAR szTempPath[MAX_PATH], initDir[MAX_PATH];
+ TCHAR *pos;
- lstrcpy(initDir,szSplashFile);
- pos = strrchr(initDir, '\\');
- if(pos != NULL) *pos = 0;
+ if (Exists(szSplashFile))
+ {
+ lstrcpy(initDir, szSplashFile);
+ pos = _tcsrchr(initDir, _T('\\'));
+ if(pos != NULL) *pos = 0;
+ }
+ else
+ {
+ szMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
+ lstrcpy(initDir, szMirDir);
+ mir_free(szMirDir);
+ }
- OPENFILENAMEA ofn = {0};
+ OPENFILENAME ofn = {0};
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.lpstrFilter = "PNG and BMP files\0*.png;*.bmp\0\0";
+ TCHAR tmp[MAX_PATH];
+ mir_sntprintf(tmp, SIZEOF(tmp), _T("%s (*.png, *.bmp)%c*.png;*.bmp%c%c"), TranslateT("Graphic files"), 0, 0, 0);
+ ofn.lpstrFilter = tmp;
ofn.hwndOwner = 0;
ofn.lpstrFile = szTempPath;
ofn.nMaxFile = MAX_PATH;
@@ -198,33 +203,33 @@ BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
ofn.Flags = OFN_HIDEREADONLY;
ofn.lpstrInitialDir = initDir;
*szTempPath = '\0';
- ofn.lpstrDefExt = "";
+ ofn.lpstrDefExt = _T("");
- if (GetOpenFileNameA(&ofn))
+ if (GetOpenFileName(&ofn))
{
- lstrcpy(szSplashFile,szTempPath);
+ lstrcpy(szSplashFile, szTempPath);
- #ifdef _DEBUG
- logMessage("Set path", szSplashFile);
- #endif
+ #ifdef _DEBUG
+ logMessage(_T("Set path"), szSplashFile);
+ #endif
// Make path relative
- int result = CallService(MS_UTILS_PATHTORELATIVE, (WPARAM)szTempPath, (LPARAM)szPath2Spash);
+ int result = CallService(MS_UTILS_PATHTORELATIVET, (WPARAM)szTempPath, (LPARAM)szPath2Spash);
- if(result && lstrlenA(szPath2Spash) > 0)
+ if(result && lstrlen(szPath2Spash) > 0)
{
if (options.random)
{
- char *pos;
- pos = strrchr(szPath2Spash, '\\');
+ TCHAR *pos;
+ pos = _tcsrchr(szPath2Spash, _T('\\'));
if (pos != NULL)
{
*pos = 0;
- lstrcat(szPath2Spash,"\\");
+ lstrcat(szPath2Spash, _T("\\"));
}
}
- SetWindowText(GetDlgItem(hwndDlg, IDC_SPLASHPATH),szPath2Spash);
+ SetWindowText(GetDlgItem(hwndDlg, IDC_SPLASHPATH), szPath2Spash);
}
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
@@ -235,16 +240,27 @@ BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
case IDC_CHOOSESND:
{
- static char szTempPath[MAX_PATH], initDir[MAX_PATH];
- char *pos;
+ TCHAR szTempPath[MAX_PATH], initDir[MAX_PATH];
+ TCHAR *pos;
- lstrcpy(initDir,szSoundFile);
- pos = strrchr(initDir, '\\');
- if(pos != NULL) *pos = 0;
+ if (Exists(szSoundFile))
+ {
+ lstrcpy(initDir, szSoundFile);
+ pos = _tcsrchr(initDir, _T('\\'));
+ if(pos != NULL) *pos = 0;
+ }
+ else
+ {
+ szMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
+ lstrcpy(initDir, szMirDir);
+ mir_free(szMirDir);
+ }
- OPENFILENAMEA ofn = {0};
+ OPENFILENAME ofn = {0};
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.lpstrFilter = "Sound files\0*.wav\0\0";
+ TCHAR tmp[MAX_PATH];
+ mir_sntprintf(tmp, SIZEOF(tmp), _T("%s (*.wav, *.mp3)%c*.wav;*.mp3%c%c"), TranslateT("Sound Files"), 0, 0, 0);
+ ofn.lpstrFilter = tmp;
ofn.hwndOwner = 0;
ofn.lpstrFile = szTempPath;
ofn.nMaxFile = MAX_PATH;
@@ -252,23 +268,21 @@ BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
ofn.Flags = OFN_HIDEREADONLY;
ofn.lpstrInitialDir = initDir;
*szTempPath = '\0';
- ofn.lpstrDefExt = "";
+ ofn.lpstrDefExt = _T("");
- if (GetOpenFileNameA(&ofn))
+ if (GetOpenFileName(&ofn))
{
lstrcpy(szSoundFile,szTempPath);
-#ifdef _DEBUG
- logMessage("Set sound path", szSoundFile);
-#endif
+ #ifdef _DEBUG
+ logMessage(_T("Set sound path"), szSoundFile);
+ #endif
// Make path relative
- int result = CallService(MS_UTILS_PATHTORELATIVE, (WPARAM)szTempPath, (LPARAM)szSoundFilePath);
+ int result = CallService(MS_UTILS_PATHTORELATIVET, (WPARAM)szTempPath, (LPARAM)szSoundFilePath);
- if(result && lstrlenA(szSoundFile) > 0)
- {
+ if(result && lstrlen(szSoundFile) > 0)
SetWindowText(GetDlgItem(hwndDlg, IDC_SNDPATH),szSoundFilePath);
- }
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
@@ -294,65 +308,61 @@ BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
{
case PSN_APPLY:
{
- static char tmp[MAX_PATH];
+ TCHAR tmp[MAX_PATH];
- GetWindowText(GetDlgItem(hwndDlg, IDC_SPLASHPATH),tmp,MAX_PATH);
- WritePrivateProfileString("Splash","Path",tmp,szIniFile);
+ GetWindowText(GetDlgItem(hwndDlg, IDC_SPLASHPATH), tmp, MAX_PATH);
+ DBWriteContactSettingTString(NULL, MODNAME, "Path", tmp);
- GetWindowText(GetDlgItem(hwndDlg, IDC_SNDPATH),tmp,MAX_PATH);
- WritePrivateProfileString("Splash","Sound",tmp,szIniFile);
+ GetWindowText(GetDlgItem(hwndDlg, IDC_SNDPATH), tmp, MAX_PATH);
+ DBWriteContactSettingTString(NULL, MODNAME, "Sound", tmp);
- GetWindowText(GetDlgItem(hwndDlg, IDC_VERSIONPREFIX),tmp,MAX_PATH);
- static char tmpstr[128] = {0};
- strcat(tmpstr,"\"");
- strcat(tmpstr,tmp);
- strcat(tmpstr,"\"");
- WritePrivateProfileString("Splash","VersionPrefix",tmpstr,szIniFile);
- ZeroMemory(&tmpstr,sizeof(tmpstr));
- strcpy(szPrefix,tmp);
-
- GetWindowText(GetDlgItem(hwndDlg, IDC_SHOWTIME),tmp,MAX_PATH);
- WritePrivateProfileString("Splash","TimeToShow",tmp,szIniFile);
-
- GetWindowText(GetDlgItem(hwndDlg, IDC_FISTEP),tmp,MAX_PATH);
- WritePrivateProfileString("Splash","FadeinSpeed",tmp,szIniFile);
- options.fisteps = atoi(tmp);
-
- GetWindowText(GetDlgItem(hwndDlg, IDC_FOSTEP),tmp,MAX_PATH);
- WritePrivateProfileString("Splash","FadeoutSpeed",tmp,szIniFile);
- options.fosteps = atoi(tmp);
+ GetWindowText(GetDlgItem(hwndDlg, IDC_VERSIONPREFIX), tmp, MAX_PATH);
+ DBWriteContactSettingTString(NULL, MODNAME, "VersionPrefix", tmp);
+ lstrcpy(szPrefix, tmp);
+
+ GetWindowText(GetDlgItem(hwndDlg, IDC_SHOWTIME), tmp, MAX_PATH);
+ DBWriteContactSettingDword(NULL, MODNAME, "TimeToShow", _ttoi(tmp));
+ options.showtime = _ttoi(tmp);
+
+ GetWindowText(GetDlgItem(hwndDlg, IDC_FISTEP), tmp, MAX_PATH);
+ DBWriteContactSettingDword(NULL, MODNAME, "FadeinSpeed", _ttoi(tmp));
+ options.fisteps = _ttoi(tmp);
+
+ GetWindowText(GetDlgItem(hwndDlg, IDC_FOSTEP), tmp, MAX_PATH);
+ DBWriteContactSettingDword(NULL, MODNAME, "FadeoutSpeed", _ttoi(tmp));
+ options.fosteps = _ttoi(tmp);
if (IsDlgButtonChecked(hwndDlg, IDC_ACTIVE))
{
- WritePrivateProfileString("Splash","Active","1",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "Active", 1);
options.active = 1;
}
else
{
- WritePrivateProfileString("Splash","Active","0",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "Active", 0);
options.active = 0;
}
if (IsDlgButtonChecked(hwndDlg, IDC_PLAYSND))
{
- WritePrivateProfileString("Splash","PlaySound","1",szIniFile);
- WritePrivateProfileString("Splash","InheritGlobalSound","1",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "PlaySound", 1);
options.playsnd = 1;
+ DBWriteContactSettingByte(NULL, MODNAME, "InheritGlobalSound", 1);
options.inheritGS = 1;
}
else
{
- WritePrivateProfileString("Splash","PlaySound","0",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "PlaySound", 0);
options.playsnd = 0;
- WritePrivateProfileString("Splash","InheritGlobalSound","0",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "InheritGlobalSound", 0);
options.inheritGS = 0;
}
if (IsDlgButtonChecked(hwndDlg, IDC_PLAYSND) == BST_INDETERMINATE)
{
- WritePrivateProfileString("Splash","PlaySound","1",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "PlaySound", 1);
options.playsnd = 1;
- WritePrivateProfileString("Splash","InheritGlobalSound","0",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "InheritGlobalSound", 0);
options.inheritGS = 0;
}
@@ -371,42 +381,42 @@ BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
if (IsDlgButtonChecked(hwndDlg, IDC_FADEIN))
{
- WritePrivateProfileString("Splash","FadeIn","1",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "FadeIn", 1);
options.fadein = 1;
}
else
{
- WritePrivateProfileString("Splash","FadeIn","0",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "FadeIn", 0);
options.fadein = 0;
}
if (IsDlgButtonChecked(hwndDlg, IDC_FADEOUT))
{
- WritePrivateProfileString("Splash","FadeOut","1",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "FadeOut", 1);
options.fadeout = 1;
}
else
{
- WritePrivateProfileString("Splash","FadeOut","0",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "FadeOut", 0);
options.fadeout = 0;
}
if (IsDlgButtonChecked(hwndDlg, IDC_RANDOM))
{
- WritePrivateProfileString("Splash","Random","1",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "Random", 1);
options.random = 1;
}
else
{
- WritePrivateProfileString("Splash","Random","0",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "Random", 0);
options.random = 0;
}
if (IsDlgButtonChecked(hwndDlg, IDC_SHOWVERSION))
{
- WritePrivateProfileString("Splash","ShowVersion","1",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "ShowVersion", 1);
options.showversion = 1;
}
else
{
- WritePrivateProfileString("Splash","ShowVersion","0",szIniFile);
+ DBWriteContactSettingByte(NULL, MODNAME, "ShowVersion", 0);
options.showversion = 0;
}
return TRUE;
@@ -428,11 +438,11 @@ int OptInit(WPARAM wParam, LPARAM lParam)
odp.cbSize = sizeof(odp);
odp.position = 0;
odp.hInstance = hInst;
- odp.pszGroup = Translate("Customize");
+ odp.ptszGroup = _T("Customize");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_SPLASH_OPT);
- odp.pszTitle = Translate("Splash Screen");
+ odp.ptszTitle = _T("Splash Screen");
odp.pfnDlgProc = DlgProcOptions;
- odp.flags = ODPF_BOLDGROUPS;
+ odp.flags = ODPF_TCHAR | ODPF_BOLDGROUPS;
CallService(MS_OPT_ADDPAGE, wParam, (LPARAM) &odp);
return 0;
}