From: Steve Brokenshire Date: Wed, 11 Jan 2017 18:59:35 +0000 (+0000) Subject: frmCalendarEditor: Added form to edit calendars X-Git-Tag: release-0.02~35 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=703ade69af31d2e1eeb3a9d39f96a85fccfc0f76;p=xestiacalendar%2F.git frmCalendarEditor: Added form to edit calendars --- diff --git a/source/forms/calendareditor/frmCalendarEditor.cpp b/source/forms/calendareditor/frmCalendarEditor.cpp new file mode 100644 index 0000000..f39a5d6 --- /dev/null +++ b/source/forms/calendareditor/frmCalendarEditor.cpp @@ -0,0 +1,126 @@ +#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 = cmbAccount->GetStringSelection(); + calendarInfo->calendarName = txtName->GetValue().ToStdString(); + calendarInfo->calendarDescription = txtDescription->GetValue().ToStdString(); + + 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())); + txtDescription->SetValue(wxString(calendarDescription.c_str())); + clpColour->SetColour(wxColour(calendarColour.red, calendarColour.green, calendarColour.blue)); + cmbAccount->SetStringSelection(wxString(accountName)); + this->calendarID = calendarID; + +} \ No newline at end of file diff --git a/source/forms/calendareditor/frmCalendarEditor.h b/source/forms/calendareditor/frmCalendarEditor.h new file mode 100644 index 0000000..5418cde --- /dev/null +++ b/source/forms/calendareditor/frmCalendarEditor.h @@ -0,0 +1,44 @@ +#ifndef __frmCalendarEditor__ +#define __frmCalendarEditor__ + +/** +@file +Subclass of frmCalendarEditorADT, which is generated by wxFormBuilder. +*/ + +#include +#include + +#include "../../AppXestiaCalendar.h" + +#include "preferences.h" +#include "events.h" +#include "structs.h" +#include "colour.h" + +//// end generated include + +/** Implementing frmCalendarEditorADT */ +class frmCalendarEditor : public frmCalendarEditorADT +{ + private: + bool editMode = false; + XCALPreferences *preferencesData = nullptr; + vector accountPrefencesIDList; + int calendarID = 0; + std::string accountName = ""; + + protected: + void CloseWindow( wxCommandEvent &event ); + void ProcessCalendar( wxCommandEvent &event ); + public: + /** Constructor */ + frmCalendarEditor( wxWindow* parent ); + //// end generated class members + void SetMode(bool setMode); + void SetupAccounts(XCALPreferences *preferencesData); + void SetData(int calendarID, std::string accountName, std::string calendarName, std::string calendarDescription, Colour calendarColour); + +}; + +#endif // __frmCalendarEditor__