prefs.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. #include "main.h"
  2. #include "config.h"
  3. #include "api__gen_ml.h"
  4. #include "resource.h"
  5. #include "./navigation.h"
  6. #include "./ml_ipc_0313.h"
  7. #include <shlwapi.h>
  8. #include <strsafe.h>
  9. extern HNAVCTRL hNavigation;
  10. #define PASSWORD_MAXLEN 256
  11. void encode_mimestr(char *in, char *out)
  12. {
  13. char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  14. int shift = 0;
  15. int accum = 0;
  16. while (in && *in)
  17. {
  18. if (*in)
  19. {
  20. accum <<= 8;
  21. shift += 8;
  22. accum |= *in++;
  23. }
  24. while (shift >= 6)
  25. {
  26. shift -= 6;
  27. *out++ = alphabet[(accum >> shift) & 0x3F];
  28. }
  29. }
  30. if (shift == 4)
  31. {
  32. *out++ = alphabet[(accum & 0xF) << 2];
  33. *out++ = '=';
  34. }
  35. else if (shift == 2)
  36. {
  37. *out++ = alphabet[(accum & 0x3) << 4];
  38. *out++ = '=';
  39. *out++ = '=';
  40. }
  41. *out++ = 0;
  42. }
  43. int ResizeComboBoxDropDown(HWND hwndDlg, UINT id, const wchar_t * str, int width){
  44. SIZE size = {0};
  45. HWND control = GetDlgItem(hwndDlg, id);
  46. HDC hdc = GetDC(control);
  47. // get and select parent dialog's font so that it'll calculate things correctly
  48. HFONT font = (HFONT)SendMessage(hwndDlg,WM_GETFONT,0,0), oldfont = (HFONT)SelectObject(hdc,font);
  49. GetTextExtentPoint32W(hdc, str, lstrlenW(str)+1, &size);
  50. int ret = width;
  51. if(size.cx > width)
  52. {
  53. SendDlgItemMessage(hwndDlg, id, CB_SETDROPPEDWIDTH, size.cx, 0);
  54. ret = size.cx;
  55. }
  56. SelectObject(hdc, oldfont);
  57. ReleaseDC(control, hdc);
  58. return ret;
  59. }
  60. static void CenterPopup(HWND hwnd, HWND hCenter)
  61. {
  62. if (NULL == hwnd || NULL == hCenter)
  63. return;
  64. RECT centerRect, windowRect;
  65. if (!GetWindowRect(hwnd, &windowRect) || !GetWindowRect(hCenter, &centerRect))
  66. return;
  67. windowRect.left = centerRect.left + ((centerRect.right - centerRect.left) - (windowRect.right - windowRect.left))/2;
  68. windowRect.top = centerRect.top + ((centerRect.bottom - centerRect.top) - (windowRect.bottom - windowRect.top))/2;
  69. SetWindowPos(hwnd, NULL, windowRect.left, windowRect.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
  70. }
  71. static INT MessageBoxWA(HWND hwnd, LPCWSTR pszText, LPCWSTR pszCaption, UINT uType)
  72. {
  73. WCHAR szText[128] = {0}, szCaption[2048] = {0};
  74. if (IS_INTRESOURCE(pszText))
  75. {
  76. if (NULL != pszText)
  77. {
  78. WASABI_API_LNGSTRINGW_BUF((INT)(INT_PTR)pszText, szText, ARRAYSIZE(szText));
  79. pszText = szText;
  80. }
  81. }
  82. if (IS_INTRESOURCE(pszCaption))
  83. {
  84. if (NULL != pszCaption)
  85. {
  86. WASABI_API_LNGSTRINGW_BUF((INT)(INT_PTR)pszCaption, szCaption, ARRAYSIZE(szCaption));
  87. pszCaption = szCaption;
  88. }
  89. }
  90. return MessageBoxW(hwnd, pszText, pszCaption, uType);
  91. }
  92. static INT_PTR CALLBACK Prefs1Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  93. {
  94. switch (uMsg)
  95. {
  96. case WM_INITDIALOG:
  97. {
  98. CheckDlgButton(hwndDlg, IDC_PLPLAYLIST, !!g_config->ReadInt(L"plplaymode", 1));
  99. CheckDlgButton(hwndDlg, IDC_VIEWPLAYMODE, !!g_config->ReadInt(L"viewplaymode", 1));
  100. wchar_t* str = WASABI_API_LNGSTRINGW(IDS_PLAY_SELECTED);
  101. SendDlgItemMessageW(hwndDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)str);
  102. int width = ResizeComboBoxDropDown(hwndDlg, IDC_COMBO1, str, 0);
  103. SendDlgItemMessageW(hwndDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)(str = WASABI_API_LNGSTRINGW(IDS_ENQUEUE_SELECTED)));
  104. ResizeComboBoxDropDown(hwndDlg, IDC_COMBO1, str, width);
  105. SendDlgItemMessage(hwndDlg, IDC_COMBO1, CB_SETCURSEL, g_config->ReadInt(L"enqueuedef", 0) ? 1 : 0, 0);
  106. CheckDlgButton(hwndDlg, IDC_CHECK1, !!g_config->ReadInt(L"attachlbolt", 0));
  107. CheckDlgButton(hwndDlg, IDC_PL_SEND_TO, !!g_config->ReadInt(L"pl_send_to", 1));
  108. CheckDlgButton(hwndDlg, IDC_PMP_SEND_TO, !!g_config->ReadInt(L"pmp_send_to", 1));
  109. if (!GetModuleHandleW(L"ml_pmp.dll")) EnableWindow(GetDlgItem(hwndDlg, IDC_PMP_SEND_TO), FALSE);
  110. CheckDlgButton(hwndDlg, IDC_WRITE_RATINGS, !!g_config->ReadInt(L"writeratings", 0));
  111. CheckDlgButton(hwndDlg, IDC_GROUP_BUTTONS, !!g_config->ReadInt(L"groupbtn", 1));
  112. int colresmode = g_config->ReadInt(L"column_resize_mode", 0);
  113. width = 0;
  114. SendDlgItemMessageW(hwndDlg, IDC_COMBO2, CB_ADDSTRING, 0, (LPARAM)(str = WASABI_API_LNGSTRINGW(IDS_COL_NORMAL)));
  115. width = ResizeComboBoxDropDown(hwndDlg, IDC_COMBO2, str, width);
  116. SendDlgItemMessageW(hwndDlg, IDC_COMBO2, CB_ADDSTRING, 0, (LPARAM)(str = WASABI_API_LNGSTRINGW(IDS_COL_SELONLY)));
  117. ResizeComboBoxDropDown(hwndDlg, IDC_COMBO2, str, width);
  118. SendDlgItemMessageW(hwndDlg, IDC_COMBO2, CB_ADDSTRING, 0, (LPARAM)(str = WASABI_API_LNGSTRINGW(IDS_COL_PROP)));
  119. ResizeComboBoxDropDown(hwndDlg, IDC_COMBO2, str, 0);
  120. SendDlgItemMessageW(hwndDlg, IDC_COMBO2, CB_SETCURSEL, colresmode, 0);
  121. }
  122. break;
  123. case WM_COMMAND:
  124. switch (LOWORD(wParam))
  125. {
  126. case IDC_COMBO1:
  127. if (HIWORD(wParam) == CBN_SELCHANGE)
  128. {
  129. int a = (INT)SendDlgItemMessage(hwndDlg, IDC_COMBO1, CB_GETCURSEL, 0, 0),
  130. mode = g_config->ReadInt(L"enqueuedef", 0);
  131. if ((a == 1) != mode)
  132. {
  133. mode = (a == 1);
  134. g_config->WriteInt(L"enqueuedef", mode);
  135. HWND hView = (HWND)SENDMLIPC(g_hwnd, ML_IPC_GETCURRENTVIEW, 0);
  136. if (IsWindow(hView)) PostMessageW(hView, WM_DISPLAYCHANGE, 0, 0);
  137. }
  138. // v5.66+ - send a general notification so plug-ins can (if needed update on
  139. // the play / enqueue mode change (mainly added for ml_playlists)
  140. pluginMessage p = {ML_MSG_VIEW_PLAY_ENQUEUE_CHANGE, (INT_PTR)!!mode,
  141. (INT_PTR)!!g_config->ReadInt(L"groupbtn", 1), 0};
  142. SENDMLIPC(g_hwnd, ML_IPC_SEND_PLUGIN_MESSAGE, (WPARAM)&p);
  143. }
  144. break;
  145. case IDC_PL_SEND_TO:
  146. g_config->WriteInt(L"pl_send_to", !!IsDlgButtonChecked(hwndDlg, IDC_PL_SEND_TO));
  147. break;
  148. case IDC_PMP_SEND_TO:
  149. g_config->WriteInt(L"pmp_send_to", !!IsDlgButtonChecked(hwndDlg, IDC_PMP_SEND_TO));
  150. break;
  151. case IDC_WRITE_RATINGS:
  152. g_config->WriteInt(L"writeratings", !!IsDlgButtonChecked(hwndDlg, IDC_WRITE_RATINGS));
  153. break;
  154. case IDC_PLPLAYLIST:
  155. g_config->WriteInt(L"plplaymode", !!IsDlgButtonChecked(hwndDlg, IDC_PLPLAYLIST));
  156. break;
  157. case IDC_VIEWPLAYMODE:
  158. g_config->WriteInt(L"viewplaymode", !!IsDlgButtonChecked(hwndDlg, IDC_VIEWPLAYMODE));
  159. break;
  160. case IDC_COMBO2:
  161. if (HIWORD(wParam) == CBN_SELCHANGE)
  162. {
  163. int colresmode = (INT)SendDlgItemMessage(hwndDlg, IDC_COMBO2, CB_GETCURSEL, 0, 0);
  164. g_config->WriteInt(L"column_resize_mode", colresmode);
  165. }
  166. break;
  167. case IDC_CHECK1:
  168. g_config->WriteInt(L"attachlbolt", !!IsDlgButtonChecked(hwndDlg, IDC_CHECK1));
  169. break;
  170. case IDC_GROUP_BUTTONS:
  171. {
  172. g_config->WriteInt(L"groupbtn", !!IsDlgButtonChecked(hwndDlg, IDC_GROUP_BUTTONS));
  173. // refresh the current view as otherwise is a pain to dynamically update as needed
  174. PostMessage(g_hwnd, WM_USER + 30, 0, 0);
  175. break;
  176. }
  177. }
  178. break;
  179. }
  180. return 0;
  181. }
  182. static INT_PTR CALLBACK GetTVPassProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  183. {
  184. switch (uMsg)
  185. {
  186. case WM_INITDIALOG:
  187. {
  188. PostMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_GPASS), TRUE);
  189. }
  190. break;
  191. case WM_COMMAND:
  192. switch (LOWORD(wParam))
  193. {
  194. case IDOK:
  195. {
  196. char pass1[64] = {0};
  197. char password[4096] = {0};
  198. GetDlgItemTextA(hwndDlg, IDC_GPASS, pass1, sizeof(pass1) - 1);
  199. encode_mimestr(pass1, password);
  200. if (strcmp(password, g_config->ReadString("stctka", "none")) != 0)
  201. {
  202. wchar_t titleStr[32] = {0};
  203. MessageBoxW(NULL,
  204. WASABI_API_LNGSTRINGW(IDS_INVALID_PASSWORD),
  205. WASABI_API_LNGSTRINGW_BUF(IDS_INTERNET_ACCESS,titleStr,32),
  206. MB_OK);
  207. EndDialog(hwndDlg, 0);
  208. break;
  209. }
  210. else
  211. {
  212. EndDialog(hwndDlg, 1);
  213. break;
  214. }
  215. }
  216. case IDCANCEL:
  217. {
  218. EndDialog(hwndDlg, 0);
  219. break;
  220. }
  221. }
  222. break;
  223. }
  224. return 0;
  225. }
  226. static INT_PTR InternetPassword_OnInitDialog(HWND hwnd, HWND hFocus, LPARAM lParam)
  227. {
  228. HWND hControl = GetDlgItem(hwnd, IDC_EDIT_PASSWORD);
  229. if (NULL != hControl)
  230. PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)hControl, TRUE);
  231. hControl = GetDlgItem(hwnd, IDOK);
  232. if (NULL != hControl)
  233. EnableWindow(hControl, FALSE);
  234. HWND hCenter = (HWND)lParam;
  235. if (NULL != hCenter && IsWindow(hCenter))
  236. CenterPopup(hwnd, hCenter);
  237. SendMessage(hwnd, DM_REPOSITION, 0, 0L);
  238. return FALSE;
  239. }
  240. static BOOL InternetPassword_GetPassword(HWND hwnd, LPWSTR pszBuffer, INT cchBufferMax)
  241. {
  242. HWND hEdit1 = GetDlgItem(hwnd, IDC_EDIT_PASSWORD);
  243. HWND hEdit2 = GetDlgItem(hwnd, IDC_EDIT_PASSWORD_VERIFY);
  244. if (NULL != hEdit1 && NULL != hEdit2)
  245. {
  246. WCHAR szPwd1[PASSWORD_MAXLEN] = {0}, szPwd2[PASSWORD_MAXLEN] = {0};
  247. INT cchPwd1 = GetWindowTextW(hEdit1, szPwd1, ARRAYSIZE(szPwd1));
  248. INT cchPwd2 = GetWindowTextW(hEdit2, szPwd2, ARRAYSIZE(szPwd2));
  249. if (0 != cchPwd1 &&
  250. cchPwd1 == cchPwd2 &&
  251. CSTR_EQUAL == CompareStringW(LOCALE_USER_DEFAULT, 0, szPwd1, cchPwd1, szPwd2, cchPwd2))
  252. {
  253. if (NULL != pszBuffer && cchBufferMax > 0)
  254. {
  255. if (FAILED(StringCchCopyW(pszBuffer, cchBufferMax, szPwd1)))
  256. return FALSE;
  257. }
  258. return TRUE;
  259. }
  260. }
  261. return FALSE;
  262. }
  263. static void InternetPassword_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND hControl)
  264. {
  265. switch (commandId)
  266. {
  267. case IDC_EDIT_PASSWORD:
  268. case IDC_EDIT_PASSWORD_VERIFY:
  269. switch(eventId)
  270. {
  271. case EN_UPDATE:
  272. HWND hButton = GetDlgItem(hwnd, IDOK);
  273. if (NULL != hButton)
  274. {
  275. EnableWindow(hButton, InternetPassword_GetPassword(hwnd, NULL, 0));
  276. }
  277. break;
  278. }
  279. break;
  280. case IDOK:
  281. {
  282. WCHAR szPassword[PASSWORD_MAXLEN] = {0};
  283. BOOL passwordOk = InternetPassword_GetPassword(hwnd, szPassword, ARRAYSIZE(szPassword));
  284. if (FALSE == passwordOk)
  285. {
  286. MessageBoxWA(hwnd, MAKEINTRESOURCEW(IDS_PASSWORD_NO_MATCH), MAKEINTRESOURCEW(IDS_INTERNET_ACCESS),
  287. MB_OK | MB_ICONEXCLAMATION);
  288. }
  289. else
  290. {
  291. char szPasswordAnsi[PASSWORD_MAXLEN * 2] = {0};
  292. BOOL fInvalidChar;
  293. if (0 == WideCharToMultiByte(CP_ACP, 0, szPassword, -1, szPasswordAnsi, ARRAYSIZE(szPasswordAnsi), NULL, &fInvalidChar) ||
  294. FALSE != fInvalidChar)
  295. {
  296. // TODO: put better error description
  297. LPCWSTR pszMessage = MAKEINTRESOURCEW(IDS_INVALID_PASSWORD);
  298. MessageBoxWA(hwnd, pszMessage, MAKEINTRESOURCEW(IDS_INTERNET_ACCESS), MB_OK | MB_ICONERROR);
  299. }
  300. else
  301. {
  302. char szEncoded[PASSWORD_MAXLEN * 2] = {0};
  303. encode_mimestr(szPasswordAnsi, szEncoded);
  304. g_config->WriteString("stctka", szEncoded);
  305. EndDialog(hwnd, IDOK);
  306. }
  307. }
  308. break;
  309. }
  310. case IDCANCEL:
  311. EndDialog(hwnd, IDCANCEL);
  312. break;
  313. }
  314. }
  315. static INT_PTR CALLBACK InternetPassword_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  316. {
  317. switch (uMsg)
  318. {
  319. case WM_INITDIALOG: return InternetPassword_OnInitDialog(hwnd, (HWND)wParam, lParam);
  320. case WM_COMMAND: InternetPassword_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); break;
  321. }
  322. return 0;
  323. }
  324. static INT_PTR CALLBACK Prefs2Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  325. {
  326. switch (uMsg)
  327. {
  328. case WM_INITDIALOG:
  329. {
  330. int passprompt = g_config->ReadInt(L"tvpp", 0);
  331. if (passprompt && strcmp("none", g_config->ReadString("stctka", "none")) == 0)
  332. {
  333. wchar_t titleStr[32] = {0};
  334. MessageBoxW(hwndDlg,
  335. WASABI_API_LNGSTRINGW(IDS_RATINGS_PASSWORD_MISSING),
  336. WASABI_API_LNGSTRINGW_BUF(IDS_SERCURITY_ALERT,titleStr,32),
  337. MB_OK);
  338. passprompt = 0;
  339. }
  340. CheckDlgButton(hwndDlg, IDC_CHECK_PASSPROMPT, passprompt);
  341. EnableWindow(GetDlgItem(hwndDlg, IDC_ITV_CHANGEPASS), passprompt);
  342. {
  343. int rating = g_config->ReadInt(L"tvrating", 7);
  344. CheckDlgButton(hwndDlg, IDC_CHECK_RATING0, !!(rating&1) || !!(rating&2));
  345. CheckDlgButton(hwndDlg, IDC_CHECK_RATING1, !!(rating&4));
  346. CheckDlgButton(hwndDlg, IDC_CHECK_RATING2, !!(rating&8));
  347. CheckDlgButton(hwndDlg, IDC_CHECK_RATING3, !!(rating&16) || !!(rating&32));
  348. CheckDlgButton(hwndDlg, IDC_CHECK_RATING4, !!(rating&64));
  349. }
  350. if (passprompt && strcmp("none", g_config->ReadString("stctka", "none")) != 0)
  351. {
  352. INT_PTR result = WASABI_API_DIALOGBOX(IDD_PREFS_ITV_GETPASS, hwndDlg, GetTVPassProc);
  353. if (!result)
  354. {
  355. HWND next = GetWindow(hwndDlg,GW_CHILD);
  356. HWND warning = GetDlgItem(hwndDlg,IDC_STATIC_INFO);
  357. while(IsWindow(next))
  358. {
  359. if(next != warning)
  360. {
  361. HWND remove = next;
  362. next = GetWindow(next, GW_HWNDNEXT);
  363. DestroyWindow(remove);
  364. }
  365. else
  366. {
  367. next = GetWindow(next, GW_HWNDNEXT);
  368. }
  369. }
  370. break;
  371. }
  372. else
  373. {
  374. DestroyWindow(GetDlgItem(hwndDlg,IDC_STATIC_INFO));
  375. }
  376. }
  377. else
  378. {
  379. DestroyWindow(GetDlgItem(hwndDlg,IDC_STATIC_INFO));
  380. }
  381. }
  382. break;
  383. case WM_COMMAND:
  384. switch (LOWORD(wParam))
  385. {
  386. case IDC_CHECK_PASSPROMPT:
  387. {
  388. int passprompt = 0;
  389. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_PASSPROMPT)) passprompt = 1;
  390. else g_config->WriteString("stctka", 0);
  391. EnableWindow(GetDlgItem(hwndDlg, IDC_ITV_CHANGEPASS), passprompt);
  392. break;
  393. }
  394. case IDC_ITV_CHANGEPASS:
  395. {
  396. WASABI_API_DIALOGBOXPARAMW(IDD_PREFS_ITV_ASSIGNPASS, hwndDlg, InternetPassword_DialogProc, (LPARAM)hwndDlg);
  397. break;
  398. }
  399. }
  400. break;
  401. case WM_DESTROY:
  402. {
  403. if(!IsWindow(GetDlgItem(hwndDlg,IDC_STATIC_INFO)))
  404. {
  405. int rating = 0;
  406. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_RATING0)) rating |= (1 | 2);
  407. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_RATING1)) rating |= 4;
  408. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_RATING2)) rating |= 8;
  409. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_RATING3)) rating |= (16 | 32);
  410. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_RATING4)) rating |= 64;
  411. g_config->WriteInt(L"tvrating", rating);
  412. int passprompt = 0;
  413. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_PASSPROMPT)) passprompt = 1;
  414. g_config->WriteInt(L"tvpp", passprompt);
  415. if (passprompt)
  416. {
  417. if (strcmp("none", g_config->ReadString("stctka", "none")) == 0)
  418. {
  419. WASABI_API_DIALOGBOX(IDD_PREFS_ITV_ASSIGNPASS, hwndDlg, InternetPassword_DialogProc);
  420. }
  421. }
  422. #if 0 // no radio
  423. radio_updateTvView(1);
  424. #endif
  425. }
  426. }
  427. break;
  428. }
  429. return 0;
  430. }
  431. C_Config *g_view_metaconf = NULL;
  432. static UINT msgNotify = 0;
  433. static HINSTANCE cloud_hinst;
  434. static int IPC_GET_CLOUD_HINST = -1, last_pos;
  435. static INT_PTR CALLBACK Prefs3Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  436. {
  437. static int edit_inited;
  438. switch (uMsg)
  439. {
  440. case WM_INITDIALOG:
  441. {
  442. wchar_t buffer[MAX_PATH] = {0};
  443. edit_inited = 0;
  444. LPCWSTR pszPath = (LPCWSTR)SendMessageW(plugin.hwndParent, WM_WA_IPC, 0, IPC_GETPLUGINDIRECTORYW);
  445. if(PathCombineW(buffer, pszPath, L"ml_disc.dll") && PathFileExistsW(buffer))
  446. {
  447. PathCombineW(buffer, WINAMP_INI_DIR, L"Plugins\\ml\\cdrom.vmd");
  448. g_view_metaconf = new C_Config(buffer);
  449. CheckDlgButton(hwndDlg, IDC_SHOW_EJECT_ICONS, g_view_metaconf->ReadInt(L"showeject", 1));
  450. CheckDlgButton(hwndDlg, IDC_GROUP_DRIVES, g_view_metaconf->ReadInt(L"showparent", 0));
  451. if(!msgNotify) msgNotify = RegisterWindowMessageW(L"ripburn_nav_update");
  452. }
  453. else
  454. {
  455. DestroyWindow(GetDlgItem(hwndDlg,IDC_CD_DVD_ITEMS));
  456. DestroyWindow(GetDlgItem(hwndDlg,IDC_SHOW_EJECT_ICONS));
  457. DestroyWindow(GetDlgItem(hwndDlg,IDC_GROUP_DRIVES));
  458. RECT r;
  459. HWND frame = GetDlgItem(hwndDlg,IDC_ML_TREE_OPTS);
  460. GetWindowRect(frame, &r);
  461. SetWindowPos(frame, 0, 0, 0, (r.right - r.left), (r.bottom - r.top) - 72,
  462. SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);
  463. }
  464. CheckDlgButton(hwndDlg, IDC_SHOW_ICONS, !!g_config->ReadInt(L"Navigation_ShowIcons", 1));
  465. CheckDlgButton(hwndDlg, IDC_HIGHLIGHT_FULL_TREE_ITEM, !!g_config->ReadInt(L"Navigation_FullRowSel", 1));
  466. CheckDlgButton(hwndDlg, IDC_RCLICK_TO_SELECT, g_config->ReadInt(L"Navigation_MouseDownSel", 0));
  467. SetDlgItemInt(hwndDlg, IDC_ITEM_HEIGHT, g_config->ReadInt(L"Navigation_ItemHeight", 18), 0);
  468. CheckDlgButton(hwndDlg, IDC_PARENT_PODCASTS, g_config->ReadInt(L"podcast_parent", 0));
  469. /*if (IPC_GET_CLOUD_HINST == -1) IPC_GET_CLOUD_HINST = (INT)SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)&"WinampCloud", IPC_REGISTER_WINAMP_IPCMESSAGE);
  470. if (!cloud_hinst) cloud_hinst = (HINSTANCE)SendMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_GET_CLOUD_HINST);
  471. SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_SETITEMDATA, SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_ADDSTRING, 0, (LPARAM)L"as a top level tree item (default)"), 0);
  472. if (cloud_hinst && cloud_hinst != (HINSTANCE)1)
  473. SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_SETITEMDATA, SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_ADDSTRING, 0, (LPARAM)L"under the 'Cloud Library' item"), 1);
  474. SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_SETITEMDATA, SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_ADDSTRING, 0, (LPARAM)L"under the 'Devices' item"), 2);
  475. last_pos = g_config->ReadInt(L"txviewpos", 0);
  476. int i = 0, count = SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_GETCOUNT, 0, 0);
  477. for (; i < count; i++)
  478. {
  479. int item = SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_GETITEMDATA, i, 0);
  480. if (item == last_pos)
  481. {
  482. SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_SETCURSEL, i, 0);
  483. break;
  484. }
  485. }
  486. if (i == count)
  487. SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_SETCURSEL, 0, 0);*/
  488. edit_inited = 1;
  489. }
  490. break;
  491. case WM_COMMAND:
  492. switch (LOWORD(wParam))
  493. {
  494. case IDC_SHOW_ICONS:
  495. g_config->WriteInt(L"Navigation_ShowIcons", !!IsDlgButtonChecked(hwndDlg, LOWORD(wParam)));
  496. NavCtrlI_UpdateLook(hNavigation);
  497. // tell ml_disc to update if present
  498. if(g_view_metaconf)SendMessage(plugin.hwndParent, msgNotify, 0, 0);
  499. break;
  500. case IDC_HIGHLIGHT_FULL_TREE_ITEM:
  501. g_config->WriteInt(L"Navigation_FullRowSel", !!IsDlgButtonChecked(hwndDlg, LOWORD(wParam)));
  502. NavCtrlI_UpdateLook(hNavigation);
  503. break;
  504. case IDC_RCLICK_TO_SELECT:
  505. g_config->WriteInt(L"Navigation_MouseDownSel", !!IsDlgButtonChecked(hwndDlg, LOWORD(wParam)));
  506. NavCtrlI_UpdateLook(hNavigation);
  507. break;
  508. case IDC_ITEM_HEIGHT:
  509. if(HIWORD(wParam) == EN_CHANGE && edit_inited)
  510. {
  511. BOOL success = 0;
  512. UINT val = GetDlgItemInt(hwndDlg, LOWORD(wParam), &success, 0);
  513. if(success)
  514. {
  515. g_config->WriteInt(L"Navigation_ItemHeight", val);
  516. NavCtrlI_UpdateLook(hNavigation);
  517. }
  518. }
  519. break;
  520. case IDC_SHOW_EJECT_ICONS:
  521. g_view_metaconf->WriteInt(L"showeject", !!IsDlgButtonChecked(hwndDlg, LOWORD(wParam)));
  522. SendMessage(plugin.hwndParent, msgNotify, 0, 0);
  523. NavCtrlI_UpdateLook(hNavigation);
  524. break;
  525. case IDC_GROUP_DRIVES:
  526. g_view_metaconf->WriteInt(L"showparent", !!IsDlgButtonChecked(hwndDlg, LOWORD(wParam)));
  527. SendMessage(plugin.hwndParent, msgNotify, 1, 0);
  528. NavCtrlI_UpdateLook(hNavigation);
  529. break;
  530. case IDC_PARENT_PODCASTS:
  531. {
  532. int parent = !!IsDlgButtonChecked(hwndDlg, LOWORD(wParam));
  533. g_config->WriteInt(L"podcast_parent", parent);
  534. pluginMessage p = {ML_MSG_DOWNLOADS_VIEW_POSITION, (INT_PTR)parent, (INT_PTR)1, 0};
  535. SENDMLIPC(g_hwnd, ML_IPC_SEND_PLUGIN_MESSAGE, (WPARAM)&p);
  536. NavCtrlI_UpdateLook(hNavigation);
  537. break;
  538. }
  539. case IDC_TRANSFERS_COMBO:
  540. if (HIWORD(wParam) == CBN_SELCHANGE)
  541. {
  542. int a = (INT)SendDlgItemMessage(hwndDlg, IDC_TRANSFERS_COMBO, CB_GETCURSEL, 0, 0);
  543. if (a != CB_ERR)
  544. {
  545. g_config->WriteInt(L"txviewpos", SendDlgItemMessageW(hwndDlg, IDC_TRANSFERS_COMBO, CB_GETITEMDATA, a, 0));
  546. wchar_t titleStr[32] = {0};
  547. if ((a != last_pos) &&
  548. MessageBoxW(hwndDlg, WASABI_API_LNGSTRINGW(IDS_RESTART_MESSAGE),
  549. WASABI_API_LNGSTRINGW_BUF(IDS_RESTART, titleStr, 32),
  550. MB_ICONQUESTION | MB_YESNO) == IDYES)
  551. {
  552. WritePrivateProfileStringW(L"winamp", L"show_prefs", L"-1", WINAMP_INI);
  553. PostMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_RESTARTWINAMP);
  554. }
  555. }
  556. }
  557. break;
  558. }
  559. break;
  560. case WM_DESTROY:
  561. if(g_view_metaconf)
  562. {
  563. delete(g_view_metaconf);
  564. g_view_metaconf = 0;
  565. }
  566. break;
  567. }
  568. return 0;
  569. }
  570. static INT_PTR CALLBACK Prefs4Proc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  571. {
  572. switch (uMsg)
  573. {
  574. case WM_INITDIALOG:
  575. {
  576. CheckDlgButton(hwndDlg, IDC_CHECK_USEPLFONT, !!g_config->ReadInt(L"plfont_everywhere", 1));
  577. CheckDlgButton(hwndDlg, IDC_FF_SCROLLBARS, config_use_ff_scrollbars);
  578. CheckDlgButton(hwndDlg, IDC_ALTERNATEITEMS, config_use_alternate_colors);
  579. CheckDlgButton(hwndDlg, IDC_SKINNED_MENUS, IsSkinnedPopupEnabled(FALSE));
  580. CheckDlgButton(hwndDlg, IDC_GENO, !!GetPrivateProfileIntW(L"winamp", L"geno", 1, WINAMP_INI));
  581. }
  582. break;
  583. case WM_COMMAND:
  584. switch (LOWORD(wParam))
  585. {
  586. case IDC_CHECK_USEPLFONT:
  587. g_config->WriteInt(L"plfont_everywhere", !!IsDlgButtonChecked(hwndDlg, IDC_CHECK_USEPLFONT));
  588. PostMessage(plugin.hwndParent, WM_DISPLAYCHANGE, 0, 0);
  589. break;
  590. case IDC_FF_SCROLLBARS:
  591. config_use_ff_scrollbars = !!IsDlgButtonChecked(hwndDlg, IDC_FF_SCROLLBARS);
  592. g_config->WriteInt(L"ffsb", config_use_ff_scrollbars);
  593. PostMessage(plugin.hwndParent, WM_DISPLAYCHANGE, 0, 0);
  594. break;
  595. case IDC_ALTERNATEITEMS:
  596. config_use_alternate_colors = !!IsDlgButtonChecked(hwndDlg, IDC_ALTERNATEITEMS);
  597. g_config->WriteInt(L"alternate_items", config_use_alternate_colors);
  598. PostMessage(plugin.hwndParent, WM_DISPLAYCHANGE, 0, 0);
  599. break;
  600. case IDC_SKINNED_MENUS:
  601. EnableSkinnedPopup(BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_SKINNED_MENUS));
  602. break;
  603. case IDC_GENO:
  604. {
  605. wchar_t buf[64] = {L"1"};
  606. StringCchPrintfW(buf, 64, L"%d", !!IsDlgButtonChecked(hwndDlg, IDC_GENO));
  607. WritePrivateProfileStringW(L"winamp", L"geno", buf, WINAMP_INI);
  608. break;
  609. }
  610. case IDC_RATING_COLUMN:
  611. SendMessage(g_hwnd,WM_COMMAND,MAKEWPARAM(ID_SHOW_RATINGTWEAK,0),0);
  612. break;
  613. }
  614. break;
  615. }
  616. return 0;
  617. }
  618. HWND subWnd = 0, prefsWnd = 0;
  619. static void _dosetsel(HWND hwndDlg)
  620. {
  621. HWND tabwnd = GetDlgItem(hwndDlg, IDC_TAB1);
  622. int sel = TabCtrl_GetCurSel(tabwnd);
  623. if (sel >= 0 && (sel != g_config->ReadInt(L"lastprefp", 0) || !subWnd))
  624. {
  625. g_config->WriteInt(L"lastprefp", sel);
  626. if (subWnd) DestroyWindow(subWnd);
  627. subWnd = 0;
  628. UINT t = 0;
  629. DLGPROC p;
  630. switch (sel)
  631. {
  632. case 0: t = IDD_PREFS1; p = Prefs1Proc; break;
  633. case 1: t = IDD_PREFS2; p = Prefs2Proc; break;
  634. case 2: t = IDD_PREFS3; p = Prefs3Proc; break;
  635. case 3: t = IDD_PREFS4; p = Prefs4Proc; break;
  636. }
  637. if (t) subWnd = WASABI_API_CREATEDIALOGW(t, hwndDlg, p);
  638. if (subWnd)
  639. {
  640. RECT r;
  641. GetClientRect(tabwnd, &r);
  642. TabCtrl_AdjustRect(tabwnd, FALSE, &r);
  643. SetWindowPos(subWnd, HWND_TOP, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOACTIVATE);
  644. ShowWindow(subWnd, SW_SHOWNA);
  645. }
  646. if (!SendMessage(plugin.hwndParent,WM_WA_IPC,IPC_ISWINTHEMEPRESENT,IPC_USE_UXTHEME_FUNC))
  647. {
  648. SendMessage(plugin.hwndParent,WM_WA_IPC,(WPARAM)tabwnd,IPC_USE_UXTHEME_FUNC);
  649. SendMessage(plugin.hwndParent,WM_WA_IPC,(WPARAM)subWnd,IPC_USE_UXTHEME_FUNC);
  650. }
  651. }
  652. }
  653. #define TabCtrl_InsertItemW(hwnd, iItem, pitem) \
  654. (int)SNDMSG((hwnd), TCM_INSERTITEMW, (WPARAM)(int)(iItem), (LPARAM)(const TC_ITEMW *)(pitem))
  655. // frame proc
  656. INT_PTR CALLBACK PrefsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  657. {
  658. switch (uMsg)
  659. {
  660. case WM_INITDIALOG:
  661. {
  662. TCITEMW item;
  663. HWND tabwnd = GetDlgItem(hwndDlg, IDC_TAB1);
  664. item.mask = TCIF_TEXT;
  665. item.pszText = WASABI_API_LNGSTRINGW(IDS_LIBRARY_OPTIONS);
  666. TabCtrl_InsertItemW(tabwnd, 0, &item);
  667. item.pszText = WASABI_API_LNGSTRINGW(IDS_ONLINE_MEDIA);
  668. TabCtrl_InsertItemW(tabwnd, 1, &item);
  669. item.pszText = WASABI_API_LNGSTRINGW(IDS_TREE_OPTIONS);
  670. TabCtrl_InsertItemW(tabwnd, 2, &item);
  671. item.pszText = WASABI_API_LNGSTRINGW(IDS_APPEARANCE);
  672. TabCtrl_InsertItemW(tabwnd, 3, &item);
  673. TabCtrl_SetCurSel(tabwnd, g_config->ReadInt(L"lastprefp", 0));
  674. _dosetsel(hwndDlg);
  675. prefsWnd = hwndDlg;
  676. }
  677. return 0;
  678. case WM_NOTIFY:
  679. {
  680. LPNMHDR p = (LPNMHDR) lParam;
  681. if (p->idFrom == IDC_TAB1 && p->code == TCN_SELCHANGE) _dosetsel(hwndDlg);
  682. }
  683. return 0;
  684. case WM_DESTROY:
  685. subWnd = NULL;
  686. prefsWnd = NULL;
  687. return 0;
  688. }
  689. return 0;
  690. }
  691. void refreshPrefs(INT_PTR screen)
  692. {
  693. if (subWnd && g_config->ReadInt(L"lastprefp", -1) == screen)
  694. {
  695. if (screen == 4) SendMessage(subWnd, WM_INITDIALOG, 0, 0);
  696. }
  697. }
  698. extern prefsDlgRecW myPrefsItem;
  699. void openPrefs(INT_PTR screen)
  700. {
  701. if (!subWnd)
  702. {
  703. if (screen != -1) g_config->WriteInt(L"lastprefp", (INT)screen);
  704. }
  705. else
  706. {
  707. if (screen != -1)
  708. {
  709. HWND tabwnd = GetDlgItem(prefsWnd, IDC_TAB1);
  710. TabCtrl_SetCurSel(tabwnd, screen);
  711. _dosetsel(prefsWnd);
  712. }
  713. }
  714. SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)&myPrefsItem, IPC_OPENPREFSTOPAGE);
  715. }