1 #include "frmEditAccount.h"
2 #include "carddav/carddav.h"
4 frmEditAccount::frmEditAccount( wxWindow* parent )
6 frmEditAccountADT( parent )
11 void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
14 // Check data before connecting.
19 ValueData = txtPort->GetValue();
20 ValueData.ToLong(&PortNum, 10);
22 ValueData = txtRefresh->GetValue();
23 ValueData.ToLong(&RefreshNum, 10);
26 if (txtAddress->IsEmpty()){
28 wxMessageBox(wxT("The server address cannot be blank."), wxT("Error"), wxICON_ERROR);
33 if (txtPort->IsEmpty() || PortNum < 0 || PortNum > 65535){
35 wxMessageBox(wxT("The server port needs to be between number 1 and 65535."), wxT("Error"), wxICON_ERROR);
40 if (txtUsername->IsEmpty()){
42 wxMessageBox(wxT("The server username cannot be blank."), wxT("Error"), wxICON_ERROR);
47 if (txtPassword->IsEmpty()){
49 wxMessageBox(wxT("The server password cannot be blank."), wxT("Error"), wxICON_ERROR);
54 UseSSL = chkSSL->GetValue();
56 if (txtRefresh->IsEmpty() || RefreshNum < 300 || RefreshNum > 86400){
62 // Setup a CardDAV object.
66 CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
68 // Attempt to extract the CardDAV address.
70 wxString ABURL = CDavObj.GetDefaultAddressBookURL();
72 txtPrefix->SetValue(ABURL);
76 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
82 void frmEditAccount::LoadSettings( wxString AccNameIn ){
84 // Get the data from the accounts settings file.
88 bool ContinueAcc = TRUE;
92 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
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")){
119 chkSSL->SetValue(TRUE);
123 cfgfile->Read("refresh", &AccountData);
124 txtRefresh->SetValue(AccountData);
130 cfgfile->SetPath(wxT("/"));
131 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
137 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
140 // Update the settings for the account.
143 bool ContinueAcc = TRUE;
144 wxString AccountName;
146 // Look for the account
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);
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){
178 cfgfile->Write(wxT("ssl"), wxT("true"));
182 cfgfile->Write(wxT("ssl"), wxT("false"));
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")){
207 chkSSL->SetValue(TRUE);
211 cfgfile->Read("refresh", &AccountData);
212 //txtRefresh->SetValue(AccountData);*/
219 cfgfile->SetPath(wxT("/"));
220 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
228 void frmEditAccount::CloseWindow( wxCommandEvent& event )