]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/infopanels.cpp
Qt4 - Meta Information, again. Add URI/URL support. Fix a bug.
[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     /*  ADD_URI - DO not show it, done outside */
104
105     /* ART_URL */
106     //    ADD_META( VLC_META_URL, setting_text );
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 ) ); }
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     /* URL / URI */
137     psz_meta = p_item->p_meta->psz_url;
138     if( !EMPTY_STR( psz_meta ) )
139         emit uriSet( QString( psz_meta ) );
140     else if( !EMPTY_STR( p_item->psz_uri ) )
141         emit uriSet( QString( p_item->psz_uri ) );
142
143     /* Other classic though */
144     UPDATE_META( artist, artist_text );
145     UPDATE_META( genre, genre_text );
146     UPDATE_META( copyright, copyright_text );
147     UPDATE_META( album, collection_text );
148     UPDATE_META( description, description_text );
149     UPDATE_META( language, language_text );
150     UPDATE_META( nowplaying, nowplaying_text );
151     UPDATE_META( publisher, publisher_text );
152     UPDATE_META( setting, setting_text );
153
154     UPDATE_META_INT( date, date_text );
155     UPDATE_META_INT( tracknum, seqnum_text );
156     UPDATE_META_INT( rating, rating_text );
157
158 #undef UPDATE_META
159 }
160
161 void MetaPanel::clear(){}
162
163 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
164                                         QWidget( parent ), p_intf( _p_intf )
165 {
166      QGridLayout *layout = new QGridLayout(this);
167      QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
168                  " are shown in this list.\n" ) );
169      topLabel->setWordWrap( true );
170      layout->addWidget( topLabel, 0, 0 );
171
172      extraMetaTree = new QTreeWidget( this );
173      extraMetaTree->setAlternatingRowColors( true );
174      extraMetaTree->setColumnCount( 2 );
175
176      extraMetaTree->header()->hide();
177 /*     QStringList *treeHeaders;
178      treeHeaders << qtr( "Test1" ) << qtr( "Test2" ); */
179
180      layout->addWidget( extraMetaTree, 1, 0 );
181 }
182
183 void ExtraMetaPanel::update( input_item_t *p_item )
184 {
185     vlc_meta_t *p_meta = p_item->p_meta;
186     QStringList tempItem;
187
188     QList<QTreeWidgetItem *> items;
189     for (int i = 0; i < p_meta->i_extra; i++ )
190     {
191         tempItem.append( qfu( p_meta->ppsz_extra_name[i] ) + " : ");
192         tempItem.append( qfu( p_meta->ppsz_extra_value[i] ) );
193         items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
194     }
195     extraMetaTree->addTopLevelItems( items );
196 }
197
198 void ExtraMetaPanel::clear(){}
199
200 /* Second Panel - Stats */
201
202 InputStatsPanel::InputStatsPanel( QWidget *parent, intf_thread_t *_p_intf ) :
203                                   QWidget( parent ), p_intf( _p_intf )
204 {
205      QGridLayout *layout = new QGridLayout(this);
206      StatsTree = new QTreeWidget(this);
207      QList<QTreeWidgetItem *> items;
208      QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
209                  " media or stream.\n Played and streamed info are shown." ) );
210      topLabel->setWordWrap( true );
211      layout->addWidget( topLabel, 0, 0 );
212
213      StatsTree->setColumnCount( 3 );
214      StatsTree->header()->hide();
215
216 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) {              \
217     itemName =                                                                 \
218       new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
219     itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
220
221 #define CREATE_CATEGORY( catName, itemText ) {                           \
222     CREATE_TREE_ITEM( catName, itemText , "", "" );                      \
223     catName->setExpanded( true );                                        \
224     StatsTree->addTopLevelItem( catName );    }
225
226 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
227     CREATE_TREE_ITEM( itemName, itemText, itemValue, unit );                   \
228     catName->addChild( itemName ); }
229
230     /* Create the main categories */
231     CREATE_CATEGORY( input, qtr("Input") );
232     CREATE_CATEGORY( video, qtr("Video") );
233     CREATE_CATEGORY( streaming, qtr("Streaming") );
234     CREATE_CATEGORY( audio, qtr("Audio") );
235
236     CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
237                            "0", input , "kB" );
238     CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
239                            "0", input, "kb/s" );
240     CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
241     CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
242                            "0", input, "kb/s" );
243
244     CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
245                            "0", video, "" );
246     CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
247                            "0", video, "" );
248     CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
249                            "0", video, "" );
250
251     CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
252     CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
253                            "0", streaming, "kB" );
254     CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
255                            "0", streaming, "kb/s" );
256
257     CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
258                            "0", audio, "" );
259     CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
260                            "0", audio, "" );
261     CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
262
263     input->setExpanded( true );
264     video->setExpanded( true );
265     streaming->setExpanded( true );
266     audio->setExpanded( true );
267
268     StatsTree->resizeColumnToContents( 0 );
269     StatsTree->setColumnWidth( 1 , 100 );
270
271     layout->addWidget(StatsTree, 1, 0 );
272 }
273
274 InputStatsPanel::~InputStatsPanel()
275 {
276 }
277
278 void InputStatsPanel::update( input_item_t *p_item )
279 {
280     vlc_mutex_lock( &p_item->p_stats->lock );
281
282 #define UPDATE( widget, format, calc... ) \
283     { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) );  }
284
285     UPDATE( read_media_stat, "%8.0f",
286             (float)(p_item->p_stats->i_read_bytes)/1000);
287     UPDATE( input_bitrate_stat, "%6.0f",
288                     (float)(p_item->p_stats->f_input_bitrate * 8000 ));
289     UPDATE( demuxed_stat, "%8.0f",
290                     (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
291     UPDATE( stream_bitrate_stat, "%6.0f",
292                     (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
293
294     /* Video */
295     UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
296     UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
297     UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
298
299     /* Sout */
300     UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
301     UPDATE( send_bytes_stat, "%8.0f",
302             (float)(p_item->p_stats->i_sent_bytes)/1000 );
303     UPDATE( send_bitrate_stat, "%6.0f",
304             (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
305
306     /* Audio*/
307     UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
308     UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
309     UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
310
311     vlc_mutex_unlock(& p_item->p_stats->lock );
312 }
313
314 void InputStatsPanel::clear()
315 {
316 }
317
318 /* Third panel - Stream info */
319
320 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
321                                       QWidget( parent ), p_intf( _p_intf )
322 {
323      QGridLayout *layout = new QGridLayout(this);
324      InfoTree = new QTreeWidget(this);
325      QList<QTreeWidgetItem *> items;
326
327      QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
328               " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
329               "are shown." ) );
330      topLabel->setWordWrap( true );
331      layout->addWidget( topLabel, 0, 0 );
332
333      InfoTree->setColumnCount( 1 );
334      InfoTree->header()->hide();
335      layout->addWidget(InfoTree, 1, 0 );
336 }
337
338 InfoPanel::~InfoPanel()
339 {
340 }
341
342 void InfoPanel::update( input_item_t *p_item)
343 {
344     InfoTree->clear();
345     QTreeWidgetItem *current_item = NULL;
346     QTreeWidgetItem *child_item = NULL;
347
348     for( int i = 0; i< p_item->i_categories ; i++)
349     {
350         current_item = new QTreeWidgetItem();
351         current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
352         InfoTree->addTopLevelItem( current_item );
353
354         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
355         {
356             child_item = new QTreeWidgetItem ();
357             child_item->setText( 0,
358                     qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
359                     + ": "
360                     + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
361
362             current_item->addChild(child_item);
363         }
364          InfoTree->setItemExpanded( current_item, true);
365     }
366 }
367
368 void InfoPanel::clear()
369 {
370     InfoTree->clear();
371 }