input_manager.cpp 34.1 KB
Newer Older
1 2 3
/*****************************************************************************
 * input_manager.cpp : Manage an input and interact with its GUI elements
 ****************************************************************************
4
 * Copyright (C) 2006-2008 the VideoLAN team
5
 * $Id$
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Ilkka Ollakka  <ileoo@videolan.org>
9
 *          Jean-Baptiste <jb@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 "input_manager.hpp"
31
#include "recents.hpp"
32 33

#include <vlc_keys.h>           /* ACTION_ID */
34
#include <vlc_url.h>            /* vlc_uri_decode */
35 36
#include <vlc_strings.h>        /* str_format_meta */
#include <vlc_aout.h>           /* audio_output_t */
37 38

#include <QApplication>
Angelo Haller's avatar
Angelo Haller committed
39
#include <QFile>
40
#include <QDir>
41
#include <QSignalMapper>
42
#include <QMessageBox>
43

44 45
#include <assert.h>

Laurent Aimar's avatar
Laurent Aimar committed
46 47
static int InputEvent( vlc_object_t *, const char *,
                       vlc_value_t, vlc_value_t, void * );
Laurent Aimar's avatar
Laurent Aimar committed
48 49
static int VbiEvent( vlc_object_t *, const char *,
                     vlc_value_t, vlc_value_t, void * );
Laurent Aimar's avatar
Laurent Aimar committed
50

51 52 53 54 55 56
/* Ensure arbitratry (not dynamically allocated) event IDs are not in use */
static inline void registerAndCheckEventIds( int start, int end )
{
    for ( int i=start ; i<=end ; i++ )
        Q_ASSERT( QEvent::registerEventType( i ) == i ); /* event ID collision ! */
}
Laurent Aimar's avatar
Laurent Aimar committed
57

58 59
/**********************************************************************
 * InputManager implementation
60 61 62
 **********************************************************************
 * The Input Manager can be the main one around the playlist
 * But can also be used for VLM dialog or similar
63 64
 **********************************************************************/

65 66
InputManager::InputManager( MainInputManager *mim, intf_thread_t *_p_intf) :
                           QObject( mim ), p_intf( _p_intf )
67
{
68
    p_mim        = mim;
69
    i_old_playing_status = END_S;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
70
    oldName      = "";
71 72
    artUrl       = "";
    p_input      = NULL;
73
    p_input_vbi  = NULL;
74
    f_rate       = 0.;
75
    p_item       = NULL;
76
    b_video      = false;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
77 78
    timeA        = 0;
    timeB        = 0;
79
    f_cache      = -1.; /* impossible initial value, different from all */
80 81
    registerAndCheckEventIds( IMEvent::PositionUpdate, IMEvent::FullscreenControlPlanHide );
    registerAndCheckEventIds( PLEvent::PLItemAppended, PLEvent::PLEmpty );
82 83 84 85
}

InputManager::~InputManager()
{
86
    delInput();
87 88
}

89 90
void InputManager::inputChangedHandler()
{
91
    setInput( p_mim->getInput() );
92 93
}

94 95
/* Define the Input used.
   Add the callbacks on input
96
   p_input is held once here */
97 98
void InputManager::setInput( input_thread_t *_p_input )
{
99
    delInput();
100
    p_input = _p_input;
101
    if( p_input != NULL )
102
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
103
        msg_Dbg( p_intf, "IM: Setting an input" );
104
        vlc_object_hold( p_input );
105
        addCallbacks();
106

107
        UpdateStatus();
108
        UpdateName();
109
        UpdateArt();
110
        UpdateTeletext();
111
        UpdateNavigation();
112
        UpdateVout();
113

114
        p_item = input_GetItem( p_input );
115
        emit rateChanged( var_GetFloat( p_input, "rate" ) );
116 117

        /* Get Saved Time */
118
        if( p_item->i_type == ITEM_TYPE_FILE )
119
        {
120 121
            char *uri = input_item_GetURI( p_item );

122
            int i_time = RecentsMRL::getInstance( p_intf )->time( qfu(uri) );
123
            if( i_time > 0 && qfu( uri ) != lastURI &&
124 125 126 127
                    !var_GetFloat( p_input, "run-time" ) &&
                    !var_GetFloat( p_input, "start-time" ) &&
                    !var_GetFloat( p_input, "stop-time" ) )
            {
128
                emit resumePlayback( (int64_t)i_time * 1000 );
129
            }
130 131 132
            playlist_Lock( THEPL );
            // Add root items only
            playlist_item_t* p_node = playlist_CurrentPlayingItem( THEPL );
133
            if ( p_node != NULL && p_node->p_parent != NULL && p_node->p_parent->i_id == THEPL->p_playing->i_id )
134 135 136 137 138 139 140 141
            {
                // Save the latest URI to avoid asking to restore the
                // position on the same input file.
                lastURI = qfu( uri );
                RecentsMRL::getInstance( p_intf )->addRecent( lastURI );
            }
            playlist_Unlock( THEPL );
            free( uri );
142
        }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
143 144 145
    }
    else
    {
146
        p_item = NULL;
147
        lastURI.clear();
148
        assert( !p_input_vbi );
149
        emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
150 151
    }
}
152

153 154 155
/* delete Input if it ever existed.
   Delete the callbacls on input
   p_input is released once here */
156 157
void InputManager::delInput()
{
158
    if( !p_input ) return;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
159
    msg_Dbg( p_intf, "IM: Deleting the input" );
160

161
    /* Save time / position */
162 163 164 165 166 167
    char *uri = input_item_GetURI( p_item );
    if( uri != NULL ) {
        float f_pos = var_GetFloat( p_input , "position" );
        int64_t i_time = -1;

        if( f_pos >= 0.05f && f_pos <= 0.95f
168 169
         && var_GetInteger( p_input, "length" ) >= 60 * CLOCK_FREQ )
            i_time = var_GetInteger( p_input, "time");
170 171 172

        RecentsMRL::getInstance( p_intf )->setTime( qfu(uri), i_time );
        free(uri);
173 174
    }

175 176
    delCallbacks();
    i_old_playing_status = END_S;
177
    p_item               = NULL;
178 179 180 181 182
    oldName              = "";
    artUrl               = "";
    b_video              = false;
    timeA                = 0;
    timeB                = 0;
183
    f_rate               = 0. ;
184

185 186 187 188 189 190
    if( p_input_vbi )
    {
        vlc_object_release( p_input_vbi );
        p_input_vbi = NULL;
    }

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
191 192 193
    vlc_object_release( p_input );
    p_input = NULL;

194
    emit positionUpdated( -1.0, 0 ,0 );
195
    emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
196 197 198
    emit nameChanged( "" );
    emit chapterChanged( 0 );
    emit titleChanged( 0 );
199
    emit playingStatusChanged( END_S );
200 201

    emit teletextPossible( false );
202
    emit AtoBchanged( false, false );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
203
    emit voutChanged( false );
204
    emit voutListChanged( NULL, 0 );
205

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
206 207
    /* Reset all InfoPanels but stats */
    emit artChanged( NULL );
208
    emit artChanged( "" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
209
    emit infoChanged( NULL );
210
    emit currentMetaChanged( (input_item_t *)NULL );
211

212
    emit encryptionChanged( false );
213
    emit recordingStateChanged( false );
214

215
    emit cachingChanged( 0.0 );
216 217
}

218
/* Convert the event from the callbacks in actions */
219 220
void InputManager::customEvent( QEvent *event )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
221
    int i_type = event->type();
222
    IMEvent *ple = static_cast<IMEvent *>(event);
223

224
    if( i_type == IMEvent::ItemChanged )
225
        UpdateMeta( ple->item() );
226

227
    if( !hasInput() )
228
        return;
229

230
    /* Actions */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
231
    switch( i_type )
232
    {
233
    case IMEvent::PositionUpdate:
234
        UpdatePosition();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
235
        break;
236
    case IMEvent::StatisticsUpdate:
237 238
        UpdateStats();
        break;
239
    case IMEvent::ItemChanged:
240
        /* Ignore ItemChanged_Type event that does not apply to our input */
241
        if( p_item == ple->item() )
242 243
        {
            UpdateStatus();
244
            UpdateName();
245
            UpdateArt();
246
            UpdateMeta();
247
            /* Update duration of file */
248
        }
249
        break;
250
    case IMEvent::ItemStateChanged:
251 252
        UpdateStatus();
        break;
253
    case IMEvent::NameChanged:
254
        UpdateName();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
255
        break;
256
    case IMEvent::MetaChanged:
257
        UpdateMeta();
258
        UpdateName(); /* Needed for NowPlaying */
259
        UpdateArt(); /* Art is part of meta in the core */
Laurent Aimar's avatar
Laurent Aimar committed
260
        break;
261
    case IMEvent::InfoChanged:
262
        UpdateInfo();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
263
        break;
264
    case IMEvent::ItemTitleChanged:
265
        UpdateNavigation();
266
        UpdateName(); /* Display the name of the Chapter, if exists */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
267
        break;
268
    case IMEvent::ItemRateChanged:
269 270
        UpdateRate();
        break;
271
    case IMEvent::ItemEsChanged:
Laurent Aimar's avatar
Laurent Aimar committed
272 273
        UpdateTeletext();
        // We don't do anything ES related. Why ?
274
        break;
275
    case IMEvent::ItemTeletextChanged:
276 277
        UpdateTeletext();
        break;
278
    case IMEvent::InterfaceVoutUpdate:
279 280
        UpdateVout();
        break;
281
    case IMEvent::SynchroChanged:
282 283
        emit synchroChanged();
        break;
284
    case IMEvent::CachingEvent:
285 286
        UpdateCaching();
        break;
287
    case IMEvent::BookmarksChanged:
288 289
        emit bookmarksChanged();
        break;
290
    case IMEvent::InterfaceAoutUpdate:
291 292
        UpdateAout();
        break;
293
    case IMEvent::RecordingEvent:
294 295
        UpdateRecord();
        break;
296
    case IMEvent::ProgramChanged:
297 298
        UpdateProgramEvent();
        break;
299
    case IMEvent::EPGEvent:
300 301
        UpdateEPG();
        break;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
302 303
    default:
        msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
304
        vlc_assert_unreachable();
305
    }
306
}
307

308 309 310 311 312 313 314 315 316 317 318 319 320
/* Add the callbacks on Input. Self explanatory */
inline void InputManager::addCallbacks()
{
    var_AddCallback( p_input, "intf-event", InputEvent, this );
}

/* Delete the callbacks on Input. Self explanatory */
inline void InputManager::delCallbacks()
{
    var_DelCallback( p_input, "intf-event", InputEvent, this );
}

/* Static callbacks for IM */
321
int MainInputManager::ItemChanged( vlc_object_t *p_this, const char *psz_var,
322 323
                        vlc_value_t oldval, vlc_value_t newval, void *param )
{
324 325
    VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );

326
    InputManager *im = (InputManager*)param;
327
    input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
328

329
    IMEvent *event = new IMEvent( IMEvent::ItemChanged, p_item );
330
    QApplication::postEvent( im, event );
331 332 333 334 335 336
    return VLC_SUCCESS;
}

static int InputEvent( vlc_object_t *p_this, const char *,
                       vlc_value_t, vlc_value_t newval, void *param )
{
337 338
    VLC_UNUSED( p_this );

339 340 341 342 343 344
    InputManager *im = (InputManager*)param;
    IMEvent *event;

    switch( newval.i_int )
    {
    case INPUT_EVENT_STATE:
345
        event = new IMEvent( IMEvent::ItemStateChanged );
346 347
        break;
    case INPUT_EVENT_RATE:
348
        event = new IMEvent( IMEvent::ItemRateChanged );
349
        break;
350 351
    case INPUT_EVENT_POSITION:
    //case INPUT_EVENT_LENGTH:
352
        event = new IMEvent( IMEvent::PositionUpdate );
353 354 355 356
        break;

    case INPUT_EVENT_TITLE:
    case INPUT_EVENT_CHAPTER:
357
        event = new IMEvent( IMEvent::ItemTitleChanged );
358 359 360
        break;

    case INPUT_EVENT_ES:
361
        event = new IMEvent( IMEvent::ItemEsChanged );
362 363
        break;
    case INPUT_EVENT_TELETEXT:
364
        event = new IMEvent( IMEvent::ItemTeletextChanged );
365 366
        break;

367
    case INPUT_EVENT_STATISTICS:
368
        event = new IMEvent( IMEvent::StatisticsUpdate );
369 370
        break;

371
    case INPUT_EVENT_VOUT:
372
        event = new IMEvent( IMEvent::InterfaceVoutUpdate );
373
        break;
374
    case INPUT_EVENT_AOUT:
375
        event = new IMEvent( IMEvent::InterfaceAoutUpdate );
376 377 378
        break;

    case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
379
        event = new IMEvent( IMEvent::MetaChanged );
380 381
        break;
    case INPUT_EVENT_ITEM_INFO: /* Codec Info */
382
        event = new IMEvent( IMEvent::InfoChanged );
383 384
        break;
    case INPUT_EVENT_ITEM_NAME:
385
        event = new IMEvent( IMEvent::NameChanged );
386 387 388 389
        break;

    case INPUT_EVENT_AUDIO_DELAY:
    case INPUT_EVENT_SUBTITLE_DELAY:
390
        event = new IMEvent( IMEvent::SynchroChanged );
391 392 393
        break;

    case INPUT_EVENT_CACHE:
394
        event = new IMEvent( IMEvent::CachingEvent );
395 396 397
        break;

    case INPUT_EVENT_BOOKMARK:
398
        event = new IMEvent( IMEvent::BookmarksChanged );
399 400 401
        break;

    case INPUT_EVENT_RECORD:
402
        event = new IMEvent( IMEvent::RecordingEvent );
403
        break;
404 405 406

    case INPUT_EVENT_PROGRAM:
        /* This is for PID changes */
407
        event = new IMEvent( IMEvent::ProgramChanged );
408 409
        break;

410 411
    case INPUT_EVENT_ITEM_EPG:
        /* EPG data changed */
412
        event = new IMEvent( IMEvent::EPGEvent );
413 414
        break;

415 416
    case INPUT_EVENT_SIGNAL:
        /* This is for capture-card signals */
417
        /* event = new IMEvent( SignalChanged_Type );
418 419 420 421 422 423 424
        break; */
    default:
        event = NULL;
        break;
    }

    if( event )
425
        QApplication::postEvent( im, event );
426 427
    return VLC_SUCCESS;
}
428

Laurent Aimar's avatar
Laurent Aimar committed
429 430 431 432
static int VbiEvent( vlc_object_t *, const char *,
                     vlc_value_t, vlc_value_t, void *param )
{
    InputManager *im = (InputManager*)param;
433
    IMEvent *event = new IMEvent( IMEvent::ItemTeletextChanged );
Laurent Aimar's avatar
Laurent Aimar committed
434

435
    QApplication::postEvent( im, event );
Laurent Aimar's avatar
Laurent Aimar committed
436 437 438
    return VLC_SUCCESS;
}

439
void InputManager::UpdatePosition()
440
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
441
    /* Update position */
442 443 444 445
    int64_t i_length = var_GetInteger(  p_input , "length" );
    int64_t i_time = var_GetInteger(  p_input , "time");
    float f_pos = var_GetFloat(  p_input , "position" );
    emit positionUpdated( f_pos, i_time, i_length / CLOCK_FREQ );
446 447
}

448
void InputManager::UpdateNavigation()
449
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
450 451
    /* Update navigation status */
    vlc_value_t val; val.i_int = 0;
452
    vlc_value_t val2; val2.i_int = 0;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
453

454
    var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
455

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
456 457
    if( val.i_int > 0 )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
458
        /* p_input != NULL since val.i_int != 0 */
459
        var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
460 461 462

        emit titleChanged( val.i_int > 1 );
        emit chapterChanged( val2.i_int > 1 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
463 464
    }
    else
465
        emit chapterChanged( false );
466 467 468 469 470

    if( hasInput() )
        emit inputCanSeek( var_GetBool( p_input, "can-seek" ) );
    else
        emit inputCanSeek( false );
471 472
}

473
void InputManager::UpdateStatus()
474
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
475
    /* Update playing status */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
476 477
    int state = var_GetInteger( p_input, "state" );
    if( i_old_playing_status != state )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
478
    {
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
479
        i_old_playing_status = state;
480
        emit playingStatusChanged( state );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
481
    }
482 483
}

484
void InputManager::UpdateRate()
485
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
486
    /* Update Rate */
487 488
    float f_new_rate = var_GetFloat( p_input, "rate" );
    if( f_new_rate != f_rate )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
489
    {
490
        f_rate = f_new_rate;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
491
        /* Update rate */
492
        emit rateChanged( f_rate );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
493
    }
494 495
}

496
void InputManager::UpdateName()
497
{
498
    /* Update text, name and nowplaying */
499
    QString name;
500

501
    /* Try to get the nowplaying */
502
    char *format = var_InheritString( p_intf, "input-title-format" );
503 504 505 506 507 508 509 510 511 512 513
    char *formatted = NULL;
    if (format != NULL)
    {
        formatted = str_format_meta( p_input, format );
        free( format );
        if( formatted != NULL )
        {
            name = qfu(formatted);
            free( formatted );
        }
    }
514

515
    /* If we have Nothing */
516
    if( name.simplified().isEmpty() )
517
    {
518 519 520 521
        char *uri = input_item_GetURI( input_GetItem( p_input ) );
        char *file = uri ? strrchr( uri, '/' ) : NULL;
        if( file != NULL )
        {
522
            vlc_uri_decode( ++file );
523 524 525 526 527
            name = qfu(file);
        }
        else
            name = qfu(uri);
        free( uri );
528 529
    }

530 531 532
    name = name.trimmed();

    if( oldName != name )
533
    {
534 535
        emit nameChanged( name );
        oldName = name;
536
    }
537
}
538

539
int InputManager::playingStatus() const
540 541 542 543
{
    return i_old_playing_status;
}

544
bool InputManager::hasAudio()
545
{
546 547 548 549 550 551 552 553 554
    if( hasInput() )
    {
        vlc_value_t val;
        var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
        return val.i_int > 0;
    }
    return false;
}

555 556 557 558 559
bool InputManager::hasVisualisation()
{
    if( !p_input )
        return false;

560
    audio_output_t *aout = input_GetAout( p_input );
561 562 563 564
    if( !aout )
        return false;

    char *visual = var_InheritString( aout, "visual" );
Rémi Duraffort's avatar
Rémi Duraffort committed
565 566
    vlc_object_release( aout );

567 568 569 570 571 572 573
    if( !visual )
        return false;

    free( visual );
    return true;
}

574
void InputManager::UpdateTeletext()
575
{
576 577
    const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
    const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
Laurent Aimar's avatar
Laurent Aimar committed
578

579 580
    /* Teletext is possible. Show the buttons */
    emit teletextPossible( b_enabled );
Laurent Aimar's avatar
Laurent Aimar committed
581

582 583 584 585 586 587
    /* If Teletext is selected */
    if( b_enabled && i_teletext_es >= 0 )
    {
        /* Then, find the current page */
        int i_page = 100;
        bool b_transparent = false;
588

589 590 591 592 593
        if( p_input_vbi )
        {
            var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
            vlc_object_release( p_input_vbi );
        }
Laurent Aimar's avatar
Laurent Aimar committed
594

595 596
        if( input_GetEsObjects( p_input, i_teletext_es, &p_input_vbi, NULL, NULL ) )
            p_input_vbi = NULL;
Laurent Aimar's avatar
Laurent Aimar committed
597

598 599 600 601 602
        if( p_input_vbi )
        {
            /* This callback is not remove explicitly, but interfaces
             * are guaranted to outlive input */
            var_AddCallback( p_input_vbi, "vbi-page", VbiEvent, this );
Laurent Aimar's avatar
Laurent Aimar committed
603

604 605
            i_page = var_GetInteger( p_input_vbi, "vbi-page" );
            b_transparent = !var_GetBool( p_input_vbi, "vbi-opaque" );
Laurent Aimar's avatar
Laurent Aimar committed
606
        }
607 608 609
        emit newTelexPageSet( i_page );
        emit teletextTransparencyActivated( b_transparent );

Laurent Aimar's avatar
Laurent Aimar committed
610
    }
611
    emit teletextActivated( b_enabled && i_teletext_es >= 0 );
612 613
}

614 615
void InputManager::UpdateEPG()
{
616
    emit epgChanged();
617 618
}

619 620
void InputManager::UpdateVout()
{
621 622
    size_t i_vout;
    vout_thread_t **pp_vout;
623 624 625 626 627

    if( !p_input )
        return;

    /* Get current vout lists from input */
628
    if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
629
    {
630 631 632
        i_vout = 0;
        pp_vout = NULL;
    }
633

634 635
    /* */
    emit voutListChanged( pp_vout, i_vout );
636

637 638 639 640 641
    /* */
    bool b_old_video = b_video;
    b_video = i_vout > 0;
    if( !!b_old_video != !!b_video )
        emit voutChanged( b_video );
642

643 644 645 646
    /* Release the vout list */
    for( size_t i = 0; i < i_vout; i++ )
        vlc_object_release( (vlc_object_t*)pp_vout[i] );
    free( pp_vout );
647
}
648

649 650
void InputManager::UpdateAout()
{
651
    /* TODO */
652
}
653

654 655
void InputManager::UpdateCaching()
{
656
    float f_newCache = var_GetFloat ( p_input, "cache" );
657 658
    if( f_newCache != f_cache )
    {
659
        f_cache = f_newCache;
660
        /* Update cache */
661 662 663 664
        emit cachingChanged( f_cache );
    }
}

665
void InputManager::requestArtUpdate( input_item_t *p_item, bool b_forced )
666
{
667 668 669 670 671
    bool b_current_item = false;
    if ( !p_item && hasInput() )
    {   /* default to current item */
        p_item = input_GetItem( p_input );
        b_current_item = true;
672
    }
673 674

    if ( p_item )
675
    {
676
        /* check if it has already been enqueued */
677
        if ( p_item->p_meta && !b_forced )
678 679
        {
            int status = vlc_meta_GetStatus( p_item->p_meta );
680
            if ( status & ( ITEM_ART_NOTFOUND|ITEM_ART_FETCHED ) )
681 682
                return;
        }
683
        libvlc_ArtRequest( p_intf->p_libvlc, p_item,
684
                           (b_forced) ? META_REQUEST_OPTION_SCOPE_ANY
685
                                      : META_REQUEST_OPTION_NONE );
686
        /* No input will signal the cover art to update,
687 688 689 690 691
             * let's do it ourself */
        if ( b_current_item )
            UpdateArt();
        else
            emit artChanged( p_item );
692
    }
693 694
}

695
const QString InputManager::decodeArtURL( input_item_t *p_item )
696
{
697
    assert( p_item );
698

699
    char *psz_art = input_item_GetArtURL( p_item );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
700 701
    if( psz_art )
    {
702
        char *psz = vlc_uri2path( psz_art );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
703 704 705
        free( psz_art );
        psz_art = psz;
    }
706

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
707
#if 0
708 709
    /* Taglib seems to define a attachment://, It won't work yet */
    url = url.replace( "attachment://", "" );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
710
#endif
711 712 713 714

    QString path = qfu( psz_art ? psz_art : "" );
    free( psz_art );
    return path;
715 716 717 718
}

void InputManager::UpdateArt()
{
719
    QString url = decodeArtURL( input_GetItem( p_input ) );
720

721 722 723 724
    /* the art hasn't changed, no need to update */
    if(artUrl == url)
        return;

725
    /* Update Art meta */
726 727
    artUrl = url;
    emit artChanged( artUrl );
728 729
}

Angelo Haller's avatar
Angelo Haller committed
730 731 732 733 734
void InputManager::setArt( input_item_t *p_item, QString fileUrl )
{
    if( hasInput() )
    {
        char *psz_cachedir = config_GetUserDir( VLC_CACHE_DIR );
735
        QString old_url = p_mim->getIM()->decodeArtURL( p_item );
736
        old_url = QDir( old_url ).canonicalPath();
Angelo Haller's avatar
Angelo Haller committed
737 738 739 740 741 742 743 744 745 746 747

        if( old_url.startsWith( QString::fromUtf8( psz_cachedir ) ) )
            QFile( old_url ).remove(); /* Purge cached artwork */

        free( psz_cachedir );

        input_item_SetArtURL( p_item , fileUrl.toUtf8().constData() );
        UpdateArt();
    }
}

748 749 750 751 752
inline void InputManager::UpdateStats()
{
    emit statisticsUpdated( input_GetItem( p_input ) );
}

753
inline void InputManager::UpdateMeta( input_item_t *p_item_ )
754
{
755
    emit metaChanged( p_item_ );
756
    emit artChanged( p_item_ );
757 758
}

759 760
inline void InputManager::UpdateMeta()
{
761
    emit currentMetaChanged( input_GetItem( p_input ) );
762 763 764 765
}

inline void InputManager::UpdateInfo()
{
766
    assert( p_input );
767 768 769
    emit infoChanged( input_GetItem( p_input ) );
}

770 771
void InputManager::UpdateRecord()
{
772
    emit recordingStateChanged( var_GetBool( p_input, "record" ) );
773 774
}

775 776
void InputManager::UpdateProgramEvent()
{
777 778
    bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
    emit encryptionChanged( b_scrambled );
779 780
}

781
/* User update of the slider */
Clément Stenac's avatar
Clément Stenac committed
782 783
void InputManager::sliderUpdate( float new_pos )
{
784 785
    if( hasInput() )
        var_SetFloat( p_input, "position", new_pos );
Jakob Leben's avatar