From d4b44cdc2002d9214a0ae2528be8b1cab14c5120 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 22 Jan 2017 19:34:49 +0000 Subject: [PATCH] defaults: Ensure 'Default' local account is created --- source/common/defaults.cpp | 56 ++++++++++++++++++++++++++++++++++++-- source/common/defaults.h | 2 ++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/source/common/defaults.cpp b/source/common/defaults.cpp index 998a601..4e966ba 100644 --- a/source/common/defaults.cpp +++ b/source/common/defaults.cpp @@ -16,8 +16,7 @@ // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see -#include -#include +#include "defaults.h" void SetupDefaultCalendar(){ @@ -133,6 +132,59 @@ void SetupDefaultSettings(){ } + // 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(){ diff --git a/source/common/defaults.h b/source/common/defaults.h index 18f157a..ee2e50c 100644 --- a/source/common/defaults.h +++ b/source/common/defaults.h @@ -18,6 +18,8 @@ #include #include +#include +#include #ifndef COMMON_DEFAULTS_H #define COMMON_DEFAULTS_H -- 2.39.2