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