+// 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"
+wxDEFINE_EVENT(XCMAIN_PROCESSCALENDAR, wxCommandEvent);
+wxDEFINE_EVENT(XCMAIN_EDITCALENDAR, wxCommandEvent);
+wxDEFINE_EVENT(XCMAIN_DELETECALENDAR, wxCommandEvent);
+wxDEFINE_EVENT(XCMAIN_ADDEVENT, wxCommandEvent);
+wxDEFINE_EVENT(XCMAIN_UPDATEEVENT, wxCommandEvent);
+wxDEFINE_EVENT(XCMAIN_EDITEVENT, wxCommandEvent);
+wxDEFINE_EVENT(XCMAIN_DELETEEVENT, wxCommandEvent);
+
+wxDEFINE_EVENT(XCMAIN_ADDWINDOWINFO, wxCommandEvent);
+wxDEFINE_EVENT(XCMAIN_UPDATEWINDOWINFO, wxCommandEvent);
+wxDEFINE_EVENT(XCMAIN_DELETEWINDOWINFO, wxCommandEvent);
+
frmMain::frmMain( wxWindow* parent )
:
frmMainADT( parent )
{
-
// Setup the default settings if they don't
// exist.
mainCalendarCtrl = new XCCalendarCtrl(this, &calendarData);
szrMain->Add(mainCalendarCtrl, 1, wxEXPAND, 5);
szrMain->Layout();
+
+ // Bind events to the control.
- 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));
+ Bind(XCMAIN_PROCESSCALENDAR, &frmMain::ProcessCalendar, this, ID_PROCESSCALENDAR);
+ Bind(XCMAIN_EDITCALENDAR, &frmMain::EditCalendar, this, ID_EDITCALENDAR);
+ Bind(XCMAIN_DELETECALENDAR, &frmMain::DeleteCalendar, this, ID_DELETECALENDAR);
+ Bind(XCMAIN_ADDEVENT, &frmMain::AddEvent, this, ID_ADDENTRY);
+ Bind(XCMAIN_UPDATEEVENT, &frmMain::UpdateEvent, this, ID_UPDATEENTRY);
+ Bind(XCMAIN_EDITEVENT, &frmMain::EditEvent, this, ID_EDITEVENT);
+ Bind(XCMAIN_DELETEEVENT, &frmMain::DeleteEvent, this, ID_DELETEEVENT);
+ Bind(XCMAIN_ADDWINDOWINFO, &frmMain::WindowAdd, this, ID_ADDWINDOW);
+ Bind(XCMAIN_UPDATEWINDOWINFO, &frmMain::WindowUpdate, this, ID_UPDATEWINDOW);
+ Bind(XCMAIN_DELETEWINDOWINFO, &frmMain::WindowDelete, this, ID_DELETEWINDOW);
}
void frmMain::QuitApp( wxCloseEvent& event )
for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
- CDSAccountResult addResult = calendarData.AddAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()), accountSeek);
+ CDSAccountResult addResult = calendarData.AddAccount(string(preferences->accounts.GetAccountName(accountSeek).ToUTF8()), accountSeek);
}
for (int accountSeek = 0; accountSeek < accountCount; accountSeek++){
- CDSGetAccountInfo accountInfo = calendarData.GetAccount(string(preferences->accounts.GetAccountName(accountSeek).mb_str()));
+ CDSGetAccountInfo accountInfo = calendarData.GetAccount(string(preferences->accounts.GetAccountName(accountSeek).ToUTF8()));
// Build the path.
- string calendarListFilename = string(GetUserDir().mb_str());
+ string calendarListFilename = string(GetUserDir().ToUTF8());
calendarListFilename += "accounts/";
- calendarListFilename += string(preferences->accounts.GetAccountDirectory(accountSeek).mb_str());
+ calendarListFilename += string(preferences->accounts.GetAccountDirectory(accountSeek).ToUTF8());
calendarListFilename += ".";
- calendarListFilename += string(preferences->accounts.GetAccountType(accountSeek).mb_str());
+ calendarListFilename += string(preferences->accounts.GetAccountType(accountSeek).ToUTF8());
// Get the list of calendars.
// Set the calendar ID.
- CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(string(preferences->accounts.GetAccountName(accountSeek).mb_str()), calendarList.calendarShortName[calendarSeek]);
+ CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(string(preferences->accounts.GetAccountName(accountSeek).ToUTF8()), calendarList.calendarShortName[calendarSeek]);
calendarList.calendarStorageID[calendarSeek] = calendarInfo.calendarID;
// Find the entries and load each entry.
- string calendarListDirectory = calendarListFilename;
+ wxString calendarListDirectory = wxString(calendarListFilename.c_str(), wxConvUTF8);
calendarListDirectory += "/";
- calendarListDirectory += calendarList.calendarShortName[calendarSeek];
+ calendarListDirectory += wxString(calendarList.calendarShortName[calendarSeek].c_str(), wxConvUTF8);
calendarListDirectory += "/";
wxDir entryListDirectory(calendarListDirectory);
while (continueProcessing){
string entryListFullFilename;
- entryListFullFilename += calendarListDirectory;
- entryListFullFilename += string(entryListFilename.mb_str());
+ entryListFullFilename += string(calendarListDirectory.ToUTF8());
+ entryListFullFilename += string(entryListFilename.ToUTF8());
continueProcessing = entryListDirectory.GetNext(&entryListFilename);
CDSAddEntryResult addEventResult = calendarData.AddEvent(calendarInfo.calendarID, entryListFullFilename);
void frmMain::ShowPreferencesWindow( wxCommandEvent& event )
{
+ // Close all windows first.
+
+ if (CloseAllWindows() == false)
+ {
+ return;
+ }
+
// Open the preferences window.
reloadAccounts = FALSE;
void frmMain::EditCalendar( wxCommandEvent& event )
{
+ // Close all windows first.
+
+ if (CloseAllWindows() == false)
+ {
+ return;
+ }
+
// Get the calendar data.
CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(event.GetInt());
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){
+ if (wxMessageBox(wxString::Format("Are you sure you want to delete the calendar %s from the %s account?", wxString(calendarInfo.calendarName.c_str(), wxConvUTF8), wxString(calendarInfo.accountName.c_str(), wxConvUTF8)), "Delete calendar", wxYES_NO|wxICON_QUESTION) == wxNO){
return;
}
// Get the account configuration file and delete the calendar information.
- CDSGetAccountInfo accountInfo = calendarData.GetAccount(calendarInfo.accountName);
+ CDSGetAccountInfo accountInfo = calendarData.GetAccount(calendarInfo.accountName.c_str());
string accountDirectoryPath = string(GetUserDir().mb_str());
accountDirectoryPath += "accounts/";
- accountDirectoryPath += string(preferences->accounts.GetAccountDirectory(calendarEventInfo->accountPreferencesID).mb_str());
+ accountDirectoryPath += string(preferences->accounts.GetAccountDirectory(calendarEventInfo->accountPreferencesID).ToUTF8());
accountDirectoryPath += ".";
- accountDirectoryPath += string(preferences->accounts.GetAccountType(calendarEventInfo->accountPreferencesID).mb_str());
+ accountDirectoryPath += string(preferences->accounts.GetAccountType(calendarEventInfo->accountPreferencesID).ToUTF8());
accountDirectoryPath += "/";
string calendarListFilenameFull = accountDirectoryPath;
string calendarDirectoryPath = accountDirectoryPath;
calendarDirectoryPath += calendarInfo.calendarTextID;
- wxFileConfig *calendarListFile = new wxFileConfig("", "", wxString(calendarListFilenameFull));
-
- //calendarListFile->SetPath(wxString(calendarInfo.calendarTextID));
- calendarListFile->DeleteGroup(wxString(calendarInfo.calendarTextID));
+ wxFileConfig *calendarListFile = new wxFileConfig("", "", wxString(calendarListFilenameFull.c_str(), wxConvUTF8));
// Delete the calendar directory.
- wxDir entryListDirectory((wxString)calendarDirectoryPath.c_str());
+ wxDir entryListDirectory(wxString(calendarDirectoryPath.c_str(), wxConvUTF8));
wxString entryListFilename;
bool continueProcessing = entryListDirectory.GetFirst(&entryListFilename, "*", wxDIR_NO_FOLLOW|wxDIR_FILES);
-
+
while (continueProcessing){
string entryListFullFilename;
- entryListFullFilename += calendarDirectoryPath;
+ entryListFullFilename += wxString(calendarDirectoryPath.c_str(), wxConvUTF8);
entryListFullFilename += "/";
entryListFullFilename += string(entryListFilename.mb_str());
- wxRemoveFile(wxString(entryListFullFilename.c_str()));
+ wxRemoveFile(wxString(entryListFullFilename.c_str(), wxConvUTF8));
continueProcessing = entryListDirectory.GetNext(&entryListFilename);
}
-
- wxRmdir(calendarDirectoryPath);
+
+ entryListDirectory.Close();
+
+ // Delete the calendar from the account calendar list.
+
+ calendarListFile->DeleteGroup(wxString(calendarInfo.calendarTextID));
// Delete the calendar from the calendar data storage.
calendarData.DeleteCalendar(calendarEventInfo->calendarID);
+ // Delete the calendar directory.
+
+ wxRmDir(wxString(calendarDirectoryPath.c_str(), wxConvUTF8));
+
delete calendarListFile;
calendarListFile = nullptr;
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();
}
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();
}
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){
+ if (wxMessageBox(wxString::Format("Are you sure you want to delete the event %s from the %s calendar?", wxString(eventDeleteData.entryName.c_str(), wxConvUTF8), wxString(calendarDeleteData.calendarName.c_str(), wxConvUTF8)), "Delete event", wxYES_NO|wxICON_QUESTION) == wxNO){
return;
}
// Get the filename and delete the entry.
- wxRemoveFile(wxString(eventDeleteData.entryFilename.c_str()));
+ wxRemoveFile(wxString(eventDeleteData.entryFilename.c_str(), wxConvUTF8));
// Delete the entry from the calendar data storage.
// Get the account name.
- CDSGetAccountInfo accountInfo = calendarData.GetAccount(calendarInfo->accountName);
+ CDSGetAccountInfo accountInfo = calendarData.GetAccount(calendarInfo->accountName.c_str());
// Build the account directory path.
string accountDirectoryPath = string(GetUserDir().mb_str());
accountDirectoryPath += "accounts/";
- accountDirectoryPath += string(preferences->accounts.GetAccountDirectory(calendarInfo->accountPreferencesID).mb_str());
+ accountDirectoryPath += string(preferences->accounts.GetAccountDirectory(calendarInfo->accountPreferencesID).ToUTF8());
accountDirectoryPath += ".";
- accountDirectoryPath += string(preferences->accounts.GetAccountType(calendarInfo->accountPreferencesID).mb_str());
+ accountDirectoryPath += string(preferences->accounts.GetAccountType(calendarInfo->accountPreferencesID).ToUTF8());
accountDirectoryPath += "/";
// Generate a UUID for the new calendar.
string calendarListFilenameFull = accountDirectoryPath;
calendarListFilenameFull += "calendarlist.db";
- wxFileConfig *calendarListFile = new wxFileConfig("", "", wxString(calendarListFilenameFull));
+ wxFileConfig *calendarListFile = new wxFileConfig("", "", wxString(calendarListFilenameFull.c_str(), wxConvUTF8));
- wxString calendarDescription = wxString(calendarInfo->calendarDescription);
+ wxString calendarDescription = wxString(calendarInfo->calendarDescription.c_str(), wxConvUTF8);
calendarDescription.Replace("\n", "\\n", true);
// not editing a calendar.
calendarListFile->SetPath(wxString(calendarUUID));
- calendarListFile->Write(wxT("name"), wxString(calendarInfo->calendarName));
+ calendarListFile->Write(wxT("name"), wxString(calendarInfo->calendarName.c_str(), wxConvUTF8));
calendarListFile->Write(wxT("description"), calendarDescription);
calendarListFile->Write(wxT("colour"), wxString(calendarInfo->calendarColour));
if (calendarInfo->editMode == false){
- wxMkDir(wxString(calendarPath), wxS_DIR_DEFAULT);
+ wxMkDir(wxString(calendarPath.c_str(), wxConvUTF8), wxS_DIR_DEFAULT);
calendarData.AddCalendar(accountInfo.accountID, calendarInfo->calendarName, calendarUUID, calendarInfo->calendarColour, calendarInfo->calendarDescription);
} else {