Browse Source

Gate update channel based on your plex.tv role

Tobias Hieta 9 years ago
parent
commit
cd80d81135

+ 2 - 5
resources/settings/settings_description.json

@@ -39,12 +39,9 @@
       },
       {
         "value": "updateChannel",
-        "default": 4,
+        "default": 0,
         "possible_values": [
-          [ 0, "Stable" ],
-          [ 8, "PlexPass" ],
-          [ 4, "Ninja" ],
-          [ 2, "Employee" ]
+          [ 0, "Stable" ]
         ]
       },
       {

+ 44 - 0
src/settings/SettingsComponent.cpp

@@ -512,4 +512,48 @@ bool SettingsComponent::componentInitialize()
   connect(ctrl, &AudioSettingsController::settingsUpdated, this, &SettingsComponent::groupUpdate);
 
   return true;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+void SettingsComponent::setUserRoleList(const QStringList& userRoles)
+{
+  QVariantList values;
+
+  // stable is always available
+  QVariantMap stable;
+  stable.insert("value", 0);
+  stable.insert("title", "Stable");
+
+  values << stable;
+
+  foreach(const QString& role, userRoles)
+  {
+    QVariantMap channel;
+    int value = 0;
+    QString title;
+
+    if (role == "ninja")
+    {
+      value = 4;
+      title = "Ninja";
+    }
+    else if (role == "plexpass")
+    {
+      value = 8;
+      title = "PlexPass";
+    }
+    else if (role == "employee")
+    {
+      value = 2;
+      title = "Employee";
+    }
+
+    channel.insert("value", value);
+    channel.insert("title", title);
+
+    values << channel;
+  }
+
+  updatePossibleValues(SETTINGS_SECTION_MAIN, "updateChannel", values);
+
 }

+ 2 - 0
src/settings/SettingsComponent.h

@@ -61,6 +61,8 @@ public:
 
   Q_SIGNAL void groupUpdate(const QString& section, const QVariant& description);
 
+  void setUserRoleList(const QStringList& userRoles);
+
 private:
   explicit SettingsComponent(QObject *parent = 0);
   bool loadDescription();

+ 9 - 2
src/system/SystemComponent.cpp

@@ -256,8 +256,15 @@ QStringList SystemComponent::networkAddresses() const
 /////////////////////////////////////////////////////////////////////////////////////////
 void SystemComponent::userInformation(const QVariantMap& userModel)
 {
-  QString username = userModel["username"].toString();
-  QLOG_DEBUG() << "Change user to " << username;
+  QStringList roleList;
+  auto roles = userModel.value("roles").toMap();
+  foreach (const QString& key, roles.keys())
+  {
+    if (roles.value(key).toBool())
+      roleList << key;
+  }
+
+  SettingsComponent::Get().setUserRoleList(roleList);
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////