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