+// frmMain.h - frmMain 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 <http://www.gnu.org/licenses/>
+
#include "frmMain.h"
frmMain::frmMain( wxWindow* parent )
szrMain->Add(mainCalendarCtrl, 1, wxEXPAND, 5);
szrMain->Layout();
+ Connect(ID_PROCESSCALENDAR, XCMAIN_PROCESSCALENDAR, wxCommandEventHandler(frmMain::ProcessCalendar));
+ Connect(ID_EDITCALENDAR, XCMAIN_EDITCALENDAR, wxCommandEventHandler(frmMain::EditCalendar));
+ Connect(ID_DELETECALENDAR, XCMAIN_DELETECALENDAR, wxCommandEventHandler(frmMain::DeleteCalendar));
+ Connect(ID_DELETEEVENT, XCMAIN_DELETEEVENT, wxCommandEventHandler(frmMain::DeleteEvent));
+ Connect(ID_ADDENTRY, XCMAIN_ADDEVENT, wxCommandEventHandler(frmMain::AddEvent));
+ Connect(ID_UPDATEENTRY, XCMAIN_UPDATEEVENT, wxCommandEventHandler(frmMain::UpdateEvent));
+ Connect(ID_EDITEVENT, XCMAIN_EDITEVENT, wxCommandEventHandler(frmMain::EditEvent));
+
+ Connect(ID_ADDWINDOW, XCMAIN_ADDWINDOWINFO, wxCommandEventHandler(frmMain::WindowAdd));
+ Connect(ID_UPDATEWINDOW, XCMAIN_UPDATEWINDOWINFO, wxCommandEventHandler(frmMain::WindowUpdate));
+ Connect(ID_DELETEWINDOW, XCMAIN_DELETEWINDOWINFO, wxCommandEventHandler(frmMain::WindowDelete));
+
}
void frmMain::QuitApp( wxCloseEvent& event )
for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
- CDSAccountResult addResult = calendarData.AddAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
+ CDSAccountResult addResult = calendarData.AddAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()), accountSeek);
}
CDSCalendarResult calendarAddResult = calendarData.AddCalendar(accountInfo.accountID,
calendarList.calendarName[calendarSeek],
calendarList.calendarShortName[calendarSeek],
- calendarList.calendarColour[calendarSeek]);
+ calendarList.calendarColour[calendarSeek],
+ calendarList.calendarDescription[calendarSeek]);
// Set the calendar ID.
}
+void frmMain::ShowPreferencesWindow( wxCommandEvent& event )
+{
+
+ // Close all windows first.
+
+ if (CloseAllWindows() == false)
+ {
+ return;
+ }
+
+ // Open the preferences window.
+
+ reloadAccounts = FALSE;
+
+ frmPreferences *framePreferences = new frmPreferences ( this );
+ framePreferences->SetupPointers(&reloadAccounts);
+ framePreferences->ShowModal();
+ delete framePreferences;
+ framePreferences = NULL;
+
+ // Reload the preferences.
+
+ if (reloadAccounts == true){
+
+ // Reload the accounts as a change has been made within
+ // the application.
+
+ wxString prefDirectory = GetUserPrefDir();
+ XCALPreferences *oldPreferences = preferences;
+ preferences = new XCALPreferences(prefDirectory);
+
+ delete oldPreferences;
+ oldPreferences = nullptr;
+
+ // Clear all of the data from the calendar data storage.
+
+ calendarData.Clear();
+ LoadAccountData();
+
+ // Politely ask the calendar control to reload it's view.
+
+ wxCommandEvent updateGrid(XCCALENDARCTRL_CHANGEGRID);
+ updateGrid.SetId(ID_CHANGEGRID);
+ wxPostEvent(mainCalendarCtrl, updateGrid);
+
+ }
+
+}
+
void frmMain::ShowAboutWindow( wxCommandEvent& event )
{
delete frameUpdate;
frameUpdate = NULL;
+}
+
+void frmMain::OpenNewAccountDialog( wxCommandEvent& event )
+{
+
+ // Open the new account dialog.
+
+ reloadAccounts = false;
+
+ frmNewAccount *frameNewAccount = new frmNewAccount ( this );
+ frameNewAccount->SetupPointers(&reloadAccounts, &calendarData);
+ frameNewAccount->ShowModal();
+ delete frameNewAccount;
+ frameNewAccount = NULL;
+
+ // Reload the preferences.
+
+ if (reloadAccounts == true){
+
+ // Reload the accounts as a change has been made within
+ // the application.
+
+ wxString prefDirectory = GetUserPrefDir();
+ XCALPreferences *oldPreferences = preferences;
+ preferences = new XCALPreferences(prefDirectory);
+
+ delete oldPreferences;
+ oldPreferences = nullptr;
+
+ // Clear all of the data from the calendar data storage.
+
+ calendarData.Clear();
+ LoadAccountData();
+
+ // Politely ask the calendar control to reload it's view.
+
+ wxCommandEvent updateGrid(XCCALENDARCTRL_CHANGEGRID);
+ updateGrid.SetId(ID_CHANGEGRID);
+ wxPostEvent(mainCalendarCtrl, updateGrid);
+
+ }
+
+}
+
+void frmMain::CreateNewCalendar( wxCommandEvent& event )
+{
+
+ frmCalendarEditor *frameNewCalendar = new frmCalendarEditor ( this );
+ frameNewCalendar->SetMode(false);
+ frameNewCalendar->SetupAccounts(preferences);
+ frameNewCalendar->ShowModal();
+ delete frameNewCalendar;
+ frameNewCalendar = nullptr;
+
+}
+
+void frmMain::EditCalendar( wxCommandEvent& event )
+{
+
+ // Close all windows first.
+
+ if (CloseAllWindows() == false)
+ {
+ return;
+ }
+
+ // Get the calendar data.
+
+ CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(event.GetInt());
+
+ frmCalendarEditor *frameNewCalendar = new frmCalendarEditor ( this );
+ frameNewCalendar->SetMode(true);
+ frameNewCalendar->SetupAccounts(preferences);
+ frameNewCalendar->SetData(event.GetInt(), calendarInfo.accountName, calendarInfo.calendarName, calendarInfo.calendarDescription, calendarInfo.calendarColour);
+ frameNewCalendar->ShowModal();
+ delete frameNewCalendar;
+ frameNewCalendar = nullptr;
+
+}
+
+void frmMain::DeleteCalendar( wxCommandEvent& event )
+{
+
+ // Close all windows first.
+
+ if (CloseAllWindows() == false)
+ {
+ return;
+ }
+
+ CalendarProperties *calendarEventInfo = (CalendarProperties*)event.GetClientData();
+
+ // Get the calendar data.
+
+ CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(calendarEventInfo->calendarID);
+
+ if (wxMessageBox(wxString::Format("Are you sure you want to delete the calendar %s from the %s account?", calendarInfo.calendarName, calendarInfo.accountName), "Delete calendar", wxYES_NO|wxICON_QUESTION) == wxNO){
+ return;
+ }
+
+ // Go through the grid and delete each calendar entry widget that
+ // is associated with the calendar.
+
+ wxCommandEvent deleteCalendar(XCCALENDARCTRL_DELETECALENDARENTRIES);
+ deleteCalendar.SetId(ID_DELETECALENDARENTRIES);
+ deleteCalendar.SetInt(calendarInfo.calendarID);
+ wxPostEvent(mainCalendarCtrl, deleteCalendar);
+
+ // Get the account configuration file and delete the calendar information.
+
+ CDSGetAccountInfo accountInfo = calendarData.GetAccount(calendarInfo.accountName);
+
+ string accountDirectoryPath = string(GetUserDir().mb_str());
+ accountDirectoryPath += "accounts/";
+ accountDirectoryPath += string(preferences->accounts.GetAccountDirectory(calendarEventInfo->accountPreferencesID).mb_str());
+ accountDirectoryPath += ".";
+ accountDirectoryPath += string(preferences->accounts.GetAccountType(calendarEventInfo->accountPreferencesID).mb_str());
+ accountDirectoryPath += "/";
+
+ string calendarListFilenameFull = accountDirectoryPath;
+ calendarListFilenameFull += "calendarlist.db";
+
+ string calendarDirectoryPath = accountDirectoryPath;
+ calendarDirectoryPath += calendarInfo.calendarTextID;
+
+ wxFileConfig *calendarListFile = new wxFileConfig("", "", wxString(calendarListFilenameFull));
+
+ //calendarListFile->SetPath(wxString(calendarInfo.calendarTextID));
+ calendarListFile->DeleteGroup(wxString(calendarInfo.calendarTextID));
+
+ // Delete the calendar directory.
+
+ wxDir entryListDirectory((wxString)calendarDirectoryPath.c_str());
+ wxString entryListFilename;
+
+ bool continueProcessing = entryListDirectory.GetFirst(&entryListFilename, "*", wxDIR_NO_FOLLOW|wxDIR_FILES);
+
+ while (continueProcessing){
+
+ string entryListFullFilename;
+ entryListFullFilename += calendarDirectoryPath;
+ entryListFullFilename += "/";
+ entryListFullFilename += string(entryListFilename.mb_str());
+
+ wxRemoveFile(wxString(entryListFullFilename.c_str()));
+
+ continueProcessing = entryListDirectory.GetNext(&entryListFilename);
+
+ }
+
+ wxRmdir(calendarDirectoryPath);
+
+ // Delete the calendar from the calendar data storage.
+
+ calendarData.DeleteCalendar(calendarEventInfo->calendarID);
+
+ delete calendarListFile;
+ calendarListFile = nullptr;
+
+ delete calendarEventInfo;
+ calendarEventInfo = nullptr;
+
+}
+
+void frmMain::CreateNewEvent( wxCommandEvent& event ){
+
+ frmEventEditor *frameNewEvent = new frmEventEditor ( this );
+ frameNewEvent->SetupForm(&calendarData, preferences);
+ frameNewEvent->SetWindowMenuItemID(++WindowMenuItemID);
+
+ // Add the window to the window list.
+
+ WindowData *newWindowData = new WindowData;
+
+ newWindowData->DataType = 1;
+ newWindowData->WindowPointer = (void*)frameNewEvent;
+ newWindowData->WindowID = WindowMenuItemID;
+
+ wxCommandEvent addevent(XCMAIN_ADDWINDOWINFO);
+ addevent.SetId(ID_ADDWINDOW);
+ addevent.SetClientData(newWindowData);
+ wxPostEvent(this, addevent);
+
+ frameNewEvent->Show();
+
+}
+
+void frmMain::EditEvent( wxCommandEvent& event ){
+
+ frmEventEditor *frameEditEvent = new frmEventEditor ( this );
+ frameEditEvent->SetEventID(event.GetInt());
+ frameEditEvent->SetEditMode(true);
+ frameEditEvent->SetWindowMenuItemID(++WindowMenuItemID);
+ frameEditEvent->SetupForm(&calendarData, preferences);
+
+ // Add the window to the window list.
+
+ WindowData *newWindowData = new WindowData;
+
+ newWindowData->DataType = 1;
+ newWindowData->WindowPointer = (void*)frameEditEvent;
+ newWindowData->WindowID = WindowMenuItemID;
+
+ wxCommandEvent addevent(XCMAIN_ADDWINDOWINFO);
+ addevent.SetId(ID_ADDWINDOW);
+ addevent.SetClientData(newWindowData);
+ wxPostEvent(this, addevent);
+
+ // Setup the form and display it.
+
+ frameEditEvent->Show();
+
+}
+
+void frmMain::DeleteEvent( wxCommandEvent& event ){
+
+ EventProperties *eventInfo = (EventProperties*)event.GetClientData();
+
+ // Get the event information.
+
+ CDSGetCalendarEntryInfo eventDeleteData = calendarData.GetEvent(eventInfo->eventID);
+ CDSGetCalendarInfo calendarDeleteData = calendarData.GetCalendar(eventInfo->calendarID);
+
+ if (wxMessageBox(wxString::Format("Are you sure you want to delete the event %s from the %s calendar?", eventDeleteData.entryName, calendarDeleteData.calendarName), "Delete event", wxYES_NO|wxICON_QUESTION) == wxNO){
+ return;
+ }
+
+ // Go through the grid and delete the entry from the GUI.
+
+ wxCommandEvent deleteEvent(XCCALENDARCTRL_DELETEENTRY);
+ deleteEvent.SetId(ID_DELETEENTRY);
+ deleteEvent.SetInt(eventInfo->eventID);
+ wxPostEvent(mainCalendarCtrl, deleteEvent);
+
+ // Get the filename and delete the entry.
+
+ wxRemoveFile(wxString(eventDeleteData.entryFilename.c_str()));
+
+ // Delete the entry from the calendar data storage.
+
+ calendarData.DeleteEvent(eventInfo->eventID);
+
+ delete eventInfo;
+ eventInfo = nullptr;
+
+}
+
+void frmMain::AddEvent( wxCommandEvent& event )
+{
+
+ EventProperties *eventInfo = (EventProperties*)event.GetClientData();
+
+ wxCommandEvent addEvent(XCCALENDARCTRL_ADDENTRY);
+ addEvent.SetId(ID_ADDENTRY);
+ addEvent.SetClientData(eventInfo);
+ wxPostEvent(mainCalendarCtrl, addEvent);
+
+}
+
+void frmMain::UpdateEvent( wxCommandEvent& event )
+{
+
+ EventProperties *eventInfo = (EventProperties*)event.GetClientData();
+
+ wxCommandEvent updateEvent(XCCALENDARCTRL_UPDATEENTRY);
+ updateEvent.SetId(ID_UPDATEENTRY);
+ updateEvent.SetClientData(eventInfo);
+ wxPostEvent(mainCalendarCtrl, updateEvent);
+
+}
+
+void frmMain::ProcessCalendar( wxCommandEvent& event )
+{
+
+ CalendarProperties *calendarInfo = (CalendarProperties*)event.GetClientData();
+
+ // Get the account name.
+
+ CDSGetAccountInfo accountInfo = calendarData.GetAccount(calendarInfo->accountName);
+
+ // Build the account directory path.
+
+ string accountDirectoryPath = string(GetUserDir().mb_str());
+ accountDirectoryPath += "accounts/";
+ accountDirectoryPath += string(preferences->accounts.GetAccountDirectory(calendarInfo->accountPreferencesID).mb_str());
+ accountDirectoryPath += ".";
+ accountDirectoryPath += string(preferences->accounts.GetAccountType(calendarInfo->accountPreferencesID).mb_str());
+ accountDirectoryPath += "/";
+
+ // Generate a UUID for the new calendar.
+
+ string calendarPath = accountDirectoryPath;
+
+ string calendarUUID = "";
+
+ if (calendarInfo->editMode == false){
+
+ calendarUUID = GenerateUUID();
+ calendarPath += calendarUUID;
+
+ } else {
+
+ calendarUUID = calendarData.GetCalendar(calendarInfo->calendarID).calendarTextID;
+ calendarPath += calendarPath;
+
+ }
+
+ calendarPath += "/";
+
+ // Open the account's calendar file and add to the list of calendars.
+
+ string calendarListFilenameFull = accountDirectoryPath;
+ calendarListFilenameFull += "calendarlist.db";
+
+ wxFileConfig *calendarListFile = new wxFileConfig("", "", wxString(calendarListFilenameFull));
+
+ wxString calendarDescription = wxString(calendarInfo->calendarDescription);
+
+ calendarDescription.Replace("\n", "\\n", true);
+
+ // Create the directory for the calendar entries if
+ // not editing a calendar.
+
+ calendarListFile->SetPath(wxString(calendarUUID));
+ calendarListFile->Write(wxT("name"), wxString(calendarInfo->calendarName));
+ calendarListFile->Write(wxT("description"), calendarDescription);
+ calendarListFile->Write(wxT("colour"), wxString(calendarInfo->calendarColour));
+
+ if (calendarInfo->editMode == false){
+
+ wxMkDir(wxString(calendarPath), wxS_DIR_DEFAULT);
+ calendarData.AddCalendar(accountInfo.accountID, calendarInfo->calendarName, calendarUUID, calendarInfo->calendarColour, calendarInfo->calendarDescription);
+
+ } else {
+
+ calendarData.UpdateCalendar(calendarInfo->calendarID, calendarInfo->calendarName, calendarInfo->calendarColour, calendarInfo->calendarDescription);
+
+ // Post event to update the colour in the calendar entries.
+
+ updateColourData.calendarID = calendarInfo->calendarID;
+ updateColourData.newColour.red = calendarInfo->calendarColour.red;
+ updateColourData.newColour.green = calendarInfo->calendarColour.green;
+ updateColourData.newColour.blue = calendarInfo->calendarColour.blue;
+ updateColourData.newColour.alpha = calendarInfo->calendarColour.alpha;
+
+ wxCommandEvent updateColour(XCCALENDARCTRL_UPDATECALENDARCOLOUR);
+ updateColour.SetClientData(&updateColourData);
+ updateColour.SetId(ID_UPDATECOLOUR);
+ wxPostEvent(mainCalendarCtrl, updateColour);
+
+ }
+
+ // Add the calendar to the calendar data storage.
+
+ delete calendarListFile;
+ calendarListFile = nullptr;
+
+ delete calendarInfo;
+ calendarInfo = nullptr;
+
+}
+
+void frmMain::ShowHelp( wxCommandEvent& event )
+{
+
+ wxMessageBox(_("The help documentation will be implemented in a future version of Xestia Calendar."), _("Unimplemented"));
+
}
\ No newline at end of file