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 *****************************************************************************/
30 #include "components/info_panels.hpp"
32 #include <QTreeWidget>
34 #include <QPushButton>
35 #include <QHeaderView>
37 #include <QStringList>
38 #include <QGridLayout>
44 /************************************************************************
46 ************************************************************************/
49 * First Panel - Meta Info
50 * All the usual MetaData are displayed and can be changed.
52 MetaPanel::MetaPanel( QWidget *parent,
53 intf_thread_t *_p_intf )
54 : QWidget( parent ), p_intf( _p_intf )
56 QGridLayout *metaLayout = new QGridLayout( this );
58 int line = 0; /* Counter for GridLayout */
61 #define ADD_META( string, widget ) { \
62 metaLayout->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
63 widget = new QLineEdit; \
64 metaLayout->addWidget( widget, line, 1, 1, 9 ); \
67 /* Title, artist and album*/
68 ADD_META( VLC_META_TITLE, title_text ); /* OK */
69 ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
70 ADD_META( VLC_META_ALBUM, collection_text ); /* OK */
73 /* TODO List id3genres.h is not includable yet ? */
74 genre_text = new QLineEdit;
75 metaLayout->addWidget( new QLabel( qtr( VLC_META_GENRE ) + " :" ), line, 0 );
76 metaLayout->addWidget( genre_text, line, 1, 1, 3 );
78 /* Number - on the same line */
79 metaLayout->addWidget( new QLabel( qtr( VLC_META_TRACK_NUMBER ) + " :" ),
81 seqnum_text = new QLineEdit;
82 seqnum_text->setInputMask("0000");
83 seqnum_text->setAlignment( Qt::AlignRight );
84 metaLayout->addWidget( seqnum_text, line, 7, 1, 3 );
87 /* Date (Should be in years) */
88 date_text = new QLineEdit;
89 date_text->setInputMask("0000");
90 date_text->setAlignment( Qt::AlignRight );
91 metaLayout->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 0 );
92 metaLayout->addWidget( date_text, line, 1, 1, 3 );
94 /* Rating - on the same line */
96 metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 4, 1, 2 );
97 rating_text = new QSpinBox; setSpinBounds( rating_text );
98 metaLayout->addWidget( rating_text, line, 6, 1, 1 );
100 /* Language on the same line */
101 metaLayout->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 5, 1, 2 );
102 language_text = new QLineEdit;
103 language_text->setReadOnly( true );
104 metaLayout->addWidget( language_text, line, 7, 1, 3 );
108 art_cover = new QLabel( "" );
109 art_cover->setMinimumHeight( 128 );
110 art_cover->setMinimumWidth( 128 );
111 art_cover->setMaximumHeight( 128 );
112 art_cover->setMaximumWidth( 128 );
113 art_cover->setScaledContents( true );
114 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
115 metaLayout->addWidget( art_cover, line, 8, 4, 2, Qt::AlignRight );
117 /* Settings is unused */
118 /* l->addWidget( new QLabel( qtr( VLC_META_SETTING ) + " :" ), line, 5 );
119 setting_text = new QLineEdit;
120 l->addWidget( setting_text, line, 6, 1, 4 ); */
122 /* Less used metadata */
123 #define ADD_META_2( string, widget ) { \
124 metaLayout->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
125 widget = new QLineEdit; \
126 metaLayout->addWidget( widget, line, 1, 1, 7 ); \
129 /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
130 ADD_META_2( VLC_META_NOW_PLAYING, nowplaying_text );
131 nowplaying_text->setReadOnly( true );
132 ADD_META_2( VLC_META_PUBLISHER, publisher_text );
133 ADD_META_2( VLC_META_COPYRIGHT, copyright_text );
134 ADD_META_2( "Comments", description_text );
136 /* useless metadata */
138 //ADD_META_2( VLC_META_ENCODED_BY, encodedby_text );
139 /* ADD_META( TRACKID ) Useless ? */
140 /* ADD_URI - DO not show it, done outside */
142 metaLayout->setColumnStretch( 1, 2 );
143 metaLayout->setColumnMinimumWidth ( 1, 80 );
147 CONNECT( title_text, textEdited( QString ), this, enterEditMode() );
148 CONNECT( artist_text, textEdited( QString ), this, enterEditMode() );
149 CONNECT( collection_text, textEdited( QString ), this, enterEditMode() );
150 CONNECT( genre_text, textEdited( QString ), this, enterEditMode() );
151 CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
153 CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
154 CONNECT( description_text, textEdited( QString ), this, enterEditMode() );
155 /* CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/
157 /* We are not yet in Edit Mode */
158 b_inEditMode = false;
161 MetaPanel::~MetaPanel(){}
164 * Update all the MetaData and art on an "item-changed" event
166 void MetaPanel::update( input_item_t *p_item )
168 /* Don't update if you are in edit mode */
169 if( b_inEditMode ) return;
170 else p_input = p_item;
173 #define UPDATE_META( meta, widget ) { \
174 psz_meta = input_item_Get##meta( p_item ); \
175 if( !EMPTY_STR( psz_meta ) ) \
176 widget->setText( qfu( psz_meta ) ); \
178 widget->setText( "" ); } \
181 #define UPDATE_META_INT( meta, widget ) { \
182 psz_meta = input_item_Get##meta( p_item ); \
183 if( !EMPTY_STR( psz_meta ) ) \
184 widget->setValue( atoi( psz_meta ) ); } \
188 psz_meta = input_item_GetTitle( p_item );
189 psz_meta = input_item_GetTitle( p_item );
190 char *psz_name = input_item_GetName( p_item );
191 if( !EMPTY_STR( psz_meta ) )
192 title_text->setText( qfu( psz_meta ) );
193 else if( !EMPTY_STR( psz_name ) )
194 title_text->setText( qfu( psz_name ) );
195 else title_text->setText( "" );
200 psz_meta = input_item_GetURL( p_item );
201 if( !EMPTY_STR( psz_meta ) )
203 emit uriSet( QString( psz_meta ) );
209 psz_meta = input_item_GetURI( p_item );
210 if( !EMPTY_STR( psz_meta ) )
211 emit uriSet( QString( psz_meta ) );
214 /* Other classic though */
215 UPDATE_META( Artist, artist_text );
216 UPDATE_META( Genre, genre_text );
217 UPDATE_META( Copyright, copyright_text );
218 UPDATE_META( Album, collection_text );
219 UPDATE_META( Description, description_text );
220 UPDATE_META( Language, language_text );
221 UPDATE_META( NowPlaying, nowplaying_text );
222 UPDATE_META( Publisher, publisher_text );
223 // UPDATE_META( Setting, setting_text );
224 // UPDATE_META( EncodedBy, encodedby_text );
226 UPDATE_META( Date, date_text );
227 UPDATE_META( TrackNum, seqnum_text );
228 // UPDATE_META_INT( Rating, rating_text );
230 #undef UPDATE_META_INT
234 psz_meta = input_item_GetArtURL( p_item );
235 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
237 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
238 art_cover->setPixmap( QPixmap( artUrl ) );
241 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
246 * Save the MetaData, triggered by parent->save Button
248 void MetaPanel::saveMeta()
250 playlist_t *p_playlist;
252 meta_export_t p_export;
253 p_export.p_item = p_input;
255 if( p_input == NULL )
258 /* we can write meta data only in a file */
259 vlc_mutex_lock( &p_input->lock );
260 int i_type = p_input->i_type;
261 vlc_mutex_unlock( &p_input->lock );
262 if( i_type == ITEM_TYPE_FILE )
264 char *psz_uri_orig = input_item_GetURI( p_input );
265 char *psz_uri = psz_uri_orig;
266 if( !strncmp( psz_uri, "file://", 7 ) )
267 psz_uri += 7; /* strlen("file://") = 7 */
269 p_export.psz_file = strndup( psz_uri, PATH_MAX );
270 free( psz_uri_orig );
275 /* now we read the modified meta data */
276 input_item_SetTitle( p_input, qtu( title_text->text() ) );
277 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
278 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
279 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
280 input_item_SetTrackNum( p_input, qtu( seqnum_text->text() ) );
281 input_item_SetDate( p_input, qtu( date_text->text() ) );
283 input_item_SetCopyright( p_input, qtu( copyright_text->text() ) );
284 input_item_SetPublisher( p_input, qtu( publisher_text->text() ) );
285 input_item_SetDescription( p_input, qtu( description_text->text() ) );
287 p_playlist = pl_Yield( p_intf );
289 p_playlist->p_private = &p_export;
291 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
293 module_Unneed( p_playlist, p_mod );
295 pl_Release( p_playlist );
297 /* Reset the status of the mode. No need to emit any signal because parent
298 is the only caller */
299 b_inEditMode = false;
303 bool MetaPanel::isInEditMode()
308 void MetaPanel::enterEditMode()
310 msg_Dbg( p_intf, "Entering Edit MetaData Mode" );
314 void MetaPanel::setEditMode( bool b_editing )
316 b_inEditMode = b_editing;
317 if( b_editing )emit editing();
321 * Clear all the metadata widgets
323 void MetaPanel::clear()
326 artist_text->clear();
328 copyright_text->clear();
329 collection_text->clear();
330 seqnum_text->clear();
331 description_text->clear();
333 language_text->clear();
334 nowplaying_text->clear();
335 publisher_text->clear();
338 setEditMode( false );
342 * Second Panel - Shows the extra metadata in a tree, non editable.
344 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
345 intf_thread_t *_p_intf )
346 : QWidget( parent ), p_intf( _p_intf )
348 QGridLayout *layout = new QGridLayout(this);
350 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
351 " are shown in this panel.\n" ) );
352 topLabel->setWordWrap( true );
353 layout->addWidget( topLabel, 0, 0 );
355 extraMetaTree = new QTreeWidget( this );
356 extraMetaTree->setAlternatingRowColors( true );
357 extraMetaTree->setColumnCount( 2 );
358 extraMetaTree->resizeColumnToContents( 0 );
359 extraMetaTree->header()->hide();
360 /* QStringList headerList = ( QStringList() << qtr( "Type" )
361 * << qtr( "Value" ) );
362 * Useless, add this header if you think it would help the user **
365 layout->addWidget( extraMetaTree, 1, 0 );
369 * Update the Extra Metadata from p_meta->i_extras
371 void ExtraMetaPanel::update( input_item_t *p_item )
373 QStringList tempItem;
374 QList<QTreeWidgetItem *> items;
376 extraMetaTree->clear();
378 vlc_mutex_lock( &p_item->lock );
379 vlc_meta_t *p_meta = p_item->p_meta;
382 vlc_mutex_unlock( &p_item->lock );
386 vlc_dictionary_t * p_dict = &p_meta->extra_tags;
387 char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
389 for( int i = 0; ppsz_allkey[i] ; i++ )
391 const char * psz_value = (const char *)vlc_dictionary_value_for_key(
392 p_dict, ppsz_allkey[i] );
393 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
394 tempItem.append( qfu( psz_value ) );
395 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
396 free( ppsz_allkey[i] );
398 vlc_mutex_unlock( &p_item->lock );
401 extraMetaTree->addTopLevelItems( items );
402 extraMetaTree->resizeColumnToContents( 0 );
406 * Clear the ExtraMetaData Tree
408 void ExtraMetaPanel::clear()
410 extraMetaTree->clear();
414 * Third panel - Stream info
415 * Display all codecs and muxers info that we could gather.
417 InfoPanel::InfoPanel( QWidget *parent,
418 intf_thread_t *_p_intf )
419 : QWidget( parent ), p_intf( _p_intf )
421 QGridLayout *layout = new QGridLayout(this);
423 QList<QTreeWidgetItem *> items;
425 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
426 " stream is made of.\nMuxer, Audio and Video Codecs, Subtitles "
428 topLabel->setWordWrap( true );
429 layout->addWidget( topLabel, 0, 0 );
431 InfoTree = new QTreeWidget(this);
432 InfoTree->setColumnCount( 1 );
433 InfoTree->header()->hide();
434 layout->addWidget(InfoTree, 1, 0 );
437 InfoPanel::~InfoPanel()
442 * Update the Codecs information on parent->update()
444 void InfoPanel::update( input_item_t *p_item)
447 QTreeWidgetItem *current_item = NULL;
448 QTreeWidgetItem *child_item = NULL;
450 for( int i = 0; i< p_item->i_categories ; i++)
452 current_item = new QTreeWidgetItem();
453 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
454 InfoTree->addTopLevelItem( current_item );
456 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
458 child_item = new QTreeWidgetItem ();
459 child_item->setText( 0,
460 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
462 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
464 current_item->addChild(child_item);
466 InfoTree->setItemExpanded( current_item, true);
473 void InfoPanel::clear()
479 * Save all the information to a file
480 * Not yet implemented.
483 void InfoPanel::saveCodecsInfo()
488 * Fourth Panel - Stats
489 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
491 InputStatsPanel::InputStatsPanel( QWidget *parent,
492 intf_thread_t *_p_intf )
493 : QWidget( parent ), p_intf( _p_intf )
495 QGridLayout *layout = new QGridLayout(this);
497 QList<QTreeWidgetItem *> items;
499 QLabel *topLabel = new QLabel( qtr( "Statistics about the currently "
500 "playing media or stream." ) );
501 topLabel->setWordWrap( true );
502 layout->addWidget( topLabel, 0, 0 );
504 StatsTree = new QTreeWidget(this);
505 StatsTree->setColumnCount( 3 );
506 StatsTree->header()->hide();
508 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
510 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
511 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
513 #define CREATE_CATEGORY( catName, itemText ) { \
514 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
515 catName->setExpanded( true ); \
516 StatsTree->addTopLevelItem( catName ); }
518 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
519 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
520 catName->addChild( itemName ); }
522 /* Create the main categories */
523 CREATE_CATEGORY( audio, qtr("Audio") );
524 CREATE_CATEGORY( video, qtr("Video") );
525 CREATE_CATEGORY( input, qtr("Input") );
526 CREATE_CATEGORY( streaming, qtr("Streaming") );
528 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
530 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
531 "0", input, "kb/s" );
532 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
533 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
534 "0", input, "kb/s" );
536 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
538 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
540 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
542 CREATE_AND_ADD_TO_CAT( vfps_stat, qtr("FPS"), "0", video, "" );
544 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
545 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
546 "0", streaming, "kB" );
547 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrate"),
548 "0", streaming, "kb/s" );
550 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
552 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
554 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
556 input->setExpanded( true );
557 video->setExpanded( true );
558 streaming->setExpanded( true );
559 audio->setExpanded( true );
561 StatsTree->resizeColumnToContents( 0 );
562 StatsTree->setColumnWidth( 1 , 100 );
564 layout->addWidget(StatsTree, 1, 0 );
567 InputStatsPanel::~InputStatsPanel()
572 * Update the Statistics
574 void InputStatsPanel::update( input_item_t *p_item )
576 vlc_mutex_lock( &p_item->p_stats->lock );
578 #define UPDATE( widget, format, calc... ) \
579 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
581 UPDATE( read_media_stat, "%8.0f",
582 (float)(p_item->p_stats->i_read_bytes)/1000);
583 UPDATE( input_bitrate_stat, "%6.0f",
584 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
585 UPDATE( demuxed_stat, "%8.0f",
586 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
587 UPDATE( stream_bitrate_stat, "%6.0f",
588 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
591 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
592 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
593 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
594 /* UPDATE( vfps_stat, "%5f", p_item->p_stats->i_lost_pictures );
595 input_Control( p_input_thread, INPUT_GET_VIDEO_FPS, &f_fps */
598 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
599 UPDATE( send_bytes_stat, "%8.0f",
600 (float)(p_item->p_stats->i_sent_bytes)/1000 );
601 UPDATE( send_bitrate_stat, "%6.0f",
602 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
605 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
606 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
607 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
609 vlc_mutex_unlock(& p_item->p_stats->lock );
612 void InputStatsPanel::clear()