// frmCalendarEditor.cpp - frmCalendarEditor form functions. // // (c) 2016-2017 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Calendar 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 Calendar 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 "frmCalendarEditor.h" using namespace std; frmCalendarEditor::frmCalendarEditor( wxWindow* parent ) : frmCalendarEditorADT( parent ) { } void frmCalendarEditor::SetMode(bool setMode){ editMode = setMode; if (editMode == true){ lblAccount->Show(false); cmbAccount->Show(false); btnCreate->SetLabel(_("Update")); } } void frmCalendarEditor::CloseWindow( wxCommandEvent &event ) { this->Close(); } void frmCalendarEditor::SetupAccounts(XCALPreferences *preferencesData){ for (int accountSeek = 0; accountSeek < preferencesData->accounts.GetCount(); accountSeek++){ // Check if the account is a supported type before adding. if (preferencesData->accounts.GetAccountType(accountSeek) != wxT("Local")){ // Go to the next account. continue; } cmbAccount->Append(preferencesData->accounts.GetAccountName(accountSeek)); accountPrefencesIDList.push_back(accountSeek); } this->preferencesData = preferencesData; } void frmCalendarEditor::ProcessCalendar( wxCommandEvent &event ){ // Check that an account has been selected before continuing. if (cmbAccount->GetCurrentSelection() == -1 && editMode == false){ wxMessageBox(_("No account was selected for this calendar."), _("Error")); return; } // Check that the calendar has a name before continuing. if (txtName->IsEmpty()){ wxMessageBox(_("No name for the calendar has been entered."), _("Error")); return; } // Post an event to the main window to create or edit the calendar with the // details given. CalendarProperties *calendarInfo = new CalendarProperties; // Setup the data. if (editMode == true){ calendarInfo->accountPreferencesID = accountPrefencesIDList[cmbAccount->GetCurrentSelection()]; calendarInfo->calendarID = calendarID; } else { // Go through the list of accounts and find the matching account name. int accountSeek = 0; for (accountSeek = 0; accountSeek < preferencesData->accounts.GetCount(); accountSeek++){ if ((wxString)cmbAccount->GetStringSelection() == preferencesData->accounts.GetAccountName(accountSeek)){ break; } } calendarInfo->accountPreferencesID = accountPrefencesIDList[cmbAccount->GetCurrentSelection()]; } calendarInfo->editMode = editMode; calendarInfo->accountName = std::string(cmbAccount->GetStringSelection().ToUTF8()); calendarInfo->calendarName = std::string(txtName->GetValue().ToUTF8()); calendarInfo->calendarDescription = std::string(txtDescription->GetValue().ToUTF8()); calendarInfo->calendarColour = (clpColour->GetColour().GetAsString(wxC2S_HTML_SYNTAX).ToStdString() + "FF"); wxCommandEvent processCalendarEvent(XCMAIN_PROCESSCALENDAR); processCalendarEvent.SetId(ID_PROCESSCALENDAR); processCalendarEvent.SetClientData((void*)calendarInfo); wxPostEvent(this->GetParent(), processCalendarEvent); this->Close(); } void frmCalendarEditor::SetData(int calendarID, std::string accountName, std::string calendarName, std::string calendarDescription, Colour calendarColour){ txtName->SetValue(wxString(calendarName.c_str(), wxConvUTF8)); txtDescription->SetValue(wxString(calendarDescription.c_str(), wxConvUTF8)); clpColour->SetColour(wxColour(calendarColour.red, calendarColour.green, calendarColour.blue)); cmbAccount->SetStringSelection(wxString(accountName.c_str(), wxConvUTF8)); this->calendarID = calendarID; }