Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Close all windows when opening preferences
[xestiaab/.git] / source / frmMain.cpp
1 // frmMain.cpp - Main window 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 <iostream>
20 #include <algorithm>
21 #include <vector>
22 #include <thread>
24 #include <wx/wx.h>
25 #include <wx/tokenzr.h>
26 #include <wx/icon.h>
27 #include <wx/mstream.h>
28 #include <wx/fs_mem.h>
29 #include <wx/ffile.h>
30 #include <wx/filesys.h>
31 #include <wx/dir.h>
32 #include <wx/stdpaths.h>
33 #include <wx/fileconf.h>
34 #include <wx/gdicmn.h>
36 // Include the forms.
38 #include "frmMain.h"
39 #include "frmAbout.h"
40 #include "frmPreferences.h"
41 #include "frmNewAccount.h"
42 #include "actmgr/frmActivityMgr.h"
43 #include "frmContact.h"
44 #include "frmConflictResolution.h"
45 #include "frmInvalidSSLCertificate.h"
46 #include "search/frmSearch.h"
47 #include "frmSSLCertificate.h"
48 #include "frmUpdate.h"
49 #include "import/frmImportResults.h"
50 #include "bitmaps.h"
52 #include "common/preferences.h"
53 #include "common/getcontactinfo.h"
54 #include "common/events.h"
55 #include "common/dirs.h"
56 #include "vcard/vcard.h"
57 #include "contacteditor/frmContactEditor.h"
58 #include "import/import.h"
59 #include "export/export.h"
60 #include "widgets/XABContactMenu.h"
61 #include "widgets/XABAccountView.h"
63 #include "version.h"
65 // Define the event types.
67 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
68 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
69 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
70 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
71 DEFINE_EVENT_TYPE(CE_OPENCONTACTLIST);
72 DEFINE_EVENT_TYPE(CE_NEWCONTACT);
73 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
74 DEFINE_EVENT_TYPE(CE_DELETECONTACT);
75 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
76 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
77 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
78 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
79 DEFINE_EVENT_TYPE(ACTMGR_START);
80 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
81 DEFINE_EVENT_TYPE(ACTMGR_STOP);
82 DEFINE_EVENT_TYPE(WINDOW_ADD);
83 DEFINE_EVENT_TYPE(WINDOW_EDIT);
84 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
85 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
86 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
87 DEFINE_EVENT_TYPE(INVALIDSSLCERTSTRING);
88 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
89 DEFINE_EVENT_TYPE(SYNCACCOUNT);
90 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
91 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
92 DEFINE_EVENT_TYPE(REFRESHADDRESSBOOK);
93 #if defined(__APPLE__)
94 DEFINE_EVENT_TYPE(INVALIDSSLTRUST);
95 #endif
97 // Setup the event table using the event types.
99 BEGIN_EVENT_TABLE(frmMain, wxFrame)
100 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
101 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
102 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
103 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
104 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
105 EVT_COMMAND(wxID_ANY, CE_OPENCONTACTLIST, frmMain::OpenContactInfoList)
106 EVT_COMMAND(wxID_ANY, CE_NEWCONTACT, frmMain::ShowContactEditorNew)
107 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
108 EVT_COMMAND(wxID_ANY, CE_DELETECONTACT, frmMain::DeleteContact)
109 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
110 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
111 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
112 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
113 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
114 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
115 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
116 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
117 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
118 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
119 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
120 EVT_COMMAND(wxID_ANY, INVALIDSSLCERTSTRING, frmMain::InvalidSSLCertificateString)
121 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
122 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
123 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
124 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
125 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
126 #if defined(__APPLE__)
127 EVT_COMMAND(wxID_ANY, INVALIDSSLTRUST, frmMain::DisplayTrustPanel)
128 #endif
129 END_EVENT_TABLE()
131 frmMain::frmMain( wxWindow* parent )
133 frmMainADT( parent )
135     
136         // Setup the account icons.
137     
138         wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
139         wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
140         wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
141         wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
142         wxMemoryInputStream estream(icons_accunsupported_png, sizeof(icons_accunsupported_png));
143     
144         wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
145         wxBitmap AccInet(icons_accinet_png, -1);
146         wxIcon wxIAccInet;
147         wxIAccInet.CopyFromBitmap(AccInet);
148     
149         wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
150         wxBitmap AccNIcon(icons_acclocal_png, -1);
151         wxIcon wxIAccNIcon;
152         wxIAccNIcon.CopyFromBitmap(AccNIcon);
153     
154         wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
155         wxBitmap AccGrp(icons_accgroup_png, -1);
156         wxIcon wxIAccGrp;
157         wxIAccGrp.CopyFromBitmap(AccGrp);
159         wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
160         wxBitmap AccNone(icons_accnone_png, -1);
161         wxIcon wxIAccNone;
162         wxIAccNone.CopyFromBitmap(AccNone);
163         
164         wxImage icons_accunsupported_png(estream, wxBITMAP_TYPE_PNG);
165         wxBitmap AccUnsupported(icons_accunsupported_png, -1);
166         wxIcon wxIAccUnsupported;
167         wxIAccUnsupported.CopyFromBitmap(AccUnsupported);
168     
169         AccountID = AccImgList->Add(wxIAccNIcon);
170         AccountNetID = AccImgList->Add(wxIAccInet);
171         AccountGrpID = AccImgList->Add(wxIAccGrp);
172         AccountNoneID = AccImgList->Add(wxIAccNone);
173         AccountUnsupportedID = AccImgList->Add(wxIAccUnsupported);
174     
175         bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
176     
177         // Setup the status bar icons.
178     
179         // SSL icons.
180     
181         wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
182         wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
183         wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
184     
185         wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
186         imgSSL = new wxBitmap(icons_ssl_png, -1);
187     
188         wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
189         imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
190     
191         wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
192         imgNoSSL = new wxBitmap(icons_nossl_png, -1);
193  
194         // Toolbar icons.
196         wxMemoryInputStream addaddressbook(toolbar_addaddressbook_png, sizeof(toolbar_addaddressbook_png));
197         wxMemoryInputStream preferences(toolbar_preferences_png, sizeof(toolbar_preferences_png));
198         wxMemoryInputStream searchcontacts(toolbar_searchcontacts_png, sizeof(toolbar_searchcontacts_png));
199         wxMemoryInputStream addcontact(toolbar_addcontact_png, sizeof(toolbar_addcontact_png));
200         wxMemoryInputStream editcontact(toolbar_editcontact_png, sizeof(toolbar_editcontact_png));
201         wxMemoryInputStream deletecontact(toolbar_deletecontact_png, sizeof(toolbar_deletecontact_png));
203         wxImage toolbar_addaddressbook_png(addaddressbook, wxBITMAP_TYPE_PNG);
204         imgAddAddressBook = new wxBitmap (toolbar_addaddressbook_png, -1);
205         tblMain->SetToolNormalBitmap(tbtNewAccount->GetId(), *imgAddAddressBook);
207         wxImage toolbar_preferences_png(preferences, wxBITMAP_TYPE_PNG);
208         imgPreferences = new wxBitmap (toolbar_preferences_png, -1);
209         tblMain->SetToolNormalBitmap(tbtPreferences->GetId(), *imgPreferences);
211         wxImage toolbar_searchcontacts_png(searchcontacts, wxBITMAP_TYPE_PNG);
212         imgSearchContacts = new wxBitmap (toolbar_searchcontacts_png, -1);
213         tblMain->SetToolNormalBitmap(tbtSearch->GetId(), *imgSearchContacts);
215         wxImage toolbar_addcontact_png(addcontact, wxBITMAP_TYPE_PNG);
216         imgAddContact = new wxBitmap (toolbar_addcontact_png, -1);
217         tblMain->SetToolNormalBitmap(tbtAddContact->GetId(), *imgAddContact);
218         
219         wxImage toolbar_editcontact_png(editcontact, wxBITMAP_TYPE_PNG);
220         imgEditContact = new wxBitmap (toolbar_editcontact_png, -1);
221         tblMain->SetToolNormalBitmap(tbtEditContact->GetId(), *imgEditContact);
222         
223         wxImage toolbar_deletecontact_png(deletecontact, wxBITMAP_TYPE_PNG);
224         imgDeleteContact = new wxBitmap (toolbar_deletecontact_png, -1);
225         tblMain->SetToolNormalBitmap(tbtDeleteContact->GetId(), *imgDeleteContact);
227         // Activity Icon.
228     
229         wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
230         wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
231         wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
232         wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
233         wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
234     
235         wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
236         imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
237     
238         wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
239         imgActIcon1 = new wxBitmap (icons_act1_png, -1);
240         wxIcon wxIAct1icon;
241         wxIAct1icon.CopyFromBitmap(*imgActIcon1);
242     
243         wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
244         imgActIcon2 = new wxBitmap (icons_act2_png, -1);
245         wxIcon wxIAct2icon;
246         wxIAct2icon.CopyFromBitmap(*imgActIcon2);
247     
248         wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
249         imgActIcon3 = new wxBitmap (icons_act3_png, -1);
250         wxIcon wxIAct3icon;
251         wxIAct3icon.CopyFromBitmap(*imgActIcon3);
252     
253         wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
254         imgActIcon4 = new wxBitmap (icons_act4_png, -1);
255         wxIcon wxIAct4icon;
256         wxIAct4icon.CopyFromBitmap(*imgActIcon4);
257     
258         // Online/Offline icons.
259     
260         wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
261         wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
262     
263         wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
264         imgOnline = new wxBitmap(icons_online_png, -1);
265     
266         wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
267         imgOffline = new wxBitmap(icons_offline_png, -1);
268     
269         // Setup the account view.
270     
271         AccCtrl->SetPopupControl(treAccounts);
272         AccCtrl->SetPopupMaxHeight(175);
273         AccCtrl->SetPopupMinWidth(250);
274         treAccounts->AssignImageList(AccImgList);
275     
276         wxListItem ColumnData;
277         ColumnData.SetId(0);
278         ColumnData.SetText(wxT("Name0"));
279         ColumnData.SetWidth(320);
280         lstContacts->InsertColumn(0, ColumnData);
281     
282         treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
283         treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
284     
285 #if defined(__HAIKU__)
286     
287 #elif defined(__WIN32__)
288     
289         int stbBottomData [4] = { -1, 8, 8, 8 };
290     
291 #else
292     
293         int stbBottomData [4] = { -1, 20, 20, 20 };
294     
295 #endif
296     
297         stbBottom->SetFieldsCount(4, stbBottomData);
298         stbBottom->SetMinHeight(16);
299     
300         wxRect rectOnline;
301         wxRect rectSSL;
302         wxRect rectActivity;
303         stbBottom->GetFieldRect(1, rectOnline);
304         stbBottom->GetFieldRect(2, rectSSL);
305         stbBottom->GetFieldRect(3, rectActivity);
306     
307         SSLToolTip = new wxToolTip(wxT(""));
308     
309         imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
310         imgConnStatus->SetBitmap(*imgOnline);
311         imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
312     
313         imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
314         imgSSLStatus->SetBitmap(*imgNoSSL);
315         imgSSLStatus->SetToolTip(SSLToolTip);
316         imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
317     
318         imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
319         imgActivityStatus->SetBitmap(*imgActIconSleep);
320         imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
321     
322         // Setup the window menu.
323     
324         // By default should be:
325     
326         // Contact windows:
327         // (none)
328         // (horizontal line)
329         // Contact editor windows:
330         // (none)
331         // (horizontal line)
332         // Search windows:
333         // (none)
334     
335         mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
336         mnuWindow->Append( mnuContactWindows );
337     
338         mnuWindow->AppendSeparator();
339     
340         mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
341         mnuWindow->Append( mnuContactEditorWindows );
342     
343         mnuWindow->AppendSeparator();
344     
345         mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
346         mnuWindow->Append( mnuSearchWindows );
347     
348 #if defined(__WIN32__)
349     
350         wxFont fontstyle;
351         fontstyle.Bold();
352     
353         mnuContactWindows->SetFont(fontstyle);
354         mnuContactEditorWindows->SetFont(fontstyle);
355         mnuSearchWindows->SetFont(fontstyle);
356     
357 #else
358     
359         mnuContactWindows->Enable(FALSE);
360         mnuContactEditorWindows->Enable(FALSE);
361         mnuSearchWindows->Enable(FALSE);
362     
363 #endif
364     
365         // Hide unimplemented functions.
366     
367         mnuMain->Remove(3);
368     
371 void frmMain::QuitApp( wxCloseEvent& event )
374         // Run the QuitApp function.
376         QuitApp();
380 void frmMain::QuitApp( wxCommandEvent& event )
382     
383         // Run the QuitApp function.
384     
385         QuitApp();
386     
389 void frmMain::QuitApp()
392         // Function to run when quitting.
393         
394         // Write out the ETag databases.
395         
396         ETagProcTimer.Stop();
397         ETagProcTimer.Notify();
398     
399         // Save Preferences: Save the window position if that option is enabled.
400     
401         wxString SetFilename = GetUserPrefDir();
402     
403 #if defined(__HAIKU__)
404     
405     
406     
407 #elif defined(__WIN32__)
408     
409         SetFilename.Append(wxT("settings"));
410     
411 #else
412     
413         // *nix OSes
414     
415         SetFilename.Append(wxT("settings"));
416     
417 #endif
418     
419         wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
420     
421         bool SaveWindowPos = FALSE;
422         wxString SaveWindowInc;
423         cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
424     
425         if (SaveWindowInc == wxT("true")){
426         
427                 SaveWindowPos = TRUE;
428         
429         }
430     
431         if (SaveWindowPos == TRUE){
432         
433                 wxRect frmMainPos = this->GetRect();
434         
435                 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
436                 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
437                 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
438                 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
439         
440         }
441     
442         delete cfgfile;
443         cfgfile = NULL;
444     
445         //Everything closed... exit.
446     
447         std::exit(0);
448     
449         Close();
450     
453 void frmMain::ShowActivityWindow( wxCommandEvent& event )
455     
456         // Open the activity manager window.
457     
458         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
459         frameActMgr->OpenWindow();
460         frameActMgr->Show();
461     
464 void frmMain::ShowAboutWindow( wxCommandEvent& event )
467         // Show the about window.
468     
469         frmAbout *frameAbout = new frmAbout ( this );
470         frameAbout->SetupAboutWindow();
471         frameAbout->ShowModal();
472         delete frameAbout;
473         frameAbout = NULL;
474     
477 void frmMain::OpenPreferences( wxCommandEvent& event)
480         // Close all windows first.
481         
482         if (CloseAllWindows() == false)
483         {
484                 return;
485         }
487         // Open the preferences window.
488     
489         ReloadAccounts = FALSE;
490     
491         frmPreferences *framePreferences = new frmPreferences ( this );
492         framePreferences->SetupPointers(&ReloadAccounts);
493         framePreferences->ShowModal();
494         delete framePreferences;
495         framePreferences = NULL;
496     
497         if (ReloadAccounts == TRUE){
498         
499                 // Reload the accounts as a change has been made within
500                 // the application and clear the current contact information.
501         
502                 this->LoadPreferences();
503                 this->ResetContactInfo();
504         
505         }
506     
509 void frmMain::OpenNewABDialog( wxCommandEvent& event)
512         // Open the new account dialog.
513     
514         ReloadAccounts = FALSE;
515     
516         frmNewAccount *frameNewAccount = new frmNewAccount ( this );
517         frameNewAccount->SetupPointers(&ReloadAccounts);
518         frameNewAccount->ShowModal();
519         delete frameNewAccount;
520         frameNewAccount = NULL;
521         
522         if (ReloadAccounts == TRUE){
523             
524                 // Reload the accounts as a change has been made within
525                 // the application.
526         
527                 this->LoadPreferences();
529         }
530     
533 void frmMain::LoadContactList( wxTreeEvent& event )
535     
536         // Load the contact list.
537     
538         // Clear all existing variables.
539     
540         lstContacts->DeleteAllItems();
541     
542         treAccounts->SetAccount();
543     
544         wxTreeItemIdValue cookie;
545         wxTreeItemId next = treAccounts->GetRootItem();
546         wxString AccountName;
547         wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
548         wxString AccountDirCmb;
549         long selectedaccount = 0;
550     
551         wxTreeItemId selectedChild = treAccounts->GetSelection();
552         wxTreeItemId nextChild;
553     
554         wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
555         int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
556     
557         int SCImg = treAccounts->GetItemImage(selectedChild);
558         int AccountIndex = 0;
559     
560         bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
561     
562         // Process each account.
563     
564         for (int i = 0; i < prefaccounts.GetCount(); i++){
565         
566                 if (ActiveItemIcon == 2){
567             
568                         std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
569                         std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
570                         int ActiveAccountG = AGLiter->second;
571             
572                         if (i == ActiveAccountG){
573                 
574                                 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
575                                 AccountType.Append(prefaccounts.GetAccountType(i));
576                 
577                                 AccountDir.Trim();
578                                 AccountType.Trim();
579                 
580                                 if (AccountType == wxT("CardDAV")){
581                                         AccountTypeFinal.Append(wxT("carddav"));
582                                 } else if (AccountType == wxT("Local")){
583                                         imgSSLStatus->SetBitmap(*imgOffline);
584                                         SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
585                                         AccountTypeFinal.Append(wxT("local"));
586                                 } else {
587                                         imgSSLStatus->SetBitmap(*imgOffline);
588                                         SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));                                       
589                                         AccountTypeFinal.Append(AccountType.Lower());
590                                 }
591                 
592                                 AccountIndex = i;
593                                 break;
594                 
595                         }
596             
597                 }
598         
599                 if (!nextChild){
600                         nextChild = treAccounts->GetFirstChild(next, cookie);
601                 } else {
602                         nextChild = treAccounts->GetNextSibling(nextChild);
603                 }
604         
605                 AccountName = treAccounts->GetItemText(nextChild);
606         
607                 if (nextChild == selectedChild){
608                         
609                         AccountDir.Append(prefaccounts.GetAccountDirectory(i));
610                         AccountType.Append(prefaccounts.GetAccountType(i));
611             
612                         AccountDir.Trim();
613                         AccountType.Trim();
614             
615                         if (AccountType == wxT("CardDAV")){
616                                 AccountTypeFinal.Append(wxT("carddav"));
617                         } else if (AccountType == wxT("Local")){
618                                 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
619                                 AccountTypeFinal.Append(wxT("local"));
620                         } else {
621                                 AccountTypeFinal.Append(AccountType.Lower());
622                         }
623             
624                         AccountIndex = i;
625             
626                 }
627         
628         }
629     
630         if (selectedaccount >= prefaccounts.GetCount()){
631         
632                 // The account selected isn't there so return.
633         
634                 RevealWait = FALSE;
635         
636                 return;
637         
638         }
639     
640         // Open the directory and get the list of .vcf files
641         // in that directory.
642     
643         ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
644         ActiveAccountType = AccountType;
645     
646         SetupSSLStatus(AccountIndex);
647     
648         AccountDirFinal.Clear();
649         AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
650     
651         ContactsFileIndex.Clear();
652     
653         wxString vCardFilename;
654         wxString vCardFilenameFull;
655         wxString vCardDataString;
656         wxStringTokenizer vcardfileline;
657         wxString lwxs;
658         wxString setname, setvalue;
659         std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
660         std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
661         long ContactIndex = 1;
662         long ContactSeekPoint = 0;
663     
664         wxDir vcardaccdir(AccountDirFinal);
666         // Get the wxTreeItemId and image icon and compare it to the list.
667     
668         if (ActiveItemIcon == AccountGrpID){
669         
670                 // It's a group so load the file containing the group and
671                 // get the members of the group.
672         
673                 vCard Group;
674                 wxString UIDCode;
675         
676                 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
677                 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
678        
679                 Group.LoadFile(AGFiter->second);
680         
681                 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
682         
683                 for (int i = 0; i < vCardMember.PropCount; i++){
684             
685                         vCardMember.PropValues[i].Trim();
686                         if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
687                 
688                                 wxString NewPropValue;
689                                 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
690                                 vCardMember.PropValues[i] = NewPropValue;
691                 
692                         }
693             
694                 }
695         
696                 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
697         
698                 while(ProcFiles){
699             
700                         if (vCardFilename.Right(4) == wxT(".vcf") ||
701                                 vCardFilename.Right(4) == wxT(".VCF") ||
702                                 vCardFilename.Right(5) == wxT(".vcard") ||
703                                 vCardFilename.Right(5) == wxT(".VCARD")){
704                 
705                                 vCard Person;
706                                 bool FoundMember = FALSE;
707                 
708                                 vCardFilenameFull.Append(AccountDirFinal);
709                                 vCardFilenameFull.Append(wxT("/"));
710                                 vCardFilenameFull.Append(vCardFilename);
711                 
712                                 Person.LoadFile(vCardFilenameFull);
713                 
714                                 UIDCode = Person.Get(wxT("UID"));
715                 
716                                 for (int i = 0; i < vCardMember.PropCount; i++){
717                     
718                                         if (vCardMember.PropValues[i] == UIDCode){
719                         
720                                                 FoundMember = TRUE;
721                         
722                                         }
724                                 }
725                 
726                                 if (FoundMember == FALSE){
727                     
728                                         vCardFilename.Clear();
729                                         vCardFilenameFull.Clear();
730                                         vCardDataString.Clear();
731                                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
732                                         continue;
733                     
734                                 }
735                 
736                                 if (Person.MeetBaseSpecification()){
737                     
738                                         if (SortMode == 1){
739                         
740                                                 // Split the name into sections.
741                         
742                                                 vCardDataString = Person.Get(wxT("N"));
743                         
744                                                 vCardName NameData = Person.GetName();
745                         
746                                                 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
747                         
748                                         } else if (SortMode == 2){
749                         
750                                                 // Split the name into sections.
751                         
752                                                 vCardName NameData = Person.GetName();
753                         
754                                                 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
755                         
756                                         } else if (SortMode == 3){
757                         
758                                                 // Check and make sure that the top most nickname is used.
759                         
760                                                 vCardDataString = Person.Get(wxT("NICKNAME"));
761                         
762                                                 if (vCardDataString.IsEmpty()){
763                             
764                                                         vCardDataString = wxT("(no nickname)");
765                             
766                                                 }
767                         
768                                         } else if (SortMode == 4){
769                         
770                                                 vCardDataString = Person.Get(wxT("FN"));
771                         
772                                         }
773                     
774                                         if (AscendingMode == TRUE){
775                                                 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
776                                         } else {
777                                                 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
778                                         }
779                     
780                                 }
781                 
782                         }
783             
784                         vCardFilename.Clear();
785                         vCardFilenameFull.Clear();
786                         vCardDataString.Clear();
787                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
788                         
789                 }
790         
791         } else {
792         
793                 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
794                 while(ProcFiles){
795             
796                         if (vCardFilename.Right(4) == wxT(".vcf") ||
797                                 vCardFilename.Right(4) == wxT(".VCF") ||
798                                 vCardFilename.Right(5) == wxT(".vcard") ||
799                                 vCardFilename.Right(5) == wxT(".VCARD")){
800                 
801                                 vCard Person;
802                 
803                                 vCardFilenameFull.Append(AccountDirFinal);
804                                 vCardFilenameFull.Append(vCardFilename);
805                 
806                                 Person.LoadFile(vCardFilenameFull);
807                 
808                                 if (Person.MeetBaseSpecification()){
809                     
810                                         if (SortMode == 1){
811                         
812                                                 // Split the name into sections.
813                         
814                                                 vCardDataString = Person.Get(wxT("N"));
815                         
816                                                 vCardName NameData = Person.GetName();
817                         
818                                                 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
819                         
820                                         } else if (SortMode == 2){
821                         
822                                                 // Split the name into sections.
823                         
824                                                 vCardName NameData = Person.GetName();
825                         
826                                                 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
827                         
828                                         } else if (SortMode == 3){
829                         
830                                                 // Check and make sure that the top most nickname is used.
831                         
832                                                 vCardDataString = Person.Get(wxT("NICKNAME"));
833                         
834                                                 if (vCardDataString.IsEmpty()){
835                             
836                                                         vCardDataString = wxT("(no nickname)");
837                             
838                                                 }
839                         
840                                         } else if (SortMode == 4){
841                         
842                                                 vCardDataString = Person.Get(wxT("FN"));
843                         
844                                         }
845                     
846                                         if (AscendingMode == TRUE){
847                                         
848                                                 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
849                                                 
850                                         } else {
851                                         
852                                                 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
853                                                 
854                                         }
855                     
856                                 }
857                 
858                         }
859             
860                         vCardFilename.Clear();
861                         vCardFilenameFull.Clear();
862                         vCardDataString.Clear();
863                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
864                 }
865         
866         }
867     
868         // Sort the data.
869     
870         // Insert the data into the control.
871     
872         if (AscendingMode == TRUE){
873                 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
874                         iter != vCardNamesAsc.end(); ++iter){
875             
876                         wxListItem ContactInfo;
877             
878                         ContactInfo.SetId(0);
879                         ContactInfo.SetText(_("Mooo"));
880                         ContactInfo.SetData(ContactSeekPoint);
881                         ContactIndex = lstContacts->InsertItem(ContactInfo);
882             
883                         lstContacts->SetItem(ContactIndex, 0, iter->first);
884             
885                         ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
886                         ContactSeekPoint++;
887             
888                 }
889         
890         } else {
891         
892                 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
893                      iter != vCardNamesDsc.end(); ++iter){
894             
895                         wxListItem ContactInfo;
896             
897                         ContactInfo.SetId(0);
898                         ContactInfo.SetText(_("Mooo"));
899                         ContactInfo.SetData(ContactSeekPoint);
900                         ContactIndex = lstContacts->InsertItem(ContactInfo);
901             
902                         lstContacts->SetItem(ContactIndex, 0, iter->first);
903                         ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
904                         ContactSeekPoint++;
905             
906                 }
907         
908         }
909     
912 void frmMain::ShowContactInfo( wxListEvent& event )
914     
915         // Display the contact information.
916     
917         long intSelected = -1;
918         long ContactSeekNum = -1;
919     
920         // Check if several contacts have been selected.
921     
922         int ContactTotal = 0;
923     
924         for (;;){
925         
926                 intSelected = lstContacts->GetNextItem(intSelected,
927                         wxLIST_NEXT_ALL,
928                         wxLIST_STATE_SELECTED);
929         
930                 if (intSelected == -1){
931             
932                     break;
933             
934                 }
935         
936                 ContactTotal++;
937         
938         }
939     
940         if (ContactTotal == 0){
941                 htmContactData->SetPage(wxT(""));
942                 return;
943         }
944     
945         if (ContactTotal > 1){
946         
947                 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
948                 ActiveFilename.Clear();
949                 return;
950         
951         }
952     
953         intSelected = lstContacts->GetNextItem(intSelected,
954                 wxLIST_NEXT_ALL,
955                 wxLIST_STATE_SELECTED);
956     
957         ContactSeekNum = lstContacts->GetItemData(intSelected);
958     
959         wxFFile ContactFile;
960         wxString wxSContactString;
961         wxString ContactLine;
962         vCard Person;
963     
964         size_t ContactLineLen;
965         bool ExtraLineSeek = FALSE;
966         int QuoteBreakPoint = 0;
967     
968         bool PropertyFind = FALSE;
969         bool QuoteMode = FALSE;
970     
971         wxString wxSPropertyNextLine;
972         wxString wxSProperty;
973         wxString wxSPropertySeg1;
974         wxString wxSPropertySeg2;
975     
976         // Check if we are using wxWidgets version 2.8 or less and
977         // execute the required command accordingly.
978     
979 #if wxABI_VERSION < 20900
980         ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
981 #else
982         ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
983 #endif
984     
985         if (ContactFile.IsOpened() == FALSE){
986         
987                 return;
988         
989         }
990     
991         ContactFile.ReadAll(&wxSContactString, wxConvAuto());
992     
993         // Split the lines.
994     
995         std::map<int, wxString> ContactFileLines;
996         std::map<int, wxString>::iterator striter;
997     
998         wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
999     
1000         int ContactLineSeek = 0;
1001     
1002         while (wSTContactFileLines.HasMoreTokens() == TRUE){
1003         
1004                 ContactLine = wSTContactFileLines.GetNextToken();
1005                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
1006                 ContactLineSeek++;
1007         
1008         }
1009     
1010         if (ContactSeekNum < 0){
1011                 return;
1012         }
1013     
1014         for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
1015                 iter != ContactFileLines.end(); ++iter){
1016         
1017                 // Find the colon which splits the start bit from the data part.
1018         
1019                 ContactLine = iter->second;
1020         
1021                 while (ExtraLineSeek == TRUE){
1022             
1023                         // Check if there is extra data on the next line
1024                         // (indicated by space or tab at the start) and add data.
1025             
1026                         iter++;
1027             
1028                         if (iter == ContactFileLines.end()){
1029                 
1030                                 iter--;
1031                                 break;
1032                 
1033                         }
1034             
1035                         wxSPropertyNextLine = iter->second;
1036             
1037             
1038                         if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
1039                 
1040                                 wxSPropertyNextLine.Remove(0, 1);
1041                                 ContactLine.Append(wxSPropertyNextLine);
1042                 
1043                         } else {
1044                 
1045                                 iter--;
1046                                 ExtraLineSeek = FALSE;
1047                 
1048                         }
1049             
1050                 }
1051         
1052                 ContactLineLen = ContactLine.Len();
1053         
1054                 // Make sure we are not in quotation mode.
1055                 // Make sure colon does not have \ or \\ before it.
1056         
1057                 for (int i = 0; i <= ContactLineLen; i++){
1058             
1059                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1060                 
1061                                 PropertyFind = FALSE;
1062                 
1063                         } else if (PropertyFind == TRUE){
1064                 
1065                                 wxSProperty.Append(ContactLine.Mid(i, 1));
1066                 
1067                         }
1068             
1069                         if (ContactLine.Mid(i, 1) == wxT("\"")){
1070                 
1071                                 if (QuoteMode == TRUE){
1072                     
1073                                         QuoteMode = FALSE;
1074                     
1075                                 } else {
1076                     
1077                                         QuoteMode = TRUE;
1078                     
1079                                 }
1080                 
1081                         }
1082             
1083                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1084                 
1085                                 QuoteBreakPoint = i;
1086                                 break;
1087                 
1088                         }
1089             
1090                 }       
1091         
1092                 // Split that line at the point into two variables (ignore the colon).
1093         
1094                 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1095                 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1096         
1097                 // Insert both into the vCard data file.
1098         
1099                 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1100         
1101                 QuoteMode = FALSE;
1102                 PropertyFind = TRUE;
1103                 ExtraLineSeek = TRUE;
1104                 ContactLineLen = 0;
1105                 QuoteBreakPoint = 0;
1106                 ContactLine.Clear();
1107                 wxSProperty.Clear();
1108         
1109         }
1110     
1111         OldSessionID = SessionID;
1112         SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1113         LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList, ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1114         ActiveFilename = ContactsFileIndex[ContactSeekNum];
1115     
1118 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1120     
1121         // Open a contact editor window to write a new contact with.
1122     
1123         // Check if there is an account selected and if not
1124         // return immediately.
1125     
1126         if (ActiveAccount.IsEmpty()){
1127         
1128                 return;
1129         
1130         }
1131         
1132         // Check if the account type is a valid account type, otherwise
1133         // display an error message.
1134         
1135         if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
1136                 ActiveAccountType != "Local" && ActiveAccountType != "local"){
1137                 
1138                 wxMessageBox(_("Cannot add a new contact as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
1139                 return;
1140                         
1141         }
1142     
1143         // Add Pointer to SetupPointers for the ETagDB.
1144     
1145         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1146         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1147         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1148         wxIcon contacticon;
1149         contacticon.CopyFromBitmap(contacticonbmp);
1150     
1151         frmContactEditor *ContactEditor = new frmContactEditor( this );
1152     
1153         WindowMenuItemID++;
1154     
1155         ContactEditor->SetUID(WindowMenuItemID);
1156     
1157         WindowData *WData = new WindowData;
1158     
1159         WData->DataType = 1;
1160         WData->WindowPointer = (void*)ContactEditor;
1161         WData->WindowID = WindowMenuItemID;
1162     
1163         wxCommandEvent addevent(WINDOW_ADD);
1164         addevent.SetClientData(WData);
1165         wxPostEvent(this, addevent);
1166     
1167         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1168         ContactEditor->SetupHeaders();
1169         ContactEditor->SetupContact(ActiveAccount);
1170         ContactEditor->SetIcon(contacticon);
1171         ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1172         ContactEditor->Show(true);
1173     
1176 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1178     
1179         // Open a contact editor window for editing an existing contact
1180         // with.
1181     
1182         // Check if there is an account selected and if not
1183         // return immediately.
1184     
1185         int DataCheck = event.GetInt();
1186     
1187         if (ActiveAccount.IsEmpty() && DataCheck == 0){
1188         
1189                 return;
1190         
1191         }
1192         
1193         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1194         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1195         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1196         wxIcon contacticon;
1197         contacticon.CopyFromBitmap(contacticonbmp);
1198     
1199         // Check if a contact has been selected.
1200     
1201         long intSelected = -1;
1202         long intContactSeekNum = -1;
1203         
1204         intSelected = lstContacts->GetNextItem(intSelected,
1205                 wxLIST_NEXT_ALL,
1206                 wxLIST_STATE_SELECTED);
1207     
1208         if (intSelected == -1){
1209         
1210                 return;
1211                 
1212         }
1213     
1214         intContactSeekNum = lstContacts->GetItemData(intSelected);
1215     
1216         // Get the filename of the selected contact.
1217     
1218         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1219         frmContactEditor *ContactEditor = new frmContactEditor( this );
1220     
1221         WindowMenuItemID++;
1222     
1223         ContactEditor->SetUID(WindowMenuItemID);
1224     
1225         WindowData *WData = new WindowData;
1226     
1227         WData->DataType = 1;
1228         WData->WindowPointer = (void*)ContactEditor;
1229         WData->WindowID = WindowMenuItemID;
1230     
1231         wxCommandEvent addevent(WINDOW_ADD);
1232         addevent.SetClientData(WData);
1233         wxPostEvent(this, addevent);
1234     
1235         ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1236         ContactEditor->SetupHeaders();
1238         if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
1239                 ActiveAccountType != "Local" && ActiveAccountType != "local"){
1240                         
1241                 ContactEditor->SetupAccountData(true);
1242                         
1243         }
1244     
1245         // Check if pointer is NULL (not from the search forms) or not.
1246     
1247         if (DataCheck == 0){
1248         
1249                 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1250                 ContactEditor->SetupContact(ActiveAccount);
1251         
1252         } else {
1253         
1254                 UCNotif *uc = (UCNotif*)event.GetClientData();
1255         
1256                 if (!uc){
1257             
1258                         ContactEditor->SetupContact(ActiveAccount);
1259                         ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1260             
1261                 } else {
1262             
1263                         ContactEditor->SetupContact(uc->ContactAccount);
1264                         ContactEditor->LoadContact(uc->ContactFilename);
1265             
1266                         delete uc;
1267                         uc = NULL;
1269                 }
1270         
1271         }
1272     
1273         ContactEditor->SetIcon(contacticon);
1274         ContactEditor->Show(true);
1275     
1278 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1280         // Refresh the address book data.
1281    
1282         // Check if ActiveAccount is empty. If not then check if
1283         // account type is not local otherwise continue.
1284     
1285         if (!ActiveAccount.IsEmpty()){
1286    
1287                 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
1288         
1289                         // Account type is not local.
1290         
1291                         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1292                         frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1293                                      wxT(""), wxT(""), wxT(""), wxT(""));
1294         
1295                 } else {
1296         
1297                         wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported"), wxICON_ERROR);
1298         
1299                 }
1300         
1301         }
1302     
1305 void frmMain::OpenContactInfoList( wxListEvent& event )
1307     
1308         // Open the contact information window.
1309     
1310         wxStringTokenizer vcardfileline;
1311         std::string l;
1312         wxString lwxs;
1313         wxString setname, setvalue;
1314         vCard Person;
1315         wxString nextchar;
1316     
1317         long intSelected = -1;
1318         long intContactSeekNum = -1;
1319     
1320         intSelected = lstContacts->GetNextItem(intSelected,
1321                 wxLIST_NEXT_ALL,
1322                 wxLIST_STATE_SELECTED);
1323     
1324         intContactSeekNum = lstContacts->GetItemData(intSelected);
1325     
1326         if (intContactSeekNum == -1){
1327         
1328                 return;
1329                 
1330         }
1331     
1332         Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1333     
1334         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1335         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1336         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1337         wxIcon contacticon;
1338         contacticon.CopyFromBitmap(contacticonbmp);
1339     
1340         frmContact *Contact = new frmContact( this );
1341     
1342         // Add to window list.
1343     
1344         WindowMenuItemID++;
1345     
1346         Contact->SetUID(WindowMenuItemID);
1347     
1348         WindowData *WData = new WindowData;
1349     
1350         WData->DataType = 0;
1351         WData->WindowPointer = (void*)Contact;
1352         WData->WindowID = WindowMenuItemID;
1353     
1354         wxCommandEvent addevent(WINDOW_ADD);
1355         addevent.SetClientData(WData);
1356         wxPostEvent(this, addevent);
1357     
1358         Contact->SetupPointers(&MemoryFileList);
1359         Contact->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1360         Contact->SetupContactData(&Person);
1361     
1362         Contact->SetIcon(contacticon);
1363         Contact->Show(true);
1364     
1367 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1369         // Open a list of contact information windows.
1371         wxListEvent pevent;
1372         OpenContactInfoList(pevent);
1376 void frmMain::OpenContactInfo( wxCommandEvent& event )
1379         // Open the contact information window.
1381         UCNotif *uc = (UCNotif*)event.GetClientData();
1382     
1383         wxStringTokenizer vcardfileline;
1384         std::string l;
1385         wxString lwxs;
1386         wxString setname, setvalue;
1387         vCard Person;
1388         wxString nextchar;
1389     
1390         Person.LoadFile(uc->ContactFilename);
1391     
1392         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1393         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1394         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1395         wxIcon contacticon;
1396         contacticon.CopyFromBitmap(contacticonbmp);
1397     
1398         frmContact *Contact = new frmContact( this );
1399     
1400         // Add to window list.
1401     
1402         WindowMenuItemID++;
1403     
1404         Contact->SetUID(WindowMenuItemID);
1405     
1406         WindowData *WData = new WindowData;
1407     
1408         WData->DataType = 0;
1409         WData->WindowPointer = (void*)Contact;
1410         WData->WindowID = WindowMenuItemID;
1411     
1412         wxCommandEvent addevent(WINDOW_ADD);
1413         addevent.SetClientData(WData);
1414         wxPostEvent(this, addevent);
1415     
1416         Contact->SetupPointers(&MemoryFileList);
1417         Contact->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1418         Contact->SetupContactData(&Person);
1419     
1420         Contact->SetIcon(contacticon);
1421         Contact->Show(true);
1422     
1426 void frmMain::LoadPreferences( wxActivateEvent& event)
1429         // Load the preferences.
1431         this->LoadPreferences();
1432         
1435 void frmMain::LoadPreferences(){
1436     
1437         // Load the preferences.
1438     
1439         wxString preffilename = GetUserPrefDir();
1440     
1441         XABPreferences preferences(preffilename);
1442     
1443         // Setup the main window position (if needed).
1444     
1445         bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1446         bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1447         bool UseBackgroundContactColour = preferences.GetBoolData(wxT("UseBackgroundContactColour"));
1448     
1449         if (SaveWindowPos == true){
1450         
1451                 this->SetSize(preferences.GetMainWindowData());
1452         
1453         }
1454     
1455         if (UseBackgroundContactColour == true){
1456                 
1457                 ContactBackgroundColour = preferences.GetBackgroundContactColourData();
1458                 
1459         }
1460         
1461         treAccounts->DeleteAllItems();
1462     
1463         wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1464     
1465         // Stop all account timers and remove the accounts.
1466     
1467         for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1468                 iter != AccountSyncTimers.end(); iter++){
1469         
1470                 wxAccountSyncTimer *AccTmrPtr = iter->second;
1471                 AccTmrPtr->Stop();
1472         
1473                 delete AccTmrPtr;
1474                 AccTmrPtr = NULL;
1475         
1476         }
1478 #if defined(__WIN32__)
1480         for (std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.begin();
1481                 CertificateIter != AccountCertificateData.end(); CertificateIter++){
1483                 CertFreeCertificateContext(CertificateIter->second);
1485         }
1487         AccountCertificateData.clear();
1489 #endif
1490     
1491         AccountSyncTimers.clear();
1492         
1493         wxString AccDir;
1494         wxString AccDirFull;
1495         wxString AccDirFullSfx;
1496         wxString AccName;
1497         wxString AccDirFinal;
1498         AccountAccDirList.clear();
1499         AccountGroupList.clear();
1500         AccountGroupFilename.clear();
1501         AccountGroupTreeId.clear();
1502         wxTreeItemId AccountTreeId;
1503         wxTreeItemId GroupTreeId;
1504         int intGroupID = 0;
1505         
1506         // Relaod the accounts for the ETagProcTimer.
1507         
1508         ETagProcTimer.ReloadAccounts();
1509     
1510         for (int i = 0; i < preferences.accounts.GetCount(); i++){
1511                 
1512                 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1513                         preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == true){
1514             
1515                         continue;
1516             
1517                 }
1518         
1519                 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1520             
1521                         continue;
1522             
1523                 }
1524         
1525                 AccDir = preferences.accounts.GetAccountDirectory(i);
1526                 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1527                 AccDirFull.Trim();
1528                 AccDirFull.Append(wxT("."));
1529                 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1530                 AccDirFullSfx.LowerCase();
1531                 AccDirFullSfx.Trim();
1532                 AccDirFull.Append(AccDirFullSfx);
1533                 AccName = preferences.accounts.GetAccountName(i);
1534                 AccName.Trim();
1535                 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1536                 
1537                 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1538                         preferences.accounts.GetAccountType(i) == wxT("carddav")){
1539             
1540                         // TODO: Check if the directory exists before doing anything.
1541             
1542             
1543             
1544                         // Add a new timer using the existing account details.
1545             
1546                         wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1547             
1548                         ActTmrPtr->SetupData(AccDirFull, AccName);
1549                         ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1550                         ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1551                         ActTmrPtr->SetOwner(this);
1552                         ActTmrPtr->Notify();
1553             
1554                         // Add the timer to the list of timers.
1555             
1556                         AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1557             
1558                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1559             
1560                 } else if (preferences.accounts.GetAccountType(i) == wxT("Local") ||
1561                         preferences.accounts.GetAccountType(i) == wxT("local")) {
1562             
1563                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1564             
1565                 } else {
1567                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountUnsupportedID, -1);
1568                         
1569                 }
1570         
1571                 // Go through the account directory and find contact files with
1572                 // 'KIND:group' set and add them to the list of groups for the account.
1573         
1574                 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1575         
1576                 wxDir vcardaccdir(AccDirFinal);
1577         
1578                 wxString vCardFilename;
1579                 wxString vCardDataString;
1580                 wxString vCardFilenameFull;
1581                 
1582                 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1583         
1584                 while(ProcFiles){
1585             
1586                         if (vCardFilename.Right(4) == wxT(".vcf") ||
1587                                 vCardFilename.Right(4) == wxT(".VCF") ||
1588                                 vCardFilename.Right(5) == wxT(".vcard") ||
1589                                 vCardFilename.Right(5) == wxT(".VCARD")){
1590                 
1591                                 vCard Person;
1592                 
1593                                 vCardFilenameFull.Append(AccDirFinal);
1594                                 vCardFilenameFull.Append(wxT("/"));
1595                                 vCardFilenameFull.Append(vCardFilename);
1596                 
1597                                 Person.LoadFile(vCardFilenameFull);
1598                 
1599                                 if (Person.MeetBaseSpecification()){
1600                     
1601                                         vCardDataString = Person.Get(wxT("KIND"));
1602                     
1603                                         if (vCardDataString == wxT("group")){
1604                         
1605                                                 // The vCard kind is a group. Add to the account's group list.
1606                         
1607                                                 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1608                                                 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1609                                                 AccountGroupList.insert(std::make_pair(intGroupID, i));
1610                                                 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1611                                                 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1612                         
1613                                         }
1614                     
1615                                         intGroupID++;
1616                     
1617                                 }
1618                 
1619                         }
1620             
1621                         vCardFilename.Clear();
1622                         vCardFilenameFull.Clear();
1623                         vCardDataString.Clear();
1624                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1625             
1626                 }
1627         
1628                 // Clearup for next account.
1629         
1630                 AccDir.clear();
1631                 AccDirFull.clear();
1632                 AccDirFullSfx.clear();
1633                 AccDirFinal.clear();
1634                 AccName.clear();
1635         
1636         }
1637     
1638         // Load the account settings as they are needed for connecting
1639         // to the servers.
1640     
1641         prefaccounts = preferences.accounts;
1642     
1645 void frmMain::ConflictResolution(wxCommandEvent& event){
1646     
1647         // Display the conflict resolution window.
1648     
1649         frmConflictResolution *frameCR = new frmConflictResolution ( this );
1650         vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1651         vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1652         vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1653         frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList, ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1654         frameCR->ShowModal();
1655     
1656         int FinalConflictResult = frameCR->GetResult();
1657     
1658         wxCommandEvent event2(ACTMGR_RESUMEPROC);
1659         event2.SetClientData(vCardConfObj->QRNotifData);
1660         event2.SetInt(FinalConflictResult);
1661     
1662         delete frameCR;
1663         frameCR = NULL;
1664     
1665         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1666         wxPostEvent(frameActMgr, event2);
1667     
1670 void frmMain::UpdateContactList(wxCommandEvent& event){
1671     
1672         // Update the contact list in the main window.
1673     
1674         UCNotif *ucd = (UCNotif*)event.GetClientData();
1675     
1676         // Check if the active account is being displayed in the
1677         // main window. If not, skip and delete the data.
1678     
1679         long longSelected = -1;
1680         int intSelectedData = 0;
1681     
1682         if (ActiveAccount == ucd->ContactAccount){
1683         
1684                 // Look at the list of contacts and if it matches the
1685                 // filename then update the name.
1686         
1687                 for (;;){
1688             
1689                         longSelected = lstContacts->GetNextItem(longSelected,
1690                                 wxLIST_NEXT_ALL,
1691                                 wxLIST_STATE_DONTCARE);
1692             
1693                         if (longSelected == -1){
1694                 
1695                                 break;
1696                 
1697                         }
1698             
1699                         intSelectedData = (int)lstContacts->GetItemData(longSelected);
1700             
1701                         if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1702                 
1703                                 // Work out which sorting mode we are in.
1704                 
1705                                 if (SortMode == 1){
1706                     
1707                                         // First Name, Last Name.
1708                     
1709                                         lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1710                     
1711                                 } else if (SortMode == 2){
1712                     
1713                                         // Last Name, First Name.
1714                     
1715                                         lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1716                     
1717                                 } else if (SortMode == 3){
1718                     
1719                                         // Nickname.
1720                     
1721                                         lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1722                     
1723                                 } else if (SortMode == 4){
1724                     
1725                                         // Display As.
1726                     
1727                                         lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1728                     
1729                                 }
1730                 
1731                 
1732                         }
1733             
1734                         // If the filename is the one loaded into the
1735                         // browser control, then update this too.
1736             
1737                         if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1738                 
1739                                 wxListEvent nullevent;
1740                                 ShowContactInfo(nullevent);
1741                 
1742                         }
1743             
1744                 }
1745         
1746         }
1747     
1748         for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1749                 WindowIter != WindowListPointers.end(); WindowIter++){
1750         
1751                 if (WindowListType[WindowIter->first] != 0){
1752             
1753                         continue;
1754             
1755                 }
1756         
1757                 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1758         
1759                 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1760             
1761                         vCard UpdatedPerson;
1762                         UpdatedPerson.LoadFile(ucd->ContactFilename);
1763                         frmContactPtr->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1764                         frmContactPtr->SetupContactData(&UpdatedPerson);
1765             
1766                 }
1767         
1768         }
1769     
1770         // Send message to search window controller subroutine and
1771         // pass that notification onto the search windows.
1772     
1773         // Setup the new pointer to use the existing UCNotif without
1774         // deleting it.
1775     
1776         UCNotif *ucd2 = ucd;
1777     
1778         wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1779         sup.SetClientData(ucd2);
1780         wxPostEvent(this, sup);
1781     
1782         // Clear up the unused pointer.
1783     
1784         ucd = NULL;
1785     
1788 void frmMain::UpdateAccountList(wxCommandEvent& event){
1789     
1790         // Update the account list (currently unimplemented).
1791     
1794 void frmMain::SetupPointers(void *ActMgrPtrInc){
1795     
1796         // Setup the pointers for the main window.
1797     
1798         ActMgrPtr = ActMgrPtrInc;
1799     
1802 void frmMain::SetupForm(){
1803     
1804         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1805         frameActMgr->SetupPointers(&ETagProcTimer, this);
1806     
1807         // Setup the contact information icons for later.
1808     
1809         wxFileSystem::AddHandler(new wxMemoryFSHandler);
1810         wxImage ciicon_png;
1811         //wxBitmap ciicon;
1812     
1813         wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1814         ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1815         wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1816     
1817         wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1818         ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1819         wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1820     
1821         wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1822         ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1823         wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1824     
1825         wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1826         ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1827         wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1828     
1829         wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1830         ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1831         wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1832     
1833         wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1834         ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1835         wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1836     
1837         LoadPreferences();
1838     
1841 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1842     
1843         // Update the contact lists in the search windows.
1844     
1845         // Go through each of the search windows and
1846         // send the required notification to update the
1847         // contact information.
1848     
1849         // Get the event notification data.
1850     
1851         UCNotif *ucd = (UCNotif*)event.GetClientData();
1852     
1853         // Process each search window giving the new details.
1854     
1855         for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1856                 switer != SearchWindowList.end(); switer++){
1857         
1858                 // Duplicate the event notification data.
1859         
1860                 UCNotif *ucd2 = new UCNotif;
1861         
1862                 ucd2->ContactAccount = ucd->ContactAccount;
1863                 ucd2->ContactFilename = ucd->ContactFilename;
1864                 ucd2->ContactName = ucd->ContactName;
1865                 ucd2->ContactNickname = ucd->ContactNickname;
1866                 ucd2->ContactNameArray = ucd->ContactNameArray;
1867         
1868                 // Pass the data to the search window for processing.
1869         
1870                 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1871                 wxCommandEvent schupdate(SE_UPDATERESULT);
1872                 schupdate.SetClientData(ucd2);
1873                 wxPostEvent(frameSCH, schupdate);
1874         
1875                 // Clear up the pointer prior to variable deletion.
1876         
1877                 frameSCH = NULL;
1878         
1879         }
1880     
1881         delete ucd;
1882         ucd = NULL;
1883     
1886 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1887     
1888         // Open a new search window.
1889     
1890         WindowMenuItemID++;
1891     
1892         frmSearch *frameSCH = new frmSearch ( this );
1893         frameSCH->SetUID(WindowMenuItemID);
1894         frameSCH->Show(true);
1895     
1896         WindowData *WData = new WindowData;
1897     
1898         WData->DataType = 2;
1899         WData->WindowPointer = (void*)frameSCH;
1900         WData->WindowID = WindowMenuItemID;
1901     
1902         wxCommandEvent addevent(WINDOW_ADD);
1903         addevent.SetClientData(WData);
1904         wxPostEvent(this, addevent);
1905     
1906         // Add pointer to the list of open search windows.
1907     
1908         SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1909     
1910         WData = NULL;
1911     
1914 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1915     
1916         // Remove the pointer for a contact window from the
1917         // window list.
1918     
1919         void *frameSCH = (void*)event.GetClientData();
1920     
1921         SearchWindowList.erase(frameSCH);
1922     
1923         frameSCH = NULL;
1924     
1927 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1928     
1929         // Remove the pointer for a contact editor window from
1930         // the window list.
1931     
1932         void *frameSCH = (void*)event.GetClientData();
1933     
1934         SearchWindowList.erase(frameSCH);
1935     
1936         frameSCH = NULL;
1937     
1940 void frmMain::RevealContact(wxCommandEvent& event){
1941     
1942         // Reveal a contact in the main window.
1943     
1944         UCNotif *uc = (UCNotif*)event.GetClientData();
1945     
1946         // Switch the account to the one passed.
1947     
1948         wxTreeItemIdValue cookie;
1949         wxTreeItemId next = treAccounts->GetRootItem();
1950         wxTreeItemId nextChild;
1951     
1952         for (int i = 0; i < prefaccounts.GetCount(); i++){
1953         
1954                 if (!nextChild){
1955                         nextChild = treAccounts->GetFirstChild(next, cookie);
1956                 } else {
1957                         nextChild = treAccounts->GetNextSibling(nextChild);
1958                 }
1959                
1960                 if (uc->ContactAccount == AccountAccDirList[i]){
1961             
1962                 treAccounts->SelectItem(nextChild, TRUE);
1963                 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1964             
1965                 }
1966         
1967         }
1968     
1969         // Switch the contact to the one passed.
1970     
1971         long longSelected = -1;
1972         int intSelectedData = 0;
1973     
1974         for (;;){
1975         
1976                 longSelected = lstContacts->GetNextItem(longSelected,
1977                         wxLIST_NEXT_ALL,
1978                         wxLIST_STATE_DONTCARE);
1979         
1980                 if (longSelected == -1){
1981             
1982                         break;
1983             
1984                 }
1985         
1986                 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1987         
1988                 // Compare the filename with the one received.
1989                 // If they match then select it.
1990         
1991                 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1992             
1993                         // Select.
1994             
1995                         lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1996                         lstContacts->EnsureVisible(longSelected);
1997             
1998                 } else {
1999         
2000                         lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
2001         
2002                 }
2003         
2004         }
2005     
2008 void frmMain::DeleteContact(wxCommandEvent& event){
2009     
2010         // Delete a contact from the main window.
2011         
2012         // Check if a contact is selected.
2013     
2014         long intSelected = -1;
2015         long intContactSeekNum = -1;
2016         wxString wxSContactName;
2017     
2018         intSelected = lstContacts->GetNextItem(intSelected,
2019                 wxLIST_NEXT_ALL,
2020                 wxLIST_STATE_SELECTED);
2021     
2022         if (intSelected == -1){
2023                 return;
2024         }
2025         
2026         // Check if the account type is a valid account type, otherwise
2027         // display an error message.
2028         
2029         if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
2030                 ActiveAccountType != "Local" && ActiveAccountType != "local"){
2031                 
2032                 wxMessageBox(_("Cannot delete contact as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
2033                 return;
2034                         
2035         }
2036     
2037         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2038     
2039         // Get the item data of the contact.
2040     
2041         intContactSeekNum = lstContacts->GetItemData(intSelected);
2042     
2043         // Get the name of the contact.
2044     
2045         wxSContactName = lstContacts->GetItemText(intSelected);
2046     
2047         // Display a message confirming if the contact should
2048         // be deleted.
2049     
2050         int QuestionResponse;
2051     
2052         QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
2053     
2054         if (QuestionResponse == wxNO){
2055         
2056                 // Exit the subroutine
2057         
2058                 return;
2059         
2060         }
2061     
2062         // Delete the contact.
2063     
2064         if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
2065         
2066                 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
2067                 return;
2068         
2069         }
2070     
2071         // Remove the contact from the list.
2072     
2073         lstContacts->DeleteItem(intSelected);
2074     
2075         // Update the search windows, removing the deleted
2076         // contact.
2077     
2078         UCNotif *ucd = new UCNotif;
2079     
2080         ucd->ContactAccount = ActiveAccount;
2081         ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
2082     
2083         for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
2084                 switer != SearchWindowList.end(); switer++){
2085         
2086                 // Duplicate the event notification data.
2087         
2088                 UCNotif *ucd2 = new UCNotif;
2089         
2090                 ucd2->ContactAccount = ucd->ContactAccount;
2091                 ucd2->ContactFilename = ucd->ContactFilename;
2092         
2093                 // Pass the data to the search window for processing.
2094         
2095                 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
2096                 wxCommandEvent schdelete(SE_DELETERESULT);
2097                 schdelete.SetClientData(ucd2);
2098                 wxPostEvent(frameSCH, schdelete);
2099         
2100                 // Clear up the pointer prior to variable deletion.
2101         
2102                 frameSCH = NULL;
2103                 ucd2 = NULL;
2104         
2105         }
2106     
2107         // Clear the wxHTMLWindow.
2108     
2109         wxString EmptyPage = wxT("");
2110     
2111         htmContactData->SetPage(EmptyPage);
2112     
2113         wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2114     
2115         wxString wxSplitFilename;
2116         wxString wxSDataURL;
2117     
2118         while(wSTFilename.HasMoreTokens()){
2119         
2120                 wxSplitFilename = wSTFilename.GetNextToken();
2121         
2122         }
2123     
2124         if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2125         
2126                 // Update the ETagDB and mark it as deleted.
2127         
2128                 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2129         
2130                 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2131         
2132                 // Get the Data URL.
2133         
2134                 wxTreeItemIdValue cookie;
2135                 wxTreeItemId next = treAccounts->GetRootItem();
2136         
2137                 wxTreeItemId selectedChild = treAccounts->GetSelection();
2138                 wxTreeItemId nextChild;
2139         
2140                 for (int i = 0; i < prefaccounts.GetCount(); i++){
2141             
2142                         if (!nextChild){
2143                                 nextChild = treAccounts->GetFirstChild(next, cookie);
2144                         } else {
2145                                 nextChild = treAccounts->GetNextSibling(nextChild);
2146                         }
2147             
2148                         if (nextChild == selectedChild){
2149                         
2150                                 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2151                                 break;
2153                         }
2154             
2155                 }
2156         
2157                 // Add task to the activity monitor to delete the contact.
2158                 
2159                 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2160         
2161         }
2162     
2163         // Clear the variable. Don't delete as it will mess things up.
2164     
2165         ContactsFileIndex[intContactSeekNum] = wxT("");
2166     
2167         delete ucd;
2168         ucd = NULL;
2172 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2173     
2174         // Display this message when the server information has changed
2175         // and it is empty.
2177         QRNotif *qrn = (QRNotif *)event.GetClientData();
2178     
2179         int QResponse = wxMessageBox(_("The list of contacts on the server is empty. Upload all locally stored contacts for this account now?"), _("No contacts on server"), wxYES_NO, this);
2180     
2181         if (QResponse == wxNO){
2182         
2183                 return;
2184     
2185         }
2186     
2187         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2188         event2.SetInt(*qrn->QResponse);
2189         event2.SetClientData(qrn->PausePtr);
2190     
2191         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2192     
2193         wxPostEvent(frameActMgr, event2);
2194     
2197 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2198     
2199         // Remove the contact from the window after syncronising.
2200     
2201         // Check which account is currently active in the window.
2202         // If it is different from the one passed to this subroutine then
2203         // exit from the subroutine.
2204     
2205         if (Account != ActiveAccount){
2206                 return;
2207         }
2208     
2209         long longSelected = -1;
2210         int intSelectedData = 0;
2211     
2212         for (;;){
2213         
2214                 longSelected = lstContacts->GetNextItem(longSelected,
2215                         wxLIST_NEXT_ALL,
2216                         wxLIST_STATE_DONTCARE);
2217         
2218                 if (longSelected == -1){
2219             
2220                         break;
2221             
2222                 }
2223         
2224                 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2225         
2226                 // Compare the filename with the one received.
2227                 // If they match then select it.
2228         
2229                 if (ContactsFileIndex[intSelectedData] == Filename){
2230             
2231                         // Remove the contact from the window.
2232             
2233                         lstContacts->DeleteItem(intSelectedData);
2234             
2235                         // Check if contact is the selected contact in the HTML window and
2236                         // if it is then clear the window.
2237             
2238                         if (ActiveFilename == Filename){
2239                 
2240                                 wxString EmptyPage = wxT("");
2241                                 htmContactData->SetPage(EmptyPage);
2242                 
2243                         }
2244             
2245                         break;
2246             
2247                 }
2248         
2249         }
2250     
2255 void frmMain::SortFNLN( wxCommandEvent& event ) {
2256     
2257         // Sort first name then last name.
2258     
2259         wxTreeEvent NullEvent;
2260         SortMode = 1;
2261         LoadContactList(NullEvent);
2262     
2265 void frmMain::SortLNFN( wxCommandEvent& event ) {
2266     
2267         // Sort last name then first name.
2268     
2269         wxTreeEvent NullEvent;
2270         SortMode = 2;
2271         LoadContactList(NullEvent);
2272     
2275 void frmMain::SortNickname( wxCommandEvent& event ) {
2276     
2277         // Sort by nickname.
2278     
2279         wxTreeEvent NullEvent;
2280         SortMode = 3;
2281         LoadContactList(NullEvent);
2282     
2285 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2286     
2287         // Sort by Display As name.
2288     
2289         wxTreeEvent NullEvent;
2290         SortMode = 4;
2291         LoadContactList(NullEvent);
2292     
2295 void frmMain::SortAscending( wxCommandEvent& event ) {
2296     
2297         // Sort Ascending.
2298     
2299         wxTreeEvent NullEvent;
2300         AscendingMode = TRUE;
2301         LoadContactList(NullEvent);
2302     
2305 void frmMain::SortDescending( wxCommandEvent& event ) {
2306     
2307         // Sort Descending.
2308     
2309         wxTreeEvent NullEvent;
2310         AscendingMode = FALSE;
2311         LoadContactList(NullEvent);
2312     
2315 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2316     
2317         // Toggle the appearance of the status bar.
2318     
2319         if (stbBottom->IsShown() == TRUE){
2320         
2321                 stbBottom->Hide();
2322         
2323         } else {
2324         
2325                 stbBottom->Show();
2326         
2327         }
2328     
2329         this->Layout();
2330     
2333 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2334     
2335         // Display the activity icon.
2336     
2337         imgActivityStatus->SetBitmap(*imgActIcon1);
2338         ActivityIconStatus = 0;
2339     
2342 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2344         // Shuffle through the activity icons.
2345     
2346         switch (ActivityIconStatus){
2347             
2348                 case 0:
2349                         imgActivityStatus->SetBitmap(*imgActIcon1);
2350                         ActivityIconStatus = 1;
2351                         break;
2352                 case 1:
2353                         imgActivityStatus->SetBitmap(*imgActIcon2);
2354                         ActivityIconStatus = 2;
2355                         break;
2356                 case 2:
2357                         imgActivityStatus->SetBitmap(*imgActIcon3);
2358                         ActivityIconStatus = 3;
2359                         break;
2360                 case 3:
2361                         imgActivityStatus->SetBitmap(*imgActIcon4);
2362                         ActivityIconStatus = 0;
2363                         break;
2364                 default:
2365                         ActivityIconStatus = 0;
2366                             
2367         }
2368     
2371 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2372     
2373         // Display the sleep icon.
2374     
2375         imgActivityStatus->SetBitmap(*imgActIconSleep);
2376     
2379 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2380     
2381         // Set the placement of the status bar icons.
2382     
2383         if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2384         
2385                 return;
2386         
2387         }
2388     
2389         wxRect rectOnline;
2390         wxRect rectSSL;
2391         wxRect rectActivity;
2392         stbBottom->GetFieldRect(1, rectOnline);
2393         stbBottom->GetFieldRect(2, rectSSL);
2394         stbBottom->GetFieldRect(3, rectActivity);
2395     
2396         imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2397         imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2398         imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2399     
2402 XABViewMode frmMain::GetViewMode(){
2403     
2404         // Set the view mode of the contact list.
2405     
2406         XABViewMode xvm;
2407     
2408         xvm.SortMode = SortMode;
2409         xvm.AscendingMode = AscendingMode;
2410     
2411         return xvm;
2412     
2415 void frmMain::WindowAdd( wxCommandEvent &event ){
2416     
2417         // Add a window to the window list.
2418     
2419         WindowData *WData = (WindowData*)event.GetClientData();
2420     
2421         size_t pos;
2422     
2423         if (WData->DataType == 0){
2424         
2425                 // Contact Window
2426         
2427                 int intID = mnuContactWindows->GetId();
2428         
2429                 mnuWindow->FindChildItem(intID, &pos);
2430                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2431                 mnuNewItem->SetId(WData->WindowID);
2432                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2433                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2434                 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2435                 mnuWindow->Insert((pos + 1), mnuNewItem);
2436                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2437         
2438         } else if (WData->DataType == 1){
2439         
2440                 // Contact Editor Window
2441         
2442                 int intID = mnuContactEditorWindows->GetId();
2443         
2444                 mnuWindow->FindChildItem(intID, &pos);
2445                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2446                 mnuNewItem->SetId(WData->WindowID);
2447                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2448                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2449                 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2450                 mnuWindow->Insert((pos + 1), mnuNewItem);
2451                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2452         
2453         } else if (WData->DataType == 2){
2454         
2455                 // Search Window
2456         
2457                 int intID = mnuSearchWindows->GetId();
2458                 
2459                 mnuWindow->FindChildItem(intID, &pos);
2460                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2461                 mnuNewItem->SetId(WData->WindowID);
2462                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2463                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2464                 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2465                 mnuWindow->Insert((pos + 1), mnuNewItem);
2466                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2467         
2468         }
2469     
2470         delete WData;
2471         WData = NULL;
2472     
2475 void frmMain::WindowEdit( wxCommandEvent &event ){
2477         // Edit a window in the window list.
2478     
2479         WindowData *WData = (WindowData*)event.GetClientData();
2480     
2481         if (WData->DataType == 0){
2482         
2483                 // Get the window title and use that.
2484         
2485                 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2486         
2487                 wxString WindowTitle = frmContactPtr->GetTitle();
2488         
2489                 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2490         
2491                 MenuIter->second->SetItemLabel(WindowTitle);
2492                 
2493         } else if (WData->DataType == 1){
2494         
2495                 // Get the window title and use that.
2496         
2497                 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2498         
2499                 wxString WindowTitle = frmCEPtr->GetTitle();
2500         
2501                 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2502         
2503                 if (WindowTitle.IsEmpty()){
2504             
2505                         MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2506             
2507                 } else {
2508             
2509                         MenuIter->second->SetItemLabel(WindowTitle);
2510             
2511                 }
2512         
2513         }
2514     
2515         delete WData;
2516         WData = NULL;
2517     
2520 void frmMain::WindowDelete( wxCommandEvent &event ){
2521     
2522         // Delete a window from the window list.
2523     
2524         WindowData *WData = (WindowData*)event.GetClientData();
2525     
2526         std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2527     
2528         mnuWindow->Remove(MenuIter->second);
2529     
2530         delete MenuIter->second;
2531         MenuIter->second = NULL;
2532     
2533         WindowListPointersMenu.erase(WData->WindowID);
2534         WindowListPointers.erase(WData->WindowID);
2535         WindowListType.erase(WData->WindowID);
2536     
2537         delete WData;
2538         WData = NULL;
2539     
2542 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2543     
2544         // Show a contact window from the window list.
2545     
2546         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2547     
2548         frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2549     
2550         frmContactPtr->Show();
2551         frmContactPtr->Raise();
2552     
2555 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2556     
2557         // Show a contact editor window from the window list.
2558     
2559         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2560     
2561         frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2562     
2563         frmCEPtr->Show();
2564         frmCEPtr->Raise();
2565     
2568 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2569     
2570         // Show a search window from the window list.   
2571             
2572         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2573     
2574         frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2575     
2576         frmSearchPtr->Show();
2577         frmSearchPtr->Raise();
2578     
2581 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2582     
2583         // Toggle the online/offline connection status.
2584     
2585         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2586         wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2587         wxPostEvent(frameActMgr, toggconn);
2588     
2591 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2592     
2593         // Check the account type before continuing.
2594     
2595         wxString SeekAccount;
2596         wxString AccTypeLower;
2597         wxString AccType;
2598         bool AccountSSL;
2599     
2600 #if defined(__APPLE__)
2602         std::map<int, SecTrustRef>::iterator SSLTrustIter;
2603         
2604         for (int i = 0; i < prefaccounts.GetCount(); i++){
2605                 
2606                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2607                 AccType.Append(prefaccounts.GetAccountType(i));
2608                 AccountSSL = prefaccounts.GetAccountSSL(i);
2609                 AccTypeLower = AccType.MakeLower();
2610                 SeekAccount.Append(wxT("."));
2611                 SeekAccount.Append(AccTypeLower);
2612                 
2613                 if (SeekAccount == ActiveAccount){
2614                         
2615                         if (AccTypeLower == wxT("local")){
2616                                 
2617                                 return;
2618                                 
2619                         }
2620                         
2621                         if (AccountSSL == false){
2622                                 
2623                                 return;
2624                                 
2625                         }
2626                         
2627                         SSLTrustIter = AccountTrustData.find(i);
2628                         
2629                         // Setup and display the form.
2630                         
2631                         DisplayCertificate(SSLTrustIter->second);
2632                         
2633                 }
2634                 
2635                 SeekAccount.Clear();
2636                 AccTypeLower.Clear();
2637                 AccType.clear();
2638                 
2639         }
2640    
2641 #elif defined(__WIN32__)
2643         std::map<int, PCCERT_CONTEXT>::iterator SSLCertificateIter;
2645         for (int i = 0; i < prefaccounts.GetCount(); i++){
2647                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2648                 AccType.Append(prefaccounts.GetAccountType(i));
2649                 AccountSSL = prefaccounts.GetAccountSSL(i);
2650                 AccTypeLower = AccType.MakeLower();
2651                 SeekAccount.Append(wxT("."));
2652                 SeekAccount.Append(AccTypeLower);
2654                 if (SeekAccount == ActiveAccount){
2656                         if (AccTypeLower == wxT("local")){
2658                                 return;
2660                         }
2662                         if (AccountSSL == false){
2664                                 return;
2666                         }
2668                         SSLCertificateIter = AccountCertificateData.find(i);
2670                         // Setup and display the form.
2672                         if (SSLCertificateIter->second->pCertInfo == NULL){
2674                                 wxMessageBox("No certificate information is available due to invalid connection details, connection being in progress or invalid certificate data received.");
2676                         } else {
2678                                 BOOL ModifiedCertificateData;
2679                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(SSLCertificateIter->second, (HWND)this->GetHandle());
2681                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
2682                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
2683                                 }
2685                         }
2687                         //DisplayCertificate(SSLTrustIter->second);
2689                 }
2691                 SeekAccount.Clear();
2692                 AccTypeLower.Clear();
2693                 AccType.clear();
2695         }
2697 #else
2698     
2699         std::map<int, SSLCertCollectionString>::iterator SSLColIter;
2700         
2701         for (int i = 0; i < prefaccounts.GetCount(); i++){
2702         
2703                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2704                 AccType.Append(prefaccounts.GetAccountType(i));
2705                 AccountSSL = prefaccounts.GetAccountSSL(i);
2706                 AccTypeLower = AccType.MakeLower();
2707                 SeekAccount.Append(wxT("."));
2708                 SeekAccount.Append(AccTypeLower);
2709         
2710                 if (SeekAccount == ActiveAccount){
2711             
2712                         if (AccTypeLower == wxT("local")){
2713                 
2714                                 return;
2715                 
2716                         }
2717             
2718                         if (AccountSSL == false){
2719                 
2720                                 return;
2721                 
2722                         }
2723             
2724                         SSLColIter = AccountSSLData.find(i);
2725             
2726                         SSLCertCollectionString SSLCertInfo = SSLColIter->second;
2727                         
2728                         frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2729                         frameSSLCert->StartCertFrom(0);
2730                         frameSSLCert->SetupCertsString(SSLCertInfo);
2731                         frameSSLCert->ShowModal();
2732             
2733                         delete frameSSLCert;
2734                         frameSSLCert = NULL;
2735             
2736                 }
2737         
2738                 SeekAccount.Clear();
2739                 AccTypeLower.Clear();
2740                 AccType.clear();
2741         
2742         }
2744 #endif
2745     
2748 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2749     
2750         // Check the account type before continuing.
2751     
2754 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2755     
2756         // Check the account type before continuing.
2757     
2760 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2761     
2762         if (event.GetInt() == 0){
2763         
2764                 imgConnStatus->SetBitmap(*imgOnline);
2765         
2766         } else {
2767         
2768                 imgConnStatus->SetBitmap(*imgOffline);
2769         
2770         }       
2771     
2774 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2775     
2776         // Display the form for showing an invalid SSL certificate.
2777     
2778         frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2779         SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2780         SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2781         wxString AccountName = SSLICNObj->AccountName;
2782         frameISC->LoadData(SSLCCData, AccountName);
2783         frameISC->ShowModal();
2784     
2785         int FinalConflictResult = frameISC->GetResult();
2786     
2787         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2788         event2.SetClientData(SSLICNObj->QRNotifData);
2789         event2.SetInt(FinalConflictResult);
2790     
2791         delete frameISC;
2792         frameISC = NULL;
2793     
2794         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);  
2795         wxPostEvent(frameActMgr, event2);
2796         
2799 void frmMain::InvalidSSLCertificateString( wxCommandEvent &event ){
2800     
2801         // Display the form for showing an invalid SSL certificate.
2802     
2803         frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2804         SSLInvalidCertNotifObjString *SSLICNObj = (SSLInvalidCertNotifObjString*)event.GetClientData();
2805         SSLCertCollectionString SSLCCData = SSLICNObj->CertCollection;
2806         wxString AccountName = SSLICNObj->AccountName;
2807         frameISC->LoadData(SSLCCData, AccountName);
2808         frameISC->ShowModal();
2809     
2810         int FinalConflictResult = frameISC->GetResult();
2811     
2812         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2813         event2.SetClientData(SSLICNObj->QRNotifData);
2814         event2.SetInt(FinalConflictResult);
2815     
2816         delete frameISC;
2817         frameISC = NULL;
2818     
2819         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);  
2820         wxPostEvent(frameActMgr, event2);
2821         
2824 void frmMain::PauseAllTimers(){
2825     
2826         // Pause all the account timers.
2827     
2828         for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2829                 ASTiter != AccountSyncTimers.end(); ASTiter++){
2830         
2831                 ASTiter->second->Stop();
2832         
2833         }
2834     
2837 void frmMain::ResumeAllTimers(){
2838     
2839         // Resume all the account timers.
2840     
2841         for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2842                 ASTiter != AccountSyncTimers.end(); ASTiter++){
2843         
2844                 ASTiter->second->Start();
2845         
2846         }
2847     
2850 #if defined(__APPLE__)
2852 #elif defined(__WIN32__)
2854 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEXT CertificateContext){
2856         // Delete existing data.
2858         std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.find(AccountID);
2860         if (CertificateIter != AccountCertificateData.end()){
2861                 CertFreeCertificateContext(CertificateIter->second);
2862         }
2864         AccountCertificateData.erase(AccountID);
2865         AccountSSLResult.erase(AccountID);
2867         // Insert new data.
2869         AccountCertificateData.insert(std::make_pair(AccountID, CertificateContext));
2870         AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2874 #else
2876 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollectionString SSLCertInc){
2877     
2878         // Delete existing data.
2879     
2880         AccountSSLData.erase(AccountID);
2881         AccountSSLResult.erase(AccountID);
2882     
2883         // Insert new data.
2884     
2885         AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2886         AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2887     
2890 #endif
2892 void frmMain::SetupSSLStatus( int AccountID ){
2893         
2894         // Check if account ID given is
2895         // the active account and if not, do nothing.
2896         
2897         wxString AccType;
2898         wxString AccTypeLower;
2899         
2900         AccType = prefaccounts.GetAccountType(AccountID);
2901         AccTypeLower = AccType.MakeLower();
2902         
2903         wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2904         AccTypeLower;
2905         
2906         if (AccountIDName != ActiveAccount){
2907                 
2908                 return;
2909                 
2910         }
2911         
2912         // Check the account type is a supported account type.
2913         
2914         if (AccType != "CardDAV" && AccType != "carddav" &&
2915                 AccType != "Local" && AccType != "local"){
2916         
2917                 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2918                 imgSSLStatus->SetBitmap(*imgNoSSL);
2919                 return;
2920                         
2921         }
2922         
2923         // Check if the account has SSL enabled.
2924         
2925         bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2926         
2927         if (SSLInUse == FALSE){
2928                 
2929                 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2930                 imgSSLStatus->SetBitmap(*imgNoSSL);
2931                 
2932         } else {
2933                 
2934                 // Get the SSL Collection Data.
2935                 
2936                 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2937                 
2938                 // Check if a result value has been set.
2940                 if (SSLResultIter == AccountSSLResult.end()){
2942                         imgSSLStatus->SetBitmap(*imgSSLWarning);
2943                         SSLToolTip->SetTip(wxT("Unable to determine SSL information for the '") + prefaccounts.GetAccountName(AccountID) + wxT("' account."));
2944                         return;
2946                 }
2948                 if (SSLResultIter->second == 1){
2949                         
2950                         imgSSLStatus->SetBitmap(*imgSSLWarning);
2951                         SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2952                                            prefaccounts.GetAccountName(AccountID) +
2953                                            wxT("' (Connection denied by user)\n\nDouble click for more information."));
2954                         
2955                 } else if (SSLResultIter->second == 0){
2956                         
2957                         imgSSLStatus->SetBitmap(*imgSSL);
2958                         SSLToolTip->SetTip(wxT("Account '") +
2959                                            prefaccounts.GetAccountName(AccountID) +
2960                                            wxT("' secured using SSL\n\nDouble click for more information."));
2961                         
2962                 }
2963                 
2964         }
2965         
2968 void frmMain::CheckUpdates( wxCommandEvent& event ){
2969     
2970         // Check for updates to Xestia Address Book.
2971     
2972         frmUpdate *frameUpdate = new frmUpdate ( this );
2973         frameUpdate->FetchData();
2974         frameUpdate->ShowModal();
2975     
2978 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2979     
2980         // Run the import contacts function.
2981     
2982         ImportRun(this);
2983     
2986 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2987     
2988         // Check if an account and at least one contact is selected
2989         // before continuing.
2990     
2991         wxArrayString ArrData;
2992     
2993         if (ActiveAccount.IsEmpty()){
2994         
2995                 return;
2996         
2997         }
2998     
2999         int ContactSelected = 0;
3000         int ContactsCollected = 0;
3001         long longSelected = -1;
3002     
3003         for (;;){
3004         
3005                 longSelected = lstContacts->GetNextItem(longSelected, 
3006                         wxLIST_NEXT_ALL,
3007                         wxLIST_STATE_SELECTED);
3008         
3009                 if (longSelected == -1){
3010             
3011                         break;
3012         
3013                 }
3014         
3015                 int FileID = (int)lstContacts->GetItemData(longSelected);
3016         
3017                 ArrData.Insert(ContactsFileIndex[FileID],
3018                        ContactsCollected, 1);
3019         
3020                 ContactSelected++;
3021         
3022         }
3023     
3024         if (ContactSelected == 0){
3025         
3026                 return;
3027         
3028         }
3029     
3030         // Run the export contacts system.
3031     
3032         ExportRun(this, &ArrData);
3033     
3036 void frmMain::GetListControl(wxListCtrl *lstContactsPtr, 
3037                              wxArrayString *ContactsFileIndexPtr){
3038     
3039         // Set the list control pointers.
3040     
3041         lstContactsPtr = lstContacts;
3042         ContactsFileIndexPtr = &ContactsFileIndex;
3043     
3046 void frmMain::GetSelectedList( wxCommandEvent& event ){
3047     
3048         // Get the array of contact filenames. 
3049     
3050         wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
3051     
3052         // Process them into an array of files. 
3053     
3054         long longSelected = -1;
3055         int ContactsCollected = 0;
3056         wxString ContactFilename;
3057     
3058         for (;;){
3059         
3060                 longSelected = lstContacts->GetNextItem(longSelected, 
3061                         wxLIST_NEXT_ALL,
3062                         wxLIST_STATE_SELECTED);
3063         
3064                 if (longSelected == -1){
3065             
3066                         break;
3067             
3068                 }
3069         
3070                 // Get the file information and add to the list.
3071         
3072                 int FileID = (int)lstContacts->GetItemData(longSelected);
3073         
3074                 ArrData->Insert(ContactsFileIndex[FileID],
3075                         ContactsCollected, 1);
3076         
3077                 ContactsCollected++;
3078                 ContactFilename.Clear();        
3079         
3080         }
3081     
3082         event.SetInt(1);
3083     
3086 void frmMain::SyncAccount( wxCommandEvent& event ){
3087     
3088         // Syncronise the selected account.
3089     
3090         wxString AccNameInc = event.GetString();
3091     
3092         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
3093         frameActMgr->AddTask(3, wxT(""), AccNameInc, 
3094                 wxT(""), wxT(""), wxT(""), wxT(""));
3095     
3098 void frmMain::ShowHelp( wxCommandEvent& event ){
3099     
3100         // Based on the operating system, work out where 
3101         // the documentation should be.
3102     
3103 //#ifdef __APPLE__
3104     
3105 #if defined(__HAIKU__)
3106     
3107 #elif defined(__WIN32__)
3108     
3109     
3110     
3111 #else
3112     
3113         if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
3114         
3115                 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
3116                 return;
3117         
3118 #if XSDAB_RELEASE == 0
3119         
3120         } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
3121         
3122                 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
3123                 return;
3124         
3125 #endif 
3126         
3127         }
3128     
3129 #endif
3130     
3131 #if XSDAB_RELEASE == 0
3132     
3133         wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
3134     
3135 #else
3136     
3137         wxMessageBox(_("The help documentation is not available in the usual locations on the system. Please visit http://documentation.xestia.co.uk/xestiaab/ for documentation"), _("Help documentation missing!"));
3138     
3139 #endif
3140     
3143 void frmMain::ShowImportResults( wxCommandEvent &event ){
3145         // Show the results of importing contacts.
3147         std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
3149         frmImportResults *frmIR = new frmImportResults(this);
3150         frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
3151         frmIR->ShowModal();
3152                 
3153         delete frmIR;
3154         frmIR = NULL;
3155         
3156         delete ResultData;
3157         ResultData = NULL;
3161 void frmMain::ReloadContactList( wxCommandEvent &event ){
3163         // Check if the account name given is the current
3164         // account selected.
3166         if (ActiveAccount == event.GetString()){
3167         
3168                 wxTreeEvent NullEvent;
3169                 LoadContactList(NullEvent);
3170         
3171         }
3175 void frmMain::ShowContactMenu( wxMouseEvent& event ){
3177         // Show the contact menu when a right click occurs
3178         // in the contacts list.
3180         bool EnableRefresh = FALSE;
3182         if (!ActiveAccount.IsEmpty() && (ActiveAccountType == "CardDAV" || ActiveAccountType == "carddav")){
3184                 EnableRefresh = TRUE;
3185         
3186         }
3188         ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
3190         this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
3194 void frmMain::ResetContactInfo(){
3196         // Reset the contact information to an empty page.
3197         
3198         wxString EmptyPage = wxT("");
3199         htmContactData->SetPage(EmptyPage);
3200         AccCtrl->SetValue("");
3201         
3204 bool frmMain::CloseAllWindows()
3206         // Attempt to close all windows.
3207         
3208         if (WindowListPointersMenu.size() == 0)
3209         {
3210                 return true;
3211         }
3212         
3213         if (wxMessageBox(_("Before preforming the action, all windows that are open will need to close. Do you wish to continue?"), _("Close All Windowss"), wxYES_NO) == wxYES)
3214         {
3215                 for(std::map<int, void*>::iterator windowIter = WindowListPointers.begin();
3216                         windowIter != WindowListPointers.end(); windowIter++)
3217                 {
3218                         wxWindow *windowPointer = static_cast<wxWindow*>(windowIter->second);
3219                         windowPointer->Close();
3220                 }
3221                 return true;
3222         }
3223         else
3224         {
3225                 return false;
3226         }
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