[vlc-devel] [PATCH] qt: enable loading/saving settings using qml
Abel Tesfaye
abeltesfaye45 at gmail.com
Wed Jun 5 20:59:47 CEST 2019
From: Abel Tesfaye <Abeltesfaye45 at gmail.com>
fixes #22171
---
modules/gui/qt/Makefile.am | 3 ++
.../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(-)
create mode 100644 modules/gui/qt/components/settings.cpp
create mode 100644 modules/gui/qt/components/settings.hpp
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 5d1fa61f6d..fc0932380c 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -105,6 +105,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 9570253345..3d6c4cff23 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 ef4b8da8e7..1f3069da43 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"
@@ -396,6 +397,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 7a58605092..41be327c1d 100644
--- a/modules/gui/qt/qml/menus/ViewMenu.qml
+++ b/modules/gui/qt/qml/menus/ViewMenu.qml
@@ -54,7 +54,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 228eac0285..c634e2465e 100644
--- a/modules/gui/qt/qml/style/VLCColors.qml
+++ b/modules/gui/qt/qml/style/VLCColors.qml
@@ -77,7 +77,7 @@ Item {
property var colorSchemes: ["system", "day", "night"]
- state: "system"
+ state: settings.VLCStyle_colors_state
states: [
//other styles are provided for testing purpose
State {
--
2.21.0
More information about the vlc-devel
mailing list