Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented search mode support using the -s/--search switch on the command line.
[xestiaab/.git] / source / frmPreferences.cpp
1 #include "frmPreferences.h"
2 #include "frmEditAccount.h"     
3 #include "frmNewAccount.h"
4 #include "frmMain.h"
5 #include "common/preferences.h"
6 #include "common/dirs.h"
7 #include "bitmaps.h"
9 #include "import/import.h"
10 #include "export/export.h"
12 #include <wx/wx.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 )
20 :
21 frmPreferencesADT( parent )
22 {
24         wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
25         wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
26         
27         wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
28         wxBitmap AccInet(icons_accinet_png, -1);
29         wxIcon wxIAccInet;
30         wxIAccInet.CopyFromBitmap(AccInet);
32         wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
33         wxBitmap AccNIcon(icons_acclocal_png, -1);
34         wxIcon wxIAccNIcon;
35         wxIAccNIcon.CopyFromBitmap(AccNIcon);
36         
37         AccountID = AccImgList->Add(wxIAccNIcon);
38         AccountNetID = AccImgList->Add(wxIAccInet);
40         NbtPreferences->RemovePage(1);
42 }
44 frmPreferences::~frmPreferences(){
46         delete AccImgList;
47         AccImgList = NULL;
49 }
51 void frmPreferences::EnableABButtons( wxListEvent& event )
52 {
53     btnAccountModify->Enable(TRUE);
54     btnAccountDelete->Enable(TRUE);    
55 }
57 void frmPreferences::DisableABButtons( wxListEvent& event )
58 {
59     btnAccountModify->Enable(FALSE);
60     btnAccountDelete->Enable(FALSE);    
61 }
63 void frmPreferences::AddABAccount(wxCommandEvent& event)
64 {
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
77                 // the application.
79                 ReloadAccounts();
80                 *ReloadAccountConfig = TRUE;
82         }
84 }
86 void frmPreferences::ModifyABAccount( wxCommandEvent& event )
87 {
89     // Get the settings for the account, setup the form for
90     // editing the account and then display the window
91     // with the settings.
92     
93     long lstAccountsIndex = -1;
94     wxString AccFilename = GetAccountsFile();
95     wxString AccName;
96     
97     wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
98     
99     // Get the account name.
100     
101     lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
102                                 wxLIST_NEXT_ALL,
103                                 wxLIST_STATE_SELECTED);
104     
105     AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
106     
107     frmEditAccount *frameEditAccount = new frmEditAccount ( this );
108     frameEditAccount->LoadPointers(cfgfile);
109     frameEditAccount->LoadSettings(AccName);
110     frameEditAccount->ShowModal();
112     delete frameEditAccount;
113     frameEditAccount = NULL;
114     delete cfgfile;
115     cfgfile = NULL;
117     // Reload the account list in the preferences window.
119     ReloadAccounts();
120     *ReloadAccountConfig = TRUE;
124 void frmPreferences::DeleteABAccount( wxCommandEvent& event )
126     // Display a confirmation dialog to confirm deletion.
127     
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);
130     
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
134         // accounts file).
135         
136         lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
137                                          wxLIST_NEXT_ALL,
138                                          wxLIST_STATE_SELECTED);
139         
140         bool ContinueAcc = TRUE;
141         wxString AccountDir;
142         wxString AccountType;
143         wxString AccountDirFull;
144         wxString AccountDirDelFull;
145         wxString AccountName;
146         wxString AccName;
147         long itemindex = 0;
148         
149         wxString AccFilename = GetAccountsFile();
150     
151         wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
152         
153         AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
154         
155         // Get the account directory name and account type..
156         
157         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
158         
159         while (ContinueAcc){
161                 if (AccountName == AccName){
163                         cfgfile->SetPath(AccountName);
164                         
165                         cfgfile->Read("accountdir", &AccountDir);
166                         cfgfile->Read("type", &AccountType);
167                 
168                         break;
170                 }
171                 
172                 cfgfile->SetPath(wxT("/"));
173                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
175         }
176         
177         AccountDirFull.Append(AccountDir);
178         AccountDirFull.Append(wxT("."));
179         
180         if (AccountType == wxT("CardDAV")){
181         
182                 AccountDirFull.Append(wxT("local"));
183         
184         } else if (AccountType == wxT("Local")){
185         
186                 AccountDirFull.Append(wxT("carddav"));
187         
188         }
189         
190         lstAccounts->DeleteItem(lstAccountsIndex);
191         
192         // Delete the directory that contains the account information.
193         
194         if (!AccountDirFull.IsEmpty()){
195         
196                 AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME")));
197                 AccountDirDelFull.Append(wxT("/.xestiaab/accounts/"));
198                 AccountDirDelFull.Append(AccountDirFull);
199         
200                 wxRmDir(AccountDirDelFull);
201         
202         }
203         
204         // Delete the account from the configuration file.
205         
206         cfgfile->SetPath(wxT("/"));
207         cfgfile->DeleteGroup(AccountName);
208         cfgfile->Flush();
209         
210         // Set flag for reloading accounts on window closure.
211     
212         *ReloadAccountConfig = TRUE;
213     
214     }
218 void frmPreferences::LoadPreferences( wxInitDialogEvent& event )
221 // Setup the preferences filename string. Default is the
222 // *nix systems one (/home/$USER/.xestiaab/preferences)
223     
224         preffilename = GetUserPrefDir();
226     preferences = new XABPreferences(preffilename);
227   
228     // Setup the General Tab.
229     
230     bool SaveWindowPos = preferences->GetBoolData(wxT("SaveWindowPosition"));
231     bool HideLocalABs = preferences->GetBoolData(wxT("HideLocalAddressBooks"));
232     
233     if (SaveWindowPos == TRUE){
234     
235         chkSaveWindowPosition->SetValue(TRUE);
236     
237     }
238     
239     if (HideLocalABs == TRUE){
240     
241         chkHideLocal->SetValue(TRUE);
242     
243     }
244     
245     // Setup the Themes tab.
247     wxListItem themecol0;
248     
249     themecol0.SetId(0);
250     themecol0.SetWidth(250);
251     themecol0.SetText(_("Theme"));
252     lstThemes->InsertColumn(0,themecol0);
253     
254     // Setup the Accounts tab.
255     
256     ReloadAccounts();   
257     
260 void frmPreferences::ReloadAccounts(){
262     if (FirstLoad == FALSE){
263         delete preferences;
264         preferences = NULL;
265         preferences = new XABPreferences(preffilename);    
266     } else {
267         FirstLoad = FALSE;
268     }
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);
288     
289     /*accountscol1.SetId(1);
290     accountscol1.SetText(_(""));
291     accountscol1.SetWidth(32);
292     lstAccounts->InsertColumn(1,accountscol1);
293     
294     accountscol2.SetId(2);
295     accountscol2.SetText(_("Name"));
296     accountscol2.SetWidth(224);    
297     lstAccounts->InsertColumn(2,accountscol2);
298     
299     accountscol3.SetId(3);
300     accountscol3.SetText(_("Type"));
301     accountscol3.SetWidth(96);
302     lstAccounts->InsertColumn(3,accountscol3);*/
303     
304     wxString AccType;
305     
306     for (int i = 0; i < preferences->accounts.GetCount() ; i++){
308         wxListItem col0;
309         col0.SetId(i);
310         if (preferences->accounts.GetAccountType(i) == wxT("CardDAV")){
311         
312                 col0.SetImage(AccountNetID);
313         
314         } else if (preferences->accounts.GetAccountType(i) == wxT("Local")){
315         
316                 col0.SetImage(AccountID);
317         
318         }
319     
320         //col0.SetText( wxString::Format(wxT("%i"),i) );
321         //col0.SetText(preferences.accounts.GetAccountName(i));
322         
323         long itemindex = lstAccounts->InsertItem( col0 );
324         
325         //AccType = preferences.accounts.GetAccountType(i);
326         //AccType.Trim();
327         
328         lstAccounts->SetItem(itemindex, 1, preferences->accounts.GetAccountName(i));
329         lstAccounts->SetItem(itemindex, 2, preferences->accounts.GetAccountType(i));
330         //lstAccounts->SetItem(itemindex, 3, AccType);
331         
332     }
333     
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.
351                 
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"));
357         
358         if (chkSaveWindowPosition->GetValue() == TRUE){
359         
360                 cfgfile->Write(wxT("SaveWindowPosition"), wxT("true"));
361         
362                 // Get parent window details.
363                 
364                 frmMain *frmMainPtr = (frmMain*)this->GetParent();
366                 // Get main window position data and save it.
367         
368                 wxRect frmMainPos = frmMainPtr->GetRect();
369         
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());
375         } else {
376         
377                 cfgfile->Write(wxT("SaveWindowPosition"), wxT("false"));
378         
379         }
380         
381         cfgfile->DeleteEntry(wxT("HideLocalAddressBooks"));
382         
383         if (chkHideLocal->GetValue() == TRUE){
385                 cfgfile->Write(wxT("HideLocalAddressBooks"), wxT("true"));
386                 *ReloadAccountConfig = TRUE;
387         
388         } else {
389         
390                 cfgfile->Write(wxT("HideLocalAddressBooks"), wxT("false"));
391                 *ReloadAccountConfig = TRUE;
392         
393         }
395         delete cfgfile;
396         cfgfile = NULL;
398         this->Close();
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