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