Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented code to delete contact via ConnectionObject
[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;
2108                                 break;
2110                         }
2111             
2112                 }
2113         
2114                 // Add task to the activity monitor to delete the contact.
2115                 
2116                 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2117         
2118         }
2119     
2120         // Clear the variable. Don't delete as it will mess things up.
2121     
2122         ContactsFileIndex[intContactSeekNum] = wxT("");
2123     
2124         delete ucd;
2125         ucd = NULL;
2129 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2130     
2131         // Display this message when the server information has changed
2132         // and it is empty.
2134         QRNotif *qrn = (QRNotif *)event.GetClientData();
2135     
2136         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);
2137     
2138         if (QResponse == wxNO){
2139         
2140                 return;
2141     
2142         }
2143     
2144         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2145         event2.SetInt(*qrn->QResponse);
2146         event2.SetClientData(qrn->PausePtr);
2147     
2148         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2149     
2150         wxPostEvent(frameActMgr, event2);
2151     
2154 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2155     
2156         // Remove the contact from the window after syncronising.
2157     
2158         // Check which account is currently active in the window.
2159         // If it is different from the one passed to this subroutine then
2160         // exit from the subroutine.
2161     
2162         if (Account != ActiveAccount){
2163                 return;
2164         }
2165     
2166         long longSelected = -1;
2167         int intSelectedData = 0;
2168     
2169         for (;;){
2170         
2171                 longSelected = lstContacts->GetNextItem(longSelected,
2172                         wxLIST_NEXT_ALL,
2173                         wxLIST_STATE_DONTCARE);
2174         
2175                 if (longSelected == -1){
2176             
2177                         break;
2178             
2179                 }
2180         
2181                 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2182         
2183                 // Compare the filename with the one received.
2184                 // If they match then select it.
2185         
2186                 if (ContactsFileIndex[intSelectedData] == Filename){
2187             
2188                         // Remove the contact from the window.
2189             
2190                         lstContacts->DeleteItem(intSelectedData);
2191             
2192                         // Check if contact is the selected contact in the HTML window and
2193                         // if it is then clear the window.
2194             
2195                         if (ActiveFilename == Filename){
2196                 
2197                                 wxString EmptyPage = wxT("");
2198                                 htmContactData->SetPage(EmptyPage);
2199                 
2200                         }
2201             
2202                         break;
2203             
2204                 }
2205         
2206         }
2207     
2212 void frmMain::SortFNLN( wxCommandEvent& event ) {
2213     
2214         // Sort first name then last name.
2215     
2216         wxTreeEvent NullEvent;
2217         SortMode = 1;
2218         LoadContactList(NullEvent);
2219     
2222 void frmMain::SortLNFN( wxCommandEvent& event ) {
2223     
2224         // Sort last name then first name.
2225     
2226         wxTreeEvent NullEvent;
2227         SortMode = 2;
2228         LoadContactList(NullEvent);
2229     
2232 void frmMain::SortNickname( wxCommandEvent& event ) {
2233     
2234         // Sort by nickname.
2235     
2236         wxTreeEvent NullEvent;
2237         SortMode = 3;
2238         LoadContactList(NullEvent);
2239     
2242 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2243     
2244         // Sort by Display As name.
2245     
2246         wxTreeEvent NullEvent;
2247         SortMode = 4;
2248         LoadContactList(NullEvent);
2249     
2252 void frmMain::SortAscending( wxCommandEvent& event ) {
2253     
2254         // Sort Ascending.
2255     
2256         wxTreeEvent NullEvent;
2257         AscendingMode = TRUE;
2258         LoadContactList(NullEvent);
2259     
2262 void frmMain::SortDescending( wxCommandEvent& event ) {
2263     
2264         // Sort Descending.
2265     
2266         wxTreeEvent NullEvent;
2267         AscendingMode = FALSE;
2268         LoadContactList(NullEvent);
2269     
2272 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2273     
2274         // Toggle the appearance of the status bar.
2275     
2276         if (stbBottom->IsShown() == TRUE){
2277         
2278                 stbBottom->Hide();
2279         
2280         } else {
2281         
2282                 stbBottom->Show();
2283         
2284         }
2285     
2286         this->Layout();
2287     
2290 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2291     
2292         // Display the activity icon.
2293     
2294         imgActivityStatus->SetBitmap(*imgActIcon1);
2295         ActivityIconStatus = 0;
2296     
2299 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2301         // Shuffle through the activity icons.
2302     
2303         switch (ActivityIconStatus){
2304             
2305                 case 0:
2306                         imgActivityStatus->SetBitmap(*imgActIcon1);
2307                         ActivityIconStatus = 1;
2308                         break;
2309                 case 1:
2310                         imgActivityStatus->SetBitmap(*imgActIcon2);
2311                         ActivityIconStatus = 2;
2312                         break;
2313                 case 2:
2314                         imgActivityStatus->SetBitmap(*imgActIcon3);
2315                         ActivityIconStatus = 3;
2316                         break;
2317                 case 3:
2318                         imgActivityStatus->SetBitmap(*imgActIcon4);
2319                         ActivityIconStatus = 0;
2320                         break;
2321                 default:
2322                         ActivityIconStatus = 0;
2323                             
2324         }
2325     
2328 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2329     
2330         // Display the sleep icon.
2331     
2332         imgActivityStatus->SetBitmap(*imgActIconSleep);
2333     
2336 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2337     
2338         // Set the placement of the status bar icons.
2339     
2340         if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2341         
2342                 return;
2343         
2344         }
2345     
2346         wxRect rectOnline;
2347         wxRect rectSSL;
2348         wxRect rectActivity;
2349         stbBottom->GetFieldRect(1, rectOnline);
2350         stbBottom->GetFieldRect(2, rectSSL);
2351         stbBottom->GetFieldRect(3, rectActivity);
2352     
2353         imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2354         imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2355         imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2356     
2359 XABViewMode frmMain::GetViewMode(){
2360     
2361         // Set the view mode of the contact list.
2362     
2363         XABViewMode xvm;
2364     
2365         xvm.SortMode = SortMode;
2366         xvm.AscendingMode = AscendingMode;
2367     
2368         return xvm;
2369     
2372 void frmMain::WindowAdd( wxCommandEvent &event ){
2373     
2374         // Add a window to the window list.
2375     
2376         WindowData *WData = (WindowData*)event.GetClientData();
2377     
2378         size_t pos;
2379     
2380         if (WData->DataType == 0){
2381         
2382                 // Contact Window
2383         
2384                 int intID = mnuContactWindows->GetId();
2385         
2386                 mnuWindow->FindChildItem(intID, &pos);
2387                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2388                 mnuNewItem->SetId(WData->WindowID);
2389                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2390                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2391                 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2392                 mnuWindow->Insert((pos + 1), mnuNewItem);
2393                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2394         
2395         } else if (WData->DataType == 1){
2396         
2397                 // Contact Editor Window
2398         
2399                 int intID = mnuContactEditorWindows->GetId();
2400         
2401                 mnuWindow->FindChildItem(intID, &pos);
2402                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2403                 mnuNewItem->SetId(WData->WindowID);
2404                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2405                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2406                 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2407                 mnuWindow->Insert((pos + 1), mnuNewItem);
2408                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2409         
2410         } else if (WData->DataType == 2){
2411         
2412                 // Search Window
2413         
2414                 int intID = mnuSearchWindows->GetId();
2415                 
2416                 mnuWindow->FindChildItem(intID, &pos);
2417                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2418                 mnuNewItem->SetId(WData->WindowID);
2419                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2420                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2421                 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2422                 mnuWindow->Insert((pos + 1), mnuNewItem);
2423                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2424         
2425         }
2426     
2427         delete WData;
2428         WData = NULL;
2429     
2432 void frmMain::WindowEdit( wxCommandEvent &event ){
2434         // Edit a window in the window list.
2435     
2436         WindowData *WData = (WindowData*)event.GetClientData();
2437     
2438         if (WData->DataType == 0){
2439         
2440                 // Get the window title and use that.
2441         
2442                 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2443         
2444                 wxString WindowTitle = frmContactPtr->GetTitle();
2445         
2446                 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2447         
2448                 MenuIter->second->SetItemLabel(WindowTitle);
2449                 
2450         } else if (WData->DataType == 1){
2451         
2452                 // Get the window title and use that.
2453         
2454                 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2455         
2456                 wxString WindowTitle = frmCEPtr->GetTitle();
2457         
2458                 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2459         
2460                 if (WindowTitle.IsEmpty()){
2461             
2462                         MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2463             
2464                 } else {
2465             
2466                         MenuIter->second->SetItemLabel(WindowTitle);
2467             
2468                 }
2469         
2470         }
2471     
2472         delete WData;
2473         WData = NULL;
2474     
2477 void frmMain::WindowDelete( wxCommandEvent &event ){
2478     
2479         // Delete a window from the window list.
2480     
2481         WindowData *WData = (WindowData*)event.GetClientData();
2482     
2483         std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2484     
2485         mnuWindow->Remove(MenuIter->second);
2486     
2487         delete MenuIter->second;
2488         MenuIter->second = NULL;
2489     
2490         WindowListPointersMenu.erase(WData->WindowID);
2491         WindowListPointers.erase(WData->WindowID);
2492         WindowListType.erase(WData->WindowID);
2493     
2494         delete WData;
2495         WData = NULL;
2496     
2499 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2500     
2501         // Show a contact window from the window list.
2502     
2503         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2504     
2505         frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2506     
2507         frmContactPtr->Show();
2508         frmContactPtr->Raise();
2509     
2512 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2513     
2514         // Show a contact editor window from the window list.
2515     
2516         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2517     
2518         frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2519     
2520         frmCEPtr->Show();
2521         frmCEPtr->Raise();
2522     
2525 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2526     
2527         // Show a search window from the window list.   
2528             
2529         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2530     
2531         frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2532     
2533         frmSearchPtr->Show();
2534         frmSearchPtr->Raise();
2535     
2538 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2539     
2540         // Toggle the online/offline connection status.
2541     
2542         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2543         wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2544         wxPostEvent(frameActMgr, toggconn);
2545     
2548 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2549     
2550         // Check the account type before continuing.
2551     
2552         wxString SeekAccount;
2553         wxString AccTypeLower;
2554         wxString AccType;
2555         bool AccountSSL;
2556     
2557 #if defined(__APPLE__)
2559         std::map<int, SecTrustRef>::iterator SSLTrustIter;
2560         
2561         for (int i = 0; i < prefaccounts.GetCount(); i++){
2562                 
2563                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2564                 AccType.Append(prefaccounts.GetAccountType(i));
2565                 AccountSSL = prefaccounts.GetAccountSSL(i);
2566                 AccTypeLower = AccType.MakeLower();
2567                 SeekAccount.Append(wxT("."));
2568                 SeekAccount.Append(AccTypeLower);
2569                 
2570                 if (SeekAccount == ActiveAccount){
2571                         
2572                         if (AccTypeLower == wxT("local")){
2573                                 
2574                                 return;
2575                                 
2576                         }
2577                         
2578                         if (AccountSSL == false){
2579                                 
2580                                 return;
2581                                 
2582                         }
2583                         
2584                         SSLTrustIter = AccountTrustData.find(i);
2585                         
2586                         // Setup and display the form.
2587                         
2588                         DisplayCertificate(SSLTrustIter->second);
2589                         
2590                 }
2591                 
2592                 SeekAccount.Clear();
2593                 AccTypeLower.Clear();
2594                 AccType.clear();
2595                 
2596         }
2597    
2598 #elif defined(__WIN32__)
2600         std::map<int, PCCERT_CONTEXT>::iterator SSLCertificateIter;
2602         for (int i = 0; i < prefaccounts.GetCount(); i++){
2604                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2605                 AccType.Append(prefaccounts.GetAccountType(i));
2606                 AccountSSL = prefaccounts.GetAccountSSL(i);
2607                 AccTypeLower = AccType.MakeLower();
2608                 SeekAccount.Append(wxT("."));
2609                 SeekAccount.Append(AccTypeLower);
2611                 if (SeekAccount == ActiveAccount){
2613                         if (AccTypeLower == wxT("local")){
2615                                 return;
2617                         }
2619                         if (AccountSSL == false){
2621                                 return;
2623                         }
2625                         SSLCertificateIter = AccountCertificateData.find(i);
2627                         // Setup and display the form.
2629                         if (SSLCertificateIter->second->pCertInfo == NULL){
2631                                 wxMessageBox("No certificate information is available due to invalid connection details, connection being in progress or invalid certificate data received.");
2633                         } else {
2635                                 BOOL ModifiedCertificateData;
2636                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(SSLCertificateIter->second, (HWND)this->GetHandle());
2638                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
2639                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
2640                                 }
2642                         }
2644                         //DisplayCertificate(SSLTrustIter->second);
2646                 }
2648                 SeekAccount.Clear();
2649                 AccTypeLower.Clear();
2650                 AccType.clear();
2652         }
2654 #else
2655     
2656         std::map<int, SSLCertCollection>::iterator SSLColIter;
2657         
2658         for (int i = 0; i < prefaccounts.GetCount(); i++){
2659         
2660                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2661                 AccType.Append(prefaccounts.GetAccountType(i));
2662                 AccountSSL = prefaccounts.GetAccountSSL(i);
2663                 AccTypeLower = AccType.MakeLower();
2664                 SeekAccount.Append(wxT("."));
2665                 SeekAccount.Append(AccTypeLower);
2666         
2667                 if (SeekAccount == ActiveAccount){
2668             
2669                         if (AccTypeLower == wxT("local")){
2670                 
2671                                 return;
2672                 
2673                         }
2674             
2675                         if (AccountSSL == false){
2676                 
2677                                 return;
2678                 
2679                         }
2680             
2681                         SSLColIter = AccountSSLData.find(i);
2682             
2683                         SSLCertCollection SSLCertInfo = SSLColIter->second;
2684             
2685                         frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2686                         frameSSLCert->StartCertFrom(0);
2687                         frameSSLCert->SetupCerts(SSLCertInfo);
2688                         frameSSLCert->ShowModal();
2689             
2690                         delete frameSSLCert;
2691                         frameSSLCert = NULL;
2692             
2693                 }
2694         
2695                 SeekAccount.Clear();
2696                 AccTypeLower.Clear();
2697                 AccType.clear();
2698         
2699         }
2701 #endif
2702     
2705 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2706     
2707         // Check the account type before continuing.
2708     
2711 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2712     
2713         // Check the account type before continuing.
2714     
2717 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2718     
2719         if (event.GetInt() == 0){
2720         
2721                 imgConnStatus->SetBitmap(*imgOnline);
2722         
2723         } else {
2724         
2725                 imgConnStatus->SetBitmap(*imgOffline);
2726         
2727         }       
2728     
2731 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2732     
2733         // Display the form for showing an invalid SSL certificate.
2734     
2735         frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2736         SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2737         SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2738         wxString AccountName = SSLICNObj->AccountName;
2739         frameISC->LoadData(SSLCCData, AccountName);
2740         frameISC->ShowModal();
2741     
2742         int FinalConflictResult = frameISC->GetResult();
2743     
2744         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2745         event2.SetClientData(SSLICNObj->QRNotifData);
2746         event2.SetInt(FinalConflictResult);
2747     
2748         delete frameISC;
2749         frameISC = NULL;
2750     
2751         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);  
2752         wxPostEvent(frameActMgr, event2);
2753         
2756 void frmMain::InvalidSSLCertificateString( wxCommandEvent &event ){
2757     
2758         // Display the form for showing an invalid SSL certificate.
2759     
2760         frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2761         SSLInvalidCertNotifObjString *SSLICNObj = (SSLInvalidCertNotifObjString*)event.GetClientData();
2762         SSLCertCollectionString SSLCCData = SSLICNObj->CertCollection;
2763         wxString AccountName = SSLICNObj->AccountName;
2764         frameISC->LoadData(SSLCCData, AccountName);
2765         frameISC->ShowModal();
2766     
2767         int FinalConflictResult = frameISC->GetResult();
2768     
2769         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2770         event2.SetClientData(SSLICNObj->QRNotifData);
2771         event2.SetInt(FinalConflictResult);
2772     
2773         delete frameISC;
2774         frameISC = NULL;
2775     
2776         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);  
2777         wxPostEvent(frameActMgr, event2);
2778         
2781 void frmMain::PauseAllTimers(){
2782     
2783         // Pause all the account timers.
2784     
2785         for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2786                 ASTiter != AccountSyncTimers.end(); ASTiter++){
2787         
2788                 ASTiter->second->Stop();
2789         
2790         }
2791     
2794 void frmMain::ResumeAllTimers(){
2795     
2796         // Resume all the account timers.
2797     
2798         for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2799                 ASTiter != AccountSyncTimers.end(); ASTiter++){
2800         
2801                 ASTiter->second->Start();
2802         
2803         }
2804     
2807 #if defined(__APPLE__)
2809 #elif defined(__WIN32__)
2811 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEXT CertificateContext){
2813         // Delete existing data.
2815         std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.find(AccountID);
2817         if (CertificateIter != AccountCertificateData.end()){
2818                 CertFreeCertificateContext(CertificateIter->second);
2819         }
2821         AccountCertificateData.erase(AccountID);
2822         AccountSSLResult.erase(AccountID);
2824         // Insert new data.
2826         AccountCertificateData.insert(std::make_pair(AccountID, CertificateContext));
2827         AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2831 #else
2833 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2834     
2835         // Delete existing data.
2836     
2837         AccountSSLData.erase(AccountID);
2838         AccountSSLResult.erase(AccountID);
2839     
2840         // Insert new data.
2841     
2842         AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2843         AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2844     
2847 #endif
2849 void frmMain::SetupSSLStatus( int AccountID ){
2850         
2851         // Check if account ID given is
2852         // the active account and if not, do nothing.
2853         
2854         wxString AccType;
2855         wxString AccTypeLower;
2856         
2857         AccType = prefaccounts.GetAccountType(AccountID);
2858         AccTypeLower = AccType.MakeLower();
2859         
2860         wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2861         AccTypeLower;
2862         
2863         if (AccountIDName != ActiveAccount){
2864                 
2865                 return;
2866                 
2867         }
2868         
2869         // Check the account type is a supported account type.
2870         
2871         if (AccType != "CardDAV" && AccType != "carddav" &&
2872                 AccType != "Local" && AccType != "local"){
2873         
2874                 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2875                 imgSSLStatus->SetBitmap(*imgNoSSL);
2876                 return;
2877                         
2878         }
2879         
2880         // Check if the account has SSL enabled.
2881         
2882         bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2883         
2884         if (SSLInUse == FALSE){
2885                 
2886                 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2887                 imgSSLStatus->SetBitmap(*imgNoSSL);
2888                 
2889         } else {
2890                 
2891                 // Get the SSL Collection Data.
2892                 
2893                 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2894                 
2895                 // Check if a result value has been set.
2897                 if (SSLResultIter == AccountSSLResult.end()){
2899                         imgSSLStatus->SetBitmap(*imgSSLWarning);
2900                         SSLToolTip->SetTip(wxT("Unable to determine SSL information for the '") + prefaccounts.GetAccountName(AccountID) + wxT("' account."));
2901                         return;
2903                 }
2905                 if (SSLResultIter->second == 1){
2906                         
2907                         imgSSLStatus->SetBitmap(*imgSSLWarning);
2908                         SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2909                                            prefaccounts.GetAccountName(AccountID) +
2910                                            wxT("' (Connection denied by user)\n\nDouble click for more information."));
2911                         
2912                 } else if (SSLResultIter->second == 0){
2913                         
2914                         imgSSLStatus->SetBitmap(*imgSSL);
2915                         SSLToolTip->SetTip(wxT("Account '") +
2916                                            prefaccounts.GetAccountName(AccountID) +
2917                                            wxT("' secured using SSL\n\nDouble click for more information."));
2918                         
2919                 }
2920                 
2921         }
2922         
2925 void frmMain::CheckUpdates( wxCommandEvent& event ){
2926     
2927         // Check for updates to Xestia Address Book.
2928     
2929         frmUpdate *frameUpdate = new frmUpdate ( this );
2930         frameUpdate->FetchData();
2931         frameUpdate->ShowModal();
2932     
2935 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2936     
2937         // Run the import contacts function.
2938     
2939         ImportRun(this);
2940     
2943 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2944     
2945         // Check if an account and at least one contact is selected
2946         // before continuing.
2947     
2948         wxArrayString ArrData;
2949     
2950         if (ActiveAccount.IsEmpty()){
2951         
2952                 return;
2953         
2954         }
2955     
2956         int ContactSelected = 0;
2957         int ContactsCollected = 0;
2958         long longSelected = -1;
2959     
2960         for (;;){
2961         
2962                 longSelected = lstContacts->GetNextItem(longSelected, 
2963                         wxLIST_NEXT_ALL,
2964                         wxLIST_STATE_SELECTED);
2965         
2966                 if (longSelected == -1){
2967             
2968                         break;
2969         
2970                 }
2971         
2972                 int FileID = (int)lstContacts->GetItemData(longSelected);
2973         
2974                 ArrData.Insert(ContactsFileIndex[FileID],
2975                        ContactsCollected, 1);
2976         
2977                 ContactSelected++;
2978         
2979         }
2980     
2981         if (ContactSelected == 0){
2982         
2983                 return;
2984         
2985         }
2986     
2987         // Run the export contacts system.
2988     
2989         ExportRun(this, &ArrData);
2990     
2993 void frmMain::GetListControl(wxListCtrl *lstContactsPtr, 
2994                              wxArrayString *ContactsFileIndexPtr){
2995     
2996         // Set the list control pointers.
2997     
2998         lstContactsPtr = lstContacts;
2999         ContactsFileIndexPtr = &ContactsFileIndex;
3000     
3003 void frmMain::GetSelectedList( wxCommandEvent& event ){
3004     
3005         // Get the array of contact filenames. 
3006     
3007         wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
3008     
3009         // Process them into an array of files. 
3010     
3011         long longSelected = -1;
3012         int ContactsCollected = 0;
3013         wxString ContactFilename;
3014     
3015         for (;;){
3016         
3017                 longSelected = lstContacts->GetNextItem(longSelected, 
3018                         wxLIST_NEXT_ALL,
3019                         wxLIST_STATE_SELECTED);
3020         
3021                 if (longSelected == -1){
3022             
3023                         break;
3024             
3025                 }
3026         
3027                 // Get the file information and add to the list.
3028         
3029                 int FileID = (int)lstContacts->GetItemData(longSelected);
3030         
3031                 ArrData->Insert(ContactsFileIndex[FileID],
3032                         ContactsCollected, 1);
3033         
3034                 ContactsCollected++;
3035                 ContactFilename.Clear();        
3036         
3037         }
3038     
3039         event.SetInt(1);
3040     
3043 void frmMain::SyncAccount( wxCommandEvent& event ){
3044     
3045         // Syncronise the selected account.
3046     
3047         wxString AccNameInc = event.GetString();
3048     
3049         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
3050         frameActMgr->AddTask(3, wxT(""), AccNameInc, 
3051                 wxT(""), wxT(""), wxT(""), wxT(""));
3052     
3055 void frmMain::ShowHelp( wxCommandEvent& event ){
3056     
3057         // Based on the operating system, work out where 
3058         // the documentation should be.
3059     
3060 //#ifdef __APPLE__
3061     
3062 #if defined(__HAIKU__)
3063     
3064 #elif defined(__WIN32__)
3065     
3066     
3067     
3068 #else
3069     
3070         if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
3071         
3072                 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
3073                 return;
3074         
3075 #if XSDAB_RELEASE == 0
3076         
3077         } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
3078         
3079                 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
3080                 return;
3081         
3082 #endif 
3083         
3084         }
3085     
3086 #endif
3087     
3088 #if XSDAB_RELEASE == 0
3089     
3090         wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
3091     
3092 #else
3093     
3094         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!"));
3095     
3096 #endif
3097     
3100 void frmMain::ShowImportResults( wxCommandEvent &event ){
3102         // Show the results of importing contacts.
3104         std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
3106         frmImportResults *frmIR = new frmImportResults(this);
3107         frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
3108         frmIR->ShowModal();
3109                 
3110         delete frmIR;
3111         frmIR = NULL;
3112         
3113         delete ResultData;
3114         ResultData = NULL;
3118 void frmMain::ReloadContactList( wxCommandEvent &event ){
3120         // Check if the account name given is the current
3121         // account selected.
3123         if (ActiveAccount == event.GetString()){
3124         
3125                 wxTreeEvent NullEvent;
3126                 LoadContactList(NullEvent);
3127         
3128         }
3132 void frmMain::ShowContactMenu( wxMouseEvent& event ){
3134         // Show the contact menu when a right click occurs
3135         // in the contacts list.
3137         bool EnableRefresh = FALSE;
3139         if (!ActiveAccount.IsEmpty() && (ActiveAccountType == "CardDAV" || ActiveAccountType == "carddav")){
3141                 EnableRefresh = TRUE;
3142         
3143         }
3145         ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
3147         this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
3151 void frmMain::ResetContactInfo(){
3153         // Reset the contact information to an empty page.
3154         
3155         wxString EmptyPage = wxT("");
3156         htmContactData->SetPage(EmptyPage);
3157         AccCtrl->SetValue("");
3158         
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