3 frmMain::frmMain( wxWindow* parent )
8 // Setup the default settings if they don't
11 // Setup the preferences.
12 wxString prefDirectory = GetUserPrefDir();
13 preferences = new XCALPreferences(prefDirectory);
17 wxString fullPrefPath;
19 fullPrefPath.Append(prefDirectory);
20 fullPrefPath.Append(wxT("settings"));
22 wxFileConfig *settingfile = new wxFileConfig("", "", fullPrefPath);
25 settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
27 if (ValueInc == wxT("true")){
29 wxRect windowPosition;
31 long posX, posY, posH, posW = 0;
33 bool posXValid, posYValid, posHValid, posWValid = false;
35 posXValid = settingfile->Read(wxT("WindowPositionX"), &posX);
36 posYValid = settingfile->Read(wxT("WindowPositionY"), &posY);
37 posHValid = settingfile->Read(wxT("WindowPositionHeight"), &posH);
38 posWValid = settingfile->Read(wxT("WindowPositionWidth"), &posW);
40 if (posXValid == true && posYValid == true && posHValid == true && posWValid == true){
42 this->SetSize(posX, posY, posH, posW);
46 this->SetSize(-1, -1, 800, 600);
52 // Load the account data.
56 // Setup the form control.
58 mainCalendarCtrl = new XCCalendarCtrl(this, &calendarData);
59 szrMain->Add(mainCalendarCtrl, 1, wxEXPAND, 5);
64 void frmMain::QuitApp( wxCloseEvent& event )
67 // Run the QuitApp function.
73 void frmMain::QuitApp( wxCommandEvent& event )
76 // Run the QuitApp function.
82 void frmMain::QuitApp()
85 // Function to run when quitting.
87 //Go through the windows and close each one (be it search
88 //or contact editor). Abort if user wants to cancel.
90 // Close the contact editor windows.
92 // Close the contact windows.
94 // Close the search windows.
96 // Write out the ETag databases.
98 // Save Preferences: Save the window position if that option is enabled.
100 wxString SetFilename = GetUserPrefDir();
102 #if defined(__HAIKU__)
106 #elif defined(__WIN32__)
108 SetFilename.Append(wxT("settings"));
114 SetFilename.Append(wxT("settings"));
118 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
120 bool SaveWindowPos = false;
121 wxString SaveWindowInc;
122 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
124 if (SaveWindowInc == wxT("true")){
126 SaveWindowPos = true;
130 if (SaveWindowPos == true){
132 wxRect frmMainPos = this->GetRect();
134 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
135 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
136 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
137 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
144 //Everything closed... exit.
152 void frmMain::LoadAccountData(){
154 // Get the list of accounts and put into the calendar data storage.
156 int accountCount = preferences->accounts.GetCount();
158 for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
160 CDSAccountResult addResult = calendarData.AddAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
164 // Get the list of calendars and put them into the calendar data storage.
166 for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
168 CDSGetAccountInfo accountInfo = calendarData.GetAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
172 string calendarListFilename = string(GetUserDir().mb_str());
173 calendarListFilename += "accounts/";
174 calendarListFilename += string(preferences->accounts.GetAccountDirectory(accountSeek).mb_str());
175 calendarListFilename += ".";
176 calendarListFilename += string(preferences->accounts.GetAccountType(accountSeek).mb_str());
178 // Get the list of calendars.
180 XCAccountCalendarList calendarList(calendarListFilename);
182 // Add the calendar and set the calendar ID for it.
184 for (int calendarSeek = 0; calendarSeek < calendarList.calendarShortName.size(); calendarSeek++){
188 CDSCalendarResult calendarAddResult = calendarData.AddCalendar(accountInfo.accountID,
189 calendarList.calendarName[calendarSeek],
190 calendarList.calendarShortName[calendarSeek],
191 calendarList.calendarColour[calendarSeek]);
193 // Set the calendar ID.
195 CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(string(preferences->accounts.GetAccountName(accountSeek).mb_str()), calendarList.calendarShortName[calendarSeek]);
196 calendarList.calendarStorageID[calendarSeek] = calendarInfo.calendarID;
198 // Find the entries and load each entry.
200 string calendarListDirectory = calendarListFilename;
201 calendarListDirectory += "/";
202 calendarListDirectory += calendarList.calendarShortName[calendarSeek];
203 calendarListDirectory += "/";
205 wxDir entryListDirectory(calendarListDirectory);
206 wxString entryListFilename;
208 bool continueProcessing = entryListDirectory.GetFirst(&entryListFilename, "*.ics", wxDIR_NO_FOLLOW|wxDIR_FILES);
210 while (continueProcessing){
212 string entryListFullFilename;
213 entryListFullFilename += calendarListDirectory;
214 entryListFullFilename += string(entryListFilename.mb_str());
216 continueProcessing = entryListDirectory.GetNext(&entryListFilename);
217 CDSAddEntryResult addEventResult = calendarData.AddEvent(calendarInfo.calendarID, entryListFullFilename);
227 void frmMain::ShowAboutWindow( wxCommandEvent& event )
230 // Show the about window.
232 frmAbout *frameAbout = new frmAbout ( this );
233 frameAbout->SetupAboutWindow();
234 frameAbout->ShowModal();