1 /*****************************************************************************
2 * playlist_item.cpp : Manage playlist item
3 ****************************************************************************
4 * Copyright © 2006-2011 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_input_item.h>
35 /*************************************************************************
36 * Playlist item implementation
37 *************************************************************************/
39 void AbstractPLItem::clearChildren()
41 qDeleteAll( children );
45 void AbstractPLItem::removeChild( AbstractPLItem *item )
47 children.removeOne( item );
52 Playlist item is just a wrapper, an abstraction of the playlist_item
53 in order to be managed by PLModel
55 PLItem have a parent, and id and a input Id
58 void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent )
60 parentItem = parent; /* Can be NULL, but only for the rootItem */
61 i_playlist_id = _playlist_item->i_id; /* Playlist item specific id */
62 p_input = _playlist_item->p_input;
63 vlc_gc_incref( p_input );
68 Call the above function init
70 PLItem::PLItem( playlist_item_t *p_item, PLItem *parent )
72 init( p_item, parent );
75 PLItem::PLItem( playlist_item_t * p_item )
82 vlc_gc_decref( p_input );
83 qDeleteAll( children );
87 int PLItem::id( int type )
92 return inputItem()->i_id;
102 void PLItem::takeChildAt( int index )
104 AbstractPLItem *child = children[index];
105 child->parentItem = NULL;
106 children.removeAt( index );
109 /* This function is used to get one's parent's row number in the model */
113 return parentItem->indexOf( this );
117 bool PLItem::operator< ( AbstractPLItem& other )
119 AbstractPLItem *item1 = this;
120 while( item1->parentItem )
122 AbstractPLItem *item2 = &other;
123 while( item2->parentItem )
125 if( item1 == item2->parentItem ) return true;
126 if( item2 == item1->parentItem ) return false;
127 if( item1->parentItem == item2->parentItem )
128 return item1->parentItem->indexOf( item1 ) <
129 item1->parentItem->indexOf( item2 );
130 item2 = item2->parentItem;
132 item1 = item1->parentItem;
137 QUrl PLItem::getURI() const
140 vlc_mutex_lock( &p_input->lock );
141 uri = QString( p_input->psz_uri );
142 vlc_mutex_unlock( &p_input->lock );
146 QString PLItem::getTitle() const
149 char *fb_name = input_item_GetTitle( p_input );
150 if( EMPTY_STR( fb_name ) )
153 fb_name = input_item_GetName( p_input );
155 title = qfu(fb_name);