1 #include "frmPreferences.h"
3 frmPreferences::frmPreferences( wxWindow* parent )
5 frmPreferencesADT( parent )
8 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
9 wxMemoryInputStream cstream(icons_accunsupported_png, sizeof(icons_accunsupported_png));
11 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
12 wxBitmap AccNIcon(icons_acclocal_png, -1);
14 wxIAccNIcon.CopyFromBitmap(AccNIcon);
16 wxImage icons_accunsupported_png(cstream, wxBITMAP_TYPE_PNG);
17 wxBitmap AccUIcon(icons_accunsupported_png, -1);
19 wxIAccUIcon.CopyFromBitmap(AccUIcon);
21 AccountID = AccImgList->Add(wxIAccNIcon);
22 AccountUnsupportedID = AccImgList->Add(wxIAccUIcon);
24 NbtPreferences->RemovePage(1);
25 btnAccountAdd->Show(false);
29 void frmPreferences::LoadPreferences( wxInitDialogEvent& event )
32 // Setup the preferences filename string. Default is the
33 // *nix systems one (/home/$USER/.xestiacal/preferences)
35 preffilename = GetUserPrefDir();
37 preferences = new XCALPreferences(preffilename);
39 // Setup the General Tab.
41 bool SaveWindowPos = preferences->GetBoolData(wxT("SaveWindowPosition"));
42 bool HideLocalABs = preferences->GetBoolData(wxT("HideLocalCalendars"));
44 if (SaveWindowPos == TRUE){
46 chkSaveWindowPosition->SetValue(TRUE);
50 if (HideLocalABs == TRUE){
52 chkHideLocal->SetValue(TRUE);
56 // Setup the Themes tab.
61 themecol0.SetWidth(250);
62 themecol0.SetText(_("Theme"));
63 lstThemes->InsertColumn(0,themecol0);
65 // Setup the Accounts tab.
71 frmPreferences::~frmPreferences(){
73 // Destory the preferences window.
80 void frmPreferences::ReloadAccounts(){
82 // Reload the accounts in the accounts list.
84 if (FirstLoad == FALSE){
87 preferences = new XCALPreferences(preffilename);
92 wxListItem accountscol0, accountscol1, accountscol2, accountscol3;
94 lstAccounts->ClearAll();
96 accountscol0.SetId(0);
97 accountscol0.SetWidth(24);
98 lstAccounts->InsertColumn(0,accountscol0);
99 lstAccounts->SetImageList(AccImgList, wxIMAGE_LIST_SMALL);
101 accountscol1.SetId(1);
102 accountscol1.SetText(_("Name"));
103 accountscol1.SetWidth(224);
104 lstAccounts->InsertColumn(1,accountscol1);
106 accountscol2.SetId(2);
107 accountscol2.SetText(_("Type"));
108 accountscol2.SetWidth(96);
109 lstAccounts->InsertColumn(2,accountscol2);
113 for (int i = 0; i < preferences->accounts.GetCount() ; i++){
118 /* if (preferences->accounts.GetAccountType(i) == wxT("CalDAV")){
120 col0.SetImage(AccountNetID);
124 if (preferences->accounts.GetAccountType(i) == wxT("Local")){
126 col0.SetImage(AccountID);
130 col0.SetImage(AccountUnsupportedID);
134 long itemindex = lstAccounts->InsertItem( col0 );
136 lstAccounts->SetItem(itemindex, 1, preferences->accounts.GetAccountName(i));
137 lstAccounts->SetItem(itemindex, 2, preferences->accounts.GetAccountType(i));
138 lstAccounts->SetItemData(itemindex, i);
144 void frmPreferences::DisableButtons( wxListEvent& event )
147 // Disable the account buttons.
149 btnAccountModify->Enable(FALSE);
150 btnAccountDelete->Enable(FALSE);
154 void frmPreferences::EnableButtons( wxListEvent& event )
157 // Enable the account buttons.
159 btnAccountModify->Enable(TRUE);
160 btnAccountDelete->Enable(TRUE);
164 void frmPreferences::AddAccount( wxCommandEvent& event )
166 // TODO: Implement AddABAccount
169 void frmPreferences::ModifyAccount( wxCommandEvent& event )
172 // Get the settings for the account, setup the form for
173 // editing the account and then display the window
174 // with the settings.
176 long lstAccountsIndex = -1;
177 wxString AccFilename = GetAccountsFile();
181 wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
183 // Get the account name.
185 lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
187 wxLIST_STATE_SELECTED);
189 // Check that the account type is a supported account type.
191 AccType = preferences->accounts.GetAccountType((int)lstAccountsIndex);
193 if (AccType != "CardDAV" && AccType != "carddav" &&
194 AccType != "Local" && AccType != "local"){
196 wxMessageBox(_("Cannot modify the selected account settings as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
201 AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
203 frmEditAccount *frameEditAccount = new frmEditAccount ( this );
204 frameEditAccount->LoadPointers(cfgfile);
205 frameEditAccount->LoadSettings(AccName);
206 frameEditAccount->ShowModal();
208 bool DialogResult = frameEditAccount->GetDialogResult();
210 delete frameEditAccount;
211 frameEditAccount = NULL;
215 if (DialogResult == false){
219 // Reload the account list in the preferences window.
222 *ReloadAccountConfig = TRUE;
223 btnAccountModify->Enable(FALSE);
224 btnAccountDelete->Enable(FALSE);
228 void frmPreferences::DeleteAccount( wxCommandEvent& event )
231 // Display a confirmation dialog to confirm deletion.
233 long lstAccountsIndex = -1;
234 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);
236 if (dlgdel.ShowModal() == wxID_YES){
238 // Remove the selected item from the accounts list
239 // and mark in the accounts list as deleted (Don't write to
242 lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
244 wxLIST_STATE_SELECTED);
246 bool ContinueAcc = TRUE;
248 wxString AccountType;
249 wxString AccountDirFull;
250 wxString AccountDirDelFull;
251 wxString AccountName;
255 wxString AccFilename = GetAccountsFile();
257 wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
259 AccName = preferences->accounts.GetAccountName((int)lstAccounts->GetItemData(lstAccountsIndex));
261 // Get the account directory name and account type..
263 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
267 if (AccountName == AccName){
269 cfgfile->SetPath(AccountName);
271 cfgfile->Read("accountdir", &AccountDir);
272 cfgfile->Read("type", &AccountType);
278 cfgfile->SetPath(wxT("/"));
279 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
283 AccountDirFull.Append(AccountDir);
284 AccountDirFull.Append(wxT("."));
286 /*if (AccountType == wxT("CalDAV")){
288 AccountDirFull.Append(wxT("local"));
292 if (AccountType == wxT("Local")){
294 AccountDirFull.Append(wxT("Local"));
298 AccountDirFull.Append(AccountType.Lower());
302 lstAccounts->DeleteItem(lstAccountsIndex);
304 // Delete the directory that contains the account information.
306 if (!AccountDirFull.IsEmpty()){
308 AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME")));
309 AccountDirDelFull.Append(wxT("/.xestiacal/accounts/"));
310 AccountDirDelFull.Append(AccountDirFull);
312 wxRmDir(AccountDirDelFull);
316 // Delete the account from the configuration file.
318 cfgfile->SetPath(wxT("/"));
319 cfgfile->DeleteGroup(AccountName);
322 // Set flag for reloading accounts on window closure.
324 *ReloadAccountConfig = TRUE;
328 btnAccountModify->Enable(FALSE);
329 btnAccountDelete->Enable(FALSE);
333 void frmPreferences::SavePreferences( wxCommandEvent& event )
336 // Load up the preferences file.
338 wxString SetFilename = GetSettingsFile();
340 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
342 // Update the settings file.
344 cfgfile->DeleteEntry(wxT("SaveWindowPosition"));
345 cfgfile->DeleteEntry(wxT("WindowPositionX"));
346 cfgfile->DeleteEntry(wxT("WindowPositionY"));
347 cfgfile->DeleteEntry(wxT("WindowPositionHeight"));
348 cfgfile->DeleteEntry(wxT("WindowPositionWidth"));
350 if (chkSaveWindowPosition->GetValue() == TRUE){
352 cfgfile->Write(wxT("SaveWindowPosition"), wxT("true"));
354 // Get parent window details.
356 frmMain *frmMainPtr = (frmMain*)this->GetParent();
358 // Get main window position data and save it.
360 wxRect frmMainPos = frmMainPtr->GetRect();
362 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
363 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
364 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
365 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
369 cfgfile->Write(wxT("SaveWindowPosition"), wxT("false"));
373 cfgfile->DeleteEntry(wxT("HideLocalCalendars"));
375 if (chkHideLocal->GetValue() == TRUE){
377 cfgfile->Write(wxT("HideLocalCalendars"), wxT("true"));
378 *ReloadAccountConfig = TRUE;
382 cfgfile->Write(wxT("HideLocalCalendars"), wxT("false"));
383 *ReloadAccountConfig = TRUE;
394 void frmPreferences::CloseWindow( wxCommandEvent& event )
397 // Close the preferences window.
403 void frmPreferences::SetupPointers(bool *ReloadAccountInc){
405 // Setup the pointers for the preferences form.
407 ReloadAccountConfig = ReloadAccountInc;