1 /*****************************************************************************
2 * playlist.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: playlist.cpp,v 1.27 2003/11/26 10:45:21 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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
35 #include "wxwindows.h"
36 #include <wx/listctrl.h>
38 /* Callback prototype */
39 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
40 vlc_value_t old_val, vlc_value_t new_val, void *param );
42 /*****************************************************************************
44 *****************************************************************************/
46 /* IDs for the controls and the menu commands */
64 EnableSelection_Event,
65 DisableSelection_Event,
67 InvertSelection_Event,
68 DeleteSelection_Event,
88 BEGIN_EVENT_TABLE(Playlist, wxFrame)
90 EVT_MENU(AddFile_Event, Playlist::OnAddFile)
91 EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
92 EVT_MENU(Close_Event, Playlist::OnClose)
93 EVT_MENU(Open_Event, Playlist::OnOpen)
94 EVT_MENU(Save_Event, Playlist::OnSave)
96 EVT_MENU(SortTitle_Event, Playlist::OnSort)
97 EVT_MENU(RSortTitle_Event, Playlist::OnSort)
98 EVT_MENU(SortAuthor_Event, Playlist::OnSort)
99 EVT_MENU(RSortAuthor_Event, Playlist::OnSort)
100 EVT_MENU(SortGroup_Event, Playlist::OnSort)
101 EVT_MENU(RSortGroup_Event, Playlist::OnSort)
103 EVT_MENU(Randomize_Event, Playlist::OnSort)
105 EVT_MENU(EnableSelection_Event, Playlist::OnEnableSelection)
106 EVT_MENU(DisableSelection_Event, Playlist::OnDisableSelection)
107 EVT_MENU(InvertSelection_Event, Playlist::OnInvertSelection)
108 EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
109 EVT_MENU(SelectAll_Event, Playlist::OnSelectAll)
110 EVT_MENU(Infos_Event, Playlist::OnInfos)
111 EVT_CHECKBOX(Random_Event, Playlist::OnRandom)
112 EVT_CHECKBOX(Repeat_Event, Playlist::OnRepeat)
113 EVT_CHECKBOX(Loop_Event, Playlist::OnLoop)
115 EVT_MENU(EnableGroup_Event, Playlist::OnEnDis)
116 EVT_MENU(DisableGroup_Event, Playlist::OnEnDis)
118 /* Listview events */
119 EVT_LIST_ITEM_ACTIVATED(ListView_Event, Playlist::OnActivateItem)
120 EVT_LIST_COL_CLICK(ListView_Event, Playlist::OnColSelect)
121 EVT_LIST_KEY_DOWN(ListView_Event, Playlist::OnKeyDown)
124 EVT_BUTTON( Search_Event, Playlist::OnSearch)
125 EVT_BUTTON( Save_Event, Playlist::OnSave)
126 EVT_BUTTON( Infos_Event, Playlist::OnInfos)
128 EVT_BUTTON( Up_Event, Playlist::OnUp)
129 EVT_BUTTON( Down_Event, Playlist::OnDown)
131 EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange)
133 /* Special events : we don't want to destroy the window when the user
135 EVT_CLOSE(Playlist::OnClose)
139 /* Event Table for the Newgroup class */
140 BEGIN_EVENT_TABLE(NewGroup, wxDialog)
141 EVT_BUTTON( wxID_OK, NewGroup::OnOk)
142 EVT_BUTTON( wxID_CANCEL, NewGroup::OnCancel)
145 /*****************************************************************************
147 *****************************************************************************/
148 Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
149 wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
150 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
152 /* Initializations */
153 iteminfo_dialog = NULL;
156 i_update_counter = 0;
157 i_sort_mode = MODE_NONE;
158 b_need_update = VLC_FALSE;
159 vlc_mutex_init( p_intf, &lock );
160 SetIcon( *p_intf->p_sys->p_icon );
167 var_Create( p_intf, "random", VLC_VAR_BOOL );
168 var_Change( p_intf, "random", VLC_VAR_INHERITVALUE, & val, NULL );
169 var_Create( p_intf, "loop", VLC_VAR_BOOL );
170 var_Create( p_intf, "loop", VLC_VAR_BOOL );
171 var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
172 var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
174 /* Create our "Manage" menu */
175 wxMenu *manage_menu = new wxMenu;
176 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add...")) );
177 manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
178 manage_menu->AppendSeparator();
179 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
180 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
181 manage_menu->AppendSeparator();
182 manage_menu->Append( Close_Event, wxU(_("&Close")) );
184 /* Create our "Sort" menu */
185 wxMenu *sort_menu = new wxMenu;
186 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
187 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
188 sort_menu->AppendSeparator();
189 sort_menu->Append( SortAuthor_Event, wxU(_("Sort by &author")) );
190 sort_menu->Append( RSortAuthor_Event, wxU(_("&Reverse sort by author")) );
191 sort_menu->AppendSeparator();
192 sort_menu->Append( SortGroup_Event, wxU(_("Sort by &group")) );
193 sort_menu->Append( RSortGroup_Event, wxU(_("&Reverse sort by group")) );
194 sort_menu->AppendSeparator();
195 sort_menu->Append( Randomize_Event, wxU(_("&Randomize Playlist")) );
197 /* Create our "Selection" menu */
198 wxMenu *selection_menu = new wxMenu;
199 selection_menu->Append( EnableSelection_Event, wxU(_("&Enable")) );
200 selection_menu->Append( DisableSelection_Event, wxU(_("&Disable")) );
201 selection_menu->AppendSeparator();
202 selection_menu->Append( InvertSelection_Event, wxU(_("&Invert")) );
203 selection_menu->Append( DeleteSelection_Event, wxU(_("&Delete")) );
204 selection_menu->Append( SelectAll_Event, wxU(_("&Select All")) );
206 /* Create our "Group" menu */
207 wxMenu *group_menu = new wxMenu;
208 group_menu->Append( EnableGroup_Event, wxU(_("&Enable all group items")) );
209 group_menu->Append( DisableGroup_Event,
210 wxU(_("&Disable all group items")) );
212 /* Append the freshly created menus to the menu bar */
213 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
214 menubar->Append( manage_menu, wxU(_("&Manage")) );
215 menubar->Append( sort_menu, wxU(_("S&ort")) );
216 menubar->Append( selection_menu, wxU(_("&Selection")) );
217 menubar->Append( group_menu, wxU(_("&Groups")) );
219 /* Attach the menu bar to the frame */
220 SetMenuBar( menubar );
223 /* Create a panel to put everything in */
224 wxPanel *playlist_panel = new wxPanel( this, -1 );
225 playlist_panel->SetAutoLayout( TRUE );
227 /* Create the Random checkbox */
228 wxCheckBox *random_checkbox =
229 new wxCheckBox( playlist_panel, Random_Event, wxU(_("Random")) );
230 var_Get( p_intf, "random", &val );
231 vlc_bool_t b_random = val.b_bool;
232 random_checkbox->SetValue( b_random == VLC_FALSE ? 0 : 1 );
234 /* Create the Loop Checkbox */
235 wxCheckBox *loop_checkbox =
236 new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Loop")) );
237 var_Get( p_intf, "loop", &val );
238 int b_loop = val.b_bool ;
239 loop_checkbox->SetValue( b_loop );
241 /* Create the Repeat one checkbox */
242 wxCheckBox *repeat_checkbox =
243 new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat one")) );
244 var_Get( p_intf, "repeat", &val );
245 int b_repeat = val.b_bool ;
246 repeat_checkbox->SetValue( b_repeat );
248 /* Create the Search Textbox */
250 new wxTextCtrl( playlist_panel, SearchText_Event, wxT(""),
251 wxDefaultPosition, wxSize(140, -1),
254 /* Create the search button */
256 new wxButton( playlist_panel, Search_Event, wxU(_("Search")) );
259 /* Create the listview */
260 /* FIXME: the given size is arbitrary, and prevents us from resizing
261 * the window to smaller dimensions. But the sizers don't seem to adjust
262 * themselves to the size of a listview, and with a wxDefaultSize the
263 * playlist window is ridiculously small */
264 listview = new wxListView( playlist_panel, ListView_Event,
265 wxDefaultPosition, wxSize( 500, 300 ),
266 wxLC_REPORT | wxSUNKEN_BORDER );
267 listview->InsertColumn( 0, wxU(_("Name")) );
269 listview->InsertColumn( 1, wxU(_("Duration")) );
271 listview->InsertColumn( 1, wxU(_("Author")) );
272 listview->InsertColumn( 2, wxU(_("Group")) );
273 listview->SetColumnWidth( 0, 270 );
274 listview->SetColumnWidth( 1, 150 );
275 listview->SetColumnWidth( 2, 80 );
277 /* Create the Up-Down buttons */
278 wxButton *up_button =
279 new wxButton( playlist_panel, Up_Event, wxU(_("Up") ) );
281 wxButton *down_button =
282 new wxButton( playlist_panel, Down_Event, wxU(_("Down") ) );
284 /* Create the iteminfo button */
285 wxButton *iteminfo_button =
286 new wxButton( playlist_panel, Infos_Event, wxU(_("Item Infos") ) );
288 /* Place everything in sizers */
289 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
290 button_sizer->Add( iteminfo_button, 0, wxALIGN_CENTER|wxLEFT , 5);
291 button_sizer->Layout();
293 wxBoxSizer *updown_sizer = new wxBoxSizer( wxHORIZONTAL );
294 updown_sizer->Add( up_button, 0, wxALIGN_LEFT|wxRIGHT, 3);
295 updown_sizer->Add( down_button, 0, wxALIGN_LEFT|wxLEFT, 3);
296 updown_sizer->Layout();
298 wxBoxSizer *checkbox_sizer = new wxBoxSizer( wxHORIZONTAL );
299 checkbox_sizer->Add( random_checkbox, 0,
300 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
301 checkbox_sizer->Add( loop_checkbox, 0,
302 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
303 checkbox_sizer->Add( repeat_checkbox, 0,
304 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
305 checkbox_sizer->Layout();
307 wxBoxSizer *search_sizer = new wxBoxSizer( wxHORIZONTAL );
308 search_sizer->Add( search_text, 0, wxRIGHT|wxALIGN_CENTER, 3);
309 search_sizer->Add( search_button, 0, wxLEFT|wxALIGN_CENTER, 3);
310 search_sizer->Layout();
312 /* The top and bottom sizers */
313 wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
314 top_sizer->Add( checkbox_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_LEFT, 4 );
315 top_sizer->Add( search_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 4 );
318 wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
319 bottom_sizer->Add( updown_sizer, 0, wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4);
320 bottom_sizer->Add( button_sizer , 0, wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
321 bottom_sizer->Layout();
323 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
325 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
326 panel_sizer->Add( top_sizer, 0, wxEXPAND | wxALL, 5 );
327 panel_sizer->Add( listview, 1, wxEXPAND | wxALL, 5 );
328 panel_sizer->Add( bottom_sizer, 0 , wxEXPAND | wxALL, 5);
329 panel_sizer->Layout();
331 playlist_panel->SetSizerAndFit( panel_sizer );
332 main_sizer->Add( playlist_panel, 1, wxGROW, 0 );
333 main_sizer->Layout();
334 SetSizerAndFit( main_sizer );
336 #if !defined(__WXX11__)
337 /* Associate drop targets with the playlist */
338 SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
341 playlist_t *p_playlist =
342 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
344 if( p_playlist == NULL )
349 /* We want to be noticed of playlist changes */
350 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
351 vlc_object_release( p_playlist );
353 /* Update the playlist */
357 Playlist::~Playlist()
359 playlist_t *p_playlist =
360 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
362 if( p_playlist == NULL )
367 delete iteminfo_dialog;
369 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
370 vlc_object_release( p_playlist );
373 /**********************************************************************
374 * Rebuild the playlist
375 **********************************************************************/
376 void Playlist::Rebuild()
378 playlist_t *p_playlist =
379 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
381 if( p_playlist == NULL )
386 int i_focused = listview->GetFocusedItem();
388 /* Clear the list... */
389 listview->DeleteAllItems();
391 /* ...and rebuild it */
392 vlc_mutex_lock( &p_playlist->object_lock );
393 for( int i = 0; i < p_playlist->i_size; i++ )
395 wxString filename = wxU(p_playlist->pp_items[i]->psz_name);
396 listview->InsertItem( i, filename );
397 listview->SetItem( i, 1, wxU(p_playlist->pp_items[i]->psz_author));
398 listview->SetItem( i, 2,
399 wxU(playlist_FindGroup(p_playlist,p_playlist->
400 pp_items[i]->i_group)));
401 if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
404 listitem.m_itemId = i;
405 listitem.SetTextColour( *wxLIGHT_GREY);
406 listview->SetItem(listitem);
408 /* FIXME: we should try to find the actual duration... */
409 /* While we don't use it, hide it, it's ugly */
411 listview->SetItem( i, 1, wxU(_("no info")) );
414 vlc_mutex_unlock( &p_playlist->object_lock );
416 /* Change the colour for the currenty played stream */
418 listitem.m_itemId = p_playlist->i_index;
419 listitem.SetTextColour( *wxRED );
420 listview->SetItem( listitem );
424 listview->Focus( i_focused );
425 listview->Select( i_focused );
429 listview->Focus( p_playlist->i_index );
432 vlc_object_release( p_playlist );
435 void Playlist::ShowPlaylist( bool show )
437 if( show ) Rebuild();
441 void Playlist::UpdatePlaylist()
443 vlc_bool_t b_need_update = VLC_FALSE;
446 /* If the playlist isn't show there's no need to update it */
447 if( !IsShown() ) return;
449 vlc_mutex_lock( &lock );
450 if( this->b_need_update )
452 b_need_update =VLC_TRUE;
453 this->b_need_update = VLC_FALSE;
455 vlc_mutex_unlock( &lock );
462 /* Updating the playing status every 0.5s is enough */
463 if( i_update_counter % 5 ) return;
465 playlist_t *p_playlist =
466 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
468 if( p_playlist == NULL )
473 /* Update the colour of items */
475 vlc_mutex_lock( &p_playlist->object_lock );
476 if( p_intf->p_sys->i_playing != p_playlist->i_index )
479 listitem.m_itemId = p_playlist->i_index;
480 listitem.SetTextColour( *wxRED );
481 listview->SetItem( listitem );
483 if( p_intf->p_sys->i_playing != -1 )
485 listitem.m_itemId = p_intf->p_sys->i_playing;
486 listitem.SetTextColour( *wxBLACK );
487 listview->SetItem( listitem );
489 p_intf->p_sys->i_playing = p_playlist->i_index;
491 vlc_mutex_unlock( &p_playlist->object_lock );
492 vlc_object_release( p_playlist );
495 /*****************************************************************************
497 *****************************************************************************/
498 void Playlist::DeleteItem( int item )
500 playlist_t *p_playlist =
501 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
503 if( p_playlist == NULL )
508 playlist_Delete( p_playlist, item );
509 listview->DeleteItem( item );
511 vlc_object_release( p_playlist );
514 void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) )
519 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
521 playlist_t *p_playlist =
522 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
524 if( p_playlist == NULL )
529 wxFileDialog dialog( this, wxU(_("Save playlist")),
530 wxT(""), wxT(""), wxT("*"), wxSAVE );
532 if( dialog.ShowModal() == wxID_OK )
534 playlist_SaveFile( p_playlist, dialog.GetPath().mb_str() );
537 vlc_object_release( p_playlist );
540 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
542 playlist_t *p_playlist =
543 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
545 if( p_playlist == NULL )
550 wxFileDialog dialog( this, wxU(_("Open playlist")),
551 wxT(""), wxT(""), wxT("*"), wxOPEN );
553 if( dialog.ShowModal() == wxID_OK )
555 playlist_LoadFile( p_playlist, dialog.GetPath().mb_str() );
558 vlc_object_release( p_playlist );
561 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
563 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
570 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
572 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
579 /********************************************************************
581 ********************************************************************/
582 void Playlist::OnUp( wxCommandEvent& event)
584 playlist_t *p_playlist =
585 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
587 if( p_playlist == NULL )
592 /* We use the first selected item, so find it */
594 i_item = listview->GetNextItem(i_item,
596 wxLIST_STATE_SELECTED);
597 if( i_item > 0 && i_item < p_playlist->i_size )
599 playlist_Move( p_playlist , i_item, i_item - 1);
602 listview->Focus( i_item - 1 );
609 vlc_object_release( p_playlist );
613 void Playlist::OnDown( wxCommandEvent& event)
615 playlist_t *p_playlist =
616 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
618 if( p_playlist == NULL )
623 /* We use the first selected item, so find it */
625 i_item = listview->GetNextItem(i_item,
627 wxLIST_STATE_SELECTED);
628 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
630 playlist_Move( p_playlist , i_item, i_item + 2 );
631 listview->Focus( i_item + 1 );
633 vlc_object_release( p_playlist );
637 /********************************************************************
639 ********************************************************************/
640 void Playlist::OnSort( wxCommandEvent& event )
642 playlist_t *p_playlist =
643 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
645 if( p_playlist == NULL )
649 switch( event.GetId() )
651 case SortTitle_Event:
652 playlist_SortTitle( p_playlist , 0 );
654 case RSortTitle_Event:
655 playlist_SortTitle( p_playlist , 1 );
657 case SortAuthor_Event:
658 playlist_SortAuthor(p_playlist , 0 );
660 case RSortAuthor_Event:
661 playlist_SortAuthor( p_playlist , 1 );
663 case SortGroup_Event:
664 playlist_SortGroup( p_playlist , 0 );
666 case RSortGroup_Event:
667 playlist_SortGroup( p_playlist , 1 );
669 case Randomize_Event:
670 playlist_Sort( p_playlist , SORT_RANDOM, SORT_NORMAL );
673 vlc_object_release( p_playlist );
680 void Playlist::OnColSelect( wxListEvent& event )
682 playlist_t *p_playlist =
683 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
685 if( p_playlist == NULL )
689 switch( event.GetColumn() )
692 if( i_title_sorted != 1 )
694 playlist_SortTitle( p_playlist, 0 );
699 playlist_SortTitle( p_playlist, 1 );
704 if( i_author_sorted != 1 )
706 playlist_SortAuthor( p_playlist, 0 );
711 playlist_SortAuthor( p_playlist, 1 );
712 i_author_sorted = -1;
716 if( i_group_sorted != 1 )
718 playlist_SortGroup( p_playlist, 0 );
723 playlist_SortGroup( p_playlist, 1 );
730 vlc_object_release( p_playlist );
737 /**********************************************************************
739 **********************************************************************/
740 void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
742 search_button->SetDefault();
745 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
747 wxString search_string= search_text->GetValue();
753 for( i_current = 0 ; i_current <= listview->GetItemCount() ; i_current++ )
755 if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED)
756 == wxLIST_STATE_SELECTED )
763 for ( i_current = i_first + 1; i_current <= listview->GetItemCount() ;
767 listitem.SetId( i_current );
768 listview->GetItem( listitem );
769 if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
775 for( long item = 0; item < listview->GetItemCount(); item++ )
777 listview->Select( item, FALSE );
781 listitem.SetId(i_item);
782 listitem.m_state = wxLIST_STATE_SELECTED;
783 listview->Select( i_item, TRUE );
784 listview->Focus( i_item );
788 /**********************************************************************
789 * Selection functions
790 **********************************************************************/
791 void Playlist::OnInvertSelection( wxCommandEvent& WXUNUSED(event) )
793 for( long item = 0; item < listview->GetItemCount(); item++ )
795 listview->Select( item, ! listview->IsSelected( item ) );
799 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
801 /* Delete from the end to the beginning, to avoid a shift of indices */
802 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
804 if( listview->IsSelected( item ) )
813 void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) )
815 playlist_t *p_playlist =
816 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
818 if( p_playlist == NULL )
823 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
825 if( listview->IsSelected( item ) )
827 playlist_Enable( p_playlist, item );
830 vlc_object_release( p_playlist);
834 void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) )
836 playlist_t *p_playlist =
837 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
839 if( p_playlist == NULL )
844 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
846 if( listview->IsSelected( item ) )
848 playlist_Disable( p_playlist, item );
851 vlc_object_release( p_playlist);
855 void Playlist::OnSelectAll( wxCommandEvent& WXUNUSED(event) )
857 for( long item = 0; item < listview->GetItemCount(); item++ )
859 listview->Select( item, TRUE );
863 /**********************************************************************
864 * Playlist mode functions
865 **********************************************************************/
866 void Playlist::OnRandom( wxCommandEvent& event )
869 val.b_bool = event.IsChecked();
870 playlist_t *p_playlist =
871 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
873 if( p_playlist == NULL )
877 var_Set( p_playlist , "random", val);
878 vlc_object_release( p_playlist );
880 void Playlist::OnLoop ( wxCommandEvent& event )
883 val.b_bool = event.IsChecked();
884 playlist_t *p_playlist =
885 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
887 if( p_playlist == NULL )
891 var_Set( p_playlist , "loop", val);
892 vlc_object_release( p_playlist );
895 void Playlist::OnRepeat ( wxCommandEvent& event )
898 val.b_bool = event.IsChecked();
899 playlist_t *p_playlist =
900 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
902 if( p_playlist == NULL )
906 var_Set( p_playlist , "repeat", val);
907 vlc_object_release( p_playlist );
912 void Playlist::OnActivateItem( wxListEvent& event )
914 playlist_t *p_playlist =
915 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
917 if( p_playlist == NULL )
921 playlist_Goto( p_playlist, event.GetIndex() );
923 vlc_object_release( p_playlist );
925 void Playlist::OnKeyDown( wxListEvent& event )
927 long keycode = event.GetKeyCode();
928 /* Delete selected items */
929 if( keycode == WXK_BACK || keycode == WXK_DELETE )
931 /* We send a dummy event */
932 OnDeleteSelection( event );
936 void Playlist::OnInfos( wxCommandEvent& WXUNUSED(event) )
938 playlist_t *p_playlist =
939 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
941 if( p_playlist == NULL )
946 if( iteminfo_dialog == NULL )
948 /* We use the first selected item, so find it */
950 i_item = listview->GetNextItem(i_item,
952 wxLIST_STATE_SELECTED);
953 if( i_item >= 0 && i_item < p_playlist->i_size )
955 iteminfo_dialog = new ItemInfoDialog(
956 p_intf, p_playlist->pp_items[i_item], this );
957 if( iteminfo_dialog->ShowModal() == wxID_OK )
959 delete iteminfo_dialog;
960 iteminfo_dialog = NULL;
963 vlc_object_release( p_playlist );
966 void Playlist::OnEnDis( wxCommandEvent& event )
968 playlist_t *p_playlist =
969 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
971 if( p_playlist == NULL )
977 i_item = listview->GetNextItem(i_item,
979 wxLIST_STATE_SELECTED);
981 if( i_item >= 0 && i_item < p_playlist->i_size )
983 switch( event.GetId() )
985 case EnableGroup_Event:
986 playlist_EnableGroup( p_playlist ,
987 p_playlist->pp_items[i_item]->i_group );
989 case DisableGroup_Event:
990 playlist_DisableGroup( p_playlist ,
991 p_playlist->pp_items[i_item]->i_group );
997 vlc_object_release( p_playlist );
1000 /*****************************************************************************
1001 * PlaylistChanged: callback triggered by the intf-change playlist variable
1002 * We don't rebuild the playlist directly here because we don't want the
1003 * caller to block for a too long time.
1004 *****************************************************************************/
1005 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1006 vlc_value_t old_val, vlc_value_t new_val, void *param )
1008 Playlist *p_playlist_dialog = (Playlist *)param;
1009 vlc_mutex_lock( &p_playlist_dialog->lock );
1010 p_playlist_dialog->b_need_update = VLC_TRUE;
1011 vlc_mutex_unlock( &p_playlist_dialog->lock );
1016 /***************************************************************************
1018 ***************************************************************************/
1019 NewGroup::NewGroup( intf_thread_t *_p_intf, wxWindow *_p_parent ):
1020 wxDialog( _p_parent, -1, wxU(_("New Group")), wxDefaultPosition,
1021 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
1023 /* Initializations */
1026 SetIcon( *p_intf->p_sys->p_icon );
1028 /* Create a panel to put everything in*/
1029 wxPanel *panel = new wxPanel( this, -1 );
1030 panel->SetAutoLayout( TRUE );
1032 wxStaticText *group_label =
1033 new wxStaticText( panel , -1,
1034 wxU(_("Enter the name for the new group")));
1036 groupname = new wxTextCtrl(panel, -1, wxU(""),wxDefaultPosition,
1037 wxSize(80,27),wxTE_PROCESS_ENTER);
1039 wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );
1040 ok_button->SetDefault();
1041 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
1044 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1046 button_sizer->Add( ok_button, 0, wxALL, 5 );
1047 button_sizer->Add( cancel_button, 0, wxALL, 5 );
1048 button_sizer->Layout();
1050 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
1051 panel_sizer->Add( group_label, 0, wxEXPAND | wxALL, 5 );
1052 panel_sizer->Add( groupname, 0, wxEXPAND | wxALL, 5 );
1053 panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );
1054 panel_sizer->Layout();
1056 panel->SetSizerAndFit( panel_sizer );
1058 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1059 main_sizer->Add( panel, 1, wxEXPAND, 0 );
1060 main_sizer->Layout();
1061 SetSizerAndFit( main_sizer );
1064 NewGroup::~NewGroup()
1068 void NewGroup::OnOk( wxCommandEvent& event )
1070 psz_name = strdup( groupname->GetLineText(0).mb_str() );
1072 playlist_t * p_playlist =
1073 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1078 if( !playlist_CreateGroup( p_playlist, psz_name ) )
1084 vlc_object_release( p_playlist );
1085 EndModal( wxID_OK );
1088 void NewGroup::OnCancel( wxCommandEvent& WXUNUSED(event) )
1090 EndModal( wxID_CANCEL );