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