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