qt: add device preferences for mmdevice
[vlc.git] / modules / gui / qt / dialogs_provider.cpp
blobedf42665aa67f5c243f8153bcdf346bf676a1bda
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 #ifdef ENABLE_VLM
99 VLMDialog::killInstance();
100 #endif
101 HelpDialog::killInstance();
102 #ifdef UPDATE_CHECK
103 UpdateDialog::killInstance();
104 #endif
105 PluginDialog::killInstance();
106 EpgDialog::killInstance();
108 delete menusMapper;
109 delete menusUpdateMapper;
111 delete popupMenu;
112 delete videoPopupMenu;
113 delete audioPopupMenu;
114 delete miscPopupMenu;
117 QStringList DialogsProvider::getOpenURL( QWidget *parent,
118 const QString &caption,
119 const QString &dir,
120 const QString &filter,
121 QString *selectedFilter )
123 QStringList res;
124 QList<QUrl> urls = QFileDialog::getOpenFileUrls( parent, caption, QUrl::fromUserInput( dir ), filter, selectedFilter );
126 foreach( const QUrl& url, urls )
127 res.append( url.toEncoded() );
129 return res;
132 QString DialogsProvider::getSaveFileName( QWidget *parent,
133 const QString &caption,
134 const QString &dir,
135 const QString &filter,
136 QString *selectedFilter )
138 return QFileDialog::getSaveFileName( parent, caption, dir, filter, selectedFilter );
141 void DialogsProvider::quit()
143 b_isDying = true;
144 libvlc_Quit( p_intf->obj.libvlc );
147 void DialogsProvider::customEvent( QEvent *event )
149 if( event->type() == DialogEvent::DialogEvent_Type )
151 DialogEvent *de = static_cast<DialogEvent*>(event);
152 switch( de->i_dialog )
154 case INTF_DIALOG_FILE_SIMPLE:
155 case INTF_DIALOG_FILE:
156 openDialog(); break;
157 case INTF_DIALOG_FILE_GENERIC:
158 openFileGenericDialog( de->p_arg ); break;
159 case INTF_DIALOG_DISC:
160 openDiscDialog(); break;
161 case INTF_DIALOG_NET:
162 openNetDialog(); break;
163 case INTF_DIALOG_SAT:
164 case INTF_DIALOG_CAPTURE:
165 openCaptureDialog(); break;
166 case INTF_DIALOG_DIRECTORY:
167 PLAppendDir(); break;
168 case INTF_DIALOG_PLAYLIST:
169 playlistDialog(); break;
170 case INTF_DIALOG_MESSAGES:
171 messagesDialog(); break;
172 case INTF_DIALOG_FILEINFO:
173 mediaInfoDialog(); break;
174 case INTF_DIALOG_PREFS:
175 prefsDialog(); break;
176 case INTF_DIALOG_BOOKMARKS:
177 bookmarksDialog(); break;
178 case INTF_DIALOG_EXTENDED:
179 extendedDialog(); break;
180 case INTF_DIALOG_SENDKEY:
181 sendKey( de->i_arg ); break;
182 #ifdef ENABLE_VLM
183 case INTF_DIALOG_VLM:
184 vlmDialog(); break;
185 #endif
186 case INTF_DIALOG_POPUPMENU:
188 delete popupMenu; popupMenu = NULL;
189 bool show = (de->i_arg != 0);
190 if( show )
192 //popping a QMenu prevents mouse release events to be received,
193 //this ensures the coherency of the vout mouse state.
194 emit releaseMouseEvents();
195 popupMenu = VLCMenuBar::PopupMenu( p_intf, show );
197 break;
199 case INTF_DIALOG_AUDIOPOPUPMENU:
201 delete audioPopupMenu; audioPopupMenu = NULL;
202 bool show = (de->i_arg != 0);
203 if( show )
204 audioPopupMenu = VLCMenuBar::AudioPopupMenu( p_intf, show );
205 break;
207 case INTF_DIALOG_VIDEOPOPUPMENU:
209 delete videoPopupMenu; videoPopupMenu = NULL;
210 bool show = (de->i_arg != 0);
211 if( show )
212 videoPopupMenu = VLCMenuBar::VideoPopupMenu( p_intf, show );
213 break;
215 case INTF_DIALOG_MISCPOPUPMENU:
217 delete miscPopupMenu; miscPopupMenu = NULL;
218 bool show = (de->i_arg != 0);
219 if( show )
220 miscPopupMenu = VLCMenuBar::MiscPopupMenu( p_intf, show );
221 break;
223 case INTF_DIALOG_WIZARD:
224 case INTF_DIALOG_STREAMWIZARD:
225 openAndStreamingDialogs(); break;
226 #ifdef UPDATE_CHECK
227 case INTF_DIALOG_UPDATEVLC:
228 updateDialog(); break;
229 #endif
230 case INTF_DIALOG_EXIT:
231 quit(); break;
232 default:
233 msg_Warn( p_intf, "unimplemented dialog" );
238 /****************************************************************************
239 * Individual simple dialogs
240 ****************************************************************************/
241 const QEvent::Type DialogEvent::DialogEvent_Type =
242 (QEvent::Type)QEvent::registerEventType();
244 void DialogsProvider::playlistDialog()
246 PlaylistDialog::getInstance( p_intf )->toggleVisible();
249 void DialogsProvider::prefsDialog()
251 PrefsDialog *p = new PrefsDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
252 p->toggleVisible();
255 void DialogsProvider::extendedDialog()
257 ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
259 if( !extDialog->isVisible() || /* Hidden */
260 extDialog->currentTab() != 0 ) /* wrong tab */
261 extDialog->showTab( 0 );
262 else
263 extDialog->hide();
266 void DialogsProvider::synchroDialog()
268 ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
270 if( !extDialog->isVisible() || /* Hidden */
271 extDialog->currentTab() != 2 ) /* wrong tab */
272 extDialog->showTab( 2 );
273 else
274 extDialog->hide();
277 void DialogsProvider::messagesDialog()
279 MessagesDialog::getInstance( p_intf )->toggleVisible();
282 void DialogsProvider::gotoTimeDialog()
284 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
287 #ifdef ENABLE_VLM
288 void DialogsProvider::vlmDialog()
290 VLMDialog::getInstance( p_intf )->toggleVisible();
292 #endif
294 void DialogsProvider::helpDialog()
296 HelpDialog::getInstance( p_intf )->toggleVisible();
299 #ifdef UPDATE_CHECK
300 void DialogsProvider::updateDialog()
302 UpdateDialog::getInstance( p_intf )->toggleVisible();
304 #endif
306 void DialogsProvider::aboutDialog()
308 AboutDialog::getInstance( p_intf )->toggleVisible();
311 void DialogsProvider::mediaInfoDialog()
313 MediaInfoDialog::getInstance( p_intf )->showTab( MediaInfoDialog::META_PANEL );
316 void DialogsProvider::mediaCodecDialog()
318 MediaInfoDialog::getInstance( p_intf )->showTab( MediaInfoDialog::INFO_PANEL );
321 void DialogsProvider::bookmarksDialog()
323 BookmarksDialog::getInstance( p_intf )->toggleVisible();
326 void DialogsProvider::podcastConfigureDialog()
328 PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
331 void DialogsProvider::toolbarDialog()
333 ToolbarEditDialog *toolbarEditor = new ToolbarEditDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
334 if( toolbarEditor->exec() == QDialog::Accepted )
335 emit toolBarConfUpdated();
338 void DialogsProvider::pluginDialog()
340 PluginDialog::getInstance( p_intf )->toggleVisible();
343 void DialogsProvider::epgDialog()
345 EpgDialog::getInstance( p_intf )->toggleVisible();
348 void DialogsProvider::setPopupMenu()
350 delete popupMenu;
351 popupMenu = VLCMenuBar::PopupMenu( p_intf, true );
354 void DialogsProvider::destroyPopupMenu()
356 delete popupMenu;
357 popupMenu = NULL;
360 /* Generic open file */
361 void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
363 if( p_arg == NULL )
365 msg_Warn( p_intf, "openFileGenericDialog() called with NULL arg" );
366 return;
369 /* Replace the extensions to a Qt format */
370 int i = 0;
371 QString extensions = qfu( p_arg->psz_extensions );
372 while ( ( i = extensions.indexOf( "|", i ) ) != -1 )
374 if( ( extensions.count( "|" ) % 2 ) == 0 )
375 extensions.replace( i, 1, ");;" );
376 else
377 extensions.replace( i, 1, "(" );
379 extensions.replace( ";*", " *" );
380 extensions.append( ")" );
382 /* Save */
383 if( p_arg->b_save )
385 QString file = getSaveFileName( NULL,
386 qfu( p_arg->psz_title ),
387 p_intf->p_sys->filepath, extensions );
388 if( !file.isEmpty() )
390 p_arg->i_results = 1;
391 p_arg->psz_results = (char **)vlc_alloc( p_arg->i_results, sizeof( char * ) );
392 p_arg->psz_results[0] = strdup( qtu( toNativeSepNoSlash( file ) ) );
394 else
395 p_arg->i_results = 0;
397 else /* non-save mode */
399 QStringList urls = getOpenURL( NULL, qfu( p_arg->psz_title ),
400 p_intf->p_sys->filepath, extensions );
401 p_arg->i_results = urls.count();
402 p_arg->psz_results = (char **)vlc_alloc( 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( ";*", " *");
496 fileTypes.chop(2); //remove trailling ";;"
498 QStringList urls = getOpenURL( NULL,
499 help.isEmpty() ? qtr(I_OP_SEL_FILES ) : help,
500 path.isEmpty() ? p_intf->p_sys->filepath : path,
501 fileTypes );
503 if( !urls.isEmpty() ) savedirpathFromFile( urls.last() );
505 return urls;
509 * Open a file,
510 * pl helps you to choose from playlist or media library,
511 * go to start or enqueue
513 void DialogsProvider::addFromSimple( bool pl, bool go)
515 QStringList urls = DialogsProvider::showSimpleOpen();
517 bool first = go;
518 urls.sort();
519 foreach( const QString &url, urls )
521 Open::openMRL( p_intf, url, first, pl);
522 first = false;
526 void DialogsProvider::simpleOpenDialog()
528 addFromSimple( true, true ); /* Playlist and Go */
531 /* Url & Clipboard */
533 * Open a MRL.
534 * If the clipboard contains URLs, the first is automatically 'preselected'.
536 void DialogsProvider::openUrlDialog()
538 OpenUrlDialog oud( p_intf );
539 if( oud.exec() != QDialog::Accepted )
540 return;
542 QString url = oud.url();
543 if( url.isEmpty() )
544 return;
546 if( !url.contains( qfu( "://" ) ) )
548 char *uri = vlc_path2uri( qtu( url ), NULL );
549 if( uri == NULL )
550 return;
551 url = qfu(uri);
552 free( uri );
555 Open::openMRL( p_intf, qtu(url), !oud.shouldEnqueue() );
558 /* Directory */
560 * Open a directory,
561 * pl helps you to choose from playlist or media library,
562 * go to start or enqueue
564 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
566 QString uri = DialogsProvider::getDirectoryDialog( p_intf );
567 if( !uri.isEmpty() )
568 Open::openMRL( p_intf, uri, go, pl );
571 QString DialogsProvider::getDirectoryDialog( intf_thread_t *p_intf )
573 QString dir = QFileDialog::getExistingDirectory( NULL,
574 qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath );
576 if( dir.isEmpty() ) return QString();
578 p_intf->p_sys->filepath = dir;
580 const char *scheme = "directory";
581 if( dir.endsWith( DIR_SEP "VIDEO_TS", Qt::CaseInsensitive ) )
582 scheme = "dvd";
583 else if( dir.endsWith( DIR_SEP "BDMV", Qt::CaseInsensitive ) )
585 scheme = "bluray";
586 dir.remove( "BDMV" );
589 char *uri = vlc_path2uri( qtu( toNativeSeparators( dir ) ), scheme );
590 if( unlikely(uri == NULL) )
591 return QString();
593 dir = qfu( uri );
594 free( uri );
596 RecentsMRL::getInstance( p_intf )->addRecent( dir );
598 return dir;
601 void DialogsProvider::PLOpenDir()
603 openDirectory( p_intf, true, true );
606 void DialogsProvider::PLAppendDir()
608 openDirectory( p_intf, true, false );
611 /****************
612 * Playlist *
613 ****************/
614 void DialogsProvider::openAPlaylist()
616 QStringList urls = showSimpleOpen( qtr( "Open playlist..." ),
617 EXT_FILTER_PLAYLIST );
618 foreach( const QString &url, urls )
620 char* psz_path = vlc_uri2path(qtu( url ));
621 if ( !psz_path )
623 msg_Warn( p_intf, "unable to load playlist '%s'", qtu( url ) );
624 continue;
626 playlist_Import( THEPL, psz_path );
627 free( psz_path );
631 void DialogsProvider::savePlayingToPlaylist()
633 static const struct
635 char filter_name[14];
636 char filter_patterns[5];
637 char module[12];
638 } types[] = {
639 { N_("XSPF playlist"), "xspf", "export-xspf", },
640 { N_("M3U playlist"), "m3u", "export-m3u", },
641 { N_("M3U8 playlist"), "m3u8", "export-m3u8", },
642 { N_("HTML playlist"), "html", "export-html", },
645 QStringList filters;
646 QString ext = getSettings()->value( "last-playlist-ext" ).toString();
648 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++ )
650 QString tmp = qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + types[i].filter_patterns + ")";
651 if( ext == qfu( types[i].filter_patterns ) )
652 filters.insert( 0, tmp );
653 else
654 filters.append( tmp );
657 QString selected;
658 QString file = getSaveFileName( NULL,
659 qtr( "Save playlist as..." ),
660 p_intf->p_sys->filepath, filters.join( ";;" ),
661 &selected );
662 const char *psz_selected_module = NULL;
663 const char *psz_last_playlist_ext = NULL;
665 if( file.isEmpty() )
666 return;
668 /* First test if the file extension is set, and different to selected filter */
669 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
671 if ( file.endsWith( QString( "." ) + qfu( types[i].filter_patterns ) ) )
673 psz_selected_module = types[i].module;
674 psz_last_playlist_ext = types[i].filter_patterns;
675 break;
679 /* otherwise apply the selected extension */
680 if ( !psz_last_playlist_ext )
682 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
684 if ( selected.startsWith( qfu( vlc_gettext( types[i].filter_name ) ) ) )
686 psz_selected_module = types[i].module;
687 psz_last_playlist_ext = types[i].filter_patterns;
688 /* Fix file extension */
689 file = file.append( QString( "." ) + qfu( psz_last_playlist_ext ) );
690 break;
695 if ( psz_selected_module )
697 playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
698 true, psz_selected_module );
699 getSettings()->setValue( "last-playlist-ext", psz_last_playlist_ext );
703 /****************************************************************************
704 * Sout emulation
705 ****************************************************************************/
707 void DialogsProvider::streamingDialog( QWidget *parent,
708 const QStringList& mrls,
709 bool b_transcode_only,
710 QStringList options )
712 QStringList outputMRLs;
714 /* Stream */
715 // Does streaming multiple files make sense? I suppose so, just stream one
716 // after the other, but not at the moment.
717 if( !b_transcode_only )
719 SoutDialog *s = new SoutDialog( parent, p_intf, mrls[0] );
720 s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
721 if( s->exec() == QDialog::Accepted )
723 outputMRLs.append(s->getMrl());
724 delete s;
726 else
728 delete s; return;
730 } else {
731 /* Convert */
732 ConvertDialog *s = new ConvertDialog( parent, p_intf, mrls );
733 s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
734 if( s->exec() == QDialog::Accepted )
736 /* Clear the playlist. This is because we're going to be populating
737 it */
738 playlist_Clear( THEPL, pl_Unlocked );
740 outputMRLs = s->getMrls();
741 delete s;
743 else
745 delete s; return;
749 /* Get SoutMRL(s) */
750 if( !outputMRLs.isEmpty() )
752 /* For all of our MRLs */
753 for(int i = 0; i < outputMRLs.length(); i++)
756 /* Duplicate the options list. This is because we need to have a
757 copy for every file we add to the playlist.*/
758 QStringList optionsCopy;
759 for(int j = 0; j < options.length(); j++)
761 optionsCopy.append(options[j]);
764 optionsCopy+= outputMRLs[i].split( " :");
765 QString title = "Converting " + mrls[i];
767 /* Add each file to convert to our playlist, making sure to not attempt to start playing it.*/
768 Open::openMRLwithOptions( p_intf, mrls[i], &optionsCopy, false, true, qtu( title ) );
771 /* Start the playlist from the beginning */
772 playlist_Control(THEPL,PLAYLIST_PLAY,pl_Unlocked);
776 void DialogsProvider::openAndStreamingDialogs()
778 OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM )
779 ->showTab( OPEN_FILE_TAB );
782 void DialogsProvider::openAndTranscodingDialogs()
784 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE )
785 ->showTab( OPEN_FILE_TAB );
788 void DialogsProvider::loadSubtitlesFile()
790 input_thread_t *p_input = THEMIM->getInput();
791 if( !p_input ) return;
793 input_item_t *p_item = input_GetItem( p_input );
794 if( !p_item ) return;
796 char *path = input_item_GetURI( p_item );
797 char *path2 = NULL;
798 if( path )
800 path2 = vlc_uri2path( path );
801 free( path );
802 if( path2 )
804 char *sep = strrchr( path2, DIR_SEP_CHAR );
805 if( sep ) *sep = '\0';
809 QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ),
810 EXT_FILTER_SUBTITLE,
811 qfu( path2 ) );
812 free( path2 );
813 foreach( const QString &qsUrl, qsl )
815 if( input_AddSlave( p_input, SLAVE_TYPE_SPU, qtu( qsUrl ), true, true, false ) )
816 msg_Warn( p_intf, "unable to load subtitles from '%s'",
817 qtu( qsUrl ) );
822 /****************************************************************************
823 * Menus
824 ****************************************************************************/
826 void DialogsProvider::menuAction( QObject *data )
828 VLCMenuBar::DoAction( data );
831 void DialogsProvider::menuUpdateAction( QObject *data )
833 MenuFunc *func = qobject_cast<MenuFunc *>(data);
834 assert( func );
835 func->doFunc( p_intf );
838 void DialogsProvider::sendKey( int key )
840 // translate from a vlc keycode into a Qt sequence
841 QKeySequence kseq0( VLCKeyToString( key, true ) );
843 if( popupMenu == NULL )
845 // make sure at least a non visible popupmenu is available
846 popupMenu = VLCMenuBar::PopupMenu( p_intf, false );
847 if( unlikely( popupMenu == NULL ) )
848 return;
851 // test against key accelerators from the popupmenu
852 QList<QAction*> actions = popupMenu->findChildren<QAction*>();
853 for( int i = 0; i < actions.size(); i++ )
855 QAction* action = actions.at(i);
856 QKeySequence kseq = action->shortcut();
857 if( kseq == kseq0 )
859 action->trigger();
860 return;
864 // forward key to vlc core when not a key accelerator
865 var_SetInteger( p_intf->obj.libvlc, "key-pressed", key );