dialogs_provider.cpp 20.1 KB
Newer Older
Clément Stenac's avatar
Clément Stenac committed
1
/*****************************************************************************
2
 * dialogs_provider.cpp : Dialog Provider
3
 *****************************************************************************
4
 * Copyright (C) 2006-2008 the VideoLAN team
5
 * $Id$
Clément Stenac's avatar
Clément Stenac committed
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
Clément Stenac's avatar
Clément Stenac committed
9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * 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
22 23
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
24

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
29 30
#include <vlc_intf_strings.h>

31
#include "qt4.hpp"
32
#include "dialogs_provider.hpp"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
33
#include "input_manager.hpp" /* Load Subtitles */
34
#include "menus.hpp"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
35
#include "recents.hpp"
36
#include "util/qt_dirs.hpp"
37 38

/* The dialogs */
Clément Stenac's avatar
Clément Stenac committed
39
#include "dialogs/playlist.hpp"
40
#include "dialogs/bookmarks.hpp"
41
#include "dialogs/preferences.hpp"
42
#include "dialogs/mediainfo.hpp"
43
#include "dialogs/messages.hpp"
44
#include "dialogs/extended.hpp"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
45
#include "dialogs/vlm.hpp"
Clément Stenac's avatar
Clément Stenac committed
46
#include "dialogs/sout.hpp"
47
#include "dialogs/open.hpp"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
48
#include "dialogs/help.hpp"
49
#include "dialogs/gototime.hpp"
50
#include "dialogs/podcast_configuration.hpp"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
51
#include "dialogs/toolbar.hpp"
52
#include "dialogs/plugins.hpp"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
53
#include "dialogs/interaction.hpp"
Clément Stenac's avatar
Clément Stenac committed
54

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
55 56 57 58 59 60
#include <QEvent>
#include <QApplication>
#include <QSignalMapper>
#include <QFileDialog>


Clément Stenac's avatar
Clément Stenac committed
61 62
DialogsProvider* DialogsProvider::instance = NULL;

63
DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
64
                                  QObject( NULL ), p_intf( _p_intf )
Clément Stenac's avatar
Clément Stenac committed
65
{
66
    b_isDying = false;
67

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
68
    /* Various signal mappers for the menus */
69
    menusMapper = new QSignalMapper();
70
    CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
71

72
    menusUpdateMapper = new QSignalMapper();
73 74
    CONNECT( menusUpdateMapper, mapped(QObject *),
             this, menuUpdateAction( QObject *) );
Clément Stenac's avatar
Clément Stenac committed
75 76 77

    SDMapper = new QSignalMapper();
    CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
Clément Stenac's avatar
Clément Stenac committed
78
}
79

Clément Stenac's avatar
Clément Stenac committed
80 81
DialogsProvider::~DialogsProvider()
{
82
    msg_Dbg( p_intf, "Destroying the Dialog Provider" );
Clément Stenac's avatar
Clément Stenac committed
83
    PlaylistDialog::killInstance();
84
    MediaInfoDialog::killInstance();
85
    MessagesDialog::killInstance();
86
    ExtendedDialog::killInstance();
87
    BookmarksDialog::killInstance();
88
    HelpDialog::killInstance();
89
#ifdef UPDATE_CHECK
90
    UpdateDialog::killInstance();
91
#endif
92

93 94 95
    delete menusMapper;
    delete menusUpdateMapper;
    delete SDMapper;
Clément Stenac's avatar
Clément Stenac committed
96 97
}

98 99
void DialogsProvider::quit()
{
100
    b_isDying = true;
101
    vlc_object_kill( p_intf->p_libvlc );
102 103
}

Clément Stenac's avatar
Clément Stenac committed
104 105
void DialogsProvider::customEvent( QEvent *event )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
106
    if( event->type() == (int)DialogEvent_Type )
Clément Stenac's avatar
Clément Stenac committed
107
    {
108
        DialogEvent *de = static_cast<DialogEvent*>(event);
Clément Stenac's avatar
Clément Stenac committed
109 110
        switch( de->i_dialog )
        {
111 112 113
        case INTF_DIALOG_FILE_SIMPLE:
        case INTF_DIALOG_FILE:
            openDialog(); break;
114 115
        case INTF_DIALOG_FILE_GENERIC:
            openFileGenericDialog( de->p_arg ); break;
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
        case INTF_DIALOG_DISC:
            openDiscDialog(); break;
        case INTF_DIALOG_NET:
            openNetDialog(); break;
        case INTF_DIALOG_SAT:
        case INTF_DIALOG_CAPTURE:
            openCaptureDialog(); break;
        case INTF_DIALOG_DIRECTORY:
            PLAppendDir(); break;
        case INTF_DIALOG_PLAYLIST:
            playlistDialog(); break;
        case INTF_DIALOG_MESSAGES:
            messagesDialog(); break;
        case INTF_DIALOG_FILEINFO:
           mediaInfoDialog(); break;
        case INTF_DIALOG_PREFS:
           prefsDialog(); break;
        case INTF_DIALOG_BOOKMARKS:
           bookmarksDialog(); break;
        case INTF_DIALOG_EXTENDED:
           extendedDialog(); break;
137
#ifdef ENABLE_VLM
138 139
        case INTF_DIALOG_VLM:
           vlmDialog(); break;
140
#endif
141 142 143 144 145 146 147 148 149 150 151 152
        case INTF_DIALOG_INTERACTION:
           doInteraction( de->p_arg ); break;
        case INTF_DIALOG_POPUPMENU:
           QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
        case INTF_DIALOG_AUDIOPOPUPMENU:
           QVLCMenu::AudioPopupMenu( p_intf ); break;
        case INTF_DIALOG_VIDEOPOPUPMENU:
           QVLCMenu::VideoPopupMenu( p_intf ); break;
        case INTF_DIALOG_MISCPOPUPMENU:
           QVLCMenu::MiscPopupMenu( p_intf ); break;
        case INTF_DIALOG_WIZARD:
        case INTF_DIALOG_STREAMWIZARD:
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
153
            openAndStreamingDialogs(); break;
Rafaël Carré's avatar
Rafaël Carré committed
154
#ifdef UPDATE_CHECK
155
        case INTF_DIALOG_UPDATEVLC:
156
            updateDialog(); break;
Rafaël Carré's avatar
Rafaël Carré committed
157
#endif
158
        case INTF_DIALOG_EXIT:
159
            quit(); break;
160 161
        default:
           msg_Warn( p_intf, "unimplemented dialog" );
Clément Stenac's avatar
Clément Stenac committed
162 163 164 165
        }
    }
}

166 167 168
/****************************************************************************
 * Individual simple dialogs
 ****************************************************************************/
Clément Stenac's avatar
Clément Stenac committed
169 170 171 172 173
void DialogsProvider::playlistDialog()
{
    PlaylistDialog::getInstance( p_intf )->toggleVisible();
}

174 175 176 177
void DialogsProvider::prefsDialog()
{
    PrefsDialog::getInstance( p_intf )->toggleVisible();
}
178

179 180 181 182 183 184 185 186 187 188
void DialogsProvider::extendedDialog()
{
    ExtendedDialog::getInstance( p_intf )->toggleVisible();
}

void DialogsProvider::messagesDialog()
{
    MessagesDialog::getInstance( p_intf )->toggleVisible();
}

189 190 191 192 193
void DialogsProvider::gotoTimeDialog()
{
    GotoTimeDialog::getInstance( p_intf )->toggleVisible();
}

194
#ifdef ENABLE_VLM
195 196
void DialogsProvider::vlmDialog()
{
197
    VLMDialog::getInstance( p_intf )->toggleVisible();
198
}
199
#endif
200

201 202 203 204 205
void DialogsProvider::helpDialog()
{
    HelpDialog::getInstance( p_intf )->toggleVisible();
}

Rafaël Carré's avatar
Rafaël Carré committed
206
#ifdef UPDATE_CHECK
207 208 209
void DialogsProvider::updateDialog()
{
    UpdateDialog::getInstance( p_intf )->toggleVisible();
210
}
Rafaël Carré's avatar
Rafaël Carré committed
211
#endif
212

213 214 215 216 217 218 219 220 221 222
void DialogsProvider::aboutDialog()
{
    AboutDialog::getInstance( p_intf )->toggleVisible();
}

void DialogsProvider::mediaInfoDialog()
{
    MediaInfoDialog::getInstance( p_intf )->toggleVisible();
}

223 224
void DialogsProvider::mediaCodecDialog()
{
225
    MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
226 227
}

228 229
void DialogsProvider::bookmarksDialog()
{
230
    BookmarksDialog::getInstance( p_intf )->toggleVisible();
231 232
}

233 234 235 236 237
void DialogsProvider::podcastConfigureDialog()
{
    PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
238 239 240 241 242
void DialogsProvider::toolbarDialog()
{
    ToolbarEditDialog::getInstance( p_intf )->toggleVisible();
}

243 244 245 246 247 248
void DialogsProvider::pluginDialog()
{
    PluginDialog *diag = new PluginDialog( p_intf );
    diag->show();
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
249
/* Generic open file */
250 251 252 253
void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
{
    if( p_arg == NULL )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
254
        msg_Warn( p_intf, "openFileGenericDialog() called with NULL arg" );
255 256
        return;
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
257 258

    /* Replace the extensions to a Qt format */
259 260 261 262 263 264 265 266 267 268 269
    int i = 0;
    QString extensions = qfu( p_arg->psz_extensions );
    while ( ( i = extensions.indexOf( "|", i ) ) != -1 )
    {
        if( ( extensions.count( "|" ) % 2 ) == 0 )
            extensions.replace( i, 1, ");;" );
        else
            extensions.replace( i, 1, "(" );
    }
    extensions.replace(QString(";*"), QString(" *"));
    extensions.append( ")" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
270 271

    /* Save */
272 273
    if( p_arg->b_save )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
274 275
        QString file = QFileDialog::getSaveFileName( NULL, p_arg->psz_title,
                            qfu( p_intf->p_sys->psz_filepath ), extensions );
276 277 278
        if( !file.isEmpty() )
        {
            p_arg->i_results = 1;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
279
            p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
280
            p_arg->psz_results[0] = strdup( qtu( toNativeSepNoSlash( file ) ) );
281 282 283 284
        }
        else
            p_arg->i_results = 0;
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
285
    else /* non-save mode */
286
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
287 288 289
        QStringList files = QFileDialog::getOpenFileNames( NULL,
                p_arg->psz_title, qfu( p_intf->p_sys->psz_filepath ),
                extensions );
290
        p_arg->i_results = files.count();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
291
        p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
292 293
        i = 0;
        foreach( QString file, files )
294
            p_arg->psz_results[i++] = strdup( qtu( toNativeSepNoSlash( file ) ) );
295
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
296 297

    /* Callback */
298 299
    if( p_arg->pf_callback )
        p_arg->pf_callback( p_arg );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
300 301

    /* Clean afterwards */
302 303 304 305 306 307 308 309 310 311
    if( p_arg->psz_results )
    {
        for( i = 0; i < p_arg->i_results; i++ )
            free( p_arg->psz_results[i] );
        free( p_arg->psz_results );
    }
    free( p_arg->psz_title );
    free( p_arg->psz_extensions );
    free( p_arg );
}
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
312 313 314 315
/****************************************************************************
 * All the open/add stuff
 * Open Dialog first - Simple Open then
 ****************************************************************************/
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
316

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
317 318 319 320 321 322 323 324
void DialogsProvider::openDialog( int i_tab )
{
    OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
}
void DialogsProvider::openDialog()
{
    openDialog( OPEN_FILE_TAB );
}
325 326
void DialogsProvider::openFileDialog()
{
327
    openDialog( OPEN_FILE_TAB );
328
}
329
void DialogsProvider::openDiscDialog()
Clément Stenac's avatar
Clément Stenac committed
330
{
331
    openDialog( OPEN_DISC_TAB );
Clément Stenac's avatar
Clément Stenac committed
332
}
333
void DialogsProvider::openNetDialog()
Clément Stenac's avatar
Clément Stenac committed
334
{
335
    openDialog( OPEN_NETWORK_TAB );
Clément Stenac's avatar
Clément Stenac committed
336
}
337 338
void DialogsProvider::openCaptureDialog()
{
339
    openDialog( OPEN_CAPTURE_TAB );
340
}
Clément Stenac's avatar
Clément Stenac committed
341

342
/* Same as the open one, but force the enqueue */
343 344
void DialogsProvider::PLAppendDialog()
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
345 346
    OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
                             OPEN_AND_ENQUEUE )->showTab( OPEN_FILE_TAB );
347
}
348

349
void DialogsProvider::MLAppendDialog()
350 351 352 353 354
{
    OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
                            OPEN_AND_ENQUEUE, false, false )
                                    ->showTab( OPEN_FILE_TAB );
}
355

356 357 358 359 360
/**
 * Simple open
 ***/
QStringList DialogsProvider::showSimpleOpen( QString help,
                                             int filters,
361
                                             QString path )
362
{
363
    QString fileTypes = "";
364
    if( filters & EXT_FILTER_MEDIA ) {
365
        ADD_FILTER_MEDIA( fileTypes );
366
    }
367
    if( filters & EXT_FILTER_VIDEO ) {
368
        ADD_FILTER_VIDEO( fileTypes );
369
    }
370
    if( filters & EXT_FILTER_AUDIO ) {
371
        ADD_FILTER_AUDIO( fileTypes );
372
    }
373
    if( filters & EXT_FILTER_PLAYLIST ) {
374
        ADD_FILTER_PLAYLIST( fileTypes );
375
    }
376
    if( filters & EXT_FILTER_SUBTITLE ) {
377 378
        ADD_FILTER_SUBTITLE( fileTypes );
    }
379
    ADD_FILTER_ALL( fileTypes );
380
    fileTypes.replace(QString(";*"), QString(" *"));
381

382
    return QFileDialog::getOpenFileNames( NULL,
383
        help.isEmpty() ? qtr(I_OP_SEL_FILES ) : help,
384
        path.isEmpty() ? qfu( p_intf->p_sys->psz_filepath ) : path,
385
        fileTypes );
386 387
}

388 389 390 391 392
/**
 * Open a file,
 * pl helps you to choose from playlist or media library,
 * go to start or enqueue
 **/
393 394 395 396 397
void DialogsProvider::addFromSimple( bool pl, bool go)
{
    QStringList files = DialogsProvider::showSimpleOpen();
    int i = 0;
    foreach( QString file, files )
398
    {
399
        playlist_Add( THEPL, qtu( toNativeSeparators( file ) ), NULL,
400 401 402 403
                      go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
                                               ( i ? PLAYLIST_PREPARSE : 0 ) )
                         : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
                      PLAYLIST_END,
404
                      pl ? true : false, false );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
405 406
        RecentsMRL::getInstance( p_intf )->addRecent(
                toNativeSeparators( file ) );
407
        i++;
408 409 410
    }
}

411 412 413 414 415
void DialogsProvider::simpleOpenDialog()
{
    addFromSimple( true, true ); /* Playlist and Go */
}

416
void DialogsProvider::simplePLAppendDialog()
Clément Stenac's avatar
Clément Stenac committed
417
{
418
    addFromSimple( true, false );
Clément Stenac's avatar
Clément Stenac committed
419 420
}

421
void DialogsProvider::simpleMLAppendDialog()
422
{
423 424 425
    addFromSimple( false, false );
}

426 427 428 429 430 431
/* Directory */
/**
 * Open a directory,
 * pl helps you to choose from playlist or media library,
 * go to start or enqueue
 **/
432
static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
433
{
434 435 436 437
    QString dir = QFileDialog::getExistingDirectory( NULL, qtr("Open Directory") );

    if (!dir.isEmpty() )
    {
438 439
        QString mrl = dir.endsWith( "VIDEO_TS", Qt::CaseInsensitive ) ?
            "dvd://" : "directory://" + toNativeSeparators( dir );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
440
        input_item_t *p_input = input_item_NewExt( THEPL, qtu( mrl ),
441
                              NULL, 0, NULL, -1 );
442

443
        /* FIXME: playlist_AddInput() can fail */
444 445
        playlist_AddInput( THEPL, p_input,
                       go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
446
                       PLAYLIST_END, pl, pl_Unlocked );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
447
        RecentsMRL::getInstance( p_intf )->addRecent( mrl );
448
        if( !go )
449
            input_Read( THEPL, p_input, true );
450
        vlc_gc_decref( p_input );
451 452 453
    }
}

454 455 456 457 458
void DialogsProvider::PLOpenDir()
{
    openDirectory( p_intf, true, true );
}

459 460
void DialogsProvider::PLAppendDir()
{
461
    openDirectory( p_intf, true, false );
462 463 464 465 466 467 468
}

void DialogsProvider::MLAppendDir()
{
    openDirectory( p_intf, false , false );
}

469 470 471
/****************
 * Playlist     *
 ****************/
472
void DialogsProvider::openAPlaylist()
473
{
474
    QStringList files = showSimpleOpen( qtr( "Open playlist..." ),
475
                                        EXT_FILTER_PLAYLIST );
476 477
    foreach( QString file, files )
    {
478
        playlist_Import( THEPL, qtu( toNativeSeparators( file ) ) );
479 480 481
    }
}

482
void DialogsProvider::saveAPlaylist()
483 484
{
    QFileDialog *qfd = new QFileDialog( NULL,
485
                                   qtr( "Save playlist as..." ),
486
                                   qfu( p_intf->p_sys->psz_filepath ),
487
                                   qtr( "XSPF playlist (*.xspf);; " ) +
488 489 490
                                   qtr( "M3U playlist (*.m3u);; " ) +
                                   qtr( "HTML playlist (*.html);;" ) +
                                   qtr( "Any (*.*) " ) );
491 492 493 494 495 496 497 498
    qfd->setFileMode( QFileDialog::AnyFile );
    qfd->setAcceptMode( QFileDialog::AcceptSave );
    qfd->setConfirmOverwrite( true );

    if( qfd->exec() == QDialog::Accepted )
    {
        if( qfd->selectedFiles().count() > 0 )
        {
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
499
            static const char psz_xspf[] = "export-xspf",
500 501
                              psz_m3u[] = "export-m3u",
                              psz_html[] = "export-html";
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
502
            const char *psz_module;
503 504 505

            QString file = qfd->selectedFiles().first();
            QString filter = qfd->selectedFilter();
506
            const char* filt = filter.toAscii();
507

508
            if( file.contains( ".xsp" ) || filter.contains( "XSPF" ) )
509 510 511 512 513
            {
                psz_module = psz_xspf;
                if( !file.contains( ".xsp" ) )
                    file.append( ".xspf" );
            }
514
            else if( file.contains( ".m3u" )  || filter.contains( "M3U" ) )
515 516 517 518 519
            {
                psz_module = psz_m3u;
                if( !file.contains( ".m3u" ) )
                    file.append( ".m3u" );
            }
520 521 522 523 524 525 526 527 528 529 530 531
            else if( file.contains(".html" ) || filter.contains( "HTML" ) )
            {
                psz_module = psz_html;
                if( !file.contains( "html" ) )
                    file.append( ".html" );
            }
            else
            {
                msg_Err( p_intf, "Impossible to recognise the file type" );
                delete qfd;
                return;
            }
532

533 534
            playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
                        THEPL->p_local_category, psz_module);
535 536 537 538 539 540 541 542 543
        }
    }
    delete qfd;
}

/****************************************************************************
 * Sout emulation
 ****************************************************************************/

544 545
void DialogsProvider::streamingDialog( QWidget *parent, QString mrl,
                                       bool b_transcode_only )
546
{
547 548
    SoutDialog *s = SoutDialog::getInstance( parent, p_intf, b_transcode_only );

549 550
    if( s->exec() == QDialog::Accepted )
    {
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
551
        const char *psz_option = qtu( s->getMrl() );
552

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
553
        msg_Dbg( p_intf, "Sout mrl %s", psz_option );
554 555
        playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
                         PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
556
                        -1, &psz_option, 1, true, pl_Unlocked );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
557
        RecentsMRL::getInstance( p_intf )->addRecent( mrl );
558 559 560
    }
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
561
void DialogsProvider::openAndStreamingDialogs()
562
{
563 564
    OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM )
                                ->showTab( OPEN_FILE_TAB );
565 566
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
567
void DialogsProvider::openAndTranscodingDialogs()
568
{
569 570
    OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE )
                                ->showTab( OPEN_FILE_TAB );
571 572
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
void DialogsProvider::loadSubtitlesFile()
{
    input_thread_t *p_input = THEMIM->getInput();
    if( !p_input ) return;

    input_item_t *p_item = input_GetItem( p_input );
    if( !p_item ) return;

    char *path = input_item_GetURI( p_item );
    if( !path ) path = strdup( "" );

    char *sep = strrchr( path, DIR_SEP_CHAR );
    if( sep ) *sep = '\0';

    QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ),
                                      EXT_FILTER_SUBTITLE,
                                      path );
    free( path );
    QString qsFile;
    foreach( qsFile, qsl )
    {
594
        if( input_AddSubtitle( p_input, qtu( toNativeSeparators( qsFile ) ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
595 596 597 598 599 600 601
                    true ) )
            msg_Warn( p_intf, "unable to load subtitles from '%s'",
                      qtu( qsFile ) );
    }
}


602
/****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
603
 * Menus
604
 ****************************************************************************/
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
605

606 607 608 609 610
void DialogsProvider::menuAction( QObject *data )
{
    QVLCMenu::DoAction( p_intf, data );
}

611 612
void DialogsProvider::menuUpdateAction( QObject *data )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
613 614 615
    MenuFunc *func = qobject_cast<MenuFunc *>(data);
    assert( func );
    func->doFunc( p_intf );
616 617
}

Clément Stenac's avatar
Clément Stenac committed
618 619
void DialogsProvider::SDMenuAction( QString data )
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
620
    const char *psz_sd = qtu( data );
Clément Stenac's avatar
Clément Stenac committed
621 622 623 624 625 626
    if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
        playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
    else
        playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
627 628 629 630 631
/**
 * Play the MRL contained in the Recently played menu.
 **/
void DialogsProvider::playMRL( const QString &mrl )
{
632 633
    playlist_Add( THEPL, qtu( mrl ) , NULL,
           PLAYLIST_APPEND | PLAYLIST_GO , PLAYLIST_END, true, false );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
634 635 636 637 638 639 640

    RecentsMRL::getInstance( p_intf )->addRecent( mrl );
}

/*************************************
 * Interactions
 *************************************/
641
void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
642
{
643 644 645
    InteractionDialog *qdialog;
    interaction_dialog_t *p_dialog = p_arg->p_dialog;
    switch( p_dialog->i_action )
646
    {
647 648 649 650 651 652 653 654
    case INTERACT_NEW:
        qdialog = new InteractionDialog( p_intf, p_dialog );
        p_dialog->p_private = (void*)qdialog;
        if( !(p_dialog->i_status == ANSWERED_DIALOG) )
            qdialog->show();
        break;
    case INTERACT_UPDATE:
        qdialog = (InteractionDialog*)(p_dialog->p_private);
Rémi Duraffort's avatar
Rémi Duraffort committed
655
        if( qdialog )
656
            qdialog->update();
657 658 659 660 661 662 663 664 665 666 667
        else
        {
            /* The INTERACT_NEW message was forgotten
               so we must create the dialog and update it*/
            qdialog = new InteractionDialog( p_intf, p_dialog );
            p_dialog->p_private = (void*)qdialog;
            if( !(p_dialog->i_status == ANSWERED_DIALOG) )
                qdialog->show();
            if( qdialog )
                qdialog->update();
        }
668 669
        break;
    case INTERACT_HIDE:
670
        msg_Dbg( p_intf, "Hide the Interaction Dialog" );
671 672 673 674 675 676
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( qdialog )
            qdialog->hide();
        p_dialog->i_status = HIDDEN_DIALOG;
        break;
    case INTERACT_DESTROY:
677
        msg_Dbg( p_intf, "Destroy the Interaction Dialog" );
678 679 680 681 682
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
            delete qdialog;
        p_dialog->i_status = DESTROYED_DIALOG;
        break;
683 684
    }
}
685