Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added support for saving REV, XML, CLIENTPIDMAP and SOURCE properties.
[xestiaab/.git] / source / frmPreferences.cpp
1 // frmPreferences.cpp - Preferences form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmPreferences.h"
20 #include "frmEditAccount.h"     
21 #include "frmNewAccount.h"
22 #include "frmMain.h"
23 #include "common/preferences.h"
24 #include "common/dirs.h"
25 #include "bitmaps.h"
27 #include "import/import.h"
28 #include "export/export.h"
30 #include <wx/wx.h>
31 #include <wx/mstream.h>
32 #include <wx/dialog.h>
33 #include <wx/msgdlg.h>
34 #include <wx/fileconf.h>
37 frmPreferences::frmPreferences( wxWindow* parent )
38 :
39 frmPreferencesADT( parent )
40 {
42         wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
43         wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
44         
45         wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
46         wxBitmap AccInet(icons_accinet_png, -1);
47         wxIcon wxIAccInet;
48         wxIAccInet.CopyFromBitmap(AccInet);
50         wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
51         wxBitmap AccNIcon(icons_acclocal_png, -1);
52         wxIcon wxIAccNIcon;
53         wxIAccNIcon.CopyFromBitmap(AccNIcon);
54         
55         AccountID = AccImgList->Add(wxIAccNIcon);
56         AccountNetID = AccImgList->Add(wxIAccInet);
58         NbtPreferences->RemovePage(1);
60 }
62 frmPreferences::~frmPreferences(){
64         delete AccImgList;
65         AccImgList = NULL;
67 }
69 void frmPreferences::EnableABButtons( wxListEvent& event )
70 {
71     btnAccountModify->Enable(TRUE);
72     btnAccountDelete->Enable(TRUE);    
73 }
75 void frmPreferences::DisableABButtons( wxListEvent& event )
76 {
77     btnAccountModify->Enable(FALSE);
78     btnAccountDelete->Enable(FALSE);    
79 }
81 void frmPreferences::AddABAccount(wxCommandEvent& event)
82 {
84         bool ReloadAccountsData = FALSE;
86         frmNewAccount *frameNewAccount = new frmNewAccount(this);
87         frameNewAccount->SetupPointers(&ReloadAccountsData);
88         frameNewAccount->ShowModal();
89         delete frameNewAccount;
90         frameNewAccount = NULL;
92         if (ReloadAccountsData == TRUE){
94                 // Reload the accounts as a change has been made within
95                 // the application.
97                 ReloadAccounts();
98                 *ReloadAccountConfig = TRUE;
100         }
104 void frmPreferences::ModifyABAccount( wxCommandEvent& event )
107     // Get the settings for the account, setup the form for
108     // editing the account and then display the window
109     // with the settings.
110     
111     long lstAccountsIndex = -1;
112     wxString AccFilename = GetAccountsFile();
113     wxString AccName;
114     
115     wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
116     
117     // Get the account name.
118     
119     lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
120                                 wxLIST_NEXT_ALL,
121                                 wxLIST_STATE_SELECTED);
122     
123     AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
124     
125     frmEditAccount *frameEditAccount = new frmEditAccount ( this );
126     frameEditAccount->LoadPointers(cfgfile);
127     frameEditAccount->LoadSettings(AccName);
128     frameEditAccount->ShowModal();
130     delete frameEditAccount;
131     frameEditAccount = NULL;
132     delete cfgfile;
133     cfgfile = NULL;
135     // Reload the account list in the preferences window.
137     ReloadAccounts();
138     *ReloadAccountConfig = TRUE;
142 void frmPreferences::DeleteABAccount( wxCommandEvent& event )
144     // Display a confirmation dialog to confirm deletion.
145     
146     long lstAccountsIndex = -1;
147     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);
148     
149     if (dlgdel.ShowModal() == wxID_YES){
150         // Remove the selected item from the accounts list
151         // and mark in the accounts list as deleted (Don't write to
152         // accounts file).
153         
154         lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
155                                          wxLIST_NEXT_ALL,
156                                          wxLIST_STATE_SELECTED);
157         
158         bool ContinueAcc = TRUE;
159         wxString AccountDir;
160         wxString AccountType;
161         wxString AccountDirFull;
162         wxString AccountDirDelFull;
163         wxString AccountName;
164         wxString AccName;
165         long itemindex = 0;
166         
167         wxString AccFilename = GetAccountsFile();
168     
169         wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
170         
171         AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
172         
173         // Get the account directory name and account type..
174         
175         ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
176         
177         while (ContinueAcc){
179                 if (AccountName == AccName){
181                         cfgfile->SetPath(AccountName);
182                         
183                         cfgfile->Read("accountdir", &AccountDir);
184                         cfgfile->Read("type", &AccountType);
185                 
186                         break;
188                 }
189                 
190                 cfgfile->SetPath(wxT("/"));
191                 ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
193         }
194         
195         AccountDirFull.Append(AccountDir);
196         AccountDirFull.Append(wxT("."));
197         
198         if (AccountType == wxT("CardDAV")){
199         
200                 AccountDirFull.Append(wxT("local"));
201         
202         } else if (AccountType == wxT("Local")){
203         
204                 AccountDirFull.Append(wxT("carddav"));
205         
206         }
207         
208         lstAccounts->DeleteItem(lstAccountsIndex);
209         
210         // Delete the directory that contains the account information.
211         
212         if (!AccountDirFull.IsEmpty()){
213         
214                 AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME")));
215                 AccountDirDelFull.Append(wxT("/.xestiaab/accounts/"));
216                 AccountDirDelFull.Append(AccountDirFull);
217         
218                 wxRmDir(AccountDirDelFull);
219         
220         }
221         
222         // Delete the account from the configuration file.
223         
224         cfgfile->SetPath(wxT("/"));
225         cfgfile->DeleteGroup(AccountName);
226         cfgfile->Flush();
227         
228         // Set flag for reloading accounts on window closure.
229     
230         *ReloadAccountConfig = TRUE;
231     
232     }
236 void frmPreferences::LoadPreferences( wxInitDialogEvent& event )
239 // Setup the preferences filename string. Default is the
240 // *nix systems one (/home/$USER/.xestiaab/preferences)
241     
242         preffilename = GetUserPrefDir();
244     preferences = new XABPreferences(preffilename);
245   
246     // Setup the General Tab.
247     
248     bool SaveWindowPos = preferences->GetBoolData(wxT("SaveWindowPosition"));
249     bool HideLocalABs = preferences->GetBoolData(wxT("HideLocalAddressBooks"));
250     
251     if (SaveWindowPos == TRUE){
252     
253         chkSaveWindowPosition->SetValue(TRUE);
254     
255     }
256     
257     if (HideLocalABs == TRUE){
258     
259         chkHideLocal->SetValue(TRUE);
260     
261     }
262     
263     // Setup the Themes tab.
265     wxListItem themecol0;
266     
267     themecol0.SetId(0);
268     themecol0.SetWidth(250);
269     themecol0.SetText(_("Theme"));
270     lstThemes->InsertColumn(0,themecol0);
271     
272     // Setup the Accounts tab.
273     
274     ReloadAccounts();   
275     
278 void frmPreferences::ReloadAccounts(){
280     if (FirstLoad == FALSE){
281         delete preferences;
282         preferences = NULL;
283         preferences = new XABPreferences(preffilename);    
284     } else {
285         FirstLoad = FALSE;
286     }
288     wxListItem accountscol0, accountscol1, accountscol2, accountscol3;
290     lstAccounts->ClearAll();
292     accountscol0.SetId(0);
293     accountscol0.SetWidth(24);
294     lstAccounts->InsertColumn(0,accountscol0);
295     lstAccounts->SetImageList(AccImgList, wxIMAGE_LIST_SMALL);
297     accountscol1.SetId(1);
298     accountscol1.SetText(_("Name"));
299     accountscol1.SetWidth(224);    
300     lstAccounts->InsertColumn(1,accountscol1);   
302     accountscol2.SetId(2);
303     accountscol2.SetText(_("Type"));
304     accountscol2.SetWidth(96);
305     lstAccounts->InsertColumn(2,accountscol2);
306     
307     /*accountscol1.SetId(1);
308     accountscol1.SetText(_(""));
309     accountscol1.SetWidth(32);
310     lstAccounts->InsertColumn(1,accountscol1);
311     
312     accountscol2.SetId(2);
313     accountscol2.SetText(_("Name"));
314     accountscol2.SetWidth(224);    
315     lstAccounts->InsertColumn(2,accountscol2);
316     
317     accountscol3.SetId(3);
318     accountscol3.SetText(_("Type"));
319     accountscol3.SetWidth(96);
320     lstAccounts->InsertColumn(3,accountscol3);*/
321     
322     wxString AccType;
323     
324     for (int i = 0; i < preferences->accounts.GetCount() ; i++){
326         wxListItem col0;
327         col0.SetId(i);
328         if (preferences->accounts.GetAccountType(i) == wxT("CardDAV")){
329         
330                 col0.SetImage(AccountNetID);
331         
332         } else if (preferences->accounts.GetAccountType(i) == wxT("Local")){
333         
334                 col0.SetImage(AccountID);
335         
336         }
337     
338         //col0.SetText( wxString::Format(wxT("%i"),i) );
339         //col0.SetText(preferences.accounts.GetAccountName(i));
340         
341         long itemindex = lstAccounts->InsertItem( col0 );
342         
343         //AccType = preferences.accounts.GetAccountType(i);
344         //AccType.Trim();
345         
346         lstAccounts->SetItem(itemindex, 1, preferences->accounts.GetAccountName(i));
347         lstAccounts->SetItem(itemindex, 2, preferences->accounts.GetAccountType(i));
348         //lstAccounts->SetItem(itemindex, 3, AccType);
349         
350     }
351     
354 void frmPreferences::SetupPointers(bool *ReloadAccountInc){
356         ReloadAccountConfig = ReloadAccountInc;
360 void frmPreferences::SavePreferences(wxCommandEvent &event){
362         // Load up the preferences file.
364         wxString SetFilename = GetSettingsFile();
366         wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
368         // Update the settings file.
369                 
370         cfgfile->DeleteEntry(wxT("SaveWindowPosition"));
371         cfgfile->DeleteEntry(wxT("WindowPositionX"));
372         cfgfile->DeleteEntry(wxT("WindowPositionY"));
373         cfgfile->DeleteEntry(wxT("WindowPositionHeight"));
374         cfgfile->DeleteEntry(wxT("WindowPositionWidth"));
375         
376         if (chkSaveWindowPosition->GetValue() == TRUE){
377         
378                 cfgfile->Write(wxT("SaveWindowPosition"), wxT("true"));
379         
380                 // Get parent window details.
381                 
382                 frmMain *frmMainPtr = (frmMain*)this->GetParent();
384                 // Get main window position data and save it.
385         
386                 wxRect frmMainPos = frmMainPtr->GetRect();
387         
388                 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
389                 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
390                 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
391                 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
393         } else {
394         
395                 cfgfile->Write(wxT("SaveWindowPosition"), wxT("false"));
396         
397         }
398         
399         cfgfile->DeleteEntry(wxT("HideLocalAddressBooks"));
400         
401         if (chkHideLocal->GetValue() == TRUE){
403                 cfgfile->Write(wxT("HideLocalAddressBooks"), wxT("true"));
404                 *ReloadAccountConfig = TRUE;
405         
406         } else {
407         
408                 cfgfile->Write(wxT("HideLocalAddressBooks"), wxT("false"));
409                 *ReloadAccountConfig = TRUE;
410         
411         }
413         delete cfgfile;
414         cfgfile = NULL;
416         this->Close();
420 void frmPreferences::CloseWindow(wxCommandEvent &event){
422         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