Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Set DialogResult when an option is selected and fetch with GetDialogResult
[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 "carddav/carddav.h"
22 frmEditAccount::frmEditAccount( wxWindow* parent )
23 :
24 frmEditAccountADT( parent )
25 {
27 }
29 void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
30 {
32         // Check data before connecting.
34         wxString ValueData;
35         
36         long PortNum;
37         ValueData = txtPort->GetValue();
38         ValueData.ToLong(&PortNum, 10);
39         long RefreshNum;
40         ValueData = txtRefresh->GetValue();
41         ValueData.ToLong(&RefreshNum, 10);
42         bool UseSSL;
43         
44         if (txtAddress->IsEmpty()){
45         
46                 wxMessageBox(wxT("The server address cannot be blank."), wxT("Error"), wxICON_ERROR);
47                 return;
48         
49         }
50         
51         if (txtPort->IsEmpty() || PortNum < 0 || PortNum > 65535){
52         
53                 wxMessageBox(wxT("The server port needs to be between number 1 and 65535."), wxT("Error"), wxICON_ERROR);
54                 return;
55         
56         }
57         
58         if (txtUsername->IsEmpty()){
59         
60                 wxMessageBox(wxT("The server username cannot be blank."), wxT("Error"), wxICON_ERROR);
61                 return;
62         
63         }
65         if (txtPassword->IsEmpty()){
66         
67                 wxMessageBox(wxT("The server password cannot be blank."), wxT("Error"), wxICON_ERROR);  
68                 return;
69         
70         }
71         
72         UseSSL = chkSSL->GetValue();
73         
74         if (txtRefresh->IsEmpty() || RefreshNum < 300 || RefreshNum > 86400){
75         
76                 RefreshNum = 1800;
77                 
78         }
79         
80         // Setup a CardDAV object.
81         
82         CardDAV CDavObj;
83         
84         CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
85         
86         // Attempt to extract the CardDAV address.
87         
88         wxString ABURL = CDavObj.GetDefaultAddressBookURL();
89         
90         txtPrefix->SetValue(ABURL);
91         
92 }
94 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
96         cfgfile = cfgin;
98 }
100 void frmEditAccount::LoadSettings( wxString AccNameIn ){
102         // Get the data from the accounts settings file.
104         AccName = AccNameIn;
105         long itemindex = 0;
106         bool ContinueAcc = TRUE;
107         wxString AccountName;
108         wxString AccountData;
110         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
112         while (ContinueAcc){
114                 if (AccountName == AccName){
116                         cfgfile->SetPath(AccountName);
117                         txtAccountName->SetValue(AccountName);
119                         cfgfile->Read("address", &AccountData);
120                         txtAddress->SetValue(AccountData);
122                         cfgfile->Read("port", &AccountData);
123                         txtPort->SetValue(AccountData);
125                         cfgfile->Read("username", &AccountData);
126                         txtUsername->SetValue(AccountData);
128                         cfgfile->Read("password", &AccountData);
129                         txtPassword->SetValue(AccountData);
131                         cfgfile->Read("prefix", &AccountData);
132                         txtPrefix->SetValue(AccountData);
134                         cfgfile->Read("ssl", &AccountData);
135                         if (AccountData == wxT("true")){
136                         
137                                 chkSSL->SetValue(TRUE);
138                         
139                         }
140                         
141                         cfgfile->Read("refresh", &AccountData);
142                         txtRefresh->SetValue(AccountData);
143                         
144                         break;
146                 }
147                 
148                 cfgfile->SetPath(wxT("/"));
149                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
151         }
155 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
158         // Update the settings for the account.
160         long itemindex = 0;
161         bool ContinueAcc = TRUE;
162         wxString AccountName;
164         // Look for the account
165         
166         while (ContinueAcc){
168                 if (AccountName == AccName){
170                         // Update the settings for the account.
172                         cfgfile->RenameGroup(AccountName, txtAccountName->GetValue());
174                         cfgfile->SetPath(txtAccountName->GetValue());
175                         //txtAccountName->SetValue(AccountName);
176                         
177                         cfgfile->DeleteEntry(wxT("address"), FALSE);
178                         cfgfile->Write(wxT("address"), txtAddress->GetValue());
180                         cfgfile->DeleteEntry(wxT("port"), FALSE);
181                         cfgfile->Write(wxT("port"), txtPort->GetValue());
183                         cfgfile->DeleteEntry(wxT("username"), FALSE);
184                         cfgfile->Write(wxT("username"), txtUsername->GetValue());
186                         cfgfile->DeleteEntry(wxT("password"), FALSE);
187                         cfgfile->Write(wxT("password"), txtPassword->GetValue());
189                         cfgfile->DeleteEntry(wxT("prefix"), FALSE);
190                         cfgfile->Write(wxT("prefix"), txtPrefix->GetValue());
192                         cfgfile->DeleteEntry(wxT("ssl"), FALSE);
194                         if (chkSSL->GetValue() == TRUE){
195                         
196                                 cfgfile->Write(wxT("ssl"), wxT("true"));
197                         
198                         } else {
199                         
200                                 cfgfile->Write(wxT("ssl"), wxT("false"));
201                         
202                         }
204                         cfgfile->DeleteEntry(wxT("refresh"), FALSE);
205                         cfgfile->Write(wxT("refresh"), txtRefresh->GetValue());
207                         /*cfgfile->Read("address", &AccountData);
208                         //txtAddress->SetValue(AccountData);
210                         cfgfile->Read("port", &AccountData);
211                         //txtPort->SetValue(AccountData);
213                         cfgfile->Read("username", &AccountData);
214                         //txtUsername->SetValue(AccountData);
216                         cfgfile->Read("password", &AccountData);
217                         //txtPassword->SetValue(AccountData);
219                         cfgfile->Read("prefix", &AccountData);
220                         //txtPrefix->SetValue(AccountData);
222                         cfgfile->Read("ssl", &AccountData);
223                         if (AccountData == wxT("true")){
224                         
225                                 chkSSL->SetValue(TRUE);
226                         
227                         }
228                         
229                         cfgfile->Read("refresh", &AccountData);
230                         //txtRefresh->SetValue(AccountData);*/
232                         
233                         break;
235                 }
236                 
237                 cfgfile->SetPath(wxT("/"));
238                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
240         }
242         DialogResult = true;    
243         this->Close();  
247 void frmEditAccount::CloseWindow( wxCommandEvent& event )
249         DialogResult = false;
250         this->Close();
253 bool frmEditAccount::GetDialogResult(){
254         
255         return DialogResult;
256         
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