Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Cleanup objects in destructors and minor code cleanup
[xestiacalendar/.git] / source / widgets / XCCalendarListAccountCtrl.cpp
1 // XCCalendarListAccountCtrl.cpp - XCCalendarListAccountCtrl class
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Calendar 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 Calendar 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 "XCCalendarListAccountCtrl.h"
21 BEGIN_EVENT_TABLE(XCCalendarListAccountCtrl, wxPanel)
22 END_EVENT_TABLE()
24 using namespace std;
26 XCCalendarListAccountCtrl::XCCalendarListAccountCtrl(wxWindow* parent, string accountName) : 
27         wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, ""){
29         // Create the sizer.
30         
31         szrMain = new wxBoxSizer( wxHORIZONTAL );
32         this->SetSizer(szrMain);
33         
34         // Setup the checkbox.
35         
36         chkShowAll = new wxCheckBox(this, wxID_ANY, "", wxPoint(0,0), wxDefaultSize, wxCHK_3STATE, wxDefaultValidator, "");
37         
38         // Setup the label.
39         
40         lblAccountName = new wxStaticText(this, wxID_ANY, wxString(accountName.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, "");
41                 
42         // Setup the font.
43                 
44         wxFont accountFont = lblAccountName->GetFont();
45         accountFont.MakeBold();
46         lblAccountName->SetFont(accountFont);
47                 
48         // Connect events to the controls.
49         
50         chkShowAll->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListAccountCtrl::ShowAllCheckboxClick), NULL, this);
51         chkShowAll->SetValue(wxCHK_CHECKED);
52         
53         // Connect them to the sizer.
54         
55         szrMain->Add(chkShowAll, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
56         szrMain->Add(lblAccountName, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
57         
58 }
60 XCCalendarListAccountCtrl::~XCCalendarListAccountCtrl(){
61         
62         // Delete the calendar controls.
63         
64         // Unbind the controls.
65         
66         chkShowAll->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListAccountCtrl::ShowAllCheckboxClick), NULL, this);
67         
68         // Delete the calendar list controls.
69         
70         for (std::vector<XCCalendarListCalendarCtrl*>::iterator calendarIter = calendarControlList.begin();
71                 calendarIter != calendarControlList.end(); calendarIter++){
72         
73                 delete *calendarIter;
74                         
75         }
76         
77         // Clear the list of deleted controls.
78         
79         calendarControlList.clear();
80         
81         // Clear the widget controls.
83         delete chkShowAll;
84         chkShowAll = nullptr;
85         
86         delete lblAccountName;
87         lblAccountName = nullptr;
89         this->SetSizer(nullptr, true);
90         
91 }
93 void XCCalendarListAccountCtrl::AddCalendar(XCCalendarListCalendarCtrl *calendarControl){
95         // Add the calendar control to the sizer.
96         
97         //szrMain->Add(calendarControl, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
98         
99         // Add the calendar control to the list.
100         
101         calendarControlList.push_back(calendarControl);
102         
105 void XCCalendarListAccountCtrl::ShowAllCheckboxClick( wxMouseEvent &mouseEvent ){
106         
107         if (chkShowAll->Get3StateValue() == wxCHK_CHECKED){
108                 
109                 wxCommandEvent event(XCCALENDARCTRL_SHOWACCOUNTENTRIES);
110                 event.SetInt(accountID);
111                 event.SetId(ID_SHOWENTRIES);
112                 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
113                 
114         } else {
115                 
116                 wxCommandEvent event(XCCALENDARCTRL_HIDEACCOUNTENTRIES);
117                 event.SetInt(accountID);
118                 event.SetId(ID_HIDEENTRIES);
119                 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
120                 
121         }
122         
125 wxCheckBoxState XCCalendarListAccountCtrl::GetShowCheckboxState(){
126         
127         return chkShowAll->Get3StateValue();
128         
131 int XCCalendarListAccountCtrl::GetAccountID(){
132         
133         return accountID;
134         
137 void XCCalendarListAccountCtrl::SetAccountID(int accountID){
138         
139         this->accountID = accountID;
140         
143 void XCCalendarListAccountCtrl::SetAccountPreferencesID(int accountID){
144         
145         this->accountPreferencesID = accountPreferencesID;
146         
149 vector<int> XCCalendarListAccountCtrl::GetHiddenCalendarList(){
150         
151         vector<int> calendarList;
152         
153         for (vector<XCCalendarListCalendarCtrl*>::iterator calendarControlListIter = calendarControlList.begin(); 
154                 calendarControlListIter != calendarControlList.end(); calendarControlListIter++){
155                 
156                 if ((*calendarControlListIter)->GetShowCheckboxState() == wxCHK_UNCHECKED){
157                         
158                         calendarList.push_back((*calendarControlListIter)->GetCalendarID());
159                         
160                 }
161                         
162         }
163         
164         return calendarList;
165         
168 void XCCalendarListAccountCtrl::SetCheckBoxValue(wxCheckBoxState newValue){
169         
170         if (newValue == wxCHK_CHECKED){
171                 showAccounts = true;
172         } else {
173                 showAccounts = false;           
174         }
175         
176         chkShowAll->SetValue(newValue);
177         
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