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 QLineEdit;
87 seqnum_text->setInputMask("0000");
88 seqnum_text->setAlignment( Qt::AlignRight );
89 l->addWidget( seqnum_text, line, 4, 1, 2 );
92 /* Date (Should be in years) */
93 date_text = new QLineEdit;
94 date_text->setInputMask("0000");
95 date_text->setAlignment( Qt::AlignRight );
96 l->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 0 );
97 l->addWidget( date_text, line, 1, 1, 1 );
101 l->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 2 );
102 rating_text = new QSpinBox; setSpinBounds( rating_text) ;
103 l->addWidget( rating_text, line, 3, 1, 1 );
106 // ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
108 /* Language and settings */
109 l->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 4 );
110 language_text = new QLineEdit;
111 l->addWidget( language_text, line, 5, 1, 1 );
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 );
118 #define ADD_META_2( string, widget ) { \
119 l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
120 widget = new QLineEdit; \
121 l->addWidget( widget, line, 1, 1, 7 ); \
124 ADD_META_2( VLC_META_COPYRIGHT, copyright_text );
125 ADD_META_2( VLC_META_PUBLISHER, publisher_text );
127 ADD_META_2( VLC_META_ENCODED_BY, encodedby_text );
128 ADD_META_2( VLC_META_DESCRIPTION, description_text );
130 /* ADD_META( TRACKID ) Useless ? */
131 /* ADD_URI - DO not show it, done outside */
137 CONNECT( title_text, textEdited( QString ), this, editMeta( QString ) );
138 // CONNECT( description_text, textEdited( QString ), this, editMeta( QString ) );
139 CONNECT( artist_text, textEdited( QString ), this, editMeta( QString ) );
140 CONNECT( collection_text, textEdited( QString ), this, editMeta( QString ) );
141 CONNECT( genre_text, textEdited( QString ), this, editMeta( QString ) );
142 CONNECT( date_text, textEdited( QString ), this, editMeta( QString ) );
143 CONNECT( seqnum_text, textEdited( QString ), this, editMeta( QString ) );
144 /* CONNECT( rating_text, valueChanged( QString ), this, editMeta( QString ) );*/
148 MetaPanel::~MetaPanel(){}
151 * Save the MetaData, triggered by parent->save Button
153 void MetaPanel::saveMeta()
155 playlist_t *p_playlist;
158 meta_export_t p_export;
159 p_export.p_item = p_input;
161 if( p_input == NULL )
164 /* we can write meta data only in a file */
165 vlc_mutex_lock( &p_input->lock );
166 int i_type = p_input->i_type;
167 vlc_mutex_unlock( &p_input->lock );
168 if( i_type == ITEM_TYPE_FILE )
170 char *psz_uri_orig = input_item_GetURI( p_input );
171 char *psz_uri = psz_uri_orig;
172 if( !strncmp( psz_uri, "file://", 7 ) )
173 psz_uri += 7; /* strlen("file://") = 7 */
175 p_export.psz_file = strndup( psz_uri, PATH_MAX );
176 free( psz_uri_orig );
181 /* now we read the modified meta data */
182 input_item_SetArtist( p_input, qtu( artist_text->text() ) );
183 input_item_SetAlbum( p_input, qtu( collection_text->text() ) );
184 input_item_SetGenre( p_input, qtu( genre_text->text() ) );
186 input_item_SetDate( p_input, qtu( date_text->text() ) );
188 input_item_SetTrackNum( p_input, qtu( seqnum_text->text() ) );
190 input_item_SetTitle( p_input, qtu( title_text->text() ) );
192 p_playlist = pl_Yield( p_intf );
195 p_playlist->p_private = &p_export;
197 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
199 module_Unneed( p_playlist, p_mod );
201 pl_Release( p_playlist );
205 void MetaPanel::editMeta( QString edit )
211 void MetaPanel::setEdit( bool editing )
216 void MetaPanel::setInput( input_item_t *input )
218 if( in_edit ) return;
224 * Update all the MetaData and art on an "item-changed" event
226 void MetaPanel::update( input_item_t *p_item )
228 if( in_edit ) return;
230 #define UPDATE_META( meta, widget ) { \
231 psz_meta = input_item_Get##meta( p_item ); \
232 if( !EMPTY_STR( psz_meta ) ) \
233 widget->setText( qfu( psz_meta ) ); \
235 widget->setText( "" ); } \
238 #define UPDATE_META_INT( meta, widget ) { \
239 psz_meta = input_item_Get##meta( p_item ); \
240 if( !EMPTY_STR( psz_meta ) ) \
241 widget->setValue( atoi( psz_meta ) ); } \
246 psz_meta = input_item_GetTitle( p_item );
247 char *psz_name = input_item_GetName( p_item );
248 if( !EMPTY_STR( psz_meta ) )
249 title_text->setText( qfu( psz_meta ) );
250 else if( !EMPTY_STR( psz_name ) )
251 title_text->setText( qfu( psz_name ) );
252 else title_text->setText( "" );
257 psz_meta = input_item_GetURL( p_item );
258 if( !EMPTY_STR( psz_meta ) )
260 emit uriSet( QString( psz_meta ) );
266 psz_meta = input_item_GetURI( p_item );
267 if( !EMPTY_STR( psz_meta ) )
268 emit uriSet( QString( psz_meta ) );
271 /* Other classic though */
272 UPDATE_META( Artist, artist_text );
273 UPDATE_META( Genre, genre_text );
274 // UPDATE_META( Copyright, copyright_text );
275 UPDATE_META( Album, collection_text );
276 // UPDATE_META( Description, description_text );
277 UPDATE_META( Language, language_text );
278 // UPDATE_META( NowPlaying, nowplaying_text );
279 // UPDATE_META( Publisher, publisher_text );
280 // UPDATE_META( Setting, setting_text );
281 // UPDATE_META( EncodedBy, encodedby_text );
283 UPDATE_META( Date, date_text );
284 UPDATE_META( TrackNum, seqnum_text );
285 UPDATE_META_INT( Rating, rating_text );
287 #undef UPDATE_META_INT
291 psz_meta = input_item_GetArtURL( p_item );
292 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
294 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
295 art_cover->setPixmap( QPixmap( artUrl ) );
298 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
303 * Clear all the metadata widgets
306 void MetaPanel::clear(){}
309 * Second Panel - Shows the extra metadata in a tree, non editable.
311 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
312 intf_thread_t *_p_intf )
313 : QWidget( parent ), p_intf( _p_intf )
315 QGridLayout *layout = new QGridLayout(this);
317 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
318 " are shown in this list.\n" ) );
319 topLabel->setWordWrap( true );
320 layout->addWidget( topLabel, 0, 0 );
322 extraMetaTree = new QTreeWidget( this );
323 extraMetaTree->setAlternatingRowColors( true );
324 extraMetaTree->setColumnCount( 2 );
325 extraMetaTree->header()->hide();
326 /* QStringList headerList = ( QStringList() << qtr( "Type" )
327 * << qtr( "Value" ) );
328 * Useless, add this header if you think it would help the user **
331 layout->addWidget( extraMetaTree, 1, 0 );
335 * Update the Extra Metadata from p_meta->i_extras
337 void ExtraMetaPanel::update( input_item_t *p_item )
339 vlc_mutex_lock( &p_item->lock );
340 vlc_meta_t *p_meta = p_item->p_meta;
343 QStringList tempItem;
345 QList<QTreeWidgetItem *> items;
346 vlc_dictionary_t * p_dict = &p_meta->extra_tags;
347 char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
348 for (int i = 0; ppsz_allkey[i] ; i++ )
350 const char * psz_value = (const char *)vlc_dictionary_value_for_key(
351 p_dict, ppsz_allkey[i] );
352 tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
353 tempItem.append( qfu( psz_value ) );
354 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
355 free( ppsz_allkey[i] );
357 vlc_mutex_unlock( &p_item->lock );
359 extraMetaTree->addTopLevelItems( items );
363 * Clear the ExtraMetaData Tree
365 void ExtraMetaPanel::clear()
367 extraMetaTree->clear();
371 * Third panel - Stream info
372 * Display all codecs and muxers info that we could gather.
374 InfoPanel::InfoPanel( QWidget *parent,
375 intf_thread_t *_p_intf )
376 : QWidget( parent ), p_intf( _p_intf )
378 QGridLayout *layout = new QGridLayout(this);
380 QList<QTreeWidgetItem *> items;
382 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
383 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
385 topLabel->setWordWrap( true );
386 layout->addWidget( topLabel, 0, 0 );
388 InfoTree = new QTreeWidget(this);
389 InfoTree->setColumnCount( 1 );
390 InfoTree->header()->hide();
391 layout->addWidget(InfoTree, 1, 0 );
394 InfoPanel::~InfoPanel()
399 * Update the Codecs information on parent->update()
401 void InfoPanel::update( input_item_t *p_item)
404 QTreeWidgetItem *current_item = NULL;
405 QTreeWidgetItem *child_item = NULL;
407 for( int i = 0; i< p_item->i_categories ; i++)
409 current_item = new QTreeWidgetItem();
410 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
411 InfoTree->addTopLevelItem( current_item );
413 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
415 child_item = new QTreeWidgetItem ();
416 child_item->setText( 0,
417 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
419 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
421 current_item->addChild(child_item);
423 InfoTree->setItemExpanded( current_item, true);
430 void InfoPanel::clear()
436 * Save all the information to a file
437 * Not yet implemented.
440 void InfoPanel::saveCodecsInfo()
447 * Fourth Panel - Stats
448 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
450 InputStatsPanel::InputStatsPanel( QWidget *parent,
451 intf_thread_t *_p_intf )
452 : QWidget( parent ), p_intf( _p_intf )
454 QGridLayout *layout = new QGridLayout(this);
456 QList<QTreeWidgetItem *> items;
458 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
459 " media or stream.\n Played and streamed info are shown." ) );
460 topLabel->setWordWrap( true );
461 layout->addWidget( topLabel, 0, 0 );
463 StatsTree = new QTreeWidget(this);
464 StatsTree->setColumnCount( 3 );
465 StatsTree->header()->hide();
467 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
469 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
470 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
472 #define CREATE_CATEGORY( catName, itemText ) { \
473 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
474 catName->setExpanded( true ); \
475 StatsTree->addTopLevelItem( catName ); }
477 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
478 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
479 catName->addChild( itemName ); }
481 /* Create the main categories */
482 CREATE_CATEGORY( input, qtr("Input") );
483 CREATE_CATEGORY( video, qtr("Video") );
484 CREATE_CATEGORY( streaming, qtr("Streaming") );
485 CREATE_CATEGORY( audio, qtr("Audio") );
487 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
489 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
490 "0", input, "kb/s" );
491 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
492 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
493 "0", input, "kb/s" );
495 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
497 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
499 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
502 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
503 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
504 "0", streaming, "kB" );
505 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
506 "0", streaming, "kb/s" );
508 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
510 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
512 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
514 input->setExpanded( true );
515 video->setExpanded( true );
516 streaming->setExpanded( true );
517 audio->setExpanded( true );
519 StatsTree->resizeColumnToContents( 0 );
520 StatsTree->setColumnWidth( 1 , 100 );
522 layout->addWidget(StatsTree, 1, 0 );
525 InputStatsPanel::~InputStatsPanel()
530 * Update the Statistics
532 void InputStatsPanel::update( input_item_t *p_item )
534 vlc_mutex_lock( &p_item->p_stats->lock );
536 #define UPDATE( widget, format, calc... ) \
537 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
539 UPDATE( read_media_stat, "%8.0f",
540 (float)(p_item->p_stats->i_read_bytes)/1000);
541 UPDATE( input_bitrate_stat, "%6.0f",
542 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
543 UPDATE( demuxed_stat, "%8.0f",
544 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
545 UPDATE( stream_bitrate_stat, "%6.0f",
546 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
549 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
550 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
551 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
554 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
555 UPDATE( send_bytes_stat, "%8.0f",
556 (float)(p_item->p_stats->i_sent_bytes)/1000 );
557 UPDATE( send_bitrate_stat, "%6.0f",
558 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
561 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
562 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
563 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
565 vlc_mutex_unlock(& p_item->p_stats->lock );
568 void InputStatsPanel::clear()