Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out code from vcard/vcard34conv-v3conv.cpp
[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"
23 frmEditAccount::frmEditAccount( wxWindow* parent )
24 :
25 frmEditAccountADT( parent )
26 {
28 }
30 void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
31 {
33         // Check data before connecting.
35         wxString ValueData;
36         
37         long PortNum;
38         ValueData = txtPort->GetValue();
39         ValueData.ToLong(&PortNum, 10);
40         long RefreshNum;
41         ValueData = txtRefresh->GetValue();
42         ValueData.ToLong(&RefreshNum, 10);
43         bool UseSSL;
44         
45         if (txtAddress->IsEmpty()){
46         
47                 wxMessageBox(wxT("The server address cannot be blank."), wxT("Error"), wxICON_ERROR);
48                 return;
49         
50         }
51         
52         if (txtPort->IsEmpty() || PortNum < 0 || PortNum > 65535){
53         
54                 wxMessageBox(wxT("The server port needs to be between number 1 and 65535."), wxT("Error"), wxICON_ERROR);
55                 return;
56         
57         }
58         
59         if (txtUsername->IsEmpty()){
60         
61                 wxMessageBox(wxT("The server username cannot be blank."), wxT("Error"), wxICON_ERROR);
62                 return;
63         
64         }
66         if (txtPassword->IsEmpty()){
67         
68                 wxMessageBox(wxT("The server password cannot be blank."), wxT("Error"), wxICON_ERROR);  
69                 return;
70         
71         }
72         
73         UseSSL = chkSSL->GetValue();
74         
75         if (txtRefresh->IsEmpty() || RefreshNum < 300 || RefreshNum > 86400){
76         
77                 RefreshNum = 1800;
78                 
79         }
80         
81         // Setup a CardDAV object.
82         
83         CardDAV CDavObj;
84         
85         CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
86         
87         // Verify SSL trust first before doing anything.
89         if (UseSSL == TRUE){
91                 CURLcode sslcode = CDavObj.SSLVerifyTest();
93                 if (sslcode == CURLE_OK){
94                                 
95                         // Certificate is okay. Do nothing.
97                 } else if (sslcode == CURLE_SSL_CACERT || sslcode == CURLE_SSL_CONNECT_ERROR){
99                         // Certificate is more than likely a self-signed or
100                         // expired certificate so display the invalid
101                         // SSL certificate message.
103                         // Setup the data to be sent in the wxPostEvent command.
105                         int SSLResult;
106                         
107                         frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
109                         frmICPtr->LoadDataNew(CDavObj.GetSSLVerifyResults(), txtAddress->GetValue());
110                         frmICPtr->ShowModal();
111                                         
112                         SSLResult = frmICPtr->GetResult();
113                                                         
114                         // Clean up before processing response.
115                                 
116                         delete frmICPtr;
117                         frmICPtr = NULL;
118                                                 
119                         // Process the response from the user.
120                                                         
121                         if (SSLResult == 1){
122                                                                 
123                                 // Accept the Certificate.
125                                 CDavObj.AllowSelfSignTest(TRUE);
126                                                                 
127                         } else if (SSLResult == 2){
128                                                                 
129                                 // Reject the certificate, abort the task and mark as failed.
131                                 wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
132                                 return;
133                                                                 
134                         }
135                                 
137                 } else {
139                         // Something else happened. Stop the process and
140                         // display an error message instead.
142                         wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR);
143                         return;
145                 }
147         }
148         
149         // Attempt to extract the CardDAV address.
150         
151         wxString ABURL = CDavObj.GetDefaultAddressBookURL();
152         
153         txtPrefix->SetValue(ABURL);
154         
157 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
159         // Setup the account configuration file pointer.
160         
161         cfgfile = cfgin;
165 void frmEditAccount::LoadSettings( wxString AccNameIn ){
167         // Get the data from the accounts settings file and
168         // fill in the account fields.
170         AccName = AccNameIn;
171         long itemindex = 0;
172         bool ContinueAcc = TRUE;
173         wxString AccountName;
174         wxString AccountData;
176         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
178         while (ContinueAcc){
180                 if (AccountName == AccName){
182                         cfgfile->SetPath(AccountName);
183                         txtAccountName->SetValue(AccountName);
185                         cfgfile->Read("address", &AccountData);
186                         txtAddress->SetValue(AccountData);
188                         cfgfile->Read("port", &AccountData);
189                         txtPort->SetValue(AccountData);
191                         cfgfile->Read("username", &AccountData);
192                         txtUsername->SetValue(AccountData);
194                         cfgfile->Read("password", &AccountData);
195                         txtPassword->SetValue(AccountData);
197                         cfgfile->Read("prefix", &AccountData);
198                         txtPrefix->SetValue(AccountData);
200                         cfgfile->Read("ssl", &AccountData);
201                         if (AccountData == wxT("true")){
202                         
203                                 chkSSL->SetValue(TRUE);
204                         
205                         }
206                         
207                         cfgfile->Read("refresh", &AccountData);
208                         txtRefresh->SetValue(AccountData);
209                         
210                         break;
212                 }
213                 
214                 cfgfile->SetPath(wxT("/"));
215                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
217         }
221 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
224         // Update the settings for the account.
226         long itemindex = 0;
227         bool ContinueAcc = TRUE;
228         wxString AccountName;
230         // Look for the account
231         
232         while (ContinueAcc){
234                 if (AccountName == AccName){
236                         // Update the settings for the account.
238                         cfgfile->RenameGroup(AccountName, txtAccountName->GetValue());
240                         cfgfile->SetPath(txtAccountName->GetValue());
241                         //txtAccountName->SetValue(AccountName);
242                         
243                         cfgfile->DeleteEntry(wxT("address"), FALSE);
244                         cfgfile->Write(wxT("address"), txtAddress->GetValue());
246                         cfgfile->DeleteEntry(wxT("port"), FALSE);
247                         cfgfile->Write(wxT("port"), txtPort->GetValue());
249                         cfgfile->DeleteEntry(wxT("username"), FALSE);
250                         cfgfile->Write(wxT("username"), txtUsername->GetValue());
252                         cfgfile->DeleteEntry(wxT("password"), FALSE);
253                         cfgfile->Write(wxT("password"), txtPassword->GetValue());
255                         cfgfile->DeleteEntry(wxT("prefix"), FALSE);
256                         cfgfile->Write(wxT("prefix"), txtPrefix->GetValue());
258                         cfgfile->DeleteEntry(wxT("ssl"), FALSE);
260                         if (chkSSL->GetValue() == TRUE){
261                         
262                                 cfgfile->Write(wxT("ssl"), wxT("true"));
263                         
264                         } else {
265                         
266                                 cfgfile->Write(wxT("ssl"), wxT("false"));
267                         
268                         }
270                         cfgfile->DeleteEntry(wxT("refresh"), FALSE);
271                         cfgfile->Write(wxT("refresh"), txtRefresh->GetValue());
273                         break;
275                 }
276                 
277                 cfgfile->SetPath(wxT("/"));
278                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
280         }
282         // Set the dialog result to true and close the window.
283         
284         DialogResult = true;    
285         this->Close();  
289 void frmEditAccount::CloseWindow( wxCommandEvent& event )
291         
292         // Set the dialog result to false and close the window.
293         
294         DialogResult = false;
295         this->Close();
296         
299 bool frmEditAccount::GetDialogResult(){
301         // Get the result of the dialog.
302         
303         return DialogResult;
304         
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