Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / common / preferences.cpp
1 #include <iostream>
2 #include <iomanip>
3 #include <ios>
4 #include <string>
5 #include <wx/fileconf.h>
7 #include "preferences.h"
9 using namespace std;
11 void SavePreferences();
12 void LoadPreferences();
14 XABPreferences::XABPreferences(wxString PreferencesFilename){
15     
16     //fstream preffile;
17     wxString fullprefpath;
18     
19     int accountnum = 0;
20     
21     bool accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
22          accountsslvalid, accountusernamevalid, accountpasswordvalid,
23          accountdirprefixvalid, accountdirvalid, accountrefreshvalid = FALSE;
24     
25     bool preaccountstage = FALSE;
26     bool isvalidaccount = FALSE;
27     bool isvalidsection = FALSE;
28     wxString accountname;
29     wxString accountaddress;
30     wxString accounttype;
31     long accountport = 8080;
32     long accountrefresh;
33     bool accountssl;
34     wxString accountusername;
35     wxString accountpassword;
36     wxString accountdirprefix;
37     wxString accountdir;
38     
39     wxString firstchar;
40     string s;
42     wxString segmentname;
43     wxString segmentvalue;
44     
45     // Load the settings.
46     
47     fullprefpath.Append(PreferencesFilename);
48     fullprefpath.Append(wxT("settings"));
50     wxFileConfig *settingfile = new wxFileConfig("", "", fullprefpath);
51     
52     wxString ValueInc;
53     settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
54     
55     if (ValueInc == wxT("true")){
56                 
57                 SaveWindowPos = TRUE;
58                 wxRect WindowPosition;
59         
60                 long PosX, PosY, PosH, PosW = 0;
62                 bool PosXValid, PosYValid, PosHValid, PosWValid = FALSE;
64                 PosXValid = settingfile->Read(wxT("WindowPositionX"), &PosX);
65                 PosYValid = settingfile->Read(wxT("WindowPositionY"), &PosY);
66                 PosHValid = settingfile->Read(wxT("WindowPositionHeight"), &PosH);
67                 PosWValid = settingfile->Read(wxT("WindowPositionWidth"), &PosW);
69                 if (PosXValid == TRUE && PosYValid == TRUE && PosHValid == TRUE && PosWValid == TRUE){
71                         WindowPosition.SetX(PosX);
72                         WindowPosition.SetY(PosY);
73                         WindowPosition.SetHeight(PosH);
74                         WindowPosition.SetWidth(PosW);
76                 } else {
78                         WindowPosition.SetX(-1);
79                         WindowPosition.SetY(-1);
80                         WindowPosition.SetHeight(500);
81                         WindowPosition.SetWidth(300);
83                 }
85                 SetMainWindowData(WindowPosition);
86         
87     }
89     settingfile->Read(wxT("HideLocalAddressBooks"), &ValueInc);
90     
91     if (ValueInc == wxT("true")){
92         HideLocalABs = TRUE;
93     }
94     
95     delete settingfile;
96     settingfile = NULL;
97     
98     // Load the accounts.
99     
100     fullprefpath.Clear();
101     fullprefpath.Append(PreferencesFilename);
102     fullprefpath.Append(wxT("accounts"));
103  
104     wxFileConfig *cfgfile = new wxFileConfig("AddressBook", "Xestia", fullprefpath);
105     
106     wxString EntryName, EntryValue;
107     wxString AccAdr, AccUsr, AccPass, AccPrefix, AccDir;
108     wxString AccSSLInc;
109     bool AccSSL = FALSE;
110     int AccRef, AccPort = 0;
111     long itemindex = 0;
112     long subitemindex = 0;
113     bool ContinueAcc = TRUE;
114     bool ContinueProc = TRUE;
115     
116     ContinueAcc = cfgfile->GetFirstGroup(accountname, itemindex);
117     
118     while (ContinueAcc){
120         cfgfile->SetPath(accountname);
121         //ContinueProc = cfgfile->GetFirstEntry(EntryName, subitemindex);
122         cfgfile->Read(wxT("type"), &EntryValue);
123      
124         if (EntryValue == wxT("Local")){
125         
126                 // Get the account directory.
127                 
128                 cfgfile->Read(wxT("accountdir"), &AccDir);
129         
130                 if (AccDir.Len() > 4){
132                         accountdirvalid = TRUE;
133                 
134                 } else {
136                         accountdirvalid = FALSE;
138                 }
139                 
140                 if (accountdirvalid == TRUE){
141                 
142                         accounts.AddAccount(accountname, wxT("Local"), wxT(""), 0,
143                            0, wxT(""), wxT(""), 
144                            wxT(""), AccDir, 0);
145                 
146                 }
147         
148         } else if (EntryValue == wxT("CardDAV")){
150                 cfgfile->Read(wxT("accountdir"), &AccDir);
151                 accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
152                 accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
153                 accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
154                 if (AccSSLInc == wxT("true")){
155                         AccSSL = TRUE;
156                 }
157                 accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
158                 accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
159                 accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
160                 accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
161                 
162                 if (AccDir.Len() > 4){
164                         accountdirvalid = TRUE;
165                 
166                 }
167                         
168                 // Make sure it is not bigger than 65535 or less than 1.
169                 // If so, default to port 8008.
170                         
171                 if (accountport < 1 || accountport > 65535){
172                    accountport = 8008;
173                    accountportvalid = TRUE;
174                 }
175                 
176                 accounts.AddAccount(accountname, wxT("CardDAV"), AccAdr, AccPort,
177                                     AccSSL, AccUsr, AccPass, 
178                                     AccPrefix, AccDir, AccRef);
179                 
180         }
182         // Clear up for the next account.
183     
184         accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
185         accountsslvalid, accountusernamevalid, accountpasswordvalid,
186         accountdirprefixvalid, accountdirvalid, accountrefreshvalid, accountssl, 
187         isvalidaccount, isvalidsection = FALSE;
188         AccAdr.Clear();
189         //AccPort.Clear();
190         AccDir.Clear();
191         AccUsr.Clear();
192         AccPass.Clear();
193         AccPrefix.Clear();
194         accountname.Clear();
195         accountaddress.Clear();
196         accounttype.Clear();
197         accountport = 0;
198         accountrefresh = 0;
199         accountusername.Clear();
200         accountpassword.Clear();
201         accountdirprefix.Clear();    
202         preaccountstage = TRUE;
203     
204         cfgfile->SetPath(wxT("/"));
205         ContinueAcc = cfgfile->GetNextGroup(accountname, itemindex);
206     }
207   
210 XABPreferences::~XABPreferences(){
211   
214 bool XABPreferences::GetBoolData(wxString SettingName){
216         if (SettingName == wxT("SaveWindowPosition")) { return SaveWindowPos; }
217         else if (SettingName == wxT("HideLocalAddressBooks")) { return HideLocalABs; }
218         
219         return FALSE;
223 wxRect XABPreferences::GetMainWindowData(){
224         
225         return MainWindowData;
229 void XABPreferences::SetMainWindowData(wxRect WindowData){
231         MainWindowData = WindowData;
235 // XABPrefAccounts
237 XABPrefAccounts::XABPrefAccounts(){
238     AccountsCount = 0;
241 int XABPrefAccounts::AddAccount(wxString NewAccName,
242         wxString NewAccType,
243         wxString NewAccAddress,
244         int NewAccPort,
245         int NewAccSSL,
246         wxString NewAccUser,
247         wxString NewAccPass,
248         wxString NewAccDirPrefix,
249         wxString NewAccDir,
250         long NewAccRefresh
251 ){
252   
253     AccountName.Add(NewAccName, 1);
254     AccountType.Add(NewAccType, 1);
255     AccountAddress.Add(NewAccAddress, 1);
256     AccountPort.Add(NewAccPort, 1);
257     AccountSSL.Add(NewAccSSL, 1);
258     AccountUsername.Add(NewAccUser, 1);
259     AccountPassword.Add(NewAccPass, 1);
260     DirectoryPrefix.Add(NewAccDirPrefix, 1);
261     AccountDirectory.Add(NewAccDir, 1);
262     AccountRefresh.Add(NewAccRefresh, 1);
263     
264     AccountsCount++;
265     
266         return 0;
270 int XABPrefAccounts::GetCount(){
271   
272     return AccountsCount;
273   
276 wxString XABPrefAccounts::GetAccountName(int AccountNum){
277  
278     if (AccountNum > AccountsCount){
279         return wxT("");
280     }
281   
282     return AccountName[AccountNum];
283   
286 wxString XABPrefAccounts::GetAccountType(int AccountNum){
287  
288     if (AccountNum > AccountsCount){
289         return wxT("");
290     }
291   
292     return AccountType[AccountNum];
293   
296 wxString XABPrefAccounts::GetAccountAddress(int AccountNum){
297  
298     if (AccountNum > AccountsCount){
299         return wxT("");
300     }
301   
302     return AccountAddress[AccountNum];
303   
306 int XABPrefAccounts::GetAccountPort(int AccountNum){
307  
308     if (AccountNum > AccountsCount){
309         return 0;
310     }
311   
312     return AccountPort[AccountNum];
313   
316 bool XABPrefAccounts::GetAccountSSL(int AccountNum){
317  
318     if (AccountNum > AccountsCount){
319         return wxT("");
320     }
321   
322     return AccountSSL[AccountNum];
323   
326 wxString XABPrefAccounts::GetAccountUsername(int AccountNum){
327  
328     if (AccountNum > AccountsCount){
329         return wxT("");
330     }
331   
332     return AccountUsername[AccountNum];
333   
336 wxString XABPrefAccounts::GetAccountPassword(int AccountNum){
337  
338     if (AccountNum > AccountsCount){
339         return wxT("");
340     }
341   
342     return AccountPassword[AccountNum];
343   
346 wxString XABPrefAccounts::GetAccountDirectory(int AccountNum){
347  
348     if (AccountNum > AccountsCount){
349         return wxT("");
350     }
351   
352     return AccountDirectory[AccountNum];
353   
356 wxString XABPrefAccounts::GetAccountDirPrefix(int AccountNum){
357  
358     if (AccountNum > AccountsCount){
359         return wxT("");
360     }
361   
362     return DirectoryPrefix[AccountNum];
363   
366 long XABPrefAccounts::GetAccountRefresh(int AccountNum){
368     if (AccountNum > AccountsCount){
369         return 0;
370     }
371   
372     return AccountRefresh[AccountNum];
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