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 = false;
219 i_items_to_append = 0;
220 p_playlist = pl_Hold( p_intf );
221 if( p_playlist == NULL ) return;
223 SetIcon( *p_intf->p_sys->p_icon );
226 p_sd_menu = SDMenu();
228 p_current_viewroot = p_playlist->p_root_category;
229 p_current_treeroot = NULL;
233 i_duration_sorted = 0;
235 var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
236 var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
237 var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
239 /* Create our "Manage" menu */
240 wxMenu *manage_menu = new wxMenu;
241 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add File...")) );
242 manage_menu->Append( AddDir_Event, wxU(_("Add &Directory...")) );
243 manage_menu->Append( AddMRL_Event, wxU(_("&Add URL...")) );
244 manage_menu->AppendSeparator();
245 manage_menu->Append( MenuDummy_Event, wxU(_("Services Discovery")),
247 manage_menu->AppendSeparator();
248 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
249 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
250 manage_menu->AppendSeparator();
251 manage_menu->Append( Close_Event, wxU(_("&Close")) );
253 /* Create our "Sort" menu */
254 wxMenu *sort_menu = new wxMenu;
255 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &Title")) );
256 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse Sort by Title")) );
257 sort_menu->AppendSeparator();
258 sort_menu->Append( Randomize_Event, wxU(_("&Shuffle")) );
260 /* Create our "Selection" menu */
261 wxMenu *selection_menu = new wxMenu;
262 selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
264 /* Create our "View" menu */
267 /* Append the freshly created menus to the menu bar */
268 wxMenuBar *menubar = new wxMenuBar();
269 menubar->Append( manage_menu, wxU(_("&Manage")) );
270 menubar->Append( sort_menu, wxU(_("S&ort")) );
271 menubar->Append( selection_menu, wxU(_("&Selection")) );
272 menubar->Append( p_view_menu, wxU(_("&View items") ) );
274 /* Attach the menu bar to the frame */
275 SetMenuBar( menubar );
277 /* Create the popup menu */
278 node_popup = new wxMenu;
279 node_popup->Append( PopupPlay_Event, wxU(_("Play")) );
280 node_popup->Append( PopupPlayThis_Event, wxU(_("Play this Branch")) );
281 node_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
282 node_popup->Append( PopupSort_Event, wxU(_("Sort this Branch")) );
283 node_popup->Append( PopupDel_Event, wxU(_("Delete")) );
284 node_popup->Append( PopupInfo_Event, wxU(_("Info")) );
285 node_popup->Append( PopupAddNode_Event, wxU(_("Add Node")) );
287 item_popup = new wxMenu;
288 item_popup->Append( PopupPlay_Event, wxU(_("Play")) );
289 item_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
290 item_popup->Append( PopupDel_Event, wxU(_("Delete")) );
291 item_popup->Append( PopupInfo_Event, wxU(_("Info")) );
293 /* Create a panel to put everything in */
294 wxPanel *playlist_panel = new wxPanel( this, -1 );
295 playlist_panel->SetAutoLayout( TRUE );
297 /* Create the toolbar */
299 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
301 /* Create the random tool */
302 toolbar->AddTool( Random_Event, wxT(""), wxBitmap(shuffle_on_xpm),
303 wxBitmap(shuffle_on_xpm), wxITEM_CHECK,
304 wxU(_(HELP_SHUFFLE) ) );
305 var_Get( p_intf, "random", &val );
306 toolbar->ToggleTool( Random_Event, val.b_bool );
308 /* Create the Loop tool */
309 toolbar->AddTool( Loop_Event, wxT(""), wxBitmap( loop_xpm),
310 wxBitmap( loop_xpm), wxITEM_CHECK,
311 wxU(_(HELP_LOOP ) ) );
312 var_Get( p_intf, "loop", &val );
313 toolbar->ToggleTool( Loop_Event, val.b_bool );
315 /* Create the Repeat one checkbox */
316 toolbar->AddTool( Repeat_Event, wxT(""), wxBitmap( repeat_xpm),
317 wxBitmap( repeat_xpm), wxITEM_CHECK,
318 wxU(_(HELP_REPEAT ) ) );
319 var_Get( p_intf, "repeat", &val );
320 toolbar->ToggleTool( Repeat_Event, val.b_bool ) ;
322 /* Create the Search Textbox */
323 search_text = new wxTextCtrl( toolbar, SearchText_Event, wxT(""),
324 wxDefaultPosition, wxSize(100, -1),
327 /* Create the search button */
328 search_button = new wxButton( toolbar , Search_Event, wxU(_("Search")) );
330 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
331 wxSize(16, 16), wxBORDER_NONE ) );
332 toolbar->AddControl( search_text );
333 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
334 wxSize(5, 5), wxBORDER_NONE ) );
335 toolbar->AddControl( search_button );
336 search_button->SetDefault();
339 /* Create teh source selector */
340 source_sel = new wxListView( playlist_panel, Source_Event,
341 wxDefaultPosition, wxDefaultSize,
342 wxLC_AUTOARRANGE|wxLC_SINGLE_SEL );
344 /* Create the tree */
345 treectrl = new wxTreeCtrl( playlist_panel, TreeCtrl_Event,
346 wxDefaultPosition, wxDefaultSize,
347 wxTR_HIDE_ROOT | wxTR_LINES_AT_ROOT|
349 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS |
350 wxTR_MULTIPLE | wxTR_EXTENDED );
352 /* Create image list */
353 wxImageList *p_images = new wxImageList( 16 , 16, TRUE );
355 /* FIXME: absolutely needs to be in the right order FIXME */
356 p_images->Add( wxIcon( type_unknown_xpm ) );
357 p_images->Add( wxIcon( type_afile_xpm ) );
358 p_images->Add( wxIcon( type_vfile_xpm ) );
359 p_images->Add( wxIcon( type_directory_xpm ) );
360 p_images->Add( wxIcon( type_disc_xpm ) );
361 p_images->Add( wxIcon( type_cdda_xpm ) );
362 p_images->Add( wxIcon( type_card_xpm ) );
363 p_images->Add( wxIcon( type_net_xpm ) );
364 p_images->Add( wxIcon( type_playlist_xpm ) );
365 p_images->Add( wxIcon( type_node_xpm ) );
366 treectrl->AssignImageList( p_images );
368 /* Reduce font size */
369 wxFont font= treectrl->GetFont();
370 font.SetPointSize(9);
371 treectrl->SetFont( font );
373 wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL );
374 panel_sizer->Add( source_sel, 0, wxALL | wxEXPAND, 5 );
375 panel_sizer->Add( treectrl, 1, wxEXPAND | wxALL, 5 );
376 panel_sizer->Layout();
378 playlist_panel->SetSizerAndFit( panel_sizer );
380 int pi_widths[1] = { -1 };
381 statusbar = CreateStatusBar( 1 );
382 statusbar->SetStatusWidths( 1, pi_widths );
384 #if wxUSE_DRAG_AND_DROP
385 /* Associate drop targets with the playlist */
386 SetDropTarget( new PlaylistFileDropTarget( this ) );
387 menubar->SetDropTarget( new PlaylistFileDropTarget( this ) );
388 toolbar->SetDropTarget( new PlaylistFileDropTarget( this ) );
392 i_saved_input_id = -1;
394 /* Some global changes happened -> Rebuild all */
395 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
397 /* We went to the next item */
398 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
400 /* One item has been updated */
401 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
403 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
404 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
406 /* Update the playlist */
407 p_current_treeroot = p_playlist->p_local_category;
411 Playlist::~Playlist()
415 char **pp_sd = pp_sds;
416 for( ; *pp_sd; pp_sd++ ) free( *pp_sd );
420 if( p_playlist == NULL ) return;
422 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
423 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
424 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
425 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
426 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
427 vlc_object_release( p_playlist );
430 /**********************************************************************
432 **********************************************************************/
435 void Playlist::UpdateNode( playlist_item_t *p_node, wxTreeItemId node )
437 wxTreeItemIdValue cookie;
439 for( int i = 0; i< p_node->i_children ; i++ )
443 child = treectrl->GetFirstChild( node, cookie);
447 child = treectrl->GetNextChild( node, cookie );
452 /* Not enough children */
453 CreateNode( p_node->pp_children[i], node );
454 /* Keep the tree pointer up to date */
455 child = treectrl->GetNextChild( node, cookie );
458 treectrl->SetItemImage( node, p_node->p_input->i_type );
462 /* Creates the node p_node as last child of parent */
463 void Playlist::CreateNode( playlist_item_t *p_node, wxTreeItemId parent )
466 treectrl->AppendItem( parent, wxL2U( p_node->p_input->psz_name ),
467 -1,-1, new PlaylistItem( p_node ) );
468 treectrl->SetItemImage( node, p_node->p_input->i_type );
470 UpdateNodeChildren( p_node, node );
473 /* Update all children (recursively) of this node */
474 void Playlist::UpdateNodeChildren( playlist_item_t *p_node,
477 for( int i = 0; i< p_node->i_children ; i++ )
479 /* Append the item */
480 if( p_node->pp_children[i]->i_children == -1 )
482 if( !(p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG) )
485 treectrl->AppendItem( node,
486 wxL2U( p_node->pp_children[i]->p_input->psz_name ), -1,-1,
487 new PlaylistItem( p_node->pp_children[i]) );
489 UpdateTreeItem( item );
494 CreateNode( p_node->pp_children[i], node );
499 /* Update an item in the tree */
500 void Playlist::UpdateTreeItem( wxTreeItemId item )
502 LockPlaylist( p_intf->p_sys, p_playlist );
503 if( ! item.IsOk() ) return;
505 wxTreeItemData *p_data = treectrl->GetItemData( item );
506 if( !p_data ) return;
508 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
509 ((PlaylistItem *)p_data)->i_id, true );
512 UnlockPlaylist( p_intf->p_sys, p_playlist );
517 wxString duration = wxU( "" );
519 char *psz_artist = input_item_GetArtist( p_item->p_input );
520 char *psz_name = input_item_GetName( p_item->p_input );
522 char psz_duration[MSTRTIME_MAX_SIZE];
523 mtime_t dur = input_item_GetDuration( p_item->p_input );
527 secstotimestr( psz_duration, dur/1000000 );
528 duration.Append( wxU( " ( " ) + wxString( wxU( psz_duration ) ) +
532 if( !psz_artist || !strcmp( psz_artist, "" ) || p_item->p_input->b_fixed_name == true )
534 msg = wxString( wxU( psz_name ) ) + duration;
538 msg = wxString(wxU( psz_artist )) + wxT(" - ") +
539 wxString(wxU(psz_name)) + duration;
543 treectrl->SetItemText( item , msg );
544 treectrl->SetItemImage( item, p_item->p_input->i_type );
546 if( p_playlist->status.p_item == p_item )
548 treectrl->SetItemBold( item, true );
549 while( treectrl->GetItemParent( item ).IsOk() )
551 item = treectrl->GetItemParent( item );
552 if( ! (item == treectrl->GetRootItem() &&
553 treectrl->HasFlag( wxTR_HIDE_ROOT ) ) )
554 treectrl->Expand( item );
559 treectrl->SetItemBold( item, false );
561 UnlockPlaylist( p_intf->p_sys, p_playlist );
564 /* Process a AppendIt em request */
565 void Playlist::AppendItem( wxCommandEvent& event )
567 playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();
568 playlist_item_t *p_item = NULL;
569 wxTreeItemId item, node;
573 /* No need to do anything if the playlist is going to be rebuilt */
574 if( b_need_update ) return;
576 node = FindItem( treectrl->GetRootItem(), p_add->i_node );
577 if( !node.IsOk() ) goto update;
579 p_item = playlist_ItemGetById( p_playlist, p_add->i_item, true );
580 if( !p_item ) goto update;
581 if( (p_item->i_flags & PLAYLIST_DBL_FLAG ) ) goto update;
583 item = FindItem( treectrl->GetRootItem(), p_add->i_item );
584 if( item.IsOk() ) goto update;
586 item = treectrl->AppendItem( node,
587 wxL2U( p_item->p_input->psz_name ), -1,-1,
588 new PlaylistItem( p_item ) );
589 treectrl->SetItemImage( item, p_item->p_input->i_type );
591 if( item.IsOk() && p_item->i_children == -1 )
593 UpdateTreeItem( item );
597 int i_count = CountItems( treectrl->GetRootItem());
598 statusbar->SetStatusText( wxString::Format( wxU(_(
599 "%i items in playlist" ) ), i_count ) );
603 /* Process a updateitem request */
604 void Playlist::UpdateItem( int i )
606 if( i < 0 ) return; /* Sanity check */
607 wxTreeItemId item = FindItemByInput( treectrl->GetRootItem(), i );
610 UpdateTreeItem( item );
614 void Playlist::RemoveItem( int i )
616 if( i <= 0 ) return; /* Sanity check */
617 if( i == i_saved_id ) i_saved_id = -1;
619 /* Hack: always invalidate input item cache */
620 i_saved_input_id = -1;
622 /// \todo Check if it is in the source selector */
624 wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
628 treectrl->Delete( item );
633 /**********************************************************************
634 * Search functions (internal)
635 **********************************************************************/
637 /* Find a wxItem from a playlist id */
638 wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id )
640 return FindItemInner( root, i_id, false );
643 wxTreeItemId Playlist::FindItemByInput( wxTreeItemId root, int i_input_id )
645 return FindItemInner( root, i_input_id, true );
648 wxTreeItemId Playlist::FindItemInner( wxTreeItemId root, int i_id, bool b_byinput )
650 wxTreeItemIdValue cookie;
651 PlaylistItem *p_wxcurrent;
653 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
656 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
660 wxTreeItemId dummy; dummy.Unset(); return dummy;
662 if( b_byinput && i_saved_input_id == i_id )
663 return saved_input_tree_item;
664 if( !b_byinput && i_saved_id == i_id)
665 return saved_tree_item;
669 wxTreeItemId dummy; dummy.Unset(); return dummy;
672 if( !b_byinput && p_wxcurrent->i_id == i_id )
675 saved_tree_item = root;
678 if( b_byinput && p_wxcurrent->i_input_id == i_id )
680 i_saved_input_id = i_id;
681 saved_input_tree_item = root;
687 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
688 if( !b_byinput && p_wxcurrent->i_id == i_id )
691 saved_tree_item = item;
694 else if( b_byinput && p_wxcurrent->i_input_id == i_id )
696 i_saved_input_id = i_id;
697 saved_input_tree_item = item;
700 if( treectrl->ItemHasChildren( item ) )
702 wxTreeItemId search = FindItemInner( item, i_id, b_byinput );
708 saved_tree_item = search;
713 i_saved_input_id = i_id;
714 saved_input_tree_item = search;
720 item = treectrl->GetNextChild( root, cookie );
723 wxTreeItemId dummy; dummy.Unset(); return dummy;
726 int Playlist::CountItems( wxTreeItemId root )
728 wxTreeItemIdValue cookie;
730 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
734 if( treectrl->ItemHasChildren( item ) )
736 count += CountItems( item );
740 playlist_item_t *p_item;
741 LockPlaylist( p_intf->p_sys, p_playlist );
742 p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id, true );
743 if( p_item && p_item->i_children == -1 )
745 UnlockPlaylist( p_intf->p_sys, p_playlist );
747 item = treectrl->GetNextChild( root, cookie );
752 /* Find a wxItem from a name (from current) */
753 wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, bool *pb_current_found )
755 wxTreeItemIdValue cookie;
757 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
762 if( treectrl->GetItemText( item).Lower().Contains(
763 search_string.Lower() ) )
765 if( !current.IsOk() || *pb_current_found == true )
769 else if( current.IsOk() && item == current )
771 *pb_current_found = true;
774 if( treectrl->ItemHasChildren( item ) )
776 wxTreeItemId search = FindItemByName( item, search_string, current,
783 item = treectrl->GetNextChild( root, cookie);
786 wxTreeItemId dummy; dummy.Unset();
790 /**********************************************************************
791 * Rebuild the playlist
792 **********************************************************************/
793 void Playlist::Rebuild( bool b_root )
795 i_items_to_append = 0;
797 LockPlaylist( p_intf->p_sys, p_playlist );
799 /* Invalidate cache */
801 i_saved_input_id = -1;
803 /* Rebuild the list */
804 source_sel->ClearAll();
805 for( int i = 0 ; i< p_current_viewroot->i_children ; i++ )
807 source_sel->InsertItem( i,
808 wxL2U( p_current_viewroot->pp_children[i]->p_input->psz_name) );
809 source_sel->SetItemData( i,
810 p_current_viewroot->pp_children[i]->i_id );
811 if( p_current_viewroot->pp_children[i] == p_current_treeroot )
812 source_sel->Select( i );
815 /* HACK we should really get new*/
816 treectrl->DeleteAllItems();
817 treectrl->AddRoot( wxU(_("root" )), -1, -1,
818 new PlaylistItem( p_current_treeroot ) );
820 wxTreeItemId root = treectrl->GetRootItem();
821 UpdateNodeChildren( p_current_treeroot, root );
823 int i_count = CountItems( treectrl->GetRootItem() );
825 statusbar->SetStatusText( wxString::Format( wxU(_(
826 "%i items in playlist")), i_count ), 0 );
828 UnlockPlaylist( p_intf->p_sys, p_playlist );
831 void Playlist::ShowPlaylist( bool show )
833 if( show ) Rebuild( true );
837 /* This function is called on a regular basis */
838 void Playlist::UpdatePlaylist()
842 /* If the playlist isn't show there's no need to update it */
843 if( !IsShown() ) return;
845 if( this->b_need_update )
847 this->b_need_update = false;
851 /* Updating the playing status every 0.5s is enough */
852 if( i_update_counter % 5 ) return;
855 /*****************************************************************************
857 *****************************************************************************/
858 void Playlist::DeleteTreeItem( wxTreeItemId item )
860 PlaylistItem *p_wxitem;
861 playlist_item_t *p_item;
862 p_wxitem = (PlaylistItem *)treectrl->GetItemData( item );
864 LockPlaylist( p_intf->p_sys, p_playlist );
865 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, true );
869 UnlockPlaylist( p_intf->p_sys, p_playlist );
873 if( p_item->i_children == -1 ) DeleteItem( p_item->p_input->i_id );
874 else DeleteNode( p_item );
876 RemoveItem( p_item->i_id );
877 UnlockPlaylist( p_intf->p_sys, p_playlist );
880 void Playlist::DeleteItem( int item_id )
882 playlist_DeleteFromInput( p_playlist, item_id, true );
885 void Playlist::DeleteNode( playlist_item_t *p_item )
887 playlist_NodeDelete( p_playlist, p_item, true , false );
890 void Playlist::OnMenuClose( wxCommandEvent& event )
896 void Playlist::OnClose( wxCloseEvent& WXUNUSED(event) )
901 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
907 } formats[] = {//{ _("M3U file"), "*.m3u", "export-m3u" },
908 { _("XSPF playlist"), "*.xspf", "export-xspf"}
911 wxString filter = wxT("");
913 if( playlist_IsEmpty( p_playlist ) )
915 wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
916 wxICON_WARNING | wxOK, this );
920 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
922 filter.Append( wxU(formats[i].psz_desc) );
923 filter.Append( wxT("|") );
924 filter.Append( wxU(formats[i].psz_filter) );
925 filter.Append( wxT("|") );
927 wxFileDialog dialog( this, wxU(_("Save playlist")),
928 wxT(""), wxT(""), filter, wxSAVE );
930 if( dialog.ShowModal() == wxID_OK )
932 if( dialog.GetPath().mb_str(wxConvUTF8) )
934 /* what root should we export? */
935 if( p_playlist->p_root_category->i_children > 0 )
937 playlist_Export( p_playlist, dialog.GetPath().mb_str(wxConvUTF8),
938 p_playlist->p_root_category->pp_children[0],
939 formats[dialog.GetFilterIndex()].psz_module );
946 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
948 wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
949 wxT("All playlists|" EXTENSIONS_PLAYLIST "|XSPF playlist|*.xspf|M3U files|*.m3u"), wxOPEN );
951 if( dialog.ShowModal() == wxID_OK )
953 playlist_Import( p_playlist, dialog.GetPath().mb_str(wxConvUTF8) );
957 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
959 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
963 void Playlist::OnAddDir( wxCommandEvent& WXUNUSED(event) )
965 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY, 0, 0 );
969 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
971 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
975 /********************************************************************
977 ********************************************************************/
978 void Playlist::OnSort( wxCommandEvent& event )
980 PlaylistItem *p_wxitem;
981 p_wxitem = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
983 LockPlaylist( p_intf->p_sys, p_playlist );
984 switch( event.GetId() )
986 case SortTitle_Event:
987 playlist_RecursiveNodeSort( p_playlist,
988 playlist_ItemGetById( p_playlist, p_wxitem->i_id,
990 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
992 case RSortTitle_Event:
993 playlist_RecursiveNodeSort( p_playlist,
994 playlist_ItemGetById( p_playlist, p_wxitem->i_id,
996 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
998 UnlockPlaylist( p_intf->p_sys, p_playlist );
1003 /**********************************************************************
1004 * Search functions (user)
1005 **********************************************************************/
1006 /*void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
1008 search_button->SetDefault();
1011 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
1013 wxString search_string = search_text->GetValue();
1014 PlaylistItem *p_wxroot;
1015 p_wxroot = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
1016 playlist_item_t *p_root = playlist_ItemGetById( p_playlist, p_wxroot->i_id,
1020 char *psz_name = wxFromLocale( search_string );
1021 playlist_LiveSearchUpdate( p_playlist, p_root, psz_name );
1024 wxLocaleFree( psz_name );
1027 /**********************************************************************
1028 * Selection functions
1029 **********************************************************************/
1030 void Playlist::RecursiveDeleteSelection( wxTreeItemId root )
1032 wxTreeItemIdValue cookie;
1033 wxTreeItemId child = treectrl->GetFirstChild( root, cookie );
1034 wxTreeItemId nextchild;
1035 bool childIsSelected = FALSE;
1036 bool nextchildIsSelected = FALSE;
1038 if( child.IsOk() ) childIsSelected = treectrl->IsSelected( child );
1040 while( child.IsOk() )
1042 nextchild = treectrl->GetNextChild( root, cookie );
1043 if( nextchild.IsOk() )
1044 nextchildIsSelected = treectrl->IsSelected( nextchild );
1045 if( childIsSelected )
1046 DeleteTreeItem( child );
1047 else if( treectrl->ItemHasChildren( child ) )
1048 RecursiveDeleteSelection( child );
1050 childIsSelected = nextchildIsSelected;
1054 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
1056 RecursiveDeleteSelection( treectrl->GetRootItem() );
1059 /**********************************************************************
1060 * Playlist mode functions
1061 **********************************************************************/
1062 void Playlist::OnRandom( wxCommandEvent& event )
1065 val.b_bool = event.IsChecked();
1066 var_Set( p_playlist, "random", val);
1069 void Playlist::OnLoop( wxCommandEvent& event )
1072 val.b_bool = event.IsChecked();
1073 var_Set( p_playlist, "loop", val);
1076 void Playlist::OnRepeat( wxCommandEvent& event )
1079 val.b_bool = event.IsChecked();
1080 var_Set( p_playlist, "repeat", val);
1083 /********************************************************************
1085 ********************************************************************/
1086 void Playlist::OnActivateItem( wxTreeEvent& event )
1088 playlist_item_t *p_item, *p_parent;
1090 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1093 LockPlaylist( p_intf->p_sys, p_playlist );
1097 UnlockPlaylist( p_intf->p_sys, p_playlist );
1100 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, true );
1105 if( p_parent == p_current_treeroot )
1107 p_parent = p_parent->p_parent;
1112 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, true, p_parent, p_item );
1114 UnlockPlaylist( p_intf->p_sys, p_playlist );
1117 void Playlist::OnKeyDown( wxTreeEvent& event )
1119 long keycode = event.GetKeyCode();
1120 /* Delete selected items */
1121 if( keycode == WXK_BACK || keycode == WXK_DELETE || keycode == WXK_NUMPAD_DELETE )
1123 /* We send a dummy event */
1124 OnDeleteSelection( event );
1126 /* Work around wxWin32 bug */
1127 else if( keycode == WXK_RETURN )
1129 wxArrayTreeItemIds items;
1130 if( treectrl->GetSelections( items ) > 0 )
1133 event.SetItem( items.Item( 0 ) );
1134 OnActivateItem( event );
1143 void Playlist::OnDragItemBegin( wxTreeEvent& event )
1146 draged_tree_item = event.GetItem();
1149 void Playlist::OnDragItemEnd( wxTreeEvent& event )
1151 wxTreeItemId dest_tree_item = event.GetItem();
1153 if( !dest_tree_item.IsOk() ) return;
1155 /* check that we're not trying to move a node into one of its children */
1156 wxTreeItemId parent = dest_tree_item;
1157 while( parent != treectrl->GetRootItem() )
1159 if( draged_tree_item == parent ) return;
1160 parent = treectrl->GetItemParent( parent );
1163 LockPlaylist( p_intf->p_sys, p_playlist );
1165 PlaylistItem *p_wxdrageditem =
1166 (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
1167 PlaylistItem *p_wxdestitem =
1168 (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
1169 if( !p_wxdrageditem || !p_wxdestitem )
1171 UnlockPlaylist( p_intf->p_sys, p_playlist );
1175 playlist_item_t *p_drageditem =
1176 playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id, true );
1177 playlist_item_t *p_destitem =
1178 playlist_ItemGetById(p_playlist, p_wxdestitem->i_id, true );
1179 if( !p_drageditem || !p_destitem )
1181 UnlockPlaylist( p_intf->p_sys, p_playlist );
1185 if( p_destitem->i_children == -1 )
1186 /* this is a leaf */
1188 parent = treectrl->GetItemParent( dest_tree_item );
1189 PlaylistItem *p_parent =
1190 (PlaylistItem *)treectrl->GetItemData( parent );
1193 UnlockPlaylist( p_intf->p_sys, p_playlist );
1196 playlist_item_t *p_destitem2 =
1197 playlist_ItemGetById( p_playlist, p_parent->i_id, true );
1200 UnlockPlaylist( p_intf->p_sys, p_playlist );
1204 for( i = 0; i < p_destitem2->i_children; i++ )
1206 if( p_destitem2->pp_children[i] == p_destitem ) break;
1208 playlist_TreeMove( p_playlist, p_drageditem, p_destitem2, i );
1211 /* this is a node */
1213 playlist_TreeMove( p_playlist, p_drageditem, p_destitem, 0 );
1216 UnlockPlaylist( p_intf->p_sys, p_playlist );
1218 /* FIXME: having this Rebuild() is dirty */
1222 #if wxUSE_DRAG_AND_DROP
1223 PlaylistFileDropTarget::PlaylistFileDropTarget( Playlist *p ):p( p ){}
1225 /********************************************************************
1226 * File Drag And Drop handling
1227 ********************************************************************/
1228 bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
1229 const wxArrayString& filenames )
1232 playlist_item_t *p_dest;
1234 LockPlaylist( p->p_intf->p_sys, p->p_playlist );
1236 /* find the destination node and position in that node */
1237 const wxPoint pt( x, y );
1238 wxTreeItemId item = p->treectrl->HitTest( pt );
1242 /* We were droped below the last item so we append to the
1244 msg_Err( p->p_playlist, "USE OF P_GENERAL" );
1245 p_dest = p->p_playlist->p_local_category;
1246 i_pos = PLAYLIST_END;
1250 PlaylistItem *p_plitem =
1251 (PlaylistItem *)p->treectrl->GetItemData( item );
1252 p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id, true );
1254 if( p_dest->i_children == -1 )
1256 /* This is a leaf. Append right after it
1257 * We thus need to find the parrent node and the position of the
1258 * leaf in its children list */
1259 wxTreeItemId parent = p->treectrl->GetItemParent( item );
1260 PlaylistItem *p_parent =
1261 (PlaylistItem *)p->treectrl->GetItemData( parent );
1264 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1267 playlist_item_t *p_node =
1268 playlist_ItemGetById( p->p_playlist, p_parent->i_id, true );
1271 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1274 for( i_pos = 0; i_pos < p_node->i_children; i_pos++ )
1276 if( p_node->pp_children[i_pos] == p_dest ) break;
1282 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1284 /* Put the items in the playlist node */
1285 for( size_t i = 0; i < filenames.GetCount(); i++ )
1287 char *psz_utf8 = wxDnDFromLocale( filenames[i] );
1288 input_item_t *p_input = input_item_New( p->p_playlist,
1289 psz_utf8, psz_utf8 );
1290 int i_ret = ( playlist_BothAddInput( p->p_playlist, p_input, p_dest,
1291 PLAYLIST_PREPARSE, i_pos, NULL, NULL, pl_Unlocked ) != VLC_SUCCESS );
1292 vlc_gc_decref( p_input );
1293 wxDnDLocaleFree( psz_utf8 );
1294 if( i_ret != VLC_SUCCESS )
1298 /* FIXME: having this Rebuild() is dirty */
1305 /**********************************************************************
1307 **********************************************************************/
1309 void Playlist::OnMenuOpen( wxMenuEvent& event)
1311 #if defined( __WXMSW__ )
1312 # define GetEventObject GetMenu
1315 if( event.GetEventObject() == p_view_menu )
1317 p_view_menu = ViewMenu();
1319 #if defined( __WXMSW__ )
1320 # undef GetEventObject
1324 void Playlist::OnMenuEvent( wxCommandEvent& event )
1326 if( event.GetId() < FirstView_Event )
1331 else if( event.GetId() < LastView_Event )
1333 if( event.GetId() == CategoryView_Event )
1335 p_current_viewroot = p_playlist->p_root_category;
1336 if( p_current_treeroot == p_playlist->p_local_category ||
1337 p_current_treeroot == p_playlist->p_local_onelevel )
1339 p_current_treeroot = p_playlist->p_local_category;
1341 else if( p_current_treeroot == p_playlist->p_ml_category ||
1342 p_current_treeroot == p_playlist->p_ml_onelevel )
1344 p_current_treeroot = p_playlist->p_ml_category;
1347 else if( event.GetId() == OneLevelView_Event )
1349 p_current_viewroot = p_playlist->p_root_onelevel;
1350 if( p_current_treeroot == p_playlist->p_local_category ||
1351 p_current_treeroot == p_playlist->p_local_onelevel )
1353 p_current_treeroot = p_playlist->p_local_onelevel;
1355 else if( p_current_treeroot == p_playlist->p_ml_category ||
1356 p_current_treeroot == p_playlist->p_ml_onelevel )
1358 p_current_treeroot = p_playlist->p_ml_onelevel;
1361 wxCommandEvent event;
1365 else if( event.GetId() >= FirstSD_Event && event.GetId() < LastSD_Event )
1367 if( !playlist_IsServicesDiscoveryLoaded( p_playlist,
1368 pp_sds[event.GetId() - FirstSD_Event] ) )
1370 playlist_ServicesDiscoveryAdd( p_playlist,
1371 pp_sds[event.GetId() - FirstSD_Event] );
1375 //wxMutexGuiLeave();
1376 playlist_ServicesDiscoveryRemove( p_playlist,
1377 pp_sds[event.GetId() - FirstSD_Event] );
1378 //wxMutexGuiEnter();
1383 wxMenu * Playlist::ViewMenu()
1387 p_view_menu = new wxMenu;
1391 wxMenuItemList::Node *node = p_view_menu->GetMenuItems().GetFirst();
1394 wxMenuItem *item = node->GetData();
1395 node = node->GetNext();
1396 p_view_menu->Delete( item );
1400 p_view_menu->Append( CategoryView_Event, wxU(_("Normal") ) );
1401 p_view_menu->Append( OneLevelView_Event, wxU(_("One level") ) );
1405 wxMenu *Playlist::SDMenu()
1407 p_sd_menu = new wxMenu;
1409 char **ppsz_longnames;
1410 char **ppsz_names = services_discovery_GetServicesNames( p_playlist,
1415 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
1419 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
1421 p_sd_menu->AppendCheckItem( FirstSD_Event + i_number++ ,
1422 wxU( *ppsz_longname ) );
1424 if( playlist_IsServicesDiscoveryLoaded( p_playlist, *ppsz_name ) )
1425 p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
1427 free( *ppsz_longname );
1429 pp_sds = ppsz_names;
1430 free( ppsz_longnames );
1435 /*****************************************************************************
1436 * Popup management functions
1437 *****************************************************************************/
1438 void Playlist::OnPopup( wxContextMenuEvent& event )
1440 wxPoint pt = event.GetPosition();
1441 playlist_item_t *p_item;
1443 i_wx_popup_item = treectrl->HitTest( ScreenToClient( pt ) );
1444 if( i_wx_popup_item.IsOk() )
1446 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1448 PlaylistItem *p_wxparent= (PlaylistItem *)treectrl->GetItemData(
1449 treectrl->GetItemParent( i_wx_popup_item ) );
1450 i_popup_item = p_wxitem->i_id;
1451 i_popup_parent = p_wxparent->i_id;
1452 treectrl->SelectItem( i_wx_popup_item );
1454 LockPlaylist( p_intf->p_sys, p_playlist );
1455 p_item = playlist_ItemGetById( p_playlist, i_popup_item, true );
1459 UnlockPlaylist( p_intf->p_sys, p_playlist );
1462 if( p_item->i_children == -1 )
1464 UnlockPlaylist( p_intf->p_sys, p_playlist );
1465 Playlist::PopupMenu( item_popup,
1466 ScreenToClient( wxGetMousePosition() ) );
1470 UnlockPlaylist( p_intf->p_sys, p_playlist );
1471 Playlist::PopupMenu( node_popup,
1472 ScreenToClient( wxGetMousePosition() ) );
1477 void Playlist::OnPopupPlay( wxCommandEvent& event )
1479 playlist_item_t *p_popup_item, *p_popup_parent;
1480 LockPlaylist( p_intf->p_sys, p_playlist );
1481 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item, true );
1483 p_popup_parent = p_popup_item;
1484 while( p_popup_parent )
1486 if( p_popup_parent == p_current_treeroot )
1488 p_popup_parent = p_popup_parent->p_parent;
1491 if( p_popup_parent )
1493 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, true, p_popup_parent,
1496 UnlockPlaylist( p_intf->p_sys, p_playlist );
1499 void Playlist::OnPopupPreparse( wxCommandEvent& event )
1504 void Playlist::Preparse()
1506 playlist_item_t *p_popup_item;
1507 LockPlaylist( p_intf->p_sys, p_playlist );
1508 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item, true );
1510 if( p_popup_item != NULL )
1512 if( p_popup_item->i_children == -1 )
1514 playlist_PreparseEnqueue( p_playlist, p_popup_item->p_input, pl_Unlocked );
1519 playlist_item_t *p_parent = p_popup_item;
1520 for( i = 0; i< p_parent->i_children ; i++ )
1523 i_wx_popup_item = FindItem( treectrl->GetRootItem(),
1524 p_parent->pp_children[i]->i_id );
1525 i_popup_item = p_parent->pp_children[i]->i_id;
1530 UnlockPlaylist( p_intf->p_sys, p_playlist );
1533 void Playlist::OnPopupDel( wxCommandEvent& event )
1535 DeleteTreeItem( i_wx_popup_item );
1538 void Playlist::OnPopupSort( wxCommandEvent& event )
1540 PlaylistItem *p_wxitem;
1541 playlist_item_t *p_item;
1543 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1544 LockPlaylist( p_intf->p_sys, p_playlist );
1546 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, true );
1547 if( p_item->i_children >= 0 )
1549 playlist_RecursiveNodeSort( p_playlist, p_item,
1550 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
1552 treectrl->DeleteChildren( i_wx_popup_item );
1553 i_saved_id = -1; i_saved_input_id = -1;
1554 UpdateNodeChildren( p_item, i_wx_popup_item );
1557 UnlockPlaylist( p_intf->p_sys, p_playlist );
1560 void Playlist::OnPopupInfo( wxCommandEvent& event )
1562 LockPlaylist( p_intf->p_sys, p_playlist );
1563 playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist,
1568 iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this );
1569 if( iteminfo_dialog->ShowModal() == wxID_OK )
1571 UpdateItem( i_wx_popup_item );
1573 delete iteminfo_dialog;
1575 UnlockPlaylist( p_intf->p_sys, p_playlist );
1578 void Playlist::OnPopupAddNode( wxCommandEvent& event )
1580 wxTextEntryDialog text( NULL, wxU(_( "Please enter node name" )),
1581 wxU(_( "Add node" )), wxU(_( "New node" )) );
1582 if( text.ShowModal() != wxID_OK ) return;
1584 char *psz_name = wxFromLocale( text.GetValue() );
1586 LockPlaylist( p_intf->p_sys, p_playlist );
1588 PlaylistItem *p_wxitem;
1589 playlist_item_t *p_item;
1591 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1593 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, true );
1595 playlist_NodeCreate( p_playlist, psz_name, p_item, 0, NULL );
1597 UnlockPlaylist( p_intf->p_sys, p_playlist );
1600 wxLocaleFree( psz_name );
1603 void Playlist::OnSourceSelected( wxListEvent &event )
1605 int i_id = event.GetData();
1607 if( !p_current_treeroot || i_id != p_current_treeroot->i_id )
1609 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,
1611 if( p_item ) p_current_treeroot = p_item;
1616 /*****************************************************************************
1617 * Custom events management
1618 *****************************************************************************/
1619 void Playlist::OnPlaylistEvent( wxCommandEvent& event )
1621 switch( event.GetId() )
1623 case UpdateItem_Event:
1624 UpdateItem( event.GetInt() );
1626 case AppendItem_Event:
1627 AppendItem( event );
1629 case RemoveItem_Event:
1630 RemoveItem( event.GetInt() );
1635 /*****************************************************************************
1636 * PlaylistChanged: callback triggered by the intf-change playlist variable
1637 * We don't rebuild the playlist directly here because we don't want the
1638 * caller to block for a too long time.
1639 *****************************************************************************/
1640 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1641 vlc_value_t oval, vlc_value_t nval, void *param )
1643 Playlist *p_playlist_dialog = (Playlist *)param;
1644 p_playlist_dialog->b_need_update = true;
1648 /*****************************************************************************
1649 * Next: callback triggered by the playlist-current playlist variable
1650 *****************************************************************************/
1651 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1652 vlc_value_t oval, vlc_value_t nval, void *param )
1654 Playlist *p_playlist_dialog = (Playlist *)param;
1656 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1657 event.SetInt( oval.i_int );
1658 p_playlist_dialog->AddPendingEvent( event );
1659 event.SetInt( nval.i_int );
1660 p_playlist_dialog->AddPendingEvent( event );
1665 /*****************************************************************************
1666 * ItemChanged: callback triggered by the item-change playlist variable
1667 *****************************************************************************/
1668 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1669 vlc_value_t old_val, vlc_value_t new_val, void *param )
1671 Playlist *p_playlist_dialog = (Playlist *)param;
1673 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1674 event.SetInt( new_val.i_int );
1675 p_playlist_dialog->AddPendingEvent( event );
1679 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1680 vlc_value_t old_val, vlc_value_t new_val, void *param )
1682 Playlist *p_playlist_dialog = (Playlist *)param;
1684 wxCommandEvent event( wxEVT_PLAYLIST, RemoveItem_Event );
1685 event.SetInt( new_val.i_int );
1686 p_playlist_dialog->AddPendingEvent( event );
1691 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1692 vlc_value_t oval, vlc_value_t nval, void *param )
1694 Playlist *p_playlist_dialog = (Playlist *)param;
1696 playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
1697 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1699 if( ++p_playlist_dialog->i_items_to_append >= 50 )
1701 /* Too many items waiting to be added, it will be quicker to rebuild
1702 * the whole playlist */
1703 p_playlist_dialog->b_need_update = true;
1707 wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );
1708 event.SetClientData( (void *)p_add );
1709 p_playlist_dialog->AddPendingEvent( event );