]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/infopanels.cpp
A bit of cleanup in the info stuff
[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
33 /************************************************************************
34  * Single panels
35  ************************************************************************/
36
37 InputStatsPanel::InputStatsPanel( QWidget *parent, intf_thread_t *_p_intf ) :
38                                   QWidget( parent ), p_intf( _p_intf )
39 {
40     ui.setupUi( this );
41 }
42
43 InputStatsPanel::~InputStatsPanel()
44 {
45 }
46
47 void InputStatsPanel::update( input_item_t *p_item )
48 {
49     vlc_mutex_lock( &p_item->p_stats->lock );
50
51 #define UPDATE( widget,format, calc... ) \
52     { QString str; ui.widget->setText( str.sprintf( format, ## calc ) );  }
53
54     UPDATE( read_text, "%8.0f kB", (float)(p_item->p_stats->i_read_bytes)/1000);
55     UPDATE( input_bitrate_text, "%6.0f kb/s",
56                     (float)(p_item->p_stats->f_input_bitrate * 8000 ));
57     UPDATE( demuxed_text, "%8.0f kB",
58                     (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
59     UPDATE( stream_bitrate_text, "%6.0f kb/s",
60                     (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
61
62     /* Video */
63     UPDATE( vdecoded_text, "%5i", p_item->p_stats->i_decoded_video );
64     UPDATE( vdisplayed_text, "%5i", p_item->p_stats->i_displayed_pictures );
65     UPDATE( vlost_frames, "%5i", p_item->p_stats->i_lost_pictures );
66
67     /* Sout */
68     UPDATE( sent_text, "%5i", p_item->p_stats->i_sent_packets );
69     UPDATE( sent_bytes_text, "%8.0f kB",
70             (float)(p_item->p_stats->i_sent_bytes)/1000 );
71     UPDATE( send_bitrate_text, "%6.0f kb/s",
72             (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
73
74     /* Audio*/
75     UPDATE( adecoded_text, "%5i", p_item->p_stats->i_decoded_audio );
76     UPDATE( aplayed_text, "%5i", p_item->p_stats->i_played_abuffers );
77     UPDATE( alost_text, "%5i", p_item->p_stats->i_lost_abuffers );
78
79     vlc_mutex_unlock(& p_item->p_stats->lock );
80 }
81
82 void InputStatsPanel::clear()
83 {
84 }
85
86 MetaPanel::MetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
87                                     QWidget( parent ), p_intf( _p_intf )
88 {
89
90 }
91 MetaPanel::~MetaPanel()
92 {
93 }
94 void MetaPanel::update( input_item_t *p_item )
95 {
96 }
97 void MetaPanel::clear()
98 {
99 }
100
101 char* MetaPanel::getURI()
102 {
103     char *URI;
104     return URI;
105 }
106
107 char* MetaPanel::getName()
108 {
109     char *Name;
110     return Name;
111 }
112
113
114 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
115                                       QWidget( parent ), p_intf( _p_intf )
116 {
117 //     resize(400, 500);
118      QGridLayout *layout = new QGridLayout(this);
119      InfoTree = new QTreeWidget(this);
120      QList<QTreeWidgetItem *> items;
121
122      layout->addWidget(InfoTree, 0, 0 );
123      InfoTree->setColumnCount( 1 );
124      InfoTree->header()->hide();
125 //     InfoTree->resize(400, 400);
126 }
127
128 InfoPanel::~InfoPanel()
129 {
130 }
131
132 void InfoPanel::update( input_item_t *p_item)
133 {
134     InfoTree->clear();
135     QTreeWidgetItem *current_item = NULL;
136     QTreeWidgetItem *child_item = NULL;
137
138     for( int i = 0; i< p_item->i_categories ; i++)
139     {
140         current_item = new QTreeWidgetItem();
141         current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
142         InfoTree->addTopLevelItem( current_item );
143
144         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
145         {
146             child_item = new QTreeWidgetItem ();
147             child_item->setText( 0,
148                     qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
149                     + ": "
150                     + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
151
152             current_item->addChild(child_item);
153         }
154          InfoTree->setItemExpanded( current_item, true);
155     }
156 }
157
158 void InfoPanel::clear()
159 {
160     InfoTree->clear();
161 }
162
163 /***************************************************************************
164  * Tab widget
165  ***************************************************************************/
166
167 InfoTab::InfoTab( QWidget *parent,  intf_thread_t *_p_intf, bool _stats ) :
168                       QTabWidget( parent ), stats( _stats ), p_intf( _p_intf )
169 {
170 //    setGeometry(0, 0, 400, 500);
171
172     MP = new MetaPanel(NULL, p_intf);
173     addTab(MP, qtr("&Meta"));
174     if( stats )
175     {
176         ISP = new InputStatsPanel( NULL, p_intf );
177         addTab(ISP, qtr("&Stats"));
178     }
179
180     IP = new InfoPanel(NULL, p_intf);
181     addTab(IP, qtr("&Info"));
182 }
183
184 InfoTab::~InfoTab()
185 {
186 }
187
188 /* This function should be called approximately twice a second.
189  * p_item should be locked
190  * Stats will always be updated */
191 void InfoTab::update( input_item_t *p_item, bool update_info,
192                       bool update_meta )
193 {
194     if( update_info )
195         IP->update( p_item );
196     if( update_meta )
197         MP->update( p_item );
198     if( stats )
199         ISP->update( p_item );
200 }
201
202 void InfoTab::clear()
203 {
204     IP->clear();
205     MP->clear();
206     if( stats ) ISP->clear();
207 }