// XCCalendarList.cpp - Xestia Calendar XCCalendarList widget class.
//
// (c) 2016 Xestia Software Development.
//
// This file is part of Xestia Calendar.
//
// Xestia Address Book is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Address Book is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Calendar. If not, see
#include "XCCalendarList.h"
XCCalendarList::XCCalendarList(wxWindow *parent)
: wxPopupTransientWindow (parent){
// Setup the controls.
szrMain = new wxBoxSizer( wxVERTICAL );
this->SetSizer(szrMain);
this->SetSize(wxSize(350, 500));
//scwMain = new wxScrolledWindow();
//szrScrolled = new wxBoxSizer( wxHORIZONTAL );
//scwMain->SetSizer(szrScrolled);
//szrMain->Add(scwMain, 0, wxEXPAND, 5);
//szrMain->Layout();
}
XCCalendarList::~XCCalendarList(){
}
void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){
// Verify if the generated code has changed. Return if not.
CDSGetChecksumResult currentChecksum = dataStorage->GetChecksum("internal_updatedata");
if (checksumUpdate == currentChecksum.checksumValue){
// Checksum matches so return.
return;
}
// TODO: Delete the old controls.
for (vector::iterator accountCtrlIter = accountControlList.begin();
accountCtrlIter != accountControlList.end(); accountCtrlIter++){
delete *accountCtrlIter;
}
accountControlList.clear();
// Get the list of accounts and create them one by one.
CDSAccountList accountListData = dataStorage->GetAccountList();
for (int AccountSeek = 0; AccountSeek < accountListData.accountList.size(); AccountSeek++){
// Create the control and add it to the list.
XCCalendarListAccountCtrl *newAccountCtrl = new XCCalendarListAccountCtrl(this, accountListData.accountList[AccountSeek].accountName);
newAccountCtrl->SetAccountID(accountListData.accountList[AccountSeek].accountID);
szrMain->Add(newAccountCtrl, 0, wxEXPAND, 5);
accountControlList.push_back(newAccountCtrl);
// Get the list of calendars and create controls.
CDSCalendarList accountCalendarList = dataStorage->GetCalendarList(accountListData.accountList[AccountSeek].accountID);
for (int calendarSeek = 0; calendarSeek < accountCalendarList.calendarList.size(); calendarSeek++){
CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(accountListData.accountList[AccountSeek].accountName, accountCalendarList.calendarListTextID[calendarSeek]);
XCCalendarListCalendarCtrl *newCalendarCtrl = new XCCalendarListCalendarCtrl(this, calendarInfo.calendarName, calendarInfo.calendarColour);
newCalendarCtrl->SetCalendarID(accountCalendarList.calendarList[calendarSeek]);
newAccountCtrl->AddCalendar(newCalendarCtrl);
szrMain->Add(newCalendarCtrl, 0, wxEXPAND, 5);
}
}
// Set the updated checksum.
checksumUpdate = currentChecksum.checksumValue;
}
std::vector XCCalendarList::GetHiddenAccountsList(){
std::vector accountList;
// Go through each of the account controls and work
// out which entries should be hidden based on account.
for (std::vector::iterator accountListIter = accountControlList.begin();
accountListIter != accountControlList.end(); accountListIter++){
if ((*accountListIter)->GetShowCheckboxState() == wxCHK_UNCHECKED){
accountList.push_back((*accountListIter)->GetAccountID());
}
}
return accountList;
}
std::vector XCCalendarList::GetHiddenCalendarsList(){
std::vector calendarList;
// Go through each of the calendar controls and
// work out which entries should be hidden based on
// calendar.
for (std::vector::iterator accountListIter = accountControlList.begin();
accountListIter != accountControlList.end(); accountListIter++){
// Get the list of hidden calendars.
vector calendarHiddenList = (*accountListIter)->GetHiddenCalendarList();
for (vector::iterator calendarHiddenIter = calendarHiddenList.begin();
calendarHiddenIter != calendarHiddenList.end(); calendarHiddenIter++){
vector::iterator calendarHiddenFind = find(calendarList.begin(), calendarList.end(), *calendarHiddenIter);
if (calendarHiddenFind == calendarList.end()){
calendarList.push_back(*calendarHiddenIter);
}
}
}
return calendarList;
}