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 CONNECT( title_text, textEdited( QString ), this, editMeta( QString ) );
132 CONNECT( description_text, textEdited( QString ), this, editMeta( QString ) );
133 CONNECT( artist_text, textEdited( QString ), this, editMeta( QString ) );
134 CONNECT( collection_text, textEdited( QString ), this, editMeta( QString ) );
135 CONNECT( genre_text, textEdited( QString ), this, editMeta( QString ) );
136 CONNECT( description_text, textEdited( QString ), this, editMeta( QString ) );
137 CONNECT( date_text, valueChanged( QString ), this, editMeta( QString ) );
138 CONNECT( seqnum_text, valueChanged( QString ), this, editMeta( QString ) );
139 CONNECT( rating_text, valueChanged( QString ), this, editMeta( QString ) );
143 MetaPanel::~MetaPanel(){}
146 * Save the MetaData, triggered by parent->save Button
148 void MetaPanel::saveMeta()
150 playlist_t *p_playlist;
153 meta_export_t p_export;
154 p_export.p_item = p_input;
156 if( p_input == NULL )
159 /* we can write meta data only in a file */
160 if( ( p_input->i_type == ITEM_TYPE_AFILE ) || \
161 ( p_input->i_type == ITEM_TYPE_VFILE ) )
162 /* some audio files are detected as video files */
164 char *psz_uri = p_input->psz_uri;
165 if( !strncmp( psz_uri, "file://", 7 ) )
166 psz_uri += 7; /* strlen("file://") = 7 */
168 p_export.psz_file = strndup( psz_uri, PATH_MAX );
173 /* now we read the modified meta data */
174 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
175 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
176 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
178 snprintf( psz, sizeof(psz), "%d", date_text->value() );
179 input_item_SetDate( p_input, psz );
181 snprintf( psz, sizeof(psz), "%d", seqnum_text->value() );
182 input_item_SetTrackNum( p_input, psz );
184 input_item_SetTitle( p_input, qtu( title_text->text() ) );
186 p_playlist = pl_Yield( p_intf );
189 p_playlist->p_private = &p_export;
191 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
193 module_Unneed( p_playlist, p_mod );
195 pl_Release( p_playlist );
199 void MetaPanel::editMeta( QString edit )
205 void MetaPanel::setEdit( bool editing )
210 void MetaPanel::setInput( input_item_t *input )
212 if( in_edit ) return;
218 * Update all the MetaData and art on an "item-changed" event
220 void MetaPanel::update( input_item_t *p_item )
222 if( in_edit ) return;
224 #define UPDATE_META( meta, widget ) { \
225 psz_meta = input_item_Get##meta( p_item ); \
226 if( !EMPTY_STR( psz_meta ) ) \
227 widget->setText( qfu( psz_meta ) ); \
229 widget->setText( "" ); } \
232 #define UPDATE_META_INT( meta, widget ) { \
233 psz_meta = input_item_Get##meta( p_item ); \
234 if( !EMPTY_STR( psz_meta ) ) \
235 widget->setValue( atoi( psz_meta ) ); } \
240 psz_meta = input_item_GetTitle( p_item );
241 if( !EMPTY_STR( psz_meta ) )
242 title_text->setText( qfu( psz_meta ) );
243 else if( !EMPTY_STR( p_item->psz_name ) )
244 title_text->setText( qfu( p_item->psz_name ) );
245 else title_text->setText( "" );
249 psz_meta = input_item_GetURL( p_item );
250 if( !EMPTY_STR( psz_meta ) )
251 emit uriSet( QString( psz_meta ) );
252 else if( !EMPTY_STR( p_item->psz_uri ) )
253 emit uriSet( QString( p_item->psz_uri ) );
256 /* Other classic though */
257 UPDATE_META( Artist, artist_text );
258 UPDATE_META( Genre, genre_text );
259 UPDATE_META( Copyright, copyright_text );
260 UPDATE_META( Album, collection_text );
261 UPDATE_META( Description, description_text );
262 UPDATE_META( Language, language_text );
263 UPDATE_META( NowPlaying, nowplaying_text );
264 UPDATE_META( Publisher, publisher_text );
265 UPDATE_META( Setting, setting_text );
267 UPDATE_META_INT( Date, date_text );
268 UPDATE_META_INT( TrackNum, seqnum_text );
269 UPDATE_META_INT( Rating, rating_text );
271 #undef UPDATE_META_INT
275 psz_meta = input_item_GetArtURL( p_item );
276 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
278 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
279 art_cover->setPixmap( QPixmap( artUrl ) );
282 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
287 * Clear all the metadata widgets
290 void MetaPanel::clear(){}
293 * Second Panel - Shows the extra metadata in a tree, non editable.
295 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
296 intf_thread_t *_p_intf )
297 : QWidget( parent ), p_intf( _p_intf )
299 QGridLayout *layout = new QGridLayout(this);
301 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
302 " are shown in this list.\n" ) );
303 topLabel->setWordWrap( true );
304 layout->addWidget( topLabel, 0, 0 );
306 extraMetaTree = new QTreeWidget( this );
307 extraMetaTree->setAlternatingRowColors( true );
308 extraMetaTree->setColumnCount( 2 );
309 extraMetaTree->header()->hide();
310 /* QStringList headerList = ( QStringList() << qtr( "Type" )
311 * << qtr( "Value" ) );
312 * Useless, add this header if you think it would help the user **
315 layout->addWidget( extraMetaTree, 1, 0 );
319 * Update the Extra Metadata from p_meta->i_extras
321 void ExtraMetaPanel::update( input_item_t *p_item )
323 vlc_mutex_lock( &p_item->lock );
324 vlc_meta_t *p_meta = p_item->p_meta;
327 QStringList tempItem;
329 QList<QTreeWidgetItem *> items;
330 vlc_dictionary_t * p_dict = &p_meta->extra_tags;
331 char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
332 for (int i = 0; ppsz_allkey[i] ; i++ )
334 const char * psz_value = (const char *)vlc_dictionary_value_for_key(
335 p_dict, ppsz_allkey[i] );
336 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
337 tempItem.append( qfu( psz_value ) );
338 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
339 free( ppsz_allkey[i] );
341 vlc_mutex_unlock( &p_item->lock );
343 extraMetaTree->addTopLevelItems( items );
347 * Clear the ExtraMetaData Tree
349 void ExtraMetaPanel::clear()
351 extraMetaTree->clear();
355 * Third panel - Stream info
356 * Display all codecs and muxers info that we could gather.
358 InfoPanel::InfoPanel( QWidget *parent,
359 intf_thread_t *_p_intf )
360 : QWidget( parent ), p_intf( _p_intf )
362 QGridLayout *layout = new QGridLayout(this);
364 QList<QTreeWidgetItem *> items;
366 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
367 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
369 topLabel->setWordWrap( true );
370 layout->addWidget( topLabel, 0, 0 );
372 InfoTree = new QTreeWidget(this);
373 InfoTree->setColumnCount( 1 );
374 InfoTree->header()->hide();
375 layout->addWidget(InfoTree, 1, 0 );
378 InfoPanel::~InfoPanel()
383 * Update the Codecs information on parent->update()
385 void InfoPanel::update( input_item_t *p_item)
388 QTreeWidgetItem *current_item = NULL;
389 QTreeWidgetItem *child_item = NULL;
391 for( int i = 0; i< p_item->i_categories ; i++)
393 current_item = new QTreeWidgetItem();
394 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
395 InfoTree->addTopLevelItem( current_item );
397 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
399 child_item = new QTreeWidgetItem ();
400 child_item->setText( 0,
401 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
403 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
405 current_item->addChild(child_item);
407 InfoTree->setItemExpanded( current_item, true);
414 void InfoPanel::clear()
420 * Save all the information to a file
421 * Not yet implemented.
424 void InfoPanel::saveCodecsInfo()
431 * Fourth Panel - Stats
432 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
434 InputStatsPanel::InputStatsPanel( QWidget *parent,
435 intf_thread_t *_p_intf )
436 : QWidget( parent ), p_intf( _p_intf )
438 QGridLayout *layout = new QGridLayout(this);
440 QList<QTreeWidgetItem *> items;
442 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
443 " media or stream.\n Played and streamed info are shown." ) );
444 topLabel->setWordWrap( true );
445 layout->addWidget( topLabel, 0, 0 );
447 StatsTree = new QTreeWidget(this);
448 StatsTree->setColumnCount( 3 );
449 StatsTree->header()->hide();
451 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
453 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
454 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
456 #define CREATE_CATEGORY( catName, itemText ) { \
457 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
458 catName->setExpanded( true ); \
459 StatsTree->addTopLevelItem( catName ); }
461 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
462 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
463 catName->addChild( itemName ); }
465 /* Create the main categories */
466 CREATE_CATEGORY( input, qtr("Input") );
467 CREATE_CATEGORY( video, qtr("Video") );
468 CREATE_CATEGORY( streaming, qtr("Streaming") );
469 CREATE_CATEGORY( audio, qtr("Audio") );
471 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
473 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
474 "0", input, "kb/s" );
475 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
476 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
477 "0", input, "kb/s" );
479 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
481 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
483 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
486 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
487 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
488 "0", streaming, "kB" );
489 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
490 "0", streaming, "kb/s" );
492 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
494 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
496 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
498 input->setExpanded( true );
499 video->setExpanded( true );
500 streaming->setExpanded( true );
501 audio->setExpanded( true );
503 StatsTree->resizeColumnToContents( 0 );
504 StatsTree->setColumnWidth( 1 , 100 );
506 layout->addWidget(StatsTree, 1, 0 );
509 InputStatsPanel::~InputStatsPanel()
514 * Update the Statistics
516 void InputStatsPanel::update( input_item_t *p_item )
518 vlc_mutex_lock( &p_item->p_stats->lock );
520 #define UPDATE( widget, format, calc... ) \
521 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
523 UPDATE( read_media_stat, "%8.0f",
524 (float)(p_item->p_stats->i_read_bytes)/1000);
525 UPDATE( input_bitrate_stat, "%6.0f",
526 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
527 UPDATE( demuxed_stat, "%8.0f",
528 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
529 UPDATE( stream_bitrate_stat, "%6.0f",
530 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
533 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
534 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
535 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
538 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
539 UPDATE( send_bytes_stat, "%8.0f",
540 (float)(p_item->p_stats->i_sent_bytes)/1000 );
541 UPDATE( send_bitrate_stat, "%6.0f",
542 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
545 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
546 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
547 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
549 vlc_mutex_unlock(& p_item->p_stats->lock );
552 void InputStatsPanel::clear()