Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9394 in orxonox.OLD for branches/proxy/src


Ignore:
Timestamp:
Jul 23, 2006, 4:07:41 PM (18 years ago)
Author:
bensch
Message:

netlink quite nice

Location:
branches/proxy/src/lib/util
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/util/Makefile.am

    r9347 r9394  
    2323                filesys/file.cc \
    2424                filesys/directory.cc \
     25                filesys/net_link.cc \
    2526                \
    2627                preferences.cc \
     
    4243                filesys/file.h \
    4344                filesys/directory.h \
     45                filesys/net_link.h \
    4446                \
    4547                preferences.h \
  • branches/proxy/src/lib/util/filesys/net_link.cc

    r9393 r9394  
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
    13
     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*/
    215
    316#include "net_link.h"
     17#include "debug.h"
    418
    5 
    6 #include "threading.h"
    7 void SimpleGameMenu::execURL() const
    8 {
    9   std::string URL = "http://www.orxonox.net";
    10   SDL_CreateThread(startURL, (void*)&URL);
    11 }
    1219
    1320#ifdef __OSX__
     
    1724#endif
    1825
    19 int SimpleGameMenu::startURL(void* url)
     26
     27NetLink::NetLink(const std::string& linkName)
    2028{
     29  this->_link = linkName;
     30}
     31
     32
     33void NetLink::openInBrowser() const
     34{
     35  SDL_CreateThread(NetLink::openupInBrowser, (void*)&this->_link);
     36}
     37
     38OrxThread::Mutex NetLink::_mutex;
     39std::string NetLink::_browser = "firefox";
     40std::list<std::string> NetLink::_browserList = NetLink::buildBrowserList();
     41
     42
     43
     44
     45int NetLink::openupInBrowser(void* url)
     46{
     47  OrxThread::MutexLock lock(&NetLink::_mutex);
     48
    2149  std::string URL = *(std::string*)url;
    2250#ifdef __linux__
    23   system ((std::string("firefox ") + URL).c_str());
     51  system ((std::string(NetLink::defaultBrowser()) + " " + URL).c_str());
     52
    2453#elif defined __OSX__
    2554  CFURLRef url_handle = CFURLCreateWithBytes (NULL, (UInt8 *)URL.c_str(), URL.size(),
     
    2756  LSOpenCFURLRef (url_handle, NULL);
    2857  CFRelease (url_handle);
     58
    2959#elif defined __WIN32__
    3060  /*  ShellExecute(GetActiveWindow(),
     
    3363#endif
    3464  PRINTF(3)("loaded external webpage %s\n", URL.c_str());
     65
     66  return 0;
    3567}
    3668
     69void NetLink::setDefaultBrowser(const std::string& browserName)
     70{
     71  OrxThread::MutexLock lock(&NetLink::_mutex);
     72  NetLink::_browser = browserName;
     73}
     74
     75std::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}
  • branches/proxy/src/lib/util/filesys/net_link.h

    r9393 r9394  
     1/*!
     2 * @file net_link.h
     3 * @brief Definition of a NetLink class
     4 * NetLink is a File link to a page of file link to the Internet,
     5 * or the local file-system
     6 *
     7 * Opening a link should be made easy through this class
     8 *
     9 * !! DANGER IT IS POSSIBLE TO EXECUTE ALL PROGRAMMS WITH USER'S RIGHTS
     10 * !! ON THE DESIGNATED MACHINE
     11 * !! THIS CLASS SHOULD BE USED WITH CAUTION WHEN USING OVER IN NETWORK
     12 * !! MODE
     13 */
    114
    215#ifndef __NET_LINK_H__
     
    619#include <list>
    720
     21#include "threading.h"
     22
     23//! NetLink is a File and Link executer for Internet Links
     24/**
     25 * @example: NetLink("http://www.orxonox.net").openInBrowser();
     26 */
    827class NetLink
    928{
    1029public:
    11   NetLink(const std::string& );
     30  NetLink(const std::string& linkName);
    1231
    13   void execURL() const;
    14   int startURL(void* url);
    15 
     32  void openInBrowser() const;
    1633
    1734  static void setDefaultBrowser(const std::string& browserName);
    18   static const std::string& defaultBrowser();
     35  static const std::string& defaultBrowser() {  return NetLink::_browser; };
    1936
    2037private:
    21   static void buildBrowserList();
     38  static int openupInBrowser(void* url);
     39
     40  static std::list<std::string> buildBrowserList();
    2241
    2342
    2443private:
    25   std::string                    _link;
     44  std::string                     _link;             //!< Linkname
     45
    2646
    2747  // static lists.
     48  static OrxThread::Mutex         _mutex;            //!< One mutex to lock them all.
    2849  static std::string              _browser;
    2950  static std::list<std::string>   _browserList;
Note: See TracChangeset for help on using the changeset viewer.