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