vlc | branch: master | Abel Tesfaye <[email protected]> | Wed Jul 3 09:46:19 2019 +0300| [52eb01269e9e91db845be1e979afa06220653ff6] | committer: Jean-Baptiste Kempf
qt: enable loading/saving settings using qml fixes #22171 Signed-off-by: Jean-Baptiste Kempf <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=52eb01269e9e91db845be1e979afa06220653ff6 --- modules/gui/qt/Makefile.am | 3 ++ .../gui/qt/components/mediacenter/mcmedialib.cpp | 4 +- modules/gui/qt/components/settings.cpp | 37 +++++++++++++++ modules/gui/qt/components/settings.hpp | 52 ++++++++++++++++++++++ modules/gui/qt/main_interface.cpp | 2 + modules/gui/qt/qml/menus/ViewMenu.qml | 2 +- modules/gui/qt/qml/style/VLCColors.qml | 2 +- 7 files changed, 99 insertions(+), 3 deletions(-) diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am index 50db6e4395..197857fee1 100644 --- a/modules/gui/qt/Makefile.am +++ b/modules/gui/qt/Makefile.am @@ -106,6 +106,8 @@ libqt_plugin_la_SOURCES = \ gui/qt/components/controller_widget.hpp \ gui/qt/components/recent_media_model.cpp \ gui/qt/components/recent_media_model.hpp \ + gui/qt/components/settings.cpp \ + gui/qt/components/settings.hpp \ gui/qt/components/voutwindow/videosurface.cpp \ gui/qt/components/voutwindow/videosurface.hpp \ gui/qt/components/voutwindow/qvoutwindow.cpp \ @@ -258,6 +260,7 @@ nodist_libqt_plugin_la_SOURCES = \ gui/qt/components/controller_widget.moc.cpp \ gui/qt/components/custom_menus.moc.cpp \ gui/qt/components/recent_media_model.moc.cpp \ + gui/qt/components/settings.moc.cpp \ gui/qt/components/voutwindow/videosurface.moc.cpp \ gui/qt/components/voutwindow/qvoutwindow.moc.cpp \ gui/qt/components/voutwindow/qvoutwindowdummy.moc.cpp \ diff --git a/modules/gui/qt/components/mediacenter/mcmedialib.cpp b/modules/gui/qt/components/mediacenter/mcmedialib.cpp index e40ad16479..d451a741d2 100644 --- a/modules/gui/qt/components/mediacenter/mcmedialib.cpp +++ b/modules/gui/qt/components/mediacenter/mcmedialib.cpp @@ -24,11 +24,12 @@ #include <vlc_input_item.h> #include "components/playlist/media.hpp" #include "components/playlist/playlist_controller.hpp" +#include <QSettings> MCMediaLib::MCMediaLib(intf_thread_t *_intf, QObject *_parent) : QObject( _parent ) , m_intf( _intf ) - , m_gridView( true ) + , m_gridView ( m_intf->p_sys->mainSettings->value("medialib-gridView",true).toBool() ) , m_ml( vlcMl() ) , m_event_cb( nullptr, [this](vlc_ml_event_callback_t* cb ) { vlc_ml_event_unregister_callback( m_ml, cb ); @@ -47,6 +48,7 @@ bool MCMediaLib::isGridView() const void MCMediaLib::setGridView(bool state) { m_gridView = state; + m_intf->p_sys->mainSettings->setValue("medialib-gridView",state); emit gridViewChanged(); } diff --git a/modules/gui/qt/components/settings.cpp b/modules/gui/qt/components/settings.cpp new file mode 100644 index 0000000000..d4d6ab2d54 --- /dev/null +++ b/modules/gui/qt/components/settings.cpp @@ -0,0 +1,37 @@ +/***************************************************************************** + * Copyright (C) 2019 VLC authors and VideoLAN + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * ( at your option ) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#include "settings.hpp" + +#define QML_AVAILABLE_PROPERTY_IMPL(PropertyName, key, defaultValue) \ + QVariant Settings::get##PropertyName() const { \ + return getSettings()->value(key, defaultValue); \ + } \ + void Settings::set##PropertyName(QVariant value) { \ + getSettings()->setValue(key, value); \ + emit PropertyName##Changed(); \ + } + +Settings::Settings(intf_thread_t *_p_intf, QObject *parent) + : QObject(parent),p_intf( _p_intf ) +{ +} + + +QML_AVAILABLE_PROPERTY_IMPL(VLCStyle_colors_state,"VLCStyle-colors-state","system") +QML_AVAILABLE_PROPERTY_IMPL(medialib_gridView,"medialib-gridView",true) diff --git a/modules/gui/qt/components/settings.hpp b/modules/gui/qt/components/settings.hpp new file mode 100644 index 0000000000..6ab7726e0f --- /dev/null +++ b/modules/gui/qt/components/settings.hpp @@ -0,0 +1,52 @@ +/***************************************************************************** + * Copyright (C) 2019 VLC authors and VideoLAN + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * ( at your option ) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifndef VLC_SETTINGS_HPP +#define VLC_SETTINGS_HPP + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "qt.hpp" +#include <QObject> +#include <QSettings> + +#define QML_AVAILABLE_PROPERTY(PropertyName) \ + Q_PROPERTY(QVariant PropertyName READ get##PropertyName WRITE set##PropertyName NOTIFY PropertyName##Changed) \ + public: \ + QVariant get##PropertyName() const; \ + void set##PropertyName(QVariant); \ + Q_SIGNAL void PropertyName##Changed(); + +class Settings : public QObject +{ + Q_OBJECT + + QML_AVAILABLE_PROPERTY(VLCStyle_colors_state) + QML_AVAILABLE_PROPERTY(medialib_gridView) + +public: + Settings(intf_thread_t *_p_intf,QObject * parent = nullptr); + +private: + intf_thread_t *p_intf; + +}; +#undef QML_AVAILABLE_PROPERTY +#endif diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp index b6c9219d53..b9613aab01 100644 --- a/modules/gui/qt/main_interface.cpp +++ b/modules/gui/qt/main_interface.cpp @@ -52,6 +52,7 @@ #include "components/mediacenter/mlvideomodel.hpp" #include "components/mediacenter/mlnetworkmodel.hpp" #include "components/recent_media_model.hpp" +#include "components/settings.hpp" #include "components/navigation_history.hpp" #include "components/aboutmodel.hpp" @@ -381,6 +382,7 @@ void MainInterface::createMainWidget( QSettings * ) rootCtx->setContextProperty( "rootWindow", this); rootCtx->setContextProperty( "dialogProvider", DialogsProvider::getInstance()); rootCtx->setContextProperty( "recentsMedias", new VLCRecentMediaModel( p_intf, this )); + rootCtx->setContextProperty( "settings", new Settings( p_intf, this )); if (b_hasMedialibrary) { diff --git a/modules/gui/qt/qml/menus/ViewMenu.qml b/modules/gui/qt/qml/menus/ViewMenu.qml index f8fd0abf2b..d7bfd54e32 100644 --- a/modules/gui/qt/qml/menus/ViewMenu.qml +++ b/modules/gui/qt/qml/menus/ViewMenu.qml @@ -65,7 +65,7 @@ Utils.MenuExt { text: modelData checkable: true checked: modelData === VLCStyle.colors.state - onTriggered: VLCStyle.colors.state = modelData + onTriggered: settings.VLCStyle_colors_state = modelData } } } diff --git a/modules/gui/qt/qml/style/VLCColors.qml b/modules/gui/qt/qml/style/VLCColors.qml index 8d3cb5d080..fb01867cdb 100644 --- a/modules/gui/qt/qml/style/VLCColors.qml +++ b/modules/gui/qt/qml/style/VLCColors.qml @@ -88,7 +88,7 @@ Item { property var colorSchemes: ["system", "day", "night"] - state: "system" + state: settings.VLCStyle_colors_state states: [ //other styles are provided for testing purpose State { _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
