]> git.mxchange.org Git - flightgear.git/commitdiff
Make web browser app configurable through CMake (for Linux)
authorThorstenB <brehmt@gmail.com>
Sat, 18 Aug 2012 12:11:31 +0000 (14:11 +0200)
committerThorstenB <brehmt@gmail.com>
Sat, 18 Aug 2012 12:11:31 +0000 (14:11 +0200)
so package builders don't need local patches.
Also, instead of hardcoded firefox, use "xdg-open" or "sensible-browser"
launchers on Linux, to auto-detect user's preferred browser.
Override with cmake switch -DWEB_BROWSER=...
(Not affecting Mac/Win which are hard-coded anyway).

CMakeLists.txt
CMakeModules/DetectBrowser.cmake [new file with mode: 0644]
src/GUI/gui_funcs.cxx
src/Include/config_cmake.h.in
src/Main/fg_init.cxx
src/Main/options.cxx

index 54409e9fd9ff7d3c65a4deec2d87ba053dfe195e..85f1982ef349900555de666d5425ed3d1f5c9385 100644 (file)
@@ -28,6 +28,7 @@ endif(InSourceBuild)
 
 # System detection/default settings
 include( DetectDistro )
+include( DetectBrowser )
 
 set(CMAKE_DEBUG_POSTFIX          "d" CACHE STRING "add a postfix, usually d on windows")
 set(CMAKE_RELEASE_POSTFIX        ""  CACHE STRING "add a postfix, usually empty on windows")
diff --git a/CMakeModules/DetectBrowser.cmake b/CMakeModules/DetectBrowser.cmake
new file mode 100644 (file)
index 0000000..6d4be54
--- /dev/null
@@ -0,0 +1,22 @@
+# DetectBrowser.cmake -- Detect web browser launcher application
+
+# Set default command to open browser. Override with -DWEB_BROWSER=...
+if (APPLE OR MSVC)
+    # opening the web browser is hardcoded for Mac and Windows,
+    # so this doesn't really have an effect...
+    set(WEB_BROWSER "open")
+else()
+    if(CMAKE_SYSTEM_NAME MATCHES "Linux")
+        # "xdg-open" provides run-time detection of user's preferred browser on (most) Linux.
+        if (NOT LINUX_DISTRO MATCHES "Debian")
+            set(WEB_BROWSER "xdg-open" CACHE STRING "Command to open web browser")
+        else()
+            # Debian is different: "sensible-browser" provides auto-detection
+            set(WEB_BROWSER "sensible-browser" CACHE STRING "Command to open web browser")
+        endif()
+    else()
+        # Default for non Linux/non Mac/non Windows platform...
+        set(WEB_BROWSER "firefox" CACHE STRING "Command to open web browser")
+    endif()
+    message(STATUS "Web browser launcher command is: ${WEB_BROWSER}")
+endif()
index 5d797d009ade2dd0560bcf91c1efebd404f8b462..e8941e3d53fbef4b772a0d105e0e1e00cca792c4 100644 (file)
@@ -192,22 +192,7 @@ bool openBrowser(string address)
   }
   
   cocoaOpenUrl(address);
-  return ok;
-#endif
-  
-#ifndef _WIN32
-
-    string command = globals->get_browser();
-    string::size_type pos;
-    if ((pos = command.find("%u", 0)) != string::npos)
-        command.replace(pos, 2, address);
-    else
-        command += " " + address;
-
-    command += " &";
-    ok = (system( command.c_str() ) == 0);
-
-#else // _WIN32
+#elif defined _WIN32
 
     // Look for favorite browser
     char win32_name[1024];
@@ -218,7 +203,17 @@ bool openBrowser(string address)
 # endif
     ShellExecute ( NULL, "open", win32_name, NULL, NULL,
                    SW_SHOWNORMAL ) ;
+#else
+    // Linux, BSD, SGI etc
+    string command = globals->get_browser();
+    string::size_type pos;
+    if ((pos = command.find("%u", 0)) != string::npos)
+        command.replace(pos, 2, address);
+    else
+        command += " \"" + address +"\"";
 
+    command += " &";
+    ok = (system( command.c_str() ) == 0);
 #endif
 
     mkDialog("The file is shown in your web browser window.");
index 245854c827e01e63dcb4e3c0cda8eb22ea2cada7..230b3d7b2800e9c758c23986a2b4fde7c8f3f959 100644 (file)
@@ -33,6 +33,7 @@
 #cmakedefine HAVE_LIBSVN_CLIENT_1
 
 #define PKGLIBDIR "@FG_DATA_DIR@"
+#define WEB_BROWSER "@WEB_BROWSER@"
 
 #cmakedefine FG_HAVE_HLA
 #cmakedefine FG_JPEG_SERVER
index 7b7f7fff961a5249b0252bbd71b7109306979594..cb4a2e537c7100e7d5f7e0558269464ab07fc4b1 100644 (file)
@@ -1028,7 +1028,9 @@ bool fgInitGeneral() {
     }
     SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
 
-    globals->set_browser(fgGetString("/sim/startup/browser-app", "firefox %u"));
+    // Note: browser command is hard-coded for Mac/Windows, so this only affects other platforms
+    globals->set_browser(fgGetString("/sim/startup/browser-app", WEB_BROWSER));
+    fgSetString("/sim/startup/browser-app", globals->get_browser());
 
     simgear::Dir cwd(simgear::Dir::current());
     SGPropertyNode *curr = fgGetNode("/sim", true);
index 77bbd78c01ffb9ab8ba32ea88c6344316badb9cb..d5cc06e9a437f3cede95373605534cab4d9a042c 100644 (file)
@@ -175,17 +175,6 @@ fgSetDefaults ()
     // fgSetString("/sim/startup/mouse-pointer", "disabled");
     fgSetString("/sim/control-mode", "joystick");
     fgSetBool("/controls/flight/auto-coordination", false);
-#if defined(WIN32)
-    fgSetString("/sim/startup/browser-app", "webrun.bat");
-#elif defined(__APPLE__)
-    fgSetString("/sim/startup/browser-app", "open");
-#elif defined(sgi)
-    fgSetString("/sim/startup/browser-app", "launchWebJumper");
-#else
-    const char* browserEnv = ::getenv( "WEBBROWSER" );
-    if (!browserEnv) browserEnv = "netscape";
-    fgSetString("/sim/startup/browser-app", browserEnv);
-#endif
     fgSetString("/sim/logging/priority", "alert");
 
                                // Features