interface.cpp 20.5 KB
Newer Older
1 2 3 4 5 6 7 8 9
/***************************************************************************
                          interface.cpp  -  description
                             -------------------
    begin                : Sun Mar 25 2001
    copyright            : (C) 2001 by andres
    email                : dae@chez.com
 ***************************************************************************/

#include "disc.h"
10
#include "info.h"
11 12 13 14 15
#include "interface.h"
#include "net.h"
#include "menu.h"
#include "slider.h"
#include "preferences.h"
16
#include "languagemenu.h"
17

18
#include <iostream>
19 20 21 22 23 24 25 26 27 28 29

#include <kaction.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <kstdaction.h>
#include <kurl.h>
#include <kurldrag.h>
#include <qcursor.h>
#include <qdragobject.h>
#include <qtimer.h>
#include <kdialog.h>
30
#include <kstatusbar.h>
31 32 33 34 35 36 37 38 39 40 41

#define ID_STATUS_MSG       1
#define ID_DATE             2
#define ID_STREAM_SOURCE    3

KInterface::KInterface( intf_thread_t *p_intf, QWidget *parent,
        const char *name ) : KMainWindow(parent,name)
{
    setAcceptDrops(true);

    this->p_intf = p_intf;
42
    p_messagesWindow = new KMessagesWindow( p_intf, p_intf->p_sys->p_msg );
43 44 45 46 47 48
    fDiskDialog = new KDiskDialog( this );
    fNetDialog = new KNetDialog( this );
    fTitleMenu = new KTitleMenu( p_intf, this );

    fSlider = new KVLCSlider( QSlider::Horizontal, this );
    fSlider->setMaxValue(10000);
49 50 51 52 53 54
    connect( fSlider, SIGNAL( userChanged( int ) ), this,
             SLOT( slotSliderMoved( int ) ) );
    connect( fSlider, SIGNAL( valueChanged( int ) ), this,
             SLOT( slotSliderChanged( int ) ) );
    connect( fSlider, SIGNAL( sliderMoved( int ) ), this,
             SLOT( slotSliderChanged( int ) ) );
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    setCentralWidget(fSlider);

    fTimer = new QTimer( this );
    connect( fTimer, SIGNAL( timeout() ), this, SLOT( slotManage() ) );

    resize( 400, 30 );
    ///////////////////////////////////////////////////////////////////
    // call inits to invoke all other construction parts
    // XXX could we move this up ?
    initStatusBar();
    initActions();

    // add certain calls to the popup menu
    fileOpen->plug( fTitleMenu );
    fileOpenRecent->plug( fTitleMenu );
    diskOpen->plug( fTitleMenu );
    streamOpen->plug( fTitleMenu );
    play->plug( fTitleMenu );
    pause->plug( fTitleMenu );
    slow->plug( fTitleMenu );
    fast->plug( fTitleMenu );
    fileQuit->plug( fTitleMenu );
77 78
    fTimer->start( 0, FALSE );

79 80 81 82 83 84 85 86 87
}

KInterface::~KInterface()
{
    ;
}

void KInterface::initActions()
{
88
    languages = new KActionMenu( _( "Languages" ), actionCollection(),
Felix Paul Kühne's avatar
Felix Paul Kühne committed
89
                                 _("language") );
90 91 92
    languages->setEnabled( false );
    languageCollection = new KActionCollection( this );
    subtitleCollection = new KActionCollection( this );
93 94
    subtitles = new KActionMenu( _( "Subtitles" ), actionCollection(),
                                 "subtitles" );
95
    subtitles->setEnabled( false );
96 97 98 99 100 101 102 103 104 105 106 107 108 109
    fileOpen =
        KStdAction::open(this, SLOT(slotFileOpen()), actionCollection());
    fileOpenRecent =
        KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL&)),
                               actionCollection());
    preferences = KStdAction::preferences(this, SLOT(slotShowPreferences()),
                                          actionCollection());
    fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()),
                                actionCollection());
    viewToolBar = KStdAction::showToolbar(this, SLOT(slotViewToolBar()),
                                          actionCollection());
    viewStatusBar = KStdAction::showStatusbar(this, SLOT(slotViewStatusBar()),
                                              actionCollection());

Felix Paul Kühne's avatar
Felix Paul Kühne committed
110
    diskOpen = new KAction( i18n( _("Open &Disk") ), 0, 0, this,
111 112
                            SLOT( slotOpenDisk() ), actionCollection(),
                            "open_disk" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
113
    streamOpen = new KAction( i18n( _("Open &Stream") ), 0, 0, this,
114 115
                              SLOT( slotOpenStream() ), actionCollection(),
                              "open_stream" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
116
    backward = new KAction( i18n( _("&Backward") ), 0, 0, this,
117 118
                            SLOT( slotBackward() ), actionCollection(),
                            "backward" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
119
    stop = new KAction( i18n( _("&Stop") ), 0, 0, this,
120
                        SLOT( slotStop() ), actionCollection(), "stop" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
121
    play = new KAction( i18n( _("&Play") ), 0, 0, this,
122
                        SLOT( slotPlay() ), actionCollection(), "play" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
123
    pause = new KAction( i18n( _("P&ause") ), 0, 0, this,
124
                         SLOT( slotPause() ), actionCollection(), "pause" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
125
    slow = new KAction( i18n( _("&Slow") ), 0, 0, this,
126
                        SLOT( slotSlow() ), actionCollection(), "slow" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
127
    fast = new KAction( i18n( _("Fas&t") ), 0, 0, this,
128
                        SLOT( slotFast() ), actionCollection(), "fast" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
129
    prev = new KAction( i18n( _("Prev") ), 0, 0, this,
130
                        SLOT( slotPrev() ), actionCollection(), "prev" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
131
    next = new KAction( i18n( _("Next") ), 0, 0, this,
132 133 134 135
                        SLOT( slotNext() ), actionCollection(), "next" );
    messages = new KAction( _( "Messages..." ), 0, 0, this,
                            SLOT( slotShowMessages() ), actionCollection(),
                            "view_messages");
136
    
137 138 139
    info = new KAction( _( "Stream info..." ), 0, 0, this,
                        SLOT( slotShowInfo() ), actionCollection(),
                        "view_stream_info");
140

141
    info->setEnabled( false );
142 143 144 145 146 147
    program = new KActionMenu( _( "Program" ), actionCollection(), "program" );
    program->setEnabled( false );
    title = new KActionMenu( _( "Title" ), actionCollection(), "title" );
    title->setEnabled( false );
    chapter = new KActionMenu( _( "Chapter" ), actionCollection(), "chapter" );
    chapter->setEnabled( false );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
148 149 150 151
    fileOpen->setStatusText(i18n(_("Opens an existing document")));
    fileOpenRecent->setStatusText(i18n(_("Opens a recently used file")));
    fileQuit->setStatusText(i18n(_("Quits the application")));
    viewToolBar->setStatusText(i18n(_("Enables/disables the toolbar")));
152
    viewStatusBar->setStatusText(i18n(_("Enables/disables the status bar")));
153

Felix Paul Kühne's avatar
Felix Paul Kühne committed
154 155 156 157 158 159 160 161 162 163
    diskOpen->setStatusText( i18n( _("Opens a disk") ) );
    streamOpen->setStatusText( i18n( _("Opens a network stream") ) );
    backward->setStatusText( i18n( _("Backward") ) );
    stop->setStatusText( i18n( _("Stops playback") ) );
    play->setStatusText( i18n( _("Starts playback") ) );
    pause->setStatusText( i18n( _("Pauses playback") ) );
    slow->setStatusText( i18n( _("Slow") ) );
    fast->setStatusText( i18n( _("Fast") ) );
    prev->setStatusText( i18n( _("Prev") ) );
    next->setStatusText( i18n( _("Next") ) );
164
    // use the absolute path to your ktestui.rc file for testing purpose in createGUI();
165 166
    char *psz_uifile = config_GetPsz( p_intf, "kde-uirc" );
    createGUI( psz_uifile );
167
//    createGUI( "./modules/gui/kde/ui.rc" );
168 169 170 171 172 173 174
}

void KInterface::initStatusBar()
{
  ///////////////////////////////////////////////////////////////////
  // STATUSBAR
  // TODO: add your own items you need for displaying current application status.
Felix Paul Kühne's avatar
Felix Paul Kühne committed
175
    statusBar()->insertItem(i18n(_("Ready.")), ID_STATUS_MSG, 1, false);
176 177 178 179 180 181 182
    statusBar()->setItemAlignment( ID_STATUS_MSG, AlignLeft | AlignVCenter );
    statusBar()->insertItem( "0:00:00", ID_DATE, 0, true );
}

/////////////////////////////////////////////////////////////////////
// SLOT IMPLEMENTATION
/////////////////////////////////////////////////////////////////////
183 184 185 186
void KInterface::slotShowMessages()
{
    p_messagesWindow->show();
}
187

188 189 190 191 192 193 194 195
void KInterface::slotShowInfo()
{
    if ( p_intf->p_sys->p_input )
    {
        new KInfoWindow(p_intf, p_intf->p_sys->p_input);
    }
}

196 197 198 199
void KInterface::slotFileOpen()
{
    playlist_t *p_playlist;

Felix Paul Kühne's avatar
Felix Paul Kühne committed
200
    slotStatusMsg( i18n( _("Opening file...") ) );
201
    KURL url=KFileDialog::getOpenURL( QString::null,
Felix Paul Kühne's avatar
Felix Paul Kühne committed
202
            i18n( "*|All files" ), this, i18n( _("Open File...") ) );
203 204 205 206 207 208 209 210

    if( !url.isEmpty() )
    {
        p_playlist = (playlist_t *)
            vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
        if( p_playlist )
        {
            fileOpenRecent->addURL( url );
Clément Stenac's avatar
Clément Stenac committed
211
            playlist_Add( p_playlist, url.path(), url.path(), 
212 213 214 215 216
                          PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
            vlc_object_release( p_playlist );
        }
    }

Felix Paul Kühne's avatar
Felix Paul Kühne committed
217
    slotStatusMsg( i18n( _("Ready.") ) );
218 219 220 221
}

void KInterface::slotFileOpenRecent(const KURL& url)
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
222 223
  slotStatusMsg(i18n(_("Opening file...")));
  slotStatusMsg(i18n(_("Ready.")));
224 225 226 227
}

void KInterface::slotFileQuit()
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
228
    slotStatusMsg(i18n(_("Exiting...")));
229
    p_intf->p_vlc->b_die = VLC_TRUE;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
230
    slotStatusMsg(i18n(_("Ready.")));
231 232 233 234
}

void KInterface::slotViewToolBar()
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
235
  slotStatusMsg(i18n(_("Toggling toolbar...")));
236 237 238 239 240 241 242 243 244 245 246
  ///////////////////////////////////////////////////////////////////
  // turn Toolbar on or off
  if(!viewToolBar->isChecked())
  {
    toolBar("mainToolBar")->hide();
  }
  else
  {
    toolBar("mainToolBar")->show();
  }        

Felix Paul Kühne's avatar
Felix Paul Kühne committed
247
  slotStatusMsg(i18n(_("Ready.")));
248 249 250 251
}

void KInterface::slotViewStatusBar()
{
252
  slotStatusMsg(i18n(_("Toggle the status bar...")));
253 254 255 256 257 258 259 260 261 262 263
  ///////////////////////////////////////////////////////////////////
  //turn Statusbar on or off
  if(!viewStatusBar->isChecked())
  {
    statusBar()->hide();
  }
  else
  {
    statusBar()->show();
  }

Felix Paul Kühne's avatar
Felix Paul Kühne committed
264
  slotStatusMsg(i18n(_("Ready.")));
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
}

void KInterface::slotShowPreferences()
{
    // Do something
    KPreferences(this->p_intf, "main", this, "preferences");
}

void KInterface::slotStatusMsg(const QString &text)
{
  ///////////////////////////////////////////////////////////////////
  // change status message permanently
  statusBar()->clear();
  statusBar()->changeItem(text, ID_STATUS_MSG);
}

void KInterface::slotManage()
{
283
    p_messagesWindow->update();
284
//    p_intf->p_sys->p_app->processEvents();
285 286 287 288 289 290 291
    vlc_mutex_lock( &p_intf->change_lock );

    /* Update the input */
    if( p_intf->p_sys->p_input == NULL )
    {
        p_intf->p_sys->p_input = (input_thread_t *)
                vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
292 293 294 295 296 297 298
        if ( p_intf->p_sys->p_input )
        {
            languages->setEnabled( true );
            subtitles->setEnabled( true );
            info->setEnabled( true );
        }
            
299 300 301 302 303
    }
    else if( p_intf->p_sys->p_input->b_dead )
    {
        vlc_object_release( p_intf->p_sys->p_input );
        p_intf->p_sys->p_input = NULL;
304 305 306
        languages->setEnabled( false );
        subtitles->setEnabled( false );
        info->setEnabled( false );
307 308 309 310 311 312 313 314 315
    }

    /* If the "display popup" flag has changed */
    if( p_intf->b_menu_change )
    {
        fTitleMenu->popup( ( QCursor::pos() ) );
        p_intf->b_menu_change = 0;
    }

316
    if( p_intf->p_sys->p_input )
317
    {
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
        input_thread_t *p_input = p_intf->p_sys->p_input;
                
        vlc_mutex_lock( &p_input->stream.stream_lock );
        if( !p_input->b_die )
        {
            /* New input or stream map change */
            if( p_input->stream.b_changed )
            {
                //            E_(GtkModeManage)( p_intf );
                //GtkSetupMenus( p_intf );
                slotUpdateLanguages();

                p_intf->p_sys->b_playing = 1;
                p_input->stream.b_changed = 0;
            }

            /* Manage the slider. fSlider->setValue triggers
             * slotSliderChanged which needs to grab the stream lock*/
#define p_area p_input->stream.p_selected_area
            if( p_area->i_size ) {
                vlc_mutex_unlock( &p_input->stream.stream_lock );
339 340
                fSlider->setValue( ( 10000 * p_area->i_tell )
                                   / p_area->i_size );
341 342 343 344 345 346 347 348 349 350 351 352 353
                vlc_mutex_lock( &p_input->stream.stream_lock );

            }
#undef p_area
            
            //         if( p_intf->p_sys->i_part !=
            //    p_input->stream.p_selected_area->i_part )
            //{
                //      p_intf->p_sys->b_chapter_update = 1;
                //GtkSetupMenus( p_intf );
            //}
        }
        vlc_mutex_unlock( &p_input->stream.stream_lock );
354

355 356 357
    }
    
    else if( p_intf->p_sys->b_playing && !p_intf->b_die )
358
    {
359 360
        //E_(GtkModeManage)( p_intf );
        p_intf->p_sys->b_playing = 0;
361 362 363 364 365 366 367 368
    }

    if( p_intf->b_die )
    {
        p_intf->p_sys->p_app->quit();
    }

    vlc_mutex_unlock( &p_intf->change_lock );
369
    msleep( 100 );
370

371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
}

void KInterface::slotSliderMoved( int position )
{
    if( p_intf->p_sys->p_input )
    {
        // XXX is this locking really useful ?
        vlc_mutex_lock( &p_intf->change_lock );

        off_t i_seek = ( position * p_intf->p_sys->p_input->stream.p_selected_area->i_size ) / 10000;
        input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );

        vlc_mutex_unlock( &p_intf->change_lock );
    }
}

387 388 389 390 391 392 393 394 395
void KInterface::slotUpdateLanguages()
{

    es_descriptor_t *   p_spu_es;
    es_descriptor_t *   p_audio_es;
    /* look for selected ES */
    p_audio_es = NULL;
    p_spu_es = NULL;

396
    for( unsigned int i = 0 ;
397 398 399
         i < p_intf->p_sys->p_input->stream.i_selected_es_number ;
         i++
        )
400
    {
401 402
        if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat
            == AUDIO_ES )
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
        {
            p_audio_es = p_intf->p_sys->p_input->stream.pp_selected_es[i];
        }

        if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
        {
            p_spu_es = p_intf->p_sys->p_input->stream.pp_selected_es[i];
        }
    }
    languages->setEnabled( false );
    subtitles->setEnabled( false );
    languageCollection->clear();
    subtitleCollection->clear();
    languages->popupMenu()->clear();
    subtitles->popupMenu()->clear();
    /* audio menus */
    /* find audio root menu */
    languageMenus( languages, p_audio_es, AUDIO_ES );

    /* sub picture menus */
    /* find spu root menu */
    languageMenus( subtitles, p_spu_es, SPU_ES );

}


/*
 * called with stream lock
 */
void KInterface::languageMenus(KActionMenu *root, es_descriptor_t *p_es,
                          int i_cat)
{
    int i_item = 0;
    if ( i_cat != AUDIO_ES )
    {
        KLanguageMenuAction *p_item =
            new KLanguageMenuAction( p_intf, _( "Off" ), 0, this );
        subtitleCollection->insert( p_item );
        root->insert( p_item );
        root->insert( new KActionSeparator( this ) );
        p_item->setExclusiveGroup( QString().sprintf( "%d", i_cat ) );
        p_item->setChecked( p_es == 0 );
    }
    
#define ES p_intf->p_sys->p_input->stream.pp_es[i]
    /* create a set of language buttons and append them to the container */
449 450 451
    for( unsigned int i = 0 ;
         i < p_intf->p_sys->p_input->stream.i_es_number ;
         i++ )
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
    {
        if( ( ES->i_cat == i_cat ) &&
            ( !ES->p_pgrm ||
              ES->p_pgrm ==
                 p_intf->p_sys->p_input->stream.p_selected_program ) )
        {
            i_item++;
            QString name = p_intf->p_sys->p_input->stream.pp_es[i]->psz_desc;
            if( name.isEmpty() )
            {
                name.sprintf( "Language %d", i_item );
            }
            KLanguageMenuAction *p_item;
            if ( i_cat == AUDIO_ES )
            {
                p_item = new KLanguageMenuAction( p_intf, name, ES,
                                                  this );
                languageCollection->insert(p_item);
            }
            else
            {
                p_item = new KLanguageMenuAction( p_intf, name, ES,
                                                  this );
                subtitleCollection->insert(p_item);
            }
            p_item->setExclusiveGroup( QString().sprintf( "%d", i_cat ) );
            root->insert( p_item );
            
            if( p_es == p_intf->p_sys->p_input->stream.pp_es[i] )
            {
                /* don't lose p_item when we append into menu */
                //p_item_active = p_item;
                p_item->setChecked( true );
            }
            connect( p_item, SIGNAL( toggled( bool, es_descriptor_t * ) ),
                     this, SLOT( slotSetLanguage( bool, es_descriptor_t * ) ));

        }
    }

    root->setEnabled( true );
}


void KInterface::slotSetLanguage( bool on, es_descriptor_t *p_es )
{
    input_ToggleES( p_intf->p_sys->p_input, p_es, on );
}

501 502 503 504
void KInterface::slotSliderChanged( int position )
{
    if( p_intf->p_sys->p_input != NULL )
    {
505
        char psz_time[ MSTRTIME_MAX_SIZE ];
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538

        vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );

#define p_area p_intf->p_sys->p_input->stream.p_selected_area
        statusBar()->changeItem( input_OffsetToTime( p_intf->p_sys->p_input, psz_time, ( p_area->i_size * position ) / 10000 ), ID_DATE );
#undef p_area

        vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
     }
}

void KInterface::slotOpenDisk()
{
    playlist_t *p_playlist;
    int r = fDiskDialog->exec();
    if ( r )
    {
        // Build source name
        QString source;
        source += fDiskDialog->type();
        source += ':';
        source += fDiskDialog->device();

        source += '@';
        source += fDiskDialog->title();
        source += ',';
        source += fDiskDialog->chapter();

        p_playlist = (playlist_t *)
            vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
        if( p_playlist )
        {
            // add it to playlist
Clément Stenac's avatar
Clément Stenac committed
539
            playlist_Add( p_playlist, source.latin1(), source.latin1(),
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
                          PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
            vlc_object_release( p_playlist );
        }
    }
}

void KInterface::slotOpenStream()
{
    playlist_t *p_playlist;
    int r = fNetDialog->exec();
    if ( r )
    {
        // Build source name
        QString source;
        source += fNetDialog->protocol();
        source += "://";
        source += fNetDialog->server();
        source += ":";
        source += QString().setNum( fNetDialog->port() );

        p_playlist = (playlist_t *)
            vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
        if( p_playlist )
        {
            // add it to playlist
Clément Stenac's avatar
Clément Stenac committed
565
            playlist_Add( p_playlist, source.latin1(), source.latin1(),
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
                          PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
            vlc_object_release( p_playlist );
        }
    }
}

void KInterface::slotPlay()
{
    if( p_intf->p_sys->p_input )
    {
        input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
    }
}

void KInterface::slotPause()
{
    if ( p_intf->p_sys->p_input )
    {
        input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
    }
}

void KInterface::slotStop()
{
    playlist_t *p_playlist = (playlist_t *)
            vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    if( p_playlist )
    {
        playlist_Stop( p_playlist );
        vlc_object_release( p_playlist );
    }
}

void KInterface::slotBackward()
{
    msg_Err( p_intf, "KInterface::slotBackward() - Unimplemented" );
}

void KInterface::slotPrev()
{
    playlist_t *p_playlist = (playlist_t *)
            vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    if( p_playlist )
    {
        playlist_Prev( p_playlist );
        vlc_object_release( p_playlist );
    }
}

void KInterface::slotNext()
{
    playlist_t *p_playlist = (playlist_t *)
            vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    if( p_playlist )
    {
        playlist_Next( p_playlist );
        vlc_object_release( p_playlist );
    }
}

void KInterface::slotSlow()
{
    if( p_intf->p_sys->p_input != NULL )
    {
        input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
    }
}

void KInterface::slotFast()
{
    if( p_intf->p_sys->p_input != NULL )
    {
        input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
    }
}

void KInterface::dragEnterEvent( QDragEnterEvent *event )
{
    event->accept( QUriDrag::canDecode( event ) );
}

void KInterface::dropEvent( QDropEvent *event )
{
    KURL::List urlList;

    playlist_t *p_playlist = (playlist_t *)
            vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    if ( KURLDrag::decode( event, urlList ) )
    {
        for ( KURL::List::ConstIterator i = urlList.begin(); i != urlList.end(); i++ )
        {
            // XXX add a private function to add a KURL with checking
            // actually a whole class for core abstraction would be neat
            if( !(*i).isEmpty() )
            {
                fileOpenRecent->addURL( *i );
Clément Stenac's avatar
Clément Stenac committed
667
                playlist_Add( p_playlist, (*i).path(), (*i).path(),
668 669 670 671 672 673 674
                          PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
            }
        }
    }

    vlc_object_release( p_playlist );
}