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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
#include "main.h"
#include "cddb.h"
#include "../nu/ListView.h"
#include "cddbinterface.h"
#include "../Agave/Language/api_language.h"
#include "../Winamp/wa_ipc.h"
#include <atlbase.h>
#include <strsafe.h>
int _g_disable_cddb;
#if 0
static DINFO *p;
static char dialogDevice;
W_ListView trackList;
static void Populate(HWND hDlg)
{
int x;
trackList.Clear();
SetDlgItemTextW(hDlg, IDC_TITLE, p->title);
SetDlgItemTextW(hDlg, IDC_PUBLISHER, p->label);
SetDlgItemTextW(hDlg, IDC_ARTIST, p->artist);
SetDlgItemTextW(hDlg, IDC_GENRE, p->genre);
SetDlgItemTextW(hDlg, IDC_YEAR, p->year);
CheckDlgButton(hDlg, IDC_COMPILATION, p->compilation?BST_CHECKED:BST_UNCHECKED);
for (x = 0; x < p->ntracks; x ++)
{
trackList.InsertItem(x, p->tracks[x].artist, 0);
trackList.SetItemText(x, 1, p->tracks[x].title);
}
}
static HRESULT CALLBACK Cddb_ResultCallback(DWORD cddbId, HRESULT result, ICddbDisc *pDisc, ULONG_PTR user)
{
CBDATA *pData = (CBDATA*)user;
DefaultValues(pData->p);
if(S_OK == result)
{
}
else if (S_FALSE == result)
{
}
else if (S_MULTIPLE == result)
{
}
Populate(pData->hwnd);
return S_OK;
}
static LRESULT CALLBACK EditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_NOTIFYFORMAT:
return NFR_UNICODE;
case WM_INITDIALOG:
trackList.setwnd(GetDlgItem(hDlg, IDC_TRACKS));
RECT rect1, rect2;
GetWindowRect(GetDlgItem(hDlg, IDC_EDITARTIST), &rect1);
GetWindowRect(GetDlgItem(hDlg, IDC_EDITTEXT), &rect2);
trackList.AddCol(WASABI_API_LNGSTRINGW(plugin.hDllInstance,IDS_ARTIST), rect2.left-rect1.left-3);
trackList.AddCol(WASABI_API_LNGSTRINGW(plugin.hDllInstance,IDS_TITLE), (rect2.right-rect2.left)-18);
if (_g_disable_cddb) EnableWindow(GetDlgItem(hDlg, IDC_GETCDDB), 0);
SendDlgItemMessage(hDlg, IDC_TITLE, EM_LIMITTEXT, 512, 0);
SendDlgItemMessage(hDlg, IDC_PUBLISHER, EM_LIMITTEXT, 512, 0);
SendDlgItemMessage(hDlg, IDC_ARTIST, EM_LIMITTEXT, 512, 0);
SendDlgItemMessage(hDlg, IDC_YEAR, EM_LIMITTEXT, 8, 0);
SendDlgItemMessage(hDlg, IDC_GENRE, EM_LIMITTEXT, 64, 0);
SendDlgItemMessage(hDlg, IDC_EDITTEXT, EM_LIMITTEXT, 512, 0);
SendDlgItemMessage(hDlg, IDC_EDITARTIST, EM_LIMITTEXT, 512, 0);
if (GetCDDBInfo(p, dialogDevice))
{
int x;
SetDlgItemText(hDlg, IDC_TITLE, WASABI_API_LNGSTRINGW(line.hDllInstance,IDS_TITLE));
SetDlgItemText(hDlg, IDC_ARTIST, WASABI_API_LNGSTRINGW(line.hDllInstance,IDS_ALBUM_ARTIST));
for (x = 0; x < p->ntracks; x ++)
{
wchar_t buf[128] = {0};
StringCchPrintfW(buf, 128, L"Track %d", x + 1);
trackList.InsertItem(x, "Artist", 0);
trackList.SetItemText(x, 1, buf);
}
}
else
{
Populate(hDlg);
}
return 1;
case WM_NOTIFY:
{
LPNMHDR l = (LPNMHDR)lParam;
switch (l->code)
{
case LVN_ITEMCHANGED:
{
LPNMLISTVIEW lvNotif = (LPNMLISTVIEW)l;
if (lvNotif->uNewState & LVIS_SELECTED)
{
wchar_t buf[512] = {0};
trackList.GetText(trackList.GetNextSelected(-1), 0, buf, 512);
SetDlgItemTextW(hDlg, IDC_EDITARTIST, buf);
trackList.GetText(trackList.GetNextSelected(-1), 1, buf, 512);
SetDlgItemTextW(hDlg, IDC_EDITTEXT, buf);
}
}
break;
}
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_GETCDDB:
{
wchar_t szTOC[2048] = {0};
if (Cddb_CalculateTOC(p, szTOC, sizeof(szTOC)/sizeof(wchar_t)))
{
CBDATA data = { p, hDlg };
HRESULT hr = Cddb_DoLookup(p->CDDBID, szTOC, hDlg, Cddb_ResultCallback,
CDDB_NOCACHE | CDDB_MODAL | CDDB_UI_MULTIPLE, (ULONG_PTR)&data);
}
else hr = CDDB_E_BADTOC;
}
break;
case IDC_CDTEXT:
if (DoCDText(p, dialogDevice))
{
Populate(hDlg);
}
break;
case IDCANCEL: EndDialog(hDlg, 1); break;
case IDOK:
{
int x;
GetDlgItemTextW(hDlg, IDC_TITLE, p->title, TITLE_SIZE);
GetDlgItemTextW(hDlg, IDC_PUBLISHER, p->label, 511); p->label[511] = 0;
GetDlgItemTextW(hDlg, IDC_ARTIST, p->artist, ARTIST_SIZE);
GetDlgItemTextW(hDlg, IDC_GENRE, p->genre, 63); p->genre[63] = 0;
GetDlgItemTextW(hDlg, IDC_YEAR, p->year, 8);
p->compilation = !!IsDlgButtonChecked(hDlg, IDC_COMPILATION);
for (x = 0; x < p->ntracks; x ++)
{
trackList.GetText(x, 0, p->tracks[x].artist, ARTIST_SIZE);
trackList.GetText(x, 1, p->tracks[x].title, TITLE_SIZE);
}
AddToDatabase(p);
}
EndDialog(hDlg, 0);
break;
case IDC_REMOVE:
RemoveFromDatabase(p);
EndDialog(hDlg, 1); break;
case IDC_EDITTEXT:
if (HIWORD(wParam) == EN_CHANGE)
{
wchar_t buf[512] = {0};
int p = trackList.GetNextSelected(-1);
if (p != LB_ERR)
{
GetDlgItemTextW(hDlg, IDC_EDITTEXT, buf, 512);
trackList.SetItemText(p, 1, buf);
}
}
break;
case IDC_EDITARTIST:
if (HIWORD(wParam) == EN_CHANGE)
{
wchar_t buf[512] = {0};
int p = trackList.GetNextSelected(-1);
if (p != LB_ERR)
{
GetDlgItemTextW(hDlg, IDC_EDITARTIST, buf, 512);
trackList.SetItemText(p, 0, buf);
if (!IsDlgButtonChecked(hDlg, IDC_COMPILATION))
{
wchar_t buf2[512] = {0};
GetDlgItemTextW(hDlg, IDC_ARTIST, buf2, 512);
if (lstrcmp(buf, buf2))
CheckDlgButton(hDlg, IDC_COMPILATION, BST_CHECKED);
}
}
}
break;
case IDC_ARTIST:
if (HIWORD(wParam) == EN_CHANGE && !IsDlgButtonChecked(hDlg, IDC_COMPILATION))
{
wchar_t buf[512] = {0};
GetDlgItemTextW(hDlg, IDC_ARTIST, buf, 512);
for (int x = 0; x < p->ntracks; x ++)
{
trackList.SetItemText(x, 0, buf);
}
if (trackList.GetNextSelected(-1) != LB_ERR)
{
SetDlgItemTextW(hDlg, IDC_EDITARTIST, buf);
}
}
break;
}
return 0;
}
return 0;
}
void DBEdit(DINFO *ps, HWND hwnd, int l, char device)
{
static int i = 0;
if (i) return ;
i = 1;
p = ps;
dialogDevice = device;
_g_disable_cddb = l;
if (!WASABI_API_DIALOGBOX(IDD_EDIT, hwnd, (DLGPROC)EditProc))
{
PostMessage(line.hMainWindow, WM_USER, (WPARAM)L"cda://", 247 /*IPC_REFRESHPLCACHE*/);
}
i = 0;
}
#endif
#if 0
typedef struct _EDITDATA
{
DINFO *p;
INT modified;
CHAR cDevice;
} EDITDATA;
#define GET_DATA(__hwnd) (EDITDATA*)(LONG_PTR)GetWindowLongPtrW((__hwnd), GWLP_USERDATA);
#define SET_IF(hwndDlg, id, data) if (data) SetDlgItemText(hwndDlg, id, data); else SetDlgItemText(hwndDlg, id, L"");
static void Fill(HWND hwndDlg, const DINFO *info)
{
SET_IF(hwndDlg, IDC_TITLE, info->title);
SET_IF(hwndDlg, IDC_ARTIST, info->artist);
if (info->discnum)
SetDlgItemInt(hwndDlg, IDC_DISC, info->discnum, FALSE);
else
SetDlgItemText(hwndDlg, IDC_DISCS, L"");
if (info->numdiscs)
SetDlgItemInt(hwndDlg, IDC_DISCS, info->numdiscs, FALSE);
else
SetDlgItemText(hwndDlg, IDC_DISCS, L"");
SET_IF(hwndDlg, IDC_YEAR, info->year);
SET_IF(hwndDlg, IDC_LABEL, info->label);
SET_IF(hwndDlg, IDC_NOTES, info->notes);
SET_IF(hwndDlg, IDC_GENRE, info->genre);
CheckDlgButton(hwndDlg, IDC_COMPILATION, (info->compilation)?BST_CHECKED:BST_UNCHECKED);
SendDlgItemMessage(hwndDlg, IDC_TRACKLIST, LB_RESETCONTENT, 0, 0);
for (int x = 0; x < info->ntracks; x ++)
{
wchar_t buf[1100] = {0};
if (!info->tracks[x].title)
StringCchPrintfW(buf, 1100, L"%d.", x+1);
else if (info->tracks[x].artist && info->tracks[x].artist[0] && wcscmp(info->tracks[x].artist, info->artist))
StringCchPrintfW(buf, 1100, L"%d. %s - %s", x+1, info->tracks[x].artist, info->tracks[x].title);
else
StringCchPrintfW(buf, 1100, L"%d. %s", x+1, info->tracks[x].title);
SendDlgItemMessageW(hwndDlg, IDC_TRACKLIST, LB_ADDSTRING, 0, (LPARAM)buf);
}
}
static HRESULT CALLBACK Cddb_LookupCallback(HRESULT result, ICddbDisc *pDisc, DWORD *pdwAutoCloseDelay, ULONG_PTR user)
{
HWND hwnd = (HWND)user;
EDITDATA *pData = GET_DATA(hwnd);
if (!pData) return E_INVALIDARG;
if(S_OK == result)
{
pData->modified = 1;
DefaultValues(pData->p);
GetDiscInfo(pDisc, pData->p);
StoreDisc(pData->p->CDDBID, pDisc);
ICddbCacheManager* pCache;
HRESULT hr = Cddb_GetICacheManger((void**)&pCache);
if (SUCCEEDED(hr))
{
CComBSTR toc;
pDisc->get_Toc(&toc);
hr = pCache->StoreDiscByToc(toc, pDisc);
pCache->Release();
}
Fill(hwnd, pData->p);
}
else
{
*pdwAutoCloseDelay = AUTOCLOSE_NEVER;
}
CddbCache_SetDisc(pData->p, result);
return S_OK;
}
static HRESULT CALLBACK Cddb_EditCallback(HRESULT result, ICddbDisc *pDisc, DWORD *pdwAutoCloseDelay, ULONG_PTR user)
{
HWND hwnd = (HWND)user;
EDITDATA *pData = GET_DATA(hwnd);
if (!pData) return E_INVALIDARG;
if (FAILED(result))
{
*pdwAutoCloseDelay = AUTOCLOSE_NEVER;
return S_OK;
}
if (SUCCEEDED(result))
{
HRESULT hr(S_OK);
wchar_t szTOC[2048] = {0};
ICDDBControl *pControl;
CDDBUIFlags uiFlags = UI_EDITMODE;
if (!Cddb_CalculateTOC(pData->p, szTOC, sizeof(szTOC)/sizeof(wchar_t))) hr = CDDB_E_BADTOC;
if (SUCCEEDED(hr)) hr = Cddb_GetIControl((void**)&pControl);
if (SUCCEEDED(hr))
{
if (!pDisc)
{
uiFlags = UI_SUBMITNEW;
hr = pControl->GetSubmitDisc(szTOC, 0, 0, &pDisc);
if (FAILED(hr)) pDisc = NULL;
}
else pDisc->AddRef();
if (pDisc)
{
Cddb_DisplayDiscInfo(pDisc, &uiFlags, hwnd);
if (uiFlags & UI_DATA_CHANGED)
{
ICddbCacheManager* pCache;
hr = Cddb_GetICacheManger((void**)&pCache);
if (SUCCEEDED(hr))
{
hr = pCache->StoreDiscByToc(szTOC, pDisc);
pCache->Release();
}
pData->modified = 1;
DefaultValues(pData->p);
GetDiscInfo(pDisc, pData->p);
StoreDisc(pData->p->CDDBID, pDisc);
Fill(hwnd, pData->p);
CddbCache_SetDisc(pData->p, S_OK);
}
pDisc->Release();
}
pControl->Release();
}
}
return S_OK;
}
static LRESULT CALLBACK EditProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
EDITDATA *pData;
switch (message)
{
case WM_INITDIALOG:
{
pData = (EDITDATA*)lParam;
if (!pData) { EndDialog(hwndDlg, 0); return 0; }
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
pData->modified = 0;
Fill(hwndDlg, pData->p);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_CDDB:
{
wchar_t szTOC[2048] = {0};
pData = GET_DATA(hwndDlg);
if (pData && Cddb_CalculateTOC(pData->p, szTOC, sizeof(szTOC)/sizeof(wchar_t)))
{
UINT flags = CDDB_NOCACHE | CDDB_UI_MODAL | CDDB_UI_MULTIPLE | CDDB_UI_RESULT_MODAL;
HRESULT hr = Cddb_DoLookup(szTOC, hwndDlg, Cddb_LookupCallback, flags, (ULONG_PTR)hwndDlg);
if (FAILED(hr)) Cddb_DisplayResultDlg(hwndDlg, hr, AUTOCLOSE_NEVER, flags);
}
}
break;
case IDC_EDIT:
{
wchar_t szTOC[2048] = {0};
pData = GET_DATA(hwndDlg);
if (pData && Cddb_CalculateTOC(pData->p, szTOC, sizeof(szTOC)/sizeof(wchar_t)))
{
UINT flags = CDDB_UI_MODAL | CDDB_UI_MULTIPLE | CDDB_UI_RESULT_MODAL;
HRESULT hr = Cddb_DoLookup(szTOC, hwndDlg, Cddb_EditCallback, flags, (ULONG_PTR)hwndDlg);
if (FAILED(hr)) Cddb_DisplayResultDlg(hwndDlg, hr, AUTOCLOSE_NEVER, flags);
}
}
break;
case IDCANCEL:
pData = (EDITDATA*)(LONG_PTR)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
EndDialog(hwndDlg, (pData) ? pData->modified : 0);
break;
}
break;
}
return 0;
}
bool CDEdit(CHAR cDevice, DINFO *ps, HWND hwnd)
{
EDITDATA data;
ZeroMemory(&data, sizeof(EDITDATA));
data.cDevice = cDevice;
data.p = ps;
if (WASABI_API_DIALOGBOXPARAM(IDD_EDIT, hwnd, (DLGPROC)EditProc, (LPARAM)&data))
{
PostMessageW(line.hMainWindow, WM_USER, (WPARAM)L"cda://", IPC_REFRESHPLCACHE);
}
return ( 0 != data.modified);
}
#endif
|