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));
30 //scwMain = new wxScrolledWindow();
32 //szrScrolled = new wxBoxSizer( wxHORIZONTAL );
33 //scwMain->SetSizer(szrScrolled);
35 //szrMain->Add(scwMain, 0, wxEXPAND, 5);
41 XCCalendarList::~XCCalendarList(){
45 void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){
47 // Verify if the generated code has changed. Return if not.
49 CDSGetChecksumResult currentChecksum = dataStorage->GetChecksum("internal_updatedata");
51 if (checksumUpdate == currentChecksum.checksumValue){
53 // Checksum matches so return.
58 // TODO: Delete the old controls.
60 for (vector<XCCalendarListAccountCtrl*>::iterator accountCtrlIter = accountControlList.begin();
61 accountCtrlIter != accountControlList.end(); accountCtrlIter++){
63 delete *accountCtrlIter;
67 accountControlList.clear();
69 // Get the list of accounts and create them one by one.
71 CDSAccountList accountListData = dataStorage->GetAccountList();
73 for (int AccountSeek = 0; AccountSeek < accountListData.accountList.size(); AccountSeek++){
75 // Create the control and add it to the list.
77 XCCalendarListAccountCtrl *newAccountCtrl = new XCCalendarListAccountCtrl(this, accountListData.accountList[AccountSeek].accountName);
78 newAccountCtrl->SetAccountID(accountListData.accountList[AccountSeek].accountID);
80 szrMain->Add(newAccountCtrl, 0, wxEXPAND, 5);
82 accountControlList.push_back(newAccountCtrl);
84 // Get the list of calendars and create controls.
86 CDSCalendarList accountCalendarList = dataStorage->GetCalendarList(accountListData.accountList[AccountSeek].accountID);
88 for (int calendarSeek = 0; calendarSeek < accountCalendarList.calendarList.size(); calendarSeek++){
90 CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(accountListData.accountList[AccountSeek].accountName, accountCalendarList.calendarListTextID[calendarSeek]);
92 XCCalendarListCalendarCtrl *newCalendarCtrl = new XCCalendarListCalendarCtrl(this, calendarInfo.calendarName, calendarInfo.calendarColour);
93 newCalendarCtrl->SetCalendarID(accountCalendarList.calendarList[calendarSeek]);
95 newAccountCtrl->AddCalendar(newCalendarCtrl);
97 szrMain->Add(newCalendarCtrl, 0, wxEXPAND, 5);
103 // Set the updated checksum.
105 checksumUpdate = currentChecksum.checksumValue;
109 std::vector<int> XCCalendarList::GetHiddenAccountsList(){
111 std::vector<int> accountList;
113 // Go through each of the account controls and work
114 // out which entries should be hidden based on account.
116 for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
117 accountListIter != accountControlList.end(); accountListIter++){
119 if ((*accountListIter)->GetShowCheckboxState() == wxCHK_UNCHECKED){
121 accountList.push_back((*accountListIter)->GetAccountID());
131 std::vector<int> XCCalendarList::GetHiddenCalendarsList(){
133 std::vector<int> calendarList;
135 // Go through each of the calendar controls and
136 // work out which entries should be hidden based on
139 for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
140 accountListIter != accountControlList.end(); accountListIter++){
142 // Get the list of hidden calendars.
144 vector<int> calendarHiddenList = (*accountListIter)->GetHiddenCalendarList();
146 for (vector<int>::iterator calendarHiddenIter = calendarHiddenList.begin();
147 calendarHiddenIter != calendarHiddenList.end(); calendarHiddenIter++){
149 vector<int>::iterator calendarHiddenFind = find(calendarList.begin(), calendarList.end(), *calendarHiddenIter);
151 if (calendarHiddenFind == calendarList.end()){
153 calendarList.push_back(*calendarHiddenIter);