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>
9 * Ilkka Ollakka <ileoo@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
31 #include "components/info_panels.hpp"
32 #include "components/interface_widgets.hpp"
37 #include <QTreeWidget>
38 #include <QHeaderView>
40 #include <QStringList>
41 #include <QGridLayout>
46 /************************************************************************
48 ************************************************************************/
51 * First Panel - Meta Info
52 * All the usual MetaData are displayed and can be changed.
54 MetaPanel::MetaPanel( QWidget *parent,
55 intf_thread_t *_p_intf )
56 : QWidget( parent ), p_intf( _p_intf )
58 QGridLayout *metaLayout = new QGridLayout( this );
60 int line = 0; /* Counter for GridLayout */
63 #define ADD_META( string, widget ) { \
64 metaLayout->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
65 widget = new QLineEdit; \
66 metaLayout->addWidget( widget, line, 1, 1, 9 ); \
69 /* Title, artist and album*/
70 ADD_META( VLC_META_TITLE, title_text ); /* OK */
71 ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
72 ADD_META( VLC_META_ALBUM, collection_text ); /* OK */
75 /* TODO List id3genres.h is not includable yet ? */
76 genre_text = new QLineEdit;
77 metaLayout->addWidget( new QLabel( qtr( VLC_META_GENRE ) + " :" ), line, 0 );
78 metaLayout->addWidget( genre_text, line, 1, 1, 3 );
80 /* Number - on the same line */
81 metaLayout->addWidget( new QLabel( qtr( VLC_META_TRACK_NUMBER ) + " :" ),
83 seqnum_text = new QLineEdit;
84 seqnum_text->setInputMask("0000");
85 seqnum_text->setAlignment( Qt::AlignRight );
86 metaLayout->addWidget( seqnum_text, line, 7, 1, 3 );
89 /* Date (Should be in years) */
90 date_text = new QLineEdit;
91 date_text->setInputMask("0000");
92 date_text->setAlignment( Qt::AlignRight );
93 metaLayout->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 0 );
94 metaLayout->addWidget( date_text, line, 1, 1, 3 );
96 /* Rating - on the same line */
98 metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 4, 1, 2 );
99 rating_text = new QSpinBox; setSpinBounds( rating_text );
100 metaLayout->addWidget( rating_text, line, 6, 1, 1 );
102 /* Language on the same line */
103 metaLayout->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 5, 1, 2 );
104 language_text = new QLineEdit;
105 language_text->setReadOnly( true );
106 metaLayout->addWidget( language_text, line, 7, 1, 3 );
110 art_cover = new CoverArtLabel( this, p_intf );
111 metaLayout->addWidget( art_cover, line, 8, 4, 2, Qt::AlignRight );
113 /* Settings is unused */
114 /* l->addWidget( new QLabel( qtr( VLC_META_SETTING ) + " :" ), line, 5 );
115 setting_text = new QLineEdit;
116 l->addWidget( setting_text, line, 6, 1, 4 ); */
118 /* Less used metadata */
119 #define ADD_META_2( string, widget ) { \
120 metaLayout->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
121 widget = new QLineEdit; \
122 metaLayout->addWidget( widget, line, 1, 1, 7 ); \
125 /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
126 ADD_META_2( VLC_META_NOW_PLAYING, nowplaying_text );
127 nowplaying_text->setReadOnly( true );
128 ADD_META_2( VLC_META_PUBLISHER, publisher_text );
129 ADD_META_2( VLC_META_COPYRIGHT, copyright_text );
130 ADD_META_2( N_("Comments"), description_text );
132 /* useless metadata */
134 //ADD_META_2( VLC_META_ENCODED_BY, encodedby_text );
135 /* ADD_META( TRACKID ) Useless ? */
136 /* ADD_URI - DO not show it, done outside */
138 metaLayout->setColumnStretch( 1, 2 );
139 metaLayout->setColumnMinimumWidth ( 1, 80 );
143 CONNECT( title_text, textEdited( QString ), this, enterEditMode() );
144 CONNECT( artist_text, textEdited( QString ), this, enterEditMode() );
145 CONNECT( collection_text, textEdited( QString ), this, enterEditMode() );
146 CONNECT( genre_text, textEdited( QString ), this, enterEditMode() );
147 CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
149 CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
150 CONNECT( description_text, textEdited( QString ), this, enterEditMode() );
151 /* CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/
153 /* We are not yet in Edit Mode */
154 b_inEditMode = false;
158 * Update all the MetaData and art on an "item-changed" event
160 void MetaPanel::update( input_item_t *p_item )
168 /* Don't update if you are in edit mode */
169 if( b_inEditMode ) return;
170 else p_input = p_item;
173 #define UPDATE_META( meta, widget ) { \
174 psz_meta = input_item_Get##meta( p_item ); \
175 if( !EMPTY_STR( psz_meta ) ) \
176 widget->setText( qfu( psz_meta ) ); \
178 widget->setText( "" ); } \
181 #define UPDATE_META_INT( meta, widget ) { \
182 psz_meta = input_item_Get##meta( p_item ); \
183 if( !EMPTY_STR( psz_meta ) ) \
184 widget->setValue( atoi( psz_meta ) ); } \
188 psz_meta = input_item_GetTitleFbName( p_item );
191 title_text->setText( qfu( psz_meta ) );
195 title_text->setText( "" );
198 psz_meta = input_item_GetURL( p_item );
199 if( !EMPTY_STR( psz_meta ) )
200 emit uriSet( qfu( psz_meta ) );
204 psz_meta = input_item_GetURI( p_item );
205 if( !EMPTY_STR( psz_meta ) )
206 emit uriSet( qfu( psz_meta ) );
210 /* Other classic though */
211 UPDATE_META( Artist, artist_text );
212 UPDATE_META( Genre, genre_text );
213 UPDATE_META( Copyright, copyright_text );
214 UPDATE_META( Album, collection_text );
215 UPDATE_META( Description, description_text );
216 UPDATE_META( Language, language_text );
217 UPDATE_META( NowPlaying, nowplaying_text );
218 UPDATE_META( Publisher, publisher_text );
219 // UPDATE_META( Setting, setting_text );
220 //FIXME this is wrong if has Publisher and EncodedBy fields
221 UPDATE_META( EncodedBy, publisher_text );
223 UPDATE_META( Date, date_text );
224 UPDATE_META( TrackNum, seqnum_text );
225 // UPDATE_META_INT( Rating, rating_text );
227 #undef UPDATE_META_INT
230 // If a artURL is available as a local file, directly display it !
233 char *psz_art = input_item_GetArtURL( p_item );
234 if( psz_art && !strncmp( psz_art, "file://", 7 ) &&
235 decode_URI( psz_art + 7 ) )
237 file = qfu( psz_art + 8 ); // Remove extra / on Win32 URI.
239 file = qfu( psz_art + 7 );
243 art_cover->showArtUpdate( file );
248 * Save the MetaData, triggered by parent->save Button
250 void MetaPanel::saveMeta()
252 if( p_input == NULL )
255 /* now we read the modified meta data */
256 input_item_SetTitle( p_input, qtu( title_text->text() ) );
257 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
258 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
259 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
260 input_item_SetTrackNum( p_input, qtu( seqnum_text->text() ) );
261 input_item_SetDate( p_input, qtu( date_text->text() ) );
263 input_item_SetCopyright( p_input, qtu( copyright_text->text() ) );
264 input_item_SetPublisher( p_input, qtu( publisher_text->text() ) );
265 input_item_SetDescription( p_input, qtu( description_text->text() ) );
267 playlist_t *p_playlist = pl_Hold( p_intf );
268 input_item_WriteMeta( VLC_OBJECT(p_playlist), p_input );
269 pl_Release( p_intf );
271 /* Reset the status of the mode. No need to emit any signal because parent
272 is the only caller */
273 b_inEditMode = false;
277 bool MetaPanel::isInEditMode()
282 void MetaPanel::enterEditMode()
284 msg_Dbg( p_intf, "Entering Edit MetaData Mode" );
288 void MetaPanel::setEditMode( bool b_editing )
290 b_inEditMode = b_editing;
291 if( b_editing )emit editing();
295 * Clear all the metadata widgets
297 void MetaPanel::clear()
300 artist_text->clear();
302 copyright_text->clear();
303 collection_text->clear();
304 seqnum_text->clear();
305 description_text->clear();
307 language_text->clear();
308 nowplaying_text->clear();
309 publisher_text->clear();
311 setEditMode( false );
316 * Second Panel - Shows the extra metadata in a tree, non editable.
318 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
319 intf_thread_t *_p_intf )
320 : QWidget( parent ), p_intf( _p_intf )
322 QGridLayout *layout = new QGridLayout(this);
324 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
325 " are shown in this panel.\n" ) );
326 topLabel->setWordWrap( true );
327 layout->addWidget( topLabel, 0, 0 );
329 extraMetaTree = new QTreeWidget( this );
330 extraMetaTree->setAlternatingRowColors( true );
331 extraMetaTree->setColumnCount( 2 );
332 extraMetaTree->resizeColumnToContents( 0 );
333 extraMetaTree->header()->hide();
334 /* QStringList headerList = ( QStringList() << qtr( "Type" )
335 * << qtr( "Value" ) );
336 * Useless, add this header if you think it would help the user **
339 layout->addWidget( extraMetaTree, 1, 0 );
343 * Update the Extra Metadata from p_meta->i_extras
345 void ExtraMetaPanel::update( input_item_t *p_item )
353 QList<QTreeWidgetItem *> items;
355 extraMetaTree->clear();
357 vlc_mutex_lock( &p_item->lock );
358 vlc_meta_t *p_meta = p_item->p_meta;
361 vlc_mutex_unlock( &p_item->lock );
365 vlc_dictionary_t * p_dict = &p_meta->extra_tags;
366 char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
368 for( int i = 0; ppsz_allkey[i] ; i++ )
370 const char * psz_value = (const char *)vlc_dictionary_value_for_key(
371 p_dict, ppsz_allkey[i] );
372 QStringList tempItem;
373 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
374 tempItem.append( qfu( psz_value ) );
375 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
376 free( ppsz_allkey[i] );
378 vlc_mutex_unlock( &p_item->lock );
381 extraMetaTree->addTopLevelItems( items );
382 extraMetaTree->resizeColumnToContents( 0 );
386 * Clear the ExtraMetaData Tree
388 void ExtraMetaPanel::clear()
390 extraMetaTree->clear();
394 * Third panel - Stream info
395 * Display all codecs and muxers info that we could gather.
397 InfoPanel::InfoPanel( QWidget *parent,
398 intf_thread_t *_p_intf )
399 : QWidget( parent ), p_intf( _p_intf )
401 QGridLayout *layout = new QGridLayout(this);
403 QList<QTreeWidgetItem *> items;
405 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
406 " stream is made of.\nMuxer, Audio and Video Codecs, Subtitles "
408 topLabel->setWordWrap( true );
409 layout->addWidget( topLabel, 0, 0 );
411 InfoTree = new QTreeWidget(this);
412 InfoTree->setColumnCount( 1 );
413 InfoTree->header()->hide();
414 layout->addWidget(InfoTree, 1, 0 );
418 * Update the Codecs information on parent->update()
420 void InfoPanel::update( input_item_t *p_item)
429 QTreeWidgetItem *current_item = NULL;
430 QTreeWidgetItem *child_item = NULL;
432 for( int i = 0; i< p_item->i_categories ; i++)
434 current_item = new QTreeWidgetItem();
435 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
436 InfoTree->addTopLevelItem( current_item );
438 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
440 child_item = new QTreeWidgetItem ();
441 child_item->setText( 0,
442 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
444 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
446 current_item->addChild(child_item);
448 InfoTree->setItemExpanded( current_item, true);
455 void InfoPanel::clear()
461 * Save all the information to a file
462 * Not yet implemented.
465 void InfoPanel::saveCodecsInfo()
470 * Fourth Panel - Stats
471 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
473 InputStatsPanel::InputStatsPanel( QWidget *parent,
474 intf_thread_t *_p_intf )
475 : QWidget( parent ), p_intf( _p_intf )
477 QGridLayout *layout = new QGridLayout(this);
479 QList<QTreeWidgetItem *> items;
481 QLabel *topLabel = new QLabel( qtr( "Statistics about the currently "
482 "playing media or stream." ) );
483 topLabel->setWordWrap( true );
484 layout->addWidget( topLabel, 0, 0 );
486 StatsTree = new QTreeWidget(this);
487 StatsTree->setColumnCount( 3 );
488 StatsTree->header()->hide();
490 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
492 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
493 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
495 #define CREATE_CATEGORY( catName, itemText ) { \
496 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
497 catName->setExpanded( true ); \
498 StatsTree->addTopLevelItem( catName ); }
500 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
501 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
502 catName->addChild( itemName ); }
504 /* Create the main categories */
505 CREATE_CATEGORY( audio, qtr("Audio") );
506 CREATE_CATEGORY( video, qtr("Video") );
507 CREATE_CATEGORY( input, qtr("Input") );
508 CREATE_CATEGORY( streaming, qtr("Streaming") );
510 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
512 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
513 "0", input, "kb/s" );
514 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
515 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
516 "0", input, "kb/s" );
517 CREATE_AND_ADD_TO_CAT( corrupted_stat, qtr("Corrupted"),
519 CREATE_AND_ADD_TO_CAT( discontinuity_stat, qtr("Discontinuities"),
522 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
524 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
526 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
529 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
530 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
531 "0", streaming, "kB" );
532 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrate"),
533 "0", streaming, "kb/s" );
535 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
537 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
539 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
541 #undef CREATE_AND_ADD_TO_CAT
542 #undef CREATE_CATEGORY
543 #undef CREATE_TREE_ITEM
545 input->setExpanded( true );
546 video->setExpanded( true );
547 streaming->setExpanded( true );
548 audio->setExpanded( true );
550 StatsTree->resizeColumnToContents( 0 );
551 StatsTree->setColumnWidth( 1 , 200 );
553 layout->addWidget(StatsTree, 1, 0 );
557 * Update the Statistics
559 void InputStatsPanel::update( input_item_t *p_item )
562 vlc_mutex_lock( &p_item->p_stats->lock );
564 #define UPDATE( widget, format, calc... ) \
565 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
567 UPDATE( read_media_stat, "%8.0f",
568 (float)(p_item->p_stats->i_read_bytes)/1000);
569 UPDATE( input_bitrate_stat, "%6.0f",
570 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
571 UPDATE( demuxed_stat, "%8.0f",
572 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
573 UPDATE( stream_bitrate_stat, "%6.0f",
574 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
575 UPDATE( corrupted_stat, "%5i", p_item->p_stats->i_demux_corrupted );
576 UPDATE( discontinuity_stat, "%5i", p_item->p_stats->i_demux_discontinuity );
579 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
580 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
581 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
584 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
585 UPDATE( send_bytes_stat, "%8.0f",
586 (float)(p_item->p_stats->i_sent_bytes)/1000 );
587 UPDATE( send_bitrate_stat, "%6.0f",
588 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
591 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
592 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
593 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
597 vlc_mutex_unlock(& p_item->p_stats->lock );
600 void InputStatsPanel::clear()