1 /*****************************************************************************
2 * playlist.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
5 * $Id: playlist.cpp,v 1.38 2004/01/16 00:01:19 gbazin 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 /*****************************************************************************
162 *****************************************************************************/
163 Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
164 wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
165 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
167 /* Initializations */
168 iteminfo_dialog = NULL;
171 i_update_counter = 0;
172 i_sort_mode = MODE_NONE;
173 b_need_update = VLC_FALSE;
174 vlc_mutex_init( p_intf, &lock );
175 SetIcon( *p_intf->p_sys->p_icon );
182 var_Create( p_intf, "random", VLC_VAR_BOOL );
183 var_Change( p_intf, "random", VLC_VAR_INHERITVALUE, & val, NULL );
184 var_Create( p_intf, "loop", VLC_VAR_BOOL );
185 var_Create( p_intf, "loop", VLC_VAR_BOOL );
186 var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
187 var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
189 /* Create our "Manage" menu */
190 wxMenu *manage_menu = new wxMenu;
191 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add...")) );
192 manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
193 manage_menu->AppendSeparator();
194 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
195 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
196 manage_menu->AppendSeparator();
197 manage_menu->Append( Close_Event, wxU(_("&Close")) );
199 /* Create our "Sort" menu */
200 wxMenu *sort_menu = new wxMenu;
201 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
202 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
203 sort_menu->AppendSeparator();
204 sort_menu->Append( SortAuthor_Event, wxU(_("Sort by &author")) );
205 sort_menu->Append( RSortAuthor_Event, wxU(_("&Reverse sort by author")) );
206 sort_menu->AppendSeparator();
207 sort_menu->Append( SortGroup_Event, wxU(_("Sort by &group")) );
208 sort_menu->Append( RSortGroup_Event, wxU(_("&Reverse sort by group")) );
209 sort_menu->AppendSeparator();
210 sort_menu->Append( Randomize_Event, wxU(_("&Randomize Playlist")) );
212 /* Create our "Selection" menu */
213 wxMenu *selection_menu = new wxMenu;
214 selection_menu->Append( EnableSelection_Event, wxU(_("&Enable")) );
215 selection_menu->Append( DisableSelection_Event, wxU(_("&Disable")) );
216 selection_menu->AppendSeparator();
217 selection_menu->Append( InvertSelection_Event, wxU(_("&Invert")) );
218 selection_menu->Append( DeleteSelection_Event, wxU(_("&Delete")) );
219 selection_menu->Append( SelectAll_Event, wxU(_("&Select All")) );
221 /* Create our "Group" menu */
222 wxMenu *group_menu = new wxMenu;
223 group_menu->Append( EnableGroup_Event, wxU(_("&Enable all group items")) );
224 group_menu->Append( DisableGroup_Event,
225 wxU(_("&Disable all group items")) );
227 /* Append the freshly created menus to the menu bar */
228 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
229 menubar->Append( manage_menu, wxU(_("&Manage")) );
230 menubar->Append( sort_menu, wxU(_("S&ort")) );
231 menubar->Append( selection_menu, wxU(_("&Selection")) );
232 menubar->Append( group_menu, wxU(_("&Groups")) );
234 /* Attach the menu bar to the frame */
235 SetMenuBar( menubar );
237 /* Create the popup menu */
238 popup_menu = new wxMenu;
239 popup_menu->Append( PopupPlay_Event, wxU(_("Play item")) );
240 popup_menu->Append( PopupDel_Event, wxU(_("Delete item")) );
241 popup_menu->Append( PopupEna_Event, wxU(_("Toggle enabled")) );
242 popup_menu->Append( PopupInfo_Event, wxU(_("Info on item")) );
244 /* Create a panel to put everything in */
245 wxPanel *playlist_panel = new wxPanel( this, -1 );
246 playlist_panel->SetAutoLayout( TRUE );
248 /* Create the Random checkbox */
249 wxCheckBox *random_checkbox =
250 new wxCheckBox( playlist_panel, Random_Event, wxU(_("Random")) );
251 var_Get( p_intf, "random", &val );
252 vlc_bool_t b_random = val.b_bool;
253 random_checkbox->SetValue( b_random == VLC_FALSE ? 0 : 1 );
255 /* Create the Loop Checkbox */
256 wxCheckBox *loop_checkbox =
257 new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Loop")) );
258 var_Get( p_intf, "loop", &val );
259 int b_loop = val.b_bool ;
260 loop_checkbox->SetValue( b_loop );
262 /* Create the Repeat one checkbox */
263 wxCheckBox *repeat_checkbox =
264 new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat one")) );
265 var_Get( p_intf, "repeat", &val );
266 int b_repeat = val.b_bool ;
267 repeat_checkbox->SetValue( b_repeat );
269 /* Create the Search Textbox */
271 new wxTextCtrl( playlist_panel, SearchText_Event, wxT(""),
272 wxDefaultPosition, wxSize(140, -1),
275 /* Create the search button */
277 new wxButton( playlist_panel, Search_Event, wxU(_("Search")) );
280 /* Create the listview */
281 /* FIXME: the given size is arbitrary, and prevents us from resizing
282 * the window to smaller dimensions. But the sizers don't seem to adjust
283 * themselves to the size of a listview, and with a wxDefaultSize the
284 * playlist window is ridiculously small */
285 listview = new wxListView( playlist_panel, ListView_Event,
286 wxDefaultPosition, wxSize( 500, 300 ),
287 wxLC_REPORT | wxSUNKEN_BORDER );
288 listview->InsertColumn( 0, wxU(_("Name")) );
289 listview->InsertColumn( 1, wxU(_("Author")) );
290 listview->InsertColumn( 2, wxU(_("Group")) );
291 listview->InsertColumn( 3, wxU(_("Duration")) );
292 listview->SetColumnWidth( 0, 270 );
293 listview->SetColumnWidth( 1, 150 );
294 listview->SetColumnWidth( 2, 80 );
296 /* Create the Up-Down buttons */
297 wxButton *up_button =
298 new wxButton( playlist_panel, Up_Event, wxU(_("Up") ) );
300 wxButton *down_button =
301 new wxButton( playlist_panel, Down_Event, wxU(_("Down") ) );
303 /* Create the iteminfo button */
304 wxButton *iteminfo_button =
305 new wxButton( playlist_panel, Infos_Event, wxU(_("Item info") ) );
307 /* Place everything in sizers */
308 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
309 button_sizer->Add( iteminfo_button, 0, wxALIGN_CENTER|wxLEFT , 5);
310 button_sizer->Layout();
312 wxBoxSizer *updown_sizer = new wxBoxSizer( wxHORIZONTAL );
313 updown_sizer->Add( up_button, 0, wxALIGN_LEFT|wxRIGHT, 3);
314 updown_sizer->Add( down_button, 0, wxALIGN_LEFT|wxLEFT, 3);
315 updown_sizer->Layout();
317 wxBoxSizer *checkbox_sizer = new wxBoxSizer( wxHORIZONTAL );
318 checkbox_sizer->Add( random_checkbox, 0,
319 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
320 checkbox_sizer->Add( loop_checkbox, 0,
321 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
322 checkbox_sizer->Add( repeat_checkbox, 0,
323 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
324 checkbox_sizer->Layout();
326 wxBoxSizer *search_sizer = new wxBoxSizer( wxHORIZONTAL );
327 search_sizer->Add( search_text, 0, wxRIGHT|wxALIGN_CENTER, 3);
328 search_sizer->Add( search_button, 0, wxLEFT|wxALIGN_CENTER, 3);
329 search_sizer->Layout();
331 /* The top and bottom sizers */
332 wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
333 top_sizer->Add( checkbox_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_LEFT, 4 );
334 top_sizer->Add( search_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 4 );
337 wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
338 bottom_sizer->Add( updown_sizer, 0, wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4);
339 bottom_sizer->Add( button_sizer , 0, wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
340 bottom_sizer->Layout();
342 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
344 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
345 panel_sizer->Add( top_sizer, 0, wxEXPAND | wxALL, 5 );
346 panel_sizer->Add( listview, 1, wxEXPAND | wxALL, 5 );
347 panel_sizer->Add( bottom_sizer, 0 , wxEXPAND | wxALL, 5);
348 panel_sizer->Layout();
350 playlist_panel->SetSizerAndFit( panel_sizer );
351 main_sizer->Add( playlist_panel, 1, wxGROW, 0 );
352 main_sizer->Layout();
353 SetSizerAndFit( main_sizer );
355 #if !defined(__WXX11__)
356 /* Associate drop targets with the playlist */
357 SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
360 playlist_t *p_playlist =
361 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
363 if( p_playlist == NULL )
368 /* We want to be noticed of playlist changes */
370 /* Some global changes happened -> Rebuild all */
371 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
373 /* We went to the next item */
374 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
376 /* One item has been updated */
377 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
380 vlc_object_release( p_playlist );
382 /* Update the playlist */
386 Playlist::~Playlist()
388 playlist_t *p_playlist =
389 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
391 if( p_playlist == NULL )
396 delete iteminfo_dialog;
398 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
399 vlc_object_release( p_playlist );
402 /**********************************************************************
403 * Update one playlist item
404 **********************************************************************/
405 void Playlist::UpdateItem( int i )
407 playlist_t *p_playlist =
408 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
410 if( p_playlist == NULL )
414 if( i < 0 || i >= p_playlist->i_size || !p_playlist->pp_items[i] )
416 vlc_object_release(p_playlist);
419 listview->SetItem( i, 0, wxL2U(p_playlist->pp_items[i]->psz_name) );
420 listview->SetItem( i, 1, wxU( playlist_GetInfo( p_playlist, i,
421 _("General") , _("Author") ) ) );
422 char *psz_group = playlist_FindGroup(p_playlist,
423 p_playlist->pp_items[i]->i_group);
424 listview->SetItem( i, 2,
425 wxL2U( psz_group ? psz_group : _("Normal") ) );
427 if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
430 listitem.m_itemId = i;
431 listitem.SetTextColour( *wxLIGHT_GREY);
432 listview->SetItem(listitem);
435 char psz_duration[MSTRTIME_MAX_SIZE];
436 mtime_t dur = p_playlist->pp_items[i]->i_duration;
437 if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
438 else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
439 listview->SetItem( i, 3, wxU(psz_duration) );
441 /* Change the colour for the currenty played stream */
443 listitem.m_itemId = i;
444 if( i == p_playlist->i_index )
446 listitem.SetTextColour( *wxRED );
450 listitem.SetTextColour( *wxBLACK );
452 listview->SetItem( listitem );
454 vlc_object_release(p_playlist);
457 /**********************************************************************
458 * Rebuild the playlist
459 **********************************************************************/
460 void Playlist::Rebuild()
462 playlist_t *p_playlist =
463 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
465 if( p_playlist == NULL )
470 int i_focused = listview->GetFocusedItem();
472 /* Clear the list... */
473 listview->DeleteAllItems();
475 /* ...and rebuild it */
476 vlc_mutex_lock( &p_playlist->object_lock );
477 for( int i = 0; i < p_playlist->i_size; i++ )
479 wxString filename = wxL2U(p_playlist->pp_items[i]->psz_name);
480 listview->InsertItem( i, filename );
483 vlc_mutex_unlock( &p_playlist->object_lock );
487 listview->Focus( i_focused );
488 listview->Select( i_focused );
492 listview->Focus( p_playlist->i_index );
495 vlc_object_release( p_playlist );
498 void Playlist::ShowPlaylist( bool show )
500 if( show ) Rebuild();
504 void Playlist::UpdatePlaylist()
506 vlc_bool_t b_need_update = VLC_FALSE;
509 /* If the playlist isn't show there's no need to update it */
510 if( !IsShown() ) return;
512 vlc_mutex_lock( &lock );
513 if( this->b_need_update )
515 b_need_update =VLC_TRUE;
516 this->b_need_update = VLC_FALSE;
518 vlc_mutex_unlock( &lock );
525 /* Updating the playing status every 0.5s is enough */
526 if( i_update_counter % 5 ) return;
528 playlist_t *p_playlist =
529 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
531 if( p_playlist == NULL )
536 /* Update the colour of items */
538 vlc_mutex_lock( &p_playlist->object_lock );
539 if( p_intf->p_sys->i_playing != p_playlist->i_index )
542 listitem.m_itemId = p_playlist->i_index;
543 listitem.SetTextColour( *wxRED );
544 listview->SetItem( listitem );
546 if( p_intf->p_sys->i_playing != -1 )
548 listitem.m_itemId = p_intf->p_sys->i_playing;
549 listitem.SetTextColour( *wxBLACK );
550 listview->SetItem( listitem );
552 p_intf->p_sys->i_playing = p_playlist->i_index;
554 vlc_mutex_unlock( &p_playlist->object_lock );
555 vlc_object_release( p_playlist );
558 /*****************************************************************************
560 *****************************************************************************/
561 void Playlist::DeleteItem( int item )
563 playlist_t *p_playlist =
564 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
566 if( p_playlist == NULL )
571 playlist_Delete( p_playlist, item );
572 listview->DeleteItem( item );
574 vlc_object_release( p_playlist );
577 void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) )
582 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
588 } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" },
589 { _("PLS file"), "*.pls", "export-pls" }};
590 wxString filter = wxT("");
591 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
593 filter.Append( wxU(formats[i].psz_desc) );
594 filter.Append( wxT("|") );
595 filter.Append( wxU(formats[i].psz_filter) );
596 filter.Append( wxT("|") );
598 wxFileDialog dialog( this, wxU(_("Save playlist")),
599 wxT(""), wxT(""), filter, wxSAVE );
601 if( dialog.ShowModal() == wxID_OK )
604 playlist_t * p_playlist =
605 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
610 if( dialog.GetFilename().mb_str() )
612 playlist_Export( p_playlist, dialog.GetFilename().mb_str(),
613 formats[dialog.GetFilterIndex()].psz_module );
617 vlc_object_release( p_playlist );
622 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
624 playlist_t *p_playlist =
625 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
627 if( p_playlist == NULL )
632 wxFileDialog dialog( this, wxU(_("Open playlist")),
633 wxT(""), wxT(""), wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
635 if( dialog.ShowModal() == wxID_OK )
637 playlist_Import( p_playlist, dialog.GetPath().mb_str() );
640 vlc_object_release( p_playlist );
643 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
645 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
652 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
654 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
661 /********************************************************************
663 ********************************************************************/
664 void Playlist::OnUp( wxCommandEvent& event)
666 playlist_t *p_playlist =
667 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
669 if( p_playlist == NULL )
674 /* We use the first selected item, so find it */
675 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
676 wxLIST_STATE_SELECTED);
677 if( i_item > 0 && i_item < p_playlist->i_size )
679 playlist_Move( p_playlist , i_item, i_item - 1);
682 listview->Focus( i_item - 1 );
689 vlc_object_release( p_playlist );
693 void Playlist::OnDown( wxCommandEvent& event)
695 playlist_t *p_playlist =
696 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
698 if( p_playlist == NULL )
703 /* We use the first selected item, so find it */
704 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
705 wxLIST_STATE_SELECTED );
706 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
708 playlist_Move( p_playlist , i_item, i_item + 2 );
709 listview->Focus( i_item + 1 );
711 vlc_object_release( p_playlist );
715 /********************************************************************
717 ********************************************************************/
718 void Playlist::OnSort( wxCommandEvent& event )
720 playlist_t *p_playlist =
721 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
723 if( p_playlist == NULL )
727 switch( event.GetId() )
729 case SortTitle_Event:
730 playlist_SortTitle( p_playlist , 0 );
732 case RSortTitle_Event:
733 playlist_SortTitle( p_playlist , 1 );
735 case SortAuthor_Event:
736 playlist_SortAuthor(p_playlist , 0 );
738 case RSortAuthor_Event:
739 playlist_SortAuthor( p_playlist , 1 );
741 case SortGroup_Event:
742 playlist_SortGroup( p_playlist , 0 );
744 case RSortGroup_Event:
745 playlist_SortGroup( p_playlist , 1 );
747 case Randomize_Event:
748 playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
751 vlc_object_release( p_playlist );
758 void Playlist::OnColSelect( wxListEvent& event )
760 playlist_t *p_playlist =
761 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
763 if( p_playlist == NULL )
767 switch( event.GetColumn() )
770 if( i_title_sorted != 1 )
772 playlist_SortTitle( p_playlist, 0 );
777 playlist_SortTitle( p_playlist, 1 );
782 if( i_author_sorted != 1 )
784 playlist_SortAuthor( p_playlist, 0 );
789 playlist_SortAuthor( p_playlist, 1 );
790 i_author_sorted = -1;
794 if( i_group_sorted != 1 )
796 playlist_SortGroup( p_playlist, 0 );
801 playlist_SortGroup( p_playlist, 1 );
808 vlc_object_release( p_playlist );
815 /**********************************************************************
817 **********************************************************************/
818 void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
820 search_button->SetDefault();
823 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
825 wxString search_string= search_text->GetValue();
831 for( i_current = 0 ; i_current <= listview->GetItemCount() ; i_current++ )
833 if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED )
834 == wxLIST_STATE_SELECTED )
841 for ( i_current = i_first + 1; i_current <= listview->GetItemCount() ;
845 listitem.SetId( i_current );
846 listview->GetItem( listitem );
847 if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
853 for( long item = 0; item < listview->GetItemCount(); item++ )
855 listview->Select( item, FALSE );
859 listitem.SetId(i_item);
860 listitem.m_state = wxLIST_STATE_SELECTED;
861 listview->Select( i_item, TRUE );
862 listview->Focus( i_item );
866 /**********************************************************************
867 * Selection functions
868 **********************************************************************/
869 void Playlist::OnInvertSelection( wxCommandEvent& WXUNUSED(event) )
871 for( long item = 0; item < listview->GetItemCount(); item++ )
873 listview->Select( item, ! listview->IsSelected( item ) );
877 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
879 /* Delete from the end to the beginning, to avoid a shift of indices */
880 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
882 if( listview->IsSelected( item ) )
891 void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) )
893 playlist_t *p_playlist =
894 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
896 if( p_playlist == NULL )
901 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
903 if( listview->IsSelected( item ) )
905 playlist_Enable( p_playlist, item );
909 vlc_object_release( p_playlist);
912 void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) )
914 playlist_t *p_playlist =
915 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
917 if( p_playlist == NULL )
922 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
924 if( listview->IsSelected( item ) )
926 playlist_Disable( p_playlist, item );
930 vlc_object_release( p_playlist);
933 void Playlist::OnSelectAll( wxCommandEvent& WXUNUSED(event) )
935 for( long item = 0; item < listview->GetItemCount(); item++ )
937 listview->Select( item, TRUE );
941 /**********************************************************************
942 * Playlist mode functions
943 **********************************************************************/
944 void Playlist::OnRandom( wxCommandEvent& event )
947 val.b_bool = event.IsChecked();
948 playlist_t *p_playlist =
949 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
951 if( p_playlist == NULL )
955 var_Set( p_playlist , "random", val);
956 vlc_object_release( p_playlist );
958 void Playlist::OnLoop ( wxCommandEvent& event )
961 val.b_bool = event.IsChecked();
962 playlist_t *p_playlist =
963 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
965 if( p_playlist == NULL )
969 var_Set( p_playlist , "loop", val);
970 vlc_object_release( p_playlist );
973 void Playlist::OnRepeat ( wxCommandEvent& event )
976 val.b_bool = event.IsChecked();
977 playlist_t *p_playlist =
978 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
980 if( p_playlist == NULL )
984 var_Set( p_playlist , "repeat", val);
985 vlc_object_release( p_playlist );
990 void Playlist::OnActivateItem( wxListEvent& event )
992 playlist_t *p_playlist =
993 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
995 if( p_playlist == NULL )
999 playlist_Goto( p_playlist, event.GetIndex() );
1001 vlc_object_release( p_playlist );
1004 void Playlist::OnKeyDown( wxListEvent& event )
1006 long keycode = event.GetKeyCode();
1007 /* Delete selected items */
1008 if( keycode == WXK_BACK || keycode == WXK_DELETE )
1010 /* We send a dummy event */
1011 OnDeleteSelection( event );
1015 void Playlist::ShowInfos( int i_item )
1017 playlist_t *p_playlist =
1018 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1020 if( p_playlist == NULL )
1024 if( iteminfo_dialog == NULL )
1026 if( i_item >= 0 && i_item < p_playlist->i_size )
1028 iteminfo_dialog = new ItemInfoDialog(
1029 p_intf, p_playlist->pp_items[i_item], this );
1030 if( iteminfo_dialog->ShowModal() == wxID_OK )
1031 UpdateItem( i_item );
1032 delete iteminfo_dialog;
1033 iteminfo_dialog = NULL;
1036 vlc_object_release( p_playlist );
1039 void Playlist::OnInfos( wxCommandEvent& WXUNUSED(event) )
1041 /* We use the first selected item, so find it */
1042 long i_item = listview->GetNextItem( -1 , wxLIST_NEXT_ALL,
1043 wxLIST_STATE_SELECTED );
1044 ShowInfos( i_item );
1047 void Playlist::OnEnDis( wxCommandEvent& event )
1049 playlist_t *p_playlist =
1050 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1052 if( p_playlist == NULL )
1057 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
1058 wxLIST_STATE_SELECTED );
1060 if( i_item >= 0 && i_item < p_playlist->i_size )
1062 switch( event.GetId() )
1064 case EnableGroup_Event:
1065 playlist_EnableGroup( p_playlist ,
1066 p_playlist->pp_items[i_item]->i_group );
1068 case DisableGroup_Event:
1069 playlist_DisableGroup( p_playlist ,
1070 p_playlist->pp_items[i_item]->i_group );
1076 vlc_object_release( p_playlist );
1079 /*****************************************************************************
1080 * Popup management functions
1081 *****************************************************************************/
1082 void Playlist::OnPopup( wxListEvent& event )
1084 i_popup_item = event.GetIndex();
1085 Playlist::PopupMenu( popup_menu , ScreenToClient( wxGetMousePosition() ) );
1089 void Playlist::OnPopupPlay( wxMenuEvent& event )
1091 playlist_t *p_playlist =
1092 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1094 if( p_playlist == NULL )
1098 if( i_popup_item != -1 )
1100 playlist_Goto( p_playlist, i_popup_item );
1102 vlc_object_release( p_playlist );
1105 void Playlist::OnPopupDel( wxMenuEvent& event )
1107 DeleteItem( i_popup_item );
1110 void Playlist::OnPopupEna( wxMenuEvent& event )
1112 playlist_t *p_playlist =
1113 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1115 if( p_playlist == NULL )
1120 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1121 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1123 playlist_Disable( p_playlist, i_popup_item );
1127 playlist_Enable( p_playlist, i_popup_item );
1129 vlc_object_release( p_playlist);
1130 UpdateItem( i_popup_item );
1133 void Playlist::OnPopupInfo( wxMenuEvent& event )
1135 ShowInfos( i_popup_item );
1138 /*****************************************************************************
1139 * PlaylistChanged: callback triggered by the intf-change playlist variable
1140 * We don't rebuild the playlist directly here because we don't want the
1141 * caller to block for a too long time.
1142 *****************************************************************************/
1143 int PlaylistChanged( 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 vlc_mutex_lock( &p_playlist_dialog->lock );
1148 p_playlist_dialog->b_need_update = VLC_TRUE;
1149 vlc_mutex_unlock( &p_playlist_dialog->lock );
1153 /*****************************************************************************
1154 * Next: callback triggered by the playlist-current playlist variable
1155 *****************************************************************************/
1156 int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1157 vlc_value_t old_val, vlc_value_t new_val, void *param )
1159 Playlist *p_playlist_dialog = (Playlist *)param;
1160 p_playlist_dialog->UpdateItem( old_val.i_int );
1161 p_playlist_dialog->UpdateItem( new_val.i_int );
1166 /*****************************************************************************
1167 * ItemChanged: callback triggered by the item-change playlist variable
1168 *****************************************************************************/
1169 int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1170 vlc_value_t old_val, vlc_value_t new_val, void *param )
1172 Playlist *p_playlist_dialog = (Playlist *)param;
1173 p_playlist_dialog->UpdateItem( new_val.i_int );
1178 /***************************************************************************
1180 ***************************************************************************/
1181 NewGroup::NewGroup( intf_thread_t *_p_intf, wxWindow *_p_parent ):
1182 wxDialog( _p_parent, -1, wxU(_("New Group")), wxDefaultPosition,
1183 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
1185 /* Initializations */
1188 SetIcon( *p_intf->p_sys->p_icon );
1190 /* Create a panel to put everything in*/
1191 wxPanel *panel = new wxPanel( this, -1 );
1192 panel->SetAutoLayout( TRUE );
1194 wxStaticText *group_label =
1195 new wxStaticText( panel , -1,
1196 wxU(_("Enter a name for the new group")));
1198 groupname = new wxTextCtrl(panel, -1, wxU(""),wxDefaultPosition,
1199 wxSize(80,27),wxTE_PROCESS_ENTER);
1201 wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );
1202 ok_button->SetDefault();
1203 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
1206 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1208 button_sizer->Add( ok_button, 0, wxALL, 5 );
1209 button_sizer->Add( cancel_button, 0, wxALL, 5 );
1210 button_sizer->Layout();
1212 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
1213 panel_sizer->Add( group_label, 0, wxEXPAND | wxALL, 5 );
1214 panel_sizer->Add( groupname, 0, wxEXPAND | wxALL, 5 );
1215 panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );
1216 panel_sizer->Layout();
1218 panel->SetSizerAndFit( panel_sizer );
1220 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1221 main_sizer->Add( panel, 1, wxEXPAND, 0 );
1222 main_sizer->Layout();
1223 SetSizerAndFit( main_sizer );
1226 NewGroup::~NewGroup()
1230 void NewGroup::OnOk( wxCommandEvent& event )
1232 psz_name = strdup( groupname->GetLineText(0).mb_str() );
1234 playlist_t * p_playlist =
1235 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1240 if( !playlist_CreateGroup( p_playlist, psz_name ) )
1244 vlc_object_release( p_playlist );
1247 EndModal( wxID_OK );
1250 void NewGroup::OnCancel( wxCommandEvent& WXUNUSED(event) )
1252 EndModal( wxID_CANCEL );