From 373ead69e449039795b5026c4012d7e903ba4835 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 28 Jan 2018 14:41:56 +0000 Subject: [PATCH] frmMain: Implemented UTF8 support in DeleteCalendar function --- source/forms/main/frmMain.cpp | 41 ++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/source/forms/main/frmMain.cpp b/source/forms/main/frmMain.cpp index 9c420ff..2f826de 100644 --- a/source/forms/main/frmMain.cpp +++ b/source/forms/main/frmMain.cpp @@ -434,7 +434,7 @@ void frmMain::DeleteCalendar( wxCommandEvent& event ) 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; } @@ -448,11 +448,11 @@ void frmMain::DeleteCalendar( wxCommandEvent& event ) // 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 += "/"; @@ -465,35 +465,40 @@ void frmMain::DeleteCalendar( wxCommandEvent& event ) 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()); + 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; @@ -616,13 +621,13 @@ void frmMain::ProcessCalendar( wxCommandEvent& event ) // 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 += "/"; @@ -652,9 +657,9 @@ void frmMain::ProcessCalendar( wxCommandEvent& event ) 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); @@ -662,13 +667,13 @@ void frmMain::ProcessCalendar( wxCommandEvent& event ) // 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 { -- 2.39.5