playlist.cpp 37.3 KB
Newer Older
1
/*****************************************************************************
gbazin's avatar
 
gbazin committed
2
 * playlist.cpp : wxWindows plugin for vlc
3
 *****************************************************************************
4
 * Copyright (C) 2000-2001, 2003 VideoLAN
zorglub's avatar
zorglub committed
5
 * $Id: playlist.cpp,v 1.33 2004/01/05 13:00:39 zorglub Exp $
6 7 8 9 10 11 12
 *
 * Authors: Olivier Teulire <ipkiss@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
gbazin's avatar
 
gbazin committed
13
 *
14 15 16 17 18 19 20 21 22 23 24 25 26
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
gbazin's avatar
 
gbazin committed
27
#include <vlc/vlc.h>
gbazin's avatar
 
gbazin committed
28
#include <vlc/intf.h>
29 30

#include "wxwindows.h"
31
#include <wx/listctrl.h>
32

gbazin's avatar
 
gbazin committed
33 34 35
/* Callback prototype */
int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
                     vlc_value_t old_val, vlc_value_t new_val, void *param );
zorglub's avatar
zorglub committed
36 37 38 39
int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
                     vlc_value_t old_val, vlc_value_t new_val, void *param );
int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
                     vlc_value_t old_val, vlc_value_t new_val, void *param );
gbazin's avatar
 
gbazin committed
40

41 42 43 44 45 46 47 48
/*****************************************************************************
 * Event Table.
 *****************************************************************************/

/* IDs for the controls and the menu commands */
enum
{
    /* menu items */
gbazin's avatar
 
gbazin committed
49 50
    AddFile_Event = 1,
    AddMRL_Event,
51
    Close_Event,
gbazin's avatar
 
gbazin committed
52 53
    Open_Event,
    Save_Event,
54

zorglub's avatar
zorglub committed
55 56 57 58 59 60
    SortTitle_Event,
    RSortTitle_Event,
    SortAuthor_Event,
    RSortAuthor_Event,
    SortGroup_Event,
    RSortGroup_Event,
zorglub's avatar
zorglub committed
61
    Randomize_Event,
zorglub's avatar
zorglub committed
62

zorglub's avatar
zorglub committed
63 64 65
    EnableSelection_Event,
    DisableSelection_Event,

66 67
    InvertSelection_Event,
    DeleteSelection_Event,
68 69
    Random_Event,
    Loop_Event,
70
    Repeat_Event,
71 72
    SelectAll_Event,

zorglub's avatar
zorglub committed
73 74
    EnableGroup_Event,
    DisableGroup_Event,
zorglub's avatar
zorglub committed
75

zorglub's avatar
zorglub committed
76 77
    Up_Event,
    Down_Event,
zorglub's avatar
zorglub committed
78 79
    Infos_Event,

zorglub's avatar
zorglub committed
80 81 82 83 84
    PopupPlay_Event,
    PopupDel_Event,
    PopupEna_Event,
    PopupInfo_Event,

zorglub's avatar
zorglub committed
85 86 87
    SearchText_Event,
    Search_Event,

88 89 90 91 92 93
    /* controls */
    ListView_Event
};

BEGIN_EVENT_TABLE(Playlist, wxFrame)
    /* Menu events */
gbazin's avatar
 
gbazin committed
94
    EVT_MENU(AddFile_Event, Playlist::OnAddFile)
gbazin's avatar
 
gbazin committed
95
    EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
96
    EVT_MENU(Close_Event, Playlist::OnClose)
gbazin's avatar
 
gbazin committed
97 98
    EVT_MENU(Open_Event, Playlist::OnOpen)
    EVT_MENU(Save_Event, Playlist::OnSave)
zorglub's avatar
zorglub committed
99 100 101 102 103 104 105 106

    EVT_MENU(SortTitle_Event, Playlist::OnSort)
    EVT_MENU(RSortTitle_Event, Playlist::OnSort)
    EVT_MENU(SortAuthor_Event, Playlist::OnSort)
    EVT_MENU(RSortAuthor_Event, Playlist::OnSort)
    EVT_MENU(SortGroup_Event, Playlist::OnSort)
    EVT_MENU(RSortGroup_Event, Playlist::OnSort)

zorglub's avatar
zorglub committed
107 108
    EVT_MENU(Randomize_Event, Playlist::OnSort)

zorglub's avatar
zorglub committed
109 110
    EVT_MENU(EnableSelection_Event, Playlist::OnEnableSelection)
    EVT_MENU(DisableSelection_Event, Playlist::OnDisableSelection)
111 112 113
    EVT_MENU(InvertSelection_Event, Playlist::OnInvertSelection)
    EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
    EVT_MENU(SelectAll_Event, Playlist::OnSelectAll)
zorglub's avatar
zorglub committed
114
    EVT_MENU(Infos_Event, Playlist::OnInfos)
115
    EVT_CHECKBOX(Random_Event, Playlist::OnRandom)
116
    EVT_CHECKBOX(Repeat_Event, Playlist::OnRepeat)
117
    EVT_CHECKBOX(Loop_Event, Playlist::OnLoop)
118

zorglub's avatar
zorglub committed
119 120 121
    EVT_MENU(EnableGroup_Event, Playlist::OnEnDis)
    EVT_MENU(DisableGroup_Event, Playlist::OnEnDis)

122 123
    /* Listview events */
    EVT_LIST_ITEM_ACTIVATED(ListView_Event, Playlist::OnActivateItem)
sigmunau's avatar
sigmunau committed
124
    EVT_LIST_COL_CLICK(ListView_Event, Playlist::OnColSelect)
125
    EVT_LIST_KEY_DOWN(ListView_Event, Playlist::OnKeyDown)
zorglub's avatar
zorglub committed
126 127 128 129 130 131 132 133
    EVT_LIST_ITEM_RIGHT_CLICK(ListView_Event, Playlist::OnPopup)

    /* Popup events */
    EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
    EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
    EVT_MENU( PopupEna_Event, Playlist::OnPopupEna)
    EVT_MENU( PopupInfo_Event, Playlist::OnPopupInfo)

134 135

    /* Button events */
zorglub's avatar
zorglub committed
136
    EVT_BUTTON( Search_Event, Playlist::OnSearch)
gbazin's avatar
 
gbazin committed
137
    EVT_BUTTON( Save_Event, Playlist::OnSave)
zorglub's avatar
zorglub committed
138
    EVT_BUTTON( Infos_Event, Playlist::OnInfos)
139

zorglub's avatar
zorglub committed
140 141 142
    EVT_BUTTON( Up_Event, Playlist::OnUp)
    EVT_BUTTON( Down_Event, Playlist::OnDown)

zorglub's avatar
zorglub committed
143 144
    EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange)

145 146 147 148 149
    /* Special events : we don't want to destroy the window when the user
     * clicks on (X) */
    EVT_CLOSE(Playlist::OnClose)
END_EVENT_TABLE()

zorglub's avatar
zorglub committed
150 151 152 153 154 155 156

/* Event Table for the Newgroup class */
BEGIN_EVENT_TABLE(NewGroup, wxDialog)
    EVT_BUTTON( wxID_OK, NewGroup::OnOk)
    EVT_BUTTON( wxID_CANCEL, NewGroup::OnCancel)
END_EVENT_TABLE()

157 158 159
/*****************************************************************************
 * Constructor.
 *****************************************************************************/
gbazin's avatar
 
gbazin committed
160 161
Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
    wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
gbazin's avatar
 
gbazin committed
162
             wxDefaultSize, wxDEFAULT_FRAME_STYLE )
163 164
{
    /* Initializations */
zorglub's avatar
zorglub committed
165
    iteminfo_dialog = NULL;
166
    p_intf = _p_intf;
167
    vlc_value_t  val;
gbazin's avatar
 
gbazin committed
168
    i_update_counter = 0;
zorglub's avatar
zorglub committed
169
    i_sort_mode = MODE_NONE;
gbazin's avatar
 
gbazin committed
170 171
    b_need_update = VLC_FALSE;
    vlc_mutex_init( p_intf, &lock );
gbazin's avatar
 
gbazin committed
172
    SetIcon( *p_intf->p_sys->p_icon );
173

174 175 176 177 178
    i_title_sorted = 0;
    i_author_sorted = 0;
    i_group_sorted = 0;


179 180 181 182 183 184 185
    var_Create( p_intf, "random", VLC_VAR_BOOL );
    var_Change( p_intf, "random", VLC_VAR_INHERITVALUE, & val, NULL );
    var_Create( p_intf, "loop", VLC_VAR_BOOL );
    var_Create( p_intf, "loop", VLC_VAR_BOOL );
    var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
    var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );

186 187
    /* Create our "Manage" menu */
    wxMenu *manage_menu = new wxMenu;
gbazin's avatar
 
gbazin committed
188
    manage_menu->Append( AddFile_Event, wxU(_("&Simple Add...")) );
gbazin's avatar
 
gbazin committed
189
    manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
zorglub's avatar
zorglub committed
190
    manage_menu->AppendSeparator();
gbazin's avatar
 
gbazin committed
191 192
    manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
    manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
193
    manage_menu->AppendSeparator();
gbazin's avatar
 
gbazin committed
194
    manage_menu->Append( Close_Event, wxU(_("&Close")) );
195

zorglub's avatar
zorglub committed
196 197
    /* Create our "Sort" menu */
    wxMenu *sort_menu = new wxMenu;
zorglub's avatar
zorglub committed
198
    sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
zorglub's avatar
zorglub committed
199 200
    sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
    sort_menu->AppendSeparator();
zorglub's avatar
zorglub committed
201
    sort_menu->Append( SortAuthor_Event, wxU(_("Sort by &author")) );
zorglub's avatar
zorglub committed
202 203
    sort_menu->Append( RSortAuthor_Event, wxU(_("&Reverse sort by author")) );
    sort_menu->AppendSeparator();
zorglub's avatar
zorglub committed
204
    sort_menu->Append( SortGroup_Event, wxU(_("Sort by &group")) );
zorglub's avatar
zorglub committed
205
    sort_menu->Append( RSortGroup_Event, wxU(_("&Reverse sort by group")) );
zorglub's avatar
zorglub committed
206 207
    sort_menu->AppendSeparator();
    sort_menu->Append( Randomize_Event, wxU(_("&Randomize Playlist")) );
zorglub's avatar
zorglub committed
208

209 210
    /* Create our "Selection" menu */
    wxMenu *selection_menu = new wxMenu;
zorglub's avatar
zorglub committed
211 212 213
    selection_menu->Append( EnableSelection_Event, wxU(_("&Enable")) );
    selection_menu->Append( DisableSelection_Event, wxU(_("&Disable")) );
    selection_menu->AppendSeparator();
gbazin's avatar
 
gbazin committed
214 215 216
    selection_menu->Append( InvertSelection_Event, wxU(_("&Invert")) );
    selection_menu->Append( DeleteSelection_Event, wxU(_("&Delete")) );
    selection_menu->Append( SelectAll_Event, wxU(_("&Select All")) );
217

zorglub's avatar
zorglub committed
218 219 220 221 222 223
    /* Create our "Group" menu */
    wxMenu *group_menu = new wxMenu;
    group_menu->Append( EnableGroup_Event, wxU(_("&Enable all group items")) );
    group_menu->Append( DisableGroup_Event,
                        wxU(_("&Disable all group items")) );

224 225
    /* Append the freshly created menus to the menu bar */
    wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
gbazin's avatar
 
gbazin committed
226
    menubar->Append( manage_menu, wxU(_("&Manage")) );
zorglub's avatar
zorglub committed
227
    menubar->Append( sort_menu, wxU(_("S&ort")) );
gbazin's avatar
 
gbazin committed
228
    menubar->Append( selection_menu, wxU(_("&Selection")) );
zorglub's avatar
zorglub committed
229
    menubar->Append( group_menu, wxU(_("&Groups")) );
230 231 232 233

    /* Attach the menu bar to the frame */
    SetMenuBar( menubar );

zorglub's avatar
zorglub committed
234 235 236 237 238 239
    /* Create the popup menu */
    popup_menu = new wxMenu;
    popup_menu->Append( PopupPlay_Event, wxU(_("Play item")) );
    popup_menu->Append( PopupDel_Event, wxU(_("Delete item")) );
    popup_menu->Append( PopupEna_Event, wxU(_("Toggle enabled")) );
    popup_menu->Append( PopupInfo_Event, wxU(_("Info on item")) );
zorglub's avatar
zorglub committed
240

gbazin's avatar
 
gbazin committed
241 242 243 244
    /* Create a panel to put everything in */
    wxPanel *playlist_panel = new wxPanel( this, -1 );
    playlist_panel->SetAutoLayout( TRUE );

245
    /* Create the Random checkbox */
zorglub's avatar
zorglub committed
246
    wxCheckBox *random_checkbox =
247
        new wxCheckBox( playlist_panel, Random_Event, wxU(_("Random")) );
gbazin's avatar
 
gbazin committed
248
    var_Get( p_intf, "random", &val );
249
    vlc_bool_t b_random = val.b_bool;
gbazin's avatar
 
gbazin committed
250
    random_checkbox->SetValue( b_random == VLC_FALSE ? 0 : 1 );
251 252

    /* Create the Loop Checkbox */
zorglub's avatar
zorglub committed
253
    wxCheckBox *loop_checkbox =
254
        new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Loop")) );
255
    var_Get( p_intf, "loop", &val );
zorglub's avatar
zorglub committed
256
    int b_loop = val.b_bool ;
257
    loop_checkbox->SetValue( b_loop );
258

259
    /* Create the Repeat one checkbox */
zorglub's avatar
zorglub committed
260 261
    wxCheckBox *repeat_checkbox =
        new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat one")) );
262
    var_Get( p_intf, "repeat", &val );
zorglub's avatar
zorglub committed
263
    int b_repeat = val.b_bool ;
264 265
    repeat_checkbox->SetValue( b_repeat );

zorglub's avatar
zorglub committed
266 267
    /* Create the Search Textbox */
    search_text =
zorglub's avatar
zorglub committed
268
        new wxTextCtrl( playlist_panel, SearchText_Event, wxT(""),
gbazin's avatar
 
gbazin committed
269
                        wxDefaultPosition, wxSize(140, -1),
zorglub's avatar
zorglub committed
270
                        wxTE_PROCESS_ENTER);
zorglub's avatar
zorglub committed
271 272

    /* Create the search button */
zorglub's avatar
zorglub committed
273 274
    search_button =
        new wxButton( playlist_panel, Search_Event, wxU(_("Search")) );
zorglub's avatar
zorglub committed
275

276

zorglub's avatar
zorglub committed
277 278 279 280 281 282 283 284 285 286 287
    /* Create the listview */
    /* FIXME: the given size is arbitrary, and prevents us from resizing
     * the window to smaller dimensions. But the sizers don't seem to adjust
     * themselves to the size of a listview, and with a wxDefaultSize the
     * playlist window is ridiculously small */
    listview = new wxListView( playlist_panel, ListView_Event,
                               wxDefaultPosition, wxSize( 500, 300 ),
                               wxLC_REPORT | wxSUNKEN_BORDER );
    listview->InsertColumn( 0, wxU(_("Name")) );
    listview->InsertColumn( 1, wxU(_("Author")) );
    listview->InsertColumn( 2, wxU(_("Group")) );
288
    listview->InsertColumn( 3, wxU(_("Duration")) );
zorglub's avatar
zorglub committed
289 290 291 292 293 294 295 296 297 298 299 300
    listview->SetColumnWidth( 0, 270 );
    listview->SetColumnWidth( 1, 150 );
    listview->SetColumnWidth( 2, 80 );

    /* Create the Up-Down buttons */
    wxButton *up_button =
        new wxButton( playlist_panel, Up_Event, wxU(_("Up") ) );

    wxButton *down_button =
        new wxButton( playlist_panel, Down_Event, wxU(_("Down") ) );

    /* Create the iteminfo button */
zorglub's avatar
zorglub committed
301
    wxButton *iteminfo_button =
Sam Hocevar's avatar
Sam Hocevar committed
302
        new wxButton( playlist_panel, Infos_Event, wxU(_("Item info") ) );
zorglub's avatar
zorglub committed
303

zorglub's avatar
zorglub committed
304 305 306
    /* Place everything in sizers */
    wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
    button_sizer->Add( iteminfo_button, 0, wxALIGN_CENTER|wxLEFT , 5);
307 308
    button_sizer->Layout();

zorglub's avatar
zorglub committed
309 310 311 312
    wxBoxSizer *updown_sizer = new wxBoxSizer( wxHORIZONTAL );
    updown_sizer->Add( up_button, 0, wxALIGN_LEFT|wxRIGHT, 3);
    updown_sizer->Add( down_button, 0, wxALIGN_LEFT|wxLEFT, 3);
    updown_sizer->Layout();
zorglub's avatar
zorglub committed
313 314 315

    wxBoxSizer *checkbox_sizer = new wxBoxSizer( wxHORIZONTAL );
    checkbox_sizer->Add( random_checkbox, 0,
gbazin's avatar
 
gbazin committed
316
                         wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
zorglub's avatar
zorglub committed
317
    checkbox_sizer->Add( loop_checkbox, 0,
gbazin's avatar
 
gbazin committed
318
                         wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
zorglub's avatar
zorglub committed
319
    checkbox_sizer->Add( repeat_checkbox, 0,
gbazin's avatar
 
gbazin committed
320
                         wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
zorglub's avatar
zorglub committed
321 322 323
    checkbox_sizer->Layout();

    wxBoxSizer *search_sizer = new wxBoxSizer( wxHORIZONTAL );
zorglub's avatar
zorglub committed
324 325
    search_sizer->Add( search_text, 0, wxRIGHT|wxALIGN_CENTER, 3);
    search_sizer->Add( search_button, 0, wxLEFT|wxALIGN_CENTER, 3);
zorglub's avatar
zorglub committed
326 327
    search_sizer->Layout();

zorglub's avatar
zorglub committed
328 329
    /* The top and bottom sizers */
    wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
gbazin's avatar
 
gbazin committed
330 331
    top_sizer->Add( checkbox_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_LEFT, 4 );
    top_sizer->Add( search_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 4 );
zorglub's avatar
zorglub committed
332
    top_sizer->Layout();
zorglub's avatar
zorglub committed
333

zorglub's avatar
zorglub committed
334 335 336
    wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
    bottom_sizer->Add( updown_sizer, 0, wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4);
    bottom_sizer->Add( button_sizer , 0, wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
337 338
    bottom_sizer->Layout();

339
    wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
zorglub's avatar
zorglub committed
340

gbazin's avatar
 
gbazin committed
341
    wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
zorglub's avatar
zorglub committed
342
    panel_sizer->Add( top_sizer, 0, wxEXPAND | wxALL, 5 );
gbazin's avatar
 
gbazin committed
343
    panel_sizer->Add( listview, 1, wxEXPAND | wxALL, 5 );
zorglub's avatar
zorglub committed
344
    panel_sizer->Add( bottom_sizer, 0 , wxEXPAND | wxALL, 5);
gbazin's avatar
 
gbazin committed
345
    panel_sizer->Layout();
zorglub's avatar
zorglub committed
346

gbazin's avatar
 
gbazin committed
347 348 349
    playlist_panel->SetSizerAndFit( panel_sizer );
    main_sizer->Add( playlist_panel, 1, wxGROW, 0 );
    main_sizer->Layout();
350
    SetSizerAndFit( main_sizer );
gbazin's avatar
 
gbazin committed
351

gbazin's avatar
 
gbazin committed
352
#if !defined(__WXX11__)
gbazin's avatar
 
gbazin committed
353
    /* Associate drop targets with the playlist */
gbazin's avatar
 
gbazin committed
354
    SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
gbazin's avatar
 
gbazin committed
355
#endif
gbazin's avatar
 
gbazin committed
356

gbazin's avatar
 
gbazin committed
357 358 359 360 361 362 363 364
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

zorglub's avatar
zorglub committed
365
    /* We want to be noticed of playlist changes */
zorglub's avatar
zorglub committed
366 367

    /* Some global changes happened -> Rebuild all */
gbazin's avatar
 
gbazin committed
368
    var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
zorglub's avatar
zorglub committed
369 370 371 372 373 374 375 376

    /* We went to the next item */
    var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );

    /* One item has been updated */
    var_AddCallback( p_playlist, "item-change", ItemChanged, this );


gbazin's avatar
 
gbazin committed
377 378
    vlc_object_release( p_playlist );

gbazin's avatar
 
gbazin committed
379 380
    /* Update the playlist */
    Rebuild();
381 382 383 384
}

Playlist::~Playlist()
{
gbazin's avatar
 
gbazin committed
385 386 387 388 389 390 391 392
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

zorglub's avatar
zorglub committed
393 394
    delete iteminfo_dialog;

gbazin's avatar
 
gbazin committed
395 396
    var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
    vlc_object_release( p_playlist );
397 398
}

zorglub's avatar
zorglub committed
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
/**********************************************************************
 * Update one playlist item
 **********************************************************************/
void Playlist::UpdateItem( int i )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    if( i < 0 || i > p_playlist->i_size )
    {
        vlc_object_release(p_playlist);
        return;
    }
    listview->SetItem( i, 0, wxL2U(p_playlist->pp_items[i]->psz_name) );
    listview->SetItem( i, 1, wxL2U( playlist_GetInfo( p_playlist, i,
                                       "General" , "Author" ) ) );
    listview->SetItem( i, 2,
             wxL2U(playlist_FindGroup(p_playlist,p_playlist->
                                    pp_items[i]->i_group) ) );

    if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
    {
        wxListItem listitem;
        listitem.m_itemId = i;
        listitem.SetTextColour( *wxLIGHT_GREY);
        listview->SetItem(listitem);
    }

    char psz_duration[MSTRTIME_MAX_SIZE];
    mtime_t dur = p_playlist->pp_items[i]->i_duration;
    if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
    else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
    listview->SetItem( i, 3, wxU(psz_duration) );

    /* Change the colour for the currenty played stream */
    wxListItem listitem;
    listitem.m_itemId = i;
    if( i == p_playlist->i_index )
    {
        listitem.SetTextColour( *wxRED );
    }
    else
    {
        listitem.SetTextColour( *wxBLACK );
    }
    listview->SetItem( listitem );

    vlc_object_release(p_playlist);
}

zorglub's avatar
zorglub committed
453 454 455
/**********************************************************************
 * Rebuild the playlist
 **********************************************************************/
456 457 458 459 460 461 462 463 464 465
void Playlist::Rebuild()
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

zorglub's avatar
zorglub committed
466 467
    int i_focused = listview->GetFocusedItem();

468 469 470 471 472 473 474
    /* Clear the list... */
    listview->DeleteAllItems();

    /* ...and rebuild it */
    vlc_mutex_lock( &p_playlist->object_lock );
    for( int i = 0; i < p_playlist->i_size; i++ )
    {
gbazin's avatar
 
gbazin committed
475
        wxString filename = wxL2U(p_playlist->pp_items[i]->psz_name);
476
        listview->InsertItem( i, filename );
zorglub's avatar
zorglub committed
477
        UpdateItem( i );
478 479 480
    }
    vlc_mutex_unlock( &p_playlist->object_lock );

zorglub's avatar
zorglub committed
481 482 483 484 485 486 487 488 489
    if( i_focused )
    {
        listview->Focus( i_focused );
        listview->Select( i_focused );
    }
    else
    {
        listview->Focus( p_playlist->i_index );
    }
490

491 492 493
    vlc_object_release( p_playlist );
}

gbazin's avatar
 
gbazin committed
494
void Playlist::ShowPlaylist( bool show )
495
{
gbazin's avatar
 
gbazin committed
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
    if( show ) Rebuild();
    Show( show );
}

void Playlist::UpdatePlaylist()
{
    vlc_bool_t b_need_update = VLC_FALSE;
    i_update_counter++;

    /* If the playlist isn't show there's no need to update it */
    if( !IsShown() ) return;

    vlc_mutex_lock( &lock );
    if( this->b_need_update )
    {
zorglub's avatar
zorglub committed
511
        b_need_update =VLC_TRUE;
gbazin's avatar
 
gbazin committed
512 513 514 515
        this->b_need_update = VLC_FALSE;
    }
    vlc_mutex_unlock( &lock );

zorglub's avatar
zorglub committed
516 517 518 519
    if( b_need_update )
    {
        Rebuild();
    }
gbazin's avatar
 
gbazin committed
520 521 522 523

    /* Updating the playing status every 0.5s is enough */
    if( i_update_counter % 5 ) return;

524 525 526 527 528 529 530 531
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

gbazin's avatar
 
gbazin committed
532
    /* Update the colour of items */
zorglub's avatar
zorglub committed
533

534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
    vlc_mutex_lock( &p_playlist->object_lock );
    if( p_intf->p_sys->i_playing != p_playlist->i_index )
    {
        wxListItem listitem;
        listitem.m_itemId = p_playlist->i_index;
        listitem.SetTextColour( *wxRED );
        listview->SetItem( listitem );

        if( p_intf->p_sys->i_playing != -1 )
        {
            listitem.m_itemId = p_intf->p_sys->i_playing;
            listitem.SetTextColour( *wxBLACK );
            listview->SetItem( listitem );
        }
        p_intf->p_sys->i_playing = p_playlist->i_index;
    }
    vlc_mutex_unlock( &p_playlist->object_lock );
    vlc_object_release( p_playlist );
}

/*****************************************************************************
 * Private methods.
 *****************************************************************************/
void Playlist::DeleteItem( int item )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    playlist_Delete( p_playlist, item );
    listview->DeleteItem( item );

    vlc_object_release( p_playlist );
}

void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) )
{
    Hide();
}

gbazin's avatar
 
gbazin committed
578 579 580 581 582 583 584 585 586 587 588
void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    wxFileDialog dialog( this, wxU(_("Save playlist")),
gbazin's avatar
 
gbazin committed
589
                         wxT(""), wxT(""), wxT("*"), wxSAVE );
gbazin's avatar
 
gbazin committed
590 591 592 593 594 595 596 597 598 599

    if( dialog.ShowModal() == wxID_OK )
    {
        playlist_SaveFile( p_playlist, dialog.GetPath().mb_str() );
    }

    vlc_object_release( p_playlist );
}

void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
600
{
gbazin's avatar
 
gbazin committed
601 602 603 604 605 606 607 608 609
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    wxFileDialog dialog( this, wxU(_("Open playlist")),
gbazin's avatar
 
gbazin committed
610
                         wxT(""), wxT(""), wxT("*"), wxOPEN );
gbazin's avatar
 
gbazin committed
611 612 613 614 615 616 617

    if( dialog.ShowModal() == wxID_OK )
    {
        playlist_LoadFile( p_playlist, dialog.GetPath().mb_str() );
    }

    vlc_object_release( p_playlist );
618 619
}

gbazin's avatar
 
gbazin committed
620 621
void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
{
gbazin's avatar
 
gbazin committed
622
    p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
gbazin's avatar
 
gbazin committed
623

gbazin's avatar
 
gbazin committed
624
#if 0
gbazin's avatar
 
gbazin committed
625
    Rebuild();
gbazin's avatar
 
gbazin committed
626
#endif
gbazin's avatar
 
gbazin committed
627 628
}

gbazin's avatar
 
gbazin committed
629
void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
630
{
gbazin's avatar
 
gbazin committed
631
    p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
gbazin's avatar
 
gbazin committed
632

gbazin's avatar
 
gbazin committed
633
#if 0
gbazin's avatar
 
gbazin committed
634
    Rebuild();
gbazin's avatar
 
gbazin committed
635
#endif
636 637
}

zorglub's avatar
zorglub committed
638 639 640 641
/********************************************************************
 * Move functions
 ********************************************************************/
void Playlist::OnUp( wxCommandEvent& event)
zorglub's avatar
zorglub committed
642 643 644 645 646 647 648 649 650
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

zorglub's avatar
zorglub committed
651
    /* We use the first selected item, so find it */
gbazin's avatar
 
gbazin committed
652 653
    long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
                                         wxLIST_STATE_SELECTED);
zorglub's avatar
zorglub committed
654 655 656 657 658 659 660 661 662 663 664 665
    if( i_item > 0 && i_item < p_playlist->i_size )
    {
        playlist_Move( p_playlist , i_item, i_item - 1);
        if( i_item > 1 )
        {
            listview->Focus( i_item - 1 );
        }
        else
        {
            listview->Focus(0);
        }
    }
zorglub's avatar
zorglub committed
666 667 668 669
    vlc_object_release( p_playlist );
    return;
}

zorglub's avatar
zorglub committed
670
void Playlist::OnDown( wxCommandEvent& event)
zorglub's avatar
zorglub committed
671 672 673 674 675 676 677 678 679
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

zorglub's avatar
zorglub committed
680
    /* We use the first selected item, so find it */
gbazin's avatar
 
gbazin committed
681 682
    long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
                                         wxLIST_STATE_SELECTED );
zorglub's avatar
zorglub committed
683 684 685 686 687 688 689 690
    if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
    {
        playlist_Move( p_playlist , i_item, i_item + 2 );
        listview->Focus( i_item + 1 );
    }
    vlc_object_release( p_playlist );
    return;
}
zorglub's avatar
zorglub committed
691

zorglub's avatar
zorglub committed
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
/********************************************************************
 * Sorting functions
 ********************************************************************/
void Playlist::OnSort( wxCommandEvent& event )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    switch( event.GetId() )
    {
        case SortTitle_Event:
           playlist_SortTitle( p_playlist , 0 );
           break;
        case RSortTitle_Event:
           playlist_SortTitle( p_playlist , 1 );
           break;
        case SortAuthor_Event:
           playlist_SortAuthor(p_playlist , 0 );
           break;
        case RSortAuthor_Event:
           playlist_SortAuthor( p_playlist , 1 );
           break;
        case SortGroup_Event:
           playlist_SortGroup( p_playlist , 0 );
           break;
        case RSortGroup_Event:
           playlist_SortGroup( p_playlist , 1 );
           break;
zorglub's avatar
zorglub committed
724 725 726
        case Randomize_Event:
           playlist_Sort( p_playlist , SORT_RANDOM, SORT_NORMAL );
           break;
zorglub's avatar
zorglub committed
727
    }
zorglub's avatar
zorglub committed
728 729 730 731 732 733 734
    vlc_object_release( p_playlist );

    Rebuild();

    return;
}

sigmunau's avatar
sigmunau committed
735 736 737 738 739 740 741 742 743 744 745 746
void Playlist::OnColSelect( wxListEvent& event )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    switch( event.GetColumn() )
    {
        case 0:
747 748 749 750 751 752 753 754 755 756
            if( i_title_sorted != 1 )
            {
                playlist_SortTitle( p_playlist, 0 );
                i_title_sorted = 1;
            }
            else
            {
                playlist_SortTitle( p_playlist, 1 );
                i_title_sorted = -1;
            }
sigmunau's avatar
sigmunau committed
757 758
            break;
        case 1:
759 760 761 762 763 764 765 766 767 768
            if( i_author_sorted != 1 )
            {
                playlist_SortAuthor( p_playlist, 0 );
                i_author_sorted = 1;
            }
            else
            {
                playlist_SortAuthor( p_playlist, 1 );
                i_author_sorted = -1;
            }
sigmunau's avatar
sigmunau committed
769 770
            break;
        case 2:
771 772 773 774 775 776 777 778 779 780
            if( i_group_sorted != 1 )
            {
                playlist_SortGroup( p_playlist, 0 );
                i_group_sorted = 1;
            }
            else
            {
                playlist_SortGroup( p_playlist, 1 );
                i_group_sorted = -1;
            }
sigmunau's avatar
sigmunau committed
781 782 783 784 785 786 787 788 789 790 791
            break;
        default:
            break;
    }
    vlc_object_release( p_playlist );

    Rebuild();

    return;
}

zorglub's avatar
zorglub committed
792 793 794
/**********************************************************************
 * Search functions
 **********************************************************************/
zorglub's avatar
zorglub committed
795 796
void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
{
zorglub's avatar
zorglub committed
797
   search_button->SetDefault();
zorglub's avatar
zorglub committed
798 799 800 801 802 803 804
}

void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
{
    wxString search_string= search_text->GetValue();

    int i_current;
zorglub's avatar
zorglub committed
805
    int i_first = 0 ;
zorglub's avatar
zorglub committed
806 807
    int i_item = -1;

zorglub's avatar
zorglub committed
808
    for( i_current = 0 ; i_current <= listview->GetItemCount() ; i_current++ )
zorglub's avatar
zorglub committed
809
    {
gbazin's avatar
 
gbazin committed
810
        if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED )
zorglub's avatar
zorglub committed
811 812 813 814 815
                   == wxLIST_STATE_SELECTED )
        {
            i_first = i_current;
            break;
        }
zorglub's avatar
zorglub committed
816 817
    }

zorglub's avatar
zorglub committed
818
    for ( i_current = i_first + 1; i_current <= listview->GetItemCount() ;
zorglub's avatar
zorglub committed
819
          i_current++ )
zorglub's avatar
zorglub committed
820
    {
zorglub's avatar
zorglub committed
821 822 823 824 825 826 827 828
        wxListItem listitem;
        listitem.SetId( i_current );
        listview->GetItem( listitem );
        if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
        {
            i_item = i_current;
            break;
        }
zorglub's avatar
zorglub committed
829 830 831 832 833
    }
    for( long item = 0; item < listview->GetItemCount(); item++ )
    {
        listview->Select( item, FALSE );
    }
zorglub's avatar
zorglub committed
834

zorglub's avatar
zorglub committed
835 836 837 838 839 840 841 842
    wxListItem listitem;
    listitem.SetId(i_item);
    listitem.m_state = wxLIST_STATE_SELECTED;
    listview->Select( i_item, TRUE );
    listview->Focus( i_item );

}

zorglub's avatar
zorglub committed
843 844 845
/**********************************************************************
 * Selection functions
 **********************************************************************/
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
void Playlist::OnInvertSelection( wxCommandEvent& WXUNUSED(event) )
{
    for( long item = 0; item < listview->GetItemCount(); item++ )
    {
        listview->Select( item, ! listview->IsSelected( item ) );
    }
}

void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
{
    /* Delete from the end to the beginning, to avoid a shift of indices */
    for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
    {
        if( listview->IsSelected( item ) )
        {
            DeleteItem( item );
        }
    }

    Rebuild();
}

zorglub's avatar
zorglub committed
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
    {
        if( listview->IsSelected( item ) )
        {
            playlist_Enable( p_playlist, item );
zorglub's avatar
zorglub committed
883
            UpdateItem( item );
zorglub's avatar
zorglub committed
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
        }
    }
    vlc_object_release( p_playlist);
}

void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    for( long item = listview->GetItemCount() - 1; item >= 0; item-- )
    {
        if( listview->IsSelected( item ) )
        {
            playlist_Disable( p_playlist, item );
zorglub's avatar
zorglub committed
904
            UpdateItem( item );
zorglub's avatar
zorglub committed
905 906 907 908 909
        }
    }
    vlc_object_release( p_playlist);
}

zorglub's avatar
zorglub committed
910 911 912 913 914 915 916 917 918 919 920
void Playlist::OnSelectAll( wxCommandEvent& WXUNUSED(event) )
{
    for( long item = 0; item < listview->GetItemCount(); item++ )
    {
        listview->Select( item, TRUE );
    }
}

/**********************************************************************
 * Playlist mode functions
 **********************************************************************/
921 922
void Playlist::OnRandom( wxCommandEvent& event )
{
923 924 925 926 927 928 929 930 931 932 933
    vlc_value_t val;
    val.b_bool = event.IsChecked();
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    var_Set( p_playlist , "random", val);
    vlc_object_release( p_playlist );
934 935 936
}
void Playlist::OnLoop ( wxCommandEvent& event )
{
937 938 939 940 941 942 943 944 945 946 947 948
    vlc_value_t val;
    val.b_bool = event.IsChecked();
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    var_Set( p_playlist , "loop", val);
    vlc_object_release( p_playlist );
}
949

950 951 952 953 954 955 956 957 958 959 960 961 962
void Playlist::OnRepeat ( wxCommandEvent& event )
{
    vlc_value_t val;
    val.b_bool = event.IsChecked();
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    var_Set( p_playlist , "repeat", val);
    vlc_object_release( p_playlist );
963 964
}

zorglub's avatar
zorglub committed
965

966 967 968 969 970 971 972 973 974 975 976 977 978 979

void Playlist::OnActivateItem( wxListEvent& event )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    playlist_Goto( p_playlist, event.GetIndex() );

    vlc_object_release( p_playlist );
}
zorglub's avatar
zorglub committed
980

981 982 983 984 985 986 987 988 989 990
void Playlist::OnKeyDown( wxListEvent& event )
{
    long keycode = event.GetKeyCode();
    /* Delete selected items */
    if( keycode == WXK_BACK || keycode == WXK_DELETE )
    {
        /* We send a dummy event */
        OnDeleteSelection( event );
    }
}
gbazin's avatar
 
gbazin committed
991

zorglub's avatar
zorglub committed
992
void Playlist::ShowInfos( int i_item )
zorglub's avatar
zorglub committed
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    if( iteminfo_dialog == NULL )
    {
        if( i_item >= 0 && i_item < p_playlist->i_size )
        {
            iteminfo_dialog = new ItemInfoDialog(
                              p_intf, p_playlist->pp_items[i_item], this );
            if( iteminfo_dialog->ShowModal()  == wxID_OK )
zorglub's avatar
zorglub committed
1008
                UpdateItem( i_item );
zorglub's avatar
zorglub committed
1009 1010 1011 1012 1013 1014 1015
            delete iteminfo_dialog;
            iteminfo_dialog = NULL;
        }
    }
    vlc_object_release( p_playlist );
}

zorglub's avatar
zorglub committed
1016 1017 1018 1019 1020 1021 1022 1023
void Playlist::OnInfos( wxCommandEvent& WXUNUSED(event) )
{
    /* We use the first selected item, so find it */
    long i_item = listview->GetNextItem( -1 , wxLIST_NEXT_ALL,
                                         wxLIST_STATE_SELECTED );
    ShowInfos( i_item );
}

zorglub's avatar
zorglub committed
1024
void Playlist::OnEnDis( wxCommandEvent& event )
zorglub's avatar
zorglub committed
1025 1026 1027 1028 1029 1030 1031 1032 1033
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

gbazin's avatar
 
gbazin committed
1034 1035
    long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
                                         wxLIST_STATE_SELECTED );
zorglub's avatar
zorglub committed
1036 1037 1038

    if( i_item >= 0 && i_item < p_playlist->i_size )
    {
zorglub's avatar
zorglub committed
1039 1040 1041 1042
       switch( event.GetId() )
       {
           case EnableGroup_Event:
               playlist_EnableGroup( p_playlist ,
zorglub's avatar
zorglub committed
1043
                                  p_playlist->pp_items[i_item]->i_group );
zorglub's avatar
zorglub committed
1044 1045 1046
               break;
           case DisableGroup_Event:
               playlist_DisableGroup( p_playlist ,
zorglub's avatar
zorglub committed
1047
                                  p_playlist->pp_items[i_item]->i_group );
zorglub's avatar
zorglub committed
1048 1049
               break;
       }
zorglub's avatar
zorglub committed
1050 1051 1052 1053 1054
       Rebuild();
    }

    vlc_object_release( p_playlist );
}
zorglub's avatar
zorglub committed
1055

zorglub's avatar
zorglub committed
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
/*****************************************************************************
 * Popup management functions
 *****************************************************************************/
void Playlist::OnPopup( wxListEvent& event )
{
    i_popup_item = event.GetIndex();
    Playlist::PopupMenu( popup_menu , ScreenToClient( wxGetMousePosition() ) );
}


void Playlist::OnPopupPlay( wxMenuEvent& event )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }
    if( i_popup_item != -1 )
    {
        playlist_Goto( p_playlist, i_popup_item );
    }
    vlc_object_release( p_playlist );
}

void Playlist::OnPopupDel( wxMenuEvent& event )
{
    DeleteItem( i_popup_item );
}

void Playlist::OnPopupEna( wxMenuEvent& event )
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    if( p_playlist->pp_items[i_popup_item]->b_enabled )
        //playlist_IsEnabled( p_playlist, i_popup_item ) )
    {
        playlist_Disable( p_playlist, i_popup_item );
    }
    else
    {
        playlist_Enable( p_playlist, i_popup_item );
    }
    vlc_object_release( p_playlist);
    UpdateItem( i_popup_item );
}

void Playlist::OnPopupInfo( wxMenuEvent& event )
{
    ShowInfos( i_popup_item );
}

gbazin's avatar
 
gbazin committed
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
/*****************************************************************************
 * PlaylistChanged: callback triggered by the intf-change playlist variable
 *  We don't rebuild the playlist directly here because we don't want the
 *  caller to block for a too long time.
 *****************************************************************************/
int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
                     vlc_value_t old_val, vlc_value_t new_val, void *param )
{
    Playlist *p_playlist_dialog = (Playlist *)param;
    vlc_mutex_lock( &p_playlist_dialog->lock );
    p_playlist_dialog->b_need_update = VLC_TRUE;
    vlc_mutex_unlock( &p_playlist_dialog->lock );
    return VLC_SUCCESS;
}