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>
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 msg_Err(p_intf, "p_playlist= 0x%x", p_playlist);
223 if( p_playlist == NULL ) return;
225 SetIcon( *p_intf->p_sys->p_icon );
228 p_sd_menu = SDMenu();
230 // i_current_view = VIEW_ONELEVEL;
231 p_current_viewroot = p_playlist->p_root_onelevel;
232 p_current_treeroot = p_playlist->p_local_onelevel;
236 i_duration_sorted = 0;
238 var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
239 var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
240 var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
242 /* Create our "Manage" menu */
243 wxMenu *manage_menu = new wxMenu;
244 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add File...")) );
245 manage_menu->Append( AddDir_Event, wxU(_("Add &Directory...")) );
246 manage_menu->Append( AddMRL_Event, wxU(_("&Add URL...")) );
247 manage_menu->AppendSeparator();
248 manage_menu->Append( MenuDummy_Event, wxU(_("Services Discovery")),
250 manage_menu->AppendSeparator();
251 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
252 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
253 manage_menu->AppendSeparator();
254 manage_menu->Append( Close_Event, wxU(_("&Close")) );
256 /* Create our "Sort" menu */
257 wxMenu *sort_menu = new wxMenu;
258 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &Title")) );
259 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse Sort by Title")) );
260 sort_menu->AppendSeparator();
261 sort_menu->Append( Randomize_Event, wxU(_("&Shuffle")) );
263 /* Create our "Selection" menu */
264 wxMenu *selection_menu = new wxMenu;
265 selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
267 /* Create our "View" menu */
270 /* Append the freshly created menus to the menu bar */
271 wxMenuBar *menubar = new wxMenuBar();
272 menubar->Append( manage_menu, wxU(_("&Manage")) );
273 menubar->Append( sort_menu, wxU(_("S&ort")) );
274 menubar->Append( selection_menu, wxU(_("&Selection")) );
275 menubar->Append( p_view_menu, wxU(_("&View items") ) );
277 /* Attach the menu bar to the frame */
278 SetMenuBar( menubar );
280 /* Create the popup menu */
281 node_popup = new wxMenu;
282 node_popup->Append( PopupPlay_Event, wxU(_("Play")) );
283 node_popup->Append( PopupPlayThis_Event, wxU(_("Play this Branch")) );
284 node_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
285 node_popup->Append( PopupSort_Event, wxU(_("Sort this Branch")) );
286 node_popup->Append( PopupDel_Event, wxU(_("Delete")) );
287 node_popup->Append( PopupInfo_Event, wxU(_("Info")) );
288 node_popup->Append( PopupAddNode_Event, wxU(_("Add Node")) );
290 item_popup = new wxMenu;
291 item_popup->Append( PopupPlay_Event, wxU(_("Play")) );
292 item_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
293 item_popup->Append( PopupDel_Event, wxU(_("Delete")) );
294 item_popup->Append( PopupInfo_Event, wxU(_("Info")) );
296 /* Create a panel to put everything in */
297 wxPanel *playlist_panel = new wxPanel( this, -1 );
298 playlist_panel->SetAutoLayout( TRUE );
300 /* Create the toolbar */
302 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
304 /* Create the random tool */
305 toolbar->AddTool( Random_Event, wxT(""), wxBitmap(shuffle_on_xpm),
306 wxBitmap(shuffle_on_xpm), wxITEM_CHECK,
307 wxU(_(HELP_SHUFFLE) ) );
308 var_Get( p_intf, "random", &val );
309 toolbar->ToggleTool( Random_Event, val.b_bool );
311 /* Create the Loop tool */
312 toolbar->AddTool( Loop_Event, wxT(""), wxBitmap( loop_xpm),
313 wxBitmap( loop_xpm), wxITEM_CHECK,
314 wxU(_(HELP_LOOP ) ) );
315 var_Get( p_intf, "loop", &val );
316 toolbar->ToggleTool( Loop_Event, val.b_bool );
318 /* Create the Repeat one checkbox */
319 toolbar->AddTool( Repeat_Event, wxT(""), wxBitmap( repeat_xpm),
320 wxBitmap( repeat_xpm), wxITEM_CHECK,
321 wxU(_(HELP_REPEAT ) ) );
322 var_Get( p_intf, "repeat", &val );
323 toolbar->ToggleTool( Repeat_Event, val.b_bool ) ;
325 /* Create the Search Textbox */
326 search_text = new wxTextCtrl( toolbar, SearchText_Event, wxT(""),
327 wxDefaultPosition, wxSize(100, -1),
330 /* Create the search button */
331 search_button = new wxButton( toolbar , Search_Event, wxU(_("Search")) );
333 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
334 wxSize(16, 16), wxBORDER_NONE ) );
335 toolbar->AddControl( search_text );
336 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
337 wxSize(5, 5), wxBORDER_NONE ) );
338 toolbar->AddControl( search_button );
339 search_button->SetDefault();
342 /* Create teh source selector */
343 source_sel = new wxListCtrl( playlist_panel, Source_Event,
344 wxDefaultPosition, wxDefaultSize,
345 wxLC_AUTOARRANGE|wxLC_SINGLE_SEL );
347 /* Create the tree */
348 treectrl = new wxTreeCtrl( playlist_panel, TreeCtrl_Event,
349 wxDefaultPosition, wxDefaultSize,
350 wxTR_HIDE_ROOT | wxTR_LINES_AT_ROOT|
352 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS |
353 wxTR_MULTIPLE | wxTR_EXTENDED );
355 /* Create image list */
356 wxImageList *p_images = new wxImageList( 16 , 16, TRUE );
358 /* FIXME: absolutely needs to be in the right order FIXME */
359 p_images->Add( wxIcon( type_unknown_xpm ) );
360 p_images->Add( wxIcon( type_afile_xpm ) );
361 p_images->Add( wxIcon( type_vfile_xpm ) );
362 p_images->Add( wxIcon( type_directory_xpm ) );
363 p_images->Add( wxIcon( type_disc_xpm ) );
364 p_images->Add( wxIcon( type_cdda_xpm ) );
365 p_images->Add( wxIcon( type_card_xpm ) );
366 p_images->Add( wxIcon( type_net_xpm ) );
367 p_images->Add( wxIcon( type_playlist_xpm ) );
368 p_images->Add( wxIcon( type_node_xpm ) );
369 treectrl->AssignImageList( p_images );
371 treectrl->AddRoot( wxU(_("root" )), -1, -1, NULL );
373 /* Reduce font size */
374 wxFont font= treectrl->GetFont();
375 font.SetPointSize(9);
376 treectrl->SetFont( font );
378 wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL );
379 panel_sizer->Add( source_sel, 0, wxALL | wxEXPAND, 5 );
380 panel_sizer->Add( treectrl, 1, wxEXPAND | wxALL, 5 );
381 panel_sizer->Layout();
383 playlist_panel->SetSizerAndFit( panel_sizer );
385 int pi_widths[1] = { -1 };
386 statusbar = CreateStatusBar( 1 );
387 statusbar->SetStatusWidths( 1, pi_widths );
389 #if wxUSE_DRAG_AND_DROP
390 /* Associate drop targets with the playlist */
391 SetDropTarget( new PlaylistFileDropTarget( this ) );
392 menubar->SetDropTarget( new PlaylistFileDropTarget( this ) );
393 toolbar->SetDropTarget( new PlaylistFileDropTarget( this ) );
397 i_saved_input_id = -1;
399 /* Some global changes happened -> Rebuild all */
400 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
402 /* We went to the next item */
403 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
405 /* One item has been updated */
406 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
408 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
409 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
411 /* Update the playlist */
416 Playlist::~Playlist()
418 if( pp_sds != NULL ) free( pp_sds );
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 );
512 UnlockPlaylist( p_intf->p_sys, p_playlist );
517 wxString duration = wxU( "" );
520 if( p_item->p_input->p_meta )
522 psz_author= p_item->p_input->p_meta->psz_artist ?
523 strdup( p_item->p_input->p_meta->psz_artist ) :
527 psz_author = strdup( "" );
529 char psz_duration[MSTRTIME_MAX_SIZE];
530 mtime_t dur = p_item->p_input->i_duration;
534 secstotimestr( psz_duration, dur/1000000 );
535 duration.Append( wxU( " ( " ) + wxString( wxU( psz_duration ) ) +
539 if( !strcmp( psz_author, "" ) || p_item->p_input->b_fixed_name == VLC_TRUE )
541 msg = wxString( wxU( p_item->p_input->psz_name ) ) + duration;
545 msg = wxString(wxU( psz_author )) + wxT(" - ") +
546 wxString(wxU(p_item->p_input->psz_name)) + duration;
549 treectrl->SetItemText( item , msg );
550 treectrl->SetItemImage( item, p_item->p_input->i_type );
552 if( p_playlist->status.p_item == p_item )
554 treectrl->SetItemBold( item, true );
555 while( treectrl->GetItemParent( item ).IsOk() )
557 item = treectrl->GetItemParent( item );
558 if( ! (item == treectrl->GetRootItem() &&
559 treectrl->HasFlag( wxTR_HIDE_ROOT ) ) )
560 treectrl->Expand( item );
565 treectrl->SetItemBold( item, false );
567 UnlockPlaylist( p_intf->p_sys, p_playlist );
570 /* Process a AppendIt em request */
571 void Playlist::AppendItem( wxCommandEvent& event )
573 playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();
574 playlist_item_t *p_item = NULL;
575 wxTreeItemId item, node;
579 /* No need to do anything if the playlist is going to be rebuilt */
580 if( b_need_update ) return;
582 node = FindItem( treectrl->GetRootItem(), p_add->i_node );
583 if( !node.IsOk() ) goto update;
585 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
586 if( !p_item ) goto update;
587 if( (p_item->i_flags & PLAYLIST_DBL_FLAG ) ) goto update;
589 item = FindItem( treectrl->GetRootItem(), p_add->i_item );
590 if( item.IsOk() ) goto update;
592 item = treectrl->AppendItem( node,
593 wxL2U( p_item->p_input->psz_name ), -1,-1,
594 new PlaylistItem( p_item ) );
595 treectrl->SetItemImage( item, p_item->p_input->i_type );
597 if( item.IsOk() && p_item->i_children == -1 )
599 UpdateTreeItem( item );
603 int i_count = CountItems( treectrl->GetRootItem());
604 statusbar->SetStatusText( wxString::Format( wxU(_(
605 "%i items in playlist" ) ), i_count ) );
609 /* Process a updateitem request */
610 void Playlist::UpdateItem( int i )
612 if( i < 0 ) return; /* Sanity check */
613 wxTreeItemId item = FindItemByInput( treectrl->GetRootItem(), i );
616 UpdateTreeItem( item );
620 void Playlist::RemoveItem( int i )
622 if( i <= 0 ) return; /* Sanity check */
623 if( i == i_saved_id ) i_saved_id = -1;
625 /* Hack: always invalidate input item cache */
626 i_saved_input_id = -1;
628 /// \todo Check if it is in the source selector */
630 wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
634 treectrl->Delete( item );
639 /**********************************************************************
640 * Search functions (internal)
641 **********************************************************************/
643 /* Find a wxItem from a playlist id */
644 wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id )
646 return FindItemInner( root, i_id, false );
649 wxTreeItemId Playlist::FindItemByInput( wxTreeItemId root, int i_input_id )
651 return FindItemInner( root, i_input_id, true );
654 wxTreeItemId Playlist::FindItemInner( wxTreeItemId root, int i_id, bool b_byinput )
656 wxTreeItemIdValue cookie;
657 PlaylistItem *p_wxcurrent;
659 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
662 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
666 wxTreeItemId dummy; dummy.Unset(); return dummy;
668 if( b_byinput && i_saved_input_id == i_id )
669 return saved_input_tree_item;
670 if( !b_byinput && i_saved_id == i_id)
671 return saved_tree_item;
675 wxTreeItemId dummy; dummy.Unset(); return dummy;
678 if( !b_byinput && p_wxcurrent->i_id == i_id )
681 saved_tree_item = root;
684 if( b_byinput && p_wxcurrent->i_input_id == i_id )
686 i_saved_input_id = i_id;
687 saved_input_tree_item = root;
693 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
694 if( !b_byinput && p_wxcurrent->i_id == i_id )
697 saved_tree_item = item;
700 else if( b_byinput && p_wxcurrent->i_input_id == i_id )
702 i_saved_input_id = i_id;
703 saved_input_tree_item = item;
706 if( treectrl->ItemHasChildren( item ) )
708 wxTreeItemId search = FindItemInner( item, i_id, b_byinput );
714 saved_tree_item = search;
719 i_saved_input_id = i_id;
720 saved_input_tree_item = search;
726 item = treectrl->GetNextChild( root, cookie );
729 wxTreeItemId dummy; dummy.Unset(); return dummy;
732 int Playlist::CountItems( wxTreeItemId root )
734 wxTreeItemIdValue cookie;
736 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
740 if( treectrl->ItemHasChildren( item ) )
742 count += CountItems( item );
746 playlist_item_t *p_item;
747 LockPlaylist( p_intf->p_sys, p_playlist );
748 p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id );
749 if( p_item && p_item->i_children == -1 )
751 UnlockPlaylist( p_intf->p_sys, p_playlist );
753 item = treectrl->GetNextChild( root, cookie );
758 /* Find a wxItem from a name (from current) */
759 wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, vlc_bool_t *pb_current_found )
761 wxTreeItemIdValue cookie;
763 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
768 if( treectrl->GetItemText( item).Lower().Contains(
769 search_string.Lower() ) )
771 if( !current.IsOk() || *pb_current_found == VLC_TRUE )
775 else if( current.IsOk() && item == current )
777 *pb_current_found = VLC_TRUE;
780 if( treectrl->ItemHasChildren( item ) )
782 wxTreeItemId search = FindItemByName( item, search_string, current,
789 item = treectrl->GetNextChild( root, cookie);
792 wxTreeItemId dummy; dummy.Unset();
796 /**********************************************************************
797 * Rebuild the playlist
798 **********************************************************************/
799 void Playlist::Rebuild( vlc_bool_t b_root )
801 i_items_to_append = 0;
803 /* We can remove the callbacks before locking, anyway, we won't
807 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
808 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
809 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
810 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
811 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
813 /* ...and rebuild it */
814 LockPlaylist( p_intf->p_sys, p_playlist );
816 /* Invalidate cache */
818 i_saved_input_id = -1;
820 /* Rebuild the list */
821 source_sel->ClearAll();
822 for( int i = 0 ; i< p_current_viewroot->i_children ; i++ )
824 source_sel->InsertItem( i,
825 wxL2U( p_current_viewroot->pp_children[i]->p_input->psz_name) );
826 source_sel->SetItemData( i,
827 p_current_viewroot->pp_children[i]->i_id );
828 if( p_current_viewroot->pp_children[i] == p_current_treeroot )
829 source_sel->Select( i );
832 /* HACK we should really get new*/
833 treectrl->DeleteAllItems();
834 treectrl->AddRoot( wxU(_("root" )), -1, -1,
835 new PlaylistItem( p_current_treeroot ) );
837 wxTreeItemId root = treectrl->GetRootItem();
838 //UpdateNode( p_current_treeroot, root );
839 //CreateNode( p_current_treeroot, root );
840 UpdateNodeChildren( p_current_treeroot, root );
842 int i_count = CountItems( treectrl->GetRootItem() );
844 statusbar->SetStatusText( wxString::Format( wxU(_(
845 "%i items in playlist")), i_count ), 0 );
849 /* Put callbacks back online */
850 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
851 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
852 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
853 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
854 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
856 UnlockPlaylist( p_intf->p_sys, p_playlist );
860 void Playlist::ShowPlaylist( bool show )
862 if( show ) Rebuild( VLC_TRUE );
866 /* This function is called on a regular basis */
867 void Playlist::UpdatePlaylist()
871 /* If the playlist isn't show there's no need to update it */
872 if( !IsShown() ) return;
874 if( this->b_need_update )
876 this->b_need_update = VLC_FALSE;
880 /* Updating the playing status every 0.5s is enough */
881 if( i_update_counter % 5 ) return;
884 /*****************************************************************************
886 *****************************************************************************/
887 void Playlist::DeleteTreeItem( wxTreeItemId item )
889 PlaylistItem *p_wxitem;
890 playlist_item_t *p_item;
891 p_wxitem = (PlaylistItem *)treectrl->GetItemData( item );
893 LockPlaylist( p_intf->p_sys, p_playlist );
894 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
898 UnlockPlaylist( p_intf->p_sys, p_playlist );
902 if( p_item->i_children == -1 ) DeleteItem( p_item->p_input->i_id );
903 else DeleteNode( p_item );
905 RemoveItem( p_item->i_id );
906 UnlockPlaylist( p_intf->p_sys, p_playlist );
909 void Playlist::DeleteItem( int item_id )
911 playlist_DeleteAllFromInput( p_playlist, item_id );
914 void Playlist::DeleteNode( playlist_item_t *p_item )
916 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );
919 void Playlist::OnMenuClose( wxCommandEvent& event )
925 void Playlist::OnClose( wxCloseEvent& WXUNUSED(event) )
930 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
936 } formats[] = {//{ _("M3U file"), "*.m3u", "export-m3u" },
937 { _("XSPF playlist"), "*.xspf", "export-xspf"}
940 wxString filter = wxT("");
942 if( p_playlist->i_size == 0 )
944 wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
945 wxICON_WARNING | wxOK, this );
949 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
951 filter.Append( wxU(formats[i].psz_desc) );
952 filter.Append( wxT("|") );
953 filter.Append( wxU(formats[i].psz_filter) );
954 filter.Append( wxT("|") );
956 wxFileDialog dialog( this, wxU(_("Save playlist")),
957 wxT(""), wxT(""), filter, wxSAVE );
959 if( dialog.ShowModal() == wxID_OK )
961 if( dialog.GetPath().mb_str() )
963 /* what root should we export? */
964 if( p_playlist->p_root_category->i_children > 0 )
966 playlist_Export( p_playlist, dialog.GetPath().mb_str(),
967 p_playlist->p_root_category->pp_children[0],
968 formats[dialog.GetFilterIndex()].psz_module );
975 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
977 wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
978 wxT("All playlists|" EXTENSIONS_PLAYLIST "|XSPF playlist|*.xspf|M3U files|*.m3u"), wxOPEN );
980 if( dialog.ShowModal() == wxID_OK )
982 playlist_Import( p_playlist, dialog.GetPath().mb_str(),
983 /*FIXME: where do we want to insert ? */
984 p_playlist->p_local_category, VLC_TRUE );
988 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
990 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
994 void Playlist::OnAddDir( wxCommandEvent& WXUNUSED(event) )
996 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY, 0, 0 );
1000 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
1002 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
1006 /********************************************************************
1008 ********************************************************************/
1009 void Playlist::OnSort( wxCommandEvent& event )
1011 PlaylistItem *p_wxitem;
1012 p_wxitem = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
1014 LockPlaylist( p_intf->p_sys, p_playlist );
1015 switch( event.GetId() )
1017 case SortTitle_Event:
1018 playlist_RecursiveNodeSort( p_playlist,
1019 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
1020 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
1022 case RSortTitle_Event:
1023 playlist_RecursiveNodeSort( p_playlist,
1024 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
1025 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
1027 UnlockPlaylist( p_intf->p_sys, p_playlist );
1029 Rebuild( VLC_TRUE );
1032 /**********************************************************************
1033 * Search functions (user)
1034 **********************************************************************/
1035 /*void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
1037 search_button->SetDefault();
1040 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
1042 wxString search_string = search_text->GetValue();
1043 PlaylistItem *p_wxroot;
1044 p_wxroot = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
1045 playlist_item_t *p_root = playlist_ItemGetById( p_playlist, p_wxroot->i_id );
1048 char *psz_name = wxFromLocale( search_string );
1049 playlist_LiveSearchUpdate( p_playlist, p_root, psz_name );
1050 Rebuild( VLC_TRUE );
1052 wxLocaleFree( psz_name );
1055 /**********************************************************************
1056 * Selection functions
1057 **********************************************************************/
1058 void Playlist::RecursiveDeleteSelection( wxTreeItemId root )
1060 wxTreeItemIdValue cookie;
1061 wxTreeItemId child = treectrl->GetFirstChild( root, cookie );
1062 while( child.IsOk() )
1064 if( treectrl->ItemHasChildren( child ) )
1066 RecursiveDeleteSelection( child );
1067 if( treectrl->IsSelected(child ) ) DeleteTreeItem( child );
1069 else if( treectrl->IsSelected( child ) )
1070 DeleteTreeItem( child );
1071 child = treectrl->GetNextChild( root, cookie );
1075 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
1077 RecursiveDeleteSelection( treectrl->GetRootItem() );
1080 /**********************************************************************
1081 * Playlist mode functions
1082 **********************************************************************/
1083 void Playlist::OnRandom( wxCommandEvent& event )
1086 val.b_bool = event.IsChecked();
1087 var_Set( p_playlist, "random", val);
1090 void Playlist::OnLoop( wxCommandEvent& event )
1093 val.b_bool = event.IsChecked();
1094 var_Set( p_playlist, "loop", val);
1097 void Playlist::OnRepeat( wxCommandEvent& event )
1100 val.b_bool = event.IsChecked();
1101 var_Set( p_playlist, "repeat", val);
1104 /********************************************************************
1106 ********************************************************************/
1107 void Playlist::OnActivateItem( wxTreeEvent& event )
1109 playlist_item_t *p_item, *p_parent;
1111 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1114 LockPlaylist( p_intf->p_sys, p_playlist );
1118 UnlockPlaylist( p_intf->p_sys, p_playlist );
1121 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1126 if( p_parent == p_current_treeroot )
1128 p_parent = p_parent->p_parent;
1133 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item );
1135 UnlockPlaylist( p_intf->p_sys, p_playlist );
1138 void Playlist::OnKeyDown( wxTreeEvent& event )
1140 long keycode = event.GetKeyCode();
1141 /* Delete selected items */
1142 if( keycode == WXK_BACK || keycode == WXK_DELETE )
1144 /* We send a dummy event */
1145 OnDeleteSelection( event );
1147 /* Work around wxWin32 bug */
1148 else if( keycode == WXK_RETURN )
1150 wxArrayTreeItemIds items;
1151 if( treectrl->GetSelections( items ) > 0 )
1154 event.SetItem( items.Item( 0 ) );
1155 OnActivateItem( event );
1164 void Playlist::OnDragItemBegin( wxTreeEvent& event )
1167 draged_tree_item = event.GetItem();
1170 void Playlist::OnDragItemEnd( wxTreeEvent& event )
1172 wxTreeItemId dest_tree_item = event.GetItem();
1174 if( !dest_tree_item.IsOk() ) return;
1176 /* check that we're not trying to move a node into one of it's children */
1177 wxTreeItemId parent = dest_tree_item;
1178 while( parent != treectrl->GetRootItem() )
1180 if( draged_tree_item == parent ) return;
1181 parent = treectrl->GetItemParent( parent );
1184 LockPlaylist( p_intf->p_sys, p_playlist );
1186 PlaylistItem *p_wxdrageditem =
1187 (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
1188 PlaylistItem *p_wxdestitem =
1189 (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
1190 if( !p_wxdrageditem || !p_wxdestitem )
1192 UnlockPlaylist( p_intf->p_sys, p_playlist );
1196 playlist_item_t *p_drageditem =
1197 playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id );
1198 playlist_item_t *p_destitem =
1199 playlist_ItemGetById(p_playlist, p_wxdestitem->i_id );
1200 if( !p_drageditem || !p_destitem )
1202 UnlockPlaylist( p_intf->p_sys, p_playlist );
1206 if( p_destitem->i_children == -1 )
1207 /* this is a leaf */
1209 parent = treectrl->GetItemParent( dest_tree_item );
1210 PlaylistItem *p_parent =
1211 (PlaylistItem *)treectrl->GetItemData( parent );
1214 UnlockPlaylist( p_intf->p_sys, p_playlist );
1217 playlist_item_t *p_destitem2 =
1218 playlist_ItemGetById( p_playlist, p_parent->i_id );
1221 UnlockPlaylist( p_intf->p_sys, p_playlist );
1225 for( i = 0; i < p_destitem2->i_children; i++ )
1227 if( p_destitem2->pp_children[i] == p_destitem ) break;
1229 playlist_TreeMove( p_playlist, p_drageditem, p_destitem2, i );
1232 /* this is a node */
1234 playlist_TreeMove( p_playlist, p_drageditem, p_destitem, 0 );
1237 UnlockPlaylist( p_intf->p_sys, p_playlist );
1239 /* FIXME: having this Rebuild() is dirty */
1240 Rebuild( VLC_TRUE );
1243 #if wxUSE_DRAG_AND_DROP
1244 PlaylistFileDropTarget::PlaylistFileDropTarget( Playlist *p ):p( p ){}
1246 /********************************************************************
1247 * File Drag And Drop handling
1248 ********************************************************************/
1249 bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
1250 const wxArrayString& filenames )
1253 playlist_item_t *p_dest;
1255 LockPlaylist( p->p_intf->p_sys, p->p_playlist );
1257 /* find the destination node and position in that node */
1258 const wxPoint pt( x, y );
1259 wxTreeItemId item = p->treectrl->HitTest( pt );
1263 /* We were droped below the last item so we append to the
1265 msg_Err( p->p_playlist, "USE OF P_GENERAL" );
1266 p_dest = p->p_playlist->p_local_category;
1267 i_pos = PLAYLIST_END;
1271 PlaylistItem *p_plitem =
1272 (PlaylistItem *)p->treectrl->GetItemData( item );
1273 p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id );
1275 if( p_dest->i_children == -1 )
1277 /* This is a leaf. Append right after it
1278 * We thus need to find the parrent node and the position of the
1279 * leaf in it's children list */
1280 wxTreeItemId parent = p->treectrl->GetItemParent( item );
1281 PlaylistItem *p_parent =
1282 (PlaylistItem *)p->treectrl->GetItemData( parent );
1285 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1288 playlist_item_t *p_node =
1289 playlist_ItemGetById( p->p_playlist, p_parent->i_id );
1292 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1295 for( i_pos = 0; i_pos < p_node->i_children; i_pos++ )
1297 if( p_node->pp_children[i_pos] == p_dest ) break;
1303 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1305 /* Put the items in the playlist node */
1306 for( size_t i = 0; i < filenames.GetCount(); i++ )
1308 const char *psz_utf8 = wxDnDFromLocale( filenames[i] );
1309 input_item_t *p_input = input_ItemNew( p->p_playlist,
1310 psz_utf8, psz_utf8 );
1311 playlist_NodeAddInput( p->p_playlist, p_input,
1312 p_dest, PLAYLIST_PREPARSE, i_pos );
1313 wxDnDLocaleFree( psz_utf8 );
1316 /* FIXME: having this Rebuild() is dirty */
1317 p->Rebuild( VLC_TRUE );
1323 /**********************************************************************
1325 **********************************************************************/
1327 void Playlist::OnMenuOpen( wxMenuEvent& event)
1329 #if defined( __WXMSW__ )
1330 # define GetEventObject GetMenu
1333 if( event.GetEventObject() == p_view_menu )
1335 p_view_menu = ViewMenu();
1337 #if defined( __WXMSW__ )
1338 # undef GetEventObject
1342 void Playlist::OnMenuEvent( wxCommandEvent& event )
1344 if( event.GetId() < FirstView_Event )
1349 else if( event.GetId() < LastView_Event )
1351 if( event.GetId() == CategoryView_Event )
1353 p_current_viewroot = p_playlist->p_root_category;
1354 if( p_current_treeroot == p_playlist->p_local_category ||
1355 p_current_treeroot == p_playlist->p_local_onelevel )
1357 p_current_treeroot = p_playlist->p_local_category;
1359 else if( p_current_treeroot == p_playlist->p_ml_category ||
1360 p_current_treeroot == p_playlist->p_ml_onelevel )
1362 p_current_treeroot = p_playlist->p_ml_category;
1365 else if( event.GetId() == OneLevelView_Event )
1367 p_current_viewroot = p_playlist->p_root_onelevel;
1368 if( p_current_treeroot == p_playlist->p_local_category ||
1369 p_current_treeroot == p_playlist->p_local_onelevel )
1371 p_current_treeroot = p_playlist->p_local_onelevel;
1373 else if( p_current_treeroot == p_playlist->p_ml_category ||
1374 p_current_treeroot == p_playlist->p_ml_onelevel )
1376 p_current_treeroot = p_playlist->p_ml_onelevel;
1379 wxCommandEvent event;
1383 else if( event.GetId() >= FirstSD_Event && event.GetId() < LastSD_Event )
1385 if( !playlist_IsServicesDiscoveryLoaded( p_playlist,
1386 pp_sds[event.GetId() - FirstSD_Event] ) )
1388 playlist_ServicesDiscoveryAdd( p_playlist,
1389 pp_sds[event.GetId() - FirstSD_Event] );
1393 //wxMutexGuiLeave();
1394 playlist_ServicesDiscoveryRemove( p_playlist,
1395 pp_sds[event.GetId() - FirstSD_Event] );
1396 //wxMutexGuiEnter();
1401 wxMenu * Playlist::ViewMenu()
1405 p_view_menu = new wxMenu;
1409 wxMenuItemList::Node *node = p_view_menu->GetMenuItems().GetFirst();
1412 wxMenuItem *item = node->GetData();
1413 node = node->GetNext();
1414 p_view_menu->Delete( item );
1418 p_view_menu->Append( CategoryView_Event, wxU(_("Normal") ) );
1419 p_view_menu->Append( OneLevelView_Event, wxU(_("One level") ) );
1423 wxMenu *Playlist::SDMenu()
1425 p_sd_menu = new wxMenu;
1427 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
1431 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1433 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1435 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1438 if( i_number ) pp_sds = (char **)calloc( i_number, sizeof(void *) );
1441 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1443 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1445 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1447 p_sd_menu->AppendCheckItem( FirstSD_Event + i_number ,
1448 wxU( p_parser->psz_longname ? p_parser->psz_longname :
1449 (p_parser->psz_shortname ?
1450 p_parser->psz_shortname : p_parser->psz_object_name) ) );
1452 /* hack to handle submodules properly */
1454 while( p_parser->pp_shortcuts[++i] != NULL );
1456 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
1457 i>=0?p_parser->pp_shortcuts[i]
1458 :p_parser->psz_object_name ) )
1460 p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
1463 pp_sds[i_number++] = i>=0?p_parser->pp_shortcuts[i]
1464 :p_parser->psz_object_name;
1467 vlc_list_release( p_list );
1472 /*****************************************************************************
1473 * Popup management functions
1474 *****************************************************************************/
1475 void Playlist::OnPopup( wxContextMenuEvent& event )
1477 wxPoint pt = event.GetPosition();
1478 playlist_item_t *p_item;
1480 i_wx_popup_item = treectrl->HitTest( ScreenToClient( pt ) );
1481 if( i_wx_popup_item.IsOk() )
1483 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1485 PlaylistItem *p_wxparent= (PlaylistItem *)treectrl->GetItemData(
1486 treectrl->GetItemParent( i_wx_popup_item ) );
1487 i_popup_item = p_wxitem->i_id;
1488 i_popup_parent = p_wxparent->i_id;
1489 treectrl->SelectItem( i_wx_popup_item );
1491 LockPlaylist( p_intf->p_sys, p_playlist );
1492 p_item = playlist_ItemGetById( p_playlist, i_popup_item );
1496 UnlockPlaylist( p_intf->p_sys, p_playlist );
1499 if( p_item->i_children == -1 )
1501 UnlockPlaylist( p_intf->p_sys, p_playlist );
1502 Playlist::PopupMenu( item_popup,
1503 ScreenToClient( wxGetMousePosition() ) );
1507 UnlockPlaylist( p_intf->p_sys, p_playlist );
1508 Playlist::PopupMenu( node_popup,
1509 ScreenToClient( wxGetMousePosition() ) );
1514 void Playlist::OnPopupPlay( wxCommandEvent& event )
1516 playlist_item_t *p_popup_item, *p_popup_parent;
1517 LockPlaylist( p_intf->p_sys, p_playlist );
1518 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1520 p_popup_parent = p_popup_item;
1521 while( p_popup_parent )
1523 if( p_popup_parent == p_current_treeroot )
1525 p_popup_parent = p_popup_parent->p_parent;
1528 if( p_popup_parent )
1530 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_popup_parent,
1533 UnlockPlaylist( p_intf->p_sys, p_playlist );
1536 void Playlist::OnPopupPreparse( wxCommandEvent& event )
1541 void Playlist::Preparse()
1543 playlist_item_t *p_popup_item;
1544 LockPlaylist( p_intf->p_sys, p_playlist );
1545 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1547 if( p_popup_item != NULL )
1549 if( p_popup_item->i_children == -1 )
1551 playlist_PreparseEnqueue( p_playlist, p_popup_item->p_input );
1556 playlist_item_t *p_parent = p_popup_item;
1557 for( i = 0; i< p_parent->i_children ; i++ )
1560 i_wx_popup_item = FindItem( treectrl->GetRootItem(),
1561 p_parent->pp_children[i]->i_id );
1562 i_popup_item = p_parent->pp_children[i]->i_id;
1567 UnlockPlaylist( p_intf->p_sys, p_playlist );
1570 void Playlist::OnPopupDel( wxCommandEvent& event )
1572 DeleteTreeItem( i_wx_popup_item );
1575 void Playlist::OnPopupSort( wxCommandEvent& event )
1577 PlaylistItem *p_wxitem;
1578 playlist_item_t *p_item;
1580 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1581 LockPlaylist( p_intf->p_sys, p_playlist );
1583 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1584 if( p_item->i_children >= 0 )
1586 playlist_RecursiveNodeSort( p_playlist, p_item,
1587 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
1589 treectrl->DeleteChildren( i_wx_popup_item );
1590 i_saved_id = -1; i_saved_input_id = -1;
1591 UpdateNodeChildren( p_item, i_wx_popup_item );
1594 UnlockPlaylist( p_intf->p_sys, p_playlist );
1597 void Playlist::OnPopupInfo( wxCommandEvent& event )
1599 LockPlaylist( p_intf->p_sys, p_playlist );
1600 playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1603 iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this );
1604 if( iteminfo_dialog->ShowModal() == wxID_OK )
1606 UpdateItem( i_wx_popup_item );
1608 delete iteminfo_dialog;
1610 UnlockPlaylist( p_intf->p_sys, p_playlist );
1613 void Playlist::OnPopupAddNode( wxCommandEvent& event )
1615 wxTextEntryDialog text( NULL, wxU(_( "Please enter node name" )),
1616 wxU(_( "Add node" )), wxU(_( "New node" )) );
1617 if( text.ShowModal() != wxID_OK ) return;
1619 char *psz_name = wxFromLocale( text.GetValue() );
1621 LockPlaylist( p_intf->p_sys, p_playlist );
1623 PlaylistItem *p_wxitem;
1624 playlist_item_t *p_item;
1626 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1628 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1630 playlist_NodeCreate( p_playlist, psz_name, p_item );
1632 UnlockPlaylist( p_intf->p_sys, p_playlist );
1633 Rebuild( VLC_TRUE );
1635 wxLocaleFree( psz_name );
1638 void Playlist::OnSourceSelected( wxListEvent &event )
1640 int i_id = event.GetData();
1642 if( p_current_treeroot && i_id != p_current_treeroot->i_id )
1644 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
1645 if( p_item ) p_current_treeroot = p_item;
1646 Rebuild( VLC_TRUE );
1650 /*****************************************************************************
1651 * Custom events management
1652 *****************************************************************************/
1653 void Playlist::OnPlaylistEvent( wxCommandEvent& event )
1655 switch( event.GetId() )
1657 case UpdateItem_Event:
1658 fprintf( stderr,"Update input item id %i\n", event.GetInt() );
1659 UpdateItem( event.GetInt() );
1661 case AppendItem_Event:
1662 fprintf( stderr,"Append item id %i\n",
1663 ((playlist_add_t*)event.GetClientData())->i_item );
1664 AppendItem( event );
1666 case RemoveItem_Event:
1667 fprintf( stderr,"Remove item id %i\n", event.GetInt() );
1668 RemoveItem( event.GetInt() );
1673 /*****************************************************************************
1674 * PlaylistChanged: callback triggered by the intf-change playlist variable
1675 * We don't rebuild the playlist directly here because we don't want the
1676 * caller to block for a too long time.
1677 *****************************************************************************/
1678 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1679 vlc_value_t oval, vlc_value_t nval, void *param )
1681 Playlist *p_playlist_dialog = (Playlist *)param;
1682 p_playlist_dialog->b_need_update = VLC_TRUE;
1686 /*****************************************************************************
1687 * Next: callback triggered by the playlist-current playlist variable
1688 *****************************************************************************/
1689 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1690 vlc_value_t oval, vlc_value_t nval, void *param )
1692 Playlist *p_playlist_dialog = (Playlist *)param;
1694 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1695 event.SetInt( oval.i_int );
1696 p_playlist_dialog->AddPendingEvent( event );
1697 event.SetInt( nval.i_int );
1698 p_playlist_dialog->AddPendingEvent( event );
1703 /*****************************************************************************
1704 * ItemChanged: callback triggered by the item-change playlist variable
1705 *****************************************************************************/
1706 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1707 vlc_value_t old_val, vlc_value_t new_val, void *param )
1709 Playlist *p_playlist_dialog = (Playlist *)param;
1711 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1712 event.SetInt( new_val.i_int );
1713 p_playlist_dialog->AddPendingEvent( event );
1717 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1718 vlc_value_t old_val, vlc_value_t new_val, void *param )
1720 Playlist *p_playlist_dialog = (Playlist *)param;
1722 wxCommandEvent event( wxEVT_PLAYLIST, RemoveItem_Event );
1723 event.SetInt( new_val.i_int );
1724 p_playlist_dialog->AddPendingEvent( event );
1729 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1730 vlc_value_t oval, vlc_value_t nval, void *param )
1732 Playlist *p_playlist_dialog = (Playlist *)param;
1734 playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
1735 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1737 if( ++p_playlist_dialog->i_items_to_append >= 50 )
1739 /* Too many items waiting to be added, it will be quicker to rebuild
1740 * the whole playlist */
1741 p_playlist_dialog->b_need_update = VLC_TRUE;
1745 wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );
1746 event.SetClientData( (void *)p_add );
1747 p_playlist_dialog->AddPendingEvent( event );