]> git.sesse.net Git - vlc/blob - modules/gui/skins2/vars/playtree.cpp
* Playtree start. Basic functionalities work. Still needs a lot of
[vlc] / modules / gui / skins2 / vars / playtree.cpp
1 /*****************************************************************************
2  * playtree.cpp
3  *****************************************************************************
4  * Copyright (C) 2005 VideoLAN
5  * $Id: playlist.hpp 8659 2004-09-07 21:16:49Z gbazin $
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 Playtree::Playtree( intf_thread_t *pIntf )
32          :VarTree( pIntf, /*m_parent = */NULL )
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     // TODO
61     notify();
62 }
63
64 void Playtree::action( VarTree *pItem )
65 {
66     vlc_mutex_lock( &m_pPlaylist->object_lock );
67     VarTree::Iterator it;
68     if( pItem->size() )
69     {
70         it = pItem->begin();
71         while( it->size() ) it = it->begin();
72     }
73     playlist_Control( m_pPlaylist,
74                       PLAYLIST_VIEWPLAY,
75                       m_pPlaylist->status.i_view,
76                       pItem->size()
77                           ? (playlist_item_t *)pItem->m_pData
78                           : (playlist_item_t *)pItem->parent()->m_pData,
79                       pItem->size()
80                           ? (playlist_item_t *)it->m_pData
81                           : (playlist_item_t *)pItem->m_pData
82                     );
83     vlc_mutex_unlock( &m_pPlaylist->object_lock );
84 }
85
86 void Playtree::onChange()
87 {
88     /* FIXME : updateTree could be a nice idea so we don't have to
89      * start from scratch each time the playlist changes */
90     buildTree();
91     notify();
92 }
93
94 void Playtree::buildNode( playlist_item_t *p_node, VarTree &m_pNode )
95 {
96     fprintf( stderr, "\e[32;1mPlaytree::buildNode\e[0m\n");
97     for( int i = 0; i < p_node->i_children; i++ )
98     {
99         fprintf( stderr, "\e[33;1m"__FILE__ "%d :\e[0m adding playtree item : %s\n", __LINE__, p_node->pp_children[i]->input.psz_name );
100         UString *pName = new UString( getIntf(), p_node->pp_children[i]->input.psz_name );
101         m_pNode.add( UStringPtr( pName ),
102                      false,
103                      m_pPlaylist->status.p_item == p_node->pp_children[i],
104                      true,
105                      p_node->pp_children[i] );
106         if( p_node->pp_children[i]->i_children )
107         {
108             buildNode( p_node->pp_children[i], m_pNode.back() );
109         }
110     }
111 }
112
113 void Playtree::buildTree()
114 {
115     clear();
116     vlc_mutex_lock( &m_pPlaylist->object_lock );
117
118     playlist_view_t *p_view;
119     p_view = playlist_ViewFind( m_pPlaylist, VIEW_CATEGORY );
120     /* TODO : let the user chose the view type */
121
122     clear();
123     /* XXX : do we need Playlist::clear() instead of VarTree::clear() ? */
124
125     /* Set the root's name */
126     UString *pName = new UString( getIntf(), p_view->p_root->input.psz_name );
127     m_cString = UStringPtr( pName );
128
129     buildNode( p_view->p_root, *this );
130
131     vlc_mutex_unlock( &m_pPlaylist->object_lock );
132     checkParents( NULL );
133 }