1 /*****************************************************************************
2 * playlist.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Clément Stenac <zorglub@videolan.org>
10 * This program is free software; you can redistribute it and/OR MODIFy
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include "dialogs/playlist.hpp"
29 #include "dialogs/iteminfo.hpp"
31 #include "bitmaps/shuffle.xpm"
32 #include "bitmaps/repeat.xpm"
33 #include "bitmaps/loop.xpm"
35 #include "bitmaps/type_unknown.xpm"
36 #include "bitmaps/type_afile.xpm"
37 #include "bitmaps/type_vfile.xpm"
38 #include "bitmaps/type_net.xpm"
39 #include "bitmaps/type_card.xpm"
40 #include "bitmaps/type_disc.xpm"
41 #include "bitmaps/type_cdda.xpm"
42 #include "bitmaps/type_directory.xpm"
43 #include "bitmaps/type_playlist.xpm"
44 #include "bitmaps/type_node.xpm"
46 #include <wx/dynarray.h>
47 #include <wx/imaglist.h>
50 #include "vlc_charset.h"
52 #define HELP_SHUFFLE N_( "Shuffle" )
53 #define HELP_LOOP N_( "Repeat All" )
54 #define HELP_REPEAT N_( "Repeat One" )
57 /* Callback prototype */
58 static int PlaylistChanged( vlc_object_t *, const char *,
59 vlc_value_t, vlc_value_t, void * );
60 static int PlaylistNext( vlc_object_t *, const char *,
61 vlc_value_t, vlc_value_t, void * );
62 static int ItemChanged( vlc_object_t *, const char *,
63 vlc_value_t, vlc_value_t, void * );
64 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
65 vlc_value_t oval, vlc_value_t nval, void *param );
66 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
67 vlc_value_t oval, vlc_value_t nval, void *param );
69 /*****************************************************************************
71 *****************************************************************************/
73 /* IDs for the controls and the menu commands */
88 DeleteSelection_Event,
108 Browse_Event, /* For export playlist */
115 MenuDummy_Event = wxID_HIGHEST + 999,
117 FirstView_Event = wxID_HIGHEST + 1000,
118 CategoryView_Event, OneLevelView_Event,
119 LastView_Event = wxID_HIGHEST + 1100,
121 FirstSD_Event = wxID_HIGHEST + 2000,
122 LastSD_Event = wxID_HIGHEST + 2100,
125 DEFINE_LOCAL_EVENT_TYPE( wxEVT_PLAYLIST );
127 BEGIN_EVENT_TABLE(Playlist, wxFrame)
128 EVT_SIZE(Playlist::OnSize)
131 EVT_MENU(AddFile_Event, Playlist::OnAddFile)
132 EVT_MENU(AddDir_Event, Playlist::OnAddDir)
133 EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
134 EVT_MENU(Close_Event, Playlist::OnMenuClose)
135 EVT_MENU(Open_Event, Playlist::OnOpen)
136 EVT_MENU(Save_Event, Playlist::OnSave)
138 EVT_MENU(SortTitle_Event, Playlist::OnSort)
139 EVT_MENU(RSortTitle_Event, Playlist::OnSort)
141 EVT_MENU(Randomize_Event, Playlist::OnSort)
143 EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
145 EVT_MENU_OPEN( Playlist::OnMenuOpen )
146 EVT_MENU( -1, Playlist::OnMenuEvent )
148 EVT_TOOL(Random_Event, Playlist::OnRandom)
149 EVT_TOOL(Repeat_Event, Playlist::OnRepeat)
150 EVT_TOOL(Loop_Event, Playlist::OnLoop)
153 EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
154 EVT_MENU( PopupPlayThis_Event, Playlist::OnPopupPlay)
155 EVT_MENU( PopupPreparse_Event, Playlist::OnPopupPreparse)
156 EVT_MENU( PopupSort_Event, Playlist::OnPopupSort)
157 EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
158 EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo)
159 EVT_MENU( PopupAddNode_Event, Playlist::OnPopupAddNode)
161 /* Source selector */
162 EVT_LIST_ITEM_SELECTED( Source_Event, Playlist::OnSourceSelected )
163 /* Tree control events */
164 EVT_TREE_ITEM_ACTIVATED( TreeCtrl_Event, Playlist::OnActivateItem )
165 EVT_TREE_KEY_DOWN( -1, Playlist::OnKeyDown )
166 EVT_TREE_BEGIN_DRAG( TreeCtrl_Event, Playlist::OnDragItemBegin )
167 EVT_TREE_END_DRAG( TreeCtrl_Event, Playlist::OnDragItemEnd )
169 EVT_CONTEXT_MENU( Playlist::OnPopup )
172 EVT_BUTTON( Search_Event, Playlist::OnSearch)
173 EVT_BUTTON( Save_Event, Playlist::OnSave)
175 /*EVT_TEXT( SearchText_Event, Playlist::OnSearchTextChange )*/
176 EVT_TEXT_ENTER( SearchText_Event, Playlist::OnSearch )
179 EVT_COMMAND(-1, wxEVT_PLAYLIST, Playlist::OnPlaylistEvent)
181 /* Special events : we don't want to destroy the window when the user
183 EVT_CLOSE(Playlist::OnClose)
186 /*****************************************************************************
188 ****************************************************************************/
189 class PlaylistItem : public wxTreeItemData
192 PlaylistItem( playlist_item_t *p_item ) : wxTreeItemData()
195 i_input_id = p_item->p_input->i_id;
200 friend class Playlist;
201 friend class PlaylistFileDropTarget;
204 /*****************************************************************************
206 *****************************************************************************/
207 Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
208 wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
209 wxSize(500,300), wxDEFAULT_FRAME_STYLE )
213 /* Initializations */
216 i_update_counter = 0;
217 i_sort_mode = MODE_NONE;
218 b_need_update = VLC_FALSE;
219 i_items_to_append = 0;
220 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
222 if( p_playlist == NULL ) return;
224 SetIcon( *p_intf->p_sys->p_icon );
227 p_sd_menu = SDMenu();
229 p_current_viewroot = p_playlist->p_root_category;
230 p_current_treeroot = NULL;
234 i_duration_sorted = 0;
236 var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
237 var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
238 var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
240 /* Create our "Manage" menu */
241 wxMenu *manage_menu = new wxMenu;
242 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add File...")) );
243 manage_menu->Append( AddDir_Event, wxU(_("Add &Directory...")) );
244 manage_menu->Append( AddMRL_Event, wxU(_("&Add URL...")) );
245 manage_menu->AppendSeparator();
246 manage_menu->Append( MenuDummy_Event, wxU(_("Services Discovery")),
248 manage_menu->AppendSeparator();
249 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
250 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
251 manage_menu->AppendSeparator();
252 manage_menu->Append( Close_Event, wxU(_("&Close")) );
254 /* Create our "Sort" menu */
255 wxMenu *sort_menu = new wxMenu;
256 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &Title")) );
257 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse Sort by Title")) );
258 sort_menu->AppendSeparator();
259 sort_menu->Append( Randomize_Event, wxU(_("&Shuffle")) );
261 /* Create our "Selection" menu */
262 wxMenu *selection_menu = new wxMenu;
263 selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
265 /* Create our "View" menu */
268 /* Append the freshly created menus to the menu bar */
269 wxMenuBar *menubar = new wxMenuBar();
270 menubar->Append( manage_menu, wxU(_("&Manage")) );
271 menubar->Append( sort_menu, wxU(_("S&ort")) );
272 menubar->Append( selection_menu, wxU(_("&Selection")) );
273 menubar->Append( p_view_menu, wxU(_("&View items") ) );
275 /* Attach the menu bar to the frame */
276 SetMenuBar( menubar );
278 /* Create the popup menu */
279 node_popup = new wxMenu;
280 node_popup->Append( PopupPlay_Event, wxU(_("Play")) );
281 node_popup->Append( PopupPlayThis_Event, wxU(_("Play this Branch")) );
282 node_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
283 node_popup->Append( PopupSort_Event, wxU(_("Sort this Branch")) );
284 node_popup->Append( PopupDel_Event, wxU(_("Delete")) );
285 node_popup->Append( PopupInfo_Event, wxU(_("Info")) );
286 node_popup->Append( PopupAddNode_Event, wxU(_("Add Node")) );
288 item_popup = new wxMenu;
289 item_popup->Append( PopupPlay_Event, wxU(_("Play")) );
290 item_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
291 item_popup->Append( PopupDel_Event, wxU(_("Delete")) );
292 item_popup->Append( PopupInfo_Event, wxU(_("Info")) );
294 /* Create a panel to put everything in */
295 wxPanel *playlist_panel = new wxPanel( this, -1 );
296 playlist_panel->SetAutoLayout( TRUE );
298 /* Create the toolbar */
300 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
302 /* Create the random tool */
303 toolbar->AddTool( Random_Event, wxT(""), wxBitmap(shuffle_on_xpm),
304 wxBitmap(shuffle_on_xpm), wxITEM_CHECK,
305 wxU(_(HELP_SHUFFLE) ) );
306 var_Get( p_intf, "random", &val );
307 toolbar->ToggleTool( Random_Event, val.b_bool );
309 /* Create the Loop tool */
310 toolbar->AddTool( Loop_Event, wxT(""), wxBitmap( loop_xpm),
311 wxBitmap( loop_xpm), wxITEM_CHECK,
312 wxU(_(HELP_LOOP ) ) );
313 var_Get( p_intf, "loop", &val );
314 toolbar->ToggleTool( Loop_Event, val.b_bool );
316 /* Create the Repeat one checkbox */
317 toolbar->AddTool( Repeat_Event, wxT(""), wxBitmap( repeat_xpm),
318 wxBitmap( repeat_xpm), wxITEM_CHECK,
319 wxU(_(HELP_REPEAT ) ) );
320 var_Get( p_intf, "repeat", &val );
321 toolbar->ToggleTool( Repeat_Event, val.b_bool ) ;
323 /* Create the Search Textbox */
324 search_text = new wxTextCtrl( toolbar, SearchText_Event, wxT(""),
325 wxDefaultPosition, wxSize(100, -1),
328 /* Create the search button */
329 search_button = new wxButton( toolbar , Search_Event, wxU(_("Search")) );
331 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
332 wxSize(16, 16), wxBORDER_NONE ) );
333 toolbar->AddControl( search_text );
334 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
335 wxSize(5, 5), wxBORDER_NONE ) );
336 toolbar->AddControl( search_button );
337 search_button->SetDefault();
340 /* Create teh source selector */
341 source_sel = new wxListView( playlist_panel, Source_Event,
342 wxDefaultPosition, wxDefaultSize,
343 wxLC_AUTOARRANGE|wxLC_SINGLE_SEL );
345 /* Create the tree */
346 treectrl = new wxTreeCtrl( playlist_panel, TreeCtrl_Event,
347 wxDefaultPosition, wxDefaultSize,
348 wxTR_HIDE_ROOT | wxTR_LINES_AT_ROOT|
350 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS |
351 wxTR_MULTIPLE | wxTR_EXTENDED );
353 /* Create image list */
354 wxImageList *p_images = new wxImageList( 16 , 16, TRUE );
356 /* FIXME: absolutely needs to be in the right order FIXME */
357 p_images->Add( wxIcon( type_unknown_xpm ) );
358 p_images->Add( wxIcon( type_afile_xpm ) );
359 p_images->Add( wxIcon( type_vfile_xpm ) );
360 p_images->Add( wxIcon( type_directory_xpm ) );
361 p_images->Add( wxIcon( type_disc_xpm ) );
362 p_images->Add( wxIcon( type_cdda_xpm ) );
363 p_images->Add( wxIcon( type_card_xpm ) );
364 p_images->Add( wxIcon( type_net_xpm ) );
365 p_images->Add( wxIcon( type_playlist_xpm ) );
366 p_images->Add( wxIcon( type_node_xpm ) );
367 treectrl->AssignImageList( p_images );
369 /* Reduce font size */
370 wxFont font= treectrl->GetFont();
371 font.SetPointSize(9);
372 treectrl->SetFont( font );
374 wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL );
375 panel_sizer->Add( source_sel, 0, wxALL | wxEXPAND, 5 );
376 panel_sizer->Add( treectrl, 1, wxEXPAND | wxALL, 5 );
377 panel_sizer->Layout();
379 playlist_panel->SetSizerAndFit( panel_sizer );
381 int pi_widths[1] = { -1 };
382 statusbar = CreateStatusBar( 1 );
383 statusbar->SetStatusWidths( 1, pi_widths );
385 #if wxUSE_DRAG_AND_DROP
386 /* Associate drop targets with the playlist */
387 SetDropTarget( new PlaylistFileDropTarget( this ) );
388 menubar->SetDropTarget( new PlaylistFileDropTarget( this ) );
389 toolbar->SetDropTarget( new PlaylistFileDropTarget( this ) );
393 i_saved_input_id = -1;
395 /* Some global changes happened -> Rebuild all */
396 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
398 /* We went to the next item */
399 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
401 /* One item has been updated */
402 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
404 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
405 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
407 /* Update the playlist */
408 p_current_treeroot = p_playlist->p_local_category;
412 Playlist::~Playlist()
414 if( pp_sds != NULL ) free( pp_sds );
416 if( p_playlist == NULL ) return;
418 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
419 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
420 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
421 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
422 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
423 vlc_object_release( p_playlist );
426 /**********************************************************************
428 **********************************************************************/
431 void Playlist::UpdateNode( playlist_item_t *p_node, wxTreeItemId node )
433 wxTreeItemIdValue cookie;
435 for( int i = 0; i< p_node->i_children ; i++ )
439 child = treectrl->GetFirstChild( node, cookie);
443 child = treectrl->GetNextChild( node, cookie );
448 /* Not enough children */
449 CreateNode( p_node->pp_children[i], node );
450 /* Keep the tree pointer up to date */
451 child = treectrl->GetNextChild( node, cookie );
454 treectrl->SetItemImage( node, p_node->p_input->i_type );
458 /* Creates the node p_node as last child of parent */
459 void Playlist::CreateNode( playlist_item_t *p_node, wxTreeItemId parent )
462 treectrl->AppendItem( parent, wxL2U( p_node->p_input->psz_name ),
463 -1,-1, new PlaylistItem( p_node ) );
464 treectrl->SetItemImage( node, p_node->p_input->i_type );
466 UpdateNodeChildren( p_node, node );
469 /* Update all children (recursively) of this node */
470 void Playlist::UpdateNodeChildren( playlist_item_t *p_node,
473 for( int i = 0; i< p_node->i_children ; i++ )
475 /* Append the item */
476 if( p_node->pp_children[i]->i_children == -1 )
478 if( !(p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG) )
481 treectrl->AppendItem( node,
482 wxL2U( p_node->pp_children[i]->p_input->psz_name ), -1,-1,
483 new PlaylistItem( p_node->pp_children[i]) );
485 UpdateTreeItem( item );
490 CreateNode( p_node->pp_children[i], node );
495 /* Update an item in the tree */
496 void Playlist::UpdateTreeItem( wxTreeItemId item )
498 LockPlaylist( p_intf->p_sys, p_playlist );
499 if( ! item.IsOk() ) return;
501 wxTreeItemData *p_data = treectrl->GetItemData( item );
502 if( !p_data ) return;
504 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
505 ((PlaylistItem *)p_data)->i_id, VLC_TRUE );
508 UnlockPlaylist( p_intf->p_sys, p_playlist );
513 wxString duration = wxU( "" );
516 psz_artist = input_item_GetArtist( p_item->p_input ) ?
517 strdup( input_item_GetArtist( p_item->p_input ) ) :
520 char psz_duration[MSTRTIME_MAX_SIZE];
521 mtime_t dur = p_item->p_input->i_duration;
525 secstotimestr( psz_duration, dur/1000000 );
526 duration.Append( wxU( " ( " ) + wxString( wxU( psz_duration ) ) +
530 if( !strcmp( psz_artist, "" ) || p_item->p_input->b_fixed_name == VLC_TRUE )
532 msg = wxString( wxU( p_item->p_input->psz_name ) ) + duration;
536 msg = wxString(wxU( psz_artist )) + wxT(" - ") +
537 wxString(wxU(p_item->p_input->psz_name)) + duration;
540 treectrl->SetItemText( item , msg );
541 treectrl->SetItemImage( item, p_item->p_input->i_type );
543 if( p_playlist->status.p_item == p_item )
545 treectrl->SetItemBold( item, true );
546 while( treectrl->GetItemParent( item ).IsOk() )
548 item = treectrl->GetItemParent( item );
549 if( ! (item == treectrl->GetRootItem() &&
550 treectrl->HasFlag( wxTR_HIDE_ROOT ) ) )
551 treectrl->Expand( item );
556 treectrl->SetItemBold( item, false );
558 UnlockPlaylist( p_intf->p_sys, p_playlist );
561 /* Process a AppendIt em request */
562 void Playlist::AppendItem( wxCommandEvent& event )
564 playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();
565 playlist_item_t *p_item = NULL;
566 wxTreeItemId item, node;
570 /* No need to do anything if the playlist is going to be rebuilt */
571 if( b_need_update ) return;
573 node = FindItem( treectrl->GetRootItem(), p_add->i_node );
574 if( !node.IsOk() ) goto update;
576 p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
577 if( !p_item ) goto update;
578 if( (p_item->i_flags & PLAYLIST_DBL_FLAG ) ) goto update;
580 item = FindItem( treectrl->GetRootItem(), p_add->i_item );
581 if( item.IsOk() ) goto update;
583 item = treectrl->AppendItem( node,
584 wxL2U( p_item->p_input->psz_name ), -1,-1,
585 new PlaylistItem( p_item ) );
586 treectrl->SetItemImage( item, p_item->p_input->i_type );
588 if( item.IsOk() && p_item->i_children == -1 )
590 UpdateTreeItem( item );
594 int i_count = CountItems( treectrl->GetRootItem());
595 statusbar->SetStatusText( wxString::Format( wxU(_(
596 "%i items in playlist" ) ), i_count ) );
600 /* Process a updateitem request */
601 void Playlist::UpdateItem( int i )
603 if( i < 0 ) return; /* Sanity check */
604 wxTreeItemId item = FindItemByInput( treectrl->GetRootItem(), i );
607 UpdateTreeItem( item );
611 void Playlist::RemoveItem( int i )
613 if( i <= 0 ) return; /* Sanity check */
614 if( i == i_saved_id ) i_saved_id = -1;
616 /* Hack: always invalidate input item cache */
617 i_saved_input_id = -1;
619 /// \todo Check if it is in the source selector */
621 wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
625 treectrl->Delete( item );
630 /**********************************************************************
631 * Search functions (internal)
632 **********************************************************************/
634 /* Find a wxItem from a playlist id */
635 wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id )
637 return FindItemInner( root, i_id, false );
640 wxTreeItemId Playlist::FindItemByInput( wxTreeItemId root, int i_input_id )
642 return FindItemInner( root, i_input_id, true );
645 wxTreeItemId Playlist::FindItemInner( wxTreeItemId root, int i_id, bool b_byinput )
647 wxTreeItemIdValue cookie;
648 PlaylistItem *p_wxcurrent;
650 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
653 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
657 wxTreeItemId dummy; dummy.Unset(); return dummy;
659 if( b_byinput && i_saved_input_id == i_id )
660 return saved_input_tree_item;
661 if( !b_byinput && i_saved_id == i_id)
662 return saved_tree_item;
666 wxTreeItemId dummy; dummy.Unset(); return dummy;
669 if( !b_byinput && p_wxcurrent->i_id == i_id )
672 saved_tree_item = root;
675 if( b_byinput && p_wxcurrent->i_input_id == i_id )
677 i_saved_input_id = i_id;
678 saved_input_tree_item = root;
684 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
685 if( !b_byinput && p_wxcurrent->i_id == i_id )
688 saved_tree_item = item;
691 else if( b_byinput && p_wxcurrent->i_input_id == i_id )
693 i_saved_input_id = i_id;
694 saved_input_tree_item = item;
697 if( treectrl->ItemHasChildren( item ) )
699 wxTreeItemId search = FindItemInner( item, i_id, b_byinput );
705 saved_tree_item = search;
710 i_saved_input_id = i_id;
711 saved_input_tree_item = search;
717 item = treectrl->GetNextChild( root, cookie );
720 wxTreeItemId dummy; dummy.Unset(); return dummy;
723 int Playlist::CountItems( wxTreeItemId root )
725 wxTreeItemIdValue cookie;
727 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
731 if( treectrl->ItemHasChildren( item ) )
733 count += CountItems( item );
737 playlist_item_t *p_item;
738 LockPlaylist( p_intf->p_sys, p_playlist );
739 p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id, VLC_TRUE );
740 if( p_item && p_item->i_children == -1 )
742 UnlockPlaylist( p_intf->p_sys, p_playlist );
744 item = treectrl->GetNextChild( root, cookie );
749 /* Find a wxItem from a name (from current) */
750 wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, vlc_bool_t *pb_current_found )
752 wxTreeItemIdValue cookie;
754 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
759 if( treectrl->GetItemText( item).Lower().Contains(
760 search_string.Lower() ) )
762 if( !current.IsOk() || *pb_current_found == VLC_TRUE )
766 else if( current.IsOk() && item == current )
768 *pb_current_found = VLC_TRUE;
771 if( treectrl->ItemHasChildren( item ) )
773 wxTreeItemId search = FindItemByName( item, search_string, current,
780 item = treectrl->GetNextChild( root, cookie);
783 wxTreeItemId dummy; dummy.Unset();
787 /**********************************************************************
788 * Rebuild the playlist
789 **********************************************************************/
790 void Playlist::Rebuild( vlc_bool_t b_root )
792 i_items_to_append = 0;
794 LockPlaylist( p_intf->p_sys, p_playlist );
796 /* Invalidate cache */
798 i_saved_input_id = -1;
800 /* Rebuild the list */
801 source_sel->ClearAll();
802 for( int i = 0 ; i< p_current_viewroot->i_children ; i++ )
804 source_sel->InsertItem( i,
805 wxL2U( p_current_viewroot->pp_children[i]->p_input->psz_name) );
806 source_sel->SetItemData( i,
807 p_current_viewroot->pp_children[i]->i_id );
808 if( p_current_viewroot->pp_children[i] == p_current_treeroot )
809 source_sel->Select( i );
812 /* HACK we should really get new*/
813 treectrl->DeleteAllItems();
814 treectrl->AddRoot( wxU(_("root" )), -1, -1,
815 new PlaylistItem( p_current_treeroot ) );
817 wxTreeItemId root = treectrl->GetRootItem();
818 UpdateNodeChildren( p_current_treeroot, root );
820 int i_count = CountItems( treectrl->GetRootItem() );
822 statusbar->SetStatusText( wxString::Format( wxU(_(
823 "%i items in playlist")), i_count ), 0 );
825 UnlockPlaylist( p_intf->p_sys, p_playlist );
828 void Playlist::ShowPlaylist( bool show )
830 if( show ) Rebuild( VLC_TRUE );
834 /* This function is called on a regular basis */
835 void Playlist::UpdatePlaylist()
839 /* If the playlist isn't show there's no need to update it */
840 if( !IsShown() ) return;
842 if( this->b_need_update )
844 this->b_need_update = VLC_FALSE;
848 /* Updating the playing status every 0.5s is enough */
849 if( i_update_counter % 5 ) return;
852 /*****************************************************************************
854 *****************************************************************************/
855 void Playlist::DeleteTreeItem( wxTreeItemId item )
857 PlaylistItem *p_wxitem;
858 playlist_item_t *p_item;
859 p_wxitem = (PlaylistItem *)treectrl->GetItemData( item );
861 LockPlaylist( p_intf->p_sys, p_playlist );
862 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE );
866 UnlockPlaylist( p_intf->p_sys, p_playlist );
870 if( p_item->i_children == -1 ) DeleteItem( p_item->p_input->i_id );
871 else DeleteNode( p_item );
873 RemoveItem( p_item->i_id );
874 UnlockPlaylist( p_intf->p_sys, p_playlist );
877 void Playlist::DeleteItem( int item_id )
879 playlist_DeleteFromInput( p_playlist, item_id, VLC_TRUE );
882 void Playlist::DeleteNode( playlist_item_t *p_item )
884 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );
887 void Playlist::OnMenuClose( wxCommandEvent& event )
893 void Playlist::OnClose( wxCloseEvent& WXUNUSED(event) )
898 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
904 } formats[] = {//{ _("M3U file"), "*.m3u", "export-m3u" },
905 { _("XSPF playlist"), "*.xspf", "export-xspf"}
908 wxString filter = wxT("");
910 if( playlist_IsEmpty( p_playlist ) )
912 wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
913 wxICON_WARNING | wxOK, this );
917 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
919 filter.Append( wxU(formats[i].psz_desc) );
920 filter.Append( wxT("|") );
921 filter.Append( wxU(formats[i].psz_filter) );
922 filter.Append( wxT("|") );
924 wxFileDialog dialog( this, wxU(_("Save playlist")),
925 wxT(""), wxT(""), filter, wxSAVE );
927 if( dialog.ShowModal() == wxID_OK )
929 if( dialog.GetPath().mb_str(wxConvUTF8) )
931 /* what root should we export? */
932 if( p_playlist->p_root_category->i_children > 0 )
934 playlist_Export( p_playlist, dialog.GetPath().mb_str(wxConvUTF8),
935 p_playlist->p_root_category->pp_children[0],
936 formats[dialog.GetFilterIndex()].psz_module );
943 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
945 wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
946 wxT("All playlists|" EXTENSIONS_PLAYLIST "|XSPF playlist|*.xspf|M3U files|*.m3u"), wxOPEN );
948 if( dialog.ShowModal() == wxID_OK )
950 playlist_Import( p_playlist, dialog.GetPath().mb_str(wxConvUTF8) );
954 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
956 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
960 void Playlist::OnAddDir( wxCommandEvent& WXUNUSED(event) )
962 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY, 0, 0 );
966 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
968 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
972 /********************************************************************
974 ********************************************************************/
975 void Playlist::OnSort( wxCommandEvent& event )
977 PlaylistItem *p_wxitem;
978 p_wxitem = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
980 LockPlaylist( p_intf->p_sys, p_playlist );
981 switch( event.GetId() )
983 case SortTitle_Event:
984 playlist_RecursiveNodeSort( p_playlist,
985 playlist_ItemGetById( p_playlist, p_wxitem->i_id,
987 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
989 case RSortTitle_Event:
990 playlist_RecursiveNodeSort( p_playlist,
991 playlist_ItemGetById( p_playlist, p_wxitem->i_id,
993 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
995 UnlockPlaylist( p_intf->p_sys, p_playlist );
1000 /**********************************************************************
1001 * Search functions (user)
1002 **********************************************************************/
1003 /*void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
1005 search_button->SetDefault();
1008 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
1010 wxString search_string = search_text->GetValue();
1011 PlaylistItem *p_wxroot;
1012 p_wxroot = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
1013 playlist_item_t *p_root = playlist_ItemGetById( p_playlist, p_wxroot->i_id,
1017 char *psz_name = wxFromLocale( search_string );
1018 playlist_LiveSearchUpdate( p_playlist, p_root, psz_name );
1019 Rebuild( VLC_TRUE );
1021 wxLocaleFree( psz_name );
1024 /**********************************************************************
1025 * Selection functions
1026 **********************************************************************/
1027 void Playlist::RecursiveDeleteSelection( wxTreeItemId root )
1029 wxTreeItemIdValue cookie;
1030 wxTreeItemId child = treectrl->GetFirstChild( root, cookie );
1031 wxTreeItemId nextchild;
1032 bool childIsSelected = FALSE;
1033 bool nextchildIsSelected = FALSE;
1035 if( child.IsOk() ) childIsSelected = treectrl->IsSelected( child );
1037 while( child.IsOk() )
1039 nextchild = treectrl->GetNextChild( root, cookie );
1040 if( nextchild.IsOk() )
1041 nextchildIsSelected = treectrl->IsSelected( nextchild );
1042 if( childIsSelected )
1043 DeleteTreeItem( child );
1044 else if( treectrl->ItemHasChildren( child ) )
1045 RecursiveDeleteSelection( child );
1047 childIsSelected = nextchildIsSelected;
1051 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
1053 RecursiveDeleteSelection( treectrl->GetRootItem() );
1056 /**********************************************************************
1057 * Playlist mode functions
1058 **********************************************************************/
1059 void Playlist::OnRandom( wxCommandEvent& event )
1062 val.b_bool = event.IsChecked();
1063 var_Set( p_playlist, "random", val);
1066 void Playlist::OnLoop( wxCommandEvent& event )
1069 val.b_bool = event.IsChecked();
1070 var_Set( p_playlist, "loop", val);
1073 void Playlist::OnRepeat( wxCommandEvent& event )
1076 val.b_bool = event.IsChecked();
1077 var_Set( p_playlist, "repeat", val);
1080 /********************************************************************
1082 ********************************************************************/
1083 void Playlist::OnActivateItem( wxTreeEvent& event )
1085 playlist_item_t *p_item, *p_parent;
1087 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1090 LockPlaylist( p_intf->p_sys, p_playlist );
1094 UnlockPlaylist( p_intf->p_sys, p_playlist );
1097 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE );
1102 if( p_parent == p_current_treeroot )
1104 p_parent = p_parent->p_parent;
1109 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item );
1111 UnlockPlaylist( p_intf->p_sys, p_playlist );
1114 void Playlist::OnKeyDown( wxTreeEvent& event )
1116 long keycode = event.GetKeyCode();
1117 /* Delete selected items */
1118 if( keycode == WXK_BACK || keycode == WXK_DELETE || keycode == WXK_NUMPAD_DELETE )
1120 /* We send a dummy event */
1121 OnDeleteSelection( event );
1123 /* Work around wxWin32 bug */
1124 else if( keycode == WXK_RETURN )
1126 wxArrayTreeItemIds items;
1127 if( treectrl->GetSelections( items ) > 0 )
1130 event.SetItem( items.Item( 0 ) );
1131 OnActivateItem( event );
1140 void Playlist::OnDragItemBegin( wxTreeEvent& event )
1143 draged_tree_item = event.GetItem();
1146 void Playlist::OnDragItemEnd( wxTreeEvent& event )
1148 wxTreeItemId dest_tree_item = event.GetItem();
1150 if( !dest_tree_item.IsOk() ) return;
1152 /* check that we're not trying to move a node into one of its children */
1153 wxTreeItemId parent = dest_tree_item;
1154 while( parent != treectrl->GetRootItem() )
1156 if( draged_tree_item == parent ) return;
1157 parent = treectrl->GetItemParent( parent );
1160 LockPlaylist( p_intf->p_sys, p_playlist );
1162 PlaylistItem *p_wxdrageditem =
1163 (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
1164 PlaylistItem *p_wxdestitem =
1165 (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
1166 if( !p_wxdrageditem || !p_wxdestitem )
1168 UnlockPlaylist( p_intf->p_sys, p_playlist );
1172 playlist_item_t *p_drageditem =
1173 playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id, VLC_TRUE );
1174 playlist_item_t *p_destitem =
1175 playlist_ItemGetById(p_playlist, p_wxdestitem->i_id, VLC_TRUE );
1176 if( !p_drageditem || !p_destitem )
1178 UnlockPlaylist( p_intf->p_sys, p_playlist );
1182 if( p_destitem->i_children == -1 )
1183 /* this is a leaf */
1185 parent = treectrl->GetItemParent( dest_tree_item );
1186 PlaylistItem *p_parent =
1187 (PlaylistItem *)treectrl->GetItemData( parent );
1190 UnlockPlaylist( p_intf->p_sys, p_playlist );
1193 playlist_item_t *p_destitem2 =
1194 playlist_ItemGetById( p_playlist, p_parent->i_id, VLC_TRUE );
1197 UnlockPlaylist( p_intf->p_sys, p_playlist );
1201 for( i = 0; i < p_destitem2->i_children; i++ )
1203 if( p_destitem2->pp_children[i] == p_destitem ) break;
1205 playlist_TreeMove( p_playlist, p_drageditem, p_destitem2, i );
1208 /* this is a node */
1210 playlist_TreeMove( p_playlist, p_drageditem, p_destitem, 0 );
1213 UnlockPlaylist( p_intf->p_sys, p_playlist );
1215 /* FIXME: having this Rebuild() is dirty */
1216 Rebuild( VLC_TRUE );
1219 #if wxUSE_DRAG_AND_DROP
1220 PlaylistFileDropTarget::PlaylistFileDropTarget( Playlist *p ):p( p ){}
1222 /********************************************************************
1223 * File Drag And Drop handling
1224 ********************************************************************/
1225 bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
1226 const wxArrayString& filenames )
1229 playlist_item_t *p_dest;
1231 LockPlaylist( p->p_intf->p_sys, p->p_playlist );
1233 /* find the destination node and position in that node */
1234 const wxPoint pt( x, y );
1235 wxTreeItemId item = p->treectrl->HitTest( pt );
1239 /* We were droped below the last item so we append to the
1241 msg_Err( p->p_playlist, "USE OF P_GENERAL" );
1242 p_dest = p->p_playlist->p_local_category;
1243 i_pos = PLAYLIST_END;
1247 PlaylistItem *p_plitem =
1248 (PlaylistItem *)p->treectrl->GetItemData( item );
1249 p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id, VLC_TRUE );
1251 if( p_dest->i_children == -1 )
1253 /* This is a leaf. Append right after it
1254 * We thus need to find the parrent node and the position of the
1255 * leaf in its children list */
1256 wxTreeItemId parent = p->treectrl->GetItemParent( item );
1257 PlaylistItem *p_parent =
1258 (PlaylistItem *)p->treectrl->GetItemData( parent );
1261 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1264 playlist_item_t *p_node =
1265 playlist_ItemGetById( p->p_playlist, p_parent->i_id, VLC_TRUE );
1268 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1271 for( i_pos = 0; i_pos < p_node->i_children; i_pos++ )
1273 if( p_node->pp_children[i_pos] == p_dest ) break;
1279 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1281 /* Put the items in the playlist node */
1282 for( size_t i = 0; i < filenames.GetCount(); i++ )
1284 char *psz_utf8 = wxDnDFromLocale( filenames[i] );
1285 input_item_t *p_input = input_ItemNew( p->p_playlist,
1286 psz_utf8, psz_utf8 );
1287 playlist_NodeAddInput( p->p_playlist, p_input,
1288 p_dest, PLAYLIST_PREPARSE, i_pos, VLC_FALSE );
1289 wxDnDLocaleFree( psz_utf8 );
1292 /* FIXME: having this Rebuild() is dirty */
1293 p->Rebuild( VLC_TRUE );
1299 /**********************************************************************
1301 **********************************************************************/
1303 void Playlist::OnMenuOpen( wxMenuEvent& event)
1305 #if defined( __WXMSW__ )
1306 # define GetEventObject GetMenu
1309 if( event.GetEventObject() == p_view_menu )
1311 p_view_menu = ViewMenu();
1313 #if defined( __WXMSW__ )
1314 # undef GetEventObject
1318 void Playlist::OnMenuEvent( wxCommandEvent& event )
1320 if( event.GetId() < FirstView_Event )
1325 else if( event.GetId() < LastView_Event )
1327 if( event.GetId() == CategoryView_Event )
1329 p_current_viewroot = p_playlist->p_root_category;
1330 if( p_current_treeroot == p_playlist->p_local_category ||
1331 p_current_treeroot == p_playlist->p_local_onelevel )
1333 p_current_treeroot = p_playlist->p_local_category;
1335 else if( p_current_treeroot == p_playlist->p_ml_category ||
1336 p_current_treeroot == p_playlist->p_ml_onelevel )
1338 p_current_treeroot = p_playlist->p_ml_category;
1341 else if( event.GetId() == OneLevelView_Event )
1343 p_current_viewroot = p_playlist->p_root_onelevel;
1344 if( p_current_treeroot == p_playlist->p_local_category ||
1345 p_current_treeroot == p_playlist->p_local_onelevel )
1347 p_current_treeroot = p_playlist->p_local_onelevel;
1349 else if( p_current_treeroot == p_playlist->p_ml_category ||
1350 p_current_treeroot == p_playlist->p_ml_onelevel )
1352 p_current_treeroot = p_playlist->p_ml_onelevel;
1355 wxCommandEvent event;
1359 else if( event.GetId() >= FirstSD_Event && event.GetId() < LastSD_Event )
1361 if( !playlist_IsServicesDiscoveryLoaded( p_playlist,
1362 pp_sds[event.GetId() - FirstSD_Event] ) )
1364 playlist_ServicesDiscoveryAdd( p_playlist,
1365 pp_sds[event.GetId() - FirstSD_Event] );
1369 //wxMutexGuiLeave();
1370 playlist_ServicesDiscoveryRemove( p_playlist,
1371 pp_sds[event.GetId() - FirstSD_Event] );
1372 //wxMutexGuiEnter();
1377 wxMenu * Playlist::ViewMenu()
1381 p_view_menu = new wxMenu;
1385 wxMenuItemList::Node *node = p_view_menu->GetMenuItems().GetFirst();
1388 wxMenuItem *item = node->GetData();
1389 node = node->GetNext();
1390 p_view_menu->Delete( item );
1394 p_view_menu->Append( CategoryView_Event, wxU(_("Normal") ) );
1395 p_view_menu->Append( OneLevelView_Event, wxU(_("One level") ) );
1399 wxMenu *Playlist::SDMenu()
1401 p_sd_menu = new wxMenu;
1403 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
1407 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1409 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1411 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1414 if( i_number ) pp_sds = (const char **)calloc( i_number, sizeof(void *) );
1417 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1419 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1421 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1423 p_sd_menu->AppendCheckItem( FirstSD_Event + i_number ,
1424 wxU( p_parser->psz_longname ? p_parser->psz_longname :
1425 (p_parser->psz_shortname ?
1426 p_parser->psz_shortname : p_parser->psz_object_name) ) );
1428 /* hack to handle submodules properly */
1430 while( p_parser->pp_shortcuts[++i] != NULL );
1432 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
1433 i>=0?p_parser->pp_shortcuts[i]
1434 :p_parser->psz_object_name ) )
1436 p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
1439 pp_sds[i_number++] = i>=0?p_parser->pp_shortcuts[i]
1440 :p_parser->psz_object_name;
1443 vlc_list_release( p_list );
1448 /*****************************************************************************
1449 * Popup management functions
1450 *****************************************************************************/
1451 void Playlist::OnPopup( wxContextMenuEvent& event )
1453 wxPoint pt = event.GetPosition();
1454 playlist_item_t *p_item;
1456 i_wx_popup_item = treectrl->HitTest( ScreenToClient( pt ) );
1457 if( i_wx_popup_item.IsOk() )
1459 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1461 PlaylistItem *p_wxparent= (PlaylistItem *)treectrl->GetItemData(
1462 treectrl->GetItemParent( i_wx_popup_item ) );
1463 i_popup_item = p_wxitem->i_id;
1464 i_popup_parent = p_wxparent->i_id;
1465 treectrl->SelectItem( i_wx_popup_item );
1467 LockPlaylist( p_intf->p_sys, p_playlist );
1468 p_item = playlist_ItemGetById( p_playlist, i_popup_item, VLC_TRUE );
1472 UnlockPlaylist( p_intf->p_sys, p_playlist );
1475 if( p_item->i_children == -1 )
1477 UnlockPlaylist( p_intf->p_sys, p_playlist );
1478 Playlist::PopupMenu( item_popup,
1479 ScreenToClient( wxGetMousePosition() ) );
1483 UnlockPlaylist( p_intf->p_sys, p_playlist );
1484 Playlist::PopupMenu( node_popup,
1485 ScreenToClient( wxGetMousePosition() ) );
1490 void Playlist::OnPopupPlay( wxCommandEvent& event )
1492 playlist_item_t *p_popup_item, *p_popup_parent;
1493 LockPlaylist( p_intf->p_sys, p_playlist );
1494 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item, VLC_TRUE );
1496 p_popup_parent = p_popup_item;
1497 while( p_popup_parent )
1499 if( p_popup_parent == p_current_treeroot )
1501 p_popup_parent = p_popup_parent->p_parent;
1504 if( p_popup_parent )
1506 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_popup_parent,
1509 UnlockPlaylist( p_intf->p_sys, p_playlist );
1512 void Playlist::OnPopupPreparse( wxCommandEvent& event )
1517 void Playlist::Preparse()
1519 playlist_item_t *p_popup_item;
1520 LockPlaylist( p_intf->p_sys, p_playlist );
1521 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item, VLC_TRUE );
1523 if( p_popup_item != NULL )
1525 if( p_popup_item->i_children == -1 )
1527 playlist_PreparseEnqueue( p_playlist, p_popup_item->p_input );
1532 playlist_item_t *p_parent = p_popup_item;
1533 for( i = 0; i< p_parent->i_children ; i++ )
1536 i_wx_popup_item = FindItem( treectrl->GetRootItem(),
1537 p_parent->pp_children[i]->i_id );
1538 i_popup_item = p_parent->pp_children[i]->i_id;
1543 UnlockPlaylist( p_intf->p_sys, p_playlist );
1546 void Playlist::OnPopupDel( wxCommandEvent& event )
1548 DeleteTreeItem( i_wx_popup_item );
1551 void Playlist::OnPopupSort( wxCommandEvent& event )
1553 PlaylistItem *p_wxitem;
1554 playlist_item_t *p_item;
1556 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1557 LockPlaylist( p_intf->p_sys, p_playlist );
1559 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE );
1560 if( p_item->i_children >= 0 )
1562 playlist_RecursiveNodeSort( p_playlist, p_item,
1563 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
1565 treectrl->DeleteChildren( i_wx_popup_item );
1566 i_saved_id = -1; i_saved_input_id = -1;
1567 UpdateNodeChildren( p_item, i_wx_popup_item );
1570 UnlockPlaylist( p_intf->p_sys, p_playlist );
1573 void Playlist::OnPopupInfo( wxCommandEvent& event )
1575 LockPlaylist( p_intf->p_sys, p_playlist );
1576 playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist,
1581 iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this );
1582 if( iteminfo_dialog->ShowModal() == wxID_OK )
1584 UpdateItem( i_wx_popup_item );
1586 delete iteminfo_dialog;
1588 UnlockPlaylist( p_intf->p_sys, p_playlist );
1591 void Playlist::OnPopupAddNode( wxCommandEvent& event )
1593 wxTextEntryDialog text( NULL, wxU(_( "Please enter node name" )),
1594 wxU(_( "Add node" )), wxU(_( "New node" )) );
1595 if( text.ShowModal() != wxID_OK ) return;
1597 char *psz_name = wxFromLocale( text.GetValue() );
1599 LockPlaylist( p_intf->p_sys, p_playlist );
1601 PlaylistItem *p_wxitem;
1602 playlist_item_t *p_item;
1604 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1606 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE );
1608 playlist_NodeCreate( p_playlist, psz_name, p_item, 0 );
1610 UnlockPlaylist( p_intf->p_sys, p_playlist );
1611 Rebuild( VLC_TRUE );
1613 wxLocaleFree( psz_name );
1616 void Playlist::OnSourceSelected( wxListEvent &event )
1618 int i_id = event.GetData();
1620 if( !p_current_treeroot || i_id != p_current_treeroot->i_id )
1622 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,
1624 if( p_item ) p_current_treeroot = p_item;
1625 Rebuild( VLC_TRUE );
1629 /*****************************************************************************
1630 * Custom events management
1631 *****************************************************************************/
1632 void Playlist::OnPlaylistEvent( wxCommandEvent& event )
1634 switch( event.GetId() )
1636 case UpdateItem_Event:
1637 UpdateItem( event.GetInt() );
1639 case AppendItem_Event:
1640 AppendItem( event );
1642 case RemoveItem_Event:
1643 RemoveItem( event.GetInt() );
1648 /*****************************************************************************
1649 * PlaylistChanged: callback triggered by the intf-change playlist variable
1650 * We don't rebuild the playlist directly here because we don't want the
1651 * caller to block for a too long time.
1652 *****************************************************************************/
1653 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1654 vlc_value_t oval, vlc_value_t nval, void *param )
1656 Playlist *p_playlist_dialog = (Playlist *)param;
1657 p_playlist_dialog->b_need_update = VLC_TRUE;
1661 /*****************************************************************************
1662 * Next: callback triggered by the playlist-current playlist variable
1663 *****************************************************************************/
1664 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1665 vlc_value_t oval, vlc_value_t nval, void *param )
1667 Playlist *p_playlist_dialog = (Playlist *)param;
1669 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1670 event.SetInt( oval.i_int );
1671 p_playlist_dialog->AddPendingEvent( event );
1672 event.SetInt( nval.i_int );
1673 p_playlist_dialog->AddPendingEvent( event );
1678 /*****************************************************************************
1679 * ItemChanged: callback triggered by the item-change playlist variable
1680 *****************************************************************************/
1681 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1682 vlc_value_t old_val, vlc_value_t new_val, void *param )
1684 Playlist *p_playlist_dialog = (Playlist *)param;
1686 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1687 event.SetInt( new_val.i_int );
1688 p_playlist_dialog->AddPendingEvent( event );
1692 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1693 vlc_value_t old_val, vlc_value_t new_val, void *param )
1695 Playlist *p_playlist_dialog = (Playlist *)param;
1697 wxCommandEvent event( wxEVT_PLAYLIST, RemoveItem_Event );
1698 event.SetInt( new_val.i_int );
1699 p_playlist_dialog->AddPendingEvent( event );
1704 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1705 vlc_value_t oval, vlc_value_t nval, void *param )
1707 Playlist *p_playlist_dialog = (Playlist *)param;
1709 playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
1710 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1712 if( ++p_playlist_dialog->i_items_to_append >= 50 )
1714 /* Too many items waiting to be added, it will be quicker to rebuild
1715 * the whole playlist */
1716 p_playlist_dialog->b_need_update = VLC_TRUE;
1720 wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );
1721 event.SetClientData( (void *)p_add );
1722 p_playlist_dialog->AddPendingEvent( event );