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