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 */
103 /* ADD_URI - DO not show it, done outside */
106 // 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 ) ); }
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( "" );
137 psz_meta = p_item->p_meta->psz_url;
138 if( !EMPTY_STR( psz_meta ) )
139 emit uriSet( QString( psz_meta ) );
140 else if( !EMPTY_STR( p_item->psz_uri ) )
141 emit uriSet( QString( p_item->psz_uri ) );
143 /* Other classic though */
144 UPDATE_META( artist, artist_text );
145 UPDATE_META( genre, genre_text );
146 UPDATE_META( copyright, copyright_text );
147 UPDATE_META( album, collection_text );
148 UPDATE_META( description, description_text );
149 UPDATE_META( language, language_text );
150 UPDATE_META( nowplaying, nowplaying_text );
151 UPDATE_META( publisher, publisher_text );
152 UPDATE_META( setting, setting_text );
154 UPDATE_META_INT( date, date_text );
155 UPDATE_META_INT( tracknum, seqnum_text );
156 UPDATE_META_INT( rating, rating_text );
161 void MetaPanel::clear(){}
163 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
164 QWidget( parent ), p_intf( _p_intf )
166 QGridLayout *layout = new QGridLayout(this);
167 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
168 " are shown in this list.\n" ) );
169 topLabel->setWordWrap( true );
170 layout->addWidget( topLabel, 0, 0 );
172 extraMetaTree = new QTreeWidget( this );
173 extraMetaTree->setAlternatingRowColors( true );
174 extraMetaTree->setColumnCount( 2 );
176 extraMetaTree->header()->hide();
177 /* QStringList *treeHeaders;
178 treeHeaders << qtr( "Test1" ) << qtr( "Test2" ); */
180 layout->addWidget( extraMetaTree, 1, 0 );
183 void ExtraMetaPanel::update( input_item_t *p_item )
185 vlc_meta_t *p_meta = p_item->p_meta;
186 QStringList tempItem;
188 QList<QTreeWidgetItem *> items;
189 for (int i = 0; i < p_meta->i_extra; i++ )
191 tempItem.append( qfu( p_meta->ppsz_extra_name[i] ) + " : ");
192 tempItem.append( qfu( p_meta->ppsz_extra_value[i] ) );
193 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
195 extraMetaTree->addTopLevelItems( items );
198 void ExtraMetaPanel::clear(){}
200 /* Second Panel - Stats */
202 InputStatsPanel::InputStatsPanel( QWidget *parent, intf_thread_t *_p_intf ) :
203 QWidget( parent ), p_intf( _p_intf )
205 QGridLayout *layout = new QGridLayout(this);
206 StatsTree = new QTreeWidget(this);
207 QList<QTreeWidgetItem *> items;
208 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
209 " media or stream.\n Played and streamed info are shown." ) );
210 topLabel->setWordWrap( true );
211 layout->addWidget( topLabel, 0, 0 );
213 StatsTree->setColumnCount( 3 );
214 StatsTree->header()->hide();
216 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
218 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
219 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
221 #define CREATE_CATEGORY( catName, itemText ) { \
222 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
223 catName->setExpanded( true ); \
224 StatsTree->addTopLevelItem( catName ); }
226 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
227 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
228 catName->addChild( itemName ); }
230 /* Create the main categories */
231 CREATE_CATEGORY( input, qtr("Input") );
232 CREATE_CATEGORY( video, qtr("Video") );
233 CREATE_CATEGORY( streaming, qtr("Streaming") );
234 CREATE_CATEGORY( audio, qtr("Audio") );
236 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
238 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
239 "0", input, "kb/s" );
240 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
241 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
242 "0", input, "kb/s" );
244 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
246 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
248 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
251 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
252 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
253 "0", streaming, "kB" );
254 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
255 "0", streaming, "kb/s" );
257 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
259 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
261 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
263 input->setExpanded( true );
264 video->setExpanded( true );
265 streaming->setExpanded( true );
266 audio->setExpanded( true );
268 StatsTree->resizeColumnToContents( 0 );
269 StatsTree->setColumnWidth( 1 , 100 );
271 layout->addWidget(StatsTree, 1, 0 );
274 InputStatsPanel::~InputStatsPanel()
278 void InputStatsPanel::update( input_item_t *p_item )
280 vlc_mutex_lock( &p_item->p_stats->lock );
282 #define UPDATE( widget, format, calc... ) \
283 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
285 UPDATE( read_media_stat, "%8.0f",
286 (float)(p_item->p_stats->i_read_bytes)/1000);
287 UPDATE( input_bitrate_stat, "%6.0f",
288 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
289 UPDATE( demuxed_stat, "%8.0f",
290 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
291 UPDATE( stream_bitrate_stat, "%6.0f",
292 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
295 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
296 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
297 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
300 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
301 UPDATE( send_bytes_stat, "%8.0f",
302 (float)(p_item->p_stats->i_sent_bytes)/1000 );
303 UPDATE( send_bitrate_stat, "%6.0f",
304 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
307 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
308 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
309 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
311 vlc_mutex_unlock(& p_item->p_stats->lock );
314 void InputStatsPanel::clear()
318 /* Third panel - Stream info */
320 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
321 QWidget( parent ), p_intf( _p_intf )
323 QGridLayout *layout = new QGridLayout(this);
324 InfoTree = new QTreeWidget(this);
325 QList<QTreeWidgetItem *> items;
327 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
328 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
330 topLabel->setWordWrap( true );
331 layout->addWidget( topLabel, 0, 0 );
333 InfoTree->setColumnCount( 1 );
334 InfoTree->header()->hide();
335 layout->addWidget(InfoTree, 1, 0 );
338 InfoPanel::~InfoPanel()
342 void InfoPanel::update( input_item_t *p_item)
345 QTreeWidgetItem *current_item = NULL;
346 QTreeWidgetItem *child_item = NULL;
348 for( int i = 0; i< p_item->i_categories ; i++)
350 current_item = new QTreeWidgetItem();
351 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
352 InfoTree->addTopLevelItem( current_item );
354 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
356 child_item = new QTreeWidgetItem ();
357 child_item->setText( 0,
358 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
360 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
362 current_item->addChild(child_item);
364 InfoTree->setItemExpanded( current_item, true);
368 void InfoPanel::clear()