1 /*****************************************************************************
2 * playlist.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
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 static int PlaylistChanged( vlc_object_t *, const char *,
34 vlc_value_t, vlc_value_t, void * );
35 static int PlaylistNext( vlc_object_t *, const char *,
36 vlc_value_t, vlc_value_t, void * );
37 static int ItemChanged( vlc_object_t *, const char *,
38 vlc_value_t, vlc_value_t, void * );
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 */
96 DEFINE_LOCAL_EVENT_TYPE( wxEVT_PLAYLIST );
98 BEGIN_EVENT_TABLE(Playlist, wxFrame)
100 EVT_MENU(AddFile_Event, Playlist::OnAddFile)
101 EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
102 EVT_MENU(Close_Event, Playlist::OnClose)
103 EVT_MENU(Open_Event, Playlist::OnOpen)
104 EVT_MENU(Save_Event, Playlist::OnSave)
106 EVT_MENU(SortTitle_Event, Playlist::OnSort)
107 EVT_MENU(RSortTitle_Event, Playlist::OnSort)
108 EVT_MENU(SortAuthor_Event, Playlist::OnSort)
109 EVT_MENU(RSortAuthor_Event, Playlist::OnSort)
110 EVT_MENU(SortGroup_Event, Playlist::OnSort)
111 EVT_MENU(RSortGroup_Event, Playlist::OnSort)
113 EVT_MENU(Randomize_Event, Playlist::OnSort)
115 EVT_MENU(EnableSelection_Event, Playlist::OnEnableSelection)
116 EVT_MENU(DisableSelection_Event, Playlist::OnDisableSelection)
117 EVT_MENU(InvertSelection_Event, Playlist::OnInvertSelection)
118 EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
119 EVT_MENU(SelectAll_Event, Playlist::OnSelectAll)
120 EVT_MENU(Infos_Event, Playlist::OnInfos)
121 EVT_CHECKBOX(Random_Event, Playlist::OnRandom)
122 EVT_CHECKBOX(Repeat_Event, Playlist::OnRepeat)
123 EVT_CHECKBOX(Loop_Event, Playlist::OnLoop)
125 EVT_MENU(EnableGroup_Event, Playlist::OnEnDis)
126 EVT_MENU(DisableGroup_Event, Playlist::OnEnDis)
128 /* Listview events */
129 EVT_LIST_ITEM_ACTIVATED(ListView_Event, Playlist::OnActivateItem)
130 EVT_LIST_COL_CLICK(ListView_Event, Playlist::OnColSelect)
131 EVT_LIST_KEY_DOWN(ListView_Event, Playlist::OnKeyDown)
132 EVT_LIST_ITEM_RIGHT_CLICK(ListView_Event, Playlist::OnPopup)
135 EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
136 EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
137 EVT_MENU( PopupEna_Event, Playlist::OnPopupEna)
138 EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo)
142 EVT_BUTTON( Search_Event, Playlist::OnSearch)
143 EVT_BUTTON( Save_Event, Playlist::OnSave)
144 EVT_BUTTON( Infos_Event, Playlist::OnInfos)
146 EVT_BUTTON( Up_Event, Playlist::OnUp)
147 EVT_BUTTON( Down_Event, Playlist::OnDown)
149 EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange)
152 EVT_COMMAND(-1, wxEVT_PLAYLIST, Playlist::OnPlaylistEvent)
154 /* Special events : we don't want to destroy the window when the user
156 EVT_CLOSE(Playlist::OnClose)
160 /* Event Table for the Newgroup class */
161 BEGIN_EVENT_TABLE(NewGroup, wxDialog)
162 EVT_BUTTON( wxID_OK, NewGroup::OnOk)
163 EVT_BUTTON( wxID_CANCEL, NewGroup::OnCancel)
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 )
176 /* Initializations */
177 iteminfo_dialog = NULL;
179 i_update_counter = 0;
180 i_sort_mode = MODE_NONE;
181 b_need_update = VLC_FALSE;
182 SetIcon( *p_intf->p_sys->p_icon );
187 i_duration_sorted = 0;
189 var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
190 var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
191 var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
193 /* Create our "Manage" menu */
194 wxMenu *manage_menu = new wxMenu;
195 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add...")) );
196 manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
197 manage_menu->AppendSeparator();
198 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
199 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
200 manage_menu->AppendSeparator();
201 manage_menu->Append( Close_Event, wxU(_("&Close")) );
203 /* Create our "Sort" menu */
204 wxMenu *sort_menu = new wxMenu;
205 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
206 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
207 sort_menu->AppendSeparator();
208 sort_menu->Append( SortAuthor_Event, wxU(_("Sort by &author")) );
209 sort_menu->Append( RSortAuthor_Event, wxU(_("Reverse sort by author")) );
210 sort_menu->AppendSeparator();
211 sort_menu->Append( SortGroup_Event, wxU(_("Sort by &group")) );
212 sort_menu->Append( RSortGroup_Event, wxU(_("Reverse sort by group")) );
213 sort_menu->AppendSeparator();
214 sort_menu->Append( Randomize_Event, wxU(_("&Shuffle Playlist")) );
216 /* Create our "Selection" menu */
217 wxMenu *selection_menu = new wxMenu;
218 selection_menu->Append( EnableSelection_Event, wxU(_("&Enable")) );
219 selection_menu->Append( DisableSelection_Event, wxU(_("&Disable")) );
220 selection_menu->AppendSeparator();
221 selection_menu->Append( InvertSelection_Event, wxU(_("&Invert")) );
222 selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
223 selection_menu->Append( SelectAll_Event, wxU(_("&Select All")) );
225 /* Create our "Group" menu */
226 wxMenu *group_menu = new wxMenu;
227 group_menu->Append( EnableGroup_Event, wxU(_("&Enable all group items")) );
228 group_menu->Append( DisableGroup_Event,
229 wxU(_("&Disable all group items")) );
231 /* Append the freshly created menus to the menu bar */
232 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
233 menubar->Append( manage_menu, wxU(_("&Manage")) );
234 menubar->Append( sort_menu, wxU(_("S&ort")) );
235 menubar->Append( selection_menu, wxU(_("&Selection")) );
236 menubar->Append( group_menu, wxU(_("&Groups")) );
238 /* Attach the menu bar to the frame */
239 SetMenuBar( menubar );
241 /* Create the popup menu */
242 popup_menu = new wxMenu;
243 popup_menu->Append( PopupPlay_Event, wxU(_("Play")) );
244 popup_menu->Append( PopupDel_Event, wxU(_("Delete")) );
245 popup_menu->Append( PopupEna_Event, wxU(_("Enable/Disable")) );
246 popup_menu->Append( PopupInfo_Event, wxU(_("Info")) );
248 /* Create a panel to put everything in */
249 wxPanel *playlist_panel = new wxPanel( this, -1 );
250 playlist_panel->SetAutoLayout( TRUE );
252 /* Create the Random checkbox */
253 wxCheckBox *random_checkbox =
254 new wxCheckBox( playlist_panel, Random_Event, wxU(_("Random")) );
255 var_Get( p_intf, "random", &val );
256 vlc_bool_t b_random = val.b_bool;
257 random_checkbox->SetValue( b_random == VLC_FALSE ? 0 : 1 );
259 /* Create the Loop Checkbox */
260 wxCheckBox *loop_checkbox =
261 new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Repeat All")) );
262 var_Get( p_intf, "loop", &val );
263 int b_loop = val.b_bool ;
264 loop_checkbox->SetValue( b_loop );
266 /* Create the Repeat one checkbox */
267 wxCheckBox *repeat_checkbox =
268 new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat One")) );
269 var_Get( p_intf, "repeat", &val );
270 int b_repeat = val.b_bool ;
271 repeat_checkbox->SetValue( b_repeat );
273 /* Create the Search Textbox */
275 new wxTextCtrl( playlist_panel, SearchText_Event, wxT(""),
276 wxDefaultPosition, wxSize(140, -1),
279 /* Create the search button */
281 new wxButton( playlist_panel, Search_Event, wxU(_("Search")) );
284 /* Create the listview */
285 /* FIXME: the given size is arbitrary, and prevents us from resizing
286 * the window to smaller dimensions. But the sizers don't seem to adjust
287 * themselves to the size of a listview, and with a wxDefaultSize the
288 * playlist window is ridiculously small */
289 listview = new wxListView( playlist_panel, ListView_Event,
290 wxDefaultPosition, wxSize( 500, 300 ),
291 wxLC_REPORT | wxSUNKEN_BORDER );
292 listview->InsertColumn( 0, wxU(_("Name")) );
293 listview->InsertColumn( 1, wxU(_("Author")) );
294 listview->InsertColumn( 2, wxU(_("Duration")) );
295 listview->InsertColumn( 3, wxU(_("Group")) );
296 listview->SetColumnWidth( 0, 270 );
297 listview->SetColumnWidth( 1, 150 );
298 listview->SetColumnWidth( 2, 80 );
300 /* Create the Up-Down buttons */
301 wxButton *up_button =
302 new wxButton( playlist_panel, Up_Event, wxU(_("Up") ) );
304 wxButton *down_button =
305 new wxButton( playlist_panel, Down_Event, wxU(_("Down") ) );
307 /* Create the iteminfo button */
308 wxButton *iteminfo_button =
309 new wxButton( playlist_panel, Infos_Event, wxU(_("Item info") ) );
311 /* Place everything in sizers */
312 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
313 button_sizer->Add( iteminfo_button, 0, wxALIGN_CENTER|wxLEFT, 5);
314 button_sizer->Layout();
316 wxBoxSizer *updown_sizer = new wxBoxSizer( wxHORIZONTAL );
317 updown_sizer->Add( up_button, 0, wxALIGN_LEFT|wxRIGHT, 3);
318 updown_sizer->Add( down_button, 0, wxALIGN_LEFT|wxLEFT, 3);
319 updown_sizer->Layout();
321 wxBoxSizer *checkbox_sizer = new wxBoxSizer( wxHORIZONTAL );
322 checkbox_sizer->Add( random_checkbox, 0,
323 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
324 checkbox_sizer->Add( loop_checkbox, 0,
325 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
326 checkbox_sizer->Add( repeat_checkbox, 0,
327 wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
328 checkbox_sizer->Layout();
330 wxBoxSizer *search_sizer = new wxBoxSizer( wxHORIZONTAL );
331 search_sizer->Add( search_text, 0, wxRIGHT|wxALIGN_CENTER, 3);
332 search_sizer->Add( search_button, 0, wxLEFT|wxALIGN_CENTER, 3);
333 search_sizer->Layout();
335 /* The top and bottom sizers */
336 wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
337 top_sizer->Add( checkbox_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_LEFT, 4 );
338 top_sizer->Add( search_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 4 );
341 wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
342 bottom_sizer->Add( updown_sizer, 0,
343 wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4 );
344 bottom_sizer->Add( button_sizer, 0,
345 wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
346 bottom_sizer->Layout();
348 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
350 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
351 panel_sizer->Add( top_sizer, 0, wxEXPAND | wxALL, 5 );
352 panel_sizer->Add( listview, 1, wxEXPAND | wxALL, 5 );
353 panel_sizer->Add( bottom_sizer, 0, wxEXPAND | wxALL, 5);
354 panel_sizer->Layout();
356 playlist_panel->SetSizerAndFit( panel_sizer );
357 main_sizer->Add( playlist_panel, 1, wxGROW, 0 );
358 main_sizer->Layout();
359 SetSizerAndFit( main_sizer );
361 #if wxUSE_DRAG_AND_DROP
362 /* Associate drop targets with the playlist */
363 SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
366 playlist_t *p_playlist =
367 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
369 if( p_playlist == NULL )
374 /* We want to be noticed of playlist changes */
376 /* Some global changes happened -> Rebuild all */
377 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
379 /* We went to the next item */
380 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
382 /* One item has been updated */
383 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
386 vlc_object_release( p_playlist );
388 /* Update the playlist */
392 Playlist::~Playlist()
394 playlist_t *p_playlist =
395 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
397 if( p_playlist == NULL )
402 delete iteminfo_dialog;
404 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
405 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
406 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
407 vlc_object_release( p_playlist );
410 /**********************************************************************
411 * Update one playlist item
412 **********************************************************************/
413 void Playlist::UpdateItem( int i )
415 if( i < 0 ) return; /* Sanity check */
417 playlist_t *p_playlist =
418 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
421 if( p_playlist == NULL )
426 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
430 vlc_object_release(p_playlist);
434 listview->SetItem( i, 0, wxL2U(p_item->input.psz_name) );
435 listview->SetItem( i, 1, wxU( playlist_ItemGetInfo( p_item,
436 _("General"), _("Author") ) ) );
437 char *psz_group = playlist_FindGroup(p_playlist,
439 listview->SetItem( i, 3,
440 wxL2U( psz_group ? psz_group : _("Normal") ) );
442 if( p_item->b_enabled == VLC_FALSE )
445 listitem.m_itemId = i;
446 listitem.SetTextColour( *wxLIGHT_GREY);
447 listview->SetItem(listitem);
450 char psz_duration[MSTRTIME_MAX_SIZE];
451 mtime_t dur = p_item->input.i_duration;
453 secstotimestr( psz_duration, dur/1000000 );
455 memcpy( psz_duration, "-:--:--", sizeof("-:--:--") );
456 listview->SetItem( i, 2, wxU(psz_duration) );
458 /* Change the colour for the currenty played stream */
460 listitem.m_itemId = i;
461 if( i == p_playlist->i_index )
463 listitem.SetTextColour( *wxRED );
467 listitem.SetTextColour( *wxBLACK );
469 listview->SetItem( listitem );
471 vlc_object_release(p_playlist);
474 /**********************************************************************
475 * Rebuild the playlist
476 **********************************************************************/
477 void Playlist::Rebuild()
479 playlist_t *p_playlist =
480 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
482 if( p_playlist == NULL )
487 int i_focused = listview->GetFocusedItem();
489 /* Clear the list... */
490 listview->DeleteAllItems();
492 /* ...and rebuild it */
493 vlc_mutex_lock( &p_playlist->object_lock );
494 for( int i = 0; i < p_playlist->i_size; i++ )
496 wxString filename = wxL2U(p_playlist->pp_items[i]->input.psz_name);
497 listview->InsertItem( i, filename );
500 vlc_mutex_unlock( &p_playlist->object_lock );
502 if( i_focused >= 0 && i_focused < p_playlist->i_size )
504 listview->Focus( i_focused );
505 listview->Select( i_focused );
507 else if( p_playlist->i_index >= 0 )
509 listview->Focus( p_playlist->i_index );
512 vlc_object_release( p_playlist );
515 void Playlist::ShowPlaylist( bool show )
517 if( show ) Rebuild();
521 void Playlist::UpdatePlaylist()
525 /* If the playlist isn't show there's no need to update it */
526 if( !IsShown() ) return;
528 if( this->b_need_update )
530 this->b_need_update = VLC_FALSE;
534 /* Updating the playing status every 0.5s is enough */
535 if( i_update_counter % 5 ) return;
537 playlist_t *p_playlist =
538 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
540 if( p_playlist == NULL )
545 /* Update the colour of items */
546 int i_playlist_index = p_playlist->i_index;
547 if( p_intf->p_sys->i_playing != i_playlist_index )
550 listitem.m_itemId = i_playlist_index;
551 listitem.SetTextColour( *wxRED );
552 listview->SetItem( listitem );
554 if( p_intf->p_sys->i_playing != -1 )
556 listitem.m_itemId = p_intf->p_sys->i_playing;
557 listitem.SetTextColour( *wxBLACK );
558 listview->SetItem( listitem );
560 p_intf->p_sys->i_playing = i_playlist_index;
563 vlc_object_release( p_playlist );
566 /*****************************************************************************
568 *****************************************************************************/
569 void Playlist::DeleteItem( int item )
571 playlist_t *p_playlist =
572 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
574 if( p_playlist == NULL )
579 playlist_Delete( p_playlist, item );
580 listview->DeleteItem( item );
582 vlc_object_release( p_playlist );
585 void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) )
590 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
596 } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" },
597 { _("PLS file"), "*.pls", "export-pls" }};
598 wxString filter = wxT("");
600 playlist_t * p_playlist =
601 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
608 if( p_playlist->i_size == 0 )
610 wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
611 wxICON_WARNING | wxOK, this );
612 vlc_object_release( p_playlist );
616 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
618 filter.Append( wxU(formats[i].psz_desc) );
619 filter.Append( wxT("|") );
620 filter.Append( wxU(formats[i].psz_filter) );
621 filter.Append( wxT("|") );
623 wxFileDialog dialog( this, wxU(_("Save playlist")),
624 wxT(""), wxT(""), filter, wxSAVE );
626 if( dialog.ShowModal() == wxID_OK )
628 if( dialog.GetPath().mb_str() )
630 playlist_Export( p_playlist, dialog.GetPath().mb_str(),
631 formats[dialog.GetFilterIndex()].psz_module );
635 vlc_object_release( p_playlist );
639 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
641 playlist_t *p_playlist =
642 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
644 if( p_playlist == NULL )
649 wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
650 wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
652 if( dialog.ShowModal() == wxID_OK )
654 playlist_Import( p_playlist, dialog.GetPath().mb_str() );
657 vlc_object_release( p_playlist );
660 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
662 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
669 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
671 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
678 /********************************************************************
680 ********************************************************************/
681 void Playlist::OnUp( wxCommandEvent& event )
683 playlist_t *p_playlist =
684 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
686 if( p_playlist == NULL )
691 /* We use the first selected item, so find it */
692 long i_item = listview->GetNextItem( -1, wxLIST_NEXT_ALL,
693 wxLIST_STATE_SELECTED);
694 if( i_item > 0 && i_item < p_playlist->i_size )
696 playlist_Move( p_playlist, i_item, i_item - 1 );
697 listview->Focus( i_item - 1 );
699 vlc_object_release( p_playlist );
702 void Playlist::OnDown( wxCommandEvent& event )
704 playlist_t *p_playlist =
705 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
707 if( p_playlist == NULL )
712 /* We use the first selected item, so find it */
713 long i_item = listview->GetNextItem( -1, wxLIST_NEXT_ALL,
714 wxLIST_STATE_SELECTED );
715 if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
717 playlist_Move( p_playlist, i_item, i_item + 2 );
718 listview->Focus( i_item + 1 );
720 vlc_object_release( p_playlist );
723 /********************************************************************
725 ********************************************************************/
726 void Playlist::OnSort( wxCommandEvent& event )
728 playlist_t *p_playlist =
729 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
731 if( p_playlist == NULL )
735 switch( event.GetId() )
737 case SortTitle_Event:
738 playlist_SortTitle( p_playlist, ORDER_NORMAL );
740 case RSortTitle_Event:
741 playlist_SortTitle( p_playlist, ORDER_REVERSE );
743 case SortAuthor_Event:
744 playlist_SortAuthor(p_playlist, ORDER_NORMAL );
746 case RSortAuthor_Event:
747 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
749 case SortGroup_Event:
750 playlist_SortGroup( p_playlist, ORDER_NORMAL );
752 case RSortGroup_Event:
753 playlist_SortGroup( p_playlist, ORDER_REVERSE );
755 case Randomize_Event:
756 playlist_Sort( p_playlist, SORT_RANDOM, ORDER_NORMAL );
759 vlc_object_release( p_playlist );
764 void Playlist::OnColSelect( wxListEvent& event )
766 playlist_t *p_playlist =
767 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
769 if( p_playlist == NULL )
773 switch( event.GetColumn() )
776 if( i_title_sorted != 1 )
778 playlist_SortTitle( p_playlist, ORDER_NORMAL );
783 playlist_SortTitle( p_playlist, ORDER_REVERSE );
788 if( i_author_sorted != 1 )
790 playlist_SortAuthor( p_playlist, ORDER_NORMAL );
795 playlist_SortAuthor( p_playlist, ORDER_REVERSE );
796 i_author_sorted = -1;
800 if( i_duration_sorted != 1 )
802 playlist_Sort( p_playlist, SORT_DURATION, ORDER_NORMAL );
803 i_duration_sorted = 1;
807 playlist_Sort( p_playlist, SORT_DURATION, ORDER_REVERSE );
808 i_duration_sorted = -1;
812 if( i_group_sorted != 1 )
814 playlist_SortGroup( p_playlist, ORDER_NORMAL );
819 playlist_SortGroup( p_playlist, ORDER_REVERSE );
826 vlc_object_release( p_playlist );
831 /**********************************************************************
833 **********************************************************************/
834 void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
836 search_button->SetDefault();
839 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
841 wxString search_string = search_text->GetValue();
848 for( i_current = 0; i_current < listview->GetItemCount(); i_current++ )
850 if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED ) ==
851 wxLIST_STATE_SELECTED )
858 if( i_first == listview->GetItemCount() )
863 for( i_current = i_first + 1; i_current < listview->GetItemCount();
867 listitem.SetId( i_current );
868 listview->GetItem( listitem );
869 if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
875 listitem.SetColumn( 1 );
876 listview->GetItem( listitem );
877 if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
886 for( i_current = -1 ; i_current < i_first - 1;
890 listitem.SetId( i_current );
891 listview->GetItem( listitem );
892 if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
898 listitem.SetColumn( 1 );
899 listview->GetItem( listitem );
900 if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
909 if( i_item < 0 || i_item >= listview->GetItemCount() )
914 for( long item = 0; item < listview->GetItemCount(); item++ )
916 listview->Select( item, FALSE );
920 listitem.SetId(i_item);
921 listitem.m_state = wxLIST_STATE_SELECTED;
922 listview->Select( i_item, TRUE );
923 listview->Focus( i_item );
926 /**********************************************************************
927 * Selection functions
928 **********************************************************************/
929 void Playlist::OnInvertSelection( wxCommandEvent& WXUNUSED(event) )
931 for( long item = 0; item < listview->GetItemCount(); item++ )
933 listview->Select( item, ! listview->IsSelected( item ) );
937 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
939 /* Delete from the end to the beginning, to avoid a shift of indices */
940 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
942 if( listview->IsSelected( item ) )
951 void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) )
953 playlist_t *p_playlist =
954 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
956 if( p_playlist == NULL )
961 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
963 if( listview->IsSelected( item ) )
966 playlist_Enable( p_playlist, item );
970 vlc_object_release( p_playlist);
973 void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) )
975 playlist_t *p_playlist =
976 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
978 if( p_playlist == NULL )
983 for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
985 if( listview->IsSelected( item ) )
988 playlist_Disable( p_playlist, item );
992 vlc_object_release( p_playlist);
995 void Playlist::OnSelectAll( wxCommandEvent& WXUNUSED(event) )
997 for( long item = 0; item < listview->GetItemCount(); item++ )
999 listview->Select( item, TRUE );
1003 /**********************************************************************
1004 * Playlist mode functions
1005 **********************************************************************/
1006 void Playlist::OnRandom( wxCommandEvent& event )
1009 val.b_bool = event.IsChecked();
1010 playlist_t *p_playlist =
1011 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1013 if( p_playlist == NULL )
1017 var_Set( p_playlist, "random", val);
1018 vlc_object_release( p_playlist );
1021 void Playlist::OnLoop( wxCommandEvent& event )
1024 val.b_bool = event.IsChecked();
1025 playlist_t *p_playlist =
1026 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1028 if( p_playlist == NULL )
1032 var_Set( p_playlist, "loop", val);
1033 vlc_object_release( p_playlist );
1036 void Playlist::OnRepeat( wxCommandEvent& event )
1039 val.b_bool = event.IsChecked();
1040 playlist_t *p_playlist =
1041 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1043 if( p_playlist == NULL )
1047 var_Set( p_playlist, "repeat", val);
1048 vlc_object_release( p_playlist );
1053 void Playlist::OnActivateItem( wxListEvent& event )
1055 playlist_t *p_playlist =
1056 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1058 if( p_playlist == NULL )
1063 playlist_Goto( p_playlist, event.GetIndex() );
1065 vlc_object_release( p_playlist );
1068 void Playlist::OnKeyDown( wxListEvent& event )
1070 long keycode = event.GetKeyCode();
1071 /* Delete selected items */
1072 if( keycode == WXK_BACK || keycode == WXK_DELETE )
1074 /* We send a dummy event */
1075 OnDeleteSelection( event );
1079 void Playlist::ShowInfos( int i_item )
1086 playlist_t *p_playlist =
1087 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1089 if( p_playlist == NULL )
1094 if( iteminfo_dialog == NULL )
1096 vlc_mutex_lock( &p_playlist->object_lock);
1097 playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
1098 vlc_mutex_unlock( &p_playlist->object_lock );
1102 iteminfo_dialog = new ItemInfoDialog( p_intf, p_item, this );
1103 if( iteminfo_dialog->ShowModal() == wxID_OK )
1104 UpdateItem( i_item );
1105 delete iteminfo_dialog;
1106 iteminfo_dialog = NULL;
1109 vlc_object_release( p_playlist );
1112 void Playlist::OnInfos( wxCommandEvent& WXUNUSED(event) )
1114 /* We use the first selected item, so find it */
1115 long i_item = listview->GetNextItem( -1, wxLIST_NEXT_ALL,
1116 wxLIST_STATE_SELECTED );
1117 ShowInfos( i_item );
1120 void Playlist::OnEnDis( wxCommandEvent& event )
1122 playlist_t *p_playlist =
1123 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1125 if( p_playlist == NULL )
1130 long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
1131 wxLIST_STATE_SELECTED );
1133 if( i_item >= 0 && i_item < p_playlist->i_size )
1135 switch( event.GetId() )
1137 case EnableGroup_Event:
1139 playlist_EnableGroup( p_playlist,
1140 p_playlist->pp_items[i_item]->i_group );
1142 case DisableGroup_Event:
1143 playlist_DisableGroup( p_playlist,
1144 p_playlist->pp_items[i_item]->i_group );
1150 vlc_object_release( p_playlist );
1153 /*****************************************************************************
1154 * Popup management functions
1155 *****************************************************************************/
1156 void Playlist::OnPopup( wxListEvent& event )
1158 i_popup_item = event.GetIndex();
1159 Playlist::PopupMenu( popup_menu, ScreenToClient( wxGetMousePosition() ) );
1162 void Playlist::OnPopupPlay( wxMenuEvent& event )
1164 playlist_t *p_playlist =
1165 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1167 if( p_playlist == NULL )
1171 if( i_popup_item != -1 )
1173 playlist_Goto( p_playlist, i_popup_item );
1175 vlc_object_release( p_playlist );
1178 void Playlist::OnPopupDel( wxMenuEvent& event )
1180 DeleteItem( i_popup_item );
1183 void Playlist::OnPopupEna( wxMenuEvent& event )
1185 playlist_t *p_playlist =
1186 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1188 if( p_playlist == NULL )
1193 if( p_playlist->pp_items[i_popup_item]->b_enabled )
1194 //playlist_IsEnabled( p_playlist, i_popup_item ) )
1196 playlist_Disable( p_playlist, i_popup_item );
1200 playlist_Enable( p_playlist, i_popup_item );
1202 vlc_object_release( p_playlist);
1203 UpdateItem( i_popup_item );
1206 void Playlist::OnPopupInfo( wxMenuEvent& event )
1208 ShowInfos( i_popup_item );
1211 /*****************************************************************************
1212 * Custom events management
1213 *****************************************************************************/
1214 void Playlist::OnPlaylistEvent( wxCommandEvent& event )
1216 switch( event.GetId() )
1218 case UpdateItem_Event:
1219 UpdateItem( event.GetInt() );
1224 /*****************************************************************************
1225 * PlaylistChanged: callback triggered by the intf-change playlist variable
1226 * We don't rebuild the playlist directly here because we don't want the
1227 * caller to block for a too long time.
1228 *****************************************************************************/
1229 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1230 vlc_value_t oval, vlc_value_t nval, void *param )
1232 Playlist *p_playlist_dialog = (Playlist *)param;
1233 p_playlist_dialog->b_need_update = VLC_TRUE;
1237 /*****************************************************************************
1238 * Next: callback triggered by the playlist-current playlist variable
1239 *****************************************************************************/
1240 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1241 vlc_value_t oval, vlc_value_t nval, void *param )
1243 Playlist *p_playlist_dialog = (Playlist *)param;
1245 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1246 event.SetInt( oval.i_int );
1247 p_playlist_dialog->AddPendingEvent( event );
1248 event.SetInt( nval.i_int );
1249 p_playlist_dialog->AddPendingEvent( event );
1254 /*****************************************************************************
1255 * ItemChanged: callback triggered by the item-change playlist variable
1256 *****************************************************************************/
1257 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1258 vlc_value_t old_val, vlc_value_t new_val, void *param )
1260 Playlist *p_playlist_dialog = (Playlist *)param;
1262 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1263 event.SetInt( new_val.i_int );
1264 p_playlist_dialog->AddPendingEvent( event );
1269 /***************************************************************************
1271 ***************************************************************************/
1272 NewGroup::NewGroup( intf_thread_t *_p_intf, wxWindow *_p_parent ):
1273 wxDialog( _p_parent, -1, wxU(_("New Group")), wxDefaultPosition,
1274 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
1276 /* Initializations */
1279 SetIcon( *p_intf->p_sys->p_icon );
1281 /* Create a panel to put everything in*/
1282 wxPanel *panel = new wxPanel( this, -1 );
1283 panel->SetAutoLayout( TRUE );
1285 wxStaticText *group_label =
1286 new wxStaticText( panel, -1,
1287 wxU(_("Enter a name for the new group:")));
1289 groupname = new wxTextCtrl(panel, -1, wxU(""), wxDefaultPosition,
1290 wxSize(100, 27), wxTE_PROCESS_ENTER);
1292 wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );
1293 ok_button->SetDefault();
1294 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
1297 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1299 button_sizer->Add( ok_button, 0, wxALL, 5 );
1300 button_sizer->Add( cancel_button, 0, wxALL, 5 );
1301 button_sizer->Layout();
1303 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
1304 panel_sizer->Add( group_label, 0, wxEXPAND | wxALL, 5 );
1305 panel_sizer->Add( groupname, 0, wxEXPAND | wxALL, 5 );
1306 panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );
1307 panel_sizer->Layout();
1309 panel->SetSizerAndFit( panel_sizer );
1311 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1312 main_sizer->Add( panel, 1, wxEXPAND, 0 );
1313 main_sizer->Layout();
1314 SetSizerAndFit( main_sizer );
1317 NewGroup::~NewGroup()
1321 void NewGroup::OnOk( wxCommandEvent& event )
1323 psz_name = strdup( groupname->GetLineText(0).mb_str() );
1325 playlist_t * p_playlist =
1326 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1331 if( !playlist_CreateGroup( p_playlist, psz_name ) )
1335 vlc_object_release( p_playlist );
1338 EndModal( wxID_OK );
1341 void NewGroup::OnCancel( wxCommandEvent& WXUNUSED(event) )
1343 EndModal( wxID_CANCEL );