1 // defaults.cpp - Default settings subroutines.
3 // (c) 2012-2016 Xestia Software Development.
5 // This file is part of Xestia Calendar. Originally from Xestia Address Book.
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.
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.
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/>
22 void SetupDefaultCalendar(){
24 // Setup the default calendar if there are none.
26 // Check if the 'Default.local' directory exists.
28 wxString DefaultLocalDir;
30 #if defined(__HAIKU__)
32 #elif defined(__WIN32__)
34 DefaultLocalDir.Clear();
35 DefaultLocalDir.Append(wxString::FromUTF8(getenv("APPDATA")));
36 DefaultLocalDir.Append(wxT("\\Xestia\\Calendar\\accounts\\"));
37 DefaultLocalDir.Append(wxT("Default.local"));
39 #elif defined(__APPLE__)
41 DefaultLocalDir.Clear();
42 DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
43 DefaultLocalDir.Append(wxT("/Library/Preferences/Xestia/Calendar/accounts/"));
44 DefaultLocalDir.Append(wxT("Default.local"));
48 DefaultLocalDir.Clear();
49 DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
50 DefaultLocalDir.Append(wxT("/.xestiacal/accounts/"));
51 DefaultLocalDir.Append(wxT("Default.local"));
55 if (wxDirExists(DefaultLocalDir) == FALSE){
57 if (wxMkdir(DefaultLocalDir, 0740) == TRUE){
65 void SetupDefaultSettings(){
67 // Setup the default settings if they don't exist.
69 // Setup default (non account) settings if they don't exist.
71 wxString DefaultPrefDir;
73 #if defined(__HAIKU__)
76 #elif defined(__WIN32__)
78 DefaultPrefDir.Clear();
79 DefaultPrefDir.Append(wxString::FromUTF8(getenv("APPDATA")));
80 DefaultPrefDir.Append(wxT("\\Xestia\\Calendar\\preferences\\"));
82 #elif defined(__APPLE__)
84 DefaultPrefDir.Clear();
85 DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
86 DefaultPrefDir.Append(wxT("/Library/Preferences/Xestia/Calendar/preferences/"));
90 DefaultPrefDir.Clear();
91 DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
92 DefaultPrefDir.Append(wxT("/.xestiacal/preferences/"));
96 // Create the accounts file if it doesn't exist.
98 if (wxFileExists(DefaultPrefDir + wxT("accounts")) == FALSE){
100 wxString AccountsFilename;
101 wxFFile AccountsFile;
103 AccountsFilename = DefaultPrefDir;
104 AccountsFilename.Append(wxT("accounts"));
106 #if wxABI_VERSION < 20900
107 AccountsFile.Open(AccountsFilename.c_str(), wxT("w"));
109 AccountsFile.Open(AccountsFilename, wxT("w"));
112 AccountsFile.Write(wxT(""));
116 // Create the preferences file if it doesn't exist.
118 if (wxFileExists(DefaultPrefDir + wxT("settings")) == FALSE){
120 wxString PrefsFilename;
123 PrefsFilename = DefaultPrefDir;
124 PrefsFilename.Append(wxT("settings"));
126 #if wxABI_VERSION < 20900
127 PrefsFile.Open(PrefsFilename.c_str(), wxT("w"));
129 PrefsFile.Open(PrefsFilename, wxT("w"));
132 PrefsFile.Write(wxT("HideLocalCalendars=false\nSaveWindowPosition=true\n"));
138 void SetupDirectories(){
140 // Create the directories if they don't exist.
142 wxString DefaultSettingsDir;
144 #if defined(__HAIKU__)
146 #elif defined(__WIN32__)
148 DefaultSettingsDir.Clear();
149 DefaultSettingsDir.Append(wxString::FromUTF8(getenv("APPDATA")));
150 DefaultSettingsDir.Append(wxT("\\Xestia\\"));
152 if (wxDirExists(DefaultSettingsDir) == FALSE){
154 // Create the directory.
156 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
162 // 'Calendar' to the directory.
164 DefaultSettingsDir.Append(wxT("\\Calendar\\"));
166 #elif defined(__APPLE__)
168 DefaultSettingsDir.Clear();
169 DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
170 DefaultSettingsDir.Append(wxT("/Library/Preferences/Xestia/"));
172 if (wxDirExists(DefaultSettingsDir) == FALSE){
174 // Create the directory.
176 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
182 // Append 'Calendar' to the directory.
184 DefaultSettingsDir.Append(wxT("/Calendar/"));
188 DefaultSettingsDir.Clear();
189 DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
190 DefaultSettingsDir.Append(wxT("/.xestiacal/"));
194 // Check if the directory exists.
196 if (wxDirExists(DefaultSettingsDir) == FALSE){
198 // Create the directory.
200 if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
206 if (wxDirExists(DefaultSettingsDir + wxT("accounts")) == FALSE){
208 if (wxMkdir(DefaultSettingsDir + wxT("accounts"), 0740) == TRUE){
214 if (wxDirExists(DefaultSettingsDir + wxT("preferences")) == FALSE){
216 if (wxMkdir(DefaultSettingsDir + wxT("preferences"), 0740) == TRUE){