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"
30 #include "interface.hpp" // Needed for D&D - TODO: Split
32 #include "bitmaps/shuffle.xpm"
33 #include "bitmaps/repeat.xpm"
34 #include "bitmaps/loop.xpm"
36 #include "bitmaps/type_unknown.xpm"
37 #include "bitmaps/type_afile.xpm"
38 #include "bitmaps/type_vfile.xpm"
39 #include "bitmaps/type_net.xpm"
40 #include "bitmaps/type_card.xpm"
41 #include "bitmaps/type_disc.xpm"
42 #include "bitmaps/type_cdda.xpm"
43 #include "bitmaps/type_directory.xpm"
44 #include "bitmaps/type_playlist.xpm"
45 #include "bitmaps/type_node.xpm"
47 #include <wx/dynarray.h>
48 #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,
107 Browse_Event, /* For export playlist */
114 MenuDummy_Event = wxID_HIGHEST + 999,
116 FirstView_Event = wxID_HIGHEST + 1000,
117 LastView_Event = wxID_HIGHEST + 1100,
119 FirstSD_Event = wxID_HIGHEST + 2000,
120 LastSD_Event = wxID_HIGHEST + 2100,
123 DEFINE_LOCAL_EVENT_TYPE( wxEVT_PLAYLIST );
125 BEGIN_EVENT_TABLE(Playlist, wxFrame)
126 EVT_SIZE(Playlist::OnSize)
129 EVT_MENU(AddFile_Event, Playlist::OnAddFile)
130 EVT_MENU(AddDir_Event, Playlist::OnAddDir)
131 EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
132 EVT_MENU(Close_Event, Playlist::OnMenuClose)
133 EVT_MENU(Open_Event, Playlist::OnOpen)
134 EVT_MENU(Save_Event, Playlist::OnSave)
136 EVT_MENU(SortTitle_Event, Playlist::OnSort)
137 EVT_MENU(RSortTitle_Event, Playlist::OnSort)
139 EVT_MENU(Randomize_Event, Playlist::OnSort)
141 EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
143 EVT_MENU_OPEN( Playlist::OnMenuOpen )
144 EVT_MENU( -1, Playlist::OnMenuEvent )
146 EVT_TOOL(Random_Event, Playlist::OnRandom)
147 EVT_TOOL(Repeat_Event, Playlist::OnRepeat)
148 EVT_TOOL(Loop_Event, Playlist::OnLoop)
151 EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
152 EVT_MENU( PopupPlayThis_Event, Playlist::OnPopupPlay)
153 EVT_MENU( PopupPreparse_Event, Playlist::OnPopupPreparse)
154 EVT_MENU( PopupSort_Event, Playlist::OnPopupSort)
155 EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
156 EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo)
157 EVT_MENU( PopupAddNode_Event, Playlist::OnPopupAddNode)
159 /* Tree control events */
160 EVT_TREE_ITEM_ACTIVATED( TreeCtrl_Event, Playlist::OnActivateItem )
161 EVT_TREE_KEY_DOWN( -1, Playlist::OnKeyDown )
162 EVT_TREE_BEGIN_DRAG( TreeCtrl_Event, Playlist::OnDragItemBegin )
163 EVT_TREE_END_DRAG( TreeCtrl_Event, Playlist::OnDragItemEnd )
165 EVT_CONTEXT_MENU( Playlist::OnPopup )
168 EVT_BUTTON( Search_Event, Playlist::OnSearch)
169 EVT_BUTTON( Save_Event, Playlist::OnSave)
171 /*EVT_TEXT( SearchText_Event, Playlist::OnSearchTextChange )*/
172 EVT_TEXT_ENTER( SearchText_Event, Playlist::OnSearch )
175 EVT_COMMAND(-1, wxEVT_PLAYLIST, Playlist::OnPlaylistEvent)
177 /* Special events : we don't want to destroy the window when the user
179 EVT_CLOSE(Playlist::OnClose)
182 /*****************************************************************************
184 ****************************************************************************/
185 class PlaylistItem : public wxTreeItemData
188 PlaylistItem( playlist_item_t *p_item ) : wxTreeItemData()
190 i_id = p_item->input.i_id;
194 friend class Playlist;
197 /*****************************************************************************
199 *****************************************************************************/
200 Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
201 wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
202 wxSize(500,300), wxDEFAULT_FRAME_STYLE )
206 /* Initializations */
209 i_update_counter = 0;
210 i_sort_mode = MODE_NONE;
211 b_need_update = VLC_FALSE;
212 i_items_to_append = 0;
213 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
215 if( p_playlist == NULL ) return;
217 SetIcon( *p_intf->p_sys->p_icon );
220 p_sd_menu = SDMenu();
222 i_current_view = VIEW_CATEGORY;
223 b_changed_view = VLC_FALSE;
227 i_duration_sorted = 0;
229 var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
230 var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
231 var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
233 /* Create our "Manage" menu */
234 wxMenu *manage_menu = new wxMenu;
235 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add File...")) );
236 manage_menu->Append( AddDir_Event, wxU(_("Add &Directory...")) );
237 manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
238 manage_menu->AppendSeparator();
239 manage_menu->Append( MenuDummy_Event, wxU(_("Services discovery")),
241 manage_menu->AppendSeparator();
242 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
243 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
244 manage_menu->AppendSeparator();
245 manage_menu->Append( Close_Event, wxU(_("&Close")) );
247 /* Create our "Sort" menu */
248 wxMenu *sort_menu = new wxMenu;
249 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
250 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
251 sort_menu->AppendSeparator();
252 sort_menu->Append( Randomize_Event, wxU(_("&Shuffle Playlist")) );
254 /* Create our "Selection" menu */
255 wxMenu *selection_menu = new wxMenu;
256 selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
258 /* Create our "View" menu */
261 /* Append the freshly created menus to the menu bar */
262 wxMenuBar *menubar = new wxMenuBar();
263 menubar->Append( manage_menu, wxU(_("&Manage")) );
264 menubar->Append( sort_menu, wxU(_("S&ort")) );
265 menubar->Append( selection_menu, wxU(_("&Selection")) );
266 menubar->Append( p_view_menu, wxU(_("&View items") ) );
268 /* Attach the menu bar to the frame */
269 SetMenuBar( menubar );
271 /* Create the popup menu */
272 node_popup = new wxMenu;
273 node_popup->Append( PopupPlay_Event, wxU(_("Play")) );
274 node_popup->Append( PopupPlayThis_Event, wxU(_("Play this branch")) );
275 node_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
276 node_popup->Append( PopupSort_Event, wxU(_("Sort this branch")) );
277 node_popup->Append( PopupDel_Event, wxU(_("Delete")) );
278 node_popup->Append( PopupInfo_Event, wxU(_("Info")) );
279 node_popup->Append( PopupAddNode_Event, wxU(_("Add node")) );
281 item_popup = new wxMenu;
282 item_popup->Append( PopupPlay_Event, wxU(_("Play")) );
283 item_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
284 item_popup->Append( PopupDel_Event, wxU(_("Delete")) );
285 item_popup->Append( PopupInfo_Event, wxU(_("Info")) );
287 /* Create a panel to put everything in */
288 wxPanel *playlist_panel = new wxPanel( this, -1 );
289 playlist_panel->SetAutoLayout( TRUE );
291 /* Create the toolbar */
293 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
295 /* Create the random tool */
296 toolbar->AddTool( Random_Event, wxT(""), wxBitmap(shuffle_on_xpm),
297 wxBitmap(shuffle_on_xpm), wxITEM_CHECK,
298 wxU(_(HELP_SHUFFLE) ) );
299 var_Get( p_intf, "random", &val );
300 toolbar->ToggleTool( Random_Event, val.b_bool );
302 /* Create the Loop tool */
303 toolbar->AddTool( Loop_Event, wxT(""), wxBitmap( loop_xpm),
304 wxBitmap( loop_xpm), wxITEM_CHECK,
305 wxU(_(HELP_LOOP ) ) );
306 var_Get( p_intf, "loop", &val );
307 toolbar->ToggleTool( Loop_Event, val.b_bool );
309 /* Create the Repeat one checkbox */
310 toolbar->AddTool( Repeat_Event, wxT(""), wxBitmap( repeat_xpm),
311 wxBitmap( repeat_xpm), wxITEM_CHECK,
312 wxU(_(HELP_REPEAT ) ) );
313 var_Get( p_intf, "repeat", &val );
314 toolbar->ToggleTool( Repeat_Event, val.b_bool ) ;
316 /* Create the Search Textbox */
317 search_text = new wxTextCtrl( toolbar, SearchText_Event, wxT(""),
318 wxDefaultPosition, wxSize(100, -1),
321 /* Create the search button */
322 search_button = new wxButton( toolbar , Search_Event, wxU(_("Search")) );
324 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
325 wxSize(16, 16), wxBORDER_NONE ) );
326 toolbar->AddControl( search_text );
327 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
328 wxSize(5, 5), wxBORDER_NONE ) );
329 toolbar->AddControl( search_button );
330 search_button->SetDefault();
333 /* Create the tree */
334 treectrl = new wxTreeCtrl( playlist_panel, TreeCtrl_Event,
335 wxDefaultPosition, wxDefaultSize,
336 wxTR_HIDE_ROOT | wxTR_LINES_AT_ROOT|
338 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS |
339 wxTR_MULTIPLE | wxTR_EXTENDED );
341 /* Create image list */
342 wxImageList *p_images = new wxImageList( 16 , 16, TRUE );
344 /* FIXME: absolutely needs to be in the right order FIXME */
345 p_images->Add( wxIcon( type_unknown_xpm ) );
346 p_images->Add( wxIcon( type_afile_xpm ) );
347 p_images->Add( wxIcon( type_vfile_xpm ) );
348 p_images->Add( wxIcon( type_directory_xpm ) );
349 p_images->Add( wxIcon( type_disc_xpm ) );
350 p_images->Add( wxIcon( type_cdda_xpm ) );
351 p_images->Add( wxIcon( type_card_xpm ) );
352 p_images->Add( wxIcon( type_net_xpm ) );
353 p_images->Add( wxIcon( type_playlist_xpm ) );
354 p_images->Add( wxIcon( type_node_xpm ) );
355 treectrl->AssignImageList( p_images );
357 treectrl->AddRoot( wxU(_("root" )), -1, -1, NULL );
359 /* Reduce font size */
360 wxFont font= treectrl->GetFont();
361 font.SetPointSize(9);
362 treectrl->SetFont( font );
364 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
365 panel_sizer->Add( treectrl, 1, wxEXPAND | wxALL, 5 );
366 panel_sizer->Layout();
368 playlist_panel->SetSizerAndFit( panel_sizer );
370 int pi_widths[1] = { -1 };
371 statusbar = CreateStatusBar( 1 );
372 statusbar->SetStatusWidths( 1, pi_widths );
374 #if wxUSE_DRAG_AND_DROP
375 /* Associate drop targets with the playlist */
376 SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
382 /* We want to be noticed of playlist changes */
384 /* Some global changes happened -> Rebuild all */
385 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
387 /* We went to the next item */
388 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
390 /* One item has been updated */
391 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
393 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
394 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
396 /* Update the playlist */
401 Playlist::~Playlist()
403 if( pp_sds != NULL ) free( pp_sds );
405 if( p_playlist == NULL ) return;
407 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
408 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
409 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
410 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
411 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
412 vlc_object_release( p_playlist );
415 /**********************************************************************
417 **********************************************************************/
420 void Playlist::UpdateNode( playlist_item_t *p_node, wxTreeItemId node )
422 wxTreeItemIdValue cookie;
424 for( int i = 0; i< p_node->i_children ; i++ )
428 child = treectrl->GetFirstChild( node, cookie);
432 child = treectrl->GetNextChild( node, cookie );
437 /* Not enough children */
438 CreateNode( p_node->pp_children[i], node );
439 /* Keep the tree pointer up to date */
440 child = treectrl->GetNextChild( node, cookie );
443 treectrl->SetItemImage( node, p_node->input.i_type );
447 /* Creates the node p_node as last child of parent */
448 void Playlist::CreateNode( playlist_item_t *p_node, wxTreeItemId parent )
451 treectrl->AppendItem( parent, wxL2U( p_node->input.psz_name ),
452 -1,-1, new PlaylistItem( p_node ) );
453 treectrl->SetItemImage( node, p_node->input.i_type );
455 UpdateNodeChildren( p_node, node );
458 /* Update all children (recursively) of this node */
459 void Playlist::UpdateNodeChildren( playlist_item_t *p_node,
463 for( int i = 0; i< p_node->i_children ; i++ )
465 /* Append the item */
466 if( p_node->pp_children[i]->i_children == -1 )
469 treectrl->AppendItem( node,
470 wxL2U( p_node->pp_children[i]->input.psz_name ), -1,-1,
471 new PlaylistItem( p_node->pp_children[i]) );
473 UpdateTreeItem( item );
477 CreateNode( p_node->pp_children[i], node );
482 /* Update an item in the tree */
483 void Playlist::UpdateTreeItem( wxTreeItemId item )
485 if( ! item.IsOk() ) return;
487 wxTreeItemData *p_data = treectrl->GetItemData( item );
488 if( !p_data ) return;
490 LockPlaylist( p_intf->p_sys, p_playlist );
491 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
492 ((PlaylistItem *)p_data)->i_id );
495 UnlockPlaylist( p_intf->p_sys, p_playlist );
500 wxString duration = wxU( "" );
501 char *psz_author = vlc_input_item_GetInfo( &p_item->input,
502 _(VLC_META_INFO_CAT), _(VLC_META_ARTIST) );
505 UnlockPlaylist( p_intf->p_sys, p_playlist );
509 char psz_duration[MSTRTIME_MAX_SIZE];
510 mtime_t dur = p_item->input.i_duration;
514 secstotimestr( psz_duration, dur/1000000 );
515 duration.Append( wxU( " ( " ) + wxString( wxU( psz_duration ) ) +
519 if( !strcmp( psz_author, "" ) || p_item->input.b_fixed_name == VLC_TRUE )
521 msg = wxString( wxU( p_item->input.psz_name ) ) + duration;
525 msg = wxString(wxU( psz_author )) + wxT(" - ") +
526 wxString(wxU(p_item->input.psz_name)) + duration;
529 treectrl->SetItemText( item , msg );
530 treectrl->SetItemImage( item, p_item->input.i_type );
532 if( p_playlist->status.p_item == p_item )
534 treectrl->SetItemBold( item, true );
535 while( treectrl->GetItemParent( item ).IsOk() )
537 item = treectrl->GetItemParent( item );
538 treectrl->Expand( item );
543 treectrl->SetItemBold( item, false );
545 UnlockPlaylist( p_intf->p_sys, p_playlist );
548 /* Process a AppendIt em request */
549 void Playlist::AppendItem( wxCommandEvent& event )
551 playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();
552 playlist_item_t *p_item = NULL;
553 wxTreeItemId item, node;
557 /* No need to do anything if the playlist is going to be rebuilt */
558 if( b_need_update ) return;
560 if( p_add->i_view != i_current_view ) goto update;
562 node = FindItem( treectrl->GetRootItem(), p_add->i_node );
563 if( !node.IsOk() ) goto update;
565 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
566 if( !p_item ) goto update;
568 item = FindItem( treectrl->GetRootItem(), p_add->i_item );
569 if( item.IsOk() ) goto update;
571 item = treectrl->AppendItem( node,
572 wxL2U( p_item->input.psz_name ), -1,-1,
573 new PlaylistItem( p_item ) );
574 treectrl->SetItemImage( item, p_item->input.i_type );
576 if( item.IsOk() && p_item->i_children == -1 )
578 UpdateTreeItem( item );
582 int i_count = CountItems( treectrl->GetRootItem());
583 if( i_count != p_playlist->i_size )
585 statusbar->SetStatusText( wxString::Format( wxU(_(
586 "%i items in playlist (%i not shown)")),
588 p_playlist->i_size - i_count ) );
589 if( !b_changed_view )
591 i_current_view = VIEW_CATEGORY;
592 b_changed_view = VLC_TRUE;
593 b_need_update = VLC_TRUE;
598 statusbar->SetStatusText( wxString::Format( wxU(_(
599 "%i items in playlist")),
600 p_playlist->i_size ), 0 );
606 /* Process a updateitem request */
607 void Playlist::UpdateItem( int i )
609 if( i < 0 ) return; /* Sanity check */
611 wxTreeItemId item = FindItem( 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 wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
628 treectrl->Delete( item );
633 /**********************************************************************
634 * Search functions (internal)
635 **********************************************************************/
637 /* Find a wxItem from a playlist id */
638 wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id )
640 wxTreeItemIdValue cookie;
641 PlaylistItem *p_wxcurrent;
643 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
646 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
653 if( i_saved_id == i_id )
655 return saved_tree_item;
664 if( p_wxcurrent->i_id == i_id )
667 saved_tree_item = root;
673 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
674 if( p_wxcurrent->i_id == i_id )
677 saved_tree_item = item;
680 if( treectrl->ItemHasChildren( item ) )
682 wxTreeItemId search = FindItem( item, i_id );
686 saved_tree_item = search;
690 item = treectrl->GetNextChild( root, cookie );
697 int Playlist::CountItems( wxTreeItemId root )
699 wxTreeItemIdValue cookie;
701 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
705 if( treectrl->ItemHasChildren( item ) )
707 count += CountItems( item );
711 playlist_item_t *p_item;
712 LockPlaylist( p_intf->p_sys, p_playlist );
713 p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id );
714 if( p_item && p_item->i_children == -1 )
716 UnlockPlaylist( p_intf->p_sys, p_playlist );
718 item = treectrl->GetNextChild( root, cookie );
723 /* Find a wxItem from a name (from current) */
724 wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, vlc_bool_t *pb_current_found )
726 wxTreeItemIdValue cookie;
728 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
733 if( treectrl->GetItemText( item).Lower().Contains(
734 search_string.Lower() ) )
736 if( !current.IsOk() || *pb_current_found == VLC_TRUE )
740 else if( current.IsOk() && item == current )
742 *pb_current_found = VLC_TRUE;
745 if( treectrl->ItemHasChildren( item ) )
747 wxTreeItemId search = FindItemByName( item, search_string, current,
754 item = treectrl->GetNextChild( root, cookie);
761 /**********************************************************************
762 * Rebuild the playlist
763 **********************************************************************/
764 void Playlist::Rebuild( vlc_bool_t b_root )
766 playlist_view_t *p_view;
768 i_items_to_append = 0;
770 /* We can remove the callbacks before locking, anyway, we won't
774 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
775 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
776 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
777 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
778 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
780 /* ...and rebuild it */
781 LockPlaylist( p_intf->p_sys, p_playlist );
785 p_view = playlist_ViewFind( p_playlist, i_current_view ); /* FIXME */
787 /* HACK we should really get new*/
788 treectrl->DeleteAllItems();
789 treectrl->AddRoot( wxU(_("root" )), -1, -1,
790 new PlaylistItem( p_view->p_root) );
792 wxTreeItemId root = treectrl->GetRootItem();
793 UpdateNode( p_view->p_root, root );
795 int i_count = CountItems( treectrl->GetRootItem() );
797 if( i_count < p_playlist->i_size && !b_changed_view )
799 i_current_view = VIEW_CATEGORY;
800 b_changed_view = VLC_TRUE;
801 Rebuild( VLC_FALSE );
803 else if( i_count != p_playlist->i_size )
805 statusbar->SetStatusText( wxString::Format( wxU(_(
806 "%i items in playlist (%i not shown)")),
808 p_playlist->i_size - i_count ) );
812 statusbar->SetStatusText( wxString::Format( wxU(_(
813 "%i items in playlist")),
814 p_playlist->i_size ), 0 );
819 /* Put callbacks back online */
820 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
821 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
822 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
823 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
824 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
826 UnlockPlaylist( p_intf->p_sys, p_playlist );
832 void Playlist::ShowPlaylist( bool show )
834 if( show ) Rebuild( VLC_TRUE );
838 /* This function is called on a regular basis */
839 void Playlist::UpdatePlaylist()
843 /* If the playlist isn't show there's no need to update it */
844 if( !IsShown() ) return;
846 if( this->b_need_update )
848 this->b_need_update = VLC_FALSE;
852 /* Updating the playing status every 0.5s is enough */
853 if( i_update_counter % 5 ) return;
856 /*****************************************************************************
858 *****************************************************************************/
859 void Playlist::DeleteTreeItem( wxTreeItemId item )
861 PlaylistItem *p_wxitem;
862 playlist_item_t *p_item;
863 p_wxitem = (PlaylistItem *)treectrl->GetItemData( item );
865 LockPlaylist( p_intf->p_sys, p_playlist );
866 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
870 UnlockPlaylist( p_intf->p_sys, p_playlist );
874 if( p_item->i_children == -1 ) DeleteItem( p_item->input.i_id );
875 else DeleteNode( p_item );
878 UnlockPlaylist( p_intf->p_sys, p_playlist );
881 void Playlist::DeleteItem( int item_id )
883 playlist_Delete( p_playlist, item_id );
886 void Playlist::DeleteNode( playlist_item_t *p_item )
888 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );
891 void Playlist::OnMenuClose( wxCommandEvent& event )
897 void Playlist::OnClose( wxCloseEvent& WXUNUSED(event) )
902 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
908 } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" }};
910 wxString filter = wxT("");
912 if( p_playlist->i_size == 0 )
914 wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
915 wxICON_WARNING | wxOK, this );
919 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
921 filter.Append( wxU(formats[i].psz_desc) );
922 filter.Append( wxT("|") );
923 filter.Append( wxU(formats[i].psz_filter) );
924 filter.Append( wxT("|") );
926 wxFileDialog dialog( this, wxU(_("Save playlist")),
927 wxT(""), wxT(""), filter, wxSAVE );
929 if( dialog.ShowModal() == wxID_OK )
931 if( dialog.GetPath().mb_str() )
933 playlist_Export( p_playlist, dialog.GetPath().mb_str(),
934 formats[dialog.GetFilterIndex()].psz_module );
940 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
942 wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
943 wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
945 if( dialog.ShowModal() == wxID_OK )
947 playlist_Import( p_playlist, dialog.GetPath().mb_str() );
951 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
953 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
957 void Playlist::OnAddDir( wxCommandEvent& WXUNUSED(event) )
959 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY, 0, 0 );
963 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
965 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
969 /********************************************************************
971 ********************************************************************/
972 void Playlist::OnSort( wxCommandEvent& event )
974 PlaylistItem *p_wxitem;
975 p_wxitem = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
977 LockPlaylist( p_intf->p_sys, p_playlist );
978 switch( event.GetId() )
980 case SortTitle_Event:
981 playlist_RecursiveNodeSort( p_playlist,
982 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
983 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
985 case RSortTitle_Event:
986 playlist_RecursiveNodeSort( p_playlist,
987 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
988 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
990 UnlockPlaylist( p_intf->p_sys, p_playlist );
995 /**********************************************************************
996 * Search functions (user)
997 **********************************************************************/
998 /*void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
1000 search_button->SetDefault();
1003 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
1005 wxString search_string = search_text->GetValue();
1007 vlc_bool_t pb_found = VLC_FALSE;
1009 wxTreeItemId found =
1010 FindItemByName( treectrl->GetRootItem(), search_string,
1011 search_current, &pb_found );
1016 search_current = dummy;
1017 found = FindItemByName( treectrl->GetRootItem(), search_string,
1018 search_current, &pb_found );
1023 search_current = found;
1024 treectrl->EnsureVisible( found );
1025 treectrl->UnselectAll();
1026 treectrl->SelectItem( found, true );
1030 /**********************************************************************
1031 * Selection functions
1032 **********************************************************************/
1033 void Playlist::RecursiveDeleteSelection( wxTreeItemId root )
1035 wxTreeItemIdValue cookie;
1036 wxTreeItemId child = treectrl->GetFirstChild( root, cookie );
1037 while( child.IsOk() )
1039 if( treectrl->ItemHasChildren( child ) )
1041 RecursiveDeleteSelection( child );
1042 if( treectrl->IsSelected(child ) ) DeleteTreeItem( child );
1044 else if( treectrl->IsSelected( child ) )
1045 DeleteTreeItem( child );
1046 child = treectrl->GetNextChild( root, cookie );
1050 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
1052 RecursiveDeleteSelection( treectrl->GetRootItem() );
1055 /**********************************************************************
1056 * Playlist mode functions
1057 **********************************************************************/
1058 void Playlist::OnRandom( wxCommandEvent& event )
1061 val.b_bool = event.IsChecked();
1062 var_Set( p_playlist, "random", val);
1065 void Playlist::OnLoop( wxCommandEvent& event )
1068 val.b_bool = event.IsChecked();
1069 var_Set( p_playlist, "loop", val);
1072 void Playlist::OnRepeat( wxCommandEvent& event )
1075 val.b_bool = event.IsChecked();
1076 var_Set( p_playlist, "repeat", val);
1079 /********************************************************************
1081 ********************************************************************/
1082 void Playlist::OnActivateItem( wxTreeEvent& event )
1084 playlist_item_t *p_item,*p_node,*p_item2,*p_node2;
1086 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1088 wxTreeItemId parent = treectrl->GetItemParent( event.GetItem() );
1090 PlaylistItem *p_wxparent = (PlaylistItem *)treectrl->GetItemData( parent );
1092 LockPlaylist( p_intf->p_sys, p_playlist );
1094 if( !( p_wxitem && p_wxparent ) )
1096 UnlockPlaylist( p_intf->p_sys, p_playlist );
1100 p_item2 = playlist_ItemGetById(p_playlist, p_wxitem->i_id);
1101 p_node2 = playlist_ItemGetById(p_playlist, p_wxparent->i_id);
1102 if( p_item2 && p_item2->i_children == -1 )
1111 /* if( p_node && p_node->i_children > 0 &&
1112 p_node->pp_children[0]->i_children == -1)
1114 p_item = p_node->pp_children[0];
1122 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view,
1124 UnlockPlaylist( p_intf->p_sys, p_playlist );
1127 void Playlist::OnKeyDown( wxTreeEvent& event )
1129 long keycode = event.GetKeyCode();
1130 /* Delete selected items */
1131 if( keycode == WXK_BACK || keycode == WXK_DELETE )
1133 /* We send a dummy event */
1134 OnDeleteSelection( event );
1142 void Playlist::OnEnDis( wxCommandEvent& event )
1144 msg_Warn( p_intf, "not implemented" );
1147 void Playlist::OnDragItemBegin( wxTreeEvent& event )
1150 draged_tree_item = event.GetItem();
1153 void Playlist::OnDragItemEnd( wxTreeEvent& event )
1155 wxTreeItemId dest_tree_item = event.GetItem();
1157 /* check that we're not trying to move a node into one of it's children */
1158 wxTreeItemId parent = dest_tree_item;
1159 while( parent != treectrl->GetRootItem() )
1161 if( draged_tree_item == parent ) return;
1162 parent = treectrl->GetItemParent( parent );
1165 if( draged_tree_item != dest_tree_item )
1167 LockPlaylist( p_intf->p_sys, p_playlist );
1169 PlaylistItem *p_wxdrageditem =
1170 (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
1171 PlaylistItem *p_wxdestitem =
1172 (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
1174 playlist_item_t *p_drageditem =
1175 playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id );
1176 playlist_item_t *p_destitem =
1177 playlist_ItemGetById(p_playlist, p_wxdestitem->i_id );
1179 if( p_destitem->i_children == -1 )
1180 /* this is a leaf */
1182 parent = treectrl->GetItemParent( dest_tree_item );
1183 PlaylistItem *p_parent =
1184 (PlaylistItem *)treectrl->GetItemData( parent );
1185 playlist_item_t *p_destitem2 =
1186 playlist_ItemGetById( p_playlist, p_parent->i_id );
1188 for( i = 0; i < p_destitem2->i_children; i++ )
1190 if( p_destitem2->pp_children[i] == p_destitem ) break;
1192 playlist_TreeMove( p_playlist, p_drageditem, p_destitem2,
1193 i, i_current_view );
1196 /* this is a node */
1198 playlist_TreeMove( p_playlist, p_drageditem, p_destitem,
1199 0, i_current_view );
1201 UnlockPlaylist( p_intf->p_sys, p_playlist );
1202 Rebuild( VLC_TRUE );
1206 /**********************************************************************
1208 **********************************************************************/
1210 void Playlist::OnMenuOpen( wxMenuEvent& event)
1212 #if defined( __WXMSW__ )
1213 # define GetEventObject GetMenu
1216 if( event.GetEventObject() == p_view_menu )
1218 p_view_menu = ViewMenu();
1220 #if defined( __WXMSW__ )
1221 # undef GetEventObject
1225 void Playlist::OnMenuEvent( wxCommandEvent& event )
1227 if( event.GetId() < FirstView_Event )
1232 else if( event.GetId() < LastView_Event )
1235 int i_new_view = event.GetId() - FirstView_Event;
1237 playlist_view_t *p_view = playlist_ViewFind( p_playlist, i_new_view );
1239 if( p_view != NULL )
1241 b_changed_view = VLC_TRUE;
1242 i_current_view = i_new_view;
1243 playlist_ViewUpdate( p_playlist, i_new_view );
1244 Rebuild( VLC_TRUE );
1247 else if( i_new_view >= VIEW_FIRST_SORTED &&
1248 i_new_view <= VIEW_LAST_SORTED )
1250 b_changed_view = VLC_TRUE;
1251 playlist_ViewInsert( p_playlist, i_new_view, "View" );
1252 playlist_ViewUpdate( p_playlist, i_new_view );
1254 i_current_view = i_new_view;
1256 Rebuild( VLC_TRUE );
1259 else if( event.GetId() >= FirstSD_Event && event.GetId() < LastSD_Event )
1261 if( !playlist_IsServicesDiscoveryLoaded( p_playlist,
1262 pp_sds[event.GetId() - FirstSD_Event] ) )
1264 playlist_ServicesDiscoveryAdd( p_playlist,
1265 pp_sds[event.GetId() - FirstSD_Event] );
1269 //wxMutexGuiLeave();
1270 playlist_ServicesDiscoveryRemove( p_playlist,
1271 pp_sds[event.GetId() - FirstSD_Event] );
1272 //wxMutexGuiEnter();
1277 wxMenu * Playlist::ViewMenu()
1281 p_view_menu = new wxMenu;
1285 wxMenuItemList::Node *node = p_view_menu->GetMenuItems().GetFirst();
1288 wxMenuItem *item = node->GetData();
1289 node = node->GetNext();
1290 p_view_menu->Delete( item );
1294 /* FIXME : have a list of "should have" views */
1295 p_view_menu->Append( FirstView_Event + VIEW_CATEGORY,
1296 wxU(_("Normal") ) );
1297 p_view_menu->Append( FirstView_Event + VIEW_S_AUTHOR,
1298 wxU(_("Sorted by artist") ) );
1299 p_view_menu->Append( FirstView_Event + VIEW_S_ALBUM,
1300 wxU(_("Sorted by Album") ) );
1305 wxMenu *Playlist::SDMenu()
1307 p_sd_menu = new wxMenu;
1309 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
1313 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1315 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1317 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1320 if( i_number ) pp_sds = (char **)calloc( i_number, sizeof(void *) );
1323 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1325 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1327 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1329 p_sd_menu->AppendCheckItem( FirstSD_Event + i_number ,
1330 wxU( p_parser->psz_longname ? p_parser->psz_longname :
1331 (p_parser->psz_shortname ?
1332 p_parser->psz_shortname : p_parser->psz_object_name) ) );
1334 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
1335 p_parser->psz_object_name ) )
1337 p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
1340 pp_sds[i_number++] = p_parser->psz_object_name;
1343 vlc_list_release( p_list );
1348 /*****************************************************************************
1349 * Popup management functions
1350 *****************************************************************************/
1351 void Playlist::OnPopup( wxContextMenuEvent& event )
1353 wxPoint pt = event.GetPosition();
1354 playlist_item_t *p_item;
1356 i_wx_popup_item = treectrl->HitTest( ScreenToClient( pt ) );
1357 if( i_wx_popup_item.IsOk() )
1359 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1361 PlaylistItem *p_wxparent= (PlaylistItem *)treectrl->GetItemData(
1362 treectrl->GetItemParent( i_wx_popup_item ) );
1363 i_popup_item = p_wxitem->i_id;
1364 i_popup_parent = p_wxparent->i_id;
1365 treectrl->SelectItem( i_wx_popup_item );
1367 LockPlaylist( p_intf->p_sys, p_playlist );
1368 p_item = playlist_ItemGetById( p_playlist, i_popup_item );
1372 UnlockPlaylist( p_intf->p_sys, p_playlist );
1375 if( p_item->i_children == -1 )
1377 UnlockPlaylist( p_intf->p_sys, p_playlist );
1378 Playlist::PopupMenu( item_popup,
1379 ScreenToClient( wxGetMousePosition() ) );
1383 UnlockPlaylist( p_intf->p_sys, p_playlist );
1384 Playlist::PopupMenu( node_popup,
1385 ScreenToClient( wxGetMousePosition() ) );
1390 void Playlist::OnPopupPlay( wxCommandEvent& event )
1392 playlist_item_t *p_popup_item, *p_popup_parent;
1393 LockPlaylist( p_intf->p_sys, p_playlist );
1394 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1395 p_popup_parent = playlist_ItemGetById( p_playlist, i_popup_parent );
1396 if( p_popup_item != NULL )
1398 if( p_popup_item->i_children > -1 )
1400 if( event.GetId() == PopupPlay_Event &&
1401 p_popup_item->i_children > 0 )
1403 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
1404 i_current_view, p_popup_item,
1405 p_popup_item->pp_children[0] );
1409 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
1410 i_current_view, p_popup_item, NULL );
1415 if( event.GetId() == PopupPlay_Event )
1417 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
1418 i_current_view, p_popup_parent,
1423 UnlockPlaylist( p_intf->p_sys, p_playlist );
1426 void Playlist::OnPopupPreparse( wxCommandEvent& event )
1431 void Playlist::Preparse()
1433 playlist_item_t *p_popup_item;
1434 LockPlaylist( p_intf->p_sys, p_playlist );
1435 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1437 if( p_popup_item != NULL )
1439 if( p_popup_item->i_children == -1 )
1441 playlist_PreparseEnqueue( p_playlist, &p_popup_item->input );
1446 playlist_item_t *p_parent = p_popup_item;
1447 for( i = 0; i< p_parent->i_children ; i++ )
1450 i_wx_popup_item = FindItem( treectrl->GetRootItem(),
1451 p_parent->pp_children[i]->input.i_id );
1452 i_popup_item = p_parent->pp_children[i]->input.i_id;
1457 UnlockPlaylist( p_intf->p_sys, p_playlist );
1460 void Playlist::OnPopupDel( wxCommandEvent& event )
1462 DeleteTreeItem( i_wx_popup_item );
1465 void Playlist::OnPopupSort( wxCommandEvent& event )
1467 PlaylistItem *p_wxitem;
1468 playlist_item_t *p_item;
1470 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1471 LockPlaylist( p_intf->p_sys, p_playlist );
1473 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1474 if( p_item->i_children >= 0 )
1476 playlist_RecursiveNodeSort( p_playlist, p_item,
1477 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
1479 treectrl->DeleteChildren( i_wx_popup_item );
1481 UpdateNodeChildren( p_item, i_wx_popup_item );
1484 UnlockPlaylist( p_intf->p_sys, p_playlist );
1487 void Playlist::OnPopupInfo( wxCommandEvent& event )
1489 LockPlaylist( p_intf->p_sys, p_playlist );
1490 playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1493 iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this );
1494 if( iteminfo_dialog->ShowModal() == wxID_OK )
1496 UpdateItem( i_wx_popup_item );
1498 delete iteminfo_dialog;
1500 UnlockPlaylist( p_intf->p_sys, p_playlist );
1503 void Playlist::OnPopupAddNode( wxCommandEvent& event )
1505 wxTextEntryDialog text( NULL, wxU(_( "Please enter node name" )),
1506 wxU(_( "Add node" )), wxU(_( "New node" )) );
1507 if( text.ShowModal() != wxID_OK ) return;
1509 char *psz_name = wxFromLocale( text.GetValue() );
1511 LockPlaylist( p_intf->p_sys, p_playlist );
1513 PlaylistItem *p_wxitem;
1514 playlist_item_t *p_item;
1516 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1518 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1520 playlist_NodeCreate( p_playlist, 0, psz_name, p_item );
1522 UnlockPlaylist( p_intf->p_sys, p_playlist );
1523 Rebuild( VLC_TRUE );
1525 wxLocaleFree( psz_name );
1529 /*****************************************************************************
1530 * Custom events management
1531 *****************************************************************************/
1532 void Playlist::OnPlaylistEvent( wxCommandEvent& event )
1534 switch( event.GetId() )
1536 case UpdateItem_Event:
1537 UpdateItem( event.GetInt() );
1539 case AppendItem_Event:
1540 AppendItem( event );
1542 case RemoveItem_Event:
1543 RemoveItem( event.GetInt() );
1548 /*****************************************************************************
1549 * PlaylistChanged: callback triggered by the intf-change playlist variable
1550 * We don't rebuild the playlist directly here because we don't want the
1551 * caller to block for a too long time.
1552 *****************************************************************************/
1553 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1554 vlc_value_t oval, vlc_value_t nval, void *param )
1556 Playlist *p_playlist_dialog = (Playlist *)param;
1557 p_playlist_dialog->b_need_update = VLC_TRUE;
1561 /*****************************************************************************
1562 * Next: callback triggered by the playlist-current playlist variable
1563 *****************************************************************************/
1564 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1565 vlc_value_t oval, vlc_value_t nval, void *param )
1567 Playlist *p_playlist_dialog = (Playlist *)param;
1569 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1570 event.SetInt( oval.i_int );
1571 p_playlist_dialog->AddPendingEvent( event );
1572 event.SetInt( nval.i_int );
1573 p_playlist_dialog->AddPendingEvent( event );
1578 /*****************************************************************************
1579 * ItemChanged: callback triggered by the item-change playlist variable
1580 *****************************************************************************/
1581 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1582 vlc_value_t old_val, vlc_value_t new_val, void *param )
1584 Playlist *p_playlist_dialog = (Playlist *)param;
1586 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1587 event.SetInt( new_val.i_int );
1588 p_playlist_dialog->AddPendingEvent( event );
1592 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1593 vlc_value_t old_val, vlc_value_t new_val, void *param )
1595 Playlist *p_playlist_dialog = (Playlist *)param;
1597 wxCommandEvent event( wxEVT_PLAYLIST, RemoveItem_Event );
1598 event.SetInt( new_val.i_int );
1599 p_playlist_dialog->AddPendingEvent( event );
1604 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1605 vlc_value_t oval, vlc_value_t nval, void *param )
1607 Playlist *p_playlist_dialog = (Playlist *)param;
1609 playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
1610 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1612 if( ++p_playlist_dialog->i_items_to_append >= 50 )
1614 /* Too many items waiting to be added, it will be quicker to rebuild
1615 * the whole playlist */
1616 p_playlist_dialog->b_need_update = VLC_TRUE;
1620 wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );
1621 event.SetClientData( (void *)p_add );
1622 p_playlist_dialog->AddPendingEvent( event );