1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2005 VideoLAN
7 * Authors: Antoine Cellerier <dionoea@videolan.org>
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.
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.
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 *****************************************************************************/
29 #include "variable.hpp"
30 #include "observer.hpp"
31 #include "ustring.hpp"
32 #include "var_percent.hpp"
34 /// Description of an update to the tree
35 typedef struct tree_update
44 class VarTree: public Variable, public Subject<VarTree, tree_update*>
47 VarTree( intf_thread_t *pIntf );
49 VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
50 const UStringPtr &rcString, bool selected, bool playing,
51 bool expanded, void *pData );
55 /// Get the variable type
56 virtual const string &getType() const { return m_type; }
58 /// Add a pointer on string in the children's list
59 virtual void add( int id, const UStringPtr &rcString, bool selected,
60 bool playing, bool expanded, void *pData );
62 /// Remove the selected item from the children's list
63 virtual void delSelected();
65 /// Remove all elements from the children's list
68 /// \todo Use accessors for these fields ?
76 /// Get the number of children
77 int size() const { return m_children.size(); }
80 typedef list<VarTree>::iterator Iterator;
81 typedef list<VarTree>::const_iterator ConstIterator;
83 /// Begining of the children's list
84 Iterator begin() { return m_children.begin(); }
85 ConstIterator begin() const { return m_children.begin(); }
87 /// End of children's list
88 Iterator end() { return m_children.end(); }
89 ConstIterator end() const { return m_children.end(); }
91 /// Back of children's list
92 VarTree &back() { return m_children.back(); }
94 /// Return an iterator on the n'th element of the children's list
95 Iterator operator[]( int n );
96 ConstIterator operator[]( int n ) const;
99 VarTree *parent() { return m_pParent; }
100 void VarTree::checkParents( VarTree *pParent );
107 VarTree *parent = this;
108 while( parent->parent() != NULL )
109 parent = parent->parent();
113 /// Get depth (root depth is 0)
116 VarTree *parent = this;
118 while( ( parent = parent->parent() ) != NULL )
123 /// Execute the action associated to this item
124 virtual void action( VarTree *pItem ) {}
126 /// Get a reference on the position variable
127 VarPercent &getPositionVar() const
128 { return *((VarPercent*)m_cPosition.get()); }
130 /// Get a counted pointer on the position variable
131 const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
133 /// Count the number of items that should be displayed if the playlist window wasn't limited
136 /// Return iterator to the n'th visible item
137 Iterator getVisibleItem( int n );
139 /// Given an iterator to a visible item, return the next visible item
140 Iterator getNextVisibleItem( Iterator it );
142 /// Given an iterator to an item, return the next item
143 Iterator getNextItem( Iterator it );
145 /// Find a children node with the given id
146 Iterator findById( int id );
148 /// Ensure an item is expanded
149 void ensureExpanded( VarTree::Iterator );
153 list<VarTree> m_children;
155 /// Pointer to parent node
159 static const string m_type;
161 /// Position variable
162 VariablePtr m_cPosition;