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 *l = new QGridLayout( this );
53 int line = 0; /* Counter for GridLayout */
56 #define ADD_META( string, widget ) { \
57 l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
58 widget = new QLineEdit; \
59 l->addWidget( widget, line, 1, 1, 5 ); \
63 art_cover = new QLabel( "" );
64 art_cover->setMinimumHeight( 128 );
65 art_cover->setMinimumWidth( 128 );
66 art_cover->setMaximumHeight( 128 );
67 art_cover->setMaximumWidth( 128 );
68 art_cover->setScaledContents( true );
69 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
70 l->addWidget( art_cover, line, 6, 4, 2 );
72 /* Title, artist and album*/
73 ADD_META( VLC_META_TITLE, title_text ); /* OK */
74 ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
75 ADD_META( VLC_META_COLLECTION, collection_text ); /* OK */
78 /* FIXME List id3genres.h is not includable yet ? */
79 genre_text = new QLineEdit;
80 l->addWidget( new QLabel( qtr( VLC_META_GENRE ) + " :" ), line, 0 );
81 l->addWidget( genre_text, line, 1, 1, 2 );
84 l->addWidget( new QLabel( qtr( "Track Number" ) + " :" ),
86 seqnum_text = new QSpinBox; setSpinBounds( seqnum_text );
87 l->addWidget( seqnum_text, line, 4, 1, 2 );
90 /* Date (Should be in years) */
91 date_text = new QSpinBox; setSpinBounds( date_text );
92 l->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 0 );
93 l->addWidget( date_text, line, 1, 1, 1 );
97 l->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 2 );
98 rating_text = new QSpinBox; setSpinBounds( rating_text) ;
99 l->addWidget( rating_text, line, 3, 1, 1 );
102 // ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
104 /* Language and settings */
105 l->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 4 );
106 language_text = new QLineEdit;
107 l->addWidget( language_text, line, 5, 1, 1 );
108 /* l->addWidget( new QLabel( qtr( VLC_META_SETTING ) + " :" ), line, 5 );
109 setting_text = new QLineEdit;
110 l->addWidget( setting_text, line, 6, 1, 4 );
114 #define ADD_META_2( string, widget ) { \
115 l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
116 widget = new QLineEdit; \
117 l->addWidget( widget, line, 1, 1, 7 ); \
120 ADD_META_2( VLC_META_COPYRIGHT, copyright_text );
121 ADD_META_2( VLC_META_PUBLISHER, publisher_text );
123 ADD_META_2( VLC_META_ENCODED_BY, encodedby_text );
124 ADD_META_2( VLC_META_DESCRIPTION, description_text );
126 /* ADD_META( TRACKID ) Useless ? */
127 /* ADD_URI - DO not show it, done outside */
133 CONNECT( title_text, textEdited( QString ), this, editMeta( QString ) );
134 // CONNECT( description_text, textEdited( QString ), this, editMeta( QString ) );
135 CONNECT( artist_text, textEdited( QString ), this, editMeta( QString ) );
136 CONNECT( collection_text, textEdited( QString ), this, editMeta( QString ) );
137 CONNECT( genre_text, textEdited( QString ), this, editMeta( QString ) );
138 CONNECT( date_text, valueChanged( QString ), this, editMeta( QString ) );
139 CONNECT( seqnum_text, valueChanged( QString ), this, editMeta( QString ) );
140 CONNECT( rating_text, valueChanged( QString ), this, editMeta( QString ) );
144 MetaPanel::~MetaPanel(){}
147 * Save the MetaData, triggered by parent->save Button
149 void MetaPanel::saveMeta()
151 playlist_t *p_playlist;
154 meta_export_t p_export;
155 p_export.p_item = p_input;
157 if( p_input == NULL )
160 /* we can write meta data only in a file */
161 if( ( p_input->i_type == ITEM_TYPE_AFILE ) || \
162 ( p_input->i_type == ITEM_TYPE_VFILE ) )
163 /* some audio files are detected as video files */
165 char *psz_uri = p_input->psz_uri;
166 if( !strncmp( psz_uri, "file://", 7 ) )
167 psz_uri += 7; /* strlen("file://") = 7 */
169 p_export.psz_file = strndup( psz_uri, PATH_MAX );
174 /* now we read the modified meta data */
175 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
176 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
177 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
179 snprintf( psz, sizeof(psz), "%d", date_text->value() );
180 input_item_SetDate( p_input, psz );
182 snprintf( psz, sizeof(psz), "%d", seqnum_text->value() );
183 input_item_SetTrackNum( p_input, psz );
185 input_item_SetTitle( p_input, qtu( title_text->text() ) );
187 p_playlist = pl_Yield( p_intf );
190 p_playlist->p_private = &p_export;
192 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
194 module_Unneed( p_playlist, p_mod );
196 pl_Release( p_playlist );
200 void MetaPanel::editMeta( QString edit )
206 void MetaPanel::setEdit( bool editing )
211 void MetaPanel::setInput( input_item_t *input )
213 if( in_edit ) return;
219 * Update all the MetaData and art on an "item-changed" event
221 void MetaPanel::update( input_item_t *p_item )
223 if( in_edit ) return;
225 #define UPDATE_META( meta, widget ) { \
226 psz_meta = input_item_Get##meta( p_item ); \
227 if( !EMPTY_STR( psz_meta ) ) \
228 widget->setText( qfu( psz_meta ) ); \
230 widget->setText( "" ); } \
233 #define UPDATE_META_INT( meta, widget ) { \
234 psz_meta = input_item_Get##meta( p_item ); \
235 if( !EMPTY_STR( psz_meta ) ) \
236 widget->setValue( atoi( psz_meta ) ); } \
241 psz_meta = input_item_GetTitle( p_item );
242 if( !EMPTY_STR( psz_meta ) )
243 title_text->setText( qfu( psz_meta ) );
244 else if( !EMPTY_STR( p_item->psz_name ) )
245 title_text->setText( qfu( p_item->psz_name ) );
246 else title_text->setText( "" );
250 psz_meta = input_item_GetURL( p_item );
251 if( !EMPTY_STR( psz_meta ) )
252 emit uriSet( QString( psz_meta ) );
253 else if( !EMPTY_STR( p_item->psz_uri ) )
254 emit uriSet( QString( p_item->psz_uri ) );
257 /* Other classic though */
258 UPDATE_META( Artist, artist_text );
259 UPDATE_META( Genre, genre_text );
260 // UPDATE_META( Copyright, copyright_text );
261 UPDATE_META( Album, collection_text );
262 // UPDATE_META( Description, description_text );
263 UPDATE_META( Language, language_text );
264 // UPDATE_META( NowPlaying, nowplaying_text );
265 // UPDATE_META( Publisher, publisher_text );
266 // UPDATE_META( Setting, setting_text );
267 // UPDATE_META( EncodedBy, encodedby_text );
269 UPDATE_META_INT( Date, date_text );
270 UPDATE_META_INT( TrackNum, seqnum_text );
271 UPDATE_META_INT( Rating, rating_text );
273 #undef UPDATE_META_INT
277 psz_meta = input_item_GetArtURL( p_item );
278 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
280 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
281 art_cover->setPixmap( QPixmap( artUrl ) );
284 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
289 * Clear all the metadata widgets
292 void MetaPanel::clear(){}
295 * Second Panel - Shows the extra metadata in a tree, non editable.
297 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
298 intf_thread_t *_p_intf )
299 : QWidget( parent ), p_intf( _p_intf )
301 QGridLayout *layout = new QGridLayout(this);
303 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
304 " are shown in this list.\n" ) );
305 topLabel->setWordWrap( true );
306 layout->addWidget( topLabel, 0, 0 );
308 extraMetaTree = new QTreeWidget( this );
309 extraMetaTree->setAlternatingRowColors( true );
310 extraMetaTree->setColumnCount( 2 );
311 extraMetaTree->header()->hide();
312 /* QStringList headerList = ( QStringList() << qtr( "Type" )
313 * << qtr( "Value" ) );
314 * Useless, add this header if you think it would help the user **
317 layout->addWidget( extraMetaTree, 1, 0 );
321 * Update the Extra Metadata from p_meta->i_extras
323 void ExtraMetaPanel::update( input_item_t *p_item )
325 vlc_mutex_lock( &p_item->lock );
326 vlc_meta_t *p_meta = p_item->p_meta;
329 QStringList tempItem;
331 QList<QTreeWidgetItem *> items;
332 vlc_dictionary_t * p_dict = &p_meta->extra_tags;
333 char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
334 for (int i = 0; ppsz_allkey[i] ; i++ )
336 const char * psz_value = (const char *)vlc_dictionary_value_for_key(
337 p_dict, ppsz_allkey[i] );
338 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
339 tempItem.append( qfu( psz_value ) );
340 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
341 free( ppsz_allkey[i] );
343 vlc_mutex_unlock( &p_item->lock );
345 extraMetaTree->addTopLevelItems( items );
349 * Clear the ExtraMetaData Tree
351 void ExtraMetaPanel::clear()
353 extraMetaTree->clear();
357 * Third panel - Stream info
358 * Display all codecs and muxers info that we could gather.
360 InfoPanel::InfoPanel( QWidget *parent,
361 intf_thread_t *_p_intf )
362 : QWidget( parent ), p_intf( _p_intf )
364 QGridLayout *layout = new QGridLayout(this);
366 QList<QTreeWidgetItem *> items;
368 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
369 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
371 topLabel->setWordWrap( true );
372 layout->addWidget( topLabel, 0, 0 );
374 InfoTree = new QTreeWidget(this);
375 InfoTree->setColumnCount( 1 );
376 InfoTree->header()->hide();
377 layout->addWidget(InfoTree, 1, 0 );
380 InfoPanel::~InfoPanel()
385 * Update the Codecs information on parent->update()
387 void InfoPanel::update( input_item_t *p_item)
390 QTreeWidgetItem *current_item = NULL;
391 QTreeWidgetItem *child_item = NULL;
393 for( int i = 0; i< p_item->i_categories ; i++)
395 current_item = new QTreeWidgetItem();
396 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
397 InfoTree->addTopLevelItem( current_item );
399 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
401 child_item = new QTreeWidgetItem ();
402 child_item->setText( 0,
403 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
405 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
407 current_item->addChild(child_item);
409 InfoTree->setItemExpanded( current_item, true);
416 void InfoPanel::clear()
422 * Save all the information to a file
423 * Not yet implemented.
426 void InfoPanel::saveCodecsInfo()
433 * Fourth Panel - Stats
434 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
436 InputStatsPanel::InputStatsPanel( QWidget *parent,
437 intf_thread_t *_p_intf )
438 : QWidget( parent ), p_intf( _p_intf )
440 QGridLayout *layout = new QGridLayout(this);
442 QList<QTreeWidgetItem *> items;
444 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
445 " media or stream.\n Played and streamed info are shown." ) );
446 topLabel->setWordWrap( true );
447 layout->addWidget( topLabel, 0, 0 );
449 StatsTree = new QTreeWidget(this);
450 StatsTree->setColumnCount( 3 );
451 StatsTree->header()->hide();
453 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
455 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
456 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
458 #define CREATE_CATEGORY( catName, itemText ) { \
459 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
460 catName->setExpanded( true ); \
461 StatsTree->addTopLevelItem( catName ); }
463 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
464 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
465 catName->addChild( itemName ); }
467 /* Create the main categories */
468 CREATE_CATEGORY( input, qtr("Input") );
469 CREATE_CATEGORY( video, qtr("Video") );
470 CREATE_CATEGORY( streaming, qtr("Streaming") );
471 CREATE_CATEGORY( audio, qtr("Audio") );
473 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
475 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
476 "0", input, "kb/s" );
477 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
478 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
479 "0", input, "kb/s" );
481 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
483 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
485 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
488 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
489 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
490 "0", streaming, "kB" );
491 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
492 "0", streaming, "kb/s" );
494 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
496 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
498 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
500 input->setExpanded( true );
501 video->setExpanded( true );
502 streaming->setExpanded( true );
503 audio->setExpanded( true );
505 StatsTree->resizeColumnToContents( 0 );
506 StatsTree->setColumnWidth( 1 , 100 );
508 layout->addWidget(StatsTree, 1, 0 );
511 InputStatsPanel::~InputStatsPanel()
516 * Update the Statistics
518 void InputStatsPanel::update( input_item_t *p_item )
520 vlc_mutex_lock( &p_item->p_stats->lock );
522 #define UPDATE( widget, format, calc... ) \
523 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
525 UPDATE( read_media_stat, "%8.0f",
526 (float)(p_item->p_stats->i_read_bytes)/1000);
527 UPDATE( input_bitrate_stat, "%6.0f",
528 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
529 UPDATE( demuxed_stat, "%8.0f",
530 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
531 UPDATE( stream_bitrate_stat, "%6.0f",
532 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
535 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
536 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
537 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
540 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
541 UPDATE( send_bytes_stat, "%8.0f",
542 (float)(p_item->p_stats->i_sent_bytes)/1000 );
543 UPDATE( send_bitrate_stat, "%6.0f",
544 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
547 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
548 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
549 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
551 vlc_mutex_unlock(& p_item->p_stats->lock );
554 void InputStatsPanel::clear()