Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
defaults: Ensure 'Default' local account is created
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 22 Jan 2017 19:34:49 +0000 (19:34 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 22 Jan 2017 19:34:49 +0000 (19:34 +0000)
source/common/defaults.cpp
source/common/defaults.h

index 998a601..4e966ba 100644 (file)
@@ -16,8 +16,7 @@
 // You should have received a copy of the GNU General Public License along
 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
 
-#include <wx/wx.h>
-#include <wx/ffile.h>
+#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(){
index 18f157a..ee2e50c 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <iostream>
 #include <wx/wx.h>
+#include <wx/ffile.h>
+#include <wx/fileconf.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