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,
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;
195 friend class PlaylistFileDropTarget;
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 PlaylistFileDropTarget( this ) );
378 menubar->SetDropTarget( new PlaylistFileDropTarget( this ) );
379 toolbar->SetDropTarget( new PlaylistFileDropTarget( this ) );
385 /* We want to be noticed of playlist changes */
387 /* Some global changes happened -> Rebuild all */
388 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
390 /* We went to the next item */
391 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
393 /* One item has been updated */
394 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
396 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
397 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
399 /* Update the playlist */
404 Playlist::~Playlist()
406 if( pp_sds != NULL ) free( pp_sds );
408 if( p_playlist == NULL ) return;
410 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
411 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
412 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
413 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
414 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
415 vlc_object_release( p_playlist );
418 /**********************************************************************
420 **********************************************************************/
423 void Playlist::UpdateNode( playlist_item_t *p_node, wxTreeItemId node )
425 wxTreeItemIdValue cookie;
427 for( int i = 0; i< p_node->i_children ; i++ )
431 child = treectrl->GetFirstChild( node, cookie);
435 child = treectrl->GetNextChild( node, cookie );
440 /* Not enough children */
441 CreateNode( p_node->pp_children[i], node );
442 /* Keep the tree pointer up to date */
443 child = treectrl->GetNextChild( node, cookie );
446 treectrl->SetItemImage( node, p_node->input.i_type );
450 /* Creates the node p_node as last child of parent */
451 void Playlist::CreateNode( playlist_item_t *p_node, wxTreeItemId parent )
454 treectrl->AppendItem( parent, wxL2U( p_node->input.psz_name ),
455 -1,-1, new PlaylistItem( p_node ) );
456 treectrl->SetItemImage( node, p_node->input.i_type );
458 UpdateNodeChildren( p_node, node );
461 /* Update all children (recursively) of this node */
462 void Playlist::UpdateNodeChildren( playlist_item_t *p_node,
466 for( int i = 0; i< p_node->i_children ; i++ )
468 /* Append the item */
469 if( p_node->pp_children[i]->i_children == -1 )
472 treectrl->AppendItem( node,
473 wxL2U( p_node->pp_children[i]->input.psz_name ), -1,-1,
474 new PlaylistItem( p_node->pp_children[i]) );
476 UpdateTreeItem( item );
480 CreateNode( p_node->pp_children[i], node );
485 /* Update an item in the tree */
486 void Playlist::UpdateTreeItem( wxTreeItemId item )
488 if( ! item.IsOk() ) return;
490 wxTreeItemData *p_data = treectrl->GetItemData( item );
491 if( !p_data ) return;
493 LockPlaylist( p_intf->p_sys, p_playlist );
494 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
495 ((PlaylistItem *)p_data)->i_id );
498 UnlockPlaylist( p_intf->p_sys, p_playlist );
503 wxString duration = wxU( "" );
504 char *psz_author = vlc_input_item_GetInfo( &p_item->input,
505 _(VLC_META_INFO_CAT), _(VLC_META_ARTIST) );
508 UnlockPlaylist( p_intf->p_sys, p_playlist );
512 char psz_duration[MSTRTIME_MAX_SIZE];
513 mtime_t dur = p_item->input.i_duration;
517 secstotimestr( psz_duration, dur/1000000 );
518 duration.Append( wxU( " ( " ) + wxString( wxU( psz_duration ) ) +
522 if( !strcmp( psz_author, "" ) || p_item->input.b_fixed_name == VLC_TRUE )
524 msg = wxString( wxU( p_item->input.psz_name ) ) + duration;
528 msg = wxString(wxU( psz_author )) + wxT(" - ") +
529 wxString(wxU(p_item->input.psz_name)) + duration;
532 treectrl->SetItemText( item , msg );
533 treectrl->SetItemImage( item, p_item->input.i_type );
535 if( p_playlist->status.p_item == p_item )
537 treectrl->SetItemBold( item, true );
538 while( treectrl->GetItemParent( item ).IsOk() )
540 item = treectrl->GetItemParent( item );
541 treectrl->Expand( item );
546 treectrl->SetItemBold( item, false );
548 UnlockPlaylist( p_intf->p_sys, p_playlist );
551 /* Process a AppendIt em request */
552 void Playlist::AppendItem( wxCommandEvent& event )
554 playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();
555 playlist_item_t *p_item = NULL;
556 wxTreeItemId item, node;
560 /* No need to do anything if the playlist is going to be rebuilt */
561 if( b_need_update ) return;
563 if( p_add->i_view != i_current_view ) goto update;
565 node = FindItem( treectrl->GetRootItem(), p_add->i_node );
566 if( !node.IsOk() ) goto update;
568 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
569 if( !p_item ) goto update;
571 item = FindItem( treectrl->GetRootItem(), p_add->i_item );
572 if( item.IsOk() ) goto update;
574 item = treectrl->AppendItem( node,
575 wxL2U( p_item->input.psz_name ), -1,-1,
576 new PlaylistItem( p_item ) );
577 treectrl->SetItemImage( item, p_item->input.i_type );
579 if( item.IsOk() && p_item->i_children == -1 )
581 UpdateTreeItem( item );
585 int i_count = CountItems( treectrl->GetRootItem());
586 if( i_count != p_playlist->i_size )
588 statusbar->SetStatusText( wxString::Format( wxU(_(
589 "%i items in playlist (%i not shown)")),
591 p_playlist->i_size - i_count ) );
592 if( !b_changed_view )
594 i_current_view = VIEW_CATEGORY;
595 b_changed_view = VLC_TRUE;
596 b_need_update = VLC_TRUE;
601 statusbar->SetStatusText( wxString::Format( wxU(_(
602 "%i items in playlist")),
603 p_playlist->i_size ), 0 );
609 /* Process a updateitem request */
610 void Playlist::UpdateItem( int i )
612 if( i < 0 ) return; /* Sanity check */
614 wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
618 UpdateTreeItem( item );
622 void Playlist::RemoveItem( int i )
624 if( i <= 0 ) return; /* Sanity check */
625 if( i == i_saved_id ) i_saved_id = -1;
627 wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
631 treectrl->Delete( item );
636 /**********************************************************************
637 * Search functions (internal)
638 **********************************************************************/
640 /* Find a wxItem from a playlist id */
641 wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id )
643 wxTreeItemIdValue cookie;
644 PlaylistItem *p_wxcurrent;
646 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
649 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
656 if( i_saved_id == i_id )
658 return saved_tree_item;
667 if( p_wxcurrent->i_id == i_id )
670 saved_tree_item = root;
676 p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
677 if( p_wxcurrent->i_id == i_id )
680 saved_tree_item = item;
683 if( treectrl->ItemHasChildren( item ) )
685 wxTreeItemId search = FindItem( item, i_id );
689 saved_tree_item = search;
693 item = treectrl->GetNextChild( root, cookie );
700 int Playlist::CountItems( wxTreeItemId root )
702 wxTreeItemIdValue cookie;
704 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
708 if( treectrl->ItemHasChildren( item ) )
710 count += CountItems( item );
714 playlist_item_t *p_item;
715 LockPlaylist( p_intf->p_sys, p_playlist );
716 p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id );
717 if( p_item && p_item->i_children == -1 )
719 UnlockPlaylist( p_intf->p_sys, p_playlist );
721 item = treectrl->GetNextChild( root, cookie );
726 /* Find a wxItem from a name (from current) */
727 wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, vlc_bool_t *pb_current_found )
729 wxTreeItemIdValue cookie;
731 wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
736 if( treectrl->GetItemText( item).Lower().Contains(
737 search_string.Lower() ) )
739 if( !current.IsOk() || *pb_current_found == VLC_TRUE )
743 else if( current.IsOk() && item == current )
745 *pb_current_found = VLC_TRUE;
748 if( treectrl->ItemHasChildren( item ) )
750 wxTreeItemId search = FindItemByName( item, search_string, current,
757 item = treectrl->GetNextChild( root, cookie);
764 /**********************************************************************
765 * Rebuild the playlist
766 **********************************************************************/
767 void Playlist::Rebuild( vlc_bool_t b_root )
769 playlist_view_t *p_view;
771 i_items_to_append = 0;
773 /* We can remove the callbacks before locking, anyway, we won't
777 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
778 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
779 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
780 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
781 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
783 /* ...and rebuild it */
784 LockPlaylist( p_intf->p_sys, p_playlist );
788 p_view = playlist_ViewFind( p_playlist, i_current_view ); /* FIXME */
790 /* HACK we should really get new*/
791 treectrl->DeleteAllItems();
792 treectrl->AddRoot( wxU(_("root" )), -1, -1,
793 new PlaylistItem( p_view->p_root) );
795 wxTreeItemId root = treectrl->GetRootItem();
796 UpdateNode( p_view->p_root, root );
798 int i_count = CountItems( treectrl->GetRootItem() );
800 if( i_count < p_playlist->i_size && !b_changed_view )
802 i_current_view = VIEW_CATEGORY;
803 b_changed_view = VLC_TRUE;
804 Rebuild( VLC_FALSE );
806 else if( i_count != p_playlist->i_size )
808 statusbar->SetStatusText( wxString::Format( wxU(_(
809 "%i items in playlist (%i not shown)")),
811 p_playlist->i_size - i_count ) );
815 statusbar->SetStatusText( wxString::Format( wxU(_(
816 "%i items in playlist")),
817 p_playlist->i_size ), 0 );
822 /* Put callbacks back online */
823 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
824 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
825 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
826 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
827 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
829 UnlockPlaylist( p_intf->p_sys, p_playlist );
835 void Playlist::ShowPlaylist( bool show )
837 if( show ) Rebuild( VLC_TRUE );
841 /* This function is called on a regular basis */
842 void Playlist::UpdatePlaylist()
846 /* If the playlist isn't show there's no need to update it */
847 if( !IsShown() ) return;
849 if( this->b_need_update )
851 this->b_need_update = VLC_FALSE;
855 /* Updating the playing status every 0.5s is enough */
856 if( i_update_counter % 5 ) return;
859 /*****************************************************************************
861 *****************************************************************************/
862 void Playlist::DeleteTreeItem( wxTreeItemId item )
864 PlaylistItem *p_wxitem;
865 playlist_item_t *p_item;
866 p_wxitem = (PlaylistItem *)treectrl->GetItemData( item );
868 LockPlaylist( p_intf->p_sys, p_playlist );
869 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
873 UnlockPlaylist( p_intf->p_sys, p_playlist );
877 if( p_item->i_children == -1 ) DeleteItem( p_item->input.i_id );
878 else DeleteNode( p_item );
881 UnlockPlaylist( p_intf->p_sys, p_playlist );
884 void Playlist::DeleteItem( int item_id )
886 playlist_Delete( p_playlist, item_id );
889 void Playlist::DeleteNode( playlist_item_t *p_item )
891 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );
894 void Playlist::OnMenuClose( wxCommandEvent& event )
900 void Playlist::OnClose( wxCloseEvent& WXUNUSED(event) )
905 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
911 } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" }};
913 wxString filter = wxT("");
915 if( p_playlist->i_size == 0 )
917 wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
918 wxICON_WARNING | wxOK, this );
922 for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
924 filter.Append( wxU(formats[i].psz_desc) );
925 filter.Append( wxT("|") );
926 filter.Append( wxU(formats[i].psz_filter) );
927 filter.Append( wxT("|") );
929 wxFileDialog dialog( this, wxU(_("Save playlist")),
930 wxT(""), wxT(""), filter, wxSAVE );
932 if( dialog.ShowModal() == wxID_OK )
934 if( dialog.GetPath().mb_str() )
936 playlist_Export( p_playlist, dialog.GetPath().mb_str(),
937 formats[dialog.GetFilterIndex()].psz_module );
943 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
945 wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
946 wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
948 if( dialog.ShowModal() == wxID_OK )
950 playlist_Import( p_playlist, dialog.GetPath().mb_str() );
954 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
956 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
960 void Playlist::OnAddDir( wxCommandEvent& WXUNUSED(event) )
962 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY, 0, 0 );
966 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
968 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
972 /********************************************************************
974 ********************************************************************/
975 void Playlist::OnSort( wxCommandEvent& event )
977 PlaylistItem *p_wxitem;
978 p_wxitem = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
980 LockPlaylist( p_intf->p_sys, p_playlist );
981 switch( event.GetId() )
983 case SortTitle_Event:
984 playlist_RecursiveNodeSort( p_playlist,
985 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
986 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
988 case RSortTitle_Event:
989 playlist_RecursiveNodeSort( p_playlist,
990 playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
991 SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
993 UnlockPlaylist( p_intf->p_sys, p_playlist );
998 /**********************************************************************
999 * Search functions (user)
1000 **********************************************************************/
1001 /*void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
1003 search_button->SetDefault();
1006 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
1008 wxString search_string = search_text->GetValue();
1010 vlc_bool_t pb_found = VLC_FALSE;
1012 wxTreeItemId found =
1013 FindItemByName( treectrl->GetRootItem(), search_string,
1014 search_current, &pb_found );
1019 search_current = dummy;
1020 found = FindItemByName( treectrl->GetRootItem(), search_string,
1021 search_current, &pb_found );
1026 search_current = found;
1027 treectrl->EnsureVisible( found );
1028 treectrl->UnselectAll();
1029 treectrl->SelectItem( found, true );
1033 /**********************************************************************
1034 * Selection functions
1035 **********************************************************************/
1036 void Playlist::RecursiveDeleteSelection( wxTreeItemId root )
1038 wxTreeItemIdValue cookie;
1039 wxTreeItemId child = treectrl->GetFirstChild( root, cookie );
1040 while( child.IsOk() )
1042 if( treectrl->ItemHasChildren( child ) )
1044 RecursiveDeleteSelection( child );
1045 if( treectrl->IsSelected(child ) ) DeleteTreeItem( child );
1047 else if( treectrl->IsSelected( child ) )
1048 DeleteTreeItem( child );
1049 child = treectrl->GetNextChild( root, cookie );
1053 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
1055 RecursiveDeleteSelection( treectrl->GetRootItem() );
1058 /**********************************************************************
1059 * Playlist mode functions
1060 **********************************************************************/
1061 void Playlist::OnRandom( wxCommandEvent& event )
1064 val.b_bool = event.IsChecked();
1065 var_Set( p_playlist, "random", val);
1068 void Playlist::OnLoop( wxCommandEvent& event )
1071 val.b_bool = event.IsChecked();
1072 var_Set( p_playlist, "loop", val);
1075 void Playlist::OnRepeat( wxCommandEvent& event )
1078 val.b_bool = event.IsChecked();
1079 var_Set( p_playlist, "repeat", val);
1082 /********************************************************************
1084 ********************************************************************/
1085 void Playlist::OnActivateItem( wxTreeEvent& event )
1087 playlist_item_t *p_item,*p_node,*p_item2,*p_node2;
1089 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1091 wxTreeItemId parent = treectrl->GetItemParent( event.GetItem() );
1093 PlaylistItem *p_wxparent = (PlaylistItem *)treectrl->GetItemData( parent );
1095 LockPlaylist( p_intf->p_sys, p_playlist );
1097 if( !( p_wxitem && p_wxparent ) )
1099 UnlockPlaylist( p_intf->p_sys, p_playlist );
1103 p_item2 = playlist_ItemGetById(p_playlist, p_wxitem->i_id);
1104 p_node2 = playlist_ItemGetById(p_playlist, p_wxparent->i_id);
1105 if( p_item2 && p_item2->i_children == -1 )
1114 /* if( p_node && p_node->i_children > 0 &&
1115 p_node->pp_children[0]->i_children == -1)
1117 p_item = p_node->pp_children[0];
1125 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view,
1127 UnlockPlaylist( p_intf->p_sys, p_playlist );
1130 void Playlist::OnKeyDown( wxTreeEvent& event )
1132 long keycode = event.GetKeyCode();
1133 /* Delete selected items */
1134 if( keycode == WXK_BACK || keycode == WXK_DELETE )
1136 /* We send a dummy event */
1137 OnDeleteSelection( event );
1145 void Playlist::OnEnDis( wxCommandEvent& event )
1147 msg_Warn( p_intf, "not implemented" );
1150 void Playlist::OnDragItemBegin( wxTreeEvent& event )
1153 draged_tree_item = event.GetItem();
1156 void Playlist::OnDragItemEnd( wxTreeEvent& event )
1158 wxTreeItemId dest_tree_item = event.GetItem();
1160 if( !dest_tree_item.IsOk() ) return;
1162 /* check that we're not trying to move a node into one of it's children */
1163 wxTreeItemId parent = dest_tree_item;
1164 while( parent != treectrl->GetRootItem() )
1166 if( draged_tree_item == parent ) return;
1167 parent = treectrl->GetItemParent( parent );
1170 LockPlaylist( p_intf->p_sys, p_playlist );
1172 PlaylistItem *p_wxdrageditem =
1173 (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
1174 PlaylistItem *p_wxdestitem =
1175 (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
1176 if( !p_wxdrageditem || !p_wxdestitem )
1178 UnlockPlaylist( p_intf->p_sys, p_playlist );
1182 playlist_item_t *p_drageditem =
1183 playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id );
1184 playlist_item_t *p_destitem =
1185 playlist_ItemGetById(p_playlist, p_wxdestitem->i_id );
1186 if( !p_drageditem || !p_destitem )
1188 UnlockPlaylist( p_intf->p_sys, p_playlist );
1192 if( p_destitem->i_children == -1 )
1193 /* this is a leaf */
1195 parent = treectrl->GetItemParent( dest_tree_item );
1196 PlaylistItem *p_parent =
1197 (PlaylistItem *)treectrl->GetItemData( parent );
1200 UnlockPlaylist( p_intf->p_sys, p_playlist );
1203 playlist_item_t *p_destitem2 =
1204 playlist_ItemGetById( p_playlist, p_parent->i_id );
1207 UnlockPlaylist( p_intf->p_sys, p_playlist );
1211 for( i = 0; i < p_destitem2->i_children; i++ )
1213 if( p_destitem2->pp_children[i] == p_destitem ) break;
1215 playlist_TreeMove( p_playlist, p_drageditem, p_destitem2,
1216 i, i_current_view );
1219 /* this is a node */
1221 playlist_TreeMove( p_playlist, p_drageditem, p_destitem,
1222 0, i_current_view );
1225 UnlockPlaylist( p_intf->p_sys, p_playlist );
1227 /* FIXME: having this Rebuild() is dirty */
1228 Rebuild( VLC_TRUE );
1231 #if wxUSE_DRAG_AND_DROP
1232 PlaylistFileDropTarget::PlaylistFileDropTarget( Playlist *p ):p( p ){}
1234 /********************************************************************
1235 * File Drag And Drop handling
1236 ********************************************************************/
1237 bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
1238 const wxArrayString& filenames )
1241 playlist_item_t *p_dest;
1243 LockPlaylist( p->p_intf->p_sys, p->p_playlist );
1245 /* find the destination node and position in that node */
1246 const wxPoint pt( x, y );
1247 wxTreeItemId item = p->treectrl->HitTest( pt );
1251 /* We were droped below the last item so we append to the
1253 p_dest = p->p_playlist->p_general;
1254 i_pos = PLAYLIST_END;
1258 PlaylistItem *p_plitem =
1259 (PlaylistItem *)p->treectrl->GetItemData( item );
1260 p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id );
1262 if( p_dest->i_children == -1 )
1264 /* This is a leaf. Append right after it
1265 * We thus need to find the parrent node and the position of the
1266 * leaf in it's children list */
1267 wxTreeItemId parent = p->treectrl->GetItemParent( item );
1268 PlaylistItem *p_parent =
1269 (PlaylistItem *)p->treectrl->GetItemData( parent );
1272 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1275 playlist_item_t *p_node =
1276 playlist_ItemGetById( p->p_playlist, p_parent->i_id );
1279 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1282 for( i_pos = 0; i_pos < p_node->i_children; i_pos++ )
1284 if( p_node->pp_children[i_pos] == p_dest ) break;
1290 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
1292 /* Put the items in the playlist node */
1293 for( size_t i = 0; i < filenames.GetCount(); i++ )
1295 char *psz_local = NULL;
1296 const char *psz_utf8 = wxDnDFromLocale( filenames[i], psz_local );
1297 playlist_item_t *p_item =
1298 playlist_ItemNew( p->p_playlist, psz_utf8, psz_utf8 );
1299 playlist_NodeAddItem( p->p_playlist, p_item, p->i_current_view,
1300 p_dest, PLAYLIST_PREPARSE, i_pos );
1301 wxDnDLocaleFree( psz_utf8, psz_local );
1304 /* FIXME: having this Rebuild() is dirty */
1305 p->Rebuild( VLC_TRUE );
1311 /**********************************************************************
1313 **********************************************************************/
1315 void Playlist::OnMenuOpen( wxMenuEvent& event)
1317 #if defined( __WXMSW__ )
1318 # define GetEventObject GetMenu
1321 if( event.GetEventObject() == p_view_menu )
1323 p_view_menu = ViewMenu();
1325 #if defined( __WXMSW__ )
1326 # undef GetEventObject
1330 void Playlist::OnMenuEvent( wxCommandEvent& event )
1332 if( event.GetId() < FirstView_Event )
1337 else if( event.GetId() < LastView_Event )
1340 int i_new_view = event.GetId() - FirstView_Event;
1342 playlist_view_t *p_view = playlist_ViewFind( p_playlist, i_new_view );
1344 if( p_view != NULL )
1346 b_changed_view = VLC_TRUE;
1347 i_current_view = i_new_view;
1348 playlist_ViewUpdate( p_playlist, i_new_view );
1349 Rebuild( VLC_TRUE );
1352 else if( i_new_view >= VIEW_FIRST_SORTED &&
1353 i_new_view <= VIEW_LAST_SORTED )
1355 b_changed_view = VLC_TRUE;
1356 playlist_ViewInsert( p_playlist, i_new_view, "View" );
1357 playlist_ViewUpdate( p_playlist, i_new_view );
1359 i_current_view = i_new_view;
1361 Rebuild( VLC_TRUE );
1364 else if( event.GetId() >= FirstSD_Event && event.GetId() < LastSD_Event )
1366 if( !playlist_IsServicesDiscoveryLoaded( p_playlist,
1367 pp_sds[event.GetId() - FirstSD_Event] ) )
1369 playlist_ServicesDiscoveryAdd( p_playlist,
1370 pp_sds[event.GetId() - FirstSD_Event] );
1374 //wxMutexGuiLeave();
1375 playlist_ServicesDiscoveryRemove( p_playlist,
1376 pp_sds[event.GetId() - FirstSD_Event] );
1377 //wxMutexGuiEnter();
1382 wxMenu * Playlist::ViewMenu()
1386 p_view_menu = new wxMenu;
1390 wxMenuItemList::Node *node = p_view_menu->GetMenuItems().GetFirst();
1393 wxMenuItem *item = node->GetData();
1394 node = node->GetNext();
1395 p_view_menu->Delete( item );
1399 /* FIXME : have a list of "should have" views */
1400 p_view_menu->Append( FirstView_Event + VIEW_CATEGORY,
1401 wxU(_("Normal") ) );
1402 p_view_menu->Append( FirstView_Event + VIEW_S_AUTHOR,
1403 wxU(_("Sorted by artist") ) );
1404 p_view_menu->Append( FirstView_Event + VIEW_S_ALBUM,
1405 wxU(_("Sorted by Album") ) );
1410 wxMenu *Playlist::SDMenu()
1412 p_sd_menu = new wxMenu;
1414 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
1418 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1420 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1422 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
1425 if( i_number ) pp_sds = (char **)calloc( i_number, sizeof(void *) );
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" ) )
1434 p_sd_menu->AppendCheckItem( FirstSD_Event + i_number ,
1435 wxU( p_parser->psz_longname ? p_parser->psz_longname :
1436 (p_parser->psz_shortname ?
1437 p_parser->psz_shortname : p_parser->psz_object_name) ) );
1439 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
1440 p_parser->psz_object_name ) )
1442 p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
1445 pp_sds[i_number++] = p_parser->psz_object_name;
1448 vlc_list_release( p_list );
1453 /*****************************************************************************
1454 * Popup management functions
1455 *****************************************************************************/
1456 void Playlist::OnPopup( wxContextMenuEvent& event )
1458 wxPoint pt = event.GetPosition();
1459 playlist_item_t *p_item;
1461 i_wx_popup_item = treectrl->HitTest( ScreenToClient( pt ) );
1462 if( i_wx_popup_item.IsOk() )
1464 PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
1466 PlaylistItem *p_wxparent= (PlaylistItem *)treectrl->GetItemData(
1467 treectrl->GetItemParent( i_wx_popup_item ) );
1468 i_popup_item = p_wxitem->i_id;
1469 i_popup_parent = p_wxparent->i_id;
1470 treectrl->SelectItem( i_wx_popup_item );
1472 LockPlaylist( p_intf->p_sys, p_playlist );
1473 p_item = playlist_ItemGetById( p_playlist, i_popup_item );
1477 UnlockPlaylist( p_intf->p_sys, p_playlist );
1480 if( p_item->i_children == -1 )
1482 UnlockPlaylist( p_intf->p_sys, p_playlist );
1483 Playlist::PopupMenu( item_popup,
1484 ScreenToClient( wxGetMousePosition() ) );
1488 UnlockPlaylist( p_intf->p_sys, p_playlist );
1489 Playlist::PopupMenu( node_popup,
1490 ScreenToClient( wxGetMousePosition() ) );
1495 void Playlist::OnPopupPlay( wxCommandEvent& event )
1497 playlist_item_t *p_popup_item, *p_popup_parent;
1498 LockPlaylist( p_intf->p_sys, p_playlist );
1499 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1500 p_popup_parent = playlist_ItemGetById( p_playlist, i_popup_parent );
1501 if( p_popup_item != NULL )
1503 if( p_popup_item->i_children > -1 )
1505 if( event.GetId() == PopupPlay_Event &&
1506 p_popup_item->i_children > 0 )
1508 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
1509 i_current_view, p_popup_item,
1510 p_popup_item->pp_children[0] );
1514 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
1515 i_current_view, p_popup_item, NULL );
1520 if( event.GetId() == PopupPlay_Event )
1522 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
1523 i_current_view, p_popup_parent,
1528 UnlockPlaylist( p_intf->p_sys, p_playlist );
1531 void Playlist::OnPopupPreparse( wxCommandEvent& event )
1536 void Playlist::Preparse()
1538 playlist_item_t *p_popup_item;
1539 LockPlaylist( p_intf->p_sys, p_playlist );
1540 p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1542 if( p_popup_item != NULL )
1544 if( p_popup_item->i_children == -1 )
1546 playlist_PreparseEnqueue( p_playlist, &p_popup_item->input );
1551 playlist_item_t *p_parent = p_popup_item;
1552 for( i = 0; i< p_parent->i_children ; i++ )
1555 i_wx_popup_item = FindItem( treectrl->GetRootItem(),
1556 p_parent->pp_children[i]->input.i_id );
1557 i_popup_item = p_parent->pp_children[i]->input.i_id;
1562 UnlockPlaylist( p_intf->p_sys, p_playlist );
1565 void Playlist::OnPopupDel( wxCommandEvent& event )
1567 DeleteTreeItem( i_wx_popup_item );
1570 void Playlist::OnPopupSort( wxCommandEvent& event )
1572 PlaylistItem *p_wxitem;
1573 playlist_item_t *p_item;
1575 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1576 LockPlaylist( p_intf->p_sys, p_playlist );
1578 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1579 if( p_item->i_children >= 0 )
1581 playlist_RecursiveNodeSort( p_playlist, p_item,
1582 SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
1584 treectrl->DeleteChildren( i_wx_popup_item );
1586 UpdateNodeChildren( p_item, i_wx_popup_item );
1589 UnlockPlaylist( p_intf->p_sys, p_playlist );
1592 void Playlist::OnPopupInfo( wxCommandEvent& event )
1594 LockPlaylist( p_intf->p_sys, p_playlist );
1595 playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item );
1598 iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this );
1599 if( iteminfo_dialog->ShowModal() == wxID_OK )
1601 UpdateItem( i_wx_popup_item );
1603 delete iteminfo_dialog;
1605 UnlockPlaylist( p_intf->p_sys, p_playlist );
1608 void Playlist::OnPopupAddNode( wxCommandEvent& event )
1610 wxTextEntryDialog text( NULL, wxU(_( "Please enter node name" )),
1611 wxU(_( "Add node" )), wxU(_( "New node" )) );
1612 if( text.ShowModal() != wxID_OK ) return;
1614 char *psz_name = wxFromLocale( text.GetValue() );
1616 LockPlaylist( p_intf->p_sys, p_playlist );
1618 PlaylistItem *p_wxitem;
1619 playlist_item_t *p_item;
1621 p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
1623 p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
1625 playlist_NodeCreate( p_playlist, i_current_view, psz_name, p_item );
1627 UnlockPlaylist( p_intf->p_sys, p_playlist );
1628 Rebuild( VLC_TRUE );
1630 wxLocaleFree( psz_name );
1634 /*****************************************************************************
1635 * Custom events management
1636 *****************************************************************************/
1637 void Playlist::OnPlaylistEvent( wxCommandEvent& event )
1639 switch( event.GetId() )
1641 case UpdateItem_Event:
1642 UpdateItem( event.GetInt() );
1644 case AppendItem_Event:
1645 AppendItem( event );
1647 case RemoveItem_Event:
1648 RemoveItem( event.GetInt() );
1653 /*****************************************************************************
1654 * PlaylistChanged: callback triggered by the intf-change playlist variable
1655 * We don't rebuild the playlist directly here because we don't want the
1656 * caller to block for a too long time.
1657 *****************************************************************************/
1658 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1659 vlc_value_t oval, vlc_value_t nval, void *param )
1661 Playlist *p_playlist_dialog = (Playlist *)param;
1662 p_playlist_dialog->b_need_update = VLC_TRUE;
1666 /*****************************************************************************
1667 * Next: callback triggered by the playlist-current playlist variable
1668 *****************************************************************************/
1669 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1670 vlc_value_t oval, vlc_value_t nval, void *param )
1672 Playlist *p_playlist_dialog = (Playlist *)param;
1674 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1675 event.SetInt( oval.i_int );
1676 p_playlist_dialog->AddPendingEvent( event );
1677 event.SetInt( nval.i_int );
1678 p_playlist_dialog->AddPendingEvent( event );
1683 /*****************************************************************************
1684 * ItemChanged: callback triggered by the item-change playlist variable
1685 *****************************************************************************/
1686 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1687 vlc_value_t old_val, vlc_value_t new_val, void *param )
1689 Playlist *p_playlist_dialog = (Playlist *)param;
1691 wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
1692 event.SetInt( new_val.i_int );
1693 p_playlist_dialog->AddPendingEvent( event );
1697 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1698 vlc_value_t old_val, vlc_value_t new_val, void *param )
1700 Playlist *p_playlist_dialog = (Playlist *)param;
1702 wxCommandEvent event( wxEVT_PLAYLIST, RemoveItem_Event );
1703 event.SetInt( new_val.i_int );
1704 p_playlist_dialog->AddPendingEvent( event );
1709 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1710 vlc_value_t oval, vlc_value_t nval, void *param )
1712 Playlist *p_playlist_dialog = (Playlist *)param;
1714 playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
1715 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1717 if( ++p_playlist_dialog->i_items_to_append >= 50 )
1719 /* Too many items waiting to be added, it will be quicker to rebuild
1720 * the whole playlist */
1721 p_playlist_dialog->b_need_update = VLC_TRUE;
1725 wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );
1726 event.SetClientData( (void *)p_add );
1727 p_playlist_dialog->AddPendingEvent( event );