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 "components/playlist/playlist_model.hpp"
33 #include <vlc_intf_strings.h>
35 #include "pixmaps/type_unknown.xpm"
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( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
51 parentItem = parent; /* Can be NULL, but only for the rootItem */
52 i_id = _i_id; /* Playlist item specific id */
53 i_input_id = _i_input_id; /* Identifier of the input */
54 model = m; /* PLModel (QAbsmodel) */
55 i_type = -1; /* Item type - Avoid segfault */
56 b_current = false; /* Is the item the current Item or not */
58 assert( model ); /* We need a model */
60 /* No parent, should be the 2 main ones */
61 if( parentItem == NULL )
63 if( model->i_depth == DEPTH_SEL ) /* Selector Panel */
65 item_col_strings.append( "" );
69 QSettings settings( "vlc", "vlc-qt-interface" );
70 i_showflags = settings.value( "qt-pl-showflags" ).toInt();
71 updateColumnHeaders();
76 i_showflags = parentItem->i_showflags;
77 //Add empty string and update() handles data appending
78 item_col_strings.append( "" );
84 Call the above function init
85 So far the first constructor isn't used...
87 PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
89 init( _i_id, _i_input_id, parent, m );
92 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
94 init( p_item->i_id, p_item->p_input->i_id, parent, m );
99 qDeleteAll( children );
104 void PLItem::updateColumnHeaders()
106 item_col_strings.clear();
108 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index *= 2 )
110 if( i_showflags & i_index )
114 case VLC_META_ENGINE_ARTIST:
115 item_col_strings.append( qtr( VLC_META_ARTIST ) );
117 case VLC_META_ENGINE_TITLE:
118 item_col_strings.append( qtr( VLC_META_TITLE ) );
120 case VLC_META_ENGINE_DESCRIPTION:
121 item_col_strings.append( qtr( VLC_META_DESCRIPTION ) );
123 case VLC_META_ENGINE_DURATION:
124 item_col_strings.append( qtr( "Duration" ) );
126 case VLC_META_ENGINE_GENRE:
127 item_col_strings.append( qtr( VLC_META_GENRE ) );
129 case VLC_META_ENGINE_COLLECTION:
130 item_col_strings.append( qtr( VLC_META_COLLECTION ) );
132 case VLC_META_ENGINE_SEQ_NUM:
133 item_col_strings.append( qtr( VLC_META_SEQ_NUM ) );
135 case VLC_META_ENGINE_RATING:
136 item_col_strings.append( qtr( VLC_META_RATING ) );
145 /* So far signal is always true.
146 Using signal false would not call PLModel... Why ?
148 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
151 model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
152 children.insert( i_pos, item );
154 model->endInsertRows();
157 void PLItem::remove( PLItem *removed )
159 if( model->i_depth == DEPTH_SEL || parentItem )
161 int i_index = parentItem->children.indexOf( removed );
162 model->beginRemoveRows( model->index( parentItem, 0 ),
164 parentItem->children.removeAt( i_index );
165 model->endRemoveRows();
169 /* This function is used to get one's parent's row number in the model */
170 int PLItem::row() const
173 return parentItem->children.indexOf( const_cast<PLItem*>(this) );
174 // We don't ever inherit PLItem, yet, but it might come :D
178 /* update the PL Item, get the good names and so on */
179 /* This function may not be the best way to do it
180 It destroys everything and gets everything again instead of just
181 building the necessary columns.
182 This does extra work if you re-display the same column. Slower...
183 On the other hand, this way saves memory.
184 There must be a more clever way.
186 void PLItem::update( playlist_item_t *p_item, bool iscurrent )
188 char psz_duration[MSTRTIME_MAX_SIZE];
191 assert( p_item->p_input->i_id == i_input_id );
193 /* Useful for the model */
194 i_type = p_item->p_input->i_type;
195 b_current = iscurrent;
197 item_col_strings.clear();
199 if( model->i_depth == 1 ) /* Selector Panel */
201 item_col_strings.append( qfu( p_item->p_input->psz_name ) );
205 #define ADD_META( item, meta ) \
206 psz_meta = input_item_Get ## meta ( item->p_input ); \
207 item_col_strings.append( qfu( psz_meta ) ); \
210 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index *= 2 )
212 if( parentItem->i_showflags & i_index )
216 case VLC_META_ENGINE_ARTIST:
217 ADD_META( p_item, Artist );
219 case VLC_META_ENGINE_TITLE:
221 psz_title = input_item_GetTitle( p_item->p_input );
224 ADD_META( p_item, Title );
229 psz_title = input_item_GetName( p_item->p_input );
232 item_col_strings.append( qfu( psz_title ) );
237 case VLC_META_ENGINE_DESCRIPTION:
238 ADD_META( p_item, Description );
240 case VLC_META_ENGINE_DURATION:
241 secstotimestr( psz_duration,
242 input_item_GetDuration( p_item->p_input ) / 1000000 );
243 item_col_strings.append( QString( psz_duration ) );
245 case VLC_META_ENGINE_GENRE:
246 ADD_META( p_item, Genre );
248 case VLC_META_ENGINE_COLLECTION:
249 ADD_META( p_item, Album );
251 case VLC_META_ENGINE_SEQ_NUM:
252 ADD_META( p_item, TrackNum );
254 case VLC_META_ENGINE_RATING:
255 ADD_META( p_item, Rating );