]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs_provider.cpp
Qt: use DIR_SEP for BDMV and VIDEO_TS detection
[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     EpgDialog::killInstance();
101
102     delete menusMapper;
103     delete menusUpdateMapper;
104     delete SDMapper;
105
106     VLCMenuBar::PopupMenu( p_intf, false );
107     VLCMenuBar::AudioPopupMenu( p_intf, false );
108     VLCMenuBar::VideoPopupMenu( p_intf, false );
109     VLCMenuBar::MiscPopupMenu( p_intf, false );
110 }
111
112 void DialogsProvider::quit()
113 {
114     b_isDying = true;
115     libvlc_Quit( p_intf->p_libvlc );
116 }
117
118 void DialogsProvider::customEvent( QEvent *event )
119 {
120     if( event->type() == DialogEvent::DialogEvent_Type )
121     {
122         DialogEvent *de = static_cast<DialogEvent*>(event);
123         switch( de->i_dialog )
124         {
125         case INTF_DIALOG_FILE_SIMPLE:
126         case INTF_DIALOG_FILE:
127             openDialog(); break;
128         case INTF_DIALOG_FILE_GENERIC:
129             openFileGenericDialog( de->p_arg ); break;
130         case INTF_DIALOG_DISC:
131             openDiscDialog(); break;
132         case INTF_DIALOG_NET:
133             openNetDialog(); break;
134         case INTF_DIALOG_SAT:
135         case INTF_DIALOG_CAPTURE:
136             openCaptureDialog(); break;
137         case INTF_DIALOG_DIRECTORY:
138             PLAppendDir(); break;
139         case INTF_DIALOG_PLAYLIST:
140             playlistDialog(); break;
141         case INTF_DIALOG_MESSAGES:
142             messagesDialog(); break;
143         case INTF_DIALOG_FILEINFO:
144            mediaInfoDialog(); break;
145         case INTF_DIALOG_PREFS:
146            prefsDialog(); break;
147         case INTF_DIALOG_BOOKMARKS:
148            bookmarksDialog(); break;
149         case INTF_DIALOG_EXTENDED:
150            extendedDialog(); break;
151 #ifdef ENABLE_VLM
152         case INTF_DIALOG_VLM:
153            vlmDialog(); break;
154 #endif
155         case INTF_DIALOG_POPUPMENU:
156            VLCMenuBar::PopupMenu( p_intf, (de->i_arg != 0) ); break;
157         case INTF_DIALOG_AUDIOPOPUPMENU:
158            VLCMenuBar::AudioPopupMenu( p_intf, (de->i_arg != 0) ); break;
159         case INTF_DIALOG_VIDEOPOPUPMENU:
160            VLCMenuBar::VideoPopupMenu( p_intf, (de->i_arg != 0) ); break;
161         case INTF_DIALOG_MISCPOPUPMENU:
162            VLCMenuBar::MiscPopupMenu( p_intf, (de->i_arg != 0) ); break;
163         case INTF_DIALOG_WIZARD:
164         case INTF_DIALOG_STREAMWIZARD:
165             openAndStreamingDialogs(); break;
166 #ifdef UPDATE_CHECK
167         case INTF_DIALOG_UPDATEVLC:
168             updateDialog(); break;
169 #endif
170         case INTF_DIALOG_EXIT:
171             quit(); break;
172         default:
173            msg_Warn( p_intf, "unimplemented dialog" );
174         }
175     }
176 }
177
178 /****************************************************************************
179  * Individual simple dialogs
180  ****************************************************************************/
181 const QEvent::Type DialogEvent::DialogEvent_Type =
182         (QEvent::Type)QEvent::registerEventType();
183
184 void DialogsProvider::playlistDialog()
185 {
186     PlaylistDialog::getInstance( p_intf )->toggleVisible();
187 }
188
189 void DialogsProvider::prefsDialog()
190 {
191     PrefsDialog *p = new PrefsDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
192     p->toggleVisible();
193 }
194
195 void DialogsProvider::extendedDialog()
196 {
197     ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
198
199     if( !extDialog->isVisible() || /* Hidden */
200         extDialog->currentTab() != 0 )  /* wrong tab */
201         extDialog->showTab( 0 );
202     else
203         extDialog->hide();
204 }
205
206 void DialogsProvider::synchroDialog()
207 {
208     ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
209
210     if( !extDialog->isVisible() || /* Hidden */
211         extDialog->currentTab() != 2 )  /* wrong tab */
212         extDialog->showTab( 2 );
213     else
214         extDialog->hide();
215 }
216
217 void DialogsProvider::messagesDialog()
218 {
219     MessagesDialog::getInstance( p_intf )->toggleVisible();
220 }
221
222 void DialogsProvider::gotoTimeDialog()
223 {
224     GotoTimeDialog::getInstance( p_intf )->toggleVisible();
225 }
226
227 #ifdef ENABLE_VLM
228 void DialogsProvider::vlmDialog()
229 {
230     VLMDialog::getInstance( p_intf )->toggleVisible();
231 }
232 #endif
233
234 void DialogsProvider::helpDialog()
235 {
236     HelpDialog::getInstance( p_intf )->toggleVisible();
237 }
238
239 #ifdef UPDATE_CHECK
240 void DialogsProvider::updateDialog()
241 {
242     UpdateDialog::getInstance( p_intf )->toggleVisible();
243 }
244 #endif
245
246 void DialogsProvider::aboutDialog()
247 {
248     AboutDialog::getInstance( p_intf )->toggleVisible();
249 }
250
251 void DialogsProvider::mediaInfoDialog()
252 {
253     MediaInfoDialog::getInstance( p_intf )->showTab( MediaInfoDialog::META_PANEL );
254 }
255
256 void DialogsProvider::mediaCodecDialog()
257 {
258     MediaInfoDialog::getInstance( p_intf )->showTab( MediaInfoDialog::INFO_PANEL );
259 }
260
261 void DialogsProvider::bookmarksDialog()
262 {
263     BookmarksDialog::getInstance( p_intf )->toggleVisible();
264 }
265
266 void DialogsProvider::podcastConfigureDialog()
267 {
268     PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
269 }
270
271 void DialogsProvider::toolbarDialog()
272 {
273     ToolbarEditDialog *toolbarEditor = new ToolbarEditDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
274     if( toolbarEditor->exec() == QDialog::Accepted )
275         emit toolBarConfUpdated();
276 }
277
278 void DialogsProvider::pluginDialog()
279 {
280     PluginDialog::getInstance( p_intf )->toggleVisible();
281 }
282
283 void DialogsProvider::epgDialog()
284 {
285     EpgDialog::getInstance( p_intf )->toggleVisible();
286 }
287
288 /* Generic open file */
289 void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
290 {
291     if( p_arg == NULL )
292     {
293         msg_Warn( p_intf, "openFileGenericDialog() called with NULL arg" );
294         return;
295     }
296
297     /* Replace the extensions to a Qt format */
298     int i = 0;
299     QString extensions = qfu( p_arg->psz_extensions );
300     while ( ( i = extensions.indexOf( "|", i ) ) != -1 )
301     {
302         if( ( extensions.count( "|" ) % 2 ) == 0 )
303             extensions.replace( i, 1, ");;" );
304         else
305             extensions.replace( i, 1, "(" );
306     }
307     extensions.replace( ";*", " *" );
308     extensions.append( ")" );
309
310     /* Save */
311     if( p_arg->b_save )
312     {
313         QString file = QFileDialog::getSaveFileName( NULL, p_arg->psz_title,
314                                         p_intf->p_sys->filepath, extensions );
315         if( !file.isEmpty() )
316         {
317             p_arg->i_results = 1;
318             p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
319             p_arg->psz_results[0] = strdup( qtu( toNativeSepNoSlash( file ) ) );
320         }
321         else
322             p_arg->i_results = 0;
323     }
324     else /* non-save mode */
325     {
326         QStringList files = QFileDialog::getOpenFileNames( NULL,
327                 p_arg->psz_title, p_intf->p_sys->filepath,
328                 extensions );
329         p_arg->i_results = files.count();
330         p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
331         i = 0;
332         foreach( const QString &file, files )
333             p_arg->psz_results[i++] = strdup( qtu( toNativeSepNoSlash( file ) ) );
334         if(i == 0)
335             p_intf->p_sys->filepath = QString::fromLatin1("");
336         else
337             p_intf->p_sys->filepath = qfu( p_arg->psz_results[i-1] );
338     }
339
340     /* Callback */
341     if( p_arg->pf_callback )
342         p_arg->pf_callback( p_arg );
343
344     /* Clean afterwards */
345     if( p_arg->psz_results )
346     {
347         for( i = 0; i < p_arg->i_results; i++ )
348             free( p_arg->psz_results[i] );
349         free( p_arg->psz_results );
350     }
351     free( p_arg->psz_title );
352     free( p_arg->psz_extensions );
353     free( p_arg );
354 }
355 /****************************************************************************
356  * All the open/add stuff
357  * Open Dialog first - Simple Open then
358  ****************************************************************************/
359
360 void DialogsProvider::openDialog( int i_tab )
361 {
362     OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
363 }
364 void DialogsProvider::openDialog()
365 {
366     openDialog( OPEN_FILE_TAB );
367 }
368 void DialogsProvider::openFileDialog()
369 {
370     openDialog( OPEN_FILE_TAB );
371 }
372 void DialogsProvider::openDiscDialog()
373 {
374     openDialog( OPEN_DISC_TAB );
375 }
376 void DialogsProvider::openNetDialog()
377 {
378     openDialog( OPEN_NETWORK_TAB );
379 }
380 void DialogsProvider::openCaptureDialog()
381 {
382     openDialog( OPEN_CAPTURE_TAB );
383 }
384
385 /* Same as the open one, but force the enqueue */
386 void DialogsProvider::PLAppendDialog( int tab )
387 {
388     OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
389                              OPEN_AND_ENQUEUE )->showTab( tab );
390 }
391
392 void DialogsProvider::MLAppendDialog( int tab )
393 {
394     OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
395                             OPEN_AND_ENQUEUE, false, false )
396                                     ->showTab( tab );
397 }
398
399 /**
400  * Simple open
401  ***/
402 QStringList DialogsProvider::showSimpleOpen( const QString& help,
403                                              int filters,
404                                              const QString& path )
405 {
406     QString fileTypes = "";
407     if( filters & EXT_FILTER_MEDIA ) {
408         ADD_EXT_FILTER( fileTypes, EXTENSIONS_MEDIA );
409     }
410     if( filters & EXT_FILTER_VIDEO ) {
411         ADD_EXT_FILTER( fileTypes, EXTENSIONS_VIDEO );
412     }
413     if( filters & EXT_FILTER_AUDIO ) {
414         ADD_EXT_FILTER( fileTypes, EXTENSIONS_AUDIO );
415     }
416     if( filters & EXT_FILTER_PLAYLIST ) {
417         ADD_EXT_FILTER( fileTypes, EXTENSIONS_PLAYLIST );
418     }
419     if( filters & EXT_FILTER_SUBTITLE ) {
420         ADD_EXT_FILTER( fileTypes, EXTENSIONS_SUBTITLE );
421     }
422     ADD_EXT_FILTER( fileTypes, EXTENSIONS_ALL );
423     fileTypes.replace( ";*", " *");
424
425     QStringList files = QFileDialog::getOpenFileNames( NULL,
426         help.isEmpty() ? qtr(I_OP_SEL_FILES ) : help,
427         path.isEmpty() ? p_intf->p_sys->filepath : path,
428         fileTypes );
429
430     if( !files.isEmpty() ) savedirpathFromFile( files.last() );
431
432     return files;
433 }
434
435 /**
436  * Open a file,
437  * pl helps you to choose from playlist or media library,
438  * go to start or enqueue
439  **/
440 void DialogsProvider::addFromSimple( bool pl, bool go)
441 {
442     QStringList files = DialogsProvider::showSimpleOpen();
443     int mode = go ? PLAYLIST_GO : PLAYLIST_PREPARSE;
444
445     files.sort();
446     foreach( const QString &file, files )
447     {
448         QString url = toURI( toNativeSeparators( file ) );
449         playlist_Add( THEPL, qtu( url ), NULL, PLAYLIST_APPEND | mode,
450                       PLAYLIST_END, pl, pl_Unlocked );
451         RecentsMRL::getInstance( p_intf )->addRecent( url );
452         mode = PLAYLIST_PREPARSE;
453     }
454 }
455
456 void DialogsProvider::simpleOpenDialog()
457 {
458     addFromSimple( true, true ); /* Playlist and Go */
459 }
460
461 /* Url & Clipboard */
462 /**
463  * Open a MRL.
464  * If the clipboard contains URLs, the first is automatically 'preselected'.
465  **/
466 void DialogsProvider::openUrlDialog()
467 {
468     OpenUrlDialog oud( p_intf );
469     if( oud.exec() != QDialog::Accepted )
470         return;
471
472     QString url = oud.url();
473     if( url.isEmpty() )
474         return;
475
476     if( !url.contains( qfu( "://" ) ) )
477     {
478         char *uri = vlc_path2uri( qtu( url ), NULL );
479         if( uri == NULL )
480             return;
481         url = qfu(uri);
482         free( uri );
483     }
484     playlist_Add( THEPL, qtu(url), NULL,
485                   !oud.shouldEnqueue() ? ( PLAYLIST_APPEND | PLAYLIST_GO )
486                                      : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
487                   PLAYLIST_END, true, false );
488     RecentsMRL::getInstance( p_intf )->addRecent( url );
489 }
490
491 /* Directory */
492 /**
493  * Open a directory,
494  * pl helps you to choose from playlist or media library,
495  * go to start or enqueue
496  **/
497 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
498 {
499     QString dir = QFileDialog::getExistingDirectory( NULL, qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath );
500
501     if( dir.isEmpty() )
502         return;
503
504     p_intf->p_sys->filepath = dir;
505
506     const char *scheme = "directory";
507     if( dir.endsWith( DIR_SEP "VIDEO_TS", Qt::CaseInsensitive ) )
508         scheme = "dvd";
509     else if( dir.endsWith( DIR_SEP "BDMV", Qt::CaseInsensitive ) )
510     {
511         scheme = "bluray";
512         dir.remove( "BDMV" );
513     }
514
515     char *uri = vlc_path2uri( qtu( toNativeSeparators( dir ) ), scheme );
516     if( unlikely(uri == NULL) )
517         return;
518
519     RecentsMRL::getInstance( p_intf )->addRecent( qfu(uri) );
520
521     input_item_t *p_input = input_item_New( uri, NULL );
522     free( uri );
523     if( unlikely( p_input == NULL ) )
524         return;
525
526     /* FIXME: playlist_AddInput() can fail */
527     playlist_AddInput( THEPL, p_input,
528                        go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
529                        PLAYLIST_END, pl, pl_Unlocked );
530     vlc_gc_decref( p_input );
531 }
532
533 QString DialogsProvider::getDirectoryDialog()
534 {
535     QString dir = QFileDialog::getExistingDirectory( NULL, qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath );
536
537     if( dir.isEmpty() ) return QString();
538
539     p_intf->p_sys->filepath = dir;
540
541     const char *scheme = "directory";
542     if( dir.endsWith( DIR_SEP "VIDEO_TS", Qt::CaseInsensitive ) )
543         scheme = "dvd";
544     else if( dir.endsWith( DIR_SEP "BDMV", Qt::CaseInsensitive ) )
545     {
546         scheme = "bluray";
547         dir.remove( "BDMV" );
548     }
549
550     char *uri = vlc_path2uri( qtu( toNativeSeparators( dir ) ), scheme );
551     if( unlikely(uri == NULL) ) return QString();
552     dir = qfu( uri );
553     free( uri );
554
555     RecentsMRL::getInstance( p_intf )->addRecent( dir );
556
557     return dir;
558 }
559
560 void DialogsProvider::PLOpenDir()
561 {
562     openDirectory( p_intf, true, true );
563 }
564
565 void DialogsProvider::PLAppendDir()
566 {
567     openDirectory( p_intf, true, false );
568 }
569
570 /****************
571  * Playlist     *
572  ****************/
573 void DialogsProvider::openAPlaylist()
574 {
575     QStringList files = showSimpleOpen( qtr( "Open playlist..." ),
576                                         EXT_FILTER_PLAYLIST );
577     foreach( const QString &file, files )
578     {
579         playlist_Import( THEPL, qtu( toNativeSeparators( file ) ) );
580     }
581 }
582
583 void DialogsProvider::saveAPlaylist(playlist_t *p_playlist, playlist_item_t *p_node)
584 {
585     static const struct
586     {
587         char filter_name[14];
588         char filter_patterns[5];
589         char module[12];
590     } types[] = {
591         { N_("XSPF playlist"), "xspf", "export-xspf", },
592         { N_("M3U playlist"),  "m3u",  "export-m3u", },
593         { N_("M3U8 playlist"), "m3u8", "export-m3u8", },
594         { N_("HTML playlist"), "html", "export-html", },
595     };
596
597     QStringList filters;
598     QString ext = getSettings()->value( "last-playlist-ext" ).toString();
599
600     for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++ )
601     {
602         QString tmp = qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + types[i].filter_patterns + ")";
603         if( ext == qfu( types[i].filter_patterns ) )
604             filters.insert( 0, tmp );
605         else
606             filters.append( tmp );
607     }
608
609     QString selected;
610     QString file = QFileDialog::getSaveFileName( NULL,
611                                                  qtr( "Save playlist as..." ),
612                                                  p_intf->p_sys->filepath, filters.join( ";;" ),
613                                                  &selected );
614     const char *psz_selected_module = NULL;
615     const char *psz_last_playlist_ext = NULL;
616
617     if( file.isEmpty() )
618         return;
619
620     /* First test if the file extension is set, and different to selected filter */
621     for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
622     {
623         if ( file.endsWith( QString( "." ) + qfu( types[i].filter_patterns ) ) )
624         {
625             psz_selected_module = types[i].module;
626             psz_last_playlist_ext = types[i].filter_patterns;
627             break;
628         }
629     }
630
631     /* otherwise apply the selected extension */
632     if ( !psz_last_playlist_ext )
633     {
634         for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
635         {
636             if ( selected.startsWith( qfu( vlc_gettext( types[i].filter_name ) ) ) )
637             {
638                 psz_selected_module = types[i].module;
639                 psz_last_playlist_ext = types[i].filter_patterns;
640                 /* Fix file extension */
641                 file = file.append( QString( "." ) + qfu( psz_last_playlist_ext ) );
642                 break;
643             }
644         }
645     }
646
647     if ( psz_selected_module )
648     {
649         playlist_Export( p_playlist, qtu( toNativeSeparators( file ) ),
650                          p_node, psz_selected_module );
651         getSettings()->setValue( "last-playlist-ext", psz_last_playlist_ext );
652     }
653 }
654
655 void DialogsProvider::savePlayingToPlaylist()
656 {
657     saveAPlaylist(THEPL, THEPL->p_playing);
658 }
659
660 void DialogsProvider::saveRecentsToPlaylist()
661 {
662     playlist_item_t *p_node_recents = RecentsMRL::getInstance(p_intf)->toPlaylist(0);
663
664     if (p_node_recents == NULL)
665     {
666         msg_Warn(p_intf, "cannot create playlist from recents");
667         return;
668     }
669
670     saveAPlaylist(THEPL, p_node_recents);
671     playlist_NodeDelete(THEPL, p_node_recents, true, false);
672 }
673
674 /****************************************************************************
675  * Sout emulation
676  ****************************************************************************/
677
678 void DialogsProvider::streamingDialog( QWidget *parent,
679                                        const QString& mrl,
680                                        bool b_transcode_only,
681                                        QStringList options )
682 {
683     QString soutoption;
684
685     /* Stream */
686     if( !b_transcode_only )
687     {
688         SoutDialog *s = new SoutDialog( parent, p_intf, mrl );
689         s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
690         if( s->exec() == QDialog::Accepted )
691         {
692             soutoption = s->getMrl();
693             delete s;
694         }
695         else
696         {
697             delete s; return;
698         }
699     } else {
700     /* Convert */
701         ConvertDialog *s = new ConvertDialog( parent, p_intf, mrl );
702         s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
703         if( s->exec() == QDialog::Accepted )
704         {
705             soutoption = s->getMrl();
706             delete s;
707         }
708         else
709         {
710             delete s; return;
711         }
712     }
713
714     /* Get SoutMRL */
715     if( !soutoption.isEmpty() )
716     {
717         options += soutoption.split( " :");
718
719         /* Create Input */
720         input_item_t *p_input;
721         p_input = input_item_New( qtu( mrl ), _("Streaming") );
722
723         /* Add normal Options */
724         for( int j = 0; j < options.count(); j++ )
725         {
726             QString qs = colon_unescape( options[j] );
727             if( !qs.isEmpty() )
728             {
729                 input_item_AddOption( p_input, qtu( qs ),
730                         VLC_INPUT_OPTION_TRUSTED );
731                 msg_Dbg( p_intf, "Adding option: %s", qtu( qs ) );
732             }
733         }
734
735         /* Switch between enqueuing and starting the item */
736         /* FIXME: playlist_AddInput() can fail */
737         playlist_AddInput( THEPL, p_input,
738                 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true, pl_Unlocked );
739         vlc_gc_decref( p_input );
740
741         RecentsMRL::getInstance( p_intf )->addRecent( mrl );
742     }
743 }
744
745 void DialogsProvider::openAndStreamingDialogs()
746 {
747     OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM )
748                                 ->showTab( OPEN_FILE_TAB );
749 }
750
751 void DialogsProvider::openAndTranscodingDialogs()
752 {
753     OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE )
754                                 ->showTab( OPEN_FILE_TAB );
755 }
756
757 void DialogsProvider::loadSubtitlesFile()
758 {
759     input_thread_t *p_input = THEMIM->getInput();
760     if( !p_input ) return;
761
762     input_item_t *p_item = input_GetItem( p_input );
763     if( !p_item ) return;
764
765     char *path = input_item_GetURI( p_item );
766     char *path2 = NULL;
767     if( path )
768     {
769         path2 = make_path( path );
770         free( path );
771         if( path2 )
772         {
773             char *sep = strrchr( path2, DIR_SEP_CHAR );
774             if( sep ) *sep = '\0';
775         }
776     }
777
778     QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ),
779                                       EXT_FILTER_SUBTITLE,
780                                       qfu( path2 ) );
781     free( path2 );
782     foreach( const QString &qsFile, qsl )
783     {
784         if( input_AddSubtitle( p_input, qtu( toNativeSeparators( qsFile ) ),
785                     true ) )
786             msg_Warn( p_intf, "unable to load subtitles from '%s'",
787                       qtu( qsFile ) );
788     }
789 }
790
791
792 /****************************************************************************
793  * Menus
794  ****************************************************************************/
795
796 void DialogsProvider::menuAction( QObject *data )
797 {
798     VLCMenuBar::DoAction( data );
799 }
800
801 void DialogsProvider::menuUpdateAction( QObject *data )
802 {
803     MenuFunc *func = qobject_cast<MenuFunc *>(data);
804     assert( func );
805     func->doFunc( p_intf );
806 }
807
808 void DialogsProvider::SDMenuAction( const QString& data )
809 {
810     if( !playlist_IsServicesDiscoveryLoaded( THEPL, qtu( data ) ) )
811         playlist_ServicesDiscoveryAdd( THEPL, qtu( data ) );
812     else
813         playlist_ServicesDiscoveryRemove( THEPL, qtu( data ) );
814 }
815
816 /**
817  * Play the MRL contained in the Recently played menu.
818  **/
819 void DialogsProvider::playMRL( const QString &mrl )
820 {
821     playlist_Add( THEPL, qtu(mrl), NULL,
822                   PLAYLIST_APPEND | PLAYLIST_GO , PLAYLIST_END, true, false );
823     RecentsMRL::getInstance( p_intf )->addRecent( mrl );
824 }