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 *****************************************************************************/
25 #include "components/infopanels.hpp"
28 #include <QTreeWidget>
29 #include <QPushButton>
30 #include <QHeaderView>
32 #include <QGridLayout>
35 /************************************************************************
37 ************************************************************************/
39 /* First Panel - Meta Info */
41 MetaPanel::MetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
42 QWidget( parent ), p_intf( _p_intf )
45 QGridLayout *l = new QGridLayout( this );
46 #define ADD_META( string, widget ) { \
47 l->addWidget( new QLabel( qtr( string ) ), line, 0 ); \
48 widget = new QLabel( "" ); \
49 l->addWidget( widget, line, 1 ); \
51 ADD_META( qtr( "Name" ), name_text );
52 ADD_META( qtr( "URI" ), uri_text );
53 ADD_META( VLC_META_ARTIST, artist_text );
54 ADD_META( VLC_META_GENRE, genre_text );
55 ADD_META( VLC_META_COPYRIGHT, copyright_text );
56 ADD_META( VLC_META_COLLECTION, collection_text );
57 ADD_META( VLC_META_SEQ_NUM, seqnum_text );
58 ADD_META( VLC_META_DESCRIPTION, description_text );
59 ADD_META( VLC_META_RATING, rating_text );
60 ADD_META( VLC_META_DATE, date_text );
61 ADD_META( VLC_META_LANGUAGE, language_text );
62 ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
63 ADD_META( VLC_META_PUBLISHER, publisher_text );
64 ADD_META( VLC_META_SETTING, setting_text );
67 MetaPanel::~MetaPanel()
71 void MetaPanel::update( input_item_t *p_item )
73 #define UPDATE_META( meta, widget ) { \
74 char* psz_meta = p_item->p_meta->psz_##meta; \
75 if( !EMPTY_STR( psz_meta ) ) \
76 widget->setText( qfu( psz_meta ) ); \
78 widget->setText( "" ); }
80 if( !EMPTY_STR( p_item->psz_name ) )
81 name_text->setText( qfu( p_item->psz_name ) );
82 else name_text->setText( "" );
83 if( !EMPTY_STR( p_item->psz_uri ) )
84 uri_text->setText( qfu( p_item->psz_uri ) );
85 else uri_text->setText( "" );
86 UPDATE_META( artist, artist_text );
87 UPDATE_META( genre, genre_text );
88 UPDATE_META( copyright, copyright_text );
89 UPDATE_META( album, collection_text );
90 UPDATE_META( tracknum, seqnum_text );
91 UPDATE_META( description, description_text );
92 UPDATE_META( rating, rating_text );
93 UPDATE_META( date, date_text );
94 UPDATE_META( language, language_text );
95 UPDATE_META( nowplaying, nowplaying_text );
96 UPDATE_META( publisher, publisher_text );
97 UPDATE_META( setting, setting_text );
102 void MetaPanel::clear()
106 /* Second Panel - Stats */
108 InputStatsPanel::InputStatsPanel( QWidget *parent, intf_thread_t *_p_intf ) :
109 QWidget( parent ), p_intf( _p_intf )
111 QGridLayout *layout = new QGridLayout(this);
112 StatsTree = new QTreeWidget(this);
113 QList<QTreeWidgetItem *> items;
115 layout->addWidget(StatsTree, 0, 0 );
116 StatsTree->setColumnCount( 3 );
117 StatsTree->header()->hide();
119 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
121 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
122 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
125 #define CREATE_CATEGORY( catName, itemText ) { \
126 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
127 catName->setExpanded( true ); \
128 StatsTree->addTopLevelItem( catName ); }
130 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ) { \
131 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
132 catName->addChild( itemName ); }
134 CREATE_CATEGORY( input, qtr("Input") );
135 CREATE_CATEGORY( video, qtr("Video") );
136 CREATE_CATEGORY( streaming, qtr("Streaming") );
137 CREATE_CATEGORY( audio, qtr("Audio") );
140 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"), "0", input , "kB") ;
141 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"), "0", input, "kb/s") ;
142 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
143 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"), "0", input, "kb/s") ;
145 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"), "0", video, "" ) ;
146 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"), "0", video, "") ;
147 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"), "0", video, "") ;
149 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "") ;
150 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"), "0", streaming, "kB") ;
151 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"), "0", streaming, "kb/s") ;
153 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"), "0", audio, "") ;
154 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"), "0", audio, "") ;
155 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "") ;
157 input->setExpanded( true );
158 video->setExpanded( true );
159 streaming->setExpanded( true );
160 audio->setExpanded( true );
162 StatsTree->resizeColumnToContents( 0 );
163 StatsTree->setColumnWidth( 1 , 100 );
166 InputStatsPanel::~InputStatsPanel()
170 void InputStatsPanel::update( input_item_t *p_item )
172 vlc_mutex_lock( &p_item->p_stats->lock );
174 #define UPDATE( widget, format, calc... ) \
175 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
177 UPDATE( read_media_stat, "%8.0f", (float)(p_item->p_stats->i_read_bytes)/1000);
178 UPDATE( input_bitrate_stat, "%6.0f",
179 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
180 UPDATE( demuxed_stat, "%8.0f",
181 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
182 UPDATE( stream_bitrate_stat, "%6.0f",
183 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
186 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
187 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
188 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
191 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
192 UPDATE( send_bytes_stat, "%8.0f",
193 (float)(p_item->p_stats->i_sent_bytes)/1000 );
194 UPDATE( send_bitrate_stat, "%6.0f",
195 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
198 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
199 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
200 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
202 vlc_mutex_unlock(& p_item->p_stats->lock );
205 void InputStatsPanel::clear()
209 /* Third panel - Stream info */
211 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
212 QWidget( parent ), p_intf( _p_intf )
214 QGridLayout *layout = new QGridLayout(this);
215 InfoTree = new QTreeWidget(this);
216 QList<QTreeWidgetItem *> items;
218 layout->addWidget(InfoTree, 0, 0 );
219 InfoTree->setColumnCount( 1 );
220 InfoTree->header()->hide();
223 InfoPanel::~InfoPanel()
227 void InfoPanel::update( input_item_t *p_item)
230 QTreeWidgetItem *current_item = NULL;
231 QTreeWidgetItem *child_item = NULL;
233 for( int i = 0; i< p_item->i_categories ; i++)
235 current_item = new QTreeWidgetItem();
236 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
237 InfoTree->addTopLevelItem( current_item );
239 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
241 child_item = new QTreeWidgetItem ();
242 child_item->setText( 0,
243 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
245 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
247 current_item->addChild(child_item);
249 InfoTree->setItemExpanded( current_item, true);
253 void InfoPanel::clear()
258 /***************************************************************************
260 ***************************************************************************/
262 InfoTab::InfoTab( QWidget *parent, intf_thread_t *_p_intf, bool _stats ) :
263 QTabWidget( parent ), stats( _stats ), p_intf( _p_intf )
265 // setGeometry(0, 0, 400, 500);
267 MP = new MetaPanel(NULL, p_intf);
268 addTab(MP, qtr("&General"));
269 IP = new InfoPanel(NULL, p_intf);
270 addTab(IP, qtr("&Details"));
273 ISP = new InputStatsPanel( NULL, p_intf );
274 addTab(ISP, qtr("&Stats"));
282 /* This function should be called approximately twice a second.
283 * p_item should be locked
284 * Stats will always be updated */
285 void InfoTab::update( input_item_t *p_item, bool update_info,
289 IP->update( p_item );
291 MP->update( p_item );
293 ISP->update( p_item );
296 void InfoTab::clear()
300 if( stats ) ISP->clear();