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