macOS vout: fix forgotten ';'
[vlc.git] / modules / gui / qt / qt.cpp
blobdedd1e5994e843de182232f57ba428704d8b92bd
1 /*****************************************************************************
2 * qt.cpp : Qt interface
3 ****************************************************************************
4 * Copyright © 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 #define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
31 #include <stdlib.h>
32 #include <unistd.h>
33 #ifndef _POSIX_SPAWN
34 # define _POSIX_SPAWN (-1)
35 #endif
36 #if (_POSIX_SPAWN >= 0)
37 # include <spawn.h>
38 # include <sys/wait.h>
40 extern "C" char **environ;
41 #endif
43 #include <QApplication>
44 #include <QDate>
45 #include <QMutex>
47 #include "qt.hpp"
49 #include "input_manager.hpp" /* THEMIM destruction */
50 #include "dialogs_provider.hpp" /* THEDP creation */
51 #ifdef _WIN32
52 # include "main_interface_win32.hpp"
53 #else
54 # include "main_interface.hpp" /* MainInterface creation */
55 #endif
56 #include "extensions_manager.hpp" /* Extensions manager */
57 #include "managers/addons_manager.hpp" /* Addons manager */
58 #include "dialogs/help.hpp" /* Launch Update */
59 #include "recents.hpp" /* Recents Item destruction */
60 #include "util/qvlcapp.hpp" /* QVLCApplication definition */
61 #include "components/playlist/playlist_model.hpp" /* for ~PLModel() */
63 #include <vlc_plugin.h>
64 #include <vlc_vout_window.h>
65 #ifndef X_DISPLAY_MISSING
66 # include <vlc_xlib.h>
67 #endif
69 #ifdef _WIN32 /* For static builds */
70 #include <QtPlugin>
72 #ifdef QT_STATICPLUGIN
73 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
74 Q_IMPORT_PLUGIN(QSvgIconPlugin)
75 Q_IMPORT_PLUGIN(QSvgPlugin)
76 #if !HAS_QT56
77 Q_IMPORT_PLUGIN(AccessibleFactory)
78 #endif
79 #endif
80 #endif
82 /*****************************************************************************
83 * Local prototypes.
84 *****************************************************************************/
85 static int OpenIntf ( vlc_object_t * );
86 static int OpenDialogs ( vlc_object_t * );
87 static int Open ( vlc_object_t *, bool );
88 static void Close ( vlc_object_t * );
89 static int WindowOpen ( vout_window_t *, const vout_window_cfg_t * );
90 static void WindowClose ( vout_window_t * );
91 static void ShowDialog ( intf_thread_t *, int, int, intf_dialog_args_t * );
93 /*****************************************************************************
94 * Module descriptor
95 *****************************************************************************/
96 #define ADVANCED_PREFS_TEXT N_( "Show advanced preferences over simple ones" )
97 #define ADVANCED_PREFS_LONGTEXT N_( "Show advanced preferences and not simple "\
98 "preferences when opening the preferences "\
99 "dialog." )
101 #define SYSTRAY_TEXT N_( "Systray icon" )
102 #define SYSTRAY_LONGTEXT N_( "Show an icon in the systray " \
103 "allowing you to control VLC media player " \
104 "for basic actions." )
106 #define MINIMIZED_TEXT N_( "Start VLC with only a systray icon" )
107 #define MINIMIZED_LONGTEXT N_( "VLC will start with just an icon in " \
108 "your taskbar." )
110 #define KEEPSIZE_TEXT N_( "Resize interface to the native video size" )
111 #define KEEPSIZE_LONGTEXT N_( "You have two choices:\n" \
112 " - The interface will resize to the native video size\n" \
113 " - The video will fit to the interface size\n " \
114 "By default, interface resize to the native video size." )
116 #define TITLE_TEXT N_( "Show playing item name in window title" )
117 #define TITLE_LONGTEXT N_( "Show the name of the song or video in the " \
118 "controller window title." )
120 #define NOTIFICATION_TEXT N_( "Show notification popup on track change" )
121 #define NOTIFICATION_LONGTEXT N_( \
122 "Show a notification popup with the artist and track name when " \
123 "the current playlist item changes, when VLC is minimized or hidden." )
125 #define OPACITY_TEXT N_( "Windows opacity between 0.1 and 1" )
126 #define OPACITY_LONGTEXT N_( "Sets the windows opacity between 0.1 and 1 " \
127 "for main interface, playlist and extended panel."\
128 " This option only works with Windows and " \
129 "X11 with composite extensions." )
131 #define OPACITY_FS_TEXT N_( "Fullscreen controller opacity between 0.1 and 1" )
132 #define OPACITY_FS_LONGTEXT N_( "Sets the fullscreen controller opacity between 0.1 and 1 " \
133 "for main interface, playlist and extended panel."\
134 " This option only works with Windows and " \
135 "X11 with composite extensions." )
137 #define ERROR_TEXT N_( "Show unimportant error and warnings dialogs" )
139 #define UPDATER_TEXT N_( "Activate the updates availability notification" )
140 #define UPDATER_LONGTEXT N_( "Activate the automatic notification of new " \
141 "versions of the software. It runs once every " \
142 "two weeks." )
143 #define UPDATER_DAYS_TEXT N_("Number of days between two update checks")
145 #define PRIVACY_TEXT N_( "Ask for network policy at start" )
147 #define RECENTPLAY_TEXT N_( "Save the recently played items in the menu" )
149 #define RECENTPLAY_FILTER_TEXT N_( "List of words separated by | to filter" )
150 #define RECENTPLAY_FILTER_LONGTEXT N_( "Regular expression used to filter " \
151 "the recent items played in the player." )
153 #define SLIDERCOL_TEXT N_( "Define the colors of the volume slider" )
154 #define SLIDERCOL_LONGTEXT N_( "Define the colors of the volume slider\n" \
155 "By specifying the 12 numbers separated by a ';'\n" \
156 "Default is '255;255;255;20;226;20;255;176;15;235;30;20'\n" \
157 "An alternative can be '30;30;50;40;40;100;50;50;160;150;150;255'")
159 #define QT_MODE_TEXT N_( "Selection of the starting mode and look" )
160 #define QT_MODE_LONGTEXT N_( "Start VLC with:\n" \
161 " - normal mode\n" \
162 " - a zone always present to show information " \
163 "as lyrics, album arts...\n" \
164 " - minimal mode with limited controls" )
166 #define QT_FULLSCREEN_TEXT N_( "Show a controller in fullscreen mode" )
167 #define QT_NATIVEOPEN_TEXT N_( "Embed the file browser in open dialog" )
169 #define FULLSCREEN_NUMBER_TEXT N_( "Define which screen fullscreen goes" )
170 #define FULLSCREEN_NUMBER_LONGTEXT N_( "Screennumber of fullscreen, instead of " \
171 "same screen where interface is." )
173 #define QT_AUTOLOAD_EXTENSIONS_TEXT N_( "Load extensions on startup" )
174 #define QT_AUTOLOAD_EXTENSIONS_LONGTEXT N_( "Automatically load the "\
175 "extensions module on startup." )
177 #define QT_MINIMAL_MODE_TEXT N_("Start in minimal view (without menus)" )
179 #define QT_BGCONE_TEXT N_( "Display background cone or art" )
180 #define QT_BGCONE_LONGTEXT N_( "Display background cone or current album art " \
181 "when not playing. " \
182 "Can be disabled to prevent burning screen." )
183 #define QT_BGCONE_EXPANDS_TEXT N_( "Expanding background cone or art" )
184 #define QT_BGCONE_EXPANDS_LONGTEXT N_( "Background art fits window's size." )
186 #define QT_DISABLE_VOLUME_KEYS_TEXT N_( "Ignore keyboard volume buttons." )
187 #define QT_DISABLE_VOLUME_KEYS_LONGTEXT N_( \
188 "With this option checked, the volume up, volume down and mute buttons on your " \
189 "keyboard will always change your system volume. With this option unchecked, the " \
190 "volume buttons will change VLC's volume when VLC is selected and change the " \
191 "system volume when VLC is not selected." )
193 #define QT_PAUSE_MINIMIZED_TEXT N_( "Pause the video playback when minimized" )
194 #define QT_PAUSE_MINIMIZED_LONGTEXT N_( \
195 "With this option enabled, the playback will be automatically paused when minimizing the window." )
197 #define ICONCHANGE_TEXT N_( "Allow automatic icon changes")
198 #define ICONCHANGE_LONGTEXT N_( \
199 "This option allows the interface to change its icon on various occasions.")
201 #define VOLUME_MAX_TEXT N_( "Maximum Volume displayed" )
203 #define AUTORAISE_ON_PLAYBACK_TEXT N_( "When to raise the interface" )
204 #define AUTORAISE_ON_PLAYBACK_LONGTEXT N_( "This option allows the interface to be raised automatically " \
205 "when a video/audio playback starts, or never." )
207 #define FULLSCREEN_CONTROL_PIXELS N_( "Fullscreen controller mouse sensitivity" )
209 #define CONTINUE_PLAYBACK_TEXT N_("Continue playback?")
211 static const int i_notification_list[] =
212 { NOTIFICATION_NEVER, NOTIFICATION_MINIMIZED, NOTIFICATION_ALWAYS };
214 static const char *const psz_notification_list_text[] =
215 { N_("Never"), N_("When minimized"), N_("Always") };
217 static const int i_continue_list[] =
218 { 0, 1, 2 };
220 static const char *const psz_continue_list_text[] =
221 { N_("Never"), N_("Ask"), N_("Always") };
223 static const int i_raise_list[] =
224 { MainInterface::RAISE_NEVER, MainInterface::RAISE_VIDEO, \
225 MainInterface::RAISE_AUDIO, MainInterface::RAISE_AUDIOVIDEO, };
227 static const char *const psz_raise_list_text[] =
228 { N_( "Never" ), N_( "Video" ), N_( "Audio" ), _( "Audio/Video" ) };
230 /**********************************************************************/
231 vlc_module_begin ()
232 set_shortname( "Qt" )
233 set_description( N_("Qt interface") )
234 set_category( CAT_INTERFACE )
235 set_subcategory( SUBCAT_INTERFACE_MAIN )
236 set_capability( "interface", 151 )
237 set_callbacks( OpenIntf, Close )
239 add_shortcut("qt")
241 add_bool( "qt-minimal-view", false, QT_MINIMAL_MODE_TEXT,
242 QT_MINIMAL_MODE_TEXT, false );
244 add_bool( "qt-system-tray", true, SYSTRAY_TEXT, SYSTRAY_LONGTEXT, false)
246 add_integer( "qt-notification", NOTIFICATION_MINIMIZED,
247 NOTIFICATION_TEXT,
248 NOTIFICATION_LONGTEXT, false )
249 change_integer_list( i_notification_list, psz_notification_list_text )
251 add_bool( "qt-start-minimized", false, MINIMIZED_TEXT,
252 MINIMIZED_LONGTEXT, true)
253 add_bool( "qt-pause-minimized", false, QT_PAUSE_MINIMIZED_TEXT,
254 QT_PAUSE_MINIMIZED_LONGTEXT, false )
256 add_float_with_range( "qt-opacity", 1., 0.1, 1., OPACITY_TEXT,
257 OPACITY_LONGTEXT, false )
258 add_float_with_range( "qt-fs-opacity", 0.8, 0.1, 1., OPACITY_FS_TEXT,
259 OPACITY_FS_LONGTEXT, false )
261 add_bool( "qt-video-autoresize", true, KEEPSIZE_TEXT,
262 KEEPSIZE_LONGTEXT, false )
263 add_bool( "qt-name-in-title", true, TITLE_TEXT,
264 TITLE_LONGTEXT, false )
265 add_bool( "qt-fs-controller", true, QT_FULLSCREEN_TEXT,
266 QT_FULLSCREEN_TEXT, false )
268 add_bool( "qt-recentplay", true, RECENTPLAY_TEXT,
269 RECENTPLAY_TEXT, false )
270 add_string( "qt-recentplay-filter", "",
271 RECENTPLAY_FILTER_TEXT, RECENTPLAY_FILTER_LONGTEXT, false )
272 add_integer( "qt-continue", 1, CONTINUE_PLAYBACK_TEXT, CONTINUE_PLAYBACK_TEXT, false )
273 change_integer_list(i_continue_list, psz_continue_list_text )
275 #ifdef UPDATE_CHECK
276 add_bool( "qt-updates-notif", true, UPDATER_TEXT,
277 UPDATER_LONGTEXT, false )
278 add_integer_with_range( "qt-updates-days", 3, 0, 180,
279 UPDATER_DAYS_TEXT, UPDATER_DAYS_TEXT, false )
280 #endif
282 #ifdef _WIN32
283 add_bool( "qt-disable-volume-keys" /* name */,
284 true /* default value */,
285 QT_DISABLE_VOLUME_KEYS_TEXT /* text */,
286 QT_DISABLE_VOLUME_KEYS_LONGTEXT /* longtext */,
287 false /* advanced mode only */)
288 #endif
290 add_bool( "qt-embedded-open", false, QT_NATIVEOPEN_TEXT,
291 QT_NATIVEOPEN_TEXT, false )
294 add_bool( "qt-advanced-pref", false, ADVANCED_PREFS_TEXT,
295 ADVANCED_PREFS_LONGTEXT, false )
296 add_bool( "qt-error-dialogs", true, ERROR_TEXT,
297 ERROR_TEXT, false )
299 add_string( "qt-slider-colours", "153;210;153;20;210;20;255;199;15;245;39;29",
300 SLIDERCOL_TEXT, SLIDERCOL_LONGTEXT, false )
302 add_bool( "qt-privacy-ask", true, PRIVACY_TEXT, PRIVACY_TEXT,
303 false )
304 change_private ()
306 add_integer( "qt-fullscreen-screennumber", -1, FULLSCREEN_NUMBER_TEXT,
307 FULLSCREEN_NUMBER_LONGTEXT, false );
309 add_bool( "qt-autoload-extensions", true,
310 QT_AUTOLOAD_EXTENSIONS_TEXT, QT_AUTOLOAD_EXTENSIONS_LONGTEXT,
311 false )
313 add_bool( "qt-bgcone", true, QT_BGCONE_TEXT, QT_BGCONE_LONGTEXT, true )
314 add_bool( "qt-bgcone-expands", false, QT_BGCONE_EXPANDS_TEXT,
315 QT_BGCONE_EXPANDS_LONGTEXT, true )
317 add_bool( "qt-icon-change", true, ICONCHANGE_TEXT, ICONCHANGE_LONGTEXT, true )
319 add_integer_with_range( "qt-max-volume", 125, 60, 300, VOLUME_MAX_TEXT, VOLUME_MAX_TEXT, true)
321 add_integer_with_range( "qt-fs-sensitivity", 3, 0, 4000, FULLSCREEN_CONTROL_PIXELS,
322 FULLSCREEN_CONTROL_PIXELS, true)
324 add_obsolete_bool( "qt-blingbling" ) /* Suppressed since 1.0.0 */
325 add_obsolete_integer( "qt-display-mode" ) /* Suppressed since 1.1.0 */
327 add_obsolete_bool( "qt-adv-options" ) /* Since 2.0.0 */
328 add_obsolete_bool( "qt-volume-complete" ) /* Since 2.0.0 */
329 add_obsolete_integer( "qt-startvolume" ) /* Since 2.0.0 */
331 add_integer( "qt-auto-raise", MainInterface::RAISE_VIDEO, AUTORAISE_ON_PLAYBACK_TEXT,
332 AUTORAISE_ON_PLAYBACK_LONGTEXT, false )
333 change_integer_list( i_raise_list, psz_raise_list_text )
335 cannot_unload_broken_library()
337 add_submodule ()
338 set_description( "Dialogs provider" )
339 set_capability( "dialogs provider", 51 )
341 set_callbacks( OpenDialogs, Close )
343 add_submodule ()
344 set_capability( "vout window", 0 )
345 set_callbacks( WindowOpen, WindowClose )
347 vlc_module_end ()
349 /*****************************************/
351 /* Ugly, but the Qt interface assumes single instance anyway */
352 static vlc_sem_t ready;
353 static QMutex lock;
354 static bool busy = false;
355 static bool active = false;
357 /*****************************************************************************
358 * Module callbacks
359 *****************************************************************************/
361 static void *Thread( void * );
363 #ifdef Q_OS_MAC
364 /* Used to abort the app.exec() on OSX after libvlc_Quit is called */
365 #include "../../../lib/libvlc_internal.h" /* libvlc_SetExitHandler */
366 static void Abort( void *obj )
368 QVLCApp::triggerQuit();
370 #endif
372 /* Open Interface */
373 static int Open( vlc_object_t *p_this, bool isDialogProvider )
375 intf_thread_t *p_intf = (intf_thread_t *)p_this;
377 #ifndef X_DISPLAY_MISSING
378 if (!vlc_xlib_init(p_this))
379 return VLC_EGENERIC;
380 #endif
382 #if (_POSIX_SPAWN >= 0)
383 /* Check if QApplication works */
384 char *path = config_GetSysPath(VLC_PKG_LIBEXEC_DIR, "vlc-qt-check");
385 if (unlikely(path == NULL))
386 return VLC_ENOMEM;
388 char *argv[] = { path, NULL };
389 pid_t pid;
391 int val = posix_spawn(&pid, path, NULL, NULL, argv, environ);
392 free(path);
393 if (val)
394 return VLC_ENOMEM;
396 int status;
397 while (waitpid(pid, &status, 0) == -1);
399 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
401 msg_Dbg(p_this, "Qt check failed (%d). Skipping.", status);
402 return VLC_EGENERIC;
404 #endif
406 QMutexLocker locker (&lock);
407 if (busy)
409 msg_Err (p_this, "cannot start Qt multiple times");
410 return VLC_EGENERIC;
413 /* Allocations of p_sys */
414 intf_sys_t *p_sys = p_intf->p_sys = new intf_sys_t;
415 p_sys->b_isDialogProvider = isDialogProvider;
416 p_sys->p_mi = NULL;
417 p_sys->pl_model = NULL;
419 /* set up the playlist to work on */
420 if( isDialogProvider )
421 p_sys->p_playlist = pl_Get( (intf_thread_t *)p_intf->obj.parent );
422 else
423 p_sys->p_playlist = pl_Get( p_intf );
425 /* */
426 vlc_sem_init (&ready, 0);
427 #ifdef Q_OS_MAC
428 /* Run mainloop on the main thread as Cocoa requires */
429 libvlc_SetExitHandler( p_intf->obj.libvlc, Abort, p_intf );
430 thread( (void *)p_intf );
431 #else
432 if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
434 delete p_sys;
435 return VLC_ENOMEM;
437 #endif
439 /* Wait for the interface to be ready. This prevents the main
440 * LibVLC thread from starting video playback before we can create
441 * an embedded video window. */
442 vlc_sem_wait (&ready);
443 vlc_sem_destroy (&ready);
444 busy = active = true;
446 return VLC_SUCCESS;
449 /* Open Qt interface */
450 static int OpenIntf( vlc_object_t *p_this )
452 return Open( p_this, false );
455 /* Open Dialog Provider */
456 static int OpenDialogs( vlc_object_t *p_this )
458 return Open( p_this, true );
461 static void Close( vlc_object_t *p_this )
463 intf_thread_t *p_intf = (intf_thread_t *)p_this;
464 intf_sys_t *p_sys = p_intf->p_sys;
466 if( !p_sys->b_isDialogProvider )
468 playlist_t *pl = THEPL;
470 playlist_Deactivate (pl); /* release window provider if needed */
473 /* And quit */
474 msg_Dbg( p_this, "requesting exit..." );
475 QVLCApp::triggerQuit();
477 msg_Dbg( p_this, "waiting for UI thread..." );
478 #ifndef Q_OS_MAC
479 vlc_join (p_sys->thread, NULL);
480 #endif
481 delete p_sys;
483 QMutexLocker locker (&lock);
484 assert (busy);
485 busy = false;
488 static void *Thread( void *obj )
490 intf_thread_t *p_intf = (intf_thread_t *)obj;
491 intf_sys_t *p_sys = p_intf->p_sys;
492 char vlc_name[] = "vlc"; /* for WM_CLASS */
493 char *argv[2];
494 int argc = 0;
496 argv[argc++] = vlc_name;
497 argv[argc] = NULL;
499 Q_INIT_RESOURCE( vlc );
501 #if HAS_QT56
502 QApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
503 QApplication::setAttribute( Qt::AA_UseHighDpiPixmaps );
504 #endif
506 /* Start the QApplication here */
507 QVLCApp app( argc, argv );
509 /* Set application direction to locale direction,
510 * necessary for RTL locales */
511 app.setLayoutDirection(QLocale().textDirection());
513 p_sys->p_app = &app;
516 /* All the settings are in the .conf/.ini style */
517 #ifdef _WIN32
518 char *cConfigDir = config_GetUserDir( VLC_CONFIG_DIR );
519 QString configDir = cConfigDir;
520 free( cConfigDir );
521 if( configDir.endsWith( "\\vlc" ) )
522 configDir.chop( 4 ); /* the "\vlc" dir is added again by QSettings */
523 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configDir );
524 #endif
526 p_sys->mainSettings = new QSettings(
527 #ifdef _WIN32
528 QSettings::IniFormat,
529 #else
530 QSettings::NativeFormat,
531 #endif
532 QSettings::UserScope, "vlc", "vlc-qt-interface" );
534 if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
535 app.setWindowIcon( QIcon::fromTheme( "vlc-xmas", QIcon( ":/logo/vlc128-xmas.png" ) ) );
536 else
537 app.setWindowIcon( QIcon::fromTheme( "vlc", QIcon( ":/logo/vlc256.png" ) ) );
539 /* Initialize the Dialog Provider and the Main Input Manager */
540 DialogsProvider::getInstance( p_intf );
541 MainInputManager* mim = MainInputManager::getInstance( p_intf );
542 mim->probeCurrentInput();
544 #ifdef UPDATE_CHECK
545 /* Checking for VLC updates */
546 if( var_InheritBool( p_intf, "qt-updates-notif" ) &&
547 !var_InheritBool( p_intf, "qt-privacy-ask" ) )
549 int interval = var_InheritInteger( p_intf, "qt-updates-days" );
550 if( QDate::currentDate() >
551 getSettings()->value( "updatedate" ).toDate().addDays( interval ) )
553 /* The constructor of the update Dialog will do the 1st request */
554 UpdateDialog::getInstance( p_intf );
555 getSettings()->setValue( "updatedate", QDate::currentDate() );
558 #endif
560 /* Create the normal interface in non-DP mode */
561 MainInterface *p_mi = NULL;
563 if( !p_sys->b_isDialogProvider )
565 #ifdef _WIN32
566 p_mi = new MainInterfaceWin32( p_intf );
567 #else
568 p_mi = new MainInterface( p_intf );
569 #endif
570 p_sys->p_mi = p_mi;
572 /* Check window type from the Qt platform back-end */
573 p_sys->voutWindowType = VOUT_WINDOW_TYPE_INVALID;
574 QString platform = app.platformName();
575 if( platform == qfu("xcb") )
576 p_sys->voutWindowType = VOUT_WINDOW_TYPE_XID;
577 else if( platform == qfu("wayland") )
578 p_sys->voutWindowType = VOUT_WINDOW_TYPE_WAYLAND;
579 else if( platform == qfu("windows") )
580 p_sys->voutWindowType = VOUT_WINDOW_TYPE_HWND;
581 else if( platform == qfu("cocoa" ) )
582 p_sys->voutWindowType = VOUT_WINDOW_TYPE_NSOBJECT;
583 else
584 msg_Err( p_intf, "unknown Qt platform: %s", qtu(platform) );
586 var_Create( THEPL, "qt4-iface", VLC_VAR_ADDRESS );
587 var_SetAddress( THEPL, "qt4-iface", p_intf );
588 var_Create( THEPL, "window", VLC_VAR_STRING );
589 if( p_sys->voutWindowType != VOUT_WINDOW_TYPE_INVALID )
590 var_SetString( THEPL, "window", "qt,any" );
593 /* Explain how to show a dialog :D */
594 p_intf->pf_show_dialog = ShowDialog;
596 /* Tell the main LibVLC thread we are ready */
597 vlc_sem_post (&ready);
599 #ifdef Q_OS_MAC
600 /* We took over main thread, register and start here */
601 if( !p_sys->b_isDialogProvider )
602 playlist_Play( THEPL );
603 #endif
605 /* Last settings */
606 app.setQuitOnLastWindowClosed( false );
608 /* Retrieve last known path used in file browsing */
609 p_sys->filepath =
610 getSettings()->value( "filedialog-path", QVLCUserDir( VLC_HOME_DIR ) ).toString();
612 /* Loads and tries to apply the preferred QStyle */
613 QString s_style = getSettings()->value( "MainWindow/QtStyle", "" ).toString();
614 if( s_style.compare("") != 0 )
615 QApplication::setStyle( s_style );
617 /* Launch */
618 app.exec();
620 msg_Dbg( p_intf, "QApp exec() finished" );
621 if (p_mi != NULL)
623 var_Destroy( THEPL, "window" );
624 var_Destroy( THEPL, "qt4-iface" );
626 QMutexLocker locker (&lock);
627 active = false;
629 p_sys->p_mi = NULL;
630 /* Destroy first the main interface because it is connected to some
631 slots in the MainInputManager */
632 delete p_mi;
635 /* */
636 ExtensionsManager::killInstance();
637 AddonsManager::killInstance();
639 /* Destroy all remaining windows,
640 because some are connected to some slots
641 in the MainInputManager
642 Settings must be destroyed after that.
644 DialogsProvider::killInstance();
646 /* Delete the recentsMRL object before the configuration */
647 RecentsMRL::killInstance();
649 /* Save the path or delete if recent play are disabled */
650 if( var_InheritBool( p_intf, "qt-recentplay" ) )
651 getSettings()->setValue( "filedialog-path", p_sys->filepath );
652 else
653 getSettings()->remove( "filedialog-path" );
655 /* */
656 delete p_sys->pl_model;
658 /* Destroy the MainInputManager */
659 MainInputManager::killInstance();
661 /* Delete the configuration. Application has to be deleted after that. */
662 delete p_sys->mainSettings;
664 /* Delete the application automatically */
665 return NULL;
668 /*****************************************************************************
669 * Callback to show a dialog
670 *****************************************************************************/
671 static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
672 intf_dialog_args_t *p_arg )
674 VLC_UNUSED( p_intf );
675 DialogEvent *event = new DialogEvent( i_dialog_event, i_arg, p_arg );
676 QApplication::postEvent( THEDP, event );
680 * Video output window provider
682 * TODO move it out of here ?
684 static int WindowControl( vout_window_t *, int i_query, va_list );
686 static int WindowOpen( vout_window_t *p_wnd, const vout_window_cfg_t *cfg )
688 if( cfg->is_standalone )
689 return VLC_EGENERIC;
691 intf_thread_t *p_intf =
692 (intf_thread_t *)var_InheritAddress( p_wnd, "qt4-iface" );
693 if( !p_intf )
694 { /* If another interface is used, this plugin cannot work */
695 msg_Dbg( p_wnd, "Qt interface not found" );
696 return VLC_EGENERIC;
699 if( cfg->type != VOUT_WINDOW_TYPE_INVALID
700 && cfg->type != p_intf->p_sys->voutWindowType )
701 return VLC_EGENERIC;
703 switch( p_intf->p_sys->voutWindowType )
705 case VOUT_WINDOW_TYPE_XID:
706 if( var_InheritBool( p_wnd, "video-wallpaper" ) )
707 return VLC_EGENERIC;
708 break;
711 QMutexLocker locker (&lock);
712 if (unlikely(!active))
713 return VLC_EGENERIC;
715 MainInterface *p_mi = p_intf->p_sys->p_mi;
716 msg_Dbg( p_wnd, "requesting video window..." );
718 if( !p_mi->getVideo( p_wnd, cfg->width, cfg->height, cfg->is_fullscreen ) )
719 return VLC_EGENERIC;
721 p_wnd->info.has_double_click = true;
722 p_wnd->control = WindowControl;
723 p_wnd->sys = (vout_window_sys_t*)p_mi;
724 return VLC_SUCCESS;
727 static int WindowControl( vout_window_t *p_wnd, int i_query, va_list args )
729 MainInterface *p_mi = (MainInterface *)p_wnd->sys;
730 QMutexLocker locker (&lock);
732 if (unlikely(!active))
734 msg_Warn (p_wnd, "video already released before control");
735 return VLC_EGENERIC;
737 return p_mi->controlVideo( i_query, args );
740 static void WindowClose( vout_window_t *p_wnd )
742 MainInterface *p_mi = (MainInterface *)p_wnd->sys;
743 QMutexLocker locker (&lock);
745 /* Normally, the interface terminates after the video. In the contrary, the
746 * Qt main loop is gone, so we cannot send any event to the user interface
747 * widgets. Ideally, we would keep the Qt main loop running until after
748 * the video window is released. But it is far simpler to just have the Qt
749 * thread destroy the window early, and to turn this function into a stub.
751 * That assumes the video output will behave sanely if it window is
752 * destroyed asynchronously.
753 * XCB and Xlib-XCB are fine with that. Plain Xlib wouldn't, */
754 if (unlikely(!active))
756 msg_Warn (p_wnd, "video already released");
757 return;
759 msg_Dbg (p_wnd, "releasing video...");
760 p_mi->releaseVideo();