Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added #include <rpc.h> to Win32 section.
[xestiaab/.git] / source / frmEditAccount.cpp
1 #include "frmEditAccount.h"
2 #include "carddav/carddav.h"
4 frmEditAccount::frmEditAccount( wxWindow* parent )
5 :
6 frmEditAccountADT( parent )
7 {
9 }
11 void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
12 {
14         // Check data before connecting.
16         wxString ValueData;
17         
18         long PortNum;
19         ValueData = txtPort->GetValue();
20         ValueData.ToLong(&PortNum, 10);
21         long RefreshNum;
22         ValueData = txtRefresh->GetValue();
23         ValueData.ToLong(&RefreshNum, 10);
24         bool UseSSL;
25         
26         if (txtAddress->IsEmpty()){
27         
28                 wxMessageBox(wxT("The server address cannot be blank."), wxT("Error"), wxICON_ERROR);
29                 return;
30         
31         }
32         
33         if (txtPort->IsEmpty() || PortNum < 0 || PortNum > 65535){
34         
35                 wxMessageBox(wxT("The server port needs to be between number 1 and 65535."), wxT("Error"), wxICON_ERROR);
36                 return;
37         
38         }
39         
40         if (txtUsername->IsEmpty()){
41         
42                 wxMessageBox(wxT("The server username cannot be blank."), wxT("Error"), wxICON_ERROR);
43                 return;
44         
45         }
47         if (txtPassword->IsEmpty()){
48         
49                 wxMessageBox(wxT("The server password cannot be blank."), wxT("Error"), wxICON_ERROR);  
50                 return;
51         
52         }
53         
54         UseSSL = chkSSL->GetValue();
55         
56         if (txtRefresh->IsEmpty() || RefreshNum < 300 || RefreshNum > 86400){
57         
58                 RefreshNum = 1800;
59                 
60         }
61         
62         // Setup a CardDAV object.
63         
64         CardDAV CDavObj;
65         
66         CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
67         
68         // Attempt to extract the CardDAV address.
69         
70         wxString ABURL = CDavObj.GetDefaultAddressBookURL();
71         
72         txtPrefix->SetValue(ABURL);
73         
74 }
76 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
78         cfgfile = cfgin;
80 }
82 void frmEditAccount::LoadSettings( wxString AccNameIn ){
84         // Get the data from the accounts settings file.
86         AccName = AccNameIn;
87         long itemindex = 0;
88         bool ContinueAcc = TRUE;
89         wxString AccountName;
90         wxString AccountData;
92         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
94         while (ContinueAcc){
96                 if (AccountName == AccName){
98                         cfgfile->SetPath(AccountName);
99                         txtAccountName->SetValue(AccountName);
101                         cfgfile->Read("address", &AccountData);
102                         txtAddress->SetValue(AccountData);
104                         cfgfile->Read("port", &AccountData);
105                         txtPort->SetValue(AccountData);
107                         cfgfile->Read("username", &AccountData);
108                         txtUsername->SetValue(AccountData);
110                         cfgfile->Read("password", &AccountData);
111                         txtPassword->SetValue(AccountData);
113                         cfgfile->Read("prefix", &AccountData);
114                         txtPrefix->SetValue(AccountData);
116                         cfgfile->Read("ssl", &AccountData);
117                         if (AccountData == wxT("true")){
118                         
119                                 chkSSL->SetValue(TRUE);
120                         
121                         }
122                         
123                         cfgfile->Read("refresh", &AccountData);
124                         txtRefresh->SetValue(AccountData);
125                         
126                         break;
128                 }
129                 
130                 cfgfile->SetPath(wxT("/"));
131                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
133         }
137 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
140         // Update the settings for the account.
142         long itemindex = 0;
143         bool ContinueAcc = TRUE;
144         wxString AccountName;
146         // Look for the account
147         
148         while (ContinueAcc){
150                 if (AccountName == AccName){
152                         // Update the settings for the account.
154                         cfgfile->RenameGroup(AccountName, txtAccountName->GetValue());
156                         cfgfile->SetPath(txtAccountName->GetValue());
157                         //txtAccountName->SetValue(AccountName);
158                         
159                         cfgfile->DeleteEntry(wxT("address"), FALSE);
160                         cfgfile->Write(wxT("address"), txtAddress->GetValue());
162                         cfgfile->DeleteEntry(wxT("port"), FALSE);
163                         cfgfile->Write(wxT("port"), txtPort->GetValue());
165                         cfgfile->DeleteEntry(wxT("username"), FALSE);
166                         cfgfile->Write(wxT("username"), txtUsername->GetValue());
168                         cfgfile->DeleteEntry(wxT("password"), FALSE);
169                         cfgfile->Write(wxT("password"), txtPassword->GetValue());
171                         cfgfile->DeleteEntry(wxT("prefix"), FALSE);
172                         cfgfile->Write(wxT("prefix"), txtPrefix->GetValue());
174                         cfgfile->DeleteEntry(wxT("ssl"), FALSE);
176                         if (chkSSL->GetValue() == TRUE){
177                         
178                                 cfgfile->Write(wxT("ssl"), wxT("true"));
179                         
180                         } else {
181                         
182                                 cfgfile->Write(wxT("ssl"), wxT("false"));
183                         
184                         }
186                         cfgfile->DeleteEntry(wxT("refresh"), FALSE);
187                         cfgfile->Write(wxT("refresh"), txtRefresh->GetValue());
189                         /*cfgfile->Read("address", &AccountData);
190                         //txtAddress->SetValue(AccountData);
192                         cfgfile->Read("port", &AccountData);
193                         //txtPort->SetValue(AccountData);
195                         cfgfile->Read("username", &AccountData);
196                         //txtUsername->SetValue(AccountData);
198                         cfgfile->Read("password", &AccountData);
199                         //txtPassword->SetValue(AccountData);
201                         cfgfile->Read("prefix", &AccountData);
202                         //txtPrefix->SetValue(AccountData);
204                         cfgfile->Read("ssl", &AccountData);
205                         if (AccountData == wxT("true")){
206                         
207                                 chkSSL->SetValue(TRUE);
208                         
209                         }
210                         
211                         cfgfile->Read("refresh", &AccountData);
212                         //txtRefresh->SetValue(AccountData);*/
214                         
215                         break;
217                 }
218                 
219                 cfgfile->SetPath(wxT("/"));
220                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
222         }
223         
224         this->Close();  
228 void frmEditAccount::CloseWindow( wxCommandEvent& event )
230         this->Close();
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