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 *****************************************************************************/
27 #include "components/infopanels.hpp"
29 #include <QTreeWidget>
31 #include <QPushButton>
32 #include <QHeaderView>
34 #include <QStringList>
35 #include <QGridLayout>
41 /************************************************************************
43 ************************************************************************/
46 * First Panel - Meta Info
47 * All the usual MetaData are displayed and can be changed.
49 MetaPanel::MetaPanel( QWidget *parent,
50 intf_thread_t *_p_intf )
51 : QWidget( parent ), p_intf( _p_intf )
53 QGridLayout *metaLayout = new QGridLayout( this );
55 int line = 0; /* Counter for GridLayout */
58 #define ADD_META( string, widget ) { \
59 metaLayout->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
60 widget = new QLineEdit; \
61 metaLayout->addWidget( widget, line, 1, 1, 9 ); \
64 /* Title, artist and album*/
65 ADD_META( VLC_META_TITLE, title_text ); /* OK */
66 ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
67 ADD_META( VLC_META_COLLECTION, collection_text ); /* OK */
70 /* FIXME List id3genres.h is not includable yet ? */
71 genre_text = new QLineEdit;
72 metaLayout->addWidget( new QLabel( qtr( VLC_META_GENRE ) + " :" ), line, 0 );
73 metaLayout->addWidget( genre_text, line, 1, 1, 4 );
75 /* Number - on the same line */
76 metaLayout->addWidget( new QLabel( qtr( "Track Number" ) + " :" ),
78 seqnum_text = new QLineEdit;
79 seqnum_text->setInputMask("0000");
80 seqnum_text->setAlignment( Qt::AlignRight );
81 metaLayout->addWidget( seqnum_text, line, 7, 1, 3 );
84 /* Date (Should be in years) */
85 date_text = new QLineEdit;
86 date_text->setInputMask("0000");
87 date_text->setAlignment( Qt::AlignRight );
88 metaLayout->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 0 );
89 metaLayout->addWidget( date_text, line, 1, 1, 3 );
91 /* Rating - on the same line */
93 metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 4, 1, 2 );
94 rating_text = new QSpinBox; setSpinBounds( rating_text );
95 metaLayout->addWidget( rating_text, line, 6, 1, 1 );
97 /* Language on the same line */
98 metaLayout->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 7, 1, 2 );
99 language_text = new QLineEdit;
100 language_text->setReadOnly( true );
101 metaLayout->addWidget( language_text, line, 9, 1, 1 );
105 art_cover = new QLabel( "" );
106 art_cover->setMinimumHeight( 128 );
107 art_cover->setMinimumWidth( 128 );
108 art_cover->setMaximumHeight( 128 );
109 art_cover->setMaximumWidth( 128 );
110 art_cover->setScaledContents( true );
111 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
112 metaLayout->addWidget( art_cover, line, 8, 4, 2 );
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 ); \
126 /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
127 ADD_META_2( VLC_META_NOW_PLAYING, nowplaying_text );
128 nowplaying_text->setReadOnly( true );
129 ADD_META_2( VLC_META_PUBLISHER, publisher_text );
130 ADD_META_2( VLC_META_COPYRIGHT, copyright_text );
131 ADD_META_2( "Comments", description_text );
133 /* useless metadata */
135 //ADD_META_2( VLC_META_ENCODED_BY, encodedby_text );
136 /* ADD_META( TRACKID ) Useless ? */
137 /* ADD_URI - DO not show it, done outside */
142 CONNECT( title_text, textEdited( QString ), this, enterEditMode() );
143 CONNECT( artist_text, textEdited( QString ), this, enterEditMode() );
144 CONNECT( collection_text, textEdited( QString ), this, enterEditMode() );
145 CONNECT( genre_text, textEdited( QString ), this, enterEditMode() );
146 CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
148 CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
149 CONNECT( description_text, textEdited( QString ), this, enterEditMode() );
150 /* CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/
152 /* We are not yet in Edit Mode */
153 b_inEditMode = false;
156 MetaPanel::~MetaPanel(){}
159 * Update all the MetaData and art on an "item-changed" event
161 void MetaPanel::update( input_item_t *p_item )
163 /* Don't update if you are in edit mode */
164 if( b_inEditMode ) return;
167 #define UPDATE_META( meta, widget ) { \
168 psz_meta = input_item_Get##meta( p_item ); \
169 if( !EMPTY_STR( psz_meta ) ) \
170 widget->setText( qfu( psz_meta ) ); \
172 widget->setText( "" ); } \
175 #define UPDATE_META_INT( meta, widget ) { \
176 psz_meta = input_item_Get##meta( p_item ); \
177 if( !EMPTY_STR( psz_meta ) ) \
178 widget->setValue( atoi( psz_meta ) ); } \
182 psz_meta = input_item_GetTitle( p_item );
183 char *psz_name = input_item_GetName( p_item );
184 if( !EMPTY_STR( psz_meta ) )
185 title_text->setText( qfu( psz_meta ) );
186 else if( !EMPTY_STR( psz_name ) )
187 title_text->setText( qfu( psz_name ) );
188 else title_text->setText( "" );
193 psz_meta = input_item_GetURL( p_item );
194 if( !EMPTY_STR( psz_meta ) )
196 emit uriSet( QString( psz_meta ) );
202 psz_meta = input_item_GetURI( p_item );
203 if( !EMPTY_STR( psz_meta ) )
204 emit uriSet( QString( psz_meta ) );
207 /* Other classic though */
208 UPDATE_META( Artist, artist_text );
209 UPDATE_META( Genre, genre_text );
210 UPDATE_META( Copyright, copyright_text );
211 UPDATE_META( Album, collection_text );
212 UPDATE_META( Description, description_text );
213 UPDATE_META( Language, language_text );
214 UPDATE_META( NowPlaying, nowplaying_text );
215 UPDATE_META( Publisher, publisher_text );
216 // UPDATE_META( Setting, setting_text );
217 // UPDATE_META( EncodedBy, encodedby_text );
219 UPDATE_META( Date, date_text );
220 UPDATE_META( TrackNum, seqnum_text );
221 // UPDATE_META_INT( Rating, rating_text );
223 #undef UPDATE_META_INT
227 psz_meta = input_item_GetArtURL( p_item );
228 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
230 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
231 art_cover->setPixmap( QPixmap( artUrl ) );
234 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
239 * Save the MetaData, triggered by parent->save Button
241 void MetaPanel::saveMeta()
243 playlist_t *p_playlist;
246 meta_export_t p_export;
247 p_export.p_item = p_input;
249 if( p_input == NULL )
252 /* we can write meta data only in a file */
253 vlc_mutex_lock( &p_input->lock );
254 int i_type = p_input->i_type;
255 vlc_mutex_unlock( &p_input->lock );
256 if( i_type == ITEM_TYPE_FILE )
258 char *psz_uri_orig = input_item_GetURI( p_input );
259 char *psz_uri = psz_uri_orig;
260 if( !strncmp( psz_uri, "file://", 7 ) )
261 psz_uri += 7; /* strlen("file://") = 7 */
263 p_export.psz_file = strndup( psz_uri, PATH_MAX );
264 free( psz_uri_orig );
269 /* now we read the modified meta data */
270 input_item_SetTitle( p_input, qtu( title_text->text() ) );
271 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
272 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
273 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
274 input_item_SetTrackNum( p_input, qtu( seqnum_text->text() ) );
275 input_item_SetDate( p_input, qtu( date_text->text() ) );
277 input_item_SetCopyright( p_input, qtu( copyright_text->text() ) );
278 input_item_SetPublisher( p_input, qtu( publisher_text->text() ) );
279 input_item_SetDescription( p_input, qtu( description_text->text() ) );
281 p_playlist = pl_Yield( p_intf );
283 p_playlist->p_private = &p_export;
285 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
287 module_Unneed( p_playlist, p_mod );
289 pl_Release( p_playlist );
291 /* Reset the status of the mode. No need to emit any signal */
292 b_inEditMode = false;
296 bool MetaPanel::isInEditMode()
301 void MetaPanel::enterEditMode()
306 void MetaPanel::setEditMode( bool b_editing )
308 b_inEditMode = b_editing;
309 if( b_editing )emit editing();
312 void MetaPanel::setInput( input_item_t *input )
314 if( b_inEditMode ) return;
320 * Clear all the metadata widgets
323 void MetaPanel::clear(){
324 setEditMode( false );
328 * Second Panel - Shows the extra metadata in a tree, non editable.
330 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
331 intf_thread_t *_p_intf )
332 : QWidget( parent ), p_intf( _p_intf )
334 QGridLayout *layout = new QGridLayout(this);
336 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
337 " are shown in this list.\n" ) );
338 topLabel->setWordWrap( true );
339 layout->addWidget( topLabel, 0, 0 );
341 extraMetaTree = new QTreeWidget( this );
342 extraMetaTree->setAlternatingRowColors( true );
343 extraMetaTree->setColumnCount( 2 );
344 extraMetaTree->header()->hide();
345 /* QStringList headerList = ( QStringList() << qtr( "Type" )
346 * << qtr( "Value" ) );
347 * Useless, add this header if you think it would help the user **
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 )
358 vlc_mutex_lock( &p_item->lock );
359 vlc_meta_t *p_meta = p_item->p_meta;
362 QStringList tempItem;
364 QList<QTreeWidgetItem *> items;
365 vlc_dictionary_t * p_dict = &p_meta->extra_tags;
366 char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
367 for (int i = 0; ppsz_allkey[i] ; i++ )
369 const char * psz_value = (const char *)vlc_dictionary_value_for_key(
370 p_dict, ppsz_allkey[i] );
371 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
372 tempItem.append( qfu( psz_value ) );
373 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
374 free( ppsz_allkey[i] );
376 vlc_mutex_unlock( &p_item->lock );
378 extraMetaTree->addTopLevelItems( items );
382 * Clear the ExtraMetaData Tree
384 void ExtraMetaPanel::clear()
386 extraMetaTree->clear();
390 * Third panel - Stream info
391 * Display all codecs and muxers info that we could gather.
393 InfoPanel::InfoPanel( QWidget *parent,
394 intf_thread_t *_p_intf )
395 : QWidget( parent ), p_intf( _p_intf )
397 QGridLayout *layout = new QGridLayout(this);
399 QList<QTreeWidgetItem *> items;
401 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
402 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
404 topLabel->setWordWrap( true );
405 layout->addWidget( topLabel, 0, 0 );
407 InfoTree = new QTreeWidget(this);
408 InfoTree->setColumnCount( 1 );
409 InfoTree->header()->hide();
410 layout->addWidget(InfoTree, 1, 0 );
413 InfoPanel::~InfoPanel()
418 * Update the Codecs information on parent->update()
420 void InfoPanel::update( input_item_t *p_item)
423 QTreeWidgetItem *current_item = NULL;
424 QTreeWidgetItem *child_item = NULL;
426 for( int i = 0; i< p_item->i_categories ; i++)
428 current_item = new QTreeWidgetItem();
429 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
430 InfoTree->addTopLevelItem( current_item );
432 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
434 child_item = new QTreeWidgetItem ();
435 child_item->setText( 0,
436 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
438 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
440 current_item->addChild(child_item);
442 InfoTree->setItemExpanded( current_item, true);
449 void InfoPanel::clear()
455 * Save all the information to a file
456 * Not yet implemented.
459 void InfoPanel::saveCodecsInfo()
464 * Fourth Panel - Stats
465 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
467 InputStatsPanel::InputStatsPanel( QWidget *parent,
468 intf_thread_t *_p_intf )
469 : QWidget( parent ), p_intf( _p_intf )
471 QGridLayout *layout = new QGridLayout(this);
473 QList<QTreeWidgetItem *> items;
475 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
476 " media or stream.\n Played and streamed info are shown." ) );
477 topLabel->setWordWrap( true );
478 layout->addWidget( topLabel, 0, 0 );
480 StatsTree = new QTreeWidget(this);
481 StatsTree->setColumnCount( 3 );
482 StatsTree->header()->hide();
484 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
486 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
487 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
489 #define CREATE_CATEGORY( catName, itemText ) { \
490 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
491 catName->setExpanded( true ); \
492 StatsTree->addTopLevelItem( catName ); }
494 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
495 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
496 catName->addChild( itemName ); }
498 /* Create the main categories */
499 CREATE_CATEGORY( audio, qtr("Audio") );
500 CREATE_CATEGORY( video, qtr("Video") );
501 CREATE_CATEGORY( input, qtr("Input") );
502 CREATE_CATEGORY( streaming, qtr("Streaming") );
504 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
506 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
507 "0", input, "kb/s" );
508 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
509 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
510 "0", input, "kb/s" );
512 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
514 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
516 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
518 CREATE_AND_ADD_TO_CAT( vfps_stat, qtr("FPS"), "0", video, "" );
520 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
521 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
522 "0", streaming, "kB" );
523 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
524 "0", streaming, "kb/s" );
526 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
528 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
530 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
532 input->setExpanded( true );
533 video->setExpanded( true );
534 streaming->setExpanded( true );
535 audio->setExpanded( true );
537 StatsTree->resizeColumnToContents( 0 );
538 StatsTree->setColumnWidth( 1 , 100 );
540 layout->addWidget(StatsTree, 1, 0 );
543 InputStatsPanel::~InputStatsPanel()
548 * Update the Statistics
550 void InputStatsPanel::update( input_item_t *p_item )
552 vlc_mutex_lock( &p_item->p_stats->lock );
554 #define UPDATE( widget, format, calc... ) \
555 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
557 UPDATE( read_media_stat, "%8.0f",
558 (float)(p_item->p_stats->i_read_bytes)/1000);
559 UPDATE( input_bitrate_stat, "%6.0f",
560 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
561 UPDATE( demuxed_stat, "%8.0f",
562 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
563 UPDATE( stream_bitrate_stat, "%6.0f",
564 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
567 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
568 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
569 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
570 /* UPDATE( vfps_stat, "%5f", p_item->p_stats->i_lost_pictures );
571 input_Control( p_input_thread, INPUT_GET_VIDEO_FPS, &f_fps */
574 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
575 UPDATE( send_bytes_stat, "%8.0f",
576 (float)(p_item->p_stats->i_sent_bytes)/1000 );
577 UPDATE( send_bitrate_stat, "%6.0f",
578 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
581 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
582 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
583 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
585 vlc_mutex_unlock(& p_item->p_stats->lock );
588 void InputStatsPanel::clear()