Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
6fae06e8357c4b4e0c0a5267317f88118e59a798
[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     bool accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
20          accountsslvalid, accountusernamevalid, accountpasswordvalid,
21          accountdirprefixvalid, accountdirvalid, accountrefreshvalid = FALSE;
22     
23     bool preaccountstage = FALSE;
24     bool isvalidaccount = FALSE;
25     bool isvalidsection = FALSE;
26     wxString accountname;
27     wxString accountaddress;
28     wxString accounttype;
29     long accountport = 8080;
30     long accountrefresh;
31     bool accountssl;
32     wxString accountusername;
33     wxString accountpassword;
34     wxString accountdirprefix;
35     wxString accountdir;
36     
37     wxString firstchar;
38     string s;
40     wxString segmentname;
41     wxString segmentvalue;
42     
43     // Load the settings.
44     
45     fullprefpath.Append(PreferencesFilename);
46     fullprefpath.Append(wxT("settings"));
48     wxFileConfig *settingfile = new wxFileConfig("", "", fullprefpath);
49     
50     wxString ValueInc;
51     settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
52     
53     if (ValueInc == wxT("true")){
54                 
55                 SaveWindowPos = TRUE;
56                 wxRect WindowPosition;
57         
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);
74                 } else {
76                         WindowPosition.SetX(-1);
77                         WindowPosition.SetY(-1);
78                         WindowPosition.SetHeight(500);
79                         WindowPosition.SetWidth(300);
81                 }
83                 SetMainWindowData(WindowPosition);
84         
85     }
87     settingfile->Read(wxT("HideLocalAddressBooks"), &ValueInc);
88     
89     if (ValueInc == wxT("true")){
90         HideLocalABs = TRUE;
91     }
92     
93     delete settingfile;
94     settingfile = NULL;
95     
96     // Load the accounts.
97     
98     fullprefpath.Clear();
99     fullprefpath.Append(PreferencesFilename);
100     fullprefpath.Append(wxT("accounts"));
101  
102     wxFileConfig *cfgfile = new wxFileConfig("AddressBook", "Xestia", fullprefpath);
103     
104     wxString EntryName, EntryValue;
105     wxString AccAdr, AccUsr, AccPass, AccPrefix, AccDir;
106     wxString AccSSLInc;
107     bool AccSSL = FALSE;
108     int AccRef, AccPort = 0;
109     long itemindex = 0;
110     bool ContinueAcc = TRUE;
111     
112     ContinueAcc = cfgfile->GetFirstGroup(accountname, itemindex);
113     
114     while (ContinueAcc){
116         cfgfile->SetPath(accountname);
117         //ContinueProc = cfgfile->GetFirstEntry(EntryName, subitemindex);
118         cfgfile->Read(wxT("type"), &EntryValue);
119          
120         if (EntryValue == wxT("Local")){
121         
122             // Get the account directory.
123             
124             cfgfile->Read(wxT("accountdir"), &AccDir);
125         
126             if (AccDir.Len() > 4){
128                 accountdirvalid = TRUE;
129             
130             } else {
132                 accountdirvalid = FALSE;
134             }
135             
136             if (accountdirvalid == TRUE){
137             
138                 accounts.AddAccount(accountname, wxT("Local"), wxT(""), 0,
139                    0, wxT(""), wxT(""), 
140                    wxT(""), AccDir, 0);
141             
142             }
143         
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")){
151                 AccSSL = TRUE;
152             }
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);
157             
158             if (AccDir.Len() > 4){
160                 accountdirvalid = TRUE;
161             
162             }
163                 
164             // Make sure it is not bigger than 65535 or less than 1.
165             // If so, default to port 8008.
166                 
167             if (accountport < 1 || accountport > 65535){
168                accountport = 8008;
169                accountportvalid = TRUE;
170             }
171             
172             accounts.AddAccount(accountname, wxT("CardDAV"), AccAdr, AccPort,
173                         AccSSL, AccUsr, AccPass, 
174                         AccPrefix, AccDir, AccRef);
175             
176         }
178         // Clear up for the next account.
179     
180         accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
181         accountsslvalid, accountusernamevalid, accountpasswordvalid,
182         accountdirprefixvalid, accountdirvalid, accountrefreshvalid, accountssl,
183         isvalidaccount, isvalidsection = FALSE;
184         
185         AccAdr.Clear();
186         AccDir.Clear();
187         AccUsr.Clear();
188         AccPass.Clear();
189         AccPrefix.Clear();
190         accountname.Clear();
191         accountaddress.Clear();
192         accounttype.Clear();
193         accountport = 0;
194         accountrefresh = 0;
195         accountusername.Clear();
196         accountpassword.Clear();
197         accountdirprefix.Clear();
198         preaccountstage = TRUE;
199     
200         cfgfile->SetPath(wxT("/"));
201         ContinueAcc = cfgfile->GetNextGroup(accountname, itemindex);
202     
203     }
204   
207 XABPreferences::~XABPreferences(){
208   
211 bool XABPreferences::GetBoolData(wxString SettingName){
213         if (SettingName == wxT("SaveWindowPosition")) { return SaveWindowPos; }
214         else if (SettingName == wxT("HideLocalAddressBooks")) { return HideLocalABs; }
215         
216         return FALSE;
220 wxRect XABPreferences::GetMainWindowData(){
221         
222         return MainWindowData;
226 void XABPreferences::SetMainWindowData(wxRect WindowData){
228         MainWindowData = WindowData;
232 // XABPrefAccounts
234 XABPrefAccounts::XABPrefAccounts(){
235     AccountsCount = 0;
238 int XABPrefAccounts::AddAccount(wxString NewAccName,
239         wxString NewAccType,
240         wxString NewAccAddress,
241         int NewAccPort,
242         int NewAccSSL,
243         wxString NewAccUser,
244         wxString NewAccPass,
245         wxString NewAccDirPrefix,
246         wxString NewAccDir,
247         long NewAccRefresh
248 ){
249   
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);
260     
261     AccountsCount++;
262     
263         return 0;
267 int XABPrefAccounts::GetCount(){
268   
269     return AccountsCount;
270   
273 wxString XABPrefAccounts::GetAccountName(int AccountNum){
274  
275     if (AccountNum > AccountsCount){
276         return wxT("");
277     }
278   
279     return AccountName[AccountNum];
280   
283 wxString XABPrefAccounts::GetAccountType(int AccountNum){
284  
285     if (AccountNum > AccountsCount){
286         return wxT("");
287     }
288   
289     return AccountType[AccountNum];
290   
293 wxString XABPrefAccounts::GetAccountAddress(int AccountNum){
294  
295     if (AccountNum > AccountsCount){
296         return wxT("");
297     }
298   
299     return AccountAddress[AccountNum];
300   
303 int XABPrefAccounts::GetAccountPort(int AccountNum){
304  
305     if (AccountNum > AccountsCount){
306         return 0;
307     }
308   
309     return AccountPort[AccountNum];
310   
313 bool XABPrefAccounts::GetAccountSSL(int AccountNum){
314  
315     if (AccountNum > AccountsCount){
316         return wxT("");
317     }
318   
319     return AccountSSL[AccountNum];
320   
323 wxString XABPrefAccounts::GetAccountUsername(int AccountNum){
324  
325     if (AccountNum > AccountsCount){
326         return wxT("");
327     }
328   
329     return AccountUsername[AccountNum];
330   
333 wxString XABPrefAccounts::GetAccountPassword(int AccountNum){
334  
335     if (AccountNum > AccountsCount){
336         return wxT("");
337     }
338   
339     return AccountPassword[AccountNum];
340   
343 wxString XABPrefAccounts::GetAccountDirectory(int AccountNum){
344  
345     if (AccountNum > AccountsCount){
346         return wxT("");
347     }
348   
349     return AccountDirectory[AccountNum];
350   
353 wxString XABPrefAccounts::GetAccountDirPrefix(int AccountNum){
354  
355     if (AccountNum > AccountsCount){
356         return wxT("");
357     }
358   
359     return DirectoryPrefix[AccountNum];
360   
363 long XABPrefAccounts::GetAccountRefresh(int AccountNum){
365     if (AccountNum > AccountsCount){
366         return 0;
367     }
368   
369     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