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 <QStringList>
34 #include <QGridLayout>
40 /************************************************************************
42 ************************************************************************/
45 * First Panel - Meta Info
46 * All the usual MetaData are displayed and can be changed.
48 MetaPanel::MetaPanel( QWidget *parent,
49 intf_thread_t *_p_intf )
50 : QWidget( parent ), p_intf( _p_intf )
52 QGridLayout *l = new QGridLayout( this );
53 int line = 0; /* Counter for GridLayout */
56 #define ADD_META( string, widget ) { \
57 l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
58 widget = new QLineEdit; \
59 l->addWidget( widget, line, 1, 1, 9 ); \
62 /* Title, artist and album*/
63 ADD_META( VLC_META_TITLE, title_text ); /* OK */
64 ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
65 ADD_META( VLC_META_COLLECTION, collection_text ); /* OK */
68 /* FIXME List id3genres.h is not includable yet ? */
69 genre_text = new QLineEdit;
70 l->addWidget( new QLabel( qtr( VLC_META_GENRE ) + " :" ), line, 0 );
71 l->addWidget( genre_text, line, 1, 1, 6 );
73 /* Date (Should be in years) */
74 date_text = new QSpinBox; setSpinBounds( date_text );
75 l->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 7 );
76 l->addWidget( date_text, line, 8, 1, 2 );
79 /* Number and Rating */
80 l->addWidget( new QLabel( qtr( "Track number/Position" ) + " :" ),
82 seqnum_text = new QSpinBox; setSpinBounds( seqnum_text );
83 l->addWidget( seqnum_text, line, 1, 1, 4 );
85 l->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 5 );
86 rating_text = new QSpinBox; setSpinBounds( rating_text) ;
87 l->addWidget( rating_text, line, 6, 1, 4 );
91 ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
93 /* Language and settings */
94 l->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 0 );
95 language_text = new QLineEdit;
96 l->addWidget( language_text, line, 1, 1, 4 );
97 l->addWidget( new QLabel( qtr( VLC_META_SETTING ) + " :" ), line, 5 );
98 setting_text = new QLineEdit;
99 l->addWidget( setting_text, line, 6, 1, 4 );
103 art_cover = new QLabel( "" );
104 art_cover->setMinimumHeight( 128 );
105 art_cover->setMinimumWidth( 128 );
106 art_cover->setMaximumHeight( 128 );
107 art_cover->setMaximumWidth( 128 );
108 art_cover->setScaledContents( true );
109 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
110 l->addWidget( art_cover, line, 8, 4, 2 );
112 #define ADD_META_2( string, widget ) { \
113 l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
114 widget = new QLineEdit; \
115 l->addWidget( widget, line, 1, 1, 7 ); \
118 ADD_META_2( VLC_META_COPYRIGHT, copyright_text );
119 ADD_META_2( VLC_META_PUBLISHER, publisher_text );
121 ADD_META_2( VLC_META_ENCODED_BY, publisher_text );
122 ADD_META_2( VLC_META_DESCRIPTION, description_text );
124 /* ADD_META( TRACKID ) Useless ? */
125 /* ADD_URI - DO not show it, done outside */
131 MetaPanel::~MetaPanel(){}
134 * Save the MetaData, triggered by parent->save Button
136 void MetaPanel::saveMeta()
138 playlist_t *p_playlist;
141 meta_export_t p_export;
142 p_export.p_item = p_input;
144 if( p_input == NULL )
147 /* we can write meta data only in a file */
148 if( ( p_input->i_type == ITEM_TYPE_AFILE ) || \
149 ( p_input->i_type == ITEM_TYPE_VFILE ) )
150 /* some audio files are detected as video files */
152 char *psz_uri = p_input->psz_uri;
153 if( !strncmp( psz_uri, "file://", 7 ) )
154 psz_uri += 7; /* strlen("file://") = 7 */
156 p_export.psz_file = strndup( psz_uri, PATH_MAX );
161 /* now we read the modified meta data */
162 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
163 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
164 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
166 asnprintf( &psz, 5, "%d", date_text->value() );
167 input_item_SetDate( p_input, psz );
170 asnprintf( &psz, 5, "%d", seqnum_text->value() );
171 input_item_SetTrackNum( p_input, psz );
174 input_item_SetTitle( p_input, qtu( title_text->text() ) );
176 p_playlist = pl_Yield( p_intf );
179 p_playlist->p_private = &p_export;
181 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
183 module_Unneed( p_playlist, p_mod );
185 pl_Release( p_playlist );
189 * Update all the MetaData and art on an "item-changed" event
191 void MetaPanel::update( input_item_t *p_item )
194 #define UPDATE_META( meta, widget ) { \
195 psz_meta = input_item_Get##meta( p_item ); \
196 if( !EMPTY_STR( psz_meta ) ) \
197 widget->setText( qfu( psz_meta ) ); \
199 widget->setText( "" ); }
201 #define UPDATE_META_INT( meta, widget ) { \
202 psz_meta = input_item_Get##meta( p_item ); \
203 if( !EMPTY_STR( psz_meta ) ) \
204 widget->setValue( atoi( psz_meta ) ); }
207 psz_meta = input_item_GetTitle( p_item );
208 if( !EMPTY_STR( psz_meta ) )
209 title_text->setText( qfu( psz_meta ) );
210 else if( !EMPTY_STR( p_item->psz_name ) )
211 title_text->setText( qfu( p_item->psz_name ) );
212 else title_text->setText( "" );
215 psz_meta = input_item_GetURL( p_item );
216 if( !EMPTY_STR( psz_meta ) )
217 emit uriSet( QString( psz_meta ) );
218 else if( !EMPTY_STR( p_item->psz_uri ) )
219 emit uriSet( QString( p_item->psz_uri ) );
221 /* Other classic though */
222 UPDATE_META( Artist, artist_text );
223 UPDATE_META( Genre, genre_text );
224 UPDATE_META( Copyright, copyright_text );
225 UPDATE_META( Album, collection_text );
226 UPDATE_META( Description, description_text );
227 UPDATE_META( Language, language_text );
228 UPDATE_META( NowPlaying, nowplaying_text );
229 UPDATE_META( Publisher, publisher_text );
230 UPDATE_META( Setting, setting_text );
232 UPDATE_META_INT( Date, date_text );
233 UPDATE_META_INT( Tracknum, seqnum_text );
234 UPDATE_META_INT( Rating, rating_text );
236 #undef UPDATE_META_INT
240 psz_meta = input_item_GetArtURL( p_item );
241 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
243 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
244 art_cover->setPixmap( QPixmap( artUrl ) );
247 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
251 * Clear all the metadata widgets
254 void MetaPanel::clear(){}
257 * Second Panel - Shows the extra metadata in a tree, non editable.
259 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
260 intf_thread_t *_p_intf )
261 : QWidget( parent ), p_intf( _p_intf )
263 QGridLayout *layout = new QGridLayout(this);
265 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
266 " are shown in this list.\n" ) );
267 topLabel->setWordWrap( true );
268 layout->addWidget( topLabel, 0, 0 );
270 extraMetaTree = new QTreeWidget( this );
271 extraMetaTree->setAlternatingRowColors( true );
272 extraMetaTree->setColumnCount( 2 );
273 extraMetaTree->header()->hide();
274 /* QStringList headerList = ( QStringList() << qtr( "Type" )
275 * << qtr( "Value" ) );
276 * Useless, add this header if you think it would help the user **
279 layout->addWidget( extraMetaTree, 1, 0 );
283 * Update the Extra Metadata from p_meta->i_extras
285 void ExtraMetaPanel::update( input_item_t *p_item )
287 vlc_meta_t *p_meta = p_item->p_meta;
290 QStringList tempItem;
292 QList<QTreeWidgetItem *> items;
293 vlc_dictionary_t * p_dict = &p_meta->extra_tags;
294 char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
295 for (int i = 0; ppsz_allkey[i] ; i++ )
297 const char * psz_value = (const char *)vlc_dictionary_value_for_key(
298 p_dict, ppsz_allkey[i] );
299 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
300 tempItem.append( qfu( psz_value ) );
301 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
302 free( ppsz_allkey[i] );
305 extraMetaTree->addTopLevelItems( items );
309 * Clear the ExtraMetaData Tree
311 void ExtraMetaPanel::clear()
313 extraMetaTree->clear();
317 * Third panel - Stream info
318 * Display all codecs and muxers info that we could gather.
320 InfoPanel::InfoPanel( QWidget *parent,
321 intf_thread_t *_p_intf )
322 : QWidget( parent ), p_intf( _p_intf )
324 QGridLayout *layout = new QGridLayout(this);
326 QList<QTreeWidgetItem *> items;
328 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
329 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
331 topLabel->setWordWrap( true );
332 layout->addWidget( topLabel, 0, 0 );
334 InfoTree = new QTreeWidget(this);
335 InfoTree->setColumnCount( 1 );
336 InfoTree->header()->hide();
337 layout->addWidget(InfoTree, 1, 0 );
340 InfoPanel::~InfoPanel()
345 * Update the Codecs information on parent->update()
347 void InfoPanel::update( input_item_t *p_item)
350 QTreeWidgetItem *current_item = NULL;
351 QTreeWidgetItem *child_item = NULL;
353 for( int i = 0; i< p_item->i_categories ; i++)
355 current_item = new QTreeWidgetItem();
356 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
357 InfoTree->addTopLevelItem( current_item );
359 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
361 child_item = new QTreeWidgetItem ();
362 child_item->setText( 0,
363 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
365 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
367 current_item->addChild(child_item);
369 InfoTree->setItemExpanded( current_item, true);
376 void InfoPanel::clear()
382 * Save all the information to a file
383 * Not yet implemented.
386 void InfoPanel::saveCodecsInfo()
393 * Fourth Panel - Stats
394 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
396 InputStatsPanel::InputStatsPanel( QWidget *parent,
397 intf_thread_t *_p_intf )
398 : QWidget( parent ), p_intf( _p_intf )
400 QGridLayout *layout = new QGridLayout(this);
402 QList<QTreeWidgetItem *> items;
404 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
405 " media or stream.\n Played and streamed info are shown." ) );
406 topLabel->setWordWrap( true );
407 layout->addWidget( topLabel, 0, 0 );
409 StatsTree = new QTreeWidget(this);
410 StatsTree->setColumnCount( 3 );
411 StatsTree->header()->hide();
413 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
415 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
416 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
418 #define CREATE_CATEGORY( catName, itemText ) { \
419 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
420 catName->setExpanded( true ); \
421 StatsTree->addTopLevelItem( catName ); }
423 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
424 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
425 catName->addChild( itemName ); }
427 /* Create the main categories */
428 CREATE_CATEGORY( input, qtr("Input") );
429 CREATE_CATEGORY( video, qtr("Video") );
430 CREATE_CATEGORY( streaming, qtr("Streaming") );
431 CREATE_CATEGORY( audio, qtr("Audio") );
433 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
435 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
436 "0", input, "kb/s" );
437 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
438 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
439 "0", input, "kb/s" );
441 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
443 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
445 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
448 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
449 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
450 "0", streaming, "kB" );
451 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
452 "0", streaming, "kb/s" );
454 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
456 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
458 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
460 input->setExpanded( true );
461 video->setExpanded( true );
462 streaming->setExpanded( true );
463 audio->setExpanded( true );
465 StatsTree->resizeColumnToContents( 0 );
466 StatsTree->setColumnWidth( 1 , 100 );
468 layout->addWidget(StatsTree, 1, 0 );
471 InputStatsPanel::~InputStatsPanel()
476 * Update the Statistics
478 void InputStatsPanel::update( input_item_t *p_item )
480 vlc_mutex_lock( &p_item->p_stats->lock );
482 #define UPDATE( widget, format, calc... ) \
483 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
485 UPDATE( read_media_stat, "%8.0f",
486 (float)(p_item->p_stats->i_read_bytes)/1000);
487 UPDATE( input_bitrate_stat, "%6.0f",
488 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
489 UPDATE( demuxed_stat, "%8.0f",
490 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
491 UPDATE( stream_bitrate_stat, "%6.0f",
492 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
495 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
496 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
497 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
500 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
501 UPDATE( send_bytes_stat, "%8.0f",
502 (float)(p_item->p_stats->i_sent_bytes)/1000 );
503 UPDATE( send_bitrate_stat, "%6.0f",
504 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
507 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
508 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
509 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
511 vlc_mutex_unlock(& p_item->p_stats->lock );
514 void InputStatsPanel::clear()