#include <wx/msgdlg.h>
#include <wx/fileconf.h>
-
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));
+ wxMemoryInputStream cstream(icons_accunsupported_png, sizeof(icons_accunsupported_png));
+ wxMemoryInputStream windowposstream(icons_windowpos_png, sizeof(icons_windowpos_png));
+ wxMemoryInputStream hideaddressbooksstream(icons_hideaddressbooks_png, sizeof(icons_hideaddressbooks_png));
+
+ wxImage icons_windowpos_png(windowposstream, wxBITMAP_TYPE_PNG);
+ wxBitmap WindowPosition(icons_windowpos_png, -1);
+
+ wxImage icons_hideaddressbooks_png(hideaddressbooksstream, wxBITMAP_TYPE_PNG);
+ wxBitmap HideAddressBooks(icons_hideaddressbooks_png, -1);
+
+ bmpWindowPosition->SetBitmap(WindowPosition);
+ bmpLocalAddressBooks->SetBitmap(HideAddressBooks);
wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
wxBitmap AccInet(icons_accinet_png, -1);
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);
AccountNetID = AccImgList->Add(wxIAccInet);
+ AccountUnsupportedID = AccImgList->Add(wxIAccUIcon);
NbtPreferences->RemovePage(1);
frmPreferences::~frmPreferences(){
+ // Destory the preferences window.
+
delete AccImgList;
AccImgList = NULL;
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);
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;
-
- wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
-
- // Get the account name.
+ long lstAccountsIndex = -1;
+ wxString AccFilename = GetAccountsFile();
+ wxString AccName;
+ wxString AccType;
- lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
- wxLIST_NEXT_ALL,
- wxLIST_STATE_SELECTED);
+ // Check if an account has been selected before continuing.
+
+ lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
+ wxLIST_NEXT_ALL,
+ wxLIST_STATE_SELECTED);
+
+ if (lstAccountsIndex == -1){
+
+ // No account has been selected so exit this subroutine.
+
+ return;
+
+ }
+
+ wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
+
+ // 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;
+
+ }
+
+ // Get the account name.
- 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();
- delete frameEditAccount;
- frameEditAccount = NULL;
- delete cfgfile;
- cfgfile = NULL;
+ bool DialogResult = frameEditAccount->GetDialogResult();
- // Reload the account list in the preferences window.
+ delete frameEditAccount;
+ frameEditAccount = NULL;
+ delete cfgfile;
+ cfgfile = NULL;
+
+ if (DialogResult == false){
+ return;
+ }
- ReloadAccounts();
- *ReloadAccountConfig = TRUE;
+ // Reload the account list in the preferences window.
+
+ ReloadAccounts();
+ *ReloadAccountConfig = TRUE;
+ btnAccountModify->Enable(FALSE);
+ btnAccountDelete->Enable(FALSE);
+
+}
+void frmPreferences::ModifyABAccount( wxMouseEvent& event )
+{
+
+ wxCommandEvent NullEvent;
+ ModifyABAccount(NullEvent);
+
}
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).
-
- 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();
+ 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);
+ 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"));
+
+ } else {
+
+ AccountDirFull.Append(AccountType.Lower());
+
+ }
- lstAccounts->DeleteItem(lstAccountsIndex);
+ lstAccounts->DeleteItem(lstAccountsIndex);
- // Delete the directory that contains the account information.
+ // Delete the directory that contains the account information.
- if (!AccountDirFull.IsEmpty()){
+ if (!AccountDirFull.IsEmpty()){
- AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME")));
- AccountDirDelFull.Append(wxT("/.xestiaab/accounts/"));
- AccountDirDelFull.Append(AccountDirFull);
+ AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME")));
+ AccountDirDelFull.Append(wxT("/.xestiaab/accounts/"));
+ AccountDirDelFull.Append(AccountDirFull);
- wxRmDir(AccountDirDelFull);
+ 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;
- }
+ }
+ btnAccountModify->Enable(FALSE);
+ btnAccountDelete->Enable(FALSE);
+
}
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"));
+ bool UseBackgroundContactColour = preferences->GetBoolData(wxT("UseBackgroundContactColour"));
- 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.
+ if (UseBackgroundContactColour == true){
+
+ chkUseBackgroundColour->SetValue(true);
+ clpContactBackgroundColour->SetColour(preferences->GetBackgroundContactColourData());
+
+ } else {
+
+ clpContactBackgroundColour->Enable(false);
+
+ }
+
+ // 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);
-
- /*accountscol1.SetId(1);
- accountscol1.SetText(_(""));
- accountscol1.SetWidth(32);
- lstAccounts->InsertColumn(1,accountscol1);
+ accountscol2.SetId(2);
+ accountscol2.SetText(_("Type"));
+ accountscol2.SetWidth(96);
+ lstAccounts->InsertColumn(2,accountscol2);
- accountscol2.SetId(2);
- accountscol2.SetText(_("Name"));
- accountscol2.SetWidth(224);
- lstAccounts->InsertColumn(2,accountscol2);
+ wxString AccType;
- accountscol3.SetId(3);
- accountscol3.SetText(_("Type"));
- accountscol3.SetWidth(96);
- lstAccounts->InsertColumn(3,accountscol3);*/
-
- 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));
-
- long itemindex = lstAccounts->InsertItem( col0 );
+ } else {
+
+ col0.SetImage(AccountUnsupportedID);
+
+ }
- //AccType = preferences.accounts.GetAccountType(i);
- //AccType.Trim();
+ long itemindex = lstAccounts->InsertItem( col0 );
- 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));
- }
+ }
}
void frmPreferences::SetupPointers(bool *ReloadAccountInc){
+ // Setup the pointers for the preferences form.
+
ReloadAccountConfig = ReloadAccountInc;
}
*ReloadAccountConfig = TRUE;
}
+
+ if (chkUseBackgroundColour->GetValue() == TRUE){
+
+ cfgfile->Write(wxT("UseBackgroundContactColour"), wxT("true"));
+ cfgfile->Write(wxT("BackgroundContactColour"), clpContactBackgroundColour->GetColour().GetAsString(wxC2S_HTML_SYNTAX));
+ *ReloadAccountConfig = TRUE;
+
+ } else {
+
+ cfgfile->Write(wxT("UseBackgroundContactColour"), wxT("false"));
+ *ReloadAccountConfig = TRUE;
+
+ }
delete cfgfile;
cfgfile = NULL;
}
+void frmPreferences::EnableBackgroundColourPicker(wxCommandEvent &event){
+
+ if (chkUseBackgroundColour->GetValue() == true){
+ clpContactBackgroundColour->Enable(true);
+ } else {
+ clpContactBackgroundColour->Enable(false);
+ }
+
+}
+
void frmPreferences::CloseWindow(wxCommandEvent &event){
+ // Close the preferences window.
+
this->Close();
}
\ No newline at end of file