]> git.sesse.net Git - vlc/blob - modules/gui/skins2/vars/playlist.cpp
80d77d78096018f4df4bce5d65583eeebffc03dc
[vlc] / modules / gui / skins2 / vars / playlist.cpp
1 /*****************************************************************************
2  * playlist.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <vlc/vlc.h>
25
26 #include "playlist.hpp"
27 #include "../utils/ustring.hpp"
28
29 Playlist::Playlist( intf_thread_t *pIntf ): VarList( pIntf )
30 {
31     // Get the playlist VLC object
32     m_pPlaylist = pIntf->p_sys->p_playlist;
33
34     buildList();
35 }
36
37
38 Playlist::~Playlist()
39 {
40 }
41
42
43 void Playlist::delSelected()
44 {
45     // Remove the items from the VLC playlist
46     int index = 0;
47     ConstIterator it;
48     for( it = begin(); it != end(); it++ )
49     {
50         if( (*it).m_selected )
51         {
52             playlist_item_t *p_item = playlist_LockItemGetByPos( m_pPlaylist,
53                                                                  index );
54             playlist_LockDelete( m_pPlaylist, p_item->input.i_id );
55         }
56         else
57         {
58             index++;
59         }
60     }
61
62     notify();
63 }
64
65
66 void Playlist::action( Elem_t *pItem )
67 {
68     // Find the index of the item
69     int index = 0;
70     ConstIterator it;
71     for( it = begin(); it != end(); it++ )
72     {
73         if( &*it == pItem ) break;
74         index++;
75     }
76     // Item found ?
77     if( index < size() )
78     {
79         playlist_Goto( m_pPlaylist, index );
80     }
81 }
82
83
84 void Playlist::onChange()
85 {
86     buildList();
87     notify();
88 }
89
90
91 void Playlist::buildList()
92 {
93     clear();
94
95     vlc_mutex_lock( &m_pPlaylist->object_lock );
96     for( int i = 0; i < m_pPlaylist->i_size; i++ )
97     {
98         // Get the name of the playlist item
99         UString *pName =
100             new UString( getIntf(), m_pPlaylist->pp_items[i]->input.psz_name );
101         // Is it the played stream ?
102         bool playing = (i == m_pPlaylist->i_index );
103         // Add the item in the list
104         m_list.push_back( Elem_t( UStringPtr( pName ), false, playing ) );
105     }
106     vlc_mutex_unlock( &m_pPlaylist->object_lock );
107 }
108