info_panels.cpp 22.4 KB
Newer Older
1
/*****************************************************************************
Pere Orga's avatar
Pere Orga committed
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 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
25

26 27 28
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
29 30

#include "qt4.hpp"
31
#include "components/info_panels.hpp"
32
#include "components/interface_widgets.hpp"
33
#include "info_widgets.hpp"
34 35
#include "dialogs/fingerprintdialog.hpp"
#include "adapters/chromaprint.hpp"
36

37
#include <assert.h>
38
#include <vlc_url.h>
Christophe Mutricy's avatar
Christophe Mutricy committed
39
#include <vlc_meta.h>
40

41
#include <QTreeWidget>
42 43
#include <QHeaderView>
#include <QList>
44
#include <QStringList>
45
#include <QGridLayout>
46 47 48
#include <QLineEdit>
#include <QLabel>
#include <QSpinBox>
49
#include <QTextEdit>
50

51 52 53 54 55 56 57 58
static inline void setSpinBounds( QSpinBox *spinbox ) {
    spinbox->setRange( 0, INT_MAX );
    spinbox->setAccelerated( true );
    spinbox->setAlignment( Qt::AlignRight );
    spinbox->setSpecialValueText("");
}


59 60 61 62
/************************************************************************
 * Single panels
 ************************************************************************/

63 64 65 66 67 68 69
/**
 * First Panel - Meta Info
 * All the usual MetaData are displayed and can be changed.
 **/
MetaPanel::MetaPanel( QWidget *parent,
                      intf_thread_t *_p_intf )
                      : QWidget( parent ), p_intf( _p_intf )
70
{
71
    QGridLayout *metaLayout = new QGridLayout( this );
72 73 74
    metaLayout->setVerticalSpacing( 0 );

    QFont smallFont = QApplication::font();
75
    smallFont.setPointSize( smallFont.pointSize() - 1 );
76
    smallFont.setBold( true );
77

78
    int line = 0; /* Counter for GridLayout */
79
    p_input = NULL;
80
    QLabel *label;
81

82 83 84 85
#define ADD_META( string, widget, col, colspan ) {                        \
    label = new QLabel( qtr( string ) ); label->setFont( smallFont );     \
    label->setContentsMargins( 3, 2, 0, 0 );                              \
    metaLayout->addWidget( label, line++, col, 1, colspan );              \
86
    widget = new QLineEdit;                                               \
87 88 89
    metaLayout->addWidget( widget, line, col, 1, colspan );               \
    CONNECT( widget, textEdited( QString ), this, enterEditMode() );      \
}
90

91
    /* Title, artist and album*/
92 93 94 95 96 97 98 99 100 101 102 103 104
    ADD_META( VLC_META_TITLE, title_text, 0, 10 ); line++;
    ADD_META( VLC_META_ARTIST, artist_text, 0, 10 ); line++;
    ADD_META( VLC_META_ALBUM, collection_text, 0, 7 );

    /* Date */
    label = new QLabel( qtr( VLC_META_DATE ) );
    label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
    metaLayout->addWidget( label, line - 1, 7, 1, 2 );

    /* Date (Should be in years) */
    date_text = new QLineEdit;
    date_text->setAlignment( Qt::AlignRight );
    date_text->setInputMask("0000");
105
    date_text->setMaximumWidth( 140 );
106 107
    metaLayout->addWidget( date_text, line, 7, 1, -1 );
    line++;
108

109
    /* Genre Name */
110
    /* TODO List id3genres.h is not includable yet ? */
111
    ADD_META( VLC_META_GENRE, genre_text, 0, 7 );
112

113
    /* Number - on the same line */
114 115
    label = new QLabel( qtr( VLC_META_TRACK_NUMBER ) );
    label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
116
    metaLayout->addWidget( label, line - 1, 7, 1, 3  );
117

118 119 120 121
    seqnum_text = new QLineEdit;
    seqnum_text->setMaximumWidth( 64 );
    seqnum_text->setAlignment( Qt::AlignRight );
    metaLayout->addWidget( seqnum_text, line, 7, 1, 1 );
122

123 124
    label = new QLabel( "/" ); label->setFont( smallFont );
    metaLayout->addWidget( label, line, 8, 1, 1 );
125

126 127 128 129
    seqtot_text = new QLineEdit;
    seqtot_text->setMaximumWidth( 64 );
    seqtot_text->setAlignment( Qt::AlignRight );
    metaLayout->addWidget( seqtot_text, line, 9, 1, 1 );
130
    line++;
131

132
    /* Rating - on the same line */
133
    /*
134
    metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) ), line, 4, 1, 2 );
135
    rating_text = new QSpinBox; setSpinBounds( rating_text );
136
    metaLayout->addWidget( rating_text, line, 6, 1, 1 );
137
    */
138 139 140 141 142

    /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
    ADD_META( VLC_META_NOW_PLAYING, nowplaying_text, 0, 7 );
    nowplaying_text->setReadOnly( true ); line--;

143
    /* Language on the same line */
144
    ADD_META( VLC_META_LANGUAGE, language_text, 7, -1 ); line++;
145 146 147 148 149 150 151 152 153
    ADD_META( VLC_META_PUBLISHER, publisher_text, 0, 7 );

    fingerprintButton = new QPushButton( qtr("&Fingerprint") );
    fingerprintButton->setToolTip( qtr( "Find meta data using audio fingerprinting" ) );
    fingerprintButton->setVisible( false );
    metaLayout->addWidget( fingerprintButton, line, 7 , 3, -1 );
    CONNECT( fingerprintButton, clicked(), this, fingerprint() );

    line++;
154 155 156 157

    lblURL = new QLabel;
    lblURL->setOpenExternalLinks( true );
    lblURL->setTextFormat( Qt::RichText );
158
    lblURL->setMaximumWidth( 128 );
159 160 161
    metaLayout->addWidget( lblURL, line -1, 7, 1, -1 );

    ADD_META( VLC_META_COPYRIGHT, copyright_text, 0,  7 ); line++;
162

163
    /* ART_URL */
164
    art_cover = new CoverArtLabel( this, p_intf );
165
    metaLayout->addWidget( art_cover, line, 7, 6, 3, Qt::AlignLeft );
166

167
    ADD_META( VLC_META_ENCODED_BY, encodedby_text, 0, 7 ); line++;
168 169 170 171 172

    label = new QLabel( qtr( N_("Comments") ) ); label->setFont( smallFont );
    label->setContentsMargins( 3, 2, 0, 0 );
    metaLayout->addWidget( label, line++, 0, 1, 7 );
    description_text = new QTextEdit;
173
    description_text->setAcceptRichText( false );
174
    metaLayout->addWidget( description_text, line, 0, 1, 7 );
175
    CONNECT( description_text, textChanged(), this, enterEditMode() );
176
    line++;
177

178 179 180
    /* VLC_META_SETTING: Useless */
    /* ADD_META( TRACKID )  Useless ? */
    /* ADD_URI - Do not show it, done outside */
181

182
    metaLayout->setColumnStretch( 1, 20 );
183
    metaLayout->setColumnMinimumWidth ( 1, 80 );
184
    metaLayout->setRowStretch( line, 10 );
185
#undef ADD_META
186

187 188
    CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
    CONNECT( seqtot_text, textEdited( QString ), this, enterEditMode() );
189

190
    CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
191
//    CONNECT( THEMIM->getIM(), artChanged( QString ), this, enterEditMode() );
192 193 194 195
/*    CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/

    /* We are not yet in Edit Mode */
    b_inEditMode = false;
196
}
197

198 199 200
/**
 * Update all the MetaData and art on an "item-changed" event
 **/
201
void MetaPanel::update( input_item_t *p_item )
202
{
203 204 205 206 207
    if( !p_item )
    {
        clear();
        return;
    }
208

209 210
    /* Don't update if you are in edit mode */
    if( b_inEditMode ) return;
211
    p_input = p_item;
212

213
    char *psz_meta;
214 215 216
#define UPDATE_META( meta, widget ) {                                   \
    psz_meta = input_item_Get##meta( p_item );                          \
    widget->setText( !EMPTY_STR( psz_meta ) ? qfu( psz_meta ) : "" );   \
217
    free( psz_meta ); }
218

219
#define UPDATE_META_INT( meta, widget ) {           \
220
    psz_meta = input_item_Get##meta( p_item );      \
221
    if( !EMPTY_STR( psz_meta ) )                    \
222 223 224
        widget->setValue( atoi( psz_meta ) ); }     \
    free( psz_meta );

225
    /* Name / Title */
226 227 228
    psz_meta = input_item_GetTitleFbName( p_item );
    if( psz_meta )
    {
229
        title_text->setText( qfu( psz_meta ) );
230 231 232 233
        free( psz_meta );
    }
    else
        title_text->setText( "" );
234

235
    /* URL / URI */
236
    psz_meta = input_item_GetURI( p_item );
237
    if( !EMPTY_STR( psz_meta ) )
238 239
        emit uriSet( qfu( psz_meta ) );
    fingerprintButton->setVisible( Chromaprint::isSupported( QString( psz_meta ) ) );
Rémi Duraffort's avatar
Rémi Duraffort committed
240
    free( psz_meta );
241

242
    /* Other classic though */
243 244
    UPDATE_META( Artist, artist_text );
    UPDATE_META( Genre, genre_text );
245
    UPDATE_META( Copyright, copyright_text );
246
    UPDATE_META( Album, collection_text );
247 248
    disconnect( description_text, SIGNAL(textChanged()), this,
                SLOT(enterEditMode()) );
249
    UPDATE_META( Description, description_text );
250
    CONNECT( description_text, textChanged(), this, enterEditMode() );
251
    UPDATE_META( Language, language_text );
252 253
    UPDATE_META( NowPlaying, nowplaying_text );
    UPDATE_META( Publisher, publisher_text );
254
    UPDATE_META( EncodedBy, encodedby_text );
255

256
    UPDATE_META( Date, date_text );
257 258
    UPDATE_META( TrackNum, seqnum_text );
    UPDATE_META( TrackTotal, seqtot_text );
259
//    UPDATE_META( Setting, setting_text );
260
//    UPDATE_META_INT( Rating, rating_text );
261

262 263
    /* URL */
    psz_meta = input_item_GetURL( p_item );
264
    if( !EMPTY_STR( psz_meta ) )
265
    {
266 267 268 269 270 271 272
        QString newURL = qfu(psz_meta);
        if( currentURL != newURL )
        {
            currentURL = newURL;
            lblURL->setText( "<a href='" + currentURL + "'>" +
                             currentURL.remove( QRegExp( ".*://") ) + "</a>" );
        }
273
    }
274
    free( psz_meta );
275
#undef UPDATE_META_INT
276
#undef UPDATE_META
277

278 279 280 281
    // If a artURL is available as a local file, directly display it !

    QString file;
    char *psz_art = input_item_GetArtURL( p_item );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
282 283 284 285 286 287 288
    if( psz_art )
    {
        char *psz = make_path( psz_art );
        free( psz_art );
        file = qfu( psz );
        free( psz );
    }
289 290

    art_cover->showArtUpdate( file );
291
    art_cover->setItem( p_item );
292 293
}

294 295 296 297 298 299 300 301 302
/**
 * Save the MetaData, triggered by parent->save Button
 **/
void MetaPanel::saveMeta()
{
    if( p_input == NULL )
        return;

    /* now we read the modified meta data */
303
    input_item_SetTitle(  p_input, qtu( title_text->text() ) );
304 305 306
    input_item_SetArtist( p_input, qtu( artist_text->text() ) );
    input_item_SetAlbum(  p_input, qtu( collection_text->text() ) );
    input_item_SetGenre(  p_input, qtu( genre_text->text() ) );
307 308
    input_item_SetTrackNum(  p_input, qtu( seqnum_text->text() ) );
    input_item_SetTrackTotal(  p_input, qtu( seqtot_text->text() ) );
309
    input_item_SetDate(  p_input, qtu( date_text->text() ) );
.'s avatar
. committed
310
    input_item_SetLanguage(  p_input, qtu( language_text->text() ) );
311

312 313
    input_item_SetCopyright( p_input, qtu( copyright_text->text() ) );
    input_item_SetPublisher( p_input, qtu( publisher_text->text() ) );
314
    input_item_SetDescription( p_input, qtu( description_text->toPlainText() ) );
315

316
    input_item_WriteMeta( VLC_OBJECT(THEPL), p_input );
317

318 319
    /* Reset the status of the mode. No need to emit any signal because parent
       is the only caller */
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
    b_inEditMode = false;
}


bool MetaPanel::isInEditMode()
{
    return b_inEditMode;
}

void MetaPanel::enterEditMode()
{
    setEditMode( true );
}

void MetaPanel::setEditMode( bool b_editing )
{
    b_inEditMode = b_editing;
    if( b_editing )emit editing();
}

340 341 342
/*
 * Clear all the metadata widgets
 */
343 344 345 346 347 348 349
void MetaPanel::clear()
{
    title_text->clear();
    artist_text->clear();
    genre_text->clear();
    copyright_text->clear();
    collection_text->clear();
350 351
    seqnum_text->clear();
    seqtot_text->clear();
352 353
    disconnect( description_text, SIGNAL(textChanged()), this,
                SLOT(enterEditMode()) );
354
    description_text->clear();
355
    CONNECT( description_text, textChanged(), this, enterEditMode() );
356 357 358 359
    date_text->clear();
    language_text->clear();
    nowplaying_text->clear();
    publisher_text->clear();
360
    encodedby_text->clear();
361
    art_cover->clear();
362
    fingerprintButton->setVisible( false );
363

364
    setEditMode( false );
365
    emit uriSet( "" );
366
}
367

368 369 370 371 372 373 374 375 376 377 378 379 380 381
void MetaPanel::fingerprint()
{
    FingerprintDialog *dialog = new FingerprintDialog( this, p_intf, p_input );
    CONNECT( dialog, metaApplied( input_item_t * ), this, fingerprintUpdate( input_item_t * ) );
    dialog->setAttribute( Qt::WA_DeleteOnClose, true );
    dialog->show();
}

void MetaPanel::fingerprintUpdate( input_item_t *p_item )
{
    update( p_item );
    setEditMode( true );
}

382 383 384
/**
 * Second Panel - Shows the extra metadata in a tree, non editable.
 **/
385
ExtraMetaPanel::ExtraMetaPanel( QWidget *parent ) : QWidget( parent )
386 387
{
     QGridLayout *layout = new QGridLayout(this);
388

389
     QLabel *topLabel = new QLabel( qtr( "Extra metadata and other information"
390
                 " are shown in this panel.\n" ) );
391 392 393 394 395 396
     topLabel->setWordWrap( true );
     layout->addWidget( topLabel, 0, 0 );

     extraMetaTree = new QTreeWidget( this );
     extraMetaTree->setAlternatingRowColors( true );
     extraMetaTree->setColumnCount( 2 );
397
     extraMetaTree->resizeColumnToContents( 0 );
398
     extraMetaTree->setHeaderHidden( true );
399 400 401
     layout->addWidget( extraMetaTree, 1, 0 );
}

402
/**
403
 * Update the Extra Metadata from p_meta->i_extras
404
 **/
405
void ExtraMetaPanel::update( input_item_t *p_item )
406
{
407 408 409 410 411
    if( !p_item )
    {
        clear();
        return;
    }
412

413 414 415 416
    QList<QTreeWidgetItem *> items;

    extraMetaTree->clear();

417
    vlc_mutex_lock( &p_item->lock );
418
    vlc_meta_t *p_meta = p_item->p_meta;
419
    if( !p_meta )
420 421
    {
        vlc_mutex_unlock( &p_item->lock );
422
        return;
423
    }
424

425 426 427 428 429 430 431 432 433
    const char *psz_disc_number = vlc_meta_Get( p_meta, vlc_meta_DiscNumber);
    if( psz_disc_number )
    {
        QStringList tempItem;
        tempItem.append( VLC_META_DISCNUMBER );
        tempItem.append( qfu( psz_disc_number ) );
        items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
    }

Christophe Mutricy's avatar
Christophe Mutricy committed
434
    char ** ppsz_allkey = vlc_meta_CopyExtraNames( p_meta);
435 436

    for( int i = 0; ppsz_allkey[i] ; i++ )
437
    {
Christophe Mutricy's avatar
Christophe Mutricy committed
438
        const char * psz_value = vlc_meta_GetExtra( p_meta, ppsz_allkey[i] );
439
        QStringList tempItem;
440
        tempItem.append( qfu( ppsz_allkey[i] ) + " : ");
441
        tempItem.append( qfu( psz_value ) );
442
        items.append( new QTreeWidgetItem ( extraMetaTree, tempItem ) );
443
        free( ppsz_allkey[i] );
444
    }
445
    vlc_mutex_unlock( &p_item->lock );
446
    free( ppsz_allkey );
447

448
    extraMetaTree->addTopLevelItems( items );
449
    extraMetaTree->resizeColumnToContents( 0 );
450 451
}

452 453 454 455 456 457 458 459 460 461 462 463
/**
 * Clear the ExtraMetaData Tree
 **/
void ExtraMetaPanel::clear()
{
    extraMetaTree->clear();
}

/**
 * Third panel - Stream info
 * Display all codecs and muxers info that we could gather.
 **/
464
InfoPanel::InfoPanel( QWidget *parent ) : QWidget( parent )
465 466 467 468 469 470
{
     QGridLayout *layout = new QGridLayout(this);

     QList<QTreeWidgetItem *> items;

     QLabel *topLabel = new QLabel( qtr( "Information about what your media or"
471
              " stream is made of.\nMuxer, Audio and Video Codecs, Subtitles "
472 473 474 475 476 477 478
              "are shown." ) );
     topLabel->setWordWrap( true );
     layout->addWidget( topLabel, 0, 0 );

     InfoTree = new QTreeWidget(this);
     InfoTree->setColumnCount( 1 );
     InfoTree->header()->hide();
479
#if HAS_QT5
480 481
     InfoTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
482
     InfoTree->header()->setResizeMode(QHeaderView::ResizeToContents);
483
#endif
484 485 486 487 488 489 490 491
     layout->addWidget(InfoTree, 1, 0 );
}

/**
 * Update the Codecs information on parent->update()
 **/
void InfoPanel::update( input_item_t *p_item)
{
492 493 494 495 496
    if( !p_item )
    {
        clear();
        return;
    }
497

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
    InfoTree->clear();
    QTreeWidgetItem *current_item = NULL;
    QTreeWidgetItem *child_item = NULL;

    for( int i = 0; i< p_item->i_categories ; i++)
    {
        current_item = new QTreeWidgetItem();
        current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
        InfoTree->addTopLevelItem( current_item );

        for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
        {
            child_item = new QTreeWidgetItem ();
            child_item->setText( 0,
                    qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
                    + ": "
                    + qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
515

516 517
            current_item->addChild(child_item);
        }
518
        InfoTree->setItemExpanded( current_item, true);
519 520
    }
}
521

522 523 524 525 526 527 528 529 530 531 532 533 534 535
/**
 * Clear the tree
 **/
void InfoPanel::clear()
{
    InfoTree->clear();
}

/**
 * Save all the information to a file
 * Not yet implemented.
 **/
/*
void InfoPanel::saveCodecsInfo()
536
{}
537 538 539 540 541 542
*/

/**
 * Fourth Panel - Stats
 * Displays the Statistics for reading/streaming/encoding/displaying in a tree
 */
543
InputStatsPanel::InputStatsPanel( QWidget *parent ): QWidget( parent )
544
{
545
     QVBoxLayout *layout = new QVBoxLayout(this);
546

François Cartegnie's avatar
François Cartegnie committed
547 548
     QLabel *topLabel = new QLabel( qtr( "Current"
                 " media / stream " "statistics") );
549 550
     topLabel->setWordWrap( true );
     layout->addWidget( topLabel, 0, 0 );
551

552
     StatsTree = new QTreeWidget(this);
553
     StatsTree->setColumnCount( 3 );
554
     StatsTree->setHeaderHidden( true );
555 556

#define CREATE_TREE_ITEM( itemName, itemText, itemValue, unit ) {              \
557 558
    itemName =                                                                 \
      new QTreeWidgetItem((QStringList () << itemText << itemValue << unit )); \
559 560 561 562 563 564 565
    itemName->setTextAlignment( 1 , Qt::AlignRight ) ; }

#define CREATE_CATEGORY( catName, itemText ) {                           \
    CREATE_TREE_ITEM( catName, itemText , "", "" );                      \
    catName->setExpanded( true );                                        \
    StatsTree->addTopLevelItem( catName );    }

566 567
#define CREATE_AND_ADD_TO_CAT( itemName, itemText, itemValue, catName, unit ){ \
    CREATE_TREE_ITEM( itemName, itemText, itemValue, unit );                   \
568 569
    catName->addChild( itemName ); }

570
    /* Create the main categories */
571
    CREATE_CATEGORY( audio, qtr("Audio") );
572
    CREATE_CATEGORY( video, qtr("Video") );
François Cartegnie's avatar
François Cartegnie committed
573 574
    CREATE_CATEGORY( input, qtr("Input/Read") );
    CREATE_CATEGORY( streaming, qtr("Output/Written/Sent") );
575

François Cartegnie's avatar
François Cartegnie committed
576
    CREATE_AND_ADD_TO_CAT( read_media_stat, qtr("Media data size"),
577
                           "0", input , "KiB" );
578 579
    CREATE_AND_ADD_TO_CAT( input_bitrate_stat, qtr("Input bitrate"),
                           "0", input, "kb/s" );
580 581
    input_bitrate_graph = new QTreeWidgetItem();
    input_bitrate_stat->addChild( input_bitrate_graph );
582
    CREATE_AND_ADD_TO_CAT( demuxed_stat, qtr("Demuxed data size"), "0", input, "KiB") ;
François Cartegnie's avatar
François Cartegnie committed
583
    CREATE_AND_ADD_TO_CAT( stream_bitrate_stat, qtr("Content bitrate"),
584
                           "0", input, "kb/s" );
François Cartegnie's avatar
François Cartegnie committed
585
    CREATE_AND_ADD_TO_CAT( corrupted_stat, qtr("Discarded (corrupted)"),
586
                           "0", input, "" );
587
    CREATE_AND_ADD_TO_CAT( discontinuity_stat, qtr("Timeline changed"),
588
                           "0", input, "" );
589

François Cartegnie's avatar
François Cartegnie committed
590 591 592 593 594 595
    CREATE_AND_ADD_TO_CAT( vdecoded_stat, qtr("Decoded"),
                           "0", video, qtr("blocks") );
    CREATE_AND_ADD_TO_CAT( vdisplayed_stat, qtr("Displayed"),
                           "0", video, qtr("frames") );
    CREATE_AND_ADD_TO_CAT( vlost_frames_stat, qtr("Lost"),
                           "0", video, qtr("frames") );
596

François Cartegnie's avatar
François Cartegnie committed
597 598
    CREATE_AND_ADD_TO_CAT( send_stat, qtr("Sent"), "0", streaming, qtr("packets") );
    CREATE_AND_ADD_TO_CAT( send_bytes_stat, qtr("Sent"),
599
                           "0", streaming, "KiB" );
François Cartegnie's avatar
François Cartegnie committed
600
    CREATE_AND_ADD_TO_CAT( send_bitrate_stat, qtr("Upstream rate"),
601 602
                           "0", streaming, "kb/s" );

François Cartegnie's avatar
François Cartegnie committed
603 604 605 606 607
    CREATE_AND_ADD_TO_CAT( adecoded_stat, qtr("Decoded"),
                           "0", audio, qtr("blocks") );
    CREATE_AND_ADD_TO_CAT( aplayed_stat, qtr("Played"),
                           "0", audio, qtr("buffers") );
    CREATE_AND_ADD_TO_CAT( alost_stat, qtr("Lost"), "0", audio, qtr("buffers") );
608

Rémi Duraffort's avatar
Rémi Duraffort committed
609 610 611 612
#undef CREATE_AND_ADD_TO_CAT
#undef CREATE_CATEGORY
#undef CREATE_TREE_ITEM

613 614 615 616 617 618
    input->setExpanded( true );
    video->setExpanded( true );
    streaming->setExpanded( true );
    audio->setExpanded( true );

    StatsTree->resizeColumnToContents( 0 );
619
    StatsTree->setColumnWidth( 1 , 200 );
620

621 622 623 624 625 626
    layout->addWidget(StatsTree, 4, 0 );

    statsView = new VLCStatsView( this );
    statsView->setFrameStyle( QFrame::NoFrame );
    statsView->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
    input_bitrate_graph->setSizeHint( 1, QSize(0, 100) );
627 628 629 630 631
    QString graphlabel =
            QString( "<font style=\"color:#ff8c00\">%1</font><br/>%2" )
            .arg( qtr("Last 60 seconds") )
            .arg( qtr("Overall") );
    StatsTree->setItemWidget( input_bitrate_graph, 0, new QLabel( graphlabel ) );
632 633 634 635 636 637 638
    StatsTree->setItemWidget( input_bitrate_graph, 1, statsView );
}

void InputStatsPanel::hideEvent( QHideEvent * event )
{
    statsView->reset();
    QWidget::hideEvent( event );
639 640
}

641 642 643
/**
 * Update the Statistics
 **/
644 645
void InputStatsPanel::update( input_item_t *p_item )
{
646
    if ( !isVisible() ) return;
647
    assert( p_item );
648 649
    vlc_mutex_lock( &p_item->p_stats->lock );

650 651 652 653
#define UPDATE_INT( widget, calc... ) \
    { widget->setText( 1, QString::number( (qulonglong)calc ) ); }

#define UPDATE_FLOAT( widget, format, calc... ) \
654 655
    { QString str; widget->setText( 1 , str.sprintf( format, ## calc ) );  }

656
    UPDATE_INT( read_media_stat, (p_item->p_stats->i_read_bytes / 1024 ) );
657
    UPDATE_FLOAT( input_bitrate_stat,  "%6.0f", (float)(p_item->p_stats->f_input_bitrate *  8000 ));
658
    UPDATE_INT( demuxed_stat,    (p_item->p_stats->i_demux_read_bytes / 1024 ) );
659
    UPDATE_FLOAT( stream_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_demux_bitrate *  8000 ));
660 661
    UPDATE_INT( corrupted_stat,      p_item->p_stats->i_demux_corrupted );
    UPDATE_INT( discontinuity_stat,  p_item->p_stats->i_demux_discontinuity );
662

663 664
    statsView->addValue( p_item->p_stats->f_input_bitrate * 8000 );

665
    /* Video */
666 667 668
    UPDATE_INT( vdecoded_stat,     p_item->p_stats->i_decoded_video );
    UPDATE_INT( vdisplayed_stat,   p_item->p_stats->i_displayed_pictures );
    UPDATE_INT( vlost_frames_stat, p_item->p_stats->i_lost_pictures );
669 670

    /* Sout */
671 672 673
    UPDATE_INT( send_stat,        p_item->p_stats->i_sent_packets );
    UPDATE_INT( send_bytes_stat,  (p_item->p_stats->i_sent_bytes)/ 1024 );
    UPDATE_FLOAT( send_bitrate_stat, "%6.0f", (float)(p_item->p_stats->f_send_bitrate * 8000 ) );
674 675

    /* Audio*/
676 677 678
    UPDATE_INT( adecoded_stat, p_item->p_stats->i_decoded_audio );
    UPDATE_INT( aplayed_stat,  p_item->p_stats->i_played_abuffers );
    UPDATE_INT( alost_stat,    p_item->p_stats->i_lost_abuffers );
679

680 681
#undef UPDATE_INT
#undef UPDATE_FLOAT
Rémi Duraffort's avatar
Rémi Duraffort committed
682

683 684 685 686 687 688
    vlc_mutex_unlock(& p_item->p_stats->lock );
}

void InputStatsPanel::clear()
{
}