frmNewAccountADT( parent )
{
+ // Disable the previous button upon form creation.
+
+ btnPrevious->Disable();
+ txtServerAddress->Disable();
+ txtServerPort->Disable();
+ txtUsername->Disable();
+ txtPassword->Disable();
+ chkUseSSL->Disable();
+
}
void frmNewAccount::UpdateRequirements( wxCommandEvent& event )
// TODO: Implement UpdateRequirements
}
-void frmNewAccount::CheckAccountName( wxCommandEvent& event )
-{
-// TODO: Implement CheckAccountName
-}
-
void frmNewAccount::ProcessPrevious( wxCommandEvent& event )
{
// TODO: Implement ProcessPrevious
void frmNewAccount::ProcessNext( wxCommandEvent& event )
{
-// TODO: Implement ProcessNext
+
+ PageSeek++;
+
+ if (PageSeek == 1){
+ PageSeek++;
+ }
+
+ if (PageSeek == 1){
+
+ // Skip this page.
+
+ } 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 XestiaCALPrefDirectory;
+ wxString XestiaCALDirectory;
+ wxString AccountSettingsFile;
+ //wxFile ASFile;
+
+ srand(time(0));
+ int RandomNumber = rand() % 32767;
+ wxString RandomNumberSuffix = wxString::Format(wxT("%i"), RandomNumber);
+ bool DirectoryCreated = FALSE;
+
+#if defined(__HAIKU__)
+
+ //preffilename = wxT("noo");
+
+#elif defined(__WIN32__)
+
+ XestiaCALPrefDirectory = GetUserPrefDir();
+ XestiaCALDirectory = GetUserDir();
+
+ AccountSettingsFile = XestiaCALPrefDirectory + 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() == 0){
+
+ // Create the account directory.
+
+ wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
+
+ if (wxMkdir(XestiaCALDirectory + 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
+
+ XestiaCALPrefDirectory = GetUserPrefDir();
+ XestiaCALDirectory = GetUserDir();
+
+ AccountSettingsFile = XestiaCALPrefDirectory + 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() == 0){
+
+ // Create the account directory.
+
+ wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
+
+ if (wxMkdir(XestiaCALDirectory + 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();
+
+ }
+
}
void frmNewAccount::CloseWindow( wxCommandEvent& event )
{
-// TODO: Implement CloseWindow
+
+ // Close the window.
+
+ *ReloadAccountConfig = FALSE;
+ this->Close();
+
}
+
+void frmNewAccount::SetupPointers(bool *ReloadAccountInc, CalendarDataStorage *dataStorage){
+
+ // Setup the pointers for the new account window.
+
+ ReloadAccountConfig = ReloadAccountInc;
+
+}
+
+void frmNewAccount::CheckAccountName( wxCommandEvent& event )
+{
+
+ // Check that the account name is valid.
+
+ wxString CheckAccName = txtAccountName->GetValue();
+
+ if ((txtAccountName->IsEmpty() && PageSeek == 2) || CheckAccName.Len() < 4){
+
+ btnNext->Disable();
+
+ } else {
+
+ btnNext->Enable();
+
+ }
+
+}
+
+void frmNewAccount::WriteAccountDetails(wxFileConfig *cfgfilein, wxString AccountType, wxString DirectoryName){
+
+ // Write the new account details.
+
+ 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);
+
+}
\ No newline at end of file