1
0

EditCDInfo.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. #include "main.h"
  2. #include "cddb.h"
  3. #include "../nu/ListView.h"
  4. #include "cddbinterface.h"
  5. #include "../Agave/Language/api_language.h"
  6. #include "../Winamp/wa_ipc.h"
  7. #include <atlbase.h>
  8. #include <strsafe.h>
  9. int _g_disable_cddb;
  10. #if 0
  11. static DINFO *p;
  12. static char dialogDevice;
  13. W_ListView trackList;
  14. static void Populate(HWND hDlg)
  15. {
  16. int x;
  17. trackList.Clear();
  18. SetDlgItemTextW(hDlg, IDC_TITLE, p->title);
  19. SetDlgItemTextW(hDlg, IDC_PUBLISHER, p->label);
  20. SetDlgItemTextW(hDlg, IDC_ARTIST, p->artist);
  21. SetDlgItemTextW(hDlg, IDC_GENRE, p->genre);
  22. SetDlgItemTextW(hDlg, IDC_YEAR, p->year);
  23. CheckDlgButton(hDlg, IDC_COMPILATION, p->compilation?BST_CHECKED:BST_UNCHECKED);
  24. for (x = 0; x < p->ntracks; x ++)
  25. {
  26. trackList.InsertItem(x, p->tracks[x].artist, 0);
  27. trackList.SetItemText(x, 1, p->tracks[x].title);
  28. }
  29. }
  30. static HRESULT CALLBACK Cddb_ResultCallback(DWORD cddbId, HRESULT result, ICddbDisc *pDisc, ULONG_PTR user)
  31. {
  32. CBDATA *pData = (CBDATA*)user;
  33. DefaultValues(pData->p);
  34. if(S_OK == result)
  35. {
  36. }
  37. else if (S_FALSE == result)
  38. {
  39. }
  40. else if (S_MULTIPLE == result)
  41. {
  42. }
  43. Populate(pData->hwnd);
  44. return S_OK;
  45. }
  46. static LRESULT CALLBACK EditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  47. {
  48. switch (message)
  49. {
  50. case WM_NOTIFYFORMAT:
  51. return NFR_UNICODE;
  52. case WM_INITDIALOG:
  53. trackList.setwnd(GetDlgItem(hDlg, IDC_TRACKS));
  54. RECT rect1, rect2;
  55. GetWindowRect(GetDlgItem(hDlg, IDC_EDITARTIST), &rect1);
  56. GetWindowRect(GetDlgItem(hDlg, IDC_EDITTEXT), &rect2);
  57. trackList.AddCol(WASABI_API_LNGSTRINGW(plugin.hDllInstance,IDS_ARTIST), rect2.left-rect1.left-3);
  58. trackList.AddCol(WASABI_API_LNGSTRINGW(plugin.hDllInstance,IDS_TITLE), (rect2.right-rect2.left)-18);
  59. if (_g_disable_cddb) EnableWindow(GetDlgItem(hDlg, IDC_GETCDDB), 0);
  60. SendDlgItemMessage(hDlg, IDC_TITLE, EM_LIMITTEXT, 512, 0);
  61. SendDlgItemMessage(hDlg, IDC_PUBLISHER, EM_LIMITTEXT, 512, 0);
  62. SendDlgItemMessage(hDlg, IDC_ARTIST, EM_LIMITTEXT, 512, 0);
  63. SendDlgItemMessage(hDlg, IDC_YEAR, EM_LIMITTEXT, 8, 0);
  64. SendDlgItemMessage(hDlg, IDC_GENRE, EM_LIMITTEXT, 64, 0);
  65. SendDlgItemMessage(hDlg, IDC_EDITTEXT, EM_LIMITTEXT, 512, 0);
  66. SendDlgItemMessage(hDlg, IDC_EDITARTIST, EM_LIMITTEXT, 512, 0);
  67. if (GetCDDBInfo(p, dialogDevice))
  68. {
  69. int x;
  70. SetDlgItemText(hDlg, IDC_TITLE, WASABI_API_LNGSTRINGW(line.hDllInstance,IDS_TITLE));
  71. SetDlgItemText(hDlg, IDC_ARTIST, WASABI_API_LNGSTRINGW(line.hDllInstance,IDS_ALBUM_ARTIST));
  72. for (x = 0; x < p->ntracks; x ++)
  73. {
  74. wchar_t buf[128] = {0};
  75. StringCchPrintfW(buf, 128, L"Track %d", x + 1);
  76. trackList.InsertItem(x, "Artist", 0);
  77. trackList.SetItemText(x, 1, buf);
  78. }
  79. }
  80. else
  81. {
  82. Populate(hDlg);
  83. }
  84. return 1;
  85. case WM_NOTIFY:
  86. {
  87. LPNMHDR l = (LPNMHDR)lParam;
  88. switch (l->code)
  89. {
  90. case LVN_ITEMCHANGED:
  91. {
  92. LPNMLISTVIEW lvNotif = (LPNMLISTVIEW)l;
  93. if (lvNotif->uNewState & LVIS_SELECTED)
  94. {
  95. wchar_t buf[512] = {0};
  96. trackList.GetText(trackList.GetNextSelected(-1), 0, buf, 512);
  97. SetDlgItemTextW(hDlg, IDC_EDITARTIST, buf);
  98. trackList.GetText(trackList.GetNextSelected(-1), 1, buf, 512);
  99. SetDlgItemTextW(hDlg, IDC_EDITTEXT, buf);
  100. }
  101. }
  102. break;
  103. }
  104. }
  105. break;
  106. case WM_COMMAND:
  107. switch (LOWORD(wParam))
  108. {
  109. case IDC_GETCDDB:
  110. {
  111. wchar_t szTOC[2048] = {0};
  112. if (Cddb_CalculateTOC(p, szTOC, sizeof(szTOC)/sizeof(wchar_t)))
  113. {
  114. CBDATA data = { p, hDlg };
  115. HRESULT hr = Cddb_DoLookup(p->CDDBID, szTOC, hDlg, Cddb_ResultCallback,
  116. CDDB_NOCACHE | CDDB_MODAL | CDDB_UI_MULTIPLE, (ULONG_PTR)&data);
  117. }
  118. else hr = CDDB_E_BADTOC;
  119. }
  120. break;
  121. case IDC_CDTEXT:
  122. if (DoCDText(p, dialogDevice))
  123. {
  124. Populate(hDlg);
  125. }
  126. break;
  127. case IDCANCEL: EndDialog(hDlg, 1); break;
  128. case IDOK:
  129. {
  130. int x;
  131. GetDlgItemTextW(hDlg, IDC_TITLE, p->title, TITLE_SIZE);
  132. GetDlgItemTextW(hDlg, IDC_PUBLISHER, p->label, 511); p->label[511] = 0;
  133. GetDlgItemTextW(hDlg, IDC_ARTIST, p->artist, ARTIST_SIZE);
  134. GetDlgItemTextW(hDlg, IDC_GENRE, p->genre, 63); p->genre[63] = 0;
  135. GetDlgItemTextW(hDlg, IDC_YEAR, p->year, 8);
  136. p->compilation = !!IsDlgButtonChecked(hDlg, IDC_COMPILATION);
  137. for (x = 0; x < p->ntracks; x ++)
  138. {
  139. trackList.GetText(x, 0, p->tracks[x].artist, ARTIST_SIZE);
  140. trackList.GetText(x, 1, p->tracks[x].title, TITLE_SIZE);
  141. }
  142. AddToDatabase(p);
  143. }
  144. EndDialog(hDlg, 0);
  145. break;
  146. case IDC_REMOVE:
  147. RemoveFromDatabase(p);
  148. EndDialog(hDlg, 1); break;
  149. case IDC_EDITTEXT:
  150. if (HIWORD(wParam) == EN_CHANGE)
  151. {
  152. wchar_t buf[512] = {0};
  153. int p = trackList.GetNextSelected(-1);
  154. if (p != LB_ERR)
  155. {
  156. GetDlgItemTextW(hDlg, IDC_EDITTEXT, buf, 512);
  157. trackList.SetItemText(p, 1, buf);
  158. }
  159. }
  160. break;
  161. case IDC_EDITARTIST:
  162. if (HIWORD(wParam) == EN_CHANGE)
  163. {
  164. wchar_t buf[512] = {0};
  165. int p = trackList.GetNextSelected(-1);
  166. if (p != LB_ERR)
  167. {
  168. GetDlgItemTextW(hDlg, IDC_EDITARTIST, buf, 512);
  169. trackList.SetItemText(p, 0, buf);
  170. if (!IsDlgButtonChecked(hDlg, IDC_COMPILATION))
  171. {
  172. wchar_t buf2[512] = {0};
  173. GetDlgItemTextW(hDlg, IDC_ARTIST, buf2, 512);
  174. if (lstrcmp(buf, buf2))
  175. CheckDlgButton(hDlg, IDC_COMPILATION, BST_CHECKED);
  176. }
  177. }
  178. }
  179. break;
  180. case IDC_ARTIST:
  181. if (HIWORD(wParam) == EN_CHANGE && !IsDlgButtonChecked(hDlg, IDC_COMPILATION))
  182. {
  183. wchar_t buf[512] = {0};
  184. GetDlgItemTextW(hDlg, IDC_ARTIST, buf, 512);
  185. for (int x = 0; x < p->ntracks; x ++)
  186. {
  187. trackList.SetItemText(x, 0, buf);
  188. }
  189. if (trackList.GetNextSelected(-1) != LB_ERR)
  190. {
  191. SetDlgItemTextW(hDlg, IDC_EDITARTIST, buf);
  192. }
  193. }
  194. break;
  195. }
  196. return 0;
  197. }
  198. return 0;
  199. }
  200. void DBEdit(DINFO *ps, HWND hwnd, int l, char device)
  201. {
  202. static int i = 0;
  203. if (i) return ;
  204. i = 1;
  205. p = ps;
  206. dialogDevice = device;
  207. _g_disable_cddb = l;
  208. if (!WASABI_API_DIALOGBOX(IDD_EDIT, hwnd, (DLGPROC)EditProc))
  209. {
  210. PostMessage(line.hMainWindow, WM_USER, (WPARAM)L"cda://", 247 /*IPC_REFRESHPLCACHE*/);
  211. }
  212. i = 0;
  213. }
  214. #endif
  215. #if 0
  216. typedef struct _EDITDATA
  217. {
  218. DINFO *p;
  219. INT modified;
  220. CHAR cDevice;
  221. } EDITDATA;
  222. #define GET_DATA(__hwnd) (EDITDATA*)(LONG_PTR)GetWindowLongPtrW((__hwnd), GWLP_USERDATA);
  223. #define SET_IF(hwndDlg, id, data) if (data) SetDlgItemText(hwndDlg, id, data); else SetDlgItemText(hwndDlg, id, L"");
  224. static void Fill(HWND hwndDlg, const DINFO *info)
  225. {
  226. SET_IF(hwndDlg, IDC_TITLE, info->title);
  227. SET_IF(hwndDlg, IDC_ARTIST, info->artist);
  228. if (info->discnum)
  229. SetDlgItemInt(hwndDlg, IDC_DISC, info->discnum, FALSE);
  230. else
  231. SetDlgItemText(hwndDlg, IDC_DISCS, L"");
  232. if (info->numdiscs)
  233. SetDlgItemInt(hwndDlg, IDC_DISCS, info->numdiscs, FALSE);
  234. else
  235. SetDlgItemText(hwndDlg, IDC_DISCS, L"");
  236. SET_IF(hwndDlg, IDC_YEAR, info->year);
  237. SET_IF(hwndDlg, IDC_LABEL, info->label);
  238. SET_IF(hwndDlg, IDC_NOTES, info->notes);
  239. SET_IF(hwndDlg, IDC_GENRE, info->genre);
  240. CheckDlgButton(hwndDlg, IDC_COMPILATION, (info->compilation)?BST_CHECKED:BST_UNCHECKED);
  241. SendDlgItemMessage(hwndDlg, IDC_TRACKLIST, LB_RESETCONTENT, 0, 0);
  242. for (int x = 0; x < info->ntracks; x ++)
  243. {
  244. wchar_t buf[1100] = {0};
  245. if (!info->tracks[x].title)
  246. StringCchPrintfW(buf, 1100, L"%d.", x+1);
  247. else if (info->tracks[x].artist && info->tracks[x].artist[0] && wcscmp(info->tracks[x].artist, info->artist))
  248. StringCchPrintfW(buf, 1100, L"%d. %s - %s", x+1, info->tracks[x].artist, info->tracks[x].title);
  249. else
  250. StringCchPrintfW(buf, 1100, L"%d. %s", x+1, info->tracks[x].title);
  251. SendDlgItemMessageW(hwndDlg, IDC_TRACKLIST, LB_ADDSTRING, 0, (LPARAM)buf);
  252. }
  253. }
  254. static HRESULT CALLBACK Cddb_LookupCallback(HRESULT result, ICddbDisc *pDisc, DWORD *pdwAutoCloseDelay, ULONG_PTR user)
  255. {
  256. HWND hwnd = (HWND)user;
  257. EDITDATA *pData = GET_DATA(hwnd);
  258. if (!pData) return E_INVALIDARG;
  259. if(S_OK == result)
  260. {
  261. pData->modified = 1;
  262. DefaultValues(pData->p);
  263. GetDiscInfo(pDisc, pData->p);
  264. StoreDisc(pData->p->CDDBID, pDisc);
  265. ICddbCacheManager* pCache;
  266. HRESULT hr = Cddb_GetICacheManger((void**)&pCache);
  267. if (SUCCEEDED(hr))
  268. {
  269. CComBSTR toc;
  270. pDisc->get_Toc(&toc);
  271. hr = pCache->StoreDiscByToc(toc, pDisc);
  272. pCache->Release();
  273. }
  274. Fill(hwnd, pData->p);
  275. }
  276. else
  277. {
  278. *pdwAutoCloseDelay = AUTOCLOSE_NEVER;
  279. }
  280. CddbCache_SetDisc(pData->p, result);
  281. return S_OK;
  282. }
  283. static HRESULT CALLBACK Cddb_EditCallback(HRESULT result, ICddbDisc *pDisc, DWORD *pdwAutoCloseDelay, ULONG_PTR user)
  284. {
  285. HWND hwnd = (HWND)user;
  286. EDITDATA *pData = GET_DATA(hwnd);
  287. if (!pData) return E_INVALIDARG;
  288. if (FAILED(result))
  289. {
  290. *pdwAutoCloseDelay = AUTOCLOSE_NEVER;
  291. return S_OK;
  292. }
  293. if (SUCCEEDED(result))
  294. {
  295. HRESULT hr(S_OK);
  296. wchar_t szTOC[2048] = {0};
  297. ICDDBControl *pControl;
  298. CDDBUIFlags uiFlags = UI_EDITMODE;
  299. if (!Cddb_CalculateTOC(pData->p, szTOC, sizeof(szTOC)/sizeof(wchar_t))) hr = CDDB_E_BADTOC;
  300. if (SUCCEEDED(hr)) hr = Cddb_GetIControl((void**)&pControl);
  301. if (SUCCEEDED(hr))
  302. {
  303. if (!pDisc)
  304. {
  305. uiFlags = UI_SUBMITNEW;
  306. hr = pControl->GetSubmitDisc(szTOC, 0, 0, &pDisc);
  307. if (FAILED(hr)) pDisc = NULL;
  308. }
  309. else pDisc->AddRef();
  310. if (pDisc)
  311. {
  312. Cddb_DisplayDiscInfo(pDisc, &uiFlags, hwnd);
  313. if (uiFlags & UI_DATA_CHANGED)
  314. {
  315. ICddbCacheManager* pCache;
  316. hr = Cddb_GetICacheManger((void**)&pCache);
  317. if (SUCCEEDED(hr))
  318. {
  319. hr = pCache->StoreDiscByToc(szTOC, pDisc);
  320. pCache->Release();
  321. }
  322. pData->modified = 1;
  323. DefaultValues(pData->p);
  324. GetDiscInfo(pDisc, pData->p);
  325. StoreDisc(pData->p->CDDBID, pDisc);
  326. Fill(hwnd, pData->p);
  327. CddbCache_SetDisc(pData->p, S_OK);
  328. }
  329. pDisc->Release();
  330. }
  331. pControl->Release();
  332. }
  333. }
  334. return S_OK;
  335. }
  336. static LRESULT CALLBACK EditProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
  337. {
  338. EDITDATA *pData;
  339. switch (message)
  340. {
  341. case WM_INITDIALOG:
  342. {
  343. pData = (EDITDATA*)lParam;
  344. if (!pData) { EndDialog(hwndDlg, 0); return 0; }
  345. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
  346. pData->modified = 0;
  347. Fill(hwndDlg, pData->p);
  348. }
  349. break;
  350. case WM_COMMAND:
  351. switch (LOWORD(wParam))
  352. {
  353. case IDC_CDDB:
  354. {
  355. wchar_t szTOC[2048] = {0};
  356. pData = GET_DATA(hwndDlg);
  357. if (pData && Cddb_CalculateTOC(pData->p, szTOC, sizeof(szTOC)/sizeof(wchar_t)))
  358. {
  359. UINT flags = CDDB_NOCACHE | CDDB_UI_MODAL | CDDB_UI_MULTIPLE | CDDB_UI_RESULT_MODAL;
  360. HRESULT hr = Cddb_DoLookup(szTOC, hwndDlg, Cddb_LookupCallback, flags, (ULONG_PTR)hwndDlg);
  361. if (FAILED(hr)) Cddb_DisplayResultDlg(hwndDlg, hr, AUTOCLOSE_NEVER, flags);
  362. }
  363. }
  364. break;
  365. case IDC_EDIT:
  366. {
  367. wchar_t szTOC[2048] = {0};
  368. pData = GET_DATA(hwndDlg);
  369. if (pData && Cddb_CalculateTOC(pData->p, szTOC, sizeof(szTOC)/sizeof(wchar_t)))
  370. {
  371. UINT flags = CDDB_UI_MODAL | CDDB_UI_MULTIPLE | CDDB_UI_RESULT_MODAL;
  372. HRESULT hr = Cddb_DoLookup(szTOC, hwndDlg, Cddb_EditCallback, flags, (ULONG_PTR)hwndDlg);
  373. if (FAILED(hr)) Cddb_DisplayResultDlg(hwndDlg, hr, AUTOCLOSE_NEVER, flags);
  374. }
  375. }
  376. break;
  377. case IDCANCEL:
  378. pData = (EDITDATA*)(LONG_PTR)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  379. EndDialog(hwndDlg, (pData) ? pData->modified : 0);
  380. break;
  381. }
  382. break;
  383. }
  384. return 0;
  385. }
  386. bool CDEdit(CHAR cDevice, DINFO *ps, HWND hwnd)
  387. {
  388. EDITDATA data;
  389. ZeroMemory(&data, sizeof(EDITDATA));
  390. data.cDevice = cDevice;
  391. data.p = ps;
  392. if (WASABI_API_DIALOGBOXPARAM(IDD_EDIT, hwnd, (DLGPROC)EditProc, (LPARAM)&data))
  393. {
  394. PostMessageW(line.hMainWindow, WM_USER, (WPARAM)L"cda://", IPC_REFRESHPLCACHE);
  395. }
  396. return ( 0 != data.modified);
  397. }
  398. #endif