Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Win32 Support: Added initial Windows support for frmMain
[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, 8, 8, 8 };
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(""));
267     
268         imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
269         imgConnStatus->SetBitmap(*imgOnline);
270         imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
271     
272         imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
273         imgSSLStatus->SetBitmap(*imgNoSSL);
274         imgSSLStatus->SetToolTip(SSLToolTip);
275         imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
276     
277         imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
278         imgActivityStatus->SetBitmap(*imgActIconSleep);
279         imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
280     
281         // Setup the window menu.
282     
283         // By default should be:
284     
285         // Contact windows:
286         // (none)
287         // (horizontal line)
288         // Contact editor windows:
289         // (none)
290         // (horizontal line)
291         // Search windows:
292         // (none)
293     
294         mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
295         mnuWindow->Append( mnuContactWindows );
296     
297         mnuWindow->AppendSeparator();
298     
299         mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
300         mnuWindow->Append( mnuContactEditorWindows );
301     
302         mnuWindow->AppendSeparator();
303     
304         mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
305         mnuWindow->Append( mnuSearchWindows );
306     
307 #if defined(__WIN32__)
308     
309         wxFont fontstyle;
310         fontstyle.Bold();
311     
312         mnuContactWindows->SetFont(fontstyle);
313         mnuContactEditorWindows->SetFont(fontstyle);
314         mnuSearchWindows->SetFont(fontstyle);
315     
316 #else
317     
318         mnuContactWindows->Enable(FALSE);
319         mnuContactEditorWindows->Enable(FALSE);
320         mnuSearchWindows->Enable(FALSE);
321     
322 #endif
323     
324         // Hide unimplemented functions.
325     
326         mnuMain->Remove(3);
327     
330 void frmMain::QuitApp( wxCloseEvent& event )
333         // Run the QuitApp function.
335         QuitApp();
339 void frmMain::QuitApp( wxCommandEvent& event )
341     
342         // Run the QuitApp function.
343     
344         QuitApp();
345     
348 void frmMain::QuitApp()
351         // Function to run when quitting.
352     
353         //Go through the windows and close each one (be it search
354         //or contact editor). Abort if user wants to cancel.
355     
356         // Close the contact editor windows.
357     
358         // Close the contact windows.
359     
360         // Close the search windows.
361     
362         // Write out the ETag databases.
363     
364         // Save Preferences: Save the window position if that option is enabled.
365     
366         wxString SetFilename = GetUserPrefDir();
367     
368 #if defined(__HAIKU__)
369     
370     
371     
372 #elif defined(__WIN32__)
373     
374         SetFilename.Append(wxT("settings"));
375     
376 #else
377     
378         // *nix OSes
379     
380         SetFilename.Append(wxT("settings"));
381     
382 #endif
383     
384         wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
385     
386         bool SaveWindowPos = FALSE;
387         wxString SaveWindowInc;
388         cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
389     
390         if (SaveWindowInc == wxT("true")){
391         
392                 SaveWindowPos = TRUE;
393         
394         }
395     
396         if (SaveWindowPos == TRUE){
397         
398                 wxRect frmMainPos = this->GetRect();
399         
400                 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
401                 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
402                 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
403                 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
404         
405         }
406     
407         delete cfgfile;
408         cfgfile = NULL;
409     
410         //Everything closed... exit.
411     
412         std::exit(0);
413     
414         Close();
415     
418 void frmMain::ShowActivityWindow( wxCommandEvent& event )
420     
421         // Open the activity manager window.
422     
423         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
424         frameActMgr->OpenWindow();
425         frameActMgr->Show();
426     
429 void frmMain::ShowAboutWindow( wxCommandEvent& event )
432         // Show the about window.
433     
434         frmAbout *frameAbout = new frmAbout ( this );
435         frameAbout->SetupAboutWindow();
436         frameAbout->ShowModal();
437         delete frameAbout;
438         frameAbout = NULL;
439     
442 void frmMain::OpenPreferences( wxCommandEvent& event)
445         // Open the preferences window.
446     
447         ReloadAccounts = FALSE;
448     
449         frmPreferences *framePreferences = new frmPreferences ( this );
450         framePreferences->SetupPointers(&ReloadAccounts);
451         framePreferences->ShowModal();
452         delete framePreferences;
453         framePreferences = NULL;
454     
455         if (ReloadAccounts == TRUE){
456         
457                 // Reload the accounts as a change has been made within
458                 // the application and clear the current contact information.
459         
460                 this->LoadPreferences();
461                 this->ResetContactInfo();
462         
463         }
464     
467 void frmMain::OpenNewABDialog( wxCommandEvent& event)
470         // Open the new account dialog.
471     
472         ReloadAccounts = FALSE;
473     
474         frmNewAccount *frameNewAccount = new frmNewAccount ( this );
475         frameNewAccount->SetupPointers(&ReloadAccounts);
476         frameNewAccount->ShowModal();
477         delete frameNewAccount;
478         frameNewAccount = NULL;
479         
480         if (ReloadAccounts == TRUE){
481             
482                 // Reload the accounts as a change has been made within
483                 // the application.
484         
485                 this->LoadPreferences();
487         }
488     
491 void frmMain::LoadContactList( wxTreeEvent& event )
493     
494         // Load the contact list.
495     
496         // Clear all existing variables.
497     
498         lstContacts->DeleteAllItems();
499     
500         treAccounts->SetAccount();
501     
502         wxTreeItemIdValue cookie;
503         wxTreeItemId next = treAccounts->GetRootItem();
504         wxString AccountName;
505         wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
506         wxString AccountDirCmb;
507         long selectedaccount = 0;
508     
509         wxTreeItemId selectedChild = treAccounts->GetSelection();
510         wxTreeItemId nextChild;
511     
512         wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
513         int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
514     
515         int SCImg = treAccounts->GetItemImage(selectedChild);
516         int AccountIndex = 0;
517     
518         bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
519     
520         // Process each account.
521     
522         for (int i = 0; i < prefaccounts.GetCount(); i++){
523         
524                 if (ActiveItemIcon == 2){
525             
526                         std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
527                         std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
528                         int ActiveAccountG = AGLiter->second;
529             
530                         if (i == ActiveAccountG){
531                 
532                                 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
533                                 AccountType.Append(prefaccounts.GetAccountType(i));
534                 
535                                 AccountDir.Trim();
536                                 AccountType.Trim();
537                 
538                                 if (AccountType == wxT("CardDAV")){
539                                         AccountTypeFinal.Append(wxT("carddav"));
540                                 } else if (AccountType == wxT("Local")){
541                                         imgSSLStatus->SetBitmap(*imgOffline);
542                                         SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
543                                         AccountTypeFinal.Append(wxT("local"));
544                                 }
545                 
546                                 AccountIndex = i;
547                                 break;
548                 
549                         }
550             
551                 }
552         
553                 if (!nextChild){
554                         nextChild = treAccounts->GetFirstChild(next, cookie);
555                 } else {
556                         nextChild = treAccounts->GetNextSibling(nextChild);
557                 }
558         
559                 AccountName = treAccounts->GetItemText(nextChild);
560         
561                 if (nextChild == selectedChild){
562                         
563                         AccountDir.Append(prefaccounts.GetAccountDirectory(i));
564                         AccountType.Append(prefaccounts.GetAccountType(i));
565             
566                         AccountDir.Trim();
567                         AccountType.Trim();
568             
569                         if (AccountType == wxT("CardDAV")){
570                                 AccountTypeFinal.Append(wxT("carddav"));
571                         } else if (AccountType == wxT("Local")){
572                                 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
573                                 AccountTypeFinal.Append(wxT("local"));
574                         }
575             
576                         AccountIndex = i;
577             
578                 }
579         
580         }
581     
582         if (selectedaccount >= prefaccounts.GetCount()){
583         
584                 // The account selected isn't there so return.
585         
586                 RevealWait = FALSE;
587         
588                 return;
589         
590         }
591     
592         // Open the directory and get the list of .vcf files
593         // in that directory.
594     
595         ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
596         ActiveAccountType = AccountType;
597     
598         SetupSSLStatus(AccountIndex);
599     
600         AccountDirFinal.Clear();
601         AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
602     
603         ContactsFileIndex.Clear();
604     
605         wxString vCardFilename;
606         wxString vCardFilenameFull;
607         wxString vCardDataString;
608         wxStringTokenizer vcardfileline;
609         wxString lwxs;
610         wxString setname, setvalue;
611         std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
612         std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
613         long ContactIndex = 1;
614         long ContactSeekPoint = 0;
615     
616         wxDir vcardaccdir(AccountDirFinal);
617     
618         // Get the wxTreeItemId and image icon and compare it to the list.
619     
620         if (ActiveItemIcon == AccountGrpID){
621         
622                 // It's a group so load the file containing the group and
623                 // get the members of the group.
624         
625                 vCard Group;
626                 wxString UIDCode;
627         
628                 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
629                 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
630        
631                 Group.LoadFile(AGFiter->second);
632         
633                 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
634         
635                 for (int i = 0; i < vCardMember.PropCount; i++){
636             
637                         vCardMember.PropValues[i].Trim();
638                         if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
639                 
640                                 wxString NewPropValue;
641                                 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
642                                 vCardMember.PropValues[i] = NewPropValue;
643                 
644                         }
645             
646                 }
647         
648                 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
649         
650                 while(ProcFiles){
651             
652                         if (vCardFilename.Right(4) == wxT(".vcf") ||
653                                 vCardFilename.Right(4) == wxT(".VCF") ||
654                                 vCardFilename.Right(5) == wxT(".vcard") ||
655                                 vCardFilename.Right(5) == wxT(".VCARD")){
656                 
657                                 vCard Person;
658                                 bool FoundMember = FALSE;
659                 
660                                 vCardFilenameFull.Append(AccountDirFinal);
661                                 vCardFilenameFull.Append(wxT("/"));
662                                 vCardFilenameFull.Append(vCardFilename);
663                 
664                                 Person.LoadFile(vCardFilenameFull);
665                 
666                                 UIDCode = Person.Get(wxT("UID"));
667                 
668                                 for (int i = 0; i < vCardMember.PropCount; i++){
669                     
670                                         if (vCardMember.PropValues[i] == UIDCode){
671                         
672                                                 FoundMember = TRUE;
673                         
674                                         }
676                                 }
677                 
678                                 if (FoundMember == FALSE){
679                     
680                                         vCardFilename.Clear();
681                                         vCardFilenameFull.Clear();
682                                         vCardDataString.Clear();
683                                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
684                                         continue;
685                     
686                                 }
687                 
688                                 if (Person.MeetBaseSpecification()){
689                     
690                                         if (SortMode == 1){
691                         
692                                                 // Split the name into sections.
693                         
694                                                 vCardDataString = Person.Get(wxT("N"));
695                         
696                                                 vCardName NameData = Person.GetName();
697                         
698                                                 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
699                         
700                                         } else if (SortMode == 2){
701                         
702                                                 // Split the name into sections.
703                         
704                                                 vCardName NameData = Person.GetName();
705                         
706                                                 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
707                         
708                                         } else if (SortMode == 3){
709                         
710                                                 // Check and make sure that the top most nickname is used.
711                         
712                                                 vCardDataString = Person.Get(wxT("NICKNAME"));
713                         
714                                                 if (vCardDataString.IsEmpty()){
715                             
716                                                         vCardDataString = wxT("(no nickname)");
717                             
718                                                 }
719                         
720                                         } else if (SortMode == 4){
721                         
722                                                 vCardDataString = Person.Get(wxT("FN"));
723                         
724                                         }
725                     
726                                         if (AscendingMode == TRUE){
727                                                 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
728                                         } else {
729                                                 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
730                                         }
731                     
732                                 }
733                 
734                         }
735             
736                         vCardFilename.Clear();
737                         vCardFilenameFull.Clear();
738                         vCardDataString.Clear();
739                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
740                         
741                 }
742         
743         } else {
744         
745                 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
746                 while(ProcFiles){
747             
748                         if (vCardFilename.Right(4) == wxT(".vcf") ||
749                                 vCardFilename.Right(4) == wxT(".VCF") ||
750                                 vCardFilename.Right(5) == wxT(".vcard") ||
751                                 vCardFilename.Right(5) == wxT(".VCARD")){
752                 
753                                 vCard Person;
754                 
755                                 vCardFilenameFull.Append(AccountDirFinal);
756                                 vCardFilenameFull.Append(vCardFilename);
757                 
758                                 Person.LoadFile(vCardFilenameFull);
759                 
760                                 if (Person.MeetBaseSpecification()){
761                     
762                                         if (SortMode == 1){
763                         
764                                                 // Split the name into sections.
765                         
766                                                 vCardDataString = Person.Get(wxT("N"));
767                         
768                                                 vCardName NameData = Person.GetName();
769                         
770                                                 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
771                         
772                                         } else if (SortMode == 2){
773                         
774                                                 // Split the name into sections.
775                         
776                                                 vCardName NameData = Person.GetName();
777                         
778                                                 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
779                         
780                                         } else if (SortMode == 3){
781                         
782                                                 // Check and make sure that the top most nickname is used.
783                         
784                                                 vCardDataString = Person.Get(wxT("NICKNAME"));
785                         
786                                                 if (vCardDataString.IsEmpty()){
787                             
788                                                         vCardDataString = wxT("(no nickname)");
789                             
790                                                 }
791                         
792                                         } else if (SortMode == 4){
793                         
794                                                 vCardDataString = Person.Get(wxT("FN"));
795                         
796                                         }
797                     
798                                         if (AscendingMode == TRUE){
799                                         
800                                                 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
801                                                 
802                                         } else {
803                                         
804                                                 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
805                                                 
806                                         }
807                     
808                                 }
809                 
810                         }
811             
812                         vCardFilename.Clear();
813                         vCardFilenameFull.Clear();
814                         vCardDataString.Clear();
815                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
816                 }
817         
818         }
819     
820         // Sort the data.
821     
822         // Insert the data into the control.
823     
824         if (AscendingMode == TRUE){
825                 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
826                         iter != vCardNamesAsc.end(); ++iter){
827             
828                         wxListItem ContactInfo;
829             
830                         ContactInfo.SetId(0);
831                         ContactInfo.SetText(_("Mooo"));
832                         ContactInfo.SetData(ContactSeekPoint);
833                         ContactIndex = lstContacts->InsertItem(ContactInfo);
834             
835                         lstContacts->SetItem(ContactIndex, 0, iter->first);
836             
837                         ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
838                         ContactSeekPoint++;
839             
840                 }
841         
842         } else {
843         
844                 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
845                      iter != vCardNamesDsc.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                         ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
856                         ContactSeekPoint++;
857             
858                 }
859         
860         }
861     
864 void frmMain::ShowContactInfo( wxListEvent& event )
866     
867         // Display the contact information.
868     
869         long intSelected = -1;
870         long ContactSeekNum = -1;
871     
872         // Check if several contacts have been selected.
873     
874         int ContactTotal = 0;
875     
876         for (;;){
877         
878                 intSelected = lstContacts->GetNextItem(intSelected,
879                         wxLIST_NEXT_ALL,
880                         wxLIST_STATE_SELECTED);
881         
882                 if (intSelected == -1){
883             
884                     break;
885             
886                 }
887         
888                 ContactTotal++;
889         
890         }
891     
892         if (ContactTotal == 0){
893                 htmContactData->SetPage(wxT(""));
894                 return;
895         }
896     
897         if (ContactTotal > 1){
898         
899                 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
900                 ActiveFilename.Clear();
901                 return;
902         
903         }
904     
905         intSelected = lstContacts->GetNextItem(intSelected,
906                 wxLIST_NEXT_ALL,
907                 wxLIST_STATE_SELECTED);
908     
909         ContactSeekNum = lstContacts->GetItemData(intSelected);
910     
911         wxFFile ContactFile;
912         wxString wxSContactString;
913         wxString ContactLine;
914         vCard Person;
915     
916         size_t ContactLineLen;
917         bool ExtraLineSeek = FALSE;
918         int QuoteBreakPoint = 0;
919     
920         bool PropertyFind = FALSE;
921         bool QuoteMode = FALSE;
922     
923         wxString wxSPropertyNextLine;
924         wxString wxSProperty;
925         wxString wxSPropertySeg1;
926         wxString wxSPropertySeg2;
927     
928         // Check if we are using wxWidgets version 2.8 or less and
929         // execute the required command accordingly.
930     
931 #if wxABI_VERSION < 20900
932         ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
933 #else
934         ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
935 #endif
936     
937         if (ContactFile.IsOpened() == FALSE){
938         
939                 return;
940         
941         }
942     
943         ContactFile.ReadAll(&wxSContactString, wxConvAuto());
944     
945         // Split the lines.
946     
947         std::map<int, wxString> ContactFileLines;
948         std::map<int, wxString>::iterator striter;
949     
950         wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
951     
952         int ContactLineSeek = 0;
953     
954         while (wSTContactFileLines.HasMoreTokens() == TRUE){
955         
956                 ContactLine = wSTContactFileLines.GetNextToken();
957                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
958                 ContactLineSeek++;
959         
960         }
961     
962         if (ContactSeekNum < 0){
963                 return;
964         }
965     
966         for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
967                 iter != ContactFileLines.end(); ++iter){
968         
969                 // Find the colon which splits the start bit from the data part.
970         
971                 ContactLine = iter->second;
972         
973                 while (ExtraLineSeek == TRUE){
974             
975                         // Check if there is extra data on the next line
976                         // (indicated by space or tab at the start) and add data.
977             
978                         iter++;
979             
980                         if (iter == ContactFileLines.end()){
981                 
982                                 iter--;
983                                 break;
984                 
985                         }
986             
987                         wxSPropertyNextLine = iter->second;
988             
989             
990                         if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
991                 
992                                 wxSPropertyNextLine.Remove(0, 1);
993                                 ContactLine.Append(wxSPropertyNextLine);
994                 
995                         } else {
996                 
997                                 iter--;
998                                 ExtraLineSeek = FALSE;
999                 
1000                         }
1001             
1002                 }
1003         
1004                 ContactLineLen = ContactLine.Len();
1005         
1006                 // Make sure we are not in quotation mode.
1007                 // Make sure colon does not have \ or \\ before it.
1008         
1009                 for (int i = 0; i <= ContactLineLen; i++){
1010             
1011                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1012                 
1013                                 PropertyFind = FALSE;
1014                 
1015                         } else if (PropertyFind == TRUE){
1016                 
1017                                 wxSProperty.Append(ContactLine.Mid(i, 1));
1018                 
1019                         }
1020             
1021                         if (ContactLine.Mid(i, 1) == wxT("\"")){
1022                 
1023                                 if (QuoteMode == TRUE){
1024                     
1025                                         QuoteMode = FALSE;
1026                     
1027                                 } else {
1028                     
1029                                         QuoteMode = TRUE;
1030                     
1031                                 }
1032                 
1033                         }
1034             
1035                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1036                 
1037                                 QuoteBreakPoint = i;
1038                                 break;
1039                 
1040                         }
1041             
1042                 }       
1043         
1044                 // Split that line at the point into two variables (ignore the colon).
1045         
1046                 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1047                 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1048         
1049                 // Insert both into the vCard data file.
1050         
1051                 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1052         
1053                 QuoteMode = FALSE;
1054                 PropertyFind = TRUE;
1055                 ExtraLineSeek = TRUE;
1056                 ContactLineLen = 0;
1057                 QuoteBreakPoint = 0;
1058                 ContactLine.Clear();
1059                 wxSProperty.Clear();
1060         
1061         }
1062     
1063         OldSessionID = SessionID;
1064         SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1065         LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1066         ActiveFilename = ContactsFileIndex[ContactSeekNum];
1067     
1070 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1072     
1073         // Open a contact editor window to write a new contact with.
1074     
1075         // Check if there is an account selected and if not
1076         // return immediately.
1077     
1078         if (ActiveAccount.IsEmpty()){
1079         
1080                 return;
1081         
1082         }
1083     
1084         // Add Pointer to SetupPointers for the ETagDB.
1085     
1086         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1087         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1088         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1089         wxIcon contacticon;
1090         contacticon.CopyFromBitmap(contacticonbmp);
1091     
1092         frmContactEditor *ContactEditor = new frmContactEditor( this );
1093     
1094         WindowMenuItemID++;
1095     
1096         ContactEditor->SetUID(WindowMenuItemID);
1097     
1098         WindowData *WData = new WindowData;
1099     
1100         WData->DataType = 1;
1101         WData->WindowPointer = (void*)ContactEditor;
1102         WData->WindowID = WindowMenuItemID;
1103     
1104         wxCommandEvent addevent(WINDOW_ADD);
1105         addevent.SetClientData(WData);
1106         wxPostEvent(this, addevent);
1107     
1108         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1109         ContactEditor->SetupHeaders();
1110         ContactEditor->SetupContact(ActiveAccount);
1111         ContactEditor->SetIcon(contacticon);
1112         ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1113         ContactEditor->Show(true);
1114     
1117 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1119     
1120         // Open a contact editor window for editing an existing contact
1121         // with.
1122     
1123         // Check if there is an account selected and if not
1124         // return immediately.
1125     
1126         int DataCheck = event.GetInt();
1127     
1128         if (ActiveAccount.IsEmpty() && DataCheck == 0){
1129         
1130                 return;
1131         
1132         }
1133     
1134         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1135         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1136         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1137         wxIcon contacticon;
1138         contacticon.CopyFromBitmap(contacticonbmp);
1139     
1140         // Check if a contact has been selected.
1141     
1142         long intSelected = -1;
1143         long intContactSeekNum = -1;
1144         
1145         intSelected = lstContacts->GetNextItem(intSelected,
1146                 wxLIST_NEXT_ALL,
1147                 wxLIST_STATE_SELECTED);
1148     
1149         if (intSelected == -1){
1150         
1151                 return;
1152                 
1153         }
1154     
1155         intContactSeekNum = lstContacts->GetItemData(intSelected);
1156     
1157         // Get the filename of the selected contact.
1158     
1159         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1160         frmContactEditor *ContactEditor = new frmContactEditor( this );
1161     
1162         WindowMenuItemID++;
1163     
1164         ContactEditor->SetUID(WindowMenuItemID);
1165     
1166         WindowData *WData = new WindowData;
1167     
1168         WData->DataType = 1;
1169         WData->WindowPointer = (void*)ContactEditor;
1170         WData->WindowID = WindowMenuItemID;
1171     
1172         wxCommandEvent addevent(WINDOW_ADD);
1173         addevent.SetClientData(WData);
1174         wxPostEvent(this, addevent);
1175     
1176         ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1177         ContactEditor->SetupHeaders();
1178     
1179         // Check if pointer is NULL (not from the search forms) or not.
1180     
1181         if (DataCheck == 0){
1182         
1183                 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1184                 ContactEditor->SetupContact(ActiveAccount);
1185         
1186         } else {
1187         
1188                 UCNotif *uc = (UCNotif*)event.GetClientData();
1189         
1190                 if (!uc){
1191             
1192                         ContactEditor->SetupContact(ActiveAccount);
1193                         ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1194             
1195                 } else {
1196             
1197                         ContactEditor->SetupContact(uc->ContactAccount);
1198                         ContactEditor->LoadContact(uc->ContactFilename);
1199             
1200                         delete uc;
1201                         uc = NULL;
1203                 }
1204         
1205         }
1206     
1207         ContactEditor->SetIcon(contacticon);
1208         ContactEditor->Show(true);
1209     
1212 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1214         // Refresh the address book data.
1215    
1216         // Check if ActiveAccount is empty. If not then check if
1217         // account type is not local otherwise continue.
1218     
1219         if (!ActiveAccount.IsEmpty()){
1220    
1221                 if (ActiveAccountType != wxT("Local")){
1222         
1223                         // Account type is not local.
1224         
1225                         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1226                         frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1227                                      wxT(""), wxT(""), wxT(""), wxT(""));
1228         
1229                 } else {
1230         
1231                         wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1232         
1233                 }
1234         
1235         }
1236     
1239 void frmMain::OpenContactInfoList( wxListEvent& event )
1241     
1242         // Open the contact information window.
1243     
1244         wxStringTokenizer vcardfileline;
1245         std::string l;
1246         wxString lwxs;
1247         wxString setname, setvalue;
1248         vCard Person;
1249         wxString nextchar;
1250     
1251         long intSelected = -1;
1252         long intContactSeekNum = -1;
1253     
1254         intSelected = lstContacts->GetNextItem(intSelected,
1255                 wxLIST_NEXT_ALL,
1256                 wxLIST_STATE_SELECTED);
1257     
1258         intContactSeekNum = lstContacts->GetItemData(intSelected);
1259     
1260         if (intContactSeekNum == -1){
1261         
1262                 return;
1263                 
1264         }
1265     
1266         Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1267     
1268         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1269         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1270         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1271         wxIcon contacticon;
1272         contacticon.CopyFromBitmap(contacticonbmp);
1273     
1274         frmContact *Contact = new frmContact( this );
1275     
1276         // Add to window list.
1277     
1278         WindowMenuItemID++;
1279     
1280         Contact->SetUID(WindowMenuItemID);
1281     
1282         WindowData *WData = new WindowData;
1283     
1284         WData->DataType = 0;
1285         WData->WindowPointer = (void*)Contact;
1286         WData->WindowID = WindowMenuItemID;
1287     
1288         wxCommandEvent addevent(WINDOW_ADD);
1289         addevent.SetClientData(WData);
1290         wxPostEvent(this, addevent);
1291     
1292         Contact->SetupPointers(&MemoryFileList);
1293         Contact->SetupContactData(&Person);
1294     
1295         Contact->SetIcon(contacticon);
1296         Contact->Show(true);
1297     
1300 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1302         // Open a list of contact information windows.
1304         wxListEvent pevent;
1305         OpenContactInfoList(pevent);
1309 void frmMain::OpenContactInfo( wxCommandEvent& event )
1312         // Open the contact information window.
1314         UCNotif *uc = (UCNotif*)event.GetClientData();
1315     
1316         wxStringTokenizer vcardfileline;
1317         std::string l;
1318         wxString lwxs;
1319         wxString setname, setvalue;
1320         vCard Person;
1321         wxString nextchar;
1322     
1323         Person.LoadFile(uc->ContactFilename);
1324     
1325         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1326         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1327         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1328         wxIcon contacticon;
1329         contacticon.CopyFromBitmap(contacticonbmp);
1330     
1331         frmContact *Contact = new frmContact( this );
1332     
1333         // Add to window list.
1334     
1335         WindowMenuItemID++;
1336     
1337         Contact->SetUID(WindowMenuItemID);
1338     
1339         WindowData *WData = new WindowData;
1340     
1341         WData->DataType = 0;
1342         WData->WindowPointer = (void*)Contact;
1343         WData->WindowID = WindowMenuItemID;
1344     
1345         wxCommandEvent addevent(WINDOW_ADD);
1346         addevent.SetClientData(WData);
1347         wxPostEvent(this, addevent);
1348     
1349         Contact->SetupPointers(&MemoryFileList);
1350         Contact->SetupContactData(&Person);
1351     
1352         Contact->SetIcon(contacticon);
1353         Contact->Show(true);
1354     
1358 void frmMain::LoadPreferences( wxActivateEvent& event)
1361         // Load the preferences.
1363         this->LoadPreferences();
1364         
1367 void frmMain::LoadPreferences(){
1368     
1369         // Load the preferences.
1370     
1371         wxString preffilename = GetUserPrefDir();
1372     
1373         XABPreferences preferences(preffilename);
1374     
1375         // Setup the main window position (if needed).
1376     
1377         bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1378         bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1379     
1380         if (SaveWindowPos == TRUE){
1381         
1382                 this->SetSize(preferences.GetMainWindowData());
1383         
1384         }
1385     
1386         treAccounts->DeleteAllItems();
1387     
1388         wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1389     
1390         // Stop all account timers and remove the accounts.
1391     
1392         for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1393                 iter != AccountSyncTimers.end(); iter++){
1394         
1395                 wxAccountSyncTimer *AccTmrPtr = iter->second;
1396                 AccTmrPtr->Stop();
1397         
1398                 delete AccTmrPtr;
1399                 AccTmrPtr = NULL;
1400         
1401         }
1402     
1403         AccountSyncTimers.clear();
1404         
1405         wxString AccDir;
1406         wxString AccDirFull;
1407         wxString AccDirFullSfx;
1408         wxString AccName;
1409         wxString AccDirFinal;
1410         AccountAccDirList.clear();
1411         AccountGroupList.clear();
1412         AccountGroupFilename.clear();
1413         AccountGroupTreeId.clear();
1414         wxTreeItemId AccountTreeId;
1415         wxTreeItemId GroupTreeId;
1416         int intGroupID = 0;
1417         
1418         // Relaod the accounts for the ETagProcTimer.
1419         
1420         ETagProcTimer.ReloadAccounts();
1421     
1422         for (int i = 0; i < preferences.accounts.GetCount(); i++){
1423         
1424                 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1425                         preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1426             
1427                         continue;
1428             
1429                 }
1430         
1431                 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1432             
1433                         continue;
1434             
1435                 }
1436         
1437                 AccDir = preferences.accounts.GetAccountDirectory(i);
1438                 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1439                 AccDirFull.Trim();
1440                 AccDirFull.Append(wxT("."));
1441                 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1442                 AccDirFullSfx.LowerCase();
1443                 AccDirFullSfx.Trim();
1444                 AccDirFull.Append(AccDirFullSfx);
1445                 AccName = preferences.accounts.GetAccountName(i);
1446                 AccName.Trim();
1447                 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1448         
1449                 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1450                         preferences.accounts.GetAccountType(i) == wxT("carddav")){
1451             
1452                         // TODO: Check if the directory exists before doing anything.
1453             
1454             
1455             
1456                         // Add a new timer using the existing account details.
1457             
1458                         wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1459             
1460                         ActTmrPtr->SetupData(AccDirFull, AccName);
1461                         ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1462                         ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1463                         ActTmrPtr->SetOwner(this);
1464                         ActTmrPtr->Notify();
1465             
1466                         // Add the timer to the list of timers.
1467             
1468                         AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1469             
1470                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1471             
1472                 } else {
1473             
1474                         AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1475             
1476                 }
1477         
1478                 // Go through the account directory and find contact files with
1479                 // 'KIND:group' set and add them to the list of groups for the account.
1480         
1481                 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1482         
1483                 wxDir vcardaccdir(AccDirFinal);
1484         
1485                 wxString vCardFilename;
1486                 wxString vCardDataString;
1487                 wxString vCardFilenameFull;
1489                 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1490         
1491                 while(ProcFiles){
1492             
1493                         if (vCardFilename.Right(4) == wxT(".vcf") ||
1494                                 vCardFilename.Right(4) == wxT(".VCF") ||
1495                                 vCardFilename.Right(5) == wxT(".vcard") ||
1496                                 vCardFilename.Right(5) == wxT(".VCARD")){
1497                 
1498                                 vCard Person;
1499                 
1500                                 vCardFilenameFull.Append(AccDirFinal);
1501                                 vCardFilenameFull.Append(wxT("/"));
1502                                 vCardFilenameFull.Append(vCardFilename);
1503                 
1504                                 Person.LoadFile(vCardFilenameFull);
1505                 
1506                                 if (Person.MeetBaseSpecification()){
1507                     
1508                                         vCardDataString = Person.Get(wxT("KIND"));
1509                     
1510                                         if (vCardDataString == wxT("group")){
1511                         
1512                                                 // The vCard kind is a group. Add to the account's group list.
1513                         
1514                                                 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1515                                                 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1516                                                 AccountGroupList.insert(std::make_pair(intGroupID, i));
1517                                                 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1518                                                 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1519                         
1520                                         }
1521                     
1522                                         intGroupID++;
1523                     
1524                                 }
1525                 
1526                         }
1527             
1528                         vCardFilename.Clear();
1529                         vCardFilenameFull.Clear();
1530                         vCardDataString.Clear();
1531                         ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1532             
1533                 }
1534         
1535                 // Clearup for next account.
1536         
1537                 AccDir.clear();
1538                 AccDirFull.clear();
1539                 AccDirFullSfx.clear();
1540                 AccDirFinal.clear();
1541                 AccName.clear();
1542         
1543         }
1544     
1545         // Load the account settings as they are needed for connecting
1546         // to the servers.
1547     
1548         prefaccounts = preferences.accounts;
1549     
1552 void frmMain::ConflictResolution(wxCommandEvent& event){
1553     
1554         // Display the conflict resolution window.
1555     
1556         frmConflictResolution *frameCR = new frmConflictResolution ( this );
1557         vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1558         vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1559         vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1560         frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1561         frameCR->ShowModal();
1562     
1563         int FinalConflictResult = frameCR->GetResult();
1564     
1565         wxCommandEvent event2(ACTMGR_RESUMEPROC);
1566         event2.SetClientData(vCardConfObj->QRNotifData);
1567         event2.SetInt(FinalConflictResult);
1568     
1569         delete frameCR;
1570         frameCR = NULL;
1571     
1572         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1573         wxPostEvent(frameActMgr, event2);
1574     
1577 void frmMain::UpdateContactList(wxCommandEvent& event){
1578     
1579         // Update the contact list in the main window.
1580     
1581         UCNotif *ucd = (UCNotif*)event.GetClientData();
1582     
1583         // Check if the active account is being displayed in the
1584         // main window. If not, skip and delete the data.
1585     
1586         long longSelected = -1;
1587         int intSelectedData = 0;
1588     
1589         if (ActiveAccount == ucd->ContactAccount){
1590         
1591                 // Look at the list of contacts and if it matches the
1592                 // filename then update the name.
1593         
1594                 for (;;){
1595             
1596                         longSelected = lstContacts->GetNextItem(longSelected,
1597                                 wxLIST_NEXT_ALL,
1598                                 wxLIST_STATE_DONTCARE);
1599             
1600                         if (longSelected == -1){
1601                 
1602                                 break;
1603                 
1604                         }
1605             
1606                         intSelectedData = (int)lstContacts->GetItemData(longSelected);
1607             
1608                         if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1609                 
1610                                 // Work out which sorting mode we are in.
1611                 
1612                                 if (SortMode == 1){
1613                     
1614                                         // First Name, Last Name.
1615                     
1616                                         lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1617                     
1618                                 } else if (SortMode == 2){
1619                     
1620                                         // Last Name, First Name.
1621                     
1622                                         lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1623                     
1624                                 } else if (SortMode == 3){
1625                     
1626                                         // Nickname.
1627                     
1628                                         lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1629                     
1630                                 } else if (SortMode == 4){
1631                     
1632                                         // Display As.
1633                     
1634                                         lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1635                     
1636                                 }
1637                 
1638                 
1639                         }
1640             
1641                         // If the filename is the one loaded into the
1642                         // browser control, then update this too.
1643             
1644                         if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1645                 
1646                                 wxListEvent nullevent;
1647                                 ShowContactInfo(nullevent);
1648                 
1649                         }
1650             
1651                 }
1652         
1653         }
1654     
1655         for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1656                 WindowIter != WindowListPointers.end(); WindowIter++){
1657         
1658                 if (WindowListType[WindowIter->first] != 0){
1659             
1660                         continue;
1661             
1662                 }
1663         
1664                 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1665         
1666                 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1667             
1668                         vCard UpdatedPerson;
1669                         UpdatedPerson.LoadFile(ucd->ContactFilename);
1670                         frmContactPtr->SetupContactData(&UpdatedPerson);
1671             
1672                 }
1673         
1674         }
1675     
1676         // Send message to search window controller subroutine and
1677         // pass that notification onto the search windows.
1678     
1679         // Setup the new pointer to use the existing UCNotif without
1680         // deleting it.
1681     
1682         UCNotif *ucd2 = ucd;
1683     
1684         wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1685         sup.SetClientData(ucd2);
1686         wxPostEvent(this, sup);
1687     
1688         // Clear up the unused pointer.
1689     
1690         ucd = NULL;
1691     
1694 void frmMain::UpdateAccountList(wxCommandEvent& event){
1695     
1696         // Update the account list (currently unimplemented).
1697     
1700 void frmMain::SetupPointers(void *ActMgrPtrInc){
1701     
1702         // Setup the pointers for the main window.
1703     
1704         ActMgrPtr = ActMgrPtrInc;
1705     
1708 void frmMain::SetupForm(){
1709     
1710         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1711         frameActMgr->SetupPointers(&ETagProcTimer, this);
1712     
1713         // Setup the contact information icons for later.
1714     
1715         wxFileSystem::AddHandler(new wxMemoryFSHandler);
1716         wxImage ciicon_png;
1717         //wxBitmap ciicon;
1718     
1719         wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1720         ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1721         wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1722     
1723         wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1724         ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1725         wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1726     
1727         wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1728         ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1729         wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1730     
1731         wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1732         ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1733         wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1734     
1735         wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1736         ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1737         wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1738     
1739         wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1740         ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1741         wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1742     
1743         LoadPreferences();
1744     
1747 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1748     
1749         // Update the contact lists in the search windows.
1750     
1751         // Go through each of the search windows and
1752         // send the required notification to update the
1753         // contact information.
1754     
1755         // Get the event notification data.
1756     
1757         UCNotif *ucd = (UCNotif*)event.GetClientData();
1758     
1759         // Process each search window giving the new details.
1760     
1761         for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1762                 switer != SearchWindowList.end(); switer++){
1763         
1764                 // Duplicate the event notification data.
1765         
1766                 UCNotif *ucd2 = new UCNotif;
1767         
1768                 ucd2->ContactAccount = ucd->ContactAccount;
1769                 ucd2->ContactFilename = ucd->ContactFilename;
1770                 ucd2->ContactName = ucd->ContactName;
1771                 ucd2->ContactNickname = ucd->ContactNickname;
1772                 ucd2->ContactNameArray = ucd->ContactNameArray;
1773         
1774                 // Pass the data to the search window for processing.
1775         
1776                 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1777                 wxCommandEvent schupdate(SE_UPDATERESULT);
1778                 schupdate.SetClientData(ucd2);
1779                 wxPostEvent(frameSCH, schupdate);
1780         
1781                 // Clear up the pointer prior to variable deletion.
1782         
1783                 frameSCH = NULL;
1784         
1785         }
1786     
1787         delete ucd;
1788         ucd = NULL;
1789     
1792 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1793     
1794         // Open a new search window.
1795     
1796         WindowMenuItemID++;
1797     
1798         frmSearch *frameSCH = new frmSearch ( this );
1799         frameSCH->SetUID(WindowMenuItemID);
1800         frameSCH->Show(true);
1801     
1802         WindowData *WData = new WindowData;
1803     
1804         WData->DataType = 2;
1805         WData->WindowPointer = (void*)frameSCH;
1806         WData->WindowID = WindowMenuItemID;
1807     
1808         wxCommandEvent addevent(WINDOW_ADD);
1809         addevent.SetClientData(WData);
1810         wxPostEvent(this, addevent);
1811     
1812         // Add pointer to the list of open search windows.
1813     
1814         SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1815     
1816         WData = NULL;
1817     
1820 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1821     
1822         // Remove the pointer for a contact window from the
1823         // window list.
1824     
1825         void *frameSCH = (void*)event.GetClientData();
1826     
1827         SearchWindowList.erase(frameSCH);
1828     
1829         frameSCH = NULL;
1830     
1833 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1834     
1835         // Remove the pointer for a contact editor window from
1836         // the window list.
1837     
1838         void *frameSCH = (void*)event.GetClientData();
1839     
1840         SearchWindowList.erase(frameSCH);
1841     
1842         frameSCH = NULL;
1843     
1846 void frmMain::RevealContact(wxCommandEvent& event){
1847     
1848         // Reveal a contact in the main window.
1849     
1850         UCNotif *uc = (UCNotif*)event.GetClientData();
1851     
1852         // Switch the account to the one passed.
1853     
1854         wxTreeItemIdValue cookie;
1855         wxTreeItemId next = treAccounts->GetRootItem();
1856         wxTreeItemId nextChild;
1857     
1858         for (int i = 0; i < prefaccounts.GetCount(); i++){
1859         
1860                 if (!nextChild){
1861                         nextChild = treAccounts->GetFirstChild(next, cookie);
1862                 } else {
1863                         nextChild = treAccounts->GetNextSibling(nextChild);
1864                 }
1865                
1866                 if (uc->ContactAccount == AccountAccDirList[i]){
1867             
1868                 treAccounts->SelectItem(nextChild, TRUE);
1869                 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1870             
1871                 }
1872         
1873         }
1874     
1875         // Switch the contact to the one passed.
1876     
1877         long longSelected = -1;
1878         int intSelectedData = 0;
1879     
1880         for (;;){
1881         
1882                 longSelected = lstContacts->GetNextItem(longSelected,
1883                         wxLIST_NEXT_ALL,
1884                         wxLIST_STATE_DONTCARE);
1885         
1886                 if (longSelected == -1){
1887             
1888                         break;
1889             
1890                 }
1891         
1892                 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1893         
1894                 // Compare the filename with the one received.
1895                 // If they match then select it.
1896         
1897                 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1898             
1899                         // Select.
1900             
1901                         lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1902                         lstContacts->EnsureVisible(longSelected);
1903             
1904                 } else {
1905         
1906                         lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1907         
1908                 }
1909         
1910         }
1911     
1914 void frmMain::DeleteContact(wxCommandEvent& event){
1915     
1916         // Delete a contact from the main window.
1917     
1918         // Check if a contact is selected.
1919     
1920         long intSelected = -1;
1921         long intContactSeekNum = -1;
1922         wxString wxSContactName;
1923     
1924         intSelected = lstContacts->GetNextItem(intSelected,
1925                 wxLIST_NEXT_ALL,
1926                 wxLIST_STATE_SELECTED);
1927     
1928         if (intSelected == -1){
1929                 return;
1930         }
1931     
1932         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1933     
1934         // Get the item data of the contact.
1935     
1936         intContactSeekNum = lstContacts->GetItemData(intSelected);
1937     
1938         // Get the name of the contact.
1939     
1940         wxSContactName = lstContacts->GetItemText(intSelected);
1941     
1942         // Display a message confirming if the contact should
1943         // be deleted.
1944     
1945         int QuestionResponse;
1946     
1947         QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1948     
1949         if (QuestionResponse == wxNO){
1950         
1951                 // Exit the subroutine
1952         
1953                 return;
1954         
1955         }
1956     
1957         // Delete the contact.
1958     
1959         if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1960         
1961                 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1962                 return;
1963         
1964         }
1965     
1966         // Remove the contact from the list.
1967     
1968         lstContacts->DeleteItem(intSelected);
1969     
1970         // Update the search windows, removing the deleted
1971         // contact.
1972     
1973         UCNotif *ucd = new UCNotif;
1974     
1975         ucd->ContactAccount = ActiveAccount;
1976         ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1977     
1978         for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1979                 switer != SearchWindowList.end(); switer++){
1980         
1981                 // Duplicate the event notification data.
1982         
1983                 UCNotif *ucd2 = new UCNotif;
1984         
1985                 ucd2->ContactAccount = ucd->ContactAccount;
1986                 ucd2->ContactFilename = ucd->ContactFilename;
1987         
1988                 // Pass the data to the search window for processing.
1989         
1990                 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1991                 wxCommandEvent schdelete(SE_DELETERESULT);
1992                 schdelete.SetClientData(ucd2);
1993                 wxPostEvent(frameSCH, schdelete);
1994         
1995                 // Clear up the pointer prior to variable deletion.
1996         
1997                 frameSCH = NULL;
1998                 ucd2 = NULL;
1999         
2000         }
2001     
2002         // Clear the wxHTMLWindow.
2003     
2004         wxString EmptyPage = wxT("");
2005     
2006         htmContactData->SetPage(EmptyPage);
2007     
2008         wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2009     
2010         wxString wxSplitFilename;
2011         wxString wxSDataURL;
2012     
2013         while(wSTFilename.HasMoreTokens()){
2014         
2015                 wxSplitFilename = wSTFilename.GetNextToken();
2016         
2017         }
2018     
2019         if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2020         
2021                 // Update the ETagDB and mark it as deleted.
2022         
2023                 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2024         
2025                 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2026         
2027                 // Get the Data URL.
2028         
2029                 wxTreeItemIdValue cookie;
2030                 wxTreeItemId next = treAccounts->GetRootItem();
2031         
2032                 wxTreeItemId selectedChild = treAccounts->GetSelection();
2033                 wxTreeItemId nextChild;
2034         
2035                 for (int i = 0; i < prefaccounts.GetCount(); i++){
2036             
2037                         if (!nextChild){
2038                                 nextChild = treAccounts->GetFirstChild(next, cookie);
2039                         } else {
2040                                 nextChild = treAccounts->GetNextSibling(nextChild);
2041                         }
2042             
2043                         if (nextChild == selectedChild){
2044                         
2045                                 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2047                         }
2048             
2049                 }
2050         
2051                 // Add task to the activity monitor to delete the contact.
2052         
2053                 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2054         
2055         }
2056     
2057         // Clear the variable. Don't delete as it will mess things up.
2058     
2059         ContactsFileIndex[intContactSeekNum] = wxT("");
2060     
2061         delete ucd;
2062         ucd = NULL;
2066 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2067     
2068         // Display this message when the server information has changed
2069         // and it is empty.
2071         QRNotif *qrn = (QRNotif *)event.GetClientData();
2072     
2073         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);
2074     
2075         if (QResponse == wxNO){
2076         
2077                 return;
2078     
2079         }
2080     
2081         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2082         event2.SetInt(*qrn->QResponse);
2083         event2.SetClientData(qrn->PausePtr);
2084     
2085         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2086     
2087         wxPostEvent(frameActMgr, event2);
2088     
2091 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2092     
2093         // Remove the contact from the window after syncronising.
2094     
2095         // Check which account is currently active in the window.
2096         // If it is different from the one passed to this subroutine then
2097         // exit from the subroutine.
2098     
2099         if (Account != ActiveAccount){
2100                 return;
2101         }
2102     
2103         long longSelected = -1;
2104         int intSelectedData = 0;
2105     
2106         for (;;){
2107         
2108                 longSelected = lstContacts->GetNextItem(longSelected,
2109                         wxLIST_NEXT_ALL,
2110                         wxLIST_STATE_DONTCARE);
2111         
2112                 if (longSelected == -1){
2113             
2114                         break;
2115             
2116                 }
2117         
2118                 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2119         
2120                 // Compare the filename with the one received.
2121                 // If they match then select it.
2122         
2123                 if (ContactsFileIndex[intSelectedData] == Filename){
2124             
2125                         // Remove the contact from the window.
2126             
2127                         lstContacts->DeleteItem(intSelectedData);
2128             
2129                         // Check if contact is the selected contact in the HTML window and
2130                         // if it is then clear the window.
2131             
2132                         if (ActiveFilename == Filename){
2133                 
2134                                 wxString EmptyPage = wxT("");
2135                                 htmContactData->SetPage(EmptyPage);
2136                 
2137                         }
2138             
2139                         break;
2140             
2141                 }
2142         
2143         }
2144     
2149 void frmMain::SortFNLN( wxCommandEvent& event ) {
2150     
2151         // Sort first name then last name.
2152     
2153         wxTreeEvent NullEvent;
2154         SortMode = 1;
2155         LoadContactList(NullEvent);
2156     
2159 void frmMain::SortLNFN( wxCommandEvent& event ) {
2160     
2161         // Sort last name then first name.
2162     
2163         wxTreeEvent NullEvent;
2164         SortMode = 2;
2165         LoadContactList(NullEvent);
2166     
2169 void frmMain::SortNickname( wxCommandEvent& event ) {
2170     
2171         // Sort by nickname.
2172     
2173         wxTreeEvent NullEvent;
2174         SortMode = 3;
2175         LoadContactList(NullEvent);
2176     
2179 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2180     
2181         // Sort by Display As name.
2182     
2183         wxTreeEvent NullEvent;
2184         SortMode = 4;
2185         LoadContactList(NullEvent);
2186     
2189 void frmMain::SortAscending( wxCommandEvent& event ) {
2190     
2191         // Sort Ascending.
2192     
2193         wxTreeEvent NullEvent;
2194         AscendingMode = TRUE;
2195         LoadContactList(NullEvent);
2196     
2199 void frmMain::SortDescending( wxCommandEvent& event ) {
2200     
2201         // Sort Descending.
2202     
2203         wxTreeEvent NullEvent;
2204         AscendingMode = FALSE;
2205         LoadContactList(NullEvent);
2206     
2209 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2210     
2211         // Toggle the appearance of the status bar.
2212     
2213         if (stbBottom->IsShown() == TRUE){
2214         
2215                 stbBottom->Hide();
2216         
2217         } else {
2218         
2219                 stbBottom->Show();
2220         
2221         }
2222     
2223         this->Layout();
2224     
2227 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2228     
2229         // Display the activity icon.
2230     
2231         imgActivityStatus->SetBitmap(*imgActIcon1);
2232         ActivityIconStatus = 0;
2233     
2236 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2238         // Shuffle through the activity icons.
2239     
2240         switch (ActivityIconStatus){
2241             
2242                 case 0:
2243                         imgActivityStatus->SetBitmap(*imgActIcon1);
2244                         ActivityIconStatus = 1;
2245                         break;
2246                 case 1:
2247                         imgActivityStatus->SetBitmap(*imgActIcon2);
2248                         ActivityIconStatus = 2;
2249                         break;
2250                 case 2:
2251                         imgActivityStatus->SetBitmap(*imgActIcon3);
2252                         ActivityIconStatus = 3;
2253                         break;
2254                 case 3:
2255                         imgActivityStatus->SetBitmap(*imgActIcon4);
2256                         ActivityIconStatus = 0;
2257                         break;
2258                 default:
2259                         ActivityIconStatus = 0;
2260                             
2261         }
2262     
2265 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2266     
2267         // Display the sleep icon.
2268     
2269         imgActivityStatus->SetBitmap(*imgActIconSleep);
2270     
2273 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2274     
2275         // Set the placement of the status bar icons.
2276     
2277         if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2278         
2279                 return;
2280         
2281         }
2282     
2283         wxRect rectOnline;
2284         wxRect rectSSL;
2285         wxRect rectActivity;
2286         stbBottom->GetFieldRect(1, rectOnline);
2287         stbBottom->GetFieldRect(2, rectSSL);
2288         stbBottom->GetFieldRect(3, rectActivity);
2289     
2290         imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2291         imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2292         imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2293     
2296 XABViewMode frmMain::GetViewMode(){
2297     
2298         // Set the view mode of the contact list.
2299     
2300         XABViewMode xvm;
2301     
2302         xvm.SortMode = SortMode;
2303         xvm.AscendingMode = AscendingMode;
2304     
2305         return xvm;
2306     
2309 void frmMain::WindowAdd( wxCommandEvent &event ){
2310     
2311         // Add a window to the window list.
2312     
2313         WindowData *WData = (WindowData*)event.GetClientData();
2314     
2315         size_t pos;
2316     
2317         if (WData->DataType == 0){
2318         
2319                 // Contact Window
2320         
2321                 int intID = mnuContactWindows->GetId();
2322         
2323                 mnuWindow->FindChildItem(intID, &pos);
2324                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2325                 mnuNewItem->SetId(WData->WindowID);
2326                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2327                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2328                 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2329                 mnuWindow->Insert((pos + 1), mnuNewItem);
2330                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2331         
2332         } else if (WData->DataType == 1){
2333         
2334                 // Contact Editor Window
2335         
2336                 int intID = mnuContactEditorWindows->GetId();
2337         
2338                 mnuWindow->FindChildItem(intID, &pos);
2339                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2340                 mnuNewItem->SetId(WData->WindowID);
2341                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2342                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2343                 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2344                 mnuWindow->Insert((pos + 1), mnuNewItem);
2345                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2346         
2347         } else if (WData->DataType == 2){
2348         
2349                 // Search Window
2350         
2351                 int intID = mnuSearchWindows->GetId();
2352                 
2353                 mnuWindow->FindChildItem(intID, &pos);
2354                 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2355                 mnuNewItem->SetId(WData->WindowID);
2356                 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2357                 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2358                 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2359                 mnuWindow->Insert((pos + 1), mnuNewItem);
2360                 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2361         
2362         }
2363     
2364         delete WData;
2365         WData = NULL;
2366     
2369 void frmMain::WindowEdit( wxCommandEvent &event ){
2371         // Edit a window in the window list.
2372     
2373         WindowData *WData = (WindowData*)event.GetClientData();
2374     
2375         if (WData->DataType == 0){
2376         
2377                 // Get the window title and use that.
2378         
2379                 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2380         
2381                 wxString WindowTitle = frmContactPtr->GetTitle();
2382         
2383                 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2384         
2385                 MenuIter->second->SetItemLabel(WindowTitle);
2386                 
2387         } else if (WData->DataType == 1){
2388         
2389                 // Get the window title and use that.
2390         
2391                 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2392         
2393                 wxString WindowTitle = frmCEPtr->GetTitle();
2394         
2395                 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2396         
2397                 if (WindowTitle.IsEmpty()){
2398             
2399                         MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2400             
2401                 } else {
2402             
2403                         MenuIter->second->SetItemLabel(WindowTitle);
2404             
2405                 }
2406         
2407         }
2408     
2409         delete WData;
2410         WData = NULL;
2411     
2414 void frmMain::WindowDelete( wxCommandEvent &event ){
2415     
2416         // Delete a window from the window list.
2417     
2418         WindowData *WData = (WindowData*)event.GetClientData();
2419     
2420         std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2421     
2422         mnuWindow->Remove(MenuIter->second);
2423     
2424         delete MenuIter->second;
2425         MenuIter->second = NULL;
2426     
2427         WindowListPointersMenu.erase(WData->WindowID);
2428         WindowListPointers.erase(WData->WindowID);
2429         WindowListType.erase(WData->WindowID);
2430     
2431         delete WData;
2432         WData = NULL;
2433     
2436 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2437     
2438         // Show a contact window from the window list.
2439     
2440         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2441     
2442         frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2443     
2444         frmContactPtr->Show();
2445         frmContactPtr->Raise();
2446     
2449 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2450     
2451         // Show a contact editor window from the window list.
2452     
2453         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2454     
2455         frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2456     
2457         frmCEPtr->Show();
2458         frmCEPtr->Raise();
2459     
2462 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2463     
2464         // Show a search window from the window list.   
2465             
2466         std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2467     
2468         frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2469     
2470         frmSearchPtr->Show();
2471         frmSearchPtr->Raise();
2472     
2475 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2476     
2477         // Toggle the online/offline connection status.
2478     
2479         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2480         wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2481         wxPostEvent(frameActMgr, toggconn);
2482     
2485 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2486     
2487         // Check the account type before continuing.
2488     
2489         wxString SeekAccount;
2490         wxString AccTypeLower;
2491         wxString AccType;
2492         bool AccountSSL;
2493     
2494 #if defined(__APPLE__)
2496         std::map<int, SecTrustRef>::iterator SSLTrustIter;
2497         
2498         for (int i = 0; i < prefaccounts.GetCount(); i++){
2499                 
2500                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2501                 AccType.Append(prefaccounts.GetAccountType(i));
2502                 AccountSSL = prefaccounts.GetAccountSSL(i);
2503                 AccTypeLower = AccType.MakeLower();
2504                 SeekAccount.Append(wxT("."));
2505                 SeekAccount.Append(AccTypeLower);
2506                 
2507                 if (SeekAccount == ActiveAccount){
2508                         
2509                         if (AccTypeLower == wxT("local")){
2510                                 
2511                                 return;
2512                                 
2513                         }
2514                         
2515                         if (AccountSSL == false){
2516                                 
2517                                 return;
2518                                 
2519                         }
2520                         
2521                         SSLTrustIter = AccountTrustData.find(i);
2522                         
2523                         // Setup and display the form.
2524                         
2525                         DisplayCertificate(SSLTrustIter->second);
2526                         
2527                 }
2528                 
2529                 SeekAccount.Clear();
2530                 AccTypeLower.Clear();
2531                 AccType.clear();
2532                 
2533         }
2534     
2535 #else
2536     
2537         std::map<int, SSLCertCollection>::iterator SSLColIter;
2538         
2539         for (int i = 0; i < prefaccounts.GetCount(); i++){
2540         
2541                 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2542                 AccType.Append(prefaccounts.GetAccountType(i));
2543                 AccountSSL = prefaccounts.GetAccountSSL(i);
2544                 AccTypeLower = AccType.MakeLower();
2545                 SeekAccount.Append(wxT("."));
2546                 SeekAccount.Append(AccTypeLower);
2547         
2548                 if (SeekAccount == ActiveAccount){
2549             
2550                         if (AccTypeLower == wxT("local")){
2551                 
2552                                 return;
2553                 
2554                         }
2555             
2556                         if (AccountSSL == false){
2557                 
2558                                 return;
2559                 
2560                         }
2561             
2562                         SSLColIter = AccountSSLData.find(i);
2563             
2564                         SSLCertCollection SSLCertInfo = SSLColIter->second;
2565             
2566                         frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2567                         frameSSLCert->StartCertFrom(0);
2568                         frameSSLCert->SetupCerts(SSLCertInfo);
2569                         frameSSLCert->ShowModal();
2570             
2571                         delete frameSSLCert;
2572                         frameSSLCert = NULL;
2573             
2574                 }
2575         
2576                 SeekAccount.Clear();
2577                 AccTypeLower.Clear();
2578                 AccType.clear();
2579         
2580         }
2582 #endif
2583     
2586 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2587     
2588         // Check the account type before continuing.
2589     
2592 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2593     
2594         // Check the account type before continuing.
2595     
2598 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2599     
2600         if (event.GetInt() == 0){
2601         
2602                 imgConnStatus->SetBitmap(*imgOnline);
2603         
2604         } else {
2605         
2606                 imgConnStatus->SetBitmap(*imgOffline);
2607         
2608         }       
2609     
2612 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2613     
2614         // Display the form for showing an invalid SSL certificate.
2615     
2616         frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2617         SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2618         SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2619         wxString AccountName = SSLICNObj->AccountName;
2620         frameISC->LoadData(SSLCCData, AccountName);
2621         frameISC->ShowModal();
2622     
2623         int FinalConflictResult = frameISC->GetResult();
2624     
2625         wxCommandEvent event2(ACTMGR_RESUMEPROC);
2626         event2.SetClientData(SSLICNObj->QRNotifData);
2627         event2.SetInt(FinalConflictResult);
2628     
2629         delete frameISC;
2630         frameISC = NULL;
2631     
2632         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);  
2633         wxPostEvent(frameActMgr, event2);
2634         
2637 void frmMain::PauseAllTimers(){
2638     
2639         // Pause all the account timers.
2640     
2641         for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2642                 ASTiter != AccountSyncTimers.end(); ASTiter++){
2643         
2644                 ASTiter->second->Stop();
2645         
2646         }
2647     
2650 void frmMain::ResumeAllTimers(){
2651     
2652         // Resume all the account timers.
2653     
2654         for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2655                 ASTiter != AccountSyncTimers.end(); ASTiter++){
2656         
2657                 ASTiter->second->Start();
2658         
2659         }
2660     
2663 #if defined(__APPLE__)
2665 #elif defined(__WIN32__)
2667 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, CERT_CONTEXT CertificateContext){
2669         // Delete existing data.
2671         AccountCertificateData.erase(AccountID);
2672         AccountSSLResult.erase(AccountID);
2674         // Insert new data.
2676         AccountCertificateData.insert(std::make_pair(AccountID, CertificateContext));
2677         AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2681 #else
2683 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2684     
2685         // Delete existing data.
2686     
2687         AccountSSLData.erase(AccountID);
2688         AccountSSLResult.erase(AccountID);
2689     
2690         // Insert new data.
2691     
2692         AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2693         AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2694     
2697 #endif
2699 void frmMain::SetupSSLStatus( int AccountID ){
2700         
2701         // Check if account ID given is
2702         // the active account and if not, do nothing.
2703         
2704         wxString AccType;
2705         wxString AccTypeLower;
2706         
2707         AccType = prefaccounts.GetAccountType(AccountID);
2708         AccTypeLower = AccType.MakeLower();
2709         
2710         wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2711         AccTypeLower;
2712         
2713         if (AccountIDName != ActiveAccount){
2714                 
2715                 return;
2716                 
2717         }
2718         
2719         // Check if the account has SSL enabled.
2720         
2721         bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2722         
2723         if (SSLInUse == FALSE){
2724                 
2725                 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2726                 imgSSLStatus->SetBitmap(*imgNoSSL);
2727                 
2728         } else {
2729                 
2730                 // Get the SSL Collection Data.
2731                 
2732                 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2733                 
2734                 if (SSLResultIter->second == 1){
2735                         
2736                         imgSSLStatus->SetBitmap(*imgSSLWarning);
2737                         SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2738                                            prefaccounts.GetAccountName(AccountID) +
2739                                            wxT("' (Connection denied by user)\n\nDouble click for more information."));
2740                         
2741                 } else if (SSLResultIter->second == 0){
2742                         
2743                         imgSSLStatus->SetBitmap(*imgSSL);
2744                         SSLToolTip->SetTip(wxT("Account '") +
2745                                            prefaccounts.GetAccountName(AccountID) +
2746                                            wxT("' secured using SSL\n\nDouble click for more information."));
2747                         
2748                 }
2749                 
2750         }
2751         
2754 void frmMain::CheckUpdates( wxCommandEvent& event ){
2755     
2756         // Check for updates to Xestia Address Book.
2757     
2758         frmUpdate *frameUpdate = new frmUpdate ( this );
2759         frameUpdate->FetchData();
2760         frameUpdate->ShowModal();
2761     
2764 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2765     
2766         // Run the import contacts function.
2767     
2768         ImportRun(this);
2769     
2772 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2773     
2774         // Check if an account and at least one contact is selected
2775         // before continuing.
2776     
2777         wxArrayString ArrData;
2778     
2779         if (ActiveAccount.IsEmpty()){
2780         
2781                 return;
2782         
2783         }
2784     
2785         int ContactSelected = 0;
2786         int ContactsCollected = 0;
2787         long longSelected = -1;
2788     
2789         for (;;){
2790         
2791                 longSelected = lstContacts->GetNextItem(longSelected, 
2792                         wxLIST_NEXT_ALL,
2793                         wxLIST_STATE_SELECTED);
2794         
2795                 if (longSelected == -1){
2796             
2797                         break;
2798         
2799                 }
2800         
2801                 int FileID = (int)lstContacts->GetItemData(longSelected);
2802         
2803                 ArrData.Insert(ContactsFileIndex[FileID],
2804                        ContactsCollected, 1);
2805         
2806                 ContactSelected++;
2807         
2808         }
2809     
2810         if (ContactSelected == 0){
2811         
2812                 return;
2813         
2814         }
2815     
2816         // Run the export contacts system.
2817     
2818         ExportRun(this, &ArrData);
2819     
2822 void frmMain::GetListControl(wxListCtrl *lstContactsPtr, 
2823                              wxArrayString *ContactsFileIndexPtr){
2824     
2825         // Set the list control pointers.
2826     
2827         lstContactsPtr = lstContacts;
2828         ContactsFileIndexPtr = &ContactsFileIndex;
2829     
2832 void frmMain::GetSelectedList( wxCommandEvent& event ){
2833     
2834         // Get the array of contact filenames. 
2835     
2836         wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2837     
2838         // Process them into an array of files. 
2839     
2840         long longSelected = -1;
2841         int ContactsCollected = 0;
2842         wxString ContactFilename;
2843     
2844         for (;;){
2845         
2846                 longSelected = lstContacts->GetNextItem(longSelected, 
2847                         wxLIST_NEXT_ALL,
2848                         wxLIST_STATE_SELECTED);
2849         
2850                 if (longSelected == -1){
2851             
2852                         break;
2853             
2854                 }
2855         
2856                 // Get the file information and add to the list.
2857         
2858                 int FileID = (int)lstContacts->GetItemData(longSelected);
2859         
2860                 ArrData->Insert(ContactsFileIndex[FileID],
2861                         ContactsCollected, 1);
2862         
2863                 ContactsCollected++;
2864                 ContactFilename.Clear();        
2865         
2866         }
2867     
2868         event.SetInt(1);
2869     
2872 void frmMain::SyncAccount( wxCommandEvent& event ){
2873     
2874         // Syncronise the selected account.
2875     
2876         wxString AccNameInc = event.GetString();
2877     
2878         frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2879         frameActMgr->AddTask(3, wxT(""), AccNameInc, 
2880                 wxT(""), wxT(""), wxT(""), wxT(""));
2881     
2884 void frmMain::ShowHelp( wxCommandEvent& event ){
2885     
2886         // Based on the operating system, work out where 
2887         // the documentation should be.
2888     
2889 //#ifdef __APPLE__
2890     
2891 #if defined(__HAIKU__)
2892     
2893 #elif defined(__WIN32__)
2894     
2895     
2896     
2897 #else
2898     
2899         if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2900         
2901                 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2902                 return;
2903         
2904 #if XSDAB_RELEASE == 0
2905         
2906         } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2907         
2908                 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2909                 return;
2910         
2911 #endif 
2912         
2913         }
2914     
2915 #endif
2916     
2917 #if XSDAB_RELEASE == 0
2918     
2919         wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2920     
2921 #else
2922     
2923         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!"));
2924     
2925 #endif
2926     
2929 void frmMain::ShowImportResults( wxCommandEvent &event ){
2931         // Show the results of importing contacts.
2933         std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2935         frmImportResults *frmIR = new frmImportResults(this);
2936         frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
2937         frmIR->ShowModal();
2938                 
2939         delete frmIR;
2940         frmIR = NULL;
2941         
2942         delete ResultData;
2943         ResultData = NULL;
2947 void frmMain::ReloadContactList( wxCommandEvent &event ){
2949         // Check if the account name given is the current
2950         // account selected.
2952         if (ActiveAccount == event.GetString()){
2953         
2954                 wxTreeEvent NullEvent;
2955                 LoadContactList(NullEvent);
2956         
2957         }
2961 void frmMain::ShowContactMenu( wxMouseEvent& event ){
2963         // Show the contact menu when a right click occurs
2964         // in the contacts list.
2966         bool EnableRefresh = FALSE;
2968         if (!ActiveAccount.IsEmpty()){
2970                 EnableRefresh = TRUE;
2971         
2972         }
2974         ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
2976         this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
2980 void frmMain::ResetContactInfo(){
2982         // Reset the contact information to an empty page.
2983         
2984         wxString EmptyPage = wxT("");
2985         htmContactData->SetPage(EmptyPage);
2986         AccCtrl->SetValue("");
2987         
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