X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fforms%2Fnewaccount%2FfrmNewAccount.cpp;h=5b94c5e8904195a5d253465e76a6a1a0060bff1d;hb=1fe6e43892e5c572949a293a9e19704b5debadad;hp=6baed829d24e76f000e75be5e3d6bdaaeacf1c72;hpb=53f288b9f66a1628babd3b0f670c5e75f812860f;p=xestiacalendar%2F.git diff --git a/source/forms/newaccount/frmNewAccount.cpp b/source/forms/newaccount/frmNewAccount.cpp index 6baed82..5b94c5e 100644 --- a/source/forms/newaccount/frmNewAccount.cpp +++ b/source/forms/newaccount/frmNewAccount.cpp @@ -1,3 +1,21 @@ +// frmNewAccount.cpp - frmNewAccount form functions +// +// (c) 2016-2017 Xestia Software Development. +// +// This file is part of Xestia Calendar. +// +// Xestia Calendar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by the +// Free Software Foundation, version 3 of the license. +// +// Xestia Calendar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with Xestia Calendar. If not, see + #include "frmNewAccount.h" frmNewAccount::frmNewAccount( wxWindow* parent ) @@ -5,6 +23,15 @@ frmNewAccount::frmNewAccount( wxWindow* parent ) 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 ) @@ -12,11 +39,6 @@ void frmNewAccount::UpdateRequirements( wxCommandEvent& event ) // TODO: Implement UpdateRequirements } -void frmNewAccount::CheckAccountName( wxCommandEvent& event ) -{ -// TODO: Implement CheckAccountName -} - void frmNewAccount::ProcessPrevious( wxCommandEvent& event ) { // TODO: Implement ProcessPrevious @@ -24,10 +46,251 @@ void frmNewAccount::ProcessPrevious( wxCommandEvent& event ) 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