This repository was archived by the owner on Feb 9, 2021. It is now read-only.
forked from hypfvieh/foo_subsonic
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpreferences.cpp
More file actions
executable file
·319 lines (236 loc) · 12.7 KB
/
preferences.cpp
File metadata and controls
executable file
·319 lines (236 loc) · 12.7 KB
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
#include "foo_subsonic.h"
#include "preferences.h"
#include "sqliteCacheDb.h"
#include "consts.h"
namespace Preferences {
const GUID guid_connect_url_data = { 0x4dcf833, 0x78b7, 0x4549,{ 0xaf, 0x34, 0xfd, 0xd3, 0x9c, 0x13, 0x9, 0xde } };
cfg_string connect_url_data(guid_connect_url_data, "");
const GUID guid_username_data = { 0x27dab537, 0xfe3a, 0x4119,{ 0xa0, 0x64, 0x3c, 0x43, 0xb5, 0x91, 0xa5, 0xb8 } };
cfg_string username_data(guid_username_data, "");
const GUID guid_password_data = { 0x3c3a9af4, 0xd496, 0x49da,{ 0xb6, 0xc, 0xe7, 0xa, 0x97, 0xd5, 0xde, 0x16 } };
cfg_string password_data(guid_password_data, "");
const GUID guid_check_selfsignedcerts_data = { 0x141b2ec3, 0x6b59, 0x49b3,{ 0xb7, 0xd7, 0x52, 0xcf, 0xb3, 0x8d, 0xe2, 0xc } };
cfg_bool check_selfsignedcerts_data(guid_check_selfsignedcerts_data, false);
const GUID guid_connect_timeout_data = { 0x5d359a74, 0x8010, 0x4fe0,{ 0xaf, 0x90, 0x45, 0x4, 0x9b, 0x1a, 0xb9, 0x84 } };
cfg_int connect_timeout_data(guid_connect_timeout_data, 10);
// Proxy Stuff
const GUID guid_proxy_url_data = { 0x91582c5c, 0xe5cf, 0x4b21,{ 0x95, 0x18, 0x59, 0x1c, 0xdd, 0x43, 0xe2, 0x45 } };
cfg_string proxy_url_data(guid_proxy_url_data, "");
const GUID guid_proxy_settings_no_data = { 0xc837b708, 0xf51f, 0x4e22,{ 0xae, 0xe2, 0x97, 0x7, 0xdb, 0x78, 0xca, 0xa5 } };
cfg_bool proxy_settings_no_data(guid_proxy_settings_no_data, true);
const GUID guid_proxy_settings_system_data = { 0x355211d1, 0x5de2, 0x46ad,{ 0xaf, 0xb1, 0x9d, 0xfe, 0x18, 0xf8, 0xd4, 0xcb } };
cfg_bool proxy_settings_system_data(guid_proxy_settings_system_data, false);
const GUID guid_proxy_settings_custom_data = { 0x2be7e55f, 0xcc61, 0x4368,{ 0xa5, 0x3f, 0x47, 0x68, 0x5b, 0x97, 0x83, 0xd2 } };
cfg_bool proxy_settings_custom_data(guid_proxy_settings_custom_data, false);
// CoverArt Stuff
const GUID guid_coverart_size_data = { 0xf79bf5f6, 0x6630, 0x415b,{ 0x80, 0xcc, 0x38, 0x3c, 0xc8, 0x67, 0x46, 0x86 } };
cfg_int coverart_size_data(guid_coverart_size_data, 500);
const GUID guid_coverart_download = { 0x1a4e3073, 0x6af4, 0x4d9c,{ 0x89, 0xb5, 0x6c, 0xe0, 0xb0, 0x17, 0xdb, 0x3f } };
cfg_bool coverart_download(guid_coverart_download, true);
const GUID guid_coverart_resize = { 0x4ed09771, 0x2bc5, 0x4f63,{ 0xba, 0xa3, 0x46, 0x18, 0x60, 0xec, 0x28, 0xa } };
cfg_bool coverart_resize(guid_coverart_resize, true);
// Cache loading
const GUID guid_load_album_cache_on_startup = { 0xc0f70300, 0x869, 0x4098,{ 0x81, 0xfc, 0xd8, 0x46, 0x38, 0xd9, 0x71, 0x3c } };
cfg_bool load_album_cache_on_startup(guid_load_album_cache_on_startup, true);
const GUID guid_load_playlist_cache_on_startup = { 0xfbaa3503, 0x1d09, 0x49d0,{ 0x8e, 0x6c, 0x5, 0xe0, 0x5e, 0xa3, 0x87, 0xba } };
cfg_bool load_playlist_cache_on_startup(guid_load_playlist_cache_on_startup, true);
}
class PreferencesPageInstance : public CDialogImpl<PreferencesPageInstance>, public preferences_page_instance {
private:
CEdit connect_url;
CEdit username;
CEdit password;
CEdit proxy_url;
CEdit connect_timeout;
CEdit coverart_size;
CCheckBox use_selfsignedcerts;
CCheckBox use_coverart_dl;
CCheckBox use_coverart_resize;
CCheckBox use_load_album_cache_on_startup;
CCheckBox use_load_playlist_cache_on_startup;
CButton proxy_settings_no;
CButton proxy_settings_system;
CButton proxy_settings_custom;
preferences_page_callback::ptr on_change_callback;
public:
PreferencesPageInstance(preferences_page_callback::ptr callback) : on_change_callback(callback)
{}
enum { IDD = IDD_PREFERENCES };
BEGIN_MSG_MAP(CPreferencesDialog)
MSG_WM_INITDIALOG(OnInitDialog)
COMMAND_HANDLER_EX(IDC_CONNECT_URL_DATA, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_USERNAME_DATA, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_PASSWORD_DATA, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_CHECK_SELFSIGNED, BN_CLICKED, OnChanged)
COMMAND_HANDLER_EX(IDC_CHK_PASSWORD_AS_HASH, BN_CLICKED, OnChanged)
COMMAND_HANDLER_EX(IDC_RADIO_PROXY_CUSTOM, BN_CLICKED, OnChanged)
COMMAND_HANDLER_EX(IDC_RADIO_PROXY_SYSTEM, BN_CLICKED, OnChanged)
COMMAND_HANDLER_EX(IDC_RADIO_PROXY_NO, BN_CLICKED, OnChanged)
COMMAND_HANDLER_EX(IDC_PROXY_URL_DATA, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_CONNECT_TIMEOUT_DATA, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_CHK_RESIZECOVERART, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_CHK_DLCOVERART, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_TXT_COVERARTSIZE, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_CHK_LOAD_ALBUM_CACHE_ONSTARTUP, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_CHK_LOAD_PLAYLIST_CACHE_ONSTARTUP, EN_UPDATE, OnChanged)
COMMAND_HANDLER(IDC_BTN_RESET_COVERART_CACHE, BN_CLICKED, OnBnClickedBtnResetCoverartCache)
COMMAND_HANDLER(IDC_BTN_RESET_CACHE, BN_CLICKED, OnBnClickedBtnResetCache)
NOTIFY_HANDLER(IDC_LNK_HELP, NM_CLICK, OnNMClickLnkHelp)
END_MSG_MAP()
BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam) {
connect_url = GetDlgItem(IDC_CONNECT_URL_DATA);
username = GetDlgItem(IDC_USERNAME_DATA);
password = GetDlgItem(IDC_PASSWORD_DATA);
coverart_size = GetDlgItem(IDC_TXT_COVERARTSIZE);
use_selfsignedcerts = GetDlgItem(IDC_CHECK_SELFSIGNED);
use_coverart_dl = GetDlgItem(IDC_CHK_DLCOVERART);
use_coverart_resize = GetDlgItem(IDC_CHK_RESIZECOVERART);
use_load_album_cache_on_startup = GetDlgItem(IDC_CHK_LOAD_ALBUM_CACHE_ONSTARTUP);
use_load_playlist_cache_on_startup = GetDlgItem(IDC_CHK_LOAD_PLAYLIST_CACHE_ONSTARTUP);
proxy_url = GetDlgItem(IDC_PROXY_HOSTNAME_DATA);
connect_timeout = GetDlgItem(IDC_CONNECT_TIMEOUT_DATA);
proxy_settings_custom = GetDlgItem(IDC_RADIO_PROXY_CUSTOM);
proxy_settings_system = GetDlgItem(IDC_RADIO_PROXY_SYSTEM);
proxy_settings_no = GetDlgItem(IDC_RADIO_PROXY_NO);
uSetWindowText(connect_url, Preferences::connect_url_data);
uSetWindowText(username, Preferences::username_data);
uSetWindowText(password, Preferences::password_data);
uSetWindowText(proxy_url, Preferences::proxy_url_data);
char tmp[20];
snprintf(tmp, 20, "%i", Preferences::connect_timeout_data.get_value());
uSetWindowText(connect_timeout, tmp);
snprintf(tmp, 20, "%i", Preferences::coverart_size_data.get_value());
uSetWindowText(coverart_size, tmp);
//CheckRadioButton(IDC_RADIO_PROXY_NO, IDC_RADIO_PROXY_CUSTOM, IDC_RADIO)
CheckDlgButton(IDC_RADIO_PROXY_NO, Preferences::proxy_settings_no_data);
CheckDlgButton(IDC_RADIO_PROXY_SYSTEM, Preferences::proxy_settings_system_data);
CheckDlgButton(IDC_RADIO_PROXY_CUSTOM, Preferences::proxy_settings_custom_data);
CheckDlgButton(IDC_CHECK_SELFSIGNED, Preferences::check_selfsignedcerts_data);
CheckDlgButton(IDC_CHK_DLCOVERART, Preferences::coverart_download);
CheckDlgButton(IDC_CHK_RESIZECOVERART, Preferences::coverart_resize);
CheckDlgButton(IDC_CHK_LOAD_ALBUM_CACHE_ONSTARTUP, Preferences::load_album_cache_on_startup);
CheckDlgButton(IDC_CHK_LOAD_PLAYLIST_CACHE_ONSTARTUP, Preferences::load_playlist_cache_on_startup);
return 0;
}
bool has_changed() {
pfc::string8 temp;
uGetWindowText(proxy_url, temp);
if (Preferences::proxy_url_data != temp && checkProxyPrefix(temp)) return true;
uGetWindowText(connect_url, temp);
if (Preferences::connect_url_data != temp) return true;
uGetWindowText(username, temp);
if (Preferences::username_data != temp) return true;
uGetWindowText(password, temp);
if (Preferences::password_data != temp) return true;
uGetWindowText(connect_timeout, temp);
int tInt = atoi(temp.c_str());
if (Preferences::connect_timeout_data != tInt) return true;
bool data;
data = IsDlgButtonChecked(IDC_CHECK_SELFSIGNED) == BST_CHECKED;
if (Preferences::check_selfsignedcerts_data != data) return true;
data = IsDlgButtonChecked(IDC_RADIO_PROXY_CUSTOM) == BST_CHECKED;
if (Preferences::proxy_settings_custom_data != data) return true;
data = IsDlgButtonChecked(IDC_RADIO_PROXY_SYSTEM) == BST_CHECKED;
if (Preferences::proxy_settings_system_data != data) return true;
data = IsDlgButtonChecked(IDC_RADIO_PROXY_NO) == BST_CHECKED;
if (Preferences::proxy_settings_no_data != data) return true;
data = IsDlgButtonChecked(IDC_CHK_DLCOVERART) == BST_CHECKED;
if (Preferences::coverart_download != data) return true;
data = IsDlgButtonChecked(IDC_CHK_RESIZECOVERART) == BST_CHECKED;
if (Preferences::coverart_resize != data) return true;
data = IsDlgButtonChecked(IDC_CHK_LOAD_ALBUM_CACHE_ONSTARTUP) == BST_CHECKED;
if (Preferences::load_album_cache_on_startup != data) return true;
data = IsDlgButtonChecked(IDC_CHK_LOAD_PLAYLIST_CACHE_ONSTARTUP) == BST_CHECKED;
if (Preferences::load_playlist_cache_on_startup != data) return true;
return false;
}
bool checkProxyPrefix(pfc::string8 proxyHost) {
pfc::string workstr = proxyHost;
workstr = workstr.toLower();
return workstr.startsWith("http://") || workstr.startsWith("https://") || workstr.startsWith("socks://") || workstr.startsWith("socks5://");
}
t_uint32 get_state() {
t_uint32 state = preferences_state::resettable;
if (has_changed()) state |= preferences_state::changed;
return state;
}
void apply() {
uGetWindowText(connect_url, Preferences::connect_url_data);
uGetWindowText(username, Preferences::username_data);
uGetWindowText(password, Preferences::password_data);
uGetWindowText(proxy_url, Preferences::proxy_url_data);
pfc::string8 tmp;
uGetWindowText(connect_timeout, tmp);
Preferences::connect_timeout_data = atoi(tmp.c_str());
uGetWindowText(coverart_size, tmp);
Preferences::coverart_size_data = atoi(tmp.c_str());
Preferences::check_selfsignedcerts_data = IsDlgButtonChecked(IDC_CHECK_SELFSIGNED) == BST_CHECKED;
Preferences::proxy_settings_no_data = IsDlgButtonChecked(IDC_RADIO_PROXY_NO) == BST_CHECKED;
Preferences::proxy_settings_system_data = IsDlgButtonChecked(IDC_RADIO_PROXY_SYSTEM) == BST_CHECKED;
Preferences::proxy_settings_custom_data = IsDlgButtonChecked(IDC_RADIO_PROXY_CUSTOM) == BST_CHECKED;
Preferences::coverart_download = IsDlgButtonChecked(IDC_CHK_DLCOVERART) == BST_CHECKED;
Preferences::coverart_resize = IsDlgButtonChecked(IDC_CHK_RESIZECOVERART) == BST_CHECKED;
Preferences::load_album_cache_on_startup = IsDlgButtonChecked(IDC_CHK_LOAD_ALBUM_CACHE_ONSTARTUP) == BST_CHECKED;
Preferences::load_playlist_cache_on_startup = IsDlgButtonChecked(IDC_CHK_LOAD_PLAYLIST_CACHE_ONSTARTUP) == BST_CHECKED;
}
void on_change() {
on_change_callback->on_state_changed();
}
void reset() {
uSetWindowText(connect_url, "");
uSetWindowText(username, "");
uSetWindowText(password, "");
uSetWindowText(proxy_url, "");
uSetWindowText(connect_timeout, "10");
uSetWindowText(coverart_size, "500");
CheckDlgButton(IDC_CHECK_SELFSIGNED, FALSE);
CheckDlgButton(IDC_CHK_PASSWORD_AS_HASH, TRUE);
CheckDlgButton(IDC_CHK_DLCOVERART, TRUE);
CheckDlgButton(IDC_CHK_RESIZECOVERART, TRUE);
CheckDlgButton(IDC_CHK_LOAD_ALBUM_CACHE_ONSTARTUP, TRUE);
CheckDlgButton(IDC_CHK_LOAD_PLAYLIST_CACHE_ONSTARTUP, TRUE);
CheckDlgButton(IDC_RADIO_PROXY_NO, TRUE);
CheckDlgButton(IDC_RADIO_PROXY_CUSTOM, FALSE);
CheckDlgButton(IDC_RADIO_PROXY_SYSTEM, FALSE);
on_change();
}
void OnChanged(UINT, int, HWND) {
on_change();
}
LRESULT OnBnClickedBtnResetCoverartCache(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
const int result = MessageBox(L"This removes all cached covert arts. Are you sure?", L"Delete cached cover arts", MB_YESNO | MB_ICONQUESTION);
if (result == IDYES) {
SqliteCacheDb::getInstance()->clearCoverArtCache();
MessageBox(L"Cover arts removed.", L"Cover arts Cache", MB_OK | MB_ICONINFORMATION);
}
return 0;
}
LRESULT OnBnClickedBtnResetCache(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
const int result = MessageBox(L"This deletes your offline cached data. Are you sure?", L"Delete Offline Cache", MB_YESNO | MB_ICONQUESTION);
if (result == IDYES) {
SqliteCacheDb::getInstance()->clearCache();
MessageBox(L"Offline cache cleared.", L"Offline Cache", MB_OK | MB_ICONINFORMATION);
}
return 0;
}
LRESULT OnNMClickLnkHelp(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/) {
ShellExecute(0, L"open", L"https://github.com/hypfvieh/foo_subsonic/wiki", NULL, NULL, SW_SHOW);
return 0;
}
};
class PreferencesPage : public preferences_page_impl<PreferencesPageInstance> {
public:
const char * get_name() {
return COMPONENT_TITLE;
}
GUID get_guid() {
static const GUID guid = { 0x6829a87b, 0xd15f, 0x4ee7,{ 0xb7, 0xa, 0xe9, 0x6a, 0xfe, 0xd4, 0x2d, 0xd7 } };
return guid;
}
GUID get_parent_guid() {
return preferences_page::guid_media_library;
}
};
preferences_page_factory_t<PreferencesPage> _;