qt: remove unused parameter
[vlc.git] / modules / gui / qt / dialogs_provider.cpp
blobdeca7ae0c82cdb228187ec27be42e232d41b5e78
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( 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( NULL, qfu( p_arg->psz_title ),
399 p_intf->p_sys->filepath, extensions );
400 p_arg->i_results = urls.count();
401 p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
402 i = 0;
403 foreach( const QString &uri, urls )
404 p_arg->psz_results[i++] = strdup( qtu( uri ) );
405 if(i == 0)
406 p_intf->p_sys->filepath = QString::fromLatin1("");
407 else
408 p_intf->p_sys->filepath = qfu( p_arg->psz_results[i-1] );
411 /* Callback */
412 if( p_arg->pf_callback )
413 p_arg->pf_callback( p_arg );
415 /* Clean afterwards */
416 if( p_arg->psz_results )
418 for( i = 0; i < p_arg->i_results; i++ )
419 free( p_arg->psz_results[i] );
420 free( p_arg->psz_results );
422 free( p_arg->psz_title );
423 free( p_arg->psz_extensions );
424 free( p_arg );
426 /****************************************************************************
427 * All the open/add stuff
428 * Open Dialog first - Simple Open then
429 ****************************************************************************/
431 void DialogsProvider::openDialog( int i_tab )
433 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
435 void DialogsProvider::openDialog()
437 openDialog( OPEN_FILE_TAB );
439 void DialogsProvider::openFileDialog()
441 openDialog( OPEN_FILE_TAB );
443 void DialogsProvider::openDiscDialog()
445 openDialog( OPEN_DISC_TAB );
447 void DialogsProvider::openNetDialog()
449 openDialog( OPEN_NETWORK_TAB );
451 void DialogsProvider::openCaptureDialog()
453 openDialog( OPEN_CAPTURE_TAB );
456 /* Same as the open one, but force the enqueue */
457 void DialogsProvider::PLAppendDialog( int tab )
459 OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
460 OPEN_AND_ENQUEUE )->showTab( tab );
463 void DialogsProvider::MLAppendDialog( int tab )
465 OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
466 OPEN_AND_ENQUEUE, false, false )
467 ->showTab( tab );
471 * Simple open
472 ***/
473 QStringList DialogsProvider::showSimpleOpen( const QString& help,
474 int filters,
475 const QString& path )
477 QString fileTypes = "";
478 if( filters & EXT_FILTER_MEDIA ) {
479 ADD_EXT_FILTER( fileTypes, EXTENSIONS_MEDIA );
481 if( filters & EXT_FILTER_VIDEO ) {
482 ADD_EXT_FILTER( fileTypes, EXTENSIONS_VIDEO );
484 if( filters & EXT_FILTER_AUDIO ) {
485 ADD_EXT_FILTER( fileTypes, EXTENSIONS_AUDIO );
487 if( filters & EXT_FILTER_PLAYLIST ) {
488 ADD_EXT_FILTER( fileTypes, EXTENSIONS_PLAYLIST );
490 if( filters & EXT_FILTER_SUBTITLE ) {
491 ADD_EXT_FILTER( fileTypes, EXTENSIONS_SUBTITLE );
493 ADD_EXT_FILTER( fileTypes, EXTENSIONS_ALL );
494 fileTypes.replace( ";*", " *");
496 QStringList urls = getOpenURL( NULL,
497 help.isEmpty() ? qtr(I_OP_SEL_FILES ) : help,
498 path.isEmpty() ? p_intf->p_sys->filepath : path,
499 fileTypes );
501 if( !urls.isEmpty() ) savedirpathFromFile( urls.last() );
503 return urls;
507 * Open a file,
508 * pl helps you to choose from playlist or media library,
509 * go to start or enqueue
511 void DialogsProvider::addFromSimple( bool pl, bool go)
513 QStringList urls = DialogsProvider::showSimpleOpen();
515 bool first = go;
516 urls.sort();
517 foreach( const QString &url, urls )
519 Open::openMRL( p_intf, url, first, pl);
520 first = false;
524 void DialogsProvider::simpleOpenDialog()
526 addFromSimple( true, true ); /* Playlist and Go */
529 /* Url & Clipboard */
531 * Open a MRL.
532 * If the clipboard contains URLs, the first is automatically 'preselected'.
534 void DialogsProvider::openUrlDialog()
536 OpenUrlDialog oud( p_intf );
537 if( oud.exec() != QDialog::Accepted )
538 return;
540 QString url = oud.url();
541 if( url.isEmpty() )
542 return;
544 if( !url.contains( qfu( "://" ) ) )
546 char *uri = vlc_path2uri( qtu( url ), NULL );
547 if( uri == NULL )
548 return;
549 url = qfu(uri);
550 free( uri );
553 Open::openMRL( p_intf, qtu(url), !oud.shouldEnqueue() );
556 /* Directory */
558 * Open a directory,
559 * pl helps you to choose from playlist or media library,
560 * go to start or enqueue
562 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
564 QString uri = DialogsProvider::getDirectoryDialog( p_intf );
565 if( !uri.isEmpty() )
566 Open::openMRL( p_intf, uri, go, pl );
569 QString DialogsProvider::getDirectoryDialog( intf_thread_t *p_intf )
571 QString dir = QFileDialog::getExistingDirectory( NULL,
572 qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath );
574 if( dir.isEmpty() ) return QString();
576 p_intf->p_sys->filepath = dir;
578 const char *scheme = "directory";
579 if( dir.endsWith( DIR_SEP "VIDEO_TS", Qt::CaseInsensitive ) )
580 scheme = "dvd";
581 else if( dir.endsWith( DIR_SEP "BDMV", Qt::CaseInsensitive ) )
583 scheme = "bluray";
584 dir.remove( "BDMV" );
587 char *uri = vlc_path2uri( qtu( toNativeSeparators( dir ) ), scheme );
588 if( unlikely(uri == NULL) )
589 return QString();
591 dir = qfu( uri );
592 free( uri );
594 RecentsMRL::getInstance( p_intf )->addRecent( dir );
596 return dir;
599 void DialogsProvider::PLOpenDir()
601 openDirectory( p_intf, true, true );
604 void DialogsProvider::PLAppendDir()
606 openDirectory( p_intf, true, false );
609 /****************
610 * Playlist *
611 ****************/
612 void DialogsProvider::openAPlaylist()
614 QStringList urls = showSimpleOpen( qtr( "Open playlist..." ),
615 EXT_FILTER_PLAYLIST );
616 foreach( const QString &url, urls )
618 playlist_Import( THEPL, qtu( url ) );
622 void DialogsProvider::savePlayingToPlaylist()
624 static const struct
626 char filter_name[14];
627 char filter_patterns[5];
628 char module[12];
629 } types[] = {
630 { N_("XSPF playlist"), "xspf", "export-xspf", },
631 { N_("M3U playlist"), "m3u", "export-m3u", },
632 { N_("M3U8 playlist"), "m3u8", "export-m3u8", },
633 { N_("HTML playlist"), "html", "export-html", },
636 QStringList filters;
637 QString ext = getSettings()->value( "last-playlist-ext" ).toString();
639 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++ )
641 QString tmp = qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + types[i].filter_patterns + ")";
642 if( ext == qfu( types[i].filter_patterns ) )
643 filters.insert( 0, tmp );
644 else
645 filters.append( tmp );
648 QString selected;
649 QString file = getSaveFileName( NULL,
650 qtr( "Save playlist as..." ),
651 p_intf->p_sys->filepath, filters.join( ";;" ),
652 &selected );
653 const char *psz_selected_module = NULL;
654 const char *psz_last_playlist_ext = NULL;
656 if( file.isEmpty() )
657 return;
659 /* First test if the file extension is set, and different to selected filter */
660 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
662 if ( file.endsWith( QString( "." ) + qfu( types[i].filter_patterns ) ) )
664 psz_selected_module = types[i].module;
665 psz_last_playlist_ext = types[i].filter_patterns;
666 break;
670 /* otherwise apply the selected extension */
671 if ( !psz_last_playlist_ext )
673 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
675 if ( selected.startsWith( qfu( vlc_gettext( types[i].filter_name ) ) ) )
677 psz_selected_module = types[i].module;
678 psz_last_playlist_ext = types[i].filter_patterns;
679 /* Fix file extension */
680 file = file.append( QString( "." ) + qfu( psz_last_playlist_ext ) );
681 break;
686 if ( psz_selected_module )
688 playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
689 true, psz_selected_module );
690 getSettings()->setValue( "last-playlist-ext", psz_last_playlist_ext );
694 /****************************************************************************
695 * Sout emulation
696 ****************************************************************************/
698 void DialogsProvider::streamingDialog( QWidget *parent,
699 const QStringList& mrls,
700 bool b_transcode_only,
701 QStringList options )
703 QStringList outputMRLs;
705 /* Stream */
706 // Does streaming multiple files make sense? I suppose so, just stream one
707 // after the other, but not at the moment.
708 if( !b_transcode_only )
710 SoutDialog *s = new SoutDialog( parent, p_intf, mrls[0] );
711 s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
712 if( s->exec() == QDialog::Accepted )
714 outputMRLs.append(s->getMrl());
715 delete s;
717 else
719 delete s; return;
721 } else {
722 /* Convert */
723 ConvertDialog *s = new ConvertDialog( parent, p_intf, mrls );
724 s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
725 if( s->exec() == QDialog::Accepted )
727 /* Clear the playlist. This is because we're going to be populating
728 it */
729 playlist_Clear( THEPL, pl_Unlocked );
731 outputMRLs = s->getMrls();
732 delete s;
734 else
736 delete s; return;
740 /* Get SoutMRL(s) */
741 if( !outputMRLs.isEmpty() )
743 /* For all of our MRLs */
744 for(int i = 0; i < outputMRLs.length(); i++)
747 /* Duplicate the options list. This is because we need to have a
748 copy for every file we add to the playlist.*/
749 QStringList optionsCopy;
750 for(int j = 0; j < options.length(); j++)
752 optionsCopy.append(options[j]);
755 optionsCopy+= outputMRLs[i].split( " :");
756 QString title = "Converting " + mrls[i];
758 /* Add each file to convert to our playlist, making sure to not attempt to start playing it.*/
759 Open::openMRLwithOptions( p_intf, mrls[i], &optionsCopy, false, true, qtu( title ) );
762 /* Start the playlist from the beginning */
763 playlist_Control(THEPL,PLAYLIST_PLAY,pl_Unlocked);
767 void DialogsProvider::openAndStreamingDialogs()
769 OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM )
770 ->showTab( OPEN_FILE_TAB );
773 void DialogsProvider::openAndTranscodingDialogs()
775 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE )
776 ->showTab( OPEN_FILE_TAB );
779 void DialogsProvider::loadSubtitlesFile()
781 input_thread_t *p_input = THEMIM->getInput();
782 if( !p_input ) return;
784 input_item_t *p_item = input_GetItem( p_input );
785 if( !p_item ) return;
787 char *path = input_item_GetURI( p_item );
788 char *path2 = NULL;
789 if( path )
791 path2 = vlc_uri2path( path );
792 free( path );
793 if( path2 )
795 char *sep = strrchr( path2, DIR_SEP_CHAR );
796 if( sep ) *sep = '\0';
800 QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ),
801 EXT_FILTER_SUBTITLE,
802 qfu( path2 ) );
803 free( path2 );
804 foreach( const QString &qsUrl, qsl )
806 if( input_AddSubtitleOSD( p_input, qtu( toNativeSeparators( QUrl( qsUrl ).toLocalFile() ) ),
807 true, true ) )
808 msg_Warn( p_intf, "unable to load subtitles from '%s'",
809 qtu( qsUrl ) );
814 /****************************************************************************
815 * Menus
816 ****************************************************************************/
818 void DialogsProvider::menuAction( QObject *data )
820 VLCMenuBar::DoAction( data );
823 void DialogsProvider::menuUpdateAction( QObject *data )
825 MenuFunc *func = qobject_cast<MenuFunc *>(data);
826 assert( func );
827 func->doFunc( p_intf );
830 void DialogsProvider::sendKey( int key )
832 // translate from a vlc keycode into a Qt sequence
833 QKeySequence kseq0( VLCKeyToString( key, true ) );
835 if( popupMenu == NULL )
837 // make sure at least a non visible popupmenu is available
838 popupMenu = VLCMenuBar::PopupMenu( p_intf, false );
839 if( unlikely( popupMenu == NULL ) )
840 return;
843 // test against key accelerators from the popupmenu
844 QList<QAction*> actions = popupMenu->findChildren<QAction*>();
845 for( int i = 0; i < actions.size(); i++ )
847 QAction* action = actions.at(i);
848 QKeySequence kseq = action->shortcut();
849 if( kseq == kseq0 )
851 action->trigger();
852 return;
856 // forward key to vlc core when not a key accelerator
857 var_SetInteger( p_intf->obj.libvlc, "key-pressed", key );