Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and licence header to C++ files and headers for the common directory.
[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){
33     
34     //fstream preffile;
35     wxString fullprefpath;
36     
37     bool accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
38          accountsslvalid, accountusernamevalid, accountpasswordvalid,
39          accountdirprefixvalid, accountdirvalid, accountrefreshvalid = FALSE;
40     
41     bool preaccountstage = FALSE;
42     bool isvalidaccount = FALSE;
43     bool isvalidsection = FALSE;
44     wxString accountname;
45     wxString accountaddress;
46     wxString accounttype;
47     long accountport = 8080;
48     long accountrefresh;
49     bool accountssl;
50     wxString accountusername;
51     wxString accountpassword;
52     wxString accountdirprefix;
53     wxString accountdir;
54     
55     wxString firstchar;
56     string s;
58     wxString segmentname;
59     wxString segmentvalue;
60     
61     // Load the settings.
62     
63     fullprefpath.Append(PreferencesFilename);
64     fullprefpath.Append(wxT("settings"));
66     wxFileConfig *settingfile = new wxFileConfig("", "", fullprefpath);
67     
68     wxString ValueInc;
69     settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
70     
71     if (ValueInc == wxT("true")){
72                 
73                 SaveWindowPos = TRUE;
74                 wxRect WindowPosition;
75         
76                 long PosX, PosY, PosH, PosW = 0;
78                 bool PosXValid, PosYValid, PosHValid, PosWValid = FALSE;
80                 PosXValid = settingfile->Read(wxT("WindowPositionX"), &PosX);
81                 PosYValid = settingfile->Read(wxT("WindowPositionY"), &PosY);
82                 PosHValid = settingfile->Read(wxT("WindowPositionHeight"), &PosH);
83                 PosWValid = settingfile->Read(wxT("WindowPositionWidth"), &PosW);
85                 if (PosXValid == TRUE && PosYValid == TRUE && PosHValid == TRUE && PosWValid == TRUE){
87                         WindowPosition.SetX((int)PosX);
88                         WindowPosition.SetY((int)PosY);
89                         WindowPosition.SetHeight((int)PosH);
90                         WindowPosition.SetWidth((int)PosW);
92                 } else {
94                         WindowPosition.SetX(-1);
95                         WindowPosition.SetY(-1);
96                         WindowPosition.SetHeight(500);
97                         WindowPosition.SetWidth(300);
99                 }
101                 SetMainWindowData(WindowPosition);
102         
103     }
105     settingfile->Read(wxT("HideLocalAddressBooks"), &ValueInc);
106     
107     if (ValueInc == wxT("true")){
108         HideLocalABs = TRUE;
109     }
110     
111     delete settingfile;
112     settingfile = NULL;
113     
114     // Load the accounts.
115     
116     fullprefpath.Clear();
117     fullprefpath.Append(PreferencesFilename);
118     fullprefpath.Append(wxT("accounts"));
119  
120     wxFileConfig *cfgfile = new wxFileConfig("AddressBook", "Xestia", fullprefpath);
121     
122     wxString EntryName, EntryValue;
123     wxString AccAdr, AccUsr, AccPass, AccPrefix, AccDir;
124     wxString AccSSLInc;
125     bool AccSSL = FALSE;
126     int AccRef, AccPort = 0;
127     long itemindex = 0;
128     bool ContinueAcc = TRUE;
129     
130     ContinueAcc = cfgfile->GetFirstGroup(accountname, itemindex);
131     
132     while (ContinueAcc){
134         cfgfile->SetPath(accountname);
135         //ContinueProc = cfgfile->GetFirstEntry(EntryName, subitemindex);
136         cfgfile->Read(wxT("type"), &EntryValue);
137          
138         if (EntryValue == wxT("Local")){
139         
140             // Get the account directory.
141             
142             cfgfile->Read(wxT("accountdir"), &AccDir);
143         
144             if (AccDir.Len() > 4){
146                 accountdirvalid = TRUE;
147             
148             } else {
150                 accountdirvalid = FALSE;
152             }
153             
154             if (accountdirvalid == TRUE){
155             
156                 accounts.AddAccount(accountname, wxT("Local"), wxT(""), 0,
157                    0, wxT(""), wxT(""), 
158                    wxT(""), AccDir, 0);
159             
160             }
161         
162         } else if (EntryValue == wxT("CardDAV")){
164             cfgfile->Read(wxT("accountdir"), &AccDir);
165             accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
166             accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
167             accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
168             if (AccSSLInc == wxT("true")){
169                 AccSSL = TRUE;
170             }
171                 accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
172                 accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
173                 accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
174                 accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
175             
176             if (AccDir.Len() > 4){
178                 accountdirvalid = TRUE;
179             
180             }
181                 
182             // Make sure it is not bigger than 65535 or less than 1.
183             // If so, default to port 8008.
184                 
185             if (accountport < 1 || accountport > 65535){
186                accountport = 8008;
187                accountportvalid = TRUE;
188             }
189             
190             accounts.AddAccount(accountname, wxT("CardDAV"), AccAdr, AccPort,
191                         AccSSL, AccUsr, AccPass, 
192                         AccPrefix, AccDir, AccRef);
193             
194         }
196         // Clear up for the next account.
197     
198         accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
199         accountsslvalid, accountusernamevalid, accountpasswordvalid,
200         accountdirprefixvalid, accountdirvalid, accountrefreshvalid, accountssl,
201         isvalidaccount, isvalidsection = FALSE;
202         
203         AccAdr.Clear();
204         AccDir.Clear();
205         AccUsr.Clear();
206         AccPass.Clear();
207         AccPrefix.Clear();
208         accountname.Clear();
209         accountaddress.Clear();
210         accounttype.Clear();
211         accountport = 0;
212         accountrefresh = 0;
213         accountusername.Clear();
214         accountpassword.Clear();
215         accountdirprefix.Clear();
216         preaccountstage = TRUE;
217     
218         cfgfile->SetPath(wxT("/"));
219         ContinueAcc = cfgfile->GetNextGroup(accountname, itemindex);
220     
221     }
222   
225 XABPreferences::~XABPreferences(){
226   
229 bool XABPreferences::GetBoolData(wxString SettingName){
231         if (SettingName == wxT("SaveWindowPosition")) { return SaveWindowPos; }
232         else if (SettingName == wxT("HideLocalAddressBooks")) { return HideLocalABs; }
233         
234         return FALSE;
238 wxRect XABPreferences::GetMainWindowData(){
239         
240         return MainWindowData;
244 void XABPreferences::SetMainWindowData(wxRect WindowData){
246         MainWindowData = WindowData;
250 // XABPrefAccounts
252 XABPrefAccounts::XABPrefAccounts(){
253     AccountsCount = 0;
256 int XABPrefAccounts::AddAccount(wxString NewAccName,
257         wxString NewAccType,
258         wxString NewAccAddress,
259         int NewAccPort,
260         int NewAccSSL,
261         wxString NewAccUser,
262         wxString NewAccPass,
263         wxString NewAccDirPrefix,
264         wxString NewAccDir,
265         long NewAccRefresh
266 ){
267   
268     AccountName.Add(NewAccName, 1);
269     AccountType.Add(NewAccType, 1);
270     AccountAddress.Add(NewAccAddress, 1);
271     AccountPort.Add(NewAccPort, 1);
272     AccountSSL.Add(NewAccSSL, 1);
273     AccountUsername.Add(NewAccUser, 1);
274     AccountPassword.Add(NewAccPass, 1);
275     DirectoryPrefix.Add(NewAccDirPrefix, 1);
276     AccountDirectory.Add(NewAccDir, 1);
277     AccountRefresh.Add(NewAccRefresh, 1);
278     
279     AccountsCount++;
280     
281         return 0;
285 int XABPrefAccounts::GetCount(){
286   
287     return AccountsCount;
288   
291 wxString XABPrefAccounts::GetAccountName(int AccountNum){
292  
293     if (AccountNum > AccountsCount){
294         return wxT("");
295     }
296   
297     return AccountName[AccountNum];
298   
301 wxString XABPrefAccounts::GetAccountType(int AccountNum){
302  
303     if (AccountNum > AccountsCount){
304         return wxT("");
305     }
306   
307     return AccountType[AccountNum];
308   
311 wxString XABPrefAccounts::GetAccountAddress(int AccountNum){
312  
313     if (AccountNum > AccountsCount){
314         return wxT("");
315     }
316   
317     return AccountAddress[AccountNum];
318   
321 int XABPrefAccounts::GetAccountPort(int AccountNum){
322  
323     if (AccountNum > AccountsCount){
324         return 0;
325     }
326   
327     return AccountPort[AccountNum];
328   
331 bool XABPrefAccounts::GetAccountSSL(int AccountNum){
332  
333     if (AccountNum > AccountsCount){
334         return wxT("");
335     }
336   
337     return AccountSSL[AccountNum];
338   
341 wxString XABPrefAccounts::GetAccountUsername(int AccountNum){
342  
343     if (AccountNum > AccountsCount){
344         return wxT("");
345     }
346   
347     return AccountUsername[AccountNum];
348   
351 wxString XABPrefAccounts::GetAccountPassword(int AccountNum){
352  
353     if (AccountNum > AccountsCount){
354         return wxT("");
355     }
356   
357     return AccountPassword[AccountNum];
358   
361 wxString XABPrefAccounts::GetAccountDirectory(int AccountNum){
362  
363     if (AccountNum > AccountsCount){
364         return wxT("");
365     }
366   
367     return AccountDirectory[AccountNum];
368   
371 wxString XABPrefAccounts::GetAccountDirPrefix(int AccountNum){
372  
373     if (AccountNum > AccountsCount){
374         return wxT("");
375     }
376   
377     return DirectoryPrefix[AccountNum];
378   
381 long XABPrefAccounts::GetAccountRefresh(int AccountNum){
383     if (AccountNum > AccountsCount){
384         return 0;
385     }
386   
387     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