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 <QGridLayout>
39 /************************************************************************
41 ************************************************************************/
43 /* First Panel - Meta Info */
45 MetaPanel::MetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
46 QWidget( parent ), p_intf( _p_intf )
49 QGridLayout *l = new QGridLayout( this );
50 l->setColumnStretch( 2, 5 );
51 l->setColumnStretch( 5, 3 );
53 #define ADD_META( string, widget ) { \
54 l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
55 widget = new QLineEdit; \
56 l->addWidget( widget, line, 1, 1, 7 ); \
59 ADD_META( VLC_META_TITLE, title_text ); /* OK */
60 ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
61 ADD_META( VLC_META_GENRE, genre_text ); /* FIXME List id3genres.h is not
65 l->addWidget( new QLabel( qfu( VLC_META_COLLECTION ) + " :" ), line, 0 );
66 collection_text = new QLineEdit;
67 l->addWidget( collection_text, line, 1, 1, 5 );
68 l->addWidget( new QLabel( qfu( VLC_META_DATE ) + " :" ), line, 6 );
69 /* Date (Should be in years) */
70 date_text = new QSpinBox; setSpinBounds( date_text );
71 l->addWidget( date_text, line, 7 );
74 /* Number and Rating */
75 l->addWidget( new QLabel( qfu( _("Track number/Position" ) ) + " :" ),
77 seqnum_text = new QSpinBox; setSpinBounds( seqnum_text );
78 l->addWidget( seqnum_text, line, 1, 1, 3 );
80 l->addWidget( new QLabel( qfu( VLC_META_RATING ) + " :" ), line, 4 );
81 rating_text = new QSpinBox; setSpinBounds( rating_text) ;
82 l->addWidget( rating_text, line, 5, 1, 3 );
85 ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
87 /* Language and settings */
88 l->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 0 );
89 language_text = new QLineEdit;
90 l->addWidget( language_text, line, 1, 1, 3 );
91 l->addWidget( new QLabel( qfu( VLC_META_SETTING ) + " :" ), line, 4 );
92 setting_text = new QLineEdit;
93 l->addWidget( setting_text, line, 5, 1, 3 );
96 ADD_META( VLC_META_COPYRIGHT, copyright_text );
97 ADD_META( VLC_META_PUBLISHER, publisher_text );
99 ADD_META( VLC_META_ENCODED_BY, publisher_text );
100 ADD_META( VLC_META_DESCRIPTION, description_text ); // Comment Two lines?
102 /* ADD_META( TRACKID) DO NOT SHOW it */
104 // ADD_META( _( "URI" ), uri_text ); // FIXME URI outside
105 // ADD_META( VLC_META_URL, setting_text );
109 MetaPanel::~MetaPanel()
113 void MetaPanel::update( input_item_t *p_item )
116 #define UPDATE_META( meta, widget ) { \
117 psz_meta = p_item->p_meta->psz_##meta; \
118 if( !EMPTY_STR( psz_meta ) ) \
119 widget->setText( qfu( psz_meta ) ); \
121 widget->setText( "" ); }
123 #define UPDATE_META_INT( meta, widget ) { \
124 psz_meta = p_item->p_meta->psz_##meta; \
125 if( !EMPTY_STR( psz_meta ) ) \
126 widget->setValue( atoi( psz_meta ) ); }/*FIXME Atoi ?*/
129 psz_meta = p_item->p_meta->psz_title;
130 if( !EMPTY_STR( psz_meta ) )
131 title_text->setText( qfu( psz_meta ) );
132 else if( !EMPTY_STR( p_item->psz_name ) )
133 title_text->setText( qfu( p_item->psz_name ) );
134 else title_text->setText( "" );
136 /* if( !EMPTY_STR( p_item->psz_uri ) )
137 uri_text->setText( qfu( p_item->psz_uri ) );*/
138 /// else uri_text->setText( "" );
140 UPDATE_META( artist, artist_text );
141 UPDATE_META( genre, genre_text );
142 UPDATE_META( copyright, copyright_text );
143 UPDATE_META( album, collection_text );
144 UPDATE_META( description, description_text );
145 UPDATE_META( language, language_text );
146 UPDATE_META( nowplaying, nowplaying_text );
147 UPDATE_META( publisher, publisher_text );
148 UPDATE_META( setting, setting_text );
150 UPDATE_META_INT( date, date_text );
151 UPDATE_META_INT( tracknum, seqnum_text );
152 UPDATE_META_INT( rating, rating_text );
157 void MetaPanel::clear(){}
159 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
160 QWidget( parent ), p_intf( _p_intf )
162 QGridLayout *layout = new QGridLayout(this);
163 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
164 " are shown in this list.\n" ) );
165 topLabel->setWordWrap( true );
166 layout->addWidget( topLabel, 0, 0 );
168 extraMetaTree = new QTreeWidget( this );
169 extraMetaTree->setAlternatingRowColors( true );
170 extraMetaTree->setColumnCount( 2 );
172 extraMetaTree->header()->hide();
173 /* QStringList *treeHeaders;
174 treeHeaders << qtr( "Test1" ) << qtr( "Test2" ); */
176 layout->addWidget( extraMetaTree, 1, 0 );
179 void ExtraMetaPanel::update( input_item_t *p_item )
181 vlc_meta_t *p_meta = p_item->p_meta;
182 QStringList tempItem;
184 QList<QTreeWidgetItem *> items;
185 for (int i = 0; i < p_meta->i_extra; i++ )
187 tempItem.append( qfu( p_meta->ppsz_extra_name[i] ) + " : ");
188 tempItem.append( qfu( p_meta->ppsz_extra_value[i] ) );
189 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
191 extraMetaTree->addTopLevelItems( items );
194 void ExtraMetaPanel::clear(){}
196 /* Second Panel - Stats */
198 InputStatsPanel::InputStatsPanel( QWidget *parent, intf_thread_t *_p_intf ) :
199 QWidget( parent ), p_intf( _p_intf )
201 QGridLayout *layout = new QGridLayout(this);
202 StatsTree = new QTreeWidget(this);
203 QList<QTreeWidgetItem *> items;
204 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
205 " media or stream.\n Played and streamed info are shown." ) );
206 topLabel->setWordWrap( true );
207 layout->addWidget( topLabel, 0, 0 );
209 StatsTree->setColumnCount( 3 );
210 StatsTree->header()->hide();
212 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
214 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
215 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
217 #define CREATE_CATEGORY( catName, itemText ) { \
218 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
219 catName->setExpanded( true ); \
220 StatsTree->addTopLevelItem( catName ); }
222 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
223 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
224 catName->addChild( itemName ); }
226 /* Create the main categories */
227 CREATE_CATEGORY( input, qtr("Input") );
228 CREATE_CATEGORY( video, qtr("Video") );
229 CREATE_CATEGORY( streaming, qtr("Streaming") );
230 CREATE_CATEGORY( audio, qtr("Audio") );
232 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
234 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
235 "0", input, "kb/s" );
236 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
237 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
238 "0", input, "kb/s" );
240 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
242 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
244 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
247 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
248 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
249 "0", streaming, "kB" );
250 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
251 "0", streaming, "kb/s" );
253 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
255 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
257 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
259 input->setExpanded( true );
260 video->setExpanded( true );
261 streaming->setExpanded( true );
262 audio->setExpanded( true );
264 StatsTree->resizeColumnToContents( 0 );
265 StatsTree->setColumnWidth( 1 , 100 );
267 layout->addWidget(StatsTree, 1, 0 );
270 InputStatsPanel::~InputStatsPanel()
274 void InputStatsPanel::update( input_item_t *p_item )
276 vlc_mutex_lock( &p_item->p_stats->lock );
278 #define UPDATE( widget, format, calc... ) \
279 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
281 UPDATE( read_media_stat, "%8.0f",
282 (float)(p_item->p_stats->i_read_bytes)/1000);
283 UPDATE( input_bitrate_stat, "%6.0f",
284 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
285 UPDATE( demuxed_stat, "%8.0f",
286 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
287 UPDATE( stream_bitrate_stat, "%6.0f",
288 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
291 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
292 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
293 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
296 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
297 UPDATE( send_bytes_stat, "%8.0f",
298 (float)(p_item->p_stats->i_sent_bytes)/1000 );
299 UPDATE( send_bitrate_stat, "%6.0f",
300 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
303 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
304 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
305 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
307 vlc_mutex_unlock(& p_item->p_stats->lock );
310 void InputStatsPanel::clear()
314 /* Third panel - Stream info */
316 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
317 QWidget( parent ), p_intf( _p_intf )
319 QGridLayout *layout = new QGridLayout(this);
320 InfoTree = new QTreeWidget(this);
321 QList<QTreeWidgetItem *> items;
323 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
324 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
326 topLabel->setWordWrap( true );
327 layout->addWidget( topLabel, 0, 0 );
329 InfoTree->setColumnCount( 1 );
330 InfoTree->header()->hide();
331 layout->addWidget(InfoTree, 1, 0 );
334 InfoPanel::~InfoPanel()
338 void InfoPanel::update( input_item_t *p_item)
341 QTreeWidgetItem *current_item = NULL;
342 QTreeWidgetItem *child_item = NULL;
344 for( int i = 0; i< p_item->i_categories ; i++)
346 current_item = new QTreeWidgetItem();
347 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
348 InfoTree->addTopLevelItem( current_item );
350 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
352 child_item = new QTreeWidgetItem ();
353 child_item->setText( 0,
354 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
356 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
358 current_item->addChild(child_item);
360 InfoTree->setItemExpanded( current_item, true);
364 void InfoPanel::clear()
369 /***************************************************************************
371 ***************************************************************************/
373 InfoTab::InfoTab( QWidget *parent, intf_thread_t *_p_intf, bool _stats ) :
374 QTabWidget( parent ), stats( _stats ), p_intf( _p_intf )
376 MP = new MetaPanel( NULL, p_intf );
377 addTab( MP, qtr( "&General" ) );
378 EMP = new ExtraMetaPanel( NULL, p_intf );
379 addTab( EMP, qtr( "&Extra Metadata" ) );
380 IP = new InfoPanel( NULL, p_intf);
381 addTab(IP, qtr("&Codec Details"));
384 ISP = new InputStatsPanel( NULL, p_intf );
385 addTab(ISP, qtr("&Stats"));
393 /* This function should be called approximately twice a second.
394 * p_item should be locked
395 * Stats will always be updated */
396 void InfoTab::update( input_item_t *p_item, bool update_info,
400 IP->update( p_item );
402 MP->update( p_item );
403 EMP->update( p_item );
405 ISP->update( p_item );
408 void InfoTab::clear()
413 if( stats ) ISP->clear();