Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditorCalAdr: Implemented priority control
[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         // Load the settings into the XABPreferences object using the
35         // settings file received in PreferencesFilename.
37         wxString fullprefpath;
38     
39         bool accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
40                 accountsslvalid, accountusernamevalid, accountpasswordvalid,
41                 accountdirprefixvalid, accountdirvalid, accountrefreshvalid = FALSE;
42     
43         bool preaccountstage = FALSE;
44         bool isvalidaccount = FALSE;
45         bool isvalidsection = FALSE;
46         wxString accountname;
47         wxString accountaddress;
48         wxString accounttype;
49         long accountport = 8080;
50         long accountrefresh;
51         bool accountssl;
52         wxString accountusername;
53         wxString accountpassword;
54         wxString accountdirprefix;
55         wxString accountdir;
56     
57         wxString firstchar;
58         string s;
60         wxString segmentname;
61         wxString segmentvalue;
62     
63         // Load the settings.
64     
65         fullprefpath.Append(PreferencesFilename);
66         fullprefpath.Append(wxT("settings"));
68         wxFileConfig *settingfile = new wxFileConfig("", "", fullprefpath);
69     
70         wxString ValueInc;
71         settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
72     
73         if (ValueInc == wxT("true")){
74                 
75                 SaveWindowPos = true;
76                 wxRect WindowPosition;
77         
78                 long PosX, PosY, PosH, PosW = 0;
80                 bool PosXValid, PosYValid, PosHValid, PosWValid = FALSE;
82                 PosXValid = settingfile->Read(wxT("WindowPositionX"), &PosX);
83                 PosYValid = settingfile->Read(wxT("WindowPositionY"), &PosY);
84                 PosHValid = settingfile->Read(wxT("WindowPositionHeight"), &PosH);
85                 PosWValid = settingfile->Read(wxT("WindowPositionWidth"), &PosW);
87                 if (PosXValid == TRUE && PosYValid == TRUE && PosHValid == TRUE && PosWValid == TRUE){
89                         WindowPosition.SetX((int)PosX);
90                         WindowPosition.SetY((int)PosY);
91                         WindowPosition.SetHeight((int)PosH);
92                         WindowPosition.SetWidth((int)PosW);
94                 } else {
96                         WindowPosition.SetX(-1);
97                         WindowPosition.SetY(-1);
98                         WindowPosition.SetHeight(500);
99                         WindowPosition.SetWidth(300);
101                 }
103                 SetMainWindowData(WindowPosition);
104         
105         }
107         settingfile->Read(wxT("HideLocalAddressBooks"), &ValueInc);
108     
109         if (ValueInc == wxT("true")){
110                 HideLocalABs = true;
111         }
112         
113         settingfile->Read(wxT("UseBackgroundContactColour"), &ValueInc);
114     
115         if (ValueInc == wxT("true")){
116                 UseBackgroundContactColour = true;
117                 wxString BackgroundContactColourRead;
118                 settingfile->Read(wxT("BackgroundContactColour"), &BackgroundContactColourRead);
119                 if (BackgroundContactColourRead.Mid(0, 1) == "#"){
120                         BackgroundContactColour.Set(BackgroundContactColourRead);
121                 }
122         }
123     
124         delete settingfile;
125         settingfile = NULL;
126     
127         // Load the accounts.
128     
129         fullprefpath.Clear();
130         fullprefpath.Append(PreferencesFilename);
131         fullprefpath.Append(wxT("accounts"));
132  
133         wxFileConfig *cfgfile = new wxFileConfig("AddressBook", "Xestia", fullprefpath);
134     
135         wxString EntryName, EntryValue;
136         wxString AccAdr, AccUsr, AccPass, AccPrefix, AccDir;
137         wxString AccSSLInc;
138         bool AccSSL = FALSE;
139         int AccRef, AccPort = 0;
140         long itemindex = 0;
141         bool ContinueAcc = TRUE;
142     
143         ContinueAcc = cfgfile->GetFirstGroup(accountname, itemindex);
144     
145         while (ContinueAcc){
147                 cfgfile->SetPath(accountname);
148                 cfgfile->Read(wxT("type"), &EntryValue);
149          
150                 if (EntryValue == wxT("Local")){
151         
152                         // Get the account directory.
153         
154                         cfgfile->Read(wxT("accountdir"), &AccDir);
155         
156                         if (AccDir.Len() > 4){
158                                 accountdirvalid = TRUE;
159             
160                         } else {
162                                 accountdirvalid = FALSE;
164                         }
165             
166                         if (accountdirvalid == TRUE){
167             
168                                 accounts.AddAccount(accountname, wxT("Local"), wxT(""), 0,
169                                         0, wxT(""), wxT(""), 
170                                         wxT(""), AccDir, 0);
171             
172                         }
173         
174                 } else if (EntryValue == wxT("CardDAV")){
176                         cfgfile->Read(wxT("accountdir"), &AccDir);
177                         accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
178                         accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
179                         accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
180                         if (AccSSLInc == wxT("true")){
181                                 AccSSL = TRUE;
182                         }
183                         else {
184                                 AccSSL = FALSE;
185                         }
186                         accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
187                         accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
188                         accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
189                         accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
190             
191                         if (AccDir.Len() > 4){
193                                 accountdirvalid = TRUE;
194             
195                         }
196                 
197                         // Make sure it is not bigger than 65535 or less than 1.
198                         // If so, default to port 8008.
199                 
200                         if (accountport < 1 || accountport > 65535){
201                                 accountport = 8008;
202                                 accountportvalid = TRUE;
203                         }
204             
205                         accounts.AddAccount(accountname, wxT("CardDAV"), AccAdr, AccPort,
206                                 AccSSL, AccUsr, AccPass, 
207                                 AccPrefix, AccDir, AccRef);
208             
209                 } else {
210                         
211                         cfgfile->Read(wxT("accountdir"), &AccDir);
212                         accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
213                         accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
214                         accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
215                         if (AccSSLInc == wxT("true")){
216                                 AccSSL = TRUE;
217                         }
218                         else {
219                                 AccSSL = FALSE;
220                         }
221                         accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
222                         accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
223                         accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
224                         accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
225             
226                         if (AccDir.Len() > 4){
228                                 accountdirvalid = TRUE;
229             
230                         }
231                 
232                         // Make sure it is not bigger than 65535 or less than 1.
233                         // If so, default to port 8008.
234                 
235                         if (accountport < 1 || accountport > 65535){
236                                 accountport = 8008;
237                                 accountportvalid = TRUE;
238                         }
239             
240                         accounts.AddAccount(accountname, EntryValue, AccAdr, AccPort,
241                                 AccSSL, AccUsr, AccPass, 
242                                 AccPrefix, AccDir, AccRef);
243                         
244                 }
246                 // Clear up for the next account.
247     
248                 accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
249                 accountsslvalid, accountusernamevalid, accountpasswordvalid,
250                 accountdirprefixvalid, accountdirvalid, accountrefreshvalid, accountssl,
251                 isvalidaccount, isvalidsection = FALSE;
252         
253                 AccAdr.Clear();
254                 AccDir.Clear();
255                 AccUsr.Clear();
256                 AccPass.Clear();
257                 AccPrefix.Clear();
258                 accountname.Clear();
259                 accountaddress.Clear();
260                 accounttype.Clear();
261                 accountport = 0;
262                 accountrefresh = 0;
263                 accountusername.Clear();
264                 accountpassword.Clear();
265                 accountdirprefix.Clear();
266                 preaccountstage = TRUE;
267     
268                 cfgfile->SetPath(wxT("/"));
269                 ContinueAcc = cfgfile->GetNextGroup(accountname, itemindex);
270     
271         }
272   
275 XABPreferences::~XABPreferences(){
276         
279 bool XABPreferences::GetBoolData(wxString SettingName){
281         // GetBoolData from the XABPreferences object.
283         if (SettingName == wxT("SaveWindowPosition")) { return SaveWindowPos; }
284         else if (SettingName == wxT("HideLocalAddressBooks")) { return HideLocalABs; }
285         else if (SettingName == wxT("UseBackgroundContactColour")) { return UseBackgroundContactColour; }
286         
287         return false;
291 wxRect XABPreferences::GetMainWindowData(){
292         
293         // Return the main window data as a wxRect object.
294         
295         return MainWindowData;
299 void XABPreferences::SetMainWindowData(wxRect WindowData){
301         // Set the main window data from a wxRect object.
303         MainWindowData = WindowData;
307 wxColour XABPreferences::GetBackgroundContactColourData(){
308         
309         return BackgroundContactColour;
310         
313 void XABPreferences::SetBackgroundContactColourData(wxColour ColourData){
314         
315         BackgroundContactColour = ColourData;
316         
319 // XABPrefAccounts
321 XABPrefAccounts::XABPrefAccounts(){
323         // Setup the default values for XABPrefAccounts.
325         AccountsCount = 0;
326         
329 int XABPrefAccounts::AddAccount(wxString NewAccName,
330         wxString NewAccType,
331         wxString NewAccAddress,
332         int NewAccPort,
333         int NewAccSSL,
334         wxString NewAccUser,
335         wxString NewAccPass,
336         wxString NewAccDirPrefix,
337         wxString NewAccDir,
338         long NewAccRefresh
339 ){
340   
341         // Add an account to the list of accounts in the
342         // XABPrefAccounts object.
343   
344         AccountName.Add(NewAccName, 1);
345         AccountType.Add(NewAccType, 1);
346         AccountAddress.Add(NewAccAddress, 1);
347         AccountPort.Add(NewAccPort, 1);
348         AccountSSL.Add(NewAccSSL, 1);
349         AccountUsername.Add(NewAccUser, 1);
350         AccountPassword.Add(NewAccPass, 1);
351         DirectoryPrefix.Add(NewAccDirPrefix, 1);
352         AccountDirectory.Add(NewAccDir, 1);
353         AccountRefresh.Add(NewAccRefresh, 1);
354     
355         AccountsCount++;
356     
357         return 0;
361 int XABPrefAccounts::GetCount(){
362   
363         // Get the count of accounts in the XABPrefAccounts object.
364   
365         return AccountsCount;
366   
369 wxString XABPrefAccounts::GetAccountName(int AccountNum){
370  
371         // Get the account name.
372  
373         if (AccountNum > AccountsCount){
374                 return wxT("");
375         }
376   
377         return AccountName[AccountNum];
378   
381 wxString XABPrefAccounts::GetAccountType(int AccountNum){
382  
383         // Get the account type.
384  
385         if (AccountNum > AccountsCount){
386                 return wxT("");
387         }
388   
389         return AccountType[AccountNum];
390   
393 wxString XABPrefAccounts::GetAccountAddress(int AccountNum){
394  
395         // Get the account server address.
396  
397         if (AccountNum > AccountsCount){
398                 return wxT("");
399         }
400   
401         return AccountAddress[AccountNum];
402   
405 int XABPrefAccounts::GetAccountPort(int AccountNum){
406  
407         // Get the account server port.
408  
409         if (AccountNum > AccountsCount){
410                 return 0;
411         }
412   
413         return AccountPort[AccountNum];
414   
417 bool XABPrefAccounts::GetAccountSSL(int AccountNum){
418  
419         // Get the account server SSL support.
420  
421         if (AccountNum > AccountsCount){
422                 return wxT("");
423         }
424   
425         return AccountSSL[AccountNum];
426   
429 wxString XABPrefAccounts::GetAccountUsername(int AccountNum){
430  
431         // Get the account username.
432  
433         if (AccountNum > AccountsCount){
434                 return wxT("");
435         }
436   
437         return AccountUsername[AccountNum];
438   
441 wxString XABPrefAccounts::GetAccountPassword(int AccountNum){
442  
443         // Get the account password.
444  
445         if (AccountNum > AccountsCount){
446                 return wxT("");
447         }
448   
449         return AccountPassword[AccountNum];
450   
453 wxString XABPrefAccounts::GetAccountDirectory(int AccountNum){
454  
455         // Get the account directory.
456  
457         if (AccountNum > AccountsCount){
458                 return wxT("");
459         }
460   
461         return AccountDirectory[AccountNum];
462   
465 wxString XABPrefAccounts::GetAccountDirPrefix(int AccountNum){
466  
467         // Get the account server directory prefix.
468  
469         if (AccountNum > AccountsCount){
470                 return wxT("");
471         }
472   
473         return DirectoryPrefix[AccountNum];
474   
477 long XABPrefAccounts::GetAccountRefresh(int AccountNum){
479         // Get the account refresh time.
481         if (AccountNum > AccountsCount){
482                 return 0;
483         }
484   
485         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