Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Cleanup objects in destructors and minor code cleanup
[xestiacalendar/.git] / source / widgets / XCCalendarList.cpp
index 62efb9c..92e7c50 100644 (file)
@@ -25,26 +25,54 @@ XCCalendarList::XCCalendarList(wxWindow *parent)
                
        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();
-       
+       this->SetSize(wxSize(350, 500));        
                
 }
 
 XCCalendarList::~XCCalendarList(){
        
+       // Delete the calendar lists.
+       
+       for (vector<XCCalendarListAccountCtrl*>::iterator accountCtrlIter = accountControlList.begin();
+               accountCtrlIter != accountControlList.end(); accountCtrlIter++){
+               
+               delete *accountCtrlIter;
+                       
+       }
+       
+       accountControlList.clear();
+       
+       this->SetSizer(nullptr, true);
+       
 }
 
 void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){
        
-       // TODO: Verify if the generated code has changed.
+       // 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;
+               
+       }
+       
+       // Delete the old controls. Remember which setting the checkboxes were hidden so they
+       // can be restored later on.
+
+       vector<int> calendarHiddenAccountsList = GetHiddenAccountsList();       
+       vector<int> calendarHiddenCalendarsList = GetHiddenCalendarsList();
+       
+       for (vector<XCCalendarListAccountCtrl*>::iterator accountCtrlIter = accountControlList.begin();
+               accountCtrlIter != accountControlList.end(); accountCtrlIter++){
+               
+               delete *accountCtrlIter;
+                       
+       }
+       
+       accountControlList.clear();
        
        // Get the list of accounts and create them one by one.
        
@@ -55,9 +83,17 @@ void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){
                // Create the control and add it to the list.
                
                XCCalendarListAccountCtrl *newAccountCtrl = new XCCalendarListAccountCtrl(this, accountListData.accountList[AccountSeek].accountName);
+               newAccountCtrl->SetAccountID(accountListData.accountList[AccountSeek].accountID);
+               newAccountCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID);
                
                szrMain->Add(newAccountCtrl, 0, wxEXPAND, 5);
                
+               if (find(calendarHiddenAccountsList.begin(), calendarHiddenAccountsList.end(), accountListData.accountList[AccountSeek].accountID) != calendarHiddenAccountsList.end()){
+                       
+                       newAccountCtrl->SetCheckBoxValue(wxCHK_UNCHECKED);
+                       
+               }
+               
                accountControlList.push_back(newAccountCtrl);
                
                // Get the list of calendars and create controls.
@@ -69,6 +105,15 @@ void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){
                        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]);
+                       
+                       newCalendarCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID);
+
+                       if (find(calendarHiddenCalendarsList.begin(), calendarHiddenCalendarsList.end(), accountCalendarList.calendarList[calendarSeek]) != calendarHiddenCalendarsList.end()){
+                       
+                               newCalendarCtrl->SetCheckBoxValue(wxCHK_UNCHECKED);
+                       
+                       }
                        
                        newAccountCtrl->AddCalendar(newCalendarCtrl);
 
@@ -78,4 +123,66 @@ void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){
                
        }
        
+       // Set the updated checksum.
+       
+       checksumUpdate = currentChecksum.checksumValue;
+
+       this->Layout();
+       
+}
+
+std::vector<int> XCCalendarList::GetHiddenAccountsList(){
+       
+       std::vector<int> accountList;
+       
+       // Go through each of the account controls and work
+       // out which entries should be hidden based on account.
+       
+       for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
+               accountListIter != accountControlList.end(); accountListIter++){
+       
+               if ((*accountListIter)->GetShowCheckboxState() == wxCHK_UNCHECKED){
+                       
+                       accountList.push_back((*accountListIter)->GetAccountID());
+                       
+               }
+                       
+       }
+       
+       return accountList;
+       
+}
+
+std::vector<int> XCCalendarList::GetHiddenCalendarsList(){
+
+       std::vector<int> calendarList;
+       
+       // Go through each of the calendar controls and
+       // work out which entries should be hidden based on
+       // calendar.
+
+       for (std::vector<XCCalendarListAccountCtrl*>::iterator accountListIter = accountControlList.begin();
+               accountListIter != accountControlList.end(); accountListIter++){
+       
+               // Get the list of hidden calendars.
+               
+               vector<int> calendarHiddenList = (*accountListIter)->GetHiddenCalendarList();
+                       
+               for (vector<int>::iterator calendarHiddenIter = calendarHiddenList.begin();
+                       calendarHiddenIter != calendarHiddenList.end(); calendarHiddenIter++){
+               
+                       vector<int>::iterator calendarHiddenFind = find(calendarList.begin(), calendarList.end(), *calendarHiddenIter);
+                       
+                       if (calendarHiddenFind == calendarList.end()){
+
+                               calendarList.push_back(*calendarHiddenIter);
+                               
+                       }
+                               
+               }
+                       
+       }
+       
+       return calendarList;
+       
 }
\ No newline at end of file
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