1 /*****************************************************************************
2 * playlist.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
7 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8 * Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* strerror() */
40 #define TEXTMAXBUF 512 // at least 500
43 #define LONG2POINT(l, pt) ((pt).x = (SHORT)LOWORD(l), (pt).y = (SHORT)HIWORD(l))
45 #define NUMIMAGES 11 // Number of buttons in the toolbar
46 #define IMAGEWIDTH 16 // Width of the buttons in the toolbar
47 #define IMAGEHEIGHT 16 // Height of the buttons in the toolbar
48 #define BUTTONWIDTH 0 // Width of the button images in the toolbar
49 #define BUTTONHEIGHT 0 // Height of the button images in the toolbar
50 #define ID_TOOLBAR 2000 // Identifier of the main tool bar
67 #define HELP_OPENPL _T("Open playlist")
68 #define HELP_SAVEPL _T("Save playlist")
69 #define HELP_ADDFILE _T("Add File")
70 #define HELP_ADDMRL _T("Add MRL")
71 #define HELP_DELETE _T("Delete selection")
72 #define HELP_INFOS _T("Item info")
73 #define HELP_UP _T("Up")
74 #define HELP_DOWN _T("Down")
75 #define HELP_RANDOM _T("Random")
76 #define HELP_LOOP _T("Repeat all")
77 #define HELP_REPEAT _T("Repeat one")
79 // The TBBUTTON structure contains information the toolbar buttons.
80 static TBBUTTON tbButton2[] =
82 {0, ID_MANAGE_OPENPL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
83 {1, ID_MANAGE_SAVEPL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
84 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
85 {2, ID_MANAGE_ADDFILE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
86 {3, ID_MANAGE_ADDMRL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
87 {4, ID_SEL_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
88 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
89 {5, Infos_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
90 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
91 {6, Up_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
92 {7, Down_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
93 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
94 {8, Random_Event, TBSTATE_ENABLED, TBSTYLE_CHECK},
95 {9, Loop_Event, TBSTATE_ENABLED, TBSTYLE_CHECK},
96 {10, Repeat_Event, TBSTATE_ENABLED, TBSTYLE_CHECK}
100 TCHAR * szToolTips2[] =
115 /*****************************************************************************
117 *****************************************************************************/
119 /*****************************************************************************
121 *****************************************************************************/
122 Playlist::Playlist( intf_thread_t *p_intf, CBaseWindow *p_parent,
124 : CBaseWindow( p_intf, p_parent, h_inst )
126 /* Initializations */
131 b_need_update = VLC_TRUE;
134 /***********************************************************************
140 ***********************************************************************/
141 static HWND CreateMenuBar( HWND hwnd, HINSTANCE hInst )
145 memset( &mbi, 0, sizeof(SHMENUBARINFO) );
146 mbi.cbSize = sizeof(SHMENUBARINFO);
147 mbi.hwndParent = hwnd;
148 mbi.hInstRes = hInst;
149 mbi.nToolBarId = IDR_MENUBAR2;
151 if( !SHCreateMenuBar( &mbi ) )
153 MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
158 tbbi.cbSize = sizeof(tbbi);
159 tbbi.dwMask = TBIF_LPARAM;
161 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_MANAGE, (LPARAM)&tbbi );
162 HMENU hmenu_file = (HMENU)tbbi.lParam;
163 RemoveMenu( hmenu_file, 0, MF_BYPOSITION );
164 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SORT, (LPARAM)&tbbi );
165 HMENU hmenu_sort = (HMENU)tbbi.lParam;
166 RemoveMenu( hmenu_sort, 0, MF_BYPOSITION );
167 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SEL, (LPARAM)&tbbi );
168 HMENU hmenu_sel = (HMENU)tbbi.lParam;
169 RemoveMenu( hmenu_sel, 0, MF_BYPOSITION );
172 HMENU hmenu_file = CreatePopupMenu();
173 HMENU hmenu_sort = CreatePopupMenu();
174 HMENU hmenu_sel = CreatePopupMenu();
177 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDFILE,
178 _T("&Add File...") );
179 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDDIRECTORY,
180 _T("Add Directory...") );
181 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDMRL,
183 AppendMenu( hmenu_file, MF_SEPARATOR, 0, 0 );
184 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_OPENPL,
185 _T("Open &Playlist") );
186 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_SAVEPL,
187 _T("Save Playlist") );
189 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_TITLE,
190 _T("Sort by &title") );
191 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_RTITLE,
192 _T("&Reverse sort by title") );
193 AppendMenu( hmenu_sort, MF_SEPARATOR, 0, 0 );
194 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_AUTHOR,
195 _T("Sort by &author") );
196 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_RAUTHOR,
197 _T("Reverse sort by &author") );
198 AppendMenu( hmenu_sort, MF_SEPARATOR, 0, 0 );
199 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_SHUFFLE,
200 _T("&Shuffle Playlist") );
202 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_ENABLE,
204 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_DISABLE,
206 AppendMenu( hmenu_sel, MF_SEPARATOR, 0, 0 );
207 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_INVERT,
209 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_DELETE,
211 AppendMenu( hmenu_sel, MF_SEPARATOR, 0, 0 );
212 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_SELECTALL,
220 HMENU hmenu = CreateMenu();
222 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_file, _T("Manage") );
223 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_sort, _T("Sort") );
224 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_sel, _T("Selection") );
226 SetMenu( hwnd, hmenu );
232 /***********************************************************************
237 Processes messages sent to the main window.
238 ***********************************************************************/
239 LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
243 INITCOMMONCONTROLSEX iccex;
248 playlist_t *p_playlist;
253 shidi.dwMask = SHIDIM_FLAGS;
254 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
255 SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
257 SHInitDialog( &shidi );
259 hwndCB = CreateMenuBar( hwnd, hInst );
261 iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
262 iccex.dwICC = ICC_BAR_CLASSES;
264 // Registers TOOLBAR control classes from the common control dll
265 InitCommonControlsEx (&iccex);
267 // Create the toolbar control.
268 dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS |
269 WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN;
271 hwndTB = CreateToolbarEx( hwnd, dwStyle, 0, NUMIMAGES,
272 hInst, IDB_BITMAP3, tbButton2,
273 sizeof (tbButton2) / sizeof (TBBUTTON),
274 BUTTONWIDTH, BUTTONHEIGHT,
275 IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );
278 // Add ToolTips to the toolbar.
279 SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM) NUMIMAGES,
280 (LPARAM)szToolTips2 );
282 // Reposition the toolbar.
283 GetClientRect( hwnd, &rect );
284 GetWindowRect( hwndTB, &rectTB );
285 MoveWindow( hwndTB, rect.left, rect.top - 2, rect.right - rect.left,
286 MENU_HEIGHT /*rectTB.bottom - rectTB.top */, TRUE);
288 // random, loop, repeat buttons states
290 p_playlist = (playlist_t *)
291 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
292 if( !p_playlist ) break;
294 var_Get( p_playlist , "random", &val );
295 bState = val.b_bool ? TBSTATE_CHECKED : 0;
296 SendMessage( hwndTB, TB_SETSTATE, Random_Event,
297 MAKELONG(bState | TBSTATE_ENABLED, 0) );
298 var_Get( p_playlist , "loop", &val );
299 bState = val.b_bool ? TBSTATE_CHECKED : 0;
300 SendMessage( hwndTB, TB_SETSTATE, Loop_Event,
301 MAKELONG(bState | TBSTATE_ENABLED, 0) );
302 var_Get( p_playlist , "repeat", &val );
303 bState = val.b_bool ? TBSTATE_CHECKED : 0;
304 SendMessage( hwndTB, TB_SETSTATE, Repeat_Event,
305 MAKELONG(bState | TBSTATE_ENABLED, 0) );
306 vlc_object_release( p_playlist );
308 GetClientRect( hwnd, &rect );
309 hListView = CreateWindow( WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD |
310 LVS_REPORT | LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL,
311 rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left,
312 rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT,
313 hwnd, NULL, hInst, NULL );
314 ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
317 lv.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
318 lv.fmt = LVCFMT_LEFT ;
319 GetClientRect( hwnd, &rect );
321 lv.pszText = _T("Name");
323 ListView_InsertColumn( hListView, 0, &lv);
325 lv.pszText = _T("Author");
327 ListView_InsertColumn( hListView, 1, &lv);
328 lv.cx = rect.right - rect.left - 180;
329 lv.pszText = _T("Duration");
331 ListView_InsertColumn( hListView, 2, &lv);
333 SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
341 EndDialog( hwnd, LOWORD( wp ) );
345 SHSipPreference( hwnd, SIP_DOWN );
346 SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
353 EndDialog( hwnd, LOWORD( wp ) );
356 case ID_MANAGE_OPENPL:
358 b_need_update = VLC_TRUE;
361 case ID_MANAGE_SAVEPL:
365 case ID_MANAGE_ADDFILE:
366 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE,
368 b_need_update = VLC_TRUE;
371 case ID_MANAGE_ADDDIRECTORY:
372 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY,
374 b_need_update = VLC_TRUE;
377 case ID_MANAGE_ADDMRL:
378 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
379 b_need_update = VLC_TRUE;
384 b_need_update = VLC_TRUE;
389 b_need_update = VLC_TRUE;
394 b_need_update = VLC_TRUE;
399 b_need_update = VLC_TRUE;
415 OnSort( ID_SORT_TITLE );
419 OnSort( ID_SORT_RTITLE );
423 OnSort( ID_SORT_AUTHOR );
426 case ID_SORT_RAUTHOR:
427 OnSort( ID_SORT_RAUTHOR );
430 case ID_SORT_SHUFFLE:
431 OnSort( ID_SORT_SHUFFLE );
439 OnDisableSelection();
446 case ID_SEL_SELECTALL:
450 case PopupPlay_Event:
452 b_need_update = VLC_TRUE;
457 b_need_update = VLC_TRUE;
462 b_need_update = VLC_TRUE;
465 case PopupInfo_Event:
467 b_need_update = VLC_TRUE;
476 if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
477 ( ((LPNMHDR)lp)->code == NM_CUSTOMDRAW ) )
479 SetWindowLong( hwnd, DWL_MSGRESULT,
480 (LONG)ProcessCustomDraw(lp) );
482 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
483 ( ((LPNMHDR)lp)->code == GN_CONTEXTMENU ) )
485 HandlePopupMenu( hwnd, ((PNMRGINFO)lp)->ptAction );
487 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
488 ( ((LPNMHDR)lp)->code == LVN_COLUMNCLICK ) )
490 OnColSelect( ((LPNMLISTVIEW)lp)->iSubItem );
492 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
493 ( ((LPNMHDR)lp)->code == LVN_ITEMACTIVATE ) )
495 OnActivateItem( ((LPNMLISTVIEW)lp)->iSubItem );
500 // the message was not processed
501 // indicate if the base class handled it
508 LRESULT Playlist::ProcessCustomDraw( LPARAM lParam )
510 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
512 switch( lplvcd->nmcd.dwDrawStage )
514 case CDDS_PREPAINT : //Before the paint cycle begins
515 //request notifications for individual listview items
516 return CDRF_NOTIFYITEMDRAW;
518 case CDDS_ITEMPREPAINT: //Before an item is drawn
519 playlist_t *p_playlist = (playlist_t *)
520 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
521 if( p_playlist == NULL ) return CDRF_DODEFAULT;
522 if( (int)lplvcd->nmcd.dwItemSpec == p_playlist->i_index )
524 lplvcd->clrText = RGB(255,0,0);
525 vlc_object_release(p_playlist);
529 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist,
530 (int)lplvcd->nmcd.dwItemSpec );
533 vlc_object_release(p_playlist);
534 return CDRF_DODEFAULT;
536 if( p_item->b_enabled == VLC_FALSE )
538 lplvcd->clrText = RGB(192,192,192);
539 vlc_object_release(p_playlist);
544 return CDRF_DODEFAULT;
547 /**********************************************************************
548 * Handles the display of the "floating" popup
549 **********************************************************************/
550 void Playlist::HandlePopupMenu( HWND hwnd, POINT point )
552 HMENU hMenuTrackPopup;
554 // Create the popup menu.
555 hMenuTrackPopup = CreatePopupMenu();
557 // Append some items.
558 AppendMenu( hMenuTrackPopup, MF_STRING, PopupPlay_Event, _T("Play") );
559 AppendMenu( hMenuTrackPopup, MF_STRING, PopupDel_Event, _T("Delete") );
560 AppendMenu( hMenuTrackPopup, MF_STRING, PopupEna_Event,
561 _T("Toggle enabled") );
562 AppendMenu( hMenuTrackPopup, MF_STRING, PopupInfo_Event, _T("Info") );
564 /* Draw and track the "floating" popup */
565 TrackPopupMenu( hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL );
567 /* Destroy the menu since were are done with it. */
568 DestroyMenu( hMenuTrackPopup );
571 /**********************************************************************
573 **********************************************************************/
574 void Playlist::ShowPlaylist( bool b_show )
576 if( b_show ) Rebuild();
580 /**********************************************************************
581 * Update the playlist
582 **********************************************************************/
583 void Playlist::UpdatePlaylist()
588 b_need_update = VLC_FALSE;
591 playlist_t *p_playlist = (playlist_t *)
592 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
593 if( p_playlist == NULL ) return;
595 /* Update the colour of items */
597 vlc_mutex_lock( &p_playlist->object_lock );
598 if( p_intf->p_sys->i_playing != p_playlist->i_index )
600 // p_playlist->i_index in RED
603 // if exists, p_intf->p_sys->i_playing in BLACK
604 p_intf->p_sys->i_playing = p_playlist->i_index;
606 vlc_mutex_unlock( &p_playlist->object_lock );
608 vlc_object_release( p_playlist );
611 /**********************************************************************
612 * Rebuild the playlist
613 **********************************************************************/
614 void Playlist::Rebuild()
616 playlist_t *p_playlist = (playlist_t *)
617 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
618 if( p_playlist == NULL ) return;
621 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
623 /* Clear the list... */
624 ListView_DeleteAllItems( hListView );
626 /* ...and rebuild it */
627 vlc_mutex_lock( &p_playlist->object_lock );
628 for( int i = 0; i < p_playlist->i_size; i++ )
636 ListView_InsertItem( hListView, &lv );
637 ListView_SetItemText( hListView, lv.iItem, 0,
638 _FROMMB(p_playlist->pp_items[i]->input.psz_name) );
641 vlc_mutex_unlock( &p_playlist->object_lock );
644 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED |
645 LVIS_SELECTED, LVIS_STATEIMAGEMASK )
647 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED,
648 LVIS_STATEIMAGEMASK );
650 vlc_object_release( p_playlist );
653 /**********************************************************************
654 * Update one playlist item
655 **********************************************************************/
656 void Playlist::UpdateItem( int i )
658 playlist_t *p_playlist = (playlist_t *)
659 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
661 if( p_playlist == NULL ) return;
663 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
667 vlc_object_release(p_playlist);
671 ListView_SetItemText( hListView, i, 0, _FROMMB(p_item->input.psz_name) );
672 ListView_SetItemText( hListView, i, 1,
673 _FROMMB( vlc_input_item_GetInfo( &p_item->input,
674 _("General") , _("Author") ) ) );
676 char psz_duration[MSTRTIME_MAX_SIZE];
677 mtime_t dur = p_item->input.i_duration;
678 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
679 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
681 ListView_SetItemText( hListView, i, 3, _FROMMB(psz_duration) );
683 vlc_object_release(p_playlist);
686 /**********************************************************************
688 **********************************************************************/
689 void Playlist::DeleteItem( int item )
691 playlist_t *p_playlist = (playlist_t *)
692 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
693 if( p_playlist == NULL ) return;
695 playlist_Delete( p_playlist, item );
696 ListView_DeleteItem( hListView, item );
698 vlc_object_release( p_playlist );
701 /**********************************************************************
703 **********************************************************************/
704 static void OnOpenCB( intf_dialog_args_t *p_arg )
706 intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
708 if( p_arg->i_results && p_arg->psz_results[0] )
710 playlist_t * p_playlist = (playlist_t *)
711 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
715 playlist_Import( p_playlist, p_arg->psz_results[0] );
718 if( p_playlist ) vlc_object_release( p_playlist );
722 void Playlist::OnOpen()
724 char *psz_filters ="All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u";
726 intf_dialog_args_t *p_arg =
727 (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
728 memset( p_arg, 0, sizeof(intf_dialog_args_t) );
730 p_arg->psz_title = strdup( "Open playlist" );
731 p_arg->psz_extensions = strdup( psz_filters );
732 p_arg->p_arg = p_intf;
733 p_arg->pf_callback = OnOpenCB;
735 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
738 static void OnSaveCB( intf_dialog_args_t *p_arg )
740 intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
742 if( p_arg->i_results && p_arg->psz_results[0] )
744 playlist_t * p_playlist = (playlist_t *)
745 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
750 char *psz_ext = strrchr( p_arg->psz_results[0], '.' );
752 if( psz_ext && !strcmp( psz_ext, ".pls") )
753 psz_export = "export-pls";
754 else psz_export = "export-m3u";
756 playlist_Export( p_playlist, p_arg->psz_results[0], psz_export );
759 if( p_playlist ) vlc_object_release( p_playlist );
763 void Playlist::OnSave()
765 char *psz_filters ="M3U file|*.m3u|PLS file|*.pls";
767 intf_dialog_args_t *p_arg =
768 (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
769 memset( p_arg, 0, sizeof(intf_dialog_args_t) );
771 p_arg->psz_title = strdup( "Save playlist" );
772 p_arg->psz_extensions = strdup( psz_filters );
773 p_arg->b_save = VLC_TRUE;
774 p_arg->p_arg = p_intf;
775 p_arg->pf_callback = OnSaveCB;
777 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC,
781 /**********************************************************************
782 * Selection functions
783 **********************************************************************/
784 void Playlist::OnDeleteSelection()
786 /* Delete from the end to the beginning, to avoid a shift of indices */
787 for( long item = ((int) ListView_GetItemCount( hListView ) - 1);
790 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
797 void Playlist::OnInvertSelection()
801 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
803 iState = ListView_GetItemState( hListView, item, LVIS_STATEIMAGEMASK );
804 ListView_SetItemState( hListView, item, iState ^ LVIS_SELECTED,
805 LVIS_STATEIMAGEMASK );
809 void Playlist::OnEnableSelection()
811 playlist_t *p_playlist = (playlist_t *)
812 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
813 if( p_playlist == NULL ) return;
815 for( long item = ListView_GetItemCount( hListView ) - 1;
818 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
820 playlist_item_t *p_item =
821 playlist_ItemGetByPos( p_playlist, item );
822 playlist_Enable( p_playlist, p_item );
826 vlc_object_release( p_playlist);
829 void Playlist::OnDisableSelection()
831 playlist_t *p_playlist = (playlist_t *)
832 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
833 if( p_playlist == NULL ) return;
835 for( long item = ListView_GetItemCount( hListView ) - 1;
838 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
841 playlist_item_t *p_item =
842 playlist_ItemGetByPos( p_playlist, item );
843 playlist_Disable( p_playlist, p_item );
847 vlc_object_release( p_playlist);
850 void Playlist::OnSelectAll()
852 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
854 ListView_SetItemState( hListView, item, LVIS_FOCUSED | LVIS_SELECTED,
855 LVIS_STATEIMAGEMASK );
859 void Playlist::OnActivateItem( int i_item )
861 playlist_t *p_playlist = (playlist_t *)
862 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
863 if( p_playlist == NULL ) return;
865 playlist_Goto( p_playlist, i_item );
867 vlc_object_release( p_playlist );
870 void Playlist::ShowInfos( HWND hwnd, int i_item )
872 playlist_t *p_playlist = (playlist_t *)
873 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
874 if( p_playlist == NULL ) return;
876 vlc_mutex_lock( &p_playlist->object_lock);
877 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
878 vlc_mutex_unlock( &p_playlist->object_lock );
882 ItemInfoDialog *iteminfo_dialog =
883 new ItemInfoDialog( p_intf, this, hInst, p_item );
884 CreateDialogBox( hwnd, iteminfo_dialog );
885 UpdateItem( i_item );
886 delete iteminfo_dialog;
889 vlc_object_release( p_playlist );
892 /********************************************************************
894 ********************************************************************/
895 void Playlist::OnUp()
897 playlist_t *p_playlist = (playlist_t *)
898 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
899 if( p_playlist == NULL ) return;
901 /* We use the first selected item, so find it */
903 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
905 if( i_item > 0 && i_item < p_playlist->i_size )
907 playlist_Move( p_playlist , i_item, i_item - 1);
910 ListView_SetItemState( hListView, i_item - 1, LVIS_FOCUSED,
911 LVIS_STATEIMAGEMASK );
915 ListView_SetItemState( hListView, 0, LVIS_FOCUSED,
916 LVIS_STATEIMAGEMASK );
919 vlc_object_release( p_playlist );
924 void Playlist::OnDown()
926 playlist_t *p_playlist = (playlist_t *)
927 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
928 if( p_playlist == NULL ) return;
930 /* We use the first selected item, so find it */
932 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
934 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
936 playlist_Move( p_playlist , i_item, i_item + 2 );
937 ListView_SetItemState( hListView, i_item + 1, LVIS_FOCUSED,
938 LVIS_STATEIMAGEMASK );
940 vlc_object_release( p_playlist );
945 /**********************************************************************
946 * Playlist mode functions
947 **********************************************************************/
948 void Playlist::OnRandom()
951 int bState = SendMessage( hwndTB, TB_GETSTATE, Random_Event, 0 );
952 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
954 playlist_t *p_playlist = (playlist_t *)
955 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
956 if( p_playlist == NULL ) return;
958 var_Set( p_playlist , "random", val );
959 vlc_object_release( p_playlist );
962 void Playlist::OnLoop ()
965 int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 );
966 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
968 playlist_t *p_playlist = (playlist_t *)
969 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
970 if( p_playlist == NULL ) return;
972 var_Set( p_playlist , "loop", val );
973 vlc_object_release( p_playlist );
976 void Playlist::OnRepeat ()
979 int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );
980 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
982 playlist_t *p_playlist = (playlist_t *)
983 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
984 if( p_playlist == NULL ) return;
986 var_Set( p_playlist , "repeat", val );
987 vlc_object_release( p_playlist );
990 /********************************************************************
992 ********************************************************************/
993 void Playlist::OnSort( UINT event )
995 playlist_t *p_playlist = (playlist_t *)
996 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
997 if( p_playlist == NULL ) return;
1002 playlist_SortTitle( p_playlist , ORDER_NORMAL );
1004 case ID_SORT_RTITLE:
1005 playlist_SortTitle( p_playlist , ORDER_REVERSE );
1007 case ID_SORT_AUTHOR:
1008 playlist_SortAuthor(p_playlist , ORDER_NORMAL );
1010 case ID_SORT_RAUTHOR:
1011 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
1013 case ID_SORT_SHUFFLE:
1014 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
1018 vlc_object_release( p_playlist );
1020 b_need_update = VLC_TRUE;
1025 void Playlist::OnColSelect( int iSubItem )
1027 playlist_t *p_playlist = (playlist_t *)
1028 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1029 if( p_playlist == NULL ) return;
1034 if( i_title_sorted != 1 )
1036 playlist_SortTitle( p_playlist, ORDER_NORMAL );
1041 playlist_SortTitle( p_playlist, ORDER_REVERSE );
1042 i_title_sorted = -1;
1046 if( i_author_sorted != 1 )
1048 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
1049 i_author_sorted = 1;
1053 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
1054 i_author_sorted = -1;
1061 vlc_object_release( p_playlist );
1063 b_need_update = VLC_TRUE;
1068 /*****************************************************************************
1069 * Popup management functions
1070 *****************************************************************************/
1071 void Playlist::OnPopupPlay()
1074 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1076 playlist_t *p_playlist = (playlist_t *)
1077 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1078 if( p_playlist == NULL ) return;
1080 if( i_popup_item != -1 )
1082 playlist_Goto( p_playlist, i_popup_item );
1085 vlc_object_release( p_playlist );
1088 void Playlist::OnPopupDel()
1091 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1093 DeleteItem( i_popup_item );
1096 void Playlist::OnPopupEna()
1099 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1101 playlist_t *p_playlist = (playlist_t *)
1102 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1103 if( p_playlist == NULL ) return;
1105 playlist_item_t *p_item =
1106 playlist_ItemGetByPos( p_playlist, i_popup_item );
1108 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1109 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1111 playlist_Disable( p_playlist, p_item );
1115 playlist_Enable( p_playlist, p_item );
1118 vlc_object_release( p_playlist);
1119 UpdateItem( i_popup_item );
1122 void Playlist::OnPopupInfo( HWND hwnd )
1125 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1127 ShowInfos( hwnd, i_popup_item );