Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Version 0.18 release
[xestiaab/.git] / source / common / defaults.cpp
1 // defaults.cpp - Default settings 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 "defaults.h"
21 using namespace std;
23 void SetupDefaultAddressBook(){
24     
25         // Setup the default address book if there are none.
26     
27         // Check if the 'Default.local' directory exists.
28     
29         wxString DefaultLocalDir;
30     
31 #if defined(__HAIKU__)
32         
33 #elif defined(__WIN32__)
34     
35         DefaultLocalDir.Clear();
36         DefaultLocalDir.Append(wxString::FromUTF8(getenv("APPDATA")));
37         DefaultLocalDir.Append(wxT("\\Xestia\\Address Book\\accounts\\"));
38         DefaultLocalDir.Append(wxT("Default.local"));
39     
40 #elif defined(__APPLE__)
41     
42         DefaultLocalDir.Clear();
43         DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
44         DefaultLocalDir.Append(wxT("/Library/Preferences/Xestia/Address Book/accounts/"));
45         DefaultLocalDir.Append(wxT("Default.local"));
46     
47 #else
48     
49         DefaultLocalDir.Clear();
50         DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
51         DefaultLocalDir.Append(wxT("/.xestiaab/accounts/"));
52         DefaultLocalDir.Append(wxT("Default.local"));
53     
54 #endif
55     
56         if (wxDirExists(DefaultLocalDir) == FALSE){
57         
58                 if (wxMkdir(DefaultLocalDir, 0740) == TRUE){
59             
60                 }
61         
62         }
63     
64 }
66 void SetupDefaultSettings(){
67     
68         // Setup the default settings if they don't exist.
69     
70         // Setup default (non account) settings if they don't exist.
71     
72         wxString DefaultPrefDir;
73     
74 #if defined(__HAIKU__)
75     
76     
77 #elif defined(__WIN32__)
78     
79         DefaultPrefDir.Clear();
80         DefaultPrefDir.Append(wxString::FromUTF8(getenv("APPDATA")));
81         DefaultPrefDir.Append(wxT("\\Xestia\\Address Book\\preferences\\"));
82     
83 #elif defined(__APPLE__)
84     
85         DefaultPrefDir.Clear();
86         DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
87         DefaultPrefDir.Append(wxT("/Library/Preferences/Xestia/Address Book/preferences/"));
88     
89 #else
90     
91         DefaultPrefDir.Clear();
92         DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
93         DefaultPrefDir.Append(wxT("/.xestiaab/preferences/"));
94     
95 #endif
96     
97         // Create the accounts file if it doesn't exist.
98     
99         if (wxFileExists(DefaultPrefDir + wxT("accounts")) == FALSE){
100         
101                 wxString AccountsFilename;
102                 wxFFile AccountsFile;
103         
104                 AccountsFilename = DefaultPrefDir;
105                 AccountsFilename.Append(wxT("accounts"));
106         
107 #if wxABI_VERSION < 20900
108                 AccountsFile.Open(AccountsFilename.c_str(), wxT("w"));
109 #else
110                 AccountsFile.Open(AccountsFilename, wxT("w"));
111 #endif
112         
113                 AccountsFile.Write(wxT(""));
114         
115         }
116     
117         // Create the preferences file if it doesn't exist.
118     
119         if (wxFileExists(DefaultPrefDir + wxT("settings")) == FALSE){
120         
121                 wxString PrefsFilename;
122                 wxFFile PrefsFile;
123         
124                 PrefsFilename = DefaultPrefDir;
125                 PrefsFilename.Append(wxT("settings"));
126         
127 #if wxABI_VERSION < 20900
128                 PrefsFile.Open(PrefsFilename.c_str(), wxT("w"));
129 #else
130                 PrefsFile.Open(PrefsFilename, wxT("w"));
131 #endif
132         
133                 PrefsFile.Write(wxT("HideLocalAddressBooks=false\nSaveWindowPosition=true\n"));
134         
135         }
136         
137         // Check if the default account is in the accounts list.
138         // Add it if it isn't.
139         
140         wxString accountsConfigFile = DefaultPrefDir;
141         accountsConfigFile.Append(wxT("accounts"));
142         
143         wxFileConfig *accountConfigData = new wxFileConfig("", "", accountsConfigFile);
144         
145         long itemIndex = 0;
146         wxString accountName;
147         wxString accountType;
148         wxString accountDirectory;
149         bool continueProcessing = false;
150         bool defaultCalendarExists = false;
151     
152         continueProcessing = accountConfigData->GetFirstGroup(accountName, itemIndex);
153         
154         while (continueProcessing){
156                 accountConfigData->SetPath(accountName);
157                 accountConfigData->Read(wxT("type"), &accountType);
158                 accountConfigData->Read(wxT("accountdir"), &accountDirectory);          
159                 
160                 if (accountType == wxT("Local") && accountDirectory == wxT("Default")){
161                         
162                         defaultCalendarExists = true;
163                         
164                 }
165                 
166                 continueProcessing = accountConfigData->GetNextGroup(accountName, itemIndex);
167                 
168         }
169         
170         if (defaultCalendarExists == false){
171                 
172                 // Create the account in the accounts file.
173                 
174                 accountConfigData->SetPath(wxT("/Default"));
175                 accountConfigData->Write(wxT("type"), wxT("Local"));
176                 accountConfigData->Write(wxT("accountdir"), wxT("Default"));
177                 accountConfigData->Write(wxT("prefix"), wxT(""));
178                 accountConfigData->Write(wxT("address"), wxT(""));
179                 accountConfigData->Write(wxT("port"), wxT(""));
180                 accountConfigData->Write(wxT("ssl"), wxT("false"));
181                 accountConfigData->Write(wxT("username"), wxT(""));
182                 accountConfigData->Write(wxT("password"), wxT(""));
183                 accountConfigData->Write(wxT("prefix"), wxT(""));
184                 accountConfigData->Write(wxT("refresh"), wxT("1800"));
185                 
186         }
187         
188         delete accountConfigData;
189         accountConfigData = nullptr;
190         
193 void SetupDirectories(){
194     
195         // Create the directories if they don't exist.
196     
197         wxString DefaultSettingsDir;
199 #if defined(__HAIKU__)
200     
201 #elif defined(__WIN32__)
202     
203         DefaultSettingsDir.Clear();
204         DefaultSettingsDir.Append(wxString::FromUTF8(getenv("APPDATA")));
205         DefaultSettingsDir.Append(wxT("\\Xestia\\"));
206     
207         if (wxDirExists(DefaultSettingsDir) == FALSE){
208         
209                 // Create the directory.
210         
211                 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
212             
213                 }
214         
215         }
216     
217         // 'Address Book' to the directory.
218     
219         DefaultSettingsDir.Append(wxT("\\Address Book\\"));
220     
221 #elif defined(__APPLE__)
222     
223         DefaultSettingsDir.Clear();
224         DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
225         DefaultSettingsDir.Append(wxT("/Library/Preferences/Xestia/"));
226     
227         if (wxDirExists(DefaultSettingsDir) == FALSE){
228         
229                 // Create the directory.
230         
231                 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
232             
233                 }
234         
235         }
236     
237         // Append 'Address Book' to the directory.
238     
239         DefaultSettingsDir.Append(wxT("/Address Book/"));
240     
241 #else
242     
243         DefaultSettingsDir.Clear();
244         DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
245         DefaultSettingsDir.Append(wxT("/.xestiaab/"));
246     
247 #endif
248     
249         // Check if the directory exists.
250     
251         if (wxDirExists(DefaultSettingsDir) == FALSE){
252         
253                 // Create the directory.
254         
255                 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){         
256             
257                 }
258         
259         }
260     
261         if (wxDirExists(DefaultSettingsDir + wxT("accounts")) == FALSE){
262         
263                 if (wxMkdir(DefaultSettingsDir + wxT("accounts"), 0740) == TRUE){               
264             
265                 }
266         
267         }
268     
269         if (wxDirExists(DefaultSettingsDir + wxT("preferences")) == FALSE){
270         
271                 if (wxMkdir(DefaultSettingsDir + wxT("preferences"), 0740) == TRUE){            
272             
273                 }
274         
275         }
276     
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