]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/infopanels.cpp
Qt4 - Copyright update and CRs
[vlc] / modules / gui / qt4 / components / infopanels.cpp
1 /*****************************************************************************
2  * infopanels.cpp : Panels for the information dialogs
3  ****************************************************************************
4  * Copyright (C) 2006-2007 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, qtr("Input") );
135     CREATE_CATEGORY( video, qtr("Video") );
136     CREATE_CATEGORY( streaming, qtr("Streaming") );
137     CREATE_CATEGORY( audio, qtr("Audio") );
138
139
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") ;
144
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, "") ;
148
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") ;
152
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, "") ;
156
157     input->setExpanded( true );
158     video->setExpanded( true );
159     streaming->setExpanded( true );
160     audio->setExpanded( true );
161
162     StatsTree->resizeColumnToContents( 0 );
163     StatsTree->setColumnWidth( 1 , 100 );
164 }
165
166 InputStatsPanel::~InputStatsPanel()
167 {
168 }
169
170 void InputStatsPanel::update( input_item_t *p_item )
171 {
172     vlc_mutex_lock( &p_item->p_stats->lock );
173
174 #define UPDATE( widget, format, calc... ) \
175     { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) );  }
176
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 ));
184
185     /* Video */
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 );
189
190     /* Sout */
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 );
196
197     /* Audio*/
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 );
201
202     vlc_mutex_unlock(& p_item->p_stats->lock );
203 }
204
205 void InputStatsPanel::clear()
206 {
207 }
208
209 /* Third panel - Stream info */
210
211 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
212                                       QWidget( parent ), p_intf( _p_intf )
213 {
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 }
222
223 InfoPanel::~InfoPanel()
224 {
225 }
226
227 void InfoPanel::update( input_item_t *p_item)
228 {
229     InfoTree->clear();
230     QTreeWidgetItem *current_item = NULL;
231     QTreeWidgetItem *child_item = NULL;
232
233     for( int i = 0; i< p_item->i_categories ; i++)
234     {
235         current_item = new QTreeWidgetItem();
236         current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
237         InfoTree->addTopLevelItem( current_item );
238
239         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
240         {
241             child_item = new QTreeWidgetItem ();
242             child_item->setText( 0,
243                     qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
244                     + ": "
245                     + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
246
247             current_item->addChild(child_item);
248         }
249          InfoTree->setItemExpanded( current_item, true);
250     }
251 }
252
253 void InfoPanel::clear()
254 {
255     InfoTree->clear();
256 }
257
258 /***************************************************************************
259  * Tab widget
260  ***************************************************************************/
261
262 InfoTab::InfoTab( QWidget *parent,  intf_thread_t *_p_intf, bool _stats ) :
263                       QTabWidget( parent ), stats( _stats ), p_intf( _p_intf )
264 {
265 //    setGeometry(0, 0, 400, 500);
266
267     MP = new MetaPanel(NULL, p_intf);
268     addTab(MP, qtr("&General"));
269     IP = new InfoPanel(NULL, p_intf);
270     addTab(IP, qtr("&Details"));
271     if( stats )
272     {
273         ISP = new InputStatsPanel( NULL, p_intf );
274         addTab(ISP, qtr("&Stats"));
275     }
276 }
277
278 InfoTab::~InfoTab()
279 {
280 }
281
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,
286                       bool update_meta )
287 {
288     if( update_info )
289         IP->update( p_item );
290     if( update_meta )
291         MP->update( p_item );
292     if( stats )
293         ISP->update( p_item );
294 }
295
296 void InfoTab::clear()
297 {
298     IP->clear();
299     MP->clear();
300     if( stats ) ISP->clear();
301 }