summaryrefslogtreecommitdiff
path: root/plugins/SplashScreen/src/options.cpp
blob: 504f43010264a3c978ccd1f5bdd93719ce36c169 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/*
Splash Screen Plugin for Miranda NG (www.miranda-ng.org)
(c) 2004-2007 nullbie, (c) 2005-2007 Thief

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 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "stdafx.h"

wchar_t szPath2Spash[MAX_PATH], szSoundFilePath[MAX_PATH];

// Reads values from db
void ReadDbConfig()
{
	options.active = db_get_b(NULL, MODNAME, "Active", 1);
	options.playsnd = db_get_b(NULL, MODNAME, "PlaySound", 0);
	options.fadein = db_get_b(NULL, MODNAME, "FadeIn", 1);
	options.fadeout = db_get_b(NULL, MODNAME, "FadeOut", 1);
	options.showtime = db_get_dw(NULL, MODNAME, "TimeToShow", 2000);
	options.fisteps = db_get_dw(NULL, MODNAME, "FadeinSpeed", 5);
	options.fosteps = db_get_dw(NULL, MODNAME, "FadeoutSpeed", 5);
	options.inheritGS = db_get_b(NULL, MODNAME, "InheritGlobalSound", 1);
	options.showversion = db_get_b(NULL, MODNAME, "ShowVersion", 0);
	options.random = db_get_b(NULL, MODNAME, "Random", 0);
}

BOOL Exists(LPCTSTR strName)
{
	return GetFileAttributes(strName) != INVALID_FILE_ATTRIBUTES;
}

INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			if (!png2dibavail) {
				ShowWindow(GetDlgItem(hwndDlg, IDC_PNG2DIBWARN), SW_SHOW);
				EnableWindow(GetDlgItem(hwndDlg, IDC_ACTIVE), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_RANDOM), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SPLASHPATH), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSESPLASH), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWVERSION), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_VERSIONPREFIX), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWTIME), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_ST_SPIN), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FADEIN), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FISTEP), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FI_SPIN), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FADEOUT), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FOSTEP), false);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FO_SPIN), false);
			}
			else {
				ReadDbConfig();
				wchar_t inBuf[80];
				DBVARIANT dbv = { 0 };
				if (!db_get_ws(NULL, MODNAME, "Path", &dbv)) {
					mir_wstrcpy(inBuf, dbv.ptszVal);
					db_free(&dbv);
				}
				else
					mir_wstrcpy(inBuf, L"splash\\splash.png");
				SetDlgItemText(hwndDlg, IDC_SPLASHPATH, inBuf);

				if (!db_get_ws(NULL, MODNAME, "Sound", &dbv)) {
					mir_wstrcpy(inBuf, dbv.ptszVal);
					db_free(&dbv);
				}
				else
					mir_wstrcpy(inBuf, L"sounds\\startup.wav");
				SetDlgItemText(hwndDlg, IDC_SNDPATH, inBuf);

				if (!db_get_ws(NULL, MODNAME, "VersionPrefix", &dbv)) {
					mir_wstrcpy(inBuf, dbv.ptszVal);
					db_free(&dbv);
				}
				else
					mir_wstrcpy(inBuf, L"");
				SetDlgItemText(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);
				EnableWindow(GetDlgItem(hwndDlg, IDC_LOOPSOUND), false);
				if (options.fadein)
					CheckDlgButton(hwndDlg, IDC_FADEIN, BST_CHECKED);
				if (options.fadeout)
					CheckDlgButton(hwndDlg, IDC_FADEOUT, BST_CHECKED);
				if (options.random)
					CheckDlgButton(hwndDlg, IDC_RANDOM, BST_CHECKED);
				if (options.showversion)
					CheckDlgButton(hwndDlg, IDC_SHOWVERSION, BST_CHECKED);

				SetDlgItemText(hwndDlg, IDC_SHOWTIME, _itow(options.showtime, inBuf, 10));
				SetDlgItemText(hwndDlg, IDC_FISTEP, _itow(options.fisteps, inBuf, 10));
				SetDlgItemText(hwndDlg, IDC_FOSTEP, _itow(options.fosteps, inBuf, 10));

				SendDlgItemMessage(hwndDlg, IDC_SHOWTIME, EM_LIMITTEXT, 5, 0);
			}

			return TRUE;
		}

	case WM_COMMAND:
		{
			switch (LOWORD(wParam)) {
			case IDC_PREVIEW:
				{
					ShowSplash(true);
					break;
				}

			case IDC_ACTIVE:
			case IDC_PLAYSND:
			case IDC_LOOPSOUND:
			case IDC_FADEIN:
			case IDC_FADEOUT:
			case IDC_SHOWTIME:
			case IDC_RANDOM:
			case IDC_SHOWVERSION:
			case IDC_FISTEP:
			case IDC_FOSTEP:
				{
					if (IsDlgButtonChecked(hwndDlg, IDC_FADEIN)) {
						EnableWindow(GetDlgItem(hwndDlg, IDC_FISTEP), true);
						EnableWindow(GetDlgItem(hwndDlg, IDC_FI_SPIN), true);
					}
					else {
						EnableWindow(GetDlgItem(hwndDlg, IDC_FISTEP), false);
						EnableWindow(GetDlgItem(hwndDlg, IDC_FI_SPIN), false);
					}
					if (IsDlgButtonChecked(hwndDlg, IDC_FADEOUT)) {
						EnableWindow(GetDlgItem(hwndDlg, IDC_FOSTEP), true);
						EnableWindow(GetDlgItem(hwndDlg, IDC_FO_SPIN), true);
					}
					else {
						EnableWindow(GetDlgItem(hwndDlg, IDC_FOSTEP), false);
						EnableWindow(GetDlgItem(hwndDlg, IDC_FO_SPIN), false);
					}

					if ((HWND)lParam != GetFocus())
						return 0;
					else {
						SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
						break;
					}
					break;
				}

			case IDC_CHOOSESPLASH:
				{
					wchar_t szTempPath[MAX_PATH], initDir[MAX_PATH];

					if (Exists(szSplashFile)) {
						mir_wstrcpy(initDir, szSplashFile);
						wchar_t *pos = wcsrchr(initDir, '\\');
						if (pos != nullptr)
							*pos = 0;
					}
					else {
						szMirDir = Utils_ReplaceVarsW(L"%miranda_path%");
						mir_wstrcpy(initDir, szMirDir);
						mir_free(szMirDir);
					}

					wchar_t tmp[MAX_PATH];
					mir_snwprintf(tmp, L"%s (*.png, *.bmp)%c*.png;*.bmp%c%c", TranslateT("Graphic files"), 0, 0, 0);

					OPENFILENAME ofn = { 0 };
					ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
					ofn.lpstrFilter = tmp;
					ofn.lpstrFile = szTempPath;
					ofn.nMaxFile = MAX_PATH;
					ofn.nMaxFileTitle = MAX_PATH;
					ofn.Flags = OFN_HIDEREADONLY;
					ofn.lpstrInitialDir = initDir;
					*szTempPath = '\0';
					ofn.lpstrDefExt = L"";

					if (GetOpenFileName(&ofn)) {
						mir_wstrcpy(szSplashFile, szTempPath);

						#ifdef _DEBUG
						logMessage(L"Set path", szSplashFile);
						#endif
						// Make path relative
						int result = PathToRelativeW(szTempPath, szPath2Spash);
						if (result && mir_wstrlen(szPath2Spash) > 0) {
							if (options.random) {
								wchar_t *pos = wcsrchr(szPath2Spash, '\\');
								if (pos != nullptr) {
									*pos = 0;
									mir_wstrcat(szPath2Spash, L"\\");
								}
							}

							SetDlgItemText(hwndDlg, IDC_SPLASHPATH, szPath2Spash);
						}

						SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
					}

					break;
				}

			case IDC_GETSPLASHES:
				Utils_OpenUrl("https://miranda-ng.org/addons/category/15");
				break;

			case IDC_CHOOSESND:
				{
					wchar_t szTempPath[MAX_PATH], initDir[MAX_PATH];
					wchar_t *pos;

					if (Exists(szSoundFile)) {
						mir_wstrcpy(initDir, szSoundFile);
						pos = wcsrchr(initDir, '\\');
						if (pos != nullptr) *pos = 0;
					}
					else {
						szMirDir = Utils_ReplaceVarsW(L"%miranda_path%");
						mir_wstrcpy(initDir, szMirDir);
						mir_free(szMirDir);
					}

					OPENFILENAME ofn = { 0 };
					ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
					wchar_t tmp[MAX_PATH];
					mir_snwprintf(tmp, L"%s (*.wav, *.mp3)%c*.wav;*.mp3%c%c", TranslateT("Sound Files"), 0, 0, 0);
					ofn.lpstrFilter = tmp;
					ofn.hwndOwner = nullptr;
					ofn.lpstrFile = szTempPath;
					ofn.nMaxFile = MAX_PATH;
					ofn.nMaxFileTitle = MAX_PATH;
					ofn.Flags = OFN_HIDEREADONLY;
					ofn.lpstrInitialDir = initDir;
					*szTempPath = '\0';
					ofn.lpstrDefExt = L"";

					if (GetOpenFileName(&ofn)) {
						mir_wstrcpy(szSoundFile, szTempPath);

						#ifdef _DEBUG
						logMessage(L"Set sound path", szSoundFile);
						#endif

						// Make path relative
						int result = PathToRelativeW(szTempPath, szSoundFilePath);
						if (result && mir_wstrlen(szSoundFile) > 0)
							SetDlgItemText(hwndDlg, IDC_SNDPATH, szSoundFilePath);

						SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
					}

					break;
				}
			}

	default:
		{
			if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())
				return 0;
			else
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		}
		break;
		}

	case WM_NOTIFY:
		{
			if (((LPNMHDR)lParam)->idFrom == 0)
				switch (((LPNMHDR)lParam)->code) {
				case PSN_APPLY:
					{
						wchar_t tmp[MAX_PATH];

						GetDlgItemText(hwndDlg, IDC_SPLASHPATH, tmp, _countof(tmp));
						db_set_ws(NULL, MODNAME, "Path", tmp);

						GetDlgItemText(hwndDlg, IDC_SNDPATH, tmp, _countof(tmp));
						db_set_ws(NULL, MODNAME, "Sound", tmp);

						GetDlgItemText(hwndDlg, IDC_VERSIONPREFIX, tmp, _countof(tmp));
						db_set_ws(NULL, MODNAME, "VersionPrefix", tmp);
						mir_wstrcpy(szPrefix, tmp);

						GetDlgItemText(hwndDlg, IDC_SHOWTIME, tmp, _countof(tmp));
						db_set_dw(NULL, MODNAME, "TimeToShow", _wtoi(tmp));
						options.showtime = _wtoi(tmp);

						GetDlgItemText(hwndDlg, IDC_FISTEP, tmp, _countof(tmp));
						db_set_dw(NULL, MODNAME, "FadeinSpeed", _wtoi(tmp));
						options.fisteps = _wtoi(tmp);

						GetDlgItemText(hwndDlg, IDC_FOSTEP, tmp, _countof(tmp));
						db_set_dw(NULL, MODNAME, "FadeoutSpeed", _wtoi(tmp));
						options.fosteps = _wtoi(tmp);

						if (IsDlgButtonChecked(hwndDlg, IDC_ACTIVE)) {
							db_set_b(NULL, MODNAME, "Active", 1);
							options.active = 1;
						}
						else {
							db_set_b(NULL, MODNAME, "Active", 0);
							options.active = 0;
						}

						if (IsDlgButtonChecked(hwndDlg, IDC_PLAYSND)) {
							db_set_b(NULL, MODNAME, "PlaySound", 1);
							options.playsnd = 1;
							db_set_b(NULL, MODNAME, "InheritGlobalSound", 1);
							options.inheritGS = 1;
						}
						else {
							db_set_b(NULL, MODNAME, "PlaySound", 0);
							options.playsnd = 0;
							db_set_b(NULL, MODNAME, "InheritGlobalSound", 0);
							options.inheritGS = 0;
						}

						if (IsDlgButtonChecked(hwndDlg, IDC_PLAYSND) == BST_INDETERMINATE) {
							db_set_b(NULL, MODNAME, "PlaySound", 1);
							options.playsnd = 1;
							db_set_b(NULL, MODNAME, "InheritGlobalSound", 0);
							options.inheritGS = 0;
						}

						/*
						if (IsDlgButtonChecked(hwndDlg, IDC_LOOPSOUND))
						{
						WritePrivateProfileString("Splash","LoopSound","1",szIniFile);
						options.loopsnd = 1;
						}
						else
						{
						WritePrivateProfileString("Splash","LoopSound","0",szIniFile);
						options.loopsnd = 0;
						}
						*/

						if (IsDlgButtonChecked(hwndDlg, IDC_FADEIN)) {
							db_set_b(NULL, MODNAME, "FadeIn", 1);
							options.fadein = 1;
						}
						else {
							db_set_b(NULL, MODNAME, "FadeIn", 0);
							options.fadein = 0;
						}
						if (IsDlgButtonChecked(hwndDlg, IDC_FADEOUT)) {
							db_set_b(NULL, MODNAME, "FadeOut", 1);
							options.fadeout = 1;
						}
						else {
							db_set_b(NULL, MODNAME, "FadeOut", 0);
							options.fadeout = 0;
						}
						if (IsDlgButtonChecked(hwndDlg, IDC_RANDOM)) {
							db_set_b(NULL, MODNAME, "Random", 1);
							options.random = 1;
						}
						else {
							db_set_b(NULL, MODNAME, "Random", 0);
							options.random = 0;
						}
						if (IsDlgButtonChecked(hwndDlg, IDC_SHOWVERSION)) {
							db_set_b(NULL, MODNAME, "ShowVersion", 1);
							options.showversion = 1;
						}
						else {
							db_set_b(NULL, MODNAME, "ShowVersion", 0);
							options.showversion = 0;
						}
						return TRUE;
					}
				}
		}

	case WM_DESTROY:
		break;
	}
	return FALSE;
}

int OptInit(WPARAM wParam, LPARAM lParam)
{
	OPTIONSDIALOGPAGE odp = { 0 };
	odp.hInstance = hInst;
	odp.szGroup.a = LPGEN("Skins");
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_SPLASH_OPT);
	odp.szTitle.a = LPGEN("Splash Screen");
	odp.pfnDlgProc = DlgProcOptions;
	odp.flags = ODPF_BOLDGROUPS;
	Options_AddPage(wParam, &odp);
	return 0;
}