]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/info_panels.cpp
Qt: use a less small font on mediainfo.
[vlc] / modules / gui / qt4 / components / info_panels.cpp
1 /*****************************************************************************
2  * info_panels.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  *          Ilkka Ollakka <ileoo@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #define __STDC_FORMAT_MACROS 1
27 #define __STDC_CONSTANT_MACROS 1
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include "qt4.hpp"
34 #include "components/info_panels.hpp"
35 #include "components/interface_widgets.hpp"
36
37 #include <assert.h>
38 #include <vlc_url.h>
39 #include <vlc_meta.h>
40
41 #include <QTreeWidget>
42 #include <QHeaderView>
43 #include <QList>
44 #include <QStringList>
45 #include <QGridLayout>
46 #include <QLineEdit>
47 #include <QLabel>
48 #include <QSpinBox>
49 #include <QTextEdit>
50
51 /************************************************************************
52  * Single panels
53  ************************************************************************/
54
55 /**
56  * First Panel - Meta Info
57  * All the usual MetaData are displayed and can be changed.
58  **/
59 MetaPanel::MetaPanel( QWidget *parent,
60                       intf_thread_t *_p_intf )
61                       : QWidget( parent ), p_intf( _p_intf )
62 {
63     QGridLayout *metaLayout = new QGridLayout( this );
64     metaLayout->setVerticalSpacing( 0 );
65
66     QFont smallFont = QApplication::font();
67     smallFont.setPointSize( smallFont.pointSize() - 1 );
68     smallFont.setBold( true );
69
70     int line = 0; /* Counter for GridLayout */
71     p_input = NULL;
72     QLabel *label;
73
74 #define ADD_META( string, widget, col, colspan ) {                        \
75     label = new QLabel( qtr( string ) ); label->setFont( smallFont );     \
76     label->setContentsMargins( 3, 2, 0, 0 );                              \
77     metaLayout->addWidget( label, line++, col, 1, colspan );              \
78     widget = new QLineEdit;                                               \
79     metaLayout->addWidget( widget, line, col, 1, colspan );               \
80     CONNECT( widget, textEdited( QString ), this, enterEditMode() );      \
81 }
82
83     /* Title, artist and album*/
84     ADD_META( VLC_META_TITLE, title_text, 0, 10 ); line++;
85     ADD_META( VLC_META_ARTIST, artist_text, 0, 10 ); line++;
86     ADD_META( VLC_META_ALBUM, collection_text, 0, 7 );
87
88     /* Date */
89     label = new QLabel( qtr( VLC_META_DATE ) );
90     label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
91     metaLayout->addWidget( label, line - 1, 7, 1, 2 );
92
93     /* Date (Should be in years) */
94     date_text = new QLineEdit;
95     date_text->setAlignment( Qt::AlignRight );
96     date_text->setInputMask("0000");
97     date_text->setMaximumWidth( 128 );
98     metaLayout->addWidget( date_text, line, 7, 1, -1 );
99     line++;
100
101     /* Genre Name */
102     /* TODO List id3genres.h is not includable yet ? */
103     ADD_META( VLC_META_GENRE, genre_text, 0, 7 );
104
105     /* Number - on the same line */
106     label = new QLabel( qtr( VLC_META_TRACK_NUMBER ) );
107     label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
108     metaLayout->addWidget( label, line - 1, 7, 1, 3  );
109
110     seqnum_text = new QLineEdit;
111     seqnum_text->setMaximumWidth( 60 );
112     metaLayout->addWidget( seqnum_text, line, 7, 1, 1 );
113
114     label = new QLabel( "/" ); label->setFont( smallFont );
115     metaLayout->addWidget( label, line, 8, 1, 1 );
116
117     seqtot_text = new QLineEdit;
118     seqtot_text->setMaximumWidth( 60 );
119     metaLayout->addWidget( seqtot_text, line, 9, 1, 1 );
120     line++;
121
122     /* Rating - on the same line */
123     /*
124     metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) ), line, 4, 1, 2 );
125     rating_text = new QSpinBox; setSpinBounds( rating_text );
126     metaLayout->addWidget( rating_text, line, 6, 1, 1 );
127     */
128
129     /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
130     ADD_META( VLC_META_NOW_PLAYING, nowplaying_text, 0, 7 );
131     nowplaying_text->setReadOnly( true ); line--;
132
133     /* Language on the same line */
134     ADD_META( VLC_META_LANGUAGE, language_text, 7, -1 ); line++;
135     ADD_META( VLC_META_PUBLISHER, publisher_text, 0, 7 ); line++;
136
137     lblURL = new QLabel;
138     lblURL->setOpenExternalLinks( true );
139     lblURL->setTextFormat( Qt::RichText );
140     metaLayout->addWidget( lblURL, line -1, 7, 1, -1 );
141
142     ADD_META( VLC_META_COPYRIGHT, copyright_text, 0,  7 ); line++;
143
144     /* ART_URL */
145     art_cover = new CoverArtLabel( this, p_intf );
146     metaLayout->addWidget( art_cover, line, 7, 6, 3, Qt::AlignLeft );
147
148     ADD_META( VLC_META_ENCODED_BY, encodedby_text, 0, 7 ); line++;
149
150     label = new QLabel( qtr( N_("Comments") ) ); label->setFont( smallFont );
151     label->setContentsMargins( 3, 2, 0, 0 );
152     metaLayout->addWidget( label, line++, 0, 1, 7 );
153     description_text = new QTextEdit;
154     description_text->setAcceptRichText( false );
155     metaLayout->addWidget( description_text, line, 0, 1, 7 );
156     // CONNECT( description_text, textChanged(), this, enterEditMode() ); //FIXME
157     line++;
158
159     /* VLC_META_SETTING: Useless */
160     /* ADD_META( TRACKID )  Useless ? */
161     /* ADD_URI - Do not show it, done outside */
162
163     metaLayout->setColumnStretch( 1, 20 );
164     metaLayout->setColumnMinimumWidth ( 1, 80 );
165     metaLayout->setRowStretch( line, 10 );
166 #undef ADD_META
167
168     CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
169     CONNECT( seqtot_text, textEdited( QString ), this, enterEditMode() );
170
171     CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
172 /*    CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/
173
174     /* We are not yet in Edit Mode */
175     b_inEditMode = false;
176 }
177
178 /**
179  * Update all the MetaData and art on an "item-changed" event
180  **/
181 void MetaPanel::update( input_item_t *p_item )
182 {
183     if( !p_item )
184     {
185         clear();
186         return;
187     }
188
189     /* Don't update if you are in edit mode */
190     if( b_inEditMode ) return;
191     else p_input = p_item;
192
193     char *psz_meta;
194 #define UPDATE_META( meta, widget ) {                                   \
195     psz_meta = input_item_Get##meta( p_item );                          \
196     widget->setText( !EMPTY_STR( psz_meta ) ? qfu( psz_meta ) : "" );   \
197     free( psz_meta ); }
198
199 #define UPDATE_META_INT( meta, widget ) {           \
200     psz_meta = input_item_Get##meta( p_item );      \
201     if( !EMPTY_STR( psz_meta ) )                    \
202         widget->setValue( atoi( psz_meta ) ); }     \
203     free( psz_meta );
204
205     /* Name / Title */
206     psz_meta = input_item_GetTitleFbName( p_item );
207     if( psz_meta )
208     {
209         title_text->setText( qfu( psz_meta ) );
210         free( psz_meta );
211     }
212     else
213         title_text->setText( "" );
214
215     /* URL / URI */
216     psz_meta = input_item_GetURI( p_item );
217     if( !EMPTY_STR( psz_meta ) )
218          emit uriSet( qfu( psz_meta ) );
219     free( psz_meta );
220
221     /* Other classic though */
222     UPDATE_META( Artist, artist_text );
223     UPDATE_META( Genre, genre_text );
224     UPDATE_META( Copyright, copyright_text );
225     UPDATE_META( Album, collection_text );
226     UPDATE_META( Description, description_text );
227     UPDATE_META( Language, language_text );
228     UPDATE_META( NowPlaying, nowplaying_text );
229     UPDATE_META( Publisher, publisher_text );
230     UPDATE_META( EncodedBy, encodedby_text );
231
232     UPDATE_META( Date, date_text );
233     UPDATE_META( TrackNum, seqnum_text );
234 //    UPDATE_META( Setting, setting_text );
235 //    UPDATE_META_INT( Rating, rating_text );
236
237     /* URL */
238     psz_meta = input_item_GetURL( p_item );
239     if( !EMPTY_STR( psz_meta ) )
240     {
241         QString newURL = qfu(psz_meta);
242         if( currentURL != newURL )
243         {
244             currentURL = newURL;
245             lblURL->setText( "<a href='" + currentURL + "'>" +
246                              currentURL.remove( QRegExp( ".*://") ) + "</a>" );
247         }
248     }
249     free( psz_meta );
250 #undef UPDATE_META_INT
251 #undef UPDATE_META
252
253     // If a artURL is available as a local file, directly display it !
254
255     QString file;
256     char *psz_art = input_item_GetArtURL( p_item );
257     if( psz_art )
258     {
259         char *psz = make_path( psz_art );
260         free( psz_art );
261         file = qfu( psz );
262         free( psz );
263     }
264
265     art_cover->showArtUpdate( file );
266 }
267
268 /**
269  * Save the MetaData, triggered by parent->save Button
270  **/
271 void MetaPanel::saveMeta()
272 {
273     if( p_input == NULL )
274         return;
275
276     /* now we read the modified meta data */
277     input_item_SetTitle(  p_input, qtu( title_text->text() ) );
278     input_item_SetArtist( p_input, qtu( artist_text->text() ) );
279     input_item_SetAlbum(  p_input, qtu( collection_text->text() ) );
280     input_item_SetGenre(  p_input, qtu( genre_text->text() ) );
281     input_item_SetTrackNum(  p_input, qtu( seqnum_text->text() ) );
282     input_item_SetDate(  p_input, qtu( date_text->text() ) );
283
284     input_item_SetCopyright( p_input, qtu( copyright_text->text() ) );
285     input_item_SetPublisher( p_input, qtu( publisher_text->text() ) );
286     input_item_SetDescription( p_input, qtu( description_text->toPlainText() ) );
287
288     playlist_t *p_playlist = pl_Get( p_intf );
289     input_item_WriteMeta( VLC_OBJECT(p_playlist), p_input );
290
291     /* Reset the status of the mode. No need to emit any signal because parent
292        is the only caller */
293     b_inEditMode = false;
294 }
295
296
297 bool MetaPanel::isInEditMode()
298 {
299     return b_inEditMode;
300 }
301
302 void MetaPanel::enterEditMode()
303 {
304     setEditMode( true );
305 }
306
307 void MetaPanel::setEditMode( bool b_editing )
308 {
309     b_inEditMode = b_editing;
310     if( b_editing )emit editing();
311 }
312
313 /*
314  * Clear all the metadata widgets
315  */
316 void MetaPanel::clear()
317 {
318     title_text->clear();
319     artist_text->clear();
320     genre_text->clear();
321     copyright_text->clear();
322     collection_text->clear();
323     seqnum_text->clear();
324     description_text->clear();
325     date_text->clear();
326     language_text->clear();
327     nowplaying_text->clear();
328     publisher_text->clear();
329
330     setEditMode( false );
331     emit uriSet( "" );
332 }
333
334 /**
335  * Second Panel - Shows the extra metadata in a tree, non editable.
336  **/
337 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
338                                 intf_thread_t *_p_intf )
339                                 : QWidget( parent ), p_intf( _p_intf )
340 {
341      QGridLayout *layout = new QGridLayout(this);
342
343      QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
344                  " are shown in this panel.\n" ) );
345      topLabel->setWordWrap( true );
346      layout->addWidget( topLabel, 0, 0 );
347
348      extraMetaTree = new QTreeWidget( this );
349      extraMetaTree->setAlternatingRowColors( true );
350      extraMetaTree->setColumnCount( 2 );
351      extraMetaTree->resizeColumnToContents( 0 );
352      extraMetaTree->setHeaderHidden( true );
353      layout->addWidget( extraMetaTree, 1, 0 );
354 }
355
356 /**
357  * Update the Extra Metadata from p_meta->i_extras
358  **/
359 void ExtraMetaPanel::update( input_item_t *p_item )
360 {
361     if( !p_item )
362     {
363         clear();
364         return;
365     }
366
367     QList<QTreeWidgetItem *> items;
368
369     extraMetaTree->clear();
370
371     vlc_mutex_lock( &p_item->lock );
372     vlc_meta_t *p_meta = p_item->p_meta;
373     if( !p_meta )
374     {
375         vlc_mutex_unlock( &p_item->lock );
376         return;
377     }
378
379     char ** ppsz_allkey = vlc_meta_CopyExtraNames( p_meta);
380
381     for( int i = 0; ppsz_allkey[i] ; i++ )
382     {
383         const char * psz_value = vlc_meta_GetExtra( p_meta, ppsz_allkey[i] );
384         QStringList tempItem;
385         tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
386         tempItem.append( qfu( psz_value ) );
387         items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
388         free( ppsz_allkey[i] );
389     }
390     vlc_mutex_unlock( &p_item->lock );
391     free( ppsz_allkey );
392
393     extraMetaTree->addTopLevelItems( items );
394     extraMetaTree->resizeColumnToContents( 0 );
395 }
396
397 /**
398  * Clear the ExtraMetaData Tree
399  **/
400 void ExtraMetaPanel::clear()
401 {
402     extraMetaTree->clear();
403 }
404
405 /**
406  * Third panel - Stream info
407  * Display all codecs and muxers info that we could gather.
408  **/
409 InfoPanel::InfoPanel( QWidget *parent,
410                       intf_thread_t *_p_intf )
411                       : QWidget( parent ), p_intf( _p_intf )
412 {
413      QGridLayout *layout = new QGridLayout(this);
414
415      QList<QTreeWidgetItem *> items;
416
417      QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
418               " stream is made of.\nMuxer, Audio and Video Codecs, Subtitles "
419               "are shown." ) );
420      topLabel->setWordWrap( true );
421      layout->addWidget( topLabel, 0, 0 );
422
423      InfoTree = new QTreeWidget(this);
424      InfoTree->setColumnCount( 1 );
425      InfoTree->header()->hide();
426      InfoTree->header()->setResizeMode(QHeaderView::ResizeToContents);
427      layout->addWidget(InfoTree, 1, 0 );
428 }
429
430 /**
431  * Update the Codecs information on parent->update()
432  **/
433 void InfoPanel::update( input_item_t *p_item)
434 {
435     if( !p_item )
436     {
437         clear();
438         return;
439     }
440
441     InfoTree->clear();
442     QTreeWidgetItem *current_item = NULL;
443     QTreeWidgetItem *child_item = NULL;
444
445     for( int i = 0; i< p_item->i_categories ; i++)
446     {
447         current_item = new QTreeWidgetItem();
448         current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
449         InfoTree->addTopLevelItem( current_item );
450
451         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
452         {
453             child_item = new QTreeWidgetItem ();
454             child_item->setText( 0,
455                     qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
456                     + ": "
457                     + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
458
459             current_item->addChild(child_item);
460         }
461         InfoTree->setItemExpanded( current_item, true);
462     }
463 }
464
465 /**
466  * Clear the tree
467  **/
468 void InfoPanel::clear()
469 {
470     InfoTree->clear();
471 }
472
473 /**
474  * Save all the information to a file
475  * Not yet implemented.
476  **/
477 /*
478 void InfoPanel::saveCodecsInfo()
479 {}
480 */
481
482 /**
483  * Fourth Panel - Stats
484  * Displays the Statistics for reading/streaming/encoding/displaying in a tree
485  */
486 InputStatsPanel::InputStatsPanel( QWidget *parent,
487                                   intf_thread_t *_p_intf )
488                                   : QWidget( parent ), p_intf( _p_intf )
489 {
490      QGridLayout *layout = new QGridLayout(this);
491
492      QLabel *topLabel = new QLabel( qtr( "Current"
493                  " media / stream " "statistics") );
494      topLabel->setWordWrap( true );
495      layout->addWidget( topLabel, 0, 0 );
496
497      StatsTree = new QTreeWidget(this);
498      StatsTree->setColumnCount( 3 );
499      StatsTree->setHeaderHidden( true );
500
501 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) {              \
502     itemName =                                                                 \
503       new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
504     itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
505
506 #define CREATE_CATEGORY( catName, itemText ) {                           \
507     CREATE_TREE_ITEM( catName, itemText , "", "" );                      \
508     catName->setExpanded( true );                                        \
509     StatsTree->addTopLevelItem( catName );    }
510
511 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
512     CREATE_TREE_ITEM( itemName, itemText, itemValue, unit );                   \
513     catName->addChild( itemName ); }
514
515     /* Create the main categories */
516     CREATE_CATEGORY( audio, qtr("Audio") );
517     CREATE_CATEGORY( video, qtr("Video") );
518     CREATE_CATEGORY( input, qtr("Input/Read") );
519     CREATE_CATEGORY( streaming, qtr("Output/Written/Sent") );
520
521     CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Media data size"),
522                            "0", input , "KiB" );
523     CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
524                            "0", input, "kb/s" );
525     CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed data size"), "0", input, "KiB") ;
526     CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Content bitrate"),
527                            "0", input, "kb/s" );
528     CREATE_AND_ADD_TO_CAT( corrupted_stat, qtr("Discarded (corrupted)"),
529                            "0", input, "" );
530     CREATE_AND_ADD_TO_CAT( discontinuity_stat, qtr("Dropped (discontinued)"),
531                            "0", input, "" );
532
533     CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded"),
534                            "0", video, qtr("blocks") );
535     CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed"),
536                            "0", video, qtr("frames") );
537     CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost"),
538                            "0", video, qtr("frames") );
539
540     CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent"), "0", streaming, qtr("packets") );
541     CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent"),
542                            "0", streaming, "KiB" );
543     CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Upstream rate"),
544                            "0", streaming, "kb/s" );
545
546     CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded"),
547                            "0", audio, qtr("blocks") );
548     CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played"),
549                            "0", audio, qtr("buffers") );
550     CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost"), "0", audio, qtr("buffers") );
551
552 #undef CREATE_AND_ADD_TO_CAT
553 #undef CREATE_CATEGORY
554 #undef CREATE_TREE_ITEM
555
556     input->setExpanded( true );
557     video->setExpanded( true );
558     streaming->setExpanded( true );
559     audio->setExpanded( true );
560
561     StatsTree->resizeColumnToContents( 0 );
562     StatsTree->setColumnWidth( 1 , 200 );
563
564     layout->addWidget(StatsTree, 1, 0 );
565 }
566
567 /**
568  * Update the Statistics
569  **/
570 void InputStatsPanel::update( input_item_t *p_item )
571 {
572     assert( p_item );
573     vlc_mutex_lock( &p_item->p_stats->lock );
574
575 #define UPDATE_INT( widget, calc... ) \
576     { widget->setText( 1, QString::number( (qulonglong)calc ) ); }
577
578 #define UPDATE_FLOAT( widget, format, calc... ) \
579     { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) );  }
580
581     UPDATE_INT( read_media_stat, (p_item->p_stats->i_read_bytes / 1024 ) );
582     UPDATE_FLOAT( input_bitrate_stat,  "%6.0f", (float)(p_item->p_stats->f_input_bitrate *  8000  ));
583     UPDATE_INT( demuxed_stat,    (p_item->p_stats->i_demux_read_bytes / 1024 ) );
584     UPDATE_FLOAT( stream_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_demux_bitrate *  8000  ));
585     UPDATE_INT( corrupted_stat,      p_item->p_stats->i_demux_corrupted );
586     UPDATE_INT( discontinuity_stat,  p_item->p_stats->i_demux_discontinuity );
587
588     /* Video */
589     UPDATE_INT( vdecoded_stat,     p_item->p_stats->i_decoded_video );
590     UPDATE_INT( vdisplayed_stat,   p_item->p_stats->i_displayed_pictures );
591     UPDATE_INT( vlost_frames_stat, p_item->p_stats->i_lost_pictures );
592
593     /* Sout */
594     UPDATE_INT( send_stat,        p_item->p_stats->i_sent_packets );
595     UPDATE_INT( send_bytes_stat,  (p_item->p_stats->i_sent_bytes)/ 1024 );
596     UPDATE_FLOAT( send_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_send_bitrate * 8000 ) );
597
598     /* Audio*/
599     UPDATE_INT( adecoded_stat, p_item->p_stats->i_decoded_audio );
600     UPDATE_INT( aplayed_stat,  p_item->p_stats->i_played_abuffers );
601     UPDATE_INT( alost_stat,    p_item->p_stats->i_lost_abuffers );
602
603 #undef UPDATE_INT
604 #undef UPDATE_FLOAT
605
606     vlc_mutex_unlock(& p_item->p_stats->lock );
607 }
608
609 void InputStatsPanel::clear()
610 {
611 }
612