Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Added code to setup, quit and load some account data
[xestiacalendar/.git] / source / forms / main / frmMain.cpp
1 #include "frmMain.h"
3 frmMain::frmMain( wxWindow* parent )
4 :
5 frmMainADT( parent )
6 {
7         
8         mainCalendarCtrl = new XCCalendarCtrl(this, &calendarData);
9         
10         // Setup the default settings if they don't
11         // exist.
12         
13         // Setup the preferences.
14         wxString prefDirectory = GetUserPrefDir();
15         preferences = new XCALPreferences(prefDirectory);
16         
17         szrMain->Add(mainCalendarCtrl, 1, wxEXPAND, 5);
18         szrMain->Layout();
19         
20         // Load the settings.
21         
22         wxString fullPrefPath;
23         
24         fullPrefPath.Append(prefDirectory);
25         fullPrefPath.Append(wxT("settings"));
27         wxFileConfig *settingfile = new wxFileConfig("", "", fullPrefPath);
28     
29         wxString ValueInc;
30         settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
31     
32         if (ValueInc == wxT("true")){
33                 
34                 wxRect windowPosition;
35         
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);
49                 } else {
51                         this->SetSize(-1, -1, 800, 600);
52                         
53                 }
54         
55         }
56         
57         LoadAccountData();
58         
59 }
61 void frmMain::QuitApp( wxCloseEvent& event )
62 {
64         // Run the QuitApp function.
66         QuitApp();
68 }
70 void frmMain::QuitApp( wxCommandEvent& event )
71 {
72     
73         // Run the QuitApp function.
74     
75         QuitApp();
76     
77 }
79 void frmMain::QuitApp()
80 {
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"));
107 #else
109         // *nix OSes
111         SetFilename.Append(wxT("settings"));
113 #endif
115         wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
117         bool SaveWindowPos = false;
118         wxString SaveWindowInc;
119         cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
121         if (SaveWindowInc == wxT("true")){
122         
123                 SaveWindowPos = true;
124         
125         }
127         if (SaveWindowPos == true){
128         
129                 wxRect frmMainPos = this->GetRect();
130         
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());
135         
136         }
138         delete cfgfile;
139         cfgfile = nullptr;
141         //Everything closed... exit.
143         std::exit(0);
145         Close();
149 void frmMain::LoadAccountData(){
150         
151         // Get the list of accounts and put into the calendar data storage.
152         
153         int accountCount = preferences->accounts.GetCount();
154         
155         for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
156                 
157                 CDSAccountResult addResult = calendarData.AddAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
158                 
159         }
160         
161         // Get the list of calendars and put them into the calendar data storage.
162         
163         for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
164         
165                 CDSGetAccountInfo accountInfo = calendarData.GetAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
166         
167                 // Build the path.
168                 
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());
174                 
175                 // Get the list of calendars.
176                 
177                 XCAccountCalendarList calendarList(calendarListFilename);
178                 
179                 // Add the calendar and set the calendar ID for it.
180                 
181                 for (int calendarSeek = 0; calendarSeek < calendarList.calendarShortName.size(); calendarSeek++){
182                         
183                         // Add the calendar.
184                         
185                         CDSCalendarResult calendarAddResult = calendarData.AddCalendar(accountInfo.accountID, 
186                                 calendarList.calendarName[calendarSeek], 
187                                 calendarList.calendarShortName[calendarSeek],
188                                 calendarList.calendarColour[calendarSeek]);
189                         
190                         // Set the calendar ID.
191                         
192                         CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(string(preferences->accounts.GetAccountName(accountSeek).mb_str()), calendarList.calendarShortName[calendarSeek]);
193                         calendarList.calendarStorageID[calendarSeek] = calendarInfo.calendarID;
194                         
195                 }
196                 
197         }
198         
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