5 #include <wx/fileconf.h>
7 #include "preferences.h"
11 void SavePreferences();
12 void LoadPreferences();
14 XABPreferences::XABPreferences(wxString PreferencesFilename){
17 wxString fullprefpath;
19 bool accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
20 accountsslvalid, accountusernamevalid, accountpasswordvalid,
21 accountdirprefixvalid, accountdirvalid, accountrefreshvalid = FALSE;
23 bool preaccountstage = FALSE;
24 bool isvalidaccount = FALSE;
25 bool isvalidsection = FALSE;
27 wxString accountaddress;
29 long accountport = 8080;
32 wxString accountusername;
33 wxString accountpassword;
34 wxString accountdirprefix;
41 wxString segmentvalue;
45 fullprefpath.Append(PreferencesFilename);
46 fullprefpath.Append(wxT("settings"));
48 wxFileConfig *settingfile = new wxFileConfig("", "", fullprefpath);
51 settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
53 if (ValueInc == wxT("true")){
56 wxRect WindowPosition;
58 long PosX, PosY, PosH, PosW = 0;
60 bool PosXValid, PosYValid, PosHValid, PosWValid = FALSE;
62 PosXValid = settingfile->Read(wxT("WindowPositionX"), &PosX);
63 PosYValid = settingfile->Read(wxT("WindowPositionY"), &PosY);
64 PosHValid = settingfile->Read(wxT("WindowPositionHeight"), &PosH);
65 PosWValid = settingfile->Read(wxT("WindowPositionWidth"), &PosW);
67 if (PosXValid == TRUE && PosYValid == TRUE && PosHValid == TRUE && PosWValid == TRUE){
69 WindowPosition.SetX((int)PosX);
70 WindowPosition.SetY((int)PosY);
71 WindowPosition.SetHeight((int)PosH);
72 WindowPosition.SetWidth((int)PosW);
76 WindowPosition.SetX(-1);
77 WindowPosition.SetY(-1);
78 WindowPosition.SetHeight(500);
79 WindowPosition.SetWidth(300);
83 SetMainWindowData(WindowPosition);
87 settingfile->Read(wxT("HideLocalAddressBooks"), &ValueInc);
89 if (ValueInc == wxT("true")){
99 fullprefpath.Append(PreferencesFilename);
100 fullprefpath.Append(wxT("accounts"));
102 wxFileConfig *cfgfile = new wxFileConfig("AddressBook", "Xestia", fullprefpath);
104 wxString EntryName, EntryValue;
105 wxString AccAdr, AccUsr, AccPass, AccPrefix, AccDir;
108 int AccRef, AccPort = 0;
110 bool ContinueAcc = TRUE;
112 ContinueAcc = cfgfile->GetFirstGroup(accountname, itemindex);
116 cfgfile->SetPath(accountname);
117 //ContinueProc = cfgfile->GetFirstEntry(EntryName, subitemindex);
118 cfgfile->Read(wxT("type"), &EntryValue);
120 if (EntryValue == wxT("Local")){
122 // Get the account directory.
124 cfgfile->Read(wxT("accountdir"), &AccDir);
126 if (AccDir.Len() > 4){
128 accountdirvalid = TRUE;
132 accountdirvalid = FALSE;
136 if (accountdirvalid == TRUE){
138 accounts.AddAccount(accountname, wxT("Local"), wxT(""), 0,
144 } else if (EntryValue == wxT("CardDAV")){
146 cfgfile->Read(wxT("accountdir"), &AccDir);
147 accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
148 accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
149 accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
150 if (AccSSLInc == wxT("true")){
153 accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
154 accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
155 accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
156 accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
158 if (AccDir.Len() > 4){
160 accountdirvalid = TRUE;
164 // Make sure it is not bigger than 65535 or less than 1.
165 // If so, default to port 8008.
167 if (accountport < 1 || accountport > 65535){
169 accountportvalid = TRUE;
172 accounts.AddAccount(accountname, wxT("CardDAV"), AccAdr, AccPort,
173 AccSSL, AccUsr, AccPass,
174 AccPrefix, AccDir, AccRef);
178 // Clear up for the next account.
180 accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
181 accountsslvalid, accountusernamevalid, accountpasswordvalid,
182 accountdirprefixvalid, accountdirvalid, accountrefreshvalid, accountssl,
183 isvalidaccount, isvalidsection = FALSE;
191 accountaddress.Clear();
195 accountusername.Clear();
196 accountpassword.Clear();
197 accountdirprefix.Clear();
198 preaccountstage = TRUE;
200 cfgfile->SetPath(wxT("/"));
201 ContinueAcc = cfgfile->GetNextGroup(accountname, itemindex);
207 XABPreferences::~XABPreferences(){
211 bool XABPreferences::GetBoolData(wxString SettingName){
213 if (SettingName == wxT("SaveWindowPosition")) { return SaveWindowPos; }
214 else if (SettingName == wxT("HideLocalAddressBooks")) { return HideLocalABs; }
220 wxRect XABPreferences::GetMainWindowData(){
222 return MainWindowData;
226 void XABPreferences::SetMainWindowData(wxRect WindowData){
228 MainWindowData = WindowData;
234 XABPrefAccounts::XABPrefAccounts(){
238 int XABPrefAccounts::AddAccount(wxString NewAccName,
240 wxString NewAccAddress,
245 wxString NewAccDirPrefix,
250 AccountName.Add(NewAccName, 1);
251 AccountType.Add(NewAccType, 1);
252 AccountAddress.Add(NewAccAddress, 1);
253 AccountPort.Add(NewAccPort, 1);
254 AccountSSL.Add(NewAccSSL, 1);
255 AccountUsername.Add(NewAccUser, 1);
256 AccountPassword.Add(NewAccPass, 1);
257 DirectoryPrefix.Add(NewAccDirPrefix, 1);
258 AccountDirectory.Add(NewAccDir, 1);
259 AccountRefresh.Add(NewAccRefresh, 1);
267 int XABPrefAccounts::GetCount(){
269 return AccountsCount;
273 wxString XABPrefAccounts::GetAccountName(int AccountNum){
275 if (AccountNum > AccountsCount){
279 return AccountName[AccountNum];
283 wxString XABPrefAccounts::GetAccountType(int AccountNum){
285 if (AccountNum > AccountsCount){
289 return AccountType[AccountNum];
293 wxString XABPrefAccounts::GetAccountAddress(int AccountNum){
295 if (AccountNum > AccountsCount){
299 return AccountAddress[AccountNum];
303 int XABPrefAccounts::GetAccountPort(int AccountNum){
305 if (AccountNum > AccountsCount){
309 return AccountPort[AccountNum];
313 bool XABPrefAccounts::GetAccountSSL(int AccountNum){
315 if (AccountNum > AccountsCount){
319 return AccountSSL[AccountNum];
323 wxString XABPrefAccounts::GetAccountUsername(int AccountNum){
325 if (AccountNum > AccountsCount){
329 return AccountUsername[AccountNum];
333 wxString XABPrefAccounts::GetAccountPassword(int AccountNum){
335 if (AccountNum > AccountsCount){
339 return AccountPassword[AccountNum];
343 wxString XABPrefAccounts::GetAccountDirectory(int AccountNum){
345 if (AccountNum > AccountsCount){
349 return AccountDirectory[AccountNum];
353 wxString XABPrefAccounts::GetAccountDirPrefix(int AccountNum){
355 if (AccountNum > AccountsCount){
359 return DirectoryPrefix[AccountNum];
363 long XABPrefAccounts::GetAccountRefresh(int AccountNum){
365 if (AccountNum > AccountsCount){
369 return AccountRefresh[AccountNum];