Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
camelCase: Converted code in forms directories
[xestiacalendar/.git] / source / forms / update / frmUpdate.cpp
1 // frmUpdate.cpp - frmUpdate form functions
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Calendar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Calendar is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "frmUpdate.h"
21 size_t WritebackFuncUpdate(char *ptr, size_t size, size_t nmemb, wxString *stream){
22         
23         // Write back function for getting version information.
24         
25         wxString data;
26         //wxString *PageInput;
27         data = wxString::FromUTF8((char *)ptr);
28         
29         stream->Append(Data);
30         
31         return size * nmemb;
33 }
35 frmUpdate::frmUpdate( wxWindow* parent )
36 :
37 frmUpdateADT( parent )
38 {
40 }
42 void frmUpdate::FetchData()
43 {
45         // Connect to the update server and grab the
46         // build type information.
48         CURL *conn;
49         conn = curl_easy_init();
50         CURLcode connCode;
52         wxString pageData;
53         wxString pageHeader;
55         wxString updateAddress = wxT("http://update.xestia.co.uk/xestiacalendar/");
56         updateAddress.Append(XSDCAL_SOURCE);
58         curl_easy_setopt(conn, CURLOPT_URL, (const char*)updateAddress.mb_str(wxConvUTF8));
59         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
60         curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
61         curl_easy_setopt(conn, CURLOPT_TIMEOUT, 3);
62         curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
63         curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDCAL_USERAGENT);
64         curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFuncUpdate);
65         curl_easy_setopt(conn, CURLOPT_WRITEDATA, &pageData);
66         curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &pageHeader);
67         curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
68         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1);
70         connCode = (curl_easy_perform(conn));
72         // Split the data received.
73         
74         pageData.Trim();
75         
76         wxString supportCode = pageData.Left(1);
77         wxString versionCode = pageData.Mid(1, wxString::npos);
78         wxString runningVer = wxString::Format(wxT("%s"), XSDCAL_VERSION);
79         
80         double availableVersion;
81         double currentVersion;
83         // Setup the running version.
84         
85         lblRunningVer->SetLabel(runningVer);
87         // Setup the build type.
89         wxString buildType = wxT(XSDCAL_SOURCE);
90         lblBuildType->SetLabel(buildType);
91         
92         if (connCode != CURLE_OK){
93         
94                 lblAvailableVer->SetLabel(_("Unable to determine."));
95                 curl_easy_cleanup(conn);
96                 curl_global_cleanup();
98                 lblUpdateMessage->SetLabel(_("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(connCode)));
100                 return;                 
101         
102         }
104         // Cleanup connections.
106         curl_easy_cleanup(conn);
108         // Setup the avaiable version.
110         runningVer.ToDouble(&currentVersion);
112         if (versionCode.ToDouble(&availableVersion)){
114                 lblAvailableVer->SetLabel(versionCode);
116         } else {
117         
118                 lblAvailableVer->SetLabel(_("Unable to determine."));
120                 lblUpdateMessage->SetLabel(_("Cannot determine the available version at this time. Please retry in a while."));
122                 return;
123         
124         }
125         
126         // Set a message.
127         
128         if (BuildType == wxT("source")){
129         
130                 // Write message about getting the update
131                 // from Xestia Gelforn.
132                 
133                 if (currentVersion >= availableVersion){
134                 
135                         lblUpdateMessage->SetLabel(_("Xestia Calendar is up to date.\n\nFor a small yearly cost, prebuilt packages and support is available from Xestia PREMIUM (https://premium.xestia.co.uk)."));
136                 
137                 } else {
138                 
139                         lblUpdateMessage->SetLabel(_("An updated version of Xestia Calendar is available from Xestia Gelforn (https://gelforn.xestia.co.uk/).\n\nFor a small yearly cost, prebuilt packages and support is available from Xestia PREMIUM (https://premium.xestia.co.uk)."));
140         
141                 }
142                 
143         } else {
144         
145                 btnVisitGelforn->Hide();
146         
147                 // Display message based on type returned.
148                 
149                 if (currentVersion >= availableVersion){
150                 
151                         wxString updateMessage = _("Xestia Calendar is up to date.\n\n");
152                 
153                         if (supportCode == wxT("U")){
155                                 updateMessage.Append(_("An updated version of Xestia Calendar is available from Xestia PREMIUM (https://premium.xestia.co.uk) but will require your operating system to be updated."));
156                 
157                         } else if (supportCode == wxT("X")){
159                                 updateMessage.Append(_("Xestia Calendar is no longer supported on the operating system you are using. Please visit the Xestia PREMIUM website (https://premium.xestia.co.uk) for a list of supported operating systems."));
160                 
161                         }
162                 
163                         lblUpdateMessage->SetLabel(updateMessage);
164                 
165                         
166                 
167                 }
168                 
169                 if (supportCode == wxT("S")){
171                         lblUpdateMessage->SetLabel(_("An updated version of Xestia Calendar for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)"));
172                 
173                 } else if (supportCode == wxT("U")){
175                         lblUpdateMessage->SetLabel(_("An updated version of Xestia Calendar is available from Xestia PREMIUM (https://premium.xestia.co.uk) but will require your operating system to be updated."));
176                 
177                 } else if (supportCode == wxT("X")){
179                         lblUpdateMessage->SetLabel(_("Xestia Calendar is no longer supported on the operating system you are using. Please visit the Xestia PREMIUM website (https://premium.xestia.co.uk) for a list of supported operating systems."));
180                 
181                 }
182         
183         }
187 void frmUpdate::VisitGelforn( wxCommandEvent& event )
189         
190         // Launch the Xestia Gelforn website.
191         
192         wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
193         
196 void frmUpdate::VisitPREMIUM( wxCommandEvent& event )
199         // Launch the Xestia PREMIUM website.
200         
201         wxLaunchDefaultBrowser(wxT("https://premium.xestia.co.uk/"));
202         
205 void frmUpdate::CloseWindow( wxCommandEvent& event )
207         
208         // Close this window.
209         
210         this->Close();
211         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy