Preferences.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "main.h"
  2. #include "api__ml_wire.h"
  3. #include "../winamp/wa_ipc.h"
  4. #include "Defaults.h"
  5. #include "UpdateTime.h"
  6. #include "UpdateAutoDownload.h"
  7. #include "./cloud.h"
  8. #include <shlobj.h>
  9. extern Cloud cloud;
  10. void Preferences_Init(HWND hwndDlg)
  11. {
  12. WCHAR szBuffer[256] = {0};
  13. for (int i = 0;i < Update::TIME_NUMENTRIES;i++)
  14. {
  15. const wchar_t *str = Update::GetTitle(i, szBuffer, ARRAYSIZE(szBuffer));
  16. SendMessage(GetDlgItem(hwndDlg, IDC_UPDATELIST), CB_ADDSTRING, 0, (LPARAM) str);
  17. }
  18. int selection = Update::GetSelection(updateTime, autoUpdate);
  19. SendMessage(GetDlgItem(hwndDlg, IDC_UPDATELIST), CB_SETCURSEL, selection, 0);
  20. WCHAR adBuffer[256] = {0};
  21. for (int i = 0;i < UpdateAutoDownload::AUTODOWNLOAD_NUMENTRIES;i++)
  22. {
  23. const wchar_t *str = UpdateAutoDownload::GetTitle(i, adBuffer, ARRAYSIZE(adBuffer));
  24. SendMessage(GetDlgItem(hwndDlg, IDC_AUTODOWNLOADLIST), CB_ADDSTRING, 0, (LPARAM) str);
  25. }
  26. selection = UpdateAutoDownload::GetSelection(autoDownloadEpisodes, autoDownload);
  27. SendMessage(GetDlgItem(hwndDlg, IDC_AUTODOWNLOADLIST), CB_SETCURSEL, selection, 0);
  28. SetDlgItemText(hwndDlg, IDC_DOWNLOADLOCATION, defaultDownloadPath);
  29. SetDlgItemText(hwndDlg, IDC_DIRECTORYURL, serviceUrl);
  30. CheckDlgButton(hwndDlg, IDC_UPDATEONLAUNCH, updateOnLaunch?BST_CHECKED:BST_UNCHECKED);
  31. }
  32. BOOL CALLBACK browseEnumProc(HWND hwnd, LPARAM lParam)
  33. {
  34. wchar_t cl[32] = {0};
  35. GetClassNameW(hwnd, cl, ARRAYSIZE(cl));
  36. if (!lstrcmpiW(cl, WC_TREEVIEW))
  37. {
  38. PostMessage(hwnd, TVM_ENSUREVISIBLE, 0, (LPARAM)TreeView_GetSelection(hwnd));
  39. return FALSE;
  40. }
  41. return TRUE;
  42. }
  43. int CALLBACK WINAPI BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  44. {
  45. if(uMsg == BFFM_INITIALIZED)
  46. {
  47. SendMessageW(hwnd, BFFM_SETSELECTIONW, 1, (LPARAM)defaultDownloadPath);
  48. // this is not nice but it fixes the selection not working correctly on all OSes
  49. EnumChildWindows(hwnd, browseEnumProc, 0);
  50. }
  51. return 0;
  52. }
  53. void Preferences_Browse(HWND hwndDlg)
  54. {
  55. wchar_t folder[MAX_PATH] = {0};
  56. BROWSEINFO browse = {0};
  57. lstrcpyn(folder, defaultDownloadPath, MAX_PATH);
  58. browse.hwndOwner = hwndDlg;
  59. browse.lpszTitle = WASABI_API_LNGSTRINGW(IDS_CHOOSE_FOLDER);
  60. browse.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
  61. browse.lpfn = BrowseCallbackProc;
  62. LPITEMIDLIST itemList = SHBrowseForFolder(&browse);
  63. if (itemList)
  64. {
  65. SHGetPathFromIDList(itemList, folder);
  66. lstrcpyn(defaultDownloadPath, folder, MAX_PATH);
  67. SetWindowText(GetDlgItem(hwndDlg, IDC_DOWNLOADLOCATION), folder);
  68. LPMALLOC malloc;
  69. SHGetMalloc(&malloc);
  70. malloc->Free(itemList);
  71. }
  72. }
  73. void Preferences_UpdateOnLaunch( HWND hwndDlg )
  74. {
  75. updateOnLaunch = ( IsDlgButtonChecked( hwndDlg, IDC_UPDATEONLAUNCH ) == BST_CHECKED );
  76. }
  77. void Preferences_UpdateList(HWND hwndDlg)
  78. {
  79. LRESULT timeSelection;
  80. timeSelection = SendMessage(GetDlgItem(hwndDlg, IDC_UPDATELIST), CB_GETCURSEL, 0, 0);
  81. if (timeSelection != CB_ERR)
  82. {
  83. autoUpdate = Update::GetAutoUpdate(timeSelection);
  84. updateTime = Update::GetTime(timeSelection);
  85. if ( autoUpdate )
  86. cloud.Pulse(); // update the waitable timer
  87. }
  88. }
  89. void Preferences_AutoDownloadList(HWND hwndDlg)
  90. {
  91. LRESULT episodeSelection;
  92. episodeSelection = SendMessage(GetDlgItem(hwndDlg, IDC_AUTODOWNLOADLIST), CB_GETCURSEL, 0, 0);
  93. if (episodeSelection != CB_ERR)
  94. {
  95. autoDownload = UpdateAutoDownload::GetAutoDownload(episodeSelection);
  96. autoDownloadEpisodes = UpdateAutoDownload::GetAutoDownloadEpisodes(episodeSelection);
  97. }
  98. }
  99. BOOL CALLBACK PreferencesDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  100. {
  101. switch (uMsg)
  102. {
  103. case WM_INITDIALOG:
  104. Preferences_Init(hwndDlg);
  105. break;
  106. case WM_COMMAND:
  107. switch (LOWORD(wParam))
  108. {
  109. case IDC_BROWSE:
  110. Preferences_Browse(hwndDlg);
  111. break;
  112. case IDC_UPDATELIST:
  113. Preferences_UpdateList(hwndDlg);
  114. break;
  115. case IDC_AUTODOWNLOADLIST:
  116. Preferences_AutoDownloadList(hwndDlg);
  117. break;
  118. case IDC_UPDATEONLAUNCH:
  119. Preferences_UpdateOnLaunch(hwndDlg);
  120. break;
  121. case IDC_DOWNLOADLOCATION:
  122. if (HIWORD(wParam) == EN_CHANGE)
  123. {
  124. GetDlgItemText(hwndDlg, IDC_DOWNLOADLOCATION, defaultDownloadPath, MAX_PATH);
  125. if (!PathFileExists(defaultDownloadPath))
  126. {
  127. BuildDefaultDownloadPath(plugin.hwndWinampParent);
  128. SetDlgItemText(hwndDlg, IDC_DOWNLOADLOCATION, defaultDownloadPath);
  129. }
  130. }
  131. break;
  132. case IDC_DIRECTORYURL:
  133. if (HIWORD(wParam) == EN_CHANGE)
  134. {
  135. GetDlgItemText(hwndDlg, IDC_DIRECTORYURL, serviceUrl, ARRAYSIZE(serviceUrl));
  136. }
  137. break;
  138. }
  139. break;
  140. case WM_DESTROY:
  141. // ensure we save the changed settings
  142. SaveAll(true);
  143. break;
  144. }
  145. return 0;
  146. }