--- /dev/null
+#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
--- /dev/null
+#ifndef __frmCalendarEditor__
+#define __frmCalendarEditor__
+
+/**
+@file
+Subclass of frmCalendarEditorADT, which is generated by wxFormBuilder.
+*/
+
+#include <string>
+#include <vector>
+
+#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<int> 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__