Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
forms: Forms updated
[xestiacalendar/.git] / source / forms / preferences / frmPreferences.cpp
1 #include "frmPreferences.h"
3 frmPreferences::frmPreferences( wxWindow* parent )
4 :
5 frmPreferencesADT( parent )
6 {
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);
13         wxIcon wxIAccNIcon;
14         wxIAccNIcon.CopyFromBitmap(AccNIcon);
15         
16         wxImage icons_accunsupported_png(cstream, wxBITMAP_TYPE_PNG);
17         wxBitmap AccUIcon(icons_accunsupported_png, -1);
18         wxIcon wxIAccUIcon;
19         wxIAccUIcon.CopyFromBitmap(AccUIcon);
20         
21         AccountID = AccImgList->Add(wxIAccNIcon);
22         AccountUnsupportedID = AccImgList->Add(wxIAccUIcon);
24         NbtPreferences->RemovePage(1);
25         btnAccountAdd->Show(false);
26         
27 }
29 void frmPreferences::LoadPreferences( wxInitDialogEvent& event )
30 {
31         
32         // Setup the preferences filename string. Default is the
33         // *nix systems one (/home/$USER/.xestiacal/preferences)
34     
35         preffilename = GetUserPrefDir();
37         preferences = new XCALPreferences(preffilename);
38   
39         // Setup the General Tab.
40     
41         bool SaveWindowPos = preferences->GetBoolData(wxT("SaveWindowPosition"));
42         bool HideLocalABs = preferences->GetBoolData(wxT("HideLocalCalendars"));
43     
44         if (SaveWindowPos == TRUE){
45     
46                 chkSaveWindowPosition->SetValue(TRUE);
47     
48         }
49     
50         if (HideLocalABs == TRUE){
51     
52                 chkHideLocal->SetValue(TRUE);
53     
54         }
55     
56         // Setup the Themes tab.
58         wxListItem themecol0;
59     
60         themecol0.SetId(0);
61         themecol0.SetWidth(250);
62         themecol0.SetText(_("Theme"));
63         lstThemes->InsertColumn(0,themecol0);
64     
65         // Setup the Accounts tab.
66     
67         ReloadAccounts();
68         
69 }
71 frmPreferences::~frmPreferences(){
72         
73         // Destory the preferences window.
74         
75         delete AccImgList;
76         AccImgList = NULL;
77         
78 }
80 void frmPreferences::ReloadAccounts(){
82         // Reload the accounts in the accounts list.
83         
84         if (FirstLoad == FALSE){
85                 delete preferences;
86                 preferences = NULL;
87                 preferences = new XCALPreferences(preffilename);
88         } else {
89                 FirstLoad = FALSE;
90         }
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);
110     
111         wxString AccType;
112     
113         for (int i = 0; i < preferences->accounts.GetCount() ; i++){
115                 wxListItem col0;
116                 col0.SetId(i);
117                 
118                 /* if (preferences->accounts.GetAccountType(i) == wxT("CalDAV")){
119         
120                         col0.SetImage(AccountNetID);
121         
122                 } else  */
123                 
124                 if (preferences->accounts.GetAccountType(i) == wxT("Local")){
125         
126                         col0.SetImage(AccountID);
127         
128                 } else {
130                         col0.SetImage(AccountUnsupportedID);
131                         
132                 }
133         
134                 long itemindex = lstAccounts->InsertItem( col0 );
135         
136                 lstAccounts->SetItem(itemindex, 1, preferences->accounts.GetAccountName(i));
137                 lstAccounts->SetItem(itemindex, 2, preferences->accounts.GetAccountType(i));
138                 lstAccounts->SetItemData(itemindex, i);
139         
140         }
141     
144 void frmPreferences::DisableButtons( wxListEvent& event )
146         
147         // Disable the account buttons.
148         
149         btnAccountModify->Enable(FALSE);
150         btnAccountDelete->Enable(FALSE);
151         
154 void frmPreferences::EnableButtons( wxListEvent& event )
156         
157         // Enable the account buttons.
158         
159         btnAccountModify->Enable(TRUE);
160         btnAccountDelete->Enable(TRUE);
161         
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.
175     
176         long lstAccountsIndex = -1;
177         wxString AccFilename = GetAccountsFile();
178         wxString AccName;
179         wxString AccType;
180     
181         wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
182         
183         // Get the account name.
184     
185         lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
186                 wxLIST_NEXT_ALL,
187                 wxLIST_STATE_SELECTED);
188         
189         // Check that the account type is a supported account type.
190         
191         AccType = preferences->accounts.GetAccountType((int)lstAccountsIndex);
192         
193         if (AccType != "CardDAV" && AccType != "carddav" &&
194                 AccType != "Local" && AccType != "local"){
195         
196                 wxMessageBox(_("Cannot modify the selected account settings as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
197                 return;
198                         
199         }
200     
201         AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
202     
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;
212         delete cfgfile;
213         cfgfile = NULL;
215         if (DialogResult == false){
216                 return;
217         }
219         // Reload the account list in the preferences window.
221         ReloadAccounts();
222         *ReloadAccountConfig = TRUE;
223         btnAccountModify->Enable(FALSE);
224         btnAccountDelete->Enable(FALSE);
225         
228 void frmPreferences::DeleteAccount( wxCommandEvent& event )
230         
231         // Display a confirmation dialog to confirm deletion.
232     
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);
235     
236         if (dlgdel.ShowModal() == wxID_YES){
237                 
238                 // Remove the selected item from the accounts list
239                 // and mark in the accounts list as deleted (Don't write to
240                 // accounts file).
241         
242                 lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
243                         wxLIST_NEXT_ALL,
244                         wxLIST_STATE_SELECTED);
245         
246                 bool ContinueAcc = TRUE;
247                 wxString AccountDir;
248                 wxString AccountType;
249                 wxString AccountDirFull;
250                 wxString AccountDirDelFull;
251                 wxString AccountName;
252                 wxString AccName;
253                 long itemindex = 0;
254         
255                 wxString AccFilename = GetAccountsFile();
256     
257                 wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
258         
259                 AccName = preferences->accounts.GetAccountName((int)lstAccounts->GetItemData(lstAccountsIndex));
260         
261                 // Get the account directory name and account type..
262         
263                 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
264         
265                 while (ContinueAcc){
267                         if (AccountName == AccName){
269                                 cfgfile->SetPath(AccountName);
270                         
271                                 cfgfile->Read("accountdir", &AccountDir);
272                                 cfgfile->Read("type", &AccountType);
273                 
274                                 break;
276                         }
277                 
278                         cfgfile->SetPath(wxT("/"));
279                         ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
280         
281                 }
282         
283                 AccountDirFull.Append(AccountDir);
284                 AccountDirFull.Append(wxT("."));
285         
286                 /*if (AccountType == wxT("CalDAV")){
287         
288                         AccountDirFull.Append(wxT("local"));
289         
290                 } else */
291                 
292                 if (AccountType == wxT("Local")){
293         
294                         AccountDirFull.Append(wxT("Local"));
295         
296                 }/*else {
297                         
298                         AccountDirFull.Append(AccountType.Lower());
299                         
300                 }*/
301         
302                 lstAccounts->DeleteItem(lstAccountsIndex);
303         
304                 // Delete the directory that contains the account information.
305         
306                 if (!AccountDirFull.IsEmpty()){
307         
308                         AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME")));
309                         AccountDirDelFull.Append(wxT("/.xestiacal/accounts/"));
310                         AccountDirDelFull.Append(AccountDirFull);
311         
312                         wxRmDir(AccountDirDelFull);
313         
314                 }
315         
316                 // Delete the account from the configuration file.
317         
318                 cfgfile->SetPath(wxT("/"));
319                 cfgfile->DeleteGroup(AccountName);
320                 cfgfile->Flush();
321         
322                 // Set flag for reloading accounts on window closure.
323     
324                 *ReloadAccountConfig = TRUE;
325     
326         }
328         btnAccountModify->Enable(FALSE);
329         btnAccountDelete->Enable(FALSE);
330         
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.
343                 
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"));
349         
350         if (chkSaveWindowPosition->GetValue() == TRUE){
351         
352                 cfgfile->Write(wxT("SaveWindowPosition"), wxT("true"));
353         
354                 // Get parent window details.
355                 
356                 frmMain *frmMainPtr = (frmMain*)this->GetParent();
358                 // Get main window position data and save it.
359         
360                 wxRect frmMainPos = frmMainPtr->GetRect();
361         
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());
367         } else {
368         
369                 cfgfile->Write(wxT("SaveWindowPosition"), wxT("false"));
370         
371         }
372         
373         cfgfile->DeleteEntry(wxT("HideLocalCalendars"));
374         
375         if (chkHideLocal->GetValue() == TRUE){
377                 cfgfile->Write(wxT("HideLocalCalendars"), wxT("true"));
378                 *ReloadAccountConfig = TRUE;
379         
380         } else {
381         
382                 cfgfile->Write(wxT("HideLocalCalendars"), wxT("false"));
383                 *ReloadAccountConfig = TRUE;
384         
385         }
387         delete cfgfile;
388         cfgfile = NULL;
390         this->Close();
391         
394 void frmPreferences::CloseWindow( wxCommandEvent& event )
396         
397         // Close the preferences window.
398         
399         this->Close();
400         
403 void frmPreferences::SetupPointers(bool *ReloadAccountInc){
405         // Setup the pointers for the preferences form.
406         
407         ReloadAccountConfig = ReloadAccountInc;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy