]> git.sesse.net Git - vlc/blob - modules/gui/skins2/vars/playtree.cpp
Remove useless playtree.* commands
[vlc] / modules / gui / skins2 / vars / playtree.cpp
1 /*****************************************************************************
2  * playtree.cpp
3  *****************************************************************************
4  * Copyright (C) 2005 VideoLAN
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include <vlc/vlc.h>
25
26 #include "playtree.hpp"
27 #include "../utils/ustring.hpp"
28
29 #include "charset.h"
30
31
32 Playtree::Playtree( intf_thread_t *pIntf ): VarTree( pIntf )
33 {
34     // Get the VLC playlist object
35     m_pPlaylist = pIntf->p_sys->p_playlist;
36
37     // Try to guess the current charset
38     char *pCharset;
39     vlc_current_charset( &pCharset );
40     iconvHandle = vlc_iconv_open( "UTF-8", pCharset );
41     msg_Dbg( pIntf, "Using character encoding: %s", pCharset );
42     free( pCharset );
43
44     if( iconvHandle == (vlc_iconv_t) - 1 )
45     {
46         msg_Warn( pIntf, "Unable to do requested conversion" );
47     }
48
49     buildTree();
50 }
51
52 Playtree::~Playtree()
53 {
54     if( iconvHandle != (vlc_iconv_t) - 1 ) vlc_iconv_close( iconvHandle );
55     // TODO : check that everything is destroyed
56 }
57
58 void Playtree::delSelected()
59 {
60     Iterator it;
61     for (it = begin(); it != end() ; it++ )
62     {
63         if( (*it).m_selected )
64         {
65             playlist_item_t *p_item = (playlist_item_t *)(it->m_pData);
66             if( p_item->i_children == -1 )
67             {
68                 playlist_LockDelete( getIntf()->p_sys->p_playlist,
69                                      p_item->input.i_id );
70             }
71             else
72             {
73                 vlc_mutex_lock( &getIntf()->p_sys->p_playlist->object_lock );
74                 playlist_NodeDelete( getIntf()->p_sys->p_playlist, p_item,
75                                      VLC_TRUE, VLC_FALSE );
76                 vlc_mutex_unlock( &getIntf()->p_sys->p_playlist->object_lock );
77             }
78         }
79     }
80     notify();
81 }
82
83 void Playtree::action( VarTree *pItem )
84 {
85     vlc_mutex_lock( &m_pPlaylist->object_lock );
86     VarTree::Iterator it;
87     if( pItem->size() )
88     {
89         it = pItem->begin();
90         while( it->size() ) it = it->begin();
91     }
92     playlist_Control( m_pPlaylist,
93                       PLAYLIST_VIEWPLAY,
94                       m_pPlaylist->status.i_view,
95                       pItem->size()
96                           ? (playlist_item_t *)pItem->m_pData
97                           : (playlist_item_t *)pItem->parent()->m_pData,
98                       pItem->size()
99                           ? (playlist_item_t *)it->m_pData
100                           : (playlist_item_t *)pItem->m_pData
101                     );
102     vlc_mutex_unlock( &m_pPlaylist->object_lock );
103 }
104
105 void Playtree::onChange()
106 {
107     buildTree();
108     notify();
109 }
110
111 void Playtree::onUpdate( int id )
112 {
113     Iterator it = findById( id );
114     if( it != end() )
115     {
116         // Update the item
117         playlist_item_t* pNode = (playlist_item_t*)(it->m_pData);
118         UString *pName = new UString( getIntf(), pNode->input.psz_name );
119         it->m_cString = UStringPtr( pName );
120         it->m_playing = m_pPlaylist->status.p_item == pNode;
121     }
122     else
123     {
124         msg_Warn(getIntf(), "Cannot find node with id %d", id );
125     }
126     // TODO update only the right node
127     notify();
128 }
129
130 void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
131 {
132     for( int i = 0; i < pNode->i_children; i++ )
133     {
134         UString *pName = new UString( getIntf(),
135                                       pNode->pp_children[i]->input.psz_name );
136         rTree.add( pNode->pp_children[i]->input.i_id, UStringPtr( pName ),
137                      false,
138                      m_pPlaylist->status.p_item == pNode->pp_children[i],
139                      true, pNode->pp_children[i] );
140         if( pNode->pp_children[i]->i_children )
141         {
142             buildNode( pNode->pp_children[i], rTree.back() );
143         }
144     }
145 }
146
147 void Playtree::buildTree()
148 {
149     clear();
150     vlc_mutex_lock( &m_pPlaylist->object_lock );
151
152     playlist_view_t *p_view;
153     p_view = playlist_ViewFind( m_pPlaylist, VIEW_CATEGORY );
154     /* TODO : let the user chose the view type */
155
156     clear();
157     /* XXX : do we need Playlist::clear() instead of VarTree::clear() ? */
158
159     /* Set the root's name */
160     UString *pName = new UString( getIntf(), p_view->p_root->input.psz_name );
161     m_cString = UStringPtr( pName );
162
163     buildNode( p_view->p_root, *this );
164
165     vlc_mutex_unlock( &m_pPlaylist->object_lock );
166     checkParents( NULL );
167 }
168