Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out code in common/preferences.cpp
[xestiaab/.git] / source / common / preferences.cpp
1 // preferences.cpp - Preferences subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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 <iostream>
20 #include <iomanip>
21 #include <ios>
22 #include <string>
23 #include <wx/fileconf.h>
25 #include "preferences.h"
27 using namespace std;
29 void SavePreferences();
30 void LoadPreferences();
32 XABPreferences::XABPreferences(wxString PreferencesFilename){
34         wxString fullprefpath;
35     
36         bool accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
37                 accountsslvalid, accountusernamevalid, accountpasswordvalid,
38                 accountdirprefixvalid, accountdirvalid, accountrefreshvalid = FALSE;
39     
40         bool preaccountstage = FALSE;
41         bool isvalidaccount = FALSE;
42         bool isvalidsection = FALSE;
43         wxString accountname;
44         wxString accountaddress;
45         wxString accounttype;
46         long accountport = 8080;
47         long accountrefresh;
48         bool accountssl;
49         wxString accountusername;
50         wxString accountpassword;
51         wxString accountdirprefix;
52         wxString accountdir;
53     
54         wxString firstchar;
55         string s;
57         wxString segmentname;
58         wxString segmentvalue;
59     
60         // Load the settings.
61     
62         fullprefpath.Append(PreferencesFilename);
63         fullprefpath.Append(wxT("settings"));
65         wxFileConfig *settingfile = new wxFileConfig("", "", fullprefpath);
66     
67         wxString ValueInc;
68         settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
69     
70         if (ValueInc == wxT("true")){
71                 
72                 SaveWindowPos = TRUE;
73                 wxRect WindowPosition;
74         
75                 long PosX, PosY, PosH, PosW = 0;
77                 bool PosXValid, PosYValid, PosHValid, PosWValid = FALSE;
79                 PosXValid = settingfile->Read(wxT("WindowPositionX"), &PosX);
80                 PosYValid = settingfile->Read(wxT("WindowPositionY"), &PosY);
81                 PosHValid = settingfile->Read(wxT("WindowPositionHeight"), &PosH);
82                 PosWValid = settingfile->Read(wxT("WindowPositionWidth"), &PosW);
84                 if (PosXValid == TRUE && PosYValid == TRUE && PosHValid == TRUE && PosWValid == TRUE){
86                         WindowPosition.SetX((int)PosX);
87                         WindowPosition.SetY((int)PosY);
88                         WindowPosition.SetHeight((int)PosH);
89                         WindowPosition.SetWidth((int)PosW);
91                 } else {
93                         WindowPosition.SetX(-1);
94                         WindowPosition.SetY(-1);
95                         WindowPosition.SetHeight(500);
96                         WindowPosition.SetWidth(300);
98                 }
100                 SetMainWindowData(WindowPosition);
101         
102         }
104         settingfile->Read(wxT("HideLocalAddressBooks"), &ValueInc);
105     
106         if (ValueInc == wxT("true")){
107                 HideLocalABs = TRUE;
108         }
109     
110         delete settingfile;
111         settingfile = NULL;
112     
113         // Load the accounts.
114     
115         fullprefpath.Clear();
116         fullprefpath.Append(PreferencesFilename);
117         fullprefpath.Append(wxT("accounts"));
118  
119         wxFileConfig *cfgfile = new wxFileConfig("AddressBook", "Xestia", fullprefpath);
120     
121         wxString EntryName, EntryValue;
122         wxString AccAdr, AccUsr, AccPass, AccPrefix, AccDir;
123         wxString AccSSLInc;
124         bool AccSSL = FALSE;
125         int AccRef, AccPort = 0;
126         long itemindex = 0;
127         bool ContinueAcc = TRUE;
128     
129         ContinueAcc = cfgfile->GetFirstGroup(accountname, itemindex);
130     
131         while (ContinueAcc){
133                 cfgfile->SetPath(accountname);
134                 cfgfile->Read(wxT("type"), &EntryValue);
135          
136                 if (EntryValue == wxT("Local")){
137         
138                         // Get the account directory.
139         
140                         cfgfile->Read(wxT("accountdir"), &AccDir);
141         
142                         if (AccDir.Len() > 4){
144                                 accountdirvalid = TRUE;
145             
146                         } else {
148                                 accountdirvalid = FALSE;
150                         }
151             
152                         if (accountdirvalid == TRUE){
153             
154                                 accounts.AddAccount(accountname, wxT("Local"), wxT(""), 0,
155                                         0, wxT(""), wxT(""), 
156                                         wxT(""), AccDir, 0);
157             
158                         }
159         
160                 } else if (EntryValue == wxT("CardDAV")){
162                         cfgfile->Read(wxT("accountdir"), &AccDir);
163                         accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
164                         accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
165                         accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
166                         if (AccSSLInc == wxT("true")){
167                                 AccSSL = TRUE;
168                         }
169                         accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
170                         accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
171                         accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
172                         accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
173             
174                         if (AccDir.Len() > 4){
176                                 accountdirvalid = TRUE;
177             
178                         }
179                 
180                         // Make sure it is not bigger than 65535 or less than 1.
181                         // If so, default to port 8008.
182                 
183                         if (accountport < 1 || accountport > 65535){
184                                 accountport = 8008;
185                                 accountportvalid = TRUE;
186                         }
187             
188                         accounts.AddAccount(accountname, wxT("CardDAV"), AccAdr, AccPort,
189                                 AccSSL, AccUsr, AccPass, 
190                                 AccPrefix, AccDir, AccRef);
191             
192                 }
194                 // Clear up for the next account.
195     
196                 accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
197                 accountsslvalid, accountusernamevalid, accountpasswordvalid,
198                 accountdirprefixvalid, accountdirvalid, accountrefreshvalid, accountssl,
199                 isvalidaccount, isvalidsection = FALSE;
200         
201                 AccAdr.Clear();
202                 AccDir.Clear();
203                 AccUsr.Clear();
204                 AccPass.Clear();
205                 AccPrefix.Clear();
206                 accountname.Clear();
207                 accountaddress.Clear();
208                 accounttype.Clear();
209                 accountport = 0;
210                 accountrefresh = 0;
211                 accountusername.Clear();
212                 accountpassword.Clear();
213                 accountdirprefix.Clear();
214                 preaccountstage = TRUE;
215     
216                 cfgfile->SetPath(wxT("/"));
217                 ContinueAcc = cfgfile->GetNextGroup(accountname, itemindex);
218     
219         }
220   
223 XABPreferences::~XABPreferences(){
224         
227 bool XABPreferences::GetBoolData(wxString SettingName){
229         if (SettingName == wxT("SaveWindowPosition")) { return SaveWindowPos; }
230         else if (SettingName == wxT("HideLocalAddressBooks")) { return HideLocalABs; }
231         
232         return FALSE;
236 wxRect XABPreferences::GetMainWindowData(){
237         
238         return MainWindowData;
242 void XABPreferences::SetMainWindowData(wxRect WindowData){
244         MainWindowData = WindowData;
248 // XABPrefAccounts
250 XABPrefAccounts::XABPrefAccounts(){
251         AccountsCount = 0;
254 int XABPrefAccounts::AddAccount(wxString NewAccName,
255         wxString NewAccType,
256         wxString NewAccAddress,
257         int NewAccPort,
258         int NewAccSSL,
259         wxString NewAccUser,
260         wxString NewAccPass,
261         wxString NewAccDirPrefix,
262         wxString NewAccDir,
263         long NewAccRefresh
264 ){
265   
266         AccountName.Add(NewAccName, 1);
267         AccountType.Add(NewAccType, 1);
268         AccountAddress.Add(NewAccAddress, 1);
269         AccountPort.Add(NewAccPort, 1);
270         AccountSSL.Add(NewAccSSL, 1);
271         AccountUsername.Add(NewAccUser, 1);
272         AccountPassword.Add(NewAccPass, 1);
273         DirectoryPrefix.Add(NewAccDirPrefix, 1);
274         AccountDirectory.Add(NewAccDir, 1);
275         AccountRefresh.Add(NewAccRefresh, 1);
276     
277         AccountsCount++;
278     
279         return 0;
283 int XABPrefAccounts::GetCount(){
284   
285         return AccountsCount;
286   
289 wxString XABPrefAccounts::GetAccountName(int AccountNum){
290  
291         if (AccountNum > AccountsCount){
292                 return wxT("");
293         }
294   
295         return AccountName[AccountNum];
296   
299 wxString XABPrefAccounts::GetAccountType(int AccountNum){
300  
301         if (AccountNum > AccountsCount){
302                 return wxT("");
303         }
304   
305         return AccountType[AccountNum];
306   
309 wxString XABPrefAccounts::GetAccountAddress(int AccountNum){
310  
311         if (AccountNum > AccountsCount){
312                 return wxT("");
313         }
314   
315         return AccountAddress[AccountNum];
316   
319 int XABPrefAccounts::GetAccountPort(int AccountNum){
320  
321         if (AccountNum > AccountsCount){
322                 return 0;
323         }
324   
325         return AccountPort[AccountNum];
326   
329 bool XABPrefAccounts::GetAccountSSL(int AccountNum){
330  
331         if (AccountNum > AccountsCount){
332                 return wxT("");
333         }
334   
335         return AccountSSL[AccountNum];
336   
339 wxString XABPrefAccounts::GetAccountUsername(int AccountNum){
340  
341         if (AccountNum > AccountsCount){
342                 return wxT("");
343         }
344   
345         return AccountUsername[AccountNum];
346   
349 wxString XABPrefAccounts::GetAccountPassword(int AccountNum){
350  
351         if (AccountNum > AccountsCount){
352                 return wxT("");
353         }
354   
355         return AccountPassword[AccountNum];
356   
359 wxString XABPrefAccounts::GetAccountDirectory(int AccountNum){
360  
361         if (AccountNum > AccountsCount){
362                 return wxT("");
363         }
364   
365         return AccountDirectory[AccountNum];
366   
369 wxString XABPrefAccounts::GetAccountDirPrefix(int AccountNum){
370  
371         if (AccountNum > AccountsCount){
372                 return wxT("");
373         }
374   
375         return DirectoryPrefix[AccountNum];
376   
379 long XABPrefAccounts::GetAccountRefresh(int AccountNum){
381         if (AccountNum > AccountsCount){
382                 return 0;
383         }
384   
385         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