1 #include "frmNewAccount.h"
3 frmNewAccount::frmNewAccount( wxWindow* parent )
5 frmNewAccountADT( parent )
8 // Disable the previous button upon form creation.
10 btnPrevious->Disable();
11 txtServerAddress->Disable();
12 txtServerPort->Disable();
13 txtUsername->Disable();
14 txtPassword->Disable();
19 void frmNewAccount::UpdateRequirements( wxCommandEvent& event )
21 // TODO: Implement UpdateRequirements
24 void frmNewAccount::ProcessPrevious( wxCommandEvent& event )
26 // TODO: Implement ProcessPrevious
29 void frmNewAccount::ProcessNext( wxCommandEvent& event )
42 } else if (PageSeek == 2){
49 szrNewAccount->RecalcSizes();
52 btnNext->SetLabel(_("Finish"));
54 if (txtAccountName->IsEmpty() && PageSeek == 2){
64 } else if (PageSeek == 3){
68 wxString XestiaCALPrefDirectory;
69 wxString XestiaCALDirectory;
70 wxString AccountSettingsFile;
74 int RandomNumber = rand() % 32767;
75 wxString RandomNumberSuffix = wxString::Format(wxT("%i"), RandomNumber);
76 bool DirectoryCreated = FALSE;
78 #if defined(__HAIKU__)
80 //preffilename = wxT("noo");
82 #elif defined(__WIN32__)
84 XestiaCALPrefDirectory = GetUserPrefDir();
85 XestiaCALDirectory = GetUserDir();
87 AccountSettingsFile = XestiaCALPrefDirectory + wxT("accounts");
89 // Open the file for writing.
91 wxFileConfig *cfgfile = new wxFileConfig("", "", AccountSettingsFile);
93 // Check if account name already exists and return an error message
94 // if this is the case.
99 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
103 if (txtAccountName->GetValue() == AccountName){
105 wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR);
110 cfgfile->SetPath(wxT("/"));
111 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
115 if (cmbServerType->GetCurrentSelection() == 0){
117 // Create the account directory.
119 wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
121 if (wxMkdir(XestiaCALDirectory + wxT("\\accounts\\") + DirectoryName + wxT(".local"), 0740) == TRUE){
123 DirectoryCreated = TRUE;
127 if (DirectoryCreated == TRUE){
129 WriteAccountDetails(cfgfile, wxT("Local"), DirectoryName);
133 wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
143 *ReloadAccountConfig = TRUE;
147 XestiaCALPrefDirectory = GetUserPrefDir();
148 XestiaCALDirectory = GetUserDir();
150 AccountSettingsFile = XestiaCALPrefDirectory + wxT("accounts");
152 // Open the file for writing.
154 wxFileConfig *cfgfile = new wxFileConfig("", "", AccountSettingsFile);
156 // Check if account name already exists and return an error message
157 // if this is the case.
159 wxString AccountName;
162 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
166 if (txtAccountName->GetValue() == AccountName){
168 wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR);
173 cfgfile->SetPath(wxT("/"));
174 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
178 if (cmbServerType->GetCurrentSelection() == 0){
180 // Create the account directory.
182 wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
184 if (wxMkdir(XestiaCALDirectory + wxT("/accounts/") + DirectoryName + wxT(".Local"), 0740) == TRUE){
186 DirectoryCreated = TRUE;
190 if (DirectoryCreated == TRUE){
192 WriteAccountDetails(cfgfile, wxT("Local"), DirectoryName);
196 wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
206 *ReloadAccountConfig = true;
216 void frmNewAccount::CloseWindow( wxCommandEvent& event )
221 *ReloadAccountConfig = FALSE;
226 void frmNewAccount::SetupPointers(bool *ReloadAccountInc, CalendarDataStorage *dataStorage){
228 // Setup the pointers for the new account window.
230 ReloadAccountConfig = ReloadAccountInc;
234 void frmNewAccount::CheckAccountName( wxCommandEvent& event )
237 // Check that the account name is valid.
239 wxString CheckAccName = txtAccountName->GetValue();
241 if ((txtAccountName->IsEmpty() && PageSeek == 2) || CheckAccName.Len() < 4){
253 void frmNewAccount::WriteAccountDetails(wxFileConfig *cfgfilein, wxString AccountType, wxString DirectoryName){
255 // Write the new account details.
257 cfgfilein->SetPath(txtAccountName->GetValue());
258 cfgfilein->Write(wxT("address"), txtServerAddress->GetValue());
259 cfgfilein->Write(wxT("port"), txtServerPort->GetValue());
260 cfgfilein->Write(wxT("username"), txtUsername->GetValue());
261 cfgfilein->Write(wxT("password"), txtPassword->GetValue());
262 cfgfilein->Write(wxT("prefix"), ServerPrefix);
263 cfgfilein->Write(wxT("accountdir"), DirectoryName);
265 if (chkUseSSL->GetValue() == TRUE){
267 cfgfilein->Write(wxT("ssl"), wxT("true"));
271 cfgfilein->Write(wxT("ssl"), wxT("false"));
275 cfgfilein->Write(wxT("refresh"), wxT("1800"));
276 cfgfilein->Write(wxT("type"), AccountType);