Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
8f00a1bd9574a356b55ea6e8a063ab3718046616
[xestiacalendar/.git] / source / forms / main / frmMain.cpp
1 #include "frmMain.h"
3 frmMain::frmMain( wxWindow* parent )
4 :
5 frmMainADT( parent )
6 {
7         
8         // Setup the default settings if they don't
9         // exist.
10         
11         // Setup the preferences.
12         wxString prefDirectory = GetUserPrefDir();
13         preferences = new XCALPreferences(prefDirectory);
14         
15         // Load the settings.
16         
17         wxString fullPrefPath;
18         
19         fullPrefPath.Append(prefDirectory);
20         fullPrefPath.Append(wxT("settings"));
22         wxFileConfig *settingfile = new wxFileConfig("", "", fullPrefPath);
23     
24         wxString ValueInc;
25         settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
26     
27         if (ValueInc == wxT("true")){
28                 
29                 wxRect windowPosition;
30         
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);
44                 } else {
46                         this->SetSize(-1, -1, 800, 600);
47                         
48                 }
49         
50         }
52         // Load the account data.
53         
54         LoadAccountData();
55         
56         // Setup the form control.
57         
58         mainCalendarCtrl = new XCCalendarCtrl(this, &calendarData);
59         szrMain->Add(mainCalendarCtrl, 1, wxEXPAND, 5);
60         szrMain->Layout();
61         
62 }
64 void frmMain::QuitApp( wxCloseEvent& event )
65 {
67         // Run the QuitApp function.
69         QuitApp();
71 }
73 void frmMain::QuitApp( wxCommandEvent& event )
74 {
75     
76         // Run the QuitApp function.
77     
78         QuitApp();
79     
80 }
82 void frmMain::QuitApp()
83 {
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"));
110 #else
112         // *nix OSes
114         SetFilename.Append(wxT("settings"));
116 #endif
118         wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
120         bool SaveWindowPos = false;
121         wxString SaveWindowInc;
122         cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
124         if (SaveWindowInc == wxT("true")){
125         
126                 SaveWindowPos = true;
127         
128         }
130         if (SaveWindowPos == true){
131         
132                 wxRect frmMainPos = this->GetRect();
133         
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());
138         
139         }
141         delete cfgfile;
142         cfgfile = nullptr;
144         //Everything closed... exit.
146         std::exit(0);
148         Close();
152 void frmMain::LoadAccountData(){
153         
154         // Get the list of accounts and put into the calendar data storage.
155         
156         int accountCount = preferences->accounts.GetCount();
157         
158         for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
159                 
160                 CDSAccountResult addResult = calendarData.AddAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
161                 
162         }
163         
164         // Get the list of calendars and put them into the calendar data storage.
165         
166         for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
167         
168                 CDSGetAccountInfo accountInfo = calendarData.GetAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
169         
170                 // Build the path.
171                 
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());
177                 
178                 // Get the list of calendars.
179                 
180                 XCAccountCalendarList calendarList(calendarListFilename);
181                 
182                 // Add the calendar and set the calendar ID for it.
183                 
184                 for (int calendarSeek = 0; calendarSeek < calendarList.calendarShortName.size(); calendarSeek++){
185                         
186                         // Add the calendar.
187                         
188                         CDSCalendarResult calendarAddResult = calendarData.AddCalendar(accountInfo.accountID, 
189                                 calendarList.calendarName[calendarSeek], 
190                                 calendarList.calendarShortName[calendarSeek],
191                                 calendarList.calendarColour[calendarSeek]);
192                         
193                         // Set the calendar ID.
194                         
195                         CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(string(preferences->accounts.GetAccountName(accountSeek).mb_str()), calendarList.calendarShortName[calendarSeek]);
196                         calendarList.calendarStorageID[calendarSeek] = calendarInfo.calendarID;
197                         
198                         // Find the entries and load each entry.
199                         
200                         string calendarListDirectory = calendarListFilename;
201                         calendarListDirectory += "/";
202                         calendarListDirectory += calendarList.calendarShortName[calendarSeek];
203                         calendarListDirectory += "/";
204                         
205                         wxDir entryListDirectory(calendarListDirectory);
206                         wxString entryListFilename;
207                         
208                         bool continueProcessing = entryListDirectory.GetFirst(&entryListFilename, "*.ics", wxDIR_NO_FOLLOW|wxDIR_FILES);
209                         
210                         while (continueProcessing){
211                                 
212                                 string entryListFullFilename;
213                                 entryListFullFilename += calendarListDirectory;
214                                 entryListFullFilename += string(entryListFilename.mb_str());
215                                 
216                                 continueProcessing = entryListDirectory.GetNext(&entryListFilename);
217                                 CDSAddEntryResult addEventResult = calendarData.AddEvent(calendarInfo.calendarID, entryListFullFilename);
218                                 
219                         }                       
220                         
221                 }
222                 
223         }
224         
227 void frmMain::ShowAboutWindow( wxCommandEvent& event )
230         // Show the about window.
231     
232         frmAbout *frameAbout = new frmAbout ( this );
233         frameAbout->SetupAboutWindow();
234         frameAbout->ShowModal();
235         delete frameAbout;
236         frameAbout = NULL;
237     
240 void frmMain::ShowUpdateWindow( wxCommandEvent& event )
243         frmUpdate *frameUpdate = new frmUpdate ( this );
244         frameUpdate->FetchData();
245         frameUpdate->ShowModal();
246         delete frameUpdate;
247         frameUpdate = NULL;
248         
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