qt: playlist: use item title if available
[vlc.git] / modules / gui / qt / qt.cpp
blob6bb0eefdb7a03052ce8d57c90960ee25bbbd8cd2
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>
46 #include <QLoggingCategory>
48 #include "qt.hpp"
50 #include "player/player_controller.hpp" /* THEMIM destruction */
51 #include "playlist/playlist_controller.hpp" /* THEMPL creation */
52 #include "dialogs/dialogs_provider.hpp" /* THEDP creation */
53 #ifdef _WIN32
54 # include "maininterface/main_interface_win32.hpp"
55 #else
56 # include "maininterface/main_interface.hpp" /* MainInterface creation */
57 #endif
58 #include "dialogs/extensions/extensions_manager.hpp" /* Extensions manager */
59 #include "dialogs/plugins/addons_manager.hpp" /* Addons manager */
60 #include "dialogs/help/help.hpp" /* Launch Update */
61 #include "util/qvlcapp.hpp" /* QVLCApplication definition */
62 #include "maininterface/compositor.hpp"
64 #include <QVector>
65 #include "playlist/playlist_item.hpp"
67 #include <vlc_plugin.h>
68 #include <vlc_vout_window.h>
69 #include <vlc_cxx_helpers.hpp>
71 #ifdef QT_STATIC /* For static builds */
72 #include <QtPlugin>
73 #include <QQuickWindow>
75 #ifdef QT_STATICPLUGIN
76 Q_IMPORT_PLUGIN(QSvgIconPlugin)
77 Q_IMPORT_PLUGIN(QSvgPlugin)
78 Q_IMPORT_PLUGIN(QJpegPlugin)
79 Q_IMPORT_PLUGIN(QtQuick2Plugin)
80 Q_IMPORT_PLUGIN(QtQuickControls2Plugin)
81 Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin)
82 Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)
83 Q_IMPORT_PLUGIN(QtQuickTemplates2Plugin)
84 Q_IMPORT_PLUGIN(QtQmlModelsPlugin)
85 Q_IMPORT_PLUGIN(QtGraphicalEffectsPlugin)
86 Q_IMPORT_PLUGIN(QtGraphicalEffectsPrivatePlugin)
87 Q_IMPORT_PLUGIN(QmlShapesPlugin)
89 #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
90 Q_IMPORT_PLUGIN(QtQmlPlugin)
91 #endif
93 #ifdef _WIN32
94 Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin)
95 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
96 #endif
97 #endif
98 #endif
100 #ifndef X_DISPLAY_MISSING
101 # include <vlc_xlib.h>
102 #endif
104 /*****************************************************************************
105 * Local prototypes.
106 *****************************************************************************/
107 static int OpenIntf ( vlc_object_t * );
108 static int OpenDialogs ( vlc_object_t * );
109 static int Open ( vlc_object_t *, bool );
110 static void Close ( vlc_object_t * );
111 static int WindowOpen ( vout_window_t * );
112 static void ShowDialog ( intf_thread_t *, int, int, intf_dialog_args_t * );
114 /*****************************************************************************
115 * Module descriptor
116 *****************************************************************************/
117 #define ADVANCED_PREFS_TEXT N_( "Show advanced preferences over simple ones" )
118 #define ADVANCED_PREFS_LONGTEXT N_( "Show advanced preferences and not simple "\
119 "preferences when opening the preferences "\
120 "dialog." )
122 #define SYSTRAY_TEXT N_( "Systray icon" )
123 #define SYSTRAY_LONGTEXT N_( "Show an icon in the systray " \
124 "allowing you to control VLC media player " \
125 "for basic actions." )
127 #define MINIMIZED_TEXT N_( "Start VLC with only a systray icon" )
128 #define MINIMIZED_LONGTEXT N_( "VLC will start with just an icon in " \
129 "your taskbar." )
131 #define KEEPSIZE_TEXT N_( "Resize interface to the native video size" )
132 #define KEEPSIZE_LONGTEXT N_( "You have two choices:\n" \
133 " - The interface will resize to the native video size\n" \
134 " - The video will fit to the interface size\n " \
135 "By default, interface resize to the native video size." )
137 #define TITLE_TEXT N_( "Show playing item name in window title" )
138 #define TITLE_LONGTEXT N_( "Show the name of the song or video in the " \
139 "controller window title." )
141 #define NOTIFICATION_TEXT N_( "Show notification popup on track change" )
142 #define NOTIFICATION_LONGTEXT N_( \
143 "Show a notification popup with the artist and track name when " \
144 "the current playlist item changes, when VLC is minimized or hidden." )
146 #define OPACITY_TEXT N_( "Windows opacity between 0.1 and 1" )
147 #define OPACITY_LONGTEXT N_( "Sets the windows opacity between 0.1 and 1 " \
148 "for main interface, playlist and extended panel."\
149 " This option only works with Windows and " \
150 "X11 with composite extensions." )
152 #define OPACITY_FS_TEXT N_( "Fullscreen controller opacity between 0.1 and 1" )
153 #define OPACITY_FS_LONGTEXT N_( "Sets the fullscreen controller opacity between 0.1 and 1 " \
154 "for main interface, playlist and extended panel."\
155 " This option only works with Windows and " \
156 "X11 with composite extensions." )
158 #define INTERFACE_SCALE_TEXT N_( "Initial user scale factor for the interface, betwwen 0.3 and 3.0" )
160 #define ERROR_TEXT N_( "Show unimportant error and warnings dialogs" )
162 #define UPDATER_TEXT N_( "Activate the updates availability notification" )
163 #define UPDATER_LONGTEXT N_( "Activate the automatic notification of new " \
164 "versions of the software. It runs once every " \
165 "two weeks." )
167 #define QT_QML_DEBUG_TEXT N_( "set the options for qml debugger" )
168 #define QT_QML_DEBUG_LONGTEXT N_( "set the options for qml debugger (see http://doc.qt.io/qt-5/qtquick-debugging.html#starting-applications)" )
170 #define UPDATER_DAYS_TEXT N_("Number of days between two update checks")
172 #define PRIVACY_TEXT N_( "Ask for network policy at start" )
174 #define RECENTPLAY_TEXT N_( "Save the recently played items in the menu" )
176 #define RECENTPLAY_FILTER_TEXT N_( "List of words separated by | to filter" )
177 #define RECENTPLAY_FILTER_LONGTEXT N_( "Regular expression used to filter " \
178 "the recent items played in the player." )
180 #define SLIDERCOL_TEXT N_( "Define the colors of the volume slider" )
181 #define SLIDERCOL_LONGTEXT N_( "Define the colors of the volume slider\n" \
182 "By specifying the 12 numbers separated by a ';'\n" \
183 "Default is '255;255;255;20;226;20;255;176;15;235;30;20'\n" \
184 "An alternative can be '30;30;50;40;40;100;50;50;160;150;150;255'")
186 #define QT_MODE_TEXT N_( "Selection of the starting mode and look" )
187 #define QT_MODE_LONGTEXT N_( "Start VLC with:\n" \
188 " - normal mode\n" \
189 " - a zone always present to show information " \
190 "as lyrics, album arts...\n" \
191 " - minimal mode with limited controls" )
193 #define QT_FULLSCREEN_TEXT N_( "Show a controller in fullscreen mode" )
194 #define QT_NATIVEOPEN_TEXT N_( "Embed the file browser in open dialog" )
196 #define FULLSCREEN_NUMBER_TEXT N_( "Define which screen fullscreen goes" )
197 #define FULLSCREEN_NUMBER_LONGTEXT N_( "Screennumber of fullscreen, instead of " \
198 "same screen where interface is." )
200 #define QT_AUTOLOAD_EXTENSIONS_TEXT N_( "Load extensions on startup" )
201 #define QT_AUTOLOAD_EXTENSIONS_LONGTEXT N_( "Automatically load the "\
202 "extensions module on startup." )
204 #define QT_MINIMAL_MODE_TEXT N_("Start in minimal view (without menus)" )
206 #define QT_BGCONE_TEXT N_( "Display background cone or art" )
207 #define QT_BGCONE_LONGTEXT N_( "Display background cone or current album art " \
208 "when not playing. " \
209 "Can be disabled to prevent burning screen." )
210 #define QT_BGCONE_EXPANDS_TEXT N_( "Expanding background cone or art" )
211 #define QT_BGCONE_EXPANDS_LONGTEXT N_( "Background art fits window's size." )
213 #define QT_DISABLE_VOLUME_KEYS_TEXT N_( "Ignore keyboard volume buttons." )
214 #define QT_DISABLE_VOLUME_KEYS_LONGTEXT N_( \
215 "With this option checked, the volume up, volume down and mute buttons on your " \
216 "keyboard will always change your system volume. With this option unchecked, the " \
217 "volume buttons will change VLC's volume when VLC is selected and change the " \
218 "system volume when VLC is not selected." )
220 #define QT_PAUSE_MINIMIZED_TEXT N_( "Pause the video playback when minimized" )
221 #define QT_PAUSE_MINIMIZED_LONGTEXT N_( \
222 "With this option enabled, the playback will be automatically paused when minimizing the window." )
224 #define ICONCHANGE_TEXT N_( "Allow automatic icon changes")
225 #define ICONCHANGE_LONGTEXT N_( \
226 "This option allows the interface to change its icon on various occasions.")
228 #define VOLUME_MAX_TEXT N_( "Maximum Volume displayed" )
230 #define AUTORAISE_ON_PLAYBACK_TEXT N_( "When to raise the interface" )
231 #define AUTORAISE_ON_PLAYBACK_LONGTEXT N_( "This option allows the interface to be raised automatically " \
232 "when a video/audio playback starts, or never." )
234 #define QT_CLIENT_SIDE_DECORATION_TEXT N_( "Enable window titlebar" )
235 #define QT_CLIENT_SIDE_DECORATION_LONGTEXT N_( "This option enables the title bar. Disabling it will remove " \
236 "the titlebar and move window buttons within the interface (Client Side Decoration)" )
239 #define QT_MENUBAR_TEXT N_( "Show the menu bar" )
240 #define QT_MENUBAR_LONGTEXT N_( "This option displays the classic menu bar" )
242 #define FULLSCREEN_CONTROL_PIXELS N_( "Fullscreen controller mouse sensitivity" )
244 #define CONTINUE_PLAYBACK_TEXT N_("Continue playback?")
246 static const int i_notification_list[] =
247 { NOTIFICATION_NEVER, NOTIFICATION_MINIMIZED, NOTIFICATION_ALWAYS };
249 static const char *const psz_notification_list_text[] =
250 { N_("Never"), N_("When minimized"), N_("Always") };
252 static const int i_continue_list[] =
253 { 0, 1, 2 };
255 static const char *const psz_continue_list_text[] =
256 { N_("Never"), N_("Ask"), N_("Always") };
258 static const int i_raise_list[] =
259 { MainInterface::RAISE_NEVER, MainInterface::RAISE_VIDEO, \
260 MainInterface::RAISE_AUDIO, MainInterface::RAISE_AUDIOVIDEO, };
262 static const char *const psz_raise_list_text[] =
263 { N_( "Never" ), N_( "Video" ), N_( "Audio" ), _( "Audio/Video" ) };
265 /**********************************************************************/
266 vlc_module_begin ()
267 set_shortname( "Qt" )
268 set_description( N_("Qt interface") )
269 set_category( CAT_INTERFACE )
270 set_subcategory( SUBCAT_INTERFACE_MAIN )
271 set_capability( "interface", 151 )
272 set_callbacks( OpenIntf, Close )
274 add_shortcut("qt")
276 add_bool( "qt-minimal-view", false, QT_MINIMAL_MODE_TEXT,
277 QT_MINIMAL_MODE_TEXT, false );
279 add_bool( "qt-system-tray", true, SYSTRAY_TEXT, SYSTRAY_LONGTEXT, false)
281 add_integer( "qt-notification", NOTIFICATION_MINIMIZED,
282 NOTIFICATION_TEXT,
283 NOTIFICATION_LONGTEXT, false )
284 change_integer_list( i_notification_list, psz_notification_list_text )
286 add_bool( "qt-start-minimized", false, MINIMIZED_TEXT,
287 MINIMIZED_LONGTEXT, true)
288 add_bool( "qt-pause-minimized", false, QT_PAUSE_MINIMIZED_TEXT,
289 QT_PAUSE_MINIMIZED_LONGTEXT, false )
291 add_float_with_range( "qt-opacity", 1., 0.1, 1., OPACITY_TEXT,
292 OPACITY_LONGTEXT, false )
293 add_float_with_range( "qt-fs-opacity", 0.8, 0.1, 1., OPACITY_FS_TEXT,
294 OPACITY_FS_LONGTEXT, false )
296 //qt-interface-scale is stored in Qt config file
297 //this option is here to force an initial scale factor at startup
298 add_float_with_range( "qt-interface-scale", -1.0, 0.3, 3.0, INTERFACE_SCALE_TEXT,
299 INTERFACE_SCALE_TEXT, false )
300 change_volatile()
302 add_bool( "qt-video-autoresize", true, KEEPSIZE_TEXT,
303 KEEPSIZE_LONGTEXT, false )
304 add_bool( "qt-name-in-title", true, TITLE_TEXT,
305 TITLE_LONGTEXT, false )
306 add_bool( "qt-fs-controller", true, QT_FULLSCREEN_TEXT,
307 QT_FULLSCREEN_TEXT, false )
309 add_bool( "qt-recentplay", true, RECENTPLAY_TEXT,
310 RECENTPLAY_TEXT, false )
311 add_string( "qt-recentplay-filter", "",
312 RECENTPLAY_FILTER_TEXT, RECENTPLAY_FILTER_LONGTEXT, false )
313 add_integer( "qt-continue", 1, CONTINUE_PLAYBACK_TEXT, CONTINUE_PLAYBACK_TEXT, false )
314 change_integer_list(i_continue_list, psz_continue_list_text )
316 #ifdef UPDATE_CHECK
317 add_bool( "qt-updates-notif", true, UPDATER_TEXT,
318 UPDATER_LONGTEXT, false )
319 add_integer_with_range( "qt-updates-days", 3, 0, 180,
320 UPDATER_DAYS_TEXT, UPDATER_DAYS_TEXT, false )
321 #endif
323 #ifdef QT_QML_DEBUG
324 add_string( "qt-qmljsdebugger", NULL,
325 QT_QML_DEBUG_TEXT, QT_QML_DEBUG_LONGTEXT, false )
326 #endif
328 #ifdef _WIN32
329 add_bool( "qt-disable-volume-keys" /* name */,
330 true /* default value */,
331 QT_DISABLE_VOLUME_KEYS_TEXT /* text */,
332 QT_DISABLE_VOLUME_KEYS_LONGTEXT /* longtext */,
333 false /* advanced mode only */)
334 #endif
336 #if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
337 add_bool( "qt-titlebar",
338 #ifdef _WIN32
339 false /* use CSD by default on windows */,
340 #else
341 true /* but not on linux */,
342 #endif
343 QT_CLIENT_SIDE_DECORATION_TEXT, QT_CLIENT_SIDE_DECORATION_LONGTEXT, false )
344 #endif
346 add_bool( "qt-menubar", false, QT_MENUBAR_TEXT, QT_MENUBAR_LONGTEXT, false )
348 add_bool( "qt-embedded-open", false, QT_NATIVEOPEN_TEXT,
349 QT_NATIVEOPEN_TEXT, false )
352 add_bool( "qt-advanced-pref", false, ADVANCED_PREFS_TEXT,
353 ADVANCED_PREFS_LONGTEXT, false )
354 add_bool( "qt-error-dialogs", true, ERROR_TEXT,
355 ERROR_TEXT, false )
357 add_string( "qt-slider-colours", "153;210;153;20;210;20;255;199;15;245;39;29",
358 SLIDERCOL_TEXT, SLIDERCOL_LONGTEXT, false )
360 add_bool( "qt-privacy-ask", true, PRIVACY_TEXT, PRIVACY_TEXT,
361 false )
362 change_private ()
364 add_integer( "qt-fullscreen-screennumber", -1, FULLSCREEN_NUMBER_TEXT,
365 FULLSCREEN_NUMBER_LONGTEXT, false );
367 add_bool( "qt-autoload-extensions", true,
368 QT_AUTOLOAD_EXTENSIONS_TEXT, QT_AUTOLOAD_EXTENSIONS_LONGTEXT,
369 false )
371 add_bool( "qt-bgcone", true, QT_BGCONE_TEXT, QT_BGCONE_LONGTEXT, true )
372 add_bool( "qt-bgcone-expands", false, QT_BGCONE_EXPANDS_TEXT,
373 QT_BGCONE_EXPANDS_LONGTEXT, true )
375 add_bool( "qt-icon-change", true, ICONCHANGE_TEXT, ICONCHANGE_LONGTEXT, true )
377 add_integer_with_range( "qt-max-volume", 125, 60, 300, VOLUME_MAX_TEXT, VOLUME_MAX_TEXT, true)
379 add_integer_with_range( "qt-fs-sensitivity", 3, 0, 4000, FULLSCREEN_CONTROL_PIXELS,
380 FULLSCREEN_CONTROL_PIXELS, true)
382 add_obsolete_bool( "qt-blingbling" ) /* Suppressed since 1.0.0 */
383 add_obsolete_integer( "qt-display-mode" ) /* Suppressed since 1.1.0 */
385 add_obsolete_bool( "qt-adv-options" ) /* Since 2.0.0 */
386 add_obsolete_bool( "qt-volume-complete" ) /* Since 2.0.0 */
387 add_obsolete_integer( "qt-startvolume" ) /* Since 2.0.0 */
389 add_integer( "qt-auto-raise", MainInterface::RAISE_VIDEO, AUTORAISE_ON_PLAYBACK_TEXT,
390 AUTORAISE_ON_PLAYBACK_LONGTEXT, false )
391 change_integer_list( i_raise_list, psz_raise_list_text )
393 cannot_unload_broken_library()
395 add_submodule ()
396 set_description( "Dialogs provider" )
397 set_capability( "dialogs provider", 51 )
399 set_callbacks( OpenDialogs, Close )
401 add_submodule ()
402 set_capability( "vout window", 0 )
403 set_callback( WindowOpen )
405 vlc_module_end ()
407 /*****************************************/
409 /* Ugly, but the Qt interface assumes single instance anyway */
410 static vlc::threads::condition_variable wait_ready;
411 static vlc::threads::mutex lock;
412 static bool busy = false;
413 static enum {
414 OPEN_STATE_INIT,
415 OPEN_STATE_OPENED,
416 OPEN_STATE_ERROR,
417 } open_state = OPEN_STATE_INIT;
419 /*****************************************************************************
420 * Module callbacks
421 *****************************************************************************/
423 static void *Thread( void * );
424 static void *ThreadCleanup( intf_thread_t *p_intf, bool error );
426 #ifdef Q_OS_MAC
427 /* Used to abort the app.exec() on OSX after libvlc_Quit is called */
428 #include "../../../lib/libvlc_internal.h" /* libvlc_SetExitHandler */
429 static void Abort( void *obj )
431 QVLCApp::triggerQuit();
433 #endif
435 /* Open Interface */
436 static int Open( vlc_object_t *p_this, bool isDialogProvider )
438 intf_thread_t *p_intf = (intf_thread_t *)p_this;
440 #ifndef X_DISPLAY_MISSING
441 if (!vlc_xlib_init(p_this))
442 return VLC_EGENERIC;
443 #endif
445 #if (_POSIX_SPAWN >= 0)
446 /* Check if QApplication works */
447 char *path = config_GetSysPath(VLC_PKG_LIBEXEC_DIR, "vlc-qt-check");
448 if (unlikely(path == NULL))
449 return VLC_ENOMEM;
451 char *argv[] = { path, NULL };
452 pid_t pid;
454 int val = posix_spawn(&pid, path, NULL, NULL, argv, environ);
455 free(path);
456 if (val)
457 return VLC_ENOMEM;
459 int status;
460 while (waitpid(pid, &status, 0) == -1);
462 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
464 msg_Dbg(p_this, "Qt check failed (%d). Skipping.", status);
465 return VLC_EGENERIC;
467 #endif
469 /* Get the playlist before the lock to avoid a lock-order-inversion */
470 vlc_playlist_t *playlist = vlc_intf_GetMainPlaylist(p_intf);
472 vlc::threads::mutex_locker locker (lock);
473 if (busy || open_state == OPEN_STATE_ERROR)
475 if (busy)
476 msg_Err (p_this, "cannot start Qt multiple times");
477 return VLC_EGENERIC;
480 /* Allocations of p_sys */
481 intf_sys_t *p_sys = p_intf->p_sys = new intf_sys_t;
482 p_sys->b_isDialogProvider = isDialogProvider;
483 p_sys->p_mi = NULL;
485 /* set up the playlist to work on */
486 p_sys->p_playlist = playlist;
487 p_sys->p_player = vlc_playlist_GetPlayer( p_sys->p_playlist );
489 /* */
490 #ifdef Q_OS_MAC
491 /* Run mainloop on the main thread as Cocoa requires */
492 libvlc_SetExitHandler( vlc_object_instance(p_intf), Abort, p_intf );
493 Thread( (void *)p_intf );
494 #else
495 if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
497 delete p_sys;
498 return VLC_ENOMEM;
500 #endif
502 /* Wait for the interface to be ready. This prevents the main
503 * LibVLC thread from starting video playback before we can create
504 * an embedded video window. */
505 while (open_state == OPEN_STATE_INIT)
506 wait_ready.wait(lock);
508 if (open_state == OPEN_STATE_ERROR)
510 #ifndef Q_OS_MAC
511 vlc_join (p_sys->thread, NULL);
512 #endif
513 delete p_sys;
514 return VLC_EGENERIC;
517 busy = true;
518 return VLC_SUCCESS;
521 /* Open Qt interface */
522 static int OpenIntf( vlc_object_t *p_this )
524 return Open( p_this, false );
527 /* Open Dialog Provider */
528 static int OpenDialogs( vlc_object_t *p_this )
530 return Open( p_this, true );
533 static void Close( vlc_object_t *p_this )
535 intf_thread_t *p_intf = (intf_thread_t *)p_this;
536 intf_sys_t *p_sys = p_intf->p_sys;
538 /* And quit */
539 msg_Dbg( p_this, "requesting exit..." );
540 QVLCApp::triggerQuit();
542 msg_Dbg( p_this, "waiting for UI thread..." );
543 #ifndef Q_OS_MAC
544 vlc_join (p_sys->thread, NULL);
545 #endif
546 delete p_sys;
548 vlc::threads::mutex_locker locker (lock);
549 assert (busy);
550 assert (open_state == OPEN_STATE_INIT);
551 busy = false;
554 static inline void qRegisterMetaTypes()
556 // register all types used by signal/slots
557 qRegisterMetaType<size_t>("size_t");
558 qRegisterMetaType<ssize_t>("ssize_t");
559 qRegisterMetaType<vlc_tick_t>("vlc_tick_t");
562 static void *Thread( void *obj )
564 intf_thread_t *p_intf = (intf_thread_t *)obj;
565 intf_sys_t *p_sys = p_intf->p_sys;
566 char vlc_name[] = "vlc"; /* for WM_CLASS */
567 char *argv[3] = { nullptr };
568 int argc = 0;
570 auto argvReleaser = vlc::wrap_carray<char*>(argv, [](char* ptr[]) {
571 for ( int i = 0; ptr[i] != nullptr; ++i )
572 free(ptr[i]);
574 argv[argc++] = strdup(vlc_name);
576 #ifdef QT_QML_DEBUG
577 char* qmlJsDebugOpt = var_InheritString(p_intf, "qt-qmljsdebugger");
578 if (qmlJsDebugOpt)
580 msg_Dbg(p_intf, "option qt-qmljsdebugger is %s", qmlJsDebugOpt);
581 char* psz_debug_opt;
582 if (asprintf(&psz_debug_opt, "-qmljsdebugger=%s", qmlJsDebugOpt) < 0)
584 free(qmlJsDebugOpt);
585 return NULL;
587 argv[argc++] = psz_debug_opt;
588 free(qmlJsDebugOpt);
590 #endif
591 argv[argc] = NULL;
593 Q_INIT_RESOURCE( vlc );
595 p_intf->p_sys->p_compositor = vlc::Compositor::createCompositor(p_intf);
597 QApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
598 QApplication::setAttribute( Qt::AA_UseHighDpiPixmaps );
600 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
601 QApplication::setHighDpiScaleFactorRoundingPolicy( Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor );
602 #endif
603 // at the moment, the vout is created in another thread than the rendering thread
604 QApplication::setAttribute( Qt::AA_DontCheckOpenGLContextThreadAffinity );
605 QQuickWindow::setDefaultAlphaBuffer(true);
607 /* Start the QApplication here */
608 QVLCApp app( argc, argv );
610 #if QT_VERSION >= QT_VERSION_CHECK(5,15,1)
611 //suppress deprecation warnings about QML 'Connections' syntax
612 //legacy connection syntax is required to keep compatibility with Qt <= 5.14
613 QLoggingCategory::setFilterRules("qt.qml.connections.warning=false");
614 #endif
616 //app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
618 /* Set application direction to locale direction,
619 * necessary for RTL locales */
620 app.setLayoutDirection(QLocale().textDirection());
622 p_sys->p_app = &app;
625 /* All the settings are in the .conf/.ini style */
626 #ifdef _WIN32
627 char *cConfigDir = config_GetUserDir( VLC_CONFIG_DIR );
628 QString configDir = cConfigDir;
629 free( cConfigDir );
630 if( configDir.endsWith( "\\vlc" ) )
631 configDir.chop( 4 ); /* the "\vlc" dir is added again by QSettings */
632 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configDir );
633 #endif
635 p_sys->mainSettings = new QSettings(
636 #ifdef _WIN32
637 QSettings::IniFormat,
638 #else
639 QSettings::NativeFormat,
640 #endif
641 QSettings::UserScope, "vlc", "vlc-qt-interface" );
643 app.setApplicationDisplayName( qtr("VLC media player") );
645 if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
646 app.setWindowIcon( QIcon::fromTheme( "vlc-xmas", QIcon( ":/logo/vlc128-xmas.png" ) ) );
647 else
648 app.setWindowIcon( QIcon::fromTheme( "vlc", QIcon( ":/logo/vlc256.png" ) ) );
650 app.setDesktopFileName( PACKAGE );
652 /* Initialize the Dialog Provider and the Main Input Manager */
653 DialogsProvider::getInstance( p_intf );
654 p_sys->p_mainPlayerController = new PlayerController(p_intf);
655 p_sys->p_mainPlaylistController = new vlc::playlist::PlaylistControllerModel(p_intf->p_sys->p_playlist);
657 #ifdef UPDATE_CHECK
658 /* Checking for VLC updates */
659 if( var_InheritBool( p_intf, "qt-updates-notif" ) &&
660 !var_InheritBool( p_intf, "qt-privacy-ask" ) )
662 int interval = var_InheritInteger( p_intf, "qt-updates-days" );
663 if( QDate::currentDate() >
664 getSettings()->value( "updatedate" ).toDate().addDays( interval ) )
666 /* The constructor of the update Dialog will do the 1st request */
667 UpdateDialog::getInstance( p_intf );
668 getSettings()->setValue( "updatedate", QDate::currentDate() );
671 #endif
673 /* Create the normal interface in non-DP mode */
674 MainInterface *p_mi = NULL;
676 if( !p_sys->b_isDialogProvider )
678 p_mi = p_intf->p_sys->p_compositor->makeMainInterface();
679 p_sys->p_mi = p_mi;
681 if (!p_mi)
683 msg_Err(p_intf, "unable to create main interface");
684 return ThreadCleanup( p_intf, true );
687 /* Check window type from the Qt platform back-end */
688 bool known_type = true;
690 QString platform = app.platformName();
691 if( platform == qfu("xcb") )
692 p_sys->voutWindowType = VOUT_WINDOW_TYPE_XID;
693 else if( platform == qfu("wayland") || platform == qfu("wayland-egl") )
694 p_sys->voutWindowType = VOUT_WINDOW_TYPE_WAYLAND;
695 else if( platform == qfu("windows") )
696 p_sys->voutWindowType = VOUT_WINDOW_TYPE_HWND;
697 else if( platform == qfu("cocoa" ) )
698 p_sys->voutWindowType = VOUT_WINDOW_TYPE_NSOBJECT;
699 else
701 msg_Err( p_intf, "unknown Qt platform: %s", qtu(platform) );
702 known_type = false;
705 /* FIXME: Temporary, while waiting for a proper window provider API */
706 libvlc_int_t *libvlc = vlc_object_instance( p_intf );
708 var_Create( libvlc, "qt4-iface", VLC_VAR_ADDRESS );
710 if( known_type )
712 var_SetAddress( libvlc, "qt4-iface", p_intf );
713 var_SetString( libvlc, "window", "qt,any" );
717 /* Explain how to show a dialog :D */
718 p_intf->pf_show_dialog = ShowDialog;
720 /* Tell the main LibVLC thread we are ready */
722 vlc::threads::mutex_locker locker (lock);
723 open_state = OPEN_STATE_OPENED;
724 wait_ready.signal();
727 #ifdef Q_OS_MAC
728 /* We took over main thread, register and start here */
729 if( !p_sys->b_isDialogProvider )
731 vlc_playlist_Lock( p_intf->p_sys->p_playlist );
732 vlc_playlist_Start( p_intf->p_sys->p_playlist );
733 vlc_playlist_Unlock( p_intf->p_sys->p_playlist );
735 #endif
737 /* Last settings */
738 app.setQuitOnLastWindowClosed( false );
740 /* Retrieve last known path used in file browsing */
741 p_sys->filepath =
742 getSettings()->value( "filedialog-path", QVLCUserDir( VLC_HOME_DIR ) ).toString();
744 /* Loads and tries to apply the preferred QStyle */
745 QString s_style = getSettings()->value( "MainWindow/QtStyle", "" ).toString();
746 if( s_style.compare("") != 0 )
747 QApplication::setStyle( s_style );
749 qRegisterMetaTypes();
751 /* Launch */
752 app.exec();
754 msg_Dbg( p_intf, "QApp exec() finished" );
755 if (p_mi != NULL)
757 libvlc_int_t *libvlc = vlc_object_instance( p_intf );
758 var_Destroy( libvlc, "qt4-iface" );
760 return ThreadCleanup( p_intf, false );
763 static void *ThreadCleanup( intf_thread_t *p_intf, bool error )
765 intf_sys_t *p_sys = p_intf->p_sys;
768 vlc::threads::mutex_locker locker (lock);
769 if( error )
771 open_state = OPEN_STATE_ERROR;
772 wait_ready.signal();
774 else
775 open_state = OPEN_STATE_INIT;
778 if (p_sys->p_compositor)
780 p_sys->p_compositor->destroyMainInterface();
781 p_sys->p_mi = nullptr;
783 delete p_sys->p_compositor;
784 p_sys->p_compositor = nullptr;
787 /* */
788 ExtensionsManager::killInstance();
789 AddonsManager::killInstance();
791 /* Destroy all remaining windows,
792 because some are connected to some slots
793 in the MainInputManager
794 Settings must be destroyed after that.
796 DialogsProvider::killInstance();
798 /* Save the path or delete if recent play are disabled */
799 if( var_InheritBool( p_intf, "qt-recentplay" ) )
800 getSettings()->setValue( "filedialog-path", p_sys->filepath );
801 else
802 getSettings()->remove( "filedialog-path" );
804 /* Destroy the main playlist controller */
805 delete p_sys->p_mainPlaylistController;
806 /* Destroy the main InputManager */
807 delete p_sys->p_mainPlayerController;
808 /* Delete the configuration. Application has to be deleted after that. */
809 delete p_sys->mainSettings;
811 /* Delete the application automatically */
812 return NULL;
815 /*****************************************************************************
816 * Callback to show a dialog
817 *****************************************************************************/
818 static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
819 intf_dialog_args_t *p_arg )
821 VLC_UNUSED( p_intf );
822 DialogEvent *event = new DialogEvent( i_dialog_event, i_arg, p_arg );
823 QApplication::postEvent( THEDP, event );
827 * Video output window provider
829 static int WindowOpen( vout_window_t *p_wnd )
831 if( !var_InheritBool( p_wnd, "embedded-video" ) )
832 return VLC_EGENERIC;
834 libvlc_int_t *libvlc = vlc_object_instance( p_wnd );
835 intf_thread_t *p_intf =
836 (intf_thread_t *)var_InheritAddress( libvlc, "qt4-iface" );
837 if( !p_intf )
838 { /* If another interface is used, this plugin cannot work */
839 msg_Dbg( p_wnd, "Qt interface not found" );
840 return VLC_EGENERIC;
843 switch( p_intf->p_sys->voutWindowType )
845 case VOUT_WINDOW_TYPE_XID:
846 case VOUT_WINDOW_TYPE_HWND:
847 if( var_InheritBool( p_wnd, "video-wallpaper" ) )
848 return VLC_EGENERIC;
849 break;
852 vlc::threads::mutex_locker locker (lock);
853 if (unlikely(open_state != OPEN_STATE_OPENED))
854 return VLC_EGENERIC;
856 return p_intf->p_sys->p_compositor->setupVoutWindow( p_wnd ) ? VLC_SUCCESS : VLC_EGENERIC;