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 *****************************************************************************/
26 #define __STDC_FORMAT_MACROS 1
27 #define __STDC_CONSTANT_MACROS 1
34 #include "components/info_panels.hpp"
35 #include "components/interface_widgets.hpp"
41 #include <QTreeWidget>
42 #include <QHeaderView>
44 #include <QStringList>
45 #include <QGridLayout>
51 /************************************************************************
53 ************************************************************************/
56 * First Panel - Meta Info
57 * All the usual MetaData are displayed and can be changed.
59 MetaPanel::MetaPanel( QWidget *parent,
60 intf_thread_t *_p_intf )
61 : QWidget( parent ), p_intf( _p_intf )
63 QGridLayout *metaLayout = new QGridLayout( this );
64 metaLayout->setVerticalSpacing( 0 );
66 QFont smallFont = QApplication::font();
67 smallFont.setPointSize( smallFont.pointSize() - 2 );
68 smallFont.setBold( true );
70 int line = 0; /* Counter for GridLayout */
74 #define ADD_META( string, widget, col, colspan ) { \
75 label = new QLabel( qtr( string ) ); label->setFont( smallFont ); \
76 label->setContentsMargins( 3, 2, 0, 0 ); \
77 metaLayout->addWidget( label, line++, col, 1, colspan ); \
78 widget = new QLineEdit; \
79 metaLayout->addWidget( widget, line, col, 1, colspan ); \
80 CONNECT( widget, textEdited( QString ), this, enterEditMode() ); \
83 /* Title, artist and album*/
84 ADD_META( VLC_META_TITLE, title_text, 0, 10 ); line++;
85 ADD_META( VLC_META_ARTIST, artist_text, 0, 10 ); line++;
86 ADD_META( VLC_META_ALBUM, collection_text, 0, 7 );
89 label = new QLabel( qtr( VLC_META_DATE ) );
90 label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
91 metaLayout->addWidget( label, line - 1, 7, 1, 2 );
93 /* Date (Should be in years) */
94 date_text = new QLineEdit;
95 date_text->setAlignment( Qt::AlignRight );
96 date_text->setInputMask("0000");
97 date_text->setMaximumWidth( 128 );
98 metaLayout->addWidget( date_text, line, 7, 1, -1 );
102 /* TODO List id3genres.h is not includable yet ? */
103 ADD_META( VLC_META_GENRE, genre_text, 0, 7 );
105 /* Number - on the same line */
106 label = new QLabel( qtr( VLC_META_TRACK_NUMBER ) );
107 label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
108 metaLayout->addWidget( label, line - 1, 7, 1, 3 );
110 seqnum_text = new QLineEdit;
111 seqnum_text->setMaximumWidth( 60 );
112 metaLayout->addWidget( seqnum_text, line, 7, 1, 1 );
114 label = new QLabel( "/" ); label->setFont( smallFont );
115 metaLayout->addWidget( label, line, 8, 1, 1 );
117 seqtot_text = new QLineEdit;
118 seqtot_text->setMaximumWidth( 60 );
119 metaLayout->addWidget( seqtot_text, line, 9, 1, 1 );
122 /* Rating - on the same line */
124 metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) ), line, 4, 1, 2 );
125 rating_text = new QSpinBox; setSpinBounds( rating_text );
126 metaLayout->addWidget( rating_text, line, 6, 1, 1 );
129 /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
130 ADD_META( VLC_META_NOW_PLAYING, nowplaying_text, 0, 7 );
131 nowplaying_text->setReadOnly( true ); line--;
133 /* Language on the same line */
134 ADD_META( VLC_META_LANGUAGE, language_text, 7, -1 ); line++;
135 ADD_META( VLC_META_PUBLISHER, publisher_text, 0, 7 ); line++;
138 lblURL->setOpenExternalLinks( true );
139 lblURL->setTextFormat( Qt::RichText );
140 metaLayout->addWidget( lblURL, line -1, 7, 1, -1 );
142 ADD_META( VLC_META_COPYRIGHT, copyright_text, 0, 7 ); line++;
145 art_cover = new CoverArtLabel( this, p_intf );
146 metaLayout->addWidget( art_cover, line, 7, 6, 3, Qt::AlignLeft );
148 ADD_META( VLC_META_ENCODED_BY, encodedby_text, 0, 7 ); line++;
150 label = new QLabel( qtr( N_("Comments") ) ); label->setFont( smallFont );
151 label->setContentsMargins( 3, 2, 0, 0 );
152 metaLayout->addWidget( label, line++, 0, 1, 7 );
153 description_text = new QTextEdit;
154 description_text->setAcceptRichText( false );
155 metaLayout->addWidget( description_text, line, 0, 1, 7 );
156 // CONNECT( description_text, textChanged(), this, enterEditMode() ); //FIXME
159 /* VLC_META_SETTING: Useless */
160 /* ADD_META( TRACKID ) Useless ? */
161 /* ADD_URI - Do not show it, done outside */
163 metaLayout->setColumnStretch( 1, 20 );
164 metaLayout->setColumnMinimumWidth ( 1, 80 );
165 metaLayout->setRowStretch( line, 10 );
168 CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
169 CONNECT( seqtot_text, textEdited( QString ), this, enterEditMode() );
171 CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
172 /* CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/
174 /* We are not yet in Edit Mode */
175 b_inEditMode = false;
179 * Update all the MetaData and art on an "item-changed" event
181 void MetaPanel::update( input_item_t *p_item )
189 /* Don't update if you are in edit mode */
190 if( b_inEditMode ) return;
191 else p_input = p_item;
194 #define UPDATE_META( meta, widget ) { \
195 psz_meta = input_item_Get##meta( p_item ); \
196 widget->setText( !EMPTY_STR( psz_meta ) ? qfu( psz_meta ) : "" ); \
199 #define UPDATE_META_INT( meta, widget ) { \
200 psz_meta = input_item_Get##meta( p_item ); \
201 if( !EMPTY_STR( psz_meta ) ) \
202 widget->setValue( atoi( psz_meta ) ); } \
206 psz_meta = input_item_GetTitleFbName( p_item );
209 title_text->setText( qfu( psz_meta ) );
213 title_text->setText( "" );
216 psz_meta = input_item_GetURI( p_item );
217 if( !EMPTY_STR( psz_meta ) )
218 emit uriSet( qfu( psz_meta ) );
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( EncodedBy, encodedby_text );
232 UPDATE_META( Date, date_text );
233 UPDATE_META( TrackNum, seqnum_text );
234 // UPDATE_META( Setting, setting_text );
235 // UPDATE_META_INT( Rating, rating_text );
238 psz_meta = input_item_GetURL( p_item );
239 if( !EMPTY_STR( psz_meta ) && strcmp( psz_meta, currentURL ) )
241 free( currentURL ); currentURL = strdup( psz_meta );
243 lblURL->setText( "<a href='" + qfu( psz_meta ) + "'>" +
244 qfu( psz_meta ).remove( QRegExp( ".*://") ) + "</a>" );
247 #undef UPDATE_META_INT
250 // If a artURL is available as a local file, directly display it !
253 char *psz_art = input_item_GetArtURL( p_item );
256 char *psz = make_path( psz_art );
262 art_cover->showArtUpdate( file );
266 * Save the MetaData, triggered by parent->save Button
268 void MetaPanel::saveMeta()
270 if( p_input == NULL )
273 /* now we read the modified meta data */
274 input_item_SetTitle( p_input, qtu( title_text->text() ) );
275 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
276 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
277 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
278 input_item_SetTrackNum( p_input, qtu( seqnum_text->text() ) );
279 input_item_SetDate( p_input, qtu( date_text->text() ) );
281 input_item_SetCopyright( p_input, qtu( copyright_text->text() ) );
282 input_item_SetPublisher( p_input, qtu( publisher_text->text() ) );
283 input_item_SetDescription( p_input, qtu( description_text->toPlainText() ) );
285 playlist_t *p_playlist = pl_Get( p_intf );
286 input_item_WriteMeta( VLC_OBJECT(p_playlist), p_input );
288 /* Reset the status of the mode. No need to emit any signal because parent
289 is the only caller */
290 b_inEditMode = false;
294 bool MetaPanel::isInEditMode()
299 void MetaPanel::enterEditMode()
304 void MetaPanel::setEditMode( bool b_editing )
306 b_inEditMode = b_editing;
307 if( b_editing )emit editing();
311 * Clear all the metadata widgets
313 void MetaPanel::clear()
316 artist_text->clear();
318 copyright_text->clear();
319 collection_text->clear();
320 seqnum_text->clear();
321 description_text->clear();
323 language_text->clear();
324 nowplaying_text->clear();
325 publisher_text->clear();
327 setEditMode( false );
332 * Second Panel - Shows the extra metadata in a tree, non editable.
334 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
335 intf_thread_t *_p_intf )
336 : QWidget( parent ), p_intf( _p_intf )
338 QGridLayout *layout = new QGridLayout(this);
340 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
341 " are shown in this panel.\n" ) );
342 topLabel->setWordWrap( true );
343 layout->addWidget( topLabel, 0, 0 );
345 extraMetaTree = new QTreeWidget( this );
346 extraMetaTree->setAlternatingRowColors( true );
347 extraMetaTree->setColumnCount( 2 );
348 extraMetaTree->resizeColumnToContents( 0 );
349 extraMetaTree->setHeaderHidden( true );
350 layout->addWidget( extraMetaTree, 1, 0 );
354 * Update the Extra Metadata from p_meta->i_extras
356 void ExtraMetaPanel::update( input_item_t *p_item )
364 QList<QTreeWidgetItem *> items;
366 extraMetaTree->clear();
368 vlc_mutex_lock( &p_item->lock );
369 vlc_meta_t *p_meta = p_item->p_meta;
372 vlc_mutex_unlock( &p_item->lock );
376 char ** ppsz_allkey = vlc_meta_CopyExtraNames( p_meta);
378 for( int i = 0; ppsz_allkey[i] ; i++ )
380 const char * psz_value = vlc_meta_GetExtra( p_meta, ppsz_allkey[i] );
381 QStringList tempItem;
382 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
383 tempItem.append( qfu( psz_value ) );
384 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
385 free( ppsz_allkey[i] );
387 vlc_mutex_unlock( &p_item->lock );
390 extraMetaTree->addTopLevelItems( items );
391 extraMetaTree->resizeColumnToContents( 0 );
395 * Clear the ExtraMetaData Tree
397 void ExtraMetaPanel::clear()
399 extraMetaTree->clear();
403 * Third panel - Stream info
404 * Display all codecs and muxers info that we could gather.
406 InfoPanel::InfoPanel( QWidget *parent,
407 intf_thread_t *_p_intf )
408 : QWidget( parent ), p_intf( _p_intf )
410 QGridLayout *layout = new QGridLayout(this);
412 QList<QTreeWidgetItem *> items;
414 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
415 " stream is made of.\nMuxer, Audio and Video Codecs, Subtitles "
417 topLabel->setWordWrap( true );
418 layout->addWidget( topLabel, 0, 0 );
420 InfoTree = new QTreeWidget(this);
421 InfoTree->setColumnCount( 1 );
422 InfoTree->header()->hide();
423 InfoTree->header()->setResizeMode(QHeaderView::ResizeToContents);
424 layout->addWidget(InfoTree, 1, 0 );
428 * Update the Codecs information on parent->update()
430 void InfoPanel::update( input_item_t *p_item)
439 QTreeWidgetItem *current_item = NULL;
440 QTreeWidgetItem *child_item = NULL;
442 for( int i = 0; i< p_item->i_categories ; i++)
444 current_item = new QTreeWidgetItem();
445 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
446 InfoTree->addTopLevelItem( current_item );
448 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
450 child_item = new QTreeWidgetItem ();
451 child_item->setText( 0,
452 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
454 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
456 current_item->addChild(child_item);
458 InfoTree->setItemExpanded( current_item, true);
465 void InfoPanel::clear()
471 * Save all the information to a file
472 * Not yet implemented.
475 void InfoPanel::saveCodecsInfo()
480 * Fourth Panel - Stats
481 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
483 InputStatsPanel::InputStatsPanel( QWidget *parent,
484 intf_thread_t *_p_intf )
485 : QWidget( parent ), p_intf( _p_intf )
487 QGridLayout *layout = new QGridLayout(this);
489 QLabel *topLabel = new QLabel( qtr( "Current"
490 " media / stream " "statistics") );
491 topLabel->setWordWrap( true );
492 layout->addWidget( topLabel, 0, 0 );
494 StatsTree = new QTreeWidget(this);
495 StatsTree->setColumnCount( 3 );
496 StatsTree->setHeaderHidden( true );
498 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
500 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
501 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
503 #define CREATE_CATEGORY( catName, itemText ) { \
504 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
505 catName->setExpanded( true ); \
506 StatsTree->addTopLevelItem( catName ); }
508 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
509 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
510 catName->addChild( itemName ); }
512 /* Create the main categories */
513 CREATE_CATEGORY( audio, qtr("Audio") );
514 CREATE_CATEGORY( video, qtr("Video") );
515 CREATE_CATEGORY( input, qtr("Input/Read") );
516 CREATE_CATEGORY( streaming, qtr("Output/Written/Sent") );
518 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Media data size"),
519 "0", input , "KiB" );
520 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
521 "0", input, "kb/s" );
522 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed data size"), "0", input, "KiB") ;
523 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Content bitrate"),
524 "0", input, "kb/s" );
525 CREATE_AND_ADD_TO_CAT( corrupted_stat, qtr("Discarded (corrupted)"),
527 CREATE_AND_ADD_TO_CAT( discontinuity_stat, qtr("Dropped (discontinued)"),
530 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded"),
531 "0", video, qtr("blocks") );
532 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed"),
533 "0", video, qtr("frames") );
534 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost"),
535 "0", video, qtr("frames") );
537 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent"), "0", streaming, qtr("packets") );
538 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent"),
539 "0", streaming, "KiB" );
540 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Upstream rate"),
541 "0", streaming, "kb/s" );
543 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded"),
544 "0", audio, qtr("blocks") );
545 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played"),
546 "0", audio, qtr("buffers") );
547 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost"), "0", audio, qtr("buffers") );
549 #undef CREATE_AND_ADD_TO_CAT
550 #undef CREATE_CATEGORY
551 #undef CREATE_TREE_ITEM
553 input->setExpanded( true );
554 video->setExpanded( true );
555 streaming->setExpanded( true );
556 audio->setExpanded( true );
558 StatsTree->resizeColumnToContents( 0 );
559 StatsTree->setColumnWidth( 1 , 200 );
561 layout->addWidget(StatsTree, 1, 0 );
565 * Update the Statistics
567 void InputStatsPanel::update( input_item_t *p_item )
570 vlc_mutex_lock( &p_item->p_stats->lock );
572 #define UPDATE_INT( widget, calc... ) \
573 { widget->setText( 1, QString::number( (qulonglong)calc ) ); }
575 #define UPDATE_FLOAT( widget, format, calc... ) \
576 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
578 UPDATE_INT( read_media_stat, (p_item->p_stats->i_read_bytes / 1024 ) );
579 UPDATE_FLOAT( input_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_input_bitrate * 8000 ));
580 UPDATE_INT( demuxed_stat, (p_item->p_stats->i_demux_read_bytes / 1024 ) );
581 UPDATE_FLOAT( stream_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
582 UPDATE_INT( corrupted_stat, p_item->p_stats->i_demux_corrupted );
583 UPDATE_INT( discontinuity_stat, p_item->p_stats->i_demux_discontinuity );
586 UPDATE_INT( vdecoded_stat, p_item->p_stats->i_decoded_video );
587 UPDATE_INT( vdisplayed_stat, p_item->p_stats->i_displayed_pictures );
588 UPDATE_INT( vlost_frames_stat, p_item->p_stats->i_lost_pictures );
591 UPDATE_INT( send_stat, p_item->p_stats->i_sent_packets );
592 UPDATE_INT( send_bytes_stat, (p_item->p_stats->i_sent_bytes)/ 1024 );
593 UPDATE_FLOAT( send_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_send_bitrate * 8000 ) );
596 UPDATE_INT( adecoded_stat, p_item->p_stats->i_decoded_audio );
597 UPDATE_INT( aplayed_stat, p_item->p_stats->i_played_abuffers );
598 UPDATE_INT( alost_stat, p_item->p_stats->i_lost_abuffers );
603 vlc_mutex_unlock(& p_item->p_stats->lock );
606 void InputStatsPanel::clear()