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