Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Added code to setup, quit and load some account data
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 25 Dec 2016 01:31:31 +0000 (01:31 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 25 Dec 2016 01:31:31 +0000 (01:31 +0000)
source/forms/main/frmMain.cpp
source/forms/main/frmMain.h

index 47199f9..c46a8ae 100644 (file)
@@ -5,8 +5,195 @@ frmMain::frmMain( wxWindow* parent )
 frmMainADT( parent )
 {
        
-       MainCalendarCtrl = new XCCalendarCtrl(this);
-       szrMain->Add(MainCalendarCtrl, 1, wxEXPAND, 5);
+       mainCalendarCtrl = new XCCalendarCtrl(this, &calendarData);
+       
+       // Setup the default settings if they don't
+       // exist.
+       
+       // Setup the preferences.
+       wxString prefDirectory = GetUserPrefDir();
+       preferences = new XCALPreferences(prefDirectory);
+       
+       szrMain->Add(mainCalendarCtrl, 1, wxEXPAND, 5);
        szrMain->Layout();
        
+       // Load the settings.
+       
+       wxString fullPrefPath;
+       
+       fullPrefPath.Append(prefDirectory);
+       fullPrefPath.Append(wxT("settings"));
+
+       wxFileConfig *settingfile = new wxFileConfig("", "", fullPrefPath);
+    
+       wxString ValueInc;
+       settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
+    
+       if (ValueInc == wxT("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){
+
+                       this->SetSize(posX, posY, posH, posW);
+
+               } else {
+
+                       this->SetSize(-1, -1, 800, 600);
+                       
+               }
+       
+       }
+       
+       LoadAccountData();
+       
 }
+
+void frmMain::QuitApp( wxCloseEvent& event )
+{
+
+       // Run the QuitApp function.
+
+       QuitApp();
+
+}
+
+void frmMain::QuitApp( wxCommandEvent& event )
+{
+    
+       // Run the QuitApp function.
+    
+       QuitApp();
+    
+}
+
+void frmMain::QuitApp()
+{
+
+       // Function to run when quitting.
+
+       //Go through the windows and close each one (be it search
+       //or contact editor). Abort if user wants to cancel.
+
+       // Close the contact editor windows.
+
+       // Close the contact windows.
+
+       // Close the search windows.
+
+       // Write out the ETag databases.
+
+       // Save Preferences: Save the window position if that option is enabled.
+
+       wxString SetFilename = GetUserPrefDir();
+
+#if defined(__HAIKU__)
+
+
+
+#elif defined(__WIN32__)
+
+       SetFilename.Append(wxT("settings"));
+
+#else
+
+       // *nix OSes
+
+       SetFilename.Append(wxT("settings"));
+
+#endif
+
+       wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
+
+       bool SaveWindowPos = false;
+       wxString SaveWindowInc;
+       cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
+
+       if (SaveWindowInc == wxT("true")){
+        
+               SaveWindowPos = true;
+        
+       }
+
+       if (SaveWindowPos == true){
+        
+               wxRect frmMainPos = this->GetRect();
+        
+               cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
+               cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
+               cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
+               cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
+        
+       }
+
+       delete cfgfile;
+       cfgfile = nullptr;
+
+       //Everything closed... exit.
+
+       std::exit(0);
+
+       Close();
+
+}
+
+void frmMain::LoadAccountData(){
+       
+       // Get the list of accounts and put into the calendar data storage.
+       
+       int accountCount = preferences->accounts.GetCount();
+       
+       for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
+               
+               CDSAccountResult addResult = calendarData.AddAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
+               
+       }
+       
+       // Get the list of calendars and put them into the calendar data storage.
+       
+       for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
+       
+               CDSGetAccountInfo accountInfo = calendarData.GetAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
+       
+               // Build the path.
+               
+               string calendarListFilename = string(GetUserDir().mb_str());
+               calendarListFilename += "accounts/";
+               calendarListFilename += string(preferences->accounts.GetAccountDirectory(accountSeek).mb_str());
+               calendarListFilename += ".";
+               calendarListFilename += string(preferences->accounts.GetAccountType(accountSeek).mb_str());
+               
+               // Get the list of calendars.
+               
+               XCAccountCalendarList calendarList(calendarListFilename);
+               
+               // Add the calendar and set the calendar ID for it.
+               
+               for (int calendarSeek = 0; calendarSeek < calendarList.calendarShortName.size(); calendarSeek++){
+                       
+                       // Add the calendar.
+                       
+                       CDSCalendarResult calendarAddResult = calendarData.AddCalendar(accountInfo.accountID, 
+                               calendarList.calendarName[calendarSeek], 
+                               calendarList.calendarShortName[calendarSeek],
+                               calendarList.calendarColour[calendarSeek]);
+                       
+                       // Set the calendar ID.
+                       
+                       CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(string(preferences->accounts.GetAccountName(accountSeek).mb_str()), calendarList.calendarShortName[calendarSeek]);
+                       calendarList.calendarStorageID[calendarSeek] = calendarInfo.calendarID;
+                       
+               }
+               
+       }
+       
+}
\ No newline at end of file
index bce60c6..32017cc 100644 (file)
@@ -6,10 +6,15 @@
 Subclass of frmMainADT, which is generated by wxFormBuilder.
 */
 
+#include <map>
+
 #include "../../AppXestiaCalendar.h"
 #include "../../widgets/XCCalendarCtrl.h"
+#include "../../libraries/CalendarDataStorage/CalendarDataStorage.h"
+#include "../../objects/calendarlist/CalendarList.h"
 #include "events.h"
-
+#include "preferences.h"
+#include "dirs.h"
 
 //// end generated include
 
@@ -18,10 +23,17 @@ class frmMain : public frmMainADT
 {
        
        private:
-               XCCalendarCtrl *MainCalendarCtrl = nullptr;
-               XCCalendarMonthView *MonthViewCtrl = nullptr;
+               XCCalendarCtrl *mainCalendarCtrl = nullptr;
+               XCCalendarMonthView *monthViewCtrl = nullptr;
+               XCALPreferences *preferences = nullptr;
+               CalendarDataStorage calendarData;
        
        protected:
+               void QuitApp( wxCloseEvent& event );
+               void QuitApp( wxCommandEvent& event );
+               void QuitApp();
+               void LoadAccountData();
+
        
        public:
                /** Constructor */
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