Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Use Display As name if no first/last name exists
[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 = 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(true);
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(true);
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                                                 vCardName NameData = Person.GetName();
741                         
742                                                 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
743                         
744                                         } else if (SortMode == 2){
745                         
746                                                 // Split the name into sections.
747                         
748                                                 vCardName NameData = Person.GetName();
749                         
750                                                 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
751                         
752                                         } else if (SortMode == 3){
753                         
754                                                 // Check and make sure that the top most nickname is used.
755                         
756                                                 vCardDataString = Person.Get(wxT("NICKNAME"));
757                         
758                                                 if (vCardDataString.IsEmpty()){
759                             
760                                                         vCardDataString = wxT("(no nickname)");
761                             
762                                                 }
763                         
764                                         } else if (SortMode == 4){
765                         
766                                                 vCardDataString = Person.Get(wxT("FN"));
767                         
768                                         }
769                     
770                                         if (AscendingMode == TRUE){
771                                                 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
772                                         } else {
773                                                 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
774                                         }
775                     
776                                 }
777                 
778                         }
779             
780                         vCardFilename.Clear();
781                         vCardFilenameFull.Clear();
782                         vCardDataString.Clear();
783                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
784                         
785                 }
786         
787         } else {
788         
789                 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
790                 while(ProcFiles){
791             
792                         if (vCardFilename.Right(4) == wxT(".vcf") ||
793                                 vCardFilename.Right(4) == wxT(".VCF") ||
794                                 vCardFilename.Right(5) == wxT(".vcard") ||
795                                 vCardFilename.Right(5) == wxT(".VCARD")){
796                 
797                                 vCard Person;
798                 
799                                 vCardFilenameFull.Append(AccountDirFinal);
800                                 vCardFilenameFull.Append(vCardFilename);
801                 
802                                 Person.LoadFile(vCardFilenameFull);
803                 
804                                 if (Person.MeetBaseSpecification()){
805                     
806                                         if (SortMode == 1){
807                         
808                                                 // Split the name into sections.
809                         
810                                                 vCardDataString = Person.Get(wxT("N"));
811                         
812                                                 vCardName NameData = Person.GetName();
813                         
814                                                 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
815                         
816                                         } else if (SortMode == 2){
817                         
818                                                 // Split the name into sections.
819                         
820                                                 vCardName NameData = Person.GetName();
821                         
822                                                 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
823                         
824                                         } else if (SortMode == 3){
825                         
826                                                 // Check and make sure that the top most nickname is used.
827                         
828                                                 vCardDataString = Person.Get(wxT("NICKNAME"));
829                         
830                                                 if (vCardDataString.IsEmpty()){
831                             
832                                                         vCardDataString = wxT("(no nickname)");
833                             
834                                                 }
835                         
836                                         } else if (SortMode == 4){
837                         
838                                                 vCardDataString = Person.Get(wxT("FN"));
839                         
840                                         }
841                     
842                                         if (AscendingMode == TRUE){
843                                         
844                                                 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
845                                                 
846                                         } else {
847                                         
848                                                 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
849                                                 
850                                         }
851                     
852                                 }
853                 
854                         }
855             
856                         vCardFilename.Clear();
857                         vCardFilenameFull.Clear();
858                         vCardDataString.Clear();
859                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
860                 }
861         
862         }
863     
864         // Sort the data.
865     
866         // Insert the data into the control.
867     
868         if (AscendingMode == TRUE){
869                 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
870                         iter != vCardNamesAsc.end(); ++iter){
871             
872                         wxListItem ContactInfo;
873             
874                         ContactInfo.SetId(0);
875                         ContactInfo.SetText(_("Mooo"));
876                         ContactInfo.SetData(ContactSeekPoint);
877                         ContactIndex = lstContacts->InsertItem(ContactInfo);
878             
879                         lstContacts->SetItem(ContactIndex, 0, iter->first);
880             
881                         ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
882                         ContactSeekPoint++;
883             
884                 }
885         
886         } else {
887         
888                 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
889                      iter != vCardNamesDsc.end(); ++iter){
890             
891                         wxListItem ContactInfo;
892             
893                         ContactInfo.SetId(0);
894                         ContactInfo.SetText(_("Mooo"));
895                         ContactInfo.SetData(ContactSeekPoint);
896                         ContactIndex = lstContacts->InsertItem(ContactInfo);
897             
898                         lstContacts->SetItem(ContactIndex, 0, iter->first);
899                         ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
900                         ContactSeekPoint++;
901             
902                 }
903         
904         }
905     
908 void frmMain::ShowContactInfo( wxListEvent& event )
910     
911         // Display the contact information.
912     
913         long intSelected = -1;
914         long ContactSeekNum = -1;
915     
916         // Check if several contacts have been selected.
917     
918         int ContactTotal = 0;
919     
920         for (;;){
921         
922                 intSelected = lstContacts->GetNextItem(intSelected,
923                         wxLIST_NEXT_ALL,
924                         wxLIST_STATE_SELECTED);
925         
926                 if (intSelected == -1){
927             
928                     break;
929             
930                 }
931         
932                 ContactTotal++;
933         
934         }
935     
936         if (ContactTotal == 0){
937                 htmContactData->SetPage(wxT(""));
938                 return;
939         }
940     
941         if (ContactTotal > 1){
942         
943                 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
944                 ActiveFilename.Clear();
945                 return;
946         
947         }
948     
949         intSelected = lstContacts->GetNextItem(intSelected,
950                 wxLIST_NEXT_ALL,
951                 wxLIST_STATE_SELECTED);
952     
953         ContactSeekNum = lstContacts->GetItemData(intSelected);
954     
955         wxFFile ContactFile;
956         wxString wxSContactString;
957         wxString ContactLine;
958         vCard Person;
959     
960         size_t ContactLineLen;
961         bool ExtraLineSeek = FALSE;
962         int QuoteBreakPoint = 0;
963     
964         bool PropertyFind = FALSE;
965         bool QuoteMode = FALSE;
966     
967         wxString wxSPropertyNextLine;
968         wxString wxSProperty;
969         wxString wxSPropertySeg1;
970         wxString wxSPropertySeg2;
971     
972         // Check if we are using wxWidgets version 2.8 or less and
973         // execute the required command accordingly.
974     
975 #if wxABI_VERSION < 20900
976         ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
977 #else
978         ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
979 #endif
980     
981         if (ContactFile.IsOpened() == FALSE){
982         
983                 return;
984         
985         }
986     
987         ContactFile.ReadAll(&wxSContactString, wxConvAuto());
988     
989         // Split the lines.
990     
991         std::map<int, wxString> ContactFileLines;
992         std::map<int, wxString>::iterator striter;
993     
994         wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
995     
996         int ContactLineSeek = 0;
997     
998         while (wSTContactFileLines.HasMoreTokens() == TRUE){
999         
1000                 ContactLine = wSTContactFileLines.GetNextToken();
1001                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
1002                 ContactLineSeek++;
1003         
1004         }
1005     
1006         if (ContactSeekNum < 0){
1007                 return;
1008         }
1009     
1010         for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
1011                 iter != ContactFileLines.end(); ++iter){
1012         
1013                 // Find the colon which splits the start bit from the data part.
1014         
1015                 ContactLine = iter->second;
1016         
1017                 while (ExtraLineSeek == TRUE){
1018             
1019                         // Check if there is extra data on the next line
1020                         // (indicated by space or tab at the start) and add data.
1021             
1022                         iter++;
1023             
1024                         if (iter == ContactFileLines.end()){
1025                 
1026                                 iter--;
1027                                 break;
1028                 
1029                         }
1030             
1031                         wxSPropertyNextLine = iter->second;
1032             
1033             
1034                         if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
1035                 
1036                                 wxSPropertyNextLine.Remove(0, 1);
1037                                 ContactLine.Append(wxSPropertyNextLine);
1038                 
1039                         } else {
1040                 
1041                                 iter--;
1042                                 ExtraLineSeek = FALSE;
1043                 
1044                         }
1045             
1046                 }
1047         
1048                 ContactLineLen = ContactLine.Len();
1049         
1050                 // Make sure we are not in quotation mode.
1051                 // Make sure colon does not have \ or \\ before it.
1052         
1053                 for (int i = 0; i <= ContactLineLen; i++){
1054             
1055                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1056                 
1057                                 PropertyFind = FALSE;
1058                 
1059                         } else if (PropertyFind == TRUE){
1060                 
1061                                 wxSProperty.Append(ContactLine.Mid(i, 1));
1062                 
1063                         }
1064             
1065                         if (ContactLine.Mid(i, 1) == wxT("\"")){
1066                 
1067                                 if (QuoteMode == TRUE){
1068                     
1069                                         QuoteMode = FALSE;
1070                     
1071                                 } else {
1072                     
1073                                         QuoteMode = TRUE;
1074                     
1075                                 }
1076                 
1077                         }
1078             
1079                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1080                 
1081                                 QuoteBreakPoint = i;
1082                                 break;
1083                 
1084                         }
1085             
1086                 }       
1087         
1088                 // Split that line at the point into two variables (ignore the colon).
1089         
1090                 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1091                 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1092         
1093                 // Insert both into the vCard data file.
1094         
1095                 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1096         
1097                 QuoteMode = FALSE;
1098                 PropertyFind = TRUE;
1099                 ExtraLineSeek = TRUE;
1100                 ContactLineLen = 0;
1101                 QuoteBreakPoint = 0;
1102                 ContactLine.Clear();
1103                 wxSProperty.Clear();
1104         
1105         }
1106     
1107         OldSessionID = SessionID;
1108         SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1109         LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList, ContactBackgroundColour);
1110         ActiveFilename = ContactsFileIndex[ContactSeekNum];
1111     
1114 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1116     
1117         // Open a contact editor window to write a new contact with.
1118     
1119         // Check if there is an account selected and if not
1120         // return immediately.
1121     
1122         if (ActiveAccount.IsEmpty()){
1123         
1124                 return;
1125         
1126         }
1127         
1128         // Check if the account type is a valid account type, otherwise
1129         // display an error message.
1130         
1131         if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
1132                 ActiveAccountType != "Local" && ActiveAccountType != "local"){
1133                 
1134                 wxMessageBox(_("Cannot add a new contact as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
1135                 return;
1136                         
1137         }
1138     
1139         // Add Pointer to SetupPointers for the ETagDB.
1140     
1141         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1142         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1143         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1144         wxIcon contacticon;
1145         contacticon.CopyFromBitmap(contacticonbmp);
1146     
1147         frmContactEditor *ContactEditor = new frmContactEditor( this );
1148     
1149         WindowMenuItemID++;
1150     
1151         ContactEditor->SetUID(WindowMenuItemID);
1152     
1153         WindowData *WData = new WindowData;
1154     
1155         WData->DataType = 1;
1156         WData->WindowPointer = (void*)ContactEditor;
1157         WData->WindowID = WindowMenuItemID;
1158     
1159         wxCommandEvent addevent(WINDOW_ADD);
1160         addevent.SetClientData(WData);
1161         wxPostEvent(this, addevent);
1162     
1163         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1164         ContactEditor->SetupHeaders();
1165         ContactEditor->SetupContact(ActiveAccount);
1166         ContactEditor->SetIcon(contacticon);
1167         ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1168         ContactEditor->Show(true);
1169     
1172 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1174     
1175         // Open a contact editor window for editing an existing contact
1176         // with.
1177     
1178         // Check if there is an account selected and if not
1179         // return immediately.
1180     
1181         int DataCheck = event.GetInt();
1182     
1183         if (ActiveAccount.IsEmpty() && DataCheck == 0){
1184         
1185                 return;
1186         
1187         }
1188         
1189         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1190         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1191         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1192         wxIcon contacticon;
1193         contacticon.CopyFromBitmap(contacticonbmp);
1194     
1195         // Check if a contact has been selected.
1196     
1197         long intSelected = -1;
1198         long intContactSeekNum = -1;
1199         
1200         intSelected = lstContacts->GetNextItem(intSelected,
1201                 wxLIST_NEXT_ALL,
1202                 wxLIST_STATE_SELECTED);
1203     
1204         if (intSelected == -1){
1205         
1206                 return;
1207                 
1208         }
1209     
1210         intContactSeekNum = lstContacts->GetItemData(intSelected);
1211     
1212         // Get the filename of the selected contact.
1213     
1214         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1215         frmContactEditor *ContactEditor = new frmContactEditor( this );
1216     
1217         WindowMenuItemID++;
1218     
1219         ContactEditor->SetUID(WindowMenuItemID);
1220     
1221         WindowData *WData = new WindowData;
1222     
1223         WData->DataType = 1;
1224         WData->WindowPointer = (void*)ContactEditor;
1225         WData->WindowID = WindowMenuItemID;
1226     
1227         wxCommandEvent addevent(WINDOW_ADD);
1228         addevent.SetClientData(WData);
1229         wxPostEvent(this, addevent);
1230     
1231         ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1232         ContactEditor->SetupHeaders();
1234         if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
1235                 ActiveAccountType != "Local" && ActiveAccountType != "local"){
1236                         
1237                 ContactEditor->SetupAccountData(true);
1238                         
1239         }
1240     
1241         // Check if pointer is NULL (not from the search forms) or not.
1242     
1243         if (DataCheck == 0){
1244         
1245                 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1246                 ContactEditor->SetupContact(ActiveAccount);
1247         
1248         } else {
1249         
1250                 UCNotif *uc = (UCNotif*)event.GetClientData();
1251         
1252                 if (!uc){
1253             
1254                         ContactEditor->SetupContact(ActiveAccount);
1255                         ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1256             
1257                 } else {
1258             
1259                         ContactEditor->SetupContact(uc->ContactAccount);
1260                         ContactEditor->LoadContact(uc->ContactFilename);
1261             
1262                         delete uc;
1263                         uc = NULL;
1265                 }
1266         
1267         }
1268     
1269         ContactEditor->SetIcon(contacticon);
1270         ContactEditor->Show(true);
1271     
1274 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1276         // Refresh the address book data.
1277    
1278         // Check if ActiveAccount is empty. If not then check if
1279         // account type is not local otherwise continue.
1280     
1281         if (!ActiveAccount.IsEmpty()){
1282    
1283                 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
1284         
1285                         // Account type is not local.
1286         
1287                         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1288                         frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1289                                      wxT(""), wxT(""), wxT(""), wxT(""));
1290         
1291                 } else {
1292         
1293                         wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported"), wxICON_ERROR);
1294         
1295                 }
1296         
1297         }
1298     
1301 void frmMain::OpenContactInfoList( wxListEvent& event )
1303     
1304         // Open the contact information window.
1305     
1306         wxStringTokenizer vcardfileline;
1307         std::string l;
1308         wxString lwxs;
1309         wxString setname, setvalue;
1310         vCard Person;
1311         wxString nextchar;
1312     
1313         long intSelected = -1;
1314         long intContactSeekNum = -1;
1315     
1316         intSelected = lstContacts->GetNextItem(intSelected,
1317                 wxLIST_NEXT_ALL,
1318                 wxLIST_STATE_SELECTED);
1319     
1320         intContactSeekNum = lstContacts->GetItemData(intSelected);
1321     
1322         if (intContactSeekNum == -1){
1323         
1324                 return;
1325                 
1326         }
1327     
1328         Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1329     
1330         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1331         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1332         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1333         wxIcon contacticon;
1334         contacticon.CopyFromBitmap(contacticonbmp);
1335     
1336         frmContact *Contact = new frmContact( this );
1337     
1338         // Add to window list.
1339     
1340         WindowMenuItemID++;
1341     
1342         Contact->SetUID(WindowMenuItemID);
1343     
1344         WindowData *WData = new WindowData;
1345     
1346         WData->DataType = 0;
1347         WData->WindowPointer = (void*)Contact;
1348         WData->WindowID = WindowMenuItemID;
1349     
1350         wxCommandEvent addevent(WINDOW_ADD);
1351         addevent.SetClientData(WData);
1352         wxPostEvent(this, addevent);
1353     
1354         Contact->SetupPointers(&MemoryFileList);
1355         Contact->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1356         Contact->SetupContactData(&Person);
1357     
1358         Contact->SetIcon(contacticon);
1359         Contact->Show(true);
1360     
1363 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1365         // Open a list of contact information windows.
1367         wxListEvent pevent;
1368         OpenContactInfoList(pevent);
1372 void frmMain::OpenContactInfo( wxCommandEvent& event )
1375         // Open the contact information window.
1377         UCNotif *uc = (UCNotif*)event.GetClientData();
1378     
1379         wxStringTokenizer vcardfileline;
1380         std::string l;
1381         wxString lwxs;
1382         wxString setname, setvalue;
1383         vCard Person;
1384         wxString nextchar;
1385     
1386         Person.LoadFile(uc->ContactFilename);
1387     
1388         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1389         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1390         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1391         wxIcon contacticon;
1392         contacticon.CopyFromBitmap(contacticonbmp);
1393     
1394         frmContact *Contact = new frmContact( this );
1395     
1396         // Add to window list.
1397     
1398         WindowMenuItemID++;
1399     
1400         Contact->SetUID(WindowMenuItemID);
1401     
1402         WindowData *WData = new WindowData;
1403     
1404         WData->DataType = 0;
1405         WData->WindowPointer = (void*)Contact;
1406         WData->WindowID = WindowMenuItemID;
1407     
1408         wxCommandEvent addevent(WINDOW_ADD);
1409         addevent.SetClientData(WData);
1410         wxPostEvent(this, addevent);
1411     
1412         Contact->SetupPointers(&MemoryFileList);
1413         Contact->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1414         Contact->SetupContactData(&Person);
1415     
1416         Contact->SetIcon(contacticon);
1417         Contact->Show(true);
1418     
1422 void frmMain::LoadPreferences( wxActivateEvent& event)
1425         // Load the preferences.
1427         this->LoadPreferences(true);
1428         
1431 void frmMain::LoadPreferences(bool skipWindowSizeReload){
1432     
1433         // Load the preferences.
1434     
1435         wxString preffilename = GetUserPrefDir();
1436     
1437         XABPreferences preferences(preffilename);
1438     
1439         // Clear the active account/filename information and account list.
1441         ActiveAccount = "";
1442         ActiveAccountType = "";
1443         ActiveFilename = "";
1444         lstContacts->DeleteAllItems();
1446         // Setup the main window position (if needed).
1447     
1448         bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1449         bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1450         bool UseBackgroundContactColour = preferences.GetBoolData(wxT("UseBackgroundContactColour"));
1451     
1452         if (SaveWindowPos == true && skipWindowSizeReload == false){
1453         
1454                 this->SetSize(preferences.GetMainWindowData());
1455         
1456         }
1457     
1458         if (UseBackgroundContactColour == true){
1459                 
1460                 ContactBackgroundColour = preferences.GetBackgroundContactColourData();
1461                 
1462         } else {
1463                 
1464                 ContactBackgroundColour = wxTransparentColour;
1465                 
1466         }
1467         
1468         treAccounts->DeleteAllItems();
1469     
1470         wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1471     
1472         // Stop all account timers and remove the accounts.
1473     
1474         for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1475                 iter != AccountSyncTimers.end(); iter++){
1476         
1477                 wxAccountSyncTimer *AccTmrPtr = iter->second;
1478                 AccTmrPtr->Stop();
1479         
1480                 delete AccTmrPtr;
1481                 AccTmrPtr = NULL;
1482         
1483         }
1485 #if defined(__WIN32__)
1487         for (std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.begin();
1488                 CertificateIter != AccountCertificateData.end(); CertificateIter++){
1490                 CertFreeCertificateContext(CertificateIter->second);
1492         }
1494         AccountCertificateData.clear();
1496 #endif
1497     
1498         AccountSyncTimers.clear();
1499         
1500         wxString AccDir;
1501         wxString AccDirFull;
1502         wxString AccDirFullSfx;
1503         wxString AccName;
1504         wxString AccDirFinal;
1505         AccountAccDirList.clear();
1506         AccountGroupList.clear();
1507         AccountGroupFilename.clear();
1508         AccountGroupTreeId.clear();
1509         wxTreeItemId AccountTreeId;
1510         wxTreeItemId GroupTreeId;
1511         int intGroupID = 0;
1512         
1513         // Relaod the accounts for the ETagProcTimer.
1514         
1515         ETagProcTimer.ReloadAccounts();
1516     
1517         for (int i = 0; i < preferences.accounts.GetCount(); i++){
1518                 
1519                 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1520                         preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == true){
1521             
1522                         continue;
1523             
1524                 }
1525         
1526                 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1527             
1528                         continue;
1529             
1530                 }
1531         
1532                 AccDir = preferences.accounts.GetAccountDirectory(i);
1533                 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1534                 AccDirFull.Trim();
1535                 AccDirFull.Append(wxT("."));
1536                 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1537                 AccDirFullSfx.LowerCase();
1538                 AccDirFullSfx.Trim();
1539                 AccDirFull.Append(AccDirFullSfx);
1540                 AccName = preferences.accounts.GetAccountName(i);
1541                 AccName.Trim();
1542                 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1543                 
1544                 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1545                         preferences.accounts.GetAccountType(i) == wxT("carddav")){
1546             
1547                         // TODO: Check if the directory exists before doing anything.
1548             
1549             
1550             
1551                         // Add a new timer using the existing account details.
1552             
1553                         wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1554             
1555                         ActTmrPtr->SetupData(AccDirFull, AccName);
1556                         ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1557                         ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1558                         ActTmrPtr->SetOwner(this);
1559                         ActTmrPtr->Notify();
1560             
1561                         // Add the timer to the list of timers.
1562             
1563                         AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1564             
1565                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1566             
1567                 } else if (preferences.accounts.GetAccountType(i) == wxT("Local") ||
1568                         preferences.accounts.GetAccountType(i) == wxT("local")) {
1569             
1570                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1571             
1572                 } else {
1574                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountUnsupportedID, -1);
1575                         
1576                 }
1577         
1578                 // Go through the account directory and find contact files with
1579                 // 'KIND:group' set and add them to the list of groups for the account.
1580         
1581                 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1582         
1583                 wxDir vcardaccdir(AccDirFinal);
1584         
1585                 wxString vCardFilename;
1586                 wxString vCardDataString;
1587                 wxString vCardFilenameFull;
1588                 
1589                 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1590         
1591                 while(ProcFiles){
1592             
1593                         if (vCardFilename.Right(4) == wxT(".vcf") ||
1594                                 vCardFilename.Right(4) == wxT(".VCF") ||
1595                                 vCardFilename.Right(5) == wxT(".vcard") ||
1596                                 vCardFilename.Right(5) == wxT(".VCARD")){
1597                 
1598                                 vCard Person;
1599                 
1600                                 vCardFilenameFull.Append(AccDirFinal);
1601                                 vCardFilenameFull.Append(wxT("/"));
1602                                 vCardFilenameFull.Append(vCardFilename);
1603                 
1604                                 Person.LoadFile(vCardFilenameFull);
1605                 
1606                                 if (Person.MeetBaseSpecification()){
1607                     
1608                                         vCardDataString = Person.Get(wxT("KIND"));
1609                     
1610                                         if (vCardDataString == wxT("group")){
1611                         
1612                                                 // The vCard kind is a group. Add to the account's group list.
1613                         
1614                                                 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1615                                                 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1616                                                 AccountGroupList.insert(std::make_pair(intGroupID, i));
1617                                                 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1618                                                 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1619                         
1620                                         }
1621                     
1622                                         intGroupID++;
1623                     
1624                                 }
1625                 
1626                         }
1627             
1628                         vCardFilename.Clear();
1629                         vCardFilenameFull.Clear();
1630                         vCardDataString.Clear();
1631                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1632             
1633                 }
1634         
1635                 // Clearup for next account.
1636         
1637                 AccDir.clear();
1638                 AccDirFull.clear();
1639                 AccDirFullSfx.clear();
1640                 AccDirFinal.clear();
1641                 AccName.clear();
1642         
1643         }
1644     
1645         // Load the account settings as they are needed for connecting
1646         // to the servers.
1647     
1648         prefaccounts = preferences.accounts;
1649     
1652 void frmMain::ConflictResolution(wxCommandEvent& event){
1653     
1654         // Display the conflict resolution window.
1655     
1656         frmConflictResolution *frameCR = new frmConflictResolution ( this );
1657         vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1658         vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1659         vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1660         frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList, ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1661         frameCR->ShowModal();
1662     
1663         int FinalConflictResult = frameCR->GetResult();
1664     
1665         wxCommandEvent event2(ACTMGR_RESUMEPROC);
1666         event2.SetClientData(vCardConfObj->QRNotifData);
1667         event2.SetInt(FinalConflictResult);
1668     
1669         delete frameCR;
1670         frameCR = NULL;
1671     
1672         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1673         wxPostEvent(frameActMgr, event2);
1674     
1677 void frmMain::UpdateContactList(wxCommandEvent& event){
1678     
1679         // Update the contact list in the main window.
1680     
1681         UCNotif *ucd = (UCNotif*)event.GetClientData();
1682     
1683         // Check if the active account is being displayed in the
1684         // main window. If not, skip and delete the data.
1685     
1686         long longSelected = -1;
1687         int intSelectedData = 0;
1688     
1689         if (ActiveAccount == ucd->ContactAccount){
1690         
1691                 // Look at the list of contacts and if it matches the
1692                 // filename then update the name.
1693         
1694                 for (;;){
1695             
1696                         longSelected = lstContacts->GetNextItem(longSelected,
1697                                 wxLIST_NEXT_ALL,
1698                                 wxLIST_STATE_DONTCARE);
1699             
1700                         if (longSelected == -1){
1701                 
1702                                 break;
1703                 
1704                         }
1705             
1706                         intSelectedData = (int)lstContacts->GetItemData(longSelected);
1707             
1708                         if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1709                 
1710                                 // Work out which sorting mode we are in.
1711                 
1712                                 if (SortMode == 1){
1713                     
1714                                         // First Name, Last Name.
1715                     
1716                                         if (ucd->ContactNameArray.Forename == wxT("") && ucd->ContactNameArray.Surname == wxT(""))
1717                                         {
1718                                                 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1719                                         }
1720                                         else
1721                                         {
1722                                                 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1723                                         }
1724                     
1725                                 } else if (SortMode == 2){
1726                     
1727                                         // Last Name, First Name.
1729                                         if (ucd->ContactNameArray.Forename == wxT("") && ucd->ContactNameArray.Surname == wxT(""))
1730                                         {
1731                                                 lstContacts->SetItem(longSelected, 0, wxT(", ") + ucd->ContactName);
1732                                         }
1733                                         else
1734                                         {
1735                                                 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1736                                         }
1737                     
1738                                 } else if (SortMode == 3){
1739                     
1740                                         // Nickname.
1741                     
1742                                         if (ucd->ContactNickname == wxT(""))
1743                                         {
1744                                                 lstContacts->SetItem(longSelected, 0, _("(no nickname)"));
1745                                         }
1746                                         else
1747                                         {
1748                                                 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1749                                         }
1750                     
1751                                 } else if (SortMode == 4){
1752                     
1753                                         // Display As.
1754                     
1755                                         lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1756                     
1757                                 }
1758                 
1759                 
1760                         }
1761             
1762                         // If the filename is the one loaded into the
1763                         // browser control, then update this too.
1764             
1765                         if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1766                 
1767                                 wxListEvent nullevent;
1768                                 ShowContactInfo(nullevent);
1769                 
1770                         }
1771             
1772                 }
1773         
1774         }
1775     
1776         for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1777                 WindowIter != WindowListPointers.end(); WindowIter++){
1778         
1779                 if (WindowListType[WindowIter->first] != 0){
1780             
1781                         continue;
1782             
1783                 }
1784         
1785                 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1786         
1787                 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1788             
1789                         vCard UpdatedPerson;
1790                         UpdatedPerson.LoadFile(ucd->ContactFilename);
1791                         frmContactPtr->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1792                         frmContactPtr->SetupContactData(&UpdatedPerson);
1793             
1794                 }
1795         
1796         }
1797     
1798         // Send message to search window controller subroutine and
1799         // pass that notification onto the search windows.
1800     
1801         // Setup the new pointer to use the existing UCNotif without
1802         // deleting it.
1803     
1804         UCNotif *ucd2 = ucd;
1805     
1806         wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1807         sup.SetClientData(ucd2);
1808         wxPostEvent(this, sup);
1809     
1810         // Clear up the unused pointer.
1811     
1812         ucd = NULL;
1813     
1816 void frmMain::SetupPointers(void *ActMgrPtrInc){
1817     
1818         // Setup the pointers for the main window.
1819     
1820         ActMgrPtr = ActMgrPtrInc;
1821     
1824 void frmMain::SetupForm(){
1825     
1826         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1827         frameActMgr->SetupPointers(&ETagProcTimer, this);
1828     
1829         // Setup the contact information icons for later.
1830     
1831         wxFileSystem::AddHandler(new wxMemoryFSHandler);
1832         wxImage ciicon_png;
1833         //wxBitmap ciicon;
1834     
1835         wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1836         ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1837         wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1838     
1839         wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1840         ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1841         wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1842     
1843         wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1844         ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1845         wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1846     
1847         wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1848         ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1849         wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1850     
1851         wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1852         ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1853         wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1854     
1855         wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1856         ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1857         wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1858     
1859         LoadPreferences(false);
1860     
1863 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1864     
1865         // Update the contact lists in the search windows.
1866     
1867         // Go through each of the search windows and
1868         // send the required notification to update the
1869         // contact information.
1870     
1871         // Get the event notification data.
1872     
1873         UCNotif *ucd = (UCNotif*)event.GetClientData();
1874     
1875         // Process each search window giving the new details.
1876     
1877         for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1878                 switer != SearchWindowList.end(); switer++){
1879         
1880                 // Duplicate the event notification data.
1881         
1882                 UCNotif *ucd2 = new UCNotif;
1883         
1884                 ucd2->ContactAccount = ucd->ContactAccount;
1885                 ucd2->ContactFilename = ucd->ContactFilename;
1886                 ucd2->ContactName = ucd->ContactName;
1887                 ucd2->ContactNickname = ucd->ContactNickname;
1888                 ucd2->ContactNameArray = ucd->ContactNameArray;
1889         
1890                 // Pass the data to the search window for processing.
1891         
1892                 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1893                 wxCommandEvent schupdate(SE_UPDATERESULT);
1894                 schupdate.SetClientData(ucd2);
1895                 wxPostEvent(frameSCH, schupdate);
1896         
1897                 // Clear up the pointer prior to variable deletion.
1898         
1899                 frameSCH = NULL;
1900         
1901         }
1902     
1903         delete ucd;
1904         ucd = NULL;
1905     
1908 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1909     
1910         // Open a new search window.
1911     
1912         WindowMenuItemID++;
1913     
1914         frmSearch *frameSCH = new frmSearch ( this );
1915         frameSCH->SetUID(WindowMenuItemID);
1916         frameSCH->Show(true);
1917     
1918         WindowData *WData = new WindowData;
1919     
1920         WData->DataType = 2;
1921         WData->WindowPointer = (void*)frameSCH;
1922         WData->WindowID = WindowMenuItemID;
1923     
1924         wxCommandEvent addevent(WINDOW_ADD);
1925         addevent.SetClientData(WData);
1926         wxPostEvent(this, addevent);
1927     
1928         // Add pointer to the list of open search windows.
1929     
1930         SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1931     
1932         WData = NULL;
1933     
1936 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1937     
1938         // Remove the pointer for a contact window from the
1939         // window list.
1940     
1941         void *frameSCH = (void*)event.GetClientData();
1942     
1943         SearchWindowList.erase(frameSCH);
1944     
1945         frameSCH = NULL;
1946     
1949 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1950     
1951         // Remove the pointer for a contact editor window from
1952         // the window list.
1953     
1954         void *frameSCH = (void*)event.GetClientData();
1955     
1956         SearchWindowList.erase(frameSCH);
1957     
1958         frameSCH = NULL;
1959     
1962 void frmMain::RevealContact(wxCommandEvent& event){
1963     
1964         // Reveal a contact in the main window.
1965     
1966         UCNotif *uc = (UCNotif*)event.GetClientData();
1967     
1968         // Switch the account to the one passed.
1969     
1970         wxTreeItemIdValue cookie;
1971         wxTreeItemId next = treAccounts->GetRootItem();
1972         wxTreeItemId nextChild;
1973     
1974         for (int i = 0; i < prefaccounts.GetCount(); i++){
1975         
1976                 if (!nextChild){
1977                         nextChild = treAccounts->GetFirstChild(next, cookie);
1978                 } else {
1979                         nextChild = treAccounts->GetNextSibling(nextChild);
1980                 }
1981                
1982                 if (uc->ContactAccount == AccountAccDirList[i]){
1983             
1984                         treAccounts->SelectItem(nextChild, TRUE);
1985                         AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1986             
1987                 }
1988         
1989         }
1990     
1991         // Switch the contact to the one passed.
1992     
1993         long longSelected = -1;
1994         int intSelectedData = 0;
1995     
1996         for (;;){
1997         
1998                 longSelected = lstContacts->GetNextItem(longSelected,
1999                         wxLIST_NEXT_ALL,
2000                         wxLIST_STATE_DONTCARE);
2001         
2002                 if (longSelected == -1){
2003             
2004                         break;
2005             
2006                 }
2007         
2008                 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2009         
2010                 // Compare the filename with the one received.
2011                 // If they match then select it.
2012         
2013                 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
2014             
2015                         // Select.
2016             
2017                         lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
2018                         lstContacts->EnsureVisible(longSelected);
2019             
2020                 } else {
2021         
2022                         lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
2023         
2024                 }
2025         
2026         }
2027     
2030 void frmMain::DeleteContact(wxCommandEvent& event){
2031     
2032         // Delete a contact from the main window.
2033         
2034         // Check if a contact is selected.
2035     
2036         long intSelected = -1;
2037         long intContactSeekNum = -1;
2038         wxString wxSContactName;
2039     
2040         intSelected = lstContacts->GetNextItem(intSelected,
2041                 wxLIST_NEXT_ALL,
2042                 wxLIST_STATE_SELECTED);
2043     
2044         if (intSelected == -1){
2045                 return;
2046         }
2047         
2048         // Check if the account type is a valid account type, otherwise
2049         // display an error message.
2050         
2051         if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
2052                 ActiveAccountType != "Local" && ActiveAccountType != "local"){
2053                 
2054                 wxMessageBox(_("Cannot delete contact as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
2055                 return;
2056                         
2057         }
2058     
2059         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2060     
2061         // Get the item data of the contact.
2062     
2063         intContactSeekNum = lstContacts->GetItemData(intSelected);
2064     
2065         // Get the name of the contact.
2066     
2067         wxSContactName = lstContacts->GetItemText(intSelected);
2068     
2069         // Display a message confirming if the contact should
2070         // be deleted.
2071     
2072         int QuestionResponse;
2073     
2074         QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
2075     
2076         if (QuestionResponse == wxNO){
2077         
2078                 // Exit the subroutine
2079         
2080                 return;
2081         
2082         }
2083     
2084         // Delete the contact.
2085     
2086         if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
2087         
2088                 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
2089                 return;
2090         
2091         }
2092     
2093         // Remove the contact from the list.
2094     
2095         lstContacts->DeleteItem(intSelected);
2096     
2097         // Update the search windows, removing the deleted
2098         // contact.
2099     
2100         UCNotif *ucd = new UCNotif;
2101     
2102         ucd->ContactAccount = ActiveAccount;
2103         ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
2104     
2105         for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
2106                 switer != SearchWindowList.end(); switer++){
2107         
2108                 // Duplicate the event notification data.
2109         
2110                 UCNotif *ucd2 = new UCNotif;
2111         
2112                 ucd2->ContactAccount = ucd->ContactAccount;
2113                 ucd2->ContactFilename = ucd->ContactFilename;
2114         
2115                 // Pass the data to the search window for processing.
2116         
2117                 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
2118                 wxCommandEvent schdelete(SE_DELETERESULT);
2119                 schdelete.SetClientData(ucd2);
2120                 wxPostEvent(frameSCH, schdelete);
2121         
2122                 // Clear up the pointer prior to variable deletion.
2123         
2124                 frameSCH = NULL;
2125                 ucd2 = NULL;
2126         
2127         }
2128     
2129         // Clear the wxHTMLWindow.
2130     
2131         wxString EmptyPage = wxT("");
2132     
2133         htmContactData->SetPage(EmptyPage);
2134     
2135         wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2136     
2137         wxString wxSplitFilename;
2138         wxString wxSDataURL;
2139     
2140         while(wSTFilename.HasMoreTokens()){
2141         
2142                 wxSplitFilename = wSTFilename.GetNextToken();
2143         
2144         }
2145     
2146         if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2147         
2148                 // Update the ETagDB and mark it as deleted.
2149         
2150                 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2151         
2152                 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2153         
2154                 // Get the Data URL.
2155         
2156                 wxTreeItemIdValue cookie;
2157                 wxTreeItemId next = treAccounts->GetRootItem();
2158         
2159                 wxTreeItemId selectedChild = treAccounts->GetSelection();
2160                 wxTreeItemId nextChild;
2161         
2162                 for (int i = 0; i < prefaccounts.GetCount(); i++){
2163             
2164                         if (!nextChild){
2165                                 nextChild = treAccounts->GetFirstChild(next, cookie);
2166                         } else {
2167                                 nextChild = treAccounts->GetNextSibling(nextChild);
2168                         }
2169             
2170                         if (nextChild == selectedChild){
2171                         
2172                                 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2173                                 break;
2175                         }
2176             
2177                 }
2178         
2179                 // Add task to the activity monitor to delete the contact.
2180                 
2181                 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2182         
2183         }
2184     
2185         // Clear the variable. Don't delete as it will mess things up.
2186     
2187         ContactsFileIndex[intContactSeekNum] = wxT("");
2188     
2189         delete ucd;
2190         ucd = NULL;
2194 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2195     
2196         // Display this message when the server information has changed
2197         // and it is empty.
2199         QRNotif *qrn = (QRNotif *)event.GetClientData();
2200     
2201         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);
2202     
2203         if (QResponse == wxNO){
2204         
2205                 return;
2206     
2207         }
2208     
2209         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2210         event2.SetInt(*qrn->QResponse);
2211         event2.SetClientData(qrn->PausePtr);
2212     
2213         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2214     
2215         wxPostEvent(frameActMgr, event2);
2216     
2219 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2220     
2221         // Remove the contact from the window after syncronising.
2222     
2223         // Check which account is currently active in the window.
2224         // If it is different from the one passed to this subroutine then
2225         // exit from the subroutine.
2226     
2227         if (Account != ActiveAccount){
2228                 return;
2229         }
2230     
2231         long longSelected = -1;
2232         int intSelectedData = 0;
2233     
2234         for (;;){
2235         
2236                 longSelected = lstContacts->GetNextItem(longSelected,
2237                         wxLIST_NEXT_ALL,
2238                         wxLIST_STATE_DONTCARE);
2239         
2240                 if (longSelected == -1){
2241             
2242                         break;
2243             
2244                 }
2245         
2246                 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2247         
2248                 // Compare the filename with the one received.
2249                 // If they match then select it.
2250         
2251                 if (ContactsFileIndex[intSelectedData] == Filename){
2252             
2253                         // Remove the contact from the window.
2254             
2255                         lstContacts->DeleteItem(intSelectedData);
2256             
2257                         // Check if contact is the selected contact in the HTML window and
2258                         // if it is then clear the window.
2259             
2260                         if (ActiveFilename == Filename){
2261                 
2262                                 wxString EmptyPage = wxT("");
2263                                 htmContactData->SetPage(EmptyPage);
2264                 
2265                         }
2266             
2267                         break;
2268             
2269                 }
2270         
2271         }
2272     
2277 void frmMain::SortFNLN( wxCommandEvent& event ) {
2278     
2279         // Sort first name then last name.
2280     
2281         wxTreeEvent NullEvent;
2282         SortMode = 1;
2283         LoadContactList(NullEvent);
2284     
2287 void frmMain::SortLNFN( wxCommandEvent& event ) {
2288     
2289         // Sort last name then first name.
2290     
2291         wxTreeEvent NullEvent;
2292         SortMode = 2;
2293         LoadContactList(NullEvent);
2294     
2297 void frmMain::SortNickname( wxCommandEvent& event ) {
2298     
2299         // Sort by nickname.
2300     
2301         wxTreeEvent NullEvent;
2302         SortMode = 3;
2303         LoadContactList(NullEvent);
2304     
2307 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2308     
2309         // Sort by Display As name.
2310     
2311         wxTreeEvent NullEvent;
2312         SortMode = 4;
2313         LoadContactList(NullEvent);
2314     
2317 void frmMain::SortAscending( wxCommandEvent& event ) {
2318     
2319         // Sort Ascending.
2320     
2321         wxTreeEvent NullEvent;
2322         AscendingMode = TRUE;
2323         LoadContactList(NullEvent);
2324     
2327 void frmMain::SortDescending( wxCommandEvent& event ) {
2328     
2329         // Sort Descending.
2330     
2331         wxTreeEvent NullEvent;
2332         AscendingMode = FALSE;
2333         LoadContactList(NullEvent);
2334     
2337 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2338     
2339         // Toggle the appearance of the status bar.
2340     
2341         if (stbBottom->IsShown() == TRUE){
2342         
2343                 stbBottom->Hide();
2344         
2345         } else {
2346         
2347                 stbBottom->Show();
2348         
2349         }
2350     
2351         this->Layout();
2352     
2355 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2356     
2357         // Display the activity icon.
2358     
2359         imgActivityStatus->SetBitmap(*imgActIcon1);
2360         ActivityIconStatus = 0;
2361     
2364 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2366         // Shuffle through the activity icons.
2367     
2368         switch (ActivityIconStatus){
2369             
2370                 case 0:
2371                         imgActivityStatus->SetBitmap(*imgActIcon1);
2372                         ActivityIconStatus = 1;
2373                         break;
2374                 case 1:
2375                         imgActivityStatus->SetBitmap(*imgActIcon2);
2376                         ActivityIconStatus = 2;
2377                         break;
2378                 case 2:
2379                         imgActivityStatus->SetBitmap(*imgActIcon3);
2380                         ActivityIconStatus = 3;
2381                         break;
2382                 case 3:
2383                         imgActivityStatus->SetBitmap(*imgActIcon4);
2384                         ActivityIconStatus = 0;
2385                         break;
2386                 default:
2387                         ActivityIconStatus = 0;
2388                             
2389         }
2390     
2393 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2394     
2395         // Display the sleep icon.
2396     
2397         imgActivityStatus->SetBitmap(*imgActIconSleep);
2398     
2401 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2402     
2403         // Set the placement of the status bar icons.
2404     
2405         if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2406         
2407                 return;
2408         
2409         }
2410     
2411         wxRect rectOnline;
2412         wxRect rectSSL;
2413         wxRect rectActivity;
2414         stbBottom->GetFieldRect(1, rectOnline);
2415         stbBottom->GetFieldRect(2, rectSSL);
2416         stbBottom->GetFieldRect(3, rectActivity);
2417     
2418         imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2419         imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2420         imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2421     
2424 XABViewMode frmMain::GetViewMode(){
2425     
2426         // Set the view mode of the contact list.
2427     
2428         XABViewMode xvm;
2429     
2430         xvm.SortMode = SortMode;
2431         xvm.AscendingMode = AscendingMode;
2432     
2433         return xvm;
2434     
2437 void frmMain::WindowAdd( wxCommandEvent &event ){
2438     
2439         // Add a window to the window list.
2440     
2441         WindowData *WData = (WindowData*)event.GetClientData();
2442     
2443         size_t pos;
2444     
2445         if (WData->DataType == 0){
2446         
2447                 // Contact Window
2448         
2449                 int intID = mnuContactWindows->GetId();
2450         
2451                 mnuWindow->FindChildItem(intID, &pos);
2452                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2453                 mnuNewItem->SetId(WData->WindowID);
2454                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2455                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2456                 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2457                 mnuWindow->Insert((pos + 1), mnuNewItem);
2458                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2459         
2460         } else if (WData->DataType == 1){
2461         
2462                 // Contact Editor Window
2463         
2464                 int intID = mnuContactEditorWindows->GetId();
2465         
2466                 mnuWindow->FindChildItem(intID, &pos);
2467                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2468                 mnuNewItem->SetId(WData->WindowID);
2469                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2470                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2471                 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2472                 mnuWindow->Insert((pos + 1), mnuNewItem);
2473                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2474         
2475         } else if (WData->DataType == 2){
2476         
2477                 // Search Window
2478         
2479                 int intID = mnuSearchWindows->GetId();
2480                 
2481                 mnuWindow->FindChildItem(intID, &pos);
2482                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2483                 mnuNewItem->SetId(WData->WindowID);
2484                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2485                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2486                 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2487                 mnuWindow->Insert((pos + 1), mnuNewItem);
2488                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2489         
2490         }
2491     
2492         delete WData;
2493         WData = NULL;
2494     
2497 void frmMain::WindowEdit( wxCommandEvent &event ){
2499         // Edit a window in the window list.
2500     
2501         WindowData *WData = (WindowData*)event.GetClientData();
2502     
2503         if (WData->DataType == 0){
2504         
2505                 // Get the window title and use that.
2506         
2507                 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2508         
2509                 wxString WindowTitle = frmContactPtr->GetTitle();
2510         
2511                 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2512         
2513                 MenuIter->second->SetItemLabel(WindowTitle);
2514                 
2515         } else if (WData->DataType == 1){
2516         
2517                 // Get the window title and use that.
2518         
2519                 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2520         
2521                 wxString WindowTitle = frmCEPtr->GetTitle();
2522         
2523                 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2524         
2525                 if (WindowTitle.IsEmpty()){
2526             
2527                         MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2528             
2529                 } else {
2530             
2531                         MenuIter->second->SetItemLabel(WindowTitle);
2532             
2533                 }
2534         
2535         }
2536     
2537         delete WData;
2538         WData = NULL;
2539     
2542 void frmMain::WindowDelete( wxCommandEvent &event ){
2543     
2544         // Delete a window from the window list.
2545     
2546         WindowData *WData = (WindowData*)event.GetClientData();
2547     
2548         std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2549     
2550         mnuWindow->Remove(MenuIter->second);
2551     
2552         delete MenuIter->second;
2553         MenuIter->second = NULL;
2554     
2555         WindowListPointersMenu.erase(WData->WindowID);
2556         WindowListPointers.erase(WData->WindowID);
2557         WindowListType.erase(WData->WindowID);
2558     
2559         delete WData;
2560         WData = NULL;
2561     
2564 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2565     
2566         // Show a contact window from the window list.
2567     
2568         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2569     
2570         frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2571     
2572         frmContactPtr->Show();
2573         frmContactPtr->Raise();
2574     
2577 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2578     
2579         // Show a contact editor window from the window list.
2580     
2581         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2582     
2583         frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2584     
2585         frmCEPtr->Show();
2586         frmCEPtr->Raise();
2587     
2590 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2591     
2592         // Show a search window from the window list.   
2593             
2594         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2595     
2596         frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2597     
2598         frmSearchPtr->Show();
2599         frmSearchPtr->Raise();
2600     
2603 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2604     
2605         // Toggle the online/offline connection status.
2606     
2607         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2608         wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2609         wxPostEvent(frameActMgr, toggconn);
2610     
2613 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2614     
2615         // Check the account type before continuing.
2616     
2617         wxString SeekAccount;
2618         wxString AccTypeLower;
2619         wxString AccType;
2620         bool AccountSSL;
2621     
2622 #if defined(__APPLE__)
2624         std::map<int, SecTrustRef>::iterator SSLTrustIter;
2625         
2626         for (int i = 0; i < prefaccounts.GetCount(); i++){
2627                 
2628                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2629                 AccType.Append(prefaccounts.GetAccountType(i));
2630                 AccountSSL = prefaccounts.GetAccountSSL(i);
2631                 AccTypeLower = AccType.MakeLower();
2632                 SeekAccount.Append(wxT("."));
2633                 SeekAccount.Append(AccTypeLower);
2634                 
2635                 if (SeekAccount == ActiveAccount){
2636                         
2637                         if (AccTypeLower == wxT("local")){
2638                                 
2639                                 return;
2640                                 
2641                         }
2642                         
2643                         if (AccountSSL == false){
2644                                 
2645                                 return;
2646                                 
2647                         }
2648                         
2649                         SSLTrustIter = AccountTrustData.find(i);
2650                         
2651                         // Setup and display the form.
2652                         
2653                         DisplayCertificate(SSLTrustIter->second);
2654                         
2655                 }
2656                 
2657                 SeekAccount.Clear();
2658                 AccTypeLower.Clear();
2659                 AccType.clear();
2660                 
2661         }
2662    
2663 #elif defined(__WIN32__)
2665         std::map<int, PCCERT_CONTEXT>::iterator SSLCertificateIter;
2667         for (int i = 0; i < prefaccounts.GetCount(); i++){
2669                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2670                 AccType.Append(prefaccounts.GetAccountType(i));
2671                 AccountSSL = prefaccounts.GetAccountSSL(i);
2672                 AccTypeLower = AccType.MakeLower();
2673                 SeekAccount.Append(wxT("."));
2674                 SeekAccount.Append(AccTypeLower);
2676                 if (SeekAccount == ActiveAccount){
2678                         if (AccTypeLower == wxT("local")){
2680                                 return;
2682                         }
2684                         if (AccountSSL == false){
2686                                 return;
2688                         }
2690                         SSLCertificateIter = AccountCertificateData.find(i);
2692                         // Setup and display the form.
2694                         if (SSLCertificateIter->second->pCertInfo == NULL){
2696                                 wxMessageBox("No certificate information is available due to invalid connection details, connection being in progress or invalid certificate data received.");
2698                         } else {
2700                                 BOOL ModifiedCertificateData;
2701                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(SSLCertificateIter->second, (HWND)this->GetHandle());
2703                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
2704                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
2705                                 }
2707                         }
2709                         //DisplayCertificate(SSLTrustIter->second);
2711                 }
2713                 SeekAccount.Clear();
2714                 AccTypeLower.Clear();
2715                 AccType.clear();
2717         }
2719 #else
2720     
2721         std::map<int, SSLCertCollectionString>::iterator SSLColIter;
2722         
2723         for (int i = 0; i < prefaccounts.GetCount(); i++){
2724         
2725                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2726                 AccType.Append(prefaccounts.GetAccountType(i));
2727                 AccountSSL = prefaccounts.GetAccountSSL(i);
2728                 AccTypeLower = AccType.MakeLower();
2729                 SeekAccount.Append(wxT("."));
2730                 SeekAccount.Append(AccTypeLower);
2731         
2732                 if (SeekAccount == ActiveAccount){
2733             
2734                         if (AccTypeLower == wxT("local")){
2735                 
2736                                 return;
2737                 
2738                         }
2739             
2740                         if (AccountSSL == false){
2741                 
2742                                 return;
2743                 
2744                         }
2745             
2746                         SSLColIter = AccountSSLData.find(i);
2747             
2748                         SSLCertCollectionString SSLCertInfo = SSLColIter->second;
2749                         
2750                         frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2751                         frameSSLCert->StartCertFrom(0);
2752                         frameSSLCert->SetupCertsString(SSLCertInfo);
2753                         frameSSLCert->ShowModal();
2754             
2755                         delete frameSSLCert;
2756                         frameSSLCert = NULL;
2757             
2758                 }
2759         
2760                 SeekAccount.Clear();
2761                 AccTypeLower.Clear();
2762                 AccType.clear();
2763         
2764         }
2766 #endif
2767     
2770 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2771     
2772         // Check the account type before continuing.
2773     
2776 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2777     
2778         // Check the account type before continuing.
2779     
2782 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2783     
2784         if (event.GetInt() == 0){
2785         
2786                 imgConnStatus->SetBitmap(*imgOnline);
2787         
2788         } else {
2789         
2790                 imgConnStatus->SetBitmap(*imgOffline);
2791         
2792         }       
2793     
2796 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2797     
2798         // Display the form for showing an invalid SSL certificate.
2799     
2800         frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2801         SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2802         SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2803         wxString AccountName = SSLICNObj->AccountName;
2804         frameISC->LoadData(SSLCCData, AccountName);
2805         frameISC->ShowModal();
2806     
2807         int FinalConflictResult = frameISC->GetResult();
2808     
2809         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2810         event2.SetClientData(SSLICNObj->QRNotifData);
2811         event2.SetInt(FinalConflictResult);
2812     
2813         delete frameISC;
2814         frameISC = NULL;
2815     
2816         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);  
2817         wxPostEvent(frameActMgr, event2);
2818         
2821 void frmMain::InvalidSSLCertificateString( wxCommandEvent &event ){
2822     
2823         // Display the form for showing an invalid SSL certificate.
2824     
2825         frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2826         SSLInvalidCertNotifObjString *SSLICNObj = (SSLInvalidCertNotifObjString*)event.GetClientData();
2827         SSLCertCollectionString SSLCCData = SSLICNObj->CertCollection;
2828         wxString AccountName = SSLICNObj->AccountName;
2829         frameISC->LoadData(SSLCCData, AccountName);
2830         frameISC->ShowModal();
2831     
2832         int FinalConflictResult = frameISC->GetResult();
2833     
2834         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2835         event2.SetClientData(SSLICNObj->QRNotifData);
2836         event2.SetInt(FinalConflictResult);
2837     
2838         delete frameISC;
2839         frameISC = NULL;
2840     
2841         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);  
2842         wxPostEvent(frameActMgr, event2);
2843         
2846 void frmMain::PauseAllTimers(){
2847     
2848         // Pause all the account timers.
2849     
2850         for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2851                 ASTiter != AccountSyncTimers.end(); ASTiter++){
2852         
2853                 ASTiter->second->Stop();
2854         
2855         }
2856     
2859 void frmMain::ResumeAllTimers(){
2860     
2861         // Resume all the account timers.
2862     
2863         for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2864                 ASTiter != AccountSyncTimers.end(); ASTiter++){
2865         
2866                 ASTiter->second->Start();
2867         
2868         }
2869     
2872 #if defined(__APPLE__)
2874 #elif defined(__WIN32__)
2876 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEXT CertificateContext){
2878         // Delete existing data.
2880         std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.find(AccountID);
2882         if (CertificateIter != AccountCertificateData.end()){
2883                 CertFreeCertificateContext(CertificateIter->second);
2884         }
2886         AccountCertificateData.erase(AccountID);
2887         AccountSSLResult.erase(AccountID);
2889         // Insert new data.
2891         AccountCertificateData.insert(std::make_pair(AccountID, CertificateContext));
2892         AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2896 #else
2898 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollectionString SSLCertInc){
2899     
2900         // Delete existing data.
2901     
2902         AccountSSLData.erase(AccountID);
2903         AccountSSLResult.erase(AccountID);
2904     
2905         // Insert new data.
2906     
2907         AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2908         AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2909     
2912 #endif
2914 void frmMain::SetupSSLStatus( int AccountID ){
2915         
2916         // Check if account ID given is
2917         // the active account and if not, do nothing.
2918         
2919         wxString AccType;
2920         wxString AccTypeLower;
2921         
2922         AccType = prefaccounts.GetAccountType(AccountID);
2923         AccTypeLower = AccType.MakeLower();
2924         
2925         wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2926         AccTypeLower;
2927         
2928         if (AccountIDName != ActiveAccount){
2929                 
2930                 return;
2931                 
2932         }
2933         
2934         // Check the account type is a supported account type.
2935         
2936         if (AccType != "CardDAV" && AccType != "carddav" &&
2937                 AccType != "Local" && AccType != "local"){
2938         
2939                 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2940                 imgSSLStatus->SetBitmap(*imgNoSSL);
2941                 return;
2942                         
2943         }
2944         
2945         // Check if the account has SSL enabled.
2946         
2947         bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2948         
2949         if (SSLInUse == FALSE){
2950                 
2951                 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2952                 imgSSLStatus->SetBitmap(*imgNoSSL);
2953                 
2954         } else {
2955                 
2956                 // Get the SSL Collection Data.
2957                 
2958                 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2959                 
2960                 // Check if a result value has been set.
2962                 if (SSLResultIter == AccountSSLResult.end()){
2964                         imgSSLStatus->SetBitmap(*imgSSLWarning);
2965                         SSLToolTip->SetTip(wxT("Unable to determine SSL information for the '") + prefaccounts.GetAccountName(AccountID) + wxT("' account."));
2966                         return;
2968                 }
2970                 if (SSLResultIter->second == 1){
2971                         
2972                         imgSSLStatus->SetBitmap(*imgSSLWarning);
2973                         SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2974                                            prefaccounts.GetAccountName(AccountID) +
2975                                            wxT("' (Connection denied by user)\n\nDouble click for more information."));
2976                         
2977                 } else if (SSLResultIter->second == 0){
2978                         
2979                         imgSSLStatus->SetBitmap(*imgSSL);
2980                         SSLToolTip->SetTip(wxT("Account '") +
2981                                            prefaccounts.GetAccountName(AccountID) +
2982                                            wxT("' secured using SSL\n\nDouble click for more information."));
2983                         
2984                 }
2985                 
2986         }
2987         
2990 void frmMain::CheckUpdates( wxCommandEvent& event ){
2991     
2992         // Check for updates to Xestia Address Book.
2993     
2994         frmUpdate *frameUpdate = new frmUpdate ( this );
2995         frameUpdate->FetchData();
2996         frameUpdate->ShowModal();
2997     
3000 void frmMain::OpenImportDialog( wxCommandEvent& event ){
3001     
3002         // Run the import contacts function.
3003     
3004         ImportRun(this);
3005     
3008 void frmMain::OpenExportDialog( wxCommandEvent& event ){
3009     
3010         // Check if an account and at least one contact is selected
3011         // before continuing.
3012     
3013         wxArrayString ArrData;
3014     
3015         if (ActiveAccount.IsEmpty()){
3016         
3017                 return;
3018         
3019         }
3020     
3021         int ContactSelected = 0;
3022         int ContactsCollected = 0;
3023         long longSelected = -1;
3024     
3025         for (;;){
3026         
3027                 longSelected = lstContacts->GetNextItem(longSelected, 
3028                         wxLIST_NEXT_ALL,
3029                         wxLIST_STATE_SELECTED);
3030         
3031                 if (longSelected == -1){
3032             
3033                         break;
3034         
3035                 }
3036         
3037                 int FileID = (int)lstContacts->GetItemData(longSelected);
3038         
3039                 ArrData.Insert(ContactsFileIndex[FileID],
3040                        ContactsCollected, 1);
3041         
3042                 ContactSelected++;
3043         
3044         }
3045     
3046         if (ContactSelected == 0){
3047         
3048                 return;
3049         
3050         }
3051     
3052         // Run the export contacts system.
3053     
3054         ExportRun(this, &ArrData);
3055     
3058 void frmMain::GetListControl(wxListCtrl *lstContactsPtr, 
3059                              wxArrayString *ContactsFileIndexPtr){
3060     
3061         // Set the list control pointers.
3062     
3063         lstContactsPtr = lstContacts;
3064         ContactsFileIndexPtr = &ContactsFileIndex;
3065     
3068 void frmMain::GetSelectedList( wxCommandEvent& event ){
3069     
3070         // Get the array of contact filenames. 
3071     
3072         wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
3073     
3074         // Process them into an array of files. 
3075     
3076         long longSelected = -1;
3077         int ContactsCollected = 0;
3078         wxString ContactFilename;
3079     
3080         for (;;){
3081         
3082                 longSelected = lstContacts->GetNextItem(longSelected, 
3083                         wxLIST_NEXT_ALL,
3084                         wxLIST_STATE_SELECTED);
3085         
3086                 if (longSelected == -1){
3087             
3088                         break;
3089             
3090                 }
3091         
3092                 // Get the file information and add to the list.
3093         
3094                 int FileID = (int)lstContacts->GetItemData(longSelected);
3095         
3096                 ArrData->Insert(ContactsFileIndex[FileID],
3097                         ContactsCollected, 1);
3098         
3099                 ContactsCollected++;
3100                 ContactFilename.Clear();        
3101         
3102         }
3103     
3104         event.SetInt(1);
3105     
3108 void frmMain::SyncAccount( wxCommandEvent& event ){
3109     
3110         // Syncronise the selected account.
3111     
3112         wxString AccNameInc = event.GetString();
3113     
3114         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
3115         frameActMgr->AddTask(3, wxT(""), AccNameInc, 
3116                 wxT(""), wxT(""), wxT(""), wxT(""));
3117     
3120 void frmMain::ShowHelp( wxCommandEvent& event ){
3121     
3122         // Based on the operating system, work out where 
3123         // the documentation should be.
3124     
3125 //#ifdef __APPLE__
3126     
3127 #if defined(__HAIKU__)
3128     
3129 #elif defined(__WIN32__)
3130     
3131     
3132     
3133 #else
3134     
3135         if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
3136         
3137                 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
3138                 return;
3139         
3140 #if XSDAB_RELEASE == 0
3141         
3142         } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
3143         
3144                 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
3145                 return;
3146         
3147 #endif 
3148         
3149         }
3150     
3151 #endif
3152     
3153 #if XSDAB_RELEASE == 0
3154     
3155         wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
3156     
3157 #else
3158     
3159         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!"));
3160     
3161 #endif
3162     
3165 void frmMain::ShowImportResults( wxCommandEvent &event ){
3167         // Show the results of importing contacts.
3169         std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
3171         frmImportResults *frmIR = new frmImportResults(this);
3172         frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
3173         frmIR->ShowModal();
3174                 
3175         delete frmIR;
3176         frmIR = NULL;
3177         
3178         delete ResultData;
3179         ResultData = NULL;
3183 void frmMain::ReloadContactList( wxCommandEvent &event ){
3185         // Check if the account name given is the current
3186         // account selected.
3188         if (ActiveAccount == event.GetString()){
3189         
3190                 wxTreeEvent NullEvent;
3191                 LoadContactList(NullEvent);
3192         
3193         }
3197 void frmMain::ShowContactMenu( wxMouseEvent& event ){
3199         // Show the contact menu when a right click occurs
3200         // in the contacts list.
3202         bool EnableRefresh = FALSE;
3204         if (!ActiveAccount.IsEmpty() && (ActiveAccountType == "CardDAV" ||
3205                 ActiveAccountType == "carddav" ||
3206                 ActiveAccountType == "Local" ||
3207                 ActiveAccountType == "local")){
3209                 EnableRefresh = TRUE;
3210         
3211         }
3213         ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
3215         this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
3219 void frmMain::ResetContactInfo(){
3221         // Reset the contact information to an empty page.
3222         
3223         wxString EmptyPage = wxT("");
3224         htmContactData->SetPage(EmptyPage);
3225         AccCtrl->SetValue("");
3226         
3229 bool frmMain::CloseAllWindows()
3231         // Attempt to close all windows.
3232         
3233         if (WindowListPointersMenu.size() == 0)
3234         {
3235                 return true;
3236         }
3237         
3238         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)
3239         {
3240                 for(std::map<int, void*>::iterator windowIter = WindowListPointers.begin();
3241                         windowIter != WindowListPointers.end(); windowIter++)
3242                 {
3243                         wxWindow *windowPointer = static_cast<wxWindow*>(windowIter->second);
3244                         windowPointer->Close();
3245                 }
3246                 return true;
3247         }
3248         else
3249         {
3250                 return false;
3251         }
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