]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/options.cxx
Fix stray back-button in Qt launcher
[flightgear.git] / src / Main / options.cxx
index 3c412ca6806abd738f0e970d3ef3e74ceee35da6..77cba345cb36dd7247fbd0199a789f8950ea9c84 100644 (file)
@@ -855,6 +855,14 @@ fgOptFgScenery( const char *arg )
     return FG_OPTIONS_OK;
 }
 
+static int
+fgOptTerrasyncDir( const char *arg )
+{
+    globals->append_fg_scenery(arg, true);
+    fgSetString("/sim/terrasync/scenery-dir", arg);
+    return FG_OPTIONS_OK;
+}
+
 static int
 fgOptFov( const char *arg )
 {
@@ -1088,6 +1096,18 @@ fgOptVisibilityMiles( const char *arg )
     return FG_OPTIONS_OK;
 }
 
+static int
+fgOptMetar( const char *arg )
+{
+    // The given METAR string cannot be effective without disabling
+    // real weather fetching.
+    fgSetBool("/environment/realwx/enabled", false);
+    // The user-supplied METAR string
+    fgSetString("/environment/metar/data", arg);
+
+    return FG_OPTIONS_OK;
+}
+
 static int
 fgOptRandomWind( const char *arg )
 {
@@ -1523,7 +1543,7 @@ struct OptionDesc {
     {"enable-random-buildings",      false, OPTION_BOOL,   "/sim/rendering/random-buildings", true, "", 0 },
     {"disable-real-weather-fetch",   false, OPTION_BOOL,   "/environment/realwx/enabled", false, "", 0 },
     {"enable-real-weather-fetch",    false, OPTION_BOOL,   "/environment/realwx/enabled", true,  "", 0 },
-    {"metar",                        true,  OPTION_STRING, "/environment/metar/data", false, "", 0 },
+    {"metar",                        true,  OPTION_FUNC,   "", false, "", fgOptMetar },
     {"disable-ai-models",            false, OPTION_BOOL,   "/sim/ai/enabled", false, "", 0 },
     {"enable-ai-models",             false, OPTION_BOOL,   "/sim/ai/enabled", true, "", 0 },
     {"disable-ai-traffic",           false, OPTION_BOOL,   "/sim/traffic-manager/enabled", false, "", 0 },
@@ -1620,7 +1640,7 @@ struct OptionDesc {
     {"materials-file",               true,  OPTION_STRING, "/sim/rendering/materials-file", false, "", 0 },
     {"disable-terrasync",            false, OPTION_BOOL,   "/sim/terrasync/enabled", false, "", 0 },
     {"enable-terrasync",             false, OPTION_BOOL,   "/sim/terrasync/enabled", true, "", 0 },
-    {"terrasync-dir",                true,  OPTION_STRING, "/sim/terrasync/scenery-dir", false, "", 0 },
+    {"terrasync-dir",                true,  OPTION_FUNC,   "", false, "", fgOptTerrasyncDir },
     {"download-dir",                 true,  OPTION_STRING, "/sim/paths/download-dir", false, "", 0 },
     {"geometry",                     true,  OPTION_FUNC,   "", false, "", fgOptGeometry },
     {"bpp",                          true,  OPTION_FUNC,   "", false, "", fgOptBpp },
@@ -1749,6 +1769,22 @@ public:
     
     return it; // not found
   }
+
+    OptionValueVec::iterator findValue(const string& key)
+    {
+        OptionValueVec::iterator it = values.begin();
+        for (; it != values.end(); ++it) {
+            if (!it->desc) {
+                continue; // ignore markers
+            }
+
+            if (it->desc->option == key) {
+                return it;
+            }
+        } // of set values iteration
+        
+        return it; // not found
+    }
   
   OptionDesc* findOption(const string& key) const
   {
@@ -2182,7 +2218,35 @@ int Options::addOption(const string &key, const string &value)
   p->values.push_back(OptionValue(desc, value));
   return FG_OPTIONS_OK;
 }
-  
+
+int Options::setOption(const string &key, const string &value)
+{
+    OptionDesc* desc = p->findOption(key);
+    if (!desc) {
+        flightgear::modalMessageBox("Unknown option", "Unknown command-line option: " + key);
+        return FG_OPTIONS_ERROR;
+    }
+
+    if (!(desc->type & OPTION_MULTI)) {
+        OptionValueVec::iterator it = p->findValue(key);
+        if (it != p->values.end()) {
+            // remove existing valye
+            p->values.erase(it);
+        }
+    }
+    
+    p->values.push_back(OptionValue(desc, value));
+    return FG_OPTIONS_OK;
+}
+
+void Options::clearOption(const std::string& key)
+{
+    OptionValueVec::iterator it = p->findValue(key);
+    for (; it != p->values.end(); it = p->findValue(key)) {
+        p->values.erase(it);
+    }
+}
+
 bool Options::isOptionSet(const string &key) const
 {
   OptionValueVec::const_iterator it = p->findValue(key);