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