dialogs_provider.cpp 18.4 KB
Newer Older
zorglub's avatar
zorglub committed
1
/*****************************************************************************
2
 * dialogs_provider.cpp : Dialog Provider
3
 *****************************************************************************
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
 *          Jean-Baptiste Kempf <jb@videolan.org>
zorglub's avatar
zorglub 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
zorglub's avatar
zorglub committed
27

zorglub's avatar
zorglub committed
28
#include <QEvent>
zorglub's avatar
zorglub committed
29 30 31 32
#include <QApplication>
#include <QSignalMapper>
#include <QFileDialog>

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

/* The dialogs */
zorglub's avatar
zorglub 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"
zorglub's avatar
zorglub committed
47
#include "dialogs/extended.hpp"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
48
#include "dialogs/vlm.hpp"
zorglub's avatar
zorglub 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"
zorglub's avatar
zorglub committed
54 55 56

DialogsProvider* DialogsProvider::instance = NULL;

zorglub's avatar
zorglub committed
57
DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
58
                                  QObject( NULL ), p_intf( _p_intf )
zorglub's avatar
zorglub committed
59
{
zorglub's avatar
zorglub committed
60
    fixed_timer = new QTimer( this );
61
    fixed_timer->start( 150 /* milliseconds */ );
zorglub's avatar
zorglub committed
62 63

    menusMapper = new QSignalMapper();
zorglub's avatar
zorglub committed
64
    CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
zorglub's avatar
zorglub committed
65

66
    menusUpdateMapper = new QSignalMapper();
zorglub's avatar
zorglub committed
67 68
    CONNECT( menusUpdateMapper, mapped(QObject *),
             this, menuUpdateAction( QObject *) );
zorglub's avatar
zorglub committed
69 70 71

    SDMapper = new QSignalMapper();
    CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
zorglub's avatar
zorglub committed
72
}
zorglub's avatar
zorglub committed
73

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

87
    fixed_timer->stop();
ivoire's avatar
ivoire committed
88 89 90
    delete menusMapper;
    delete menusUpdateMapper;
    delete SDMapper;
zorglub's avatar
zorglub committed
91 92
}

zorglub's avatar
zorglub committed
93 94
void DialogsProvider::quit()
{
95
    vlc_object_kill( p_intf->p_libvlc );
96
    QApplication::closeAllWindows();
zorglub's avatar
zorglub committed
97 98 99
    QApplication::quit();
}

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

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

zorglub's avatar
zorglub committed
170 171 172 173
void DialogsProvider::prefsDialog()
{
    PrefsDialog::getInstance( p_intf )->toggleVisible();
}
174

zorglub's avatar
zorglub committed
175 176 177 178 179 180 181 182 183 184
void DialogsProvider::extendedDialog()
{
    ExtendedDialog::getInstance( p_intf )->toggleVisible();
}

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

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

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

zorglub's avatar
zorglub committed
197 198 199 200 201
void DialogsProvider::helpDialog()
{
    HelpDialog::getInstance( p_intf )->toggleVisible();
}

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

zorglub's avatar
zorglub committed
209 210 211 212 213 214 215 216 217 218
void DialogsProvider::aboutDialog()
{
    AboutDialog::getInstance( p_intf )->toggleVisible();
}

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

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

zorglub's avatar
zorglub committed
224 225
void DialogsProvider::bookmarksDialog()
{
226
    BookmarksDialog::getInstance( p_intf )->toggleVisible();
zorglub's avatar
zorglub committed
227 228
}

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


zorglub's avatar
zorglub committed
235 236
/****************************************************************************
 * All the open/add stuff
237
 * Open Dialog first - Simple Open then
zorglub's avatar
zorglub committed
238 239
 ****************************************************************************/

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

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

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

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

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

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

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

/* Unimplemmented yet - Usefull ? */
336
void DialogsProvider::MLAppendDialog()
337
{}
338

339 340 341 342 343
/**
 * Simple open
 ***/
QStringList DialogsProvider::showSimpleOpen( QString help,
                                             int filters,
344
                                             QString path )
zorglub's avatar
zorglub committed
345
{
346
    QString fileTypes = "";
347
    if( filters & EXT_FILTER_MEDIA ) {
348
        ADD_FILTER_MEDIA( fileTypes );
349
    }
350
    if( filters & EXT_FILTER_VIDEO ) {
351
        ADD_FILTER_VIDEO( fileTypes );
352
    }
353
    if( filters & EXT_FILTER_AUDIO ) {
354
        ADD_FILTER_AUDIO( fileTypes );
355
    }
356
    if( filters & EXT_FILTER_PLAYLIST ) {
357
        ADD_FILTER_PLAYLIST( fileTypes );
358
    }
359
    if( filters & EXT_FILTER_SUBTITLE ) {
360 361
        ADD_FILTER_SUBTITLE( fileTypes );
    }
362
    ADD_FILTER_ALL( fileTypes );
363 364
    fileTypes.replace(QString(";*"), QString(" *"));
    return QFileDialog::getOpenFileNames( NULL,
365
        help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
366
        path.isNull() ? qfu( p_intf->p_sys->psz_filepath ) : path,
367
        fileTypes );
zorglub's avatar
zorglub committed
368 369
}

370 371 372 373 374
/**
 * Open a file,
 * pl helps you to choose from playlist or media library,
 * go to start or enqueue
 **/
zorglub's avatar
zorglub committed
375 376 377 378 379
void DialogsProvider::addFromSimple( bool pl, bool go)
{
    QStringList files = DialogsProvider::showSimpleOpen();
    int i = 0;
    foreach( QString file, files )
zorglub's avatar
zorglub committed
380
    {
zorglub's avatar
zorglub committed
381 382 383 384 385 386
        const char * psz_utf8 = qtu( file );
        playlist_Add( THEPL, psz_utf8, NULL,
                      go ? ( PLAYLIST_APPEND | ( i ? 0 : PLAYLIST_GO ) |
                                               ( i ? PLAYLIST_PREPARSE : 0 ) )
                         : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
                      PLAYLIST_END,
387
                      pl ? true : false, false );
zorglub's avatar
zorglub committed
388
        i++;
zorglub's avatar
zorglub committed
389 390 391
    }
}

392 393 394 395 396
void DialogsProvider::simpleOpenDialog()
{
    addFromSimple( true, true ); /* Playlist and Go */
}

zorglub's avatar
zorglub committed
397
void DialogsProvider::simplePLAppendDialog()
zorglub's avatar
zorglub committed
398
{
zorglub's avatar
zorglub committed
399
    addFromSimple( true, false );
zorglub's avatar
zorglub committed
400 401
}

zorglub's avatar
zorglub committed
402
void DialogsProvider::simpleMLAppendDialog()
zorglub's avatar
zorglub committed
403
{
zorglub's avatar
zorglub committed
404 405 406
    addFromSimple( false, false );
}

407 408 409 410 411 412
/* Directory */
/**
 * Open a directory,
 * pl helps you to choose from playlist or media library,
 * go to start or enqueue
 **/
413
static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
414
{
415
    QString dir = QFileDialog::getExistingDirectory( 0, qtr("Open Directory") );
416
    if (!dir.isEmpty()) {
417
        input_item_t *p_input = input_item_NewExt( THEPL,
418 419
                                        qtu( "directory://" + dir ), NULL,
                                        0, NULL, -1 );
420

421
        /* FIXME: playlist_AddInput() can fail */
422 423
        playlist_AddInput( THEPL, p_input,
                       go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
ivoire's avatar
ivoire committed
424
                       PLAYLIST_END, pl, pl_Unlocked );
425
        input_Read( THEPL, p_input, false );
426
        vlc_gc_decref( p_input );
427 428 429 430 431
    }
}

void DialogsProvider::PLAppendDir()
{
432
    openDirectory( p_intf, true, false );
433 434 435 436 437 438 439
}

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

440 441 442
/****************
 * Playlist     *
 ****************/
443
void DialogsProvider::openAPlaylist()
zorglub's avatar
zorglub committed
444
{
445 446
    QStringList files = showSimpleOpen( qtr( "Open playlist file" ),
                                        EXT_FILTER_PLAYLIST );
zorglub's avatar
zorglub committed
447 448 449 450 451 452
    foreach( QString file, files )
    {
        playlist_Import( THEPL, qtu(file) );
    }
}

453
void DialogsProvider::saveAPlaylist()
zorglub's avatar
zorglub committed
454 455
{
    QFileDialog *qfd = new QFileDialog( NULL,
456
                                   qtr( "Choose a filename to save playlist" ),
457
                                   qfu( p_intf->p_sys->psz_filepath ),
458 459
                                   qtr( "XSPF playlist (*.xspf);; " ) +
                                   qtr( "M3U playlist (*.m3u);; Any (*.*) " ) );
zorglub's avatar
zorglub committed
460 461 462 463 464 465 466 467
    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
468
            static const char psz_xspf[] = "export-xspf",
Rafaël Carré's avatar
Rafaël Carré committed
469
                              psz_m3u[] = "export-m3u";
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
470
            const char *psz_module;
zorglub's avatar
zorglub committed
471 472 473 474

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

475 476
            if( file.contains( ".xsp" ) ||
                ( filter.contains( ".xspf" ) && !file.contains( ".m3u" ) ) )
zorglub's avatar
zorglub committed
477 478 479 480 481 482 483 484 485 486 487 488
            {
                psz_module = psz_xspf;
                if( !file.contains( ".xsp" ) )
                    file.append( ".xspf" );
            }
            else
            {
                psz_module = psz_m3u;
                if( !file.contains( ".m3u" ) )
                    file.append( ".m3u" );
            }

489
            playlist_Export( THEPL, qtu( file ), THEPL->p_local_category,
zorglub's avatar
zorglub committed
490 491 492 493 494 495 496 497 498 499 500
                             psz_module);
        }
    }
    delete qfd;
}


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

501 502
void DialogsProvider::streamingDialog( QWidget *parent, QString mrl,
                                       bool b_transcode_only )
503
{
504 505
    SoutDialog *s = SoutDialog::getInstance( parent, p_intf, b_transcode_only );

506 507
    if( s->exec() == QDialog::Accepted )
    {
508
        msg_Dbg( p_intf, "Sout mrl %s", qta( s->getMrl() ) );
509
        /* Just do it */
510
        int i_len = strlen( qtu( s->getMrl() ) ) + 10;
511
        char *psz_option = (char*)malloc( i_len );
512
        snprintf( psz_option, i_len - 1, "%s", qtu( s->getMrl() ) );
513 514 515

        playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
                         PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
ivoire's avatar
ivoire committed
516
                        -1, &psz_option, 1, true, pl_Unlocked );
517 518 519 520 521
    }
}

void DialogsProvider::openThenStreamingDialogs()
{
522 523
    OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM )
                                ->showTab( OPEN_FILE_TAB );
524 525 526 527
}

void DialogsProvider::openThenTranscodingDialogs()
{
528 529
    OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE )
                                ->showTab( OPEN_FILE_TAB );
530 531
}

zorglub's avatar
zorglub committed
532 533 534
/****************************************************************************
 * Menus / Interaction
 ****************************************************************************/
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
535

zorglub's avatar
zorglub committed
536 537 538 539 540
void DialogsProvider::menuAction( QObject *data )
{
    QVLCMenu::DoAction( p_intf, data );
}

541 542 543 544 545 546
void DialogsProvider::menuUpdateAction( QObject *data )
{
    MenuFunc * f = qobject_cast<MenuFunc *>(data);
    f->doFunc( p_intf );
}

zorglub's avatar
zorglub committed
547 548
void DialogsProvider::SDMenuAction( QString data )
{
549
    char *psz_sd = strdup( qtu( data ) );
zorglub's avatar
zorglub committed
550 551 552 553
    if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
        playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
    else
        playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
554
    free( psz_sd );
zorglub's avatar
zorglub committed
555 556
}

zorglub's avatar
zorglub committed
557
void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg )
zorglub's avatar
zorglub committed
558
{
zorglub's avatar
zorglub committed
559 560 561
    InteractionDialog *qdialog;
    interaction_dialog_t *p_dialog = p_arg->p_dialog;
    switch( p_dialog->i_action )
zorglub's avatar
zorglub committed
562
    {
zorglub's avatar
zorglub committed
563 564 565 566 567 568 569 570
    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);
ivoire's avatar
ivoire committed
571
        if( qdialog )
zorglub's avatar
zorglub committed
572
            qdialog->update();
573 574 575 576 577 578 579 580 581 582 583
        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();
        }
zorglub's avatar
zorglub committed
584 585
        break;
    case INTERACT_HIDE:
586
        msg_Dbg( p_intf, "Hide the Interaction Dialog" );
zorglub's avatar
zorglub committed
587 588 589 590 591 592
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( qdialog )
            qdialog->hide();
        p_dialog->i_status = HIDDEN_DIALOG;
        break;
    case INTERACT_DESTROY:
593
        msg_Dbg( p_intf, "Destroy the Interaction Dialog" );
zorglub's avatar
zorglub committed
594 595 596 597 598
        qdialog = (InteractionDialog*)(p_dialog->p_private);
        if( !p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
            delete qdialog;
        p_dialog->i_status = DESTROYED_DIALOG;
        break;
zorglub's avatar
zorglub committed
599 600
    }
}
601 602 603

void DialogsProvider::loadSubtitlesFile()
{
604 605
    input_thread_t *p_input = THEMIM->getInput();
    if( !p_input )
606
        return;
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
    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 file" ),
                                      EXT_FILTER_SUBTITLE,
                                      path );
    free( path );
    QString qsFile;
    foreach( qsFile, qsl )
    {
        if( !input_AddSubtitles( p_input, qtu( qsFile ), true ) )
            msg_Warn( p_intf, "unable to load subtitles from '%s'",
                      qtu( qsFile ) );
    }
627
}