qt: move the main interface to its own folder
[vlc.git] / modules / gui / qt / qt.cpp
blob176c6a6da788bd22f769dec90097e5c9af4a6fc6
1 /*****************************************************************************
2 * qt.cpp : Qt interface
3 ****************************************************************************
4 * Copyright © 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 #define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
30 #include <stdlib.h>
31 #include <unistd.h>
32 #ifndef _POSIX_SPAWN
33 # define _POSIX_SPAWN (-1)
34 #endif
35 #if (_POSIX_SPAWN >= 0)
36 # include <spawn.h>
37 # include <sys/wait.h>
39 extern "C" char **environ;
40 #endif
42 #include <QApplication>
43 #include <QDate>
44 #include <QMutex>
45 #include <QtQuickControls2/QQuickStyle>
47 #include "qt.hpp"
49 #include "player/player_controller.hpp" /* THEMIM destruction */
50 #include "playlist/playlist_controller.hpp" /* THEMPL creation */
51 #include "dialogs/dialogs_provider.hpp" /* THEDP creation */
52 #ifdef _WIN32
53 # include "maininterface/main_interface_win32.hpp"
54 #else
55 # include "maininterface/main_interface.hpp" /* MainInterface creation */
56 #endif
57 #include "dialogs/extensions/extensions_manager.hpp" /* Extensions manager */
58 #include "dialogs/plugins/addons_manager.hpp" /* Addons manager */
59 #include "dialogs/help/help.hpp" /* Launch Update */
60 #include "recents.hpp" /* Recents Item destruction */
61 #include "util/qvlcapp.hpp" /* QVLCApplication definition */
63 #include <QVector>
64 #include "playlist/playlist_item.hpp"
66 #include <vlc_plugin.h>
67 #include <vlc_vout_window.h>
68 #include <vlc_cxx_helpers.hpp>
70 #ifdef QT_STATIC /* For static builds */
71 #include <QtPlugin>
72 #include <QQuickWindow>
74 #ifdef QT_STATICPLUGIN
75 Q_IMPORT_PLUGIN(QSvgIconPlugin)
76 Q_IMPORT_PLUGIN(QSvgPlugin)
77 Q_IMPORT_PLUGIN(QJpegPlugin)
78 Q_IMPORT_PLUGIN(QtQuick2Plugin)
79 Q_IMPORT_PLUGIN(QtQuickControls2Plugin)
80 Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin)
81 Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)
82 Q_IMPORT_PLUGIN(QtQuickTemplates2Plugin)
83 Q_IMPORT_PLUGIN(QtQmlModelsPlugin)
84 Q_IMPORT_PLUGIN(QtGraphicalEffectsPlugin)
85 Q_IMPORT_PLUGIN(QtGraphicalEffectsPrivatePlugin)
87 #if !HAS_QT56
88 Q_IMPORT_PLUGIN(AccessibleFactory)
89 #endif
90 #ifdef _WIN32
91 Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin)
92 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
93 #endif
94 #endif
95 #endif
97 #ifndef X_DISPLAY_MISSING
98 # include <vlc_xlib.h>
99 #endif
101 /*****************************************************************************
102 * Local prototypes.
103 *****************************************************************************/
104 static int OpenIntf ( vlc_object_t * );
105 static int OpenDialogs ( vlc_object_t * );
106 static int Open ( vlc_object_t *, bool );
107 static void Close ( vlc_object_t * );
108 static int WindowOpen ( vout_window_t * );
109 static void ShowDialog ( intf_thread_t *, int, int, intf_dialog_args_t * );
111 /*****************************************************************************
112 * Module descriptor
113 *****************************************************************************/
114 #define ADVANCED_PREFS_TEXT N_( "Show advanced preferences over simple ones" )
115 #define ADVANCED_PREFS_LONGTEXT N_( "Show advanced preferences and not simple "\
116 "preferences when opening the preferences "\
117 "dialog." )
119 #define SYSTRAY_TEXT N_( "Systray icon" )
120 #define SYSTRAY_LONGTEXT N_( "Show an icon in the systray " \
121 "allowing you to control VLC media player " \
122 "for basic actions." )
124 #define MINIMIZED_TEXT N_( "Start VLC with only a systray icon" )
125 #define MINIMIZED_LONGTEXT N_( "VLC will start with just an icon in " \
126 "your taskbar." )
128 #define KEEPSIZE_TEXT N_( "Resize interface to the native video size" )
129 #define KEEPSIZE_LONGTEXT N_( "You have two choices:\n" \
130 " - The interface will resize to the native video size\n" \
131 " - The video will fit to the interface size\n " \
132 "By default, interface resize to the native video size." )
134 #define TITLE_TEXT N_( "Show playing item name in window title" )
135 #define TITLE_LONGTEXT N_( "Show the name of the song or video in the " \
136 "controller window title." )
138 #define NOTIFICATION_TEXT N_( "Show notification popup on track change" )
139 #define NOTIFICATION_LONGTEXT N_( \
140 "Show a notification popup with the artist and track name when " \
141 "the current playlist item changes, when VLC is minimized or hidden." )
143 #define OPACITY_TEXT N_( "Windows opacity between 0.1 and 1" )
144 #define OPACITY_LONGTEXT N_( "Sets the windows opacity between 0.1 and 1 " \
145 "for main interface, playlist and extended panel."\
146 " This option only works with Windows and " \
147 "X11 with composite extensions." )
149 #define OPACITY_FS_TEXT N_( "Fullscreen controller opacity between 0.1 and 1" )
150 #define OPACITY_FS_LONGTEXT N_( "Sets the fullscreen controller opacity between 0.1 and 1 " \
151 "for main interface, playlist and extended panel."\
152 " This option only works with Windows and " \
153 "X11 with composite extensions." )
155 #define ERROR_TEXT N_( "Show unimportant error and warnings dialogs" )
157 #define UPDATER_TEXT N_( "Activate the updates availability notification" )
158 #define UPDATER_LONGTEXT N_( "Activate the automatic notification of new " \
159 "versions of the software. It runs once every " \
160 "two weeks." )
162 #define QT_QML_DEBUG_TEXT N_( "set the options for qml debugger" )
163 #define QT_QML_DEBUG_LONGTEXT N_( "set the options for qml debugger (see http://doc.qt.io/qt-5/qtquick-debugging.html#starting-applications)" )
165 #define UPDATER_DAYS_TEXT N_("Number of days between two update checks")
167 #define PRIVACY_TEXT N_( "Ask for network policy at start" )
169 #define RECENTPLAY_TEXT N_( "Save the recently played items in the menu" )
171 #define RECENTPLAY_FILTER_TEXT N_( "List of words separated by | to filter" )
172 #define RECENTPLAY_FILTER_LONGTEXT N_( "Regular expression used to filter " \
173 "the recent items played in the player." )
175 #define SLIDERCOL_TEXT N_( "Define the colors of the volume slider" )
176 #define SLIDERCOL_LONGTEXT N_( "Define the colors of the volume slider\n" \
177 "By specifying the 12 numbers separated by a ';'\n" \
178 "Default is '255;255;255;20;226;20;255;176;15;235;30;20'\n" \
179 "An alternative can be '30;30;50;40;40;100;50;50;160;150;150;255'")
181 #define QT_MODE_TEXT N_( "Selection of the starting mode and look" )
182 #define QT_MODE_LONGTEXT N_( "Start VLC with:\n" \
183 " - normal mode\n" \
184 " - a zone always present to show information " \
185 "as lyrics, album arts...\n" \
186 " - minimal mode with limited controls" )
188 #define QT_FULLSCREEN_TEXT N_( "Show a controller in fullscreen mode" )
189 #define QT_NATIVEOPEN_TEXT N_( "Embed the file browser in open dialog" )
191 #define FULLSCREEN_NUMBER_TEXT N_( "Define which screen fullscreen goes" )
192 #define FULLSCREEN_NUMBER_LONGTEXT N_( "Screennumber of fullscreen, instead of " \
193 "same screen where interface is." )
195 #define QT_AUTOLOAD_EXTENSIONS_TEXT N_( "Load extensions on startup" )
196 #define QT_AUTOLOAD_EXTENSIONS_LONGTEXT N_( "Automatically load the "\
197 "extensions module on startup." )
199 #define QT_MINIMAL_MODE_TEXT N_("Start in minimal view (without menus)" )
201 #define QT_BGCONE_TEXT N_( "Display background cone or art" )
202 #define QT_BGCONE_LONGTEXT N_( "Display background cone or current album art " \
203 "when not playing. " \
204 "Can be disabled to prevent burning screen." )
205 #define QT_BGCONE_EXPANDS_TEXT N_( "Expanding background cone or art" )
206 #define QT_BGCONE_EXPANDS_LONGTEXT N_( "Background art fits window's size." )
208 #define QT_DISABLE_VOLUME_KEYS_TEXT N_( "Ignore keyboard volume buttons." )
209 #define QT_DISABLE_VOLUME_KEYS_LONGTEXT N_( \
210 "With this option checked, the volume up, volume down and mute buttons on your " \
211 "keyboard will always change your system volume. With this option unchecked, the " \
212 "volume buttons will change VLC's volume when VLC is selected and change the " \
213 "system volume when VLC is not selected." )
215 #define QT_PAUSE_MINIMIZED_TEXT N_( "Pause the video playback when minimized" )
216 #define QT_PAUSE_MINIMIZED_LONGTEXT N_( \
217 "With this option enabled, the playback will be automatically paused when minimizing the window." )
219 #define ICONCHANGE_TEXT N_( "Allow automatic icon changes")
220 #define ICONCHANGE_LONGTEXT N_( \
221 "This option allows the interface to change its icon on various occasions.")
223 #define VOLUME_MAX_TEXT N_( "Maximum Volume displayed" )
225 #define AUTORAISE_ON_PLAYBACK_TEXT N_( "When to raise the interface" )
226 #define AUTORAISE_ON_PLAYBACK_LONGTEXT N_( "This option allows the interface to be raised automatically " \
227 "when a video/audio playback starts, or never." )
229 #define FULLSCREEN_CONTROL_PIXELS N_( "Fullscreen controller mouse sensitivity" )
231 #define CONTINUE_PLAYBACK_TEXT N_("Continue playback?")
233 static const int i_notification_list[] =
234 { NOTIFICATION_NEVER, NOTIFICATION_MINIMIZED, NOTIFICATION_ALWAYS };
236 static const char *const psz_notification_list_text[] =
237 { N_("Never"), N_("When minimized"), N_("Always") };
239 static const int i_continue_list[] =
240 { 0, 1, 2 };
242 static const char *const psz_continue_list_text[] =
243 { N_("Never"), N_("Ask"), N_("Always") };
245 static const int i_raise_list[] =
246 { MainInterface::RAISE_NEVER, MainInterface::RAISE_VIDEO, \
247 MainInterface::RAISE_AUDIO, MainInterface::RAISE_AUDIOVIDEO, };
249 static const char *const psz_raise_list_text[] =
250 { N_( "Never" ), N_( "Video" ), N_( "Audio" ), _( "Audio/Video" ) };
252 /**********************************************************************/
253 vlc_module_begin ()
254 set_shortname( "Qt" )
255 set_description( N_("Qt interface") )
256 set_category( CAT_INTERFACE )
257 set_subcategory( SUBCAT_INTERFACE_MAIN )
258 set_capability( "interface", 151 )
259 set_callbacks( OpenIntf, Close )
261 add_shortcut("qt")
263 add_bool( "qt-minimal-view", false, QT_MINIMAL_MODE_TEXT,
264 QT_MINIMAL_MODE_TEXT, false );
266 add_bool( "qt-system-tray", true, SYSTRAY_TEXT, SYSTRAY_LONGTEXT, false)
268 add_integer( "qt-notification", NOTIFICATION_MINIMIZED,
269 NOTIFICATION_TEXT,
270 NOTIFICATION_LONGTEXT, false )
271 change_integer_list( i_notification_list, psz_notification_list_text )
273 add_bool( "qt-start-minimized", false, MINIMIZED_TEXT,
274 MINIMIZED_LONGTEXT, true)
275 add_bool( "qt-pause-minimized", false, QT_PAUSE_MINIMIZED_TEXT,
276 QT_PAUSE_MINIMIZED_LONGTEXT, false )
278 add_float_with_range( "qt-opacity", 1., 0.1, 1., OPACITY_TEXT,
279 OPACITY_LONGTEXT, false )
280 add_float_with_range( "qt-fs-opacity", 0.8, 0.1, 1., OPACITY_FS_TEXT,
281 OPACITY_FS_LONGTEXT, false )
283 add_bool( "qt-video-autoresize", true, KEEPSIZE_TEXT,
284 KEEPSIZE_LONGTEXT, false )
285 add_bool( "qt-name-in-title", true, TITLE_TEXT,
286 TITLE_LONGTEXT, false )
287 add_bool( "qt-fs-controller", true, QT_FULLSCREEN_TEXT,
288 QT_FULLSCREEN_TEXT, false )
290 add_bool( "qt-recentplay", true, RECENTPLAY_TEXT,
291 RECENTPLAY_TEXT, false )
292 add_string( "qt-recentplay-filter", "",
293 RECENTPLAY_FILTER_TEXT, RECENTPLAY_FILTER_LONGTEXT, false )
294 add_integer( "qt-continue", 1, CONTINUE_PLAYBACK_TEXT, CONTINUE_PLAYBACK_TEXT, false )
295 change_integer_list(i_continue_list, psz_continue_list_text )
297 #ifdef UPDATE_CHECK
298 add_bool( "qt-updates-notif", true, UPDATER_TEXT,
299 UPDATER_LONGTEXT, false )
300 add_integer_with_range( "qt-updates-days", 3, 0, 180,
301 UPDATER_DAYS_TEXT, UPDATER_DAYS_TEXT, false )
302 #endif
304 #ifdef QT_QML_DEBUG
305 add_string( "qt-qmljsdebugger", NULL,
306 QT_QML_DEBUG_TEXT, QT_QML_DEBUG_LONGTEXT, false )
307 #endif
309 #ifdef _WIN32
310 add_bool( "qt-disable-volume-keys" /* name */,
311 true /* default value */,
312 QT_DISABLE_VOLUME_KEYS_TEXT /* text */,
313 QT_DISABLE_VOLUME_KEYS_LONGTEXT /* longtext */,
314 false /* advanced mode only */)
315 #endif
317 add_bool( "qt-embedded-open", false, QT_NATIVEOPEN_TEXT,
318 QT_NATIVEOPEN_TEXT, false )
321 add_bool( "qt-advanced-pref", false, ADVANCED_PREFS_TEXT,
322 ADVANCED_PREFS_LONGTEXT, false )
323 add_bool( "qt-error-dialogs", true, ERROR_TEXT,
324 ERROR_TEXT, false )
326 add_string( "qt-slider-colours", "153;210;153;20;210;20;255;199;15;245;39;29",
327 SLIDERCOL_TEXT, SLIDERCOL_LONGTEXT, false )
329 add_bool( "qt-privacy-ask", true, PRIVACY_TEXT, PRIVACY_TEXT,
330 false )
331 change_private ()
333 add_integer( "qt-fullscreen-screennumber", -1, FULLSCREEN_NUMBER_TEXT,
334 FULLSCREEN_NUMBER_LONGTEXT, false );
336 add_bool( "qt-autoload-extensions", true,
337 QT_AUTOLOAD_EXTENSIONS_TEXT, QT_AUTOLOAD_EXTENSIONS_LONGTEXT,
338 false )
340 add_bool( "qt-bgcone", true, QT_BGCONE_TEXT, QT_BGCONE_LONGTEXT, true )
341 add_bool( "qt-bgcone-expands", false, QT_BGCONE_EXPANDS_TEXT,
342 QT_BGCONE_EXPANDS_LONGTEXT, true )
344 add_bool( "qt-icon-change", true, ICONCHANGE_TEXT, ICONCHANGE_LONGTEXT, true )
346 add_integer_with_range( "qt-max-volume", 125, 60, 300, VOLUME_MAX_TEXT, VOLUME_MAX_TEXT, true)
348 add_integer_with_range( "qt-fs-sensitivity", 3, 0, 4000, FULLSCREEN_CONTROL_PIXELS,
349 FULLSCREEN_CONTROL_PIXELS, true)
351 add_obsolete_bool( "qt-blingbling" ) /* Suppressed since 1.0.0 */
352 add_obsolete_integer( "qt-display-mode" ) /* Suppressed since 1.1.0 */
354 add_obsolete_bool( "qt-adv-options" ) /* Since 2.0.0 */
355 add_obsolete_bool( "qt-volume-complete" ) /* Since 2.0.0 */
356 add_obsolete_integer( "qt-startvolume" ) /* Since 2.0.0 */
358 add_integer( "qt-auto-raise", MainInterface::RAISE_VIDEO, AUTORAISE_ON_PLAYBACK_TEXT,
359 AUTORAISE_ON_PLAYBACK_LONGTEXT, false )
360 change_integer_list( i_raise_list, psz_raise_list_text )
362 cannot_unload_broken_library()
364 add_submodule ()
365 set_description( "Dialogs provider" )
366 set_capability( "dialogs provider", 51 )
368 set_callbacks( OpenDialogs, Close )
370 add_submodule ()
371 set_capability( "vout window", 0 )
372 set_callback( WindowOpen )
374 vlc_module_end ()
376 /*****************************************/
378 /* Ugly, but the Qt interface assumes single instance anyway */
379 static vlc_cond_t wait_ready = VLC_STATIC_COND;
380 static vlc_mutex_t lock = VLC_STATIC_MUTEX;
381 static bool busy = false;
382 static enum {
383 OPEN_STATE_INIT,
384 OPEN_STATE_OPENED,
385 OPEN_STATE_ERROR,
386 } open_state = OPEN_STATE_INIT;
388 /*****************************************************************************
389 * Module callbacks
390 *****************************************************************************/
392 static void *Thread( void * );
393 static void *ThreadCleanup( intf_thread_t *p_intf, bool error );
395 #ifdef Q_OS_MAC
396 /* Used to abort the app.exec() on OSX after libvlc_Quit is called */
397 #include "../../../lib/libvlc_internal.h" /* libvlc_SetExitHandler */
398 static void Abort( void *obj )
400 QVLCApp::triggerQuit();
402 #endif
404 /* Open Interface */
405 static int Open( vlc_object_t *p_this, bool isDialogProvider )
407 intf_thread_t *p_intf = (intf_thread_t *)p_this;
409 #ifndef X_DISPLAY_MISSING
410 if (!vlc_xlib_init(p_this))
411 return VLC_EGENERIC;
412 #endif
414 #if (_POSIX_SPAWN >= 0)
415 /* Check if QApplication works */
416 char *path = config_GetSysPath(VLC_PKG_LIBEXEC_DIR, "vlc-qt-check");
417 if (unlikely(path == NULL))
418 return VLC_ENOMEM;
420 char *argv[] = { path, NULL };
421 pid_t pid;
423 int val = posix_spawn(&pid, path, NULL, NULL, argv, environ);
424 free(path);
425 if (val)
426 return VLC_ENOMEM;
428 int status;
429 while (waitpid(pid, &status, 0) == -1);
431 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
433 msg_Dbg(p_this, "Qt check failed (%d). Skipping.", status);
434 return VLC_EGENERIC;
436 #endif
438 /* Get the playlist before the lock to avoid a lock-order-inversion */
439 vlc_playlist_t *playlist = vlc_intf_GetMainPlaylist(p_intf);
441 vlc_mutex_locker locker (&lock);
442 if (busy || open_state == OPEN_STATE_ERROR)
444 if (busy)
445 msg_Err (p_this, "cannot start Qt multiple times");
446 return VLC_EGENERIC;
449 /* Allocations of p_sys */
450 intf_sys_t *p_sys = p_intf->p_sys = new intf_sys_t;
451 p_sys->b_isDialogProvider = isDialogProvider;
452 p_sys->p_mi = NULL;
454 /* set up the playlist to work on */
455 p_sys->p_playlist = playlist;
456 p_sys->p_player = vlc_playlist_GetPlayer( p_sys->p_playlist );
458 /* */
459 #ifdef Q_OS_MAC
460 /* Run mainloop on the main thread as Cocoa requires */
461 libvlc_SetExitHandler( vlc_object_instance(p_intf), Abort, p_intf );
462 Thread( (void *)p_intf );
463 #else
464 if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
466 delete p_sys;
467 return VLC_ENOMEM;
469 #endif
471 /* Wait for the interface to be ready. This prevents the main
472 * LibVLC thread from starting video playback before we can create
473 * an embedded video window. */
474 while (open_state == OPEN_STATE_INIT)
475 vlc_cond_wait(&wait_ready, &lock);
477 if (open_state == OPEN_STATE_ERROR)
479 #ifndef Q_OS_MAC
480 vlc_join (p_sys->thread, NULL);
481 #endif
482 delete p_sys;
483 return VLC_EGENERIC;
486 busy = true;
487 return VLC_SUCCESS;
490 /* Open Qt interface */
491 static int OpenIntf( vlc_object_t *p_this )
493 return Open( p_this, false );
496 /* Open Dialog Provider */
497 static int OpenDialogs( vlc_object_t *p_this )
499 return Open( p_this, true );
502 static void Close( vlc_object_t *p_this )
504 intf_thread_t *p_intf = (intf_thread_t *)p_this;
505 intf_sys_t *p_sys = p_intf->p_sys;
507 /* And quit */
508 msg_Dbg( p_this, "requesting exit..." );
509 QVLCApp::triggerQuit();
511 msg_Dbg( p_this, "waiting for UI thread..." );
512 #ifndef Q_OS_MAC
513 vlc_join (p_sys->thread, NULL);
514 #endif
515 delete p_sys;
517 vlc_mutex_locker locker (&lock);
518 assert (busy);
519 assert (open_state == OPEN_STATE_INIT);
520 busy = false;
523 static inline void qRegisterMetaTypes()
525 // register all types used by signal/slots
526 qRegisterMetaType<size_t>("size_t");
527 qRegisterMetaType<ssize_t>("ssize_t");
528 qRegisterMetaType<vlc_tick_t>("vlc_tick_t");
531 static void *Thread( void *obj )
533 intf_thread_t *p_intf = (intf_thread_t *)obj;
534 intf_sys_t *p_sys = p_intf->p_sys;
535 char vlc_name[] = "vlc"; /* for WM_CLASS */
536 char *argv[3] = { nullptr };
537 int argc = 0;
539 auto argvReleaser = vlc::wrap_carray<char*>(argv, [](char* ptr[]) {
540 for ( int i = 0; ptr[i] != nullptr; ++i )
541 free(ptr[i]);
543 argv[argc++] = strdup(vlc_name);
545 #ifdef QT_QML_DEBUG
546 char* qmlJsDebugOpt = var_InheritString(p_intf, "qt-qmljsdebugger");
547 if (qmlJsDebugOpt)
549 msg_Dbg(p_intf, "option qt-qmljsdebugger is %s", qmlJsDebugOpt);
550 char* psz_debug_opt;
551 if (asprintf(&psz_debug_opt, "-qmljsdebugger=%s", qmlJsDebugOpt) < 0)
553 free(qmlJsDebugOpt);
554 return NULL;
556 argv[argc++] = psz_debug_opt;
557 free(qmlJsDebugOpt);
559 #endif
560 argv[argc] = NULL;
562 Q_INIT_RESOURCE( vlc );
564 #if HAS_QT56
565 QApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
566 QApplication::setAttribute( Qt::AA_UseHighDpiPixmaps );
567 #endif
569 // at the moment, the vout is created in another thread than the rendering thread
570 QApplication::setAttribute( Qt::AA_DontCheckOpenGLContextThreadAffinity );
571 QQuickWindow::setDefaultAlphaBuffer(true);
573 QQuickStyle::setStyle("fusion");
575 /* Start the QApplication here */
576 QVLCApp app( argc, argv );
578 //app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
580 /* Set application direction to locale direction,
581 * necessary for RTL locales */
582 app.setLayoutDirection(QLocale().textDirection());
584 p_sys->p_app = &app;
587 /* All the settings are in the .conf/.ini style */
588 #ifdef _WIN32
589 char *cConfigDir = config_GetUserDir( VLC_CONFIG_DIR );
590 QString configDir = cConfigDir;
591 free( cConfigDir );
592 if( configDir.endsWith( "\\vlc" ) )
593 configDir.chop( 4 ); /* the "\vlc" dir is added again by QSettings */
594 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configDir );
595 #endif
597 p_sys->mainSettings = new QSettings(
598 #ifdef _WIN32
599 QSettings::IniFormat,
600 #else
601 QSettings::NativeFormat,
602 #endif
603 QSettings::UserScope, "vlc", "vlc-qt-interface" );
605 app.setApplicationDisplayName( qtr("VLC media player") );
607 if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
608 app.setWindowIcon( QIcon::fromTheme( "vlc-xmas", QIcon( ":/logo/vlc128-xmas.png" ) ) );
609 else
610 app.setWindowIcon( QIcon::fromTheme( "vlc", QIcon( ":/logo/vlc256.png" ) ) );
612 app.setDesktopFileName( PACKAGE );
614 /* Initialize the Dialog Provider and the Main Input Manager */
615 DialogsProvider::getInstance( p_intf );
616 p_sys->p_mainPlayerController = new PlayerController(p_intf);
617 p_sys->p_mainPlaylistController = new vlc::playlist::PlaylistControllerModel(p_intf->p_sys->p_playlist);
619 #ifdef UPDATE_CHECK
620 /* Checking for VLC updates */
621 if( var_InheritBool( p_intf, "qt-updates-notif" ) &&
622 !var_InheritBool( p_intf, "qt-privacy-ask" ) )
624 int interval = var_InheritInteger( p_intf, "qt-updates-days" );
625 if( QDate::currentDate() >
626 getSettings()->value( "updatedate" ).toDate().addDays( interval ) )
628 /* The constructor of the update Dialog will do the 1st request */
629 UpdateDialog::getInstance( p_intf );
630 getSettings()->setValue( "updatedate", QDate::currentDate() );
633 #endif
635 /* Create the normal interface in non-DP mode */
636 MainInterface *p_mi = NULL;
638 if( !p_sys->b_isDialogProvider )
640 #ifdef _WIN32
641 p_mi = new MainInterfaceWin32( p_intf );
642 #else
643 p_mi = new MainInterface( p_intf );
644 #endif
645 p_sys->p_mi = p_mi;
647 QList<QQmlError> qmlErrors = p_sys->p_mi->qmlErrors();
648 if( !qmlErrors.isEmpty() )
650 msg_Err( p_intf, "Missing qml modules: " );
652 for( QQmlError &qmlError : qmlErrors )
653 msg_Err( p_intf, "%s", qtu(qmlError.description()) );
654 #ifdef QT_STATICPLUGIN
655 assert( !"Missing qml modules from qt contribs." );
656 #else
657 msg_Err( p_intf, "Install missing modules using your packaging tool" );
658 #endif
659 return ThreadCleanup( p_intf, true );
662 /* Check window type from the Qt platform back-end */
663 bool known_type = true;
665 QString platform = app.platformName();
666 if( platform == qfu("xcb") )
667 p_sys->voutWindowType = VOUT_WINDOW_TYPE_XID;
668 else if( platform == qfu("wayland") || platform == qfu("wayland-egl") )
669 p_sys->voutWindowType = VOUT_WINDOW_TYPE_WAYLAND;
670 else if( platform == qfu("windows") )
671 p_sys->voutWindowType = VOUT_WINDOW_TYPE_HWND;
672 else if( platform == qfu("cocoa" ) )
673 p_sys->voutWindowType = VOUT_WINDOW_TYPE_NSOBJECT;
674 else
676 msg_Err( p_intf, "unknown Qt platform: %s", qtu(platform) );
677 known_type = false;
680 /* FIXME: Temporary, while waiting for a proper window provider API */
681 libvlc_int_t *libvlc = vlc_object_instance( p_intf );
683 var_Create( libvlc, "qt4-iface", VLC_VAR_ADDRESS );
684 var_Create( libvlc, "window", VLC_VAR_STRING );
686 if( known_type )
688 var_SetAddress( libvlc, "qt4-iface", p_intf );
689 var_SetString( libvlc, "window", "qt,any" );
693 /* Explain how to show a dialog :D */
694 p_intf->pf_show_dialog = ShowDialog;
696 /* Tell the main LibVLC thread we are ready */
698 vlc_mutex_locker locker (&lock);
699 open_state = OPEN_STATE_OPENED;
700 vlc_cond_signal(&wait_ready);
703 #ifdef Q_OS_MAC
704 /* We took over main thread, register and start here */
705 if( !p_sys->b_isDialogProvider )
707 vlc_playlist_Lock( p_intf->p_sys->p_playlist );
708 vlc_playlist_Start( p_intf->p_sys->p_playlist );
709 vlc_playlist_Unlock( p_intf->p_sys->p_playlist );
711 #endif
713 /* Last settings */
714 app.setQuitOnLastWindowClosed( false );
716 /* Retrieve last known path used in file browsing */
717 p_sys->filepath =
718 getSettings()->value( "filedialog-path", QVLCUserDir( VLC_HOME_DIR ) ).toString();
720 /* Loads and tries to apply the preferred QStyle */
721 QString s_style = getSettings()->value( "MainWindow/QtStyle", "" ).toString();
722 if( s_style.compare("") != 0 )
723 QApplication::setStyle( s_style );
725 qRegisterMetaTypes();
727 /* Launch */
728 app.exec();
730 msg_Dbg( p_intf, "QApp exec() finished" );
731 if (p_mi != NULL)
733 libvlc_int_t *libvlc = vlc_object_instance( p_intf );
734 var_Destroy( libvlc, "window" );
735 var_Destroy( libvlc, "qt4-iface" );
737 return ThreadCleanup( p_intf, false );
740 static void *ThreadCleanup( intf_thread_t *p_intf, bool error )
742 intf_sys_t *p_sys = p_intf->p_sys;
745 vlc_mutex_locker locker (&lock);
746 if( error )
748 open_state = OPEN_STATE_ERROR;
749 vlc_cond_signal( &wait_ready );
751 else
752 open_state = OPEN_STATE_INIT;
755 if( p_sys->p_mi != NULL)
757 MainInterface *p_mi = p_sys->p_mi;
758 p_sys->p_mi = NULL;
759 /* Destroy first the main interface because it is connected to some
760 slots in the MainInputManager */
761 delete p_mi;
764 /* */
765 ExtensionsManager::killInstance();
766 AddonsManager::killInstance();
768 /* Destroy all remaining windows,
769 because some are connected to some slots
770 in the MainInputManager
771 Settings must be destroyed after that.
773 DialogsProvider::killInstance();
775 /* Delete the recentsMRL object before the configuration */
776 RecentsMRL::killInstance();
778 /* Save the path or delete if recent play are disabled */
779 if( var_InheritBool( p_intf, "qt-recentplay" ) )
780 getSettings()->setValue( "filedialog-path", p_sys->filepath );
781 else
782 getSettings()->remove( "filedialog-path" );
784 /* Destroy the main playlist controller */
785 delete p_sys->p_mainPlaylistController;
786 /* Destroy the main InputManager */
787 delete p_sys->p_mainPlayerController;
788 /* Delete the configuration. Application has to be deleted after that. */
789 delete p_sys->mainSettings;
791 /* Delete the application automatically */
792 return NULL;
795 /*****************************************************************************
796 * Callback to show a dialog
797 *****************************************************************************/
798 static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
799 intf_dialog_args_t *p_arg )
801 VLC_UNUSED( p_intf );
802 DialogEvent *event = new DialogEvent( i_dialog_event, i_arg, p_arg );
803 QApplication::postEvent( THEDP, event );
807 * Video output window provider
809 static int WindowOpen( vout_window_t *p_wnd )
811 if( !var_InheritBool( p_wnd, "embedded-video" ) )
812 return VLC_EGENERIC;
814 libvlc_int_t *libvlc = vlc_object_instance( p_wnd );
815 intf_thread_t *p_intf =
816 (intf_thread_t *)var_InheritAddress( libvlc, "qt4-iface" );
817 if( !p_intf )
818 { /* If another interface is used, this plugin cannot work */
819 msg_Dbg( p_wnd, "Qt interface not found" );
820 return VLC_EGENERIC;
823 switch( p_intf->p_sys->voutWindowType )
825 case VOUT_WINDOW_TYPE_XID:
826 case VOUT_WINDOW_TYPE_HWND:
827 if( var_InheritBool( p_wnd, "video-wallpaper" ) )
828 return VLC_EGENERIC;
829 break;
832 vlc_mutex_locker locker (&lock);
833 if (unlikely(open_state != OPEN_STATE_OPENED))
834 return VLC_EGENERIC;
836 MainInterface *p_mi = p_intf->p_sys->p_mi;
838 return p_mi->getVideo( p_wnd ) ? VLC_SUCCESS : VLC_EGENERIC;