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

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

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

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

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

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

116 117
        char *uri = input_item_GetURI( p_item );

118
        /* Get Saved Time */
119
        if( p_item->i_type == ITEM_TYPE_FILE )
120
        {
121
            int i_time = RecentsMRL::getInstance( p_intf )->time( qfu(uri) );
122
            if( i_time > 0 && qfu( uri ) != lastURI &&
123 124 125 126
                    !var_GetFloat( p_input, "run-time" ) &&
                    !var_GetFloat( p_input, "start-time" ) &&
                    !var_GetFloat( p_input, "stop-time" ) )
            {
127
                emit resumePlayback( (int64_t)i_time * 1000 );
128
            }
129
        }
130 131 132 133

        // Save the latest URI to avoid asking to restore the
        // position on the same input file.
        lastURI = qfu( uri );
134
        RecentsMRL::getInstance( p_intf )->addRecent( lastURI );
135
        free( uri );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
136 137 138
    }
    else
    {
139
        p_item = NULL;
140
        assert( !p_input_vbi );
141
        emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
142 143
    }
}
144

145 146 147
/* delete Input if it ever existed.
   Delete the callbacls on input
   p_input is released once here */
148 149
void InputManager::delInput()
{
150
    if( !p_input ) return;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
151
    msg_Dbg( p_intf, "IM: Deleting the input" );
152

153
    /* Save time / position */
154 155 156 157 158 159
    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
160 161
         && var_GetInteger( p_input, "length" ) >= 60 * CLOCK_FREQ )
            i_time = var_GetInteger( p_input, "time");
162 163 164

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

167 168
    delCallbacks();
    i_old_playing_status = END_S;
169
    p_item               = NULL;
170 171 172 173 174
    oldName              = "";
    artUrl               = "";
    b_video              = false;
    timeA                = 0;
    timeB                = 0;
175
    f_rate               = 0. ;
176

177 178 179 180 181 182
    if( p_input_vbi )
    {
        vlc_object_release( p_input_vbi );
        p_input_vbi = NULL;
    }

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
183 184 185
    vlc_object_release( p_input );
    p_input = NULL;

186
    emit positionUpdated( -1.0, 0 ,0 );
187
    emit rateChanged( var_InheritFloat( p_intf, "rate" ) );
188 189 190
    emit nameChanged( "" );
    emit chapterChanged( 0 );
    emit titleChanged( 0 );
191
    emit playingStatusChanged( END_S );
192 193

    emit teletextPossible( false );
194
    emit AtoBchanged( false, false );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
195
    emit voutChanged( false );
196
    emit voutListChanged( NULL, 0 );
197

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
198 199
    /* Reset all InfoPanels but stats */
    emit artChanged( NULL );
200
    emit artChanged( "" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
201
    emit infoChanged( NULL );
202
    emit currentMetaChanged( (input_item_t *)NULL );
203

204
    emit encryptionChanged( false );
205
    emit recordingStateChanged( false );
206

207
    emit cachingChanged( 0.0 );
208 209
}

210
/* Convert the event from the callbacks in actions */
211 212
void InputManager::customEvent( QEvent *event )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
213
    int i_type = event->type();
214
    IMEvent *ple = static_cast<IMEvent *>(event);
215

216
    if( i_type == IMEvent::ItemChanged )
217
        UpdateMeta( ple->item() );
218

219
    if( !hasInput() )
220
        return;
221

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

300 301 302 303 304 305 306 307 308 309 310 311 312
/* 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 */
313
int MainInputManager::ItemChanged( vlc_object_t *p_this, const char *psz_var,
314 315
                        vlc_value_t oldval, vlc_value_t newval, void *param )
{
316 317
    VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );

318
    InputManager *im = (InputManager*)param;
319
    input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
320

321
    IMEvent *event = new IMEvent( IMEvent::ItemChanged, p_item );
322
    QApplication::postEvent( im, event );
323 324 325 326 327 328
    return VLC_SUCCESS;
}

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

331 332 333 334 335 336
    InputManager *im = (InputManager*)param;
    IMEvent *event;

    switch( newval.i_int )
    {
    case INPUT_EVENT_STATE:
337
        event = new IMEvent( IMEvent::ItemStateChanged );
338 339
        break;
    case INPUT_EVENT_RATE:
340
        event = new IMEvent( IMEvent::ItemRateChanged );
341
        break;
342 343
    case INPUT_EVENT_POSITION:
    //case INPUT_EVENT_LENGTH:
344
        event = new IMEvent( IMEvent::PositionUpdate );
345 346 347 348
        break;

    case INPUT_EVENT_TITLE:
    case INPUT_EVENT_CHAPTER:
349
        event = new IMEvent( IMEvent::ItemTitleChanged );
350 351 352
        break;

    case INPUT_EVENT_ES:
353
        event = new IMEvent( IMEvent::ItemEsChanged );
354 355
        break;
    case INPUT_EVENT_TELETEXT:
356
        event = new IMEvent( IMEvent::ItemTeletextChanged );
357 358
        break;

359
    case INPUT_EVENT_STATISTICS:
360
        event = new IMEvent( IMEvent::StatisticsUpdate );
361 362
        break;

363
    case INPUT_EVENT_VOUT:
364
        event = new IMEvent( IMEvent::InterfaceVoutUpdate );
365
        break;
366
    case INPUT_EVENT_AOUT:
367
        event = new IMEvent( IMEvent::InterfaceAoutUpdate );
368 369 370
        break;

    case INPUT_EVENT_ITEM_META: /* Codec MetaData + Art */
371
        event = new IMEvent( IMEvent::MetaChanged );
372 373
        break;
    case INPUT_EVENT_ITEM_INFO: /* Codec Info */
374
        event = new IMEvent( IMEvent::InfoChanged );
375 376
        break;
    case INPUT_EVENT_ITEM_NAME:
377
        event = new IMEvent( IMEvent::NameChanged );
378 379 380 381
        break;

    case INPUT_EVENT_AUDIO_DELAY:
    case INPUT_EVENT_SUBTITLE_DELAY:
382
        event = new IMEvent( IMEvent::SynchroChanged );
383 384 385
        break;

    case INPUT_EVENT_CACHE:
386
        event = new IMEvent( IMEvent::CachingEvent );
387 388 389
        break;

    case INPUT_EVENT_BOOKMARK:
390
        event = new IMEvent( IMEvent::BookmarksChanged );
391 392 393
        break;

    case INPUT_EVENT_RECORD:
394
        event = new IMEvent( IMEvent::RecordingEvent );
395
        break;
396 397 398

    case INPUT_EVENT_PROGRAM:
        /* This is for PID changes */
399
        event = new IMEvent( IMEvent::ProgramChanged );
400 401
        break;

402 403
    case INPUT_EVENT_ITEM_EPG:
        /* EPG data changed */
404
        event = new IMEvent( IMEvent::EPGEvent );
405 406
        break;

407 408
    case INPUT_EVENT_SIGNAL:
        /* This is for capture-card signals */
409
        /* event = new IMEvent( SignalChanged_Type );
410 411 412 413 414 415 416
        break; */
    default:
        event = NULL;
        break;
    }

    if( event )
417
        QApplication::postEvent( im, event );
418 419
    return VLC_SUCCESS;
}
420

Laurent Aimar's avatar
Laurent Aimar committed
421 422 423 424
static int VbiEvent( vlc_object_t *, const char *,
                     vlc_value_t, vlc_value_t, void *param )
{
    InputManager *im = (InputManager*)param;
425
    IMEvent *event = new IMEvent( IMEvent::ItemTeletextChanged );
Laurent Aimar's avatar
Laurent Aimar committed
426

427
    QApplication::postEvent( im, event );
Laurent Aimar's avatar
Laurent Aimar committed
428 429 430
    return VLC_SUCCESS;
}

431
void InputManager::UpdatePosition()
432
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
433
    /* Update position */
434 435 436 437
    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 );
438 439
}

440
void InputManager::UpdateNavigation()
441
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
442 443
    /* Update navigation status */
    vlc_value_t val; val.i_int = 0;
444
    vlc_value_t val2; val2.i_int = 0;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
445

446 447
    if( hasInput() )
        var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
448

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
449 450
    if( val.i_int > 0 )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
451
        /* p_input != NULL since val.i_int != 0 */
452
        var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val2, NULL );
453 454 455

        emit titleChanged( val.i_int > 1 );
        emit chapterChanged( val2.i_int > 1 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
456 457
    }
    else
458
        emit chapterChanged( false );
459 460 461 462 463

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

466
void InputManager::UpdateStatus()
467
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
468
    /* Update playing status */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
469 470
    int state = var_GetInteger( p_input, "state" );
    if( i_old_playing_status != state )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
471
    {
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
472
        i_old_playing_status = state;
473
        emit playingStatusChanged( state );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
474
    }
475 476
}

477
void InputManager::UpdateRate()
478
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
479
    /* Update Rate */
480 481
    float f_new_rate = var_GetFloat( p_input, "rate" );
    if( f_new_rate != f_rate )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
482
    {
483
        f_rate = f_new_rate;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
484
        /* Update rate */
485
        emit rateChanged( f_rate );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
486
    }
487 488
}

489
void InputManager::UpdateName()
490
{
491 492
    assert( p_input );

493
    /* Update text, name and nowplaying */
494
    QString name;
495

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

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

525 526 527
    name = name.trimmed();

    if( oldName != name )
528
    {
529 530
        emit nameChanged( name );
        oldName = name;
531
    }
532
}
533

534 535 536 537 538
int InputManager::playingStatus()
{
    return i_old_playing_status;
}

539
bool InputManager::hasAudio()
540
{
541 542 543 544 545 546 547 548 549
    if( hasInput() )
    {
        vlc_value_t val;
        var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
        return val.i_int > 0;
    }
    return false;
}

550 551 552 553 554
bool InputManager::hasVisualisation()
{
    if( !p_input )
        return false;

555
    audio_output_t *aout = input_GetAout( p_input );
556 557 558 559
    if( !aout )
        return false;

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

562 563 564 565 566 567 568
    if( !visual )
        return false;

    free( visual );
    return true;
}

569
void InputManager::UpdateTeletext()
570 571
{
    if( hasInput() )
Laurent Aimar's avatar
Laurent Aimar committed
572 573 574 575 576 577 578 579 580 581 582 583
    {
        const bool b_enabled = var_CountChoices( p_input, "teletext-es" ) > 0;
        const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );

        /* Teletext is possible. Show the buttons */
        emit teletextPossible( b_enabled );

        /* If Teletext is selected */
        if( b_enabled && i_teletext_es >= 0 )
        {
            /* Then, find the current page */
            int i_page = 100;
Laurent Aimar's avatar
Laurent Aimar committed
584
            bool b_transparent = false;
Laurent Aimar's avatar
Laurent Aimar committed
585

586 587 588 589 590
            if( p_input_vbi )
            {
                var_DelCallback( p_input_vbi, "vbi-page", VbiEvent, this );
                vlc_object_release( p_input_vbi );
            }
591 592 593

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

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

601 602
                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
603
            }
Laurent Aimar's avatar
Laurent Aimar committed
604
            emit newTelexPageSet( i_page );
Laurent Aimar's avatar
Laurent Aimar committed
605 606
            emit teletextTransparencyActivated( b_transparent );

Laurent Aimar's avatar
Laurent Aimar committed
607 608 609
        }
        emit teletextActivated( b_enabled && i_teletext_es >= 0 );
    }
610
    else
Laurent Aimar's avatar
Laurent Aimar committed
611 612 613 614
    {
        emit teletextActivated( false );
        emit teletextPossible( false );
    }
615 616
}

617 618 619 620 621 622 623 624
void InputManager::UpdateEPG()
{
    if( hasInput() )
    {
       emit epgChanged();
    }
}

625 626 627 628
void InputManager::UpdateVout()
{
    if( hasInput() )
    {
629
        /* Get current vout lists from input */
630
        size_t i_vout;
631 632 633 634 635 636 637 638 639 640 641
        vout_thread_t **pp_vout;
        if( input_Control( p_input, INPUT_GET_VOUTS, &pp_vout, &i_vout ) )
        {
            i_vout = 0;
            pp_vout = NULL;
        }

        /* */
        emit voutListChanged( pp_vout, i_vout );

        /* */
642
        bool b_old_video = b_video;
643
        b_video = i_vout > 0;
644 645
        if( !!b_old_video != !!b_video )
            emit voutChanged( b_video );
646 647

        /* Release the vout list */
648
        for( size_t i = 0; i < i_vout; i++ )
649 650 651 652 653 654 655 656 657
            vlc_object_release( (vlc_object_t*)pp_vout[i] );
        free( pp_vout );
    }
}
void InputManager::UpdateAout()
{
    if( hasInput() )
    {
        /* TODO */
658 659
    }
}
660 661
void InputManager::UpdateCaching()
{
662 663 664
    if(!hasInput()) return;

    float f_newCache = var_GetFloat ( p_input, "cache" );
665 666
    if( f_newCache != f_cache )
    {
667
        f_cache = f_newCache;
668
        /* Update cache */
669 670 671 672
        emit cachingChanged( f_cache );
    }
}

673
void InputManager::requestArtUpdate( input_item_t *p_item, bool b_forced )
674
{
675 676 677 678 679
    bool b_current_item = false;
    if ( !p_item && hasInput() )
    {   /* default to current item */
        p_item = input_GetItem( p_input );
        b_current_item = true;
680
    }
681 682

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

703
const QString InputManager::decodeArtURL( input_item_t *p_item )
704
{
705
    assert( p_item );
706

707
    char *psz_art = input_item_GetArtURL( p_item );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
708 709
    if( psz_art )
    {
710
        char *psz = vlc_uri2path( psz_art );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
711 712 713
        free( psz_art );
        psz_art = psz;
    }
714

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
715
#if 0
716 717
    /* 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
718
#endif
719 720 721 722

    QString path = qfu( psz_art ? psz_art : "" );
    free( psz_art );
    return path;
723 724 725 726 727 728 729 730
}

void InputManager::UpdateArt()
{
    QString url;

    if( hasInput() )
        url = decodeArtURL( input_GetItem( p_input ) );
731

732 733 734 735
    /* the art hasn't changed, no need to update */
    if(artUrl == url)
        return;

736
    /* Update Art meta */
737 738
    artUrl = url;
    emit artChanged( artUrl );
739 740
}

Angelo Haller's avatar
Angelo Haller committed
741 742 743 744 745 746
void InputManager::setArt( input_item_t *p_item, QString fileUrl )
{
    if( hasInput() )
    {
        char *psz_cachedir = config_GetUserDir( VLC_CACHE_DIR );
        QString old_url = THEMIM->getIM()->decodeArtURL( p_item );
747
        old_url = QDir( old_url ).canonicalPath();
Angelo Haller's avatar
Angelo Haller committed
748 749 750 751 752 753 754 755 756 757 758

        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();
    }
}

759 760
inline void InputManager::UpdateStats()
{
761
    assert( p_input );
762 763 764
    emit statisticsUpdated( input_GetItem( p_input ) );
}

765
inline void InputManager::UpdateMeta( input_item_t *p_item_ )
766
{
767
    emit metaChanged( p_item_ );
768
    emit artChanged( p_item_ );
769 770
}

771 772
inline void InputManager::UpdateMeta()
{
773
    assert( p_input );
774
    emit currentMetaChanged( input_GetItem( p_input ) );
775 776 777 778
}

inline void InputManager::UpdateInfo()
{
779
    assert( p_input );
780 781 782
    emit infoChanged( input_GetItem( p_input ) );
}

783 784 785 786 787 788 789 790
void InputManager::UpdateRecord()
{
    if( hasInput() )
    {
        emit recordingStateChanged( var_GetBool( p_input, "record" ) );
    }
}

791 792 793 794 795 796 797 798 799
void InputManager::UpdateProgramEvent()
{
    if( hasInput() )
    {
        bool b_scrambled = var_GetBool( p_input, "program-scrambled" );
        emit encryptionChanged( b_scrambled );
    }
}

800
/* User update of the slider */
Clément Stenac's avatar
Clément Stenac committed
801 802
void InputManager::sliderUpdate( float new_pos )
{
803 804
    if( hasInput() )
        var_SetFloat( p_input, "position", new_pos );
805
    emit seekRequested( new_pos );
Clément Stenac's avatar
Clément Stenac committed
806
}
807

808 809 810 811
void InputManager::sectionPrev()
{
    if( hasInput() )
    {
812
        int i_type = var_Type( p_input, "next-chapter" );
813 814
        var_TriggerCallback( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
                             "prev-chapter":"prev-title" );
815 816 817 818 819