X-Git-Url: http://Server1/repobrowser/?p=xestiacalendar%2F.git;a=blobdiff_plain;f=source%2Fforms%2Fpreferences%2FfrmPreferences.cpp;h=f35fac16fc67c0439b074c52f6bfffd68a8bc05d;hp=aa9aefe42488fb65ce5065738bf89fda04b0da45;hb=0c16b6458c0fdc03b94288c17d7a685b95f122fc;hpb=53f288b9f66a1628babd3b0f670c5e75f812860f diff --git a/source/forms/preferences/frmPreferences.cpp b/source/forms/preferences/frmPreferences.cpp index aa9aefe..f35fac1 100644 --- a/source/forms/preferences/frmPreferences.cpp +++ b/source/forms/preferences/frmPreferences.cpp @@ -1,3 +1,21 @@ +// frmPreferences.cpp - frmPreferences 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 + #include "frmPreferences.h" frmPreferences::frmPreferences( wxWindow* parent ) @@ -5,44 +23,406 @@ 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); + NbtPreferences->ChangeSelection(0); + } 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::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::DisableABButtons( wxListEvent& event ) +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