1 /*****************************************************************************
2 * infopanels.cpp : Panels for the information dialogs
3 ****************************************************************************
4 * Copyright (C) 2006-2007 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 *****************************************************************************/
26 #include "components/infopanels.hpp"
28 #include <QTreeWidget>
30 #include <QPushButton>
31 #include <QHeaderView>
33 #include <QGridLayout>
39 /************************************************************************
41 ************************************************************************/
43 /* First Panel - Meta Info */
45 MetaPanel::MetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
46 QWidget( parent ), p_intf( _p_intf )
49 QGridLayout *l = new QGridLayout( this );
52 #define ADD_META( string, widget ) { \
53 l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
54 widget = new QLineEdit; \
55 l->addWidget( widget, line, 1, 1, 9 ); \
58 ADD_META( VLC_META_TITLE, title_text ); /* OK */
59 ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
60 ADD_META( VLC_META_COLLECTION, collection_text ); /* OK */
62 /* Genre Name */ /* FIXME List id3genres.h is not includable yet ? */
63 genre_text = new QLineEdit;
64 l->addWidget( new QLabel( qtr( VLC_META_GENRE ) + " :" ), line, 0 );
65 l->addWidget( genre_text, line, 1, 1, 6 );
66 /* Date (Should be in years) */
67 date_text = new QSpinBox; setSpinBounds( date_text );
68 l->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 7 );
69 l->addWidget( date_text, line, 8, 1, 2 );
72 /* Number and Rating */
73 l->addWidget( new QLabel( qtr( "Track number/Position" ) + " :" ),
75 seqnum_text = new QSpinBox; setSpinBounds( seqnum_text );
76 l->addWidget( seqnum_text, line, 1, 1, 4 );
78 l->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 5 );
79 rating_text = new QSpinBox; setSpinBounds( rating_text) ;
80 l->addWidget( rating_text, line, 6, 1, 4 );
83 ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
85 /* Language and settings */
86 l->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 0 );
87 language_text = new QLineEdit;
88 l->addWidget( language_text, line, 1, 1, 4 );
89 l->addWidget( new QLabel( qtr( VLC_META_SETTING ) + " :" ), line, 5 );
90 setting_text = new QLineEdit;
91 l->addWidget( setting_text, line, 6, 1, 4 );
95 // ADD_META( VLC_META_URL, setting_text );
96 art_cover = new QLabel( "" );
97 art_cover->setMinimumHeight( 128 );
98 art_cover->setMinimumWidth( 128 );
99 art_cover->setMaximumHeight( 128 );
100 art_cover->setMaximumWidth( 128 );
101 art_cover->setScaledContents( true );
102 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
104 l->addWidget( art_cover, line, 8, 4, 2 );
106 #define ADD_META_B( string, widget ) { \
107 l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
108 widget = new QLineEdit; \
109 l->addWidget( widget, line, 1, 1, 7 ); \
112 ADD_META_B( VLC_META_COPYRIGHT, copyright_text );
113 ADD_META_B( VLC_META_PUBLISHER, publisher_text );
115 ADD_META_B( VLC_META_ENCODED_BY, publisher_text );
116 ADD_META_B( VLC_META_DESCRIPTION, description_text ); // Comment Two lines?
118 /* ADD_META( TRACKID) DO NOT SHOW it */
119 /* ADD_URI - DO not show it, done outside */
124 // CONNECT( model, artSet( QString ) , this, setArt( QString ) );
127 MetaPanel::~MetaPanel()
131 void MetaPanel::saveMeta()
133 playlist_t *p_playlist;
135 meta_export_t p_export;
136 p_export.p_item = p_input;
138 if( p_input == NULL )
141 /* we can write meta data only in a file */
142 if( ( p_input->i_type == ITEM_TYPE_AFILE ) || \
143 ( p_input->i_type == ITEM_TYPE_VFILE ) )
144 /* some audio files are detected as video files */
146 char *psz_uri = p_input->psz_uri;
147 if( !strncmp( psz_uri, "file://", 7 ) )
148 psz_uri += 7; /* strlen("file://") = 7 */
150 p_export.psz_file = strndup( psz_uri, PATH_MAX );
155 /* now we read the modified meta data */
156 free( p_input->p_meta->psz_artist );
157 p_input->p_meta->psz_artist = strdup( artist_text->text().toUtf8() );
158 free( p_input->p_meta->psz_album );
159 p_input->p_meta->psz_album = strdup( collection_text->text().toUtf8() );
160 free( p_input->p_meta->psz_genre );
161 p_input->p_meta->psz_genre = strdup( genre_text->text().toUtf8() );
162 free( p_input->p_meta->psz_date );
163 p_input->p_meta->psz_date = (char*) malloc(5);
164 snprintf( p_input->p_meta->psz_date, 5, "%d", date_text->value() );
165 free( p_input->p_meta->psz_tracknum );
166 p_input->p_meta->psz_tracknum = (char*) malloc(5);
167 snprintf( p_input->p_meta->psz_tracknum, 5, "%d", seqnum_text->value() );
168 free( p_input->p_meta->psz_title );
169 p_input->p_meta->psz_title = strdup( title_text->text().toUtf8() );
171 p_playlist = pl_Yield( p_intf );
174 p_playlist->p_private = &p_export;
176 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
178 module_Unneed( p_playlist, p_mod );
180 pl_Release( p_playlist );
183 void MetaPanel::update( input_item_t *p_item )
186 #define UPDATE_META( meta, widget ) { \
187 psz_meta = p_item->p_meta->psz_##meta; \
188 if( !EMPTY_STR( psz_meta ) ) \
189 widget->setText( qfu( psz_meta ) ); \
191 widget->setText( "" ); }
193 #define UPDATE_META_INT( meta, widget ) { \
194 psz_meta = p_item->p_meta->psz_##meta; \
195 if( !EMPTY_STR( psz_meta ) ) \
196 widget->setValue( atoi( psz_meta ) ); }
199 psz_meta = p_item->p_meta->psz_title;
200 if( !EMPTY_STR( psz_meta ) )
201 title_text->setText( qfu( psz_meta ) );
202 else if( !EMPTY_STR( p_item->psz_name ) )
203 title_text->setText( qfu( p_item->psz_name ) );
204 else title_text->setText( "" );
207 psz_meta = p_item->p_meta->psz_url;
208 if( !EMPTY_STR( psz_meta ) )
209 emit uriSet( QString( psz_meta ) );
210 else if( !EMPTY_STR( p_item->psz_uri ) )
211 emit uriSet( QString( p_item->psz_uri ) );
213 /* Other classic though */
214 UPDATE_META( artist, artist_text );
215 UPDATE_META( genre, genre_text );
216 UPDATE_META( copyright, copyright_text );
217 UPDATE_META( album, collection_text );
218 UPDATE_META( description, description_text );
219 UPDATE_META( language, language_text );
220 UPDATE_META( nowplaying, nowplaying_text );
221 UPDATE_META( publisher, publisher_text );
222 UPDATE_META( setting, setting_text );
224 UPDATE_META_INT( date, date_text );
225 UPDATE_META_INT( tracknum, seqnum_text );
226 UPDATE_META_INT( rating, rating_text );
229 psz_meta = p_item->p_meta->psz_arturl;
230 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
232 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
233 art_cover->setPixmap( QPixmap( artUrl ) );
236 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
239 void MetaPanel::clear(){}
241 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
242 QWidget( parent ), p_intf( _p_intf )
244 QGridLayout *layout = new QGridLayout(this);
245 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
246 " are shown in this list.\n" ) );
247 topLabel->setWordWrap( true );
248 layout->addWidget( topLabel, 0, 0 );
250 extraMetaTree = new QTreeWidget( this );
251 extraMetaTree->setAlternatingRowColors( true );
252 extraMetaTree->setColumnCount( 2 );
254 extraMetaTree->header()->hide();
255 /* QStringList *treeHeaders;
256 treeHeaders << qtr( "Test1" ) << qtr( "Test2" ); */
258 layout->addWidget( extraMetaTree, 1, 0 );
261 void ExtraMetaPanel::update( input_item_t *p_item )
263 vlc_meta_t *p_meta = p_item->p_meta;
264 QStringList tempItem;
266 QList<QTreeWidgetItem *> items;
267 for (int i = 0; i < p_meta->i_extra; i++ )
269 tempItem.append( qfu( p_meta->ppsz_extra_name[i] ) + " : ");
270 tempItem.append( qfu( p_meta->ppsz_extra_value[i] ) );
271 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
273 extraMetaTree->addTopLevelItems( items );
276 void ExtraMetaPanel::clear(){}
278 /* Second Panel - Stats */
280 InputStatsPanel::InputStatsPanel( QWidget *parent, intf_thread_t *_p_intf ) :
281 QWidget( parent ), p_intf( _p_intf )
283 QGridLayout *layout = new QGridLayout(this);
284 StatsTree = new QTreeWidget(this);
285 QList<QTreeWidgetItem *> items;
286 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
287 " media or stream.\n Played and streamed info are shown." ) );
288 topLabel->setWordWrap( true );
289 layout->addWidget( topLabel, 0, 0 );
291 StatsTree->setColumnCount( 3 );
292 StatsTree->header()->hide();
294 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
296 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
297 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
299 #define CREATE_CATEGORY( catName, itemText ) { \
300 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
301 catName->setExpanded( true ); \
302 StatsTree->addTopLevelItem( catName ); }
304 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
305 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
306 catName->addChild( itemName ); }
308 /* Create the main categories */
309 CREATE_CATEGORY( input, qtr("Input") );
310 CREATE_CATEGORY( video, qtr("Video") );
311 CREATE_CATEGORY( streaming, qtr("Streaming") );
312 CREATE_CATEGORY( audio, qtr("Audio") );
314 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
316 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
317 "0", input, "kb/s" );
318 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
319 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
320 "0", input, "kb/s" );
322 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
324 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
326 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
329 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
330 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
331 "0", streaming, "kB" );
332 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
333 "0", streaming, "kb/s" );
335 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
337 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
339 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
341 input->setExpanded( true );
342 video->setExpanded( true );
343 streaming->setExpanded( true );
344 audio->setExpanded( true );
346 StatsTree->resizeColumnToContents( 0 );
347 StatsTree->setColumnWidth( 1 , 100 );
349 layout->addWidget(StatsTree, 1, 0 );
352 InputStatsPanel::~InputStatsPanel()
356 void InputStatsPanel::update( input_item_t *p_item )
358 vlc_mutex_lock( &p_item->p_stats->lock );
360 #define UPDATE( widget, format, calc... ) \
361 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
363 UPDATE( read_media_stat, "%8.0f",
364 (float)(p_item->p_stats->i_read_bytes)/1000);
365 UPDATE( input_bitrate_stat, "%6.0f",
366 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
367 UPDATE( demuxed_stat, "%8.0f",
368 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
369 UPDATE( stream_bitrate_stat, "%6.0f",
370 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
373 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
374 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
375 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
378 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
379 UPDATE( send_bytes_stat, "%8.0f",
380 (float)(p_item->p_stats->i_sent_bytes)/1000 );
381 UPDATE( send_bitrate_stat, "%6.0f",
382 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
385 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
386 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
387 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
389 vlc_mutex_unlock(& p_item->p_stats->lock );
392 void InputStatsPanel::clear()
396 /* Third panel - Stream info */
398 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
399 QWidget( parent ), p_intf( _p_intf )
401 QGridLayout *layout = new QGridLayout(this);
402 InfoTree = new QTreeWidget(this);
403 QList<QTreeWidgetItem *> items;
405 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
406 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
408 topLabel->setWordWrap( true );
409 layout->addWidget( topLabel, 0, 0 );
411 InfoTree->setColumnCount( 1 );
412 InfoTree->header()->hide();
413 layout->addWidget(InfoTree, 1, 0 );
416 InfoPanel::~InfoPanel()
420 void InfoPanel::update( input_item_t *p_item)
423 QTreeWidgetItem *current_item = NULL;
424 QTreeWidgetItem *child_item = NULL;
426 for( int i = 0; i< p_item->i_categories ; i++)
428 current_item = new QTreeWidgetItem();
429 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
430 InfoTree->addTopLevelItem( current_item );
432 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
434 child_item = new QTreeWidgetItem ();
435 child_item->setText( 0,
436 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
438 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
440 current_item->addChild(child_item);
442 InfoTree->setItemExpanded( current_item, true);
446 void InfoPanel::clear()