1 /*****************************************************************************
2 * infopanels.cpp : Panels for the information dialogs
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
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.
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.
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 *****************************************************************************/
26 #include "components/infopanels.hpp"
28 #include <QTreeWidget>
30 #include <QPushButton>
31 #include <QHeaderView>
33 #include <QGridLayout>
39 /************************************************************************
41 ************************************************************************/
43 /* First Panel - Meta Info */
45 MetaPanel::MetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
46 QWidget( parent ), p_intf( _p_intf )
49 QGridLayout *l = new QGridLayout( this );
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 ); \
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 */
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( qtr( VLC_META_DATE ) + " :" ), line, 7 );
68 l->addWidget( date_text, line, 8, 1, 2 );
71 /* Number and Rating */
72 l->addWidget( new QLabel( qtr( "Track number/Position" ) + " :" ),
74 seqnum_text = new QSpinBox; setSpinBounds( seqnum_text );
75 l->addWidget( seqnum_text, line, 1, 1, 4 );
77 l->addWidget( new QLabel( qtr( VLC_META_RATING ) + " :" ), line, 5 );
78 rating_text = new QSpinBox; setSpinBounds( rating_text) ;
79 l->addWidget( rating_text, line, 6, 1, 4 );
82 ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
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( qtr( VLC_META_SETTING ) + " :" ), line, 5 );
89 setting_text = new QLineEdit;
90 l->addWidget( setting_text, line, 6, 1, 4 );
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" ) );
103 l->addWidget( art_cover, line, 8, 4, 2 );
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 ); \
111 ADD_META_B( VLC_META_COPYRIGHT, copyright_text );
112 ADD_META_B( VLC_META_PUBLISHER, publisher_text );
114 ADD_META_B( VLC_META_ENCODED_BY, publisher_text );
115 ADD_META_B( VLC_META_DESCRIPTION, description_text ); // Comment Two lines?
117 QPushButton *write = new QPushButton( qtr( "&Write" ) );
118 l->addWidget( write, line, 0 );
120 BUTTONACT( write, saveMeta() );
122 /* ADD_META( TRACKID) DO NOT SHOW it */
123 /* ADD_URI - DO not show it, done outside */
128 // CONNECT( model, artSet( QString ) , this, setArt( QString ) );
131 MetaPanel::~MetaPanel()
135 void MetaPanel::saveMeta()
137 playlist_t *p_playlist;
139 meta_export_t p_export;
140 p_export.p_item = p_input;
142 /* we can write meta data only in a file */
143 if( ( p_input->i_type == ITEM_TYPE_AFILE ) || \
144 ( p_input->i_type == ITEM_TYPE_VFILE ) )
145 /* some audio files are detected as video files */
147 char *psz_uri = p_input->psz_uri;
148 if( !strncmp( psz_uri, "file://", 7 ) )
149 psz_uri += 7; /* strlen("file://") = 7 */
151 p_export.psz_file = strndup( psz_uri, PATH_MAX );
156 /* now we read the modified meta data */
157 free( p_input->p_meta->psz_artist );
158 p_input->p_meta->psz_artist = strdup( artist_text->text().toUtf8() );
159 free( p_input->p_meta->psz_album );
160 p_input->p_meta->psz_album = strdup( collection_text->text().toUtf8() );
161 free( p_input->p_meta->psz_genre );
162 p_input->p_meta->psz_genre = strdup( genre_text->text().toUtf8() );
163 free( p_input->p_meta->psz_date );
164 p_input->p_meta->psz_date = (char*) malloc(5);
165 snprintf( p_input->p_meta->psz_date, 5, "%d", date_text->value() );
166 free( p_input->p_meta->psz_tracknum );
167 p_input->p_meta->psz_tracknum = (char*) malloc(5);
168 snprintf( p_input->p_meta->psz_tracknum, 5, "%d", seqnum_text->value() );
169 free( p_input->p_meta->psz_title );
170 p_input->p_meta->psz_title = strdup( title_text->text().toUtf8() );
172 p_playlist = pl_Yield( p_intf );
175 p_playlist->p_private = &p_export;
177 module_t *p_mod = module_Need( p_playlist, "meta writer", NULL, 0 );
179 module_Unneed( p_playlist, p_mod );
181 pl_Release( p_playlist );
184 void MetaPanel::update( input_item_t *p_item )
187 #define UPDATE_META( meta, widget ) { \
188 psz_meta = p_item->p_meta->psz_##meta; \
189 if( !EMPTY_STR( psz_meta ) ) \
190 widget->setText( qfu( psz_meta ) ); \
192 widget->setText( "" ); }
194 #define UPDATE_META_INT( meta, widget ) { \
195 psz_meta = p_item->p_meta->psz_##meta; \
196 if( !EMPTY_STR( psz_meta ) ) \
197 widget->setValue( atoi( psz_meta ) ); }
200 psz_meta = p_item->p_meta->psz_title;
201 if( !EMPTY_STR( psz_meta ) )
202 title_text->setText( qfu( psz_meta ) );
203 else if( !EMPTY_STR( p_item->psz_name ) )
204 title_text->setText( qfu( p_item->psz_name ) );
205 else title_text->setText( "" );
208 psz_meta = p_item->p_meta->psz_url;
209 if( !EMPTY_STR( psz_meta ) )
210 emit uriSet( QString( psz_meta ) );
211 else if( !EMPTY_STR( p_item->psz_uri ) )
212 emit uriSet( QString( p_item->psz_uri ) );
214 /* Other classic though */
215 UPDATE_META( artist, artist_text );
216 UPDATE_META( genre, genre_text );
217 UPDATE_META( copyright, copyright_text );
218 UPDATE_META( album, collection_text );
219 UPDATE_META( description, description_text );
220 UPDATE_META( language, language_text );
221 UPDATE_META( nowplaying, nowplaying_text );
222 UPDATE_META( publisher, publisher_text );
223 UPDATE_META( setting, setting_text );
225 UPDATE_META_INT( date, date_text );
226 UPDATE_META_INT( tracknum, seqnum_text );
227 UPDATE_META_INT( rating, rating_text );
230 psz_meta = p_item->p_meta->psz_arturl;
231 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
233 QString artUrl = qfu( psz_meta ).replace( "file://",QString("" ) );
234 art_cover->setPixmap( QPixmap( artUrl ) );
237 art_cover->setPixmap( QPixmap( ":/noart.png" ) );
240 void MetaPanel::clear(){}
242 ExtraMetaPanel::ExtraMetaPanel( QWidget *parent, intf_thread_t *_p_intf ) :
243 QWidget( parent ), p_intf( _p_intf )
245 QGridLayout *layout = new QGridLayout(this);
246 QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
247 " are shown in this list.\n" ) );
248 topLabel->setWordWrap( true );
249 layout->addWidget( topLabel, 0, 0 );
251 extraMetaTree = new QTreeWidget( this );
252 extraMetaTree->setAlternatingRowColors( true );
253 extraMetaTree->setColumnCount( 2 );
255 extraMetaTree->header()->hide();
256 /* QStringList *treeHeaders;
257 treeHeaders << qtr( "Test1" ) << qtr( "Test2" ); */
259 layout->addWidget( extraMetaTree, 1, 0 );
262 void ExtraMetaPanel::update( input_item_t *p_item )
264 vlc_meta_t *p_meta = p_item->p_meta;
265 QStringList tempItem;
267 QList<QTreeWidgetItem *> items;
268 for (int i = 0; i < p_meta->i_extra; i++ )
270 tempItem.append( qfu( p_meta->ppsz_extra_name[i] ) + " : ");
271 tempItem.append( qfu( p_meta->ppsz_extra_value[i] ) );
272 items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
274 extraMetaTree->addTopLevelItems( items );
277 void ExtraMetaPanel::clear(){}
279 /* Second Panel - Stats */
281 InputStatsPanel::InputStatsPanel( QWidget *parent, intf_thread_t *_p_intf ) :
282 QWidget( parent ), p_intf( _p_intf )
284 QGridLayout *layout = new QGridLayout(this);
285 StatsTree = new QTreeWidget(this);
286 QList<QTreeWidgetItem *> items;
287 QLabel *topLabel = new QLabel( qtr( "Various statistics about the current"
288 " media or stream.\n Played and streamed info are shown." ) );
289 topLabel->setWordWrap( true );
290 layout->addWidget( topLabel, 0, 0 );
292 StatsTree->setColumnCount( 3 );
293 StatsTree->header()->hide();
295 #define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) { \
297 new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
298 itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }
300 #define CREATE_CATEGORY( catName, itemText ) { \
301 CREATE_TREE_ITEM( catName, itemText , "", "" ); \
302 catName->setExpanded( true ); \
303 StatsTree->addTopLevelItem( catName ); }
305 #define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
306 CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ); \
307 catName->addChild( itemName ); }
309 /* Create the main categories */
310 CREATE_CATEGORY( input, qtr("Input") );
311 CREATE_CATEGORY( video, qtr("Video") );
312 CREATE_CATEGORY( streaming, qtr("Streaming") );
313 CREATE_CATEGORY( audio, qtr("Audio") );
315 CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Read at media"),
317 CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
318 "0", input, "kb/s" );
319 CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed"), "0", input, "kB") ;
320 CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Stream bitrate"),
321 "0", input, "kb/s" );
323 CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded blocks"),
325 CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed frames"),
327 CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost frames"),
330 CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent packets"), "0", streaming, "" );
331 CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent bytes"),
332 "0", streaming, "kB" );
333 CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Sent bitrates"),
334 "0", streaming, "kb/s" );
336 CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded blocks"),
338 CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played buffers"),
340 CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost buffers"), "0", audio, "" );
342 input->setExpanded( true );
343 video->setExpanded( true );
344 streaming->setExpanded( true );
345 audio->setExpanded( true );
347 StatsTree->resizeColumnToContents( 0 );
348 StatsTree->setColumnWidth( 1 , 100 );
350 layout->addWidget(StatsTree, 1, 0 );
353 InputStatsPanel::~InputStatsPanel()
357 void InputStatsPanel::update( input_item_t *p_item )
359 vlc_mutex_lock( &p_item->p_stats->lock );
361 #define UPDATE( widget, format, calc... ) \
362 { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) ); }
364 UPDATE( read_media_stat, "%8.0f",
365 (float)(p_item->p_stats->i_read_bytes)/1000);
366 UPDATE( input_bitrate_stat, "%6.0f",
367 (float)(p_item->p_stats->f_input_bitrate * 8000 ));
368 UPDATE( demuxed_stat, "%8.0f",
369 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
370 UPDATE( stream_bitrate_stat, "%6.0f",
371 (float)(p_item->p_stats->f_demux_bitrate * 8000 ));
374 UPDATE( vdecoded_stat, "%5i", p_item->p_stats->i_decoded_video );
375 UPDATE( vdisplayed_stat, "%5i", p_item->p_stats->i_displayed_pictures );
376 UPDATE( vlost_frames_stat, "%5i", p_item->p_stats->i_lost_pictures );
379 UPDATE( send_stat, "%5i", p_item->p_stats->i_sent_packets );
380 UPDATE( send_bytes_stat, "%8.0f",
381 (float)(p_item->p_stats->i_sent_bytes)/1000 );
382 UPDATE( send_bitrate_stat, "%6.0f",
383 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
386 UPDATE( adecoded_stat, "%5i", p_item->p_stats->i_decoded_audio );
387 UPDATE( aplayed_stat, "%5i", p_item->p_stats->i_played_abuffers );
388 UPDATE( alost_stat, "%5i", p_item->p_stats->i_lost_abuffers );
390 vlc_mutex_unlock(& p_item->p_stats->lock );
393 void InputStatsPanel::clear()
397 /* Third panel - Stream info */
399 InfoPanel::InfoPanel( QWidget *parent, intf_thread_t *_p_intf ) :
400 QWidget( parent ), p_intf( _p_intf )
402 QGridLayout *layout = new QGridLayout(this);
403 InfoTree = new QTreeWidget(this);
404 QList<QTreeWidgetItem *> items;
406 QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
407 " stream is made of.\n Muxer, Audio and Video Codecs, Subtitles "
409 topLabel->setWordWrap( true );
410 layout->addWidget( topLabel, 0, 0 );
412 InfoTree->setColumnCount( 1 );
413 InfoTree->header()->hide();
414 layout->addWidget(InfoTree, 1, 0 );
417 InfoPanel::~InfoPanel()
421 void InfoPanel::update( input_item_t *p_item)
424 QTreeWidgetItem *current_item = NULL;
425 QTreeWidgetItem *child_item = NULL;
427 for( int i = 0; i< p_item->i_categories ; i++)
429 current_item = new QTreeWidgetItem();
430 current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
431 InfoTree->addTopLevelItem( current_item );
433 for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
435 child_item = new QTreeWidgetItem ();
436 child_item->setText( 0,
437 qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
439 + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
441 current_item->addChild(child_item);
443 InfoTree->setItemExpanded( current_item, true);
447 void InfoPanel::clear()