]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/infopanels.cpp
Disables some useless metadata in infopanel 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 <QStringList>
34 #include <QGridLayout>
35 #include <QLineEdit>
36 #include <QLabel>
37 #include <QSpinBox>
38 #include <QTabWidget>
39
40 /************************************************************************
41  * Single panels
42  ************************************************************************/
43
44 /**
45  * First Panel - Meta Info
46  * All the usual MetaData are displayed and can be changed.
47  **/
48 MetaPanel::MetaPanel( QWidget *parent,
49                       intf_thread_t *_p_intf )
50                       : QWidget( parent ), p_intf( _p_intf )
51 {
52     QGridLayout *l = new QGridLayout( this );
53     int line = 0; /* Counter for GridLayout */
54     p_input = NULL;
55
56 #define ADD_META( string, widget ) {                             \
57     l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
58     widget = new QLineEdit;                                      \
59     l->addWidget( widget, line, 1, 1, 5 );                       \
60     line++;            }
61
62     /* ART_URL */
63     art_cover = new QLabel( "" );
64     art_cover->setMinimumHeight( 128 );
65     art_cover->setMinimumWidth( 128 );
66     art_cover->setMaximumHeight( 128 );
67     art_cover->setMaximumWidth( 128 );
68     art_cover->setScaledContents( true );
69     art_cover->setPixmap( QPixmap( ":/noart.png" ) );
70     l->addWidget( art_cover, line, 6, 4, 2 );
71
72     /* Title, artist and album*/
73     ADD_META( VLC_META_TITLE, title_text ); /* OK */
74     ADD_META( VLC_META_ARTIST, artist_text ); /* OK */
75     ADD_META( VLC_META_COLLECTION, collection_text ); /* OK */
76
77     /* Genre Name */
78     /* FIXME List id3genres.h is not includable yet ? */
79     genre_text = new QLineEdit;
80     l->addWidget( new QLabel( qtr( VLC_META_GENRE ) + " :" ), line, 0 );
81     l->addWidget( genre_text, line, 1, 1, 2 );
82
83     /* Number */
84     l->addWidget( new QLabel( qtr( "Track Number" )  + " :" ),
85                   line, 3 );
86     seqnum_text = new QSpinBox; setSpinBounds( seqnum_text );
87     l->addWidget( seqnum_text, line, 4, 1, 2 );
88     line++;
89
90     /* Date (Should be in years) */
91     date_text = new QSpinBox; setSpinBounds( date_text );
92     l->addWidget( new QLabel( qtr( VLC_META_DATE ) + " :" ), line, 0 );
93     l->addWidget( date_text, line, 1, 1, 1 );
94
95     /* Rating */
96
97     l->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 2 );
98     rating_text = new QSpinBox; setSpinBounds( rating_text) ;
99     l->addWidget( rating_text, line, 3, 1, 1 );
100
101     /* Now Playing ? */
102 //    ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
103
104     /* Language and settings */
105     l->addWidget( new QLabel( qfu( VLC_META_LANGUAGE ) + " :" ), line, 4 );
106     language_text = new QLineEdit;
107     l->addWidget( language_text, line, 5, 1, 1 );
108 /*    l->addWidget( new QLabel( qtr( VLC_META_SETTING ) + " :" ), line, 5 );
109     setting_text = new QLineEdit;
110     l->addWidget( setting_text, line, 6, 1, 4 );
111     line++;*/
112
113 /* useless metadata
114 #define ADD_META_2( string, widget ) {                             \
115     l->addWidget( new QLabel( qtr( string ) + " :" ), line, 0 ); \
116     widget = new QLineEdit;                                      \
117     l->addWidget( widget, line, 1, 1, 7 );                       \
118     line++;            }
119
120     ADD_META_2( VLC_META_COPYRIGHT, copyright_text );
121     ADD_META_2( VLC_META_PUBLISHER, publisher_text );
122
123     ADD_META_2( VLC_META_ENCODED_BY, encodedby_text );
124     ADD_META_2( VLC_META_DESCRIPTION, description_text );
125 */
126     /*  ADD_META( TRACKID )  Useless ? */
127     /*  ADD_URI - DO not show it, done outside */
128
129 #undef ADD_META
130 //#undef ADD_META_2
131
132
133     CONNECT( title_text, textEdited( QString ), this, editMeta( QString ) );
134 //    CONNECT( description_text, textEdited( QString ), this, editMeta( QString ) );
135     CONNECT( artist_text, textEdited( QString ), this, editMeta( QString ) );
136     CONNECT( collection_text, textEdited( QString ), this, editMeta( QString ) );
137     CONNECT( genre_text, textEdited( QString ), this, editMeta( QString ) );
138     CONNECT( date_text, valueChanged( QString ), this, editMeta( QString ) );
139     CONNECT( seqnum_text, valueChanged( QString ), this, editMeta( QString ) );
140     CONNECT( rating_text, valueChanged( QString ), this, editMeta( QString ) );
141     in_edit = false;
142 }
143
144 MetaPanel::~MetaPanel(){}
145
146 /**
147  * Save the MetaData, triggered by parent->save Button
148  **/
149 void MetaPanel::saveMeta()
150 {
151     playlist_t *p_playlist;
152     char psz[5];
153
154     meta_export_t p_export;
155     p_export.p_item = p_input;
156
157     if( p_input == NULL )
158         return;
159
160     /* we can write meta data only in a file */
161     if( ( p_input->i_type == ITEM_TYPE_AFILE ) || \
162         ( p_input->i_type == ITEM_TYPE_VFILE ) )
163         /* some audio files are detected as video files */
164     {
165         char *psz_uri = p_input->psz_uri;
166         if( !strncmp( psz_uri, "file://", 7 ) )
167             psz_uri += 7; /* strlen("file://") = 7 */
168
169         p_export.psz_file = strndup( psz_uri, PATH_MAX );
170     }
171     else
172         return;
173
174     /* now we read the modified meta data */
175     input_item_SetArtist( p_input, qtu( artist_text->text() ) );
176     input_item_SetAlbum(  p_input, qtu( collection_text->text() ) );
177     input_item_SetGenre(  p_input, qtu( genre_text->text() ) );
178
179     snprintf( psz, sizeof(psz), "%d", date_text->value() );
180     input_item_SetDate(  p_input, psz );
181
182     snprintf( psz, sizeof(psz), "%d", seqnum_text->value() );
183     input_item_SetTrackNum(  p_input, psz );
184
185     input_item_SetTitle(  p_input, qtu( title_text->text() ) );
186
187     p_playlist = pl_Yield( p_intf );
188
189     PL_LOCK;
190     p_playlist->p_private = &p_export;
191
192     module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
193     if( p_mod )
194         module_Unneed( p_playlist, p_mod );
195     PL_UNLOCK;
196     pl_Release( p_playlist );
197     in_edit = false;
198 }
199
200 void MetaPanel::editMeta( QString edit )
201 {
202     in_edit = true;
203     emit editing();
204 }
205
206 void MetaPanel::setEdit( bool editing )
207 {
208    in_edit = editing;
209 }
210
211 void MetaPanel::setInput( input_item_t *input )
212 {
213     if( in_edit ) return;
214
215     p_input = input;
216 }
217
218 /**
219  * Update all the MetaData and art on an "item-changed" event
220  **/
221 void MetaPanel::update( input_item_t *p_item )
222 {
223     if( in_edit ) return;
224     char *psz_meta; 
225 #define UPDATE_META( meta, widget ) {               \
226     psz_meta = input_item_Get##meta( p_item );      \
227     if( !EMPTY_STR( psz_meta ) )                    \
228         widget->setText( qfu( psz_meta ) );         \
229     else                                            \
230         widget->setText( "" ); }                    \
231     free( psz_meta );
232
233 #define UPDATE_META_INT( meta, widget ) {           \
234     psz_meta = input_item_Get##meta( p_item );      \
235     if( !EMPTY_STR( psz_meta ) )                    \
236         widget->setValue( atoi( psz_meta ) ); }     \
237     free( psz_meta );
238
239
240     /* Name / Title */
241     psz_meta = input_item_GetTitle( p_item );
242     if( !EMPTY_STR( psz_meta ) )
243         title_text->setText( qfu( psz_meta ) );
244     else if( !EMPTY_STR( p_item->psz_name ) )
245         title_text->setText( qfu( p_item->psz_name ) );
246     else title_text->setText( "" );
247     free( psz_meta );
248
249     /* URL / URI */
250     psz_meta = input_item_GetURL( p_item );
251     if( !EMPTY_STR( psz_meta ) )
252         emit uriSet( QString( psz_meta ) );
253     else if( !EMPTY_STR( p_item->psz_uri ) )
254         emit uriSet( QString( p_item->psz_uri ) );
255     free( psz_meta );
256
257     /* Other classic though */
258     UPDATE_META( Artist, artist_text );
259     UPDATE_META( Genre, genre_text );
260 //    UPDATE_META( Copyright, copyright_text );
261     UPDATE_META( Album, collection_text );
262 //    UPDATE_META( Description, description_text );
263     UPDATE_META( Language, language_text );
264 //    UPDATE_META( NowPlaying, nowplaying_text );
265 //    UPDATE_META( Publisher, publisher_text );
266 //    UPDATE_META( Setting, setting_text );
267 //    UPDATE_META( EncodedBy, encodedby_text );
268
269     UPDATE_META_INT( Date, date_text );
270     UPDATE_META_INT( TrackNum, seqnum_text );
271     UPDATE_META_INT( Rating, rating_text );
272
273 #undef UPDATE_META_INT
274 #undef UPDATE_META
275
276     /* Art Urls */
277     psz_meta = input_item_GetArtURL( p_item );
278     if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
279     {
280         QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
281         art_cover->setPixmap( QPixmap( artUrl ) );
282     }
283     else
284         art_cover->setPixmap( QPixmap( ":/noart.png" ) );
285     free( psz_meta );
286 }
287
288 /*
289  * Clear all the metadata widgets
290  * Unused yet
291  */
292 void MetaPanel::clear(){}
293
294 /**
295  * Second Panel - Shows the extra metadata in a tree, non editable.
296  **/
297 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent,
298                                 intf_thread_t *_p_intf )
299                                 : QWidget( parent ), p_intf( _p_intf )
300 {
301      QGridLayout *layout = new QGridLayout(this);
302
303      QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
304                  " are shown in this list.\n" ) );
305      topLabel->setWordWrap( true );
306      layout->addWidget( topLabel, 0, 0 );
307
308      extraMetaTree = new QTreeWidget( this );
309      extraMetaTree->setAlternatingRowColors( true );
310      extraMetaTree->setColumnCount( 2 );
311      extraMetaTree->header()->hide();
312 /*     QStringList headerList = ( QStringList() << qtr( "Type" )
313  *                                             << qtr( "Value" ) );
314  * Useless, add this header if you think it would help the user          **
315  */
316
317      layout->addWidget( extraMetaTree, 1, 0 );
318 }
319
320 /**
321  * Update the Extra Metadata from p_meta->i_extras 
322  **/
323 void ExtraMetaPanel::update( input_item_t *p_item )
324 {
325     vlc_mutex_lock( &p_item->lock );
326     vlc_meta_t *p_meta = p_item->p_meta;
327     if( !p_meta )
328         return;
329     QStringList tempItem;
330
331     QList<QTreeWidgetItem *> items;
332     vlc_dictionary_t * p_dict = &p_meta->extra_tags;
333     char ** ppsz_allkey = vlc_dictionary_all_keys( p_dict );
334     for (int i = 0; ppsz_allkey[i] ; i++ )
335     {
336         const char * psz_value = (const char *)vlc_dictionary_value_for_key(
337                 p_dict, ppsz_allkey[i] );
338         tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
339         tempItem.append( qfu( psz_value ) );
340         items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
341         free( ppsz_allkey[i] );
342     }
343     vlc_mutex_unlock( &p_item->lock );
344     free( ppsz_allkey );
345     extraMetaTree->addTopLevelItems( items );
346 }
347
348 /**
349  * Clear the ExtraMetaData Tree
350  **/
351 void ExtraMetaPanel::clear()
352 {
353     extraMetaTree->clear();
354 }
355
356 /**
357  * Third panel - Stream info
358  * Display all codecs and muxers info that we could gather.
359  **/
360 InfoPanel::InfoPanel( QWidget *parent,
361                       intf_thread_t *_p_intf )
362                       : QWidget( parent ), p_intf( _p_intf )
363 {
364      QGridLayout *layout = new QGridLayout(this);
365
366      QList<QTreeWidgetItem *> items;
367
368      QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
369               " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
370               "are shown." ) );
371      topLabel->setWordWrap( true );
372      layout->addWidget( topLabel, 0, 0 );
373
374      InfoTree = new QTreeWidget(this);
375      InfoTree->setColumnCount( 1 );
376      InfoTree->header()->hide();
377      layout->addWidget(InfoTree, 1, 0 );
378 }
379
380 InfoPanel::~InfoPanel()
381 {
382 }
383
384 /**
385  * Update the Codecs information on parent->update()
386  **/
387 void InfoPanel::update( input_item_t *p_item)
388 {
389     InfoTree->clear();
390     QTreeWidgetItem *current_item = NULL;
391     QTreeWidgetItem *child_item = NULL;
392
393     for( int i = 0; i< p_item->i_categories ; i++)
394     {
395         current_item = new QTreeWidgetItem();
396         current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
397         InfoTree->addTopLevelItem( current_item );
398
399         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
400         {
401             child_item = new QTreeWidgetItem ();
402             child_item->setText( 0,
403                     qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
404                     + ": "
405                     + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
406
407             current_item->addChild(child_item);
408         }
409          InfoTree->setItemExpanded( current_item, true);
410     }
411 }
412
413 /**
414  * Clear the tree
415  **/
416 void InfoPanel::clear()
417 {
418     InfoTree->clear();
419 }
420
421 /**
422  * Save all the information to a file
423  * Not yet implemented.
424  **/
425 /*
426 void InfoPanel::saveCodecsInfo()
427 {
428
429 }
430 */
431
432 /**
433  * Fourth Panel - Stats
434  * Displays the Statistics for reading/streaming/encoding/displaying in a tree
435  */
436 InputStatsPanel::InputStatsPanel( QWidget *parent,
437                                   intf_thread_t *_p_intf )
438                                   : QWidget( parent ), p_intf( _p_intf )
439 {
440      QGridLayout *layout = new QGridLayout(this);
441
442      QList<QTreeWidgetItem *> items;
443
444      QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
445                  " media or stream.\n Played and streamed info are shown." ) );
446      topLabel->setWordWrap( true );
447      layout->addWidget( topLabel, 0, 0 );
448
449      StatsTree = new QTreeWidget(this);
450      StatsTree->setColumnCount( 3 );
451      StatsTree->header()->hide();
452
453 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) {              \
454     itemName =                                                                 \
455       new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
456     itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
457
458 #define CREATE_CATEGORY( catName, itemText ) {                           \
459     CREATE_TREE_ITEM( catName, itemText , "", "" );                      \
460     catName->setExpanded( true );                                        \
461     StatsTree->addTopLevelItem( catName );    }
462
463 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
464     CREATE_TREE_ITEM( itemName, itemText, itemValue, unit );                   \
465     catName->addChild( itemName ); }
466
467     /* Create the main categories */
468     CREATE_CATEGORY( input, qtr("Input") );
469     CREATE_CATEGORY( video, qtr("Video") );
470     CREATE_CATEGORY( streaming, qtr("Streaming") );
471     CREATE_CATEGORY( audio, qtr("Audio") );
472
473     CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
474                            "0", input , "kB" );
475     CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
476                            "0", input, "kb/s" );
477     CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
478     CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
479                            "0", input, "kb/s" );
480
481     CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
482                            "0", video, "" );
483     CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
484                            "0", video, "" );
485     CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
486                            "0", video, "" );
487
488     CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
489     CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
490                            "0", streaming, "kB" );
491     CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
492                            "0", streaming, "kb/s" );
493
494     CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
495                            "0", audio, "" );
496     CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
497                            "0", audio, "" );
498     CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
499
500     input->setExpanded( true );
501     video->setExpanded( true );
502     streaming->setExpanded( true );
503     audio->setExpanded( true );
504
505     StatsTree->resizeColumnToContents( 0 );
506     StatsTree->setColumnWidth( 1 , 100 );
507
508     layout->addWidget(StatsTree, 1, 0 );
509 }
510
511 InputStatsPanel::~InputStatsPanel()
512 {
513 }
514
515 /**
516  * Update the Statistics
517  **/
518 void InputStatsPanel::update( input_item_t *p_item )
519 {
520     vlc_mutex_lock( &p_item->p_stats->lock );
521
522 #define UPDATE( widget, format, calc... ) \
523     { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) );  }
524
525     UPDATE( read_media_stat, "%8.0f",
526             (float)(p_item->p_stats->i_read_bytes)/1000);
527     UPDATE( input_bitrate_stat, "%6.0f",
528                     (float)(p_item->p_stats->f_input_bitrate * 8000 ));
529     UPDATE( demuxed_stat, "%8.0f",
530                     (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
531     UPDATE( stream_bitrate_stat, "%6.0f",
532                     (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
533
534     /* Video */
535     UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
536     UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
537     UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
538
539     /* Sout */
540     UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
541     UPDATE( send_bytes_stat, "%8.0f",
542             (float)(p_item->p_stats->i_sent_bytes)/1000 );
543     UPDATE( send_bitrate_stat, "%6.0f",
544             (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
545
546     /* Audio*/
547     UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
548     UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
549     UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
550
551     vlc_mutex_unlock(& p_item->p_stats->lock );
552 }
553
554 void InputStatsPanel::clear()
555 {
556 }
557
558