[vlc-devel] [PATCH 26/38] qt: add controlbar model default builder

Fatih Uzunoglu fuzun54 at outlook.com
Thu Aug 20 19:55:35 CEST 2020


and use it instead of #define.
---
 .../gui/qt/player/playercontrolbarmodel.cpp   | 61 +++++++++++++++----
 .../gui/qt/player/playercontrolbarmodel.hpp   |  4 +-
 2 files changed, 51 insertions(+), 14 deletions(-)

diff --git a/modules/gui/qt/player/playercontrolbarmodel.cpp b/modules/gui/qt/player/playercontrolbarmodel.cpp
index 75e3434e34..b202f7b2dd 100644
--- a/modules/gui/qt/player/playercontrolbarmodel.cpp
+++ b/modules/gui/qt/player/playercontrolbarmodel.cpp
@@ -20,13 +20,39 @@
 #include "qt.hpp"
 #include "playercontrolbarmodel.hpp"
 
-#define MAIN_TB1_DEFAULT "20;21;65;17;3;0;1;4;18;65;33;7"
-#define MINI_TB_DEFAULT "65;17;3;0;1;4;18;65;33;7"
+
+static const PlayerControlBarModel::IconToolButton MAIN_TB_DEFAULT[] = {
+                                                                           {PlayerControlBarModel::LANG_BUTTON},
+                                                                           {PlayerControlBarModel::MENU_BUTTON},
+                                                                           {PlayerControlBarModel::WIDGET_SPACER_EXTEND},
+                                                                           {PlayerControlBarModel::RANDOM_BUTTON},
+                                                                           {PlayerControlBarModel::PREVIOUS_BUTTON},
+                                                                           {PlayerControlBarModel::PLAY_BUTTON},
+                                                                           {PlayerControlBarModel::STOP_BUTTON},
+                                                                           {PlayerControlBarModel::NEXT_BUTTON},
+                                                                           {PlayerControlBarModel::LOOP_BUTTON},
+                                                                           {PlayerControlBarModel::WIDGET_SPACER_EXTEND},
+                                                                           {PlayerControlBarModel::VOLUME},
+                                                                           {PlayerControlBarModel::FULLSCREEN_BUTTON}
+                                                                       };
+
+static const PlayerControlBarModel::IconToolButton MINI_TB_DEFAULT[] = {
+                                                                           {PlayerControlBarModel::WIDGET_SPACER_EXTEND},
+                                                                           {PlayerControlBarModel::RANDOM_BUTTON},
+                                                                           {PlayerControlBarModel::PREVIOUS_BUTTON},
+                                                                           {PlayerControlBarModel::PLAY_BUTTON},
+                                                                           {PlayerControlBarModel::STOP_BUTTON},
+                                                                           {PlayerControlBarModel::NEXT_BUTTON},
+                                                                           {PlayerControlBarModel::LOOP_BUTTON},
+                                                                           {PlayerControlBarModel::WIDGET_SPACER_EXTEND},
+                                                                           {PlayerControlBarModel::VOLUME},
+                                                                           {PlayerControlBarModel::FULLSCREEN_BUTTON}
+                                                                       };
+
 
 PlayerControlBarModel::PlayerControlBarModel(QObject *_parent) : QAbstractListModel(_parent)
 {
     configName = "MainPlayerToolbar";
-    defaultConfig = MAIN_TB1_DEFAULT;
 }
 
 void PlayerControlBarModel::saveConfig()
@@ -56,13 +82,28 @@ void PlayerControlBarModel::reloadModel()
 {
     beginResetModel();
     mButtons.clear();
-    QString config = getSettings() ->value( configName, defaultConfig )
-                                            .toString();
-    parseAndAdd(config);
+
+    QVariant config = getSettings() ->value(configName);
+
+    if (!config.isNull() && config.canConvert<QString>())
+        parseAndAdd(config.toString());
+    else if (configName == "MainPlayerToolbar")
+        parseDefault(MAIN_TB_DEFAULT, ARRAY_SIZE(MAIN_TB_DEFAULT));
+    else
+        parseDefault(MINI_TB_DEFAULT, ARRAY_SIZE(MINI_TB_DEFAULT));
+    
     endResetModel();
 }
 
-void PlayerControlBarModel::parseAndAdd(QString &config)
+void PlayerControlBarModel::parseDefault(const PlayerControlBarModel::IconToolButton* config, const size_t config_size)
+{
+    beginInsertRows(QModelIndex(),rowCount(),rowCount() + config_size);
+    for (size_t i = 0; i < config_size; i++)
+        mButtons.append(config[i]);
+    endInsertRows();
+}
+
+void PlayerControlBarModel::parseAndAdd(const QString &config)
 {
     beginInsertRows(QModelIndex(),rowCount(),rowCount()+config.split(";", QString::SkipEmptyParts).length() - 1);
 
@@ -76,7 +117,7 @@ void PlayerControlBarModel::parseAndAdd(QString &config)
             continue;
         }
         bool ok;
-        ButtonType_e i_type = static_cast<ButtonType_e>(iconPropertyTxt.contains("-") ? iconPropertyTxt.split("-").at( 0 ).toInt( &ok ) : iconPropertyTxt.toInt( &ok));
+        ButtonType_e i_type = static_cast<ButtonType_e>( list2.at( 0 ).toInt( &ok ) );
         if( !ok )
         {
             msg_Warn( p_intf, "Parsing error 2. Please, report this." );
@@ -173,10 +214,6 @@ void PlayerControlBarModel::setConfigName(QString name)
     if(configName == name)
         return;
     configName = name;
-    if(configName == "MainPlayerToolbar")
-        defaultConfig = MAIN_TB1_DEFAULT;
-    else
-        defaultConfig = MINI_TB_DEFAULT;
     if  (m_mainCtx)
         reloadModel();
     emit configNameChanged(name);
diff --git a/modules/gui/qt/player/playercontrolbarmodel.hpp b/modules/gui/qt/player/playercontrolbarmodel.hpp
index 6fe9c153cd..23172bc2f6 100644
--- a/modules/gui/qt/player/playercontrolbarmodel.hpp
+++ b/modules/gui/qt/player/playercontrolbarmodel.hpp
@@ -109,9 +109,9 @@ protected:
 private:
     QVector<IconToolButton> mButtons;
     QString configName;
-    QString defaultConfig;
 
-    void parseAndAdd(QString& config);
+    void parseAndAdd(const QString& config);
+    void parseDefault(const IconToolButton* config, const size_t config_size);
 
     bool setButtonAt(int index, const IconToolButton &button);
     void addProfiles();
-- 
2.25.1



More information about the vlc-devel mailing list