From: Steve Brokenshire Date: Wed, 9 Mar 2016 22:09:18 +0000 (+0000) Subject: Added comments and correct identation in frmPreferences X-Git-Tag: release-0.11~167 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=08422295fa6a0695f6cd6d2da90b560342bec79f;p=xestiaab%2F.git Added comments and correct identation in frmPreferences --- diff --git a/source/frmPreferences.cpp b/source/frmPreferences.cpp index 01a4656..716fc7a 100644 --- a/source/frmPreferences.cpp +++ b/source/frmPreferences.cpp @@ -39,6 +39,8 @@ frmPreferences::frmPreferences( wxWindow* parent ) frmPreferencesADT( parent ) { + // Setup the preferences window. + wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png)); wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png)); @@ -61,6 +63,8 @@ frmPreferencesADT( parent ) frmPreferences::~frmPreferences(){ + // Destory the preferences window. + delete AccImgList; AccImgList = NULL; @@ -68,19 +72,29 @@ frmPreferences::~frmPreferences(){ void frmPreferences::EnableABButtons( wxListEvent& event ) { - btnAccountModify->Enable(TRUE); - btnAccountDelete->Enable(TRUE); + + // Enable the account buttons. + + btnAccountModify->Enable(TRUE); + btnAccountDelete->Enable(TRUE); + } void frmPreferences::DisableABButtons( wxListEvent& event ) { - btnAccountModify->Enable(FALSE); - btnAccountDelete->Enable(FALSE); + + // Disable the account buttons. + + btnAccountModify->Enable(FALSE); + btnAccountDelete->Enable(FALSE); + } void frmPreferences::AddABAccount(wxCommandEvent& event) { + // Add new account. + bool ReloadAccountsData = FALSE; frmNewAccount *frameNewAccount = new frmNewAccount(this); @@ -104,213 +118,216 @@ void frmPreferences::AddABAccount(wxCommandEvent& event) void frmPreferences::ModifyABAccount( wxCommandEvent& event ) { - // Get the settings for the account, setup the form for - // editing the account and then display the window - // with the settings. + // 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; + long lstAccountsIndex = -1; + wxString AccFilename = GetAccountsFile(); + wxString AccName; - wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename); + wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename); - // Get the account name. + // Get the account name. - lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex, - wxLIST_NEXT_ALL, - wxLIST_STATE_SELECTED); + lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex, + wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); - AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex); + AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex); - frmEditAccount *frameEditAccount = new frmEditAccount ( this ); - frameEditAccount->LoadPointers(cfgfile); - frameEditAccount->LoadSettings(AccName); - frameEditAccount->ShowModal(); + frmEditAccount *frameEditAccount = new frmEditAccount ( this ); + frameEditAccount->LoadPointers(cfgfile); + frameEditAccount->LoadSettings(AccName); + frameEditAccount->ShowModal(); - bool DialogResult = frameEditAccount->GetDialogResult(); + bool DialogResult = frameEditAccount->GetDialogResult(); - delete frameEditAccount; - frameEditAccount = NULL; - delete cfgfile; - cfgfile = NULL; + delete frameEditAccount; + frameEditAccount = NULL; + delete cfgfile; + cfgfile = NULL; - if (DialogResult == false){ - return; - } + if (DialogResult == false){ + return; + } - // Reload the account list in the preferences window. + // Reload the account list in the preferences window. - ReloadAccounts(); - *ReloadAccountConfig = TRUE; - btnAccountModify->Enable(FALSE); - btnAccountDelete->Enable(FALSE); + ReloadAccounts(); + *ReloadAccountConfig = TRUE; + btnAccountModify->Enable(FALSE); + btnAccountDelete->Enable(FALSE); } void frmPreferences::DeleteABAccount( wxCommandEvent& event ) { - // Display a confirmation dialog to confirm deletion. + // 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); + 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). + 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; + lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex, + wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); - wxString AccFilename = GetAccountsFile(); + 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); + wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename); - AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex); + AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex); - // Get the account directory name and account type.. + // Get the account directory name and account type.. - ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex); + ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex); - while (ContinueAcc){ + while (ContinueAcc){ - if (AccountName == AccName){ + if (AccountName == AccName){ - cfgfile->SetPath(AccountName); + cfgfile->SetPath(AccountName); - cfgfile->Read("accountdir", &AccountDir); - cfgfile->Read("type", &AccountType); + cfgfile->Read("accountdir", &AccountDir); + cfgfile->Read("type", &AccountType); - break; + break; - } + } - cfgfile->SetPath(wxT("/")); - ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex); - - } + cfgfile->SetPath(wxT("/")); + ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex); - AccountDirFull.Append(AccountDir); - AccountDirFull.Append(wxT(".")); + } - if (AccountType == wxT("CardDAV")){ + AccountDirFull.Append(AccountDir); + AccountDirFull.Append(wxT(".")); - AccountDirFull.Append(wxT("local")); + if (AccountType == wxT("CardDAV")){ - } else if (AccountType == wxT("Local")){ + AccountDirFull.Append(wxT("local")); - AccountDirFull.Append(wxT("carddav")); + } else if (AccountType == wxT("Local")){ - } + AccountDirFull.Append(wxT("carddav")); - lstAccounts->DeleteItem(lstAccountsIndex); + } - // Delete the directory that contains the account information. + lstAccounts->DeleteItem(lstAccountsIndex); - if (!AccountDirFull.IsEmpty()){ + // Delete the directory that contains the account information. - AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME"))); - AccountDirDelFull.Append(wxT("/.xestiaab/accounts/")); - AccountDirDelFull.Append(AccountDirFull); + if (!AccountDirFull.IsEmpty()){ - wxRmDir(AccountDirDelFull); + AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME"))); + AccountDirDelFull.Append(wxT("/.xestiaab/accounts/")); + AccountDirDelFull.Append(AccountDirFull); - } + wxRmDir(AccountDirDelFull); - // Delete the account from the configuration file. + } + + // Delete the account from the configuration file. - cfgfile->SetPath(wxT("/")); - cfgfile->DeleteGroup(AccountName); - cfgfile->Flush(); + cfgfile->SetPath(wxT("/")); + cfgfile->DeleteGroup(AccountName); + cfgfile->Flush(); - // Set flag for reloading accounts on window closure. + // Set flag for reloading accounts on window closure. - *ReloadAccountConfig = TRUE; + *ReloadAccountConfig = TRUE; - } + } } void frmPreferences::LoadPreferences( wxInitDialogEvent& event ) { -// Setup the preferences filename string. Default is the -// *nix systems one (/home/$USER/.xestiaab/preferences) + // Setup the preferences filename string. Default is the + // *nix systems one (/home/$USER/.xestiaab/preferences) preffilename = GetUserPrefDir(); - preferences = new XABPreferences(preffilename); + preferences = new XABPreferences(preffilename); - // Setup the General Tab. + // Setup the General Tab. - bool SaveWindowPos = preferences->GetBoolData(wxT("SaveWindowPosition")); - bool HideLocalABs = preferences->GetBoolData(wxT("HideLocalAddressBooks")); + bool SaveWindowPos = preferences->GetBoolData(wxT("SaveWindowPosition")); + bool HideLocalABs = preferences->GetBoolData(wxT("HideLocalAddressBooks")); - if (SaveWindowPos == TRUE){ + if (SaveWindowPos == TRUE){ - chkSaveWindowPosition->SetValue(TRUE); + chkSaveWindowPosition->SetValue(TRUE); - } + } - if (HideLocalABs == TRUE){ + if (HideLocalABs == TRUE){ - chkHideLocal->SetValue(TRUE); + chkHideLocal->SetValue(TRUE); - } + } - // Setup the Themes tab. + // Setup the Themes tab. - wxListItem themecol0; + wxListItem themecol0; - themecol0.SetId(0); - themecol0.SetWidth(250); - themecol0.SetText(_("Theme")); - lstThemes->InsertColumn(0,themecol0); + themecol0.SetId(0); + themecol0.SetWidth(250); + themecol0.SetText(_("Theme")); + lstThemes->InsertColumn(0,themecol0); - // Setup the Accounts tab. + // Setup the Accounts tab. - ReloadAccounts(); + ReloadAccounts(); } void frmPreferences::ReloadAccounts(){ - if (FirstLoad == FALSE){ - delete preferences; - preferences = NULL; - preferences = new XABPreferences(preffilename); - } else { - FirstLoad = FALSE; - } + // Reload the accounts in the accounts list. + + if (FirstLoad == FALSE){ + delete preferences; + preferences = NULL; + preferences = new XABPreferences(preffilename); + } else { + FirstLoad = FALSE; + } - wxListItem accountscol0, accountscol1, accountscol2, accountscol3; + wxListItem accountscol0, accountscol1, accountscol2, accountscol3; - lstAccounts->ClearAll(); + lstAccounts->ClearAll(); - accountscol0.SetId(0); - accountscol0.SetWidth(24); - lstAccounts->InsertColumn(0,accountscol0); - lstAccounts->SetImageList(AccImgList, wxIMAGE_LIST_SMALL); + 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); + 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); + accountscol2.SetId(2); + accountscol2.SetText(_("Type")); + accountscol2.SetWidth(96); + lstAccounts->InsertColumn(2,accountscol2); /*accountscol1.SetId(1); accountscol1.SetText(_("")); @@ -327,40 +344,43 @@ void frmPreferences::ReloadAccounts(){ accountscol3.SetWidth(96); lstAccounts->InsertColumn(3,accountscol3);*/ - wxString AccType; + wxString AccType; - for (int i = 0; i < preferences->accounts.GetCount() ; i++){ + for (int i = 0; i < preferences->accounts.GetCount() ; i++){ - wxListItem col0; - col0.SetId(i); - if (preferences->accounts.GetAccountType(i) == wxT("CardDAV")){ + wxListItem col0; + col0.SetId(i); + + if (preferences->accounts.GetAccountType(i) == wxT("CardDAV")){ - col0.SetImage(AccountNetID); + col0.SetImage(AccountNetID); - } else if (preferences->accounts.GetAccountType(i) == wxT("Local")){ + } else if (preferences->accounts.GetAccountType(i) == wxT("Local")){ - col0.SetImage(AccountID); + col0.SetImage(AccountID); - } + } - //col0.SetText( wxString::Format(wxT("%i"),i) ); - //col0.SetText(preferences.accounts.GetAccountName(i)); + //col0.SetText( wxString::Format(wxT("%i"),i) ); + //col0.SetText(preferences.accounts.GetAccountName(i)); - long itemindex = lstAccounts->InsertItem( col0 ); + long itemindex = lstAccounts->InsertItem( col0 ); - //AccType = preferences.accounts.GetAccountType(i); - //AccType.Trim(); + //AccType = preferences.accounts.GetAccountType(i); + //AccType.Trim(); - lstAccounts->SetItem(itemindex, 1, preferences->accounts.GetAccountName(i)); - lstAccounts->SetItem(itemindex, 2, preferences->accounts.GetAccountType(i)); - //lstAccounts->SetItem(itemindex, 3, AccType); + lstAccounts->SetItem(itemindex, 1, preferences->accounts.GetAccountName(i)); + lstAccounts->SetItem(itemindex, 2, preferences->accounts.GetAccountType(i)); + //lstAccounts->SetItem(itemindex, 3, AccType); - } + } } void frmPreferences::SetupPointers(bool *ReloadAccountInc){ + // Setup the pointers for the preferences form. + ReloadAccountConfig = ReloadAccountInc; } @@ -427,6 +447,8 @@ void frmPreferences::SavePreferences(wxCommandEvent &event){ void frmPreferences::CloseWindow(wxCommandEvent &event){ + // Close the preferences window. + this->Close(); } \ No newline at end of file