dialogs_provider.cpp 18.8 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.
 *****************************************************************************/
24 25 26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
Clément Stenac's avatar
Clément Stenac committed
27

Clément Stenac's avatar
Clément Stenac committed
28
#include <QEvent>
Clément Stenac's avatar
Clément Stenac committed
29 30 31 32
#include <QApplication>
#include <QSignalMapper>
#include <QFileDialog>

33
#include <vlc_common.h>
Clément Stenac's avatar
Clément Stenac committed
34
#include "qt4.hpp"
35
#include "dialogs_provider.hpp"
36
#include "main_interface.hpp"
Clément Stenac's avatar
Clément Stenac committed
37 38
#include "menus.hpp"
#include <vlc_intf_strings.h>
39
#include "input_manager.hpp"
Clément Stenac's avatar
Clément Stenac committed
40 41

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

DialogsProvider* DialogsProvider::instance = NULL;

57
DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
58
                                  QObject( NULL ), p_intf( _p_intf )
Clément Stenac's avatar
Clément Stenac committed
59
{
60
    b_isDying = false;
61 62

    menusMapper = new QSignalMapper();
Clément Stenac's avatar
Clément Stenac committed
63
    CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
64

65
    menusUpdateMapper = new QSignalMapper();
Clément Stenac's avatar
Clément Stenac committed
66 67
    CONNECT( menusUpdateMapper, mapped(QObject *),
             this, menuUpdateAction( QObject *) );
Clément Stenac's avatar
Clément Stenac committed
68 69 70

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

Clément Stenac's avatar
Clément Stenac committed
73 74
DialogsProvider::~DialogsProvider()
{
75
    msg_Dbg( p_intf, "Destroying the Dialog Provider" );
Clément Stenac's avatar
Clément Stenac committed
76
    PlaylistDialog::killInstance();
77
    MediaInfoDialog::killInstance();
78
    MessagesDialog::killInstance();
79
    ExtendedDialog::killInstance();
80
    BookmarksDialog::killInstance();
81
    HelpDialog::killInstance();
82
#ifdef UPDATE_CHECK
83
    UpdateDialog::killInstance();
84
#endif
85

86 87 88
    delete menusMapper;
    delete menusUpdateMapper;
    delete SDMapper;
Clément Stenac's avatar
Clément Stenac committed
89 90
}

91 92
void DialogsProvider::quit()
{
93 94
    /* Stop the playlist */
    playlist_Stop( THEPL );
95
    b_isDying = true;
96
    vlc_object_kill( p_intf->p_libvlc );
97
    QApplication::closeAllWindows();
98 99 100
    QApplication::quit();
}

Clément Stenac's avatar
Clément Stenac committed
101 102 103 104
void DialogsProvider::customEvent( QEvent *event )
{
    if( event->type() == DialogEvent_Type )
    {
Clément Stenac's avatar
Clément Stenac committed
105
        DialogEvent *de = static_cast<DialogEvent*>(event);
Clément Stenac's avatar
Clément Stenac committed
106 107
        switch( de->i_dialog )
        {
108 109 110
        case INTF_DIALOG_FILE_SIMPLE:
        case INTF_DIALOG_FILE:
            openDialog(); break;
111 112
        case INTF_DIALOG_FILE_GENERIC:
            openFileGenericDialog( de->p_arg ); break;
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
        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;
134
#ifdef ENABLE_VLM
135 136
        case INTF_DIALOG_VLM:
           vlmDialog(); break;
137
#endif
138 139 140 141 142 143 144 145 146 147 148 149
        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:
150
            openThenStreamingDialogs(); break;
Rafaël Carré's avatar
Rafaël Carré committed
151
#ifdef UPDATE_CHECK
152
        case INTF_DIALOG_UPDATEVLC:
153
            updateDialog(); break;
Rafaël Carré's avatar
Rafaël Carré committed
154
#endif
155
        case INTF_DIALOG_EXIT:
156
            quit(); break;
157 158
        default:
           msg_Warn( p_intf, "unimplemented dialog" );
Clément Stenac's avatar
Clément Stenac committed
159 160 161 162
        }
    }
}

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

171 172 173 174
void DialogsProvider::prefsDialog()
{
    PrefsDialog::getInstance( p_intf )->toggleVisible();
}
175

176 177 178 179 180 181 182 183 184 185
void DialogsProvider::extendedDialog()
{
    ExtendedDialog::getInstance( p_intf )->toggleVisible();
}

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

186 187 188 189 190
void DialogsProvider::gotoTimeDialog()
{
    GotoTimeDialog::getInstance( p_intf )->toggleVisible();
}

191
#ifdef ENABLE_VLM
192 193
void DialogsProvider::vlmDialog()
{
194
    VLMDialog::getInstance( p_intf )->toggleVisible();
195
}
196
#endif
197

198 199 200 201 202
void DialogsProvider::helpDialog()
{
    HelpDialog::getInstance( p_intf )->toggleVisible();
}

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

210 211 212 213 214 215 216 217 218 219
void DialogsProvider::aboutDialog()
{
    AboutDialog::getInstance( p_intf )->toggleVisible();
}

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

220 221
void DialogsProvider::mediaCodecDialog()
{
222
    MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
223 224
}

225 226
void DialogsProvider::bookmarksDialog()
{
227
    BookmarksDialog::getInstance( p_intf )->toggleVisible();
228 229
}

230 231 232 233 234 235
void DialogsProvider::podcastConfigureDialog()
{
    PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
}


236 237
/****************************************************************************
 * All the open/add stuff
238
 * Open Dialog first - Simple Open then
239 240
 ****************************************************************************/

241 242 243 244
void DialogsProvider::openDialog( int i_tab )
{
    OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
}
245 246
void DialogsProvider::openDialog()
{
247
    openDialog( OPEN_FILE_TAB );
248
}
249 250 251 252
void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
{
    if( p_arg == NULL )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
253
        msg_Warn( p_intf, "openFileGenericDialog() called with NULL arg" );
254 255
        return;
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
256 257

    /* Replace the extensions to a Qt format */
258 259 260 261 262 263 264 265 266 267 268
    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
269 270

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

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

    /* Clean afterwards */
301 302 303 304 305 306 307 308 309 310
    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
311

312 313
void DialogsProvider::openFileDialog()
{
314
    openDialog( OPEN_FILE_TAB );
315
}
316
void DialogsProvider::openDiscDialog()
Clément Stenac's avatar
Clément Stenac committed
317
{
318
    openDialog( OPEN_DISC_TAB );
Clément Stenac's avatar
Clément Stenac committed
319
}
320
void DialogsProvider::openNetDialog()
Clément Stenac's avatar
Clément Stenac committed
321
{
322
    openDialog( OPEN_NETWORK_TAB );
Clément Stenac's avatar
Clément Stenac committed
323
}
324 325
void DialogsProvider::openCaptureDialog()
{
326
    openDialog( OPEN_CAPTURE_TAB );
327
}
Clément Stenac's avatar
Clément Stenac committed
328

329
/* Same as the open one, but force the enqueue */
330 331
void DialogsProvider::PLAppendDialog()
{
332
    OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_ENQUEUE)
333
                            ->showTab( OPEN_FILE_TAB );
334
}
335

336
void DialogsProvider::MLAppendDialog()
337 338 339 340 341
{
    OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
                            OPEN_AND_ENQUEUE, false, false )
                                    ->showTab( OPEN_FILE_TAB );
}
342

343 344 345 346 347
/**
 * Simple open
 ***/
QStringList DialogsProvider::showSimpleOpen( QString help,
                                             int filters,
348
                                             QString path )
349
{
350
    QString fileTypes = "";
351
    if( filters & EXT_FILTER_MEDIA ) {
352
        ADD_FILTER_MEDIA( fileTypes );
353
    }
354
    if( filters & EXT_FILTER_VIDEO ) {
355
        ADD_FILTER_VIDEO( fileTypes );
356
    }
357
    if( filters & EXT_FILTER_AUDIO ) {
358
        ADD_FILTER_AUDIO( fileTypes );
359
    }
360
    if( filters & EXT_FILTER_PLAYLIST ) {
361
        ADD_FILTER_PLAYLIST( fileTypes );
362
    }
363
    if( filters & EXT_FILTER_SUBTITLE ) {
364 365
        ADD_FILTER_SUBTITLE( fileTypes );
    }
366
    ADD_FILTER_ALL( fileTypes );
367
    fileTypes.replace(QString(";*"), QString(" *"));
368

369
    return QFileDialog::getOpenFileNames( NULL,
370 371
        help.isEmpty() ? qfu(I_OP_SEL_FILES ) : help,
        path.isEmpty() ? qfu( p_intf->p_sys->psz_filepath ) : path,
372
        fileTypes );
373 374
}

375 376 377 378 379
/**
 * Open a file,
 * pl helps you to choose from playlist or media library,
 * go to start or enqueue
 **/
380 381 382 383 384
void DialogsProvider::addFromSimple( bool pl, bool go)
{
    QStringList files = DialogsProvider::showSimpleOpen();
    int i = 0;
    foreach( QString file, files )
385
    {
386
        playlist_Add( THEPL, qtu( toNativeSeparators( file ) ), NULL,
387 388 389 390
                      go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
                                               ( i ? PLAYLIST_PREPARSE : 0 ) )
                         : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
                      PLAYLIST_END,
391
                      pl ? true : false, false );
392
        i++;
393 394 395
    }
}

396 397 398 399 400
void DialogsProvider::simpleOpenDialog()
{
    addFromSimple( true, true ); /* Playlist and Go */
}

401
void DialogsProvider::simplePLAppendDialog()
Clément Stenac's avatar
Clément Stenac committed
402
{
403
    addFromSimple( true, false );
Clément Stenac's avatar
Clément Stenac committed
404 405
}

406
void DialogsProvider::simpleMLAppendDialog()
407
{
408 409 410
    addFromSimple( false, false );
}

411 412 413 414 415 416
/* Directory */
/**
 * Open a directory,
 * pl helps you to choose from playlist or media library,
 * go to start or enqueue
 **/
417
static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
418
{
419 420 421 422
    QString dir = QFileDialog::getExistingDirectory( NULL, qtr("Open Directory") );

    if (!dir.isEmpty() )
    {
423
        input_item_t *p_input = input_item_NewExt( THEPL,
424 425
                              qtu( "directory://" + toNativeSeparators(dir) ),
                              NULL, 0, NULL, -1 );
426

427
        /* FIXME: playlist_AddInput() can fail */
428 429
        playlist_AddInput( THEPL, p_input,
                       go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
430
                       PLAYLIST_END, pl, pl_Unlocked );
431
        if( !go )
432
            input_Read( THEPL, p_input, true );
433
        vlc_gc_decref( p_input );
434 435 436
    }
}

437 438 439 440 441
void DialogsProvider::PLOpenDir()
{
    openDirectory( p_intf, true, true );
}

442 443
void DialogsProvider::PLAppendDir()
{
444
    openDirectory( p_intf, true, false );
445 446 447 448 449 450 451
}

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

452 453 454
/****************
 * Playlist     *
 ****************/
455
void DialogsProvider::openAPlaylist()
456
{
457
    QStringList files = showSimpleOpen( qtr( "Open playlist..." ),
458
                                        EXT_FILTER_PLAYLIST );
459 460
    foreach( QString file, files )
    {
461
        playlist_Import( THEPL, qtu( toNativeSeparators( file ) ) );
462 463 464
    }
}

465
void DialogsProvider::saveAPlaylist()
466 467
{
    QFileDialog *qfd = new QFileDialog( NULL,
468
                                   qtr( "Save playlist as..." ),
469
                                   qfu( p_intf->p_sys->psz_filepath ),
470 471
                                   qtr( "XSPF playlist (*.xspf);; " ) +
                                   qtr( "M3U playlist (*.m3u);; Any (*.*) " ) );
472 473 474 475 476 477 478 479
    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
480
            static const char psz_xspf[] = "export-xspf",
Rafaël Carré's avatar
Rafaël Carré committed
481
                              psz_m3u[] = "export-m3u";
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
482
            const char *psz_module;
483 484 485 486

            QString file = qfd->selectedFiles().first();
            QString filter = qfd->selectedFilter();

487 488
            if( file.contains( ".xsp" ) ||
                ( filter.contains( ".xspf" ) && !file.contains( ".m3u" ) ) )
489 490 491 492 493 494 495 496 497 498 499 500
            {
                psz_module = psz_xspf;
                if( !file.contains( ".xsp" ) )
                    file.append( ".xspf" );
            }
            else
            {
                psz_module = psz_m3u;
                if( !file.contains( ".m3u" ) )
                    file.append( ".m3u" );
            }

501 502
            playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
                        THEPL->p_local_category, psz_module);
503 504 505 506 507 508 509 510 511 512
        }
    }
    delete qfd;
}


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

513 514
void DialogsProvider::streamingDialog( QWidget *parent, QString mrl,
                                       bool b_transcode_only )
515
{
516 517
    SoutDialog *s = SoutDialog::getInstance( parent, p_intf, b_transcode_only );

518 519
    if( s->exec() == QDialog::Accepted )
    {
520
        msg_Dbg( p_intf, "Sout mrl %s", qta( s->getMrl() ) );
521
        /* Just do it */
522
        int i_len = strlen( qtu( s->getMrl() ) ) + 10;
523
        char *psz_option = (char*)malloc( i_len );
524
        snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
525 526 527

        playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
                         PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
528
                        -1, &psz_option, 1, true, pl_Unlocked );
529 530 531 532 533
    }
}

void DialogsProvider::openThenStreamingDialogs()
{
534 535
    OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM )
                                ->showTab( OPEN_FILE_TAB );
536 537 538 539
}

void DialogsProvider::openThenTranscodingDialogs()
{
540 541
    OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE )
                                ->showTab( OPEN_FILE_TAB );
542 543
}

544 545 546
/****************************************************************************
 * Menus / Interaction
 ****************************************************************************/
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
547

548 549 550 551 552
void DialogsProvider::menuAction( QObject *data )
{
    QVLCMenu::DoAction( p_intf, data );
}

553 554 555 556 557 558
void DialogsProvider::menuUpdateAction( QObject *data )
{
    MenuFunc * f = qobject_cast<MenuFunc *>(data);
    f->doFunc( p_intf );
}

Clément Stenac's avatar
Clément Stenac committed
559 560
void DialogsProvider::SDMenuAction( QString data )
{
561
    char *psz_sd = strdup( qtu( data ) );
Clément Stenac's avatar
Clément Stenac committed
562 563 564 565
    if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
        playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
    else
        playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
566
    free( psz_sd );
Clément Stenac's avatar
Clément Stenac committed
567 568
}

569
void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
Clément Stenac's avatar
Clément Stenac committed
570
{
571 572 573
    InteractionDialog *qdialog;
    interaction_dialog_t *p_dialog = p_arg->p_dialog;
    switch( p_dialog->i_action )
Clément Stenac's avatar
Clément Stenac committed
574
    {
575 576 577 578 579 580 581 582
    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
583
        if( qdialog )
584
            qdialog->update();
585 586 587 588 589 590 591 592 593 594 595
        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();
        }
596 597
        break;
    case INTERACT_HIDE:
598
        msg_Dbg( p_intf, "Hide the Interaction Dialog" );
599 600 601 602 603 604
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( qdialog )
            qdialog->hide();
        p_dialog->i_status = HIDDEN_DIALOG;
        break;
    case INTERACT_DESTROY:
605
        msg_Dbg( p_intf, "Destroy the Interaction Dialog" );
606 607 608 609 610
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
            delete qdialog;
        p_dialog->i_status = DESTROYED_DIALOG;
        break;
Clément Stenac's avatar
Clément Stenac committed
611 612
    }
}
613 614 615

void DialogsProvider::loadSubtitlesFile()
{
616 617
    input_thread_t *p_input = THEMIM->getInput();
    if( !p_input )
618
        return;
619 620 621 622 623 624 625 626 627
    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';
628
    QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ),
629 630 631 632 633 634
                                      EXT_FILTER_SUBTITLE,
                                      path );
    free( path );
    QString qsFile;
    foreach( qsFile, qsl )
    {
635 636
        if( !input_AddSubtitles( p_input, qtu( toNativeSeparators( qsFile ) ),
                    true ) )
637 638 639
            msg_Warn( p_intf, "unable to load subtitles from '%s'",
                      qtu( qsFile ) );
    }
640
}