3 frmMain::frmMain( wxWindow* parent )
8 mainCalendarCtrl = new XCCalendarCtrl(this, &calendarData);
10 // Setup the default settings if they don't
13 // Setup the preferences.
14 wxString prefDirectory = GetUserPrefDir();
15 preferences = new XCALPreferences(prefDirectory);
17 szrMain->Add(mainCalendarCtrl, 1, wxEXPAND, 5);
22 wxString fullPrefPath;
24 fullPrefPath.Append(prefDirectory);
25 fullPrefPath.Append(wxT("settings"));
27 wxFileConfig *settingfile = new wxFileConfig("", "", fullPrefPath);
30 settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
32 if (ValueInc == wxT("true")){
34 wxRect windowPosition;
36 long posX, posY, posH, posW = 0;
38 bool posXValid, posYValid, posHValid, posWValid = false;
40 posXValid = settingfile->Read(wxT("WindowPositionX"), &posX);
41 posYValid = settingfile->Read(wxT("WindowPositionY"), &posY);
42 posHValid = settingfile->Read(wxT("WindowPositionHeight"), &posH);
43 posWValid = settingfile->Read(wxT("WindowPositionWidth"), &posW);
45 if (posXValid == true && posYValid == true && posHValid == true && posWValid == true){
47 this->SetSize(posX, posY, posH, posW);
51 this->SetSize(-1, -1, 800, 600);
61 void frmMain::QuitApp( wxCloseEvent& event )
64 // Run the QuitApp function.
70 void frmMain::QuitApp( wxCommandEvent& event )
73 // Run the QuitApp function.
79 void frmMain::QuitApp()
82 // Function to run when quitting.
84 //Go through the windows and close each one (be it search
85 //or contact editor). Abort if user wants to cancel.
87 // Close the contact editor windows.
89 // Close the contact windows.
91 // Close the search windows.
93 // Write out the ETag databases.
95 // Save Preferences: Save the window position if that option is enabled.
97 wxString SetFilename = GetUserPrefDir();
99 #if defined(__HAIKU__)
103 #elif defined(__WIN32__)
105 SetFilename.Append(wxT("settings"));
111 SetFilename.Append(wxT("settings"));
115 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
117 bool SaveWindowPos = false;
118 wxString SaveWindowInc;
119 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
121 if (SaveWindowInc == wxT("true")){
123 SaveWindowPos = true;
127 if (SaveWindowPos == true){
129 wxRect frmMainPos = this->GetRect();
131 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
132 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
133 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
134 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
141 //Everything closed... exit.
149 void frmMain::LoadAccountData(){
151 // Get the list of accounts and put into the calendar data storage.
153 int accountCount = preferences->accounts.GetCount();
155 for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
157 CDSAccountResult addResult = calendarData.AddAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
161 // Get the list of calendars and put them into the calendar data storage.
163 for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
165 CDSGetAccountInfo accountInfo = calendarData.GetAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
169 string calendarListFilename = string(GetUserDir().mb_str());
170 calendarListFilename += "accounts/";
171 calendarListFilename += string(preferences->accounts.GetAccountDirectory(accountSeek).mb_str());
172 calendarListFilename += ".";
173 calendarListFilename += string(preferences->accounts.GetAccountType(accountSeek).mb_str());
175 // Get the list of calendars.
177 XCAccountCalendarList calendarList(calendarListFilename);
179 // Add the calendar and set the calendar ID for it.
181 for (int calendarSeek = 0; calendarSeek < calendarList.calendarShortName.size(); calendarSeek++){
185 CDSCalendarResult calendarAddResult = calendarData.AddCalendar(accountInfo.accountID,
186 calendarList.calendarName[calendarSeek],
187 calendarList.calendarShortName[calendarSeek],
188 calendarList.calendarColour[calendarSeek]);
190 // Set the calendar ID.
192 CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(string(preferences->accounts.GetAccountName(accountSeek).mb_str()), calendarList.calendarShortName[calendarSeek]);
193 calendarList.calendarStorageID[calendarSeek] = calendarInfo.calendarID;