From df3db592b57a92dd99a97d769152da1492cdea0e Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 15 Jan 2017 19:50:42 +0000 Subject: [PATCH] defaults: Check if default account exists each time XAB starts --- source/common/defaults.cpp | 60 ++++++++++++++++++++++++++++++++++++-- source/common/defaults.h | 5 ++++ 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/source/common/defaults.cpp b/source/common/defaults.cpp index 57a8ad5..9f89b0d 100644 --- a/source/common/defaults.cpp +++ b/source/common/defaults.cpp @@ -16,8 +16,9 @@ // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see -#include -#include +#include "defaults.h" + +using namespace std; void SetupDefaultAddressBook(){ @@ -132,7 +133,60 @@ void SetupDefaultSettings(){ PrefsFile.Write(wxT("HideLocalAddressBooks=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(){ diff --git a/source/common/defaults.h b/source/common/defaults.h index a54ab5d..6a783aa 100644 --- a/source/common/defaults.h +++ b/source/common/defaults.h @@ -17,7 +17,12 @@ // with Xestia Address Book. If not, see #include + #include +#include +#include + +#include "dirs.h" #ifndef COMMON_DEFAULTS_H #define COMMON_DEFAULTS_H -- 2.39.2