]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/infopanels.cpp
Qt4 - MediaInfo: spaces cleanup
[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 "qt4.hpp"
26 #include "components/infopanels.hpp"
27
28 #include <QTreeWidget>
29 #include <QListView>
30 #include <QPushButton>
31 #include <QHeaderView>
32 #include <QList>
33 #include <QGridLayout>
34 #include <QLineEdit>
35 #include <QLabel>
36 #include <QSpinBox>
37 #include <QTabWidget>
38
39 /************************************************************************
40  * Single panels
41  ************************************************************************/
42
43 /* First Panel - Meta Info */
44
45 MetaPanel::MetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
46                                     QWidget( parent ), p_intf( _p_intf )
47 {
48     int line = 0;
49     QGridLayout *l = new QGridLayout( this );
50     l->setColumnStretch( 2, 5 );
51     l->setColumnStretch( 5, 3 );
52
53 #define ADD_META( string, widget ) {                             \
54     l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
55     widget = new QLineEdit;                                      \
56     l->addWidget( widget, line, 1, 1, 7 );                       \
57     line++;            }
58
59     ADD_META( VLC_META_TITLE, title_text ); /* OK */
60     ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
61     ADD_META( VLC_META_GENRE, genre_text ); /* FIXME List id3genres.h is not
62                                                includable yet ? */
63
64     /* Album Name */
65     l->addWidget( new QLabel( qfu( VLC_META_COLLECTION ) + " :" ), line, 0 );
66     collection_text = new QLineEdit;
67     l->addWidget( collection_text, line, 1, 1, 5 );
68     l->addWidget( new QLabel( qfu( VLC_META_DATE ) + " :" ), line, 6 );
69     /* Date (Should be in years) */
70     date_text = new QSpinBox; setSpinBounds( date_text );
71     l->addWidget( date_text, line, 7 );
72     line++;
73
74     /* Number and Rating */
75     l->addWidget( new QLabel( qfu( _("Track number/Position" ) ) + " :" ),
76                   line, 0 );
77     seqnum_text = new QSpinBox; setSpinBounds( seqnum_text );
78     l->addWidget( seqnum_text, line, 1, 1, 3 );
79
80     l->addWidget( new QLabel( qfu( VLC_META_RATING ) + " :" ), line, 4 );
81     rating_text = new QSpinBox; setSpinBounds( rating_text) ;
82     l->addWidget( rating_text, line, 5, 1, 3 );
83     line++;
84
85     ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
86
87     /* Language and settings */
88     l->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 0 );
89     language_text = new QLineEdit;
90     l->addWidget( language_text, line, 1, 1, 3 );
91     l->addWidget( new QLabel( qfu( VLC_META_SETTING ) + " :" ), line, 4 );
92     setting_text = new QLineEdit;
93     l->addWidget( setting_text, line, 5, 1, 3 );
94     line++;
95
96     ADD_META( VLC_META_COPYRIGHT, copyright_text );
97     ADD_META( VLC_META_PUBLISHER, publisher_text );
98
99     ADD_META( VLC_META_ENCODED_BY, publisher_text );
100     ADD_META( VLC_META_DESCRIPTION, description_text ); // Comment Two lines?
101
102     /*  ADD_META( TRACKID)  DO NOT SHOW it */
103
104     // ADD_META( _( "URI" ), uri_text ); // FIXME URI outside
105     //    ADD_META( VLC_META_URL, setting_text );
106     /* ART_URL */
107 }
108
109 MetaPanel::~MetaPanel()
110 {
111 }
112
113 void MetaPanel::update( input_item_t *p_item )
114 {
115     char *psz_meta;
116 #define UPDATE_META( meta, widget ) {               \
117     psz_meta = p_item->p_meta->psz_##meta;          \
118     if( !EMPTY_STR( psz_meta ) )                    \
119         widget->setText( qfu( psz_meta ) );         \
120     else                                            \
121         widget->setText( "" );          }
122
123 #define UPDATE_META_INT( meta, widget ) {           \
124     psz_meta = p_item->p_meta->psz_##meta;          \
125     if( !EMPTY_STR( psz_meta ) )                    \
126         widget->setValue( atoi( psz_meta ) ); }/*FIXME Atoi ?*/
127
128     /* Name / Title */
129     psz_meta = p_item->p_meta->psz_title;
130     if( !EMPTY_STR( psz_meta ) )
131         title_text->setText( qfu( psz_meta ) );
132     else if( !EMPTY_STR( p_item->psz_name ) )
133         title_text->setText( qfu( p_item->psz_name ) );
134     else title_text->setText( "" );
135
136   /*  if( !EMPTY_STR( p_item->psz_uri ) )
137         uri_text->setText( qfu( p_item->psz_uri ) );*/
138 ///    else uri_text->setText( "" );
139
140     UPDATE_META( artist, artist_text );
141     UPDATE_META( genre, genre_text );
142     UPDATE_META( copyright, copyright_text );
143     UPDATE_META( album, collection_text );
144     UPDATE_META( description, description_text );
145     UPDATE_META( language, language_text );
146     UPDATE_META( nowplaying, nowplaying_text );
147     UPDATE_META( publisher, publisher_text );
148     UPDATE_META( setting, setting_text );
149
150     UPDATE_META_INT( date, date_text );
151     UPDATE_META_INT( tracknum, seqnum_text );
152     UPDATE_META_INT( rating, rating_text );
153
154 #undef UPDATE_META
155 }
156
157 void MetaPanel::clear(){}
158
159 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
160                                         QWidget( parent ), p_intf( _p_intf )
161 {
162      QGridLayout *layout = new QGridLayout(this);
163      QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
164                  " are shown in this list.\n" ) );
165      topLabel->setWordWrap( true );
166      layout->addWidget( topLabel, 0, 0 );
167
168      extraMetaTree = new QTreeWidget( this );
169      extraMetaTree->setAlternatingRowColors( true );
170      extraMetaTree->setColumnCount( 2 );
171
172      extraMetaTree->header()->hide();
173 /*     QStringList *treeHeaders;
174      treeHeaders << qtr( "Test1" ) << qtr( "Test2" ); */
175
176      layout->addWidget( extraMetaTree, 1, 0 );
177 }
178
179 void ExtraMetaPanel::update( input_item_t *p_item )
180 {
181     vlc_meta_t *p_meta = p_item->p_meta;
182     QStringList tempItem;
183
184     QList<QTreeWidgetItem *> items;
185     for (int i = 0; i < p_meta->i_extra; i++ )
186     {
187         tempItem.append( qfu( p_meta->ppsz_extra_name[i] ) + " : ");
188         tempItem.append( qfu( p_meta->ppsz_extra_value[i] ) );
189         items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
190     }
191     extraMetaTree->addTopLevelItems( items );
192 }
193
194 void ExtraMetaPanel::clear(){}
195
196 /* Second Panel - Stats */
197
198 InputStatsPanel::InputStatsPanel( QWidget *parent, intf_thread_t *_p_intf ) :
199                                   QWidget( parent ), p_intf( _p_intf )
200 {
201      QGridLayout *layout = new QGridLayout(this);
202      StatsTree = new QTreeWidget(this);
203      QList<QTreeWidgetItem *> items;
204      QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
205                  " media or stream.\n Played and streamed info are shown." ) );
206      topLabel->setWordWrap( true );
207      layout->addWidget( topLabel, 0, 0 );
208
209      StatsTree->setColumnCount( 3 );
210      StatsTree->header()->hide();
211
212 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) {              \
213     itemName =                                                                 \
214       new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
215     itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
216
217 #define CREATE_CATEGORY( catName, itemText ) {                           \
218     CREATE_TREE_ITEM( catName, itemText , "", "" );                      \
219     catName->setExpanded( true );                                        \
220     StatsTree->addTopLevelItem( catName );    }
221
222 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
223     CREATE_TREE_ITEM( itemName, itemText, itemValue, unit );                   \
224     catName->addChild( itemName ); }
225
226     /* Create the main categories */
227     CREATE_CATEGORY( input, qtr("Input") );
228     CREATE_CATEGORY( video, qtr("Video") );
229     CREATE_CATEGORY( streaming, qtr("Streaming") );
230     CREATE_CATEGORY( audio, qtr("Audio") );
231
232     CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
233                            "0", input , "kB" );
234     CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
235                            "0", input, "kb/s" );
236     CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
237     CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
238                            "0", input, "kb/s" );
239
240     CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
241                            "0", video, "" );
242     CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
243                            "0", video, "" );
244     CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
245                            "0", video, "" );
246
247     CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
248     CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
249                            "0", streaming, "kB" );
250     CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
251                            "0", streaming, "kb/s" );
252
253     CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
254                            "0", audio, "" );
255     CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
256                            "0", audio, "" );
257     CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
258
259     input->setExpanded( true );
260     video->setExpanded( true );
261     streaming->setExpanded( true );
262     audio->setExpanded( true );
263
264     StatsTree->resizeColumnToContents( 0 );
265     StatsTree->setColumnWidth( 1 , 100 );
266
267     layout->addWidget(StatsTree, 1, 0 );
268 }
269
270 InputStatsPanel::~InputStatsPanel()
271 {
272 }
273
274 void InputStatsPanel::update( input_item_t *p_item )
275 {
276     vlc_mutex_lock( &p_item->p_stats->lock );
277
278 #define UPDATE( widget, format, calc... ) \
279     { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) );  }
280
281     UPDATE( read_media_stat, "%8.0f",
282             (float)(p_item->p_stats->i_read_bytes)/1000);
283     UPDATE( input_bitrate_stat, "%6.0f",
284                     (float)(p_item->p_stats->f_input_bitrate * 8000 ));
285     UPDATE( demuxed_stat, "%8.0f",
286                     (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
287     UPDATE( stream_bitrate_stat, "%6.0f",
288                     (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
289
290     /* Video */
291     UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
292     UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
293     UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
294
295     /* Sout */
296     UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
297     UPDATE( send_bytes_stat, "%8.0f",
298             (float)(p_item->p_stats->i_sent_bytes)/1000 );
299     UPDATE( send_bitrate_stat, "%6.0f",
300             (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
301
302     /* Audio*/
303     UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
304     UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
305     UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
306
307     vlc_mutex_unlock(& p_item->p_stats->lock );
308 }
309
310 void InputStatsPanel::clear()
311 {
312 }
313
314 /* Third panel - Stream info */
315
316 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
317                                       QWidget( parent ), p_intf( _p_intf )
318 {
319      QGridLayout *layout = new QGridLayout(this);
320      InfoTree = new QTreeWidget(this);
321      QList<QTreeWidgetItem *> items;
322
323      QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
324               " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
325               "are shown." ) );
326      topLabel->setWordWrap( true );
327      layout->addWidget( topLabel, 0, 0 );
328
329      InfoTree->setColumnCount( 1 );
330      InfoTree->header()->hide();
331      layout->addWidget(InfoTree, 1, 0 );
332 }
333
334 InfoPanel::~InfoPanel()
335 {
336 }
337
338 void InfoPanel::update( input_item_t *p_item)
339 {
340     InfoTree->clear();
341     QTreeWidgetItem *current_item = NULL;
342     QTreeWidgetItem *child_item = NULL;
343
344     for( int i = 0; i< p_item->i_categories ; i++)
345     {
346         current_item = new QTreeWidgetItem();
347         current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
348         InfoTree->addTopLevelItem( current_item );
349
350         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
351         {
352             child_item = new QTreeWidgetItem ();
353             child_item->setText( 0,
354                     qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
355                     + ": "
356                     + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
357
358             current_item->addChild(child_item);
359         }
360          InfoTree->setItemExpanded( current_item, true);
361     }
362 }
363
364 void InfoPanel::clear()
365 {
366     InfoTree->clear();
367 }