#include "frmMain.h" frmMain::frmMain( wxWindow* parent ) : frmMainADT( parent ) { 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; } } }