Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
forms: Forms updated
[xestiacalendar/.git] / source / forms / newaccount / frmNewAccount.cpp
1 #include "frmNewAccount.h"
3 frmNewAccount::frmNewAccount( wxWindow* parent )
4 :
5 frmNewAccountADT( parent )
6 {
8         // Disable the previous button upon form creation.
10         btnPrevious->Disable();
11         txtServerAddress->Disable();
12         txtServerPort->Disable();
13         txtUsername->Disable();
14         txtPassword->Disable();
15         chkUseSSL->Disable();
16         
17 }
19 void frmNewAccount::UpdateRequirements( wxCommandEvent& event )
20 {
21 // TODO: Implement UpdateRequirements
22 }
24 void frmNewAccount::ProcessPrevious( wxCommandEvent& event )
25 {
26 // TODO: Implement ProcessPrevious
27 }
29 void frmNewAccount::ProcessNext( wxCommandEvent& event )
30 {
32         PageSeek++;
33         
34         if (PageSeek == 1){
35                 PageSeek++;
36         }
37     
38         if (PageSeek == 1){
39         
40                 // Skip this page.
41         
42         } else if (PageSeek == 2){
43         
44                 // Finish screen.
45         
46                 tabType->Hide();
47                 tabConn->Hide();
48                 tabFinish->Show();
49                 szrNewAccount->RecalcSizes();
50         
51                 btnNext->Disable();
52                 btnNext->SetLabel(_("Finish"));
53         
54                 if (txtAccountName->IsEmpty() && PageSeek == 2){
55         
56                         btnNext->Disable();
57             
58                 } else {
59         
60                         btnNext->Enable();
61             
62                 }
63         
64         } else if (PageSeek == 3){
65         
66                 // Finished.
67         
68                 wxString XestiaCALPrefDirectory;
69                 wxString XestiaCALDirectory;
70                 wxString AccountSettingsFile;
71                 //wxFile ASFile;
72                 
73                 srand(time(0));
74                 int RandomNumber = rand() % 32767;
75                 wxString RandomNumberSuffix = wxString::Format(wxT("%i"), RandomNumber);
76                 bool DirectoryCreated = FALSE;
77         
78 #if defined(__HAIKU__)
79         
80                 //preffilename = wxT("noo");
81         
82 #elif defined(__WIN32__)
83         
84                 XestiaCALPrefDirectory = GetUserPrefDir();
85                 XestiaCALDirectory = GetUserDir();
86         
87                 AccountSettingsFile = XestiaCALPrefDirectory + wxT("accounts");
88         
89                 // Open the file for writing.
90         
91                 wxFileConfig *cfgfile = new wxFileConfig("", "", AccountSettingsFile);
92         
93                 // Check if account name already exists and return an error message
94                 // if this is the case.
95         
96                 wxString AccountName;
97                 long itemindex = 0;
98                 bool ContinueAcc;
99                 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
100         
101                 while (ContinueAcc){
102             
103                         if (txtAccountName->GetValue() == AccountName){
104                 
105                                 wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR);
106                                 return;
107                 
108                         }
109             
110                         cfgfile->SetPath(wxT("/"));
111                         ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
112             
113                 }
114         
115                 if (cmbServerType->GetCurrentSelection() == 0){
116             
117                         // Create the account directory.
118             
119                         wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
120             
121                         if (wxMkdir(XestiaCALDirectory + wxT("\\accounts\\") + DirectoryName + wxT(".local"), 0740) == TRUE){
122                 
123                                 DirectoryCreated = TRUE;
124                 
125                         }
126             
127                         if (DirectoryCreated == TRUE){
128                 
129                                 WriteAccountDetails(cfgfile, wxT("Local"), DirectoryName);
130                 
131                         } else {
132                 
133                                 wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
134                                 return;
135                 
136                         }
137             
138                 }
139         
140                 delete cfgfile;
141                 cfgfile = NULL;
142         
143                 *ReloadAccountConfig = TRUE;
144         
145 #else
146         
147                 XestiaCALPrefDirectory = GetUserPrefDir();
148                 XestiaCALDirectory = GetUserDir();
149         
150                 AccountSettingsFile = XestiaCALPrefDirectory + wxT("accounts");
151         
152                 // Open the file for writing.
153         
154                 wxFileConfig *cfgfile = new wxFileConfig("", "", AccountSettingsFile);
155         
156                 // Check if account name already exists and return an error message
157                 // if this is the case.
158         
159                 wxString AccountName;
160                 long itemindex = 0;
161                 bool ContinueAcc;
162                 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
163         
164                 while (ContinueAcc){
165             
166                         if (txtAccountName->GetValue() == AccountName){
167                 
168                                 wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR);
169                                 return;
170                 
171                         }
172             
173                         cfgfile->SetPath(wxT("/"));
174                         ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
175             
176                 }
177         
178                 if (cmbServerType->GetCurrentSelection() == 0){
179             
180                         // Create the account directory.
181             
182                         wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix;
183             
184                         if (wxMkdir(XestiaCALDirectory + wxT("/accounts/") + DirectoryName + wxT(".Local"), 0740) == TRUE){
185                 
186                                 DirectoryCreated = TRUE;
187                 
188                         }
189             
190                         if (DirectoryCreated == TRUE){
191                 
192                                 WriteAccountDetails(cfgfile, wxT("Local"), DirectoryName);
193                 
194                         } else {
195                 
196                                 wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
197                                 return;
198                 
199                         }
200             
201                 }
202         
203                 delete cfgfile;
204                 cfgfile = NULL;
205         
206                 *ReloadAccountConfig = true;
207                 
208 #endif
209         
210                 this->Close();
211         
212         }
213         
216 void frmNewAccount::CloseWindow( wxCommandEvent& event )
218         
219         // Close the window.
221         *ReloadAccountConfig = FALSE;
222         this->Close();
223         
226 void frmNewAccount::SetupPointers(bool *ReloadAccountInc, CalendarDataStorage *dataStorage){
228         // Setup the pointers for the new account window.
229    
230         ReloadAccountConfig = ReloadAccountInc;
231     
234 void frmNewAccount::CheckAccountName( wxCommandEvent& event )
236     
237         // Check that the account name is valid.
238     
239         wxString CheckAccName = txtAccountName->GetValue();
240     
241         if ((txtAccountName->IsEmpty() && PageSeek == 2) || CheckAccName.Len() < 4){
242         
243                 btnNext->Disable();
244         
245         } else {
246         
247                 btnNext->Enable();
248         
249         }
250     
253 void frmNewAccount::WriteAccountDetails(wxFileConfig *cfgfilein, wxString AccountType, wxString DirectoryName){
254     
255         // Write the new account details.
256     
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);
264     
265         if (chkUseSSL->GetValue() == TRUE){
266         
267                 cfgfilein->Write(wxT("ssl"), wxT("true"));
268         
269         } else {
270         
271                 cfgfilein->Write(wxT("ssl"), wxT("false"));
272         
273         }
274     
275         cfgfilein->Write(wxT("refresh"), wxT("1800"));
276         cfgfilein->Write(wxT("type"), AccountType);
277     
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