1 /*****************************************************************************
2 * playlist_item.cpp : Manage playlist item
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
31 #include "components/playlist/playlist_model.hpp"
32 #include "dialogs/mediainfo.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 main one */
61 if( parentItem == NULL )
63 i_showflags = config_GetInt( model->p_intf, "qt-pl-showflags" );
64 updateColumnHeaders();
68 i_showflags = parentItem->i_showflags;
69 //Add empty string and update() handles data appending
70 item_col_strings.append( "" );
72 msg_Dbg( model->p_intf, "PLItem created of type: %i", model->i_depth );
77 Call the above function init
78 So far the first constructor isn't used...
80 PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
82 init( _i_id, _i_input_id, parent, m );
85 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
87 init( p_item->i_id, p_item->p_input->i_id, parent, m );
92 qDeleteAll( children );
97 void PLItem::updateColumnHeaders()
99 item_col_strings.clear();
101 if( model->i_depth == 1 ) /* Selector Panel */
103 item_col_strings.append( "" );
107 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index *= 2 )
109 if( i_showflags & i_index )
113 case VLC_META_ENGINE_ARTIST:
114 item_col_strings.append( qtr( VLC_META_ARTIST ) );
116 case VLC_META_ENGINE_TITLE:
117 item_col_strings.append( qtr( VLC_META_TITLE ) );
119 case VLC_META_ENGINE_DESCRIPTION:
120 item_col_strings.append( qtr( VLC_META_DESCRIPTION ) );
122 case VLC_META_ENGINE_DURATION:
123 item_col_strings.append( qtr( "Duration" ) );
125 case VLC_META_ENGINE_GENRE:
126 item_col_strings.append( qtr( VLC_META_GENRE ) );
128 case VLC_META_ENGINE_COLLECTION:
129 item_col_strings.append( qtr( VLC_META_COLLECTION ) );
131 case VLC_META_ENGINE_SEQ_NUM:
132 item_col_strings.append( qtr( VLC_META_SEQ_NUM ) );
134 case VLC_META_ENGINE_RATING:
135 item_col_strings.append( qtr( VLC_META_RATING ) );
144 /* So far signal is always true.
145 Using signal false would not call PLModel... Why ?
147 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
150 model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
151 children.insert( i_pos, item );
153 model->endInsertRows();
156 void PLItem::remove( PLItem *removed )
158 if( model->i_depth == DEPTH_SEL || parentItem )
160 int i_index = parentItem->children.indexOf( removed );
161 model->beginRemoveRows( model->index( parentItem, 0 ),
163 parentItem->children.removeAt( i_index );
164 model->endRemoveRows();
168 /* This function is used to get one's parent's row number in the model */
169 int PLItem::row() const
172 return parentItem->children.indexOf( const_cast<PLItem*>(this) );
173 // We don't ever inherit PLItem, yet, but it might come :D
177 /* update the PL Item, get the good names and so on */
178 void PLItem::update( playlist_item_t *p_item, bool iscurrent )
180 char psz_duration[MSTRTIME_MAX_SIZE];
183 assert( p_item->p_input->i_id == i_input_id );
185 i_type = p_item->p_input->i_type;
186 b_current = iscurrent;
188 item_col_strings.clear();
190 if( model->i_depth == 1 ) /* Selector Panel */
192 item_col_strings.append( qfu( p_item->p_input->psz_name ) );
196 #define ADD_META( item, meta ) \
197 psz_meta = input_item_Get ## meta ( item->p_input ); \
198 item_col_strings.append( qfu( psz_meta ) ); \
201 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index *= 2 )
203 if( parentItem->i_showflags & i_index )
207 case VLC_META_ENGINE_ARTIST:
208 ADD_META( p_item, Artist );
210 case VLC_META_ENGINE_TITLE:
212 psz_title = input_item_GetTitle( p_item->p_input );
215 ADD_META( p_item, Title );
220 psz_title = input_item_GetName( p_item->p_input );
223 item_col_strings.append( qfu( psz_title ) );
228 case VLC_META_ENGINE_DESCRIPTION:
229 ADD_META( p_item, Description );
231 case VLC_META_ENGINE_DURATION:
232 secstotimestr( psz_duration,
233 input_item_GetDuration( p_item->p_input ) / 1000000 );
234 item_col_strings.append( QString( psz_duration ) );
236 case VLC_META_ENGINE_GENRE:
237 ADD_META( p_item, Genre );
239 case VLC_META_ENGINE_COLLECTION:
240 ADD_META( p_item, Album );
242 case VLC_META_ENGINE_SEQ_NUM:
243 ADD_META( p_item, TrackNum );
245 case VLC_META_ENGINE_RATING:
246 ADD_META( p_item, Rating );