From 1f2a50bcd354e3aae80ce4f99e50f618a7b83e3c Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Fri, 9 Sep 2016 23:51:40 +0100 Subject: CLOUD: Move openUrl to OSystem --- backends/platform/sdl/posix/posix.cpp | 51 ++++++++++++++++++++++++++++++++++- backends/platform/sdl/posix/posix.h | 4 +++ 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'backends/platform/sdl/posix') diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index 0d5f39736a..b805a452cf 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -25,6 +25,7 @@ #define FORBIDDEN_SYMBOL_EXCEPTION_exit #define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h #define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h +#define FORBIDDEN_SYMBOL_EXCEPTION_system #include "common/scummsys.h" @@ -40,6 +41,9 @@ #include "backends/audiocd/linux/linux-audiocd.h" #endif +#include "common/textconsole.h" + +#include #include #include #include @@ -78,7 +82,7 @@ void OSystem_POSIX::initBackend() { } bool OSystem_POSIX::hasFeature(Feature f) { - if (f == kFeatureDisplayLogFile) + if (f == kFeatureDisplayLogFile || f == kFeatureOpenUrl) return true; return OSystem_SDL::hasFeature(f); } @@ -261,6 +265,51 @@ bool OSystem_POSIX::displayLogFile() { return WIFEXITED(status) && WEXITSTATUS(status) == 0; } +bool OSystem_POSIX::openUrl(const Common::String &url) { + // inspired by Qt's "qdesktopservices_x11.cpp" + + // try "standards" + if (launchBrowser("xdg-open", url)) + return true; + if (launchBrowser(getenv("DEFAULT_BROWSER"), url)) + return true; + if (launchBrowser(getenv("BROWSER"), url)) + return true; + + // try desktop environment specific tools + if (launchBrowser("gnome-open", url)) // gnome + return true; + if (launchBrowser("kfmclient openURL", url)) // kde + return true; + if (launchBrowser("exo-open", url)) // xfce + return true; + + // try browser names + if (launchBrowser("firefox", url)) + return true; + if (launchBrowser("mozilla", url)) + return true; + if (launchBrowser("netscape", url)) + return true; + if (launchBrowser("opera", url)) + return true; + if (launchBrowser("chromium-browser", url)) + return true; + if (launchBrowser("google-chrome", url)) + return true; + + warning("openUrl() (POSIX) failed to open URL"); + return false; +} + +bool OSystem_POSIX::launchBrowser(const Common::String& client, const Common::String &url) { + // FIXME: system's input must be heavily escaped + // well, when url's specified by user + // it's OK now (urls are hardcoded somewhere in GUI) + Common::String cmd = client + " " + url; + return (system(cmd.c_str()) != -1); +} + AudioCDManager *OSystem_POSIX::createAudioCDManager() { #ifdef USE_LINUXCD diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h index 050463c273..e5110ff632 100644 --- a/backends/platform/sdl/posix/posix.h +++ b/backends/platform/sdl/posix/posix.h @@ -35,6 +35,8 @@ public: virtual bool displayLogFile(); + virtual bool openUrl(const Common::String &url); + virtual void init(); virtual void initBackend(); @@ -63,6 +65,8 @@ protected: virtual Common::WriteStream *createLogFile(); virtual AudioCDManager *createAudioCDManager(); + + bool launchBrowser(const Common::String& client, const Common::String &url); }; #endif -- cgit v1.2.3