Browse Source

Switch Windows default back to OpenGL, change handling of the option

The trick with creating a dummy file for the OpenGL vs. ANGLE setting
was somewhat attractive, because we didn't have to load/parse the main
config file a second time. The problem is that SettingsComponent is a
singleton, and it needs to be created at a specific point in the
program. We can't just create it earlier.

But it created an awkward requirement to restart PMP twice when editing
the config file. It also makes it much harder to change the default
setting.

Abandon the previous approach, and let it load the main config file
twice. The logic for this is in readPreinitValue(). (Not bothering with
the case if we need this for something else - loading the config file is
cheap.) This duplicates some config file traversal logic, but
fortunately it's only 1 line of code.
Vincent Lang 9 years ago
parent
commit
d31be7a8f5

+ 2 - 1
resources/settings/settings_description.json

@@ -76,7 +76,8 @@
       },
       {
         "value": "useOpenGL",
-        "default": false,
+        // Warning: the default must be the same as the one in preinitQt().
+        "default": true,
         "platforms": [ "windows" ]
       }
     ]

+ 8 - 21
src/main.cpp

@@ -35,28 +35,20 @@ static void preinitQt()
   QCoreApplication::setOrganizationDomain("plex.tv");
 
 #ifdef Q_OS_WIN32
-  if (QFile::exists(Paths::dataDir("use_opengl")))
+  QVariant useOpengl = SettingsComponent::readPreinitValue(SETTINGS_SECTION_MAIN, "useOpenGL");
+
+  // Warning: this must be the same as the default value as declared in
+  // the settings_description.json file, or confusion will result.
+  if (useOpengl.type() != QMetaType::Bool)
+    useOpengl = true;
+
+  if (useOpengl.toBool())
     QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
   else
     QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
 #endif
 }
 
-/////////////////////////////////////////////////////////////////////////////////////////
-static void updateGL(const QVariantMap& values)
-{
-#ifdef Q_OS_WIN32
-  QString path = Paths::dataDir("use_opengl");
-  if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "useOpenGL").toBool())
-  {
-    QFile f(path);
-    f.open(QIODevice::WriteOnly);
-  }
-  else
-    QFile::remove(path);
-#endif
-}
-
 /////////////////////////////////////////////////////////////////////////////////////////
 static void qtMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
 {
@@ -262,11 +254,6 @@ int main(int argc, char *argv[])
     //
     ComponentManager::Get().initialize();
 
-    auto mainSection = SettingsComponent::Get().getSection("main");
-    if (mainSection)
-      QObject::connect(mainSection, &SettingsSection::valuesUpdated, &updateGL);
-    updateGL(QVariantMap{});
-
     // enable remote inspection if we have the correct setting for it.
     if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool())
       qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992");

+ 7 - 0
src/settings/SettingsComponent.cpp

@@ -100,6 +100,13 @@ static void writeJson(const QString& filename, const QJsonObject& data, bool pre
   writeFile(filename, json.toJson(pretty ? QJsonDocument::Indented : QJsonDocument::Compact));
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////
+QVariant SettingsComponent::readPreinitValue(const QString& sectionID, const QString& key)
+{
+  QJsonObject json = loadJson(Paths::dataDir("plexmediaplayer.conf"));
+  return json["sections"].toObject()[sectionID].toObject()[key].toVariant();
+}
+
 /////////////////////////////////////////////////////////////////////////////////////////
 void SettingsComponent::load()
 {

+ 4 - 0
src/settings/SettingsComponent.h

@@ -67,6 +67,10 @@ public:
 
   void setUserRoleList(const QStringList& userRoles);
 
+  // A hack to load a value from the config file at very early init time, before
+  // the SettingsComponent is created.
+  static QVariant readPreinitValue(const QString& sectionID, const QString& key);
+
 private:
   explicit SettingsComponent(QObject *parent = 0);
   bool loadDescription();