Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added signal for display the import results.
[xestiaab/.git] / source / frmMain.cpp
1 #include <iostream>
2 #include <algorithm>
3 #include <vector>
4 #include <thread>
6 #include <wx/wx.h>
7 #include <wx/tokenzr.h>
8 #include <wx/icon.h>
9 #include <wx/mstream.h>
10 #include <wx/fs_mem.h>
11 #include <wx/ffile.h>
12 #include <wx/filesys.h>
13 #include <wx/dir.h>
14 #include <wx/stdpaths.h>
15 #include <wx/fileconf.h>
16 //#include <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(wxT("/"));
764                 vCardFilenameFull.Append(vCardFilename);
765                 
766                 Person.LoadFile(vCardFilenameFull);
767                 
768                 if (Person.MeetBaseSpecification()){
769                     
770                     if (SortMode == 1){
771                         
772                         // Split the name into sections.
773                         
774                         vCardDataString = Person.Get(wxT("N"));
775                         
776                         vCardName NameData = Person.GetName();
777                         
778                         vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
779                         
780                     } else if (SortMode == 2){
781                         
782                         // Split the name into sections.
783                         
784                         vCardName NameData = Person.GetName();
785                         
786                         vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
787                         
788                     } else if (SortMode == 3){
789                         
790                         // Check and make sure that the top most nickname is used.
791                         
792                         vCardDataString = Person.Get(wxT("NICKNAME"));
793                         
794                         if (vCardDataString.IsEmpty()){
795                             
796                             vCardDataString = wxT("(no nickname)");
797                             
798                         }
799                         
800                     } else if (SortMode == 4){
801                         
802                         vCardDataString = Person.Get(wxT("FN"));
803                         
804                     }
805                     
806                     if (AscendingMode == TRUE){
807                         vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
808                     } else {
809                         vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
810                     }
811                     
812                 } else {
813                     
814                 }
815                 
816             }
817             
818             vCardFilename.Clear();
819             vCardFilenameFull.Clear();
820             vCardDataString.Clear();
821             ProcFiles = vcardaccdir.GetNext(&vCardFilename);
822         }
823         
824     }
825     
826     // Sort the data.
827     
828     // Insert the data into the control.
829     
830     if (AscendingMode == TRUE){
831         for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
832              iter != vCardNamesAsc.end(); ++iter){
833             
834             wxListItem ContactInfo;
835             
836             ContactInfo.SetId(0);
837             ContactInfo.SetText(_("Mooo"));
838             ContactInfo.SetData(ContactSeekPoint);
839             ContactIndex = lstContacts->InsertItem(ContactInfo);
840             
841             lstContacts->SetItem(ContactIndex, 0, iter->first);
842             ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
843             ContactSeekPoint++;
844             
845         }
846         
847     } else {
848         
849         for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
850              iter != vCardNamesDsc.end(); ++iter){
851             
852             wxListItem ContactInfo;
853             
854             ContactInfo.SetId(0);
855             ContactInfo.SetText(_("Mooo"));
856             ContactInfo.SetData(ContactSeekPoint);
857             ContactIndex = lstContacts->InsertItem(ContactInfo);
858             
859             lstContacts->SetItem(ContactIndex, 0, iter->first);
860             ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
861             ContactSeekPoint++;
862             
863         }
864         
865     }
866     
869 void frmMain::ShowContactInfo( wxListEvent& event )
871     
872     long intSelected = -1;
873     long ContactSeekNum = -1;
874     
875     //    intSelected = lstContacts->GetSelection();
876     
877     // Check if several contacts have been selected.
878     
879     int ContactTotal = 0;
880     
881     for (;;){
882         
883         intSelected = lstContacts->GetNextItem(intSelected,
884                                                wxLIST_NEXT_ALL,
885                                                wxLIST_STATE_SELECTED);
886         
887         if (intSelected == -1){
888             
889             break;
890             
891         }
892         
893         ContactTotal++;
894         
895     }
896     
897     if (ContactTotal == 0){
898         htmContactData->SetPage(wxT(""));
899         return;
900     }
901     
902     if (ContactTotal > 1){
903         
904         htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
905         ActiveFilename.Clear();
906         return;
907         
908     }
909     
910     intSelected = lstContacts->GetNextItem(intSelected,
911                                            wxLIST_NEXT_ALL,
912                                            wxLIST_STATE_SELECTED);
913     
914     ContactSeekNum = lstContacts->GetItemData(intSelected);
915     
916     wxFFile ContactFile;
917     wxString wxSContactString;
918     wxString ContactLine;
919     vCard Person;
920     
921     size_t ContactLineLen;
922     bool ExtraLineSeek = FALSE;
923     int QuoteBreakPoint = 0;
924     
925     bool PropertyFind = FALSE;
926     bool QuoteMode = FALSE;
927     
928     wxString wxSPropertyNextLine;
929     wxString wxSProperty;
930     wxString wxSPropertySeg1;
931     wxString wxSPropertySeg2;
932     
933     // Check if we are using wxWidgets version 2.8 or less and
934     // execute the required command accordingly.
935     
936 #if wxABI_VERSION < 20900
937     ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
938 #else
939     ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
940 #endif
941     
942     if (ContactFile.IsOpened() == FALSE){
943         
944         return;
945         
946     }
947     
948     ContactFile.ReadAll(&wxSContactString, wxConvAuto());
949     
950     // Split the lines.
951     
952     std::map<int, wxString> ContactFileLines;
953     std::map<int, wxString>::iterator striter;
954     
955     wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
956     
957     int ContactLineSeek = 0;
958     
959     while (wSTContactFileLines.HasMoreTokens() == TRUE){
960         
961         ContactLine = wSTContactFileLines.GetNextToken();
962         ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
963         ContactLineSeek++;
964         
965     }
966     
967     if (ContactSeekNum < 0){
968         return;
969     }
970     
971     for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
972          iter != ContactFileLines.end(); ++iter){
973         
974         // Find the colon which splits the start bit from the data part.
975         
976         ContactLine = iter->second;
977         
978         while (ExtraLineSeek == TRUE){
979             
980             // Check if there is extra data on the next line
981             // (indicated by space or tab at the start) and add data.
982             
983             iter++;
984             
985             if (iter == ContactFileLines.end()){
986                 
987                 iter--;
988                 break;
989                 
990             }
991             
992             wxSPropertyNextLine = iter->second;
993             
994             
995             if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
996                 
997                 wxSPropertyNextLine.Remove(0, 1);
998                 //wxSPropertyNextLine.Trim(FALSE);
999                 //ContactLine.Trim();
1000                 ContactLine.Append(wxSPropertyNextLine);
1001                 
1002             } else {
1003                 
1004                 iter--;
1005                 ExtraLineSeek = FALSE;
1006                 
1007             }
1008             
1009         }
1010         
1011         ContactLineLen = ContactLine.Len();
1012         
1013         // Make sure we are not in quotation mode.
1014         // Make sure colon does not have \ or \\ before it.
1015         
1016         for (int i = 0; i <= ContactLineLen; i++){
1017             
1018             if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1019                 
1020                 PropertyFind = FALSE;
1021                 
1022             } else if (PropertyFind == TRUE){
1023                 
1024                 wxSProperty.Append(ContactLine.Mid(i, 1));
1025                 
1026             }
1027             
1028             if (ContactLine.Mid(i, 1) == wxT("\"")){
1029                 
1030                 if (QuoteMode == TRUE){
1031                     
1032                     QuoteMode = FALSE;
1033                     
1034                 } else {
1035                     
1036                     QuoteMode = TRUE;
1037                     
1038                 }
1039                 
1040             }
1041             
1042             if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1043                 
1044                 QuoteBreakPoint = i;
1045                 break;
1046                 
1047             }
1048             
1049         }
1050         
1051         // Split that line at the point into two variables (ignore the colon).
1052         
1053         wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1054         wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1055         
1056         // Insert both into the vCard data file.
1057         
1058         Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1059         
1060         QuoteMode = FALSE;
1061         PropertyFind = TRUE;
1062         ExtraLineSeek = TRUE;
1063         ContactLineLen = 0;
1064         QuoteBreakPoint = 0;
1065         ContactLine.Clear();
1066         wxSProperty.Clear();
1067         
1068     }
1069     
1070     OldSessionID = SessionID;
1071     SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1072     LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1073     ActiveFilename = ContactsFileIndex[ContactSeekNum];
1074     
1077 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1079     
1080     // Check if there is an account selected and if not
1081     // return immediately.
1082     
1083     if (ActiveAccount.IsEmpty()){
1084         
1085         return;
1086         
1087     }
1088     
1089     // Add Pointer to SetupPointers for the ETagDB.
1090     
1091     wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1092     wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1093     wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1094     wxIcon contacticon;
1095     contacticon.CopyFromBitmap(contacticonbmp);
1096     
1097     frmContactEditor *ContactEditor = new frmContactEditor( this );
1098     
1099     WindowMenuItemID++;
1100     
1101     ContactEditor->SetUID(WindowMenuItemID);
1102     
1103     WindowData *WData = new WindowData;
1104     
1105     WData->DataType = 1;
1106     WData->WindowPointer = (void*)ContactEditor;
1107     WData->WindowID = WindowMenuItemID;
1108     
1109     wxCommandEvent addevent(WINDOW_ADD);
1110     addevent.SetClientData(WData);
1111     wxPostEvent(this, addevent);
1112     
1113     frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1114     ContactEditor->SetupHeaders();
1115     ContactEditor->SetupContact(ActiveAccount);
1116     ContactEditor->SetIcon(contacticon);
1117     ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1118     ContactEditor->Show(true);
1119     
1122 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1124     
1125     // Check if there is an account selected and if not
1126     // return immediately.
1127     
1128     int DataCheck = event.GetInt();
1129     
1130     if (ActiveAccount.IsEmpty() && DataCheck == 0){
1131         
1132         return;
1133         
1134     }
1135     
1136     wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1137     wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1138     wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1139     wxIcon contacticon;
1140     contacticon.CopyFromBitmap(contacticonbmp);
1141     
1142     // Check if a contact has been selected.
1143     
1144     long intSelected = -1;
1145     long intContactSeekNum = -1;
1146     
1147     //    intSelected = lstContacts->GetSelection();
1148     
1149     intSelected = lstContacts->GetNextItem(intSelected,
1150                                            wxLIST_NEXT_ALL,
1151                                            wxLIST_STATE_SELECTED);
1152     
1153     if (intSelected == -1){
1154         return;
1155     }
1156     
1157     intContactSeekNum = lstContacts->GetItemData(intSelected);
1158     
1159     // Get the filename of the selected contact.
1160     
1161     frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1162     frmContactEditor *ContactEditor = new frmContactEditor( this );
1163     
1164     WindowMenuItemID++;
1165     
1166     ContactEditor->SetUID(WindowMenuItemID);
1167     
1168     WindowData *WData = new WindowData;
1169     
1170     WData->DataType = 1;
1171     WData->WindowPointer = (void*)ContactEditor;
1172     WData->WindowID = WindowMenuItemID;
1173     
1174     wxCommandEvent addevent(WINDOW_ADD);
1175     addevent.SetClientData(WData);
1176     wxPostEvent(this, addevent);
1177     
1178     ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1179     ContactEditor->SetupHeaders();
1180     
1181     // Check if pointer is NULL (not from the search forms) or not.
1182     
1183     if (DataCheck == 0){
1184         
1185         ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1186         ContactEditor->SetupContact(ActiveAccount);
1187         
1188     } else {
1189         
1190         UCNotif *uc = (UCNotif*)event.GetClientData();
1191         
1192         if (!uc){
1193             
1194             ContactEditor->SetupContact(ActiveAccount);
1195             ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1196             
1197         } else {
1198             
1199             ContactEditor->SetupContact(uc->ContactAccount);
1200             ContactEditor->LoadContact(uc->ContactFilename);
1201             
1202             delete uc;
1203             uc = NULL;
1204             
1205             
1206         }
1207         
1208     }
1209     
1210     ContactEditor->SetIcon(contacticon);
1211     ContactEditor->Show(true);
1212     
1215 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1216    
1217     // Check if ActiveAccount is empty. If not then check if
1218     // account type is not local otherwise continue.
1219     
1220     if (!ActiveAccount.IsEmpty()){
1221    
1222         if (ActiveAccountType != wxT("Local")){
1223         
1224                 // Account type is not local.
1225         
1226                 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1227                 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1228                                      wxT(""), wxT(""), wxT(""), wxT(""));
1229         
1230         } else {
1231         
1232                 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1233         
1234         }
1235         
1236     }
1237     
1240 void frmMain::OpenContactInfo( wxListEvent& event )
1242     
1243     wxStringTokenizer vcardfileline;
1244     std::string l;
1245     wxString lwxs;
1246     wxString setname, setvalue;
1247     vCard Person;
1248     wxString nextchar;
1249     
1250     long intSelected = -1;
1251     long intContactSeekNum = -1;
1252     
1253     intSelected = lstContacts->GetNextItem(intSelected,
1254                                            wxLIST_NEXT_ALL,
1255                                            wxLIST_STATE_SELECTED);
1256     
1257     intContactSeekNum = lstContacts->GetItemData(intSelected);
1258     
1259     if (intContactSeekNum == -1){
1260         return;
1261     }
1262     
1263     Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1264     
1265     wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1266     wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1267     wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1268     wxIcon contacticon;
1269     contacticon.CopyFromBitmap(contacticonbmp);
1270     
1271     frmContact *Contact = new frmContact( this );
1272     
1273     // Add to window list.
1274     
1275     WindowMenuItemID++;
1276     
1277     Contact->SetUID(WindowMenuItemID);
1278     
1279     WindowData *WData = new WindowData;
1280     
1281     WData->DataType = 0;
1282     WData->WindowPointer = (void*)Contact;
1283     WData->WindowID = WindowMenuItemID;
1284     
1285     wxCommandEvent addevent(WINDOW_ADD);
1286     addevent.SetClientData(WData);
1287     wxPostEvent(this, addevent);
1288     
1289     Contact->SetupPointers(&MemoryFileList);
1290     Contact->SetupContactData(&Person);
1291     
1292     Contact->SetIcon(contacticon);
1293     Contact->Show(true);
1294     
1297 void frmMain::OpenContactInfo( wxCommandEvent& event )
1299     
1300     UCNotif *uc = (UCNotif*)event.GetClientData();
1301     
1302     wxStringTokenizer vcardfileline;
1303     std::string l;
1304     wxString lwxs;
1305     wxString setname, setvalue;
1306     vCard Person;
1307     wxString nextchar;
1308     //std::fstream vcardfile;
1309     
1310     Person.LoadFile(uc->ContactFilename);
1311     
1312     wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1313     wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1314     wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1315     wxIcon contacticon;
1316     contacticon.CopyFromBitmap(contacticonbmp);
1317     
1318     frmContact *Contact = new frmContact( this );
1319     
1320     // Add to window list.
1321     
1322     WindowMenuItemID++;
1323     
1324     Contact->SetUID(WindowMenuItemID);
1325     
1326     WindowData *WData = new WindowData;
1327     
1328     WData->DataType = 0;
1329     WData->WindowPointer = (void*)Contact;
1330     WData->WindowID = WindowMenuItemID;
1331     
1332     wxCommandEvent addevent(WINDOW_ADD);
1333     addevent.SetClientData(WData);
1334     wxPostEvent(this, addevent);
1335     
1336     Contact->SetupPointers(&MemoryFileList);
1337     Contact->SetupContactData(&Person);
1338     
1339     Contact->SetIcon(contacticon);
1340     Contact->Show(true);
1341     
1345 void frmMain::LoadPreferences( wxActivateEvent& event)
1347     this->LoadPreferences();
1350 void frmMain::LoadPreferences(){
1351     
1352     // Load the preferences.
1353     
1354     wxString preffilename = GetUserPrefDir();
1355     
1356     XABPreferences preferences(preffilename);
1357     
1358     // Setup the main window position (if needed).
1359     
1360     bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1361     bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1362     
1363     if (SaveWindowPos == TRUE){
1364         
1365         this->SetSize(preferences.GetMainWindowData());
1366         
1367     }
1368     
1369     treAccounts->DeleteAllItems();
1370     
1371     wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1372     
1373     // Stop all account timers and remove the accounts.
1374     
1375     for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1376          iter != AccountSyncTimers.end(); iter++){
1377         
1378         wxAccountSyncTimer *AccTmrPtr = iter->second;
1379         AccTmrPtr->Stop();
1380         
1381         delete AccTmrPtr;
1382         AccTmrPtr = NULL;
1383         
1384     }
1385     
1386     AccountSyncTimers.clear();
1387     
1388     /*
1389      for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
1390      treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
1391      }
1392      */
1393     
1394     wxString AccDir;
1395     wxString AccDirFull;
1396     wxString AccDirFullSfx;
1397     wxString AccName;
1398     wxString AccDirFinal;
1399     AccountAccDirList.clear();
1400     AccountGroupList.clear();
1401     AccountGroupFilename.clear();
1402     AccountGroupTreeId.clear();
1403     wxTreeItemId AccountTreeId;
1404     wxTreeItemId GroupTreeId;
1405     int intGroupID = 0;
1406     
1407     for (int i = 0; i < preferences.accounts.GetCount(); i++){
1408         
1409         if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1410              preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1411             
1412             continue;
1413             
1414         }
1415         
1416         if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1417             
1418             continue;
1419             
1420         }
1421         
1422         AccDir = preferences.accounts.GetAccountDirectory(i);
1423         AccDirFull = preferences.accounts.GetAccountDirectory(i);
1424         AccDirFull.Trim();
1425         AccDirFull.Append(wxT("."));
1426         AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1427         AccDirFullSfx.LowerCase();
1428         AccDirFullSfx.Trim();
1429         AccDirFull.Append(AccDirFullSfx);
1430         AccName = preferences.accounts.GetAccountName(i);
1431         AccName.Trim();
1432         AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1433         
1434         if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1435             preferences.accounts.GetAccountType(i) == wxT("carddav")){
1436             
1437             // Check if the directory exists before doing anything.
1438             
1439             
1440             
1441             // Add a new timer using the existing account details.
1442             
1443             wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1444             
1445             ActTmrPtr->SetupData(AccDirFull, AccName);
1446             ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1447             ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1448             ActTmrPtr->SetOwner(this);
1449             ActTmrPtr->Notify();
1450             
1451             // Add the timer to the list of timers.
1452             
1453             AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1454             
1455             AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1456             
1457         } else {
1458             
1459             AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1460             
1461         }
1462         
1463         // Go through the account directory and find contact files with
1464         // 'KIND:group' set and add them to the list of groups for the account.
1465         
1466         AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1467         
1468         wxDir vcardaccdir(AccDirFinal);
1469         
1470         wxString vCardFilename;
1471         wxString vCardDataString;
1472         wxString vCardFilenameFull;
1473         //bool ProcFiles = FALSE;
1474         
1475         bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1476         while(ProcFiles){
1477             
1478             if (vCardFilename.Right(4) == wxT(".vcf") ||
1479                 vCardFilename.Right(4) == wxT(".VCF") ||
1480                 vCardFilename.Right(5) == wxT(".vcard") ||
1481                 vCardFilename.Right(5) == wxT(".VCARD")){
1482                 
1483                 vCard Person;
1484                 
1485                 vCardFilenameFull.Append(AccDirFinal);
1486                 vCardFilenameFull.Append(wxT("/"));
1487                 vCardFilenameFull.Append(vCardFilename);
1488                 
1489                 Person.LoadFile(vCardFilenameFull);
1490                 
1491                 if (Person.MeetBaseSpecification()){
1492                     
1493                     vCardDataString = Person.Get(wxT("KIND"));
1494                     
1495                     if (vCardDataString == wxT("group")){
1496                         
1497                         // The vCard kind is a group. Add to the account's group list.
1498                         
1499                         GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1500                         treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1501                         AccountGroupList.insert(std::make_pair(intGroupID, i));
1502                         AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1503                         AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1504                         
1505                     }
1506                     
1507                     intGroupID++;
1508                     
1509                 } else {
1510                     
1511                 }
1512                 
1513             }
1514             
1515             vCardFilename.Clear();
1516             vCardFilenameFull.Clear();
1517             vCardDataString.Clear();
1518             ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1519             
1520         }
1521         
1522         // Clearup for next account.
1523         
1524         AccDir.clear();
1525         AccDirFull.clear();
1526         AccDirFullSfx.clear();
1527         AccDirFinal.clear();
1528         AccName.clear();
1529         
1530     }
1531     
1532     // Load the account settings as they are needed for connecting
1533     // to the servers.
1534     
1535     prefaccounts = preferences.accounts;
1536     
1539 void frmMain::ConflictResolution(wxCommandEvent& event){
1540     
1541     frmConflictResolution *frameCR = new frmConflictResolution ( this );
1542     vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1543     vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1544     vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1545     //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1546     //wxString Moo = ClientDataPtr->WriteString();
1547     //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1548     frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1549     //frameCR->LoadData(vCardConfObj->vCardLocalData, vCardConfObj->vCardServerData, &MemoryFileList);
1550     frameCR->ShowModal();
1551     
1552     int FinalConflictResult = frameCR->GetResult();
1553     
1554     wxCommandEvent event2(ACTMGR_RESUMEPROC);
1555     event2.SetClientData(vCardConfObj->QRNotifData);
1556     event2.SetInt(FinalConflictResult);
1557     
1558     delete frameCR;
1559     frameCR = NULL;
1560     
1561     frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1562     wxPostEvent(frameActMgr, event2);
1563     
1566 void frmMain::UpdateContactList(wxCommandEvent& event){
1567     
1568     UCNotif *ucd = (UCNotif*)event.GetClientData();
1569     
1570     // Check if the active account is being displayed in the
1571     // main window. If not, skip and delete the data.
1572     
1573     long longSelected = -1;
1574     int intSelectedData = 0;
1575     
1576     if (ActiveAccount == ucd->ContactAccount){
1577         
1578         // Look at the list of contacts and if it matches the
1579         // filename then update the name.
1580         
1581         for (;;){
1582             
1583             longSelected = lstContacts->GetNextItem(longSelected,
1584                                                     wxLIST_NEXT_ALL,
1585                                                     wxLIST_STATE_DONTCARE);
1586             
1587             if (longSelected == -1){
1588                 
1589                 break;
1590                 
1591             }
1592             
1593             intSelectedData = (int)lstContacts->GetItemData(longSelected);
1594             
1595             if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1596                 
1597                 // Work out which sorting mode we are in.
1598                 
1599                 if (SortMode == 1){
1600                     
1601                     // First Name, Last Name.
1602                     
1603                     lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1604                     
1605                 } else if (SortMode == 2){
1606                     
1607                     // Last Name, First Name.
1608                     
1609                     lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1610                     
1611                 } else if (SortMode == 3){
1612                     
1613                     // Nickname.
1614                     
1615                     lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1616                     
1617                 } else if (SortMode == 4){
1618                     
1619                     // Display As.
1620                     
1621                     lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1622                     
1623                 }
1624                 
1625                 
1626             }
1627             
1628             // If the filename is the one loaded into the
1629             // browser control, then update this too.
1630             
1631             if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1632                 
1633                 wxListEvent nullevent;
1634                 ShowContactInfo(nullevent);
1635                 
1636             }
1637             
1638         }
1639         
1640     }
1641     
1642     for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1643          WindowIter != WindowListPointers.end(); WindowIter++){
1644         
1645         if (WindowListType[WindowIter->first] != 0){
1646             
1647             continue;
1648             
1649         }
1650         
1651         frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1652         
1653         if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1654             
1655             vCard UpdatedPerson;
1656             UpdatedPerson.LoadFile(ucd->ContactFilename);
1657             frmContactPtr->SetupContactData(&UpdatedPerson);
1658             
1659         }
1660         
1661     }
1662     
1663     // Send message to search window controller subroutine and
1664     // pass that notification onto the search windows.
1665     
1666     // Setup the new pointer to use the existing UCNotif without
1667     // deleting it.
1668     
1669     UCNotif *ucd2 = ucd;
1670     
1671     wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1672     sup.SetClientData(ucd2);
1673     wxPostEvent(this, sup);
1674     
1675     // Clear up the unused pointer.
1676     
1677     ucd = NULL;
1678     
1681 void frmMain::UpdateAccountList(wxCommandEvent& event){
1682     
1685 void frmMain::SetupPointers(void *ActMgrPtrInc){
1686     
1687     ActMgrPtr = ActMgrPtrInc;
1688     
1691 void frmMain::SetupForm(){
1692     
1693     frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1694     frameActMgr->SetupPointers(&ETagProcTimer, this);
1695     
1696     // Setup the contact information icons for later.
1697     
1698     wxFileSystem::AddHandler(new wxMemoryFSHandler);
1699     wxImage ciicon_png;
1700     //wxBitmap ciicon;
1701     
1702     wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1703     ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1704     wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1705     
1706     wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1707     ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1708     wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1709     
1710     wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1711     ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1712     wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1713     
1714     wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1715     ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1716     wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1717     
1718     wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1719     ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1720     wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1721     
1722     wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1723     ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1724     wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1725     
1726     LoadPreferences();
1727     
1730 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1731     
1732     // Go through each of the search windows and
1733     // send the required notification to update the
1734     // contact information.
1735     
1736     // Get the event notification data.
1737     
1738     UCNotif *ucd = (UCNotif*)event.GetClientData();
1739     
1740     // Process each search window giving the new details.
1741     
1742     for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1743          switer != SearchWindowList.end(); switer++){
1744         
1745         // Duplicate the event notification data.
1746         
1747         UCNotif *ucd2 = new UCNotif;
1748         
1749         ucd2->ContactAccount = ucd->ContactAccount;
1750         ucd2->ContactFilename = ucd->ContactFilename;
1751         ucd2->ContactName = ucd->ContactName;
1752         ucd2->ContactNickname = ucd->ContactNickname;
1753         ucd2->ContactNameArray = ucd->ContactNameArray;
1754         
1755         // Pass the data to the search window for processing.
1756         
1757         frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1758         wxCommandEvent schupdate(SE_UPDATERESULT);
1759         schupdate.SetClientData(ucd2);
1760         wxPostEvent(frameSCH, schupdate);
1761         
1762         // Clear up the pointer prior to variable deletion.
1763         
1764         frameSCH = NULL;
1765         
1766     }
1767     
1768     delete ucd;
1769     ucd = NULL;
1770     
1773 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1774     
1775     WindowMenuItemID++;
1776     
1777     frmSearch *frameSCH = new frmSearch ( this );
1778     frameSCH->SetUID(WindowMenuItemID);
1779     frameSCH->Show(true);
1780     
1781     WindowData *WData = new WindowData;
1782     
1783     WData->DataType = 2;
1784     WData->WindowPointer = (void*)frameSCH;
1785     WData->WindowID = WindowMenuItemID;
1786     
1787     wxCommandEvent addevent(WINDOW_ADD);
1788     addevent.SetClientData(WData);
1789     wxPostEvent(this, addevent);
1790     
1791     // Add pointer to the list of open search windows.
1792     
1793     SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1794     
1795     WData = NULL;
1796     
1799 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1800     
1801     //frmSearch *frameSCH = static_cast<frmSearch*>(ActMgrPtr);
1802     void *frameSCH = (void*)event.GetClientData();
1803     
1804     SearchWindowList.erase(frameSCH);
1805     
1806     frameSCH = NULL;
1807     
1810 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1811     
1812     void *frameSCH = (void*)event.GetClientData();
1813     
1814     SearchWindowList.erase(frameSCH);
1815     
1816     frameSCH = NULL;
1817     
1820 void frmMain::UpdateWindowList(wxCommandEvent& event){
1821     
1822     // Update the Window List.
1823     
1824     // Delete the existing items in the window menu.
1825     
1826     // Get the list of contacts.
1827     
1828     // Insert a separator.
1829     
1830     // Get the list of search windows.
1831     
1834 void frmMain::RevealContact(wxCommandEvent& event){
1835     
1836     UCNotif *uc = (UCNotif*)event.GetClientData();
1837     
1838     // Switch the account to the one passed.
1839     
1840     wxTreeItemIdValue cookie;
1841     wxTreeItemId next = treAccounts->GetRootItem();
1842     wxTreeItemId nextChild;
1843     
1844     for (int i = 0; i < prefaccounts.GetCount(); i++){
1845         
1846         if (!nextChild){
1847             nextChild = treAccounts->GetFirstChild(next, cookie);
1848         } else {
1849             nextChild = treAccounts->GetNextSibling(nextChild);
1850         }
1851         
1852         //AccountName = treAccounts->GetItemText(nextChild);
1853         
1854         if (uc->ContactAccount == AccountAccDirList[i]){
1855             
1856             //AccControl->();
1857             treAccounts->SelectItem(nextChild, TRUE);
1858             AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1859             
1860         }
1861         
1862     }
1863     
1864     // Switch the contact to the one passed.
1865     
1866     long longSelected = -1;
1867     int intSelectedData = 0;
1868     
1869     for (;;){
1870         
1871         longSelected = lstContacts->GetNextItem(longSelected,
1872                                                 wxLIST_NEXT_ALL,
1873                                                 wxLIST_STATE_DONTCARE);
1874         
1875         if (longSelected == -1){
1876             
1877             break;
1878             
1879         }
1880         
1881         intSelectedData = (int)lstContacts->GetItemData(longSelected);
1882         
1883         // Compare the filename with the one received.
1884         // If they match then select it.
1885         
1886         if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1887             
1888             // Select.
1889             
1890             lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1891             lstContacts->EnsureVisible(longSelected);
1892             
1893             break;
1894             
1895         }
1896         
1897     }
1898     
1901 void frmMain::DeleteContact(wxCommandEvent& event){
1902     
1903     // Check if a contact is selected.
1904     
1905     long intSelected = -1;
1906     long intContactSeekNum = -1;
1907     wxString wxSContactName;
1908     
1909     intSelected = lstContacts->GetNextItem(intSelected,
1910                                            wxLIST_NEXT_ALL,
1911                                            wxLIST_STATE_SELECTED);
1912     
1913     if (intSelected == -1){
1914         return;
1915     }
1916     
1917     frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1918     
1919     // Get the item data of the contact.
1920     
1921     intContactSeekNum = lstContacts->GetItemData(intSelected);
1922     
1923     // Get the name of the contact.
1924     
1925     wxSContactName = lstContacts->GetItemText(intSelected);
1926     
1927     // Display a message confirming if the contact should
1928     // be deleted.
1929     
1930     int QuestionResponse;
1931     
1932     QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1933     
1934     if (QuestionResponse == wxNO){
1935         
1936         // Exit the subroutine
1937         
1938         return;
1939         
1940     }
1941     
1942     // Delete the contact.
1943     
1944     if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1945         
1946         wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1947         return;
1948         
1949     }
1950     
1951     // Remove the contact from the list.
1952     
1953     lstContacts->DeleteItem(intSelected);
1954     
1955     // Update the search windows, removing the deleted
1956     // contact.
1957     
1958     UCNotif *ucd = new UCNotif;
1959     
1960     ucd->ContactAccount = ActiveAccount;
1961     ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1962     
1963     for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1964          switer != SearchWindowList.end(); switer++){
1965         
1966         // Duplicate the event notification data.
1967         
1968         UCNotif *ucd2 = new UCNotif;
1969         
1970         ucd2->ContactAccount = ucd->ContactAccount;
1971         ucd2->ContactFilename = ucd->ContactFilename;
1972         
1973         // Pass the data to the search window for processing.
1974         
1975         frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1976         wxCommandEvent schdelete(SE_DELETERESULT);
1977         schdelete.SetClientData(ucd2);
1978         wxPostEvent(frameSCH, schdelete);
1979         
1980         // Clear up the pointer prior to variable deletion.
1981         
1982         frameSCH = NULL;
1983         ucd2 = NULL;
1984         
1985     }
1986     
1987     // Clear the wxHTMLWindow.
1988     
1989     wxString EmptyPage = wxT("");
1990     
1991     htmContactData->SetPage(EmptyPage);
1992     
1993     wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
1994     
1995     wxString wxSplitFilename;
1996     wxString wxSDataURL;
1997     
1998     while(wSTFilename.HasMoreTokens()){
1999         
2000         wxSplitFilename = wSTFilename.GetNextToken();
2001         
2002     }
2003     
2004     if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2005         
2006         // Update the ETagDB and mark it as deleted.
2007         
2008         ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2009         
2010         ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2011         
2012         // Get the Data URL.
2013         
2014         wxTreeItemIdValue cookie;
2015         wxTreeItemId next = treAccounts->GetRootItem();
2016         
2017         wxTreeItemId selectedChild = treAccounts->GetSelection();
2018         wxTreeItemId nextChild;
2019         
2020         for (int i = 0; i < prefaccounts.GetCount(); i++){
2021             
2022             if (!nextChild){
2023                 nextChild = treAccounts->GetFirstChild(next, cookie);
2024             }
2025             else {
2026                 nextChild = treAccounts->GetNextSibling(nextChild);
2027             }
2028             
2029             if (nextChild == selectedChild){
2030                 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2031                 
2032             }
2033             
2034         }
2035         
2036         // Add task to the activity monitor to delete the contact.
2037         
2038         frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2039         
2040     }
2041     
2042     // Clear the variable. Don't delete as it will mess things up.
2043     
2044     ContactsFileIndex[intContactSeekNum] = wxT("");
2045     
2046     delete ucd;
2047     ucd = NULL;
2048     
2051 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2052     
2053     QRNotif *qrn = (QRNotif *)event.GetClientData();
2054     
2055     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);
2056     
2057     if (QResponse == wxNO){
2058         
2059         return;
2060     
2061     }
2062     
2063     wxCommandEvent event2(ACTMGR_RESUMEPROC);
2064     event2.SetInt(*qrn->QResponse);
2065     event2.SetClientData(qrn->PausePtr);
2066     
2067     frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2068     
2069     wxPostEvent(frameActMgr, event2);
2070     
2073 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2074     
2075     // Remove the contact from the window after syncronising.
2076     
2077     // Check which account is currently active in the window.
2078     // If it is different from the one passed to this subroutine then
2079     // exit from the subroutine.
2080     
2081     if (Account != ActiveAccount){
2082         return;
2083     }
2084     
2085     long longSelected = -1;
2086     int intSelectedData = 0;
2087     
2088     for (;;){
2089         
2090         longSelected = lstContacts->GetNextItem(longSelected,
2091                                                 wxLIST_NEXT_ALL,
2092                                                 wxLIST_STATE_DONTCARE);
2093         
2094         if (longSelected == -1){
2095             
2096             break;
2097             
2098         }
2099         
2100         intSelectedData = (int)lstContacts->GetItemData(longSelected);
2101         
2102         // Compare the filename with the one received.
2103         // If they match then select it.
2104         
2105         if (ContactsFileIndex[intSelectedData] == Filename){
2106             
2107             // Remove the contact from the window.
2108             
2109             lstContacts->DeleteItem(intSelectedData);
2110             
2111             // Check if contact is the selected contact in the HTML window and
2112             // if it is then clear the window.
2113             
2114             if (ActiveFilename == Filename){
2115                 
2116                 wxString EmptyPage = wxT("");
2117                 htmContactData->SetPage(EmptyPage);
2118                 
2119             }
2120             
2121             break;
2122             
2123         }
2124         
2125     }
2126     
2131 void frmMain::SortFNLN( wxCommandEvent& event ) {
2132     
2133     wxTreeEvent NullEvent;
2134     SortMode = 1;
2135     LoadContactList(NullEvent);
2136     
2139 void frmMain::SortLNFN( wxCommandEvent& event ) {
2140     
2141     wxTreeEvent NullEvent;
2142     SortMode = 2;
2143     LoadContactList(NullEvent);
2144     
2147 void frmMain::SortNickname( wxCommandEvent& event ) {
2148     
2149     wxTreeEvent NullEvent;
2150     SortMode = 3;
2151     LoadContactList(NullEvent);
2152     
2155 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2156     
2157     wxTreeEvent NullEvent;
2158     SortMode = 4;
2159     LoadContactList(NullEvent);
2160     
2163 void frmMain::SortAscending( wxCommandEvent& event ) {
2164     
2165     wxTreeEvent NullEvent;
2166     AscendingMode = TRUE;
2167     LoadContactList(NullEvent);
2168     
2171 void frmMain::SortDescending( wxCommandEvent& event ) {
2172     
2173     wxTreeEvent NullEvent;
2174     AscendingMode = FALSE;
2175     LoadContactList(NullEvent);
2176     
2179 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2180     
2181     if (stbBottom->IsShown() == TRUE){
2182         
2183         stbBottom->Hide();
2184         
2185     } else {
2186         
2187         stbBottom->Show();
2188         
2189     }
2190     
2191     this->Layout();
2192     
2195 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2196     
2197     // Display the activity icon.
2198     
2199     imgActivityStatus->SetBitmap(*imgActIcon1);
2200     ActivityIconStatus = 0;
2201     
2204 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2205     
2206     switch (ActivityIconStatus){
2207             
2208         case 0:
2209             imgActivityStatus->SetBitmap(*imgActIcon1);
2210             ActivityIconStatus = 1;
2211             break;
2212         case 1:
2213             imgActivityStatus->SetBitmap(*imgActIcon2);
2214             ActivityIconStatus = 2;
2215             break;
2216         case 2:
2217             imgActivityStatus->SetBitmap(*imgActIcon3);
2218             ActivityIconStatus = 3;
2219             break;
2220         case 3:
2221             imgActivityStatus->SetBitmap(*imgActIcon4);
2222             ActivityIconStatus = 0;
2223             break;
2224         default:
2225             ActivityIconStatus = 0;
2226             
2227     }
2228     
2231 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2232     
2233     // Display the sleep icon.
2234     
2235     imgActivityStatus->SetBitmap(*imgActIconSleep);
2236     
2239 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2240     
2241     if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2242         
2243         return;
2244         
2245     }
2246     
2247     wxRect rectOnline;
2248     wxRect rectSSL;
2249     wxRect rectActivity;
2250     stbBottom->GetFieldRect(1, rectOnline);
2251     stbBottom->GetFieldRect(2, rectSSL);
2252     stbBottom->GetFieldRect(3, rectActivity);
2253     
2254     imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2255     imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2256     imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2257     
2260 XABViewMode frmMain::GetViewMode(){
2261     
2262     XABViewMode xvm;
2263     
2264     xvm.SortMode = SortMode;
2265     xvm.AscendingMode = AscendingMode;
2266     
2267     return xvm;
2268     
2271 void frmMain::WindowAdd( wxCommandEvent &event ){
2272     
2273     WindowData *WData = (WindowData*)event.GetClientData();
2274     
2275     size_t pos;
2276     
2277     if (WData->DataType == 0){
2278         
2279         // Contact Window
2280         
2281         int intID = mnuContactWindows->GetId();
2282         
2283         mnuWindow->FindChildItem(intID, &pos);
2284         wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2285         mnuNewItem->SetId(WData->WindowID);
2286         WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2287         WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2288         WindowListType.insert(std::make_pair(WData->WindowID, 0));
2289         mnuWindow->Insert((pos + 1), mnuNewItem);
2290         this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2291         
2292     } else if (WData->DataType == 1){
2293         
2294         // Contact Editor Window
2295         
2296         int intID = mnuContactEditorWindows->GetId();
2297         
2298         mnuWindow->FindChildItem(intID, &pos);
2299         wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2300         mnuNewItem->SetId(WData->WindowID);
2301         WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2302         WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2303         WindowListType.insert(std::make_pair(WData->WindowID, 1));
2304         mnuWindow->Insert((pos + 1), mnuNewItem);
2305         this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2306         
2307     } else if (WData->DataType == 2){
2308         
2309         // Search Window
2310         
2311         int intID = mnuSearchWindows->GetId();
2312         
2313         mnuWindow->FindChildItem(intID, &pos);
2314         wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2315         mnuNewItem->SetId(WData->WindowID);
2316         WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2317         WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2318         WindowListType.insert(std::make_pair(WData->WindowID, 2));
2319         mnuWindow->Insert((pos + 1), mnuNewItem);
2320         this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2321         
2322     }
2323     
2324     delete WData;
2325     WData = NULL;
2326     
2329 void frmMain::WindowEdit( wxCommandEvent &event ){
2330     
2331     WindowData *WData = (WindowData*)event.GetClientData();
2332     
2333     if (WData->DataType == 0){
2334         
2335         // Get the window title and use that.
2336         
2337         frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2338         
2339         wxString WindowTitle = frmContactPtr->GetTitle();
2340         
2341         std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2342         
2343         MenuIter->second->SetItemLabel(WindowTitle);
2344         
2345         //mnuWindow->FindChildItem(intID, &pos);
2346         //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2347         //mnuNewItem->SetId(WData->WindowID);
2348         //ContactWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2349         //ContactWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2350         //mnuWindow->Insert((pos + 1), mnuNewItem);
2351         //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2352         
2353     } else if (WData->DataType == 1){
2354         
2355         // Get the window title and use that.
2356         
2357         frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2358         
2359         wxString WindowTitle = frmCEPtr->GetTitle();
2360         
2361         std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2362         
2363         if (WindowTitle.IsEmpty()){
2364             
2365             MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2366             
2367         } else {
2368             
2369             MenuIter->second->SetItemLabel(WindowTitle);
2370             
2371         }
2372         
2373         //mnuWindow->FindChildItem(intID, &pos);
2374         //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2375         //mnuNewItem->SetId(WData->WindowID);
2376         //ContactEditorWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2377         //ContactEditorWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2378         //mnuWindow->Insert((pos + 1), mnuNewItem);
2379         //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2380         
2381     }
2382     
2383     delete WData;
2384     WData = NULL;
2385     
2388 void frmMain::WindowDelete( wxCommandEvent &event ){
2389     
2390     WindowData *WData = (WindowData*)event.GetClientData();
2391     
2392     std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2393     
2394     mnuWindow->Remove(MenuIter->second);
2395     
2396     delete MenuIter->second;
2397     MenuIter->second = NULL;
2398     
2399     WindowListPointersMenu.erase(WData->WindowID);
2400     WindowListPointers.erase(WData->WindowID);
2401     WindowListType.erase(WData->WindowID);
2402     
2403     delete WData;
2404     WData = NULL;
2405     
2408 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2409     
2410     std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2411     
2412     frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2413     
2414     frmContactPtr->Show();
2415     frmContactPtr->Raise();
2416     
2419 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2420     
2421     std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2422     
2423     frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2424     
2425     frmCEPtr->Show();
2426     frmCEPtr->Raise();
2427     
2430 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2431     
2432     // Look through the Search Window List Pointers, grab the
2433     // window point and show the window.
2434     
2435     std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2436     
2437     frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2438     
2439     frmSearchPtr->Show();
2440     frmSearchPtr->Raise();
2441     
2444 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2445     
2446     frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2447     wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2448     wxPostEvent(frameActMgr, toggconn);
2449     
2452 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2453     
2454     // Check the account type before continuing.
2455     
2456     wxString SeekAccount;
2457     wxString AccTypeLower;
2458     wxString AccType;
2459     bool AccountSSL;
2460     std::map<int, SSLCertCollection>::iterator SSLColIter;
2461     
2462     for (int i = 0; i < prefaccounts.GetCount(); i++){
2463         
2464         SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2465         AccType.Append(prefaccounts.GetAccountType(i));
2466         AccountSSL = prefaccounts.GetAccountSSL(i);
2467         AccTypeLower = AccType.MakeLower();
2468         SeekAccount.Append(wxT("."));
2469         SeekAccount.Append(AccTypeLower);
2470         
2471         if (SeekAccount == ActiveAccount){
2472             
2473             if (AccTypeLower == wxT("local")){
2474                 
2475                 return;
2476                 
2477             }
2478             
2479             if (AccountSSL == false){
2480                 
2481                 return;
2482                 
2483             }
2484             
2485             SSLColIter = AccountSSLData.find(i);
2486             
2487             SSLCertCollection SSLCertInfo = SSLColIter->second;
2488             
2489             frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2490             frameSSLCert->StartCertFrom(0);
2491             frameSSLCert->SetupCerts(SSLCertInfo);
2492             frameSSLCert->ShowModal();
2493             
2494             delete frameSSLCert;
2495             frameSSLCert = NULL;
2496             
2497         }
2498         
2499         SeekAccount.Clear();
2500         AccTypeLower.Clear();
2501         AccType.clear();
2502         
2503     }
2504     
2507 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2508     
2509     // Check the account type before continuing.
2510     
2513 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2514     
2515     // Check the account type before continuing.
2516     
2519 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2520     
2521     if (event.GetInt() == 0){
2522         
2523         imgConnStatus->SetBitmap(*imgOnline);
2524         
2525     } else {
2526         
2527         imgConnStatus->SetBitmap(*imgOffline);
2528         
2529     }   
2530     
2533 void frmMain::SetupSSLStatus( int AccountID ){
2534     
2535     // Check if account ID given is
2536     // the active account and if not, do nothing.
2537     
2538     wxString AccType;
2539     wxString AccTypeLower;
2540     
2541     AccType = prefaccounts.GetAccountType(AccountID);
2542     AccTypeLower = AccType.MakeLower();
2543     
2544     wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2545                                 AccTypeLower;
2546     
2547     if (AccountIDName != ActiveAccount){
2548         
2549         return;
2550         
2551     }
2552     
2553     // Check if the account has SSL enabled.
2554     
2555     bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2556     
2557     if (SSLInUse == FALSE){
2558         
2559         SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2560         imgSSLStatus->SetBitmap(*imgNoSSL);
2561         
2562     } else {
2563         
2564         // Get the SSL Collection Data.
2565         
2566         std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2567         
2568         if (SSLResultIter->second == 1){
2569             
2570             imgSSLStatus->SetBitmap(*imgSSLWarning);
2571             SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") + 
2572                                prefaccounts.GetAccountName(AccountID) +
2573                                wxT("' (Connection denied by user)\n\nDouble click for more information."));
2574             
2575             
2576         } else if (SSLResultIter->second == 0){
2577             
2578             imgSSLStatus->SetBitmap(*imgSSL);
2579             SSLToolTip->SetTip(wxT("Account '") + 
2580                                prefaccounts.GetAccountName(AccountID) +
2581                                wxT("' secured using SSL\n\nDouble click for more information."));
2582             
2583         }
2584         
2585     }
2586     
2589 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2590     
2591     frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2592     SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2593     SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2594     wxString AccountName = SSLICNObj->AccountName;
2595     frameISC->LoadData(SSLCCData, AccountName);
2596     frameISC->ShowModal();
2597     
2598     int FinalConflictResult = frameISC->GetResult();
2599     
2600     wxCommandEvent event2(ACTMGR_RESUMEPROC);
2601     event2.SetClientData(SSLICNObj->QRNotifData);
2602     event2.SetInt(FinalConflictResult);
2603     
2604     delete frameISC;
2605     frameISC = NULL;
2606     
2607     frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);      
2608     wxPostEvent(frameActMgr, event2);
2611 void frmMain::PauseAllTimers(){
2612     
2613     for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2614          ASTiter != AccountSyncTimers.end(); ASTiter++){
2615         
2616         ASTiter->second->Stop();
2617         
2618     }
2619     
2622 void frmMain::ResumeAllTimers(){
2623     
2624     for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin(); 
2625          ASTiter != AccountSyncTimers.end(); ASTiter++){
2626         
2627         ASTiter->second->Start();
2628         
2629     }
2630     
2633 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2634     
2635     // Delete existing data.
2636     
2637     AccountSSLData.erase(AccountID);
2638     AccountSSLResult.erase(AccountID);
2639     
2640     // Insert new data.
2641     
2642     AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2643     AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2644     
2647 void frmMain::CheckUpdates( wxCommandEvent& event ){
2648     
2649     frmUpdate *frameUpdate = new frmUpdate ( this );
2650     frameUpdate->FetchData();
2651     frameUpdate->ShowModal();
2652     
2655 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2656     
2657     // Run the import contacts system.
2658     
2659     ImportRun(this);
2660     
2663 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2664     
2665     // Check if an account and at least one contact is selected
2666     // before continuing.
2667     
2668     wxArrayString ArrData;
2669     
2670     if (ActiveAccount.IsEmpty()){
2671         
2672         return;
2673         
2674     }
2675     
2676     int ContactSelected = 0;
2677     int ContactsCollected = 0;
2678     long longSelected = -1;
2679     
2680     for (;;){
2681         
2682         longSelected = lstContacts->GetNextItem(longSelected, 
2683                                                 wxLIST_NEXT_ALL,
2684                                                 wxLIST_STATE_SELECTED);
2685         
2686         if (longSelected == -1){
2687             
2688             break;
2689             
2690         }
2691         
2692         int FileID = (int)lstContacts->GetItemData(longSelected);
2693         
2694         ArrData.Insert(ContactsFileIndex[FileID],
2695                        ContactsCollected, 1);
2696         
2697         ContactSelected++;
2698         
2699     }
2700     
2701     if (ContactSelected == 0){
2702         
2703         return;
2704         
2705     }
2706     
2707     // Run the export contacts system.
2708     
2709     ExportRun(this, &ArrData);
2710     
2713 void frmMain::GetListControl(wxListCtrl *lstContactsPtr, 
2714                              wxArrayString *ContactsFileIndexPtr){
2715     
2716     lstContactsPtr = lstContacts;
2717     ContactsFileIndexPtr = &ContactsFileIndex;
2718     
2721 void frmMain::GetSelectedList( wxCommandEvent& event ){
2722     
2723     // Get the array of contact filenames. 
2724     
2725     wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2726     
2727     // Process them into an array of files.     
2728     
2729     long longSelected = -1;
2730     int ContactsCollected = 0;
2731     wxString ContactFilename;
2732     
2733     for (;;){
2734         
2735         longSelected = lstContacts->GetNextItem(longSelected, 
2736                                                 wxLIST_NEXT_ALL,
2737                                                 wxLIST_STATE_SELECTED);
2738         
2739         if (longSelected == -1){
2740             
2741             break;
2742             
2743         }
2744         
2745         // Get the file information and add to the list.
2746         
2747         int FileID = (int)lstContacts->GetItemData(longSelected);
2748         
2749         ArrData->Insert(ContactsFileIndex[FileID],
2750                         ContactsCollected, 1);
2751         
2752         ContactsCollected++;
2753         ContactFilename.Clear();        
2754         
2755     }
2756     
2757     event.SetInt(1);
2758     
2761 void frmMain::SyncAccount( wxCommandEvent& event ){
2762     
2763     wxString *AccNameInc = (wxString*)event.GetClientData();
2764     
2765     frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2766     frameActMgr->AddTask(3, wxT(""), *AccNameInc, 
2767                          wxT(""), wxT(""), wxT(""), wxT(""));
2768     
2771 void frmMain::ShowHelp( wxCommandEvent& event ){
2772     
2773     // Based on the operating system, work out where 
2774     // the documentation should be.
2775     
2776     //#ifdef __APPLE__
2777     
2778 #if defined(__HAIKU__)
2779     
2780 #elif defined(__WIN32__)
2781     
2782     
2783     
2784 #else
2785     
2786     if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2787         
2788         wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2789         return;
2790         
2791 #if XSDAB_RELEASE == 0
2792         
2793     } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2794         
2795         wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2796         return;
2797         
2798 #endif 
2799         
2800     }
2801     
2802 #endif
2803     
2804 #if XSDAB_RELEASE == 0
2805     
2806     wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2807     
2808 #else
2809     
2810     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!"));
2811     
2812 #endif
2813     
2816 void frmMain::ShowImportResults( wxCommandEvent &event ){
2818         std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2820         frmImportResults *frmIR = new frmImportResults(this);
2821         frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
2822         frmIR->ShowModal();
2823                 
2824         delete frmIR;
2825         frmIR = NULL;
2826         
2827         delete ResultData;
2828         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