1 /*****************************************************************************
2 * playlist_item.cpp : Manage playlist item
3 ****************************************************************************
4 * Copyright © 2006-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
32 #include "playlist_item.hpp"
33 #include <vlc_intf_strings.h>
37 /*************************************************************************
38 * Playlist item implementation
39 *************************************************************************/
42 Playlist item is just a wrapper, an abstraction of the playlist_item
43 in order to be managed by PLModel
45 PLItem have a parent, and id and a input Id
49 void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent )
51 parentItem = parent; /* Can be NULL, but only for the rootItem */
52 i_id = _playlist_item->i_id; /* Playlist item specific id */
53 p_input = _playlist_item->p_input;
54 vlc_gc_incref( p_input );
60 Call the above function init
62 PLItem::PLItem( playlist_item_t *p_item, PLItem *parent )
64 init( p_item, parent );
67 PLItem::PLItem( playlist_item_t * p_item )
74 vlc_gc_decref( p_input );
75 qDeleteAll( children );
79 /* So far signal is always true.
80 Using signal false would not call PLModel... Why ?
82 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
84 children.insert( i_pos, item );
87 void PLItem::removeChild( PLItem *item )
89 children.removeOne( item );
93 void PLItem::removeChildren()
95 qDeleteAll( children );
99 void PLItem::takeChildAt( int index )
101 PLItem *child = children[index];
102 child->parentItem = NULL;
103 children.removeAt( index );
106 /* This function is used to get one's parent's row number in the model */
107 int PLItem::row() const
110 return parentItem->children.indexOf( const_cast<PLItem*>(this) );
111 // We don't ever inherit PLItem, yet, but it might come :D
115 bool PLItem::operator< ( PLItem& other )
117 PLItem *item1 = this;
118 while( item1->parentItem )
120 PLItem *item2 = &other;
121 while( item2->parentItem )
123 if( item1 == item2->parentItem ) return true;
124 if( item2 == item1->parentItem ) return false;
125 if( item1->parentItem == item2->parentItem )
126 return item1->parentItem->children.indexOf( item1 ) <
127 item1->parentItem->children.indexOf( item2 );
128 item2 = item2->parentItem;
130 item1 = item1->parentItem;