]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/infopanels.cpp
Qt4: add meta info panel and fix layout bug in stats
[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", (float)(p_item->p_stats->i_read_bytes)/1000);
55     UPDATE( input_bitrate_text, "%6.0f",
56                     (float)(p_item->p_stats->f_input_bitrate * 8000 ));
57     UPDATE( demuxed_text, "%8.0f",
58                     (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
59     UPDATE( stream_bitrate_text, "%6.0f",
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",
70             (float)(p_item->p_stats->i_sent_bytes)/1000 );
71     UPDATE( send_bitrate_text, "%6.0f",
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     int line = 0;
90     QGridLayout *l = new QGridLayout( this );
91 #define ADD_META( string, widget ) {                            \
92     l->addWidget( new QLabel( qfu( string ) ), line, 0 );       \
93     widget = new QLabel( "" );                                  \
94     l->addWidget( widget, line, 1 );                            \
95     line++;            }
96     ADD_META( _( "Name" ), name_text );
97     ADD_META( _( "URI" ), uri_text );
98     ADD_META( VLC_META_ARTIST, artist_text );
99     ADD_META( VLC_META_GENRE, genre_text );
100     ADD_META( VLC_META_COPYRIGHT, copyright_text );
101     ADD_META( VLC_META_COLLECTION, collection_text );
102     ADD_META( VLC_META_SEQ_NUM, seqnum_text );
103     ADD_META( VLC_META_DESCRIPTION, description_text );
104     ADD_META( VLC_META_RATING, rating_text );
105     ADD_META( VLC_META_DATE, date_text );
106     ADD_META( VLC_META_LANGUAGE, language_text );
107     ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
108     ADD_META( VLC_META_PUBLISHER, publisher_text );
109     ADD_META( VLC_META_SETTING, setting_text );
110 }
111
112 MetaPanel::~MetaPanel()
113 {
114 }
115
116 void MetaPanel::update( input_item_t *p_item )
117 {
118 #define UPDATE_META( meta, widget ) {               \
119     char* psz_meta = p_item->p_meta->psz_##meta;    \
120     if( !EMPTY_STR( psz_meta ) )                    \
121         widget->setText( qfu( psz_meta ) );         \
122     else                                            \
123         widget->setText( "" );          }
124
125     if( !EMPTY_STR( p_item->psz_name ) )
126         name_text->setText( qfu( p_item->psz_name ) );
127     else name_text->setText( "" );
128     if( !EMPTY_STR( p_item->psz_uri ) )
129         uri_text->setText( qfu( p_item->psz_uri ) );
130     else uri_text->setText( "" );
131     UPDATE_META( artist, artist_text );
132     UPDATE_META( genre, genre_text );
133     UPDATE_META( copyright, copyright_text );
134     UPDATE_META( album, collection_text );
135     UPDATE_META( tracknum, seqnum_text );
136     UPDATE_META( description, description_text );
137     UPDATE_META( rating, rating_text );
138     UPDATE_META( date, date_text );
139     UPDATE_META( language, language_text );
140     UPDATE_META( nowplaying, nowplaying_text );
141     UPDATE_META( publisher, publisher_text );
142     UPDATE_META( setting, setting_text );
143
144 #undef UPDATE_META
145 }
146
147 void MetaPanel::clear()
148 {
149 }
150
151 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
152                                       QWidget( parent ), p_intf( _p_intf )
153 {
154 //     resize(400, 500);
155      QGridLayout *layout = new QGridLayout(this);
156      InfoTree = new QTreeWidget(this);
157      QList<QTreeWidgetItem *> items;
158
159      layout->addWidget(InfoTree, 0, 0 );
160      InfoTree->setColumnCount( 1 );
161      InfoTree->header()->hide();
162 //     InfoTree->resize(400, 400);
163 }
164
165 InfoPanel::~InfoPanel()
166 {
167 }
168
169 void InfoPanel::update( input_item_t *p_item)
170 {
171     InfoTree->clear();
172     QTreeWidgetItem *current_item = NULL;
173     QTreeWidgetItem *child_item = NULL;
174
175     for( int i = 0; i< p_item->i_categories ; i++)
176     {
177         current_item = new QTreeWidgetItem();
178         current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
179         InfoTree->addTopLevelItem( current_item );
180
181         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
182         {
183             child_item = new QTreeWidgetItem ();
184             child_item->setText( 0,
185                     qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
186                     + ": "
187                     + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
188
189             current_item->addChild(child_item);
190         }
191          InfoTree->setItemExpanded( current_item, true);
192     }
193 }
194
195 void InfoPanel::clear()
196 {
197     InfoTree->clear();
198 }
199
200 /***************************************************************************
201  * Tab widget
202  ***************************************************************************/
203
204 InfoTab::InfoTab( QWidget *parent,  intf_thread_t *_p_intf, bool _stats ) :
205                       QTabWidget( parent ), stats( _stats ), p_intf( _p_intf )
206 {
207 //    setGeometry(0, 0, 400, 500);
208
209     MP = new MetaPanel(NULL, p_intf);
210     addTab(MP, qtr("&General"));
211     IP = new InfoPanel(NULL, p_intf);
212     addTab(IP, qtr("&Details"));
213     if( stats )
214     {
215         ISP = new InputStatsPanel( NULL, p_intf );
216         addTab(ISP, qtr("&Stats"));
217     }
218 }
219
220 InfoTab::~InfoTab()
221 {
222 }
223
224 /* This function should be called approximately twice a second.
225  * p_item should be locked
226  * Stats will always be updated */
227 void InfoTab::update( input_item_t *p_item, bool update_info,
228                       bool update_meta )
229 {
230     if( update_info )
231         IP->update( p_item );
232     if( update_meta )
233         MP->update( p_item );
234     if( stats )
235         ISP->update( p_item );
236 }
237
238 void InfoTab::clear()
239 {
240     IP->clear();
241     MP->clear();
242     if( stats ) ISP->clear();
243 }