1 /*****************************************************************************
2 * playlist.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
5 * $Id: playlist.cpp,v 1.39 2004/01/25 03:29:01 hartman 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"
32 /* Callback prototype */
33 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
34 vlc_value_t old_val, vlc_value_t new_val, void *param );
35 int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
36 vlc_value_t old_val, vlc_value_t new_val, void *param );
37 int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
38 vlc_value_t old_val, vlc_value_t new_val, void *param );
40 /*****************************************************************************
42 *****************************************************************************/
44 /* IDs for the controls and the menu commands */
62 EnableSelection_Event,
63 DisableSelection_Event,
65 InvertSelection_Event,
66 DeleteSelection_Event,
90 Browse_Event, /* For export playlist */
93 BEGIN_EVENT_TABLE(Playlist, wxFrame)
95 EVT_MENU(AddFile_Event, Playlist::OnAddFile)
96 EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
97 EVT_MENU(Close_Event, Playlist::OnClose)
98 EVT_MENU(Open_Event, Playlist::OnOpen)
99 EVT_MENU(Save_Event, Playlist::OnSave)
101 EVT_MENU(SortTitle_Event, Playlist::OnSort)
102 EVT_MENU(RSortTitle_Event, Playlist::OnSort)
103 EVT_MENU(SortAuthor_Event, Playlist::OnSort)
104 EVT_MENU(RSortAuthor_Event, Playlist::OnSort)
105 EVT_MENU(SortGroup_Event, Playlist::OnSort)
106 EVT_MENU(RSortGroup_Event, Playlist::OnSort)
108 EVT_MENU(Randomize_Event, Playlist::OnSort)
110 EVT_MENU(EnableSelection_Event, Playlist::OnEnableSelection)
111 EVT_MENU(DisableSelection_Event, Playlist::OnDisableSelection)
112 EVT_MENU(InvertSelection_Event, Playlist::OnInvertSelection)
113 EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
114 EVT_MENU(SelectAll_Event, Playlist::OnSelectAll)
115 EVT_MENU(Infos_Event, Playlist::OnInfos)
116 EVT_CHECKBOX(Random_Event, Playlist::OnRandom)
117 EVT_CHECKBOX(Repeat_Event, Playlist::OnRepeat)
118 EVT_CHECKBOX(Loop_Event, Playlist::OnLoop)
120 EVT_MENU(EnableGroup_Event, Playlist::OnEnDis)
121 EVT_MENU(DisableGroup_Event, Playlist::OnEnDis)
123 /* Listview events */
124 EVT_LIST_ITEM_ACTIVATED(ListView_Event, Playlist::OnActivateItem)
125 EVT_LIST_COL_CLICK(ListView_Event, Playlist::OnColSelect)
126 EVT_LIST_KEY_DOWN(ListView_Event, Playlist::OnKeyDown)
127 EVT_LIST_ITEM_RIGHT_CLICK(ListView_Event, Playlist::OnPopup)
130 EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
131 EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
132 EVT_MENU( PopupEna_Event, Playlist::OnPopupEna)
133 EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo)
137 EVT_BUTTON( Search_Event, Playlist::OnSearch)
138 EVT_BUTTON( Save_Event, Playlist::OnSave)
139 EVT_BUTTON( Infos_Event, Playlist::OnInfos)
141 EVT_BUTTON( Up_Event, Playlist::OnUp)
142 EVT_BUTTON( Down_Event, Playlist::OnDown)
144 EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange)
146 /* Special events : we don't want to destroy the window when the user
148 EVT_CLOSE(Playlist::OnClose)
152 /* Event Table for the Newgroup class */
153 BEGIN_EVENT_TABLE(NewGroup, wxDialog)
154 EVT_BUTTON( wxID_OK, NewGroup::OnOk)
155 EVT_BUTTON( wxID_CANCEL, NewGroup::OnCancel)
159 /*****************************************************************************
161 *****************************************************************************/
162 Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
163 wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
164 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
166 /* Initializations */
167 iteminfo_dialog = NULL;
170 i_update_counter = 0;
171 i_sort_mode = MODE_NONE;
172 b_need_update = VLC_FALSE;
173 vlc_mutex_init( p_intf, &lock );
174 SetIcon( *p_intf->p_sys->p_icon );
181 var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
182 var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
183 var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
185 /* Create our "Manage" menu */
186 wxMenu *manage_menu = new wxMenu;
187 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add...")) );
188 manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
189 manage_menu->AppendSeparator();
190 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
191 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
192 manage_menu->AppendSeparator();
193 manage_menu->Append( Close_Event, wxU(_("&Close")) );
195 /* Create our "Sort" menu */
196 wxMenu *sort_menu = new wxMenu;
197 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
198 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
199 sort_menu->AppendSeparator();
200 sort_menu->Append( SortAuthor_Event, wxU(_("Sort by &author")) );
201 sort_menu->Append( RSortAuthor_Event, wxU(_("Reverse sort by author")) );
202 sort_menu->AppendSeparator();
203 sort_menu->Append( SortGroup_Event, wxU(_("Sort by &group")) );
204 sort_menu->Append( RSortGroup_Event, wxU(_("Reverse sort by group")) );
205 sort_menu->AppendSeparator();
206 sort_menu->Append( Randomize_Event, wxU(_("&Shuffle Playlist")) );
208 /* Create our "Selection" menu */
209 wxMenu *selection_menu = new wxMenu;
210 selection_menu->Append( EnableSelection_Event, wxU(_("&Enable")) );
211 selection_menu->Append( DisableSelection_Event, wxU(_("&Disable")) );
212 selection_menu->AppendSeparator();
213 selection_menu->Append( InvertSelection_Event, wxU(_("&Invert")) );
214 selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
215 selection_menu->Append( SelectAll_Event, wxU(_("&Select All")) );
217 /* Create our "Group" menu */
218 wxMenu *group_menu = new wxMenu;
219 group_menu->Append( EnableGroup_Event, wxU(_("&Enable all group items")) );
220 group_menu->Append( DisableGroup_Event,
221 wxU(_("&Disable all group items")) );
223 /* Append the freshly created menus to the menu bar */
224 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
225 menubar->Append( manage_menu, wxU(_("&Manage")) );
226 menubar->Append( sort_menu, wxU(_("S&ort")) );
227 menubar->Append( selection_menu, wxU(_("&Selection")) );
228 menubar->Append( group_menu, wxU(_("&Groups")) );
230 /* Attach the menu bar to the frame */
231 SetMenuBar( menubar );
233 /* Create the popup menu */
234 popup_menu = new wxMenu;
235 popup_menu->Append( PopupPlay_Event, wxU(_("Play")) );
236 popup_menu->Append( PopupDel_Event, wxU(_("Delete")) );
237 popup_menu->Append( PopupEna_Event, wxU(_("Toggle enabled")) );
238 popup_menu->Append( PopupInfo_Event, wxU(_("Info")) );
240 /* Create a panel to put everything in */
241 wxPanel *playlist_panel = new wxPanel( this, -1 );
242 playlist_panel->SetAutoLayout( TRUE );
244 /* Create the Random checkbox */
245 wxCheckBox *random_checkbox =
246 new wxCheckBox( playlist_panel, Random_Event, wxU(_("Random")) );
247 var_Get( p_intf, "random", &val );
248 vlc_bool_t b_random = val.b_bool;
249 random_checkbox->SetValue( b_random == VLC_FALSE ? 0 : 1 );
251 /* Create the Loop Checkbox */
252 wxCheckBox *loop_checkbox =
253 new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Repeat All")) );
254 var_Get( p_intf, "loop", &val );
255 int b_loop = val.b_bool ;
256 loop_checkbox->SetValue( b_loop );
258 /* Create the Repeat one checkbox */
259 wxCheckBox *repeat_checkbox =
260 new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat One")) );
261 var_Get( p_intf, "repeat", &val );
262 int b_repeat = val.b_bool ;
263 repeat_checkbox->SetValue( b_repeat );
265 /* Create the Search Textbox */
267 new wxTextCtrl( playlist_panel, SearchText_Event, wxT(""),
268 wxDefaultPosition, wxSize(140, -1),
271 /* Create the search button */
273 new wxButton( playlist_panel, Search_Event, wxU(_("Search")) );
276 /* Create the listview */
277 /* FIXME: the given size is arbitrary, and prevents us from resizing
278 * the window to smaller dimensions. But the sizers don't seem to adjust
279 * themselves to the size of a listview, and with a wxDefaultSize the
280 * playlist window is ridiculously small */
281 listview = new wxListView( playlist_panel, ListView_Event,
282 wxDefaultPosition, wxSize( 500, 300 ),
283 wxLC_REPORT | wxSUNKEN_BORDER );
284 listview->InsertColumn( 0, wxU(_("Name")) );
285 listview->InsertColumn( 1, wxU(_("Author")) );
286 listview->InsertColumn( 2, wxU(_("Group")) );
287 listview->InsertColumn( 3, wxU(_("Duration")) );
288 listview->SetColumnWidth( 0, 270 );
289 listview->SetColumnWidth( 1, 150 );
290 listview->SetColumnWidth( 2, 80 );
292 /* Create the Up-Down buttons */
293 wxButton *up_button =
294 new wxButton( playlist_panel, Up_Event, wxU(_("Up") ) );
296 wxButton *down_button =
297 new wxButton( playlist_panel, Down_Event, wxU(_("Down") ) );
299 /* Create the iteminfo button */
300 wxButton *iteminfo_button =
301 new wxButton( playlist_panel, Infos_Event, wxU(_("Item info") ) );
303 /* Place everything in sizers */
304 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
305 button_sizer->Add( iteminfo_button, 0, wxALIGN_CENTER|wxLEFT , 5);
306 button_sizer->Layout();
308 wxBoxSizer *updown_sizer = new wxBoxSizer( wxHORIZONTAL );
309 updown_sizer->Add( up_button, 0, wxALIGN_LEFT|wxRIGHT, 3);
310 updown_sizer->Add( down_button, 0, wxALIGN_LEFT|wxLEFT, 3);
311 updown_sizer->Layout();
313 wxBoxSizer *checkbox_sizer = new wxBoxSizer( wxHORIZONTAL );
314 checkbox_sizer->Add( random_checkbox, 0,
315 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
316 checkbox_sizer->Add( loop_checkbox, 0,
317 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
318 checkbox_sizer->Add( repeat_checkbox, 0,
319 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
320 checkbox_sizer->Layout();
322 wxBoxSizer *search_sizer = new wxBoxSizer( wxHORIZONTAL );
323 search_sizer->Add( search_text, 0, wxRIGHT|wxALIGN_CENTER, 3);
324 search_sizer->Add( search_button, 0, wxLEFT|wxALIGN_CENTER, 3);
325 search_sizer->Layout();
327 /* The top and bottom sizers */
328 wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
329 top_sizer->Add( checkbox_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_LEFT, 4 );
330 top_sizer->Add( search_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 4 );
333 wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
334 bottom_sizer->Add( updown_sizer, 0, wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4);
335 bottom_sizer->Add( button_sizer , 0, wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
336 bottom_sizer->Layout();
338 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
340 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
341 panel_sizer->Add( top_sizer, 0, wxEXPAND | wxALL, 5 );
342 panel_sizer->Add( listview, 1, wxEXPAND | wxALL, 5 );
343 panel_sizer->Add( bottom_sizer, 0 , wxEXPAND | wxALL, 5);
344 panel_sizer->Layout();
346 playlist_panel->SetSizerAndFit( panel_sizer );
347 main_sizer->Add( playlist_panel, 1, wxGROW, 0 );
348 main_sizer->Layout();
349 SetSizerAndFit( main_sizer );
351 #if !defined(__WXX11__)
352 /* Associate drop targets with the playlist */
353 SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
356 playlist_t *p_playlist =
357 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
359 if( p_playlist == NULL )
364 /* We want to be noticed of playlist changes */
366 /* Some global changes happened -> Rebuild all */
367 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
369 /* We went to the next item */
370 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
372 /* One item has been updated */
373 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
376 vlc_object_release( p_playlist );
378 /* Update the playlist */
382 Playlist::~Playlist()
384 playlist_t *p_playlist =
385 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
387 if( p_playlist == NULL )
392 delete iteminfo_dialog;
394 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
395 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
396 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
397 vlc_object_release( p_playlist );
400 /**********************************************************************
401 * Update one playlist item
402 **********************************************************************/
403 void Playlist::UpdateItem( int i )
405 playlist_t *p_playlist =
406 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
408 if( p_playlist == NULL )
412 if( i < 0 || i >= p_playlist->i_size || !p_playlist->pp_items[i] )
414 vlc_object_release(p_playlist);
417 listview->SetItem( i, 0, wxL2U(p_playlist->pp_items[i]->psz_name) );
418 listview->SetItem( i, 1, wxU( playlist_GetInfo( p_playlist, i,
419 _("General") , _("Author") ) ) );
420 char *psz_group = playlist_FindGroup(p_playlist,
421 p_playlist->pp_items[i]->i_group);
422 listview->SetItem( i, 2,
423 wxL2U( psz_group ? psz_group : _("Normal") ) );
425 if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
428 listitem.m_itemId = i;
429 listitem.SetTextColour( *wxLIGHT_GREY);
430 listview->SetItem(listitem);
433 char psz_duration[MSTRTIME_MAX_SIZE];
434 mtime_t dur = p_playlist->pp_items[i]->i_duration;
435 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
436 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
437 listview->SetItem( i, 3, wxU(psz_duration) );
439 /* Change the colour for the currenty played stream */
441 listitem.m_itemId = i;
442 if( i == p_playlist->i_index )
444 listitem.SetTextColour( *wxRED );
448 listitem.SetTextColour( *wxBLACK );
450 listview->SetItem( listitem );
452 vlc_object_release(p_playlist);
455 /**********************************************************************
456 * Rebuild the playlist
457 **********************************************************************/
458 void Playlist::Rebuild()
460 playlist_t *p_playlist =
461 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
463 if( p_playlist == NULL )
468 int i_focused = listview->GetFocusedItem();
470 /* Clear the list... */
471 listview->DeleteAllItems();
473 /* ...and rebuild it */
474 vlc_mutex_lock( &p_playlist->object_lock );
475 for( int i = 0; i < p_playlist->i_size; i++ )
477 wxString filename = wxL2U(p_playlist->pp_items[i]->psz_name);
478 listview->InsertItem( i, filename );
481 vlc_mutex_unlock( &p_playlist->object_lock );
485 listview->Focus( i_focused );
486 listview->Select( i_focused );
490 listview->Focus( p_playlist->i_index );
493 vlc_object_release( p_playlist );
496 void Playlist::ShowPlaylist( bool show )
498 if( show ) Rebuild();
502 void Playlist::UpdatePlaylist()
504 vlc_bool_t b_need_update = VLC_FALSE;
507 /* If the playlist isn't show there's no need to update it */
508 if( !IsShown() ) return;
510 vlc_mutex_lock( &lock );
511 if( this->b_need_update )
513 b_need_update =VLC_TRUE;
514 this->b_need_update = VLC_FALSE;
516 vlc_mutex_unlock( &lock );
523 /* Updating the playing status every 0.5s is enough */
524 if( i_update_counter % 5 ) return;
526 playlist_t *p_playlist =
527 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
529 if( p_playlist == NULL )
534 /* Update the colour of items */
536 vlc_mutex_lock( &p_playlist->object_lock );
537 if( p_intf->p_sys->i_playing != p_playlist->i_index )
540 listitem.m_itemId = p_playlist->i_index;
541 listitem.SetTextColour( *wxRED );
542 listview->SetItem( listitem );
544 if( p_intf->p_sys->i_playing != -1 )
546 listitem.m_itemId = p_intf->p_sys->i_playing;
547 listitem.SetTextColour( *wxBLACK );
548 listview->SetItem( listitem );
550 p_intf->p_sys->i_playing = p_playlist->i_index;
552 vlc_mutex_unlock( &p_playlist->object_lock );
553 vlc_object_release( p_playlist );
556 /*****************************************************************************
558 *****************************************************************************/
559 void Playlist::DeleteItem( int item )
561 playlist_t *p_playlist =
562 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
564 if( p_playlist == NULL )
569 playlist_Delete( p_playlist, item );
570 listview->DeleteItem( item );
572 vlc_object_release( p_playlist );
575 void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) )
580 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
586 } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" },
587 { _("PLS file"), "*.pls", "export-pls" }};
588 wxString filter = wxT("");
589 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
591 filter.Append( wxU(formats[i].psz_desc) );
592 filter.Append( wxT("|") );
593 filter.Append( wxU(formats[i].psz_filter) );
594 filter.Append( wxT("|") );
596 wxFileDialog dialog( this, wxU(_("Save playlist")),
597 wxT(""), wxT(""), filter, wxSAVE );
599 if( dialog.ShowModal() == wxID_OK )
602 playlist_t * p_playlist =
603 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
608 if( dialog.GetFilename().mb_str() )
610 playlist_Export( p_playlist, dialog.GetFilename().mb_str(),
611 formats[dialog.GetFilterIndex()].psz_module );
615 vlc_object_release( p_playlist );
620 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
622 playlist_t *p_playlist =
623 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
625 if( p_playlist == NULL )
630 wxFileDialog dialog( this, wxU(_("Open playlist")),
631 wxT(""), wxT(""), wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
633 if( dialog.ShowModal() == wxID_OK )
635 playlist_Import( p_playlist, dialog.GetPath().mb_str() );
638 vlc_object_release( p_playlist );
641 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
643 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
650 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
652 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
659 /********************************************************************
661 ********************************************************************/
662 void Playlist::OnUp( wxCommandEvent& event)
664 playlist_t *p_playlist =
665 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
667 if( p_playlist == NULL )
672 /* We use the first selected item, so find it */
673 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
674 wxLIST_STATE_SELECTED);
675 if( i_item > 0 && i_item < p_playlist->i_size )
677 playlist_Move( p_playlist , i_item, i_item - 1);
680 listview->Focus( i_item - 1 );
687 vlc_object_release( p_playlist );
691 void Playlist::OnDown( wxCommandEvent& event)
693 playlist_t *p_playlist =
694 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
696 if( p_playlist == NULL )
701 /* We use the first selected item, so find it */
702 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
703 wxLIST_STATE_SELECTED );
704 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
706 playlist_Move( p_playlist , i_item, i_item + 2 );
707 listview->Focus( i_item + 1 );
709 vlc_object_release( p_playlist );
713 /********************************************************************
715 ********************************************************************/
716 void Playlist::OnSort( wxCommandEvent& event )
718 playlist_t *p_playlist =
719 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
721 if( p_playlist == NULL )
725 switch( event.GetId() )
727 case SortTitle_Event:
728 playlist_SortTitle( p_playlist , ORDER_NORMAL );
730 case RSortTitle_Event:
731 playlist_SortTitle( p_playlist , ORDER_REVERSE );
733 case SortAuthor_Event:
734 playlist_SortAuthor(p_playlist , ORDER_NORMAL );
736 case RSortAuthor_Event:
737 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
739 case SortGroup_Event:
740 playlist_SortGroup( p_playlist , ORDER_NORMAL );
742 case RSortGroup_Event:
743 playlist_SortGroup( p_playlist , ORDER_REVERSE );
745 case Randomize_Event:
746 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
749 vlc_object_release( p_playlist );
756 void Playlist::OnColSelect( wxListEvent& event )
758 playlist_t *p_playlist =
759 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
761 if( p_playlist == NULL )
765 switch( event.GetColumn() )
768 if( i_title_sorted != 1 )
770 playlist_SortTitle( p_playlist, ORDER_NORMAL );
775 playlist_SortTitle( p_playlist, ORDER_REVERSE );
780 if( i_author_sorted != 1 )
782 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
787 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
788 i_author_sorted = -1;
792 if( i_group_sorted != 1 )
794 playlist_SortGroup( p_playlist, ORDER_NORMAL );
799 playlist_SortGroup( p_playlist, ORDER_REVERSE );
806 vlc_object_release( p_playlist );
813 /**********************************************************************
815 **********************************************************************/
816 void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
818 search_button->SetDefault();
821 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
823 wxString search_string= search_text->GetValue();
829 for( i_current = 0 ; i_current <= listview->GetItemCount() ; i_current++ )
831 if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED )
832 == wxLIST_STATE_SELECTED )
839 for ( i_current = i_first + 1; i_current <= listview->GetItemCount() ;
843 listitem.SetId( i_current );
844 listview->GetItem( listitem );
845 if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
851 for( long item = 0; item < listview->GetItemCount(); item++ )
853 listview->Select( item, FALSE );
857 listitem.SetId(i_item);
858 listitem.m_state = wxLIST_STATE_SELECTED;
859 listview->Select( i_item, TRUE );
860 listview->Focus( i_item );
864 /**********************************************************************
865 * Selection functions
866 **********************************************************************/
867 void Playlist::OnInvertSelection( wxCommandEvent& WXUNUSED(event) )
869 for( long item = 0; item < listview->GetItemCount(); item++ )
871 listview->Select( item, ! listview->IsSelected( item ) );
875 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
877 /* Delete from the end to the beginning, to avoid a shift of indices */
878 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
880 if( listview->IsSelected( item ) )
889 void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) )
891 playlist_t *p_playlist =
892 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
894 if( p_playlist == NULL )
899 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
901 if( listview->IsSelected( item ) )
903 playlist_Enable( p_playlist, item );
907 vlc_object_release( p_playlist);
910 void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) )
912 playlist_t *p_playlist =
913 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
915 if( p_playlist == NULL )
920 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
922 if( listview->IsSelected( item ) )
924 playlist_Disable( p_playlist, item );
928 vlc_object_release( p_playlist);
931 void Playlist::OnSelectAll( wxCommandEvent& WXUNUSED(event) )
933 for( long item = 0; item < listview->GetItemCount(); item++ )
935 listview->Select( item, TRUE );
939 /**********************************************************************
940 * Playlist mode functions
941 **********************************************************************/
942 void Playlist::OnRandom( wxCommandEvent& event )
945 val.b_bool = event.IsChecked();
946 playlist_t *p_playlist =
947 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
949 if( p_playlist == NULL )
953 var_Set( p_playlist , "random", val);
954 vlc_object_release( p_playlist );
956 void Playlist::OnLoop ( wxCommandEvent& event )
959 val.b_bool = event.IsChecked();
960 playlist_t *p_playlist =
961 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
963 if( p_playlist == NULL )
967 var_Set( p_playlist , "loop", val);
968 vlc_object_release( p_playlist );
971 void Playlist::OnRepeat ( wxCommandEvent& event )
974 val.b_bool = event.IsChecked();
975 playlist_t *p_playlist =
976 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
978 if( p_playlist == NULL )
982 var_Set( p_playlist , "repeat", val);
983 vlc_object_release( p_playlist );
988 void Playlist::OnActivateItem( wxListEvent& event )
990 playlist_t *p_playlist =
991 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
993 if( p_playlist == NULL )
997 playlist_Goto( p_playlist, event.GetIndex() );
999 vlc_object_release( p_playlist );
1002 void Playlist::OnKeyDown( wxListEvent& event )
1004 long keycode = event.GetKeyCode();
1005 /* Delete selected items */
1006 if( keycode == WXK_BACK || keycode == WXK_DELETE )
1008 /* We send a dummy event */
1009 OnDeleteSelection( event );
1013 void Playlist::ShowInfos( int i_item )
1015 playlist_t *p_playlist =
1016 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1018 if( p_playlist == NULL )
1022 if( iteminfo_dialog == NULL )
1024 if( i_item >= 0 && i_item < p_playlist->i_size )
1026 iteminfo_dialog = new ItemInfoDialog(
1027 p_intf, p_playlist->pp_items[i_item], this );
1028 if( iteminfo_dialog->ShowModal() == wxID_OK )
1029 UpdateItem( i_item );
1030 delete iteminfo_dialog;
1031 iteminfo_dialog = NULL;
1034 vlc_object_release( p_playlist );
1037 void Playlist::OnInfos( wxCommandEvent& WXUNUSED(event) )
1039 /* We use the first selected item, so find it */
1040 long i_item = listview->GetNextItem( -1 , wxLIST_NEXT_ALL,
1041 wxLIST_STATE_SELECTED );
1042 ShowInfos( i_item );
1045 void Playlist::OnEnDis( wxCommandEvent& event )
1047 playlist_t *p_playlist =
1048 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1050 if( p_playlist == NULL )
1055 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
1056 wxLIST_STATE_SELECTED );
1058 if( i_item >= 0 && i_item < p_playlist->i_size )
1060 switch( event.GetId() )
1062 case EnableGroup_Event:
1063 playlist_EnableGroup( p_playlist ,
1064 p_playlist->pp_items[i_item]->i_group );
1066 case DisableGroup_Event:
1067 playlist_DisableGroup( p_playlist ,
1068 p_playlist->pp_items[i_item]->i_group );
1074 vlc_object_release( p_playlist );
1077 /*****************************************************************************
1078 * Popup management functions
1079 *****************************************************************************/
1080 void Playlist::OnPopup( wxListEvent& event )
1082 i_popup_item = event.GetIndex();
1083 Playlist::PopupMenu( popup_menu , ScreenToClient( wxGetMousePosition() ) );
1087 void Playlist::OnPopupPlay( wxMenuEvent& event )
1089 playlist_t *p_playlist =
1090 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1092 if( p_playlist == NULL )
1096 if( i_popup_item != -1 )
1098 playlist_Goto( p_playlist, i_popup_item );
1100 vlc_object_release( p_playlist );
1103 void Playlist::OnPopupDel( wxMenuEvent& event )
1105 DeleteItem( i_popup_item );
1108 void Playlist::OnPopupEna( wxMenuEvent& event )
1110 playlist_t *p_playlist =
1111 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1113 if( p_playlist == NULL )
1118 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1119 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1121 playlist_Disable( p_playlist, i_popup_item );
1125 playlist_Enable( p_playlist, i_popup_item );
1127 vlc_object_release( p_playlist);
1128 UpdateItem( i_popup_item );
1131 void Playlist::OnPopupInfo( wxMenuEvent& event )
1133 ShowInfos( i_popup_item );
1136 /*****************************************************************************
1137 * PlaylistChanged: callback triggered by the intf-change playlist variable
1138 * We don't rebuild the playlist directly here because we don't want the
1139 * caller to block for a too long time.
1140 *****************************************************************************/
1141 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1142 vlc_value_t old_val, vlc_value_t new_val, void *param )
1144 Playlist *p_playlist_dialog = (Playlist *)param;
1145 vlc_mutex_lock( &p_playlist_dialog->lock );
1146 p_playlist_dialog->b_need_update = VLC_TRUE;
1147 vlc_mutex_unlock( &p_playlist_dialog->lock );
1151 /*****************************************************************************
1152 * Next: callback triggered by the playlist-current playlist variable
1153 *****************************************************************************/
1154 int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1155 vlc_value_t old_val, vlc_value_t new_val, void *param )
1157 Playlist *p_playlist_dialog = (Playlist *)param;
1158 p_playlist_dialog->UpdateItem( old_val.i_int );
1159 p_playlist_dialog->UpdateItem( new_val.i_int );
1164 /*****************************************************************************
1165 * ItemChanged: callback triggered by the item-change playlist variable
1166 *****************************************************************************/
1167 int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1168 vlc_value_t old_val, vlc_value_t new_val, void *param )
1170 Playlist *p_playlist_dialog = (Playlist *)param;
1171 p_playlist_dialog->UpdateItem( new_val.i_int );
1176 /***************************************************************************
1178 ***************************************************************************/
1179 NewGroup::NewGroup( intf_thread_t *_p_intf, wxWindow *_p_parent ):
1180 wxDialog( _p_parent, -1, wxU(_("New Group")), wxDefaultPosition,
1181 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
1183 /* Initializations */
1186 SetIcon( *p_intf->p_sys->p_icon );
1188 /* Create a panel to put everything in*/
1189 wxPanel *panel = new wxPanel( this, -1 );
1190 panel->SetAutoLayout( TRUE );
1192 wxStaticText *group_label =
1193 new wxStaticText( panel , -1,
1194 wxU(_("Enter a name for the new group:")));
1196 groupname = new wxTextCtrl(panel, -1, wxU(""),wxDefaultPosition,
1197 wxSize(100,27),wxTE_PROCESS_ENTER);
1199 wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );
1200 ok_button->SetDefault();
1201 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
1204 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1206 button_sizer->Add( ok_button, 0, wxALL, 5 );
1207 button_sizer->Add( cancel_button, 0, wxALL, 5 );
1208 button_sizer->Layout();
1210 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
1211 panel_sizer->Add( group_label, 0, wxEXPAND | wxALL, 5 );
1212 panel_sizer->Add( groupname, 0, wxEXPAND | wxALL, 5 );
1213 panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );
1214 panel_sizer->Layout();
1216 panel->SetSizerAndFit( panel_sizer );
1218 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1219 main_sizer->Add( panel, 1, wxEXPAND, 0 );
1220 main_sizer->Layout();
1221 SetSizerAndFit( main_sizer );
1224 NewGroup::~NewGroup()
1228 void NewGroup::OnOk( wxCommandEvent& event )
1230 psz_name = strdup( groupname->GetLineText(0).mb_str() );
1232 playlist_t * p_playlist =
1233 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1238 if( !playlist_CreateGroup( p_playlist, psz_name ) )
1242 vlc_object_release( p_playlist );
1245 EndModal( wxID_OK );
1248 void NewGroup::OnCancel( wxCommandEvent& WXUNUSED(event) )
1250 EndModal( wxID_CANCEL );