1 // XCCalendarList.cpp - Xestia Calendar XCCalendarList widget class.
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
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.
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.
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){
24 // Setup the controls.
26 szrMain = new wxBoxSizer( wxVERTICAL );
27 this->SetSizer(szrMain);
28 this->SetSize(wxSize(350, 500));
32 XCCalendarList::~XCCalendarList(){
34 // Delete the calendar lists.
36 for (vector<XCCalendarListAccountCtrl*>::iterator accountCtrlIter = accountControlList.begin();
37 accountCtrlIter != accountControlList.end(); accountCtrlIter++){
39 delete *accountCtrlIter;
43 accountControlList.clear();
45 this->SetSizer(nullptr, true);
49 void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){
51 // Verify if the generated code has changed. Return if not.
53 CDSGetChecksumResult currentChecksum = dataStorage->GetChecksum("internal_updatedata");
55 if (checksumUpdate == currentChecksum.checksumValue){
57 // Checksum matches so return.
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();
68 for (vector<XCCalendarListAccountCtrl*>::iterator accountCtrlIter = accountControlList.begin();
69 accountCtrlIter != accountControlList.end(); accountCtrlIter++){
71 delete *accountCtrlIter;
75 accountControlList.clear();
77 // Get the list of accounts and create them one by one.
79 CDSAccountList accountListData = dataStorage->GetAccountList();
81 for (int AccountSeek = 0; AccountSeek < accountListData.accountList.size(); AccountSeek++){
83 // Create the control and add it to the list.
85 XCCalendarListAccountCtrl *newAccountCtrl = new XCCalendarListAccountCtrl(this, accountListData.accountList[AccountSeek].accountName);
86 newAccountCtrl->SetAccountID(accountListData.accountList[AccountSeek].accountID);
87 newAccountCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID);
89 szrMain->Add(newAccountCtrl, 0, wxEXPAND, 5);
91 if (find(calendarHiddenAccountsList.begin(), calendarHiddenAccountsList.end(), accountListData.accountList[AccountSeek].accountID) != calendarHiddenAccountsList.end()){
93 newAccountCtrl->SetCheckBoxValue(wxCHK_UNCHECKED);
97 accountControlList.push_back(newAccountCtrl);
99 // Get the list of calendars and create controls.
101 CDSCalendarList accountCalendarList = dataStorage->GetCalendarList(accountListData.accountList[AccountSeek].accountID);
103 for (int calendarSeek = 0; calendarSeek < accountCalendarList.calendarList.size(); calendarSeek++){
105 CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(accountListData.accountList[AccountSeek].accountName, accountCalendarList.calendarListTextID[calendarSeek]);
107 XCCalendarListCalendarCtrl *newCalendarCtrl = new XCCalendarListCalendarCtrl(this, calendarInfo.calendarName, calendarInfo.calendarColour);
108 newCalendarCtrl->SetCalendarID(accountCalendarList.calendarList[calendarSeek]);
110 newCalendarCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID);
112 if (find(calendarHiddenCalendarsList.begin(), calendarHiddenCalendarsList.end(), accountCalendarList.calendarList[calendarSeek]) != calendarHiddenCalendarsList.end()){
114 newCalendarCtrl->SetCheckBoxValue(wxCHK_UNCHECKED);
118 newAccountCtrl->AddCalendar(newCalendarCtrl);
120 szrMain->Add(newCalendarCtrl, 0, wxEXPAND, 5);
126 // Set the updated checksum.
128 checksumUpdate = currentChecksum.checksumValue;
134 std::vector<int> XCCalendarList::GetHiddenAccountsList(){
136 std::vector<int> accountList;
138 // Go through each of the account controls and work
139 // out which entries should be hidden based on account.
141 for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
142 accountListIter != accountControlList.end(); accountListIter++){
144 if ((*accountListIter)->GetShowCheckboxState() == wxCHK_UNCHECKED){
146 accountList.push_back((*accountListIter)->GetAccountID());
156 std::vector<int> XCCalendarList::GetHiddenCalendarsList(){
158 std::vector<int> calendarList;
160 // Go through each of the calendar controls and
161 // work out which entries should be hidden based on
164 for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
165 accountListIter != accountControlList.end(); accountListIter++){
167 // Get the list of hidden calendars.
169 vector<int> calendarHiddenList = (*accountListIter)->GetHiddenCalendarList();
171 for (vector<int>::iterator calendarHiddenIter = calendarHiddenList.begin();
172 calendarHiddenIter != calendarHiddenList.end(); calendarHiddenIter++){
174 vector<int>::iterator calendarHiddenFind = find(calendarList.begin(), calendarList.end(), *calendarHiddenIter);
176 if (calendarHiddenFind == calendarList.end()){
178 calendarList.push_back(*calendarHiddenIter);