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