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