1 #include "frmPreferences.h"
2 #include "frmEditAccount.h"
3 #include "frmNewAccount.h"
5 #include "common/preferences.h"
6 #include "common/dirs.h"
9 #include "import/import.h"
10 #include "export/export.h"
13 #include <wx/mstream.h>
14 #include <wx/dialog.h>
15 #include <wx/msgdlg.h>
16 #include <wx/fileconf.h>
19 frmPreferences::frmPreferences( wxWindow* parent )
21 frmPreferencesADT( parent )
24 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
25 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
27 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
28 wxBitmap AccInet(icons_accinet_png, -1);
30 wxIAccInet.CopyFromBitmap(AccInet);
32 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
33 wxBitmap AccNIcon(icons_acclocal_png, -1);
35 wxIAccNIcon.CopyFromBitmap(AccNIcon);
37 AccountID = AccImgList->Add(wxIAccNIcon);
38 AccountNetID = AccImgList->Add(wxIAccInet);
40 NbtPreferences->RemovePage(1);
44 frmPreferences::~frmPreferences(){
51 void frmPreferences::EnableABButtons( wxListEvent& event )
53 btnAccountModify->Enable(TRUE);
54 btnAccountDelete->Enable(TRUE);
57 void frmPreferences::DisableABButtons( wxListEvent& event )
59 btnAccountModify->Enable(FALSE);
60 btnAccountDelete->Enable(FALSE);
63 void frmPreferences::AddABAccount(wxCommandEvent& event)
66 bool ReloadAccountsData = FALSE;
68 frmNewAccount *frameNewAccount = new frmNewAccount(this);
69 frameNewAccount->SetupPointers(&ReloadAccountsData);
70 frameNewAccount->ShowModal();
71 delete frameNewAccount;
72 frameNewAccount = NULL;
74 if (ReloadAccountsData == TRUE){
76 // Reload the accounts as a change has been made within
80 *ReloadAccountConfig = TRUE;
86 void frmPreferences::ModifyABAccount( wxCommandEvent& event )
89 // Get the settings for the account, setup the form for
90 // editing the account and then display the window
93 long lstAccountsIndex = -1;
94 wxString AccFilename = GetAccountsFile();
97 wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
99 // Get the account name.
101 lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
103 wxLIST_STATE_SELECTED);
105 AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
107 frmEditAccount *frameEditAccount = new frmEditAccount ( this );
108 frameEditAccount->LoadPointers(cfgfile);
109 frameEditAccount->LoadSettings(AccName);
110 frameEditAccount->ShowModal();
112 delete frameEditAccount;
113 frameEditAccount = NULL;
117 // Reload the account list in the preferences window.
120 *ReloadAccountConfig = TRUE;
124 void frmPreferences::DeleteABAccount( wxCommandEvent& event )
126 // Display a confirmation dialog to confirm deletion.
128 long lstAccountsIndex = -1;
129 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);
131 if (dlgdel.ShowModal() == wxID_YES){
132 // Remove the selected item from the accounts list
133 // and mark in the accounts list as deleted (Don't write to
136 lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
138 wxLIST_STATE_SELECTED);
140 bool ContinueAcc = TRUE;
142 wxString AccountType;
143 wxString AccountDirFull;
144 wxString AccountDirDelFull;
145 wxString AccountName;
149 wxString AccFilename = GetAccountsFile();
151 wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
153 AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
155 // Get the account directory name and account type..
157 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
161 if (AccountName == AccName){
163 cfgfile->SetPath(AccountName);
165 cfgfile->Read("accountdir", &AccountDir);
166 cfgfile->Read("type", &AccountType);
172 cfgfile->SetPath(wxT("/"));
173 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
177 AccountDirFull.Append(AccountDir);
178 AccountDirFull.Append(wxT("."));
180 if (AccountType == wxT("CardDAV")){
182 AccountDirFull.Append(wxT("local"));
184 } else if (AccountType == wxT("Local")){
186 AccountDirFull.Append(wxT("carddav"));
190 lstAccounts->DeleteItem(lstAccountsIndex);
192 // Delete the directory that contains the account information.
194 if (!AccountDirFull.IsEmpty()){
196 AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME")));
197 AccountDirDelFull.Append(wxT("/.xestiaab/accounts/"));
198 AccountDirDelFull.Append(AccountDirFull);
200 wxRmDir(AccountDirDelFull);
204 // Delete the account from the configuration file.
206 cfgfile->SetPath(wxT("/"));
207 cfgfile->DeleteGroup(AccountName);
210 // Set flag for reloading accounts on window closure.
212 *ReloadAccountConfig = TRUE;
218 void frmPreferences::LoadPreferences( wxInitDialogEvent& event )
221 // Setup the preferences filename string. Default is the
222 // *nix systems one (/home/$USER/.xestiaab/preferences)
224 preffilename = GetUserPrefDir();
226 preferences = new XABPreferences(preffilename);
228 // Setup the General Tab.
230 bool SaveWindowPos = preferences->GetBoolData(wxT("SaveWindowPosition"));
231 bool HideLocalABs = preferences->GetBoolData(wxT("HideLocalAddressBooks"));
233 if (SaveWindowPos == TRUE){
235 chkSaveWindowPosition->SetValue(TRUE);
239 if (HideLocalABs == TRUE){
241 chkHideLocal->SetValue(TRUE);
245 // Setup the Themes tab.
247 wxListItem themecol0;
250 themecol0.SetWidth(250);
251 themecol0.SetText(_("Theme"));
252 lstThemes->InsertColumn(0,themecol0);
254 // Setup the Accounts tab.
260 void frmPreferences::ReloadAccounts(){
262 if (FirstLoad == FALSE){
265 preferences = new XABPreferences(preffilename);
270 wxListItem accountscol0, accountscol1, accountscol2, accountscol3;
272 lstAccounts->ClearAll();
274 accountscol0.SetId(0);
275 accountscol0.SetWidth(24);
276 lstAccounts->InsertColumn(0,accountscol0);
277 lstAccounts->SetImageList(AccImgList, wxIMAGE_LIST_SMALL);
279 accountscol1.SetId(1);
280 accountscol1.SetText(_("Name"));
281 accountscol1.SetWidth(224);
282 lstAccounts->InsertColumn(1,accountscol1);
284 accountscol2.SetId(2);
285 accountscol2.SetText(_("Type"));
286 accountscol2.SetWidth(96);
287 lstAccounts->InsertColumn(2,accountscol2);
289 /*accountscol1.SetId(1);
290 accountscol1.SetText(_(""));
291 accountscol1.SetWidth(32);
292 lstAccounts->InsertColumn(1,accountscol1);
294 accountscol2.SetId(2);
295 accountscol2.SetText(_("Name"));
296 accountscol2.SetWidth(224);
297 lstAccounts->InsertColumn(2,accountscol2);
299 accountscol3.SetId(3);
300 accountscol3.SetText(_("Type"));
301 accountscol3.SetWidth(96);
302 lstAccounts->InsertColumn(3,accountscol3);*/
306 for (int i = 0; i < preferences->accounts.GetCount() ; i++){
310 if (preferences->accounts.GetAccountType(i) == wxT("CardDAV")){
312 col0.SetImage(AccountNetID);
314 } else if (preferences->accounts.GetAccountType(i) == wxT("Local")){
316 col0.SetImage(AccountID);
320 //col0.SetText( wxString::Format(wxT("%i"),i) );
321 //col0.SetText(preferences.accounts.GetAccountName(i));
323 long itemindex = lstAccounts->InsertItem( col0 );
325 //AccType = preferences.accounts.GetAccountType(i);
328 lstAccounts->SetItem(itemindex, 1, preferences->accounts.GetAccountName(i));
329 lstAccounts->SetItem(itemindex, 2, preferences->accounts.GetAccountType(i));
330 //lstAccounts->SetItem(itemindex, 3, AccType);
336 void frmPreferences::SetupPointers(bool *ReloadAccountInc){
338 ReloadAccountConfig = ReloadAccountInc;
342 void frmPreferences::SavePreferences(wxCommandEvent &event){
344 // Load up the preferences file.
346 wxString SetFilename = GetSettingsFile();
348 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
350 // Update the settings file.
352 cfgfile->DeleteEntry(wxT("SaveWindowPosition"));
353 cfgfile->DeleteEntry(wxT("WindowPositionX"));
354 cfgfile->DeleteEntry(wxT("WindowPositionY"));
355 cfgfile->DeleteEntry(wxT("WindowPositionHeight"));
356 cfgfile->DeleteEntry(wxT("WindowPositionWidth"));
358 if (chkSaveWindowPosition->GetValue() == TRUE){
360 cfgfile->Write(wxT("SaveWindowPosition"), wxT("true"));
362 // Get parent window details.
364 frmMain *frmMainPtr = (frmMain*)this->GetParent();
366 // Get main window position data and save it.
368 wxRect frmMainPos = frmMainPtr->GetRect();
370 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
371 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
372 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
373 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
377 cfgfile->Write(wxT("SaveWindowPosition"), wxT("false"));
381 cfgfile->DeleteEntry(wxT("HideLocalAddressBooks"));
383 if (chkHideLocal->GetValue() == TRUE){
385 cfgfile->Write(wxT("HideLocalAddressBooks"), wxT("true"));
386 *ReloadAccountConfig = TRUE;
390 cfgfile->Write(wxT("HideLocalAddressBooks"), wxT("false"));
391 *ReloadAccountConfig = TRUE;