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