From 5b1cce07faa46fa19248ee845ff509d669b967cd Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 25 Dec 2016 01:27:18 +0000 Subject: [PATCH] Added existing common code from Xestia Address Book --- source/common/defaults.cpp | 222 ++++++++++++++++ source/common/defaults.h | 29 +++ source/common/dirs.cpp | 253 +++++++++++++++++++ source/common/dirs.h | 31 +++ source/common/preferences.cpp | 463 ++++++++++++++++++++++++++++++++++ source/common/preferences.h | 123 +++++++++ 6 files changed, 1121 insertions(+) create mode 100644 source/common/defaults.cpp create mode 100644 source/common/defaults.h create mode 100644 source/common/dirs.cpp create mode 100644 source/common/dirs.h create mode 100644 source/common/preferences.cpp create mode 100644 source/common/preferences.h diff --git a/source/common/defaults.cpp b/source/common/defaults.cpp new file mode 100644 index 0000000..51476de --- /dev/null +++ b/source/common/defaults.cpp @@ -0,0 +1,222 @@ +// defaults.cpp - Default settings subroutines. +// +// (c) 2012-2016 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 +#include + +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){ + + } + + } + +} + +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")); + + } + +} + +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){ + + } + + } + +} \ No newline at end of file diff --git a/source/common/defaults.h b/source/common/defaults.h new file mode 100644 index 0000000..2147597 --- /dev/null +++ b/source/common/defaults.h @@ -0,0 +1,29 @@ +// defaults.h - Default settings subroutines header. +// +// (c) 2012-2016 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 +#include + +#ifndef COMMON_DEFAULTS_H +#define COMMON_DEFAULTS_H + +void SetupDefaultCalendar(); +void SetupDefaultSettings(); +void SetupDirectories(); + +#endif \ No newline at end of file diff --git a/source/common/dirs.cpp b/source/common/dirs.cpp new file mode 100644 index 0000000..fa9442b --- /dev/null +++ b/source/common/dirs.cpp @@ -0,0 +1,253 @@ +// dirs.cpp - Directory subroutines. +// +// (c) 2012-2015 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 + +wxString GetUserDir() +{ + + // Get the user directory. + + wxString UserDir; + +#if defined(__HAIKU__) + +#elif defined(__WIN32__) + + UserDir.Clear(); + UserDir.Append(wxString::FromUTF8(getenv("APPDATA"))); + UserDir.Append(wxT("\\Xestia\\Calendar\\")); + +#elif defined(__APPLE__) + + UserDir.Clear(); + UserDir.Append(wxString::FromUTF8(getenv("HOME"))); + UserDir.Append(wxT("/Library/Preferences/Xestia/Calendar/")); + +#else + + UserDir.Clear(); + UserDir.Append(wxString::FromUTF8(getenv("HOME"))); + UserDir.Append(wxT("/.xestiacal/")); + +#endif + + return UserDir; + +} + +wxString GetUserPrefDir() +{ + + // Get the user preferences directory. + + wxString UserPrefDir; + +#if defined(__HAIKU__) + +#elif defined(__WIN32__) + + UserPrefDir.Clear(); + UserPrefDir.Append(wxString::FromUTF8(getenv("APPDATA"))); + UserPrefDir.Append(wxT("\\Xestia\\Calendar\\preferences\\")); + +#elif defined(__APPLE__) + + UserPrefDir.Clear(); + UserPrefDir.Append(wxString::FromUTF8(getenv("HOME"))); + UserPrefDir.Append(wxT("/Library/Preferences/Xestia/Calendar/preferences/")); + +#else + + UserPrefDir.Clear(); + UserPrefDir.Append(wxString::FromUTF8(getenv("HOME"))); + UserPrefDir.Append(wxT("/.xestiacal/preferences/")); + +#endif + + return UserPrefDir; + +} + +wxString GetAccountDir(wxString AccName, bool ServerCert) +{ + + // Get the account directory. + + wxString AccountDir; + +#if defined(__HAIKU__) + +#elif defined(__WIN32__) + + AccountDir.Clear(); + AccountDir.Append(wxString::FromUTF8(getenv("APPDATA"))); + AccountDir.Append(wxT("\\Xestia\\Calendar\\accounts\\")); + AccountDir.Append(AccName); + AccountDir.Append(wxT("\\")); + + if (ServerCert == TRUE){ + AccountDir.Append(wxT("server.crt")); + } + +#elif defined(__APPLE__) + + AccountDir.Clear(); + AccountDir.Append(wxString::FromUTF8(getenv("HOME"))); + AccountDir.Append(wxT("/Library/Preferences/Xestia/Calendar/accounts/")); + AccountDir.Append(AccName); + AccountDir.Append(wxT("/")); + + if (ServerCert == TRUE){ + AccountDir.Append(wxT("server.crt")); + } + +#else + + AccountDir.Clear(); + AccountDir.Append(wxString::FromUTF8(getenv("HOME"))); + AccountDir.Append(wxT("/.xestiacal/accounts/")); + AccountDir.Append(AccName); + AccountDir.Append(wxT("/")); + + if (ServerCert == TRUE){ + AccountDir.Append(wxT("server.crt")); + } + +#endif + + return AccountDir; + +} + +std::string GetAccountDir(std::string AccName, bool ServerCert) +{ + + // Get the account directory. + + std::string AccountDir; + +#if defined(__HAIKU__) + +#elif defined(__WIN32__) + + AccountDir.clear(); + AccountDir.append(getenv("APPDATA")); + AccountDir.append("\\Xestia\\Calendar\\accounts\\"); + AccountDir.append(AccName); + AccountDir.append("\\"); + + if (ServerCert == true){ + AccountDir.append("server.crt"); + } + +#elif defined(__APPLE__) + + AccountDir.clear(); + AccountDir.append(getenv("HOME")); + AccountDir.append("/Library/Preferences/Xestia/Calendar/accounts/"); + AccountDir.append(AccName); + AccountDir.append("/"); + + if (ServerCert == true){ + AccountDir.append("server.crt"); + } + +#else + + AccountDir.clear(); + AccountDir.append(getenv("HOME")); + AccountDir.append("/.xestiacal/accounts/"); + AccountDir.append(AccName); + AccountDir.append("/"); + + if (ServerCert == true){ + AccountDir.append("server.crt"); + } + +#endif + + return AccountDir; + +} + +wxString GetAccountsFile() +{ + + // Get the accounts preferences file. + + wxString AccountsFile; + +#if defined(__HAIKU__) + +#elif defined(__WIN32__) + + AccountsFile.Clear(); + AccountsFile.Append(wxString::FromUTF8(getenv("APPDATA"))); + AccountsFile.Append(wxT("\\Xestia\\Calendar\\preferences\\accounts")); + +#elif defined(__APPLE__) + + AccountsFile.Clear(); + AccountsFile.Append(wxString::FromUTF8(getenv("HOME"))); + AccountsFile.Append(wxT("/Library/Preferences/Xestia/Calendar/preferences/accounts")); + +#else + + AccountsFile.Clear(); + AccountsFile.Append(wxString::FromUTF8(getenv("HOME"))); + AccountsFile.Append(wxT("/.xestiacal/preferences/accounts")); + +#endif + + return AccountsFile; + +} + +wxString GetSettingsFile() +{ + + // Get the preferences general settings file. + + wxString SettingsFile; + +#if defined(__HAIKU__) + +#elif defined(__WIN32__) + + SettingsFile.Clear(); + SettingsFile.Append(wxString::FromUTF8(getenv("APPDATA"))); + SettingsFile.Append(wxT("\\Xestia\\Calendar\\preferences\\settings")); + +#elif defined(__APPLE__) + + SettingsFile.Clear(); + SettingsFile.Append(wxString::FromUTF8(getenv("HOME"))); + SettingsFile.Append(wxT("/Library/Preferences/Xestia/Calendar/preferences/settings")); + +#else + + SettingsFile.Clear(); + SettingsFile.Append(wxString::FromUTF8(getenv("HOME"))); + SettingsFile.Append(wxT("/.xestiacal/preferences/settings")); + +#endif + + return SettingsFile; + +} \ No newline at end of file diff --git a/source/common/dirs.h b/source/common/dirs.h new file mode 100644 index 0000000..b0d443c --- /dev/null +++ b/source/common/dirs.h @@ -0,0 +1,31 @@ +// dirs.h - Directory subroutines header. +// +// (c) 2012-2015 Xestia Software Development. +// +// This file is part of Xestia Address Book. +// +// Xestia Address Book 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 Address Book 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 Address Book. If not, see + +#ifndef DIRS_H +#define DIRS_H + +#include + +wxString GetUserDir(); +wxString GetUserPrefDir(); +wxString GetAccountDir(wxString AccName, bool ServerCert); +std::string GetAccountDir(std::string AccName, bool ServerCert); +wxString GetAccountsFile(); +wxString GetSettingsFile(); + +#endif \ No newline at end of file diff --git a/source/common/preferences.cpp b/source/common/preferences.cpp new file mode 100644 index 0000000..8c51693 --- /dev/null +++ b/source/common/preferences.cpp @@ -0,0 +1,463 @@ +// preferences.cpp - Preferences subroutines. +// +// (c) 2012-2016 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 +#include +#include +#include +#include + +#include "preferences.h" + +using namespace std; + +void SavePreferences(); +void LoadPreferences(); + +XCALPreferences::XCALPreferences(wxString PreferencesFilename){ + + // Load the settings into the XCALPreferences object using the + // settings file received in PreferencesFilename. + + wxString fullprefpath; + + bool accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid, + accountsslvalid, accountusernamevalid, accountpasswordvalid, + accountdirprefixvalid, accountdirvalid, accountrefreshvalid = FALSE; + + bool preaccountstage = FALSE; + bool isvalidaccount = FALSE; + bool isvalidsection = FALSE; + wxString accountname; + wxString accountaddress; + wxString accounttype; + long accountport = 8080; + long accountrefresh; + bool accountssl; + wxString accountusername; + wxString accountpassword; + wxString accountdirprefix; + wxString accountdir; + + wxString firstchar; + string s; + + wxString segmentname; + wxString segmentvalue; + + // Load the settings. + + fullprefpath.Append(PreferencesFilename); + fullprefpath.Append(wxT("settings")); + + wxFileConfig *settingfile = new wxFileConfig("", "", fullprefpath); + + wxString ValueInc; + settingfile->Read(wxT("SaveWindowPosition"), &ValueInc); + + if (ValueInc == wxT("true")){ + + SaveWindowPos = TRUE; + wxRect WindowPosition; + + long PosX, PosY, PosH, PosW = 0; + + bool PosXValid, PosYValid, PosHValid, PosWValid = FALSE; + + PosXValid = settingfile->Read(wxT("WindowPositionX"), &PosX); + PosYValid = settingfile->Read(wxT("WindowPositionY"), &PosY); + PosHValid = settingfile->Read(wxT("WindowPositionHeight"), &PosH); + PosWValid = settingfile->Read(wxT("WindowPositionWidth"), &PosW); + + if (PosXValid == TRUE && PosYValid == TRUE && PosHValid == TRUE && PosWValid == TRUE){ + + WindowPosition.SetX((int)PosX); + WindowPosition.SetY((int)PosY); + WindowPosition.SetHeight((int)PosH); + WindowPosition.SetWidth((int)PosW); + + } else { + + WindowPosition.SetX(-1); + WindowPosition.SetY(-1); + WindowPosition.SetHeight(500); + WindowPosition.SetWidth(300); + + } + + SetMainWindowData(WindowPosition); + + } + + settingfile->Read(wxT("HideLocalAddressBooks"), &ValueInc); + + if (ValueInc == wxT("true")){ + HideLocalABs = TRUE; + } + + delete settingfile; + settingfile = NULL; + + // Load the accounts. + + fullprefpath.Clear(); + fullprefpath.Append(PreferencesFilename); + fullprefpath.Append(wxT("accounts")); + + wxFileConfig *cfgfile = new wxFileConfig("AddressBook", "Xestia", fullprefpath); + + wxString EntryName, EntryValue; + wxString AccAdr, AccUsr, AccPass, AccPrefix, AccDir; + wxString AccSSLInc; + bool AccSSL = FALSE; + int AccRef, AccPort = 0; + long itemindex = 0; + bool ContinueAcc = TRUE; + + ContinueAcc = cfgfile->GetFirstGroup(accountname, itemindex); + + while (ContinueAcc){ + + cfgfile->SetPath(accountname); + cfgfile->Read(wxT("type"), &EntryValue); + + if (EntryValue == wxT("Local")){ + + // Get the account directory. + + cfgfile->Read(wxT("accountdir"), &AccDir); + + if (AccDir.Len() > 4){ + + accountdirvalid = TRUE; + + } else { + + accountdirvalid = FALSE; + + } + + if (accountdirvalid == TRUE){ + + accounts.AddAccount(accountname, wxT("Local"), wxT(""), 0, + 0, wxT(""), wxT(""), + wxT(""), AccDir, 0); + + } + + } else if (EntryValue == wxT("CalDAV")){ + + cfgfile->Read(wxT("accountdir"), &AccDir); + accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr); + accountportvalid = cfgfile->Read(wxT("port"), &AccPort); + accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc); + if (AccSSLInc == wxT("true")){ + AccSSL = TRUE; + } + else { + AccSSL = FALSE; + } + accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr); + accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass); + accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix); + accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef); + + if (AccDir.Len() > 4){ + + accountdirvalid = TRUE; + + } + + // Make sure it is not bigger than 65535 or less than 1. + // If so, default to port 8008. + + if (accountport < 1 || accountport > 65535){ + accountport = 8008; + accountportvalid = TRUE; + } + + accounts.AddAccount(accountname, wxT("CalDAV"), AccAdr, AccPort, + AccSSL, AccUsr, AccPass, + AccPrefix, AccDir, AccRef); + + } else { + + cfgfile->Read(wxT("accountdir"), &AccDir); + accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr); + accountportvalid = cfgfile->Read(wxT("port"), &AccPort); + accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc); + if (AccSSLInc == wxT("true")){ + AccSSL = TRUE; + } + else { + AccSSL = FALSE; + } + accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr); + accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass); + accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix); + accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef); + + if (AccDir.Len() > 4){ + + accountdirvalid = TRUE; + + } + + // Make sure it is not bigger than 65535 or less than 1. + // If so, default to port 8008. + + if (accountport < 1 || accountport > 65535){ + accountport = 8008; + accountportvalid = TRUE; + } + + accounts.AddAccount(accountname, EntryValue, AccAdr, AccPort, + AccSSL, AccUsr, AccPass, + AccPrefix, AccDir, AccRef); + + } + + // Clear up for the next account. + + accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid, + accountsslvalid, accountusernamevalid, accountpasswordvalid, + accountdirprefixvalid, accountdirvalid, accountrefreshvalid, accountssl, + isvalidaccount, isvalidsection = FALSE; + + AccAdr.Clear(); + AccDir.Clear(); + AccUsr.Clear(); + AccPass.Clear(); + AccPrefix.Clear(); + accountname.Clear(); + accountaddress.Clear(); + accounttype.Clear(); + accountport = 0; + accountrefresh = 0; + accountusername.Clear(); + accountpassword.Clear(); + accountdirprefix.Clear(); + preaccountstage = TRUE; + + cfgfile->SetPath(wxT("/")); + ContinueAcc = cfgfile->GetNextGroup(accountname, itemindex); + + } + +} + +XCALPreferences::~XCALPreferences(){ + +} + +bool XCALPreferences::GetBoolData(wxString SettingName){ + + // GetBoolData from the XCALPreferences object. + + if (SettingName == wxT("SaveWindowPosition")) { return SaveWindowPos; } + else if (SettingName == wxT("HideLocalAddressBooks")) { return HideLocalABs; } + + return FALSE; + +} + +wxRect XCALPreferences::GetMainWindowData(){ + + // Return the main window data as a wxRect object. + + return MainWindowData; + +} + +void XCALPreferences::SetMainWindowData(wxRect WindowData){ + + // Set the main window data from a wxRect object. + + MainWindowData = WindowData; + +} + +// XCALPrefAccounts + +XCALPrefAccounts::XCALPrefAccounts(){ + + // Setup the default values for XCALPrefAccounts. + + AccountsCount = 0; + +} + +int XCALPrefAccounts::AddAccount(wxString NewAccName, + wxString NewAccType, + wxString NewAccAddress, + int NewAccPort, + int NewAccSSL, + wxString NewAccUser, + wxString NewAccPass, + wxString NewAccDirPrefix, + wxString NewAccDir, + long NewAccRefresh +){ + + // Add an account to the list of accounts in the + // XCALPrefAccounts object. + + AccountName.Add(NewAccName, 1); + AccountType.Add(NewAccType, 1); + AccountAddress.Add(NewAccAddress, 1); + AccountPort.Add(NewAccPort, 1); + AccountSSL.Add(NewAccSSL, 1); + AccountUsername.Add(NewAccUser, 1); + AccountPassword.Add(NewAccPass, 1); + DirectoryPrefix.Add(NewAccDirPrefix, 1); + AccountDirectory.Add(NewAccDir, 1); + AccountRefresh.Add(NewAccRefresh, 1); + + AccountsCount++; + + return 0; + +} + +int XCALPrefAccounts::GetCount(){ + + // Get the count of accounts in the XCALPrefAccounts object. + + return AccountsCount; + +} + +wxString XCALPrefAccounts::GetAccountName(int AccountNum){ + + // Get the account name. + + if (AccountNum > AccountsCount){ + return wxT(""); + } + + return AccountName[AccountNum]; + +} + +wxString XCALPrefAccounts::GetAccountType(int AccountNum){ + + // Get the account type. + + if (AccountNum > AccountsCount){ + return wxT(""); + } + + return AccountType[AccountNum]; + +} + +wxString XCALPrefAccounts::GetAccountAddress(int AccountNum){ + + // Get the account server address. + + if (AccountNum > AccountsCount){ + return wxT(""); + } + + return AccountAddress[AccountNum]; + +} + +int XCALPrefAccounts::GetAccountPort(int AccountNum){ + + // Get the account server port. + + if (AccountNum > AccountsCount){ + return 0; + } + + return AccountPort[AccountNum]; + +} + +bool XCALPrefAccounts::GetAccountSSL(int AccountNum){ + + // Get the account server SSL support. + + if (AccountNum > AccountsCount){ + return wxT(""); + } + + return AccountSSL[AccountNum]; + +} + +wxString XCALPrefAccounts::GetAccountUsername(int AccountNum){ + + // Get the account username. + + if (AccountNum > AccountsCount){ + return wxT(""); + } + + return AccountUsername[AccountNum]; + +} + +wxString XCALPrefAccounts::GetAccountPassword(int AccountNum){ + + // Get the account password. + + if (AccountNum > AccountsCount){ + return wxT(""); + } + + return AccountPassword[AccountNum]; + +} + +wxString XCALPrefAccounts::GetAccountDirectory(int AccountNum){ + + // Get the account directory. + + if (AccountNum > AccountsCount){ + return wxT(""); + } + + return AccountDirectory[AccountNum]; + +} + +wxString XCALPrefAccounts::GetAccountDirPrefix(int AccountNum){ + + // Get the account server directory prefix. + + if (AccountNum > AccountsCount){ + return wxT(""); + } + + return DirectoryPrefix[AccountNum]; + +} + +long XCALPrefAccounts::GetAccountRefresh(int AccountNum){ + + // Get the account refresh time. + + if (AccountNum > AccountsCount){ + return 0; + } + + return AccountRefresh[AccountNum]; + +} \ No newline at end of file diff --git a/source/common/preferences.h b/source/common/preferences.h new file mode 100644 index 0000000..dd5c5c6 --- /dev/null +++ b/source/common/preferences.h @@ -0,0 +1,123 @@ +// preferences.h - Preferences subroutines header. +// +// (c) 2012-2016 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 + +#ifndef PREFERENCES_H +#define PREFERENCES_H + +#include +#include + +void SavePreferences(); +void LoadPreferences(); + +class XCALPrefThemes +{ +private: + +public: + wxArrayString ThemeName; + wxArrayString ThemeData; +}; + +class XCALPrefAccounts +{ +private: + wxArrayString AccountName; + wxArrayString AccountType; + wxArrayString AccountAddress; + wxArrayInt AccountPort; + wxArrayInt AccountSSL; + wxArrayString AccountUsername; + wxArrayString AccountPassword; + wxArrayString DirectoryPrefix; + wxArrayString AccountDirectory; + wxArrayLong AccountRefresh; + int AccountsCount; +public: + XCALPrefAccounts(); + + int GetCount(); + wxString GetAccountName(int AccountNum); + wxString GetAccountType(int AccountNum); + wxString GetAccountAddress(int AccountNum); + int GetAccountPort(int AcconutNum); + bool GetAccountSSL(int AccountNum); + wxString GetAccountUsername(int AccountNum); + wxString GetAccountPassword(int AccountNum); + wxString GetAccountDirectory(int AccountNum); + wxString GetAccountDirPrefix(int AccountNum); + long GetAccountRefresh(int AccountNum); + int AddAccount(wxString NewAccName, + wxString NewAccType, + wxString NewAccAddress, + int NewAccPort, + int NewAccSSL, + wxString NewAccUser, + wxString NewAccPass, + wxString NewAccDirPrefix, + wxString NewAccDir, + long NewAccRefresh + ); +}; + +//XCALPreferences should emulate what is in the Preferences window. +//Including others which aren't in the window such as main window +//position and size. + +class XCALPreferences +{ +private: + + // General Tab + bool SaveWindowPos = FALSE; + wxRect MainWindowData; + bool HideLocalABs = FALSE; + + // Themes tab + bool EnableThemes = FALSE; + + // Accounts tab + + // General things. + wxString Filename; + +public: + XCALPreferences(wxString PreferencesFilename); + ~XCALPreferences(); + + XCALPrefAccounts accounts; + XCALPrefThemes themes; + + int WritePreferences(); + int ReadPreferences(); + + bool GetBoolData(wxString SettingName); + bool SetBoolData(wxString SettingName, bool SettingValue); + wxRect GetMainWindowData(); + void SetMainWindowData(wxRect WindowData); + + //int AddAccount(wxString Name); + + int GetThemeCount(); + wxString GetThemeData(wxString ThemeName); + + int ErrorFlag; + +}; + +#endif -- 2.39.2