+ } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE) {
+
+ lblServerSSLValid->SetLabel(_("Unable to verify"));
+
+ }
+
+ if (CardDAVConn.CanDoCardDAV() == TRUE){
+
+ lblCardDAVSupportResult->SetLabel(_("Supported"));
+
+ } else {
+
+ lblCardDAVSupportResult->SetLabel(_("Unsupported"));
+
+ }
+
+ if (CardDAVConn.AbleToLogin() == TRUE){
+
+ lblAbleToLoginResult->SetLabel(_("Yes"));
+
+ } else {
+
+ lblAbleToLoginResult->SetLabel(_("No"));
+
+ }
+
+ // Get the address to process CardDAV requests.
+
+ ServerPrefix = CardDAVConn.GetDefaultAddressBookURL();
+
+ if (CardDAVConn.HasValidResponse() == TRUE){
+
+ lblServerResponse->SetLabel(_("Yes"));
+
+ } else {
+
+ lblServerResponse->SetLabel(_("No"));
+
+ }
+
+ if (ServerResult == TRUE && CardDAVConn.HasValidResponse() == TRUE &&
+ //CardDAVConn.CanDoSSL() == TRUE && CardDAVConn.SSLVerify() == TRUE &&
+ CardDAVConn.CanDoCardDAV() == TRUE && CardDAVConn.AbleToLogin() == TRUE){
+
+ btnNext->Enable();
+
+ lblConnectionResultText->SetLabel(_("Click on Next to set the account name."));
+
+ } else {
+
+ lblConnectionResultText->SetLabel(_("A problem has occured whilst connecting to the CardDAV server.\nPlease review the above information and change the server details if needed.\nIf there are still problems, please speak to your system administrator(s)."));
+
+ }
+
+ } else if (PageSeek == 2){
+
+ // Finish screen.
+
+ tabType->Hide();
+ tabConn->Hide();
+ tabFinish->Show();
+ szrNewAccount->RecalcSizes();
+
+ btnNext->Disable();
+ btnNext->SetLabel(_("Finish"));
+ if (txtAccountName->IsEmpty() && PageSeek == 2){
+ btnNext->Disable();
+ } else {
+ btnNext->Enable();
+ }
+
+ } else if (PageSeek == 3){
+
+ // Finished.
+
+ wxString XestiaABPrefDirectory;
+ wxString XestiaABDirectory;
+ wxString AccountSettingsFile;
+ //wxFile ASFile;
+ wxString RandomNumberSuffix = wxString::Format(wxT("%i"), rand() % 32767);
+ bool DirectoryCreated = FALSE;
+
+#if defined(__HAIKU__)
+
+ //preffilename = wxT("noo");
+
+#elif defined(__WIN32__)
+
+ XestiaABPrefDirectory = GetUserPrefDir();
+ XestiaABDirectory = GetUserDir();
+
+ AccountSettingsFile = XestiaABPrefDirectory + wxT("accounts");
+
+ // Open the file for writing.
+
+ wxFileConfig *cfgfile = new wxFileConfig("", "", AccountSettingsFile);
+
+ // Check if account name already exists and return an error message
+ // if this is the case.
+
+ wxString AccountName;
+ long itemindex = 0;
+ bool ContinueAcc;
+ ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
+
+ while (ContinueAcc){
+
+ if (txtAccountName->GetValue() == AccountName){
+
+ wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR);
+ return;
+
+ }
+
+ cfgfile->SetPath(wxT("/"));
+ ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
+
+ }
+
+ if (cmbServerType->GetCurrentSelection() == 1){
+
+ // Create the account directory.
+
+ wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
+
+ if (wxMkdir(XestiaABDirectory + wxT("\\accounts\\") + DirectoryName + wxT(".carddav"), 0740) == TRUE){
+
+ DirectoryCreated = TRUE;
+
+ }
+
+ if (DirectoryCreated == TRUE){
+
+ WriteAccountDetails(cfgfile, wxT("CardDAV"), DirectoryName);
+
+ } else {
+
+ wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
+ return;
+
+ }
+
+ } else if (cmbServerType->GetCurrentSelection() == 0){
+
+ // Create the account directory.
+
+ wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
+
+ if (wxMkdir(XestiaABDirectory + wxT("\\accounts\\") + DirectoryName + wxT(".local"), 0740) == TRUE){
+
+ DirectoryCreated = TRUE;
+
+ }
+
+ if (DirectoryCreated == TRUE){
+
+ WriteAccountDetails(cfgfile, wxT("Local"), DirectoryName);
+
+ } else {
+
+ wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
+ return;
+
+ }
+
+ }
+
+ delete cfgfile;
+ cfgfile = NULL;
+
+ ReloadAccountConfig = TRUE;
+
+#else
+
+ XestiaABPrefDirectory = GetUserPrefDir();
+ XestiaABDirectory = GetUserDir();
+
+ AccountSettingsFile = XestiaABPrefDirectory + wxT("accounts");
+
+ // Open the file for writing.
+
+ wxFileConfig *cfgfile = new wxFileConfig("", "", AccountSettingsFile);
+
+ // Check if account name already exists and return an error message
+ // if this is the case.
+
+ wxString AccountName;
+ long itemindex = 0;
+ bool ContinueAcc;
+ ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
+
+ while (ContinueAcc){
+
+ if (txtAccountName->GetValue() == AccountName){
+
+ wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR);
+ return;
+
+ }
+
+ cfgfile->SetPath(wxT("/"));
+ ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
+
+ }
+
+ if (cmbServerType->GetCurrentSelection() == 1){
+
+ // Create the account directory.
+
+ wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
+
+ if (wxMkdir(XestiaABDirectory + wxT("/accounts/") + DirectoryName + wxT(".carddav"), 0740) == TRUE){
+
+ DirectoryCreated = TRUE;
+
+ }
+
+ if (DirectoryCreated == TRUE){
+
+ WriteAccountDetails(cfgfile, wxT("CardDAV"), DirectoryName);
+
+ } else {
+
+ wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
+ return;
+
+ }
+
+ } else if (cmbServerType->GetCurrentSelection() == 0){
+
+ // Create the account directory.
+
+ wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
+
+ if (wxMkdir(XestiaABDirectory + wxT("/accounts/") + DirectoryName + wxT(".local"), 0740) == TRUE){
+
+ DirectoryCreated = TRUE;
+
+ }
+
+ if (DirectoryCreated == TRUE){
+
+ WriteAccountDetails(cfgfile, wxT("Local"), DirectoryName);
+
+ } else {
+
+ wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
+ return;
+
+ }
+
+ }
+
+ delete cfgfile;
+ cfgfile = NULL;
+
+ ReloadAccountConfig = TRUE;
+
+#endif
+
+ this->Close();
+
+ }
+
+}