Ignore:
Timestamp:
09/01/07 20:56:05 (6 years ago)
Author:
guyru
Message:

check for updates support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/OpenYahtzee/src/MainFrame.cpp

    r37 r38  
    4747 
    4848//include the icon file 
    49 #ifdef WIN32 
    50         #include "icon32.xpm" 
    51 #else 
    52         #include "icon.xpm" 
    53 #endif 
     49#include "Icon.h" 
    5450 
    5551//default values 
    5652#define SPACE_SIZE 1 
    5753#define DEF_HIGHSCORESIZE 16 
     54#define OY_VERSION "1.6.0" 
    5855 
    5956MainFrame::MainFrame(const wxString& title, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE) 
     
    6158{ 
    6259        //give the frame an icon 
    63 #ifdef WIN32 
    64         SetIcon(wxIcon(icon32_xpm)); 
    65 #else 
    66         SetIcon(wxIcon(icon_xpm)); 
    67 #endif 
     60        SetIcon(wxIcon(ICON)); 
     61 
    6862 
    6963        std::ostringstream sstr; 
     
    10296         
    10397        //insert menu items into menu Help 
     98        helpMenu->Append(ID_CHECK_FOR_UPDATES, wxT("&Check for Updates"), 
     99                        wxT("Check for new version of the game via the web")); 
    104100        helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"), 
    105101                        wxT("Show about dialog")); 
     
    224220        Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnQuit)); 
    225221        Connect(wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnAbout)); 
     222        Connect(ID_CHECK_FOR_UPDATES, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnCheckForUpdates)); 
    226223        Connect(ID_NEWGAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnNewGame)); 
    227224        Connect(ID_UNDO, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnUndo)); 
     
    256253        wxString msg; 
    257254        wxString sqliteversion = wxString(sqlite3_version,wxConvUTF8); 
    258         msg.Printf(wxT("OpenYahtzee 1.6\nCopyright (C) 2006 by Guy Rutenberg\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.\n\nOpenYahtzee was built against:\nwxWidgets %i.%i\n"),wxMAJOR_VERSION,wxMINOR_VERSION); 
     255        msg.Printf(wxT("OpenYahtzee %s\nCopyright (C) 2006 by Guy Rutenberg\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.\n\nOpenYahtzee was built against:\nwxWidgets %i.%i\n"),wxT(OY_VERSION),wxMAJOR_VERSION,wxMINOR_VERSION); 
    259256        msg += wxT("SQLite ") + sqliteversion; 
    260257                 
    261258        wxMessageBox(msg, wxT("About Yahtzee"), wxOK | wxICON_INFORMATION, this); 
     259} 
     260 
     261void MainFrame::OnCheckForUpdates (wxCommandEvent& event){ 
     262         
     263        wxString path; 
     264        wxPathList path_list; 
     265        wxString link = wxT("http://openyahtzee.sourceforge.net/update.php?version="); 
     266         
     267        link += wxT(OY_VERSION); 
     268 
     269        if (!wxLaunchDefaultBrowser(link)){ 
     270                 //if builtin function doesn't work search for couple of browsers manually. see 
     271                 //http://linux-consulting.buanzo.com.ar/2006/05/wxwidgets-code-to-launch-browser.html 
     272 
     273                // variable declarations 
     274                wxArrayString browsers; 
     275                wxPathList path_list; 
     276                bool BrowserWasFound = false; 
     277                unsigned int i = 0; 
     278                wxString path; 
     279 
     280                // Add directories to wxPathList's search path from PATH environment variable 
     281                path_list.AddEnvList(wxT("PATH")); 
     282                 
     283                // Add browsers filenames. First item = most priority 
     284                browsers.Add(wxT("firefox")); 
     285                browsers.Add(wxT("firefox-bin")); 
     286                browsers.Add(wxT("mozilla")); 
     287                browsers.Add(wxT("mozilla-bin")); 
     288                browsers.Add(wxT("opera")); 
     289                browsers.Add(wxT("konqueror")); 
     290                browsers.Add(wxT("epiphany")); 
     291                 
     292                for (i = 0; i < browsers.GetCount(); i++) { 
     293                        path = path_list.FindAbsoluteValidPath(browsers[i]); 
     294                        if (path.IsEmpty()) { 
     295                                continue; 
     296                        } else { 
     297                                BrowserWasFound = true; 
     298                                break; 
     299                        } 
     300                } 
     301                 
     302                browsers.Clear(); 
     303                 
     304                if (BrowserWasFound) { 
     305                        path += wxT(" "); 
     306                        path += link; 
     307                        ::wxExecute(path); 
     308                } else { 
     309                        wxMessageBox(wxT("No browser has been found."),wxT("OpenYahtzee")); 
     310                } 
     311        } 
     312 
     313 
    262314} 
    263315 
Note: See TracChangeset for help on using the changeset viewer.