1 /*****************************************************************************
2 * infopanels.cpp : Panels for the information dialogs
3 ****************************************************************************
4 * Copyright (C) 2006 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( qfu( string ) ), line, 0 ); \
48 widget = new QLabel( "" ); \
49 l->addWidget( widget, line, 1 ); \
51 ADD_META( _( "Name" ), name_text );
52 ADD_META( _( "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, "Input" );
135 CREATE_CATEGORY( video, "Video" );
136 CREATE_CATEGORY( streaming, "Streaming" );
137 CREATE_CATEGORY( audio, "Audio" );
139 CREATE_AND_ADD_TO_CAT( read_media_stat, "Read at media", "0", input , "kB") ;
140 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, "Input bitrate", "0", input, "kb/s") ;
141 CREATE_AND_ADD_TO_CAT( demuxed_stat, "Demuxed", "0", input, "kB") ;
142 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, "Stream bitrate", "0", input, "kb/s") ;
144 CREATE_AND_ADD_TO_CAT( vdecoded_stat, "Decoded blocks", "0", video, "" ) ;
145 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, "Displayed frames", "0", video, "") ;
146 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, "Lost frames", "0", video, "") ;
148 CREATE_AND_ADD_TO_CAT( send_stat, "Sent packets", "0", streaming, "") ;
149 CREATE_AND_ADD_TO_CAT( send_bytes_stat, "Sent bytes", "0", streaming, "kB") ;
150 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, "Sent bitrates", "0", streaming, "kb/s") ;
152 CREATE_AND_ADD_TO_CAT( adecoded_stat, "Decoded blocks", "0", audio, "") ;
153 CREATE_AND_ADD_TO_CAT( aplayed_stat, "Played buffers", "0", audio, "") ;
154 CREATE_AND_ADD_TO_CAT( alost_stat, "Lost buffers", "0", audio, "") ;
156 input->setExpanded( true );
157 video->setExpanded( true );
158 streaming->setExpanded( true );
159 audio->setExpanded( true );
161 StatsTree->resizeColumnToContents( 0 );
162 StatsTree->setColumnWidth( 1 , 100 );
165 InputStatsPanel::~InputStatsPanel()
169 void InputStatsPanel::update( input_item_t *p_item )
171 vlc_mutex_lock( &p_item->p_stats->lock );
173 #define UPDATE( widget, format, calc... ) \
174 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
176 UPDATE( read_media_stat, "%8.0f", (float)(p_item->p_stats->i_read_bytes)/1000);
177 UPDATE( input_bitrate_stat, "%6.0f",
178 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
179 UPDATE( demuxed_stat, "%8.0f",
180 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
181 UPDATE( stream_bitrate_stat, "%6.0f",
182 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
185 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
186 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
187 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
190 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
191 UPDATE( send_bytes_stat, "%8.0f",
192 (float)(p_item->p_stats->i_sent_bytes)/1000 );
193 UPDATE( send_bitrate_stat, "%6.0f",
194 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
197 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
198 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
199 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
201 vlc_mutex_unlock(& p_item->p_stats->lock );
204 void InputStatsPanel::clear()
208 /* Third panel - Stream info */
210 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
211 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();
221 // InfoTree->resize(400, 400);
224 InfoPanel::~InfoPanel()
228 void InfoPanel::update( input_item_t *p_item)
231 QTreeWidgetItem *current_item = NULL;
232 QTreeWidgetItem *child_item = NULL;
234 for( int i = 0; i< p_item->i_categories ; i++)
236 current_item = new QTreeWidgetItem();
237 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
238 InfoTree->addTopLevelItem( current_item );
240 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
242 child_item = new QTreeWidgetItem ();
243 child_item->setText( 0,
244 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
246 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
248 current_item->addChild(child_item);
250 InfoTree->setItemExpanded( current_item, true);
254 void InfoPanel::clear()
259 /***************************************************************************
261 ***************************************************************************/
263 InfoTab::InfoTab( QWidget *parent, intf_thread_t *_p_intf, bool _stats ) :
264 QTabWidget( parent ), stats( _stats ), p_intf( _p_intf )
266 // setGeometry(0, 0, 400, 500);
268 MP = new MetaPanel(NULL, p_intf);
269 addTab(MP, qtr("&General"));
270 IP = new InfoPanel(NULL, p_intf);
271 addTab(IP, qtr("&Details"));
274 ISP = new InputStatsPanel( NULL, p_intf );
275 addTab(ISP, qtr("&Stats"));
283 /* This function should be called approximately twice a second.
284 * p_item should be locked
285 * Stats will always be updated */
286 void InfoTab::update( input_item_t *p_item, bool update_info,
290 IP->update( p_item );
292 MP->update( p_item );
294 ISP->update( p_item );
297 void InfoTab::clear()
301 if( stats ) ISP->clear();