1 // frmCalendarEditor.cpp - frmCalendarEditor form functions.
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
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.
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.
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 "frmCalendarEditor.h"
23 frmCalendarEditor::frmCalendarEditor( wxWindow* parent )
25 frmCalendarEditorADT( parent )
30 void frmCalendarEditor::SetMode(bool setMode){
34 if (editMode == true){
36 lblAccount->Show(false);
37 cmbAccount->Show(false);
38 btnCreate->SetLabel(_("Update"));
44 void frmCalendarEditor::CloseWindow( wxCommandEvent &event )
51 void frmCalendarEditor::SetupAccounts(XCALPreferences *preferencesData){
53 for (int accountSeek = 0; accountSeek < preferencesData->accounts.GetCount(); accountSeek++){
55 // Check if the account is a supported type before adding.
57 if (preferencesData->accounts.GetAccountType(accountSeek) != wxT("Local")){
59 // Go to the next account.
65 cmbAccount->Append(preferencesData->accounts.GetAccountName(accountSeek));
66 accountPrefencesIDList.push_back(accountSeek);
70 this->preferencesData = preferencesData;
74 void frmCalendarEditor::ProcessCalendar( wxCommandEvent &event ){
76 // Check that an account has been selected before continuing.
78 if (cmbAccount->GetCurrentSelection() == -1 && editMode == false){
79 wxMessageBox(_("No account was selected for this calendar."), _("Error"));
83 // Check that the calendar has a name before continuing.
85 if (txtName->IsEmpty()){
86 wxMessageBox(_("No name for the calendar has been entered."), _("Error"));
90 // Post an event to the main window to create or edit the calendar with the
93 CalendarProperties *calendarInfo = new CalendarProperties;
97 if (editMode == true){
99 calendarInfo->accountPreferencesID = accountPrefencesIDList[cmbAccount->GetCurrentSelection()];
100 calendarInfo->calendarID = calendarID;
104 // Go through the list of accounts and find the matching account name.
108 for (accountSeek = 0; accountSeek < preferencesData->accounts.GetCount(); accountSeek++){
110 if ((wxString)cmbAccount->GetStringSelection() == preferencesData->accounts.GetAccountName(accountSeek)){
116 calendarInfo->accountPreferencesID = accountPrefencesIDList[cmbAccount->GetCurrentSelection()];
120 calendarInfo->editMode = editMode;
121 calendarInfo->accountName = cmbAccount->GetStringSelection();
122 calendarInfo->calendarName = txtName->GetValue().ToStdString();
123 calendarInfo->calendarDescription = txtDescription->GetValue().ToStdString();
125 calendarInfo->calendarColour = (clpColour->GetColour().GetAsString(wxC2S_HTML_SYNTAX).ToStdString() + "FF");
127 wxCommandEvent processCalendarEvent(XCMAIN_PROCESSCALENDAR);
128 processCalendarEvent.SetId(ID_PROCESSCALENDAR);
129 processCalendarEvent.SetClientData((void*)calendarInfo);
130 wxPostEvent(this->GetParent(), processCalendarEvent);
136 void frmCalendarEditor::SetData(int calendarID, std::string accountName, std::string calendarName, std::string calendarDescription, Colour calendarColour){
138 txtName->SetValue(wxString(calendarName.c_str()));
139 txtDescription->SetValue(wxString(calendarDescription.c_str()));
140 clpColour->SetColour(wxColour(calendarColour.red, calendarColour.green, calendarColour.blue));
141 cmbAccount->SetStringSelection(wxString(accountName));
142 this->calendarID = calendarID;