aboutsummaryrefslogtreecommitdiff
path: root/Src/Winamp/options_title.cpp
blob: 366e3affaeeb906e550e6047dcee873e919c3f80 (plain) (blame)
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
/** (c) Nullsoft, Inc.         C O N F I D E N T I A L
 ** Filename: 
 ** Project:
 ** Description:
 ** Author:
 ** Created:
 **/
#include "main.h"
#include "resource.h"
#include "options.h"
#include "api.h"
#include <Wininet.h>
#include "language.h"

int atf_changed = 0, old_config_useexttitles = 0;
wchar_t old_config_titlefmt[1024] = {0};
INT_PTR CALLBACK TitleProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
{
	extern char *g_titlefmt_default;
	hi helpinfo[]={
 		{IDC_USEID5,IDS_P_O_ONPLAY},
		{IDC_USEID4,IDS_P_O_ONLOAD},
		{IDC_USEID3,IDS_P_O_ONDEM},
		{IDC_CONVERT1,IDS_P_O_CONVERT1},
		{IDC_CONVERT2,IDS_P_O_CONVERT2},
	};
	DO_HELP();

	switch (uMsg)
	{
		case WM_INITDIALOG:
			atf_changed = 0;
			link_startsubclass(hwndDlg, IDC_TAGZ_HELP);
			lstrcpynW(old_config_titlefmt,config_titlefmt,1024);
			old_config_useexttitles = !!config_useexttitles;
			SetDlgItemTextW(hwndDlg,IDC_FORMAT,config_titlefmt);
			CheckDlgButton(hwndDlg,IDC_CHECK1,!!config_useexttitles);
			CheckDlgButton(hwndDlg,IDC_USEID3,config_riol == 0?1:0);
			CheckDlgButton(hwndDlg,IDC_USEID4,config_riol == 1?1:0);
			CheckDlgButton(hwndDlg,IDC_USEID6,(config_riol == 4)?1:0);
			CheckDlgButton(hwndDlg,IDC_USEID5,(config_riol != 0 && config_riol != 1 && config_riol != 4)?1:0);
			CheckDlgButton(hwndDlg,IDC_CONVERT1,(config_fixtitles&1)?1:0);
			CheckDlgButton(hwndDlg,IDC_CONVERT2,(config_fixtitles&2)?1:0);
			EnableWindow(GetDlgItem(hwndDlg,IDC_TAGZ_DEFAULT),config_useexttitles);
			EnableWindow(GetDlgItem(hwndDlg,IDC_FORMAT),config_useexttitles);
			EnableWindow(GetDlgItem(hwndDlg,IDC_ATF_INFO),config_useexttitles);
		return 0;

		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
				case IDC_CHECK1:
					config_useexttitles=!!IsDlgButtonChecked(hwndDlg,IDC_CHECK1);
					EnableWindow(GetDlgItem(hwndDlg,IDC_TAGZ_DEFAULT),config_useexttitles);
					EnableWindow(GetDlgItem(hwndDlg,IDC_FORMAT),config_useexttitles);
					EnableWindow(GetDlgItem(hwndDlg,IDC_ATF_INFO),config_useexttitles);
				break;

				case IDC_TAGZ_HELP:
				{
					wchar_t dirmask[MAX_PATH] = {0}, lang_code[4] = {0};
					lstrcpynW(lang_code, langManager->GetLanguageIdentifier(LANG_LANG_CODE), 3);

					// if we're not using a language pack or it reports en-US then use the default
					if(!config_langpack[0] || !lang_code[0] || !_wcsicmp(lang_code, L"en"))
					{
						GetTempPathW(MAX_PATH, dirmask);
						PathCombineW(dirmask, dirmask, L"atf.htm");
						if (!PathFileExistsW(dirmask))
						{
						save_local:
							DWORD size = 0, written = 0;
							HGLOBAL hResource = langManager->LoadResourceFromFile(hMainInstance, hMainInstance, RT_HTML,MAKEINTRESOURCE(IDR_ATF_HTML), &size);

							HANDLE hFile = CreateFileW(dirmask, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
							if (INVALID_HANDLE_VALUE != hFile)
							{
								WriteFile(hFile, hResource, size, &written, NULL);
								CloseHandle(hFile);
							}
						}
					}
					else
					{
						PathCombineW(dirmask, lang_directory, L"atf.htm");
						if (!PathFileExistsW(dirmask))
						{
							goto save_local;
						}
					}
					myOpenURL(hwndDlg, dirmask);
				}
				break;

				case IDC_TAGZ_DEFAULT:
					StringCchCopyW(config_titlefmt, sizeof(config_titlefmt)/sizeof(*config_titlefmt), L"[%artist% - ]$if2(%title%,$filepart(%filename%))");
					SetDlgItemTextW(hwndDlg,IDC_FORMAT,config_titlefmt);
				break;

				case IDC_FORMAT:
					if (HIWORD(wParam) == EN_CHANGE)
					{
						GetDlgItemTextW(hwndDlg,IDC_FORMAT,config_titlefmt, sizeof(config_titlefmt)/sizeof(*config_titlefmt) - 1);
						config_titlefmt[sizeof(config_titlefmt)/sizeof(*config_titlefmt) - 1]=0;
						atf_changed = !!lstrcmpW(old_config_titlefmt,config_titlefmt);
					}
				break;

				case IDC_CONVERT1:
				case IDC_CONVERT2:
					config_fixtitles = (IsDlgButtonChecked(hwndDlg,IDC_CONVERT1)?1:0)|(IsDlgButtonChecked(hwndDlg,IDC_CONVERT2)?2:0);
				break;

				case IDC_USEID3:
				case IDC_USEID4:
				case IDC_USEID5:
				case IDC_USEID6:
					if (HIWORD(wParam) == BN_CLICKED)
					{
						config_riol = IsDlgButtonChecked(hwndDlg,IDC_USEID4)?1:2;
						if (config_riol==2) {
							config_riol = IsDlgButtonChecked(hwndDlg,IDC_USEID3)?0:2;
						}
						if (config_riol==2) {
							config_riol = IsDlgButtonChecked(hwndDlg,IDC_USEID6)?4:2;
						}
					}
				break;
			}
		return 0;

		case WM_DESTROY:
			char titleStr[64] = {0};
			if(((atf_changed && !!config_useexttitles) || (old_config_useexttitles != config_useexttitles )) &&
				MessageBoxA(hwndDlg,getString(IDS_ATF_HAS_CHANGED,NULL,0),
						   getString(IDS_REFRESH_PLAYLIST_TITLES,titleStr,64),
						   MB_ICONQUESTION | MB_YESNO) == IDYES)
			{
				wchar_t ft[FILETITLE_SIZE] = {0};
				for (int x = 0; x < PlayList_getlength(); x ++)
				{
					if (!PlayList_gethidden(x) && !PlayList_hasanycurtain(x))
					{
						wchar_t fn[FILENAME_SIZE] = {0};
						PlayList_getitem(x, fn, ft);
						PlayList_setitem(x, fn, PlayList_gettitle(fn, 1));
						PlayList_setlastlen(x);
					}
				}
				InvalidateRect(hPLWindow, NULL, FALSE);
			}
		break;
	}

	link_handledraw(hwndDlg,uMsg,wParam,lParam);
	return 0;
}