Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code so that OSX is now supported.
[xestiaab/.git] / source / frmNewAccount.cpp
index 30c6fa2..1681134 100644 (file)
@@ -11,480 +11,485 @@ frmNewAccount::frmNewAccount( wxWindow* parent )
 :
 frmNewAccountADT( parent )
 {
-       btnPrevious->Disable();
+    btnPrevious->Disable();
 }
 
 void frmNewAccount::CheckAccountName( wxCommandEvent& event )
 {
-
-       wxString CheckAccName = txtAccountName->GetValue();
-
-       if (txtAccountName->IsEmpty() && PageSeek == 2 || CheckAccName.Len() < 4){
-       
-               btnNext->Disable();
-       
-       } else {
-       
-               btnNext->Enable();
-       
-       }
-       
+    
+    wxString CheckAccName = txtAccountName->GetValue();
+    
+    if ((txtAccountName->IsEmpty() && PageSeek == 2) || CheckAccName.Len() < 4){
+        
+        btnNext->Disable();
+        
+    } else {
+        
+        btnNext->Enable();
+        
+    }
+    
 }
 
 void frmNewAccount::ProcessPrevious( wxCommandEvent& event )
 {
-       PageSeek--;
-       
-       if (PageSeek == 0){
-       
-               // Currently at the Connection test screen.
-               
-               //tbkAccount->ChangeSelection(0);
-               tabConn->Hide();
-               tabFinish->Hide();
-               tabType->Show();
-               szrNewAccount->RecalcSizes();
-               
-               btnPrevious->Disable();
-               btnNext->Enable();
-       
-       } else if (PageSeek == 1){
-       
-               if (cmbServerType->GetCurrentSelection() == 0){
-               
-                       tabConn->Hide();
-                       tabFinish->Hide();
-                       tabType->Show();
-                       PageSeek = 0;
-                       btnPrevious->Disable();
-                       btnNext->Enable();
-                       btnNext->SetLabel(_("Next >"));                 
-                       return;
-               
-               }
-       
-               // Currently at the Finish screen.
-               
-               tabType->Hide();
-               tabConn->Show();
-               tabFinish->Hide();
-               szrNewAccount->RecalcSizes();
-               
-               btnNext->SetLabel(_("Next >"));
-               btnNext->Enable();
-       
-       }       
-       
+    PageSeek--;
+    
+    if (PageSeek == 0){
+        
+        // Currently at the Connection test screen.
+        
+        //tbkAccount->ChangeSelection(0);
+        tabConn->Hide();
+        tabFinish->Hide();
+        tabType->Show();
+        szrNewAccount->RecalcSizes();
+        
+        btnPrevious->Disable();
+        btnNext->Enable();
+        
+    } else if (PageSeek == 1){
+        
+        if (cmbServerType->GetCurrentSelection() == 0){
+            
+            tabConn->Hide();
+            tabFinish->Hide();
+            tabType->Show();
+            PageSeek = 0;
+            btnPrevious->Disable();
+            btnNext->Enable();
+            btnNext->SetLabel(_("Next >"));
+            return;
+            
+        }
+        
+        // Currently at the Finish screen.
+        
+        tabType->Hide();
+        tabConn->Show();
+        tabFinish->Hide();
+        szrNewAccount->RecalcSizes();
+        
+        btnNext->SetLabel(_("Next >"));
+        btnNext->Enable();
+        
+    }
+    
 }
 
 void frmNewAccount::ProcessNext( wxCommandEvent& event )
 {
-       PageSeek++;
-       
-       if (PageSeek == 1){
-       
-               if (cmbServerType->GetCurrentSelection() == 0){
-               
-                       tabType->Hide();
-                       tabConn->Hide();
-                       tabFinish->Show();
-                       PageSeek = 2;
-                       btnPrevious->Enable();
-                       szrNewAccount->RecalcSizes();
-                       btnNext->Disable();
-                       btnNext->SetLabel(_("Finish"));
-                       return;
-               
-               }
-       
-               btnNext->Disable();
-       
-               bool ServerResult = FALSE;
-               bool ServerAction = FALSE;
-               bool UseSSL = TRUE;
-               wxString ServerMessage;
-       
-               // Connection test screen.
-               
-               tabType->Hide();
-               tabConn->Show();
-               tabFinish->Hide();
-               szrNewAccount->RecalcSizes();
-               btnPrevious->Enable();
-               
-               // Reset screen.
-
-               lblServerConnResult->SetLabel(wxT(""));
-               lblServerResponse->SetLabel(wxT(""));
-               lblServerSSLResult->SetLabel(wxT(""));
-               lblServerSSLValid->SetLabel(wxT(""));
-               lblAbleToLoginResult->SetLabel(wxT(""));
-               lblCardDAVSupportResult->SetLabel(wxT(""));
-
-               // Spawn a thread and check if server supports CardDAV.
-               
-               CardDAV CardDAVConn;
-               
-               lblServerConnResult->SetLabel(_("Testing..."));
-               
-               UseSSL = chkUseSSL->GetValue();
-               
-               CardDAVConn.SetupConnection(txtServerAddress->GetValue(), 
-                       wxAtoi(txtServerPort->GetValue()), 
-                       txtUsername->GetValue(), 
-                       txtPassword->GetValue(),
-                       UseSSL);
-               CardDAVConn.SetupResultBools(&ServerResult, &ServerAction);
-               
-               std::thread ConnTest(&CardDAV::Connect, &CardDAVConn);
-               
-               ConnTest.join();
-               
-               if (ServerResult == FALSE){
-               
-                       lblServerConnResult->SetLabel(_("Failed"));
-                       wxMessageBox(CardDAVConn.GetErrorMessage());
-                       return;
-               
-               } else {
-               
-                       lblServerConnResult->SetLabel(_("Connected"));
-               
-               }
-               
-               if (CardDAVConn.HasValidResponse() == TRUE){
-               
-                       lblServerResponse->SetLabel(_("Yes"));
-               
-               } else {
-               
-                       lblServerResponse->SetLabel(_("No"));
-               
-               }               
-               
-               if (CardDAVConn.CanDoSSL() == TRUE){
-               
-                       lblCardDAVSupportResult->SetLabel(_("Used"));
-               
-               } else {
-               
-                       lblServerSSLResult->SetLabel(_("Not Used"));
-                       lblServerSSLValid->SetLabel(_("Not Applicable"));
-               
-               }               
-               
-               if (CardDAVConn.SSLVerify() == TRUE && CardDAVConn.CanDoSSL() == TRUE){
-
-                       lblCardDAVSupportResult->SetLabel(_("Verified"));
-               
-               } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE) {
-               
-                       lblServerSSLResult->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();
-               
-               wxMessageBox(ServerPrefix);
-
-               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 AccountSettingsFile;
-               //wxFile ASFile;
-               wxString RandomNumberSuffix = wxString::Format(wxT("%i"), rand() % 32767);
-               bool DirectoryCreated = FALSE;
-
-#if defined(__HAIKU__)
+    PageSeek++;
     
-               //preffilename = wxT("noo");
-
+    if (PageSeek == 1){
+        
+        if (cmbServerType->GetCurrentSelection() == 0){
+            
+            tabType->Hide();
+            tabConn->Hide();
+            tabFinish->Show();
+            PageSeek = 2;
+            btnPrevious->Enable();
+            szrNewAccount->RecalcSizes();
+            btnNext->Disable();
+            btnNext->SetLabel(_("Finish"));
+            return;
+            
+        }
+        
+        btnNext->Disable();
+        
+        bool ServerResult = FALSE;
+        bool ServerAction = FALSE;
+        bool UseSSL = TRUE;
+        wxString ServerMessage;
+        
+        // Connection test screen.
+        
+        tabType->Hide();
+        tabConn->Show();
+        tabFinish->Hide();
+        szrNewAccount->RecalcSizes();
+        btnPrevious->Enable();
+        
+        // Reset screen.
+        
+        lblServerConnResult->SetLabel(wxT(""));
+        lblServerResponse->SetLabel(wxT(""));
+        lblServerSSLResult->SetLabel(wxT(""));
+        lblServerSSLValid->SetLabel(wxT(""));
+        lblAbleToLoginResult->SetLabel(wxT(""));
+        lblCardDAVSupportResult->SetLabel(wxT(""));
+        
+        // Spawn a thread and check if server supports CardDAV.
+        
+        CardDAV CardDAVConn;
+        
+        lblServerConnResult->SetLabel(_("Testing..."));
+        
+        UseSSL = chkUseSSL->GetValue();
+        
+        CardDAVConn.SetupConnection(txtServerAddress->GetValue(),
+                                    wxAtoi(txtServerPort->GetValue()),
+                                    txtUsername->GetValue(),
+                                    txtPassword->GetValue(),
+                                    UseSSL);
+        CardDAVConn.SetupResultBools(&ServerResult, &ServerAction);
+        
+        std::thread ConnTest(&CardDAV::Connect, &CardDAVConn);
+        
+        ConnTest.join();
+        
+        if (ServerResult == FALSE){
+            
+            lblServerConnResult->SetLabel(_("Failed"));
+            wxMessageBox(CardDAVConn.GetErrorMessage());
+            return;
+            
+        } else {
+            
+            lblServerConnResult->SetLabel(_("Connected"));
+            
+        }
+        
+        if (CardDAVConn.HasValidResponse() == TRUE){
+            
+            lblServerResponse->SetLabel(_("Yes"));
+            
+        } else {
+            
+            lblServerResponse->SetLabel(_("No"));
+            
+        }
+        
+        if (CardDAVConn.CanDoSSL() == TRUE){
+            
+            lblCardDAVSupportResult->SetLabel(_("Used"));
+            
+        } else {
+            
+            lblServerSSLResult->SetLabel(_("Not Used"));
+            lblServerSSLValid->SetLabel(_("Not Applicable"));
+            
+        }
+        
+        if (CardDAVConn.SSLVerify() == TRUE && CardDAVConn.CanDoSSL() == TRUE){
+            
+            lblCardDAVSupportResult->SetLabel(_("Verified"));
+            
+        } else if (CardDAVConn.SSLVerify() == FALSE && CardDAVConn.CanDoSSL() == TRUE) {
+            
+            lblServerSSLResult->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();
+        
+        wxMessageBox(ServerPrefix);
+        
+        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 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();
-
-               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);
-
-               }
-
-               cfgfile->SetPath(txtAccountName->GetValue());
-               cfgfile->Write(wxT("address"), txtServerAddress->GetValue());
-               cfgfile->Write(wxT("port"), txtServerPort->GetValue());
-               cfgfile->Write(wxT("username"), txtUsername->GetValue());
-               cfgfile->Write(wxT("password"), txtPassword->GetValue());
-               cfgfile->Write(wxT("prefix"), ServerPrefix);
-
-               if (chkUseSSL->GetValue() == TRUE){
-
-                       cfgfile->Write(wxT("ssl"), wxT("true"));
-
-               } else {
-
-                       cfgfile->Write(wxT("ssl"), wxT("false"));
-
-               }
-
-               cfgfile->Write(wxT("refresh"), wxT("1800"));
-
-               if (cmbServerType->GetCurrentSelection() == 1){
-
-                       cfgfile->Write(wxT("type"), wxT("CardDAV"));
-
-                       while(DirectoryCreated == FALSE){
-
-                               wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
-                               wxString XestiaABUserDirectory = GetUserDir();
-
-                               if (wxMkdir(XestiaABUserDirectory + wxT("\\accounts\\") + DirectoryName + wxT(".carddav"), 0740) == TRUE){
-
-                                       DirectoryCreated = TRUE;
-                                       cfgfile->Write(wxT("accountdir"), DirectoryName);
-
-                               } else {
-
-
-
-                               }
-
-                       }
-
-               } else if (cmbServerType->GetCurrentSelection() == 0){
-
-                       // Create the account directory.
-
-                       cfgfile->Write(wxT("type"), wxT("Local"));
-
-                       while(DirectoryCreated == FALSE){
-
-                               wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
-                               wxString XestiaABUserDirectory = GetUserDir();
-
-                               if (wxMkdir(XestiaABUserDirectory + wxT("\\accounts\\") + DirectoryName + wxT(".local"), 0740) == TRUE){
-
-                                       DirectoryCreated = TRUE;
-                                       cfgfile->Write(wxT("accountdir"), DirectoryName);
-
-                               }
-
-                       }
-
-               }
-
-               delete cfgfile;
-               cfgfile = NULL;
-
-               ReloadAccountConfig = TRUE;             
-
+        
+        XestiaABPrefDirectory = 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(XestiaABPrefDirectory + 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(XestiaABPrefDirectory + 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
-
-               XestiaABUserDirectory = GetUserPrefDir();
-
-               AccountSettingsFile = XestiaABUserDirectory + 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);
-               
-               }
-               
-               cfgfile->SetPath(txtAccountName->GetValue());
-               cfgfile->Write(wxT("address"), txtServerAddress->GetValue());
-               cfgfile->Write(wxT("port"), txtServerPort->GetValue());
-               cfgfile->Write(wxT("username"), txtUsername->GetValue());
-               cfgfile->Write(wxT("password"), txtPassword->GetValue());
-               cfgfile->Write(wxT("prefix"), ServerPrefix);
-               
-               if (chkUseSSL->GetValue() == TRUE){
-               
-                       cfgfile->Write(wxT("ssl"), wxT("true"));
-               
-               } else {
-               
-                       cfgfile->Write(wxT("ssl"), wxT("false"));
-               
-               }
-
-               cfgfile->Write(wxT("refresh"), wxT("1800"));
-
-               if (cmbServerType->GetCurrentSelection() == 1){
-               
-                       while(DirectoryCreated == FALSE){
-
-                               wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
-       
-                               if (wxMkdir(XestiaABUserDirectory + wxT("/accounts/") + DirectoryName + wxT(".carddav"), 0740) == TRUE){
-               
-                                       DirectoryCreated = TRUE;
-                                       cfgfile->Write(wxT("accountdir"), DirectoryName);
-               
-                               }
-                       
-                       }
-               
-               } else if (cmbServerType->GetCurrentSelection() == 0){
-               
-                       // Create the account directory.
-                       
-                       while(DirectoryCreated == FALSE){
-                       
-                               wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
-                       
-                               if (wxMkdir(XestiaABUserDirectory + wxT("/accounts/") + DirectoryName + wxT(".carddav"), 0740) == TRUE){
-                               
-                                       DirectoryCreated = TRUE;
-                                       cfgfile->Write(wxT("accountdir"), DirectoryName);
-                               
-                               }
-                       
-                       }
-                       
-               }
-
-               delete cfgfile;
-               cfgfile = NULL;
-               
-               ReloadAccountConfig = TRUE;
-
+        
+        XestiaABPrefDirectory = GetUserDir();
+        
+        AccountSettingsFile = GetUserPrefDir() + 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(XestiaABPrefDirectory + 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(XestiaABPrefDirectory + 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();
+        
+    }
+    
+}
 
-               this->Close();
-       
-       }
-
+void frmNewAccount::WriteAccountDetails(wxFileConfig *cfgfilein, wxString AccountType, wxString DirectoryName){
+    
+    cfgfilein->SetPath(txtAccountName->GetValue());
+    cfgfilein->Write(wxT("address"), txtServerAddress->GetValue());
+    cfgfilein->Write(wxT("port"), txtServerPort->GetValue());
+    cfgfilein->Write(wxT("username"), txtUsername->GetValue());
+    cfgfilein->Write(wxT("password"), txtPassword->GetValue());
+    cfgfilein->Write(wxT("prefix"), ServerPrefix);
+    cfgfilein->Write(wxT("accountdir"), DirectoryName);
+    
+    if (chkUseSSL->GetValue() == TRUE){
+        
+        cfgfilein->Write(wxT("ssl"), wxT("true"));
+        
+    } else {
+        
+        cfgfilein->Write(wxT("ssl"), wxT("false"));
+        
+    }
+    
+    cfgfilein->Write(wxT("refresh"), wxT("1800"));
+    cfgfilein->Write(wxT("type"), AccountType);
+    
 }
 
 void frmNewAccount::CloseWindow( wxCommandEvent& event )
 {
-       ReloadAccountConfig = FALSE;
-       this->Close();
+    ReloadAccountConfig = FALSE;
+    this->Close();
 }
 
 void frmNewAccount::UpdateRequirements( wxCommandEvent& event )
 {
-
-       // Update the options.
-       
-       if (cmbServerType->GetCurrentSelection() == 1){
-
-               txtServerAddress->Enable();
-               txtServerPort->Enable();
-               txtUsername->Enable();
-               txtPassword->Enable();
-               chkUseSSL->Enable();
-       
-       } else if (cmbServerType->GetCurrentSelection() == 0){
-       
-               txtServerAddress->Disable();
-               txtServerPort->Disable();
-               txtUsername->Disable();
-               txtPassword->Disable();
-               chkUseSSL->Disable();
-       
-       }
-
+    
+    // Update the options.
+    
+    if (cmbServerType->GetCurrentSelection() == 1){
+        
+        txtServerAddress->Enable();
+        txtServerPort->Enable();
+        txtUsername->Enable();
+        txtPassword->Enable();
+        chkUseSSL->Enable();
+        
+    } else if (cmbServerType->GetCurrentSelection() == 0){
+        
+        txtServerAddress->Disable();
+        txtServerPort->Disable();
+        txtUsername->Disable();
+        txtPassword->Disable();
+        chkUseSSL->Disable();
+        
+    }
+    
 }
 
 void frmNewAccount::SetupPointers(bool *ReloadAccountInc){
-
-       ReloadAccountConfig = ReloadAccountInc;
-
+    
+    ReloadAccountConfig = ReloadAccountInc;
+    
 }
\ No newline at end of file
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