Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmUpdate: Implemented code from Xestia Address Book
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sat, 31 Dec 2016 20:55:20 +0000 (20:55 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sat, 31 Dec 2016 20:55:20 +0000 (20:55 +0000)
Implemented frmUpdate using code from Xestia Address Book and adjusted
code to check for Xestia Calendar accordingly.

source/AppXestiaCalendar.cpp
source/AppXestiaCalendar.h
source/forms/main/frmMain.cpp
source/forms/main/frmMain.h
source/forms/update/frmUpdate.cpp
source/forms/update/frmUpdate.h

index bd39f58..360ec6e 100644 (file)
@@ -74,6 +74,7 @@ frmMainADT::frmMainADT( wxWindow* parent, wxWindowID id, const wxString& title,
        // Connect Events
        this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( frmMainADT::QuitApp ) );
        this->Connect( mnuManageExit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmMainADT::QuitApp ) );
+       this->Connect( mnuHelpUpdate->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmMainADT::ShowUpdateWindow ) );
        this->Connect( mnuHelpAbout->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmMainADT::ShowAboutWindow ) );
 }
 
@@ -82,6 +83,7 @@ frmMainADT::~frmMainADT()
        // Disconnect Events
        this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( frmMainADT::QuitApp ) );
        this->Disconnect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmMainADT::QuitApp ) );
+       this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmMainADT::ShowUpdateWindow ) );
        this->Disconnect( wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( frmMainADT::ShowAboutWindow ) );
        
 }
index b4623fe..6329767 100644 (file)
@@ -59,6 +59,7 @@ class frmMainADT : public wxFrame
                // Virtual event handlers, overide them in your derived class
                virtual void QuitApp( wxCloseEvent& event ) { event.Skip(); }
                virtual void QuitApp( wxCommandEvent& event ) { event.Skip(); }
+               virtual void ShowUpdateWindow( wxCommandEvent& event ) { event.Skip(); }
                virtual void ShowAboutWindow( wxCommandEvent& event ) { event.Skip(); }
                
        
index a674367..8f00a1b 100644 (file)
@@ -235,4 +235,15 @@ void frmMain::ShowAboutWindow( wxCommandEvent& event )
        delete frameAbout;
        frameAbout = NULL;
     
+}
+
+void frmMain::ShowUpdateWindow( wxCommandEvent& event )
+{
+
+       frmUpdate *frameUpdate = new frmUpdate ( this );
+       frameUpdate->FetchData();
+       frameUpdate->ShowModal();
+       delete frameUpdate;
+       frameUpdate = NULL;
+       
 }
\ No newline at end of file
index ca8fd1d..5dd5ec3 100644 (file)
@@ -14,6 +14,7 @@ Subclass of frmMainADT, which is generated by wxFormBuilder.
 #include "../../AppXestiaCalendar.h"
 
 #include "../about/frmAbout.h"
+#include "../update/frmUpdate.h"
 
 #include "../../widgets/XCCalendarCtrl.h"
 #include "../../libraries/CalendarDataStorage/CalendarDataStorage.h"
@@ -38,6 +39,7 @@ class frmMain : public frmMainADT
                void QuitApp( wxCloseEvent& event );
                void QuitApp( wxCommandEvent& event );
                void QuitApp();
+               void ShowUpdateWindow( wxCommandEvent& event );
                void ShowAboutWindow( wxCommandEvent& event );
                void LoadAccountData();
 
index bd9a39c..06a1e0f 100644 (file)
@@ -1,5 +1,19 @@
 #include "frmUpdate.h"
 
+size_t WritebackFuncUpdate(char *ptr, size_t size, size_t nmemb, wxString *stream){
+       
+       // Write back function for getting version information.
+       
+       wxString Data;
+       //wxString *PageInput;
+       Data = wxString::FromUTF8((char *)ptr);
+       
+       stream->Append(Data);
+       
+       return size * nmemb;
+
+}
+
 frmUpdate::frmUpdate( wxWindow* parent )
 :
 frmUpdateADT( parent )
@@ -7,17 +21,173 @@ frmUpdateADT( parent )
 
 }
 
+void frmUpdate::FetchData()
+{
+
+       // Connect to the update server and grab the
+       // build type information.
+
+       CURL *conn;
+       conn = curl_easy_init();
+       CURLcode conncode;
+
+       wxString PageData;
+       wxString PageHeader;
+
+       wxString UpdateAddress = wxT("http://update.xestia.co.uk/xestiacalendar/");
+       UpdateAddress.Append(XSDCAL_SOURCE);
+
+       curl_easy_setopt(conn, CURLOPT_URL, (const char*)UpdateAddress.mb_str(wxConvUTF8));
+       curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
+       curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
+       curl_easy_setopt(conn, CURLOPT_TIMEOUT, 3);
+       curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
+       curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDCAL_USERAGENT);
+       curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFuncUpdate);
+       curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
+       curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
+       curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
+       curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1);
+
+       conncode = (curl_easy_perform(conn));
+
+       // Split the data received.
+       
+       PageData.Trim();
+       
+       wxString SupportCode = PageData.Left(1);
+       wxString VersionCode = PageData.Mid(1, wxString::npos);
+       wxString RunningVer = wxString::Format(wxT("%s"), XSDCAL_VERSION);
+       double VersionCodeDouble;
+       double CurrentVerDouble;
+
+       // Setup the running version.
+       
+       lblRunningVer->SetLabel(RunningVer);
+
+       // Setup the build type.
+
+       wxString BuildType = wxT(XSDCAL_SOURCE);
+       lblBuildType->SetLabel(BuildType);
+       
+       if (conncode != CURLE_OK){
+       
+               lblAvailableVer->SetLabel(wxT("Unable to determine."));
+               curl_easy_cleanup(conn);
+               curl_global_cleanup();
+
+               lblUpdateMessage->SetLabel(wxT("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(conncode)));
+
+               return;                 
+       
+       }
+
+       // Cleanup connections.
+
+       curl_easy_cleanup(conn);
+
+       // Setup the avaiable version.
+
+       RunningVer.ToDouble(&CurrentVerDouble);
+
+       if (VersionCode.ToDouble(&VersionCodeDouble)){
+
+               lblAvailableVer->SetLabel(VersionCode);
+
+       } else {
+       
+               lblAvailableVer->SetLabel(wxT("Unable to determine."));
+
+               lblUpdateMessage->SetLabel(wxT("Cannot determine the available version at this time. Please retry in a while."));
+
+               return;
+       
+       }
+       
+       // Set a message.
+       
+       if (BuildType == wxT("source")){
+       
+               // Write message about getting the update
+               // from Xestia Gelforn.
+               
+               if (CurrentVerDouble >= VersionCodeDouble){
+               
+                       lblUpdateMessage->SetLabel(wxT("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)."));
+               
+               } else {
+               
+                       lblUpdateMessage->SetLabel(wxT("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)."));
+       
+               }
+               
+       } else {
+       
+               btnVisitGelforn->Hide();
+       
+               // Display message based on type returned.
+               
+               if (CurrentVerDouble >= VersionCodeDouble){
+               
+                       wxString UpdateMessage = wxT("Xestia Calendar is up to date.\n\n");
+               
+                       if (SupportCode == wxT("U")){
+
+                               UpdateMessage.Append(wxT("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."));
+               
+                       } else if (SupportCode == wxT("X")){
+
+                               UpdateMessage.Append(wxT("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."));
+               
+                       }
+               
+                       lblUpdateMessage->SetLabel(UpdateMessage);
+               
+                       
+               
+               }
+               
+               if (SupportCode == wxT("S")){
+
+                       lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Calendar for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)"));
+               
+               } else if (SupportCode == wxT("U")){
+
+                       lblUpdateMessage->SetLabel(wxT("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."));
+               
+               } else if (SupportCode == wxT("X")){
+
+                       lblUpdateMessage->SetLabel(wxT("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."));
+               
+               }
+       
+       }
+
+}
+
 void frmUpdate::VisitGelforn( wxCommandEvent& event )
 {
-// TODO: Implement VisitGelforn
+       
+       // Launch the Xestia Gelforn website.
+       
+       wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
+       
 }
 
 void frmUpdate::VisitPREMIUM( wxCommandEvent& event )
 {
-// TODO: Implement VisitPREMIUM
+
+       // Launch the Xestia PREMIUM website.
+       
+       wxLaunchDefaultBrowser(wxT("https://premium.xestia.co.uk/"));
+       
 }
 
 void frmUpdate::CloseWindow( wxCommandEvent& event )
 {
-// TODO: Implement CloseWindow
+       
+       // Close this window.
+       
+       this->Close();
+       
 }
index b4371a4..7bc386d 100644 (file)
@@ -6,7 +6,10 @@
 Subclass of frmUpdateADT, which is generated by wxFormBuilder.
 */
 
+#include <curl/curl.h>
+
 #include "../AppXestiaCalendar.h"
+#include "../../version.h"
 
 //// end generated include
 
@@ -21,6 +24,7 @@ class frmUpdate : public frmUpdateADT
        public:
                /** Constructor */
                frmUpdate( wxWindow* parent );
+               void FetchData();
        //// end generated class members
        
 };
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