summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-07-21 22:03:13 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-21 22:15:58 +0300
commit0db159ef0f611ba014c59e773a59661b92ab7fde (patch)
tree7fd3b318e213f2172ac6226b8fcc7b1a8db40f4a /src
parent8e3f06edfa547e4a6f0f03e91e05eb1fdab29464 (diff)
downloadmanaplus-0db159ef0f611ba014c59e773a59661b92ab7fde.tar.gz
manaplus-0db159ef0f611ba014c59e773a59661b92ab7fde.tar.bz2
manaplus-0db159ef0f611ba014c59e773a59661b92ab7fde.tar.xz
manaplus-0db159ef0f611ba014c59e773a59661b92ab7fde.zip
Add support for opening urls in system default browser.
Diffstat (limited to 'src')
-rw-r--r--src/gui/helpwindow.cpp12
-rw-r--r--src/test/testmain.cpp8
-rw-r--r--src/utils/process.cpp97
-rw-r--r--src/utils/process.h9
4 files changed, 110 insertions, 16 deletions
diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp
index c2b0d873f..f88394f82 100644
--- a/src/gui/helpwindow.cpp
+++ b/src/gui/helpwindow.cpp
@@ -38,6 +38,7 @@
#include "utils/gettext.h"
#include "utils/langs.h"
+#include "utils/process.h"
#include "utils/translation/podict.h"
#include "utils/translation/translationmanager.h"
@@ -92,8 +93,15 @@ void HelpWindow::action(const gcn::ActionEvent &event)
void HelpWindow::handleLink(const std::string &link,
gcn::MouseEvent *event A_UNUSED)
{
- std::string helpFile = link;
- loadHelp(helpFile);
+ if (!strStartWith(link, "http://"))
+ {
+ std::string helpFile = link;
+ loadHelp(helpFile);
+ }
+ else
+ {
+ openBrowser(link);
+ }
}
void HelpWindow::loadHelp(const std::string &helpFile)
diff --git a/src/test/testmain.cpp b/src/test/testmain.cpp
index bdf071394..07e7a8f01 100644
--- a/src/test/testmain.cpp
+++ b/src/test/testmain.cpp
@@ -260,7 +260,7 @@ int TestMain::invokeTest(std::string test)
mConfig.setValue("opengl", 0);
mConfig.write();
- int ret = execFile(fileName, fileName, "-t", test);
+ int ret = execFileWait(fileName, fileName, "-t", test);
return ret;
}
@@ -277,7 +277,7 @@ int TestMain::invokeSoftwareRenderTest(std::string test)
{
mConfig.setValue("opengl", 0);
mConfig.write();
- int ret = execFile(fileName, fileName, "-t", test, 30);
+ int ret = execFileWait(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
return ret;
}
@@ -287,7 +287,7 @@ int TestMain::invokeFastOpenGLRenderTest(std::string test)
#if defined USE_OPENGL
mConfig.setValue("opengl", 1);
mConfig.write();
- int ret = execFile(fileName, fileName, "-t", test, 30);
+ int ret = execFileWait(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
return ret;
#else
@@ -300,7 +300,7 @@ int TestMain::invokeSafeOpenGLRenderTest(std::string test)
#if defined USE_OPENGL
mConfig.setValue("opengl", 2);
mConfig.write();
- int ret = execFile(fileName, fileName, "-t", test, 30);
+ int ret = execFileWait(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
return ret;
#else
diff --git a/src/utils/process.cpp b/src/utils/process.cpp
index 2d64f3a37..54f85b066 100644
--- a/src/utils/process.cpp
+++ b/src/utils/process.cpp
@@ -37,8 +37,8 @@ const int timeOut = 10;
#include <windows.h>
-int execFile(std::string pathName, std::string name A_UNUSED,
- std::string arg1, std::string arg2, int waitTime)
+int execFileWait(std::string pathName, std::string name A_UNUSED,
+ std::string arg1, std::string arg2, int waitTime)
{
if (!waitTime)
waitTime = timeOut;
@@ -74,21 +74,59 @@ int execFile(std::string pathName, std::string name A_UNUSED,
return -1;
}
+bool execFile(std::string pathName, std::string name A_UNUSED,
+ std::string arg1, std::string arg2)
+{
+ STARTUPINFO siStartupInfo;
+ PROCESS_INFORMATION piProcessInfo;
+ memset(&siStartupInfo, 0, sizeof(siStartupInfo));
+ memset(&piProcessInfo, 0, sizeof(piProcessInfo));
+ siStartupInfo.cb = sizeof(siStartupInfo);
+ std::string args(pathName + " " + arg1);
+ if (!arg2.empty())
+ args += " " + arg2;
+
+ bool res = CreateProcess(pathName.c_str(), (char*)args.c_str(), nullptr,
+ nullptr, false, CREATE_DEFAULT_ERROR_MODE, nullptr, nullptr,
+ &siStartupInfo, &piProcessInfo);
+
+ CloseHandle(piProcessInfo.hProcess);
+ CloseHandle(piProcessInfo.hThread);
+ return res;
+}
+
+bool openBrowser(std::string url)
+{
+ return (int)ShellExecute(nullptr, "open", url.c_str(), nullptr,
+ nullptr, SW_SHOWNORMAL) > 32;
+}
+
#elif defined(__APPLE__)
-int execFile(std::string pathName, std::string name,
- std::string arg1, std::string arg2, int waitTime)
+int execFileWait(std::string pathName, std::string name,
+ std::string arg1, std::string arg2, int waitTime)
{
return -1;
}
+bool execFile(std::string pathName, std::string name,
+ std::string arg1, std::string arg2)
+{
+ return false;
+}
+
+bool openBrowser(std::string url)
+{
+ return false;
+}
+
#elif defined __linux__ || defined __linux
#include <sys/types.h>
#include <sys/wait.h>
-int execFile(std::string pathName, std::string name,
- std::string arg1, std::string arg2, int waitTime)
+int execFileWait(std::string pathName, std::string name,
+ std::string arg1, std::string arg2, int waitTime)
{
pid_t mon_pid;
int status;
@@ -161,12 +199,55 @@ int execFile(std::string pathName, std::string name,
return -1;
}
+bool execFile(std::string pathName, std::string name,
+ std::string arg1, std::string arg2)
+{
+ int status;
+
+ pid_t pid;
+ if ((pid = fork()) == -1)
+ { // fork error
+ return false;
+ }
+ else if (!pid)
+ { // work child
+ if (arg2.empty())
+ {
+ execl(pathName.c_str(), name.c_str(),
+ arg1.c_str(), static_cast<char *>(nullptr));
+ }
+ else
+ {
+ execl(pathName.c_str(), name.c_str(), arg1.c_str(),
+ arg2.c_str(), static_cast<char *>(nullptr));
+ }
+ return false;
+ }
+ return true;
+}
+
+bool openBrowser(std::string url)
+{
+ return execFile("/usr/bin/xdg-open", "/usr/bin/xdg-open", url, "") == 0;
+}
+
#else
-int execFile(std::string pathName, std::string name,
- std::string arg1, std::string arg2, int waitTime)
+int execFileWait(std::string pathName, std::string name,
+ std::string arg1, std::string arg2, int waitTime)
{
return -1;
}
+bool execFile(std::string pathName, std::string name,
+ std::string arg1, std::string arg2)
+{
+ return false;
+}
+
+bool openBrowser(std::string url)
+{
+ return false;
+}
+
#endif
diff --git a/src/utils/process.h b/src/utils/process.h
index 12421729f..1895ed880 100644
--- a/src/utils/process.h
+++ b/src/utils/process.h
@@ -23,7 +23,12 @@
#include <string>
-int execFile(std::string pathName, std::string name,
- std::string arg1, std::string arg2, int waitTime = 0);
+int execFileWait(std::string pathName, std::string name,
+ std::string arg1, std::string arg2, int waitTime = 0);
+
+bool execFile(std::string pathName, std::string name,
+ std::string arg1, std::string arg2);
+
+bool openBrowser(std::string url);
#endif // UTILS_PROCESS_H