gui: qt: use float for rate
[vlc.git] / modules / gui / qt / dialogs_provider.cpp
blob084892aa7fccd23031d14d9483820ece913040aa
1 /*****************************************************************************
2 * dialogs_provider.cpp : Dialog Provider
3 *****************************************************************************
4 * Copyright (C) 2006-2009 the VideoLAN team
6 * Authors: Clément Stenac <zorglub@videolan.org>
7 * Jean-Baptiste Kempf <jb@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <vlc_intf_strings.h>
30 #include "qt.hpp"
31 #include "dialogs_provider.hpp"
32 #include "input_manager.hpp" /* Load Subtitles */
33 #include "menus.hpp"
34 #include "recents.hpp"
35 #include "util/qt_dirs.hpp"
36 #include "util/customwidgets.hpp" /* VLCKeyToString() */
37 #include "main_interface.hpp"
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"
60 #include <QEvent>
61 #include <QApplication>
62 #include <QSignalMapper>
63 #include <QFileDialog>
64 #include <QUrl>
66 #define I_OP_DIR_WINTITLE I_DIR_OR_FOLDER( N_("Open Directory"), \
67 N_("Open Folder") )
69 DialogsProvider* DialogsProvider::instance = NULL;
71 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
72 QObject( NULL ), p_intf( _p_intf ),
73 popupMenu( NULL ),
74 videoPopupMenu( NULL ),
75 audioPopupMenu( NULL ),
76 miscPopupMenu( NULL )
78 b_isDying = false;
80 /* Various signal mappers for the menus */
81 menusMapper = new QSignalMapper();
82 CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) );
84 menusUpdateMapper = new QSignalMapper();
85 CONNECT( menusUpdateMapper, mapped(QObject *),
86 this, menuUpdateAction( QObject *) );
88 new DialogHandler (p_intf, this );
91 DialogsProvider::~DialogsProvider()
93 PlaylistDialog::killInstance();
94 MediaInfoDialog::killInstance();
95 MessagesDialog::killInstance();
96 BookmarksDialog::killInstance();
97 #ifdef ENABLE_VLM
98 VLMDialog::killInstance();
99 #endif
100 HelpDialog::killInstance();
101 #ifdef UPDATE_CHECK
102 UpdateDialog::killInstance();
103 #endif
104 PluginDialog::killInstance();
105 EpgDialog::killInstance();
107 delete menusMapper;
108 delete menusUpdateMapper;
110 delete popupMenu;
111 delete videoPopupMenu;
112 delete audioPopupMenu;
113 delete miscPopupMenu;
115 /* free parentless menus */
116 VLCMenuBar::freeRecentsMenu();
117 VLCMenuBar::freeRendererMenu();
120 QString DialogsProvider::getSaveFileName( QWidget *parent,
121 const QString &caption,
122 const QUrl &dir,
123 const QString &filter,
124 QString *selectedFilter )
126 const QStringList schemes = QStringList(QStringLiteral("file"));
127 return QFileDialog::getSaveFileUrl( parent, caption, dir, filter, selectedFilter, QFileDialog::Options(), schemes).toLocalFile();
130 void DialogsProvider::quit()
132 b_isDying = true;
133 libvlc_Quit( p_intf->obj.libvlc );
136 void DialogsProvider::customEvent( QEvent *event )
138 if( event->type() == DialogEvent::DialogEvent_Type )
140 DialogEvent *de = static_cast<DialogEvent*>(event);
141 switch( de->i_dialog )
143 case INTF_DIALOG_FILE_SIMPLE:
144 case INTF_DIALOG_FILE:
145 openDialog(); break;
146 case INTF_DIALOG_FILE_GENERIC:
147 openFileGenericDialog( de->p_arg ); break;
148 case INTF_DIALOG_DISC:
149 openDiscDialog(); break;
150 case INTF_DIALOG_NET:
151 openNetDialog(); break;
152 case INTF_DIALOG_SAT:
153 case INTF_DIALOG_CAPTURE:
154 openCaptureDialog(); break;
155 case INTF_DIALOG_DIRECTORY:
156 PLAppendDir(); break;
157 case INTF_DIALOG_PLAYLIST:
158 playlistDialog(); break;
159 case INTF_DIALOG_MESSAGES:
160 messagesDialog(); break;
161 case INTF_DIALOG_FILEINFO:
162 mediaInfoDialog(); break;
163 case INTF_DIALOG_PREFS:
164 prefsDialog(); break;
165 case INTF_DIALOG_BOOKMARKS:
166 bookmarksDialog(); break;
167 case INTF_DIALOG_EXTENDED:
168 extendedDialog(); break;
169 case INTF_DIALOG_SENDKEY:
170 sendKey( de->i_arg ); break;
171 #ifdef ENABLE_VLM
172 case INTF_DIALOG_VLM:
173 vlmDialog(); break;
174 #endif
175 case INTF_DIALOG_POPUPMENU:
177 delete popupMenu; popupMenu = NULL;
178 bool show = (de->i_arg != 0);
179 if( show )
181 //popping a QMenu prevents mouse release events to be received,
182 //this ensures the coherency of the vout mouse state.
183 emit releaseMouseEvents();
184 popupMenu = VLCMenuBar::PopupMenu( p_intf, show );
186 break;
188 case INTF_DIALOG_AUDIOPOPUPMENU:
190 delete audioPopupMenu; audioPopupMenu = NULL;
191 bool show = (de->i_arg != 0);
192 if( show )
193 audioPopupMenu = VLCMenuBar::AudioPopupMenu( p_intf, show );
194 break;
196 case INTF_DIALOG_VIDEOPOPUPMENU:
198 delete videoPopupMenu; videoPopupMenu = NULL;
199 bool show = (de->i_arg != 0);
200 if( show )
201 videoPopupMenu = VLCMenuBar::VideoPopupMenu( p_intf, show );
202 break;
204 case INTF_DIALOG_MISCPOPUPMENU:
206 delete miscPopupMenu; miscPopupMenu = NULL;
207 bool show = (de->i_arg != 0);
208 if( show )
209 miscPopupMenu = VLCMenuBar::MiscPopupMenu( p_intf, show );
210 break;
212 case INTF_DIALOG_WIZARD:
213 case INTF_DIALOG_STREAMWIZARD:
214 openAndStreamingDialogs(); break;
215 #ifdef UPDATE_CHECK
216 case INTF_DIALOG_UPDATEVLC:
217 updateDialog(); break;
218 #endif
219 case INTF_DIALOG_EXIT:
220 quit(); break;
221 default:
222 msg_Warn( p_intf, "unimplemented dialog" );
227 /****************************************************************************
228 * Individual simple dialogs
229 ****************************************************************************/
230 const QEvent::Type DialogEvent::DialogEvent_Type =
231 (QEvent::Type)QEvent::registerEventType();
233 void DialogsProvider::playlistDialog()
235 PlaylistDialog::getInstance( p_intf )->toggleVisible();
238 void DialogsProvider::prefsDialog()
240 PrefsDialog *p = new PrefsDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
241 p->toggleVisible();
244 void DialogsProvider::extendedDialog()
246 ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
248 if( !extDialog->isVisible() || /* Hidden */
249 extDialog->currentTab() != 0 ) /* wrong tab */
250 extDialog->showTab( 0 );
251 else
252 extDialog->hide();
255 void DialogsProvider::synchroDialog()
257 ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
259 if( !extDialog->isVisible() || /* Hidden */
260 extDialog->currentTab() != 2 ) /* wrong tab */
261 extDialog->showTab( 2 );
262 else
263 extDialog->hide();
266 void DialogsProvider::messagesDialog()
268 MessagesDialog::getInstance( p_intf )->toggleVisible();
271 void DialogsProvider::gotoTimeDialog()
273 GotoTimeDialog::getInstance( p_intf )->toggleVisible();
276 #ifdef ENABLE_VLM
277 void DialogsProvider::vlmDialog()
279 VLMDialog::getInstance( p_intf )->toggleVisible();
281 #endif
283 void DialogsProvider::helpDialog()
285 HelpDialog::getInstance( p_intf )->toggleVisible();
288 #ifdef UPDATE_CHECK
289 void DialogsProvider::updateDialog()
291 UpdateDialog::getInstance( p_intf )->toggleVisible();
293 #endif
295 void DialogsProvider::aboutDialog()
297 AboutDialog::getInstance( p_intf )->toggleVisible();
300 void DialogsProvider::mediaInfoDialog()
302 MediaInfoDialog *dialog = MediaInfoDialog::getInstance( p_intf );
303 if( !dialog->isVisible() || dialog->currentTab() != MediaInfoDialog::META_PANEL )
304 dialog->showTab( MediaInfoDialog::META_PANEL );
305 else
306 dialog->hide();
309 void DialogsProvider::mediaCodecDialog()
311 MediaInfoDialog *dialog = MediaInfoDialog::getInstance( p_intf );
312 if( !dialog->isVisible() || dialog->currentTab() != MediaInfoDialog::INFO_PANEL )
313 dialog->showTab( MediaInfoDialog::INFO_PANEL );
314 else
315 dialog->hide();
318 void DialogsProvider::bookmarksDialog()
320 BookmarksDialog::getInstance( p_intf )->toggleVisible();
323 void DialogsProvider::podcastConfigureDialog()
325 PodcastConfigDialog::getInstance( p_intf )->toggleVisible();
328 void DialogsProvider::toolbarDialog()
330 ToolbarEditDialog *toolbarEditor = new ToolbarEditDialog( (QWidget *)p_intf->p_sys->p_mi, p_intf );
331 if( toolbarEditor->exec() == QDialog::Accepted )
332 emit toolBarConfUpdated();
335 void DialogsProvider::pluginDialog()
337 PluginDialog::getInstance( p_intf )->toggleVisible();
340 void DialogsProvider::epgDialog()
342 EpgDialog::getInstance( p_intf )->toggleVisible();
345 void DialogsProvider::setPopupMenu()
347 delete popupMenu;
348 popupMenu = VLCMenuBar::PopupMenu( p_intf, true );
351 void DialogsProvider::destroyPopupMenu()
353 delete popupMenu;
354 popupMenu = NULL;
357 /* Generic open file */
358 void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
360 if( p_arg == NULL )
362 msg_Warn( p_intf, "openFileGenericDialog() called with NULL arg" );
363 return;
366 /* Replace the extensions to a Qt format */
367 int i = 0;
368 QString extensions = qfu( p_arg->psz_extensions );
369 while ( ( i = extensions.indexOf( "|", i ) ) != -1 )
371 if( ( extensions.count( "|" ) % 2 ) == 0 )
372 extensions.replace( i, 1, ");;" );
373 else
374 extensions.replace( i, 1, "(" );
376 extensions.replace( ";*", " *" );
377 extensions.append( ")" );
379 /* Save */
380 if( p_arg->b_save )
382 QString file = getSaveFileName( NULL,
383 qfu( p_arg->psz_title ),
384 p_intf->p_sys->filepath, extensions );
385 if( !file.isEmpty() )
387 p_arg->i_results = 1;
388 p_arg->psz_results = (char **)vlc_alloc( p_arg->i_results, sizeof( char * ) );
389 p_arg->psz_results[0] = strdup( qtu( toNativeSepNoSlash( file ) ) );
391 else
392 p_arg->i_results = 0;
394 else /* non-save mode */
396 QList<QUrl> urls = QFileDialog::getOpenFileUrls( NULL, qfu( p_arg->psz_title ),
397 p_intf->p_sys->filepath, extensions );
398 p_arg->i_results = urls.count();
399 p_arg->psz_results = (char **)vlc_alloc( p_arg->i_results, sizeof( char * ) );
400 i = 0;
401 foreach( const QUrl &uri, urls )
402 p_arg->psz_results[i++] = strdup( uri.toEncoded().constData() );
403 if( !urls.isEmpty() )
404 p_intf->p_sys->filepath = urls.last();
407 /* Callback */
408 if( p_arg->pf_callback )
409 p_arg->pf_callback( p_arg );
411 /* Clean afterwards */
412 if( p_arg->psz_results )
414 for( i = 0; i < p_arg->i_results; i++ )
415 free( p_arg->psz_results[i] );
416 free( p_arg->psz_results );
418 free( p_arg->psz_title );
419 free( p_arg->psz_extensions );
420 free( p_arg );
422 /****************************************************************************
423 * All the open/add stuff
424 * Open Dialog first - Simple Open then
425 ****************************************************************************/
427 void DialogsProvider::openDialog( int i_tab )
429 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab );
431 void DialogsProvider::openDialog()
433 openDialog( OPEN_FILE_TAB );
435 void DialogsProvider::openFileDialog()
437 openDialog( OPEN_FILE_TAB );
439 void DialogsProvider::openDiscDialog()
441 openDialog( OPEN_DISC_TAB );
443 void DialogsProvider::openNetDialog()
445 openDialog( OPEN_NETWORK_TAB );
447 void DialogsProvider::openCaptureDialog()
449 openDialog( OPEN_CAPTURE_TAB );
452 /* Same as the open one, but force the enqueue */
453 void DialogsProvider::PLAppendDialog( int tab )
455 OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false,
456 OPEN_AND_ENQUEUE )->showTab( tab );
460 * Simple open
461 ***/
462 QStringList DialogsProvider::showSimpleOpen( const QString& help,
463 int filters,
464 const QUrl& path )
466 QString fileTypes = "";
467 if( filters & EXT_FILTER_MEDIA ) {
468 ADD_EXT_FILTER( fileTypes, EXTENSIONS_MEDIA );
470 if( filters & EXT_FILTER_VIDEO ) {
471 ADD_EXT_FILTER( fileTypes, EXTENSIONS_VIDEO );
473 if( filters & EXT_FILTER_AUDIO ) {
474 ADD_EXT_FILTER( fileTypes, EXTENSIONS_AUDIO );
476 if( filters & EXT_FILTER_PLAYLIST ) {
477 ADD_EXT_FILTER( fileTypes, EXTENSIONS_PLAYLIST );
479 if( filters & EXT_FILTER_SUBTITLE ) {
480 ADD_EXT_FILTER( fileTypes, EXTENSIONS_SUBTITLE );
482 ADD_EXT_FILTER( fileTypes, EXTENSIONS_ALL );
483 fileTypes.replace( ";*", " *");
484 fileTypes.chop(2); //remove trailling ";;"
486 QList<QUrl> urls = QFileDialog::getOpenFileUrls( NULL,
487 help.isEmpty() ? qtr(I_OP_SEL_FILES ) : help,
488 path.isEmpty() ? p_intf->p_sys->filepath : path,
489 fileTypes );
491 if( !urls.isEmpty() )
492 p_intf->p_sys->filepath = urls.last();
494 QStringList res;
495 foreach( const QUrl &url, urls )
496 res << url.toEncoded();
498 return res;
501 void DialogsProvider::simpleOpenDialog()
503 QStringList urls = DialogsProvider::showSimpleOpen();
505 bool first = true;
506 urls.sort();
507 foreach( const QString &url, urls )
509 Open::openMRL( p_intf, url, first );
510 first = false;
514 /* Url & Clipboard */
516 * Open a MRL.
517 * If the clipboard contains URLs, the first is automatically 'preselected'.
519 void DialogsProvider::openUrlDialog()
521 OpenUrlDialog oud( p_intf );
522 if( oud.exec() != QDialog::Accepted )
523 return;
525 QString url = oud.url();
526 if( url.isEmpty() )
527 return;
529 if( !url.contains( qfu( "://" ) ) )
531 char *uri = vlc_path2uri( qtu( url ), NULL );
532 if( uri == NULL )
533 return;
534 url = qfu(uri);
535 free( uri );
538 Open::openMRL( p_intf, qtu(url), !oud.shouldEnqueue() );
541 /* Directory */
543 * Open a directory,
544 * pl helps you to choose from playlist or media library,
545 * go to start or enqueue
547 static void openDirectory( intf_thread_t *p_intf, bool go )
549 QString uri = DialogsProvider::getDirectoryDialog( p_intf );
550 if( !uri.isEmpty() )
551 Open::openMRL( p_intf, uri, go );
554 QString DialogsProvider::getDirectoryDialog( intf_thread_t *p_intf )
556 const QStringList schemes = QStringList(QStringLiteral("file"));
557 QUrl dirurl = QFileDialog::getExistingDirectoryUrl( NULL,
558 qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath,
559 QFileDialog::ShowDirsOnly, schemes );
561 if( dirurl.isEmpty() ) return QString();
563 p_intf->p_sys->filepath = dirurl;
565 QString dir = dirurl.toLocalFile();
566 const char *scheme = "directory";
567 if( dir.endsWith( DIR_SEP "VIDEO_TS", Qt::CaseInsensitive ) )
568 scheme = "dvd";
569 else if( dir.endsWith( DIR_SEP "BDMV", Qt::CaseInsensitive ) )
571 scheme = "bluray";
572 dir.remove( "BDMV" );
575 char *uri = vlc_path2uri( qtu( toNativeSeparators( dir ) ), scheme );
576 if( unlikely(uri == NULL) )
577 return QString();
579 dir = qfu( uri );
580 free( uri );
582 RecentsMRL::getInstance( p_intf )->addRecent( dir );
584 return dir;
587 void DialogsProvider::PLOpenDir()
589 openDirectory( p_intf, true );
592 void DialogsProvider::PLAppendDir()
594 openDirectory( p_intf, false );
597 /****************
598 * Playlist *
599 ****************/
600 void DialogsProvider::openAPlaylist()
602 QStringList urls = showSimpleOpen( qtr( "Open playlist..." ),
603 EXT_FILTER_PLAYLIST );
604 foreach( const QString &url, urls )
606 char* psz_path = vlc_uri2path(qtu( url ));
607 if ( !psz_path )
609 msg_Warn( p_intf, "unable to load playlist '%s'", qtu( url ) );
610 continue;
612 playlist_Import( THEPL, psz_path );
613 free( psz_path );
617 void DialogsProvider::savePlayingToPlaylist()
619 static const struct
621 char filter_name[14];
622 char filter_patterns[5];
623 char module[12];
624 } types[] = {
625 { N_("XSPF playlist"), "xspf", "export-xspf", },
626 { N_("M3U playlist"), "m3u", "export-m3u", },
627 { N_("M3U8 playlist"), "m3u8", "export-m3u8", },
628 { N_("HTML playlist"), "html", "export-html", },
631 QStringList filters;
632 QString ext = getSettings()->value( "last-playlist-ext" ).toString();
634 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++ )
636 QString tmp = qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + types[i].filter_patterns + ")";
637 if( ext == qfu( types[i].filter_patterns ) )
638 filters.insert( 0, tmp );
639 else
640 filters.append( tmp );
643 QString selected;
644 QString file = getSaveFileName( NULL,
645 qtr( "Save playlist as..." ),
646 p_intf->p_sys->filepath, filters.join( ";;" ),
647 &selected );
648 const char *psz_selected_module = NULL;
649 const char *psz_last_playlist_ext = NULL;
651 if( file.isEmpty() )
652 return;
654 /* First test if the file extension is set, and different to selected filter */
655 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
657 if ( file.endsWith( QString( "." ) + qfu( types[i].filter_patterns ) ) )
659 psz_selected_module = types[i].module;
660 psz_last_playlist_ext = types[i].filter_patterns;
661 break;
665 /* otherwise apply the selected extension */
666 if ( !psz_last_playlist_ext )
668 for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
670 if ( selected.startsWith( qfu( vlc_gettext( types[i].filter_name ) ) ) )
672 psz_selected_module = types[i].module;
673 psz_last_playlist_ext = types[i].filter_patterns;
674 /* Fix file extension */
675 file = file.append( QString( "." ) + qfu( psz_last_playlist_ext ) );
676 break;
681 if ( psz_selected_module )
683 playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
684 psz_selected_module );
685 getSettings()->setValue( "last-playlist-ext", psz_last_playlist_ext );
689 /****************************************************************************
690 * Sout emulation
691 ****************************************************************************/
693 void DialogsProvider::streamingDialog( QWidget *parent,
694 const QStringList& mrls,
695 bool b_transcode_only,
696 QStringList options )
698 QStringList outputMRLs;
700 /* Stream */
701 // Does streaming multiple files make sense? I suppose so, just stream one
702 // after the other, but not at the moment.
703 if( !b_transcode_only )
705 SoutDialog *s = new SoutDialog( parent, p_intf, mrls[0] );
706 s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
707 if( s->exec() == QDialog::Accepted )
709 outputMRLs.append(s->getMrl());
710 delete s;
712 else
714 delete s; return;
716 } else {
717 /* Convert */
718 ConvertDialog *s = new ConvertDialog( parent, p_intf, mrls );
719 s->setAttribute( Qt::WA_QuitOnClose, false ); // See #4883
720 if( s->exec() == QDialog::Accepted )
722 /* Clear the playlist. This is because we're going to be populating
723 it */
724 playlist_Clear( THEPL, pl_Unlocked );
726 outputMRLs = s->getMrls();
727 delete s;
729 else
731 delete s; return;
735 /* Get SoutMRL(s) */
736 if( !outputMRLs.isEmpty() )
738 /* For all of our MRLs */
739 for(int i = 0; i < outputMRLs.length(); i++)
742 /* Duplicate the options list. This is because we need to have a
743 copy for every file we add to the playlist.*/
744 QStringList optionsCopy;
745 for(int j = 0; j < options.length(); j++)
747 optionsCopy.append(options[j]);
750 optionsCopy+= outputMRLs[i].split( " :");
751 QString title = "Converting " + mrls[i];
753 /* Add each file to convert to our playlist, making sure to not attempt to start playing it.*/
754 Open::openMRLwithOptions( p_intf, mrls[i], &optionsCopy, false, qtu( title ) );
757 /* Start the playlist from the beginning */
758 playlist_Control(THEPL,PLAYLIST_PLAY,pl_Unlocked);
762 void DialogsProvider::openAndStreamingDialogs()
764 OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM )
765 ->showTab( OPEN_FILE_TAB );
768 void DialogsProvider::openAndTranscodingDialogs()
770 OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE )
771 ->showTab( OPEN_FILE_TAB );
774 void DialogsProvider::loadSubtitlesFile()
776 input_thread_t *p_input = THEMIM->getInput();
777 if( !p_input ) return;
779 input_item_t *p_item = input_GetItem( p_input );
780 if( !p_item ) return;
782 char *path = input_item_GetURI( p_item );
783 QUrl url;
784 if( path )
786 url.setUrl( qfu(path) );
787 url = url.adjusted(QUrl::RemoveFilename);
788 if (url.scheme() != "file")
789 url.clear();
790 free(path);
793 QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ),
794 EXT_FILTER_SUBTITLE,
795 url );
797 foreach( const QString &qsUrl, qsl )
799 if( input_AddSlave( p_input, SLAVE_TYPE_SPU, qtu( qsUrl ), true, true, false ) )
800 msg_Warn( p_intf, "unable to load subtitles from '%s'",
801 qtu( qsUrl ) );
806 /****************************************************************************
807 * Menus
808 ****************************************************************************/
810 void DialogsProvider::menuAction( QObject *data )
812 VLCMenuBar::DoAction( data );
815 void DialogsProvider::menuUpdateAction( QObject *data )
817 MenuFunc *func = qobject_cast<MenuFunc *>(data);
818 assert( func );
819 func->doFunc( p_intf );
822 void DialogsProvider::sendKey( int key )
824 // translate from a vlc keycode into a Qt sequence
825 QKeySequence kseq0( VLCKeyToString( key, true ) );
827 if( popupMenu == NULL )
829 // make sure at least a non visible popupmenu is available
830 popupMenu = VLCMenuBar::PopupMenu( p_intf, false );
831 if( unlikely( popupMenu == NULL ) )
832 return;
835 // test against key accelerators from the popupmenu
836 QList<QAction*> actions = popupMenu->findChildren<QAction*>();
837 for( int i = 0; i < actions.size(); i++ )
839 QAction* action = actions.at(i);
840 QKeySequence kseq = action->shortcut();
841 if( kseq == kseq0 )
843 action->trigger();
844 return;
848 // forward key to vlc core when not a key accelerator
849 var_SetInteger( p_intf->obj.libvlc, "key-pressed", key );