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