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 ); \
63 /* Title, artist and album*/
64 ADD_META( VLC_META_TITLE, title_text ); /* OK */
65 ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
66 ADD_META( VLC_META_COLLECTION, collection_text ); /* OK */
69 /* FIXME List id3genres.h is not includable yet ? */
70 genre_text = new QLineEdit;
71 metaLayout->addWidget( new QLabel( qtr( VLC_META_GENRE ) + " :" ), line, 0 );
72 metaLayout->addWidget( genre_text, line, 1, 1, 5 );
74 /* Number - on the same line */
75 metaLayout->addWidget( new QLabel( qtr( "Track Number" ) + " :" ),
77 seqnum_text = new QLineEdit;
78 seqnum_text->setInputMask("0000");
79 seqnum_text->setAlignment( Qt::AlignRight );
80 metaLayout->addWidget( seqnum_text, line, 7, 1, 4 );
83 /* Date (Should be in years) */
84 date_text = new QLineEdit;
85 date_text->setInputMask("0000");
86 date_text->setAlignment( Qt::AlignRight );
87 metaLayout->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 0 );
88 metaLayout->addWidget( date_text, line, 1, 1, 2 );
90 /* Rating - on the same line */
91 metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 3, 1, 2 );
92 rating_text = new QSpinBox; setSpinBounds( rating_text );
93 metaLayout->addWidget( rating_text, line, 5, 1, 2 );
95 /* Language on the same line */
96 metaLayout->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 7 );
97 language_text = new QLineEdit;
98 metaLayout->addWidget( language_text, line, 8, 1, 2 );
102 art_cover = new QLabel( "" );
103 art_cover->setMinimumHeight( 128 );
104 art_cover->setMinimumWidth( 128 );
105 art_cover->setMaximumHeight( 128 );
106 art_cover->setMaximumWidth( 128 );
107 art_cover->setScaledContents( true );
108 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
109 metaLayout->addWidget( art_cover, line, 8, 4, 2 );
111 /* Settings is unused */
112 /* l->addWidget( new QLabel( qtr( VLC_META_SETTING ) + " :" ), line, 5 );
113 setting_text = new QLineEdit;
114 l->addWidget( setting_text, line, 6, 1, 4 ); */
116 /* Less used metadata */
117 #define ADD_META_2( string, widget ) { \
118 metaLayout->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
119 widget = new QLineEdit; \
120 metaLayout->addWidget( widget, line, 1, 1, 7 ); \
123 /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
124 ADD_META_2( VLC_META_NOW_PLAYING, nowplaying_text );
125 nowplaying_text->setReadOnly( true );
126 ADD_META_2( VLC_META_PUBLISHER, publisher_text );
127 ADD_META_2( VLC_META_COPYRIGHT, copyright_text );
128 ADD_META_2( "Comments:", description_text );
130 /* useless metadata */
132 //ADD_META_2( VLC_META_ENCODED_BY, encodedby_text );
133 /* ADD_META( TRACKID ) Useless ? */
134 /* ADD_URI - DO not show it, done outside */
139 CONNECT( title_text, textEdited( QString ), this, enterEditMode() );
140 CONNECT( description_text, textEdited( QString ), this, enterEditMode() );
141 CONNECT( artist_text, textEdited( QString ), this, enterEditMode() );
142 CONNECT( collection_text, textEdited( QString ), this, enterEditMode() );
143 CONNECT( genre_text, textEdited( QString ), this, enterEditMode() );
144 CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
145 CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
146 /* CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/
148 /* We are not yet in Edit Mode */
149 b_inEditMode = false;
152 MetaPanel::~MetaPanel(){}
155 * Update all the MetaData and art on an "item-changed" event
157 void MetaPanel::update( input_item_t *p_item )
159 /* Don't update if you are in edit mode */
160 if( b_inEditMode ) return;
163 #define UPDATE_META( meta, widget ) { \
164 psz_meta = input_item_Get##meta( p_item ); \
165 if( !EMPTY_STR( psz_meta ) ) \
166 widget->setText( qfu( psz_meta ) ); \
168 widget->setText( "" ); } \
171 #define UPDATE_META_INT( meta, widget ) { \
172 psz_meta = input_item_Get##meta( p_item ); \
173 if( !EMPTY_STR( psz_meta ) ) \
174 widget->setValue( atoi( psz_meta ) ); } \
178 psz_meta = input_item_GetTitle( p_item );
179 char *psz_name = input_item_GetName( p_item );
180 if( !EMPTY_STR( psz_meta ) )
181 title_text->setText( qfu( psz_meta ) );
182 else if( !EMPTY_STR( psz_name ) )
183 title_text->setText( qfu( psz_name ) );
184 else title_text->setText( "" );
189 psz_meta = input_item_GetURL( p_item );
190 if( !EMPTY_STR( psz_meta ) )
192 emit uriSet( QString( psz_meta ) );
198 psz_meta = input_item_GetURI( p_item );
199 if( !EMPTY_STR( psz_meta ) )
200 emit uriSet( QString( psz_meta ) );
203 /* Other classic though */
204 UPDATE_META( Artist, artist_text );
205 UPDATE_META( Genre, genre_text );
206 UPDATE_META( Copyright, copyright_text );
207 UPDATE_META( Album, collection_text );
208 UPDATE_META( Description, description_text );
209 UPDATE_META( Language, language_text );
210 UPDATE_META( NowPlaying, nowplaying_text );
211 UPDATE_META( Publisher, publisher_text );
212 // UPDATE_META( Setting, setting_text );
213 // UPDATE_META( EncodedBy, encodedby_text );
215 UPDATE_META( Date, date_text );
216 UPDATE_META( TrackNum, seqnum_text );
217 UPDATE_META_INT( Rating, rating_text );
219 #undef UPDATE_META_INT
223 psz_meta = input_item_GetArtURL( p_item );
224 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
226 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
227 art_cover->setPixmap( QPixmap( artUrl ) );
230 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
235 * Save the MetaData, triggered by parent->save Button
237 void MetaPanel::saveMeta()
239 playlist_t *p_playlist;
242 meta_export_t p_export;
243 p_export.p_item = p_input;
245 if( p_input == NULL )
248 /* we can write meta data only in a file */
249 vlc_mutex_lock( &p_input->lock );
250 int i_type = p_input->i_type;
251 vlc_mutex_unlock( &p_input->lock );
252 if( i_type == ITEM_TYPE_FILE )
254 char *psz_uri_orig = input_item_GetURI( p_input );
255 char *psz_uri = psz_uri_orig;
256 if( !strncmp( psz_uri, "file://", 7 ) )
257 psz_uri += 7; /* strlen("file://") = 7 */
259 p_export.psz_file = strndup( psz_uri, PATH_MAX );
260 free( psz_uri_orig );
265 /* now we read the modified meta data */
266 input_item_SetTitle( p_input, qtu( title_text->text() ) );
267 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
268 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
269 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
270 input_item_SetTrackNum( p_input, qtu( seqnum_text->text() ) );
271 input_item_SetDate( p_input, qtu( date_text->text() ) );
273 input_item_SetCopyright( p_input, qtu( copyright_text->text() ) );
274 input_item_SetPublisher( p_input, qtu( publisher_text->text() ) );
275 input_item_SetDescription( p_input, qtu( description_text->text() ) );
277 p_playlist = pl_Yield( p_intf );
279 p_playlist->p_private = &p_export;
281 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
283 module_Unneed( p_playlist, p_mod );
285 pl_Release( p_playlist );
287 /* Reset the status of the mode. No need to emit any signal */
288 b_inEditMode = false;
292 bool MetaPanel::isInEditMode()
297 void MetaPanel::enterEditMode()
302 void MetaPanel::setEditMode( bool b_editing )
304 b_inEditMode = b_editing;
305 if( b_editing )emit editing();
308 void MetaPanel::setInput( input_item_t *input )
310 if( b_inEditMode ) return;
316 * Clear all the metadata widgets
319 void MetaPanel::clear(){
320 setEditMode( false );
324 * Second Panel - Shows the extra metadata in a tree, non editable.
326 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
327 intf_thread_t *_p_intf )
328 : QWidget( parent ), p_intf( _p_intf )
330 QGridLayout *layout = new QGridLayout(this);
332 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
333 " are shown in this list.\n" ) );
334 topLabel->setWordWrap( true );
335 layout->addWidget( topLabel, 0, 0 );
337 extraMetaTree = new QTreeWidget( this );
338 extraMetaTree->setAlternatingRowColors( true );
339 extraMetaTree->setColumnCount( 2 );
340 extraMetaTree->header()->hide();
341 /* QStringList headerList = ( QStringList() << qtr( "Type" )
342 * << qtr( "Value" ) );
343 * Useless, add this header if you think it would help the user **
346 layout->addWidget( extraMetaTree, 1, 0 );
350 * Update the Extra Metadata from p_meta->i_extras
352 void ExtraMetaPanel::update( input_item_t *p_item )
354 vlc_mutex_lock( &p_item->lock );
355 vlc_meta_t *p_meta = p_item->p_meta;
358 QStringList tempItem;
360 QList<QTreeWidgetItem *> items;
361 vlc_dictionary_t * p_dict = &p_meta->extra_tags;
362 char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
363 for (int i = 0; ppsz_allkey[i] ; i++ )
365 const char * psz_value = (const char *)vlc_dictionary_value_for_key(
366 p_dict, ppsz_allkey[i] );
367 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
368 tempItem.append( qfu( psz_value ) );
369 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
370 free( ppsz_allkey[i] );
372 vlc_mutex_unlock( &p_item->lock );
374 extraMetaTree->addTopLevelItems( items );
378 * Clear the ExtraMetaData Tree
380 void ExtraMetaPanel::clear()
382 extraMetaTree->clear();
386 * Third panel - Stream info
387 * Display all codecs and muxers info that we could gather.
389 InfoPanel::InfoPanel( QWidget *parent,
390 intf_thread_t *_p_intf )
391 : QWidget( parent ), p_intf( _p_intf )
393 QGridLayout *layout = new QGridLayout(this);
395 QList<QTreeWidgetItem *> items;
397 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
398 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
400 topLabel->setWordWrap( true );
401 layout->addWidget( topLabel, 0, 0 );
403 InfoTree = new QTreeWidget(this);
404 InfoTree->setColumnCount( 1 );
405 InfoTree->header()->hide();
406 layout->addWidget(InfoTree, 1, 0 );
409 InfoPanel::~InfoPanel()
414 * Update the Codecs information on parent->update()
416 void InfoPanel::update( input_item_t *p_item)
419 QTreeWidgetItem *current_item = NULL;
420 QTreeWidgetItem *child_item = NULL;
422 for( int i = 0; i< p_item->i_categories ; i++)
424 current_item = new QTreeWidgetItem();
425 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
426 InfoTree->addTopLevelItem( current_item );
428 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
430 child_item = new QTreeWidgetItem ();
431 child_item->setText( 0,
432 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
434 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
436 current_item->addChild(child_item);
438 InfoTree->setItemExpanded( current_item, true);
445 void InfoPanel::clear()
451 * Save all the information to a file
452 * Not yet implemented.
455 void InfoPanel::saveCodecsInfo()
462 * Fourth Panel - Stats
463 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
465 InputStatsPanel::InputStatsPanel( QWidget *parent,
466 intf_thread_t *_p_intf )
467 : QWidget( parent ), p_intf( _p_intf )
469 QGridLayout *layout = new QGridLayout(this);
471 QList<QTreeWidgetItem *> items;
473 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
474 " media or stream.\n Played and streamed info are shown." ) );
475 topLabel->setWordWrap( true );
476 layout->addWidget( topLabel, 0, 0 );
478 StatsTree = new QTreeWidget(this);
479 StatsTree->setColumnCount( 3 );
480 StatsTree->header()->hide();
482 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
484 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
485 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
487 #define CREATE_CATEGORY( catName, itemText ) { \
488 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
489 catName->setExpanded( true ); \
490 StatsTree->addTopLevelItem( catName ); }
492 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
493 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
494 catName->addChild( itemName ); }
496 /* Create the main categories */
497 CREATE_CATEGORY( input, qtr("Input") );
498 CREATE_CATEGORY( video, qtr("Video") );
499 CREATE_CATEGORY( streaming, qtr("Streaming") );
500 CREATE_CATEGORY( audio, qtr("Audio") );
502 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
504 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
505 "0", input, "kb/s" );
506 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
507 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
508 "0", input, "kb/s" );
510 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
512 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
514 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
517 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
518 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
519 "0", streaming, "kB" );
520 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
521 "0", streaming, "kb/s" );
523 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
525 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
527 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
529 input->setExpanded( true );
530 video->setExpanded( true );
531 streaming->setExpanded( true );
532 audio->setExpanded( true );
534 StatsTree->resizeColumnToContents( 0 );
535 StatsTree->setColumnWidth( 1 , 100 );
537 layout->addWidget(StatsTree, 1, 0 );
540 InputStatsPanel::~InputStatsPanel()
545 * Update the Statistics
547 void InputStatsPanel::update( input_item_t *p_item )
549 vlc_mutex_lock( &p_item->p_stats->lock );
551 #define UPDATE( widget, format, calc... ) \
552 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
554 UPDATE( read_media_stat, "%8.0f",
555 (float)(p_item->p_stats->i_read_bytes)/1000);
556 UPDATE( input_bitrate_stat, "%6.0f",
557 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
558 UPDATE( demuxed_stat, "%8.0f",
559 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
560 UPDATE( stream_bitrate_stat, "%6.0f",
561 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
564 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
565 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
566 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
569 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
570 UPDATE( send_bytes_stat, "%8.0f",
571 (float)(p_item->p_stats->i_sent_bytes)/1000 );
572 UPDATE( send_bitrate_stat, "%6.0f",
573 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
576 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
577 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
578 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
580 vlc_mutex_unlock(& p_item->p_stats->lock );
583 void InputStatsPanel::clear()