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