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