]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/playlist.cpp
* configure.ac : Added new folders
[vlc] / modules / gui / wxwindows / playlist.cpp
1 /*****************************************************************************
2  * playlist.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
5  * $Id: playlist.cpp,v 1.36 2004/01/11 00:45:06 zorglub Exp $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc/intf.h>
29
30 #include "wxwindows.h"
31 #include <wx/listctrl.h>
32
33 /* Callback prototype */
34 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
35                      vlc_value_t old_val, vlc_value_t new_val, void *param );
36 int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
37                      vlc_value_t old_val, vlc_value_t new_val, void *param );
38 int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
39                      vlc_value_t old_val, vlc_value_t new_val, void *param );
40
41 /*****************************************************************************
42  * Event Table.
43  *****************************************************************************/
44
45 /* IDs for the controls and the menu commands */
46 enum
47 {
48     /* menu items */
49     AddFile_Event = 1,
50     AddMRL_Event,
51     Close_Event,
52     Open_Event,
53     Save_Event,
54
55     SortTitle_Event,
56     RSortTitle_Event,
57     SortAuthor_Event,
58     RSortAuthor_Event,
59     SortGroup_Event,
60     RSortGroup_Event,
61     Randomize_Event,
62
63     EnableSelection_Event,
64     DisableSelection_Event,
65
66     InvertSelection_Event,
67     DeleteSelection_Event,
68     Random_Event,
69     Loop_Event,
70     Repeat_Event,
71     SelectAll_Event,
72
73     EnableGroup_Event,
74     DisableGroup_Event,
75
76     Up_Event,
77     Down_Event,
78     Infos_Event,
79
80     PopupPlay_Event,
81     PopupDel_Event,
82     PopupEna_Event,
83     PopupInfo_Event,
84
85     SearchText_Event,
86     Search_Event,
87
88     /* controls */
89     ListView_Event,
90
91     Browse_Event,  /* For export playlist */
92 };
93
94 BEGIN_EVENT_TABLE(Playlist, wxFrame)
95     /* Menu events */
96     EVT_MENU(AddFile_Event, Playlist::OnAddFile)
97     EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
98     EVT_MENU(Close_Event, Playlist::OnClose)
99     EVT_MENU(Open_Event, Playlist::OnOpen)
100     EVT_MENU(Save_Event, Playlist::OnSave)
101
102     EVT_MENU(SortTitle_Event, Playlist::OnSort)
103     EVT_MENU(RSortTitle_Event, Playlist::OnSort)
104     EVT_MENU(SortAuthor_Event, Playlist::OnSort)
105     EVT_MENU(RSortAuthor_Event, Playlist::OnSort)
106     EVT_MENU(SortGroup_Event, Playlist::OnSort)
107     EVT_MENU(RSortGroup_Event, Playlist::OnSort)
108
109     EVT_MENU(Randomize_Event, Playlist::OnSort)
110
111     EVT_MENU(EnableSelection_Event, Playlist::OnEnableSelection)
112     EVT_MENU(DisableSelection_Event, Playlist::OnDisableSelection)
113     EVT_MENU(InvertSelection_Event, Playlist::OnInvertSelection)
114     EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
115     EVT_MENU(SelectAll_Event, Playlist::OnSelectAll)
116     EVT_MENU(Infos_Event, Playlist::OnInfos)
117     EVT_CHECKBOX(Random_Event, Playlist::OnRandom)
118     EVT_CHECKBOX(Repeat_Event, Playlist::OnRepeat)
119     EVT_CHECKBOX(Loop_Event, Playlist::OnLoop)
120
121     EVT_MENU(EnableGroup_Event, Playlist::OnEnDis)
122     EVT_MENU(DisableGroup_Event, Playlist::OnEnDis)
123
124     /* Listview events */
125     EVT_LIST_ITEM_ACTIVATED(ListView_Event, Playlist::OnActivateItem)
126     EVT_LIST_COL_CLICK(ListView_Event, Playlist::OnColSelect)
127     EVT_LIST_KEY_DOWN(ListView_Event, Playlist::OnKeyDown)
128     EVT_LIST_ITEM_RIGHT_CLICK(ListView_Event, Playlist::OnPopup)
129
130     /* Popup events */
131     EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
132     EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
133     EVT_MENU( PopupEna_Event, Playlist::OnPopupEna)
134     EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo)
135
136
137     /* Button events */
138     EVT_BUTTON( Search_Event, Playlist::OnSearch)
139     EVT_BUTTON( Save_Event, Playlist::OnSave)
140     EVT_BUTTON( Infos_Event, Playlist::OnInfos)
141
142     EVT_BUTTON( Up_Event, Playlist::OnUp)
143     EVT_BUTTON( Down_Event, Playlist::OnDown)
144
145     EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange)
146
147     /* Special events : we don't want to destroy the window when the user
148      * clicks on (X) */
149     EVT_CLOSE(Playlist::OnClose)
150 END_EVENT_TABLE()
151
152
153 /* Event Table for the Newgroup class */
154 BEGIN_EVENT_TABLE(NewGroup, wxDialog)
155     EVT_BUTTON( wxID_OK, NewGroup::OnOk)
156     EVT_BUTTON( wxID_CANCEL, NewGroup::OnCancel)
157 END_EVENT_TABLE()
158
159
160 /* Event Table for the ExportPlaylist class */
161 BEGIN_EVENT_TABLE(ExportPlaylist, wxDialog)
162     EVT_BUTTON( wxID_OK, ExportPlaylist::OnOk)
163     EVT_BUTTON( wxID_CANCEL, ExportPlaylist::OnCancel)
164     EVT_BUTTON( Browse_Event, ExportPlaylist::OnBrowse)
165 END_EVENT_TABLE()
166
167 /*****************************************************************************
168  * Constructor.
169  *****************************************************************************/
170 Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
171     wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
172              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
173 {
174     /* Initializations */
175     iteminfo_dialog = NULL;
176     p_intf = _p_intf;
177     vlc_value_t  val;
178     i_update_counter = 0;
179     i_sort_mode = MODE_NONE;
180     b_need_update = VLC_FALSE;
181     vlc_mutex_init( p_intf, &lock );
182     SetIcon( *p_intf->p_sys->p_icon );
183
184     i_title_sorted = 0;
185     i_author_sorted = 0;
186     i_group_sorted = 0;
187
188
189     var_Create( p_intf, "random", VLC_VAR_BOOL );
190     var_Change( p_intf, "random", VLC_VAR_INHERITVALUE, & val, NULL );
191     var_Create( p_intf, "loop", VLC_VAR_BOOL );
192     var_Create( p_intf, "loop", VLC_VAR_BOOL );
193     var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
194     var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
195
196     /* Create our "Manage" menu */
197     wxMenu *manage_menu = new wxMenu;
198     manage_menu->Append( AddFile_Event, wxU(_("&Simple Add...")) );
199     manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
200     manage_menu->AppendSeparator();
201     manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
202     manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
203     manage_menu->AppendSeparator();
204     manage_menu->Append( Close_Event, wxU(_("&Close")) );
205
206     /* Create our "Sort" menu */
207     wxMenu *sort_menu = new wxMenu;
208     sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
209     sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
210     sort_menu->AppendSeparator();
211     sort_menu->Append( SortAuthor_Event, wxU(_("Sort by &author")) );
212     sort_menu->Append( RSortAuthor_Event, wxU(_("&Reverse sort by author")) );
213     sort_menu->AppendSeparator();
214     sort_menu->Append( SortGroup_Event, wxU(_("Sort by &group")) );
215     sort_menu->Append( RSortGroup_Event, wxU(_("&Reverse sort by group")) );
216     sort_menu->AppendSeparator();
217     sort_menu->Append( Randomize_Event, wxU(_("&Randomize Playlist")) );
218
219     /* Create our "Selection" menu */
220     wxMenu *selection_menu = new wxMenu;
221     selection_menu->Append( EnableSelection_Event, wxU(_("&Enable")) );
222     selection_menu->Append( DisableSelection_Event, wxU(_("&Disable")) );
223     selection_menu->AppendSeparator();
224     selection_menu->Append( InvertSelection_Event, wxU(_("&Invert")) );
225     selection_menu->Append( DeleteSelection_Event, wxU(_("&Delete")) );
226     selection_menu->Append( SelectAll_Event, wxU(_("&Select All")) );
227
228     /* Create our "Group" menu */
229     wxMenu *group_menu = new wxMenu;
230     group_menu->Append( EnableGroup_Event, wxU(_("&Enable all group items")) );
231     group_menu->Append( DisableGroup_Event,
232                         wxU(_("&Disable all group items")) );
233
234     /* Append the freshly created menus to the menu bar */
235     wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
236     menubar->Append( manage_menu, wxU(_("&Manage")) );
237     menubar->Append( sort_menu, wxU(_("S&ort")) );
238     menubar->Append( selection_menu, wxU(_("&Selection")) );
239     menubar->Append( group_menu, wxU(_("&Groups")) );
240
241     /* Attach the menu bar to the frame */
242     SetMenuBar( menubar );
243
244     /* Create the popup menu */
245     popup_menu = new wxMenu;
246     popup_menu->Append( PopupPlay_Event, wxU(_("Play item")) );
247     popup_menu->Append( PopupDel_Event, wxU(_("Delete item")) );
248     popup_menu->Append( PopupEna_Event, wxU(_("Toggle enabled")) );
249     popup_menu->Append( PopupInfo_Event, wxU(_("Info on item")) );
250
251     /* Create a panel to put everything in */
252     wxPanel *playlist_panel = new wxPanel( this, -1 );
253     playlist_panel->SetAutoLayout( TRUE );
254
255     /* Create the Random checkbox */
256     wxCheckBox *random_checkbox =
257         new wxCheckBox( playlist_panel, Random_Event, wxU(_("Random")) );
258     var_Get( p_intf, "random", &val );
259     vlc_bool_t b_random = val.b_bool;
260     random_checkbox->SetValue( b_random == VLC_FALSE ? 0 : 1 );
261
262     /* Create the Loop Checkbox */
263     wxCheckBox *loop_checkbox =
264         new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Loop")) );
265     var_Get( p_intf, "loop", &val );
266     int b_loop = val.b_bool ;
267     loop_checkbox->SetValue( b_loop );
268
269     /* Create the Repeat one checkbox */
270     wxCheckBox *repeat_checkbox =
271         new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat one")) );
272     var_Get( p_intf, "repeat", &val );
273     int b_repeat = val.b_bool ;
274     repeat_checkbox->SetValue( b_repeat );
275
276     /* Create the Search Textbox */
277     search_text =
278         new wxTextCtrl( playlist_panel, SearchText_Event, wxT(""),
279                         wxDefaultPosition, wxSize(140, -1),
280                         wxTE_PROCESS_ENTER);
281
282     /* Create the search button */
283     search_button =
284         new wxButton( playlist_panel, Search_Event, wxU(_("Search")) );
285
286
287     /* Create the listview */
288     /* FIXME: the given size is arbitrary, and prevents us from resizing
289      * the window to smaller dimensions. But the sizers don't seem to adjust
290      * themselves to the size of a listview, and with a wxDefaultSize the
291      * playlist window is ridiculously small */
292     listview = new wxListView( playlist_panel, ListView_Event,
293                                wxDefaultPosition, wxSize( 500, 300 ),
294                                wxLC_REPORT | wxSUNKEN_BORDER );
295     listview->InsertColumn( 0, wxU(_("Name")) );
296     listview->InsertColumn( 1, wxU(_("Author")) );
297     listview->InsertColumn( 2, wxU(_("Group")) );
298     listview->InsertColumn( 3, wxU(_("Duration")) );
299     listview->SetColumnWidth( 0, 270 );
300     listview->SetColumnWidth( 1, 150 );
301     listview->SetColumnWidth( 2, 80 );
302
303     /* Create the Up-Down buttons */
304     wxButton *up_button =
305         new wxButton( playlist_panel, Up_Event, wxU(_("Up") ) );
306
307     wxButton *down_button =
308         new wxButton( playlist_panel, Down_Event, wxU(_("Down") ) );
309
310     /* Create the iteminfo button */
311     wxButton *iteminfo_button =
312         new wxButton( playlist_panel, Infos_Event, wxU(_("Item info") ) );
313
314     /* Place everything in sizers */
315     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
316     button_sizer->Add( iteminfo_button, 0, wxALIGN_CENTER|wxLEFT , 5);
317     button_sizer->Layout();
318
319     wxBoxSizer *updown_sizer = new wxBoxSizer( wxHORIZONTAL );
320     updown_sizer->Add( up_button, 0, wxALIGN_LEFT|wxRIGHT, 3);
321     updown_sizer->Add( down_button, 0, wxALIGN_LEFT|wxLEFT, 3);
322     updown_sizer->Layout();
323
324     wxBoxSizer *checkbox_sizer = new wxBoxSizer( wxHORIZONTAL );
325     checkbox_sizer->Add( random_checkbox, 0,
326                          wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
327     checkbox_sizer->Add( loop_checkbox, 0,
328                          wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
329     checkbox_sizer->Add( repeat_checkbox, 0,
330                          wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
331     checkbox_sizer->Layout();
332
333     wxBoxSizer *search_sizer = new wxBoxSizer( wxHORIZONTAL );
334     search_sizer->Add( search_text, 0, wxRIGHT|wxALIGN_CENTER, 3);
335     search_sizer->Add( search_button, 0, wxLEFT|wxALIGN_CENTER, 3);
336     search_sizer->Layout();
337
338     /* The top and bottom sizers */
339     wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
340     top_sizer->Add( checkbox_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_LEFT, 4 );
341     top_sizer->Add( search_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 4 );
342     top_sizer->Layout();
343
344     wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
345     bottom_sizer->Add( updown_sizer, 0, wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4);
346     bottom_sizer->Add( button_sizer , 0, wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
347     bottom_sizer->Layout();
348
349     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
350
351     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
352     panel_sizer->Add( top_sizer, 0, wxEXPAND | wxALL, 5 );
353     panel_sizer->Add( listview, 1, wxEXPAND | wxALL, 5 );
354     panel_sizer->Add( bottom_sizer, 0 , wxEXPAND | wxALL, 5);
355     panel_sizer->Layout();
356
357     playlist_panel->SetSizerAndFit( panel_sizer );
358     main_sizer->Add( playlist_panel, 1, wxGROW, 0 );
359     main_sizer->Layout();
360     SetSizerAndFit( main_sizer );
361
362 #if !defined(__WXX11__)
363     /* Associate drop targets with the playlist */
364     SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
365 #endif
366
367     playlist_t *p_playlist =
368         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
369                                        FIND_ANYWHERE );
370     if( p_playlist == NULL )
371     {
372         return;
373     }
374
375     /* We want to be noticed of playlist changes */
376
377     /* Some global changes happened -> Rebuild all */
378     var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
379
380     /* We went to the next item */
381     var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
382
383     /* One item has been updated */
384     var_AddCallback( p_playlist, "item-change", ItemChanged, this );
385
386
387     vlc_object_release( p_playlist );
388
389     /* Update the playlist */
390     Rebuild();
391 }
392
393 Playlist::~Playlist()
394 {
395     playlist_t *p_playlist =
396         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
397                                        FIND_ANYWHERE );
398     if( p_playlist == NULL )
399     {
400         return;
401     }
402
403     delete iteminfo_dialog;
404
405     var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
406     vlc_object_release( p_playlist );
407 }
408
409 /**********************************************************************
410  * Update one playlist item
411  **********************************************************************/
412 void Playlist::UpdateItem( int i )
413 {
414     playlist_t *p_playlist =
415         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
416                                        FIND_ANYWHERE );
417     if( p_playlist == NULL )
418     {
419         return;
420     }
421     if( i < 0 || i >= p_playlist->i_size || !p_playlist->pp_items[i] )
422     {
423         vlc_object_release(p_playlist);
424         return;
425     }
426     listview->SetItem( i, 0, wxL2U(p_playlist->pp_items[i]->psz_name) );
427     listview->SetItem( i, 1, wxL2U( playlist_GetInfo( p_playlist, i,
428                                        _("General") , _("Author") ) ) );
429     char *psz_group = playlist_FindGroup(p_playlist,p_playlist->
430                                     pp_items[i]->i_group);
431     listview->SetItem( i, 2,
432              wxL2U( psz_group ? psz_group : _("Normal") ) );
433
434     if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
435     {
436         wxListItem listitem;
437         listitem.m_itemId = i;
438         listitem.SetTextColour( *wxLIGHT_GREY);
439         listview->SetItem(listitem);
440     }
441
442     char psz_duration[MSTRTIME_MAX_SIZE];
443     mtime_t dur = p_playlist->pp_items[i]->i_duration;
444     if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
445     else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
446     listview->SetItem( i, 3, wxU(psz_duration) );
447
448     /* Change the colour for the currenty played stream */
449     wxListItem listitem;
450     listitem.m_itemId = i;
451     if( i == p_playlist->i_index )
452     {
453         listitem.SetTextColour( *wxRED );
454     }
455     else
456     {
457         listitem.SetTextColour( *wxBLACK );
458     }
459     listview->SetItem( listitem );
460
461     vlc_object_release(p_playlist);
462 }
463
464 /**********************************************************************
465  * Rebuild the playlist
466  **********************************************************************/
467 void Playlist::Rebuild()
468 {
469     playlist_t *p_playlist =
470         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
471                                        FIND_ANYWHERE );
472     if( p_playlist == NULL )
473     {
474         return;
475     }
476
477     int i_focused = listview->GetFocusedItem();
478
479     /* Clear the list... */
480     listview->DeleteAllItems();
481
482     /* ...and rebuild it */
483     vlc_mutex_lock( &p_playlist->object_lock );
484     for( int i = 0; i < p_playlist->i_size; i++ )
485     {
486         wxString filename = wxL2U(p_playlist->pp_items[i]->psz_name);
487         listview->InsertItem( i, filename );
488         UpdateItem( i );
489     }
490     vlc_mutex_unlock( &p_playlist->object_lock );
491
492     if( i_focused )
493     {
494         listview->Focus( i_focused );
495         listview->Select( i_focused );
496     }
497     else
498     {
499         listview->Focus( p_playlist->i_index );
500     }
501
502     vlc_object_release( p_playlist );
503 }
504
505 void Playlist::ShowPlaylist( bool show )
506 {
507     if( show ) Rebuild();
508     Show( show );
509 }
510
511 void Playlist::UpdatePlaylist()
512 {
513     vlc_bool_t b_need_update = VLC_FALSE;
514     i_update_counter++;
515
516     /* If the playlist isn't show there's no need to update it */
517     if( !IsShown() ) return;
518
519     vlc_mutex_lock( &lock );
520     if( this->b_need_update )
521     {
522         b_need_update =VLC_TRUE;
523         this->b_need_update = VLC_FALSE;
524     }
525     vlc_mutex_unlock( &lock );
526
527     if( b_need_update )
528     {
529         Rebuild();
530     }
531
532     /* Updating the playing status every 0.5s is enough */
533     if( i_update_counter % 5 ) return;
534
535     playlist_t *p_playlist =
536         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
537                                        FIND_ANYWHERE );
538     if( p_playlist == NULL )
539     {
540         return;
541     }
542
543     /* Update the colour of items */
544
545     vlc_mutex_lock( &p_playlist->object_lock );
546     if( p_intf->p_sys->i_playing != p_playlist->i_index )
547     {
548         wxListItem listitem;
549         listitem.m_itemId = p_playlist->i_index;
550         listitem.SetTextColour( *wxRED );
551         listview->SetItem( listitem );
552
553         if( p_intf->p_sys->i_playing != -1 )
554         {
555             listitem.m_itemId = p_intf->p_sys->i_playing;
556             listitem.SetTextColour( *wxBLACK );
557             listview->SetItem( listitem );
558         }
559         p_intf->p_sys->i_playing = p_playlist->i_index;
560     }
561     vlc_mutex_unlock( &p_playlist->object_lock );
562     vlc_object_release( p_playlist );
563 }
564
565 /*****************************************************************************
566  * Private methods.
567  *****************************************************************************/
568 void Playlist::DeleteItem( int item )
569 {
570     playlist_t *p_playlist =
571         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
572                                        FIND_ANYWHERE );
573     if( p_playlist == NULL )
574     {
575         return;
576     }
577
578     playlist_Delete( p_playlist, item );
579     listview->DeleteItem( item );
580
581     vlc_object_release( p_playlist );
582 }
583
584 void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) )
585 {
586     Hide();
587 }
588
589 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
590 {
591     ExportPlaylist *exp_pl = new ExportPlaylist( p_intf, this);
592     exp_pl->ShowModal();
593     delete exp_pl;
594 }
595
596 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
597 {
598     playlist_t *p_playlist =
599         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
600                                        FIND_ANYWHERE );
601     if( p_playlist == NULL )
602     {
603         return;
604     }
605
606     wxFileDialog dialog( this, wxU(_("Open playlist")),
607                          wxT(""), wxT(""), wxT("*"), wxOPEN );
608
609     if( dialog.ShowModal() == wxID_OK )
610     {
611         playlist_Import( p_playlist, dialog.GetPath().mb_str() );
612     }
613
614     vlc_object_release( p_playlist );
615 }
616
617 void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
618 {
619     p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
620
621 #if 0
622     Rebuild();
623 #endif
624 }
625
626 void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
627 {
628     p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
629
630 #if 0
631     Rebuild();
632 #endif
633 }
634
635 /********************************************************************
636  * Move functions
637  ********************************************************************/
638 void Playlist::OnUp( wxCommandEvent& event)
639 {
640     playlist_t *p_playlist =
641         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
642                                        FIND_ANYWHERE );
643     if( p_playlist == NULL )
644     {
645         return;
646     }
647
648     /* We use the first selected item, so find it */
649     long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
650                                          wxLIST_STATE_SELECTED);
651     if( i_item > 0 && i_item < p_playlist->i_size )
652     {
653         playlist_Move( p_playlist , i_item, i_item - 1);
654         if( i_item > 1 )
655         {
656             listview->Focus( i_item - 1 );
657         }
658         else
659         {
660             listview->Focus(0);
661         }
662     }
663     vlc_object_release( p_playlist );
664     return;
665 }
666
667 void Playlist::OnDown( wxCommandEvent& event)
668 {
669     playlist_t *p_playlist =
670         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
671                                        FIND_ANYWHERE );
672     if( p_playlist == NULL )
673     {
674         return;
675     }
676
677     /* We use the first selected item, so find it */
678     long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
679                                          wxLIST_STATE_SELECTED );
680     if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
681     {
682         playlist_Move( p_playlist , i_item, i_item + 2 );
683         listview->Focus( i_item + 1 );
684     }
685     vlc_object_release( p_playlist );
686     return;
687 }
688
689 /********************************************************************
690  * Sorting functions
691  ********************************************************************/
692 void Playlist::OnSort( wxCommandEvent& event )
693 {
694     playlist_t *p_playlist =
695         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
696                                        FIND_ANYWHERE );
697     if( p_playlist == NULL )
698     {
699         return;
700     }
701     switch( event.GetId() )
702     {
703         case SortTitle_Event:
704            playlist_SortTitle( p_playlist , 0 );
705            break;
706         case RSortTitle_Event:
707            playlist_SortTitle( p_playlist , 1 );
708            break;
709         case SortAuthor_Event:
710            playlist_SortAuthor(p_playlist , 0 );
711            break;
712         case RSortAuthor_Event:
713            playlist_SortAuthor( p_playlist , 1 );
714            break;
715         case SortGroup_Event:
716            playlist_SortGroup( p_playlist , 0 );
717            break;
718         case RSortGroup_Event:
719            playlist_SortGroup( p_playlist , 1 );
720            break;
721         case Randomize_Event:
722            playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
723            break;
724     }
725     vlc_object_release( p_playlist );
726
727     Rebuild();
728
729     return;
730 }
731
732 void Playlist::OnColSelect( wxListEvent& event )
733 {
734     playlist_t *p_playlist =
735         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
736                                        FIND_ANYWHERE );
737     if( p_playlist == NULL )
738     {
739         return;
740     }
741     switch( event.GetColumn() )
742     {
743         case 0:
744             if( i_title_sorted != 1 )
745             {
746                 playlist_SortTitle( p_playlist, 0 );
747                 i_title_sorted = 1;
748             }
749             else
750             {
751                 playlist_SortTitle( p_playlist, 1 );
752                 i_title_sorted = -1;
753             }
754             break;
755         case 1:
756             if( i_author_sorted != 1 )
757             {
758                 playlist_SortAuthor( p_playlist, 0 );
759                 i_author_sorted = 1;
760             }
761             else
762             {
763                 playlist_SortAuthor( p_playlist, 1 );
764                 i_author_sorted = -1;
765             }
766             break;
767         case 2:
768             if( i_group_sorted != 1 )
769             {
770                 playlist_SortGroup( p_playlist, 0 );
771                 i_group_sorted = 1;
772             }
773             else
774             {
775                 playlist_SortGroup( p_playlist, 1 );
776                 i_group_sorted = -1;
777             }
778             break;
779         default:
780             break;
781     }
782     vlc_object_release( p_playlist );
783
784     Rebuild();
785
786     return;
787 }
788
789 /**********************************************************************
790  * Search functions
791  **********************************************************************/
792 void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
793 {
794    search_button->SetDefault();
795 }
796
797 void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
798 {
799     wxString search_string= search_text->GetValue();
800
801     int i_current;
802     int i_first = 0 ;
803     int i_item = -1;
804
805     for( i_current = 0 ; i_current <= listview->GetItemCount() ; i_current++ )
806     {
807         if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED )
808                    == wxLIST_STATE_SELECTED )
809         {
810             i_first = i_current;
811             break;
812         }
813     }
814
815     for ( i_current = i_first + 1; i_current <= listview->GetItemCount() ;
816           i_current++ )
817     {
818         wxListItem listitem;
819         listitem.SetId( i_current );
820         listview->GetItem( listitem );
821         if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
822         {
823             i_item = i_current;
824             break;
825         }
826     }
827     for( long item = 0; item < listview->GetItemCount(); item++ )
828     {
829         listview->Select( item, FALSE );
830     }
831
832     wxListItem listitem;
833     listitem.SetId(i_item);
834     listitem.m_state = wxLIST_STATE_SELECTED;
835     listview->Select( i_item, TRUE );
836     listview->Focus( i_item );
837
838 }
839
840 /**********************************************************************
841  * Selection functions
842  **********************************************************************/
843 void Playlist::OnInvertSelection( wxCommandEvent& WXUNUSED(event) )
844 {
845     for( long item = 0; item < listview->GetItemCount(); item++ )
846     {
847         listview->Select( item, ! listview->IsSelected( item ) );
848     }
849 }
850
851 void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
852 {
853     /* Delete from the end to the beginning, to avoid a shift of indices */
854     for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
855     {
856         if( listview->IsSelected( item ) )
857         {
858             DeleteItem( item );
859         }
860     }
861
862     Rebuild();
863 }
864
865 void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) )
866 {
867     playlist_t *p_playlist =
868         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
869                                        FIND_ANYWHERE );
870     if( p_playlist == NULL )
871     {
872         return;
873     }
874
875     for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
876     {
877         if( listview->IsSelected( item ) )
878         {
879             playlist_Enable( p_playlist, item );
880             UpdateItem( item );
881         }
882     }
883     vlc_object_release( p_playlist);
884 }
885
886 void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) )
887 {
888     playlist_t *p_playlist =
889         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
890                                        FIND_ANYWHERE );
891     if( p_playlist == NULL )
892     {
893         return;
894     }
895
896     for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
897     {
898         if( listview->IsSelected( item ) )
899         {
900             playlist_Disable( p_playlist, item );
901             UpdateItem( item );
902         }
903     }
904     vlc_object_release( p_playlist);
905 }
906
907 void Playlist::OnSelectAll( wxCommandEvent& WXUNUSED(event) )
908 {
909     for( long item = 0; item < listview->GetItemCount(); item++ )
910     {
911         listview->Select( item, TRUE );
912     }
913 }
914
915 /**********************************************************************
916  * Playlist mode functions
917  **********************************************************************/
918 void Playlist::OnRandom( wxCommandEvent& event )
919 {
920     vlc_value_t val;
921     val.b_bool = event.IsChecked();
922     playlist_t *p_playlist =
923         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
924                                        FIND_ANYWHERE );
925     if( p_playlist == NULL )
926     {
927         return;
928     }
929     var_Set( p_playlist , "random", val);
930     vlc_object_release( p_playlist );
931 }
932 void Playlist::OnLoop ( wxCommandEvent& event )
933 {
934     vlc_value_t val;
935     val.b_bool = event.IsChecked();
936     playlist_t *p_playlist =
937         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
938                                        FIND_ANYWHERE );
939     if( p_playlist == NULL )
940     {
941         return;
942     }
943     var_Set( p_playlist , "loop", val);
944     vlc_object_release( p_playlist );
945 }
946
947 void Playlist::OnRepeat ( wxCommandEvent& event )
948 {
949     vlc_value_t val;
950     val.b_bool = event.IsChecked();
951     playlist_t *p_playlist =
952         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
953                                        FIND_ANYWHERE );
954     if( p_playlist == NULL )
955     {
956         return;
957     }
958     var_Set( p_playlist , "repeat", val);
959     vlc_object_release( p_playlist );
960 }
961
962
963
964 void Playlist::OnActivateItem( wxListEvent& event )
965 {
966     playlist_t *p_playlist =
967         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
968                                        FIND_ANYWHERE );
969     if( p_playlist == NULL )
970     {
971         return;
972     }
973     playlist_Goto( p_playlist, event.GetIndex() );
974
975     vlc_object_release( p_playlist );
976 }
977
978 void Playlist::OnKeyDown( wxListEvent& event )
979 {
980     long keycode = event.GetKeyCode();
981     /* Delete selected items */
982     if( keycode == WXK_BACK || keycode == WXK_DELETE )
983     {
984         /* We send a dummy event */
985         OnDeleteSelection( event );
986     }
987 }
988
989 void Playlist::ShowInfos( int i_item )
990 {
991     playlist_t *p_playlist =
992         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
993                                        FIND_ANYWHERE );
994     if( p_playlist == NULL )
995     {
996         return;
997     }
998     if( iteminfo_dialog == NULL )
999     {
1000         if( i_item >= 0 && i_item < p_playlist->i_size )
1001         {
1002             iteminfo_dialog = new ItemInfoDialog(
1003                               p_intf, p_playlist->pp_items[i_item], this );
1004             if( iteminfo_dialog->ShowModal()  == wxID_OK )
1005                 UpdateItem( i_item );
1006             delete iteminfo_dialog;
1007             iteminfo_dialog = NULL;
1008         }
1009     }
1010     vlc_object_release( p_playlist );
1011 }
1012
1013 void Playlist::OnInfos( wxCommandEvent& WXUNUSED(event) )
1014 {
1015     /* We use the first selected item, so find it */
1016     long i_item = listview->GetNextItem( -1 , wxLIST_NEXT_ALL,
1017                                          wxLIST_STATE_SELECTED );
1018     ShowInfos( i_item );
1019 }
1020
1021 void Playlist::OnEnDis( wxCommandEvent& event )
1022 {
1023     playlist_t *p_playlist =
1024         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1025                                        FIND_ANYWHERE );
1026     if( p_playlist == NULL )
1027     {
1028         return;
1029     }
1030
1031     long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
1032                                          wxLIST_STATE_SELECTED );
1033
1034     if( i_item >= 0 && i_item < p_playlist->i_size )
1035     {
1036        switch( event.GetId() )
1037        {
1038            case EnableGroup_Event:
1039                playlist_EnableGroup( p_playlist ,
1040                                   p_playlist->pp_items[i_item]->i_group );
1041                break;
1042            case DisableGroup_Event:
1043                playlist_DisableGroup( p_playlist ,
1044                                   p_playlist->pp_items[i_item]->i_group );
1045                break;
1046        }
1047        Rebuild();
1048     }
1049
1050     vlc_object_release( p_playlist );
1051 }
1052
1053 /*****************************************************************************
1054  * Popup management functions
1055  *****************************************************************************/
1056 void Playlist::OnPopup( wxListEvent& event )
1057 {
1058     i_popup_item = event.GetIndex();
1059     Playlist::PopupMenu( popup_menu , ScreenToClient( wxGetMousePosition() ) );
1060 }
1061
1062
1063 void Playlist::OnPopupPlay( wxMenuEvent& event )
1064 {
1065     playlist_t *p_playlist =
1066         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1067                                        FIND_ANYWHERE );
1068     if( p_playlist == NULL )
1069     {
1070         return;
1071     }
1072     if( i_popup_item != -1 )
1073     {
1074         playlist_Goto( p_playlist, i_popup_item );
1075     }
1076     vlc_object_release( p_playlist );
1077 }
1078
1079 void Playlist::OnPopupDel( wxMenuEvent& event )
1080 {
1081     DeleteItem( i_popup_item );
1082 }
1083
1084 void Playlist::OnPopupEna( wxMenuEvent& event )
1085 {
1086     playlist_t *p_playlist =
1087         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1088                                        FIND_ANYWHERE );
1089     if( p_playlist == NULL )
1090     {
1091         return;
1092     }
1093
1094     if( p_playlist->pp_items[i_popup_item]->b_enabled )
1095         //playlist_IsEnabled( p_playlist, i_popup_item ) )
1096     {
1097         playlist_Disable( p_playlist, i_popup_item );
1098     }
1099     else
1100     {
1101         playlist_Enable( p_playlist, i_popup_item );
1102     }
1103     vlc_object_release( p_playlist);
1104     UpdateItem( i_popup_item );
1105 }
1106
1107 void Playlist::OnPopupInfo( wxMenuEvent& event )
1108 {
1109     ShowInfos( i_popup_item );
1110 }
1111
1112 /*****************************************************************************
1113  * PlaylistChanged: callback triggered by the intf-change playlist variable
1114  *  We don't rebuild the playlist directly here because we don't want the
1115  *  caller to block for a too long time.
1116  *****************************************************************************/
1117 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1118                      vlc_value_t old_val, vlc_value_t new_val, void *param )
1119 {
1120     Playlist *p_playlist_dialog = (Playlist *)param;
1121     vlc_mutex_lock( &p_playlist_dialog->lock );
1122     p_playlist_dialog->b_need_update = VLC_TRUE;
1123     vlc_mutex_unlock( &p_playlist_dialog->lock );
1124     return VLC_SUCCESS;
1125 }
1126
1127 /*****************************************************************************
1128  * Next: callback triggered by the playlist-current playlist variable
1129  *****************************************************************************/
1130 int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1131                  vlc_value_t old_val, vlc_value_t new_val, void *param )
1132 {
1133     Playlist *p_playlist_dialog = (Playlist *)param;
1134     p_playlist_dialog->UpdateItem( old_val.i_int );
1135     p_playlist_dialog->UpdateItem( new_val.i_int );
1136     return 0;
1137 }
1138
1139
1140 /*****************************************************************************
1141  * ItemChanged: callback triggered by the item-change playlist variable
1142  *****************************************************************************/
1143 int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1144                  vlc_value_t old_val, vlc_value_t new_val, void *param )
1145 {
1146     Playlist *p_playlist_dialog = (Playlist *)param;
1147     p_playlist_dialog->UpdateItem( new_val.i_int );
1148     return 0;
1149 }
1150
1151
1152 /***************************************************************************
1153  * NewGroup Class
1154  ***************************************************************************/
1155 NewGroup::NewGroup( intf_thread_t *_p_intf, wxWindow *_p_parent ):
1156     wxDialog( _p_parent, -1, wxU(_("New Group")), wxDefaultPosition,
1157              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
1158 {
1159     /* Initializations */
1160     p_intf = _p_intf;
1161     psz_name = NULL;
1162     SetIcon( *p_intf->p_sys->p_icon );
1163
1164     /* Create a panel to put everything in*/
1165     wxPanel *panel = new wxPanel( this, -1 );
1166     panel->SetAutoLayout( TRUE );
1167
1168     wxStaticText *group_label =
1169             new wxStaticText( panel , -1,
1170                 wxU(_("Enter a name for the new group")));
1171
1172     groupname = new wxTextCtrl(panel, -1, wxU(""),wxDefaultPosition,
1173                                wxSize(80,27),wxTE_PROCESS_ENTER);
1174
1175     wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );
1176     ok_button->SetDefault();
1177     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
1178                                             wxU(_("Cancel")) );
1179
1180     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1181
1182     button_sizer->Add( ok_button, 0, wxALL, 5 );
1183     button_sizer->Add( cancel_button, 0, wxALL, 5 );
1184     button_sizer->Layout();
1185
1186     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
1187     panel_sizer->Add( group_label, 0, wxEXPAND | wxALL, 5 );
1188     panel_sizer->Add( groupname, 0, wxEXPAND | wxALL, 5 );
1189     panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );
1190     panel_sizer->Layout();
1191
1192     panel->SetSizerAndFit( panel_sizer );
1193
1194     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1195     main_sizer->Add( panel, 1, wxEXPAND, 0 );
1196     main_sizer->Layout();
1197     SetSizerAndFit( main_sizer );
1198 }
1199
1200 NewGroup::~NewGroup()
1201 {
1202 }
1203
1204 void NewGroup::OnOk( wxCommandEvent& event )
1205 {
1206     psz_name = strdup( groupname->GetLineText(0).mb_str() );
1207
1208     playlist_t * p_playlist =
1209           (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1210                                        FIND_ANYWHERE );
1211
1212     if( p_playlist )
1213     {
1214         if( !playlist_CreateGroup( p_playlist, psz_name ) )
1215         {
1216             psz_name = NULL;
1217         }
1218         vlc_object_release( p_playlist );
1219     }
1220
1221     EndModal( wxID_OK );
1222 }
1223
1224 void NewGroup::OnCancel( wxCommandEvent& WXUNUSED(event) )
1225 {
1226     EndModal( wxID_CANCEL );
1227 }
1228
1229
1230
1231 /***************************************************************************
1232  * Export playlist class
1233  ***************************************************************************/
1234 ExportPlaylist::ExportPlaylist( intf_thread_t *_p_intf, wxWindow *_p_parent ):
1235     wxDialog( _p_parent, -1, wxU(_("Export playlist")), wxDefaultPosition,
1236              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
1237 {
1238     vlc_list_t *p_list;
1239     module_t *p_module;
1240
1241     /* Initializations */
1242     p_intf = _p_intf;
1243     SetIcon( *p_intf->p_sys->p_icon );
1244
1245     /* Create a panel to put everything in*/
1246     wxPanel *panel = new wxPanel( this, -1 );
1247     panel->SetAutoLayout( TRUE );
1248
1249     /* Create the file box */
1250     wxStaticBox *file_box = new wxStaticBox( panel, -1,
1251                                              wxU(_("File to save to")) );
1252     wxStaticBoxSizer *file_sizer = new wxStaticBoxSizer( file_box,
1253                                                         wxHORIZONTAL );
1254
1255     file_text = new wxTextCtrl(panel, -1, wxU(""),wxDefaultPosition,
1256                                wxSize(250,-1),wxTE_PROCESS_ENTER);
1257
1258     file_text->SetToolTip( wxU(_("Enter the name of the file to export "
1259                                  "the playlist to.")) );
1260
1261     wxButton *file_button = new wxButton( panel, Browse_Event,
1262                                           wxU(_("Browse")) );
1263
1264     file_sizer->Add( file_text, 0, wxALL | wxALIGN_CENTER , 5 );
1265     file_sizer->Add( file_button, 0, wxALL | wxALIGN_CENTER , 5 );
1266
1267     /* Create the type box */
1268     wxStaticBox *type_box = new wxStaticBox( panel, -1,
1269                                              wxU(_("Select export type")) );
1270
1271     wxStaticBoxSizer *type_sizer = new wxStaticBoxSizer( type_box,
1272                                                         wxHORIZONTAL );
1273
1274     type_combo = new wxComboBox( panel, -1, wxT(""), wxDefaultPosition,
1275                                  wxSize(250, -1), 0, NULL );
1276
1277     type_sizer->Add( type_combo, 0, wxALL | wxALIGN_CENTER, 5 );
1278     type_sizer->Layout();
1279
1280
1281
1282     wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );
1283     ok_button->SetDefault();
1284     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
1285                                             wxU(_("Cancel")) );
1286
1287     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1288
1289     button_sizer->Add( ok_button, 0, wxALL, 5 );
1290     button_sizer->Add( cancel_button, 0, wxALL, 5 );
1291     button_sizer->Layout();
1292
1293     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
1294     panel_sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
1295     panel_sizer->Add( type_sizer, 0, wxEXPAND | wxALL, 5 );
1296     panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );
1297     panel_sizer->Layout();
1298
1299     panel->SetSizerAndFit( panel_sizer );
1300
1301     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1302     main_sizer->Add( panel, 1, wxEXPAND, 0 );
1303     main_sizer->Layout();
1304     SetSizerAndFit( main_sizer );
1305
1306     /* build a list of available modules */
1307     p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1308     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
1309     {
1310         p_module = (module_t *)p_list->p_values[i_index].p_object ;
1311         if( !strcmp( p_module->psz_capability, "playlist export" ) )
1312         {
1313             type_combo->Append( wxU(p_module->psz_longname),
1314                                 p_module->pp_shortcuts[1] ?
1315                                 p_module->pp_shortcuts[1] :
1316                                 p_module->psz_object_name );
1317         }
1318     }
1319     vlc_list_release( p_list );
1320 }
1321
1322
1323 ExportPlaylist::~ExportPlaylist()
1324 {
1325 }
1326
1327 void ExportPlaylist::OnOk( wxCommandEvent& WXUNUSED(event) )
1328 {
1329     playlist_t * p_playlist =
1330           (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1331                                        FIND_ANYWHERE );
1332
1333     if( p_playlist )
1334     {
1335         char *psz_type = (char *)type_combo->GetClientData(
1336                                              type_combo->GetSelection() );
1337         if( file_text->GetValue().mb_str() && psz_type )
1338         {
1339             playlist_Export( p_playlist, file_text->GetValue().mb_str(),
1340                              psz_type );
1341         }
1342     }
1343
1344     vlc_object_release( p_playlist );
1345     EndModal( wxID_OK );
1346 }
1347
1348 void ExportPlaylist::OnCancel( wxCommandEvent& WXUNUSED(event) )
1349 {
1350     EndModal( wxID_CANCEL );
1351 }
1352
1353 void ExportPlaylist::OnBrowse( wxCommandEvent& WXUNUSED(event) )
1354 {
1355     wxFileDialog dialog( this, wxU(_("Save playlist")),
1356                          wxT(""), wxT(""), wxT("*"), wxSAVE );
1357
1358     if( dialog.ShowModal() == wxID_OK )
1359     {
1360         file_text->SetValue( dialog.GetPath() );
1361     }
1362 }