]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/infopanels.cpp
* Qt4 : Use a QTreeWidget instead of a ui to display stats. I hope in that way it...
[vlc] / modules / gui / qt4 / components / infopanels.cpp
1 /*****************************************************************************
2  * infopanels.cpp : Panels for the information dialogs
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #include "components/infopanels.hpp"
26 #include "qt4.hpp"
27
28 #include <QTreeWidget>
29 #include <QPushButton>
30 #include <QHeaderView>
31 #include <QList>
32 #include <QGridLayout>
33
34
35 /************************************************************************
36  * Single panels
37  ************************************************************************/
38
39 /* First Panel - Meta Info */
40
41 MetaPanel::MetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
42                                     QWidget( parent ), p_intf( _p_intf )
43 {
44     int line = 0;
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 );                            \
50     line++;            }
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 );
65 }
66
67 MetaPanel::~MetaPanel()
68 {
69 }
70
71 void MetaPanel::update( input_item_t *p_item )
72 {
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 ) );         \
77     else                                            \
78         widget->setText( "" );          }
79
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 );
98
99 #undef UPDATE_META
100 }
101
102 void MetaPanel::clear()
103 {
104 }
105
106 /* Second Panel - Stats */
107
108 InputStatsPanel::InputStatsPanel( QWidget *parent, intf_thread_t *_p_intf ) :
109                                   QWidget( parent ), p_intf( _p_intf )
110 {
111      QGridLayout *layout = new QGridLayout(this);
112      StatsTree = new QTreeWidget(this);
113      QList<QTreeWidgetItem *> items;
114
115      layout->addWidget(StatsTree, 0, 0 );
116      StatsTree->setColumnCount( 3 );
117      StatsTree->header()->hide();
118
119 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) {              \
120     itemName =                                                           \
121         new QTreeWidgetItem((QStringList () << itemText << itemValue << unit ));  \
122     itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
123
124
125 #define CREATE_CATEGORY( catName, itemText ) {                           \
126     CREATE_TREE_ITEM( catName, itemText , "", "" );                      \
127     catName->setExpanded( true );                                        \
128     StatsTree->addTopLevelItem( catName );    }
129
130 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ) { \
131     CREATE_TREE_ITEM( itemName, itemText, itemValue, unit );             \
132     catName->addChild( itemName ); }
133
134     CREATE_CATEGORY( input, "Input" );
135     CREATE_CATEGORY( video, "Video" );
136     CREATE_CATEGORY( streaming, "Streaming" );
137     CREATE_CATEGORY( audio, "Audio" );
138
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") ;
143
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, "") ;
147
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") ;
151
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, "") ;
155
156     input->setExpanded( true );
157     video->setExpanded( true );
158     streaming->setExpanded( true );
159     audio->setExpanded( true );
160
161     StatsTree->resizeColumnToContents( 0 );
162     StatsTree->setColumnWidth( 1 , 100 );
163 }
164
165 InputStatsPanel::~InputStatsPanel()
166 {
167 }
168
169 void InputStatsPanel::update( input_item_t *p_item )
170 {
171     vlc_mutex_lock( &p_item->p_stats->lock );
172
173 #define UPDATE( widget, format, calc... ) \
174     { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) );  }
175
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 ));
183
184     /* Video */
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 );
188
189     /* Sout */
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 );
195
196     /* Audio*/
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 );
200
201     vlc_mutex_unlock(& p_item->p_stats->lock );
202 }
203
204 void InputStatsPanel::clear()
205 {
206 }
207
208 /* Third panel - Stream info */
209
210 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
211                                       QWidget( parent ), p_intf( _p_intf )
212 {
213 //     resize(400, 500);
214      QGridLayout *layout = new QGridLayout(this);
215      InfoTree = new QTreeWidget(this);
216      QList<QTreeWidgetItem *> items;
217
218      layout->addWidget(InfoTree, 0, 0 );
219      InfoTree->setColumnCount( 1 );
220      InfoTree->header()->hide();
221 //     InfoTree->resize(400, 400);
222 }
223
224 InfoPanel::~InfoPanel()
225 {
226 }
227
228 void InfoPanel::update( input_item_t *p_item)
229 {
230     InfoTree->clear();
231     QTreeWidgetItem *current_item = NULL;
232     QTreeWidgetItem *child_item = NULL;
233
234     for( int i = 0; i< p_item->i_categories ; i++)
235     {
236         current_item = new QTreeWidgetItem();
237         current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
238         InfoTree->addTopLevelItem( current_item );
239
240         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
241         {
242             child_item = new QTreeWidgetItem ();
243             child_item->setText( 0,
244                     qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
245                     + ": "
246                     + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
247
248             current_item->addChild(child_item);
249         }
250          InfoTree->setItemExpanded( current_item, true);
251     }
252 }
253
254 void InfoPanel::clear()
255 {
256     InfoTree->clear();
257 }
258
259 /***************************************************************************
260  * Tab widget
261  ***************************************************************************/
262
263 InfoTab::InfoTab( QWidget *parent,  intf_thread_t *_p_intf, bool _stats ) :
264                       QTabWidget( parent ), stats( _stats ), p_intf( _p_intf )
265 {
266 //    setGeometry(0, 0, 400, 500);
267
268     MP = new MetaPanel(NULL, p_intf);
269     addTab(MP, qtr("&General"));
270     IP = new InfoPanel(NULL, p_intf);
271     addTab(IP, qtr("&Details"));
272     if( stats )
273     {
274         ISP = new InputStatsPanel( NULL, p_intf );
275         addTab(ISP, qtr("&Stats"));
276     }
277 }
278
279 InfoTab::~InfoTab()
280 {
281 }
282
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,
287                       bool update_meta )
288 {
289     if( update_info )
290         IP->update( p_item );
291     if( update_meta )
292         MP->update( p_item );
293     if( stats )
294         ISP->update( p_item );
295 }
296
297 void InfoTab::clear()
298 {
299     IP->clear();
300     MP->clear();
301     if( stats ) ISP->clear();
302 }