Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
camelCase: Converted code in widgets directory
[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));        
29                 
30 }
32 XCCalendarList::~XCCalendarList(){
33         
34 }
36 void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){
37         
38         // Verify if the generated code has changed. Return if not.
40         CDSGetChecksumResult currentChecksum = dataStorage->GetChecksum("internal_updatedata");
41         
42         if (checksumUpdate == currentChecksum.checksumValue){
43                 
44                 // Checksum matches so return.
45                 return;
46                 
47         }
48         
49         // Delete the old controls. Remember which setting the checkboxes were hidden so they
50         // can be restored later on.
52         vector<int> calendarHiddenAccountsList = GetHiddenAccountsList();       
53         vector<int> calendarHiddenCalendarsList = GetHiddenCalendarsList();
54         
55         for (vector<XCCalendarListAccountCtrl*>::iterator accountCtrlIter = accountControlList.begin();
56                 accountCtrlIter != accountControlList.end(); accountCtrlIter++){
57                 
58                 delete *accountCtrlIter;
59                         
60         }
61         
62         accountControlList.clear();
63         
64         // Get the list of accounts and create them one by one.
65         
66         CDSAccountList accountListData = dataStorage->GetAccountList();
67         
68         for (int AccountSeek = 0; AccountSeek < accountListData.accountList.size(); AccountSeek++){
69                 
70                 // Create the control and add it to the list.
71                 
72                 XCCalendarListAccountCtrl *newAccountCtrl = new XCCalendarListAccountCtrl(this, accountListData.accountList[AccountSeek].accountName);
73                 newAccountCtrl->SetAccountID(accountListData.accountList[AccountSeek].accountID);
74                 newAccountCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID);
75                 
76                 szrMain->Add(newAccountCtrl, 0, wxEXPAND, 5);
77                 
78                 if (find(calendarHiddenAccountsList.begin(), calendarHiddenAccountsList.end(), accountListData.accountList[AccountSeek].accountID) != calendarHiddenAccountsList.end()){
79                         
80                         newAccountCtrl->SetCheckBoxValue(wxCHK_UNCHECKED);
81                         
82                 }
83                 
84                 accountControlList.push_back(newAccountCtrl);
85                 
86                 // Get the list of calendars and create controls.
87                 
88                 CDSCalendarList accountCalendarList = dataStorage->GetCalendarList(accountListData.accountList[AccountSeek].accountID);
89                 
90                 for (int calendarSeek = 0; calendarSeek < accountCalendarList.calendarList.size(); calendarSeek++){
91                         
92                         CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(accountListData.accountList[AccountSeek].accountName, accountCalendarList.calendarListTextID[calendarSeek]);
93                         
94                         XCCalendarListCalendarCtrl *newCalendarCtrl = new XCCalendarListCalendarCtrl(this, calendarInfo.calendarName, calendarInfo.calendarColour);
95                         newCalendarCtrl->SetCalendarID(accountCalendarList.calendarList[calendarSeek]);
96                         
97                         newCalendarCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID);
99                         if (find(calendarHiddenCalendarsList.begin(), calendarHiddenCalendarsList.end(), accountCalendarList.calendarList[calendarSeek]) != calendarHiddenCalendarsList.end()){
100                         
101                                 newCalendarCtrl->SetCheckBoxValue(wxCHK_UNCHECKED);
102                         
103                         }
104                         
105                         newAccountCtrl->AddCalendar(newCalendarCtrl);
107                         szrMain->Add(newCalendarCtrl, 0, wxEXPAND, 5);
108                         
109                 }
110                 
111         }
112         
113         // Set the updated checksum.
114         
115         checksumUpdate = currentChecksum.checksumValue;
116         
119 std::vector<int> XCCalendarList::GetHiddenAccountsList(){
120         
121         std::vector<int> accountList;
122         
123         // Go through each of the account controls and work
124         // out which entries should be hidden based on account.
125         
126         for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
127                 accountListIter != accountControlList.end(); accountListIter++){
128         
129                 if ((*accountListIter)->GetShowCheckboxState() == wxCHK_UNCHECKED){
130                         
131                         accountList.push_back((*accountListIter)->GetAccountID());
132                         
133                 }
134                         
135         }
136         
137         return accountList;
138         
141 std::vector<int> XCCalendarList::GetHiddenCalendarsList(){
143         std::vector<int> calendarList;
144         
145         // Go through each of the calendar controls and
146         // work out which entries should be hidden based on
147         // calendar.
149         for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
150                 accountListIter != accountControlList.end(); accountListIter++){
151         
152                 // Get the list of hidden calendars.
153                 
154                 vector<int> calendarHiddenList = (*accountListIter)->GetHiddenCalendarList();
155                         
156                 for (vector<int>::iterator calendarHiddenIter = calendarHiddenList.begin();
157                         calendarHiddenIter != calendarHiddenList.end(); calendarHiddenIter++){
158                 
159                         vector<int>::iterator calendarHiddenFind = find(calendarList.begin(), calendarList.end(), *calendarHiddenIter);
160                         
161                         if (calendarHiddenFind == calendarList.end()){
163                                 calendarList.push_back(*calendarHiddenIter);
164                                 
165                         }
166                                 
167                 }
168                         
169         }
170         
171         return calendarList;
172         
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