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