demux: mkv: handle WAVE_FORMAT_MPEG_ADTS_AAC
[vlc.git] / modules / gui / qt / dialogs_provider.cpp
blob1e26f1f71e92613d37d7e0fa175725038594604f
1 /*****************************************************************************
2 * dialogs_provider.cpp : Dialog Provider
3 *****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
5 * $Id$
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
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.
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.
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 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <vlc_intf_strings.h>
31 #include "qt.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 "util/customwidgets.hpp" /* VLCKeyToString() */
38 #include "main_interface.hpp"
40 /* The dialogs */
41 #include "dialogs/playlist.hpp"
42 #include "dialogs/bookmarks.hpp"
43 #include "dialogs/preferences.hpp"
44 #include "dialogs/mediainfo.hpp"
45 #include "dialogs/messages.hpp"
46 #include "dialogs/extended.hpp"
47 #include "dialogs/vlm.hpp"
48 #include "dialogs/sout.hpp"
49 #include "dialogs/convert.hpp"
50 #include "dialogs/open.hpp"
51 #include "dialogs/openurl.hpp"
52 #include "dialogs/help.hpp"
53 #include "dialogs/gototime.hpp"
54 #include "dialogs/podcast_configuration.hpp"
55 #include "dialogs/toolbar.hpp"
56 #include "dialogs/plugins.hpp"
57 #include "dialogs/external.hpp"
58 #include "dialogs/epg.hpp"
59 #include "dialogs/errors.hpp"
61 #include <QEvent>
62 #include <QApplication>
63 #include <QSignalMapper>
64 #include <QFileDialog>
65 #include <QUrl>
67 #define I_OP_DIR_WINTITLE I_DIR_OR_FOLDER( N_("Open Directory"), \
68 N_("Open Folder") )
70 DialogsProvider* DialogsProvider::instance = NULL;
72 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
73 QObject( NULL ), p_intf( _p_intf ),
74 popupMenu( NULL ),
75 videoPopupMenu( NULL ),
76 audioPopupMenu( NULL ),
77 miscPopupMenu( NULL )
79 b_isDying = false;
81 /* Various signal mappers for the menus */
82 menusMapper = new QSignalMapper();
83 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
85 menusUpdateMapper = new QSignalMapper();
86 CONNECT( menusUpdateMapper, mapped(QObject *),
87 this, menuUpdateAction( QObject *) );
89 new DialogHandler (p_intf, this );
92 DialogsProvider::~DialogsProvider()
94 PlaylistDialog::killInstance();
95 MediaInfoDialog::killInstance();
96 MessagesDialog::killInstance();
97 BookmarksDialog::killInstance();
98 HelpDialog::killInstance();
99 #ifdef UPDATE_CHECK
100 UpdateDialog::killInstance();
101 #endif
102 PluginDialog::killInstance();
103 EpgDialog::killInstance();
105 delete menusMapper;
106 delete menusUpdateMapper;
108 delete popupMenu;
109 delete videoPopupMenu;
110 delete audioPopupMenu;
111 delete miscPopupMenu;
114 QStringList DialogsProvider::getOpenURL( intf_thread_t* p_intf, QWidget *parent,
115 const QString &caption,
116 const QString &dir,
117 const QString &filter,
118 QString *selectedFilter )
120 QStringList res;
122 #if HAS_QT5
123 QList<QUrl> urls = QFileDialog::getOpenFileUrls( parent, caption, QUrl::fromUserInput( dir ), filter, selectedFilter );
125 foreach( const QUrl& url, urls )
126 res.append( url.toEncoded() );
127 #else
128 QStringList files = QFileDialog::getOpenFileNames( parent, caption, dir, filter, selectedFilter );
129 foreach ( const QString& file, files )
130 res.append( toURI( toNativeSeparators( file ) ) );
131 #endif
133 return res;
136 QString DialogsProvider::getSaveFileName( QWidget *parent,
137 const QString &caption,
138 const QString &dir,
139 const QString &filter,
140 QString *selectedFilter )
142 return QFileDialog::getSaveFileName( parent, caption, dir, filter, selectedFilter );
145 void DialogsProvider::quit()
147 b_isDying = true;
148 libvlc_Quit( p_intf->obj.libvlc );
151 void DialogsProvider::customEvent( QEvent *event )
153 if( event->type() == DialogEvent::DialogEvent_Type )
155 DialogEvent *de = static_cast<DialogEvent*>(event);
156 switch( de->i_dialog )
158 case INTF_DIALOG_FILE_SIMPLE:
159 case INTF_DIALOG_FILE:
160 openDialog(); break;
161 case INTF_DIALOG_FILE_GENERIC:
162 openFileGenericDialog( de->p_arg ); break;
163 case INTF_DIALOG_DISC:
164 openDiscDialog(); break;
165 case INTF_DIALOG_NET:
166 openNetDialog(); break;
167 case INTF_DIALOG_SAT:
168 case INTF_DIALOG_CAPTURE:
169 openCaptureDialog(); break;
170 case INTF_DIALOG_DIRECTORY:
171 PLAppendDir(); break;
172 case INTF_DIALOG_PLAYLIST:
173 playlistDialog(); break;
174 case INTF_DIALOG_MESSAGES:
175 messagesDialog(); break;
176 case INTF_DIALOG_FILEINFO:
177 mediaInfoDialog(); break;
178 case INTF_DIALOG_PREFS:
179 prefsDialog(); break;
180 case INTF_DIALOG_BOOKMARKS:
181 bookmarksDialog(); break;
182 case INTF_DIALOG_EXTENDED:
183 extendedDialog(); break;
184 case INTF_DIALOG_SENDKEY:
185 sendKey( de->i_arg ); break;
186 #ifdef ENABLE_VLM
187 case INTF_DIALOG_VLM:
188 vlmDialog(); break;
189 #endif
190 case INTF_DIALOG_POPUPMENU:
192 delete popupMenu; popupMenu = NULL;
193 bool show = (de->i_arg != 0);
194 if( show )
195 popupMenu = VLCMenuBar::PopupMenu( p_intf, show );
196 break;
198 case INTF_DIALOG_AUDIOPOPUPMENU:
200 delete audioPopupMenu; audioPopupMenu = NULL;
201 bool show = (de->i_arg != 0);
202 if( show )
203 audioPopupMenu = VLCMenuBar::AudioPopupMenu( p_intf, show );
204 break;
206 case INTF_DIALOG_VIDEOPOPUPMENU:
208 delete videoPopupMenu; videoPopupMenu = NULL;
209 bool show = (de->i_arg != 0);
210 if( show )
211 videoPopupMenu = VLCMenuBar::VideoPopupMenu( p_intf, show );
212 break;
214 case INTF_DIALOG_MISCPOPUPMENU:
216 delete miscPopupMenu; miscPopupMenu = NULL;
217 bool show = (de->i_arg != 0);
218 if( show )
219 miscPopupMenu = VLCMenuBar::MiscPopupMenu( p_intf, show );
220 break;
222 case INTF_DIALOG_WIZARD:
223 case INTF_DIALOG_STREAMWIZARD:
224 openAndStreamingDialogs(); break;
225 #ifdef UPDATE_CHECK
226 case INTF_DIALOG_UPDATEVLC:
227 updateDialog(); break;
228 #endif
229 case INTF_DIALOG_EXIT:
230 quit(); break;
231 default:
232 msg_Warn( p_intf, "unimplemented dialog" );
237 /****************************************************************************
238 * Individual simple dialogs
239 ****************************************************************************/
240 const QEvent::Type DialogEvent::DialogEvent_Type =
241 (QEvent::Type)QEvent::registerEventType();
243 void DialogsProvider::playlistDialog()
245 PlaylistDialog::getInstance( p_intf )->toggleVisible();
248 void DialogsProvider::prefsDialog()
250 PrefsDialog *p = new PrefsDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
251 p->toggleVisible();
254 void DialogsProvider::extendedDialog()
256 ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
258 if( !extDialog->isVisible() || /* Hidden */
259 extDialog->currentTab() != 0 ) /* wrong tab */
260 extDialog->showTab( 0 );
261 else
262 extDialog->hide();
265 void DialogsProvider::synchroDialog()
267 ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
269 if( !extDialog->isVisible() || /* Hidden */
270 extDialog->currentTab() != 2 ) /* wrong tab */
271 extDialog->showTab( 2 );
272 else
273 extDialog->hide();
276 void DialogsProvider::messagesDialog()
278 MessagesDialog::getInstance( p_intf )->toggleVisible();
281 void DialogsProvider::gotoTimeDialog()
283 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
286 #ifdef ENABLE_VLM
287 void DialogsProvider::vlmDialog()
289 VLMDialog::getInstance( p_intf )->toggleVisible();
291 #endif
293 void DialogsProvider::helpDialog()
295 HelpDialog::getInstance( p_intf )->toggleVisible();
298 #ifdef UPDATE_CHECK
299 void DialogsProvider::updateDialog()
301 UpdateDialog::getInstance( p_intf )->toggleVisible();
303 #endif
305 void DialogsProvider::aboutDialog()
307 AboutDialog::getInstance( p_intf )->toggleVisible();
310 void DialogsProvider::mediaInfoDialog()
312 MediaInfoDialog::getInstance( p_intf )->showTab( MediaInfoDialog::META_PANEL );
315 void DialogsProvider::mediaCodecDialog()
317 MediaInfoDialog::getInstance( p_intf )->showTab( MediaInfoDialog::INFO_PANEL );
320 void DialogsProvider::bookmarksDialog()
322 BookmarksDialog::getInstance( p_intf )->toggleVisible();
325 void DialogsProvider::podcastConfigureDialog()
327 PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
330 void DialogsProvider::toolbarDialog()
332 ToolbarEditDialog *toolbarEditor = new ToolbarEditDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
333 if( toolbarEditor->exec() == QDialog::Accepted )
334 emit toolBarConfUpdated();
337 void DialogsProvider::pluginDialog()
339 PluginDialog::getInstance( p_intf )->toggleVisible();
342 void DialogsProvider::epgDialog()
344 EpgDialog::getInstance( p_intf )->toggleVisible();
347 void DialogsProvider::setPopupMenu()
349 delete popupMenu;
350 popupMenu = VLCMenuBar::PopupMenu( p_intf, true );
353 void DialogsProvider::destroyPopupMenu()
355 delete popupMenu;
356 popupMenu = NULL;
359 /* Generic open file */
360 void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
362 if( p_arg == NULL )
364 msg_Warn( p_intf, "openFileGenericDialog() called with NULL arg" );
365 return;
368 /* Replace the extensions to a Qt format */
369 int i = 0;
370 QString extensions = qfu( p_arg->psz_extensions );
371 while ( ( i = extensions.indexOf( "|", i ) ) != -1 )
373 if( ( extensions.count( "|" ) % 2 ) == 0 )
374 extensions.replace( i, 1, ");;" );
375 else
376 extensions.replace( i, 1, "(" );
378 extensions.replace( ";*", " *" );
379 extensions.append( ")" );
381 /* Save */
382 if( p_arg->b_save )
384 QString file = getSaveFileName( NULL,
385 qfu( p_arg->psz_title ),
386 p_intf->p_sys->filepath, extensions );
387 if( !file.isEmpty() )
389 p_arg->i_results = 1;
390 p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
391 p_arg->psz_results[0] = strdup( qtu( toNativeSepNoSlash( file ) ) );
393 else
394 p_arg->i_results = 0;
396 else /* non-save mode */
398 QStringList urls = getOpenURL( p_intf, NULL,
399 qfu( p_arg->psz_title ), p_intf->p_sys->filepath,
400 extensions );
401 p_arg->i_results = urls.count();
402 p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
403 i = 0;
404 foreach( const QString &uri, urls )
405 p_arg->psz_results[i++] = strdup( qtu( uri ) );
406 if(i == 0)
407 p_intf->p_sys->filepath = QString::fromLatin1("");
408 else
409 p_intf->p_sys->filepath = qfu( p_arg->psz_results[i-1] );
412 /* Callback */
413 if( p_arg->pf_callback )
414 p_arg->pf_callback( p_arg );
416 /* Clean afterwards */
417 if( p_arg->psz_results )
419 for( i = 0; i < p_arg->i_results; i++ )
420 free( p_arg->psz_results[i] );
421 free( p_arg->psz_results );
423 free( p_arg->psz_title );
424 free( p_arg->psz_extensions );
425 free( p_arg );
427 /****************************************************************************
428 * All the open/add stuff
429 * Open Dialog first - Simple Open then
430 ****************************************************************************/
432 void DialogsProvider::openDialog( int i_tab )
434 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
436 void DialogsProvider::openDialog()
438 openDialog( OPEN_FILE_TAB );
440 void DialogsProvider::openFileDialog()
442 openDialog( OPEN_FILE_TAB );
444 void DialogsProvider::openDiscDialog()
446 openDialog( OPEN_DISC_TAB );
448 void DialogsProvider::openNetDialog()
450 openDialog( OPEN_NETWORK_TAB );
452 void DialogsProvider::openCaptureDialog()
454 openDialog( OPEN_CAPTURE_TAB );
457 /* Same as the open one, but force the enqueue */
458 void DialogsProvider::PLAppendDialog( int tab )
460 OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
461 OPEN_AND_ENQUEUE )->showTab( tab );
464 void DialogsProvider::MLAppendDialog( int tab )
466 OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
467 OPEN_AND_ENQUEUE, false, false )
468 ->showTab( tab );
472 * Simple open
473 ***/
474 QStringList DialogsProvider::showSimpleOpen( const QString& help,
475 int filters,
476 const QString& path )
478 QString fileTypes = "";
479 if( filters & EXT_FILTER_MEDIA ) {
480 ADD_EXT_FILTER( fileTypes, EXTENSIONS_MEDIA );
482 if( filters & EXT_FILTER_VIDEO ) {
483 ADD_EXT_FILTER( fileTypes, EXTENSIONS_VIDEO );
485 if( filters & EXT_FILTER_AUDIO ) {
486 ADD_EXT_FILTER( fileTypes, EXTENSIONS_AUDIO );
488 if( filters & EXT_FILTER_PLAYLIST ) {
489 ADD_EXT_FILTER( fileTypes, EXTENSIONS_PLAYLIST );
491 if( filters & EXT_FILTER_SUBTITLE ) {
492 ADD_EXT_FILTER( fileTypes, EXTENSIONS_SUBTITLE );
494 ADD_EXT_FILTER( fileTypes, EXTENSIONS_ALL );
495 fileTypes.replace( ";*", " *");
497 QStringList urls = getOpenURL( p_intf, NULL,
498 help.isEmpty() ? qtr(I_OP_SEL_FILES ) : help,
499 path.isEmpty() ? p_intf->p_sys->filepath : path,
500 fileTypes );
502 if( !urls.isEmpty() ) savedirpathFromFile( urls.last() );
504 return urls;
508 * Open a file,
509 * pl helps you to choose from playlist or media library,
510 * go to start or enqueue
512 void DialogsProvider::addFromSimple( bool pl, bool go)
514 QStringList urls = DialogsProvider::showSimpleOpen();
516 bool first = go;
517 urls.sort();
518 foreach( const QString &url, urls )
520 Open::openMRL( p_intf, url, first, pl);
521 first = false;
525 void DialogsProvider::simpleOpenDialog()
527 addFromSimple( true, true ); /* Playlist and Go */
530 /* Url & Clipboard */
532 * Open a MRL.
533 * If the clipboard contains URLs, the first is automatically 'preselected'.
535 void DialogsProvider::openUrlDialog()
537 OpenUrlDialog oud( p_intf );
538 if( oud.exec() != QDialog::Accepted )
539 return;
541 QString url = oud.url();
542 if( url.isEmpty() )
543 return;
545 if( !url.contains( qfu( "://" ) ) )
547 char *uri = vlc_path2uri( qtu( url ), NULL );
548 if( uri == NULL )
549 return;
550 url = qfu(uri);
551 free( uri );
554 Open::openMRL( p_intf, qtu(url), !oud.shouldEnqueue() );
557 /* Directory */
559 * Open a directory,
560 * pl helps you to choose from playlist or media library,
561 * go to start or enqueue
563 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
565 QString uri = DialogsProvider::getDirectoryDialog( p_intf );
566 if( !uri.isEmpty() )
567 Open::openMRL( p_intf, uri, go, pl );
570 QString DialogsProvider::getDirectoryDialog( intf_thread_t *p_intf )
572 QString dir = QFileDialog::getExistingDirectory( NULL,
573 qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath );
575 if( dir.isEmpty() ) return QString();
577 p_intf->p_sys->filepath = dir;
579 const char *scheme = "directory";
580 if( dir.endsWith( DIR_SEP "VIDEO_TS", Qt::CaseInsensitive ) )
581 scheme = "dvd";
582 else if( dir.endsWith( DIR_SEP "BDMV", Qt::CaseInsensitive ) )
584 scheme = "bluray";
585 dir.remove( "BDMV" );
588 char *uri = vlc_path2uri( qtu( toNativeSeparators( dir ) ), scheme );
589 if( unlikely(uri == NULL) )
590 return QString();
592 dir = qfu( uri );
593 free( uri );
595 RecentsMRL::getInstance( p_intf )->addRecent( dir );
597 return dir;
600 void DialogsProvider::PLOpenDir()
602 openDirectory( p_intf, true, true );
605 void DialogsProvider::PLAppendDir()
607 openDirectory( p_intf, true, false );
610 /****************
611 * Playlist *
612 ****************/
613 void DialogsProvider::openAPlaylist()
615 QStringList urls = showSimpleOpen( qtr( "Open playlist..." ),
616 EXT_FILTER_PLAYLIST );
617 foreach( const QString &url, urls )
619 playlist_Import( THEPL, qtu( url ) );
623 void DialogsProvider::savePlayingToPlaylist()
625 static const struct
627 char filter_name[14];
628 char filter_patterns[5];
629 char module[12];
630 } types[] = {
631 { N_("XSPF playlist"), "xspf", "export-xspf", },
632 { N_("M3U playlist"), "m3u", "export-m3u", },
633 { N_("M3U8 playlist"), "m3u8", "export-m3u8", },
634 { N_("HTML playlist"), "html", "export-html", },
637 QStringList filters;
638 QString ext = getSettings()->value( "last-playlist-ext" ).toString();
640 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++ )
642 QString tmp = qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + types[i].filter_patterns + ")";
643 if( ext == qfu( types[i].filter_patterns ) )
644 filters.insert( 0, tmp );
645 else
646 filters.append( tmp );
649 QString selected;
650 QString file = getSaveFileName( NULL,
651 qtr( "Save playlist as..." ),
652 p_intf->p_sys->filepath, filters.join( ";;" ),
653 &selected );
654 const char *psz_selected_module = NULL;
655 const char *psz_last_playlist_ext = NULL;
657 if( file.isEmpty() )
658 return;
660 /* First test if the file extension is set, and different to selected filter */
661 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
663 if ( file.endsWith( QString( "." ) + qfu( types[i].filter_patterns ) ) )
665 psz_selected_module = types[i].module;
666 psz_last_playlist_ext = types[i].filter_patterns;
667 break;
671 /* otherwise apply the selected extension */
672 if ( !psz_last_playlist_ext )
674 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
676 if ( selected.startsWith( qfu( vlc_gettext( types[i].filter_name ) ) ) )
678 psz_selected_module = types[i].module;
679 psz_last_playlist_ext = types[i].filter_patterns;
680 /* Fix file extension */
681 file = file.append( QString( "." ) + qfu( psz_last_playlist_ext ) );
682 break;
687 if ( psz_selected_module )
689 playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
690 true, psz_selected_module );
691 getSettings()->setValue( "last-playlist-ext", psz_last_playlist_ext );
695 /****************************************************************************
696 * Sout emulation
697 ****************************************************************************/
699 void DialogsProvider::streamingDialog( QWidget *parent,
700 const QStringList& mrls,
701 bool b_transcode_only,
702 QStringList options )
704 QStringList outputMRLs;
706 /* Stream */
707 // Does streaming multiple files make sense? I suppose so, just stream one
708 // after the other, but not at the moment.
709 if( !b_transcode_only )
711 SoutDialog *s = new SoutDialog( parent, p_intf, mrls[0] );
712 s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
713 if( s->exec() == QDialog::Accepted )
715 outputMRLs.append(s->getMrl());
716 delete s;
718 else
720 delete s; return;
722 } else {
723 /* Convert */
724 ConvertDialog *s = new ConvertDialog( parent, p_intf, mrls );
725 s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
726 if( s->exec() == QDialog::Accepted )
728 /* Clear the playlist. This is because we're going to be populating
729 it */
730 playlist_Clear( THEPL, pl_Unlocked );
732 outputMRLs = s->getMrls();
733 delete s;
735 else
737 delete s; return;
741 /* Get SoutMRL(s) */
742 if( !outputMRLs.isEmpty() )
744 /* For all of our MRLs */
745 for(int i = 0; i < outputMRLs.length(); i++)
748 /* Duplicate the options list. This is because we need to have a
749 copy for every file we add to the playlist.*/
750 QStringList optionsCopy;
751 for(int j = 0; j < options.length(); j++)
753 optionsCopy.append(options[j]);
756 optionsCopy+= outputMRLs[i].split( " :");
757 QString title = "Converting " + mrls[i];
759 /* Add each file to convert to our playlist, making sure to not attempt to start playing it.*/
760 Open::openMRLwithOptions( p_intf, mrls[i], &optionsCopy, false, true, qtu( title ) );
763 /* Start the playlist from the beginning */
764 playlist_Control(THEPL,PLAYLIST_PLAY,pl_Unlocked);
768 void DialogsProvider::openAndStreamingDialogs()
770 OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM )
771 ->showTab( OPEN_FILE_TAB );
774 void DialogsProvider::openAndTranscodingDialogs()
776 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE )
777 ->showTab( OPEN_FILE_TAB );
780 void DialogsProvider::loadSubtitlesFile()
782 input_thread_t *p_input = THEMIM->getInput();
783 if( !p_input ) return;
785 input_item_t *p_item = input_GetItem( p_input );
786 if( !p_item ) return;
788 char *path = input_item_GetURI( p_item );
789 char *path2 = NULL;
790 if( path )
792 path2 = vlc_uri2path( path );
793 free( path );
794 if( path2 )
796 char *sep = strrchr( path2, DIR_SEP_CHAR );
797 if( sep ) *sep = '\0';
801 QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ),
802 EXT_FILTER_SUBTITLE,
803 qfu( path2 ) );
804 free( path2 );
805 foreach( const QString &qsUrl, qsl )
807 if( input_AddSubtitleOSD( p_input, qtu( toNativeSeparators( QUrl( qsUrl ).toLocalFile() ) ),
808 true, true ) )
809 msg_Warn( p_intf, "unable to load subtitles from '%s'",
810 qtu( qsUrl ) );
815 /****************************************************************************
816 * Menus
817 ****************************************************************************/
819 void DialogsProvider::menuAction( QObject *data )
821 VLCMenuBar::DoAction( data );
824 void DialogsProvider::menuUpdateAction( QObject *data )
826 MenuFunc *func = qobject_cast<MenuFunc *>(data);
827 assert( func );
828 func->doFunc( p_intf );
831 void DialogsProvider::sendKey( int key )
833 // translate from a vlc keycode into a Qt sequence
834 QKeySequence kseq0( VLCKeyToString( key, true ) );
836 if( popupMenu == NULL )
838 // make sure at least a non visible popupmenu is available
839 popupMenu = VLCMenuBar::PopupMenu( p_intf, false );
840 if( unlikely( popupMenu == NULL ) )
841 return;
844 // test against key accelerators from the popupmenu
845 QList<QAction*> actions = popupMenu->findChildren<QAction*>();
846 for( int i = 0; i < actions.size(); i++ )
848 QAction* action = actions.at(i);
849 QKeySequence kseq = action->shortcut();
850 if( kseq == kseq0 )
852 action->trigger();
853 return;
857 // forward key to vlc core when not a key accelerator
858 var_SetInteger( p_intf->obj.libvlc, "key-pressed", key );