| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (C) 2006-2007 by Guy Rutenberg * |
|---|
| 3 | * guyrutenberg@gmail.com * |
|---|
| 4 | * * |
|---|
| 5 | * This program is free software; you can redistribute it and/or modify * |
|---|
| 6 | * it under the terms of the GNU General Public License as published by * |
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
|---|
| 8 | * (at your option) any later version. * |
|---|
| 9 | * * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, * |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|---|
| 13 | * GNU General Public License for more details. * |
|---|
| 14 | * * |
|---|
| 15 | * You should have received a copy of the GNU General Public License * |
|---|
| 16 | * along with this program; if not, write to the * |
|---|
| 17 | * Free Software Foundation, Inc., * |
|---|
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|---|
| 19 | ***************************************************************************/ |
|---|
| 20 | |
|---|
| 21 | /**\file UtilityFunctions.cpp |
|---|
| 22 | *\brief General purpuse functions. |
|---|
| 23 | * |
|---|
| 24 | * This file contains the implementation for some general |
|---|
| 25 | * purpuse utility functions. |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | #include "UtilityFunctions.h" |
|---|
| 29 | #include <sstream> |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * This function launches the default browser and directs it to a given url. |
|---|
| 36 | * |
|---|
| 37 | * This function extends the wxWidgets default function for this job by checking manually for |
|---|
| 38 | * different browsers if the wxWidgets' function doesn't find one. This is usually necessary |
|---|
| 39 | * under linux when epiphany isn't installed for some unknown reason. |
|---|
| 40 | * @param link The url that the browser will go to when it stats. |
|---|
| 41 | */ |
|---|
| 42 | void LaunchBrowser (wxString link) |
|---|
| 43 | { |
|---|
| 44 | if (!wxLaunchDefaultBrowser(link)){ |
|---|
| 45 | //if builtin function doesn't work search for couple of browsers manually. see |
|---|
| 46 | //http://linux-consulting.buanzo.com.ar/2006/05/wxwidgets-code-to-launch-browser.html |
|---|
| 47 | |
|---|
| 48 | // variable declarations |
|---|
| 49 | wxArrayString browsers; |
|---|
| 50 | wxPathList path_list; |
|---|
| 51 | bool BrowserWasFound = false; |
|---|
| 52 | unsigned int i = 0; |
|---|
| 53 | wxString path; |
|---|
| 54 | |
|---|
| 55 | // Add directories to wxPathList's search path from PATH environment variable |
|---|
| 56 | path_list.AddEnvList(wxT("PATH")); |
|---|
| 57 | |
|---|
| 58 | // Add browsers filenames. First item = most priority |
|---|
| 59 | browsers.Add(wxT("firefox")); |
|---|
| 60 | browsers.Add(wxT("firefox-bin")); |
|---|
| 61 | browsers.Add(wxT("mozilla")); |
|---|
| 62 | browsers.Add(wxT("mozilla-bin")); |
|---|
| 63 | browsers.Add(wxT("opera")); |
|---|
| 64 | browsers.Add(wxT("konqueror")); |
|---|
| 65 | browsers.Add(wxT("epiphany")); |
|---|
| 66 | |
|---|
| 67 | for (i = 0; i < browsers.GetCount(); i++) { |
|---|
| 68 | path = path_list.FindAbsoluteValidPath(browsers[i]); |
|---|
| 69 | if (path.IsEmpty()) { |
|---|
| 70 | continue; |
|---|
| 71 | } else { |
|---|
| 72 | BrowserWasFound = true; |
|---|
| 73 | break; |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | browsers.Clear(); |
|---|
| 78 | |
|---|
| 79 | if (BrowserWasFound) { |
|---|
| 80 | path += wxT(" "); |
|---|
| 81 | path += link; |
|---|
| 82 | ::wxExecute(path); |
|---|
| 83 | } else { |
|---|
| 84 | wxMessageBox(wxT("No browser has been found."), |
|---|
| 85 | wxT("Open Yahtzee")); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | } |
|---|