Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Implemented UTF8 support in DeleteCalendar function
[xestiacalendar/.git] / source / forms / newaccount / frmNewAccount.cpp
1 // frmNewAccount.cpp - frmNewAccount form functions
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Calendar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Calendar is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "frmNewAccount.h"
21 frmNewAccount::frmNewAccount( wxWindow* parent )
22 :
23 frmNewAccountADT( parent )
24 {
26         // Disable the previous button upon form creation.
28         btnPrevious->Disable();
29         txtServerAddress->Disable();
30         txtServerPort->Disable();
31         txtUsername->Disable();
32         txtPassword->Disable();
33         chkUseSSL->Disable();
34         
35 }
37 void frmNewAccount::UpdateRequirements( wxCommandEvent& event )
38 {
39 // TODO: Implement UpdateRequirements
40 }
42 void frmNewAccount::ProcessPrevious( wxCommandEvent& event )
43 {
44 // TODO: Implement ProcessPrevious
45 }
47 void frmNewAccount::ProcessNext( wxCommandEvent& event )
48 {
50         pageSeek++;
51         
52         if (pageSeek == 1){
53                 pageSeek++;
54         }
55     
56         if (pageSeek == 1){
57         
58                 // Skip this page.
59         
60         } else if (pageSeek == 2){
61         
62                 // Finish screen.
63         
64                 tabType->Hide();
65                 tabConn->Hide();
66                 tabFinish->Show();
67                 szrNewAccount->RecalcSizes();
68         
69                 btnNext->Disable();
70                 btnNext->SetLabel(_("Finish"));
71         
72                 if (txtAccountName->IsEmpty() && pageSeek == 2){
73         
74                         btnNext->Disable();
75             
76                 } else {
77         
78                         btnNext->Enable();
79             
80                 }
81         
82         } else if (pageSeek == 3){
83         
84                 // Finished.
85         
86                 wxString xestiaCALPrefDirectory;
87                 wxString xestiaCALDirectory;
88                 wxString accountSettingsFile;
89                 //wxFile ASFile;
90                 
91                 srand(time(0));
92                 int randomNumber = rand() % 32767;
93                 wxString randomNumberSuffix = wxString::Format(wxT("%i"), randomNumber);
94                 bool directoryCreated = FALSE;
95         
96 #if defined(__HAIKU__)
97         
98                 //preffilename = wxT("noo");
99         
100 #elif defined(__WIN32__)
101         
102                 xestiaCALPrefDirectory = GetUserPrefDir();
103                 xestiaCALDirectory = GetUserDir();
104         
105                 accountSettingsFile = xestiaCALPrefDirectory + wxT("accounts");
106         
107                 // Open the file for writing.
108         
109                 wxFileConfig *cfgFile = new wxFileConfig("", "", accountSettingsFile);
110         
111                 // Check if account name already exists and return an error message
112                 // if this is the case.
113         
114                 wxString accountName;
115                 long itemIndex = 0;
116                 bool continueAcc;
117                 continueAcc = cfgFile->GetFirstGroup(accountName, itemIndex);
118         
119                 while (continueAcc){
120             
121                         if (txtAccountName->GetValue() == accountName){
122                 
123                                 wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR);
124                                 return;
125                 
126                         }
127             
128                         cfgFile->SetPath(wxT("/"));
129                         continueAcc = cfgFile->GetNextGroup(accountName, itemIndex);
130             
131                 }
132         
133                 if (cmbServerType->GetCurrentSelection() == 0){
134             
135                         // Create the account directory.
136             
137                         wxString directoryName = txtAccountName->GetValue().Mid(0, 30) + randomNumberSuffix;
138             
139                         if (wxMkdir(xestiaCALDirectory + wxT("\\accounts\\") + directoryName + wxT(".local"), 0740) == TRUE){
140                 
141                                 directoryCreated = TRUE;
142                 
143                         }
144             
145                         if (directoryCreated == TRUE){
146                 
147                                 WriteAccountDetails(cfgFile, wxT("Local"), directoryName);
148                 
149                         } else {
150                 
151                                 wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
152                                 return;
153                 
154                         }
155             
156                 }
157         
158                 delete cfgFile;
159                 cfgFile = NULL;
160         
161                 *reloadAccountConfig = TRUE;
162         
163 #else
164         
165                 xestiaCALPrefDirectory = GetUserPrefDir();
166                 xestiaCALDirectory = GetUserDir();
167         
168                 accountSettingsFile = xestiaCALPrefDirectory + wxT("accounts");
169         
170                 // Open the file for writing.
171         
172                 wxFileConfig *cfgFile = new wxFileConfig("", "", accountSettingsFile);
173         
174                 // Check if account name already exists and return an error message
175                 // if this is the case.
176         
177                 wxString accountName;
178                 long itemIndex = 0;
179                 bool continueAcc;
180                 continueAcc = cfgFile->GetFirstGroup(accountName, itemIndex);
181         
182                 while (continueAcc){
183             
184                         if (txtAccountName->GetValue() == accountName){
185                 
186                                 wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR);
187                                 return;
188                 
189                         }
190             
191                         cfgFile->SetPath(wxT("/"));
192                         continueAcc = cfgFile->GetNextGroup(accountName, itemIndex);
193             
194                 }
195         
196                 if (cmbServerType->GetCurrentSelection() == 0){
197             
198                         // Create the account directory.
199             
200                         wxString directoryName = txtAccountName->GetValue().Mid(0, 30) + randomNumberSuffix;
201             
202                         if (wxMkdir(xestiaCALDirectory + wxT("/accounts/") + directoryName + wxT(".Local"), 0740) == TRUE){
203                 
204                                 directoryCreated = TRUE;
205                 
206                         }
207             
208                         if (directoryCreated == TRUE){
209                 
210                                 WriteAccountDetails(cfgFile, wxT("Local"), directoryName);
211                 
212                         } else {
213                 
214                                 wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory"));
215                                 return;
216                 
217                         }
218             
219                 }
220         
221                 delete cfgFile;
222                 cfgFile = NULL;
223         
224                 *reloadAccountConfig = true;
225                 
226 #endif
227         
228                 this->Close();
229         
230         }
231         
234 void frmNewAccount::CloseWindow( wxCommandEvent& event )
236         
237         // Close the window.
239         *reloadAccountConfig = FALSE;
240         this->Close();
241         
244 void frmNewAccount::SetupPointers(bool *ReloadAccountInc, CalendarDataStorage *dataStorage){
246         // Setup the pointers for the new account window.
247    
248         reloadAccountConfig = ReloadAccountInc;
249     
252 void frmNewAccount::CheckAccountName( wxCommandEvent& event )
254     
255         // Check that the account name is valid.
256     
257         wxString checkAccName = txtAccountName->GetValue();
258     
259         if ((txtAccountName->IsEmpty() && pageSeek == 2) || checkAccName.Len() < 4){
260         
261                 btnNext->Disable();
262         
263         } else {
264         
265                 btnNext->Enable();
266         
267         }
268     
271 void frmNewAccount::WriteAccountDetails(wxFileConfig *cfgFileIn, wxString accountType, wxString directoryName){
272     
273         // Write the new account details.
274     
275         cfgFileIn->SetPath(txtAccountName->GetValue());
276         cfgFileIn->Write(wxT("address"), txtServerAddress->GetValue());
277         cfgFileIn->Write(wxT("port"), txtServerPort->GetValue());
278         cfgFileIn->Write(wxT("username"), txtUsername->GetValue());
279         cfgFileIn->Write(wxT("password"), txtPassword->GetValue());
280         cfgFileIn->Write(wxT("prefix"), serverPrefix);
281         cfgFileIn->Write(wxT("accountdir"), directoryName);
282     
283         if (chkUseSSL->GetValue() == TRUE){
284         
285                 cfgFileIn->Write(wxT("ssl"), wxT("true"));
286         
287         } else {
288         
289                 cfgFileIn->Write(wxT("ssl"), wxT("false"));
290         
291         }
292     
293         cfgFileIn->Write(wxT("refresh"), wxT("1800"));
294         cfgFileIn->Write(wxT("type"), accountType);
295     
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