1 /*****************************************************************************
2 * playlist.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* strerror() */
40 #define NMAXFILE 512 // at least 256
44 #define TEXTMAXBUF 512 // at least 500
47 #define LONG2POINT(l, pt) ((pt).x = (SHORT)LOWORD(l), (pt).y = (SHORT)HIWORD(l))
49 #define NUMIMAGES 11 // Number of buttons in the toolbar
50 #define IMAGEWIDTH 16 // Width of the buttons in the toolbar
51 #define IMAGEHEIGHT 16 // Height of the buttons in the toolbar
52 #define BUTTONWIDTH 0 // Width of the button images in the toolbar
53 #define BUTTONHEIGHT 0 // Height of the button images in the toolbar
54 #define ID_TOOLBAR 2000 // Identifier of the main tool bar
71 #define HELP_OPENPL _T("Open playlist")
72 #define HELP_SAVEPL _T("Save playlist")
73 #define HELP_ADDFILE _T("Add File")
74 #define HELP_ADDMRL _T("Add MRL")
75 #define HELP_DELETE _T("Delete selection")
76 #define HELP_INFOS _T("Item info")
77 #define HELP_UP _T("Up")
78 #define HELP_DOWN _T("Down")
79 #define HELP_RANDOM _T("Random")
80 #define HELP_LOOP _T("Repeat all")
81 #define HELP_REPEAT _T("Repeat one")
83 // The TBBUTTON structure contains information the toolbar buttons.
84 static TBBUTTON tbButton2[] =
86 {0, ID_MANAGE_OPENPL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
87 {1, ID_MANAGE_SAVEPL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
88 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
89 {2, ID_MANAGE_ADDFILE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
90 {3, ID_MANAGE_ADDMRL, TBSTATE_ENABLED, TBSTYLE_BUTTON},
91 {4, ID_SEL_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
92 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
93 {5, Infos_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
94 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
95 {6, Up_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
96 {7, Down_Event, TBSTATE_ENABLED, TBSTYLE_BUTTON},
97 {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
98 {8, Random_Event, TBSTATE_ENABLED, TBSTYLE_CHECK},
99 {9, Loop_Event, TBSTATE_ENABLED, TBSTYLE_CHECK},
100 {10, Repeat_Event, TBSTATE_ENABLED, TBSTYLE_CHECK}
104 TCHAR * szToolTips2[] =
119 /*****************************************************************************
121 *****************************************************************************/
123 /*****************************************************************************
125 *****************************************************************************/
126 Playlist::Playlist( intf_thread_t *_p_intf, HINSTANCE _hInst )
128 /* Initializations */
136 b_need_update = VLC_TRUE;
139 /***********************************************************************
145 ***********************************************************************/
146 static HWND CreateMenuBar( HWND hwnd, HINSTANCE hInst )
150 memset( &mbi, 0, sizeof(SHMENUBARINFO) );
151 mbi.cbSize = sizeof(SHMENUBARINFO);
152 mbi.hwndParent = hwnd;
153 mbi.hInstRes = hInst;
154 mbi.nToolBarId = IDR_MENUBAR2;
156 if( !SHCreateMenuBar( &mbi ) )
158 MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
163 tbbi.cbSize = sizeof(tbbi);
164 tbbi.dwMask = TBIF_LPARAM;
166 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_MANAGE, (LPARAM)&tbbi );
167 HMENU hmenu_file = (HMENU)tbbi.lParam;
168 RemoveMenu( hmenu_file, 0, MF_BYPOSITION );
169 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SORT, (LPARAM)&tbbi );
170 HMENU hmenu_sort = (HMENU)tbbi.lParam;
171 RemoveMenu( hmenu_sort, 0, MF_BYPOSITION );
172 SendMessage( mbi.hwndMB, TB_GETBUTTONINFO, IDM_SEL, (LPARAM)&tbbi );
173 HMENU hmenu_sel = (HMENU)tbbi.lParam;
174 RemoveMenu( hmenu_sel, 0, MF_BYPOSITION );
177 HMENU hmenu_file = CreatePopupMenu();
178 HMENU hmenu_sort = CreatePopupMenu();
179 HMENU hmenu_sel = CreatePopupMenu();
182 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDFILE,
183 _T("&Add File...") );
184 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDDIRECTORY,
185 _T("Add Directory...") );
186 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_ADDMRL,
188 AppendMenu( hmenu_file, MF_SEPARATOR, 0, 0 );
189 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_OPENPL,
190 _T("Open &Playlist") );
191 AppendMenu( hmenu_file, MF_STRING, ID_MANAGE_SAVEPL,
192 _T("Save Playlist") );
194 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_TITLE,
195 _T("Sort by &title") );
196 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_RTITLE,
197 _T("&Reverse sort by title") );
198 AppendMenu( hmenu_sort, MF_SEPARATOR, 0, 0 );
199 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_AUTHOR,
200 _T("Sort by &author") );
201 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_RAUTHOR,
202 _T("Reverse sort by &author") );
203 AppendMenu( hmenu_sort, MF_SEPARATOR, 0, 0 );
204 AppendMenu( hmenu_sort, MF_STRING, ID_SORT_SHUFFLE,
205 _T("&Shuffle Playlist") );
207 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_ENABLE,
209 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_DISABLE,
211 AppendMenu( hmenu_sel, MF_SEPARATOR, 0, 0 );
212 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_INVERT,
214 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_DELETE,
216 AppendMenu( hmenu_sel, MF_SEPARATOR, 0, 0 );
217 AppendMenu( hmenu_sel, MF_STRING, ID_SEL_SELECTALL,
225 HMENU hmenu = CreateMenu();
227 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_file, _T("Manage") );
228 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_sort, _T("Sort") );
229 AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)hmenu_sel, _T("Selection") );
231 SetMenu( hwnd, hmenu );
237 /***********************************************************************
242 Processes messages sent to the main window.
243 ***********************************************************************/
244 LRESULT Playlist::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
248 INITCOMMONCONTROLSEX iccex;
253 playlist_t *p_playlist;
258 shidi.dwMask = SHIDIM_FLAGS;
259 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
260 SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
262 SHInitDialog( &shidi );
264 hwndCB = CreateMenuBar( hwnd, hInst );
266 iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
267 iccex.dwICC = ICC_BAR_CLASSES;
269 // Registers TOOLBAR control classes from the common control dll
270 InitCommonControlsEx (&iccex);
272 // Create the toolbar control.
273 dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS |
274 WS_EX_OVERLAPPEDWINDOW | CCS_NOPARENTALIGN;
276 hwndTB = CreateToolbarEx( hwnd, dwStyle, 0, NUMIMAGES,
277 hInst, IDB_BITMAP3, tbButton2,
278 sizeof (tbButton2) / sizeof (TBBUTTON),
279 BUTTONWIDTH, BUTTONHEIGHT,
280 IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON) );
283 // Add ToolTips to the toolbar.
284 SendMessage( hwndTB, TB_SETTOOLTIPS, (WPARAM) NUMIMAGES,
285 (LPARAM)szToolTips2 );
287 // Reposition the toolbar.
288 GetClientRect( hwnd, &rect );
289 GetWindowRect( hwndTB, &rectTB );
290 MoveWindow( hwndTB, rect.left, rect.top - 2, rect.right - rect.left,
291 MENU_HEIGHT /*rectTB.bottom - rectTB.top */, TRUE);
293 // random, loop, repeat buttons states
295 p_playlist = (playlist_t *)
296 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
297 if( !p_playlist ) break;
299 var_Get( p_playlist , "random", &val );
300 bState = val.b_bool ? TBSTATE_CHECKED : 0;
301 SendMessage( hwndTB, TB_SETSTATE, Random_Event,
302 MAKELONG(bState | TBSTATE_ENABLED, 0) );
303 var_Get( p_playlist , "loop", &val );
304 bState = val.b_bool ? TBSTATE_CHECKED : 0;
305 SendMessage( hwndTB, TB_SETSTATE, Loop_Event,
306 MAKELONG(bState | TBSTATE_ENABLED, 0) );
307 var_Get( p_playlist , "repeat", &val );
308 bState = val.b_bool ? TBSTATE_CHECKED : 0;
309 SendMessage( hwndTB, TB_SETSTATE, Repeat_Event,
310 MAKELONG(bState | TBSTATE_ENABLED, 0) );
311 vlc_object_release( p_playlist );
313 GetClientRect( hwnd, &rect );
314 hListView = CreateWindow( WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD |
315 LVS_REPORT | LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL,
316 rect.left, rect.top + 2*(MENU_HEIGHT+1), rect.right - rect.left,
317 rect.bottom - ( rect.top + 2*MENU_HEIGHT) - MENU_HEIGHT,
318 hwnd, NULL, hInst, NULL );
319 ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
322 lv.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
323 lv.fmt = LVCFMT_LEFT ;
324 GetClientRect( hwnd, &rect );
326 lv.pszText = _T("Name");
328 ListView_InsertColumn( hListView, 0, &lv);
330 lv.pszText = _T("Author");
332 ListView_InsertColumn( hListView, 1, &lv);
333 lv.cx = rect.right - rect.left - 180;
334 lv.pszText = _T("Duration");
336 ListView_InsertColumn( hListView, 2, &lv);
338 SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
340 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
348 EndDialog( hwnd, LOWORD( wp ) );
355 EndDialog( hwnd, LOWORD( wp ) );
358 case ID_MANAGE_OPENPL:
360 b_need_update = VLC_TRUE;
363 case ID_MANAGE_SAVEPL:
364 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
366 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
369 case ID_MANAGE_ADDFILE:
370 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
372 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
373 b_need_update = VLC_TRUE;
376 case ID_MANAGE_ADDDIRECTORY:
377 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
379 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
380 b_need_update = VLC_TRUE;
383 case ID_MANAGE_ADDMRL:
384 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
386 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
387 b_need_update = VLC_TRUE;
392 b_need_update = VLC_TRUE;
396 SHFullScreen( GetForegroundWindow(), SHFS_SHOWSIPBUTTON );
398 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
399 b_need_update = VLC_TRUE;
404 b_need_update = VLC_TRUE;
409 b_need_update = VLC_TRUE;
425 OnSort( ID_SORT_TITLE );
429 OnSort( ID_SORT_RTITLE );
433 OnSort( ID_SORT_AUTHOR );
436 case ID_SORT_RAUTHOR:
437 OnSort( ID_SORT_RAUTHOR );
440 case ID_SORT_SHUFFLE:
441 OnSort( ID_SORT_SHUFFLE );
449 OnDisableSelection();
456 case ID_SEL_SELECTALL:
460 case PopupPlay_Event:
462 b_need_update = VLC_TRUE;
467 b_need_update = VLC_TRUE;
472 b_need_update = VLC_TRUE;
475 case PopupInfo_Event:
477 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
478 b_need_update = VLC_TRUE;
487 if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
488 ( ((LPNMHDR)lp)->code == NM_CUSTOMDRAW ) )
490 SetWindowLong( hwnd, DWL_MSGRESULT,
491 (LONG)ProcessCustomDraw(lp) );
493 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
494 ( ((LPNMHDR)lp)->code == GN_CONTEXTMENU ) )
496 HandlePopupMenu( hwnd, ((PNMRGINFO)lp)->ptAction );
498 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
499 ( ((LPNMHDR)lp)->code == LVN_COLUMNCLICK ) )
501 OnColSelect( ((LPNMLISTVIEW)lp)->iSubItem );
503 else if( ( ((LPNMHDR)lp)->hwndFrom == hListView ) &&
504 ( ((LPNMHDR)lp)->code == LVN_ITEMACTIVATE ) )
506 OnActivateItem( ((LPNMLISTVIEW)lp)->iSubItem );
511 // the message was not processed
512 // indicate if the base class handled it
519 LRESULT Playlist::ProcessCustomDraw( LPARAM lParam )
521 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
523 switch( lplvcd->nmcd.dwDrawStage )
525 case CDDS_PREPAINT : //Before the paint cycle begins
526 //request notifications for individual listview items
527 return CDRF_NOTIFYITEMDRAW;
529 case CDDS_ITEMPREPAINT: //Before an item is drawn
530 playlist_t *p_playlist = (playlist_t *)
531 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
532 if( p_playlist == NULL ) return CDRF_DODEFAULT;
533 if( (int)lplvcd->nmcd.dwItemSpec == p_playlist->i_index )
535 lplvcd->clrText = RGB(255,0,0);
536 vlc_object_release(p_playlist);
540 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist,
541 (int)lplvcd->nmcd.dwItemSpec );
544 vlc_object_release(p_playlist);
545 return CDRF_DODEFAULT;
547 if( p_item->b_enabled == VLC_FALSE )
549 lplvcd->clrText = RGB(192,192,192);
550 vlc_object_release(p_playlist);
555 return CDRF_DODEFAULT;
558 /**********************************************************************
559 * Handles the display of the "floating" popup
560 **********************************************************************/
561 void Playlist::HandlePopupMenu( HWND hwnd, POINT point )
563 HMENU hMenuTrackPopup;
565 // Create the popup menu.
566 hMenuTrackPopup = CreatePopupMenu();
568 // Append some items.
569 AppendMenu( hMenuTrackPopup, MF_STRING, PopupPlay_Event, _T("Play") );
570 AppendMenu( hMenuTrackPopup, MF_STRING, PopupDel_Event, _T("Delete") );
571 AppendMenu( hMenuTrackPopup, MF_STRING, PopupEna_Event,
572 _T("Toggle enabled") );
573 AppendMenu( hMenuTrackPopup, MF_STRING, PopupInfo_Event, _T("Info") );
575 /* Draw and track the "floating" popup */
576 TrackPopupMenu( hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL );
578 /* Destroy the menu since were are done with it. */
579 DestroyMenu( hMenuTrackPopup );
582 /**********************************************************************
583 * Update the playlist
584 **********************************************************************/
585 void Playlist::UpdatePlaylist()
590 b_need_update = VLC_FALSE;
593 playlist_t *p_playlist = (playlist_t *)
594 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
595 if( p_playlist == NULL ) return;
597 /* Update the colour of items */
599 vlc_mutex_lock( &p_playlist->object_lock );
600 if( p_intf->p_sys->i_playing != p_playlist->i_index )
602 // p_playlist->i_index in RED
605 // if exists, p_intf->p_sys->i_playing in BLACK
606 p_intf->p_sys->i_playing = p_playlist->i_index;
608 vlc_mutex_unlock( &p_playlist->object_lock );
610 vlc_object_release( p_playlist );
613 /**********************************************************************
614 * Rebuild the playlist
615 **********************************************************************/
616 void Playlist::Rebuild()
618 playlist_t *p_playlist = (playlist_t *)
619 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
620 if( p_playlist == NULL ) return;
623 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
625 /* Clear the list... */
626 ListView_DeleteAllItems( hListView );
628 /* ...and rebuild it */
629 vlc_mutex_lock( &p_playlist->object_lock );
630 for( int i = 0; i < p_playlist->i_size; i++ )
638 ListView_InsertItem( hListView, &lv );
639 ListView_SetItemText( hListView, lv.iItem, 0,
640 _FROMMB(p_playlist->pp_items[i]->input.psz_name) );
643 vlc_mutex_unlock( &p_playlist->object_lock );
646 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED |
647 LVIS_SELECTED, LVIS_STATEIMAGEMASK )
649 ListView_SetItemState( hListView, i_focused, LVIS_FOCUSED,
650 LVIS_STATEIMAGEMASK );
652 vlc_object_release( p_playlist );
655 /**********************************************************************
656 * Update one playlist item
657 **********************************************************************/
658 void Playlist::UpdateItem( int i )
660 playlist_t *p_playlist = (playlist_t *)
661 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
663 if( p_playlist == NULL ) return;
665 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
669 vlc_object_release(p_playlist);
673 ListView_SetItemText( hListView, i, 0, _FROMMB(p_item->input.psz_name) );
674 ListView_SetItemText( hListView, i, 1,
675 _FROMMB( vlc_input_item_GetInfo( &p_item->input,
676 _("General") , _("Author") ) ) );
678 char psz_duration[MSTRTIME_MAX_SIZE];
679 mtime_t dur = p_item->input.i_duration;
680 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
681 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
683 ListView_SetItemText( hListView, i, 3, _FROMMB(psz_duration) );
685 vlc_object_release(p_playlist);
688 /**********************************************************************
690 **********************************************************************/
691 void Playlist::DeleteItem( int item )
693 playlist_t *p_playlist = (playlist_t *)
694 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
695 if( p_playlist == NULL ) return;
697 playlist_Delete( p_playlist, item );
698 ListView_DeleteItem( hListView, item );
700 vlc_object_release( p_playlist );
703 /**********************************************************************
705 **********************************************************************/
706 void Playlist::OnOpen()
709 TCHAR DateiName[80+1] = _T("\0");
710 static TCHAR szFilter[] = _T("All playlists (*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u)\0*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u\0");
712 playlist_t *p_playlist = (playlist_t *)
713 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
714 if( p_playlist == NULL ) return;
716 memset( &ofn, 0, sizeof(OPENFILENAME) );
717 ofn.lStructSize = sizeof (OPENFILENAME);
718 ofn.hwndOwner = NULL;
719 ofn.hInstance = hInst;
720 ofn.lpstrFilter = szFilter;
721 ofn.lpstrCustomFilter = NULL;
722 ofn.nMaxCustFilter = 0;
723 ofn.nFilterIndex = 1;
724 ofn.lpstrFile = (LPTSTR) DateiName;
726 ofn.lpstrFileTitle = NULL;
727 ofn.nMaxFileTitle = 40;
728 ofn.lpstrInitialDir = NULL;
729 ofn.lpstrTitle = _T("Open playlist");
732 ofn.nFileExtension = 0;
733 ofn.lpstrDefExt = NULL;
736 ofn.lpTemplateName = NULL;
738 if( GetOpenFileName((LPOPENFILENAME)&ofn) )
740 playlist_Import( p_playlist, _TOMB(ofn.lpstrFile) );
743 vlc_object_release( p_playlist );
746 void Playlist::OnSave()
748 TCHAR szFile[NMAXFILE] = _T("\0");
750 TCHAR psz_filters[1000];
759 { { "M3U file", "*.m3u", "export-m3u" },
760 { "PLS file", "*.pls", "export-pls" }
763 for( int i_len = 0, i = 0; i < sizeof(formats)/sizeof(formats[0]); i++ )
765 _tcscpy( psz_filters + i_len, _FROMMB(formats[i].psz_desc) );
766 i_len = i_len + _tcslen( psz_filters + i_len );
767 psz_filters[i_len++] = '\0';
768 _tcscpy( psz_filters + i_len, _FROMMB(formats[i].psz_filter) );
769 i_len = i_len + _tcslen( psz_filters + i_len );
770 psz_filters[i_len++] = '\0';
771 if( i == sizeof(formats)/sizeof(formats[0]) -1 )
772 psz_filters[i_len] = '\0';
775 memset( &(ofn), 0, sizeof(ofn));
776 ofn.lStructSize = sizeof(ofn);
777 ofn.hwndOwner = NULL;
778 ofn.lpstrFile = szFile;
779 ofn.nMaxFile = NMAXFILE;
780 ofn.lpstrFilter = psz_filters;
781 ofn.lpstrTitle = _T("Save playlist");
782 ofn.Flags = OFN_HIDEREADONLY;
784 if( GetSaveFileName( (LPOPENFILENAME)&ofn ) )
786 playlist_t * p_playlist = (playlist_t *)
787 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
789 if( p_playlist && ofn.lpstrFile )
791 playlist_Export( p_playlist, _TOMB(ofn.lpstrFile),
792 formats[ofn.nFilterIndex ?
793 ofn.nFilterIndex - 1 : 0].psz_module );
796 if( p_playlist ) vlc_object_release( p_playlist );
800 void Playlist::OnAddFile()
802 // Same code as in Interface
804 TCHAR DateiName[80+1] = _T("\0");
805 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
807 memset( &ofn, 0, sizeof(OPENFILENAME) );
808 ofn.lStructSize = sizeof(OPENFILENAME);
809 ofn.hwndOwner = NULL;
810 ofn.hInstance = hInst;
811 ofn.lpstrFilter = szFilter;
812 ofn.lpstrCustomFilter = NULL;
813 ofn.nMaxCustFilter = 0;
814 ofn.nFilterIndex = 1;
815 ofn.lpstrFile = (LPTSTR)DateiName;
817 ofn.lpstrFileTitle = NULL;
818 ofn.nMaxFileTitle = 40;
819 ofn.lpstrInitialDir = NULL;
820 ofn.lpstrTitle = _T("Add File");
823 ofn.nFileExtension = 0;
824 ofn.lpstrDefExt = NULL;
827 ofn.lpTemplateName = NULL;
829 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
831 if( GetOpenFileName( (LPOPENFILENAME)&ofn ) )
833 playlist_t *p_playlist = (playlist_t *)
834 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
835 if( p_playlist == NULL ) return;
837 char *psz_filename = _TOMB(ofn.lpstrFile);
838 playlist_Add( p_playlist, psz_filename, psz_filename,
839 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
840 vlc_object_release( p_playlist );
844 void Playlist::OnAddMRL()
848 /**********************************************************************
849 * Selection functions
850 **********************************************************************/
851 void Playlist::OnDeleteSelection()
853 /* Delete from the end to the beginning, to avoid a shift of indices */
854 for( long item = ((int) ListView_GetItemCount( hListView ) - 1);
857 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
864 void Playlist::OnInvertSelection()
868 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
870 iState = ListView_GetItemState( hListView, item, LVIS_STATEIMAGEMASK );
871 ListView_SetItemState( hListView, item, iState ^ LVIS_SELECTED,
872 LVIS_STATEIMAGEMASK );
876 void Playlist::OnEnableSelection()
878 playlist_t *p_playlist = (playlist_t *)
879 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
880 if( p_playlist == NULL ) return;
882 for( long item = ListView_GetItemCount( hListView ) - 1;
885 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
887 playlist_item_t *p_item =
888 playlist_ItemGetByPos( p_playlist, item );
889 playlist_Enable( p_playlist, p_item );
893 vlc_object_release( p_playlist);
896 void Playlist::OnDisableSelection()
898 playlist_t *p_playlist = (playlist_t *)
899 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
900 if( p_playlist == NULL ) return;
902 for( long item = ListView_GetItemCount( hListView ) - 1;
905 if( ListView_GetItemState( hListView, item, LVIS_SELECTED ) )
908 playlist_item_t *p_item =
909 playlist_ItemGetByPos( p_playlist, item );
910 playlist_Disable( p_playlist, p_item );
914 vlc_object_release( p_playlist);
917 void Playlist::OnSelectAll()
919 for( long item = 0; item < ListView_GetItemCount( hListView ); item++ )
921 ListView_SetItemState( hListView, item, LVIS_FOCUSED | LVIS_SELECTED,
922 LVIS_STATEIMAGEMASK );
926 void Playlist::OnActivateItem( int i_item )
928 playlist_t *p_playlist = (playlist_t *)
929 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
930 if( p_playlist == NULL ) return;
932 playlist_Goto( p_playlist, i_item );
934 vlc_object_release( p_playlist );
937 void Playlist::ShowInfos( HWND hwnd, int i_item )
939 playlist_t *p_playlist = (playlist_t *)
940 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
941 if( p_playlist == NULL ) return;
943 vlc_mutex_lock( &p_playlist->object_lock);
944 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
945 vlc_mutex_unlock( &p_playlist->object_lock );
949 ItemInfoDialog *iteminfo_dialog =
950 new ItemInfoDialog( p_intf, hInst, p_item );
951 CreateDialogBox( hwnd, iteminfo_dialog );
952 UpdateItem( i_item );
953 delete iteminfo_dialog;
956 vlc_object_release( p_playlist );
959 /********************************************************************
961 ********************************************************************/
962 void Playlist::OnUp()
964 playlist_t *p_playlist = (playlist_t *)
965 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
966 if( p_playlist == NULL ) return;
968 /* We use the first selected item, so find it */
970 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
972 if( i_item > 0 && i_item < p_playlist->i_size )
974 playlist_Move( p_playlist , i_item, i_item - 1);
977 ListView_SetItemState( hListView, i_item - 1, LVIS_FOCUSED,
978 LVIS_STATEIMAGEMASK );
982 ListView_SetItemState( hListView, 0, LVIS_FOCUSED,
983 LVIS_STATEIMAGEMASK );
986 vlc_object_release( p_playlist );
991 void Playlist::OnDown()
993 playlist_t *p_playlist = (playlist_t *)
994 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
995 if( p_playlist == NULL ) return;
997 /* We use the first selected item, so find it */
999 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1001 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
1003 playlist_Move( p_playlist , i_item, i_item + 2 );
1004 ListView_SetItemState( hListView, i_item + 1, LVIS_FOCUSED,
1005 LVIS_STATEIMAGEMASK );
1007 vlc_object_release( p_playlist );
1012 /**********************************************************************
1013 * Playlist mode functions
1014 **********************************************************************/
1015 void Playlist::OnRandom()
1018 int bState = SendMessage( hwndTB, TB_GETSTATE, Random_Event, 0 );
1019 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
1021 playlist_t *p_playlist = (playlist_t *)
1022 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1023 if( p_playlist == NULL ) return;
1025 var_Set( p_playlist , "random", val );
1026 vlc_object_release( p_playlist );
1029 void Playlist::OnLoop ()
1032 int bState = SendMessage( hwndTB, TB_GETSTATE, Loop_Event, 0 );
1033 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
1035 playlist_t *p_playlist = (playlist_t *)
1036 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1037 if( p_playlist == NULL ) return;
1039 var_Set( p_playlist , "loop", val );
1040 vlc_object_release( p_playlist );
1043 void Playlist::OnRepeat ()
1046 int bState = SendMessage( hwndTB, TB_GETSTATE, Repeat_Event, 0 );
1047 val.b_bool = (bState & TBSTATE_CHECKED) ? VLC_TRUE : VLC_FALSE;
1049 playlist_t *p_playlist = (playlist_t *)
1050 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1051 if( p_playlist == NULL ) return;
1053 var_Set( p_playlist , "repeat", val );
1054 vlc_object_release( p_playlist );
1057 /********************************************************************
1059 ********************************************************************/
1060 void Playlist::OnSort( UINT event )
1062 playlist_t *p_playlist = (playlist_t *)
1063 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1064 if( p_playlist == NULL ) return;
1069 playlist_SortTitle( p_playlist , ORDER_NORMAL );
1071 case ID_SORT_RTITLE:
1072 playlist_SortTitle( p_playlist , ORDER_REVERSE );
1074 case ID_SORT_AUTHOR:
1075 playlist_SortAuthor(p_playlist , ORDER_NORMAL );
1077 case ID_SORT_RAUTHOR:
1078 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
1080 case ID_SORT_SHUFFLE:
1081 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
1085 vlc_object_release( p_playlist );
1087 b_need_update = VLC_TRUE;
1092 void Playlist::OnColSelect( int iSubItem )
1094 playlist_t *p_playlist = (playlist_t *)
1095 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1096 if( p_playlist == NULL ) return;
1101 if( i_title_sorted != 1 )
1103 playlist_SortTitle( p_playlist, ORDER_NORMAL );
1108 playlist_SortTitle( p_playlist, ORDER_REVERSE );
1109 i_title_sorted = -1;
1113 if( i_author_sorted != 1 )
1115 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
1116 i_author_sorted = 1;
1120 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
1121 i_author_sorted = -1;
1128 vlc_object_release( p_playlist );
1130 b_need_update = VLC_TRUE;
1135 /*****************************************************************************
1136 * Popup management functions
1137 *****************************************************************************/
1138 void Playlist::OnPopupPlay()
1141 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1143 playlist_t *p_playlist = (playlist_t *)
1144 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1145 if( p_playlist == NULL ) return;
1147 if( i_popup_item != -1 )
1149 playlist_Goto( p_playlist, i_popup_item );
1152 vlc_object_release( p_playlist );
1155 void Playlist::OnPopupDel()
1158 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1160 DeleteItem( i_popup_item );
1163 void Playlist::OnPopupEna()
1166 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1168 playlist_t *p_playlist = (playlist_t *)
1169 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1170 if( p_playlist == NULL ) return;
1172 playlist_item_t *p_item =
1173 playlist_ItemGetByPos( p_playlist, i_popup_item );
1175 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1176 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1178 playlist_Disable( p_playlist, p_item );
1182 playlist_Enable( p_playlist, p_item );
1185 vlc_object_release( p_playlist);
1186 UpdateItem( i_popup_item );
1189 void Playlist::OnPopupInfo( HWND hwnd )
1192 ListView_GetNextItem( hListView, -1, LVIS_SELECTED | LVNI_ALL );
1194 ShowInfos( hwnd, i_popup_item );