1 // frmEditAccount.cpp - Edit Account form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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 )
24 frmEditAccountADT( parent )
29 void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
32 // Check data before connecting.
37 ValueData = txtPort->GetValue();
38 ValueData.ToLong(&PortNum, 10);
40 ValueData = txtRefresh->GetValue();
41 ValueData.ToLong(&RefreshNum, 10);
44 if (txtAddress->IsEmpty()){
46 wxMessageBox(wxT("The server address cannot be blank."), wxT("Error"), wxICON_ERROR);
51 if (txtPort->IsEmpty() || PortNum < 0 || PortNum > 65535){
53 wxMessageBox(wxT("The server port needs to be between number 1 and 65535."), wxT("Error"), wxICON_ERROR);
58 if (txtUsername->IsEmpty()){
60 wxMessageBox(wxT("The server username cannot be blank."), wxT("Error"), wxICON_ERROR);
65 if (txtPassword->IsEmpty()){
67 wxMessageBox(wxT("The server password cannot be blank."), wxT("Error"), wxICON_ERROR);
72 UseSSL = chkSSL->GetValue();
74 if (txtRefresh->IsEmpty() || RefreshNum < 300 || RefreshNum > 86400){
80 // Setup a CardDAV object.
84 CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
86 // Attempt to extract the CardDAV address.
88 wxString ABURL = CDavObj.GetDefaultAddressBookURL();
90 txtPrefix->SetValue(ABURL);
94 void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){
100 void frmEditAccount::LoadSettings( wxString AccNameIn ){
102 // Get the data from the accounts settings file.
106 bool ContinueAcc = TRUE;
107 wxString AccountName;
108 wxString AccountData;
110 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
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")){
137 chkSSL->SetValue(TRUE);
141 cfgfile->Read("refresh", &AccountData);
142 txtRefresh->SetValue(AccountData);
148 cfgfile->SetPath(wxT("/"));
149 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
155 void frmEditAccount::UpdateSettings( wxCommandEvent& event )
158 // Update the settings for the account.
161 bool ContinueAcc = TRUE;
162 wxString AccountName;
164 // Look for the account
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);
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){
196 cfgfile->Write(wxT("ssl"), wxT("true"));
200 cfgfile->Write(wxT("ssl"), wxT("false"));
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")){
225 chkSSL->SetValue(TRUE);
229 cfgfile->Read("refresh", &AccountData);
230 //txtRefresh->SetValue(AccountData);*/
237 cfgfile->SetPath(wxT("/"));
238 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
246 void frmEditAccount::CloseWindow( wxCommandEvent& event )