Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
faea105f49e090a5ae95d09eca19dbc073100829
[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         std::string ReceivedServerPrefix = "";
35         
36         long PortNum = 80;
37         ValueData = txtPort->GetValue();
38         ValueData.ToLong(&PortNum, 10);
39         long RefreshNum = 1800;
40         ValueData = txtRefresh->GetValue();
41         ValueData.ToLong(&RefreshNum, 10);
42         bool UseSSL = true;
43         bool UsingSSLBypass = false;
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         }
81         CardDAV2 TestConnection(txtAddress->GetValue().ToStdString(),
82                 wxAtoi(txtPort->GetValue()),
83                 txtUsername->GetValue().ToStdString(),
84                 txtPassword->GetValue().ToStdString(),
85                 chkSSL->GetValue());
86         
87         // Test the connection.
88         
89         TestConnection.SetupConnectionObject();
90         COConnectResult TestConnectionResult = TestConnection.Connect(false);
91         
92         // If server is using SSL, verify that the SSL connection is valid.
93         
94         if (TestConnection.SSLVerify() == COSSL_UNABLETOVERIFY){
95 #if defined(__APPLE__)
96 #elif defined(__WIN32__)
97 #else
98         
99                 // Connect again and fetch SSL certificate information.
100                 
101                 TestConnection.BypassSSLVerification(true);
102                 
103                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
104                 
105                 TestConnection.BypassSSLVerification(false);
107                 SSLCertCollectionString CertData = TestConnection.BuildSSLCollection();
108                 frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
109                 
110                 frmICPtr->LoadDataNew(CertData, txtAddress->GetValue().ToStdString());
111                 frmICPtr->ShowModal();
112                                                                 
113                 int SSLResult = frmICPtr->GetResult();
114                                                         
115                 // Clean up before processing response.
116                                 
117                 delete frmICPtr;
118                 frmICPtr = NULL;
119                                                         
120                 // Process the response from the user.
121                                                         
122                 if (SSLResult == 1){
123                                                                 
124                         // Accept the Certificate.
125                         
126                         UsingSSLBypass = true;
127                         TestConnection.BypassSSLVerification(true);
128                 
129                         COConnectResult TestConnectionResult = TestConnection.Connect(true);
130                 
131                         TestConnection.BypassSSLVerification(false);
132                                                                 
133                 } else if (SSLResult == 2){
134                                                                 
135                         // Reject the certificate, abort the task.
137                         wxMessageBox(_("Server certficiate rejected. Unable to detect the prefix."), _("Failed"), wxOK+wxICON_ERROR);
138                         
139                         return; 
140                         
141                 }               
142                 
143 #endif
144         }
145         
146         // Get the server prefix if the connection was successful.
147         
148         if (TestConnectionResult == COCONNECT_OK){
150                 if (UsingSSLBypass == true){
151                         TestConnection.BypassSSLVerification(true);                     
152                 }
153                 
154                 COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix);
156                 if (UsingSSLBypass == true){
157                         TestConnection.BypassSSLVerification(true);                     
158                 }
159                 
160         } else {
161                 
162                 wxMessageBox(_("An error occured whilst detecting the prefix: ") + TestConnection.GetErrorMessage(), _("Failed"), wxOK+wxICON_ERROR);
163                 
164         }
165         
166         txtPrefix->SetValue(ReceivedServerPrefix);
167         
170 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
172         // Setup the account configuration file pointer.
173         
174         cfgfile = cfgin;
178 void frmEditAccount::LoadSettings( wxString AccNameIn ){
180         // Get the data from the accounts settings file and
181         // fill in the account fields.
183         AccName = AccNameIn;
184         long itemindex = 0;
185         bool ContinueAcc = TRUE;
186         wxString AccountName;
187         wxString AccountData;
188         
189         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
190         
191         while (ContinueAcc){
193                 if (AccountName == AccName){
195                         cfgfile->SetPath(AccountName);
196                         txtAccountName->SetValue(AccountName);
198                         cfgfile->Read("address", &AccountData);
199                         txtAddress->SetValue(AccountData);
201                         cfgfile->Read("port", &AccountData);
202                         txtPort->SetValue(AccountData);
204                         cfgfile->Read("username", &AccountData);
205                         txtUsername->SetValue(AccountData);
207                         cfgfile->Read("password", &AccountData);
208                         txtPassword->SetValue(AccountData);
210                         cfgfile->Read("prefix", &AccountData);
211                         txtPrefix->SetValue(AccountData);
213                         cfgfile->Read("ssl", &AccountData);
214                         if (AccountData == wxT("true")){
215                         
216                                 chkSSL->SetValue(TRUE);
217                         
218                         }
219                         
220                         cfgfile->Read("refresh", &AccountData);
221                         txtRefresh->SetValue(AccountData);
222                         
223                         break;
225                 }
226                 
227                 cfgfile->SetPath(wxT("/"));
228                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
230         }
234 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
237         // Check if server address matches against the blacklist.
238         // Bring up warning message if it does.
239         
240         if (CheckBlacklist(txtAddress->GetValue())){
241                 
242                 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);
243                 
244                 if (MessageBoxResult == wxNO){
245                         return;
246                 }
247                         
248         }
249         
250         // Update the settings for the account.
252         long itemindex = 0;
253         bool ContinueAcc = TRUE;
254         wxString AccountName;
256         // Look for the account
257         
258         while (ContinueAcc){
260                 if (AccountName == AccName){
262                         // Update the settings for the account.
264                         cfgfile->RenameGroup(AccountName, txtAccountName->GetValue());
266                         cfgfile->SetPath(txtAccountName->GetValue());
267                         //txtAccountName->SetValue(AccountName);
268                         
269                         cfgfile->DeleteEntry(wxT("address"), FALSE);
270                         cfgfile->Write(wxT("address"), txtAddress->GetValue());
272                         cfgfile->DeleteEntry(wxT("port"), FALSE);
273                         cfgfile->Write(wxT("port"), txtPort->GetValue());
275                         cfgfile->DeleteEntry(wxT("username"), FALSE);
276                         cfgfile->Write(wxT("username"), txtUsername->GetValue());
278                         cfgfile->DeleteEntry(wxT("password"), FALSE);
279                         cfgfile->Write(wxT("password"), txtPassword->GetValue());
281                         cfgfile->DeleteEntry(wxT("prefix"), FALSE);
282                         cfgfile->Write(wxT("prefix"), txtPrefix->GetValue());
284                         cfgfile->DeleteEntry(wxT("ssl"), FALSE);
286                         if (chkSSL->GetValue() == TRUE){
287                         
288                                 cfgfile->Write(wxT("ssl"), wxT("true"));
289                         
290                         } else {
291                         
292                                 cfgfile->Write(wxT("ssl"), wxT("false"));
293                         
294                         }
296                         cfgfile->DeleteEntry(wxT("refresh"), FALSE);
297                         cfgfile->Write(wxT("refresh"), txtRefresh->GetValue());
299                         break;
301                 }
302                 
303                 cfgfile->SetPath(wxT("/"));
304                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
306         }
308         // Set the dialog result to true and close the window.
309         
310         DialogResult = true;    
311         this->Close();  
315 void frmEditAccount::CloseWindow( wxCommandEvent& event )
317         
318         // Set the dialog result to false and close the window.
319         
320         DialogResult = false;
321         this->Close();
322         
325 bool frmEditAccount::GetDialogResult(){
327         // Get the result of the dialog.
328         
329         return DialogResult;
330         
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