1 /*****************************************************************************
2 * playlist.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
5 * $Id: playlist.cpp,v 1.36 2004/01/11 00:45:06 zorglub Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
30 #include "wxwindows.h"
31 #include <wx/listctrl.h>
33 /* Callback prototype */
34 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
35 vlc_value_t old_val, vlc_value_t new_val, void *param );
36 int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
37 vlc_value_t old_val, vlc_value_t new_val, void *param );
38 int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
39 vlc_value_t old_val, vlc_value_t new_val, void *param );
41 /*****************************************************************************
43 *****************************************************************************/
45 /* IDs for the controls and the menu commands */
63 EnableSelection_Event,
64 DisableSelection_Event,
66 InvertSelection_Event,
67 DeleteSelection_Event,
91 Browse_Event, /* For export playlist */
94 BEGIN_EVENT_TABLE(Playlist, wxFrame)
96 EVT_MENU(AddFile_Event, Playlist::OnAddFile)
97 EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
98 EVT_MENU(Close_Event, Playlist::OnClose)
99 EVT_MENU(Open_Event, Playlist::OnOpen)
100 EVT_MENU(Save_Event, Playlist::OnSave)
102 EVT_MENU(SortTitle_Event, Playlist::OnSort)
103 EVT_MENU(RSortTitle_Event, Playlist::OnSort)
104 EVT_MENU(SortAuthor_Event, Playlist::OnSort)
105 EVT_MENU(RSortAuthor_Event, Playlist::OnSort)
106 EVT_MENU(SortGroup_Event, Playlist::OnSort)
107 EVT_MENU(RSortGroup_Event, Playlist::OnSort)
109 EVT_MENU(Randomize_Event, Playlist::OnSort)
111 EVT_MENU(EnableSelection_Event, Playlist::OnEnableSelection)
112 EVT_MENU(DisableSelection_Event, Playlist::OnDisableSelection)
113 EVT_MENU(InvertSelection_Event, Playlist::OnInvertSelection)
114 EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
115 EVT_MENU(SelectAll_Event, Playlist::OnSelectAll)
116 EVT_MENU(Infos_Event, Playlist::OnInfos)
117 EVT_CHECKBOX(Random_Event, Playlist::OnRandom)
118 EVT_CHECKBOX(Repeat_Event, Playlist::OnRepeat)
119 EVT_CHECKBOX(Loop_Event, Playlist::OnLoop)
121 EVT_MENU(EnableGroup_Event, Playlist::OnEnDis)
122 EVT_MENU(DisableGroup_Event, Playlist::OnEnDis)
124 /* Listview events */
125 EVT_LIST_ITEM_ACTIVATED(ListView_Event, Playlist::OnActivateItem)
126 EVT_LIST_COL_CLICK(ListView_Event, Playlist::OnColSelect)
127 EVT_LIST_KEY_DOWN(ListView_Event, Playlist::OnKeyDown)
128 EVT_LIST_ITEM_RIGHT_CLICK(ListView_Event, Playlist::OnPopup)
131 EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
132 EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
133 EVT_MENU( PopupEna_Event, Playlist::OnPopupEna)
134 EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo)
138 EVT_BUTTON( Search_Event, Playlist::OnSearch)
139 EVT_BUTTON( Save_Event, Playlist::OnSave)
140 EVT_BUTTON( Infos_Event, Playlist::OnInfos)
142 EVT_BUTTON( Up_Event, Playlist::OnUp)
143 EVT_BUTTON( Down_Event, Playlist::OnDown)
145 EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange)
147 /* Special events : we don't want to destroy the window when the user
149 EVT_CLOSE(Playlist::OnClose)
153 /* Event Table for the Newgroup class */
154 BEGIN_EVENT_TABLE(NewGroup, wxDialog)
155 EVT_BUTTON( wxID_OK, NewGroup::OnOk)
156 EVT_BUTTON( wxID_CANCEL, NewGroup::OnCancel)
160 /* Event Table for the ExportPlaylist class */
161 BEGIN_EVENT_TABLE(ExportPlaylist, wxDialog)
162 EVT_BUTTON( wxID_OK, ExportPlaylist::OnOk)
163 EVT_BUTTON( wxID_CANCEL, ExportPlaylist::OnCancel)
164 EVT_BUTTON( Browse_Event, ExportPlaylist::OnBrowse)
167 /*****************************************************************************
169 *****************************************************************************/
170 Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
171 wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
172 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
174 /* Initializations */
175 iteminfo_dialog = NULL;
178 i_update_counter = 0;
179 i_sort_mode = MODE_NONE;
180 b_need_update = VLC_FALSE;
181 vlc_mutex_init( p_intf, &lock );
182 SetIcon( *p_intf->p_sys->p_icon );
189 var_Create( p_intf, "random", VLC_VAR_BOOL );
190 var_Change( p_intf, "random", VLC_VAR_INHERITVALUE, & val, NULL );
191 var_Create( p_intf, "loop", VLC_VAR_BOOL );
192 var_Create( p_intf, "loop", VLC_VAR_BOOL );
193 var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
194 var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
196 /* Create our "Manage" menu */
197 wxMenu *manage_menu = new wxMenu;
198 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add...")) );
199 manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
200 manage_menu->AppendSeparator();
201 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
202 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
203 manage_menu->AppendSeparator();
204 manage_menu->Append( Close_Event, wxU(_("&Close")) );
206 /* Create our "Sort" menu */
207 wxMenu *sort_menu = new wxMenu;
208 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
209 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
210 sort_menu->AppendSeparator();
211 sort_menu->Append( SortAuthor_Event, wxU(_("Sort by &author")) );
212 sort_menu->Append( RSortAuthor_Event, wxU(_("&Reverse sort by author")) );
213 sort_menu->AppendSeparator();
214 sort_menu->Append( SortGroup_Event, wxU(_("Sort by &group")) );
215 sort_menu->Append( RSortGroup_Event, wxU(_("&Reverse sort by group")) );
216 sort_menu->AppendSeparator();
217 sort_menu->Append( Randomize_Event, wxU(_("&Randomize Playlist")) );
219 /* Create our "Selection" menu */
220 wxMenu *selection_menu = new wxMenu;
221 selection_menu->Append( EnableSelection_Event, wxU(_("&Enable")) );
222 selection_menu->Append( DisableSelection_Event, wxU(_("&Disable")) );
223 selection_menu->AppendSeparator();
224 selection_menu->Append( InvertSelection_Event, wxU(_("&Invert")) );
225 selection_menu->Append( DeleteSelection_Event, wxU(_("&Delete")) );
226 selection_menu->Append( SelectAll_Event, wxU(_("&Select All")) );
228 /* Create our "Group" menu */
229 wxMenu *group_menu = new wxMenu;
230 group_menu->Append( EnableGroup_Event, wxU(_("&Enable all group items")) );
231 group_menu->Append( DisableGroup_Event,
232 wxU(_("&Disable all group items")) );
234 /* Append the freshly created menus to the menu bar */
235 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
236 menubar->Append( manage_menu, wxU(_("&Manage")) );
237 menubar->Append( sort_menu, wxU(_("S&ort")) );
238 menubar->Append( selection_menu, wxU(_("&Selection")) );
239 menubar->Append( group_menu, wxU(_("&Groups")) );
241 /* Attach the menu bar to the frame */
242 SetMenuBar( menubar );
244 /* Create the popup menu */
245 popup_menu = new wxMenu;
246 popup_menu->Append( PopupPlay_Event, wxU(_("Play item")) );
247 popup_menu->Append( PopupDel_Event, wxU(_("Delete item")) );
248 popup_menu->Append( PopupEna_Event, wxU(_("Toggle enabled")) );
249 popup_menu->Append( PopupInfo_Event, wxU(_("Info on item")) );
251 /* Create a panel to put everything in */
252 wxPanel *playlist_panel = new wxPanel( this, -1 );
253 playlist_panel->SetAutoLayout( TRUE );
255 /* Create the Random checkbox */
256 wxCheckBox *random_checkbox =
257 new wxCheckBox( playlist_panel, Random_Event, wxU(_("Random")) );
258 var_Get( p_intf, "random", &val );
259 vlc_bool_t b_random = val.b_bool;
260 random_checkbox->SetValue( b_random == VLC_FALSE ? 0 : 1 );
262 /* Create the Loop Checkbox */
263 wxCheckBox *loop_checkbox =
264 new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Loop")) );
265 var_Get( p_intf, "loop", &val );
266 int b_loop = val.b_bool ;
267 loop_checkbox->SetValue( b_loop );
269 /* Create the Repeat one checkbox */
270 wxCheckBox *repeat_checkbox =
271 new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat one")) );
272 var_Get( p_intf, "repeat", &val );
273 int b_repeat = val.b_bool ;
274 repeat_checkbox->SetValue( b_repeat );
276 /* Create the Search Textbox */
278 new wxTextCtrl( playlist_panel, SearchText_Event, wxT(""),
279 wxDefaultPosition, wxSize(140, -1),
282 /* Create the search button */
284 new wxButton( playlist_panel, Search_Event, wxU(_("Search")) );
287 /* Create the listview */
288 /* FIXME: the given size is arbitrary, and prevents us from resizing
289 * the window to smaller dimensions. But the sizers don't seem to adjust
290 * themselves to the size of a listview, and with a wxDefaultSize the
291 * playlist window is ridiculously small */
292 listview = new wxListView( playlist_panel, ListView_Event,
293 wxDefaultPosition, wxSize( 500, 300 ),
294 wxLC_REPORT | wxSUNKEN_BORDER );
295 listview->InsertColumn( 0, wxU(_("Name")) );
296 listview->InsertColumn( 1, wxU(_("Author")) );
297 listview->InsertColumn( 2, wxU(_("Group")) );
298 listview->InsertColumn( 3, wxU(_("Duration")) );
299 listview->SetColumnWidth( 0, 270 );
300 listview->SetColumnWidth( 1, 150 );
301 listview->SetColumnWidth( 2, 80 );
303 /* Create the Up-Down buttons */
304 wxButton *up_button =
305 new wxButton( playlist_panel, Up_Event, wxU(_("Up") ) );
307 wxButton *down_button =
308 new wxButton( playlist_panel, Down_Event, wxU(_("Down") ) );
310 /* Create the iteminfo button */
311 wxButton *iteminfo_button =
312 new wxButton( playlist_panel, Infos_Event, wxU(_("Item info") ) );
314 /* Place everything in sizers */
315 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
316 button_sizer->Add( iteminfo_button, 0, wxALIGN_CENTER|wxLEFT , 5);
317 button_sizer->Layout();
319 wxBoxSizer *updown_sizer = new wxBoxSizer( wxHORIZONTAL );
320 updown_sizer->Add( up_button, 0, wxALIGN_LEFT|wxRIGHT, 3);
321 updown_sizer->Add( down_button, 0, wxALIGN_LEFT|wxLEFT, 3);
322 updown_sizer->Layout();
324 wxBoxSizer *checkbox_sizer = new wxBoxSizer( wxHORIZONTAL );
325 checkbox_sizer->Add( random_checkbox, 0,
326 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
327 checkbox_sizer->Add( loop_checkbox, 0,
328 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
329 checkbox_sizer->Add( repeat_checkbox, 0,
330 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
331 checkbox_sizer->Layout();
333 wxBoxSizer *search_sizer = new wxBoxSizer( wxHORIZONTAL );
334 search_sizer->Add( search_text, 0, wxRIGHT|wxALIGN_CENTER, 3);
335 search_sizer->Add( search_button, 0, wxLEFT|wxALIGN_CENTER, 3);
336 search_sizer->Layout();
338 /* The top and bottom sizers */
339 wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
340 top_sizer->Add( checkbox_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_LEFT, 4 );
341 top_sizer->Add( search_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 4 );
344 wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
345 bottom_sizer->Add( updown_sizer, 0, wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4);
346 bottom_sizer->Add( button_sizer , 0, wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
347 bottom_sizer->Layout();
349 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
351 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
352 panel_sizer->Add( top_sizer, 0, wxEXPAND | wxALL, 5 );
353 panel_sizer->Add( listview, 1, wxEXPAND | wxALL, 5 );
354 panel_sizer->Add( bottom_sizer, 0 , wxEXPAND | wxALL, 5);
355 panel_sizer->Layout();
357 playlist_panel->SetSizerAndFit( panel_sizer );
358 main_sizer->Add( playlist_panel, 1, wxGROW, 0 );
359 main_sizer->Layout();
360 SetSizerAndFit( main_sizer );
362 #if !defined(__WXX11__)
363 /* Associate drop targets with the playlist */
364 SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
367 playlist_t *p_playlist =
368 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
370 if( p_playlist == NULL )
375 /* We want to be noticed of playlist changes */
377 /* Some global changes happened -> Rebuild all */
378 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
380 /* We went to the next item */
381 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
383 /* One item has been updated */
384 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
387 vlc_object_release( p_playlist );
389 /* Update the playlist */
393 Playlist::~Playlist()
395 playlist_t *p_playlist =
396 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
398 if( p_playlist == NULL )
403 delete iteminfo_dialog;
405 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
406 vlc_object_release( p_playlist );
409 /**********************************************************************
410 * Update one playlist item
411 **********************************************************************/
412 void Playlist::UpdateItem( int i )
414 playlist_t *p_playlist =
415 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
417 if( p_playlist == NULL )
421 if( i < 0 || i >= p_playlist->i_size || !p_playlist->pp_items[i] )
423 vlc_object_release(p_playlist);
426 listview->SetItem( i, 0, wxL2U(p_playlist->pp_items[i]->psz_name) );
427 listview->SetItem( i, 1, wxL2U( playlist_GetInfo( p_playlist, i,
428 _("General") , _("Author") ) ) );
429 char *psz_group = playlist_FindGroup(p_playlist,p_playlist->
430 pp_items[i]->i_group);
431 listview->SetItem( i, 2,
432 wxL2U( psz_group ? psz_group : _("Normal") ) );
434 if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
437 listitem.m_itemId = i;
438 listitem.SetTextColour( *wxLIGHT_GREY);
439 listview->SetItem(listitem);
442 char psz_duration[MSTRTIME_MAX_SIZE];
443 mtime_t dur = p_playlist->pp_items[i]->i_duration;
444 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
445 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
446 listview->SetItem( i, 3, wxU(psz_duration) );
448 /* Change the colour for the currenty played stream */
450 listitem.m_itemId = i;
451 if( i == p_playlist->i_index )
453 listitem.SetTextColour( *wxRED );
457 listitem.SetTextColour( *wxBLACK );
459 listview->SetItem( listitem );
461 vlc_object_release(p_playlist);
464 /**********************************************************************
465 * Rebuild the playlist
466 **********************************************************************/
467 void Playlist::Rebuild()
469 playlist_t *p_playlist =
470 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
472 if( p_playlist == NULL )
477 int i_focused = listview->GetFocusedItem();
479 /* Clear the list... */
480 listview->DeleteAllItems();
482 /* ...and rebuild it */
483 vlc_mutex_lock( &p_playlist->object_lock );
484 for( int i = 0; i < p_playlist->i_size; i++ )
486 wxString filename = wxL2U(p_playlist->pp_items[i]->psz_name);
487 listview->InsertItem( i, filename );
490 vlc_mutex_unlock( &p_playlist->object_lock );
494 listview->Focus( i_focused );
495 listview->Select( i_focused );
499 listview->Focus( p_playlist->i_index );
502 vlc_object_release( p_playlist );
505 void Playlist::ShowPlaylist( bool show )
507 if( show ) Rebuild();
511 void Playlist::UpdatePlaylist()
513 vlc_bool_t b_need_update = VLC_FALSE;
516 /* If the playlist isn't show there's no need to update it */
517 if( !IsShown() ) return;
519 vlc_mutex_lock( &lock );
520 if( this->b_need_update )
522 b_need_update =VLC_TRUE;
523 this->b_need_update = VLC_FALSE;
525 vlc_mutex_unlock( &lock );
532 /* Updating the playing status every 0.5s is enough */
533 if( i_update_counter % 5 ) return;
535 playlist_t *p_playlist =
536 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
538 if( p_playlist == NULL )
543 /* Update the colour of items */
545 vlc_mutex_lock( &p_playlist->object_lock );
546 if( p_intf->p_sys->i_playing != p_playlist->i_index )
549 listitem.m_itemId = p_playlist->i_index;
550 listitem.SetTextColour( *wxRED );
551 listview->SetItem( listitem );
553 if( p_intf->p_sys->i_playing != -1 )
555 listitem.m_itemId = p_intf->p_sys->i_playing;
556 listitem.SetTextColour( *wxBLACK );
557 listview->SetItem( listitem );
559 p_intf->p_sys->i_playing = p_playlist->i_index;
561 vlc_mutex_unlock( &p_playlist->object_lock );
562 vlc_object_release( p_playlist );
565 /*****************************************************************************
567 *****************************************************************************/
568 void Playlist::DeleteItem( int item )
570 playlist_t *p_playlist =
571 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
573 if( p_playlist == NULL )
578 playlist_Delete( p_playlist, item );
579 listview->DeleteItem( item );
581 vlc_object_release( p_playlist );
584 void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) )
589 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
591 ExportPlaylist *exp_pl = new ExportPlaylist( p_intf, this);
596 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
598 playlist_t *p_playlist =
599 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
601 if( p_playlist == NULL )
606 wxFileDialog dialog( this, wxU(_("Open playlist")),
607 wxT(""), wxT(""), wxT("*"), wxOPEN );
609 if( dialog.ShowModal() == wxID_OK )
611 playlist_Import( p_playlist, dialog.GetPath().mb_str() );
614 vlc_object_release( p_playlist );
617 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
619 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
626 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
628 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
635 /********************************************************************
637 ********************************************************************/
638 void Playlist::OnUp( wxCommandEvent& event)
640 playlist_t *p_playlist =
641 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
643 if( p_playlist == NULL )
648 /* We use the first selected item, so find it */
649 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
650 wxLIST_STATE_SELECTED);
651 if( i_item > 0 && i_item < p_playlist->i_size )
653 playlist_Move( p_playlist , i_item, i_item - 1);
656 listview->Focus( i_item - 1 );
663 vlc_object_release( p_playlist );
667 void Playlist::OnDown( wxCommandEvent& event)
669 playlist_t *p_playlist =
670 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
672 if( p_playlist == NULL )
677 /* We use the first selected item, so find it */
678 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
679 wxLIST_STATE_SELECTED );
680 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
682 playlist_Move( p_playlist , i_item, i_item + 2 );
683 listview->Focus( i_item + 1 );
685 vlc_object_release( p_playlist );
689 /********************************************************************
691 ********************************************************************/
692 void Playlist::OnSort( wxCommandEvent& event )
694 playlist_t *p_playlist =
695 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
697 if( p_playlist == NULL )
701 switch( event.GetId() )
703 case SortTitle_Event:
704 playlist_SortTitle( p_playlist , 0 );
706 case RSortTitle_Event:
707 playlist_SortTitle( p_playlist , 1 );
709 case SortAuthor_Event:
710 playlist_SortAuthor(p_playlist , 0 );
712 case RSortAuthor_Event:
713 playlist_SortAuthor( p_playlist , 1 );
715 case SortGroup_Event:
716 playlist_SortGroup( p_playlist , 0 );
718 case RSortGroup_Event:
719 playlist_SortGroup( p_playlist , 1 );
721 case Randomize_Event:
722 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
725 vlc_object_release( p_playlist );
732 void Playlist::OnColSelect( wxListEvent& event )
734 playlist_t *p_playlist =
735 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
737 if( p_playlist == NULL )
741 switch( event.GetColumn() )
744 if( i_title_sorted != 1 )
746 playlist_SortTitle( p_playlist, 0 );
751 playlist_SortTitle( p_playlist, 1 );
756 if( i_author_sorted != 1 )
758 playlist_SortAuthor( p_playlist, 0 );
763 playlist_SortAuthor( p_playlist, 1 );
764 i_author_sorted = -1;
768 if( i_group_sorted != 1 )
770 playlist_SortGroup( p_playlist, 0 );
775 playlist_SortGroup( p_playlist, 1 );
782 vlc_object_release( p_playlist );
789 /**********************************************************************
791 **********************************************************************/
792 void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
794 search_button->SetDefault();
797 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
799 wxString search_string= search_text->GetValue();
805 for( i_current = 0 ; i_current <= listview->GetItemCount() ; i_current++ )
807 if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED )
808 == wxLIST_STATE_SELECTED )
815 for ( i_current = i_first + 1; i_current <= listview->GetItemCount() ;
819 listitem.SetId( i_current );
820 listview->GetItem( listitem );
821 if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
827 for( long item = 0; item < listview->GetItemCount(); item++ )
829 listview->Select( item, FALSE );
833 listitem.SetId(i_item);
834 listitem.m_state = wxLIST_STATE_SELECTED;
835 listview->Select( i_item, TRUE );
836 listview->Focus( i_item );
840 /**********************************************************************
841 * Selection functions
842 **********************************************************************/
843 void Playlist::OnInvertSelection( wxCommandEvent& WXUNUSED(event) )
845 for( long item = 0; item < listview->GetItemCount(); item++ )
847 listview->Select( item, ! listview->IsSelected( item ) );
851 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
853 /* Delete from the end to the beginning, to avoid a shift of indices */
854 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
856 if( listview->IsSelected( item ) )
865 void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) )
867 playlist_t *p_playlist =
868 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
870 if( p_playlist == NULL )
875 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
877 if( listview->IsSelected( item ) )
879 playlist_Enable( p_playlist, item );
883 vlc_object_release( p_playlist);
886 void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) )
888 playlist_t *p_playlist =
889 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
891 if( p_playlist == NULL )
896 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
898 if( listview->IsSelected( item ) )
900 playlist_Disable( p_playlist, item );
904 vlc_object_release( p_playlist);
907 void Playlist::OnSelectAll( wxCommandEvent& WXUNUSED(event) )
909 for( long item = 0; item < listview->GetItemCount(); item++ )
911 listview->Select( item, TRUE );
915 /**********************************************************************
916 * Playlist mode functions
917 **********************************************************************/
918 void Playlist::OnRandom( wxCommandEvent& event )
921 val.b_bool = event.IsChecked();
922 playlist_t *p_playlist =
923 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
925 if( p_playlist == NULL )
929 var_Set( p_playlist , "random", val);
930 vlc_object_release( p_playlist );
932 void Playlist::OnLoop ( wxCommandEvent& event )
935 val.b_bool = event.IsChecked();
936 playlist_t *p_playlist =
937 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
939 if( p_playlist == NULL )
943 var_Set( p_playlist , "loop", val);
944 vlc_object_release( p_playlist );
947 void Playlist::OnRepeat ( wxCommandEvent& event )
950 val.b_bool = event.IsChecked();
951 playlist_t *p_playlist =
952 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
954 if( p_playlist == NULL )
958 var_Set( p_playlist , "repeat", val);
959 vlc_object_release( p_playlist );
964 void Playlist::OnActivateItem( wxListEvent& event )
966 playlist_t *p_playlist =
967 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
969 if( p_playlist == NULL )
973 playlist_Goto( p_playlist, event.GetIndex() );
975 vlc_object_release( p_playlist );
978 void Playlist::OnKeyDown( wxListEvent& event )
980 long keycode = event.GetKeyCode();
981 /* Delete selected items */
982 if( keycode == WXK_BACK || keycode == WXK_DELETE )
984 /* We send a dummy event */
985 OnDeleteSelection( event );
989 void Playlist::ShowInfos( int i_item )
991 playlist_t *p_playlist =
992 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
994 if( p_playlist == NULL )
998 if( iteminfo_dialog == NULL )
1000 if( i_item >= 0 && i_item < p_playlist->i_size )
1002 iteminfo_dialog = new ItemInfoDialog(
1003 p_intf, p_playlist->pp_items[i_item], this );
1004 if( iteminfo_dialog->ShowModal() == wxID_OK )
1005 UpdateItem( i_item );
1006 delete iteminfo_dialog;
1007 iteminfo_dialog = NULL;
1010 vlc_object_release( p_playlist );
1013 void Playlist::OnInfos( wxCommandEvent& WXUNUSED(event) )
1015 /* We use the first selected item, so find it */
1016 long i_item = listview->GetNextItem( -1 , wxLIST_NEXT_ALL,
1017 wxLIST_STATE_SELECTED );
1018 ShowInfos( i_item );
1021 void Playlist::OnEnDis( wxCommandEvent& event )
1023 playlist_t *p_playlist =
1024 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1026 if( p_playlist == NULL )
1031 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
1032 wxLIST_STATE_SELECTED );
1034 if( i_item >= 0 && i_item < p_playlist->i_size )
1036 switch( event.GetId() )
1038 case EnableGroup_Event:
1039 playlist_EnableGroup( p_playlist ,
1040 p_playlist->pp_items[i_item]->i_group );
1042 case DisableGroup_Event:
1043 playlist_DisableGroup( p_playlist ,
1044 p_playlist->pp_items[i_item]->i_group );
1050 vlc_object_release( p_playlist );
1053 /*****************************************************************************
1054 * Popup management functions
1055 *****************************************************************************/
1056 void Playlist::OnPopup( wxListEvent& event )
1058 i_popup_item = event.GetIndex();
1059 Playlist::PopupMenu( popup_menu , ScreenToClient( wxGetMousePosition() ) );
1063 void Playlist::OnPopupPlay( wxMenuEvent& event )
1065 playlist_t *p_playlist =
1066 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1068 if( p_playlist == NULL )
1072 if( i_popup_item != -1 )
1074 playlist_Goto( p_playlist, i_popup_item );
1076 vlc_object_release( p_playlist );
1079 void Playlist::OnPopupDel( wxMenuEvent& event )
1081 DeleteItem( i_popup_item );
1084 void Playlist::OnPopupEna( wxMenuEvent& event )
1086 playlist_t *p_playlist =
1087 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1089 if( p_playlist == NULL )
1094 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1095 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1097 playlist_Disable( p_playlist, i_popup_item );
1101 playlist_Enable( p_playlist, i_popup_item );
1103 vlc_object_release( p_playlist);
1104 UpdateItem( i_popup_item );
1107 void Playlist::OnPopupInfo( wxMenuEvent& event )
1109 ShowInfos( i_popup_item );
1112 /*****************************************************************************
1113 * PlaylistChanged: callback triggered by the intf-change playlist variable
1114 * We don't rebuild the playlist directly here because we don't want the
1115 * caller to block for a too long time.
1116 *****************************************************************************/
1117 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1118 vlc_value_t old_val, vlc_value_t new_val, void *param )
1120 Playlist *p_playlist_dialog = (Playlist *)param;
1121 vlc_mutex_lock( &p_playlist_dialog->lock );
1122 p_playlist_dialog->b_need_update = VLC_TRUE;
1123 vlc_mutex_unlock( &p_playlist_dialog->lock );
1127 /*****************************************************************************
1128 * Next: callback triggered by the playlist-current playlist variable
1129 *****************************************************************************/
1130 int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1131 vlc_value_t old_val, vlc_value_t new_val, void *param )
1133 Playlist *p_playlist_dialog = (Playlist *)param;
1134 p_playlist_dialog->UpdateItem( old_val.i_int );
1135 p_playlist_dialog->UpdateItem( new_val.i_int );
1140 /*****************************************************************************
1141 * ItemChanged: callback triggered by the item-change playlist variable
1142 *****************************************************************************/
1143 int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1144 vlc_value_t old_val, vlc_value_t new_val, void *param )
1146 Playlist *p_playlist_dialog = (Playlist *)param;
1147 p_playlist_dialog->UpdateItem( new_val.i_int );
1152 /***************************************************************************
1154 ***************************************************************************/
1155 NewGroup::NewGroup( intf_thread_t *_p_intf, wxWindow *_p_parent ):
1156 wxDialog( _p_parent, -1, wxU(_("New Group")), wxDefaultPosition,
1157 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
1159 /* Initializations */
1162 SetIcon( *p_intf->p_sys->p_icon );
1164 /* Create a panel to put everything in*/
1165 wxPanel *panel = new wxPanel( this, -1 );
1166 panel->SetAutoLayout( TRUE );
1168 wxStaticText *group_label =
1169 new wxStaticText( panel , -1,
1170 wxU(_("Enter a name for the new group")));
1172 groupname = new wxTextCtrl(panel, -1, wxU(""),wxDefaultPosition,
1173 wxSize(80,27),wxTE_PROCESS_ENTER);
1175 wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );
1176 ok_button->SetDefault();
1177 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
1180 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1182 button_sizer->Add( ok_button, 0, wxALL, 5 );
1183 button_sizer->Add( cancel_button, 0, wxALL, 5 );
1184 button_sizer->Layout();
1186 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
1187 panel_sizer->Add( group_label, 0, wxEXPAND | wxALL, 5 );
1188 panel_sizer->Add( groupname, 0, wxEXPAND | wxALL, 5 );
1189 panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );
1190 panel_sizer->Layout();
1192 panel->SetSizerAndFit( panel_sizer );
1194 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1195 main_sizer->Add( panel, 1, wxEXPAND, 0 );
1196 main_sizer->Layout();
1197 SetSizerAndFit( main_sizer );
1200 NewGroup::~NewGroup()
1204 void NewGroup::OnOk( wxCommandEvent& event )
1206 psz_name = strdup( groupname->GetLineText(0).mb_str() );
1208 playlist_t * p_playlist =
1209 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1214 if( !playlist_CreateGroup( p_playlist, psz_name ) )
1218 vlc_object_release( p_playlist );
1221 EndModal( wxID_OK );
1224 void NewGroup::OnCancel( wxCommandEvent& WXUNUSED(event) )
1226 EndModal( wxID_CANCEL );
1231 /***************************************************************************
1232 * Export playlist class
1233 ***************************************************************************/
1234 ExportPlaylist::ExportPlaylist( intf_thread_t *_p_intf, wxWindow *_p_parent ):
1235 wxDialog( _p_parent, -1, wxU(_("Export playlist")), wxDefaultPosition,
1236 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
1241 /* Initializations */
1243 SetIcon( *p_intf->p_sys->p_icon );
1245 /* Create a panel to put everything in*/
1246 wxPanel *panel = new wxPanel( this, -1 );
1247 panel->SetAutoLayout( TRUE );
1249 /* Create the file box */
1250 wxStaticBox *file_box = new wxStaticBox( panel, -1,
1251 wxU(_("File to save to")) );
1252 wxStaticBoxSizer *file_sizer = new wxStaticBoxSizer( file_box,
1255 file_text = new wxTextCtrl(panel, -1, wxU(""),wxDefaultPosition,
1256 wxSize(250,-1),wxTE_PROCESS_ENTER);
1258 file_text->SetToolTip( wxU(_("Enter the name of the file to export "
1259 "the playlist to.")) );
1261 wxButton *file_button = new wxButton( panel, Browse_Event,
1264 file_sizer->Add( file_text, 0, wxALL | wxALIGN_CENTER , 5 );
1265 file_sizer->Add( file_button, 0, wxALL | wxALIGN_CENTER , 5 );
1267 /* Create the type box */
1268 wxStaticBox *type_box = new wxStaticBox( panel, -1,
1269 wxU(_("Select export type")) );
1271 wxStaticBoxSizer *type_sizer = new wxStaticBoxSizer( type_box,
1274 type_combo = new wxComboBox( panel, -1, wxT(""), wxDefaultPosition,
1275 wxSize(250, -1), 0, NULL );
1277 type_sizer->Add( type_combo, 0, wxALL | wxALIGN_CENTER, 5 );
1278 type_sizer->Layout();
1282 wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );
1283 ok_button->SetDefault();
1284 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
1287 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1289 button_sizer->Add( ok_button, 0, wxALL, 5 );
1290 button_sizer->Add( cancel_button, 0, wxALL, 5 );
1291 button_sizer->Layout();
1293 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
1294 panel_sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
1295 panel_sizer->Add( type_sizer, 0, wxEXPAND | wxALL, 5 );
1296 panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );
1297 panel_sizer->Layout();
1299 panel->SetSizerAndFit( panel_sizer );
1301 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1302 main_sizer->Add( panel, 1, wxEXPAND, 0 );
1303 main_sizer->Layout();
1304 SetSizerAndFit( main_sizer );
1306 /* build a list of available modules */
1307 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1308 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1310 p_module = (module_t *)p_list->p_values[i_index].p_object ;
1311 if( !strcmp( p_module->psz_capability, "playlist export" ) )
1313 type_combo->Append( wxU(p_module->psz_longname),
1314 p_module->pp_shortcuts[1] ?
1315 p_module->pp_shortcuts[1] :
1316 p_module->psz_object_name );
1319 vlc_list_release( p_list );
1323 ExportPlaylist::~ExportPlaylist()
1327 void ExportPlaylist::OnOk( wxCommandEvent& WXUNUSED(event) )
1329 playlist_t * p_playlist =
1330 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1335 char *psz_type = (char *)type_combo->GetClientData(
1336 type_combo->GetSelection() );
1337 if( file_text->GetValue().mb_str() && psz_type )
1339 playlist_Export( p_playlist, file_text->GetValue().mb_str(),
1344 vlc_object_release( p_playlist );
1345 EndModal( wxID_OK );
1348 void ExportPlaylist::OnCancel( wxCommandEvent& WXUNUSED(event) )
1350 EndModal( wxID_CANCEL );
1353 void ExportPlaylist::OnBrowse( wxCommandEvent& WXUNUSED(event) )
1355 wxFileDialog dialog( this, wxU(_("Save playlist")),
1356 wxT(""), wxT(""), wxT("*"), wxSAVE );
1358 if( dialog.ShowModal() == wxID_OK )
1360 file_text->SetValue( dialog.GetPath() );