Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
utf8: Implemented further UTF8 support
[xestiacalendar/.git] / source / forms / main / frmMain.cpp
index e1f2bd9..11246ae 100644 (file)
@@ -1,10 +1,39 @@
+// 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.
        
@@ -58,15 +87,20 @@ frmMainADT( parent )
        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 )
@@ -165,7 +199,7 @@ void frmMain::LoadAccountData(){
        
        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);
                
        }
        
@@ -173,7 +207,7 @@ void frmMain::LoadAccountData(){
        
        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.
                
@@ -206,9 +240,9 @@ void frmMain::LoadAccountData(){
                        
                        // 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);
@@ -219,8 +253,8 @@ void frmMain::LoadAccountData(){
                        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);
@@ -236,6 +270,13 @@ void frmMain::LoadAccountData(){
 void frmMain::ShowPreferencesWindow( wxCommandEvent& event )
 {
 
+       // Close all windows first.
+       
+       if (CloseAllWindows() == false)
+       {
+               return;
+       }
+       
        // Open the preferences window.
     
        reloadAccounts = FALSE;
@@ -356,6 +397,13 @@ void frmMain::CreateNewCalendar( wxCommandEvent& event )
 void frmMain::EditCalendar( wxCommandEvent& event )
 {
        
+       // Close all windows first.
+       
+       if (CloseAllWindows() == false)
+       {
+               return;
+       }
+       
        // Get the calendar data.
        
        CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(event.GetInt());
@@ -373,13 +421,20 @@ void frmMain::EditCalendar( wxCommandEvent& event )
 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;
        }
        
@@ -393,13 +448,13 @@ 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 += string(preferences->accounts.GetAccountType(calendarEventInfo->accountPreferencesID).ToUTF8());
        accountDirectoryPath += "/";
        
        string calendarListFilenameFull = accountDirectoryPath;
@@ -408,37 +463,42 @@ void frmMain::DeleteCalendar( wxCommandEvent& event )
        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;
        
@@ -451,6 +511,21 @@ 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();
        
 }
@@ -460,7 +535,24 @@ 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();
        
 }
@@ -474,7 +566,7 @@ void frmMain::DeleteEvent( wxCommandEvent& event ){
        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;
        }
        
@@ -487,7 +579,7 @@ void frmMain::DeleteEvent( wxCommandEvent& event ){
        
        // 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.
        
@@ -529,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 += "/";
@@ -565,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);
        
@@ -575,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 {
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy