diff options
author | Thierry Crozat | 2016-09-09 23:51:40 +0100 |
---|---|---|
committer | Thierry Crozat | 2016-09-10 01:12:42 +0100 |
commit | 1f2a50bcd354e3aae80ce4f99e50f618a7b83e3c (patch) | |
tree | 872c1e77f3264360936c029e20a9ebc6bea6d1da /backends/platform | |
parent | dff88b105885e0ed3766f5e86c0d7f606348634a (diff) | |
download | scummvm-rg350-1f2a50bcd354e3aae80ce4f99e50f618a7b83e3c.tar.gz scummvm-rg350-1f2a50bcd354e3aae80ce4f99e50f618a7b83e3c.tar.bz2 scummvm-rg350-1f2a50bcd354e3aae80ce4f99e50f618a7b83e3c.zip |
CLOUD: Move openUrl to OSystem
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/android/android.cpp | 7 | ||||
-rw-r--r-- | backends/platform/android/android.h | 1 | ||||
-rw-r--r-- | backends/platform/sdl/macosx/macosx.cpp | 9 | ||||
-rw-r--r-- | backends/platform/sdl/macosx/macosx.h | 2 | ||||
-rw-r--r-- | backends/platform/sdl/posix/posix.cpp | 51 | ||||
-rw-r--r-- | backends/platform/sdl/posix/posix.h | 4 | ||||
-rw-r--r-- | backends/platform/sdl/win32/win32.cpp | 12 | ||||
-rw-r--r-- | backends/platform/sdl/win32/win32.h | 2 |
8 files changed, 84 insertions, 4 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 798772cc24..4e4417400c 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -401,7 +401,8 @@ bool OSystem_Android::hasFeature(Feature f) { f == kFeatureAspectRatioCorrection || f == kFeatureCursorPalette || f == kFeatureVirtualKeyboard || - f == kFeatureOverlaySupportsAlpha); + f == kFeatureOverlaySupportsAlpha || + f == kFeatureOpenUrl); } void OSystem_Android::setFeatureState(Feature f, bool enable) { @@ -586,6 +587,10 @@ Common::String OSystem_Android::getSystemLanguage() const { getSystemProperty("persist.sys.country").c_str()); } +bool OSystem_Android::openUrl(const Common::String &url) { + return JNI::openUrl(url.c_str()); +} + Common::String OSystem_Android::getSystemProperty(const char *name) const { char value[PROP_VALUE_MAX]; diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index ade84dd42d..2935d96381 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -286,6 +286,7 @@ public: virtual void logMessage(LogMessageType::Type type, const char *message); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); + virtual bool openUrl(const Common::String &url); virtual Common::String getSystemLanguage() const; }; diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp index c4e83dc9d3..212af6723e 100644 --- a/backends/platform/sdl/macosx/macosx.cpp +++ b/backends/platform/sdl/macosx/macosx.cpp @@ -107,7 +107,7 @@ void OSystem_MacOSX::addSysArchivesToSearchSet(Common::SearchSet &s, int priorit } bool OSystem_MacOSX::hasFeature(Feature f) { - if (f == kFeatureDisplayLogFile || f == kFeatureClipboardSupport) + if (f == kFeatureDisplayLogFile || f == kFeatureClipboardSupport || f == kFeatureOpenUrl) return true; return OSystem_POSIX::hasFeature(f); } @@ -133,6 +133,13 @@ Common::String OSystem_MacOSX::getTextFromClipboard() { return getTextFromClipboardMacOSX(); } +bool OSystem_MacOSX::openUrl(const Common::String &url) { + CFURLRef urlRef = CFURLCreateWithBytes (NULL, (UInt8*)url.c_str(), url.size(), kCFStringEncodingASCII, NULL); + OSStatus err = LSOpenCFURLRef(urlRef, NULL); + CFRelease(urlRef); + return err != noErr; +} + Common::String OSystem_MacOSX::getSystemLanguage() const { #if defined(USE_DETECTLANG) && defined(USE_TRANSLATION) CFArrayRef availableLocalizations = CFBundleCopyBundleLocalizations(CFBundleGetMainBundle()); diff --git a/backends/platform/sdl/macosx/macosx.h b/backends/platform/sdl/macosx/macosx.h index 0c755cbf6d..929f2f91fa 100644 --- a/backends/platform/sdl/macosx/macosx.h +++ b/backends/platform/sdl/macosx/macosx.h @@ -35,6 +35,8 @@ public: virtual bool hasTextInClipboard(); virtual Common::String getTextFromClipboard(); + + virtual bool openUrl(const Common::String &url); virtual Common::String getSystemLanguage() const; 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 <stdlib.h> #include <errno.h> #include <sys/stat.h> #include <sys/wait.h> @@ -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 diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index fcc0849624..99c71a49e0 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -94,7 +94,7 @@ void OSystem_Win32::initBackend() { bool OSystem_Win32::hasFeature(Feature f) { - if (f == kFeatureDisplayLogFile) + if (f == kFeatureDisplayLogFile || f == kFeatureOpenUrl) return true; return OSystem_SDL::hasFeature(f); @@ -135,6 +135,16 @@ bool OSystem_Win32::displayLogFile() { return false; } +bool OSystem_Win32::openUrl(const Common::String &url) { + const uint64 result = (uint64)ShellExecute(0, 0, /*(wchar_t*)nativeFilePath.utf16()*/url.c_str(), 0, 0, SW_SHOWNORMAL); + // ShellExecute returns a value greater than 32 if successful + if (result <= 32) { + warning("ShellExecute failed: error = %u", result); + return false; + } + return true; +} + Common::String OSystem_Win32::getDefaultConfigFileName() { char configFile[MAXPATHLEN]; diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h index ca0843e834..636ebae88f 100644 --- a/backends/platform/sdl/win32/win32.h +++ b/backends/platform/sdl/win32/win32.h @@ -36,6 +36,8 @@ public: virtual bool displayLogFile(); + virtual bool openUrl(const Common::String &url); + protected: /** * The path of the currently open log file, if any. |