Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
defaults: Check if default account exists each time XAB starts
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 15 Jan 2017 19:50:42 +0000 (19:50 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 15 Jan 2017 19:50:42 +0000 (19:50 +0000)
source/common/defaults.cpp
source/common/defaults.h

index 57a8ad5..9f89b0d 100644 (file)
@@ -16,8 +16,9 @@
 // You should have received a copy of the GNU General Public License along
 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
 
-#include <wx/wx.h>
-#include <wx/ffile.h>
+#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(){
index a54ab5d..6a783aa 100644 (file)
 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
 
 #include <iostream>
+
 #include <wx/wx.h>
+#include <wx/ffile.h>
+#include <wx/fileconf.h>
+
+#include "dirs.h"
 
 #ifndef COMMON_DEFAULTS_H
 #define COMMON_DEFAULTS_H
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy