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

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy