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 *metaLayout = new QGridLayout( this );
54 int line = 0; /* Counter for GridLayout */
57 #define ADD_META( string, widget ) { \
58 metaLayout->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
59 widget = new QLineEdit; \
60 metaLayout->addWidget( widget, line, 1, 1, 9 ); \
64 art_cover = new QLabel( "" );
65 art_cover->setMinimumHeight( 128 );
66 art_cover->setMinimumWidth( 128 );
67 art_cover->setMaximumHeight( 128 );
68 art_cover->setMaximumWidth( 128 );
69 art_cover->setScaledContents( true );
70 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
71 metaLayout->addWidget( art_cover, line, 8, 4, 2 );
73 /* Title, artist and album*/
74 ADD_META( VLC_META_TITLE, title_text ); /* OK */
75 ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
76 ADD_META( VLC_META_COLLECTION, collection_text ); /* OK */
79 /* FIXME List id3genres.h is not includable yet ? */
80 genre_text = new QLineEdit;
81 metaLayout->addWidget( new QLabel( qtr( VLC_META_GENRE ) + " :" ), line, 0 );
82 metaLayout->addWidget( genre_text, line, 1, 1, 2 );
84 /* Number - on the same line */
85 metaLayout->addWidget( new QLabel( qtr( "Track Number" ) + " :" ),
87 seqnum_text = new QLineEdit;
88 seqnum_text->setInputMask("0000");
89 seqnum_text->setAlignment( Qt::AlignRight );
90 metaLayout->addWidget( seqnum_text, line, 4, 1, 2 );
93 /* Date (Should be in years) */
94 date_text = new QLineEdit;
95 date_text->setInputMask("0000");
96 date_text->setAlignment( Qt::AlignRight );
97 metaLayout->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 0 );
98 metaLayout->addWidget( date_text, line, 1, 1, 1 );
100 /* Rating - on the same line */
101 metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 2 );
102 rating_text = new QSpinBox; setSpinBounds( rating_text );
103 metaLayout->addWidget( rating_text, line, 3, 1, 1 );
105 /* Language on the same line */
106 metaLayout->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 4 );
107 language_text = new QLineEdit;
108 metaLayout->addWidget( language_text, line, 5, 1, 1 );
111 /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
112 ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
114 /* Settings is unused */
115 /* l->addWidget( new QLabel( qtr( VLC_META_SETTING ) + " :" ), line, 5 );
116 setting_text = new QLineEdit;
117 l->addWidget( setting_text, line, 6, 1, 4 ); */
119 /* Less used metadata */
120 #define ADD_META_2( string, widget ) { \
121 metaLayout->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
122 widget = new QLineEdit; \
123 metaLayout->addWidget( widget, line, 1, 1, 7 ); \
125 ADD_META_2( VLC_META_PUBLISHER, publisher_text );
126 ADD_META_2( VLC_META_COPYRIGHT, copyright_text );
127 ADD_META_2( "Comments:", description_text );
129 /* useless metadata */
131 //ADD_META_2( VLC_META_ENCODED_BY, encodedby_text );
132 /* ADD_META( TRACKID ) Useless ? */
133 /* ADD_URI - DO not show it, done outside */
138 CONNECT( title_text, textEdited( QString ), this, enterEditMode() );
139 CONNECT( description_text, textEdited( QString ), this, enterEditMode() );
140 CONNECT( artist_text, textEdited( QString ), this, enterEditMode() );
141 CONNECT( collection_text, textEdited( QString ), this, enterEditMode() );
142 CONNECT( genre_text, textEdited( QString ), this, enterEditMode() );
143 CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
144 CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
145 /* CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/
147 /* We are not yet in Edit Mode */
148 b_inEditMode = false;
151 MetaPanel::~MetaPanel(){}
154 * Update all the MetaData and art on an "item-changed" event
156 void MetaPanel::update( input_item_t *p_item )
158 /* Don't update if you are in edit mode */
159 if( b_inEditMode ) return;
162 #define UPDATE_META( meta, widget ) { \
163 psz_meta = input_item_Get##meta( p_item ); \
164 if( !EMPTY_STR( psz_meta ) ) \
165 widget->setText( qfu( psz_meta ) ); \
167 widget->setText( "" ); } \
170 #define UPDATE_META_INT( meta, widget ) { \
171 psz_meta = input_item_Get##meta( p_item ); \
172 if( !EMPTY_STR( psz_meta ) ) \
173 widget->setValue( atoi( psz_meta ) ); } \
177 psz_meta = input_item_GetTitle( p_item );
178 char *psz_name = input_item_GetName( p_item );
179 if( !EMPTY_STR( psz_meta ) )
180 title_text->setText( qfu( psz_meta ) );
181 else if( !EMPTY_STR( psz_name ) )
182 title_text->setText( qfu( psz_name ) );
183 else title_text->setText( "" );
188 psz_meta = input_item_GetURL( p_item );
189 if( !EMPTY_STR( psz_meta ) )
191 emit uriSet( QString( psz_meta ) );
197 psz_meta = input_item_GetURI( p_item );
198 if( !EMPTY_STR( psz_meta ) )
199 emit uriSet( QString( psz_meta ) );
202 /* Other classic though */
203 UPDATE_META( Artist, artist_text );
204 UPDATE_META( Genre, genre_text );
205 UPDATE_META( Copyright, copyright_text );
206 UPDATE_META( Album, collection_text );
207 UPDATE_META( Description, description_text );
208 UPDATE_META( Language, language_text );
209 UPDATE_META( NowPlaying, nowplaying_text );
210 UPDATE_META( Publisher, publisher_text );
211 // UPDATE_META( Setting, setting_text );
212 // UPDATE_META( EncodedBy, encodedby_text );
214 UPDATE_META( Date, date_text );
215 UPDATE_META( TrackNum, seqnum_text );
216 UPDATE_META_INT( Rating, rating_text );
218 #undef UPDATE_META_INT
222 psz_meta = input_item_GetArtURL( p_item );
223 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
225 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
226 art_cover->setPixmap( QPixmap( artUrl ) );
229 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
234 * Save the MetaData, triggered by parent->save Button
236 void MetaPanel::saveMeta()
238 playlist_t *p_playlist;
241 meta_export_t p_export;
242 p_export.p_item = p_input;
244 if( p_input == NULL )
247 /* we can write meta data only in a file */
248 vlc_mutex_lock( &p_input->lock );
249 int i_type = p_input->i_type;
250 vlc_mutex_unlock( &p_input->lock );
251 if( i_type == ITEM_TYPE_FILE )
253 char *psz_uri_orig = input_item_GetURI( p_input );
254 char *psz_uri = psz_uri_orig;
255 if( !strncmp( psz_uri, "file://", 7 ) )
256 psz_uri += 7; /* strlen("file://") = 7 */
258 p_export.psz_file = strndup( psz_uri, PATH_MAX );
259 free( psz_uri_orig );
264 /* now we read the modified meta data */
265 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
266 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
267 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
269 input_item_SetDate( p_input, qtu( date_text->text() ) );
271 input_item_SetTrackNum( p_input, qtu( seqnum_text->text() ) );
273 input_item_SetTitle( p_input, qtu( title_text->text() ) );
275 p_playlist = pl_Yield( p_intf );
278 p_playlist->p_private = &p_export;
280 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
282 module_Unneed( p_playlist, p_mod );
284 pl_Release( p_playlist );
285 b_inEditMode = false;
289 bool MetaPanel::isInEditMode()
294 void MetaPanel::enterEditMode()
299 void MetaPanel::setEditMode( bool b_editing )
301 b_inEditMode = b_editing;
302 if( b_editing )emit editing();
305 void MetaPanel::setInput( input_item_t *input )
307 if( b_inEditMode ) return;
313 * Clear all the metadata widgets
316 void MetaPanel::clear(){
317 setEditMode( false );
321 * Second Panel - Shows the extra metadata in a tree, non editable.
323 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
324 intf_thread_t *_p_intf )
325 : QWidget( parent ), p_intf( _p_intf )
327 QGridLayout *layout = new QGridLayout(this);
329 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
330 " are shown in this list.\n" ) );
331 topLabel->setWordWrap( true );
332 layout->addWidget( topLabel, 0, 0 );
334 extraMetaTree = new QTreeWidget( this );
335 extraMetaTree->setAlternatingRowColors( true );
336 extraMetaTree->setColumnCount( 2 );
337 extraMetaTree->header()->hide();
338 /* QStringList headerList = ( QStringList() << qtr( "Type" )
339 * << qtr( "Value" ) );
340 * Useless, add this header if you think it would help the user **
343 layout->addWidget( extraMetaTree, 1, 0 );
347 * Update the Extra Metadata from p_meta->i_extras
349 void ExtraMetaPanel::update( input_item_t *p_item )
351 vlc_mutex_lock( &p_item->lock );
352 vlc_meta_t *p_meta = p_item->p_meta;
355 QStringList tempItem;
357 QList<QTreeWidgetItem *> items;
358 vlc_dictionary_t * p_dict = &p_meta->extra_tags;
359 char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
360 for (int i = 0; ppsz_allkey[i] ; i++ )
362 const char * psz_value = (const char *)vlc_dictionary_value_for_key(
363 p_dict, ppsz_allkey[i] );
364 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
365 tempItem.append( qfu( psz_value ) );
366 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
367 free( ppsz_allkey[i] );
369 vlc_mutex_unlock( &p_item->lock );
371 extraMetaTree->addTopLevelItems( items );
375 * Clear the ExtraMetaData Tree
377 void ExtraMetaPanel::clear()
379 extraMetaTree->clear();
383 * Third panel - Stream info
384 * Display all codecs and muxers info that we could gather.
386 InfoPanel::InfoPanel( QWidget *parent,
387 intf_thread_t *_p_intf )
388 : QWidget( parent ), p_intf( _p_intf )
390 QGridLayout *layout = new QGridLayout(this);
392 QList<QTreeWidgetItem *> items;
394 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
395 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
397 topLabel->setWordWrap( true );
398 layout->addWidget( topLabel, 0, 0 );
400 InfoTree = new QTreeWidget(this);
401 InfoTree->setColumnCount( 1 );
402 InfoTree->header()->hide();
403 layout->addWidget(InfoTree, 1, 0 );
406 InfoPanel::~InfoPanel()
411 * Update the Codecs information on parent->update()
413 void InfoPanel::update( input_item_t *p_item)
416 QTreeWidgetItem *current_item = NULL;
417 QTreeWidgetItem *child_item = NULL;
419 for( int i = 0; i< p_item->i_categories ; i++)
421 current_item = new QTreeWidgetItem();
422 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
423 InfoTree->addTopLevelItem( current_item );
425 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
427 child_item = new QTreeWidgetItem ();
428 child_item->setText( 0,
429 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
431 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
433 current_item->addChild(child_item);
435 InfoTree->setItemExpanded( current_item, true);
442 void InfoPanel::clear()
448 * Save all the information to a file
449 * Not yet implemented.
452 void InfoPanel::saveCodecsInfo()
459 * Fourth Panel - Stats
460 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
462 InputStatsPanel::InputStatsPanel( QWidget *parent,
463 intf_thread_t *_p_intf )
464 : QWidget( parent ), p_intf( _p_intf )
466 QGridLayout *layout = new QGridLayout(this);
468 QList<QTreeWidgetItem *> items;
470 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
471 " media or stream.\n Played and streamed info are shown." ) );
472 topLabel->setWordWrap( true );
473 layout->addWidget( topLabel, 0, 0 );
475 StatsTree = new QTreeWidget(this);
476 StatsTree->setColumnCount( 3 );
477 StatsTree->header()->hide();
479 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
481 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
482 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
484 #define CREATE_CATEGORY( catName, itemText ) { \
485 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
486 catName->setExpanded( true ); \
487 StatsTree->addTopLevelItem( catName ); }
489 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
490 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
491 catName->addChild( itemName ); }
493 /* Create the main categories */
494 CREATE_CATEGORY( input, qtr("Input") );
495 CREATE_CATEGORY( video, qtr("Video") );
496 CREATE_CATEGORY( streaming, qtr("Streaming") );
497 CREATE_CATEGORY( audio, qtr("Audio") );
499 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
501 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
502 "0", input, "kb/s" );
503 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
504 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
505 "0", input, "kb/s" );
507 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
509 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
511 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
514 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
515 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
516 "0", streaming, "kB" );
517 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
518 "0", streaming, "kb/s" );
520 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
522 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
524 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
526 input->setExpanded( true );
527 video->setExpanded( true );
528 streaming->setExpanded( true );
529 audio->setExpanded( true );
531 StatsTree->resizeColumnToContents( 0 );
532 StatsTree->setColumnWidth( 1 , 100 );
534 layout->addWidget(StatsTree, 1, 0 );
537 InputStatsPanel::~InputStatsPanel()
542 * Update the Statistics
544 void InputStatsPanel::update( input_item_t *p_item )
546 vlc_mutex_lock( &p_item->p_stats->lock );
548 #define UPDATE( widget, format, calc... ) \
549 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
551 UPDATE( read_media_stat, "%8.0f",
552 (float)(p_item->p_stats->i_read_bytes)/1000);
553 UPDATE( input_bitrate_stat, "%6.0f",
554 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
555 UPDATE( demuxed_stat, "%8.0f",
556 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
557 UPDATE( stream_bitrate_stat, "%6.0f",
558 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
561 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
562 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
563 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
566 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
567 UPDATE( send_bytes_stat, "%8.0f",
568 (float)(p_item->p_stats->i_sent_bytes)/1000 );
569 UPDATE( send_bitrate_stat, "%6.0f",
570 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
573 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
574 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
575 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
577 vlc_mutex_unlock(& p_item->p_stats->lock );
580 void InputStatsPanel::clear()