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
|
#include "main.h"
#include "PlaylistView.h"
#include "Playlist.h"
#include "CurrentPlaylist.h"
#include "api__ml_playlists.h"
#include "../ml_local/api_mldb.h"
#include "../ml_pmp/pmp.h"
#include <strsafe.h>
extern Playlist currentPlaylist;
static BOOL playlist_GetDisplayInfo( NMLVDISPINFO *lpdi )
{
size_t item = lpdi->item.iItem;
if ( item < 0 || item >= currentPlaylist.GetNumItems() )
return 0;
if ( lpdi->item.mask & LVIF_TEXT )
{
switch ( lpdi->item.iSubItem )
{
case 0:
{
if ( !currentPlaylist.IsCached( item ) )
{
wchar_t title[ FILETITLE_SIZE ] = { 0 };
int length = -1;
mediaLibrary.GetFileInfo( currentPlaylist.ItemName( item ), title, FILETITLE_SIZE, &length );
currentPlaylist.SetItemLengthMilliseconds( item, length * 1000 );
currentPlaylist.SetItemTitle( item, title );
}
// CUT: currentPlaylist.GetItemTitle(item, lpdi->item.pszText, lpdi->item.cchTextMax);
const wchar_t *title = currentPlaylist.ItemTitle( item );
if ( !title )
title = currentPlaylist.ItemName( item );
// TODO - just using for debugging to check values
#ifdef DEBUG
wchar_t info[ 128 ] = { 0 };
if ( currentPlaylist.GetItemExtendedInfo( item, L"cloud", info, 128 ) )
{
StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"[%s] %d. %s", info, item + 1, title );
}
else
{
#endif
StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"%d. %s", item + 1, title );
#ifdef DEBUG
}
#endif
}
break;
case 1:
{
wchar_t info[ 16 ] = { 0 };
if ( currentPlaylist.GetItemExtendedInfo( item, L"cloud_status", info, 16 ) )
{
StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"%s", info );
}
else
StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"%d", 4 );
}
break;
case 2:
{
if ( currentPlaylist.GetItemLengthMilliseconds( item ) == 0 ) // if the length is 0, then we'll re-read it
{
wchar_t title[ FILETITLE_SIZE ] = { 0 };
int length = 0;
mediaLibrary.GetFileInfo( currentPlaylist.ItemName( item ), title, FILETITLE_SIZE, &length );
if ( length == 0 )
currentPlaylist.SetItemLengthMilliseconds( item, -1000 );
else
{
currentPlaylist.SetItemLengthMilliseconds( item, length * 1000 );
}
}
int length = currentPlaylist.GetItemLengthMilliseconds( item ) / 1000;
if ( length <= 0 )
lpdi->item.pszText[ 0 ] = 0;
else
StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"%d:%02d", length / 60, length % 60 );
}
break;
}
}
return 0;
}
BOOL playlist_OnCustomDraw( HWND hwndDlg, NMLVCUSTOMDRAW *plvcd, LRESULT *pResult )
{
static BOOL bDrawFocus;
static RECT rcView;
static CLOUDCOLUMNPAINT cloudColumnPaint;
*pResult = CDRF_DODEFAULT;
switch ( plvcd->nmcd.dwDrawStage )
{
case CDDS_PREPAINT:
*pResult |= CDRF_NOTIFYITEMDRAW;
CopyRect( &rcView, &plvcd->nmcd.rc );
cloudColumnPaint.hwndList = plvcd->nmcd.hdr.hwndFrom;
cloudColumnPaint.hdc = plvcd->nmcd.hdc;
cloudColumnPaint.prcView = &rcView;
return TRUE;
case CDDS_ITEMPREPAINT:
*pResult |= CDRF_NOTIFYSUBITEMDRAW;
bDrawFocus = ( CDIS_FOCUS & plvcd->nmcd.uItemState );
if ( bDrawFocus )
{
plvcd->nmcd.uItemState &= ~CDIS_FOCUS;
*pResult |= CDRF_NOTIFYPOSTPAINT;
}
return TRUE;
case CDDS_ITEMPOSTPAINT:
if ( bDrawFocus )
{
RECT rc;
rc.left = LVIR_BOUNDS;
SendMessageW( plvcd->nmcd.hdr.hwndFrom, LVM_GETITEMRECT, plvcd->nmcd.dwItemSpec, (LPARAM)&rc );
rc.left += 3;
DrawFocusRect( plvcd->nmcd.hdc, &rc );
plvcd->nmcd.uItemState |= CDIS_FOCUS;
bDrawFocus = FALSE;
}
*pResult = CDRF_SKIPDEFAULT;
return TRUE;
case( CDDS_SUBITEM | CDDS_ITEMPREPAINT ):
// TODO need to have a map between column ids so we do this correctly
if ( plvcd->iSubItem == 1 )
{
if ( 0 == plvcd->iSubItem && 0 == plvcd->nmcd.rc.right )
break;
cloudColumnPaint.iItem = plvcd->nmcd.dwItemSpec;
cloudColumnPaint.iSubItem = plvcd->iSubItem;
int cloud_icon = 4;
size_t item = plvcd->nmcd.dwItemSpec;
wchar_t info[ 16 ] = { 0 };
if ( currentPlaylist.GetItemExtendedInfo( item, L"cloud_status", info, 16 ) )
cloud_icon = _wtoi( info );
// TODO have this show an appropriate cloud icon for the playlist
// currently all we have is cloud or nothing as we'll only
// have files locally for this for the moment (need todo!!!)
cloudColumnPaint.value = cloud_icon;
cloudColumnPaint.prcItem = &plvcd->nmcd.rc;
cloudColumnPaint.rgbBk = plvcd->clrTextBk;
cloudColumnPaint.rgbFg = plvcd->clrText;
if ( MLCloudColumn_Paint( plugin.hwndLibraryParent, &cloudColumnPaint ) )
{
*pResult = CDRF_SKIPDEFAULT;
return TRUE;
}
}
break;
}
return FALSE;
}
BOOL playlist_Notify( HWND hwndDlg, WPARAM wParam, LPARAM lParam )
{
LPNMHDR l = (LPNMHDR)lParam;
if ( l->idFrom == IDC_PLAYLIST_EDITOR )
{
switch ( l->code )
{
case NM_DBLCLK:
PlaySelection( g_config->ReadInt( L"enqueuedef", 0 ) == 1, g_config->ReadInt( L"plplaymode", 1 ) );
break;
case LVN_GETDISPINFO:
return playlist_GetDisplayInfo( (NMLVDISPINFO *)lParam );
case LVN_BEGINDRAG:
we_are_drag_and_dropping = 1;
SetCapture( hwndDlg );
break;
case LVN_ITEMCHANGED:
case LVN_ODSTATECHANGED:
UpdatePlaylistTime( hwndDlg );
break;
case NM_CUSTOMDRAW:
{
LRESULT result = 0;
if ( cloud_avail && playlist_OnCustomDraw( hwndDlg, (NMLVCUSTOMDRAW *)lParam, &result ) )
{
SetWindowLongPtrW( hwndDlg, DWLP_MSGRESULT, (LONG_PTR)result );
return 1;
}
break;
}
case NM_CLICK:
{
LPNMITEMACTIVATE pnmitem = (LPNMITEMACTIVATE)lParam;
if ( cloud_avail && pnmitem->iItem != -1 && pnmitem->iSubItem == 1 )
{
RECT itemRect = { 0 };
if ( pnmitem->iSubItem )
ListView_GetSubItemRect( pnmitem->hdr.hwndFrom, pnmitem->iItem, pnmitem->iSubItem, LVIR_BOUNDS, &itemRect );
else
{
ListView_GetItemRect( pnmitem->hdr.hwndFrom, pnmitem->iItem, &itemRect, LVIR_BOUNDS );
itemRect.right = itemRect.left + ListView_GetColumnWidth( pnmitem->hdr.hwndFrom, pnmitem->iSubItem );
}
MapWindowPoints( l->hwndFrom, HWND_DESKTOP, (POINT *)&itemRect, 2 );
//int cloud_devices = 0;
HMENU cloud_hmenu = 0;
int mark = playlist_list.GetSelectionMark();
if ( mark != -1 )
{
wchar_t filename[ MAX_PATH ] = { 0 };
currentPlaylist.entries[ mark ]->GetFilename( filename, MAX_PATH );
cloud_hmenu = CreatePopupMenu();
WASABI_API_SYSCB->syscb_issueCallback( api_mldb::SYSCALLBACK, api_mldb::MLDB_FILE_GET_CLOUD_STATUS, (intptr_t)&filename, (intptr_t)&cloud_hmenu );
if ( cloud_hmenu )
{
int r = Menu_TrackPopup( plugin.hwndLibraryParent, cloud_hmenu, TPM_RETURNCMD | TPM_RIGHTBUTTON | TPM_LEFTBUTTON | TPM_NONOTIFY, itemRect.right, itemRect.top, hwndDlg, NULL );
if ( r >= CLOUD_SOURCE_MENUS && r < CLOUD_SOURCE_MENUS_UPPER )
{ // deals with cloud specific menus
// 0 = no change
// 1 = adding to cloud
// 2 = added locally
// 4 = removed
int mode = 0; // deals with cloud specific menus
WASABI_API_SYSCB->syscb_issueCallback( api_mldb::SYSCALLBACK, api_mldb::MLDB_FILE_PROCESS_CLOUD_STATUS, (intptr_t)r, (intptr_t)&mode );
// TODO
/*switch (mode)
{
case 1:
setCloudValue(&itemCache.Items[pnmitem->iItem], L"5");
break;
case 2:
setCloudValue(&itemCache.Items[pnmitem->iItem], L"4");
break;
case 4:
setCloudValue(&itemCache.Items[pnmitem->iItem], L"4");
break;
}
InvalidateRect(resultlist.getwnd(), NULL, TRUE);*/
}
DestroyMenu( cloud_hmenu );
}
}
}
}
break;
}
}
switch ( l->code )
{
case HDN_ITEMCHANGING:
{
LPNMHEADERW phdr = (LPNMHEADERW)lParam;
if ( phdr->pitem && ( HDI_WIDTH & phdr->pitem->mask ) && phdr->iItem == 1 )
{
if ( !cloud_avail )
phdr->pitem->cxy = 0;
else
{
INT width = phdr->pitem->cxy;
if ( MLCloudColumn_GetWidth( plugin.hwndLibraryParent, &width ) )
phdr->pitem->cxy = width;
}
}
break;
}
}
return 0;
}
|