| 1 | /* | 
|---|
| 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 3 |  | 
|---|
| 4 |    Copyright (C) 2004 orx | 
|---|
| 5 |  | 
|---|
| 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 |  | 
|---|
| 16 | #include "net_link.h" | 
|---|
| 17 | #include "debug.h" | 
|---|
| 18 |  | 
|---|
| 19 | #include "threads/mutex_locker.h" | 
|---|
| 20 |  | 
|---|
| 21 | #ifdef __OSX__ | 
|---|
| 22 | #include <ApplicationServices/ApplicationServices.h> | 
|---|
| 23 | #elif defined __WIN32__ | 
|---|
| 24 | //#include <shellapi.h> | 
|---|
| 25 | #endif | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | NetLink::NetLink(const std::string& linkName) | 
|---|
| 29 | { | 
|---|
| 30 |   this->_link = linkName; | 
|---|
| 31 | } | 
|---|
| 32 |  | 
|---|
| 33 |  | 
|---|
| 34 | void NetLink::openInBrowser() const | 
|---|
| 35 | { | 
|---|
| 36 |   SDL_CreateThread(NetLink::openupInBrowser, (void*)&this->_link); | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | OrxThread::Mutex NetLink::_mutex; | 
|---|
| 40 | std::string NetLink::_defaultBrowser = "firefox"; | 
|---|
| 41 | std::list<std::string> NetLink::_browserList = NetLink::buildBrowserList(); | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 |  | 
|---|
| 45 |  | 
|---|
| 46 | int NetLink::openupInBrowser(void* url) | 
|---|
| 47 | { | 
|---|
| 48 |   OrxThread::MutexLocker lock(&NetLink::_mutex); | 
|---|
| 49 |  | 
|---|
| 50 |   std::string URL = *(std::string*)url; | 
|---|
| 51 | #ifdef __linux__ | 
|---|
| 52 |   system ((std::string(NetLink::defaultBrowser()) + " " + URL).c_str()); | 
|---|
| 53 |  | 
|---|
| 54 | #elif defined __OSX__ | 
|---|
| 55 |   CFURLRef url_handle = CFURLCreateWithBytes (NULL, (UInt8 *)URL.c_str(), URL.size(), | 
|---|
| 56 |                                               kCFStringEncodingASCII, NULL); | 
|---|
| 57 |   LSOpenCFURLRef (url_handle, NULL); | 
|---|
| 58 |   CFRelease (url_handle); | 
|---|
| 59 |  | 
|---|
| 60 | #elif defined __WIN32__ | 
|---|
| 61 |   /*  ShellExecute(GetActiveWindow(), | 
|---|
| 62 |                "open", URL.c_str(), NULL, NULL, SW_SHOWNORMAL); | 
|---|
| 63 | }*/ | 
|---|
| 64 | #endif | 
|---|
| 65 |   PRINTF(3)("loaded external webpage %s\n", URL.c_str()); | 
|---|
| 66 |  | 
|---|
| 67 |   return 0; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | void NetLink::setDefaultBrowser(const std::string& browserName) | 
|---|
| 71 | { | 
|---|
| 72 |   OrxThread::MutexLocker lock(&NetLink::_mutex); | 
|---|
| 73 |   NetLink::_defaultBrowser = browserName; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | std::list<std::string> NetLink::buildBrowserList() | 
|---|
| 77 | { | 
|---|
| 78 |   std::list<std::string> browserList; | 
|---|
| 79 |   browserList.push_back("firefox"); | 
|---|
| 80 |   browserList.push_back("mozilla"); | 
|---|
| 81 |   browserList.push_back("konqueror"); | 
|---|
| 82 |  | 
|---|
| 83 |   return  browserList; | 
|---|
| 84 | } | 
|---|