input_manager.cpp 22.5 KB
Newer Older
zorglub's avatar
zorglub committed
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$
zorglub's avatar
zorglub committed
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Ilkka Ollakka  <ileoo@videolan.org>
9
 *          Jean-Baptiste <jb@videolan.org>
zorglub's avatar
zorglub committed
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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
zorglub's avatar
zorglub committed
28

zorglub's avatar
zorglub committed
29
#include "qt4.hpp"
zorglub's avatar
zorglub committed
30 31 32
#include "input_manager.hpp"
#include "dialogs_provider.hpp"

33 34
static int ChangeSPU( vlc_object_t *p_this, const char *var, vlc_value_t o,
                      vlc_value_t n, void *param );
35 36 37 38

static int ChangeTeletext( vlc_object_t *p_this, const char *var, vlc_value_t o,
                           vlc_value_t n, void *param );

39 40
static int ItemChanged( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
41
static int PLItemChanged( vlc_object_t *, const char *,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
42
                        vlc_value_t, vlc_value_t, void * );
43 44 45 46 47 48 49 50
static int InterfaceChanged( vlc_object_t *, const char *,
                            vlc_value_t, vlc_value_t, void * );
static int ItemStateChanged( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
static int ItemRateChanged( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
static int ItemTitleChanged( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
51 52
static int VolumeChanged( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
53

54 55
/**********************************************************************
 * InputManager implementation
56 57 58
 **********************************************************************
 * The Input Manager can be the main one around the playlist
 * But can also be used for VLM dialog or similar
59 60
 **********************************************************************/

zorglub's avatar
zorglub committed
61 62 63
InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
                           QObject( parent ), p_intf( _p_intf )
{
64
    i_old_playing_status = END_S;
65 66 67 68 69
    old_name     = "";
    artUrl       = "";
    p_input      = NULL;
    i_rate       = 0;
    i_input_id   = 0;
70
    b_transparentTelextext = false;
zorglub's avatar
zorglub committed
71 72 73 74
}

InputManager::~InputManager()
{
75
    delInput();
zorglub's avatar
zorglub committed
76 77
}

78 79 80
/* Define the Input used.
   Add the callbacks on input
   p_input is yield once here */
zorglub's avatar
zorglub committed
81 82
void InputManager::setInput( input_thread_t *_p_input )
{
83
    delInput();
zorglub's avatar
zorglub committed
84
    p_input = _p_input;
85
    if( p_input && !( p_input->b_dead || !vlc_object_alive (p_input) ) )
86
    {
87
        vlc_object_yield( p_input );
88
        emit statusChanged( PLAYING_S );
89 90
        UpdateMeta();
        UpdateArt();
91
        UpdateSPU();
92
        UpdateTeletext();
93
        UpdateNavigation();
94
        addCallbacks();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
95 96 97 98
        i_input_id = input_GetItem( p_input )->i_id;
    }
    else
    {
99 100
        p_input = NULL;
        i_input_id = 0;
101
        emit rateChanged( INPUT_RATE_DEFAULT );
102 103
    }
}
104

105 106 107
/* delete Input if it ever existed.
   Delete the callbacls on input
   p_input is released once here */
108 109 110 111
void InputManager::delInput()
{
    if( p_input )
    {
112
        delCallbacks();
113
        i_old_playing_status = END_S;
114
        i_input_id = 0;
115 116
        old_name   = "";
        artUrl     = "";
117
        emit positionUpdated( -1.0, 0 ,0 );
118 119
        emit statusChanged( END_S );
        emit nameChanged( "" );
120
        emit artChanged( NULL );
121
        emit rateChanged( INPUT_RATE_DEFAULT );
Rafaël Carré's avatar
Rafaël Carré committed
122 123
        vlc_object_release( p_input );
        p_input = NULL;
124
        UpdateSPU();
125
        UpdateTeletext();
126
    }
zorglub's avatar
zorglub committed
127 128
}

129
/* Add the callbacks on Input. Self explanatory */
130
void InputManager::addCallbacks()
131
{
132 133 134 135 136 137 138 139
    /* We don't care about:
       - chapter
       - programs
       - audio-delay
       - spu-delay
       - bookmark
       - position, time, length, because they are included in intf-change
     */
140 141
    /* src/input/input.c:1629 */
    var_AddCallback( p_input, "state", ItemStateChanged, this );
142 143
    /* src/input/es-out.c:552 */
    var_AddCallback( p_input, "spu-es", ChangeSPU, this );
144 145 146
    /* emit UpdateStatus so that main_interface updates controls 
     * if there is new videotracks (mpeg-ts)*/
    var_AddCallback( p_input, "video-es", ItemStateChanged, this );
147 148
    /* src/input/es-out.c: */
    var_AddCallback( p_input, "teletext-es", ChangeTeletext, this );
149
    /* src/input/input.c:1765 */
150
    var_AddCallback( p_input, "rate-change", ItemRateChanged, this );
151 152 153 154 155 156
    /* src/input/input.c:2003 */
    var_AddCallback( p_input, "title", ItemTitleChanged, this );
    /* src/input/input.c:734 for timers update*/
    var_AddCallback( p_input, "intf-change", InterfaceChanged, this );
}

157
/* Delete the callbacks on Input. Self explanatory */
158
void InputManager::delCallbacks()
159
{
160
    var_DelCallback( p_input, "spu-es", ChangeSPU, this );
161
    var_DelCallback( p_input, "video-es", ItemStateChanged, this );
162
    var_DelCallback( p_input, "teletext-es", ChangeTeletext, this );
163
    var_DelCallback( p_input, "state", ItemStateChanged, this );
164
    var_DelCallback( p_input, "rate-change", ItemRateChanged, this );
165 166
    var_DelCallback( p_input, "title", ItemTitleChanged, this );
    var_DelCallback( p_input, "intf-change", InterfaceChanged, this );
167 168
}

169
/* Convert the event from the callbacks in actions */
170 171 172
void InputManager::customEvent( QEvent *event )
{
    int type = event->type();
173
    IMEvent *ple = static_cast<IMEvent *>(event);
174

175 176 177 178
    if ( type != PositionUpdate_Type &&
         type != ItemChanged_Type &&
         type != ItemRateChanged_Type &&
         type != ItemTitleChanged_Type &&
179
         type != ItemSpuChanged_Type &&
180
         type != ItemTeletextChanged_Type &&
181 182
         type != ItemStateChanged_Type )
        return;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
183

184 185 186
    if( type == ItemStateChanged_Type )
    {
        UpdateNavigation();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
187
        UpdateTeletext();
188 189
    }

190 191
    if( !hasInput() ) return;

192 193
    if( ( type != PositionUpdate_Type  &&
          type != ItemRateChanged_Type &&
194
          type != ItemSpuChanged_Type &&
195
          type != ItemTeletextChanged_Type &&
196 197 198
          type != ItemStateChanged_Type
        )
        && ( i_input_id != ple->i_id ) )
199
        return;
200

201 202 203
    if( type != PositionUpdate_Type )
        msg_Dbg( p_intf, "New Event: type %i", type );

204
    /* Actions */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
205
    switch( type )
206
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
207
    case PositionUpdate_Type:
208
        UpdatePosition();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
209 210
        break;
    case ItemChanged_Type:
211
        UpdateMeta();
212
        UpdateStatus();
213
        UpdateArt();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
214
        break;
215 216 217 218
    case ItemStateChanged_Type:
        UpdateStatus();
        UpdateNavigation();
        UpdateMeta();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
219 220
        break;
    case ItemTitleChanged_Type:
221
        UpdateNavigation();
222
        UpdateMeta();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
223
        break;
224 225 226
    case ItemRateChanged_Type:
        UpdateRate();
        break;
227 228
    case ItemSpuChanged_Type:
        UpdateSPU();
229
        break;
230 231 232
    case ItemTeletextChanged_Type:
        UpdateTeletext();
        break;
233
    }
234
}
235

236
void InputManager::UpdatePosition()
237
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
238 239 240 241 242 243 244
    /* Update position */
    int i_length, i_time; /* Int is enough, since we store seconds */
    float f_pos;
    i_length = var_GetTime(  p_input , "length" ) / 1000000;
    i_time = var_GetTime(  p_input , "time") / 1000000;
    f_pos = var_GetFloat(  p_input , "position" );
    emit positionUpdated( f_pos, i_time, i_length );
245 246
}

247
void InputManager::UpdateNavigation()
248
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
249 250
    /* Update navigation status */
    vlc_value_t val; val.i_int = 0;
251 252
    if( hasInput() )
        var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
253 254 255 256 257 258 259 260 261 262
    if( val.i_int > 0 )
    {
        val.i_int = 0;
        var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
        emit navigationChanged( (val.i_int > 0) ? 1 : 2 );
    }
    else
    {
        emit navigationChanged( 0 );
    }
263 264
}

265
void InputManager::UpdateStatus()
266
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
267 268 269 270 271 272 273 274
    /* Update playing status */
    vlc_value_t val; val.i_int = 0;
    var_Get( p_input, "state", &val );
    if( i_old_playing_status != val.i_int )
    {
        i_old_playing_status = val.i_int;
        emit statusChanged( val.i_int );
    }
275 276
}

277
void InputManager::UpdateRate()
278
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
279 280 281 282 283 284 285 286
    /* Update Rate */
    int i_new_rate = var_GetInteger( p_input, "rate");
    if( i_new_rate != i_rate )
    {
        i_rate = i_new_rate;
        /* Update rate */
        emit rateChanged( i_rate );
    }
287 288
}

289
void InputManager::UpdateMeta()
290
{
291 292
    /* Update text, name and nowplaying */
    QString text;
293

294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
    char *psz_name = input_item_GetTitle( input_GetItem( p_input ) );
    if( EMPTY_STR( psz_name ) )
    {
        free( psz_name );
        psz_name = input_item_GetName( input_GetItem( p_input ) );
    }

    char *psz_nowplaying =
        input_item_GetNowPlaying( input_GetItem( p_input ) );
    if( !EMPTY_STR( psz_nowplaying ) )
    {
        text.sprintf( "%s - %s", psz_nowplaying, psz_name );
    }
    else
    {
        char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
        if( !EMPTY_STR( psz_artist ) )
        {
            text.sprintf( "%s - %s", psz_artist, psz_name );
        }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
314 315 316
        else
        {
            text.sprintf( "%s", psz_name );
317 318
        }
        free( psz_artist );
319 320 321 322 323 324 325 326 327
    }
    free( psz_name );
    free( psz_nowplaying );

    if( old_name != text )
    {
        emit nameChanged( text );
        old_name=text;
    }
328
}
329

330
bool InputManager::hasAudio()
331
{
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
    if( hasInput() )
    {
        vlc_value_t val;
        var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
        return val.i_int > 0;
    }
    return false;
}

bool InputManager::hasVideo()
{
    if( hasInput() )
    {
        vlc_value_t val;
        var_Change( p_input, "video-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
        return val.i_int > 0;
    }
    return false;
350

351 352 353
}

void InputManager::UpdateSPU()
354 355 356 357 358
{
    UpdateTeletext();
}

void InputManager::UpdateTeletext()
359 360
{
    if( hasInput() )
361
        telexToggle( var_GetInteger( p_input, "teletext-es" ) >= 0 );
362 363
    else
        telexToggle( false );
364 365
}

Jean-Baptiste Kempf's avatar
 
Jean-Baptiste Kempf committed
366
void InputManager::UpdateArt()
367 368
{
    /* Update Art meta */
369
    emit artChanged( input_GetItem( p_input ) );
370 371
}

372
/* User update of the slider */
zorglub's avatar
zorglub committed
373 374
void InputManager::sliderUpdate( float new_pos )
{
375 376
    if( hasInput() )
        var_SetFloat( p_input, "position", new_pos );
zorglub's avatar
zorglub committed
377
}
378

379
/* User togglePlayPause */
380 381 382 383
void InputManager::togglePlayPause()
{
    vlc_value_t state;
    var_Get( p_input, "state", &state );
384
    state.i_int = ( state.i_int != PLAYING_S ) ? PLAYING_S : PAUSE_S;
385 386 387 388
    var_Set( p_input, "state", state );
    emit statusChanged( state.i_int );
}

389 390 391 392
void InputManager::sectionPrev()
{
    if( hasInput() )
    {
393
        int i_type = var_Type( p_input, "next-chapter" );
394
        vlc_value_t val; val.b_bool = true;
395 396 397 398 399 400 401 402 403
        var_Set( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
                            "prev-chapter":"prev-title", val );
    }
}

void InputManager::sectionNext()
{
    if( hasInput() )
    {
404
        int i_type = var_Type( p_input, "next-chapter" );
405
        vlc_value_t val; val.b_bool = true;
406 407 408 409 410 411 412 413
        var_Set( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
                            "next-chapter":"next-title", val );
    }
}

void InputManager::sectionMenu()
{
    if( hasInput() )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
414
    {
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
        vlc_value_t val, text;
        vlc_value_t root;

        if( var_Change( p_input, "title  0", VLC_VAR_GETLIST, &val, &text ) < 0 )
            return;

        /* XXX is it "Root" or "Title" we want here ?" (set 0 by default) */
        root.i_int = 0;
        for( int i = 0; i < val.p_list->i_count; i++ )
        {
            if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
                root.i_int = i;
        }
        var_Change( p_input, "title  0", VLC_VAR_FREELIST, &val, &text );

        var_Set( p_input, "title  0", root );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
431
    }
432 433
}

434 435
void InputManager::telexGotoPage( int page )
{
436
    if( hasInput() )
437
    {
438 439 440 441
        const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
        const int i_spu_es = var_GetInteger( p_input, "spu-es" );

        if( i_teletext_es >= 0 && i_teletext_es == i_spu_es )
442
        {
443 444 445 446 447 448 449 450
            vlc_object_t *p_vbi;
            p_vbi = (vlc_object_t *) vlc_object_find_name( p_input,
                        "zvbi", FIND_ANYWHERE );
            if( p_vbi )
            {
                var_SetInteger( p_vbi, "vbi-page", page );
                vlc_object_release( p_vbi );
            }
451 452
        }
    }
lukas.durfina's avatar
lukas.durfina committed
453
    emit setNewTelexPage( page );
454 455 456 457
}

void InputManager::telexToggle( bool b_enabled )
{
458 459
    if( hasInput() )
    {
460 461 462
        const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
        const int i_spu_es = var_GetInteger( p_input, "spu-es" );

463 464 465
        b_enabled = (i_teletext_es >= 0);
        emit teletextEnabled( b_enabled );
        if( b_enabled && (i_teletext_es == i_spu_es) )
466
        {
467
            vlc_object_t *p_vbi;
468
            int i_page = 100;
469 470 471 472 473 474 475 476 477
            p_vbi = (vlc_object_t *) vlc_object_find_name( p_input,
                        "zvbi", FIND_ANYWHERE );
            if( p_vbi )
            {
                i_page = var_GetInteger( p_vbi, "vbi-page" );
                vlc_object_release( p_vbi );
                i_page = b_enabled ? i_page : 0;
                telexGotoPage( i_page );
            }
478 479
        }
    }
480
    else emit teletextEnabled( b_enabled );
lukas.durfina's avatar
lukas.durfina committed
481 482 483 484
}

void InputManager::telexToggleButtons()
{
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
    if( hasInput() )
    {
        const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
        if( i_teletext_es >= 0 )
        {
            const int i_spu_es = var_GetInteger( p_input, "spu-es" );

            if( i_teletext_es == i_spu_es )
                var_SetInteger( p_input, "spu-es", -1 );
            else
                var_SetInteger( p_input, "spu-es", i_teletext_es );

            emit toggleTelexButtons();
        }
    }
500 501
}

502
void InputManager::telexSetTransparency()
503
{
504
    if( hasInput() )
505 506 507 508 509 510
    {
        vlc_object_t *p_vbi;
        p_vbi = (vlc_object_t *) vlc_object_find_name( p_input,
                    "zvbi", FIND_ANYWHERE );
        if( p_vbi )
        {
511 512
            var_SetBool( p_vbi, "vbi-opaque", b_transparentTelextext );
            b_transparentTelextext = !b_transparentTelextext;
513 514 515
            vlc_object_release( p_vbi );
        }
    }
lukas.durfina's avatar
lukas.durfina committed
516
    emit toggleTelexTransparency();
517 518
}

zorglub's avatar
zorglub committed
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
void InputManager::slower()
{
    if( hasInput() )
        var_SetVoid( p_input, "rate-slower" );
}

void InputManager::faster()
{
    if( hasInput() )
        var_SetVoid( p_input, "rate-faster" );
}

void InputManager::normalRate()
{
    if( hasInput() )
        var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
}

537 538 539 540 541 542
void InputManager::setRate( int new_rate )
{
    if( hasInput() )
        var_SetInteger( p_input, "rate", new_rate );
}

543 544
/**********************************************************************
 * MainInputManager implementation. Wrap an input manager and
545 546
 * take care of updating the main playlist input.
 * Used in the main playlist Dialog
547 548 549
 **********************************************************************/
MainInputManager * MainInputManager::instance = NULL;

550 551
MainInputManager::MainInputManager( intf_thread_t *_p_intf )
                 : QObject(NULL), p_intf( _p_intf )
552 553 554
{
    p_input = NULL;
    im = new InputManager( this, p_intf );
555

556
//    var_AddCallback( THEPL, "item-change", PLItemChanged, this );
557
    var_AddCallback( THEPL, "item-change", ItemChanged, im );
558 559
    var_AddCallback( THEPL, "playlist-current", PLItemChanged, this );
    var_AddCallback( THEPL, "activity", PLItemChanged, this );
560

561
    var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
562

563
    /* Warn our embedded IM about input changes */
zorglub's avatar
zorglub committed
564
    CONNECT( this, inputChanged( input_thread_t * ),
565
             im, setInput( input_thread_t * ) );
566 567 568 569 570 571 572

    /* emit check if playlist has allready started playing */
    vlc_value_t val;
    var_Change( THEPL, "playlist-current", VLC_VAR_CHOICESCOUNT, &val, NULL );
    IMEvent *event = new IMEvent( ItemChanged_Type, val.i_int);
    QApplication::postEvent( this, static_cast<QEvent*>(event) );

573 574
}

zorglub's avatar
zorglub committed
575 576
MainInputManager::~MainInputManager()
{
577 578
    if( p_input )
    {
579 580
       var_DelCallback( p_input, "state", PLItemChanged, this );
       vlc_object_release( p_input );
581 582
       emit inputChanged( NULL );
    }
583

584
    var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
585 586

    var_DelCallback( THEPL, "activity", PLItemChanged, this );
587
    var_DelCallback( THEPL, "item-change", ItemChanged, im );
588
//    var_DelCallback( THEPL, "item-change", PLItemChanged, this );
589

590
    var_DelCallback( THEPL, "playlist-current", PLItemChanged, this );
zorglub's avatar
zorglub committed
591 592
}

593
void MainInputManager::customEvent( QEvent *event )
594
{
595
    int type = event->type();
596 597 598
    if ( type != ItemChanged_Type && type != VolumeChanged_Type )
        return;

599
    // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
600 601 602
    if( type == VolumeChanged_Type )
    {
        emit volumeChanged();
603
        return;
604
    }
605

606
    /* Should be PLItemChanged Event */
607
    if( VLC_OBJECT_INTF == p_intf->i_object_type ) /* FIXME: don't use object type */
608
    {
609
        vlc_mutex_lock( &p_intf->change_lock );
610
        if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) )
611
        {
612 613
            var_DelCallback( p_input, "state", PLItemChanged, this );
            vlc_object_release( p_input );
614
            emit inputChanged( NULL );
615
            p_input = NULL;
616 617
            vlc_mutex_unlock( &p_intf->change_lock );
            return;
618
        }
619

620 621 622 623
        if( !p_input )
        {
            QPL_LOCK;
            p_input = THEPL->p_input;
624
            if( p_input && !( !vlc_object_alive (p_input) || p_input->b_dead) )
625
            {
626 627
                vlc_object_yield( p_input );
                var_AddCallback( p_input, "state", PLItemChanged, this );
628 629
                emit inputChanged( p_input );
            }
630 631
            else
                p_input = NULL;
632 633 634 635
            QPL_UNLOCK;
        }
        vlc_mutex_unlock( &p_intf->change_lock );
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
636 637
    else
    {
638
        /* we are working as a dialogs provider */
639
        playlist_t *p_playlist = pl_Yield( p_intf );
640
        p_input = playlist_CurrentInput( p_playlist );
641 642 643 644 645
        if( p_input )
        {
            emit inputChanged( p_input );
            vlc_object_release( p_input );
        }
646
        pl_Release( p_intf );
647 648
    }
}
649

650
/* Playlist Control functions */
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
void MainInputManager::stop()
{
   playlist_Stop( THEPL );
}

void MainInputManager::next()
{
   playlist_Next( THEPL );
}

void MainInputManager::prev()
{
   playlist_Prev( THEPL );
}

666 667 668 669 670 671 672 673 674
void MainInputManager::togglePlayPause()
{
    if( p_input == NULL )
    {
        playlist_Play( THEPL );
        return;
    }
    getIM()->togglePlayPause();
}
675

676 677 678 679 680
bool MainInputManager::teletextState()
{
    im = getIM();
    if( im->hasInput() )
    {
681 682 683 684
        const int i_teletext_es = var_GetInteger( getInput(), "teletext-es" );
        const int i_spu_es = var_GetInteger( getInput(), "spu-es" );

        return i_teletext_es >= 0 && i_teletext_es == i_spu_es;
685 686 687 688
    }
    return false;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
689 690 691
/* Static callbacks */

/* IM */
692 693 694 695 696 697
static int InterfaceChanged( vlc_object_t *p_this, const char *psz_var,
                           vlc_value_t oldval, vlc_value_t newval, void *param )
{
    static int counter = 0;
    InputManager *im = (InputManager*)param;

698
    counter = ++counter % 4;
699 700 701 702 703 704 705 706
    if(!counter)
        return VLC_SUCCESS;
    IMEvent *event = new IMEvent( PositionUpdate_Type, 0 );
    QApplication::postEvent( im, static_cast<QEvent*>(event) );
    return VLC_SUCCESS;
}

static int ItemStateChanged( vlc_object_t *p_this, const char *psz_var,
707
                           vlc_value_t oldval, vlc_value_t newval, void *param )
708 709 710 711 712 713 714 715 716
{
    InputManager *im = (InputManager*)param;

    IMEvent *event = new IMEvent( ItemStateChanged_Type, 0 );
    QApplication::postEvent( im, static_cast<QEvent*>(event) );
    return VLC_SUCCESS;
}

static int ItemRateChanged( vlc_object_t *p_this, const char *psz_var,
717
                           vlc_value_t oldval, vlc_value_t newval, void *param )
718 719
{
    InputManager *im = (InputManager*)param;
720

721 722 723 724 725 726
    IMEvent *event = new IMEvent( ItemRateChanged_Type, 0 );
    QApplication::postEvent( im, static_cast<QEvent*>(event) );
    return VLC_SUCCESS;
}

static int ItemTitleChanged( vlc_object_t *p_this, const char *psz_var,
727
                           vlc_value_t oldval, vlc_value_t newval, void *param )
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
{
    InputManager *im = (InputManager*)param;

    IMEvent *event = new IMEvent( ItemTitleChanged_Type, 0 );
    QApplication::postEvent( im, static_cast<QEvent*>(event) );
    return VLC_SUCCESS;
}

static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *param )
{
    InputManager *im = (InputManager*)param;

    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
    QApplication::postEvent( im, static_cast<QEvent*>(event) );
    return VLC_SUCCESS;
}
745

746 747 748 749
static int ChangeSPU( vlc_object_t *p_this, const char *var, vlc_value_t o,
                        vlc_value_t n, void *param )
{
    InputManager *im = (InputManager*)param;
750 751
    IMEvent *event = new IMEvent( ItemSpuChanged_Type, 0 );
    QApplication::postEvent( im, static_cast<QEvent*>(event) );
752
    return VLC_SUCCESS;
753 754 755 756 757
}

static int ChangeTeletext( vlc_object_t *p_this, const char *var, vlc_value_t o,
                           vlc_value_t n, void *param )
{
758

759 760 761 762
    InputManager *im = (InputManager*)param;
    IMEvent *event = new IMEvent( ItemTeletextChanged_Type, 0 );
    QApplication::postEvent( im, static_cast<QEvent*>(event) );
    return VLC_SUCCESS;
763 764
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
765
/* MIM */
766
static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
767 768
                        vlc_value_t oldval, vlc_value_t newval, void *param )
{
769
    MainInputManager *mim = (MainInputManager*)param;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
770 771

    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
772
    QApplication::postEvent( mim, static_cast<QEvent*>(event) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
773 774 775 776 777 778
    return VLC_SUCCESS;
}

static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *param )
{
779
    MainInputManager *mim = (MainInputManager*)param;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
780 781

    IMEvent *event = new IMEvent( VolumeChanged_Type, newval.i_int );
782
    QApplication::postEvent( mim, static_cast<QEvent*>(event) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
783 784 785
    return VLC_SUCCESS;
}