Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Moved includes in frmEditAccount.cpp to frmEditAccount.h
[xestiaab/.git] / source / frmEditAccount.cpp
1 // frmEditAccount.cpp - Edit Account form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book 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 Address Book 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 Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmEditAccount.h"
21 frmEditAccount::frmEditAccount( wxWindow* parent )
22 :
23 frmEditAccountADT( parent )
24 {
26 }
28 void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
29 {
31         // Check data before connecting.
33         wxString ValueData;
34         
35         long PortNum;
36         ValueData = txtPort->GetValue();
37         ValueData.ToLong(&PortNum, 10);
38         long RefreshNum;
39         ValueData = txtRefresh->GetValue();
40         ValueData.ToLong(&RefreshNum, 10);
41         bool UseSSL;
42         
43         if (txtAddress->IsEmpty()){
44         
45                 wxMessageBox(wxT("The server address cannot be blank."), wxT("Error"), wxICON_ERROR);
46                 return;
47         
48         }
49         
50         if (txtPort->IsEmpty() || PortNum < 0 || PortNum > 65535){
51         
52                 wxMessageBox(wxT("The server port needs to be between number 1 and 65535."), wxT("Error"), wxICON_ERROR);
53                 return;
54         
55         }
56         
57         if (txtUsername->IsEmpty()){
58         
59                 wxMessageBox(wxT("The server username cannot be blank."), wxT("Error"), wxICON_ERROR);
60                 return;
61         
62         }
64         if (txtPassword->IsEmpty()){
65         
66                 wxMessageBox(wxT("The server password cannot be blank."), wxT("Error"), wxICON_ERROR);  
67                 return;
68         
69         }
70         
71         UseSSL = chkSSL->GetValue();
72         
73         if (txtRefresh->IsEmpty() || RefreshNum < 300 || RefreshNum > 86400){
74         
75                 RefreshNum = 1800;
76                 
77         }
78         
79         // Setup a CardDAV object.
80         
81         CardDAV CDavObj;
82         
83         CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
84         
85         // Verify SSL trust first before doing anything.
87         if (UseSSL == TRUE){
89                 CURLcode sslcode = CDavObj.SSLVerifyTest();
91                 if (sslcode == CURLE_OK){
92                                 
93                         // Certificate is okay. Do nothing.
95                 } else if (sslcode == CURLE_SSL_CACERT || sslcode == CURLE_SSL_CONNECT_ERROR){
97                         // Certificate is more than likely a self-signed or
98                         // expired certificate so display the invalid
99                         // SSL certificate message.
101                         // Setup the data to be sent in the wxPostEvent command.
103                         int SSLResult;
104                         
105 #if defined(__APPLE__)
106         
107                         SSLResult = DisplayTrustPanel(&CDavObj);
108                         
109 #else
110                         
111                         frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
113                         frmICPtr->LoadDataNew(CDavObj.GetSSLVerifyResults(), txtAddress->GetValue());
114                         frmICPtr->ShowModal();
115                                         
116                         SSLResult = frmICPtr->GetResult();
117                                                         
118                         // Clean up before processing response.
119                                 
120                         delete frmICPtr;
121                         frmICPtr = NULL;
122                         
123 #endif
124                         
125                         // Process the response from the user.
126                                                         
127                         if (SSLResult == 1){
128                                                                 
129                                 // Accept the Certificate.
131                                 CDavObj.AllowSelfSignTest(TRUE);
132                                                                 
133                         } else if (SSLResult == 2){
134                                                                 
135                                 // Reject the certificate, abort the task and mark as failed.
137                                 wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
138                                 return;
139                                                                 
140                         }
142                 } else {
144                         // Something else happened. Stop the process and
145                         // display an error message instead.
147                         wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
148                         return;
150                 }
152         }
153         
154         // Attempt to extract the CardDAV address.
155         
156         wxString ABURL = CDavObj.GetDefaultAddressBookURL();
157         
158         txtPrefix->SetValue(ABURL);
159         
162 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
164         // Setup the account configuration file pointer.
165         
166         cfgfile = cfgin;
170 void frmEditAccount::LoadSettings( wxString AccNameIn ){
172         // Get the data from the accounts settings file and
173         // fill in the account fields.
175         AccName = AccNameIn;
176         long itemindex = 0;
177         bool ContinueAcc = TRUE;
178         wxString AccountName;
179         wxString AccountData;
180         
181         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
182         
183         while (ContinueAcc){
185                 if (AccountName == AccName){
187                         cfgfile->SetPath(AccountName);
188                         txtAccountName->SetValue(AccountName);
190                         cfgfile->Read("address", &AccountData);
191                         txtAddress->SetValue(AccountData);
193                         cfgfile->Read("port", &AccountData);
194                         txtPort->SetValue(AccountData);
196                         cfgfile->Read("username", &AccountData);
197                         txtUsername->SetValue(AccountData);
199                         cfgfile->Read("password", &AccountData);
200                         txtPassword->SetValue(AccountData);
202                         cfgfile->Read("prefix", &AccountData);
203                         txtPrefix->SetValue(AccountData);
205                         cfgfile->Read("ssl", &AccountData);
206                         if (AccountData == wxT("true")){
207                         
208                                 chkSSL->SetValue(TRUE);
209                         
210                         }
211                         
212                         cfgfile->Read("refresh", &AccountData);
213                         txtRefresh->SetValue(AccountData);
214                         
215                         break;
217                 }
218                 
219                 cfgfile->SetPath(wxT("/"));
220                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
222         }
226 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
229         // Check if server address matches against the blacklist.
230         // Bring up warning message if it does.
231         
232         if (CheckBlacklist(txtAddress->GetValue())){
233                 
234                 int MessageBoxResult = wxMessageBox(_("The server with the address given does not support the CardDAV protocol properly and shouldn't be used.\n\nData loss is very likely.\n\nDo you still want to continue using this server?"), _("Server warning"), wxYES_NO, this);
235                 
236                 if (MessageBoxResult == wxNO){
237                         return;
238                 }
239                         
240         }
241         
242         // Update the settings for the account.
244         long itemindex = 0;
245         bool ContinueAcc = TRUE;
246         wxString AccountName;
248         // Look for the account
249         
250         while (ContinueAcc){
252                 if (AccountName == AccName){
254                         // Update the settings for the account.
256                         cfgfile->RenameGroup(AccountName, txtAccountName->GetValue());
258                         cfgfile->SetPath(txtAccountName->GetValue());
259                         //txtAccountName->SetValue(AccountName);
260                         
261                         cfgfile->DeleteEntry(wxT("address"), FALSE);
262                         cfgfile->Write(wxT("address"), txtAddress->GetValue());
264                         cfgfile->DeleteEntry(wxT("port"), FALSE);
265                         cfgfile->Write(wxT("port"), txtPort->GetValue());
267                         cfgfile->DeleteEntry(wxT("username"), FALSE);
268                         cfgfile->Write(wxT("username"), txtUsername->GetValue());
270                         cfgfile->DeleteEntry(wxT("password"), FALSE);
271                         cfgfile->Write(wxT("password"), txtPassword->GetValue());
273                         cfgfile->DeleteEntry(wxT("prefix"), FALSE);
274                         cfgfile->Write(wxT("prefix"), txtPrefix->GetValue());
276                         cfgfile->DeleteEntry(wxT("ssl"), FALSE);
278                         if (chkSSL->GetValue() == TRUE){
279                         
280                                 cfgfile->Write(wxT("ssl"), wxT("true"));
281                         
282                         } else {
283                         
284                                 cfgfile->Write(wxT("ssl"), wxT("false"));
285                         
286                         }
288                         cfgfile->DeleteEntry(wxT("refresh"), FALSE);
289                         cfgfile->Write(wxT("refresh"), txtRefresh->GetValue());
291                         break;
293                 }
294                 
295                 cfgfile->SetPath(wxT("/"));
296                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
298         }
300         // Set the dialog result to true and close the window.
301         
302         DialogResult = true;    
303         this->Close();  
307 void frmEditAccount::CloseWindow( wxCommandEvent& event )
309         
310         // Set the dialog result to false and close the window.
311         
312         DialogResult = false;
313         this->Close();
314         
317 bool frmEditAccount::GetDialogResult(){
319         // Get the result of the dialog.
320         
321         return DialogResult;
322         
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