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 if( p_playlist == NULL ) return;
224 SetIcon( *p_intf->p_sys->p_icon );
227 p_sd_menu = SDMenu();
229 // i_current_view = VIEW_ONELEVEL;
230 p_current_viewroot = p_playlist->p_root_onelevel;
231 p_current_treeroot = p_playlist->p_local_onelevel;
235 i_duration_sorted = 0;
237 var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
238 var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
239 var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
241 /* Create our "Manage" menu */
242 wxMenu *manage_menu = new wxMenu;
243 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add File...")) );
244 manage_menu->Append( AddDir_Event, wxU(_("Add &Directory...")) );
245 manage_menu->Append( AddMRL_Event, wxU(_("&Add URL...")) );
246 manage_menu->AppendSeparator();
247 manage_menu->Append( MenuDummy_Event, wxU(_("Services Discovery")),
249 manage_menu->AppendSeparator();
250 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
251 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
252 manage_menu->AppendSeparator();
253 manage_menu->Append( Close_Event, wxU(_("&Close")) );
255 /* Create our "Sort" menu */
256 wxMenu *sort_menu = new wxMenu;
257 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &Title")) );
258 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse Sort by Title")) );
259 sort_menu->AppendSeparator();
260 sort_menu->Append( Randomize_Event, wxU(_("&Shuffle")) );
262 /* Create our "Selection" menu */
263 wxMenu *selection_menu = new wxMenu;
264 selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
266 /* Create our "View" menu */
269 /* Append the freshly created menus to the menu bar */
270 wxMenuBar *menubar = new wxMenuBar();
271 menubar->Append( manage_menu, wxU(_("&Manage")) );
272 menubar->Append( sort_menu, wxU(_("S&ort")) );
273 menubar->Append( selection_menu, wxU(_("&Selection")) );
274 menubar->Append( p_view_menu, wxU(_("&View items") ) );
276 /* Attach the menu bar to the frame */
277 SetMenuBar( menubar );
279 /* Create the popup menu */
280 node_popup = new wxMenu;
281 node_popup->Append( PopupPlay_Event, wxU(_("Play")) );
282 node_popup->Append( PopupPlayThis_Event, wxU(_("Play this Branch")) );
283 node_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
284 node_popup->Append( PopupSort_Event, wxU(_("Sort this Branch")) );
285 node_popup->Append( PopupDel_Event, wxU(_("Delete")) );
286 node_popup->Append( PopupInfo_Event, wxU(_("Info")) );
287 node_popup->Append( PopupAddNode_Event, wxU(_("Add Node")) );
289 item_popup = new wxMenu;
290 item_popup->Append( PopupPlay_Event, wxU(_("Play")) );
291 item_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
292 item_popup->Append( PopupDel_Event, wxU(_("Delete")) );
293 item_popup->Append( PopupInfo_Event, wxU(_("Info")) );
295 /* Create a panel to put everything in */
296 wxPanel *playlist_panel = new wxPanel( this, -1 );
297 playlist_panel->SetAutoLayout( TRUE );
299 /* Create the toolbar */
301 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
303 /* Create the random tool */
304 toolbar->AddTool( Random_Event, wxT(""), wxBitmap(shuffle_on_xpm),
305 wxBitmap(shuffle_on_xpm), wxITEM_CHECK,
306 wxU(_(HELP_SHUFFLE) ) );
307 var_Get( p_intf, "random", &val );
308 toolbar->ToggleTool( Random_Event, val.b_bool );
310 /* Create the Loop tool */
311 toolbar->AddTool( Loop_Event, wxT(""), wxBitmap( loop_xpm),
312 wxBitmap( loop_xpm), wxITEM_CHECK,
313 wxU(_(HELP_LOOP ) ) );
314 var_Get( p_intf, "loop", &val );
315 toolbar->ToggleTool( Loop_Event, val.b_bool );
317 /* Create the Repeat one checkbox */
318 toolbar->AddTool( Repeat_Event, wxT(""), wxBitmap( repeat_xpm),
319 wxBitmap( repeat_xpm), wxITEM_CHECK,
320 wxU(_(HELP_REPEAT ) ) );
321 var_Get( p_intf, "repeat", &val );
322 toolbar->ToggleTool( Repeat_Event, val.b_bool ) ;
324 /* Create the Search Textbox */
325 search_text = new wxTextCtrl( toolbar, SearchText_Event, wxT(""),
326 wxDefaultPosition, wxSize(100, -1),
329 /* Create the search button */
330 search_button = new wxButton( toolbar , Search_Event, wxU(_("Search")) );
332 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
333 wxSize(16, 16), wxBORDER_NONE ) );
334 toolbar->AddControl( search_text );
335 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
336 wxSize(5, 5), wxBORDER_NONE ) );
337 toolbar->AddControl( search_button );
338 search_button->SetDefault();
341 /* Create teh source selector */
342 source_sel = new wxListView( playlist_panel, Source_Event,
343 wxDefaultPosition, wxDefaultSize,
344 wxLC_AUTOARRANGE|wxLC_SINGLE_SEL );
346 /* Create the tree */
347 treectrl = new wxTreeCtrl( playlist_panel, TreeCtrl_Event,
348 wxDefaultPosition, wxDefaultSize,
349 wxTR_HIDE_ROOT | wxTR_LINES_AT_ROOT|
351 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS |
352 wxTR_MULTIPLE | wxTR_EXTENDED );
354 /* Create image list */
355 wxImageList *p_images = new wxImageList( 16 , 16, TRUE );
357 /* FIXME: absolutely needs to be in the right order FIXME */
358 p_images->Add( wxIcon( type_unknown_xpm ) );
359 p_images->Add( wxIcon( type_afile_xpm ) );
360 p_images->Add( wxIcon( type_vfile_xpm ) );
361 p_images->Add( wxIcon( type_directory_xpm ) );
362 p_images->Add( wxIcon( type_disc_xpm ) );
363 p_images->Add( wxIcon( type_cdda_xpm ) );
364 p_images->Add( wxIcon( type_card_xpm ) );
365 p_images->Add( wxIcon( type_net_xpm ) );
366 p_images->Add( wxIcon( type_playlist_xpm ) );
367 p_images->Add( wxIcon( type_node_xpm ) );
368 treectrl->AssignImageList( p_images );
370 treectrl->AddRoot( wxU(_("root" )), -1, -1, NULL );
372 /* Reduce font size */
373 wxFont font= treectrl->GetFont();
374 font.SetPointSize(9);
375 treectrl->SetFont( font );
377 wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL );
378 panel_sizer->Add( source_sel, 0, wxALL | wxEXPAND, 5 );
379 panel_sizer->Add( treectrl, 1, wxEXPAND | wxALL, 5 );
380 panel_sizer->Layout();
382 playlist_panel->SetSizerAndFit( panel_sizer );
384 int pi_widths[1] = { -1 };
385 statusbar = CreateStatusBar( 1 );
386 statusbar->SetStatusWidths( 1, pi_widths );
388 #if wxUSE_DRAG_AND_DROP
389 /* Associate drop targets with the playlist */
390 SetDropTarget( new PlaylistFileDropTarget( this ) );
391 menubar->SetDropTarget( new PlaylistFileDropTarget( this ) );
392 toolbar->SetDropTarget( new PlaylistFileDropTarget( this ) );
396 i_saved_input_id = -1;
398 /* Some global changes happened -> Rebuild all */
399 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
401 /* We went to the next item */
402 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
404 /* One item has been updated */
405 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
407 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
408 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
410 /* Update the playlist */
415 Playlist::~Playlist()
417 if( pp_sds != NULL ) free( pp_sds );
419 if( p_playlist == NULL ) return;
421 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
422 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
423 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
424 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
425 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
426 vlc_object_release( p_playlist );
429 /**********************************************************************
431 **********************************************************************/
434 void Playlist::UpdateNode( playlist_item_t *p_node, wxTreeItemId node )
436 wxTreeItemIdValue cookie;
438 for( int i = 0; i< p_node->i_children ; i++ )
442 child = treectrl->GetFirstChild( node, cookie);
446 child = treectrl->GetNextChild( node, cookie );
451 /* Not enough children */
452 CreateNode( p_node->pp_children[i], node );
453 /* Keep the tree pointer up to date */
454 child = treectrl->GetNextChild( node, cookie );
457 treectrl->SetItemImage( node, p_node->p_input->i_type );
461 /* Creates the node p_node as last child of parent */
462 void Playlist::CreateNode( playlist_item_t *p_node, wxTreeItemId parent )
465 treectrl->AppendItem( parent, wxL2U( p_node->p_input->psz_name ),
466 -1,-1, new PlaylistItem( p_node ) );
467 treectrl->SetItemImage( node, p_node->p_input->i_type );
469 UpdateNodeChildren( p_node, node );
472 /* Update all children (recursively) of this node */
473 void Playlist::UpdateNodeChildren( playlist_item_t *p_node,
476 for( int i = 0; i< p_node->i_children ; i++ )
478 /* Append the item */
479 if( p_node->pp_children[i]->i_children == -1 )
481 if( !(p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG) )
484 treectrl->AppendItem( node,
485 wxL2U( p_node->pp_children[i]->p_input->psz_name ), -1,-1,
486 new PlaylistItem( p_node->pp_children[i]) );
488 UpdateTreeItem( item );
493 CreateNode( p_node->pp_children[i], node );
498 /* Update an item in the tree */
499 void Playlist::UpdateTreeItem( wxTreeItemId item )
501 LockPlaylist( p_intf->p_sys, p_playlist );
502 if( ! item.IsOk() ) return;
504 wxTreeItemData *p_data = treectrl->GetItemData( item );
505 if( !p_data ) return;
507 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
508 ((PlaylistItem *)p_data)->i_id );
511 UnlockPlaylist( p_intf->p_sys, p_playlist );
516 wxString duration = wxU( "" );
519 if( p_item->p_input->p_meta )
521 psz_artist= p_item->p_input->p_meta->psz_artist ?
522 strdup( p_item->p_input->p_meta->psz_artist ) :
526 psz_artist = strdup( "" );
528 char psz_duration[MSTRTIME_MAX_SIZE];
529 mtime_t dur = p_item->p_input->i_duration;
533 secstotimestr( psz_duration, dur/1000000 );
534 duration.Append( wxU( " ( " ) + wxString( wxU( psz_duration ) ) +
538 if( !strcmp( psz_artist, "" ) || p_item->p_input->b_fixed_name == VLC_TRUE )
540 msg = wxString( wxU( p_item->p_input->psz_name ) ) + duration;
544 msg = wxString(wxU( psz_artist )) + wxT(" - ") +
545 wxString(wxU(p_item->p_input->psz_name)) + duration;
548 treectrl->SetItemText( item , msg );
549 treectrl->SetItemImage( item, p_item->p_input->i_type );
551 if( p_playlist->status.p_item == p_item )
553 treectrl->SetItemBold( item, true );
554 while( treectrl->GetItemParent( item ).IsOk() )
556 item = treectrl->GetItemParent( item );
557 if( ! (item == treectrl->GetRootItem() &&
558 treectrl->HasFlag( wxTR_HIDE_ROOT ) ) )
559 treectrl->Expand( item );
564 treectrl->SetItemBold( item, false );
566 UnlockPlaylist( p_intf->p_sys, p_playlist );
569 /* Process a AppendIt em request */
570 void Playlist::AppendItem( wxCommandEvent& event )
572 playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();
573 playlist_item_t *p_item = NULL;
574 wxTreeItemId item, node;
578 /* No need to do anything if the playlist is going to be rebuilt */
579 if( b_need_update ) return;
581 node = FindItem( treectrl->GetRootItem(), p_add->i_node );
582 if( !node.IsOk() ) goto update;
584 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
585 if( !p_item ) goto update;
586 if( (p_item->i_flags & PLAYLIST_DBL_FLAG ) ) goto update;
588 item = FindItem( treectrl->GetRootItem(), p_add->i_item );
589 if( item.IsOk() ) goto update;
591 item = treectrl->AppendItem( node,
592 wxL2U( p_item->p_input->psz_name ), -1,-1,
593 new PlaylistItem( p_item ) );
594 treectrl->SetItemImage( item, p_item->p_input->i_type );
596 if( item.IsOk() && p_item->i_children == -1 )
598 UpdateTreeItem( item );
602 int i_count = CountItems( treectrl->GetRootItem());
603 statusbar->SetStatusText( wxString::Format( wxU(_(
604 "%i items in playlist" ) ), i_count ) );
608 /* Process a updateitem request */
609 void Playlist::UpdateItem( int i )
611 if( i < 0 ) return; /* Sanity check */
612 wxTreeItemId item = FindItemByInput( treectrl->GetRootItem(), i );
615 UpdateTreeItem( item );
619 void Playlist::RemoveItem( int i )
621 if( i <= 0 ) return; /* Sanity check */
622 if( i == i_saved_id ) i_saved_id = -1;
624 /* Hack: always invalidate input item cache */
625 i_saved_input_id = -1;
627 /// \todo Check if it is in the source selector */
629 wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
633 treectrl->Delete( item );
638 /**********************************************************************
639 * Search functions (internal)
640 **********************************************************************/
642 /* Find a wxItem from a playlist id */
643 wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id )
645 return FindItemInner( root, i_id, false );
648 wxTreeItemId Playlist::FindItemByInput( wxTreeItemId root, int i_input_id )
650 return FindItemInner( root, i_input_id, true );
653 wxTreeItemId Playlist::FindItemInner( wxTreeItemId root, int i_id, bool b_byinput )
655 wxTreeItemIdValue cookie;
656 PlaylistItem *p_wxcurrent;
658 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
661 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
665 wxTreeItemId dummy; dummy.Unset(); return dummy;
667 if( b_byinput && i_saved_input_id == i_id )
668 return saved_input_tree_item;
669 if( !b_byinput && i_saved_id == i_id)
670 return saved_tree_item;
674 wxTreeItemId dummy; dummy.Unset(); return dummy;
677 if( !b_byinput && p_wxcurrent->i_id == i_id )
680 saved_tree_item = root;
683 if( b_byinput && p_wxcurrent->i_input_id == i_id )
685 i_saved_input_id = i_id;
686 saved_input_tree_item = root;
692 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
693 if( !b_byinput && p_wxcurrent->i_id == i_id )
696 saved_tree_item = item;
699 else if( b_byinput && p_wxcurrent->i_input_id == i_id )
701 i_saved_input_id = i_id;
702 saved_input_tree_item = item;
705 if( treectrl->ItemHasChildren( item ) )
707 wxTreeItemId search = FindItemInner( item, i_id, b_byinput );
713 saved_tree_item = search;
718 i_saved_input_id = i_id;
719 saved_input_tree_item = search;
725 item = treectrl->GetNextChild( root, cookie );
728 wxTreeItemId dummy; dummy.Unset(); return dummy;
731 int Playlist::CountItems( wxTreeItemId root )
733 wxTreeItemIdValue cookie;
735 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
739 if( treectrl->ItemHasChildren( item ) )
741 count += CountItems( item );
745 playlist_item_t *p_item;
746 LockPlaylist( p_intf->p_sys, p_playlist );
747 p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id );
748 if( p_item && p_item->i_children == -1 )
750 UnlockPlaylist( p_intf->p_sys, p_playlist );
752 item = treectrl->GetNextChild( root, cookie );
757 /* Find a wxItem from a name (from current) */
758 wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, vlc_bool_t *pb_current_found )
760 wxTreeItemIdValue cookie;
762 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
767 if( treectrl->GetItemText( item).Lower().Contains(
768 search_string.Lower() ) )
770 if( !current.IsOk() || *pb_current_found == VLC_TRUE )
774 else if( current.IsOk() && item == current )
776 *pb_current_found = VLC_TRUE;
779 if( treectrl->ItemHasChildren( item ) )
781 wxTreeItemId search = FindItemByName( item, search_string, current,
788 item = treectrl->GetNextChild( root, cookie);
791 wxTreeItemId dummy; dummy.Unset();
795 /**********************************************************************
796 * Rebuild the playlist
797 **********************************************************************/
798 void Playlist::Rebuild( vlc_bool_t b_root )
800 i_items_to_append = 0;
802 /* We can remove the callbacks before locking, anyway, we won't
806 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
807 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
808 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
809 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
810 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
812 /* ...and rebuild it */
813 LockPlaylist( p_intf->p_sys, p_playlist );
815 /* Invalidate cache */
817 i_saved_input_id = -1;
819 /* Rebuild the list */
820 source_sel->ClearAll();
821 for( int i = 0 ; i< p_current_viewroot->i_children ; i++ )
823 source_sel->InsertItem( i,
824 wxL2U( p_current_viewroot->pp_children[i]->p_input->psz_name) );
825 source_sel->SetItemData( i,
826 p_current_viewroot->pp_children[i]->i_id );
827 if( p_current_viewroot->pp_children[i] == p_current_treeroot )
828 source_sel->Select( i );
831 /* HACK we should really get new*/
832 treectrl->DeleteAllItems();
833 treectrl->AddRoot( wxU(_("root" )), -1, -1,
834 new PlaylistItem( p_current_treeroot ) );
836 wxTreeItemId root = treectrl->GetRootItem();
837 //UpdateNode( p_current_treeroot, root );
838 //CreateNode( p_current_treeroot, root );
839 UpdateNodeChildren( p_current_treeroot, root );
841 int i_count = CountItems( treectrl->GetRootItem() );
843 statusbar->SetStatusText( wxString::Format( wxU(_(
844 "%i items in playlist")), i_count ), 0 );
848 /* Put callbacks back online */
849 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
850 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
851 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
852 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
853 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
855 UnlockPlaylist( p_intf->p_sys, p_playlist );
859 void Playlist::ShowPlaylist( bool show )
861 if( show ) Rebuild( VLC_TRUE );
865 /* This function is called on a regular basis */
866 void Playlist::UpdatePlaylist()
870 /* If the playlist isn't show there's no need to update it */
871 if( !IsShown() ) return;
873 if( this->b_need_update )
875 this->b_need_update = VLC_FALSE;
879 /* Updating the playing status every 0.5s is enough */
880 if( i_update_counter % 5 ) return;
883 /*****************************************************************************
885 *****************************************************************************/
886 void Playlist::DeleteTreeItem( wxTreeItemId item )
888 PlaylistItem *p_wxitem;
889 playlist_item_t *p_item;
890 p_wxitem = (PlaylistItem *)treectrl->GetItemData( item );
892 LockPlaylist( p_intf->p_sys, p_playlist );
893 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
897 UnlockPlaylist( p_intf->p_sys, p_playlist );
901 if( p_item->i_children == -1 ) DeleteItem( p_item->p_input->i_id );
902 else DeleteNode( p_item );
904 RemoveItem( p_item->i_id );
905 UnlockPlaylist( p_intf->p_sys, p_playlist );
908 void Playlist::DeleteItem( int item_id )
910 playlist_DeleteAllFromInput( p_playlist, item_id );
913 void Playlist::DeleteNode( playlist_item_t *p_item )
915 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );
918 void Playlist::OnMenuClose( wxCommandEvent& event )
924 void Playlist::OnClose( wxCloseEvent& WXUNUSED(event) )
929 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
935 } formats[] = {//{ _("M3U file"), "*.m3u", "export-m3u" },
936 { _("XSPF playlist"), "*.xspf", "export-xspf"}
939 wxString filter = wxT("");
941 if( playlist_IsEmpty( p_playlist ) )
943 wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
944 wxICON_WARNING | wxOK, this );
948 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
950 filter.Append( wxU(formats[i].psz_desc) );
951 filter.Append( wxT("|") );
952 filter.Append( wxU(formats[i].psz_filter) );
953 filter.Append( wxT("|") );
955 wxFileDialog dialog( this, wxU(_("Save playlist")),
956 wxT(""), wxT(""), filter, wxSAVE );
958 if( dialog.ShowModal() == wxID_OK )
960 if( dialog.GetPath().mb_str() )
962 /* what root should we export? */
963 if( p_playlist->p_root_category->i_children > 0 )
965 playlist_Export( p_playlist, dialog.GetPath().mb_str(),
966 p_playlist->p_root_category->pp_children[0],
967 formats[dialog.GetFilterIndex()].psz_module );
974 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
976 wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
977 wxT("All playlists|" EXTENSIONS_PLAYLIST "|XSPF playlist|*.xspf|M3U files|*.m3u"), wxOPEN );
979 if( dialog.ShowModal() == wxID_OK )
981 playlist_Import( p_playlist, dialog.GetPath().mb_str() );
985 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
987 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
991 void Playlist::OnAddDir( wxCommandEvent& WXUNUSED(event) )
993 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY, 0, 0 );
997 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
999 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
1003 /********************************************************************
1005 ********************************************************************/
1006 void Playlist::OnSort( wxCommandEvent& event )
1008 PlaylistItem *p_wxitem;
1009 p_wxitem = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
1011 LockPlaylist( p_intf->p_sys, p_playlist );
1012 switch( event.GetId() )
1014 case SortTitle_Event:
1015 playlist_RecursiveNodeSort( p_playlist,
1016 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
1017 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
1019 case RSortTitle_Event:
1020 playlist_RecursiveNodeSort( p_playlist,
1021 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
1022 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
1024 UnlockPlaylist( p_intf->p_sys, p_playlist );
1026 Rebuild( VLC_TRUE );
1029 /**********************************************************************
1030 * Search functions (user)
1031 **********************************************************************/
1032 /*void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
1034 search_button->SetDefault();
1037 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
1039 wxString search_string = search_text->GetValue();
1040 PlaylistItem *p_wxroot;
1041 p_wxroot = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
1042 playlist_item_t *p_root = playlist_ItemGetById( p_playlist, p_wxroot->i_id );
1045 char *psz_name = wxFromLocale( search_string );
1046 playlist_LiveSearchUpdate( p_playlist, p_root, psz_name );
1047 Rebuild( VLC_TRUE );
1049 wxLocaleFree( psz_name );
1052 /**********************************************************************
1053 * Selection functions
1054 **********************************************************************/
1055 void Playlist::RecursiveDeleteSelection( wxTreeItemId root )
1057 wxTreeItemIdValue cookie;
1058 wxTreeItemId child = treectrl->GetFirstChild( root, cookie );
1059 while( child.IsOk() )
1061 if( treectrl->ItemHasChildren( child ) )
1063 RecursiveDeleteSelection( child );
1064 if( treectrl->IsSelected(child ) ) DeleteTreeItem( child );
1066 else if( treectrl->IsSelected( child ) )
1067 DeleteTreeItem( child );
1068 child = treectrl->GetNextChild( root, cookie );
1072 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
1074 RecursiveDeleteSelection( treectrl->GetRootItem() );
1077 /**********************************************************************
1078 * Playlist mode functions
1079 **********************************************************************/
1080 void Playlist::OnRandom( wxCommandEvent& event )
1083 val.b_bool = event.IsChecked();
1084 var_Set( p_playlist, "random", val);
1087 void Playlist::OnLoop( wxCommandEvent& event )
1090 val.b_bool = event.IsChecked();
1091 var_Set( p_playlist, "loop", val);
1094 void Playlist::OnRepeat( wxCommandEvent& event )
1097 val.b_bool = event.IsChecked();
1098 var_Set( p_playlist, "repeat", val);
1101 /********************************************************************
1103 ********************************************************************/
1104 void Playlist::OnActivateItem( wxTreeEvent& event )
1106 playlist_item_t *p_item, *p_parent;
1108 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1111 LockPlaylist( p_intf->p_sys, p_playlist );
1115 UnlockPlaylist( p_intf->p_sys, p_playlist );
1118 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1123 if( p_parent == p_current_treeroot )
1125 p_parent = p_parent->p_parent;
1130 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item );
1132 UnlockPlaylist( p_intf->p_sys, p_playlist );
1135 void Playlist::OnKeyDown( wxTreeEvent& event )
1137 long keycode = event.GetKeyCode();
1138 /* Delete selected items */
1139 if( keycode == WXK_BACK || keycode == WXK_DELETE )
1141 /* We send a dummy event */
1142 OnDeleteSelection( event );
1144 /* Work around wxWin32 bug */
1145 else if( keycode == WXK_RETURN )
1147 wxArrayTreeItemIds items;
1148 if( treectrl->GetSelections( items ) > 0 )
1151 event.SetItem( items.Item( 0 ) );
1152 OnActivateItem( event );
1161 void Playlist::OnDragItemBegin( wxTreeEvent& event )
1164 draged_tree_item = event.GetItem();
1167 void Playlist::OnDragItemEnd( wxTreeEvent& event )
1169 wxTreeItemId dest_tree_item = event.GetItem();
1171 if( !dest_tree_item.IsOk() ) return;
1173 /* check that we're not trying to move a node into one of its children */
1174 wxTreeItemId parent = dest_tree_item;
1175 while( parent != treectrl->GetRootItem() )
1177 if( draged_tree_item == parent ) return;
1178 parent = treectrl->GetItemParent( parent );
1181 LockPlaylist( p_intf->p_sys, p_playlist );
1183 PlaylistItem *p_wxdrageditem =
1184 (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
1185 PlaylistItem *p_wxdestitem =
1186 (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
1187 if( !p_wxdrageditem || !p_wxdestitem )
1189 UnlockPlaylist( p_intf->p_sys, p_playlist );
1193 playlist_item_t *p_drageditem =
1194 playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id );
1195 playlist_item_t *p_destitem =
1196 playlist_ItemGetById(p_playlist, p_wxdestitem->i_id );
1197 if( !p_drageditem || !p_destitem )
1199 UnlockPlaylist( p_intf->p_sys, p_playlist );
1203 if( p_destitem->i_children == -1 )
1204 /* this is a leaf */
1206 parent = treectrl->GetItemParent( dest_tree_item );
1207 PlaylistItem *p_parent =
1208 (PlaylistItem *)treectrl->GetItemData( parent );
1211 UnlockPlaylist( p_intf->p_sys, p_playlist );
1214 playlist_item_t *p_destitem2 =
1215 playlist_ItemGetById( p_playlist, p_parent->i_id );
1218 UnlockPlaylist( p_intf->p_sys, p_playlist );
1222 for( i = 0; i < p_destitem2->i_children; i++ )
1224 if( p_destitem2->pp_children[i] == p_destitem ) break;
1226 playlist_TreeMove( p_playlist, p_drageditem, p_destitem2, i );
1229 /* this is a node */
1231 playlist_TreeMove( p_playlist, p_drageditem, p_destitem, 0 );
1234 UnlockPlaylist( p_intf->p_sys, p_playlist );
1236 /* FIXME: having this Rebuild() is dirty */
1237 Rebuild( VLC_TRUE );
1240 #if wxUSE_DRAG_AND_DROP
1241 PlaylistFileDropTarget::PlaylistFileDropTarget( Playlist *p ):p( p ){}
1243 /********************************************************************
1244 * File Drag And Drop handling
1245 ********************************************************************/
1246 bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
1247 const wxArrayString& filenames )
1250 playlist_item_t *p_dest;
1252 LockPlaylist( p->p_intf->p_sys, p->p_playlist );
1254 /* find the destination node and position in that node */
1255 const wxPoint pt( x, y );
1256 wxTreeItemId item = p->treectrl->HitTest( pt );
1260 /* We were droped below the last item so we append to the
1262 msg_Err( p->p_playlist, "USE OF P_GENERAL" );
1263 p_dest = p->p_playlist->p_local_category;
1264 i_pos = PLAYLIST_END;
1268 PlaylistItem *p_plitem =
1269 (PlaylistItem *)p->treectrl->GetItemData( item );
1270 p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id );
1272 if( p_dest->i_children == -1 )
1274 /* This is a leaf. Append right after it
1275 * We thus need to find the parrent node and the position of the
1276 * leaf in its children list */
1277 wxTreeItemId parent = p->treectrl->GetItemParent( item );
1278 PlaylistItem *p_parent =
1279 (PlaylistItem *)p->treectrl->GetItemData( parent );
1282 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1285 playlist_item_t *p_node =
1286 playlist_ItemGetById( p->p_playlist, p_parent->i_id );
1289 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1292 for( i_pos = 0; i_pos < p_node->i_children; i_pos++ )
1294 if( p_node->pp_children[i_pos] == p_dest ) break;
1300 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1302 /* Put the items in the playlist node */
1303 for( size_t i = 0; i < filenames.GetCount(); i++ )
1305 char *psz_utf8 = wxDnDFromLocale( filenames[i] );
1306 input_item_t *p_input = input_ItemNew( p->p_playlist,
1307 psz_utf8, psz_utf8 );
1308 playlist_NodeAddInput( p->p_playlist, p_input,
1309 p_dest, PLAYLIST_PREPARSE, i_pos );
1310 wxDnDLocaleFree( psz_utf8 );
1313 /* FIXME: having this Rebuild() is dirty */
1314 p->Rebuild( VLC_TRUE );
1320 /**********************************************************************
1322 **********************************************************************/
1324 void Playlist::OnMenuOpen( wxMenuEvent& event)
1326 #if defined( __WXMSW__ )
1327 # define GetEventObject GetMenu
1330 if( event.GetEventObject() == p_view_menu )
1332 p_view_menu = ViewMenu();
1334 #if defined( __WXMSW__ )
1335 # undef GetEventObject
1339 void Playlist::OnMenuEvent( wxCommandEvent& event )
1341 if( event.GetId() < FirstView_Event )
1346 else if( event.GetId() < LastView_Event )
1348 if( event.GetId() == CategoryView_Event )
1350 p_current_viewroot = p_playlist->p_root_category;
1351 if( p_current_treeroot == p_playlist->p_local_category ||
1352 p_current_treeroot == p_playlist->p_local_onelevel )
1354 p_current_treeroot = p_playlist->p_local_category;
1356 else if( p_current_treeroot == p_playlist->p_ml_category ||
1357 p_current_treeroot == p_playlist->p_ml_onelevel )
1359 p_current_treeroot = p_playlist->p_ml_category;
1362 else if( event.GetId() == OneLevelView_Event )
1364 p_current_viewroot = p_playlist->p_root_onelevel;
1365 if( p_current_treeroot == p_playlist->p_local_category ||
1366 p_current_treeroot == p_playlist->p_local_onelevel )
1368 p_current_treeroot = p_playlist->p_local_onelevel;
1370 else if( p_current_treeroot == p_playlist->p_ml_category ||
1371 p_current_treeroot == p_playlist->p_ml_onelevel )
1373 p_current_treeroot = p_playlist->p_ml_onelevel;
1376 wxCommandEvent event;
1380 else if( event.GetId() >= FirstSD_Event && event.GetId() < LastSD_Event )
1382 if( !playlist_IsServicesDiscoveryLoaded( p_playlist,
1383 pp_sds[event.GetId() - FirstSD_Event] ) )
1385 playlist_ServicesDiscoveryAdd( p_playlist,
1386 pp_sds[event.GetId() - FirstSD_Event] );
1390 //wxMutexGuiLeave();
1391 playlist_ServicesDiscoveryRemove( p_playlist,
1392 pp_sds[event.GetId() - FirstSD_Event] );
1393 //wxMutexGuiEnter();
1398 wxMenu * Playlist::ViewMenu()
1402 p_view_menu = new wxMenu;
1406 wxMenuItemList::Node *node = p_view_menu->GetMenuItems().GetFirst();
1409 wxMenuItem *item = node->GetData();
1410 node = node->GetNext();
1411 p_view_menu->Delete( item );
1415 p_view_menu->Append( CategoryView_Event, wxU(_("Normal") ) );
1416 p_view_menu->Append( OneLevelView_Event, wxU(_("One level") ) );
1420 wxMenu *Playlist::SDMenu()
1422 p_sd_menu = new wxMenu;
1424 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
1428 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1430 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1432 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1435 if( i_number ) pp_sds = (char **)calloc( i_number, sizeof(void *) );
1438 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1440 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1442 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1444 p_sd_menu->AppendCheckItem( FirstSD_Event + i_number ,
1445 wxU( p_parser->psz_longname ? p_parser->psz_longname :
1446 (p_parser->psz_shortname ?
1447 p_parser->psz_shortname : p_parser->psz_object_name) ) );
1449 /* hack to handle submodules properly */
1451 while( p_parser->pp_shortcuts[++i] != NULL );
1453 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
1454 i>=0?p_parser->pp_shortcuts[i]
1455 :p_parser->psz_object_name ) )
1457 p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
1460 pp_sds[i_number++] = i>=0?p_parser->pp_shortcuts[i]
1461 :p_parser->psz_object_name;
1464 vlc_list_release( p_list );
1469 /*****************************************************************************
1470 * Popup management functions
1471 *****************************************************************************/
1472 void Playlist::OnPopup( wxContextMenuEvent& event )
1474 wxPoint pt = event.GetPosition();
1475 playlist_item_t *p_item;
1477 i_wx_popup_item = treectrl->HitTest( ScreenToClient( pt ) );
1478 if( i_wx_popup_item.IsOk() )
1480 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1482 PlaylistItem *p_wxparent= (PlaylistItem *)treectrl->GetItemData(
1483 treectrl->GetItemParent( i_wx_popup_item ) );
1484 i_popup_item = p_wxitem->i_id;
1485 i_popup_parent = p_wxparent->i_id;
1486 treectrl->SelectItem( i_wx_popup_item );
1488 LockPlaylist( p_intf->p_sys, p_playlist );
1489 p_item = playlist_ItemGetById( p_playlist, i_popup_item );
1493 UnlockPlaylist( p_intf->p_sys, p_playlist );
1496 if( p_item->i_children == -1 )
1498 UnlockPlaylist( p_intf->p_sys, p_playlist );
1499 Playlist::PopupMenu( item_popup,
1500 ScreenToClient( wxGetMousePosition() ) );
1504 UnlockPlaylist( p_intf->p_sys, p_playlist );
1505 Playlist::PopupMenu( node_popup,
1506 ScreenToClient( wxGetMousePosition() ) );
1511 void Playlist::OnPopupPlay( wxCommandEvent& event )
1513 playlist_item_t *p_popup_item, *p_popup_parent;
1514 LockPlaylist( p_intf->p_sys, p_playlist );
1515 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1517 p_popup_parent = p_popup_item;
1518 while( p_popup_parent )
1520 if( p_popup_parent == p_current_treeroot )
1522 p_popup_parent = p_popup_parent->p_parent;
1525 if( p_popup_parent )
1527 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_popup_parent,
1530 UnlockPlaylist( p_intf->p_sys, p_playlist );
1533 void Playlist::OnPopupPreparse( wxCommandEvent& event )
1538 void Playlist::Preparse()
1540 playlist_item_t *p_popup_item;
1541 LockPlaylist( p_intf->p_sys, p_playlist );
1542 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1544 if( p_popup_item != NULL )
1546 if( p_popup_item->i_children == -1 )
1548 playlist_PreparseEnqueue( p_playlist, p_popup_item->p_input );
1553 playlist_item_t *p_parent = p_popup_item;
1554 for( i = 0; i< p_parent->i_children ; i++ )
1557 i_wx_popup_item = FindItem( treectrl->GetRootItem(),
1558 p_parent->pp_children[i]->i_id );
1559 i_popup_item = p_parent->pp_children[i]->i_id;
1564 UnlockPlaylist( p_intf->p_sys, p_playlist );
1567 void Playlist::OnPopupDel( wxCommandEvent& event )
1569 DeleteTreeItem( i_wx_popup_item );
1572 void Playlist::OnPopupSort( wxCommandEvent& event )
1574 PlaylistItem *p_wxitem;
1575 playlist_item_t *p_item;
1577 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1578 LockPlaylist( p_intf->p_sys, p_playlist );
1580 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1581 if( p_item->i_children >= 0 )
1583 playlist_RecursiveNodeSort( p_playlist, p_item,
1584 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
1586 treectrl->DeleteChildren( i_wx_popup_item );
1587 i_saved_id = -1; i_saved_input_id = -1;
1588 UpdateNodeChildren( p_item, i_wx_popup_item );
1591 UnlockPlaylist( p_intf->p_sys, p_playlist );
1594 void Playlist::OnPopupInfo( wxCommandEvent& event )
1596 LockPlaylist( p_intf->p_sys, p_playlist );
1597 playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1600 iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this );
1601 if( iteminfo_dialog->ShowModal() == wxID_OK )
1603 UpdateItem( i_wx_popup_item );
1605 delete iteminfo_dialog;
1607 UnlockPlaylist( p_intf->p_sys, p_playlist );
1610 void Playlist::OnPopupAddNode( wxCommandEvent& event )
1612 wxTextEntryDialog text( NULL, wxU(_( "Please enter node name" )),
1613 wxU(_( "Add node" )), wxU(_( "New node" )) );
1614 if( text.ShowModal() != wxID_OK ) return;
1616 char *psz_name = wxFromLocale( text.GetValue() );
1618 LockPlaylist( p_intf->p_sys, p_playlist );
1620 PlaylistItem *p_wxitem;
1621 playlist_item_t *p_item;
1623 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1625 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1627 playlist_NodeCreate( p_playlist, psz_name, p_item );
1629 UnlockPlaylist( p_intf->p_sys, p_playlist );
1630 Rebuild( VLC_TRUE );
1632 wxLocaleFree( psz_name );
1635 void Playlist::OnSourceSelected( wxListEvent &event )
1637 int i_id = event.GetData();
1639 if( p_current_treeroot && i_id != p_current_treeroot->i_id )
1641 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
1642 if( p_item ) p_current_treeroot = p_item;
1643 Rebuild( VLC_TRUE );
1647 /*****************************************************************************
1648 * Custom events management
1649 *****************************************************************************/
1650 void Playlist::OnPlaylistEvent( wxCommandEvent& event )
1652 switch( event.GetId() )
1654 case UpdateItem_Event:
1655 UpdateItem( event.GetInt() );
1657 case AppendItem_Event:
1658 AppendItem( event );
1660 case RemoveItem_Event:
1661 RemoveItem( event.GetInt() );
1666 /*****************************************************************************
1667 * PlaylistChanged: callback triggered by the intf-change playlist variable
1668 * We don't rebuild the playlist directly here because we don't want the
1669 * caller to block for a too long time.
1670 *****************************************************************************/
1671 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1672 vlc_value_t oval, vlc_value_t nval, void *param )
1674 Playlist *p_playlist_dialog = (Playlist *)param;
1675 p_playlist_dialog->b_need_update = VLC_TRUE;
1679 /*****************************************************************************
1680 * Next: callback triggered by the playlist-current playlist variable
1681 *****************************************************************************/
1682 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1683 vlc_value_t oval, vlc_value_t nval, void *param )
1685 Playlist *p_playlist_dialog = (Playlist *)param;
1687 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1688 event.SetInt( oval.i_int );
1689 p_playlist_dialog->AddPendingEvent( event );
1690 event.SetInt( nval.i_int );
1691 p_playlist_dialog->AddPendingEvent( event );
1696 /*****************************************************************************
1697 * ItemChanged: callback triggered by the item-change playlist variable
1698 *****************************************************************************/
1699 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1700 vlc_value_t old_val, vlc_value_t new_val, void *param )
1702 Playlist *p_playlist_dialog = (Playlist *)param;
1704 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1705 event.SetInt( new_val.i_int );
1706 p_playlist_dialog->AddPendingEvent( event );
1710 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1711 vlc_value_t old_val, vlc_value_t new_val, void *param )
1713 Playlist *p_playlist_dialog = (Playlist *)param;
1715 wxCommandEvent event( wxEVT_PLAYLIST, RemoveItem_Event );
1716 event.SetInt( new_val.i_int );
1717 p_playlist_dialog->AddPendingEvent( event );
1722 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1723 vlc_value_t oval, vlc_value_t nval, void *param )
1725 Playlist *p_playlist_dialog = (Playlist *)param;
1727 playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
1728 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1730 if( ++p_playlist_dialog->i_items_to_append >= 50 )
1732 /* Too many items waiting to be added, it will be quicker to rebuild
1733 * the whole playlist */
1734 p_playlist_dialog->b_need_update = VLC_TRUE;
1738 wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );
1739 event.SetClientData( (void *)p_add );
1740 p_playlist_dialog->AddPendingEvent( event );