[9394] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[9393] | 3 | |
---|
[9394] | 4 | Copyright (C) 2004 orx |
---|
[9393] | 5 | |
---|
[9394] | 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Benjamin Grauer |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[9393] | 16 | #include "net_link.h" |
---|
[9394] | 17 | #include "debug.h" |
---|
[9393] | 18 | |
---|
| 19 | |
---|
| 20 | #ifdef __OSX__ |
---|
| 21 | #include <ApplicationServices/ApplicationServices.h> |
---|
| 22 | #elif defined __WIN32__ |
---|
| 23 | //#include <shellapi.h> |
---|
| 24 | #endif |
---|
| 25 | |
---|
[9394] | 26 | |
---|
| 27 | NetLink::NetLink(const std::string& linkName) |
---|
[9393] | 28 | { |
---|
[9394] | 29 | this->_link = linkName; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | void NetLink::openInBrowser() const |
---|
| 34 | { |
---|
| 35 | SDL_CreateThread(NetLink::openupInBrowser, (void*)&this->_link); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | OrxThread::Mutex NetLink::_mutex; |
---|
[9395] | 39 | std::string NetLink::_defaultBrowser = "firefox"; |
---|
[9394] | 40 | std::list<std::string> NetLink::_browserList = NetLink::buildBrowserList(); |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | int NetLink::openupInBrowser(void* url) |
---|
| 46 | { |
---|
| 47 | OrxThread::MutexLock lock(&NetLink::_mutex); |
---|
| 48 | |
---|
[9393] | 49 | std::string URL = *(std::string*)url; |
---|
| 50 | #ifdef __linux__ |
---|
[9394] | 51 | system ((std::string(NetLink::defaultBrowser()) + " " + URL).c_str()); |
---|
| 52 | |
---|
[9393] | 53 | #elif defined __OSX__ |
---|
| 54 | CFURLRef url_handle = CFURLCreateWithBytes (NULL, (UInt8 *)URL.c_str(), URL.size(), |
---|
| 55 | kCFStringEncodingASCII, NULL); |
---|
| 56 | LSOpenCFURLRef (url_handle, NULL); |
---|
| 57 | CFRelease (url_handle); |
---|
[9394] | 58 | |
---|
[9393] | 59 | #elif defined __WIN32__ |
---|
| 60 | /* ShellExecute(GetActiveWindow(), |
---|
| 61 | "open", URL.c_str(), NULL, NULL, SW_SHOWNORMAL); |
---|
| 62 | }*/ |
---|
| 63 | #endif |
---|
| 64 | PRINTF(3)("loaded external webpage %s\n", URL.c_str()); |
---|
[9394] | 65 | |
---|
| 66 | return 0; |
---|
[9393] | 67 | } |
---|
| 68 | |
---|
[9394] | 69 | void NetLink::setDefaultBrowser(const std::string& browserName) |
---|
| 70 | { |
---|
| 71 | OrxThread::MutexLock lock(&NetLink::_mutex); |
---|
[9395] | 72 | NetLink::_defaultBrowser = browserName; |
---|
[9394] | 73 | } |
---|
| 74 | |
---|
| 75 | std::list<std::string> NetLink::buildBrowserList() |
---|
| 76 | { |
---|
| 77 | std::list<std::string> browserList; |
---|
| 78 | browserList.push_back("firefox"); |
---|
| 79 | browserList.push_back("mozilla"); |
---|
| 80 | browserList.push_back("konqueror"); |
---|
| 81 | |
---|
| 82 | return browserList; |
---|
| 83 | } |
---|