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