Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added OS X support to frmEditAccount
[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"
20 #include "frmInvalidSSLCertificate.h"
21 #include "carddav/carddav.h"
22 #include "common/svrblist.h"
24 frmEditAccount::frmEditAccount( wxWindow* parent )
25 :
26 frmEditAccountADT( parent )
27 {
29 }
31 void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
32 {
34         // Check data before connecting.
36         wxString ValueData;
37         
38         long PortNum;
39         ValueData = txtPort->GetValue();
40         ValueData.ToLong(&PortNum, 10);
41         long RefreshNum;
42         ValueData = txtRefresh->GetValue();
43         ValueData.ToLong(&RefreshNum, 10);
44         bool UseSSL;
45         
46         if (txtAddress->IsEmpty()){
47         
48                 wxMessageBox(wxT("The server address cannot be blank."), wxT("Error"), wxICON_ERROR);
49                 return;
50         
51         }
52         
53         if (txtPort->IsEmpty() || PortNum < 0 || PortNum > 65535){
54         
55                 wxMessageBox(wxT("The server port needs to be between number 1 and 65535."), wxT("Error"), wxICON_ERROR);
56                 return;
57         
58         }
59         
60         if (txtUsername->IsEmpty()){
61         
62                 wxMessageBox(wxT("The server username cannot be blank."), wxT("Error"), wxICON_ERROR);
63                 return;
64         
65         }
67         if (txtPassword->IsEmpty()){
68         
69                 wxMessageBox(wxT("The server password cannot be blank."), wxT("Error"), wxICON_ERROR);  
70                 return;
71         
72         }
73         
74         UseSSL = chkSSL->GetValue();
75         
76         if (txtRefresh->IsEmpty() || RefreshNum < 300 || RefreshNum > 86400){
77         
78                 RefreshNum = 1800;
79                 
80         }
81         
82         // Setup a CardDAV object.
83         
84         CardDAV CDavObj;
85         
86         CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
87         
88         // Verify SSL trust first before doing anything.
90         if (UseSSL == TRUE){
92                 CURLcode sslcode = CDavObj.SSLVerifyTest();
94                 if (sslcode == CURLE_OK){
95                                 
96                         // Certificate is okay. Do nothing.
98                 } else if (sslcode == CURLE_SSL_CACERT || sslcode == CURLE_SSL_CONNECT_ERROR){
100                         // Certificate is more than likely a self-signed or
101                         // expired certificate so display the invalid
102                         // SSL certificate message.
104                         // Setup the data to be sent in the wxPostEvent command.
106                         int SSLResult;
107                         
108 #if defined(__APPLE__)
109         
110                         SSLResult = DisplayTrustPanel(&CDavObj);
111                         
112 #else
113                         
114                         frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
116                         frmICPtr->LoadDataNew(CDavObj.GetSSLVerifyResults(), txtAddress->GetValue());
117                         frmICPtr->ShowModal();
118                                         
119                         SSLResult = frmICPtr->GetResult();
120                                                         
121                         // Clean up before processing response.
122                                 
123                         delete frmICPtr;
124                         frmICPtr = NULL;
125                         
126 #endif
127                         
128                         // Process the response from the user.
129                                                         
130                         if (SSLResult == 1){
131                                                                 
132                                 // Accept the Certificate.
134                                 CDavObj.AllowSelfSignTest(TRUE);
135                                                                 
136                         } else if (SSLResult == 2){
137                                                                 
138                                 // Reject the certificate, abort the task and mark as failed.
140                                 wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
141                                 return;
142                                                                 
143                         }
145                 } else {
147                         // Something else happened. Stop the process and
148                         // display an error message instead.
150                         wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
151                         return;
153                 }
155         }
156         
157         // Attempt to extract the CardDAV address.
158         
159         wxString ABURL = CDavObj.GetDefaultAddressBookURL();
160         
161         txtPrefix->SetValue(ABURL);
162         
165 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
167         // Setup the account configuration file pointer.
168         
169         cfgfile = cfgin;
173 void frmEditAccount::LoadSettings( wxString AccNameIn ){
175         // Get the data from the accounts settings file and
176         // fill in the account fields.
178         AccName = AccNameIn;
179         long itemindex = 0;
180         bool ContinueAcc = TRUE;
181         wxString AccountName;
182         wxString AccountData;
183         
184         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
185         
186         while (ContinueAcc){
188                 if (AccountName == AccName){
190                         cfgfile->SetPath(AccountName);
191                         txtAccountName->SetValue(AccountName);
193                         cfgfile->Read("address", &AccountData);
194                         txtAddress->SetValue(AccountData);
196                         cfgfile->Read("port", &AccountData);
197                         txtPort->SetValue(AccountData);
199                         cfgfile->Read("username", &AccountData);
200                         txtUsername->SetValue(AccountData);
202                         cfgfile->Read("password", &AccountData);
203                         txtPassword->SetValue(AccountData);
205                         cfgfile->Read("prefix", &AccountData);
206                         txtPrefix->SetValue(AccountData);
208                         cfgfile->Read("ssl", &AccountData);
209                         if (AccountData == wxT("true")){
210                         
211                                 chkSSL->SetValue(TRUE);
212                         
213                         }
214                         
215                         cfgfile->Read("refresh", &AccountData);
216                         txtRefresh->SetValue(AccountData);
217                         
218                         break;
220                 }
221                 
222                 cfgfile->SetPath(wxT("/"));
223                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
225         }
229 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
232         // Check if server address matches against the blacklist.
233         // Bring up warning message if it does.
234         
235         if (CheckBlacklist(txtAddress->GetValue())){
236                 
237                 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);
238                 
239                 if (MessageBoxResult == wxNO){
240                         return;
241                 }
242                         
243         }
244         
245         // Update the settings for the account.
247         long itemindex = 0;
248         bool ContinueAcc = TRUE;
249         wxString AccountName;
251         // Look for the account
252         
253         while (ContinueAcc){
255                 if (AccountName == AccName){
257                         // Update the settings for the account.
259                         cfgfile->RenameGroup(AccountName, txtAccountName->GetValue());
261                         cfgfile->SetPath(txtAccountName->GetValue());
262                         //txtAccountName->SetValue(AccountName);
263                         
264                         cfgfile->DeleteEntry(wxT("address"), FALSE);
265                         cfgfile->Write(wxT("address"), txtAddress->GetValue());
267                         cfgfile->DeleteEntry(wxT("port"), FALSE);
268                         cfgfile->Write(wxT("port"), txtPort->GetValue());
270                         cfgfile->DeleteEntry(wxT("username"), FALSE);
271                         cfgfile->Write(wxT("username"), txtUsername->GetValue());
273                         cfgfile->DeleteEntry(wxT("password"), FALSE);
274                         cfgfile->Write(wxT("password"), txtPassword->GetValue());
276                         cfgfile->DeleteEntry(wxT("prefix"), FALSE);
277                         cfgfile->Write(wxT("prefix"), txtPrefix->GetValue());
279                         cfgfile->DeleteEntry(wxT("ssl"), FALSE);
281                         if (chkSSL->GetValue() == TRUE){
282                         
283                                 cfgfile->Write(wxT("ssl"), wxT("true"));
284                         
285                         } else {
286                         
287                                 cfgfile->Write(wxT("ssl"), wxT("false"));
288                         
289                         }
291                         cfgfile->DeleteEntry(wxT("refresh"), FALSE);
292                         cfgfile->Write(wxT("refresh"), txtRefresh->GetValue());
294                         break;
296                 }
297                 
298                 cfgfile->SetPath(wxT("/"));
299                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
301         }
303         // Set the dialog result to true and close the window.
304         
305         DialogResult = true;    
306         this->Close();  
310 void frmEditAccount::CloseWindow( wxCommandEvent& event )
312         
313         // Set the dialog result to false and close the window.
314         
315         DialogResult = false;
316         this->Close();
317         
320 bool frmEditAccount::GetDialogResult(){
322         // Get the result of the dialog.
323         
324         return DialogResult;
325         
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