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>
53 #define HELP_SHUFFLE N_( "Shuffle" )
54 #define HELP_LOOP N_( "Repeat All" )
55 #define HELP_REPEAT N_( "Repeat One" )
58 /* Callback prototype */
59 static int PlaylistChanged( vlc_object_t *, const char *,
60 vlc_value_t, vlc_value_t, void * );
61 static int PlaylistNext( vlc_object_t *, const char *,
62 vlc_value_t, vlc_value_t, void * );
63 static int ItemChanged( vlc_object_t *, const char *,
64 vlc_value_t, vlc_value_t, void * );
65 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
66 vlc_value_t oval, vlc_value_t nval, void *param );
67 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
68 vlc_value_t oval, vlc_value_t nval, void *param );
70 /*****************************************************************************
72 *****************************************************************************/
74 /* IDs for the controls and the menu commands */
89 DeleteSelection_Event,
108 Browse_Event, /* For export playlist */
115 MenuDummy_Event = wxID_HIGHEST + 999,
117 FirstView_Event = wxID_HIGHEST + 1000,
118 LastView_Event = wxID_HIGHEST + 1100,
120 FirstSD_Event = wxID_HIGHEST + 2000,
121 LastSD_Event = wxID_HIGHEST + 2100,
124 DEFINE_LOCAL_EVENT_TYPE( wxEVT_PLAYLIST );
126 BEGIN_EVENT_TABLE(Playlist, wxFrame)
127 EVT_SIZE(Playlist::OnSize)
130 EVT_MENU(AddFile_Event, Playlist::OnAddFile)
131 EVT_MENU(AddDir_Event, Playlist::OnAddDir)
132 EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
133 EVT_MENU(Close_Event, Playlist::OnMenuClose)
134 EVT_MENU(Open_Event, Playlist::OnOpen)
135 EVT_MENU(Save_Event, Playlist::OnSave)
137 EVT_MENU(SortTitle_Event, Playlist::OnSort)
138 EVT_MENU(RSortTitle_Event, Playlist::OnSort)
140 EVT_MENU(Randomize_Event, Playlist::OnSort)
142 EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
144 EVT_MENU_OPEN( Playlist::OnMenuOpen )
145 EVT_MENU( -1, Playlist::OnMenuEvent )
147 EVT_TOOL(Random_Event, Playlist::OnRandom)
148 EVT_TOOL(Repeat_Event, Playlist::OnRepeat)
149 EVT_TOOL(Loop_Event, Playlist::OnLoop)
152 EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
153 EVT_MENU( PopupPlayThis_Event, Playlist::OnPopupPlay)
154 EVT_MENU( PopupPreparse_Event, Playlist::OnPopupPreparse)
155 EVT_MENU( PopupSort_Event, Playlist::OnPopupSort)
156 EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
157 EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo)
158 EVT_MENU( PopupAddNode_Event, Playlist::OnPopupAddNode)
160 /* Tree control events */
161 EVT_TREE_ITEM_ACTIVATED( TreeCtrl_Event, Playlist::OnActivateItem )
162 EVT_TREE_KEY_DOWN( -1, Playlist::OnKeyDown )
163 EVT_TREE_BEGIN_DRAG( TreeCtrl_Event, Playlist::OnDragItemBegin )
164 EVT_TREE_END_DRAG( TreeCtrl_Event, Playlist::OnDragItemEnd )
166 EVT_CONTEXT_MENU( Playlist::OnPopup )
169 EVT_BUTTON( Search_Event, Playlist::OnSearch)
170 EVT_BUTTON( Save_Event, Playlist::OnSave)
172 /*EVT_TEXT( SearchText_Event, Playlist::OnSearchTextChange )*/
173 EVT_TEXT_ENTER( SearchText_Event, Playlist::OnSearch )
176 EVT_COMMAND(-1, wxEVT_PLAYLIST, Playlist::OnPlaylistEvent)
178 /* Special events : we don't want to destroy the window when the user
180 EVT_CLOSE(Playlist::OnClose)
183 /*****************************************************************************
185 ****************************************************************************/
186 class PlaylistItem : public wxTreeItemData
189 PlaylistItem( playlist_item_t *p_item ) : wxTreeItemData()
191 i_id = p_item->input.i_id;
195 friend class Playlist;
198 /*****************************************************************************
200 *****************************************************************************/
201 Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
202 wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
203 wxSize(500,300), wxDEFAULT_FRAME_STYLE )
207 /* Initializations */
210 i_update_counter = 0;
211 i_sort_mode = MODE_NONE;
212 b_need_update = VLC_FALSE;
213 i_items_to_append = 0;
214 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
216 if( p_playlist == NULL ) return;
218 SetIcon( *p_intf->p_sys->p_icon );
221 p_sd_menu = SDMenu();
223 i_current_view = VIEW_CATEGORY;
224 b_changed_view = VLC_FALSE;
228 i_duration_sorted = 0;
230 var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
231 var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
232 var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
234 /* Create our "Manage" menu */
235 wxMenu *manage_menu = new wxMenu;
236 manage_menu->Append( AddFile_Event, wxU(_("&Simple Add File...")) );
237 manage_menu->Append( AddDir_Event, wxU(_("Add &Directory...")) );
238 manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
239 manage_menu->AppendSeparator();
240 manage_menu->Append( MenuDummy_Event, wxU(_("Services discovery")),
242 manage_menu->AppendSeparator();
243 manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
244 manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
245 manage_menu->AppendSeparator();
246 manage_menu->Append( Close_Event, wxU(_("&Close")) );
248 /* Create our "Sort" menu */
249 wxMenu *sort_menu = new wxMenu;
250 sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
251 sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
252 sort_menu->AppendSeparator();
253 sort_menu->Append( Randomize_Event, wxU(_("&Shuffle Playlist")) );
255 /* Create our "Selection" menu */
256 wxMenu *selection_menu = new wxMenu;
257 selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
259 /* Create our "View" menu */
262 /* Append the freshly created menus to the menu bar */
263 wxMenuBar *menubar = new wxMenuBar();
264 menubar->Append( manage_menu, wxU(_("&Manage")) );
265 menubar->Append( sort_menu, wxU(_("S&ort")) );
266 menubar->Append( selection_menu, wxU(_("&Selection")) );
267 menubar->Append( p_view_menu, wxU(_("&View items") ) );
269 /* Attach the menu bar to the frame */
270 SetMenuBar( menubar );
272 /* Create the popup menu */
273 node_popup = new wxMenu;
274 node_popup->Append( PopupPlay_Event, wxU(_("Play")) );
275 node_popup->Append( PopupPlayThis_Event, wxU(_("Play this branch")) );
276 node_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
277 node_popup->Append( PopupSort_Event, wxU(_("Sort this branch")) );
278 node_popup->Append( PopupDel_Event, wxU(_("Delete")) );
279 node_popup->Append( PopupInfo_Event, wxU(_("Info")) );
280 node_popup->Append( PopupAddNode_Event, wxU(_("Add node")) );
282 item_popup = new wxMenu;
283 item_popup->Append( PopupPlay_Event, wxU(_("Play")) );
284 item_popup->Append( PopupPreparse_Event, wxU(_("Preparse")) );
285 item_popup->Append( PopupDel_Event, wxU(_("Delete")) );
286 item_popup->Append( PopupInfo_Event, wxU(_("Info")) );
288 /* Create a panel to put everything in */
289 wxPanel *playlist_panel = new wxPanel( this, -1 );
290 playlist_panel->SetAutoLayout( TRUE );
292 /* Create the toolbar */
294 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
296 /* Create the random tool */
297 toolbar->AddTool( Random_Event, wxT(""), wxBitmap(shuffle_on_xpm),
298 wxBitmap(shuffle_on_xpm), wxITEM_CHECK,
299 wxU(_(HELP_SHUFFLE) ) );
300 var_Get( p_intf, "random", &val );
301 toolbar->ToggleTool( Random_Event, val.b_bool );
303 /* Create the Loop tool */
304 toolbar->AddTool( Loop_Event, wxT(""), wxBitmap( loop_xpm),
305 wxBitmap( loop_xpm), wxITEM_CHECK,
306 wxU(_(HELP_LOOP ) ) );
307 var_Get( p_intf, "loop", &val );
308 toolbar->ToggleTool( Loop_Event, val.b_bool );
310 /* Create the Repeat one checkbox */
311 toolbar->AddTool( Repeat_Event, wxT(""), wxBitmap( repeat_xpm),
312 wxBitmap( repeat_xpm), wxITEM_CHECK,
313 wxU(_(HELP_REPEAT ) ) );
314 var_Get( p_intf, "repeat", &val );
315 toolbar->ToggleTool( Repeat_Event, val.b_bool ) ;
317 /* Create the Search Textbox */
318 search_text = new wxTextCtrl( toolbar, SearchText_Event, wxT(""),
319 wxDefaultPosition, wxSize(100, -1),
322 /* Create the search button */
323 search_button = new wxButton( toolbar , Search_Event, wxU(_("Search")) );
325 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
326 wxSize(16, 16), wxBORDER_NONE ) );
327 toolbar->AddControl( search_text );
328 toolbar->AddControl( new wxControl( toolbar, -1, wxDefaultPosition,
329 wxSize(5, 5), wxBORDER_NONE ) );
330 toolbar->AddControl( search_button );
331 search_button->SetDefault();
334 /* Create the tree */
335 treectrl = new wxTreeCtrl( playlist_panel, TreeCtrl_Event,
336 wxDefaultPosition, wxDefaultSize,
337 wxTR_HIDE_ROOT | wxTR_LINES_AT_ROOT|
339 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS |
340 wxTR_MULTIPLE | wxTR_EXTENDED );
342 /* Create image list */
343 wxImageList *p_images = new wxImageList( 16 , 16, TRUE );
345 /* FIXME: absolutely needs to be in the right order FIXME */
346 p_images->Add( wxIcon( type_unknown_xpm ) );
347 p_images->Add( wxIcon( type_afile_xpm ) );
348 p_images->Add( wxIcon( type_vfile_xpm ) );
349 p_images->Add( wxIcon( type_directory_xpm ) );
350 p_images->Add( wxIcon( type_disc_xpm ) );
351 p_images->Add( wxIcon( type_cdda_xpm ) );
352 p_images->Add( wxIcon( type_card_xpm ) );
353 p_images->Add( wxIcon( type_net_xpm ) );
354 p_images->Add( wxIcon( type_playlist_xpm ) );
355 p_images->Add( wxIcon( type_node_xpm ) );
356 treectrl->AssignImageList( p_images );
358 treectrl->AddRoot( wxU(_("root" )), -1, -1, NULL );
360 /* Reduce font size */
361 wxFont font= treectrl->GetFont();
362 font.SetPointSize(9);
363 treectrl->SetFont( font );
365 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
366 panel_sizer->Add( treectrl, 1, wxEXPAND | wxALL, 5 );
367 panel_sizer->Layout();
369 playlist_panel->SetSizerAndFit( panel_sizer );
371 int pi_widths[1] = { -1 };
372 statusbar = CreateStatusBar( 1 );
373 statusbar->SetStatusWidths( 1, pi_widths );
375 #if wxUSE_DRAG_AND_DROP
376 /* Associate drop targets with the playlist */
377 SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
383 /* We want to be noticed of playlist changes */
385 /* Some global changes happened -> Rebuild all */
386 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
388 /* We went to the next item */
389 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
391 /* One item has been updated */
392 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
394 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
395 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
397 /* Update the playlist */
402 Playlist::~Playlist()
404 if( pp_sds != NULL ) free( pp_sds );
406 if( p_playlist == NULL ) return;
408 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
409 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
410 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
411 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
412 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
413 vlc_object_release( p_playlist );
416 /**********************************************************************
418 **********************************************************************/
421 void Playlist::UpdateNode( playlist_item_t *p_node, wxTreeItemId node )
423 wxTreeItemIdValue cookie;
425 for( int i = 0; i< p_node->i_children ; i++ )
429 child = treectrl->GetFirstChild( node, cookie);
433 child = treectrl->GetNextChild( node, cookie );
438 /* Not enough children */
439 CreateNode( p_node->pp_children[i], node );
440 /* Keep the tree pointer up to date */
441 child = treectrl->GetNextChild( node, cookie );
444 treectrl->SetItemImage( node, p_node->input.i_type );
448 /* Creates the node p_node as last child of parent */
449 void Playlist::CreateNode( playlist_item_t *p_node, wxTreeItemId parent )
452 treectrl->AppendItem( parent, wxL2U( p_node->input.psz_name ),
453 -1,-1, new PlaylistItem( p_node ) );
454 treectrl->SetItemImage( node, p_node->input.i_type );
456 UpdateNodeChildren( p_node, node );
459 /* Update all children (recursively) of this node */
460 void Playlist::UpdateNodeChildren( playlist_item_t *p_node,
464 for( int i = 0; i< p_node->i_children ; i++ )
466 /* Append the item */
467 if( p_node->pp_children[i]->i_children == -1 )
470 treectrl->AppendItem( node,
471 wxL2U( p_node->pp_children[i]->input.psz_name ), -1,-1,
472 new PlaylistItem( p_node->pp_children[i]) );
474 UpdateTreeItem( item );
478 CreateNode( p_node->pp_children[i], node );
483 /* Update an item in the tree */
484 void Playlist::UpdateTreeItem( wxTreeItemId item )
486 if( ! item.IsOk() ) return;
488 wxTreeItemData *p_data = treectrl->GetItemData( item );
489 if( !p_data ) return;
491 LockPlaylist( p_intf->p_sys, p_playlist );
492 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
493 ((PlaylistItem *)p_data)->i_id );
496 UnlockPlaylist( p_intf->p_sys, p_playlist );
501 wxString duration = wxU( "" );
502 char *psz_author = vlc_input_item_GetInfo( &p_item->input,
503 _(VLC_META_INFO_CAT), _(VLC_META_ARTIST) );
506 UnlockPlaylist( p_intf->p_sys, p_playlist );
510 char psz_duration[MSTRTIME_MAX_SIZE];
511 mtime_t dur = p_item->input.i_duration;
515 secstotimestr( psz_duration, dur/1000000 );
516 duration.Append( wxU( " ( " ) + wxString( wxU( psz_duration ) ) +
520 if( !strcmp( psz_author, "" ) || p_item->input.b_fixed_name == VLC_TRUE )
522 msg = wxString( wxU( p_item->input.psz_name ) ) + duration;
526 msg = wxString(wxU( psz_author )) + wxT(" - ") +
527 wxString(wxU(p_item->input.psz_name)) + duration;
530 treectrl->SetItemText( item , msg );
531 treectrl->SetItemImage( item, p_item->input.i_type );
533 if( p_playlist->status.p_item == p_item )
535 treectrl->SetItemBold( item, true );
536 while( treectrl->GetItemParent( item ).IsOk() )
538 item = treectrl->GetItemParent( item );
539 treectrl->Expand( item );
544 treectrl->SetItemBold( item, false );
546 UnlockPlaylist( p_intf->p_sys, p_playlist );
549 /* Process a AppendIt em request */
550 void Playlist::AppendItem( wxCommandEvent& event )
552 playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();
553 playlist_item_t *p_item = NULL;
554 wxTreeItemId item, node;
558 /* No need to do anything if the playlist is going to be rebuilt */
559 if( b_need_update ) return;
561 if( p_add->i_view != i_current_view ) goto update;
563 node = FindItem( treectrl->GetRootItem(), p_add->i_node );
564 if( !node.IsOk() ) goto update;
566 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
567 if( !p_item ) goto update;
569 item = FindItem( treectrl->GetRootItem(), p_add->i_item );
570 if( item.IsOk() ) goto update;
572 item = treectrl->AppendItem( node,
573 wxL2U( p_item->input.psz_name ), -1,-1,
574 new PlaylistItem( p_item ) );
575 treectrl->SetItemImage( item, p_item->input.i_type );
577 if( item.IsOk() && p_item->i_children == -1 )
579 UpdateTreeItem( item );
583 int i_count = CountItems( treectrl->GetRootItem());
584 if( i_count != p_playlist->i_size )
586 statusbar->SetStatusText( wxString::Format( wxU(_(
587 "%i items in playlist (%i not shown)")),
589 p_playlist->i_size - i_count ) );
590 if( !b_changed_view )
592 i_current_view = VIEW_CATEGORY;
593 b_changed_view = VLC_TRUE;
594 b_need_update = VLC_TRUE;
599 statusbar->SetStatusText( wxString::Format( wxU(_(
600 "%i items in playlist")),
601 p_playlist->i_size ), 0 );
607 /* Process a updateitem request */
608 void Playlist::UpdateItem( int i )
610 if( i < 0 ) return; /* Sanity check */
612 wxTreeItemId item = FindItem( 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 wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
629 treectrl->Delete( item );
634 /**********************************************************************
635 * Search functions (internal)
636 **********************************************************************/
638 /* Find a wxItem from a playlist id */
639 wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id )
641 wxTreeItemIdValue cookie;
642 PlaylistItem *p_wxcurrent;
644 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
647 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
654 if( i_saved_id == i_id )
656 return saved_tree_item;
665 if( p_wxcurrent->i_id == i_id )
668 saved_tree_item = root;
674 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
675 if( p_wxcurrent->i_id == i_id )
678 saved_tree_item = item;
681 if( treectrl->ItemHasChildren( item ) )
683 wxTreeItemId search = FindItem( item, i_id );
687 saved_tree_item = search;
691 item = treectrl->GetNextChild( root, cookie );
698 int Playlist::CountItems( wxTreeItemId root )
700 wxTreeItemIdValue cookie;
702 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
706 if( treectrl->ItemHasChildren( item ) )
708 count += CountItems( item );
712 playlist_item_t *p_item;
713 LockPlaylist( p_intf->p_sys, p_playlist );
714 p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id );
715 if( p_item && p_item->i_children == -1 )
717 UnlockPlaylist( p_intf->p_sys, p_playlist );
719 item = treectrl->GetNextChild( root, cookie );
724 /* Find a wxItem from a name (from current) */
725 wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, vlc_bool_t *pb_current_found )
727 wxTreeItemIdValue cookie;
729 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
734 if( treectrl->GetItemText( item).Lower().Contains(
735 search_string.Lower() ) )
737 if( !current.IsOk() || *pb_current_found == VLC_TRUE )
741 else if( current.IsOk() && item == current )
743 *pb_current_found = VLC_TRUE;
746 if( treectrl->ItemHasChildren( item ) )
748 wxTreeItemId search = FindItemByName( item, search_string, current,
755 item = treectrl->GetNextChild( root, cookie);
762 /**********************************************************************
763 * Rebuild the playlist
764 **********************************************************************/
765 void Playlist::Rebuild( vlc_bool_t b_root )
767 playlist_view_t *p_view;
769 i_items_to_append = 0;
771 /* We can remove the callbacks before locking, anyway, we won't
775 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
776 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
777 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
778 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
779 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
781 /* ...and rebuild it */
782 LockPlaylist( p_intf->p_sys, p_playlist );
786 p_view = playlist_ViewFind( p_playlist, i_current_view ); /* FIXME */
788 /* HACK we should really get new*/
789 treectrl->DeleteAllItems();
790 treectrl->AddRoot( wxU(_("root" )), -1, -1,
791 new PlaylistItem( p_view->p_root) );
793 wxTreeItemId root = treectrl->GetRootItem();
794 UpdateNode( p_view->p_root, root );
796 int i_count = CountItems( treectrl->GetRootItem() );
798 if( i_count < p_playlist->i_size && !b_changed_view )
800 i_current_view = VIEW_CATEGORY;
801 b_changed_view = VLC_TRUE;
802 Rebuild( VLC_FALSE );
804 else if( i_count != p_playlist->i_size )
806 statusbar->SetStatusText( wxString::Format( wxU(_(
807 "%i items in playlist (%i not shown)")),
809 p_playlist->i_size - i_count ) );
813 statusbar->SetStatusText( wxString::Format( wxU(_(
814 "%i items in playlist")),
815 p_playlist->i_size ), 0 );
820 /* Put callbacks back online */
821 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
822 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
823 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
824 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
825 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
827 UnlockPlaylist( p_intf->p_sys, p_playlist );
833 void Playlist::ShowPlaylist( bool show )
835 if( show ) Rebuild( VLC_TRUE );
839 /* This function is called on a regular basis */
840 void Playlist::UpdatePlaylist()
844 /* If the playlist isn't show there's no need to update it */
845 if( !IsShown() ) return;
847 if( this->b_need_update )
849 this->b_need_update = VLC_FALSE;
853 /* Updating the playing status every 0.5s is enough */
854 if( i_update_counter % 5 ) return;
857 /*****************************************************************************
859 *****************************************************************************/
860 void Playlist::DeleteTreeItem( wxTreeItemId item )
862 PlaylistItem *p_wxitem;
863 playlist_item_t *p_item;
864 p_wxitem = (PlaylistItem *)treectrl->GetItemData( item );
866 LockPlaylist( p_intf->p_sys, p_playlist );
867 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
871 UnlockPlaylist( p_intf->p_sys, p_playlist );
875 if( p_item->i_children == -1 ) DeleteItem( p_item->input.i_id );
876 else DeleteNode( p_item );
879 UnlockPlaylist( p_intf->p_sys, p_playlist );
882 void Playlist::DeleteItem( int item_id )
884 playlist_Delete( p_playlist, item_id );
887 void Playlist::DeleteNode( playlist_item_t *p_item )
889 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );
892 void Playlist::OnMenuClose( wxCommandEvent& event )
898 void Playlist::OnClose( wxCloseEvent& WXUNUSED(event) )
903 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
909 } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" }};
911 wxString filter = wxT("");
913 if( p_playlist->i_size == 0 )
915 wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
916 wxICON_WARNING | wxOK, this );
920 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
922 filter.Append( wxU(formats[i].psz_desc) );
923 filter.Append( wxT("|") );
924 filter.Append( wxU(formats[i].psz_filter) );
925 filter.Append( wxT("|") );
927 wxFileDialog dialog( this, wxU(_("Save playlist")),
928 wxT(""), wxT(""), filter, wxSAVE );
930 if( dialog.ShowModal() == wxID_OK )
932 if( dialog.GetPath().mb_str() )
934 playlist_Export( p_playlist, dialog.GetPath().mb_str(),
935 formats[dialog.GetFilterIndex()].psz_module );
941 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
943 wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
944 wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
946 if( dialog.ShowModal() == wxID_OK )
948 playlist_Import( p_playlist, dialog.GetPath().mb_str() );
952 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
954 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
958 void Playlist::OnAddDir( wxCommandEvent& WXUNUSED(event) )
960 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY, 0, 0 );
964 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
966 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
970 /********************************************************************
972 ********************************************************************/
973 void Playlist::OnSort( wxCommandEvent& event )
975 PlaylistItem *p_wxitem;
976 p_wxitem = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
978 LockPlaylist( p_intf->p_sys, p_playlist );
979 switch( event.GetId() )
981 case SortTitle_Event:
982 playlist_RecursiveNodeSort( p_playlist,
983 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
984 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
986 case RSortTitle_Event:
987 playlist_RecursiveNodeSort( p_playlist,
988 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
989 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
991 UnlockPlaylist( p_intf->p_sys, p_playlist );
996 /**********************************************************************
997 * Search functions (user)
998 **********************************************************************/
999 /*void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
1001 search_button->SetDefault();
1004 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
1006 wxString search_string = search_text->GetValue();
1008 vlc_bool_t pb_found = VLC_FALSE;
1010 wxTreeItemId found =
1011 FindItemByName( treectrl->GetRootItem(), search_string,
1012 search_current, &pb_found );
1017 search_current = dummy;
1018 found = FindItemByName( treectrl->GetRootItem(), search_string,
1019 search_current, &pb_found );
1024 search_current = found;
1025 treectrl->EnsureVisible( found );
1026 treectrl->UnselectAll();
1027 treectrl->SelectItem( found, true );
1031 /**********************************************************************
1032 * Selection functions
1033 **********************************************************************/
1034 void Playlist::RecursiveDeleteSelection( wxTreeItemId root )
1036 wxTreeItemIdValue cookie;
1037 wxTreeItemId child = treectrl->GetFirstChild( root, cookie );
1038 while( child.IsOk() )
1040 if( treectrl->ItemHasChildren( child ) )
1042 RecursiveDeleteSelection( child );
1043 if( treectrl->IsSelected(child ) ) DeleteTreeItem( child );
1045 else if( treectrl->IsSelected( child ) )
1046 DeleteTreeItem( child );
1047 child = treectrl->GetNextChild( root, cookie );
1051 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
1053 RecursiveDeleteSelection( treectrl->GetRootItem() );
1056 /**********************************************************************
1057 * Playlist mode functions
1058 **********************************************************************/
1059 void Playlist::OnRandom( wxCommandEvent& event )
1062 val.b_bool = event.IsChecked();
1063 var_Set( p_playlist, "random", val);
1066 void Playlist::OnLoop( wxCommandEvent& event )
1069 val.b_bool = event.IsChecked();
1070 var_Set( p_playlist, "loop", val);
1073 void Playlist::OnRepeat( wxCommandEvent& event )
1076 val.b_bool = event.IsChecked();
1077 var_Set( p_playlist, "repeat", val);
1080 /********************************************************************
1082 ********************************************************************/
1083 void Playlist::OnActivateItem( wxTreeEvent& event )
1085 playlist_item_t *p_item,*p_node,*p_item2,*p_node2;
1087 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1089 wxTreeItemId parent = treectrl->GetItemParent( event.GetItem() );
1091 PlaylistItem *p_wxparent = (PlaylistItem *)treectrl->GetItemData( parent );
1093 LockPlaylist( p_intf->p_sys, p_playlist );
1095 if( !( p_wxitem && p_wxparent ) )
1097 UnlockPlaylist( p_intf->p_sys, p_playlist );
1101 p_item2 = playlist_ItemGetById(p_playlist, p_wxitem->i_id);
1102 p_node2 = playlist_ItemGetById(p_playlist, p_wxparent->i_id);
1103 if( p_item2 && p_item2->i_children == -1 )
1112 /* if( p_node && p_node->i_children > 0 &&
1113 p_node->pp_children[0]->i_children == -1)
1115 p_item = p_node->pp_children[0];
1123 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view,
1125 UnlockPlaylist( p_intf->p_sys, p_playlist );
1128 void Playlist::OnKeyDown( wxTreeEvent& event )
1130 long keycode = event.GetKeyCode();
1131 /* Delete selected items */
1132 if( keycode == WXK_BACK || keycode == WXK_DELETE )
1134 /* We send a dummy event */
1135 OnDeleteSelection( event );
1143 void Playlist::OnEnDis( wxCommandEvent& event )
1145 msg_Warn( p_intf, "not implemented" );
1148 void Playlist::OnDragItemBegin( wxTreeEvent& event )
1151 draged_tree_item = event.GetItem();
1154 void Playlist::OnDragItemEnd( wxTreeEvent& event )
1156 wxTreeItemId dest_tree_item = event.GetItem();
1158 if( !dest_tree_item.IsOk() ) return;
1160 /* check that we're not trying to move a node into one of it's children */
1161 wxTreeItemId parent = dest_tree_item;
1162 while( parent != treectrl->GetRootItem() )
1164 if( draged_tree_item == parent ) return;
1165 parent = treectrl->GetItemParent( parent );
1168 LockPlaylist( p_intf->p_sys, p_playlist );
1170 PlaylistItem *p_wxdrageditem =
1171 (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
1172 PlaylistItem *p_wxdestitem =
1173 (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
1174 if( !p_wxdrageditem || !p_wxdestitem )
1176 UnlockPlaylist( p_intf->p_sys, p_playlist );
1180 playlist_item_t *p_drageditem =
1181 playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id );
1182 playlist_item_t *p_destitem =
1183 playlist_ItemGetById(p_playlist, p_wxdestitem->i_id );
1184 if( !p_drageditem || !p_destitem )
1186 UnlockPlaylist( p_intf->p_sys, p_playlist );
1190 if( p_destitem->i_children == -1 )
1191 /* this is a leaf */
1193 parent = treectrl->GetItemParent( dest_tree_item );
1194 PlaylistItem *p_parent =
1195 (PlaylistItem *)treectrl->GetItemData( parent );
1198 UnlockPlaylist( p_intf->p_sys, p_playlist );
1201 playlist_item_t *p_destitem2 =
1202 playlist_ItemGetById( p_playlist, p_parent->i_id );
1205 UnlockPlaylist( p_intf->p_sys, p_playlist );
1209 for( i = 0; i < p_destitem2->i_children; i++ )
1211 if( p_destitem2->pp_children[i] == p_destitem ) break;
1213 playlist_TreeMove( p_playlist, p_drageditem, p_destitem2,
1214 i, i_current_view );
1217 /* this is a node */
1219 playlist_TreeMove( p_playlist, p_drageditem, p_destitem,
1220 0, i_current_view );
1223 UnlockPlaylist( p_intf->p_sys, p_playlist );
1225 Rebuild( VLC_TRUE );
1228 /**********************************************************************
1230 **********************************************************************/
1232 void Playlist::OnMenuOpen( wxMenuEvent& event)
1234 #if defined( __WXMSW__ )
1235 # define GetEventObject GetMenu
1238 if( event.GetEventObject() == p_view_menu )
1240 p_view_menu = ViewMenu();
1242 #if defined( __WXMSW__ )
1243 # undef GetEventObject
1247 void Playlist::OnMenuEvent( wxCommandEvent& event )
1249 if( event.GetId() < FirstView_Event )
1254 else if( event.GetId() < LastView_Event )
1257 int i_new_view = event.GetId() - FirstView_Event;
1259 playlist_view_t *p_view = playlist_ViewFind( p_playlist, i_new_view );
1261 if( p_view != NULL )
1263 b_changed_view = VLC_TRUE;
1264 i_current_view = i_new_view;
1265 playlist_ViewUpdate( p_playlist, i_new_view );
1266 Rebuild( VLC_TRUE );
1269 else if( i_new_view >= VIEW_FIRST_SORTED &&
1270 i_new_view <= VIEW_LAST_SORTED )
1272 b_changed_view = VLC_TRUE;
1273 playlist_ViewInsert( p_playlist, i_new_view, "View" );
1274 playlist_ViewUpdate( p_playlist, i_new_view );
1276 i_current_view = i_new_view;
1278 Rebuild( VLC_TRUE );
1281 else if( event.GetId() >= FirstSD_Event && event.GetId() < LastSD_Event )
1283 if( !playlist_IsServicesDiscoveryLoaded( p_playlist,
1284 pp_sds[event.GetId() - FirstSD_Event] ) )
1286 playlist_ServicesDiscoveryAdd( p_playlist,
1287 pp_sds[event.GetId() - FirstSD_Event] );
1291 //wxMutexGuiLeave();
1292 playlist_ServicesDiscoveryRemove( p_playlist,
1293 pp_sds[event.GetId() - FirstSD_Event] );
1294 //wxMutexGuiEnter();
1299 wxMenu * Playlist::ViewMenu()
1303 p_view_menu = new wxMenu;
1307 wxMenuItemList::Node *node = p_view_menu->GetMenuItems().GetFirst();
1310 wxMenuItem *item = node->GetData();
1311 node = node->GetNext();
1312 p_view_menu->Delete( item );
1316 /* FIXME : have a list of "should have" views */
1317 p_view_menu->Append( FirstView_Event + VIEW_CATEGORY,
1318 wxU(_("Normal") ) );
1319 p_view_menu->Append( FirstView_Event + VIEW_S_AUTHOR,
1320 wxU(_("Sorted by artist") ) );
1321 p_view_menu->Append( FirstView_Event + VIEW_S_ALBUM,
1322 wxU(_("Sorted by Album") ) );
1327 wxMenu *Playlist::SDMenu()
1329 p_sd_menu = new wxMenu;
1331 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
1335 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1337 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1339 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1342 if( i_number ) pp_sds = (char **)calloc( i_number, sizeof(void *) );
1345 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1347 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1349 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1351 p_sd_menu->AppendCheckItem( FirstSD_Event + i_number ,
1352 wxU( p_parser->psz_longname ? p_parser->psz_longname :
1353 (p_parser->psz_shortname ?
1354 p_parser->psz_shortname : p_parser->psz_object_name) ) );
1356 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
1357 p_parser->psz_object_name ) )
1359 p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
1362 pp_sds[i_number++] = p_parser->psz_object_name;
1365 vlc_list_release( p_list );
1370 /*****************************************************************************
1371 * Popup management functions
1372 *****************************************************************************/
1373 void Playlist::OnPopup( wxContextMenuEvent& event )
1375 wxPoint pt = event.GetPosition();
1376 playlist_item_t *p_item;
1378 i_wx_popup_item = treectrl->HitTest( ScreenToClient( pt ) );
1379 if( i_wx_popup_item.IsOk() )
1381 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1383 PlaylistItem *p_wxparent= (PlaylistItem *)treectrl->GetItemData(
1384 treectrl->GetItemParent( i_wx_popup_item ) );
1385 i_popup_item = p_wxitem->i_id;
1386 i_popup_parent = p_wxparent->i_id;
1387 treectrl->SelectItem( i_wx_popup_item );
1389 LockPlaylist( p_intf->p_sys, p_playlist );
1390 p_item = playlist_ItemGetById( p_playlist, i_popup_item );
1394 UnlockPlaylist( p_intf->p_sys, p_playlist );
1397 if( p_item->i_children == -1 )
1399 UnlockPlaylist( p_intf->p_sys, p_playlist );
1400 Playlist::PopupMenu( item_popup,
1401 ScreenToClient( wxGetMousePosition() ) );
1405 UnlockPlaylist( p_intf->p_sys, p_playlist );
1406 Playlist::PopupMenu( node_popup,
1407 ScreenToClient( wxGetMousePosition() ) );
1412 void Playlist::OnPopupPlay( wxCommandEvent& event )
1414 playlist_item_t *p_popup_item, *p_popup_parent;
1415 LockPlaylist( p_intf->p_sys, p_playlist );
1416 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1417 p_popup_parent = playlist_ItemGetById( p_playlist, i_popup_parent );
1418 if( p_popup_item != NULL )
1420 if( p_popup_item->i_children > -1 )
1422 if( event.GetId() == PopupPlay_Event &&
1423 p_popup_item->i_children > 0 )
1425 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
1426 i_current_view, p_popup_item,
1427 p_popup_item->pp_children[0] );
1431 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
1432 i_current_view, p_popup_item, NULL );
1437 if( event.GetId() == PopupPlay_Event )
1439 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
1440 i_current_view, p_popup_parent,
1445 UnlockPlaylist( p_intf->p_sys, p_playlist );
1448 void Playlist::OnPopupPreparse( wxCommandEvent& event )
1453 void Playlist::Preparse()
1455 playlist_item_t *p_popup_item;
1456 LockPlaylist( p_intf->p_sys, p_playlist );
1457 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1459 if( p_popup_item != NULL )
1461 if( p_popup_item->i_children == -1 )
1463 playlist_PreparseEnqueue( p_playlist, &p_popup_item->input );
1468 playlist_item_t *p_parent = p_popup_item;
1469 for( i = 0; i< p_parent->i_children ; i++ )
1472 i_wx_popup_item = FindItem( treectrl->GetRootItem(),
1473 p_parent->pp_children[i]->input.i_id );
1474 i_popup_item = p_parent->pp_children[i]->input.i_id;
1479 UnlockPlaylist( p_intf->p_sys, p_playlist );
1482 void Playlist::OnPopupDel( wxCommandEvent& event )
1484 DeleteTreeItem( i_wx_popup_item );
1487 void Playlist::OnPopupSort( wxCommandEvent& event )
1489 PlaylistItem *p_wxitem;
1490 playlist_item_t *p_item;
1492 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1493 LockPlaylist( p_intf->p_sys, p_playlist );
1495 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1496 if( p_item->i_children >= 0 )
1498 playlist_RecursiveNodeSort( p_playlist, p_item,
1499 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
1501 treectrl->DeleteChildren( i_wx_popup_item );
1503 UpdateNodeChildren( p_item, i_wx_popup_item );
1506 UnlockPlaylist( p_intf->p_sys, p_playlist );
1509 void Playlist::OnPopupInfo( wxCommandEvent& event )
1511 LockPlaylist( p_intf->p_sys, p_playlist );
1512 playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1515 iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this );
1516 if( iteminfo_dialog->ShowModal() == wxID_OK )
1518 UpdateItem( i_wx_popup_item );
1520 delete iteminfo_dialog;
1522 UnlockPlaylist( p_intf->p_sys, p_playlist );
1525 void Playlist::OnPopupAddNode( wxCommandEvent& event )
1527 wxTextEntryDialog text( NULL, wxU(_( "Please enter node name" )),
1528 wxU(_( "Add node" )), wxU(_( "New node" )) );
1529 if( text.ShowModal() != wxID_OK ) return;
1531 char *psz_name = wxFromLocale( text.GetValue() );
1533 LockPlaylist( p_intf->p_sys, p_playlist );
1535 PlaylistItem *p_wxitem;
1536 playlist_item_t *p_item;
1538 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1540 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1542 playlist_NodeCreate( p_playlist, 0, psz_name, p_item );
1544 UnlockPlaylist( p_intf->p_sys, p_playlist );
1545 Rebuild( VLC_TRUE );
1547 wxLocaleFree( psz_name );
1551 /*****************************************************************************
1552 * Custom events management
1553 *****************************************************************************/
1554 void Playlist::OnPlaylistEvent( wxCommandEvent& event )
1556 switch( event.GetId() )
1558 case UpdateItem_Event:
1559 UpdateItem( event.GetInt() );
1561 case AppendItem_Event:
1562 AppendItem( event );
1564 case RemoveItem_Event:
1565 RemoveItem( event.GetInt() );
1570 /*****************************************************************************
1571 * PlaylistChanged: callback triggered by the intf-change playlist variable
1572 * We don't rebuild the playlist directly here because we don't want the
1573 * caller to block for a too long time.
1574 *****************************************************************************/
1575 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1576 vlc_value_t oval, vlc_value_t nval, void *param )
1578 Playlist *p_playlist_dialog = (Playlist *)param;
1579 p_playlist_dialog->b_need_update = VLC_TRUE;
1583 /*****************************************************************************
1584 * Next: callback triggered by the playlist-current playlist variable
1585 *****************************************************************************/
1586 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1587 vlc_value_t oval, vlc_value_t nval, void *param )
1589 Playlist *p_playlist_dialog = (Playlist *)param;
1591 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1592 event.SetInt( oval.i_int );
1593 p_playlist_dialog->AddPendingEvent( event );
1594 event.SetInt( nval.i_int );
1595 p_playlist_dialog->AddPendingEvent( event );
1600 /*****************************************************************************
1601 * ItemChanged: callback triggered by the item-change playlist variable
1602 *****************************************************************************/
1603 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1604 vlc_value_t old_val, vlc_value_t new_val, void *param )
1606 Playlist *p_playlist_dialog = (Playlist *)param;
1608 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1609 event.SetInt( new_val.i_int );
1610 p_playlist_dialog->AddPendingEvent( event );
1614 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1615 vlc_value_t old_val, vlc_value_t new_val, void *param )
1617 Playlist *p_playlist_dialog = (Playlist *)param;
1619 wxCommandEvent event( wxEVT_PLAYLIST, RemoveItem_Event );
1620 event.SetInt( new_val.i_int );
1621 p_playlist_dialog->AddPendingEvent( event );
1626 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1627 vlc_value_t oval, vlc_value_t nval, void *param )
1629 Playlist *p_playlist_dialog = (Playlist *)param;
1631 playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
1632 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1634 if( ++p_playlist_dialog->i_items_to_append >= 50 )
1636 /* Too many items waiting to be added, it will be quicker to rebuild
1637 * the whole playlist */
1638 p_playlist_dialog->b_need_update = VLC_TRUE;
1642 wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );
1643 event.SetClientData( (void *)p_add );
1644 p_playlist_dialog->AddPendingEvent( event );