Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
camelCase: Converted remaining code that was missed
[xestiacalendar/.git] / source / common / preferences.cpp
1 // preferences.cpp - Preferences subroutines.
2 //
3 // (c) 2012-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar. Originally from Xestia Address Book.
6 //
7 // Xestia Calendar 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 Calendar 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 Calendar. 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 XCALPreferences::XCALPreferences(wxString preferencesFilename){
34         // Load the settings into the XCALPreferences 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;
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         delete settingFile;
114         settingFile = NULL;
115     
116         // Load the accounts.
117     
118         fullPrefPath.Clear();
119         fullPrefPath.Append(preferencesFilename);
120         fullPrefPath.Append(wxT("accounts"));
121  
122         wxFileConfig *cfgFile = new wxFileConfig("AddressBook", "Xestia", fullPrefPath);
123     
124         wxString entryName, entryValue;
125         wxString accAdr, accUsr, accPass, accPrefix, accDir;
126         wxString accSSLInc;
127         bool accSSL = FALSE;
128         int accRef, accPort = 0;
129         long itemIndex = 0;
130         bool continueAcc = TRUE;
131     
132         continueAcc = cfgFile->GetFirstGroup(accountName, itemIndex);
133     
134         while (continueAcc){
136                 cfgFile->SetPath(accountName);
137                 cfgFile->Read(wxT("type"), &entryValue);
138          
139                 if (entryValue == wxT("Local")){
140         
141                         // Get the account directory.
142         
143                         cfgFile->Read(wxT("accountdir"), &accDir);
144         
145                         if (accDir.Len() > 4){
147                                 accountDirValid = TRUE;
148             
149                         } else {
151                                 accountDirValid = FALSE;
153                         }
154             
155                         if (accountDirValid == TRUE){
156             
157                                 accounts.AddAccount(accountName, wxT("Local"), wxT(""), 0,
158                                         0, wxT(""), wxT(""), 
159                                         wxT(""), accDir, 0);
160             
161                         }
162         
163                 } else if (entryValue == wxT("CalDAV")){
165                         cfgFile->Read(wxT("accountdir"), &accDir);
166                         accountAddressValid = cfgFile->Read(wxT("address"), &accAdr);
167                         accountPortValid = cfgFile->Read(wxT("port"), &accPort);
168                         accountSSLValid = cfgFile->Read(wxT("ssl"), &accSSLInc);
169                         if (accSSLInc == wxT("true")){
170                                 accSSL = TRUE;
171                         }
172                         else {
173                                 accSSL = FALSE;
174                         }
175                         accountUsernameValid = cfgFile->Read(wxT("username"), &accUsr);
176                         accountPasswordValid = cfgFile->Read(wxT("password"), &accPass);
177                         accountDirPrefixValid = cfgFile->Read(wxT("prefix"), &accPrefix);
178                         accountRefreshValid = cfgFile->Read(wxT("refresh"), &accRef);
179             
180                         if (accDir.Len() > 4){
182                                 accountDirValid = TRUE;
183             
184                         }
185                 
186                         // Make sure it is not bigger than 65535 or less than 1.
187                         // If so, default to port 8008.
188                 
189                         if (accountPort < 1 || accountPort > 65535){
190                                 accountPort = 8008;
191                                 accountPortValid = TRUE;
192                         }
193             
194                         accounts.AddAccount(accountName, wxT("CalDAV"), accAdr, accPort,
195                                 accSSL, accUsr, accPass, 
196                                 accPrefix, accDir, accRef);
197             
198                 } else {
199                         
200                         cfgFile->Read(wxT("accountdir"), &accDir);
201                         accountAddressValid = cfgFile->Read(wxT("address"), &accAdr);
202                         accountPortValid = cfgFile->Read(wxT("port"), &accPort);
203                         accountSSLValid = cfgFile->Read(wxT("ssl"), &accSSLInc);
204                         if (accSSLInc == wxT("true")){
205                                 accSSL = TRUE;
206                         }
207                         else {
208                                 accSSL = FALSE;
209                         }
210                         accountUsernameValid = cfgFile->Read(wxT("username"), &accUsr);
211                         accountPasswordValid = cfgFile->Read(wxT("password"), &accPass);
212                         accountDirPrefixValid = cfgFile->Read(wxT("prefix"), &accPrefix);
213                         accountRefreshValid = cfgFile->Read(wxT("refresh"), &accRef);
214             
215                         if (accDir.Len() > 4){
217                                 accountDirValid = TRUE;
218             
219                         }
220                 
221                         // Make sure it is not bigger than 65535 or less than 1.
222                         // If so, default to port 8008.
223                 
224                         if (accountPort < 1 || accountPort > 65535){
225                                 accountPort = 8008;
226                                 accountPortValid = TRUE;
227                         }
228             
229                         accounts.AddAccount(accountName, entryValue, accAdr, accPort,
230                                 accSSL, accUsr, accPass, 
231                                 accPrefix, accDir, accRef);
232                         
233                 }
235                 // Clear up for the next account.
236     
237                 accountNameValid, accountAddressValid, accountTypeValid, accountPortValid,
238                 accountSSLValid, accountUsernameValid, accountPasswordValid,
239                 accountDirPrefixValid, accountDirValid, accountRefreshValid, accountSSL,
240                 isValidAccount, isValidSection = FALSE;
241         
242                 accAdr.Clear();
243                 accDir.Clear();
244                 accUsr.Clear();
245                 accPass.Clear();
246                 accPrefix.Clear();
247                 accountName.Clear();
248                 accountAddress.Clear();
249                 accountType.Clear();
250                 accountPort = 0;
251                 accountRefresh = 0;
252                 accountUsername.Clear();
253                 accountPassword.Clear();
254                 accountDirPrefix.Clear();
255                 preAccountStage = TRUE;
256     
257                 cfgFile->SetPath(wxT("/"));
258                 continueAcc = cfgFile->GetNextGroup(accountName, itemIndex);
259     
260         }
261   
264 XCALPreferences::~XCALPreferences(){
265         
268 bool XCALPreferences::GetBoolData(wxString settingName){
270         // GetBoolData from the XCALPreferences object.
272         if (settingName == wxT("SaveWindowPosition")) { return saveWindowPos; }
273         else if (settingName == wxT("HideLocalAddressBooks")) { return hideLocalABs; }
274         
275         return FALSE;
279 wxRect XCALPreferences::GetMainWindowData(){
280         
281         // Return the main window data as a wxRect object.
282         
283         return mainWindowData;
287 void XCALPreferences::SetMainWindowData(wxRect windowData){
289         // Set the main window data from a wxRect object.
291         mainWindowData = windowData;
295 // XCALPrefAccounts
297 XCALPrefAccounts::XCALPrefAccounts(){
299         // Setup the default values for XCALPrefAccounts.
301         accountsCount = 0;
302         
305 int XCALPrefAccounts::AddAccount(wxString newAccName,
306         wxString newAccType,
307         wxString newAccAddress,
308         int newAccPort,
309         int newAccSSL,
310         wxString newAccUser,
311         wxString newAccPass,
312         wxString newAccDirPrefix,
313         wxString newAccDir,
314         long newAccRefresh
315 ){
316   
317         // Add an account to the list of accounts in the
318         // XCALPrefAccounts object.
319   
320         accountName.Add(newAccName, 1);
321         accountType.Add(newAccType, 1);
322         accountAddress.Add(newAccAddress, 1);
323         accountPort.Add(newAccPort, 1);
324         accountSSL.Add(newAccSSL, 1);
325         accountUsername.Add(newAccUser, 1);
326         accountPassword.Add(newAccPass, 1);
327         directoryPrefix.Add(newAccDirPrefix, 1);
328         accountDirectory.Add(newAccDir, 1);
329         accountRefresh.Add(newAccRefresh, 1);
330     
331         accountsCount++;
332     
333         return 0;
337 int XCALPrefAccounts::GetCount(){
338   
339         // Get the count of accounts in the XCALPrefAccounts object.
340   
341         return accountsCount;
342   
345 wxString XCALPrefAccounts::GetAccountName(int accountNum){
346  
347         // Get the account name.
348  
349         if (accountNum > accountsCount){
350                 return wxT("");
351         }
352   
353         return accountName[accountNum];
354   
357 wxString XCALPrefAccounts::GetAccountType(int accountNum){
358  
359         // Get the account type.
360  
361         if (accountNum > accountsCount){
362                 return wxT("");
363         }
364   
365         return accountType[accountNum];
366   
369 wxString XCALPrefAccounts::GetAccountAddress(int accountNum){
370  
371         // Get the account server address.
372  
373         if (accountNum > accountsCount){
374                 return wxT("");
375         }
376   
377         return accountAddress[accountNum];
378   
381 int XCALPrefAccounts::GetAccountPort(int accountNum){
382  
383         // Get the account server port.
384  
385         if (accountNum > accountsCount){
386                 return 0;
387         }
388   
389         return accountPort[accountNum];
390   
393 bool XCALPrefAccounts::GetAccountSSL(int accountNum){
394  
395         // Get the account server SSL support.
396  
397         if (accountNum > accountsCount){
398                 return wxT("");
399         }
400   
401         return accountSSL[accountNum];
402   
405 wxString XCALPrefAccounts::GetAccountUsername(int accountNum){
406  
407         // Get the account username.
408  
409         if (accountNum > accountsCount){
410                 return wxT("");
411         }
412   
413         return accountUsername[accountNum];
414   
417 wxString XCALPrefAccounts::GetAccountPassword(int accountNum){
418  
419         // Get the account password.
420  
421         if (accountNum > accountsCount){
422                 return wxT("");
423         }
424   
425         return accountPassword[accountNum];
426   
429 wxString XCALPrefAccounts::GetAccountDirectory(int accountNum){
430  
431         // Get the account directory.
432  
433         if (accountNum > accountsCount){
434                 return wxT("");
435         }
436   
437         return accountDirectory[accountNum];
438   
441 wxString XCALPrefAccounts::GetAccountDirPrefix(int accountNum){
442  
443         // Get the account server directory prefix.
444  
445         if (accountNum > accountsCount){
446                 return wxT("");
447         }
448   
449         return directoryPrefix[accountNum];
450   
453 long XCALPrefAccounts::GetAccountRefresh(int accountNum){
455         // Get the account refresh time.
457         if (accountNum > accountsCount){
458                 return 0;
459         }
460   
461         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