From: Steve Brokenshire Date: Wed, 6 Dec 2017 23:26:36 +0000 (+0000) Subject: frmNewAccount: Implemented support for adding a CalDAV account X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=e87900a936df5e226539b82fc141649c4c4f4dc7;p=xestiacalendar%2F.git frmNewAccount: Implemented support for adding a CalDAV account --- diff --git a/source/AppXestiaCalendar.cpp b/source/AppXestiaCalendar.cpp index 914f7db..bafdb01 100644 --- a/source/AppXestiaCalendar.cpp +++ b/source/AppXestiaCalendar.cpp @@ -594,7 +594,7 @@ frmNewAccountADT::frmNewAccountADT( wxWindow* parent, wxWindowID id, const wxStr lblAbleToLoginResult->Wrap( -1 ); fgSizer34->Add( lblAbleToLoginResult, 0, wxALL, 5 ); - lblIsCalDAV = new wxStaticText( tabConn, wxID_ANY, wxT("Server has CardDAV Support:"), wxDefaultPosition, wxDefaultSize, 0 ); + lblIsCalDAV = new wxStaticText( tabConn, wxID_ANY, wxT("Server has CalDAV Support:"), wxDefaultPosition, wxDefaultSize, 0 ); lblIsCalDAV->Wrap( -1 ); fgSizer34->Add( lblIsCalDAV, 0, wxALL, 5 ); diff --git a/source/forms/newaccount/frmNewAccount.cpp b/source/forms/newaccount/frmNewAccount.cpp index fc1ae8a..854dc70 100644 --- a/source/forms/newaccount/frmNewAccount.cpp +++ b/source/forms/newaccount/frmNewAccount.cpp @@ -117,6 +117,7 @@ void frmNewAccount::Navigate( wxCommandEvent& event ) } btnNext->Disable(); + btnNext->SetLabel(_("Next >")); bool ServerResult = FALSE; bool ServerAction = FALSE; @@ -155,12 +156,11 @@ void frmNewAccount::Navigate( wxCommandEvent& event ) tabConn->Hide(); tabFinish->Show(); szrNewAccount->RecalcSizes(); - - btnNext->Disable(); + btnPrevious->Enable(); btnNext->SetLabel(_("Finish")); - if (txtAccountName->IsEmpty() && pageSeek == 2){ + if (txtAccountName->IsEmpty() || txtAccountName->GetValue().Len() < 4 && pageSeek == 3){ btnNext->Disable(); @@ -221,21 +221,30 @@ void frmNewAccount::Navigate( wxCommandEvent& event ) } - if (cmbServerType->GetCurrentSelection() == 1){ + wxString directoryName = txtAccountName->GetValue().Mid(0, 30) + randomNumberSuffix; + + if (cmbServerType->GetCurrentSelection() == 0){ // Create the account directory. - wxString directoryName = txtAccountName->GetValue().Mid(0, 30) + randomNumberSuffix; - - if (wxMkdir(xestiaCALDirectory + wxT("\\accounts\\") + directoryName + wxT(".local"), 0740) == TRUE){ + if (wxMkdir(xestiaCALDirectory + wxT("\\accounts\\") + directoryName + wxT(".local"), 0740) == true){ - directoryCreated = TRUE; + WriteAccountDetails(cfgFile, wxT("Local"), directoryName); + + } else { + + wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory")); + return; } - if (directoryCreated == TRUE){ + } else if (cmbServerType->GetCurrentSelection() == 1){ + + // Create the account directory. + + if (wxMkdir(xestiaCALDirectory + wxT("\\accounts\\") + directoryName + wxT(".caldav"), 0740) == true){ - WriteAccountDetails(cfgFile, wxT("Local"), directoryName); + WriteAccountDetails(cfgFile, wxT("CalDAV"), directoryName); } else { @@ -243,7 +252,7 @@ void frmNewAccount::Navigate( wxCommandEvent& event ) return; } - + } delete cfgFile; @@ -283,23 +292,34 @@ void frmNewAccount::Navigate( wxCommandEvent& event ) continueAcc = cfgFile->GetNextGroup(accountName, itemIndex); } + + wxString directoryName = txtAccountName->GetValue().Mid(0, 30) + randomNumberSuffix; - if (cmbServerType->GetCurrentSelection() == 1){ + if (cmbServerType->GetCurrentSelection() == 0){ // Create the account directory. - wxString directoryName = txtAccountName->GetValue().Mid(0, 30) + randomNumberSuffix; - - if (wxMkdir(xestiaCALDirectory + wxT("/accounts/") + directoryName + wxT(".Local"), 0740) == TRUE){ + if (wxMkdir(xestiaCALDirectory + wxT("/accounts/") + directoryName + wxT(".Local"), 0740) == true){ - directoryCreated = TRUE; + WriteAccountDetails(cfgFile, wxT("Local"), directoryName); + + } else { + + wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory")); + return; } - if (directoryCreated == TRUE){ - - WriteAccountDetails(cfgFile, wxT("Local"), directoryName); + } else if (cmbServerType->GetCurrentSelection() == 1){ + + // Create the account directory. + + wxString directoryName = txtAccountName->GetValue().Mid(0, 30) + randomNumberSuffix; + + if (wxMkdir(xestiaCALDirectory + wxT("/accounts/") + directoryName + wxT(".caldav"), 0740) == true){ + WriteAccountDetails(cfgFile, wxT("CalDAV"), directoryName); + } else { wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory")); @@ -310,7 +330,7 @@ void frmNewAccount::Navigate( wxCommandEvent& event ) } delete cfgFile; - cfgFile = NULL; + cfgFile = nullptr; *reloadAccountConfig = true; @@ -388,7 +408,56 @@ void frmNewAccount::WriteAccountDetails(wxFileConfig *cfgFileIn, wxString accoun void frmNewAccount::UpdateResults( wxCommandEvent &event ) { + NewAccountResult *resultData = static_cast(event.GetClientData()); + + lblServerConnResult->SetLabel((resultData->Connected ? _("Successful") : _("Failed"))); + lblServerResponse->SetLabel((resultData->ValidResponse ? _("Yes") : _("No"))); + if (chkUseSSL->GetValue()) + { + lblServerSSLResult->SetLabel((resultData->SSLStatus ? _("Yes") : _("No"))); + lblServerSSLValid->SetLabel((resultData->SSLVerified == COSSL_VERIFIED ? _("Yes") : _("No"))); + } else { + lblServerSSLResult->SetLabel(_("Not Applicable")); + lblServerSSLValid->SetLabel(_("Not Applicable")); + } + lblAbleToLoginResult->SetLabel((resultData->AuthPassed ? _("Yes") : _("No"))); + lblCalDAVSupportResult->SetLabel((resultData->CanProcess ? _("Yes") : _("No"))); + + if (resultData->ErrorMessage != "") + { + lblConnectionResultText->SetLabel(_("An error occured whilst connecting to the server: ") + resultData->ErrorMessage); + } + + if (VerifyResultData(resultData)) + { + lblConnectionResultText->SetLabel(_("Successfully connected to the server. Press Next to set the account name.")); + btnNext->Enable(true); + } + else + { + btnNext->Enable(false); + } + tabConn->Layout(); + btnPrevious->Enable(true); + + delete resultData; + resultData = nullptr; +} + +bool frmNewAccount::VerifyResultData(NewAccountResult *resultData) +{ + if (!resultData->Connected) return false; + if (!resultData->ValidResponse) return false; + if (chkUseSSL->GetValue()) + { + if (!resultData->SSLStatus) return false; + if (resultData->SSLVerified != COSSL_VERIFIED) return false; + } + if (!resultData->AuthPassed) return false; + if (!resultData->CanProcess) return false; + + return true; } void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) @@ -401,6 +470,7 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) lblServerSSLResult->SetLabel(wxT("")); lblServerSSLValid->SetLabel(wxT("")); lblAbleToLoginResult->SetLabel(wxT("")); + lblConnectionResultText->SetLabel(wxT("")); bool usingSSLBypass = false; // Setup a CalDAV connection object for testing. @@ -424,7 +494,7 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) // Test the connection. //testConnection.SetupConnectionObject(); - CalDAVServerResult testConnectionResult = testConnection.Connect(); + CalDAVServerResult testConnectionResult = testConnection.Connect(false); // If server is using SSL, verify that the SSL connection is valid. @@ -509,7 +579,7 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) testConnection.BypassSSLVerification(true); - CalDAVServerResult testConnectionResult = testConnection.Connect(); + CalDAVServerResult testConnectionResult = testConnection.Connect(false); testConnection.BypassSSLVerification(false); @@ -524,7 +594,7 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) // Clean up before processing response. delete frmICPtr; - frmICPtr = NULL; + frmICPtr = nullptr; // Process the response from the user. @@ -535,7 +605,7 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) usingSSLBypass = true; testConnection.BypassSSLVerification(true); - CalDAVServerResult testConnectionResult = testConnection.Connect(); + CalDAVServerResult testConnectionResult = testConnection.Connect(true); testConnection.BypassSSLVerification(false); @@ -546,40 +616,57 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) // TODO: Integrate into the code. //lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str())); + + resultData->Connected = true; + resultData->SSLStatus = true; + resultData->SSLVerified = COSSL_UNABLETOVERIFY; + resultData->ValidResponse = false; + resultData->AuthPassed = false; + resultData->CanProcess = false; + resultData->ErrorMessage = _("Server is using self-signed certificate and was rejected."); + + wxCommandEvent resultsEvent(UPDATERESULTS); + resultsEvent.SetClientData(resultData); + wxPostEvent(this, resultsEvent); + + return; } #endif } - testConnectionResult = testConnection.Connect(); + if (usingSSLBypass == true){ + testConnection.BypassSSLVerification(true); + } + + testConnectionResult = testConnection.Connect(true); // Get the server prefix if the connection was successful. if (testConnectionResult.result == CALDAVQUERYRESULT_OK){ - - if (usingSSLBypass == true){ - testConnection.BypassSSLVerification(true); - } std::string receivedServerPrefix; receivedServerPrefix = testConnection.GetUserPrincipal(); serverPrefix = receivedServerPrefix; - if (usingSSLBypass == true){ - testConnection.BypassSSLVerification(true); - } - } - testConnectionResult.result == CALDAVQUERYRESULT_OK ? resultData->Connected = true : resultData->Connected = false; + CalDAVServerSupport testConnectionSupport = testConnection.GetServerSupport(); + + if (usingSSLBypass == true){ + testConnection.BypassSSLVerification(false); + } + + (testConnectionResult.result == CALDAVQUERYRESULT_OK || testConnectionResult.result == CALDAVQUERYRESULT_SSLFAILURE) ? + resultData->Connected = true : resultData->Connected = false; resultData->SSLStatus = testConnection.CanDoSSL(); resultData->SSLVerified = testConnection.SSLVerify(); resultData->ValidResponse = testConnection.HasValidResponse(); resultData->AuthPassed = testConnection.AbleToLogin(); - resultData->CanProcess = testConnection.CanDoProcessing(); + resultData->CanProcess = testConnectionSupport.basicSupport; resultData->ErrorMessage = testConnection.GetErrorMessage(); // Post event back confirming the tests. diff --git a/source/forms/newaccount/frmNewAccount.h b/source/forms/newaccount/frmNewAccount.h index f799979..8e01256 100644 --- a/source/forms/newaccount/frmNewAccount.h +++ b/source/forms/newaccount/frmNewAccount.h @@ -61,6 +61,7 @@ class frmNewAccount : public frmNewAccountADT bool CanProcess = false; std::string ErrorMessage = ""; }; + bool VerifyResultData(NewAccountResult *resultData); protected: // Handlers for frmNewAccountADT events. void UpdateRequirements( wxCommandEvent &event );