From: Steve Brokenshire Date: Wed, 11 Jan 2017 19:42:44 +0000 (+0000) Subject: forms: Forms updated X-Git-Tag: release-0.02~26 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=457d38a9a7b94871b8df70e3a595fd316ca9c4c0;p=xestiacalendar%2F.git forms: Forms updated --- diff --git a/source/forms/main/frmMain.cpp b/source/forms/main/frmMain.cpp index 8f00a1b..e1f2bd9 100644 --- a/source/forms/main/frmMain.cpp +++ b/source/forms/main/frmMain.cpp @@ -59,6 +59,14 @@ frmMainADT( 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)); + } void frmMain::QuitApp( wxCloseEvent& event ) @@ -157,7 +165,7 @@ void frmMain::LoadAccountData(){ 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); } @@ -188,7 +196,8 @@ void frmMain::LoadAccountData(){ 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. @@ -224,6 +233,48 @@ void frmMain::LoadAccountData(){ } +void frmMain::ShowPreferencesWindow( wxCommandEvent& event ) +{ + + // 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 ) { @@ -246,4 +297,325 @@ void frmMain::ShowUpdateWindow( 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 ) +{ + + // 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 ) +{ + + 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->Show(); + +} + +void frmMain::EditEvent( wxCommandEvent& event ){ + + frmEventEditor *frameEditEvent = new frmEventEditor ( this ); + frameEditEvent->SetEventID(event.GetInt()); + frameEditEvent->SetEditMode(true); + frameEditEvent->SetupForm(&calendarData, preferences); + 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 diff --git a/source/forms/main/frmMain.h b/source/forms/main/frmMain.h index 5dd5ec3..194ec11 100644 --- a/source/forms/main/frmMain.h +++ b/source/forms/main/frmMain.h @@ -15,6 +15,10 @@ Subclass of frmMainADT, which is generated by wxFormBuilder. #include "../about/frmAbout.h" #include "../update/frmUpdate.h" +#include "../preferences/frmPreferences.h" +#include "../newaccount/frmNewAccount.h" +#include "../calendareditor/frmCalendarEditor.h" +#include "../eventeditor/frmEventEditor.h" #include "../../widgets/XCCalendarCtrl.h" #include "../../libraries/CalendarDataStorage/CalendarDataStorage.h" @@ -22,6 +26,8 @@ Subclass of frmMainADT, which is generated by wxFormBuilder. #include "events.h" #include "preferences.h" #include "dirs.h" +#include "structs.h" +#include "uuid.h" //// end generated include @@ -34,15 +40,29 @@ class frmMain : public frmMainADT XCCalendarMonthView *monthViewCtrl = nullptr; XCALPreferences *preferences = nullptr; CalendarDataStorage calendarData; + ColourUpdateProperties updateColourData; + bool reloadAccounts = false; protected: void QuitApp( wxCloseEvent& event ); void QuitApp( wxCommandEvent& event ); void QuitApp(); + void ShowPreferencesWindow( wxCommandEvent& event ); + void CreateNewCalendar( wxCommandEvent& event ); + void EditCalendar( wxCommandEvent& event ); + void DeleteCalendar( wxCommandEvent& event ); + void CreateNewEvent( wxCommandEvent& event ); + void EditEvent( wxCommandEvent& event ); + void DeleteEvent( wxCommandEvent& event ); + void AddEvent( wxCommandEvent& event ); + void UpdateEvent( wxCommandEvent& event ); void ShowUpdateWindow( wxCommandEvent& event ); void ShowAboutWindow( wxCommandEvent& event ); + void OpenNewAccountDialog( wxCommandEvent& event ); + void ProcessCalendar( wxCommandEvent& event ); void LoadAccountData(); - + void CloseWindow( wxCommandEvent& event ); + void ShowHelp( wxCommandEvent& event ); public: /** Constructor */ diff --git a/source/forms/newaccount/frmNewAccount.cpp b/source/forms/newaccount/frmNewAccount.cpp index 6baed82..9eb5d24 100644 --- a/source/forms/newaccount/frmNewAccount.cpp +++ b/source/forms/newaccount/frmNewAccount.cpp @@ -5,6 +5,15 @@ frmNewAccount::frmNewAccount( wxWindow* parent ) frmNewAccountADT( parent ) { + // Disable the previous button upon form creation. + + btnPrevious->Disable(); + txtServerAddress->Disable(); + txtServerPort->Disable(); + txtUsername->Disable(); + txtPassword->Disable(); + chkUseSSL->Disable(); + } void frmNewAccount::UpdateRequirements( wxCommandEvent& event ) @@ -12,11 +21,6 @@ void frmNewAccount::UpdateRequirements( wxCommandEvent& event ) // TODO: Implement UpdateRequirements } -void frmNewAccount::CheckAccountName( wxCommandEvent& event ) -{ -// TODO: Implement CheckAccountName -} - void frmNewAccount::ProcessPrevious( wxCommandEvent& event ) { // TODO: Implement ProcessPrevious @@ -24,10 +28,251 @@ void frmNewAccount::ProcessPrevious( wxCommandEvent& event ) void frmNewAccount::ProcessNext( wxCommandEvent& event ) { -// TODO: Implement ProcessNext + + PageSeek++; + + if (PageSeek == 1){ + PageSeek++; + } + + if (PageSeek == 1){ + + // Skip this page. + + } else if (PageSeek == 2){ + + // Finish screen. + + tabType->Hide(); + tabConn->Hide(); + tabFinish->Show(); + szrNewAccount->RecalcSizes(); + + btnNext->Disable(); + btnNext->SetLabel(_("Finish")); + + if (txtAccountName->IsEmpty() && PageSeek == 2){ + + btnNext->Disable(); + + } else { + + btnNext->Enable(); + + } + + } else if (PageSeek == 3){ + + // Finished. + + wxString XestiaCALPrefDirectory; + wxString XestiaCALDirectory; + wxString AccountSettingsFile; + //wxFile ASFile; + + srand(time(0)); + int RandomNumber = rand() % 32767; + wxString RandomNumberSuffix = wxString::Format(wxT("%i"), RandomNumber); + bool DirectoryCreated = FALSE; + +#if defined(__HAIKU__) + + //preffilename = wxT("noo"); + +#elif defined(__WIN32__) + + XestiaCALPrefDirectory = GetUserPrefDir(); + XestiaCALDirectory = GetUserDir(); + + AccountSettingsFile = XestiaCALPrefDirectory + wxT("accounts"); + + // Open the file for writing. + + wxFileConfig *cfgfile = new wxFileConfig("", "", AccountSettingsFile); + + // Check if account name already exists and return an error message + // if this is the case. + + wxString AccountName; + long itemindex = 0; + bool ContinueAcc; + ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex); + + while (ContinueAcc){ + + if (txtAccountName->GetValue() == AccountName){ + + wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR); + return; + + } + + cfgfile->SetPath(wxT("/")); + ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex); + + } + + if (cmbServerType->GetCurrentSelection() == 0){ + + // Create the account directory. + + wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix; + + if (wxMkdir(XestiaCALDirectory + wxT("\\accounts\\") + DirectoryName + wxT(".local"), 0740) == TRUE){ + + DirectoryCreated = TRUE; + + } + + if (DirectoryCreated == TRUE){ + + WriteAccountDetails(cfgfile, wxT("Local"), DirectoryName); + + } else { + + wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory")); + return; + + } + + } + + delete cfgfile; + cfgfile = NULL; + + *ReloadAccountConfig = TRUE; + +#else + + XestiaCALPrefDirectory = GetUserPrefDir(); + XestiaCALDirectory = GetUserDir(); + + AccountSettingsFile = XestiaCALPrefDirectory + wxT("accounts"); + + // Open the file for writing. + + wxFileConfig *cfgfile = new wxFileConfig("", "", AccountSettingsFile); + + // Check if account name already exists and return an error message + // if this is the case. + + wxString AccountName; + long itemindex = 0; + bool ContinueAcc; + ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex); + + while (ContinueAcc){ + + if (txtAccountName->GetValue() == AccountName){ + + wxMessageBox(_("The selected account name is already used, please use another account name."), _("Account name already used"), wxICON_ERROR); + return; + + } + + cfgfile->SetPath(wxT("/")); + ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex); + + } + + if (cmbServerType->GetCurrentSelection() == 0){ + + // Create the account directory. + + wxString DirectoryName = txtAccountName->GetValue().Mid(0, 30) + RandomNumberSuffix; + + if (wxMkdir(XestiaCALDirectory + wxT("/accounts/") + DirectoryName + wxT(".Local"), 0740) == TRUE){ + + DirectoryCreated = TRUE; + + } + + if (DirectoryCreated == TRUE){ + + WriteAccountDetails(cfgfile, wxT("Local"), DirectoryName); + + } else { + + wxMessageBox(_("An error occured whilst creating the account directory."), _("Cannot create account directory")); + return; + + } + + } + + delete cfgfile; + cfgfile = NULL; + + *ReloadAccountConfig = true; + +#endif + + this->Close(); + + } + } void frmNewAccount::CloseWindow( wxCommandEvent& event ) { -// TODO: Implement CloseWindow + + // Close the window. + + *ReloadAccountConfig = FALSE; + this->Close(); + } + +void frmNewAccount::SetupPointers(bool *ReloadAccountInc, CalendarDataStorage *dataStorage){ + + // Setup the pointers for the new account window. + + ReloadAccountConfig = ReloadAccountInc; + +} + +void frmNewAccount::CheckAccountName( wxCommandEvent& event ) +{ + + // Check that the account name is valid. + + wxString CheckAccName = txtAccountName->GetValue(); + + if ((txtAccountName->IsEmpty() && PageSeek == 2) || CheckAccName.Len() < 4){ + + btnNext->Disable(); + + } else { + + btnNext->Enable(); + + } + +} + +void frmNewAccount::WriteAccountDetails(wxFileConfig *cfgfilein, wxString AccountType, wxString DirectoryName){ + + // Write the new account details. + + cfgfilein->SetPath(txtAccountName->GetValue()); + cfgfilein->Write(wxT("address"), txtServerAddress->GetValue()); + cfgfilein->Write(wxT("port"), txtServerPort->GetValue()); + cfgfilein->Write(wxT("username"), txtUsername->GetValue()); + cfgfilein->Write(wxT("password"), txtPassword->GetValue()); + cfgfilein->Write(wxT("prefix"), ServerPrefix); + cfgfilein->Write(wxT("accountdir"), DirectoryName); + + if (chkUseSSL->GetValue() == TRUE){ + + cfgfilein->Write(wxT("ssl"), wxT("true")); + + } else { + + cfgfilein->Write(wxT("ssl"), wxT("false")); + + } + + cfgfilein->Write(wxT("refresh"), wxT("1800")); + cfgfilein->Write(wxT("type"), AccountType); + +} \ No newline at end of file diff --git a/source/forms/newaccount/frmNewAccount.h b/source/forms/newaccount/frmNewAccount.h index bf5ff04..c74a148 100644 --- a/source/forms/newaccount/frmNewAccount.h +++ b/source/forms/newaccount/frmNewAccount.h @@ -6,13 +6,25 @@ Subclass of frmNewAccountADT, which is generated by wxFormBuilder. */ +#include +#include +#include + #include "../../AppXestiaCalendar.h" +#include "../../libraries/CalendarDataStorage/CalendarDataStorage.h" + +#include "dirs.h" + //// end generated include /** Implementing frmNewAccountADT */ class frmNewAccount : public frmNewAccountADT { + private: + int PageSeek = 0; + wxString ServerPrefix; + bool *ReloadAccountConfig = NULL; protected: // Handlers for frmNewAccountADT events. void UpdateRequirements( wxCommandEvent& event ); @@ -20,9 +32,11 @@ class frmNewAccount : public frmNewAccountADT void ProcessPrevious( wxCommandEvent& event ); void ProcessNext( wxCommandEvent& event ); void CloseWindow( wxCommandEvent& event ); + void WriteAccountDetails( wxFileConfig *cfgfilein, wxString AccountType, wxString DirectoryName ); public: /** Constructor */ frmNewAccount( wxWindow* parent ); + void SetupPointers(bool *ReloadAccountInc, CalendarDataStorage *dataStorage); //// end generated class members }; diff --git a/source/forms/preferences/frmPreferences.cpp b/source/forms/preferences/frmPreferences.cpp index aa9aefe..d072475 100644 --- a/source/forms/preferences/frmPreferences.cpp +++ b/source/forms/preferences/frmPreferences.cpp @@ -5,44 +5,405 @@ frmPreferences::frmPreferences( wxWindow* parent ) frmPreferencesADT( parent ) { + wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png)); + wxMemoryInputStream cstream(icons_accunsupported_png, sizeof(icons_accunsupported_png)); + + wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG); + wxBitmap AccNIcon(icons_acclocal_png, -1); + wxIcon wxIAccNIcon; + wxIAccNIcon.CopyFromBitmap(AccNIcon); + + wxImage icons_accunsupported_png(cstream, wxBITMAP_TYPE_PNG); + wxBitmap AccUIcon(icons_accunsupported_png, -1); + wxIcon wxIAccUIcon; + wxIAccUIcon.CopyFromBitmap(AccUIcon); + + AccountID = AccImgList->Add(wxIAccNIcon); + AccountUnsupportedID = AccImgList->Add(wxIAccUIcon); + + NbtPreferences->RemovePage(1); + btnAccountAdd->Show(false); + } void frmPreferences::LoadPreferences( wxInitDialogEvent& event ) { -// TODO: Implement LoadPreferences + + // Setup the preferences filename string. Default is the + // *nix systems one (/home/$USER/.xestiacal/preferences) + + preffilename = GetUserPrefDir(); + + preferences = new XCALPreferences(preffilename); + + // Setup the General Tab. + + bool SaveWindowPos = preferences->GetBoolData(wxT("SaveWindowPosition")); + bool HideLocalABs = preferences->GetBoolData(wxT("HideLocalCalendars")); + + if (SaveWindowPos == TRUE){ + + chkSaveWindowPosition->SetValue(TRUE); + + } + + if (HideLocalABs == TRUE){ + + chkHideLocal->SetValue(TRUE); + + } + + // Setup the Themes tab. + + wxListItem themecol0; + + themecol0.SetId(0); + themecol0.SetWidth(250); + themecol0.SetText(_("Theme")); + lstThemes->InsertColumn(0,themecol0); + + // Setup the Accounts tab. + + ReloadAccounts(); + +} + +frmPreferences::~frmPreferences(){ + + // Destory the preferences window. + + delete AccImgList; + AccImgList = NULL; + } -void frmPreferences::DisableABButtons( wxListEvent& event ) +void frmPreferences::ReloadAccounts(){ + + // Reload the accounts in the accounts list. + + if (FirstLoad == FALSE){ + delete preferences; + preferences = NULL; + preferences = new XCALPreferences(preffilename); + } else { + FirstLoad = FALSE; + } + + wxListItem accountscol0, accountscol1, accountscol2, accountscol3; + + lstAccounts->ClearAll(); + + accountscol0.SetId(0); + accountscol0.SetWidth(24); + lstAccounts->InsertColumn(0,accountscol0); + lstAccounts->SetImageList(AccImgList, wxIMAGE_LIST_SMALL); + + accountscol1.SetId(1); + accountscol1.SetText(_("Name")); + accountscol1.SetWidth(224); + lstAccounts->InsertColumn(1,accountscol1); + + accountscol2.SetId(2); + accountscol2.SetText(_("Type")); + accountscol2.SetWidth(96); + lstAccounts->InsertColumn(2,accountscol2); + + wxString AccType; + + for (int i = 0; i < preferences->accounts.GetCount() ; i++){ + + wxListItem col0; + col0.SetId(i); + + /* if (preferences->accounts.GetAccountType(i) == wxT("CalDAV")){ + + col0.SetImage(AccountNetID); + + } else */ + + if (preferences->accounts.GetAccountType(i) == wxT("Local")){ + + col0.SetImage(AccountID); + + } else { + + col0.SetImage(AccountUnsupportedID); + + } + + long itemindex = lstAccounts->InsertItem( col0 ); + + lstAccounts->SetItem(itemindex, 1, preferences->accounts.GetAccountName(i)); + lstAccounts->SetItem(itemindex, 2, preferences->accounts.GetAccountType(i)); + lstAccounts->SetItemData(itemindex, i); + + } + +} + +void frmPreferences::DisableButtons( wxListEvent& event ) { -// TODO: Implement DisableABButtons + + // Disable the account buttons. + + btnAccountModify->Enable(FALSE); + btnAccountDelete->Enable(FALSE); + } -void frmPreferences::EnableABButtons( wxListEvent& event ) +void frmPreferences::EnableButtons( wxListEvent& event ) { -// TODO: Implement EnableABButtons + + // Enable the account buttons. + + btnAccountModify->Enable(TRUE); + btnAccountDelete->Enable(TRUE); + } -void frmPreferences::AddABAccount( wxCommandEvent& event ) +void frmPreferences::AddAccount( wxCommandEvent& event ) { // TODO: Implement AddABAccount } -void frmPreferences::ModifyABAccount( wxCommandEvent& event ) +void frmPreferences::ModifyAccount( wxCommandEvent& event ) { -// TODO: Implement ModifyABAccount + + // Get the settings for the account, setup the form for + // editing the account and then display the window + // with the settings. + + long lstAccountsIndex = -1; + wxString AccFilename = GetAccountsFile(); + wxString AccName; + wxString AccType; + + wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename); + + // Get the account name. + + lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex, + wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); + + // Check that the account type is a supported account type. + + AccType = preferences->accounts.GetAccountType((int)lstAccountsIndex); + + if (AccType != "CardDAV" && AccType != "carddav" && + AccType != "Local" && AccType != "local"){ + + wxMessageBox(_("Cannot modify the selected account settings as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR); + return; + + } + + AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex); + + frmEditAccount *frameEditAccount = new frmEditAccount ( this ); + frameEditAccount->LoadPointers(cfgfile); + frameEditAccount->LoadSettings(AccName); + frameEditAccount->ShowModal(); + + bool DialogResult = frameEditAccount->GetDialogResult(); + + delete frameEditAccount; + frameEditAccount = NULL; + delete cfgfile; + cfgfile = NULL; + + if (DialogResult == false){ + return; + } + + // Reload the account list in the preferences window. + + ReloadAccounts(); + *ReloadAccountConfig = TRUE; + btnAccountModify->Enable(FALSE); + btnAccountDelete->Enable(FALSE); + } -void frmPreferences::DeleteABAccount( wxCommandEvent& event ) +void frmPreferences::DeleteAccount( wxCommandEvent& event ) { -// TODO: Implement DeleteABAccount + + // Display a confirmation dialog to confirm deletion. + + long lstAccountsIndex = -1; + wxMessageDialog dlgdel(this, wxT("Are you sure you want to delete this account?\r\n\r\nAll data that is stored locally will be removed."), wxT("Delete account"), wxYES_NO | wxICON_EXCLAMATION); + + if (dlgdel.ShowModal() == wxID_YES){ + + // Remove the selected item from the accounts list + // and mark in the accounts list as deleted (Don't write to + // accounts file). + + lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex, + wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); + + bool ContinueAcc = TRUE; + wxString AccountDir; + wxString AccountType; + wxString AccountDirFull; + wxString AccountDirDelFull; + wxString AccountName; + wxString AccName; + long itemindex = 0; + + wxString AccFilename = GetAccountsFile(); + + wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename); + + AccName = preferences->accounts.GetAccountName((int)lstAccounts->GetItemData(lstAccountsIndex)); + + // Get the account directory name and account type.. + + ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex); + + while (ContinueAcc){ + + if (AccountName == AccName){ + + cfgfile->SetPath(AccountName); + + cfgfile->Read("accountdir", &AccountDir); + cfgfile->Read("type", &AccountType); + + break; + + } + + cfgfile->SetPath(wxT("/")); + ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex); + + } + + AccountDirFull.Append(AccountDir); + AccountDirFull.Append(wxT(".")); + + /*if (AccountType == wxT("CalDAV")){ + + AccountDirFull.Append(wxT("local")); + + } else */ + + if (AccountType == wxT("Local")){ + + AccountDirFull.Append(wxT("Local")); + + }/*else { + + AccountDirFull.Append(AccountType.Lower()); + + }*/ + + lstAccounts->DeleteItem(lstAccountsIndex); + + // Delete the directory that contains the account information. + + if (!AccountDirFull.IsEmpty()){ + + AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME"))); + AccountDirDelFull.Append(wxT("/.xestiacal/accounts/")); + AccountDirDelFull.Append(AccountDirFull); + + wxRmDir(AccountDirDelFull); + + } + + // Delete the account from the configuration file. + + cfgfile->SetPath(wxT("/")); + cfgfile->DeleteGroup(AccountName); + cfgfile->Flush(); + + // Set flag for reloading accounts on window closure. + + *ReloadAccountConfig = TRUE; + + } + + btnAccountModify->Enable(FALSE); + btnAccountDelete->Enable(FALSE); + } void frmPreferences::SavePreferences( wxCommandEvent& event ) { -// TODO: Implement SavePreferences + + // Load up the preferences file. + + wxString SetFilename = GetSettingsFile(); + + wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename); + + // Update the settings file. + + cfgfile->DeleteEntry(wxT("SaveWindowPosition")); + cfgfile->DeleteEntry(wxT("WindowPositionX")); + cfgfile->DeleteEntry(wxT("WindowPositionY")); + cfgfile->DeleteEntry(wxT("WindowPositionHeight")); + cfgfile->DeleteEntry(wxT("WindowPositionWidth")); + + if (chkSaveWindowPosition->GetValue() == TRUE){ + + cfgfile->Write(wxT("SaveWindowPosition"), wxT("true")); + + // Get parent window details. + + frmMain *frmMainPtr = (frmMain*)this->GetParent(); + + // Get main window position data and save it. + + wxRect frmMainPos = frmMainPtr->GetRect(); + + cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX()); + cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY()); + cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight()); + cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth()); + + } else { + + cfgfile->Write(wxT("SaveWindowPosition"), wxT("false")); + + } + + cfgfile->DeleteEntry(wxT("HideLocalCalendars")); + + if (chkHideLocal->GetValue() == TRUE){ + + cfgfile->Write(wxT("HideLocalCalendars"), wxT("true")); + *ReloadAccountConfig = TRUE; + + } else { + + cfgfile->Write(wxT("HideLocalCalendars"), wxT("false")); + *ReloadAccountConfig = TRUE; + + } + + delete cfgfile; + cfgfile = NULL; + + this->Close(); + } void frmPreferences::CloseWindow( wxCommandEvent& event ) { -// TODO: Implement CloseWindow + + // Close the preferences window. + + this->Close(); + } + +void frmPreferences::SetupPointers(bool *ReloadAccountInc){ + + // Setup the pointers for the preferences form. + + ReloadAccountConfig = ReloadAccountInc; + +} \ No newline at end of file diff --git a/source/forms/preferences/frmPreferences.h b/source/forms/preferences/frmPreferences.h index 931ca40..3c8cfd8 100644 --- a/source/forms/preferences/frmPreferences.h +++ b/source/forms/preferences/frmPreferences.h @@ -6,26 +6,50 @@ Subclass of frmPreferencesADT, which is generated by wxFormBuilder. */ +#include +#include +#include +#include +#include + #include "../../AppXestiaCalendar.h" +#include "../../bitmaps.h" +#include "../main/frmMain.h" +#include "../editaccount/frmEditAccount.h" + +#include "preferences.h" +#include "dirs.h" //// end generated include /** Implementing frmPreferencesADT */ class frmPreferences : public frmPreferencesADT { + private: + void ReloadAccounts(); + wxImageList *AccImgList = new wxImageList(16,16,true,wxIMAGE_LIST_SMALL); + int AccountID = 0; + int AccountNetID = 0; + int AccountUnsupportedID = 0; + XCALPreferences *preferences; + wxString preffilename; + bool FirstLoad = TRUE; + bool *ReloadAccountConfig; protected: // Handlers for frmPreferencesADT events. void LoadPreferences( wxInitDialogEvent& event ); - void DisableABButtons( wxListEvent& event ); - void EnableABButtons( wxListEvent& event ); - void AddABAccount( wxCommandEvent& event ); - void ModifyABAccount( wxCommandEvent& event ); - void DeleteABAccount( wxCommandEvent& event ); + void DisableButtons( wxListEvent& event ); + void EnableButtons( wxListEvent& event ); + void AddAccount( wxCommandEvent& event ); + void ModifyAccount( wxCommandEvent& event ); + void DeleteAccount( wxCommandEvent& event ); void SavePreferences( wxCommandEvent& event ); void CloseWindow( wxCommandEvent& event ); public: /** Constructor */ frmPreferences( wxWindow* parent ); + ~frmPreferences(); + void SetupPointers( bool *ReloadAccountInc ); //// end generated class members };