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