PlaylistView.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. #include "main.h"
  2. #include "PlaylistView.h"
  3. #include "Playlist.h"
  4. #include "CurrentPlaylist.h"
  5. #include "api__ml_playlists.h"
  6. #include "../ml_local/api_mldb.h"
  7. #include "../ml_pmp/pmp.h"
  8. #include <strsafe.h>
  9. extern Playlist currentPlaylist;
  10. static BOOL playlist_GetDisplayInfo( NMLVDISPINFO *lpdi )
  11. {
  12. size_t item = lpdi->item.iItem;
  13. if ( item < 0 || item >= currentPlaylist.GetNumItems() )
  14. return 0;
  15. if ( lpdi->item.mask & LVIF_TEXT )
  16. {
  17. switch ( lpdi->item.iSubItem )
  18. {
  19. case 0:
  20. {
  21. if ( !currentPlaylist.IsCached( item ) )
  22. {
  23. wchar_t title[ FILETITLE_SIZE ] = { 0 };
  24. int length = -1;
  25. mediaLibrary.GetFileInfo( currentPlaylist.ItemName( item ), title, FILETITLE_SIZE, &length );
  26. currentPlaylist.SetItemLengthMilliseconds( item, length * 1000 );
  27. currentPlaylist.SetItemTitle( item, title );
  28. }
  29. // CUT: currentPlaylist.GetItemTitle(item, lpdi->item.pszText, lpdi->item.cchTextMax);
  30. const wchar_t *title = currentPlaylist.ItemTitle( item );
  31. if ( !title )
  32. title = currentPlaylist.ItemName( item );
  33. // TODO - just using for debugging to check values
  34. #ifdef DEBUG
  35. wchar_t info[ 128 ] = { 0 };
  36. if ( currentPlaylist.GetItemExtendedInfo( item, L"cloud", info, 128 ) )
  37. {
  38. StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"[%s] %d. %s", info, item + 1, title );
  39. }
  40. else
  41. {
  42. #endif
  43. StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"%d. %s", item + 1, title );
  44. #ifdef DEBUG
  45. }
  46. #endif
  47. }
  48. break;
  49. case 1:
  50. {
  51. wchar_t info[ 16 ] = { 0 };
  52. if ( currentPlaylist.GetItemExtendedInfo( item, L"cloud_status", info, 16 ) )
  53. {
  54. StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"%s", info );
  55. }
  56. else
  57. StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"%d", 4 );
  58. }
  59. break;
  60. case 2:
  61. {
  62. if ( currentPlaylist.GetItemLengthMilliseconds( item ) == 0 ) // if the length is 0, then we'll re-read it
  63. {
  64. wchar_t title[ FILETITLE_SIZE ] = { 0 };
  65. int length = 0;
  66. mediaLibrary.GetFileInfo( currentPlaylist.ItemName( item ), title, FILETITLE_SIZE, &length );
  67. if ( length == 0 )
  68. currentPlaylist.SetItemLengthMilliseconds( item, -1000 );
  69. else
  70. {
  71. currentPlaylist.SetItemLengthMilliseconds( item, length * 1000 );
  72. }
  73. }
  74. int length = currentPlaylist.GetItemLengthMilliseconds( item ) / 1000;
  75. if ( length <= 0 )
  76. lpdi->item.pszText[ 0 ] = 0;
  77. else
  78. StringCchPrintf( lpdi->item.pszText, lpdi->item.cchTextMax, L"%d:%02d", length / 60, length % 60 );
  79. }
  80. break;
  81. }
  82. }
  83. return 0;
  84. }
  85. BOOL playlist_OnCustomDraw( HWND hwndDlg, NMLVCUSTOMDRAW *plvcd, LRESULT *pResult )
  86. {
  87. static BOOL bDrawFocus;
  88. static RECT rcView;
  89. static CLOUDCOLUMNPAINT cloudColumnPaint;
  90. *pResult = CDRF_DODEFAULT;
  91. switch ( plvcd->nmcd.dwDrawStage )
  92. {
  93. case CDDS_PREPAINT:
  94. *pResult |= CDRF_NOTIFYITEMDRAW;
  95. CopyRect( &rcView, &plvcd->nmcd.rc );
  96. cloudColumnPaint.hwndList = plvcd->nmcd.hdr.hwndFrom;
  97. cloudColumnPaint.hdc = plvcd->nmcd.hdc;
  98. cloudColumnPaint.prcView = &rcView;
  99. return TRUE;
  100. case CDDS_ITEMPREPAINT:
  101. *pResult |= CDRF_NOTIFYSUBITEMDRAW;
  102. bDrawFocus = ( CDIS_FOCUS & plvcd->nmcd.uItemState );
  103. if ( bDrawFocus )
  104. {
  105. plvcd->nmcd.uItemState &= ~CDIS_FOCUS;
  106. *pResult |= CDRF_NOTIFYPOSTPAINT;
  107. }
  108. return TRUE;
  109. case CDDS_ITEMPOSTPAINT:
  110. if ( bDrawFocus )
  111. {
  112. RECT rc;
  113. rc.left = LVIR_BOUNDS;
  114. SendMessageW( plvcd->nmcd.hdr.hwndFrom, LVM_GETITEMRECT, plvcd->nmcd.dwItemSpec, (LPARAM)&rc );
  115. rc.left += 3;
  116. DrawFocusRect( plvcd->nmcd.hdc, &rc );
  117. plvcd->nmcd.uItemState |= CDIS_FOCUS;
  118. bDrawFocus = FALSE;
  119. }
  120. *pResult = CDRF_SKIPDEFAULT;
  121. return TRUE;
  122. case( CDDS_SUBITEM | CDDS_ITEMPREPAINT ):
  123. // TODO need to have a map between column ids so we do this correctly
  124. if ( plvcd->iSubItem == 1 )
  125. {
  126. if ( 0 == plvcd->iSubItem && 0 == plvcd->nmcd.rc.right )
  127. break;
  128. cloudColumnPaint.iItem = plvcd->nmcd.dwItemSpec;
  129. cloudColumnPaint.iSubItem = plvcd->iSubItem;
  130. int cloud_icon = 4;
  131. size_t item = plvcd->nmcd.dwItemSpec;
  132. wchar_t info[ 16 ] = { 0 };
  133. if ( currentPlaylist.GetItemExtendedInfo( item, L"cloud_status", info, 16 ) )
  134. cloud_icon = _wtoi( info );
  135. // TODO have this show an appropriate cloud icon for the playlist
  136. // currently all we have is cloud or nothing as we'll only
  137. // have files locally for this for the moment (need todo!!!)
  138. cloudColumnPaint.value = cloud_icon;
  139. cloudColumnPaint.prcItem = &plvcd->nmcd.rc;
  140. cloudColumnPaint.rgbBk = plvcd->clrTextBk;
  141. cloudColumnPaint.rgbFg = plvcd->clrText;
  142. if ( MLCloudColumn_Paint( plugin.hwndLibraryParent, &cloudColumnPaint ) )
  143. {
  144. *pResult = CDRF_SKIPDEFAULT;
  145. return TRUE;
  146. }
  147. }
  148. break;
  149. }
  150. return FALSE;
  151. }
  152. BOOL playlist_Notify( HWND hwndDlg, WPARAM wParam, LPARAM lParam )
  153. {
  154. LPNMHDR l = (LPNMHDR)lParam;
  155. if ( l->idFrom == IDC_PLAYLIST_EDITOR )
  156. {
  157. switch ( l->code )
  158. {
  159. case NM_DBLCLK:
  160. PlaySelection( g_config->ReadInt( L"enqueuedef", 0 ) == 1, g_config->ReadInt( L"plplaymode", 1 ) );
  161. break;
  162. case LVN_GETDISPINFO:
  163. return playlist_GetDisplayInfo( (NMLVDISPINFO *)lParam );
  164. case LVN_BEGINDRAG:
  165. we_are_drag_and_dropping = 1;
  166. SetCapture( hwndDlg );
  167. break;
  168. case LVN_ITEMCHANGED:
  169. case LVN_ODSTATECHANGED:
  170. UpdatePlaylistTime( hwndDlg );
  171. break;
  172. case NM_CUSTOMDRAW:
  173. {
  174. LRESULT result = 0;
  175. if ( cloud_avail && playlist_OnCustomDraw( hwndDlg, (NMLVCUSTOMDRAW *)lParam, &result ) )
  176. {
  177. SetWindowLongPtrW( hwndDlg, DWLP_MSGRESULT, (LONG_PTR)result );
  178. return 1;
  179. }
  180. break;
  181. }
  182. case NM_CLICK:
  183. {
  184. LPNMITEMACTIVATE pnmitem = (LPNMITEMACTIVATE)lParam;
  185. if ( cloud_avail && pnmitem->iItem != -1 && pnmitem->iSubItem == 1 )
  186. {
  187. RECT itemRect = { 0 };
  188. if ( pnmitem->iSubItem )
  189. ListView_GetSubItemRect( pnmitem->hdr.hwndFrom, pnmitem->iItem, pnmitem->iSubItem, LVIR_BOUNDS, &itemRect );
  190. else
  191. {
  192. ListView_GetItemRect( pnmitem->hdr.hwndFrom, pnmitem->iItem, &itemRect, LVIR_BOUNDS );
  193. itemRect.right = itemRect.left + ListView_GetColumnWidth( pnmitem->hdr.hwndFrom, pnmitem->iSubItem );
  194. }
  195. MapWindowPoints( l->hwndFrom, HWND_DESKTOP, (POINT *)&itemRect, 2 );
  196. //int cloud_devices = 0;
  197. HMENU cloud_hmenu = 0;
  198. int mark = playlist_list.GetSelectionMark();
  199. if ( mark != -1 )
  200. {
  201. wchar_t filename[ MAX_PATH ] = { 0 };
  202. currentPlaylist.entries[ mark ]->GetFilename( filename, MAX_PATH );
  203. cloud_hmenu = CreatePopupMenu();
  204. WASABI_API_SYSCB->syscb_issueCallback( api_mldb::SYSCALLBACK, api_mldb::MLDB_FILE_GET_CLOUD_STATUS, (intptr_t)&filename, (intptr_t)&cloud_hmenu );
  205. if ( cloud_hmenu )
  206. {
  207. int r = Menu_TrackPopup( plugin.hwndLibraryParent, cloud_hmenu, TPM_RETURNCMD | TPM_RIGHTBUTTON | TPM_LEFTBUTTON | TPM_NONOTIFY, itemRect.right, itemRect.top, hwndDlg, NULL );
  208. if ( r >= CLOUD_SOURCE_MENUS && r < CLOUD_SOURCE_MENUS_UPPER )
  209. { // deals with cloud specific menus
  210. // 0 = no change
  211. // 1 = adding to cloud
  212. // 2 = added locally
  213. // 4 = removed
  214. int mode = 0; // deals with cloud specific menus
  215. WASABI_API_SYSCB->syscb_issueCallback( api_mldb::SYSCALLBACK, api_mldb::MLDB_FILE_PROCESS_CLOUD_STATUS, (intptr_t)r, (intptr_t)&mode );
  216. // TODO
  217. /*switch (mode)
  218. {
  219. case 1:
  220. setCloudValue(&itemCache.Items[pnmitem->iItem], L"5");
  221. break;
  222. case 2:
  223. setCloudValue(&itemCache.Items[pnmitem->iItem], L"4");
  224. break;
  225. case 4:
  226. setCloudValue(&itemCache.Items[pnmitem->iItem], L"4");
  227. break;
  228. }
  229. InvalidateRect(resultlist.getwnd(), NULL, TRUE);*/
  230. }
  231. DestroyMenu( cloud_hmenu );
  232. }
  233. }
  234. }
  235. }
  236. break;
  237. }
  238. }
  239. switch ( l->code )
  240. {
  241. case HDN_ITEMCHANGING:
  242. {
  243. LPNMHEADERW phdr = (LPNMHEADERW)lParam;
  244. if ( phdr->pitem && ( HDI_WIDTH & phdr->pitem->mask ) && phdr->iItem == 1 )
  245. {
  246. if ( !cloud_avail )
  247. phdr->pitem->cxy = 0;
  248. else
  249. {
  250. INT width = phdr->pitem->cxy;
  251. if ( MLCloudColumn_GetWidth( plugin.hwndLibraryParent, &width ) )
  252. phdr->pitem->cxy = width;
  253. }
  254. }
  255. break;
  256. }
  257. }
  258. return 0;
  259. }