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