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