channelEditor.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. #include "main.h"
  2. #include "./util.h"
  3. #include "./channelEditor.h"
  4. #include "api__ml_wire.h"
  5. #include "./defaults.h"
  6. #include "./updateTime.h"
  7. #include "./UpdateAutoDownload.h"
  8. #include "./errors.h"
  9. #include "./feeds.h"
  10. #include "./feedUtil.h"
  11. #include "./cloud.h"
  12. #include "./subscriptionView.h"
  13. #include <strsafe.h>
  14. using namespace Nullsoft::Utility;
  15. extern Cloud cloud;
  16. typedef struct __CHANNELEDITOR
  17. {
  18. HWND hOwner;
  19. size_t iChannel;
  20. UINT flags;
  21. BOOL enableAutoDownload;
  22. BOOL enableAutoUpdate;
  23. __time64_t updateTime;
  24. INT numOfAutoDownloadEpisodes;
  25. } CHANNELEDITOR;
  26. #define GetEditor(__hwnd) ((CHANNELEDITOR*)GetPropW((__hwnd), MAKEINTATOM(VIEWPROP)))
  27. static INT_PTR CALLBACK ChannelEditor_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  28. INT_PTR ChannelEditor_Show(HWND hOwner, size_t channelIndex, UINT flags)
  29. {
  30. if (0 == VIEWPROP)
  31. return 0;
  32. if (NULL == hOwner)
  33. hOwner = plugin.hwndLibraryParent;
  34. if (0 == (CEF_CREATENEW & flags) && BAD_CHANNEL == channelIndex)
  35. return 0;
  36. CHANNELEDITOR editor;
  37. ZeroMemory(&editor, sizeof(editor));
  38. editor.hOwner = hOwner;
  39. editor.iChannel = channelIndex;
  40. editor.flags = flags;
  41. INT_PTR result = WASABI_API_DIALOGBOXPARAMW(IDD_ADDURL, hOwner, ChannelEditor_DialogProc, (LPARAM)&editor);
  42. return result;
  43. }
  44. static BOOL ChannelEditor_SetUpdateTime(HWND hwnd, __time64_t updateTime, BOOL enableAutoUpdate)
  45. {
  46. HWND hCombo = GetDlgItem(hwnd, IDC_UPDATELIST);
  47. if (NULL == hCombo) return FALSE;
  48. INT selectedVal = Update::GetSelection(updateTime, (FALSE != enableAutoUpdate));
  49. INT iCount = (INT)SNDMSG(hCombo, CB_GETCOUNT, 0, 0L);
  50. INT iSelect = CB_ERR;
  51. for (INT i = 0; i < iCount && CB_ERR == iSelect; i++)
  52. {
  53. if (selectedVal == (INT)SNDMSG(hCombo, CB_GETITEMDATA, i, 0L))
  54. iSelect = i;
  55. }
  56. if (CB_ERR == iSelect)
  57. return FALSE;
  58. if (iSelect != (INT)SNDMSG(hCombo, CB_GETCURSEL, 0, 0L) &&
  59. CB_ERR == SNDMSG(hCombo, CB_SETCURSEL, iSelect, 0))
  60. {
  61. return FALSE;
  62. }
  63. return TRUE;
  64. }
  65. static BOOL ChannelEditor_SetAutoDownload(HWND hwnd, INT numOfEpisodes, BOOL enableAutoDownload)
  66. {
  67. HWND hCombo = GetDlgItem(hwnd, IDC_AUTODOWNLOADLIST);
  68. if (NULL == hCombo) return FALSE;
  69. INT selectedVal = UpdateAutoDownload::GetSelection(numOfEpisodes, (FALSE != enableAutoDownload));
  70. INT iCount = (INT)SNDMSG(hCombo, CB_GETCOUNT, 0, 0L);
  71. INT iSelect = CB_ERR;
  72. for (INT i = 0; i < iCount && CB_ERR == iSelect; i++)
  73. {
  74. if (selectedVal == (INT)SNDMSG(hCombo, CB_GETITEMDATA, i, 0L))
  75. iSelect = i;
  76. }
  77. if (CB_ERR == iSelect)
  78. return FALSE;
  79. if (iSelect != (INT)SNDMSG(hCombo, CB_GETCURSEL, 0, 0L) &&
  80. CB_ERR == SNDMSG(hCombo, CB_SETCURSEL, iSelect, 0))
  81. {
  82. return FALSE;
  83. }
  84. return TRUE;
  85. }
  86. static BOOL ChannelEditor_InitCombobox(HWND hwnd)
  87. {
  88. HWND hCombo = GetDlgItem(hwnd, IDC_UPDATELIST);
  89. HWND hAutoDownloadCombo = GetDlgItem(hwnd, IDC_AUTODOWNLOADLIST);
  90. if ( NULL == hCombo || NULL == hAutoDownloadCombo ) return FALSE;
  91. WCHAR szBuffer[256] = {0};
  92. INT iPos = 0;
  93. SNDMSG(hCombo, WM_SETREDRAW, FALSE, 0L);
  94. for (INT i = 0; i < Update::TIME_NUMENTRIES; i++)
  95. {
  96. if (NULL != Update::GetTitle(i, szBuffer, ARRAYSIZE(szBuffer)))
  97. {
  98. iPos = (INT)SNDMSG(hCombo, CB_ADDSTRING, 0, (LPARAM)szBuffer);
  99. if (CB_ERR != iPos)
  100. {
  101. SNDMSG(hCombo, CB_SETITEMDATA, (WPARAM)iPos, (LPARAM)i);
  102. }
  103. }
  104. }
  105. SNDMSG(hCombo, WM_SETREDRAW, TRUE, 0L);
  106. SNDMSG(hAutoDownloadCombo, WM_SETREDRAW, FALSE, 0L);
  107. for (INT i = 0; i < UpdateAutoDownload::AUTODOWNLOAD_NUMENTRIES; i++)
  108. {
  109. if (NULL != UpdateAutoDownload::GetTitle(i, szBuffer, ARRAYSIZE(szBuffer)))
  110. {
  111. iPos = (INT)SNDMSG(hAutoDownloadCombo, CB_ADDSTRING, 0, (LPARAM)szBuffer);
  112. if (CB_ERR != iPos)
  113. {
  114. SNDMSG(hAutoDownloadCombo, CB_SETITEMDATA, (WPARAM)iPos, (LPARAM)i);
  115. }
  116. }
  117. }
  118. SNDMSG(hAutoDownloadCombo, WM_SETREDRAW, TRUE, 0L);
  119. return TRUE;
  120. }
  121. static BOOL ChannelEditor_EnableUserSettings(HWND hwnd, BOOL fEnable)
  122. {
  123. BOOL result;
  124. UINT activeButton = (FALSE == fEnable) ? IDC_USEDEFAULTS : IDC_USECUSTOM;
  125. result = CheckRadioButton(hwnd, IDC_USEDEFAULTS, IDC_USECUSTOM, activeButton);
  126. if (FALSE != result)
  127. {
  128. SendDlgItemMessage(hwnd, activeButton, BM_CLICK, 0, 0L);
  129. }
  130. return result;
  131. }
  132. #if 0
  133. static BOOL ChannelEditor_EnableAutoDownload(HWND hwnd, BOOL fEnable)
  134. {
  135. BOOL result;
  136. result = CheckDlgButton(hwnd, IDC_AUTODOWNLOAD, (FALSE != fEnable) ? BST_CHECKED : BST_UNCHECKED);
  137. return result;
  138. }
  139. #endif
  140. static BOOL ChannelEditor_SetUrl(HWND hwnd, LPCWSTR pszUrl)
  141. {
  142. HWND hEdit = GetDlgItem(hwnd, IDC_EDITURL);
  143. if (NULL == hEdit) return FALSE;
  144. return SNDMSG(hEdit, WM_SETTEXT, 0, (LPARAM)pszUrl);
  145. }
  146. static void ChannelEditor_UpdateTitle(HWND hwnd, BOOL fModified)
  147. {
  148. CHANNELEDITOR *editor = GetEditor(hwnd);
  149. if (NULL == editor) return;
  150. if (0 != (CEF_CREATENEW & editor->flags))
  151. return;
  152. WCHAR szBuffer[256] = {0};
  153. size_t remaining = ARRAYSIZE(szBuffer);
  154. LPWSTR cursor = szBuffer;
  155. if (FALSE != fModified)
  156. {
  157. StringCchCopyEx(cursor, remaining, L"*", &cursor, &remaining, 0);
  158. }
  159. WASABI_API_LNGSTRINGW_BUF(IDS_EDIT_CHANNEL, cursor, remaining);
  160. INT cchLen = lstrlen(cursor);
  161. cursor += cchLen;
  162. remaining -= cchLen;
  163. AutoLock lock (channels);
  164. LPCWSTR title = NULL;
  165. if (editor->iChannel < channels.size())
  166. {
  167. Channel *channel = &channels[editor->iChannel];
  168. title = channel->title;
  169. if (NULL != title && L'\0' != title)
  170. {
  171. StringCchPrintf(cursor, remaining, L": %s", title);
  172. }
  173. }
  174. SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)szBuffer);
  175. }
  176. static void ChannelEditor_UpdateModifiedState(HWND hwnd)
  177. {
  178. CHANNELEDITOR *editor = GetEditor(hwnd);
  179. if (NULL == editor) return;
  180. if (0 != (CEF_CREATENEW & editor->flags))
  181. return;
  182. AutoLock lock (channels);
  183. if (editor->iChannel >= channels.size())
  184. return;
  185. BOOL fModified = FALSE;
  186. Channel *channel = &channels[editor->iChannel];
  187. HWND hControl;
  188. if (FALSE == fModified && (NULL != (hControl = GetDlgItem(hwnd, IDC_USECUSTOM))) &&
  189. (BST_CHECKED == SNDMSG(hControl, BM_GETCHECK, 0, 0L)) != (false == channel->useDefaultUpdate))
  190. {
  191. fModified = TRUE;
  192. }
  193. if (false == channel->useDefaultUpdate)
  194. {
  195. if (editor->enableAutoDownload != (BOOL)channel->autoDownload ||
  196. editor->enableAutoUpdate != (BOOL)channel->autoUpdate ||
  197. editor->updateTime != channel->updateTime ||
  198. editor->numOfAutoDownloadEpisodes != channel->autoDownloadEpisodes)
  199. {
  200. fModified = TRUE;
  201. }
  202. }
  203. hControl = GetDlgItem(hwnd, IDOK);
  204. if (NULL != hControl) EnableWindow(hControl, fModified);
  205. ChannelEditor_UpdateTitle(hwnd, fModified);
  206. }
  207. static BOOL ChannelEditor_Reposition(HWND hwnd)
  208. {
  209. CHANNELEDITOR *editor = GetEditor(hwnd);
  210. if (NULL == editor) return FALSE;
  211. RECT rectEditor, rectOwner;
  212. if (0 != (CEF_CENTEROWNER & editor->flags))
  213. {
  214. if (FALSE == GetWindowRect(editor->hOwner, &rectOwner) ||
  215. FALSE == GetWindowRect(hwnd, &rectEditor))
  216. {
  217. return FALSE;
  218. }
  219. LONG x = rectOwner.left + ((rectOwner.right - rectOwner.left) - (rectEditor.right - rectEditor.left))/2;
  220. LONG y = rectOwner.top + ((rectOwner.bottom - rectOwner.top) - (rectEditor.bottom - rectEditor.top))/2;
  221. SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
  222. SendMessage(hwnd, DM_REPOSITION, 0, 0L);
  223. }
  224. return TRUE;
  225. }
  226. static INT_PTR ChannelEditor_OnInitDialog(HWND hwnd, HWND hFocus, LPARAM lParam)
  227. {
  228. CHANNELEDITOR *editor = (CHANNELEDITOR*)lParam;
  229. if (NULL == editor || FALSE == SetProp(hwnd, MAKEINTATOM(VIEWPROP), editor))
  230. {
  231. EndDialog(hwnd, 0);
  232. return 0;
  233. }
  234. ChannelEditor_InitCombobox(hwnd);
  235. editor->enableAutoDownload = autoDownload;
  236. editor->enableAutoUpdate = autoUpdate;
  237. editor->updateTime = updateTime;
  238. editor->numOfAutoDownloadEpisodes = autoDownloadEpisodes;
  239. if (0 != (CEF_CREATENEW & editor->flags))
  240. {
  241. ChannelEditor_SetUrl(hwnd, L"");
  242. ChannelEditor_EnableUserSettings(hwnd, FALSE);
  243. }
  244. else
  245. {
  246. AutoLock lock (channels);
  247. if (editor->iChannel >= channels.size())
  248. {
  249. EndDialog(hwnd, 0);
  250. return 0;
  251. }
  252. Channel *channel = &channels[editor->iChannel];
  253. HWND hControl;
  254. hControl = GetDlgItem(hwnd, IDC_EDITURL);
  255. if (NULL != hControl) SNDMSG(hControl, EM_SETREADONLY, TRUE, 0L);
  256. hControl = GetDlgItem(hwnd, IDOK);
  257. if (NULL != hControl)
  258. {
  259. WCHAR szBuffer[128] = {0};
  260. WASABI_API_LNGSTRINGW_BUF(IDS_SAVE, szBuffer, ARRAYSIZE(szBuffer));
  261. SNDMSG(hControl, WM_SETTEXT, 0, (LPARAM)szBuffer);
  262. }
  263. if (false == channel->useDefaultUpdate)
  264. {
  265. editor->enableAutoDownload = channel->autoDownload;
  266. editor->enableAutoUpdate = channel->autoUpdate;
  267. editor->updateTime = channel->updateTime;
  268. editor->numOfAutoDownloadEpisodes = channel->autoDownloadEpisodes;
  269. }
  270. ChannelEditor_SetUrl(hwnd, channel->url);
  271. ChannelEditor_EnableUserSettings(hwnd, !channel->useDefaultUpdate);
  272. }
  273. ChannelEditor_Reposition(hwnd);
  274. return TRUE;
  275. }
  276. static void ChannelEditor_OnDestroy(HWND hwnd)
  277. {
  278. CHANNELEDITOR *editor = GetEditor(hwnd);
  279. RemoveProp(hwnd, MAKEINTATOM(VIEWPROP));
  280. }
  281. static void ChannelEditor_UpdateUserSettings(HWND hwnd)
  282. {
  283. CHANNELEDITOR *editor = GetEditor(hwnd);
  284. if (NULL == editor) return;
  285. HWND hControl;
  286. FALSE;
  287. hControl = GetDlgItem(hwnd, IDC_USECUSTOM);
  288. BOOL enableUser = (NULL != hControl && BST_CHECKED == (INT)SNDMSG(hControl, BM_GETCHECK, 0, 0L));
  289. if (FALSE == enableUser)
  290. {
  291. ChannelEditor_SetUpdateTime(hwnd, updateTime, autoUpdate);
  292. ChannelEditor_SetAutoDownload(hwnd, autoDownloadEpisodes, autoDownload);
  293. }
  294. else
  295. {
  296. ChannelEditor_SetUpdateTime(hwnd, editor->updateTime, editor->enableAutoUpdate);
  297. ChannelEditor_SetAutoDownload(hwnd, editor->numOfAutoDownloadEpisodes, editor->enableAutoDownload);
  298. }
  299. const INT szControl[] = { IDC_UPDATELIST, IDC_AUTODOWNLOADLIST, IDC_STATIC_UPDATEEVERY, IDC_STATIC_AUTODOWNLOAD, };
  300. for (INT i = 0; i < ARRAYSIZE(szControl); i++)
  301. {
  302. hControl = GetDlgItem(hwnd, szControl[i]);
  303. if (NULL != hControl) EnableWindow(hControl, enableUser);
  304. }
  305. ChannelEditor_UpdateModifiedState(hwnd);
  306. }
  307. static INT_PTR ChannelEditor_SaveChannel(HWND hwnd)
  308. {
  309. CHANNELEDITOR *editor = GetEditor(hwnd);
  310. if (NULL == editor) return 0;
  311. AutoLock lock (channels);
  312. if (editor->iChannel >= channels.size())
  313. return 0;
  314. HWND hControl = GetDlgItem(hwnd, IDC_USECUSTOM);
  315. if (NULL == hControl) return 0;
  316. Channel *channel = &channels[editor->iChannel];
  317. if (BST_CHECKED == SNDMSG(hControl, BM_GETCHECK, 0, 0L))
  318. {
  319. channel->useDefaultUpdate = false;
  320. channel->autoDownload = (FALSE != editor->enableAutoDownload);
  321. channel->updateTime = editor->updateTime;
  322. channel->autoUpdate = (FALSE != editor->enableAutoUpdate);
  323. channel->autoDownloadEpisodes = editor->numOfAutoDownloadEpisodes;
  324. }
  325. else
  326. {
  327. channel->useDefaultUpdate = true;
  328. channel->autoDownload = autoDownload;
  329. channel->updateTime = updateTime;
  330. channel->autoUpdate = autoUpdate;
  331. channel->autoDownloadEpisodes = autoDownloadEpisodes;
  332. }
  333. if (channel->autoUpdate)
  334. cloud.Pulse();
  335. return
  336. IDOK;
  337. }
  338. static DWORD AddUrlThread(void *vBuffer, HWND hwndDlg)
  339. {
  340. Channel newFeed;
  341. newFeed.autoUpdate = false; // TODO check defaults
  342. newFeed.autoDownload = false; // leave this as false
  343. newFeed.SetURL((const wchar_t *)vBuffer);
  344. delete vBuffer;
  345. int downloadError = DownloadFeedInformation(newFeed);
  346. if (downloadError != DOWNLOAD_SUCCESS)
  347. return downloadError;
  348. // TODO check defaults;
  349. if (IsDlgButtonChecked(hwndDlg, IDC_USECUSTOM) == BST_CHECKED)
  350. {
  351. LRESULT timeSelection;
  352. timeSelection = SendMessage(GetDlgItem(hwndDlg, IDC_UPDATELIST), CB_GETCURSEL, 0, 0);
  353. if (timeSelection != CB_ERR)
  354. {
  355. newFeed.autoUpdate = Update::GetAutoUpdate(timeSelection);
  356. newFeed.updateTime = Update::GetTime(timeSelection);
  357. }
  358. LRESULT episodesSelection;
  359. episodesSelection = SendMessage(GetDlgItem(hwndDlg, IDC_AUTODOWNLOADLIST), CB_GETCURSEL, 0, 0);
  360. if (episodesSelection != CB_ERR)
  361. {
  362. newFeed.autoDownload = UpdateAutoDownload::GetAutoDownload(episodesSelection);
  363. newFeed.autoDownloadEpisodes = UpdateAutoDownload::GetAutoDownloadEpisodes(episodesSelection);
  364. }
  365. newFeed.useDefaultUpdate = false;
  366. }
  367. else
  368. {
  369. newFeed.useDefaultUpdate = true;
  370. newFeed.autoUpdate = autoUpdate;
  371. newFeed.updateTime = updateTime;
  372. newFeed.autoDownloadEpisodes = autoDownloadEpisodes;
  373. newFeed.autoDownload = autoDownload;
  374. }
  375. //newFeed.title += L" ";
  376. AutoLock lock (channels LOCKNAME("AddURL"));
  377. if (!channels.AddChannel(newFeed))
  378. {
  379. wchar_t error_msg[1024] = {0}, titleStr[64] = {0};
  380. StringCchPrintf( error_msg, 1024, WASABI_API_LNGSTRINGW( IDS_CHANNEL_ALREADY_PRESENT ), newFeed.title, newFeed.url );
  381. MessageBox( hwndDlg, error_msg, WASABI_API_LNGSTRINGW_BUF( IDS_DUPLICATE_CHANNEL, titleStr, 64 ), MB_OK );
  382. return DOWNLOAD_DUPLICATE;
  383. }
  384. else
  385. {
  386. cloud.Pulse(); // TODO why?
  387. HWND hView = SubscriptionView_FindWindow();
  388. if (NULL != hView)
  389. {
  390. SubscriptionView_RefreshChannels(hView, TRUE);
  391. }
  392. }
  393. return DOWNLOAD_SUCCESS; // success
  394. }
  395. static INT ChannelEditor_AddUrl(HWND hwnd)
  396. {
  397. size_t length = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDITURL)) + 1;
  398. wchar_t *buffer = new wchar_t[length];
  399. ZeroMemory(buffer,sizeof(wchar_t)*length);
  400. GetDlgItemText(hwnd, IDC_EDITURL, buffer, (int)length);
  401. return AddUrlThread((void *)buffer, hwnd);
  402. }
  403. static INT_PTR ChannelEditor_CreateChannel(HWND hwnd)
  404. {
  405. INT result = ChannelEditor_AddUrl(hwnd);
  406. if (DOWNLOAD_SUCCESS == result)
  407. return IDOK;
  408. INT messageId = IDS_ERROR_ADDING_URL;
  409. INT titleId = IDS_ERROR_ADDING_URL;
  410. switch (result)
  411. {
  412. case DOWNLOAD_ERROR_PARSING_XML: messageId = IDS_ERROR_PARSING_XML_FROM_SERVER; break;
  413. case DOWNLOAD_NOTRSS: messageId = IDS_LINK_HAS_NO_RSS_INFO; break;
  414. case DOWNLOAD_404: messageId = IDS_INVALID_LINK; break;
  415. case DOWNLOAD_NOHTTP: messageId = IDS_NO_JNETLIB; titleId = IDS_JNETLIB_MISSING; break;
  416. case DOWNLOAD_NOPARSER: messageId = IDS_NO_EXPAT; titleId = IDS_EXPAT_MISSING; break;
  417. case DOWNLOAD_CONNECTIONRESET: messageId = IDS_CONNECTION_RESET_BY_PEER; break;
  418. }
  419. if(result != DOWNLOAD_DUPLICATE)
  420. {
  421. WCHAR szMessage[512] = {0}, szTitle[128] = {0};
  422. WASABI_API_LNGSTRINGW_BUF(messageId, szMessage, ARRAYSIZE(szMessage));
  423. WASABI_API_LNGSTRINGW_BUF(titleId, szTitle, ARRAYSIZE(szTitle));
  424. MessageBox(hwnd, szMessage, szTitle, MB_OK | MB_ICONERROR);
  425. }
  426. return IDIGNORE;
  427. }
  428. static void ChannelEditor_OnCancel(HWND hwnd)
  429. {
  430. EndDialog(hwnd, IDCANCEL);
  431. }
  432. static void ChannelEditor_OnOk(HWND hwnd)
  433. {
  434. INT_PTR result = 0;
  435. CHANNELEDITOR *editor = GetEditor(hwnd);
  436. if (NULL != editor)
  437. {
  438. if (0 == (CEF_CREATENEW & editor->flags))
  439. {
  440. result = ChannelEditor_SaveChannel(hwnd);
  441. }
  442. else
  443. {
  444. result = ChannelEditor_CreateChannel(hwnd);
  445. }
  446. }
  447. if (IDIGNORE != result)
  448. {
  449. EndDialog(hwnd, result);
  450. }
  451. }
  452. #if 0
  453. static void ChannelEditor_OnAutoDownloadChanged(HWND hwnd)
  454. {
  455. CHANNELEDITOR *editor = GetEditor(hwnd);
  456. if (NULL == editor) return;
  457. HWND hControl = GetDlgItem(hwnd, IDC_USECUSTOM);
  458. if (NULL == hControl || BST_CHECKED != SNDMSG(hControl, BM_GETCHECK, 0, 0L)) return;
  459. hControl = GetDlgItem(hwnd, IDC_AUTODOWNLOAD);
  460. if (NULL == hControl) return;
  461. editor->enableAutoDownload = (BST_CHECKED == SNDMSG(hControl, BM_GETCHECK, 0, 0L));
  462. ChannelEditor_UpdateModifiedState(hwnd);
  463. }
  464. #endif
  465. static void ChannelEditor_OnUrlChange(HWND hwnd)
  466. {
  467. WCHAR szBuffer[4096] = {0};
  468. HWND hControl = GetDlgItem(hwnd, IDC_EDITURL);
  469. if (NULL == hControl || 0 == (INT)SNDMSG(hControl, WM_GETTEXT, (WPARAM)ARRAYSIZE(szBuffer), (LPARAM)szBuffer))
  470. szBuffer[0] = L'\0';
  471. LPCWSTR p = szBuffer;
  472. while (L' ' == *p && L'\0' != *p) p++;
  473. BOOL enableButton = (L'\0' != *p);
  474. hControl = GetDlgItem(hwnd, IDOK);
  475. if (NULL != hControl)
  476. {
  477. EnableWindow(hControl, enableButton);
  478. }
  479. }
  480. static void ChannelEditor_OnUpdateTimeChange(HWND hwnd)
  481. {
  482. CHANNELEDITOR *editor = GetEditor(hwnd);
  483. if (NULL == editor) return;
  484. HWND hControl = GetDlgItem(hwnd, IDC_USECUSTOM);
  485. if (NULL == hControl || BST_CHECKED != SNDMSG(hControl, BM_GETCHECK, 0, 0L)) return;
  486. hControl = GetDlgItem(hwnd, IDC_UPDATELIST);
  487. if (NULL == hControl) return;
  488. INT iSelected = (INT)SNDMSG(hControl, CB_GETCURSEL, 0, 0L);
  489. if (CB_ERR == iSelected) return;
  490. INT selectedVal = (INT)SNDMSG(hControl, CB_GETITEMDATA, iSelected, 0L);
  491. if (selectedVal < 0 || selectedVal >= Update::TIME_NUMENTRIES) return;
  492. editor->updateTime = Update::GetTime(selectedVal);
  493. editor->enableAutoUpdate = Update::GetAutoUpdate(selectedVal);
  494. ChannelEditor_UpdateModifiedState(hwnd);
  495. }
  496. static void ChannelEditor_OnUpdateAutoDownloadChange(HWND hwnd)
  497. {
  498. CHANNELEDITOR *editor = GetEditor(hwnd);
  499. if (NULL == editor) return;
  500. HWND hControl = GetDlgItem(hwnd, IDC_USECUSTOM);
  501. if (NULL == hControl || BST_CHECKED != SNDMSG(hControl, BM_GETCHECK, 0, 0L)) return;
  502. hControl = GetDlgItem(hwnd, IDC_AUTODOWNLOADLIST);
  503. if (NULL == hControl) return;
  504. INT iSelected = (INT)SNDMSG(hControl, CB_GETCURSEL, 0, 0L);
  505. if (CB_ERR == iSelected) return;
  506. INT selectedVal = (INT)SNDMSG(hControl, CB_GETITEMDATA, iSelected, 0L);
  507. if (selectedVal < 0 || selectedVal >= UpdateAutoDownload::AUTODOWNLOAD_NUMENTRIES) return;
  508. editor->numOfAutoDownloadEpisodes = UpdateAutoDownload::GetAutoDownloadEpisodes(selectedVal);
  509. editor->enableAutoDownload = UpdateAutoDownload::GetAutoDownload(selectedVal);
  510. ChannelEditor_UpdateModifiedState(hwnd);
  511. }
  512. static void ChannelEditor_OnCommand(HWND hwnd, UINT commandId, UINT eventId, HWND hControl)
  513. {
  514. switch(commandId)
  515. {
  516. case IDCANCEL: ChannelEditor_OnCancel(hwnd); break;
  517. case IDOK: ChannelEditor_OnOk(hwnd); break;
  518. case IDC_USEDEFAULTS:
  519. case IDC_USECUSTOM:
  520. switch(eventId)
  521. {
  522. case BN_CLICKED: ChannelEditor_UpdateUserSettings(hwnd); break;
  523. }
  524. break;
  525. case IDC_EDITURL:
  526. switch(eventId)
  527. {
  528. case EN_CHANGE: ChannelEditor_OnUrlChange(hwnd); break;
  529. }
  530. break;
  531. case IDC_UPDATELIST:
  532. switch(eventId)
  533. {
  534. case CBN_SELCHANGE: ChannelEditor_OnUpdateTimeChange(hwnd); break;
  535. }
  536. break;
  537. case IDC_AUTODOWNLOADLIST:
  538. switch(eventId)
  539. {
  540. case CBN_SELCHANGE: ChannelEditor_OnUpdateAutoDownloadChange(hwnd); break;
  541. }
  542. break;
  543. }
  544. }
  545. static INT_PTR CALLBACK ChannelEditor_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  546. {
  547. switch(uMsg)
  548. {
  549. case WM_INITDIALOG: return ChannelEditor_OnInitDialog(hwnd, (HWND)wParam, lParam);
  550. case WM_DESTROY: ChannelEditor_OnDestroy(hwnd); return TRUE;
  551. case WM_COMMAND: ChannelEditor_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); return TRUE;
  552. }
  553. return 0;
  554. }