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