]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs_provider.cpp
Qt: Tell users about the delete key
[vlc] / modules / gui / qt4 / dialogs_provider.cpp
1 /*****************************************************************************
2  * dialogs_provider.cpp : Dialog Provider
3  *****************************************************************************
4  * Copyright (C) 2006-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_intf_strings.h>
30
31 #include "qt4.hpp"
32 #include "dialogs_provider.hpp"
33 #include "input_manager.hpp" /* Load Subtitles */
34 #include "menus.hpp"
35 #include "recents.hpp"
36 #include "util/qt_dirs.hpp"
37 #include "main_interface.hpp"
38
39 /* The dialogs */
40 #include "dialogs/playlist.hpp"
41 #include "dialogs/bookmarks.hpp"
42 #include "dialogs/preferences.hpp"
43 #include "dialogs/mediainfo.hpp"
44 #include "dialogs/messages.hpp"
45 #include "dialogs/extended.hpp"
46 #include "dialogs/vlm.hpp"
47 #include "dialogs/sout.hpp"
48 #include "dialogs/convert.hpp"
49 #include "dialogs/open.hpp"
50 #include "dialogs/openurl.hpp"
51 #include "dialogs/help.hpp"
52 #include "dialogs/gototime.hpp"
53 #include "dialogs/podcast_configuration.hpp"
54 #include "dialogs/toolbar.hpp"
55 #include "dialogs/plugins.hpp"
56 #include "dialogs/external.hpp"
57 #include "dialogs/epg.hpp"
58 #include "dialogs/errors.hpp"
59
60 #include <QEvent>
61 #include <QApplication>
62 #include <QSignalMapper>
63 #include <QFileDialog>
64
65 #define I_OP_DIR_WINTITLE I_DIR_OR_FOLDER( N_("Open Directory"), \
66                                            N_("Open Folder") )
67
68 DialogsProvider* DialogsProvider::instance = NULL;
69
70 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
71                                   QObject( NULL ), p_intf( _p_intf )
72 {
73     b_isDying = false;
74
75     /* Various signal mappers for the menus */
76     menusMapper = new QSignalMapper();
77     CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
78
79     menusUpdateMapper = new QSignalMapper();
80     CONNECT( menusUpdateMapper, mapped(QObject *),
81              this, menuUpdateAction( QObject *) );
82
83     SDMapper = new QSignalMapper();
84     CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
85
86     new DialogHandler (p_intf, this );
87 }
88
89 DialogsProvider::~DialogsProvider()
90 {
91     PlaylistDialog::killInstance();
92     MediaInfoDialog::killInstance();
93     MessagesDialog::killInstance();
94     BookmarksDialog::killInstance();
95     HelpDialog::killInstance();
96 #ifdef UPDATE_CHECK
97     UpdateDialog::killInstance();
98 #endif
99     PluginDialog::killInstance();
100
101     delete menusMapper;
102     delete menusUpdateMapper;
103     delete SDMapper;
104
105     VLCMenuBar::PopupMenu( p_intf, false );
106     VLCMenuBar::AudioPopupMenu( p_intf, false );
107     VLCMenuBar::VideoPopupMenu( p_intf, false );
108     VLCMenuBar::MiscPopupMenu( p_intf, false );
109 }
110
111 void DialogsProvider::quit()
112 {
113     b_isDying = true;
114     libvlc_Quit( p_intf->p_libvlc );
115 }
116
117 void DialogsProvider::customEvent( QEvent *event )
118 {
119     if( event->type() == (int)DialogEvent_Type )
120     {
121         DialogEvent *de = static_cast<DialogEvent*>(event);
122         switch( de->i_dialog )
123         {
124         case INTF_DIALOG_FILE_SIMPLE:
125         case INTF_DIALOG_FILE:
126             openDialog(); break;
127         case INTF_DIALOG_FILE_GENERIC:
128             openFileGenericDialog( de->p_arg ); break;
129         case INTF_DIALOG_DISC:
130             openDiscDialog(); break;
131         case INTF_DIALOG_NET:
132             openNetDialog(); break;
133         case INTF_DIALOG_SAT:
134         case INTF_DIALOG_CAPTURE:
135             openCaptureDialog(); break;
136         case INTF_DIALOG_DIRECTORY:
137             PLAppendDir(); break;
138         case INTF_DIALOG_PLAYLIST:
139             playlistDialog(); break;
140         case INTF_DIALOG_MESSAGES:
141             messagesDialog(); break;
142         case INTF_DIALOG_FILEINFO:
143            mediaInfoDialog(); break;
144         case INTF_DIALOG_PREFS:
145            prefsDialog(); break;
146         case INTF_DIALOG_BOOKMARKS:
147            bookmarksDialog(); break;
148         case INTF_DIALOG_EXTENDED:
149            extendedDialog(); break;
150 #ifdef ENABLE_VLM
151         case INTF_DIALOG_VLM:
152            vlmDialog(); break;
153 #endif
154         case INTF_DIALOG_POPUPMENU:
155            VLCMenuBar::PopupMenu( p_intf, (de->i_arg != 0) ); break;
156         case INTF_DIALOG_AUDIOPOPUPMENU:
157            VLCMenuBar::AudioPopupMenu( p_intf, (de->i_arg != 0) ); break;
158         case INTF_DIALOG_VIDEOPOPUPMENU:
159            VLCMenuBar::VideoPopupMenu( p_intf, (de->i_arg != 0) ); break;
160         case INTF_DIALOG_MISCPOPUPMENU:
161            VLCMenuBar::MiscPopupMenu( p_intf, (de->i_arg != 0) ); break;
162         case INTF_DIALOG_WIZARD:
163         case INTF_DIALOG_STREAMWIZARD:
164             openAndStreamingDialogs(); break;
165 #ifdef UPDATE_CHECK
166         case INTF_DIALOG_UPDATEVLC:
167             updateDialog(); break;
168 #endif
169         case INTF_DIALOG_EXIT:
170             quit(); break;
171         default:
172            msg_Warn( p_intf, "unimplemented dialog" );
173         }
174     }
175 }
176
177 /****************************************************************************
178  * Individual simple dialogs
179  ****************************************************************************/
180 void DialogsProvider::playlistDialog()
181 {
182     PlaylistDialog::getInstance( p_intf )->toggleVisible();
183 }
184
185 void DialogsProvider::prefsDialog()
186 {
187     PrefsDialog *p = new PrefsDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
188     p->toggleVisible();
189 }
190
191 void DialogsProvider::extendedDialog()
192 {
193     ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
194
195     if( !extDialog->isVisible() || /* Hidden */
196         extDialog->currentTab() != 0 )  /* wrong tab */
197         extDialog->showTab( 0 );
198     else
199         extDialog->hide();
200 }
201
202 void DialogsProvider::synchroDialog()
203 {
204     ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
205
206     if( !extDialog->isVisible() || /* Hidden */
207         extDialog->currentTab() != 2 )  /* wrong tab */
208         extDialog->showTab( 2 );
209     else
210         extDialog->hide();
211 }
212
213 void DialogsProvider::messagesDialog()
214 {
215     MessagesDialog::getInstance( p_intf )->toggleVisible();
216 }
217
218 void DialogsProvider::gotoTimeDialog()
219 {
220     GotoTimeDialog::getInstance( p_intf )->toggleVisible();
221 }
222
223 #ifdef ENABLE_VLM
224 void DialogsProvider::vlmDialog()
225 {
226     VLMDialog::getInstance( p_intf )->toggleVisible();
227 }
228 #endif
229
230 void DialogsProvider::helpDialog()
231 {
232     HelpDialog::getInstance( p_intf )->toggleVisible();
233 }
234
235 #ifdef UPDATE_CHECK
236 void DialogsProvider::updateDialog()
237 {
238     UpdateDialog::getInstance( p_intf )->toggleVisible();
239 }
240 #endif
241
242 void DialogsProvider::aboutDialog()
243 {
244     AboutDialog::getInstance( p_intf )->toggleVisible();
245 }
246
247 void DialogsProvider::mediaInfoDialog()
248 {
249     MediaInfoDialog::getInstance( p_intf )->showTab( 0 );
250 }
251
252 void DialogsProvider::mediaCodecDialog()
253 {
254     MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
255 }
256
257 void DialogsProvider::bookmarksDialog()
258 {
259     BookmarksDialog::getInstance( p_intf )->toggleVisible();
260 }
261
262 void DialogsProvider::podcastConfigureDialog()
263 {
264     PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
265 }
266
267 void DialogsProvider::toolbarDialog()
268 {
269     ToolbarEditDialog *toolbarEditor = new ToolbarEditDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
270     if( toolbarEditor->exec() == QDialog::Accepted )
271         emit toolBarConfUpdated();
272 }
273
274 void DialogsProvider::pluginDialog()
275 {
276     PluginDialog::getInstance( p_intf )->toggleVisible();
277 }
278
279 void DialogsProvider::epgDialog()
280 {
281     EpgDialog::getInstance( p_intf )->toggleVisible();
282 }
283
284 /* Generic open file */
285 void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
286 {
287     if( p_arg == NULL )
288     {
289         msg_Warn( p_intf, "openFileGenericDialog() called with NULL arg" );
290         return;
291     }
292
293     /* Replace the extensions to a Qt format */
294     int i = 0;
295     QString extensions = qfu( p_arg->psz_extensions );
296     while ( ( i = extensions.indexOf( "|", i ) ) != -1 )
297     {
298         if( ( extensions.count( "|" ) % 2 ) == 0 )
299             extensions.replace( i, 1, ");;" );
300         else
301             extensions.replace( i, 1, "(" );
302     }
303     extensions.replace( ";*", " *" );
304     extensions.append( ")" );
305
306     /* Save */
307     if( p_arg->b_save )
308     {
309         QString file = QFileDialog::getSaveFileName( NULL, p_arg->psz_title,
310                                         p_intf->p_sys->filepath, extensions );
311         if( !file.isEmpty() )
312         {
313             p_arg->i_results = 1;
314             p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
315             p_arg->psz_results[0] = strdup( qtu( toNativeSepNoSlash( file ) ) );
316         }
317         else
318             p_arg->i_results = 0;
319     }
320     else /* non-save mode */
321     {
322         QStringList files = QFileDialog::getOpenFileNames( NULL,
323                 p_arg->psz_title, p_intf->p_sys->filepath,
324                 extensions );
325         p_arg->i_results = files.count();
326         p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
327         i = 0;
328         foreach( const QString &file, files )
329             p_arg->psz_results[i++] = strdup( qtu( toNativeSepNoSlash( file ) ) );
330         if(i == 0)
331             p_intf->p_sys->filepath = QString::fromAscii("");
332         else
333             p_intf->p_sys->filepath = qfu( p_arg->psz_results[i-1] );
334     }
335
336     /* Callback */
337     if( p_arg->pf_callback )
338         p_arg->pf_callback( p_arg );
339
340     /* Clean afterwards */
341     if( p_arg->psz_results )
342     {
343         for( i = 0; i < p_arg->i_results; i++ )
344             free( p_arg->psz_results[i] );
345         free( p_arg->psz_results );
346     }
347     free( p_arg->psz_title );
348     free( p_arg->psz_extensions );
349     free( p_arg );
350 }
351 /****************************************************************************
352  * All the open/add stuff
353  * Open Dialog first - Simple Open then
354  ****************************************************************************/
355
356 void DialogsProvider::openDialog( int i_tab )
357 {
358     OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
359 }
360 void DialogsProvider::openDialog()
361 {
362     openDialog( OPEN_FILE_TAB );
363 }
364 void DialogsProvider::openFileDialog()
365 {
366     openDialog( OPEN_FILE_TAB );
367 }
368 void DialogsProvider::openDiscDialog()
369 {
370     openDialog( OPEN_DISC_TAB );
371 }
372 void DialogsProvider::openNetDialog()
373 {
374     openDialog( OPEN_NETWORK_TAB );
375 }
376 void DialogsProvider::openCaptureDialog()
377 {
378     openDialog( OPEN_CAPTURE_TAB );
379 }
380
381 /* Same as the open one, but force the enqueue */
382 void DialogsProvider::PLAppendDialog( int tab )
383 {
384     OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
385                              OPEN_AND_ENQUEUE )->showTab( tab );
386 }
387
388 void DialogsProvider::MLAppendDialog( int tab )
389 {
390     OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
391                             OPEN_AND_ENQUEUE, false, false )
392                                     ->showTab( tab );
393 }
394
395 /**
396  * Simple open
397  ***/
398 QStringList DialogsProvider::showSimpleOpen( const QString& help,
399                                              int filters,
400                                              const QString& path )
401 {
402     QString fileTypes = "";
403     if( filters & EXT_FILTER_MEDIA ) {
404         ADD_EXT_FILTER( fileTypes, EXTENSIONS_MEDIA );
405     }
406     if( filters & EXT_FILTER_VIDEO ) {
407         ADD_EXT_FILTER( fileTypes, EXTENSIONS_VIDEO );
408     }
409     if( filters & EXT_FILTER_AUDIO ) {
410         ADD_EXT_FILTER( fileTypes, EXTENSIONS_AUDIO );
411     }
412     if( filters & EXT_FILTER_PLAYLIST ) {
413         ADD_EXT_FILTER( fileTypes, EXTENSIONS_PLAYLIST );
414     }
415     if( filters & EXT_FILTER_SUBTITLE ) {
416         ADD_EXT_FILTER( fileTypes, EXTENSIONS_SUBTITLE );
417     }
418     ADD_EXT_FILTER( fileTypes, EXTENSIONS_ALL );
419     fileTypes.replace( ";*", " *");
420
421     QStringList files = QFileDialog::getOpenFileNames( NULL,
422         help.isEmpty() ? qtr(I_OP_SEL_FILES ) : help,
423         path.isEmpty() ? p_intf->p_sys->filepath : path,
424         fileTypes );
425
426     if( !files.isEmpty() ) savedirpathFromFile( files.last() );
427
428     return files;
429 }
430
431 /**
432  * Open a file,
433  * pl helps you to choose from playlist or media library,
434  * go to start or enqueue
435  **/
436 void DialogsProvider::addFromSimple( bool pl, bool go)
437 {
438     QStringList files = DialogsProvider::showSimpleOpen();
439     int mode = go ? PLAYLIST_GO : PLAYLIST_PREPARSE;
440
441     files.sort();
442     foreach( const QString &file, files )
443     {
444         QString url = toURI( toNativeSeparators( file ) );
445         playlist_Add( THEPL, qtu( url ), NULL, PLAYLIST_APPEND | mode,
446                       PLAYLIST_END, pl, pl_Unlocked );
447         RecentsMRL::getInstance( p_intf )->addRecent( url );
448         mode = PLAYLIST_PREPARSE;
449     }
450 }
451
452 void DialogsProvider::simpleOpenDialog()
453 {
454     addFromSimple( true, true ); /* Playlist and Go */
455 }
456
457 void DialogsProvider::simplePLAppendDialog()
458 {
459     addFromSimple( true, false );
460 }
461
462 void DialogsProvider::simpleMLAppendDialog()
463 {
464     addFromSimple( false, false );
465 }
466
467 /* Url & Clipboard */
468 /**
469  * Open a MRL.
470  * If the clipboard contains URLs, the first is automatically 'preselected'.
471  **/
472 void DialogsProvider::openUrlDialog()
473 {
474     OpenUrlDialog *oud = new OpenUrlDialog( p_intf );
475     if( oud->exec() == QDialog::Accepted )
476     {
477         QString url = oud->url();
478         if( !url.isEmpty() )
479         {
480             char *uri = make_URI( qtu( url ), NULL );
481             if( likely( uri != NULL ) )
482             {
483                 playlist_Add( THEPL, uri,
484                               NULL, !oud->shouldEnqueue() ?
485                                       ( PLAYLIST_APPEND | PLAYLIST_GO )
486                                     : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
487                               PLAYLIST_END, true, false );
488                 RecentsMRL::getInstance( p_intf )->addRecent( url );
489                 free( uri );
490             }
491         }
492     }
493     delete oud;
494 }
495
496 /* Directory */
497 /**
498  * Open a directory,
499  * pl helps you to choose from playlist or media library,
500  * go to start or enqueue
501  **/
502 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
503 {
504     QString dir = QFileDialog::getExistingDirectory( NULL, qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath );
505
506     if( dir.isEmpty() )
507         return;
508
509     p_intf->p_sys->filepath = qtu( dir );
510
511     const char *scheme = "directory";
512     if( dir.endsWith( "/VIDEO_TS", Qt::CaseInsensitive ) )
513         scheme = "dvd";
514     else if( dir.endsWith( "/BDMV", Qt::CaseInsensitive ) )
515     {
516         scheme = "bluray";
517         dir.remove( "BDMV" );
518     }
519
520     char *uri = make_URI( qtu( toNativeSeparators( dir ) ), scheme );
521     if( unlikely(uri == NULL) )
522         return;
523
524     RecentsMRL::getInstance( p_intf )->addRecent( qfu(uri) );
525
526     input_item_t *p_input = input_item_New( uri, NULL );
527     free( uri );
528     if( unlikely( p_input == NULL ) )
529         return;
530
531     /* FIXME: playlist_AddInput() can fail */
532     playlist_AddInput( THEPL, p_input,
533                        go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
534                        PLAYLIST_END, pl, pl_Unlocked );
535     vlc_gc_decref( p_input );
536 }
537
538 void DialogsProvider::PLOpenDir()
539 {
540     openDirectory( p_intf, true, true );
541 }
542
543 void DialogsProvider::PLAppendDir()
544 {
545     openDirectory( p_intf, true, false );
546 }
547
548 void DialogsProvider::MLAppendDir()
549 {
550     openDirectory( p_intf, false , false );
551 }
552
553 /****************
554  * Playlist     *
555  ****************/
556 void DialogsProvider::openAPlaylist()
557 {
558     QStringList files = showSimpleOpen( qtr( "Open playlist..." ),
559                                         EXT_FILTER_PLAYLIST );
560     foreach( const QString &file, files )
561     {
562         playlist_Import( THEPL, qtu( toNativeSeparators( file ) ) );
563     }
564 }
565
566 void DialogsProvider::saveAPlaylist()
567 {
568     static const struct
569     {
570         char filter_name[14];
571         char filter_patterns[5];
572         char module[12];
573     } types[] = {
574         { N_("XSPF playlist"), "xspf", "export-xspf", },
575         { N_("M3U playlist"),  "m3u",  "export-m3u", },
576         { N_("M3U8 playlist"), "m3u8", "export-m3u8", },
577         { N_("HTML playlist"), "html", "export-html", },
578     };
579
580     QStringList filters;
581     QString ext = getSettings()->value( "last-playlist-ext" ).toString();
582
583     for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++ )
584     {
585         QString tmp = qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + types[i].filter_patterns + ")";
586         if( ext == qfu( types[i].filter_patterns ) )
587             filters.insert( 0, tmp );
588         else
589             filters.append( tmp );
590     }
591
592     QString selected;
593     QString file = QFileDialog::getSaveFileName( NULL,
594                                   qtr( "Save playlist as..." ),
595                                   p_intf->p_sys->filepath, filters.join( ";;" ),
596                                   &selected );
597     if( file.isEmpty() )
598         return;
599
600     for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
601         if( selected == qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + qfu( types[i].filter_patterns ) + ")" )
602         {
603             playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
604                              THEPL->p_playing, types[i].module );
605             getSettings()->setValue( "last-playlist-ext", types[i].filter_patterns );
606             break;
607         }
608 }
609
610 /****************************************************************************
611  * Sout emulation
612  ****************************************************************************/
613
614 void DialogsProvider::streamingDialog( QWidget *parent,
615                                        const QString& mrl,
616                                        bool b_transcode_only,
617                                        QStringList options )
618 {
619     QString soutoption;
620
621     /* Stream */
622     if( !b_transcode_only )
623     {
624         SoutDialog *s = new SoutDialog( parent, p_intf, mrl );
625         s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
626         if( s->exec() == QDialog::Accepted )
627         {
628             soutoption = s->getMrl();
629             delete s;
630         }
631         else
632         {
633             delete s; return;
634         }
635     } else {
636     /* Convert */
637         ConvertDialog *s = new ConvertDialog( parent, p_intf, mrl );
638         s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
639         if( s->exec() == QDialog::Accepted )
640         {
641             soutoption = s->getMrl();
642             delete s;
643         }
644         else
645         {
646             delete s; return;
647         }
648     }
649
650     /* Get SoutMRL */
651     if( !soutoption.isEmpty() )
652     {
653         options += soutoption.split( " :");
654
655         /* Create Input */
656         input_item_t *p_input;
657         p_input = input_item_New( qtu( mrl ), _("Streaming") );
658
659         /* Add normal Options */
660         for( int j = 0; j < options.count(); j++ )
661         {
662             QString qs = colon_unescape( options[j] );
663             if( !qs.isEmpty() )
664             {
665                 input_item_AddOption( p_input, qtu( qs ),
666                         VLC_INPUT_OPTION_TRUSTED );
667                 msg_Dbg( p_intf, "Adding option: %s", qtu( qs ) );
668             }
669         }
670
671         /* Switch between enqueuing and starting the item */
672         /* FIXME: playlist_AddInput() can fail */
673         playlist_AddInput( THEPL, p_input,
674                 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true, pl_Unlocked );
675         vlc_gc_decref( p_input );
676
677         RecentsMRL::getInstance( p_intf )->addRecent( mrl );
678     }
679 }
680
681 void DialogsProvider::openAndStreamingDialogs()
682 {
683     OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM )
684                                 ->showTab( OPEN_FILE_TAB );
685 }
686
687 void DialogsProvider::openAndTranscodingDialogs()
688 {
689     OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE )
690                                 ->showTab( OPEN_FILE_TAB );
691 }
692
693 void DialogsProvider::loadSubtitlesFile()
694 {
695     input_thread_t *p_input = THEMIM->getInput();
696     if( !p_input ) return;
697
698     input_item_t *p_item = input_GetItem( p_input );
699     if( !p_item ) return;
700
701     char *path = input_item_GetURI( p_item );
702     char *path2 = NULL;
703     if( path )
704     {
705         path2 = make_path( path );
706         free( path );
707         if( path2 )
708         {
709             char *sep = strrchr( path2, DIR_SEP_CHAR );
710             if( sep ) *sep = '\0';
711         }
712     }
713
714     QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ),
715                                       EXT_FILTER_SUBTITLE,
716                                       qfu( path2 ) );
717     free( path2 );
718     foreach( const QString &qsFile, qsl )
719     {
720         if( input_AddSubtitle( p_input, qtu( toNativeSeparators( qsFile ) ),
721                     true ) )
722             msg_Warn( p_intf, "unable to load subtitles from '%s'",
723                       qtu( qsFile ) );
724     }
725 }
726
727
728 /****************************************************************************
729  * Menus
730  ****************************************************************************/
731
732 void DialogsProvider::menuAction( QObject *data )
733 {
734     VLCMenuBar::DoAction( data );
735 }
736
737 void DialogsProvider::menuUpdateAction( QObject *data )
738 {
739     MenuFunc *func = qobject_cast<MenuFunc *>(data);
740     assert( func );
741     func->doFunc( p_intf );
742 }
743
744 void DialogsProvider::SDMenuAction( const QString& data )
745 {
746     if( !playlist_IsServicesDiscoveryLoaded( THEPL, qtu( data ) ) )
747         playlist_ServicesDiscoveryAdd( THEPL, qtu( data ) );
748     else
749         playlist_ServicesDiscoveryRemove( THEPL, qtu( data ) );
750 }
751
752 /**
753  * Play the MRL contained in the Recently played menu.
754  **/
755 void DialogsProvider::playMRL( const QString &mrl )
756 {
757     char *uri = make_URI( qtu( mrl ), NULL );
758     if( unlikely( uri == NULL ) )
759         return;
760
761     playlist_Add( THEPL, uri, NULL,
762            PLAYLIST_APPEND | PLAYLIST_GO , PLAYLIST_END, true, false );
763     RecentsMRL::getInstance( p_intf )->addRecent( mrl );
764     free( uri );
765 }