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