Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out code from vcard/vcard34conv-v3conv.cpp
[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         // Setup the preferences window.
43         
44         wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
45         wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
46         
47         wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
48         wxBitmap AccInet(icons_accinet_png, -1);
49         wxIcon wxIAccInet;
50         wxIAccInet.CopyFromBitmap(AccInet);
52         wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
53         wxBitmap AccNIcon(icons_acclocal_png, -1);
54         wxIcon wxIAccNIcon;
55         wxIAccNIcon.CopyFromBitmap(AccNIcon);
56         
57         AccountID = AccImgList->Add(wxIAccNIcon);
58         AccountNetID = AccImgList->Add(wxIAccInet);
60         NbtPreferences->RemovePage(1);
62 }
64 frmPreferences::~frmPreferences(){
66         // Destory the preferences window.
67         
68         delete AccImgList;
69         AccImgList = NULL;
71 }
73 void frmPreferences::EnableABButtons( wxListEvent& event )
74 {
75         
76         // Enable the account buttons.
77         
78         btnAccountModify->Enable(TRUE);
79         btnAccountDelete->Enable(TRUE);
80         
81 }
83 void frmPreferences::DisableABButtons( wxListEvent& event )
84 {
85         
86         // Disable the account buttons.
87         
88         btnAccountModify->Enable(FALSE);
89         btnAccountDelete->Enable(FALSE);
90         
91 }
93 void frmPreferences::AddABAccount(wxCommandEvent& event)
94 {
96         // Add new account.
97         
98         bool ReloadAccountsData = FALSE;
100         frmNewAccount *frameNewAccount = new frmNewAccount(this);
101         frameNewAccount->SetupPointers(&ReloadAccountsData);
102         frameNewAccount->ShowModal();
103         delete frameNewAccount;
104         frameNewAccount = NULL;
106         if (ReloadAccountsData == TRUE){
108                 // Reload the accounts as a change has been made within
109                 // the application.
111                 ReloadAccounts();
112                 *ReloadAccountConfig = TRUE;
114         }
118 void frmPreferences::ModifyABAccount( wxCommandEvent& event )
121         // Get the settings for the account, setup the form for
122         // editing the account and then display the window
123         // with the settings.
124     
125         long lstAccountsIndex = -1;
126         wxString AccFilename = GetAccountsFile();
127         wxString AccName;
128     
129         wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
130     
131         // Get the account name.
132     
133         lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
134                 wxLIST_NEXT_ALL,
135                 wxLIST_STATE_SELECTED);
136     
137         AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
138     
139         frmEditAccount *frameEditAccount = new frmEditAccount ( this );
140         frameEditAccount->LoadPointers(cfgfile);
141         frameEditAccount->LoadSettings(AccName);
142         frameEditAccount->ShowModal();
144         bool DialogResult = frameEditAccount->GetDialogResult();
146         delete frameEditAccount;
147         frameEditAccount = NULL;
148         delete cfgfile;
149         cfgfile = NULL;
151         if (DialogResult == false){
152                 return;
153         }
155         // Reload the account list in the preferences window.
157         ReloadAccounts();
158         *ReloadAccountConfig = TRUE;
159         btnAccountModify->Enable(FALSE);
160         btnAccountDelete->Enable(FALSE);
161     
164 void frmPreferences::DeleteABAccount( wxCommandEvent& event )
166         // Display a confirmation dialog to confirm deletion.
167     
168         long lstAccountsIndex = -1;
169         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);
170     
171         if (dlgdel.ShowModal() == wxID_YES){
172                 
173                 // Remove the selected item from the accounts list
174                 // and mark in the accounts list as deleted (Don't write to
175                 // accounts file).
176         
177                 lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
178                         wxLIST_NEXT_ALL,
179                         wxLIST_STATE_SELECTED);
180         
181                 bool ContinueAcc = TRUE;
182                 wxString AccountDir;
183                 wxString AccountType;
184                 wxString AccountDirFull;
185                 wxString AccountDirDelFull;
186                 wxString AccountName;
187                 wxString AccName;
188                 long itemindex = 0;
189         
190                 wxString AccFilename = GetAccountsFile();
191     
192                 wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
193         
194                 AccName = preferences->accounts.GetAccountName((int)lstAccountsIndex);
195         
196                 // Get the account directory name and account type..
197         
198                 ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
199         
200                 while (ContinueAcc){
202                         if (AccountName == AccName){
204                                 cfgfile->SetPath(AccountName);
205                         
206                                 cfgfile->Read("accountdir", &AccountDir);
207                                 cfgfile->Read("type", &AccountType);
208                 
209                                 break;
211                         }
212                 
213                         cfgfile->SetPath(wxT("/"));
214                         ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
215         
216                 }
217         
218                 AccountDirFull.Append(AccountDir);
219                 AccountDirFull.Append(wxT("."));
220         
221                 if (AccountType == wxT("CardDAV")){
222         
223                         AccountDirFull.Append(wxT("local"));
224         
225                 } else if (AccountType == wxT("Local")){
226         
227                         AccountDirFull.Append(wxT("carddav"));
228         
229                 }
230         
231                 lstAccounts->DeleteItem(lstAccountsIndex);
232         
233                 // Delete the directory that contains the account information.
234         
235                 if (!AccountDirFull.IsEmpty()){
236         
237                         AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME")));
238                         AccountDirDelFull.Append(wxT("/.xestiaab/accounts/"));
239                         AccountDirDelFull.Append(AccountDirFull);
240         
241                         wxRmDir(AccountDirDelFull);
242         
243                 }
244         
245                 // Delete the account from the configuration file.
246         
247                 cfgfile->SetPath(wxT("/"));
248                 cfgfile->DeleteGroup(AccountName);
249                 cfgfile->Flush();
250         
251                 // Set flag for reloading accounts on window closure.
252     
253                 *ReloadAccountConfig = TRUE;
254     
255         }
259 void frmPreferences::LoadPreferences( wxInitDialogEvent& event )
262         // Setup the preferences filename string. Default is the
263         // *nix systems one (/home/$USER/.xestiaab/preferences)
264     
265         preffilename = GetUserPrefDir();
267         preferences = new XABPreferences(preffilename);
268   
269         // Setup the General Tab.
270     
271         bool SaveWindowPos = preferences->GetBoolData(wxT("SaveWindowPosition"));
272         bool HideLocalABs = preferences->GetBoolData(wxT("HideLocalAddressBooks"));
273     
274         if (SaveWindowPos == TRUE){
275     
276                 chkSaveWindowPosition->SetValue(TRUE);
277     
278         }
279     
280         if (HideLocalABs == TRUE){
281     
282                 chkHideLocal->SetValue(TRUE);
283     
284         }
285     
286         // Setup the Themes tab.
288         wxListItem themecol0;
289     
290         themecol0.SetId(0);
291         themecol0.SetWidth(250);
292         themecol0.SetText(_("Theme"));
293         lstThemes->InsertColumn(0,themecol0);
294     
295         // Setup the Accounts tab.
296     
297         ReloadAccounts();   
298     
301 void frmPreferences::ReloadAccounts(){
303         // Reload the accounts in the accounts list.
304         
305         if (FirstLoad == FALSE){
306                 delete preferences;
307                 preferences = NULL;
308                 preferences = new XABPreferences(preffilename);    
309         } else {
310                 FirstLoad = FALSE;
311         }
313         wxListItem accountscol0, accountscol1, accountscol2, accountscol3;
315         lstAccounts->ClearAll();
317         accountscol0.SetId(0);
318         accountscol0.SetWidth(24);
319         lstAccounts->InsertColumn(0,accountscol0);
320         lstAccounts->SetImageList(AccImgList, wxIMAGE_LIST_SMALL);
322         accountscol1.SetId(1);
323         accountscol1.SetText(_("Name"));
324         accountscol1.SetWidth(224);    
325         lstAccounts->InsertColumn(1,accountscol1);   
327         accountscol2.SetId(2);
328         accountscol2.SetText(_("Type"));
329         accountscol2.SetWidth(96);
330         lstAccounts->InsertColumn(2,accountscol2);
331     
332         wxString AccType;
333     
334         for (int i = 0; i < preferences->accounts.GetCount() ; i++){
336                 wxListItem col0;
337                 col0.SetId(i);
338                 
339                 if (preferences->accounts.GetAccountType(i) == wxT("CardDAV")){
340         
341                         col0.SetImage(AccountNetID);
342         
343                 } else if (preferences->accounts.GetAccountType(i) == wxT("Local")){
344         
345                         col0.SetImage(AccountID);
346         
347                 }
348         
349                 long itemindex = lstAccounts->InsertItem( col0 );
350         
351                 lstAccounts->SetItem(itemindex, 1, preferences->accounts.GetAccountName(i));
352                 lstAccounts->SetItem(itemindex, 2, preferences->accounts.GetAccountType(i));
353         
354         }
355     
358 void frmPreferences::SetupPointers(bool *ReloadAccountInc){
360         // Setup the pointers for the preferences form.
361         
362         ReloadAccountConfig = ReloadAccountInc;
366 void frmPreferences::SavePreferences(wxCommandEvent &event){
368         // Load up the preferences file.
370         wxString SetFilename = GetSettingsFile();
372         wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
374         // Update the settings file.
375                 
376         cfgfile->DeleteEntry(wxT("SaveWindowPosition"));
377         cfgfile->DeleteEntry(wxT("WindowPositionX"));
378         cfgfile->DeleteEntry(wxT("WindowPositionY"));
379         cfgfile->DeleteEntry(wxT("WindowPositionHeight"));
380         cfgfile->DeleteEntry(wxT("WindowPositionWidth"));
381         
382         if (chkSaveWindowPosition->GetValue() == TRUE){
383         
384                 cfgfile->Write(wxT("SaveWindowPosition"), wxT("true"));
385         
386                 // Get parent window details.
387                 
388                 frmMain *frmMainPtr = (frmMain*)this->GetParent();
390                 // Get main window position data and save it.
391         
392                 wxRect frmMainPos = frmMainPtr->GetRect();
393         
394                 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
395                 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
396                 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
397                 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
399         } else {
400         
401                 cfgfile->Write(wxT("SaveWindowPosition"), wxT("false"));
402         
403         }
404         
405         cfgfile->DeleteEntry(wxT("HideLocalAddressBooks"));
406         
407         if (chkHideLocal->GetValue() == TRUE){
409                 cfgfile->Write(wxT("HideLocalAddressBooks"), wxT("true"));
410                 *ReloadAccountConfig = TRUE;
411         
412         } else {
413         
414                 cfgfile->Write(wxT("HideLocalAddressBooks"), wxT("false"));
415                 *ReloadAccountConfig = TRUE;
416         
417         }
419         delete cfgfile;
420         cfgfile = NULL;
422         this->Close();
426 void frmPreferences::CloseWindow(wxCommandEvent &event){
428         // Close the preferences window.
429         
430         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