Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Widget controls updated
[xestiacalendar/.git] / source / widgets / XCCalendarList.cpp
1 // XCCalendarList.cpp - Xestia Calendar XCCalendarList widget class.
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/> 
19 #include "XCCalendarList.h" 
21 XCCalendarList::XCCalendarList(wxWindow *parent)
22         : wxPopupTransientWindow (parent){
23                 
24         // Setup the controls.
25                 
26         szrMain = new wxBoxSizer( wxVERTICAL );
27         this->SetSizer(szrMain);
28         this->SetSize(wxSize(350, 500));
30         //scwMain = new wxScrolledWindow();
31         
32         //szrScrolled = new wxBoxSizer( wxHORIZONTAL );
33         //scwMain->SetSizer(szrScrolled);
34                 
35         //szrMain->Add(scwMain, 0, wxEXPAND, 5);
36         //szrMain->Layout();
37         
38                 
39 }
41 XCCalendarList::~XCCalendarList(){
42         
43 }
45 void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){
46         
47         // Verify if the generated code has changed. Return if not.
49         CDSGetChecksumResult currentChecksum = dataStorage->GetChecksum("internal_updatedata");
50         
51         if (checksumUpdate == currentChecksum.checksumValue){
52                 
53                 // Checksum matches so return.
54                 return;
55                 
56         }
57         
58         // Delete the old controls. Remember which setting the checkboxes were hidden so they
59         // can be restored later on.
61         vector<int> calendarHiddenAccountsList = GetHiddenAccountsList();       
62         vector<int> calendarHiddenCalendarsList = GetHiddenCalendarsList();
63         
64         for (vector<XCCalendarListAccountCtrl*>::iterator accountCtrlIter = accountControlList.begin();
65                 accountCtrlIter != accountControlList.end(); accountCtrlIter++){
66                 
67                 delete *accountCtrlIter;
68                         
69         }
70         
71         accountControlList.clear();
72         
73         // Get the list of accounts and create them one by one.
74         
75         CDSAccountList accountListData = dataStorage->GetAccountList();
76         
77         for (int AccountSeek = 0; AccountSeek < accountListData.accountList.size(); AccountSeek++){
78                 
79                 // Create the control and add it to the list.
80                 
81                 XCCalendarListAccountCtrl *newAccountCtrl = new XCCalendarListAccountCtrl(this, accountListData.accountList[AccountSeek].accountName);
82                 newAccountCtrl->SetAccountID(accountListData.accountList[AccountSeek].accountID);
83                 newAccountCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID);
84                 
85                 szrMain->Add(newAccountCtrl, 0, wxEXPAND, 5);
86                 
87                 if (find(calendarHiddenAccountsList.begin(), calendarHiddenAccountsList.end(), accountListData.accountList[AccountSeek].accountID) != calendarHiddenAccountsList.end()){
88                         
89                         newAccountCtrl->SetCheckBoxValue(wxCHK_UNCHECKED);
90                         
91                 }
92                 
93                 accountControlList.push_back(newAccountCtrl);
94                 
95                 // Get the list of calendars and create controls.
96                 
97                 CDSCalendarList accountCalendarList = dataStorage->GetCalendarList(accountListData.accountList[AccountSeek].accountID);
98                 
99                 for (int calendarSeek = 0; calendarSeek < accountCalendarList.calendarList.size(); calendarSeek++){
100                         
101                         CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(accountListData.accountList[AccountSeek].accountName, accountCalendarList.calendarListTextID[calendarSeek]);
102                         
103                         XCCalendarListCalendarCtrl *newCalendarCtrl = new XCCalendarListCalendarCtrl(this, calendarInfo.calendarName, calendarInfo.calendarColour);
104                         newCalendarCtrl->SetCalendarID(accountCalendarList.calendarList[calendarSeek]);
105                         
106                         newCalendarCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID);
108                         if (find(calendarHiddenCalendarsList.begin(), calendarHiddenCalendarsList.end(), accountCalendarList.calendarList[calendarSeek]) != calendarHiddenCalendarsList.end()){
109                         
110                                 newCalendarCtrl->SetCheckBoxValue(wxCHK_UNCHECKED);
111                         
112                         }
113                         
114                         newAccountCtrl->AddCalendar(newCalendarCtrl);
116                         szrMain->Add(newCalendarCtrl, 0, wxEXPAND, 5);
117                         
118                 }
119                 
120         }
121         
122         // Set the updated checksum.
123         
124         checksumUpdate = currentChecksum.checksumValue;
125         
128 std::vector<int> XCCalendarList::GetHiddenAccountsList(){
129         
130         std::vector<int> accountList;
131         
132         // Go through each of the account controls and work
133         // out which entries should be hidden based on account.
134         
135         for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
136                 accountListIter != accountControlList.end(); accountListIter++){
137         
138                 if ((*accountListIter)->GetShowCheckboxState() == wxCHK_UNCHECKED){
139                         
140                         accountList.push_back((*accountListIter)->GetAccountID());
141                         
142                 }
143                         
144         }
145         
146         return accountList;
147         
150 std::vector<int> XCCalendarList::GetHiddenCalendarsList(){
152         std::vector<int> calendarList;
153         
154         // Go through each of the calendar controls and
155         // work out which entries should be hidden based on
156         // calendar.
158         for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
159                 accountListIter != accountControlList.end(); accountListIter++){
160         
161                 // Get the list of hidden calendars.
162                 
163                 vector<int> calendarHiddenList = (*accountListIter)->GetHiddenCalendarList();
164                         
165                 for (vector<int>::iterator calendarHiddenIter = calendarHiddenList.begin();
166                         calendarHiddenIter != calendarHiddenList.end(); calendarHiddenIter++){
167                 
168                         vector<int>::iterator calendarHiddenFind = find(calendarList.begin(), calendarList.end(), *calendarHiddenIter);
169                         
170                         if (calendarHiddenFind == calendarList.end()){
172                                 calendarList.push_back(*calendarHiddenIter);
173                                 
174                         }
175                                 
176                 }
177                         
178         }
179         
180         return calendarList;
181         
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