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