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