[vlc-commits] qt: Add multiple config support to playercontrolbarmodel

Rohan Rajpal git at videolan.org
Wed Aug 21 16:26:55 CEST 2019


vlc | branch: master | Rohan Rajpal <rohan17089 at iiitd.ac.in> | Fri Aug  2 23:53:19 2019 +0530| [cebf83a2ab2bfafed3f50bbdacc67b56da914994] | committer: Jean-Baptiste Kempf

qt: Add multiple config support to playercontrolbarmodel

Extend player controlbar model to support different configs

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cebf83a2ab2bfafed3f50bbdacc67b56da914994
---

 .../gui/qt/components/playercontrolbarmodel.cpp    | 27 ++++++++++++++--------
 .../gui/qt/components/playercontrolbarmodel.hpp    |  7 ++++++
 modules/gui/qt/qml/dialogs/ToolbarEditor.qml       |  3 +++
 modules/gui/qt/qml/player/ControlBar.qml           |  3 +++
 4 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/modules/gui/qt/components/playercontrolbarmodel.cpp b/modules/gui/qt/components/playercontrolbarmodel.cpp
index bb29040b89..0781e44d86 100644
--- a/modules/gui/qt/components/playercontrolbarmodel.cpp
+++ b/modules/gui/qt/components/playercontrolbarmodel.cpp
@@ -21,21 +21,17 @@
 #include "playercontrolbarmodel.hpp"
 
 #define MAIN_TB1_DEFAULT "20;21;65;17;3;0-2;1-2;4;18;65;33;7"
+#define MINI_TB_DEFAULT "17;3;0;1;4;18"
 
 PlayerControlBarModel::PlayerControlBarModel(QObject *_parent) : QAbstractListModel(_parent)
 {
-}
-
-void PlayerControlBarModel::loadConfig()
-{
-    QString config = getSettings() ->value( "MainWindow/PlayerControlToolbar1", MAIN_TB1_DEFAULT )
-                                            .toString();
-    parseAndAdd(config);
+    configName = "MainPlayerToolbar";
+    defaultConfig = MAIN_TB1_DEFAULT;
 }
 
 void PlayerControlBarModel::saveConfig()
 {
-    getSettings()->setValue("MainWindow/PlayerControlToolbar1",getConfig());
+    getSettings()->setValue(configName,getConfig());
 }
 
 QString PlayerControlBarModel::getConfig()
@@ -62,7 +58,7 @@ void PlayerControlBarModel::reloadModel()
 {
     beginResetModel();
     mButtons.clear();
-    QString config = getSettings() ->value( "MainWindow/PlayerControlToolbar1", MAIN_TB1_DEFAULT )
+    QString config = getSettings() ->value( configName, defaultConfig )
                                             .toString();
     parseAndAdd(config);
     endResetModel();
@@ -190,7 +186,18 @@ void PlayerControlBarModel::setMainCtx(QmlMainContext* ctx)
         p_intf = temp_intf;
     else
         return;
-    loadConfig();
+}
+
+void PlayerControlBarModel::setConfigName(QString name)
+{
+    if(configName == name)
+        return;
+    configName = name;
+    if(configName == "MainPlayerToolbar")
+        defaultConfig = MAIN_TB1_DEFAULT;
+    else
+        defaultConfig = MINI_TB_DEFAULT;
+    emit configNameChanged(name);
 }
 
 void PlayerControlBarModel::insert(int index, QVariantMap bdata)
diff --git a/modules/gui/qt/components/playercontrolbarmodel.hpp b/modules/gui/qt/components/playercontrolbarmodel.hpp
index c4c6780761..ed4bda5083 100644
--- a/modules/gui/qt/components/playercontrolbarmodel.hpp
+++ b/modules/gui/qt/components/playercontrolbarmodel.hpp
@@ -28,6 +28,7 @@ class PlayerControlBarModel : public QAbstractListModel
 {
     Q_OBJECT
     Q_PROPERTY(QmlMainContext* mainCtx READ getMainCtx WRITE setMainCtx NOTIFY ctxChanged)
+    Q_PROPERTY(QString configName READ getConfigName WRITE setConfigName NOTIFY configNameChanged)
 
 public:
     explicit PlayerControlBarModel(QObject *_parent = nullptr);
@@ -101,14 +102,20 @@ public:
     inline QmlMainContext* getMainCtx() const { return m_mainCtx; }
     void setMainCtx(QmlMainContext*);
 
+    inline QString getConfigName() { return configName; }
+    void setConfigName(QString name);
+
 signals:
     void ctxChanged(QmlMainContext*);
+    void configNameChanged(QString);
 
 protected:
     intf_thread_t       *p_intf;
 
 private:
     QVector<IconToolButton> mButtons;
+    QString configName;
+    QString defaultConfig;
 
     void parseAndAdd(QString& config);
 
diff --git a/modules/gui/qt/qml/dialogs/ToolbarEditor.qml b/modules/gui/qt/qml/dialogs/ToolbarEditor.qml
index 56ae3a252d..91f1ed8d2c 100644
--- a/modules/gui/qt/qml/dialogs/ToolbarEditor.qml
+++ b/modules/gui/qt/qml/dialogs/ToolbarEditor.qml
@@ -193,6 +193,9 @@ Rectangle{
     PlayerControlBarModel {
         id: playerControlBarModel
         mainCtx: mainctx
+        configName: "MainPlayerToolbar"
+        /* Load the model when mainctx is set */
+        Component.onCompleted: reloadModel()
     }
 
     Player.ControlButtons{
diff --git a/modules/gui/qt/qml/player/ControlBar.qml b/modules/gui/qt/qml/player/ControlBar.qml
index e817b5717e..a02cde9e6c 100644
--- a/modules/gui/qt/qml/player/ControlBar.qml
+++ b/modules/gui/qt/qml/player/ControlBar.qml
@@ -131,6 +131,9 @@ Utils.NavigableFocusScope {
     PlayerControlBarModel{
         id:playerControlBarModel
         mainCtx: mainctx
+        configName: "MainPlayerToolbar"
+        /* Load the model when mainctx is set */
+        Component.onCompleted: reloadModel()
     }
 
     ControlButtons{



More information about the vlc-commits mailing list