// defaults.cpp - Default settings subroutines. // // (c) 2012-2017 Xestia Software Development. // // This file is part of Xestia Calendar. Originally from Xestia Address Book. // // Xestia Calendar is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Calendar is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #include "defaults.h" void SetupDefaultCalendar(){ // Setup the default calendar if there are none. // Check if the 'Default.local' directory exists. wxString defaultLocalDir; #if defined(__HAIKU__) #elif defined(__WIN32__) defaultLocalDir.Clear(); defaultLocalDir.Append(wxString::FromUTF8(getenv("APPDATA"))); defaultLocalDir.Append(wxT("\\Xestia\\Calendar\\accounts\\")); defaultLocalDir.Append(wxT("Default.local")); #elif defined(__APPLE__) defaultLocalDir.Clear(); defaultLocalDir.Append(wxString::FromUTF8(getenv("HOME"))); defaultLocalDir.Append(wxT("/Library/Preferences/Xestia/Calendar/accounts/")); defaultLocalDir.Append(wxT("Default.local")); #else defaultLocalDir.Clear(); defaultLocalDir.Append(wxString::FromUTF8(getenv("HOME"))); defaultLocalDir.Append(wxT("/.xestiacal/accounts/")); defaultLocalDir.Append(wxT("Default.Local")); #endif if (wxDirExists(defaultLocalDir) == FALSE){ if (wxMkdir(defaultLocalDir, 0740) == TRUE){ } wxFile defaultCalendarDB; #if defined(__WIN32__) defaultCalendarDB.Create(defaultLocalDir + "\\calendarlist.db", false, wxPOSIX_USER_READ|wxPOSIX_USER_WRITE|wxPOSIX_GROUP_READ); #else defaultCalendarDB.Create(defaultLocalDir + "/calendarlist.db", false, wxPOSIX_USER_READ|wxPOSIX_USER_WRITE|wxPOSIX_GROUP_READ); #endif } } void SetupDefaultSettings(){ // Setup the default settings if they don't exist. // Setup default (non account) settings if they don't exist. wxString defaultPrefDir; #if defined(__HAIKU__) #elif defined(__WIN32__) defaultPrefDir.Clear(); defaultPrefDir.Append(wxString::FromUTF8(getenv("APPDATA"))); defaultPrefDir.Append(wxT("\\Xestia\\Calendar\\preferences\\")); #elif defined(__APPLE__) defaultPrefDir.Clear(); defaultPrefDir.Append(wxString::FromUTF8(getenv("HOME"))); defaultPrefDir.Append(wxT("/Library/Preferences/Xestia/Calendar/preferences/")); #else defaultPrefDir.Clear(); defaultPrefDir.Append(wxString::FromUTF8(getenv("HOME"))); defaultPrefDir.Append(wxT("/.xestiacal/preferences/")); #endif // Create the accounts file if it doesn't exist. if (wxFileExists(defaultPrefDir + wxT("accounts")) == FALSE){ wxString accountsFilename; wxFFile accountsFile; accountsFilename = defaultPrefDir; accountsFilename.Append(wxT("accounts")); #if wxABI_VERSION < 20900 accountsFile.Open(accountsFilename.c_str(), wxT("w")); #else accountsFile.Open(accountsFilename, wxT("w")); #endif accountsFile.Write(wxT("")); } // Create the preferences file if it doesn't exist. if (wxFileExists(defaultPrefDir + wxT("settings")) == FALSE){ wxString prefsFilename; wxFFile prefsFile; prefsFilename = defaultPrefDir; prefsFilename.Append(wxT("settings")); #if wxABI_VERSION < 20900 prefsFile.Open(prefsFilename.c_str(), wxT("w")); #else prefsFile.Open(prefsFilename, wxT("w")); #endif prefsFile.Write(wxT("HideLocalCalendars=false\nSaveWindowPosition=true\n")); } // Check if the default account is in the accounts list. // Add it if it isn't. wxString accountsConfigFile = defaultPrefDir; accountsConfigFile.Append(wxT("accounts")); wxFileConfig *accountConfigData = new wxFileConfig("", "", accountsConfigFile); long itemIndex = 0; wxString accountName; wxString accountType; wxString accountDirectory; bool continueProcessing = false; bool defaultCalendarExists = false; continueProcessing = accountConfigData->GetFirstGroup(accountName, itemIndex); while (continueProcessing){ accountConfigData->SetPath(accountName); accountConfigData->Read(wxT("type"), &accountType); accountConfigData->Read(wxT("accountdir"), &accountDirectory); if (accountType == wxT("Local") && accountDirectory == wxT("Default")){ defaultCalendarExists = true; } continueProcessing = accountConfigData->GetNextGroup(accountName, itemIndex); } if (defaultCalendarExists == false){ // Create the account in the accounts file. accountConfigData->SetPath(wxT("/Default")); accountConfigData->Write(wxT("type"), wxT("Local")); accountConfigData->Write(wxT("accountdir"), wxT("Default")); accountConfigData->Write(wxT("prefix"), wxT("")); accountConfigData->Write(wxT("address"), wxT("")); accountConfigData->Write(wxT("port"), wxT("")); accountConfigData->Write(wxT("ssl"), wxT("false")); accountConfigData->Write(wxT("username"), wxT("")); accountConfigData->Write(wxT("password"), wxT("")); accountConfigData->Write(wxT("prefix"), wxT("")); } delete accountConfigData; accountConfigData = nullptr; } void SetupDirectories(){ // Create the directories if they don't exist. wxString defaultSettingsDir; #if defined(__HAIKU__) #elif defined(__WIN32__) defaultSettingsDir.Clear(); defaultSettingsDir.Append(wxString::FromUTF8(getenv("APPDATA"))); defaultSettingsDir.Append(wxT("\\Xestia\\")); if (wxDirExists(defaultSettingsDir) == FALSE){ // Create the directory. if (wxMkdir(defaultSettingsDir, 0740) == TRUE){ } } // 'Calendar' to the directory. defaultSettingsDir.Append(wxT("\\Calendar\\")); #elif defined(__APPLE__) defaultSettingsDir.Clear(); defaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME"))); defaultSettingsDir.Append(wxT("/Library/Preferences/Xestia/")); if (wxDirExists(defaultSettingsDir) == FALSE){ // Create the directory. if (wxMkdir(defaultSettingsDir, 0740) == TRUE){ } } // Append 'Calendar' to the directory. defaultSettingsDir.Append(wxT("/Calendar/")); #else defaultSettingsDir.Clear(); defaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME"))); defaultSettingsDir.Append(wxT("/.xestiacal/")); #endif // Check if the directory exists. if (wxDirExists(defaultSettingsDir) == FALSE){ // Create the directory. if (wxMkdir(defaultSettingsDir, 0740) == TRUE){ } } if (wxDirExists(defaultSettingsDir + wxT("accounts")) == FALSE){ if (wxMkdir(defaultSettingsDir + wxT("accounts"), 0740) == TRUE){ } } if (wxDirExists(defaultSettingsDir + wxT("preferences")) == FALSE){ if (wxMkdir(defaultSettingsDir + wxT("preferences"), 0740) == TRUE){ } } }