playlist.cpp 40.4 KB
Newer Older
1
/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
2
 * playlist.cpp : wxWindows plugin for vlc
3
 *****************************************************************************
4
 * Copyright (C) 2000-2004 VideoLAN
Clément Stenac's avatar
Clément Stenac committed
5
 * $Id$
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.
Gildas Bazin's avatar
 
Gildas Bazin 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
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
27
#include <vlc/vlc.h>
Gildas Bazin's avatar
 
Gildas Bazin committed
28
#include <vlc/intf.h>
29 30 31

#include "wxwindows.h"

Gildas Bazin's avatar
 
Gildas Bazin committed
32
/* Callback prototype */
33 34 35 36 37 38
static int PlaylistChanged( vlc_object_t *, const char *,
                            vlc_value_t, vlc_value_t, void * );
static int PlaylistNext( vlc_object_t *, const char *,
                         vlc_value_t, vlc_value_t, void * );
static int ItemChanged( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
Gildas Bazin's avatar
 
Gildas Bazin committed
39

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

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

54 55 56 57 58 59
    SortTitle_Event,
    RSortTitle_Event,
    SortAuthor_Event,
    RSortAuthor_Event,
    SortGroup_Event,
    RSortGroup_Event,
Clément Stenac's avatar
Clément Stenac committed
60
    Randomize_Event,
61

Clément Stenac's avatar
Clément Stenac committed
62 63 64
    EnableSelection_Event,
    DisableSelection_Event,

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

72 73
    EnableGroup_Event,
    DisableGroup_Event,
Clément Stenac's avatar
Clément Stenac committed
74

75 76
    Up_Event,
    Down_Event,
Clément Stenac's avatar
Clément Stenac committed
77 78
    Infos_Event,

79 80 81 82 83
    PopupPlay_Event,
    PopupDel_Event,
    PopupEna_Event,
    PopupInfo_Event,

Clément Stenac's avatar
Clément Stenac committed
84 85 86
    SearchText_Event,
    Search_Event,

87
    /* controls */
88 89 90
    ListView_Event,

    Browse_Event,  /* For export playlist */
91 92 93

    /* custom events */
    UpdateItem_Event
94 95
};

96 97
DEFINE_LOCAL_EVENT_TYPE( wxEVT_PLAYLIST );

98 99
BEGIN_EVENT_TABLE(Playlist, wxFrame)
    /* Menu events */
Gildas Bazin's avatar
 
Gildas Bazin committed
100
    EVT_MENU(AddFile_Event, Playlist::OnAddFile)
Gildas Bazin's avatar
 
Gildas Bazin committed
101
    EVT_MENU(AddMRL_Event, Playlist::OnAddMRL)
102
    EVT_MENU(Close_Event, Playlist::OnClose)
Gildas Bazin's avatar
 
Gildas Bazin committed
103 104
    EVT_MENU(Open_Event, Playlist::OnOpen)
    EVT_MENU(Save_Event, Playlist::OnSave)
105 106 107 108 109 110 111 112

    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)

Clément Stenac's avatar
Clément Stenac committed
113 114
    EVT_MENU(Randomize_Event, Playlist::OnSort)

Clément Stenac's avatar
Clément Stenac committed
115 116
    EVT_MENU(EnableSelection_Event, Playlist::OnEnableSelection)
    EVT_MENU(DisableSelection_Event, Playlist::OnDisableSelection)
117 118 119
    EVT_MENU(InvertSelection_Event, Playlist::OnInvertSelection)
    EVT_MENU(DeleteSelection_Event, Playlist::OnDeleteSelection)
    EVT_MENU(SelectAll_Event, Playlist::OnSelectAll)
Clément Stenac's avatar
Clément Stenac committed
120
    EVT_MENU(Infos_Event, Playlist::OnInfos)
121
    EVT_CHECKBOX(Random_Event, Playlist::OnRandom)
122
    EVT_CHECKBOX(Repeat_Event, Playlist::OnRepeat)
123
    EVT_CHECKBOX(Loop_Event, Playlist::OnLoop)
124

125 126 127
    EVT_MENU(EnableGroup_Event, Playlist::OnEnDis)
    EVT_MENU(DisableGroup_Event, Playlist::OnEnDis)

128 129
    /* Listview events */
    EVT_LIST_ITEM_ACTIVATED(ListView_Event, Playlist::OnActivateItem)
130
    EVT_LIST_COL_CLICK(ListView_Event, Playlist::OnColSelect)
131
    EVT_LIST_KEY_DOWN(ListView_Event, Playlist::OnKeyDown)
132 133 134 135 136 137 138 139
    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)

140 141

    /* Button events */
Clément Stenac's avatar
Clément Stenac committed
142
    EVT_BUTTON( Search_Event, Playlist::OnSearch)
Gildas Bazin's avatar
 
Gildas Bazin committed
143
    EVT_BUTTON( Save_Event, Playlist::OnSave)
Clément Stenac's avatar
Clément Stenac committed
144
    EVT_BUTTON( Infos_Event, Playlist::OnInfos)
145

146 147 148
    EVT_BUTTON( Up_Event, Playlist::OnUp)
    EVT_BUTTON( Down_Event, Playlist::OnDown)

Clément Stenac's avatar
Clément Stenac committed
149 150
    EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange)

151 152 153
    /* Custom events */
    EVT_COMMAND(-1, wxEVT_PLAYLIST, Playlist::OnPlaylistEvent)

154 155 156 157 158
    /* Special events : we don't want to destroy the window when the user
     * clicks on (X) */
    EVT_CLOSE(Playlist::OnClose)
END_EVENT_TABLE()

159 160 161 162 163 164 165

/* 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()

166

167 168 169
/*****************************************************************************
 * Constructor.
 *****************************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
170 171
Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
    wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
Gildas Bazin's avatar
 
Gildas Bazin committed
172
             wxDefaultSize, wxDEFAULT_FRAME_STYLE )
173
{
Gildas Bazin's avatar
 
Gildas Bazin committed
174 175
    vlc_value_t val;

176
    /* Initializations */
Clément Stenac's avatar
Clément Stenac committed
177
    iteminfo_dialog = NULL;
178
    p_intf = _p_intf;
Gildas Bazin's avatar
 
Gildas Bazin committed
179
    i_update_counter = 0;
180
    i_sort_mode = MODE_NONE;
Gildas Bazin's avatar
 
Gildas Bazin committed
181
    b_need_update = VLC_FALSE;
Gildas Bazin's avatar
 
Gildas Bazin committed
182
    SetIcon( *p_intf->p_sys->p_icon );
183

184 185 186
    i_title_sorted = 0;
    i_author_sorted = 0;
    i_group_sorted = 0;
187
    i_duration_sorted = 0;
188

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
189 190 191
    var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
    var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
    var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
192

193 194
    /* Create our "Manage" menu */
    wxMenu *manage_menu = new wxMenu;
Gildas Bazin's avatar
 
Gildas Bazin committed
195
    manage_menu->Append( AddFile_Event, wxU(_("&Simple Add...")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
196
    manage_menu->Append( AddMRL_Event, wxU(_("&Add MRL...")) );
197
    manage_menu->AppendSeparator();
Gildas Bazin's avatar
 
Gildas Bazin committed
198 199
    manage_menu->Append( Open_Event, wxU(_("&Open Playlist...")) );
    manage_menu->Append( Save_Event, wxU(_("&Save Playlist...")) );
200
    manage_menu->AppendSeparator();
Gildas Bazin's avatar
 
Gildas Bazin committed
201
    manage_menu->Append( Close_Event, wxU(_("&Close")) );
202

203 204
    /* Create our "Sort" menu */
    wxMenu *sort_menu = new wxMenu;
Clément Stenac's avatar
Clément Stenac committed
205
    sort_menu->Append( SortTitle_Event, wxU(_("Sort by &title")) );
206 207
    sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
    sort_menu->AppendSeparator();
Clément Stenac's avatar
Clément Stenac committed
208
    sort_menu->Append( SortAuthor_Event, wxU(_("Sort by &author")) );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
209
    sort_menu->Append( RSortAuthor_Event, wxU(_("Reverse sort by author")) );
210
    sort_menu->AppendSeparator();
Clément Stenac's avatar
Clément Stenac committed
211
    sort_menu->Append( SortGroup_Event, wxU(_("Sort by &group")) );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
212
    sort_menu->Append( RSortGroup_Event, wxU(_("Reverse sort by group")) );
Clément Stenac's avatar
Clément Stenac committed
213
    sort_menu->AppendSeparator();
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
214
    sort_menu->Append( Randomize_Event, wxU(_("&Shuffle Playlist")) );
215

216 217
    /* Create our "Selection" menu */
    wxMenu *selection_menu = new wxMenu;
Clément Stenac's avatar
Clément Stenac committed
218 219 220
    selection_menu->Append( EnableSelection_Event, wxU(_("&Enable")) );
    selection_menu->Append( DisableSelection_Event, wxU(_("&Disable")) );
    selection_menu->AppendSeparator();
Gildas Bazin's avatar
 
Gildas Bazin committed
221
    selection_menu->Append( InvertSelection_Event, wxU(_("&Invert")) );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
222
    selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
223
    selection_menu->Append( SelectAll_Event, wxU(_("&Select All")) );
224

225 226 227 228 229 230
    /* 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")) );

231 232
    /* Append the freshly created menus to the menu bar */
    wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
Gildas Bazin's avatar
 
Gildas Bazin committed
233
    menubar->Append( manage_menu, wxU(_("&Manage")) );
234
    menubar->Append( sort_menu, wxU(_("S&ort")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
235
    menubar->Append( selection_menu, wxU(_("&Selection")) );
236
    menubar->Append( group_menu, wxU(_("&Groups")) );
237 238 239 240

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

241 242
    /* Create the popup menu */
    popup_menu = new wxMenu;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
243 244
    popup_menu->Append( PopupPlay_Event, wxU(_("Play")) );
    popup_menu->Append( PopupDel_Event, wxU(_("Delete")) );
245
    popup_menu->Append( PopupEna_Event, wxU(_("Enable/Disable")) );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
246
    popup_menu->Append( PopupInfo_Event, wxU(_("Info")) );
247

Gildas Bazin's avatar
 
Gildas Bazin committed
248 249 250 251
    /* Create a panel to put everything in */
    wxPanel *playlist_panel = new wxPanel( this, -1 );
    playlist_panel->SetAutoLayout( TRUE );

252
    /* Create the Random checkbox */
Clément Stenac's avatar
Clément Stenac committed
253
    wxCheckBox *random_checkbox =
254
        new wxCheckBox( playlist_panel, Random_Event, wxU(_("Random")) );
Gildas Bazin's avatar
 
Gildas Bazin committed
255
    var_Get( p_intf, "random", &val );
256
    vlc_bool_t b_random = val.b_bool;
Gildas Bazin's avatar
 
Gildas Bazin committed
257
    random_checkbox->SetValue( b_random == VLC_FALSE ? 0 : 1 );
258 259

    /* Create the Loop Checkbox */
Clément Stenac's avatar
Clément Stenac committed
260
    wxCheckBox *loop_checkbox =
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
261
        new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Repeat All")) );
262
    var_Get( p_intf, "loop", &val );
Clément Stenac's avatar
Clément Stenac committed
263
    int b_loop = val.b_bool ;
264
    loop_checkbox->SetValue( b_loop );
265

266
    /* Create the Repeat one checkbox */
Clément Stenac's avatar
Clément Stenac committed
267
    wxCheckBox *repeat_checkbox =
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
268
        new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat One")) );
269
    var_Get( p_intf, "repeat", &val );
Clément Stenac's avatar
Clément Stenac committed
270
    int b_repeat = val.b_bool ;
271 272
    repeat_checkbox->SetValue( b_repeat );

Clément Stenac's avatar
Clément Stenac committed
273 274
    /* Create the Search Textbox */
    search_text =
Clément Stenac's avatar
Clément Stenac committed
275
        new wxTextCtrl( playlist_panel, SearchText_Event, wxT(""),
Gildas Bazin's avatar
 
Gildas Bazin committed
276
                        wxDefaultPosition, wxSize(140, -1),
Clément Stenac's avatar
Clément Stenac committed
277
                        wxTE_PROCESS_ENTER);
Clément Stenac's avatar
Clément Stenac committed
278 279

    /* Create the search button */
Clément Stenac's avatar
Clément Stenac committed
280 281
    search_button =
        new wxButton( playlist_panel, Search_Event, wxU(_("Search")) );
Clément Stenac's avatar
Clément Stenac committed
282

283

284 285 286 287 288 289 290 291 292 293
    /* 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")) );
294 295
    listview->InsertColumn( 2, wxU(_("Duration")) );
    listview->InsertColumn( 3, wxU(_("Group")) );
296 297 298 299 300 301 302 303 304 305 306 307
    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 */
Clément Stenac's avatar
Clément Stenac committed
308
    wxButton *iteminfo_button =
Sam Hocevar's avatar
Sam Hocevar committed
309
        new wxButton( playlist_panel, Infos_Event, wxU(_("Item info") ) );
310

Clément Stenac's avatar
Clément Stenac committed
311 312
    /* Place everything in sizers */
    wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
313
    button_sizer->Add( iteminfo_button, 0, wxALIGN_CENTER|wxLEFT, 5);
314 315
    button_sizer->Layout();

316 317 318 319
    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();
Clément Stenac's avatar
Clément Stenac committed
320 321 322

    wxBoxSizer *checkbox_sizer = new wxBoxSizer( wxHORIZONTAL );
    checkbox_sizer->Add( random_checkbox, 0,
Gildas Bazin's avatar
 
Gildas Bazin committed
323
                         wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
Clément Stenac's avatar
Clément Stenac committed
324
    checkbox_sizer->Add( loop_checkbox, 0,
Gildas Bazin's avatar
 
Gildas Bazin committed
325
                         wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
Clément Stenac's avatar
Clément Stenac committed
326
    checkbox_sizer->Add( repeat_checkbox, 0,
Gildas Bazin's avatar
 
Gildas Bazin committed
327
                         wxEXPAND | wxALIGN_RIGHT | wxALL, 5);
Clément Stenac's avatar
Clément Stenac committed
328 329 330
    checkbox_sizer->Layout();

    wxBoxSizer *search_sizer = new wxBoxSizer( wxHORIZONTAL );
331 332
    search_sizer->Add( search_text, 0, wxRIGHT|wxALIGN_CENTER, 3);
    search_sizer->Add( search_button, 0, wxLEFT|wxALIGN_CENTER, 3);
Clément Stenac's avatar
Clément Stenac committed
333 334
    search_sizer->Layout();

335 336
    /* The top and bottom sizers */
    wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
Gildas Bazin's avatar
 
Gildas Bazin committed
337 338
    top_sizer->Add( checkbox_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_LEFT, 4 );
    top_sizer->Add( search_sizer, 1, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 4 );
339
    top_sizer->Layout();
Clément Stenac's avatar
Clément Stenac committed
340

341
    wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
Gildas Bazin's avatar
 
Gildas Bazin committed
342 343
    bottom_sizer->Add( updown_sizer, 0,
                       wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4 );
344
    bottom_sizer->Add( button_sizer, 0,
Gildas Bazin's avatar
 
Gildas Bazin committed
345
                       wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
346 347
    bottom_sizer->Layout();

348
    wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
Clément Stenac's avatar
Clément Stenac committed
349

Gildas Bazin's avatar
 
Gildas Bazin committed
350
    wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
351
    panel_sizer->Add( top_sizer, 0, wxEXPAND | wxALL, 5 );
Gildas Bazin's avatar
 
Gildas Bazin committed
352
    panel_sizer->Add( listview, 1, wxEXPAND | wxALL, 5 );
353
    panel_sizer->Add( bottom_sizer, 0, wxEXPAND | wxALL, 5);
Gildas Bazin's avatar
 
Gildas Bazin committed
354
    panel_sizer->Layout();
Clément Stenac's avatar
Clément Stenac committed
355

Gildas Bazin's avatar
 
Gildas Bazin committed
356 357 358
    playlist_panel->SetSizerAndFit( panel_sizer );
    main_sizer->Add( playlist_panel, 1, wxGROW, 0 );
    main_sizer->Layout();
359
    SetSizerAndFit( main_sizer );
Gildas Bazin's avatar
 
Gildas Bazin committed
360

361
#if wxUSE_DRAG_AND_DROP
Gildas Bazin's avatar
 
Gildas Bazin committed
362
    /* Associate drop targets with the playlist */
Gildas Bazin's avatar
 
Gildas Bazin committed
363
    SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
Gildas Bazin's avatar
 
Gildas Bazin committed
364
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
365

Gildas Bazin's avatar
 
Gildas Bazin committed
366 367 368 369 370 371 372 373
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

374
    /* We want to be noticed of playlist changes */
375 376

    /* Some global changes happened -> Rebuild all */
Gildas Bazin's avatar
 
Gildas Bazin committed
377
    var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
378 379 380 381 382 383 384 385

    /* 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 );


Gildas Bazin's avatar
 
Gildas Bazin committed
386 387
    vlc_object_release( p_playlist );

Gildas Bazin's avatar
 
Gildas Bazin committed
388 389
    /* Update the playlist */
    Rebuild();
390 391 392 393
}

Playlist::~Playlist()
{
Gildas Bazin's avatar
 
Gildas Bazin committed
394 395 396 397 398 399 400 401
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

Clément Stenac's avatar
Clément Stenac committed
402 403
    delete iteminfo_dialog;

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
404 405
    var_DelCallback( p_playlist, "item-change", ItemChanged, this );
    var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
Gildas Bazin's avatar
 
Gildas Bazin committed
406 407
    var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
    vlc_object_release( p_playlist );
408 409
}

410 411 412 413 414
/**********************************************************************
 * Update one playlist item
 **********************************************************************/
void Playlist::UpdateItem( int i )
{
Gildas Bazin's avatar
 
Gildas Bazin committed
415 416
    if( i < 0 ) return; /* Sanity check */

417 418 419
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
420

421 422 423 424
    if( p_playlist == NULL )
    {
        return;
    }
425 426 427 428

    playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );

    if( !p_item )
429 430 431 432
    {
        vlc_object_release(p_playlist);
        return;
    }
433

434
    listview->SetItem( i, 0, wxL2U(p_item->input.psz_name) );
435
    listview->SetItem( i, 1, wxU( playlist_ItemGetInfo( p_item,
436
                                       _("General"), _("Author") ) ) );
437
    char *psz_group = playlist_FindGroup(p_playlist,
438
                                         p_item->i_group);
439
    listview->SetItem( i, 3,
440
             wxL2U( psz_group ? psz_group : _("Normal") ) );
441

442
    if( p_item->b_enabled == VLC_FALSE )
443 444 445 446 447 448 449 450
    {
        wxListItem listitem;
        listitem.m_itemId = i;
        listitem.SetTextColour( *wxLIGHT_GREY);
        listview->SetItem(listitem);
    }

    char psz_duration[MSTRTIME_MAX_SIZE];
451
    mtime_t dur = p_item->input.i_duration;
452 453 454 455
    if( dur != -1 )
        secstotimestr( psz_duration, dur/1000000 );
    else
        memcpy( psz_duration, "-:--:--", sizeof("-:--:--") );
456
    listview->SetItem( i, 2, wxU(psz_duration) );
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473

    /* 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);
}

474 475 476
/**********************************************************************
 * Rebuild the playlist
 **********************************************************************/
477 478 479 480 481 482 483 484 485 486
void Playlist::Rebuild()
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

487 488
    int i_focused = listview->GetFocusedItem();

489 490 491 492 493 494 495
    /* 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++ )
    {
496
        wxString filename = wxL2U(p_playlist->pp_items[i]->input.psz_name);
497
        listview->InsertItem( i, filename );
498
        UpdateItem( i );
499 500 501
    }
    vlc_mutex_unlock( &p_playlist->object_lock );

Gildas Bazin's avatar
 
Gildas Bazin committed
502
    if( i_focused >= 0 && i_focused < p_playlist->i_size )
503 504 505 506
    {
        listview->Focus( i_focused );
        listview->Select( i_focused );
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
507
    else if( p_playlist->i_index >= 0 )
508 509 510
    {
        listview->Focus( p_playlist->i_index );
    }
511

512 513 514
    vlc_object_release( p_playlist );
}

Gildas Bazin's avatar
 
Gildas Bazin committed
515
void Playlist::ShowPlaylist( bool show )
516
{
Gildas Bazin's avatar
 
Gildas Bazin committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530
    if( show ) Rebuild();
    Show( show );
}

void Playlist::UpdatePlaylist()
{
    i_update_counter++;

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

    if( this->b_need_update )
    {
        this->b_need_update = VLC_FALSE;
531 532
        Rebuild();
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
533 534 535 536

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

537 538 539 540 541 542 543 544
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
545
    /* Update the colour of items */
Gildas Bazin's avatar
 
Gildas Bazin committed
546 547
    int i_playlist_index = p_playlist->i_index;
    if( p_intf->p_sys->i_playing != i_playlist_index )
548 549
    {
        wxListItem listitem;
Gildas Bazin's avatar
 
Gildas Bazin committed
550
        listitem.m_itemId = i_playlist_index;
551 552 553 554 555 556 557 558 559
        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 );
        }
Gildas Bazin's avatar
 
Gildas Bazin committed
560
        p_intf->p_sys->i_playing = i_playlist_index;
561
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
562

563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
    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();
}

Gildas Bazin's avatar
 
Gildas Bazin committed
590 591
void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
{
592 593 594 595
    struct {
        char *psz_desc;
        char *psz_filter;
        char *psz_module;
Clément Stenac's avatar
Cancel  
Clément Stenac committed
596
    } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" },
597 598
                   { _("PLS file"), "*.pls", "export-pls" }};
    wxString filter = wxT("");
Clément Stenac's avatar
Clément Stenac committed
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615

    playlist_t * p_playlist =
                (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                               FIND_ANYWHERE );

    if( ! p_playlist )
    {
        return;
    }
    if( p_playlist->i_size == 0 )
    {
        wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
                      wxICON_WARNING | wxOK, this );
        vlc_object_release( p_playlist );
        return;
    }

616 617
    for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
618
        filter.Append( wxU(formats[i].psz_desc) );
619
        filter.Append( wxT("|") );
Gildas Bazin's avatar
 
Gildas Bazin committed
620
        filter.Append( wxU(formats[i].psz_filter) );
621 622 623 624 625 626 627
        filter.Append( wxT("|") );
    }
    wxFileDialog dialog( this, wxU(_("Save playlist")),
                         wxT(""), wxT(""), filter, wxSAVE );

    if( dialog.ShowModal() == wxID_OK )
    {
628
        if( dialog.GetPath().mb_str() )
629
        {
630
            playlist_Export( p_playlist, dialog.GetPath().mb_str(),
Clément Stenac's avatar
Clément Stenac committed
631
                             formats[dialog.GetFilterIndex()].psz_module );
632
        }
Clément Stenac's avatar
Clément Stenac committed
633
    }
634

Clément Stenac's avatar
Clément Stenac committed
635
    vlc_object_release( p_playlist );
636

Gildas Bazin's avatar
 
Gildas Bazin committed
637 638 639
}

void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
640
{
Gildas Bazin's avatar
 
Gildas Bazin committed
641 642 643 644 645 646 647 648
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
649 650
    wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
        wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
Gildas Bazin's avatar
 
Gildas Bazin committed
651 652 653

    if( dialog.ShowModal() == wxID_OK )
    {
654
        playlist_Import( p_playlist, dialog.GetPath().mb_str() );
Gildas Bazin's avatar
 
Gildas Bazin committed
655 656 657
    }

    vlc_object_release( p_playlist );
658 659
}

Gildas Bazin's avatar
 
Gildas Bazin committed
660 661
void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
{
Gildas Bazin's avatar
 
Gildas Bazin committed
662
    p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
663

Gildas Bazin's avatar
 
Gildas Bazin committed
664
#if 0
Gildas Bazin's avatar
 
Gildas Bazin committed
665
    Rebuild();
Gildas Bazin's avatar
 
Gildas Bazin committed
666
#endif
Gildas Bazin's avatar
 
Gildas Bazin committed
667 668
}

Gildas Bazin's avatar
 
Gildas Bazin committed
669
void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
670
{
Gildas Bazin's avatar
 
Gildas Bazin committed
671
    p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );
Gildas Bazin's avatar
 
Gildas Bazin committed
672

Gildas Bazin's avatar
 
Gildas Bazin committed
673
#if 0
Gildas Bazin's avatar
 
Gildas Bazin committed
674
    Rebuild();
Gildas Bazin's avatar
 
Gildas Bazin committed
675
#endif
676 677
}

678 679 680
/********************************************************************
 * Move functions
 ********************************************************************/
Gildas Bazin's avatar
 
Gildas Bazin committed
681
void Playlist::OnUp( wxCommandEvent& event )
Clément Stenac's avatar
Clément Stenac committed
682 683 684 685 686 687 688 689 690
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

691
    /* We use the first selected item, so find it */
Gildas Bazin's avatar
 
Gildas Bazin committed
692
    long i_item = listview->GetNextItem( -1, wxLIST_NEXT_ALL,
Gildas Bazin's avatar
 
Gildas Bazin committed
693
                                         wxLIST_STATE_SELECTED);
694 695
    if( i_item > 0 && i_item < p_playlist->i_size )
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
696 697
        playlist_Move( p_playlist, i_item, i_item - 1 );
        listview->Focus( i_item - 1 );
698
    }
Clément Stenac's avatar
Clément Stenac committed
699 700 701
    vlc_object_release( p_playlist );
}

Gildas Bazin's avatar
 
Gildas Bazin committed
702
void Playlist::OnDown( wxCommandEvent& event )
Clément Stenac's avatar
Clément Stenac committed
703 704 705 706 707 708 709 710 711
{
    playlist_t *p_playlist =
        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

712
    /* We use the first selected item, so find it */
Gildas Bazin's avatar
 
Gildas Bazin committed
713
    long i_item = listview->GetNextItem( -1, wxLIST_NEXT_ALL,
Gildas Bazin's avatar
 
Gildas Bazin committed
714
                                         wxLIST_STATE_SELECTED );
715 716
    if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
    {
717
        playlist_Move( p_playlist, i_item, i_item + 2 );
718 719 720 721
        listview->Focus( i_item + 1 );
    }
    vlc_object_release( p_playlist );
}
Clément Stenac's avatar
Clément Stenac committed
722

723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
/********************************************************************
 * 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:
738
           playlist_SortTitle( p_playlist, ORDER_NORMAL );
739 740
           break;
        case RSortTitle_Event:
741
           playlist_SortTitle( p_playlist, ORDER_REVERSE );
742 743
           break;
        case SortAuthor_Event:
744
           playlist_SortAuthor(p_playlist, ORDER_NORMAL );
745 746
           break;
        case RSortAuthor_Event:
747
           playlist_SortAuthor( p_playlist, ORDER_REVERSE );
748 749
           break;
        case SortGroup_Event:
750
           playlist_SortGroup( p_playlist, ORDER_NORMAL );
751 752
           break;
        case RSortGroup_Event:
753
           playlist_SortGroup( p_playlist, ORDER_REVERSE );
754
           break;
Clément Stenac's avatar
Clément Stenac committed
755
        case Randomize_Event:
756
           playlist_Sort( p_playlist, SORT_RANDOM, ORDER_NORMAL );
Clément Stenac's avatar
Clément Stenac committed
757
           break;
758
    }
Clément Stenac's avatar
Clément Stenac committed
759 760 761 762 763
    vlc_object_release( p_playlist );

    Rebuild();
}

764 765 766 767 768 769 770 771 772 773 774 775
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:
776 777
            if( i_title_sorted != 1 )
            {
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
778
                playlist_SortTitle( p_playlist, ORDER_NORMAL );
779 780 781 782
                i_title_sorted = 1;
            }
            else
            {
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
783
                playlist_SortTitle( p_playlist, ORDER_REVERSE );
784 785
                i_title_sorted = -1;
            }
786 787
            break;
        case 1:
788 789
            if( i_author_sorted != 1 )
            {
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
790
                playlist_SortAuthor( p_playlist, ORDER_NORMAL );
791 792 793 794
                i_author_sorted = 1;
            }
            else
            {
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
795
                playlist_SortAuthor( p_playlist, ORDER_REVERSE );
796 797
                i_author_sorted = -1;
            }
798 799
            break;
        case 2:
800 801 802 803 804 805 806 807 808 809 810 811
            if( i_duration_sorted != 1 )
            {
                playlist_Sort( p_playlist, SORT_DURATION, ORDER_NORMAL );
                i_duration_sorted = 1;
            }
            else
            {
                playlist_Sort( p_playlist, SORT_DURATION, ORDER_REVERSE );
                i_duration_sorted = -1;
            }
            break;
        case 3:
812 813
            if( i_group_sorted != 1 )
            {
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
814
                playlist_SortGroup( p_playlist, ORDER_NORMAL );
815 816 817 818
                i_group_sorted = 1;
            }
            else
            {
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
819
                playlist_SortGroup( p_playlist, ORDER_REVERSE );
820 821
                i_group_sorted = -1;
            }
822 823 824 825 826 827 828 829 830
            break;
        default:
            break;
    }
    vlc_object_release( p_playlist );

    Rebuild();
}

831 832 833
/**********************************************************************
 * Search functions
 **********************************************************************/
Clément Stenac's avatar
Clément Stenac committed
834 835
void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
{
Clément Stenac's avatar
Clément Stenac committed
836
   search_button->SetDefault();
Clément Stenac's avatar
Clément Stenac committed
837 838 839 840
}

void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
{
Gildas Bazin's avatar
 
Gildas Bazin committed
841
    wxString search_string = search_text->GetValue();
Clément Stenac's avatar
Clément Stenac committed
842

Clément Stenac's avatar
Clément Stenac committed
843
    bool b_ok = false;
Clément Stenac's avatar
Clément Stenac committed
844
    int i_current;
Clément Stenac's avatar
Clément Stenac committed
845
    int i_first = 0 ;
Clément Stenac's avatar
Clément Stenac committed
846 847
    int i_item = -1;

Gildas Bazin's avatar
 
Gildas Bazin committed
848
    for( i_current = 0; i_current < listview->GetItemCount(); i_current++ )
Clément Stenac's avatar
Clément Stenac committed
849
    {
Gildas Bazin's avatar
 
Gildas Bazin committed
850 851
        if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED ) ==
              wxLIST_STATE_SELECTED )
Clément Stenac's avatar
Clément Stenac committed
852 853 854 855
        {
            i_first = i_current;
            break;
        }
Clément Stenac's avatar
Clément Stenac committed
856 857
    }

Clément Stenac's avatar
Clément Stenac committed
858 859 860 861 862
    if( i_first == listview->GetItemCount() )
    {
        i_first = -1;
    }

Gildas Bazin's avatar
 
Gildas Bazin committed
863 864
    for( i_current = i_first + 1; i_current < listview->GetItemCount();
         i_current++ )
Clément Stenac's avatar
Clément Stenac committed
865
    {
Clément Stenac's avatar
Clément Stenac committed
866 867 868 869 870 871
        wxListItem listitem;
        listitem.SetId( i_current );
        listview->GetItem( listitem );
        if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
        {
            i_item = i_current;
Clément Stenac's avatar
Clément Stenac committed
872
            b_ok = true;
Clément Stenac's avatar
Clément Stenac committed
873 874
            break;
        }
875 876 877 878 879 880 881 882
        listitem.SetColumn( 1 );
        listview->GetItem( listitem );
        if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
        {
            i_item = i_current;
            b_ok = true;
            break;
        }
Clément Stenac's avatar
Clément Stenac committed
883
    }
Clément Stenac's avatar
Clément Stenac committed
884 885 886 887 888 889 890 891 892 893 894 895 896 897
    if( !b_ok )
    {
        for( i_current = -1 ; i_current < i_first - 1;
             i_current++ )
        {
            wxListItem listitem;
            listitem.SetId( i_current );
            listview->GetItem( listitem );
            if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
            {
                i_item = i_current;
                b_ok = true;
                break;
            }
898 899 900 901 902 903 904 905
            listitem.SetColumn( 1 );
            listview->GetItem( listitem );
            if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
            {
                i_item = i_current;
                b_ok = true;
                break;
            }
Clément Stenac's avatar
Clément Stenac committed
906 907
        }
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
908

909 910 911 912
    if( i_item < 0 || i_item >= listview->GetItemCount() )
    {
        return;
    }
Gildas Bazin's avatar
 
Gildas Bazin committed
913

Clément Stenac's avatar
Clément Stenac committed
914 915 916 917
    for( long item = 0; item < listview->GetItemCount(); item++ )
    {
        listview->Select( item, FALSE );
    }
918

Clément Stenac's avatar
Clément Stenac committed
919 920 921 922 923 924 925
    wxListItem listitem;
    listitem.SetId(i_item);
    listitem.m_state = wxLIST_STATE_SELECTED;
    listview->Select( i_item, TRUE );
    listview->Focus( i_item );
}

926 927 928
/**********************************************************************
 * Selection functions
 **********************************************************************/
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
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();
}

Clément Stenac's avatar
Clément Stenac committed
951 952 953 954 955 956 957 958 959 960 961 962 963 964
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 ) )
        {
965
            /*XXX*/
Clément Stenac's avatar
Clément Stenac committed
966
            playlist_Enable( p_playlist, item );
967
            UpdateItem( item );
Clément Stenac's avatar
Clément Stenac committed
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
        }
    }
    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