1 // frmMain.cpp - Main window form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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/>
25 #include <wx/tokenzr.h>
27 #include <wx/mstream.h>
28 #include <wx/fs_mem.h>
30 #include <wx/filesys.h>
32 #include <wx/stdpaths.h>
33 #include <wx/fileconf.h>
34 #include <wx/gdicmn.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"
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"
66 //extern const wxEventType MyHaremEvent = wxNewEventType();
68 //#define CE_UPDATECONTACTLIST 7700
69 //#define CE_UPDATEACCOUNTLIST 7701
71 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
72 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
73 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
74 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
75 DEFINE_EVENT_TYPE(CE_OPENCONTACTLIST);
76 DEFINE_EVENT_TYPE(CE_NEWCONTACT);
77 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
78 DEFINE_EVENT_TYPE(CE_DELETECONTACT);
79 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
80 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
81 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
82 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
83 DEFINE_EVENT_TYPE(ACTMGR_START);
84 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
85 DEFINE_EVENT_TYPE(ACTMGR_STOP);
86 DEFINE_EVENT_TYPE(WINDOW_ADD);
87 DEFINE_EVENT_TYPE(WINDOW_EDIT);
88 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
89 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
90 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
91 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
92 DEFINE_EVENT_TYPE(SYNCACCOUNT);
93 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
94 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
95 DEFINE_EVENT_TYPE(REFRESHADDRESSBOOK);
97 BEGIN_EVENT_TABLE(frmMain, wxFrame)
98 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
99 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
100 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
101 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
102 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
103 EVT_COMMAND(wxID_ANY, CE_OPENCONTACTLIST, frmMain::OpenContactInfoList)
104 EVT_COMMAND(wxID_ANY, CE_NEWCONTACT, frmMain::ShowContactEditorNew)
105 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
106 EVT_COMMAND(wxID_ANY, CE_DELETECONTACT, frmMain::DeleteContact)
107 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
108 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
109 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
110 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
111 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
112 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
113 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
114 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
115 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
116 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
117 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
118 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
119 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
120 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
121 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
122 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
125 frmMain::frmMain( wxWindow* parent )
130 // Setup the account icons.
132 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
133 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
134 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
135 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
137 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
138 wxBitmap AccInet(icons_accinet_png, -1);
140 wxIAccInet.CopyFromBitmap(AccInet);
142 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
143 wxBitmap AccNIcon(icons_acclocal_png, -1);
145 wxIAccNIcon.CopyFromBitmap(AccNIcon);
147 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
148 wxBitmap AccGrp(icons_accgroup_png, -1);
150 wxIAccGrp.CopyFromBitmap(AccGrp);
152 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
153 wxBitmap AccNone(icons_accnone_png, -1);
155 wxIAccNone.CopyFromBitmap(AccNone);
157 AccountID = AccImgList->Add(wxIAccNIcon);
158 AccountNetID = AccImgList->Add(wxIAccInet);
159 AccountGrpID = AccImgList->Add(wxIAccGrp);
160 AccountNoneID = AccImgList->Add(wxIAccNone);
162 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
164 // Setup the status bar icons.
168 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
169 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
170 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
172 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
173 imgSSL = new wxBitmap(icons_ssl_png, -1);
175 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
176 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
178 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
179 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
183 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
184 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
185 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
186 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
187 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
189 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
190 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
192 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
193 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
195 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
197 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
198 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
200 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
202 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
203 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
205 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
207 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
208 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
210 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
212 // Online/Offline icons.
214 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
215 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
217 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
218 imgOnline = new wxBitmap(icons_online_png, -1);
220 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
221 imgOffline = new wxBitmap(icons_offline_png, -1);
223 // Setup the account view.
225 AccCtrl->SetPopupControl(treAccounts);
226 AccCtrl->SetPopupMaxHeight(175);
227 AccCtrl->SetPopupMinWidth(250);
228 treAccounts->AssignImageList(AccImgList);
230 wxListItem ColumnData;
232 ColumnData.SetText(wxT("Name0"));
233 ColumnData.SetWidth(320);
234 lstContacts->InsertColumn(0, ColumnData);
236 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
237 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
239 #if defined(__HAIKU__)
241 #elif defined(__WIN32__)
243 int stbBottomData [4] = { -1, 8, 8, 8 };
247 int stbBottomData [4] = { -1, 20, 20, 20 };
251 stbBottom->SetFieldsCount(4, stbBottomData);
252 stbBottom->SetMinHeight(16);
257 stbBottom->GetFieldRect(1, rectOnline);
258 stbBottom->GetFieldRect(2, rectSSL);
259 stbBottom->GetFieldRect(3, rectActivity);
261 SSLToolTip = new wxToolTip(wxT(""));
263 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
264 imgConnStatus->SetBitmap(*imgOnline);
265 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
267 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
268 imgSSLStatus->SetBitmap(*imgNoSSL);
269 imgSSLStatus->SetToolTip(SSLToolTip);
270 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
272 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
273 imgActivityStatus->SetBitmap(*imgActIconSleep);
274 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
276 // Setup the window menu.
278 // By default should be:
283 // Contact editor windows:
289 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
290 mnuWindow->Append( mnuContactWindows );
292 mnuWindow->AppendSeparator();
294 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
295 mnuWindow->Append( mnuContactEditorWindows );
297 mnuWindow->AppendSeparator();
299 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
300 mnuWindow->Append( mnuSearchWindows );
302 #if defined(__WIN32__)
307 mnuContactWindows->SetFont(fontstyle);
308 mnuContactEditorWindows->SetFont(fontstyle);
309 mnuSearchWindows->SetFont(fontstyle);
313 mnuContactWindows->Enable(FALSE);
314 mnuContactEditorWindows->Enable(FALSE);
315 mnuSearchWindows->Enable(FALSE);
319 // Hide unimplemented functions.
325 void frmMain::QuitApp( wxCloseEvent& event )
332 void frmMain::QuitApp( wxCommandEvent& event )
339 void frmMain::QuitApp()
341 //-------------------------------------------------------------------
342 // frmMain::QuitApp: Quits the application by simply closing this
343 // window which causes the exit as frmMain is the main window.
345 // wxCommandEvent Accepts a referenced event command.
346 //-------------------------------------------------------------------
348 //-------------------------------------------------------------------
349 // frmMain::QuitApp: Quits the application by simply closing this
350 // window which causes the exit as frmMain is the main window.
352 // wxCommandEvent Accepts a referenced event command.
353 //-------------------------------------------------------------------
355 //Go through the windows and close each one (be it search
356 //or contact editor). Abort if user wants to cancel.
358 // Close the contact editor windows.
360 // Close the contact windows.
362 // Close the search windows.
364 // Write out the ETag databases.
366 // Save Preferences: Save the window position if that option is enabled.
368 wxString SetFilename = GetUserPrefDir();
370 #if defined(__HAIKU__)
374 #elif defined(__WIN32__)
376 SetFilename.Append(wxT("settings"));
382 SetFilename.Append(wxT("settings"));
386 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
388 bool SaveWindowPos = FALSE;
389 wxString SaveWindowInc;
390 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
392 if (SaveWindowInc == wxT("true")){
394 SaveWindowPos = TRUE;
398 if (SaveWindowPos == TRUE){
400 wxRect frmMainPos = this->GetRect();
402 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
403 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
404 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
405 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
413 //Everything closed... exit.
421 void frmMain::ShowActivityWindow( wxCommandEvent& event )
424 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
425 frameActMgr->OpenWindow();
430 void frmMain::ShowAboutWindow( wxCommandEvent& event )
432 //-------------------------------------------------------------------
433 // frmMain::ShowAboutWindow: Shows the About window as a modal
434 // dialog and then cleans up when finished.
436 // wxCommandEvent Accepts a referenced event command.
437 //-------------------------------------------------------------------
439 frmAbout *frameAbout = new frmAbout ( this );
440 frameAbout->SetupAboutWindow();
441 frameAbout->ShowModal();
447 void frmMain::OpenPreferences( wxCommandEvent& event)
449 //-------------------------------------------------------------------
450 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
451 // dialog and then cleans up when finished.
453 // wxCommandEvent Accepts a referenced event command.
454 //-------------------------------------------------------------------
456 ReloadAccounts = FALSE;
458 frmPreferences *framePreferences = new frmPreferences ( this );
459 framePreferences->SetupPointers(&ReloadAccounts);
460 framePreferences->ShowModal();
461 delete framePreferences;
462 framePreferences = NULL;
464 if (ReloadAccounts == TRUE){
466 // Reload the accounts as a change has been made within
469 this->LoadPreferences();
475 void frmMain::OpenNewABDialog( wxCommandEvent& event)
477 //-------------------------------------------------------------------
478 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
479 // dialog and then cleans up when finished.
481 // wxCommandEvent Accepts a referenced event command.
482 //-------------------------------------------------------------------
484 ReloadAccounts = FALSE;
486 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
487 frameNewAccount->SetupPointers(&ReloadAccounts);
488 frameNewAccount->ShowModal();
489 delete frameNewAccount;
490 frameNewAccount = NULL;
492 if (ReloadAccounts == TRUE){
494 // Reload the accounts as a change has been made within
497 this->LoadPreferences();
503 void frmMain::LoadContactList( wxTreeEvent& event )
506 // Clear all existing variables.
508 lstContacts->DeleteAllItems();
510 treAccounts->SetAccount();
512 wxTreeItemIdValue cookie;
513 wxTreeItemId next = treAccounts->GetRootItem();
514 wxString AccountName;
515 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
516 wxString AccountDirCmb;
517 long selectedaccount = 0;
519 wxTreeItemId selectedChild = treAccounts->GetSelection();
520 wxTreeItemId nextChild;
522 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
523 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
525 int SCImg = treAccounts->GetItemImage(selectedChild);
526 int AccountIndex = 0;
528 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
530 for (int i = 0; i < prefaccounts.GetCount(); i++){
532 if (ActiveItemIcon == 2){
534 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
535 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
536 int ActiveAccountG = AGLiter->second;
538 if (i == ActiveAccountG){
540 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
541 AccountType.Append(prefaccounts.GetAccountType(i));
546 if (AccountType == wxT("CardDAV")){
547 AccountTypeFinal.Append(wxT("carddav"));
549 else if (AccountType == wxT("Local")){
550 imgSSLStatus->SetBitmap(*imgOffline);
551 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
552 AccountTypeFinal.Append(wxT("local"));
563 nextChild = treAccounts->GetFirstChild(next, cookie);
566 nextChild = treAccounts->GetNextSibling(nextChild);
569 AccountName = treAccounts->GetItemText(nextChild);
571 if (nextChild == selectedChild){
572 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
573 AccountType.Append(prefaccounts.GetAccountType(i));
578 if (AccountType == wxT("CardDAV")){
579 AccountTypeFinal.Append(wxT("carddav"));
581 else if (AccountType == wxT("Local")){
582 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
583 AccountTypeFinal.Append(wxT("local"));
592 if (selectedaccount >= prefaccounts.GetCount()){
594 // The account selected isn't there so return.
602 // Open the directory and get the list of .vcf files
603 // in that directory.
605 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
606 ActiveAccountType = AccountType;
608 SetupSSLStatus(AccountIndex);
610 AccountDirFinal.Clear();
611 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
613 ContactsFileIndex.Clear();
615 wxString vCardFilename;
616 wxString vCardFilenameFull;
617 wxString vCardDataString;
618 wxStringTokenizer vcardfileline;
620 wxString setname, setvalue;
621 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
622 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
623 long ContactIndex = 1;
624 long ContactSeekPoint = 0;
626 wxDir vcardaccdir(AccountDirFinal);
628 // Get the wxTreeItemId and image icon and compare it to the list.
630 if (ActiveItemIcon == AccountGrpID){
632 // It's a group so load the file containing the group and
633 // get the members of the group.
638 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
639 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
641 Group.LoadFile(AGFiter->second);
643 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
645 for (int i = 0; i < vCardMember.PropCount; i++){
647 vCardMember.PropValues[i].Trim();
648 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
650 wxString NewPropValue;
651 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
652 vCardMember.PropValues[i] = NewPropValue;
659 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
662 if (vCardFilename.Right(4) == wxT(".vcf") ||
663 vCardFilename.Right(4) == wxT(".VCF") ||
664 vCardFilename.Right(5) == wxT(".vcard") ||
665 vCardFilename.Right(5) == wxT(".VCARD")){
668 bool FoundMember = FALSE;
670 vCardFilenameFull.Append(AccountDirFinal);
671 vCardFilenameFull.Append(wxT("/"));
672 vCardFilenameFull.Append(vCardFilename);
674 Person.LoadFile(vCardFilenameFull);
676 UIDCode = Person.Get(wxT("UID"));
678 for (int i = 0; i < vCardMember.PropCount; i++){
680 if (vCardMember.PropValues[i] == UIDCode){
688 if (FoundMember == FALSE){
690 vCardFilename.Clear();
691 vCardFilenameFull.Clear();
692 vCardDataString.Clear();
693 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
698 if (Person.MeetBaseSpecification()){
702 // Split the name into sections.
704 vCardDataString = Person.Get(wxT("N"));
706 vCardName NameData = Person.GetName();
708 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
710 } else if (SortMode == 2){
712 // Split the name into sections.
714 vCardName NameData = Person.GetName();
716 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
718 } else if (SortMode == 3){
720 // Check and make sure that the top most nickname is used.
722 vCardDataString = Person.Get(wxT("NICKNAME"));
724 if (vCardDataString.IsEmpty()){
726 vCardDataString = wxT("(no nickname)");
730 } else if (SortMode == 4){
732 vCardDataString = Person.Get(wxT("FN"));
736 if (AscendingMode == TRUE){
737 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
739 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
748 vCardFilename.Clear();
749 vCardFilenameFull.Clear();
750 vCardDataString.Clear();
751 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
756 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
759 if (vCardFilename.Right(4) == wxT(".vcf") ||
760 vCardFilename.Right(4) == wxT(".VCF") ||
761 vCardFilename.Right(5) == wxT(".vcard") ||
762 vCardFilename.Right(5) == wxT(".VCARD")){
766 vCardFilenameFull.Append(AccountDirFinal);
767 vCardFilenameFull.Append(vCardFilename);
769 Person.LoadFile(vCardFilenameFull);
771 if (Person.MeetBaseSpecification()){
775 // Split the name into sections.
777 vCardDataString = Person.Get(wxT("N"));
779 vCardName NameData = Person.GetName();
781 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
783 } else if (SortMode == 2){
785 // Split the name into sections.
787 vCardName NameData = Person.GetName();
789 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
791 } else if (SortMode == 3){
793 // Check and make sure that the top most nickname is used.
795 vCardDataString = Person.Get(wxT("NICKNAME"));
797 if (vCardDataString.IsEmpty()){
799 vCardDataString = wxT("(no nickname)");
803 } else if (SortMode == 4){
805 vCardDataString = Person.Get(wxT("FN"));
809 if (AscendingMode == TRUE){
810 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
812 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
821 vCardFilename.Clear();
822 vCardFilenameFull.Clear();
823 vCardDataString.Clear();
824 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
831 // Insert the data into the control.
833 if (AscendingMode == TRUE){
834 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
835 iter != vCardNamesAsc.end(); ++iter){
837 wxListItem ContactInfo;
839 ContactInfo.SetId(0);
840 ContactInfo.SetText(_("Mooo"));
841 ContactInfo.SetData(ContactSeekPoint);
842 ContactIndex = lstContacts->InsertItem(ContactInfo);
844 lstContacts->SetItem(ContactIndex, 0, iter->first);
845 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
852 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
853 iter != vCardNamesDsc.end(); ++iter){
855 wxListItem ContactInfo;
857 ContactInfo.SetId(0);
858 ContactInfo.SetText(_("Mooo"));
859 ContactInfo.SetData(ContactSeekPoint);
860 ContactIndex = lstContacts->InsertItem(ContactInfo);
862 lstContacts->SetItem(ContactIndex, 0, iter->first);
863 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
872 void frmMain::ShowContactInfo( wxListEvent& event )
875 long intSelected = -1;
876 long ContactSeekNum = -1;
878 // Check if several contacts have been selected.
880 int ContactTotal = 0;
884 intSelected = lstContacts->GetNextItem(intSelected,
886 wxLIST_STATE_SELECTED);
888 if (intSelected == -1){
898 if (ContactTotal == 0){
899 htmContactData->SetPage(wxT(""));
903 if (ContactTotal > 1){
905 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
906 ActiveFilename.Clear();
911 intSelected = lstContacts->GetNextItem(intSelected,
913 wxLIST_STATE_SELECTED);
915 ContactSeekNum = lstContacts->GetItemData(intSelected);
918 wxString wxSContactString;
919 wxString ContactLine;
922 size_t ContactLineLen;
923 bool ExtraLineSeek = FALSE;
924 int QuoteBreakPoint = 0;
926 bool PropertyFind = FALSE;
927 bool QuoteMode = FALSE;
929 wxString wxSPropertyNextLine;
930 wxString wxSProperty;
931 wxString wxSPropertySeg1;
932 wxString wxSPropertySeg2;
934 // Check if we are using wxWidgets version 2.8 or less and
935 // execute the required command accordingly.
937 #if wxABI_VERSION < 20900
938 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
940 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
943 if (ContactFile.IsOpened() == FALSE){
949 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
953 std::map<int, wxString> ContactFileLines;
954 std::map<int, wxString>::iterator striter;
956 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
958 int ContactLineSeek = 0;
960 while (wSTContactFileLines.HasMoreTokens() == TRUE){
962 ContactLine = wSTContactFileLines.GetNextToken();
963 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
968 if (ContactSeekNum < 0){
972 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
973 iter != ContactFileLines.end(); ++iter){
975 // Find the colon which splits the start bit from the data part.
977 ContactLine = iter->second;
979 while (ExtraLineSeek == TRUE){
981 // Check if there is extra data on the next line
982 // (indicated by space or tab at the start) and add data.
986 if (iter == ContactFileLines.end()){
993 wxSPropertyNextLine = iter->second;
996 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
998 wxSPropertyNextLine.Remove(0, 1);
999 ContactLine.Append(wxSPropertyNextLine);
1004 ExtraLineSeek = FALSE;
1010 ContactLineLen = ContactLine.Len();
1012 // Make sure we are not in quotation mode.
1013 // Make sure colon does not have \ or \\ before it.
1015 for (int i = 0; i <= ContactLineLen; i++){
1017 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1019 PropertyFind = FALSE;
1021 } else if (PropertyFind == TRUE){
1023 wxSProperty.Append(ContactLine.Mid(i, 1));
1027 if (ContactLine.Mid(i, 1) == wxT("\"")){
1029 if (QuoteMode == TRUE){
1041 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1043 QuoteBreakPoint = i;
1050 // Split that line at the point into two variables (ignore the colon).
1052 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1053 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1055 // Insert both into the vCard data file.
1057 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1060 PropertyFind = TRUE;
1061 ExtraLineSeek = TRUE;
1063 QuoteBreakPoint = 0;
1064 ContactLine.Clear();
1065 wxSProperty.Clear();
1069 OldSessionID = SessionID;
1070 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1071 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1072 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1076 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1079 // Check if there is an account selected and if not
1080 // return immediately.
1082 if (ActiveAccount.IsEmpty()){
1088 // Add Pointer to SetupPointers for the ETagDB.
1090 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1091 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1092 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1094 contacticon.CopyFromBitmap(contacticonbmp);
1096 frmContactEditor *ContactEditor = new frmContactEditor( this );
1100 ContactEditor->SetUID(WindowMenuItemID);
1102 WindowData *WData = new WindowData;
1104 WData->DataType = 1;
1105 WData->WindowPointer = (void*)ContactEditor;
1106 WData->WindowID = WindowMenuItemID;
1108 wxCommandEvent addevent(WINDOW_ADD);
1109 addevent.SetClientData(WData);
1110 wxPostEvent(this, addevent);
1112 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1113 ContactEditor->SetupHeaders();
1114 ContactEditor->SetupContact(ActiveAccount);
1115 ContactEditor->SetIcon(contacticon);
1116 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1117 ContactEditor->Show(true);
1121 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1124 // Check if there is an account selected and if not
1125 // return immediately.
1127 int DataCheck = event.GetInt();
1129 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1135 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1136 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1137 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1139 contacticon.CopyFromBitmap(contacticonbmp);
1141 // Check if a contact has been selected.
1143 long intSelected = -1;
1144 long intContactSeekNum = -1;
1146 intSelected = lstContacts->GetNextItem(intSelected,
1148 wxLIST_STATE_SELECTED);
1150 if (intSelected == -1){
1154 intContactSeekNum = lstContacts->GetItemData(intSelected);
1156 // Get the filename of the selected contact.
1158 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1159 frmContactEditor *ContactEditor = new frmContactEditor( this );
1163 ContactEditor->SetUID(WindowMenuItemID);
1165 WindowData *WData = new WindowData;
1167 WData->DataType = 1;
1168 WData->WindowPointer = (void*)ContactEditor;
1169 WData->WindowID = WindowMenuItemID;
1171 wxCommandEvent addevent(WINDOW_ADD);
1172 addevent.SetClientData(WData);
1173 wxPostEvent(this, addevent);
1175 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1176 ContactEditor->SetupHeaders();
1178 // Check if pointer is NULL (not from the search forms) or not.
1180 if (DataCheck == 0){
1182 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1183 ContactEditor->SetupContact(ActiveAccount);
1187 UCNotif *uc = (UCNotif*)event.GetClientData();
1191 ContactEditor->SetupContact(ActiveAccount);
1192 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1196 ContactEditor->SetupContact(uc->ContactAccount);
1197 ContactEditor->LoadContact(uc->ContactFilename);
1207 ContactEditor->SetIcon(contacticon);
1208 ContactEditor->Show(true);
1212 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1214 // Check if ActiveAccount is empty. If not then check if
1215 // account type is not local otherwise continue.
1217 if (!ActiveAccount.IsEmpty()){
1219 if (ActiveAccountType != wxT("Local")){
1221 // Account type is not local.
1223 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1224 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1225 wxT(""), wxT(""), wxT(""), wxT(""));
1229 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1237 void frmMain::OpenContactInfoList( wxListEvent& event )
1240 wxStringTokenizer vcardfileline;
1243 wxString setname, setvalue;
1247 long intSelected = -1;
1248 long intContactSeekNum = -1;
1250 intSelected = lstContacts->GetNextItem(intSelected,
1252 wxLIST_STATE_SELECTED);
1254 intContactSeekNum = lstContacts->GetItemData(intSelected);
1256 if (intContactSeekNum == -1){
1260 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1262 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1263 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1264 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1266 contacticon.CopyFromBitmap(contacticonbmp);
1268 frmContact *Contact = new frmContact( this );
1270 // Add to window list.
1274 Contact->SetUID(WindowMenuItemID);
1276 WindowData *WData = new WindowData;
1278 WData->DataType = 0;
1279 WData->WindowPointer = (void*)Contact;
1280 WData->WindowID = WindowMenuItemID;
1282 wxCommandEvent addevent(WINDOW_ADD);
1283 addevent.SetClientData(WData);
1284 wxPostEvent(this, addevent);
1286 Contact->SetupPointers(&MemoryFileList);
1287 Contact->SetupContactData(&Person);
1289 Contact->SetIcon(contacticon);
1290 Contact->Show(true);
1294 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1297 OpenContactInfoList(pevent);
1301 void frmMain::OpenContactInfo( wxCommandEvent& event )
1304 UCNotif *uc = (UCNotif*)event.GetClientData();
1306 wxStringTokenizer vcardfileline;
1309 wxString setname, setvalue;
1313 Person.LoadFile(uc->ContactFilename);
1315 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1316 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1317 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1319 contacticon.CopyFromBitmap(contacticonbmp);
1321 frmContact *Contact = new frmContact( this );
1323 // Add to window list.
1327 Contact->SetUID(WindowMenuItemID);
1329 WindowData *WData = new WindowData;
1331 WData->DataType = 0;
1332 WData->WindowPointer = (void*)Contact;
1333 WData->WindowID = WindowMenuItemID;
1335 wxCommandEvent addevent(WINDOW_ADD);
1336 addevent.SetClientData(WData);
1337 wxPostEvent(this, addevent);
1339 Contact->SetupPointers(&MemoryFileList);
1340 Contact->SetupContactData(&Person);
1342 Contact->SetIcon(contacticon);
1343 Contact->Show(true);
1348 void frmMain::LoadPreferences( wxActivateEvent& event)
1350 this->LoadPreferences();
1353 void frmMain::LoadPreferences(){
1355 // Load the preferences.
1357 wxString preffilename = GetUserPrefDir();
1359 XABPreferences preferences(preffilename);
1361 // Setup the main window position (if needed).
1363 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1364 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1366 if (SaveWindowPos == TRUE){
1368 this->SetSize(preferences.GetMainWindowData());
1372 treAccounts->DeleteAllItems();
1374 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1376 // Stop all account timers and remove the accounts.
1378 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1379 iter != AccountSyncTimers.end(); iter++){
1381 wxAccountSyncTimer *AccTmrPtr = iter->second;
1389 AccountSyncTimers.clear();
1392 wxString AccDirFull;
1393 wxString AccDirFullSfx;
1395 wxString AccDirFinal;
1396 AccountAccDirList.clear();
1397 AccountGroupList.clear();
1398 AccountGroupFilename.clear();
1399 AccountGroupTreeId.clear();
1400 wxTreeItemId AccountTreeId;
1401 wxTreeItemId GroupTreeId;
1404 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1406 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1407 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1413 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1419 AccDir = preferences.accounts.GetAccountDirectory(i);
1420 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1422 AccDirFull.Append(wxT("."));
1423 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1424 AccDirFullSfx.LowerCase();
1425 AccDirFullSfx.Trim();
1426 AccDirFull.Append(AccDirFullSfx);
1427 AccName = preferences.accounts.GetAccountName(i);
1429 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1431 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1432 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1434 // TODO: Check if the directory exists before doing anything.
1438 // Add a new timer using the existing account details.
1440 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1442 ActTmrPtr->SetupData(AccDirFull, AccName);
1443 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1444 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1445 ActTmrPtr->SetOwner(this);
1446 ActTmrPtr->Notify();
1448 // Add the timer to the list of timers.
1450 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1452 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1456 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1460 // Go through the account directory and find contact files with
1461 // 'KIND:group' set and add them to the list of groups for the account.
1463 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1465 wxDir vcardaccdir(AccDirFinal);
1467 wxString vCardFilename;
1468 wxString vCardDataString;
1469 wxString vCardFilenameFull;
1471 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1474 if (vCardFilename.Right(4) == wxT(".vcf") ||
1475 vCardFilename.Right(4) == wxT(".VCF") ||
1476 vCardFilename.Right(5) == wxT(".vcard") ||
1477 vCardFilename.Right(5) == wxT(".VCARD")){
1481 vCardFilenameFull.Append(AccDirFinal);
1482 vCardFilenameFull.Append(wxT("/"));
1483 vCardFilenameFull.Append(vCardFilename);
1485 Person.LoadFile(vCardFilenameFull);
1487 if (Person.MeetBaseSpecification()){
1489 vCardDataString = Person.Get(wxT("KIND"));
1491 if (vCardDataString == wxT("group")){
1493 // The vCard kind is a group. Add to the account's group list.
1495 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1496 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1497 AccountGroupList.insert(std::make_pair(intGroupID, i));
1498 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1499 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1511 vCardFilename.Clear();
1512 vCardFilenameFull.Clear();
1513 vCardDataString.Clear();
1514 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1518 // Clearup for next account.
1522 AccDirFullSfx.clear();
1523 AccDirFinal.clear();
1528 // Load the account settings as they are needed for connecting
1531 prefaccounts = preferences.accounts;
1535 void frmMain::ConflictResolution(wxCommandEvent& event){
1537 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1538 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1539 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1540 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1541 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1542 frameCR->ShowModal();
1544 int FinalConflictResult = frameCR->GetResult();
1546 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1547 event2.SetClientData(vCardConfObj->QRNotifData);
1548 event2.SetInt(FinalConflictResult);
1553 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1554 wxPostEvent(frameActMgr, event2);
1558 void frmMain::UpdateContactList(wxCommandEvent& event){
1560 UCNotif *ucd = (UCNotif*)event.GetClientData();
1562 // Check if the active account is being displayed in the
1563 // main window. If not, skip and delete the data.
1565 long longSelected = -1;
1566 int intSelectedData = 0;
1568 if (ActiveAccount == ucd->ContactAccount){
1570 // Look at the list of contacts and if it matches the
1571 // filename then update the name.
1575 longSelected = lstContacts->GetNextItem(longSelected,
1577 wxLIST_STATE_DONTCARE);
1579 if (longSelected == -1){
1585 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1587 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1589 // Work out which sorting mode we are in.
1593 // First Name, Last Name.
1595 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1597 } else if (SortMode == 2){
1599 // Last Name, First Name.
1601 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1603 } else if (SortMode == 3){
1607 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1609 } else if (SortMode == 4){
1613 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1620 // If the filename is the one loaded into the
1621 // browser control, then update this too.
1623 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1625 wxListEvent nullevent;
1626 ShowContactInfo(nullevent);
1634 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1635 WindowIter != WindowListPointers.end(); WindowIter++){
1637 if (WindowListType[WindowIter->first] != 0){
1643 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1645 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1647 vCard UpdatedPerson;
1648 UpdatedPerson.LoadFile(ucd->ContactFilename);
1649 frmContactPtr->SetupContactData(&UpdatedPerson);
1655 // Send message to search window controller subroutine and
1656 // pass that notification onto the search windows.
1658 // Setup the new pointer to use the existing UCNotif without
1661 UCNotif *ucd2 = ucd;
1663 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1664 sup.SetClientData(ucd2);
1665 wxPostEvent(this, sup);
1667 // Clear up the unused pointer.
1673 void frmMain::UpdateAccountList(wxCommandEvent& event){
1677 void frmMain::SetupPointers(void *ActMgrPtrInc){
1679 ActMgrPtr = ActMgrPtrInc;
1683 void frmMain::SetupForm(){
1685 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1686 frameActMgr->SetupPointers(&ETagProcTimer, this);
1688 // Setup the contact information icons for later.
1690 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1694 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1695 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1696 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1698 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1699 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1700 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1702 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1703 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1704 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1706 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1707 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1708 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1710 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1711 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1712 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1714 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1715 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1716 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1722 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1724 // Go through each of the search windows and
1725 // send the required notification to update the
1726 // contact information.
1728 // Get the event notification data.
1730 UCNotif *ucd = (UCNotif*)event.GetClientData();
1732 // Process each search window giving the new details.
1734 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1735 switer != SearchWindowList.end(); switer++){
1737 // Duplicate the event notification data.
1739 UCNotif *ucd2 = new UCNotif;
1741 ucd2->ContactAccount = ucd->ContactAccount;
1742 ucd2->ContactFilename = ucd->ContactFilename;
1743 ucd2->ContactName = ucd->ContactName;
1744 ucd2->ContactNickname = ucd->ContactNickname;
1745 ucd2->ContactNameArray = ucd->ContactNameArray;
1747 // Pass the data to the search window for processing.
1749 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1750 wxCommandEvent schupdate(SE_UPDATERESULT);
1751 schupdate.SetClientData(ucd2);
1752 wxPostEvent(frameSCH, schupdate);
1754 // Clear up the pointer prior to variable deletion.
1765 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1769 frmSearch *frameSCH = new frmSearch ( this );
1770 frameSCH->SetUID(WindowMenuItemID);
1771 frameSCH->Show(true);
1773 WindowData *WData = new WindowData;
1775 WData->DataType = 2;
1776 WData->WindowPointer = (void*)frameSCH;
1777 WData->WindowID = WindowMenuItemID;
1779 wxCommandEvent addevent(WINDOW_ADD);
1780 addevent.SetClientData(WData);
1781 wxPostEvent(this, addevent);
1783 // Add pointer to the list of open search windows.
1785 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1791 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1793 void *frameSCH = (void*)event.GetClientData();
1795 SearchWindowList.erase(frameSCH);
1801 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1803 void *frameSCH = (void*)event.GetClientData();
1805 SearchWindowList.erase(frameSCH);
1811 void frmMain::RevealContact(wxCommandEvent& event){
1813 UCNotif *uc = (UCNotif*)event.GetClientData();
1815 // Switch the account to the one passed.
1817 wxTreeItemIdValue cookie;
1818 wxTreeItemId next = treAccounts->GetRootItem();
1819 wxTreeItemId nextChild;
1821 for (int i = 0; i < prefaccounts.GetCount(); i++){
1824 nextChild = treAccounts->GetFirstChild(next, cookie);
1826 nextChild = treAccounts->GetNextSibling(nextChild);
1829 //AccountName = treAccounts->GetItemText(nextChild);
1831 if (uc->ContactAccount == AccountAccDirList[i]){
1834 treAccounts->SelectItem(nextChild, TRUE);
1835 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1841 // Switch the contact to the one passed.
1843 long longSelected = -1;
1844 int intSelectedData = 0;
1848 longSelected = lstContacts->GetNextItem(longSelected,
1850 wxLIST_STATE_DONTCARE);
1852 if (longSelected == -1){
1858 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1860 // Compare the filename with the one received.
1861 // If they match then select it.
1863 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1867 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1868 lstContacts->EnsureVisible(longSelected);
1872 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1880 void frmMain::DeleteContact(wxCommandEvent& event){
1882 // Check if a contact is selected.
1884 long intSelected = -1;
1885 long intContactSeekNum = -1;
1886 wxString wxSContactName;
1888 intSelected = lstContacts->GetNextItem(intSelected,
1890 wxLIST_STATE_SELECTED);
1892 if (intSelected == -1){
1896 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1898 // Get the item data of the contact.
1900 intContactSeekNum = lstContacts->GetItemData(intSelected);
1902 // Get the name of the contact.
1904 wxSContactName = lstContacts->GetItemText(intSelected);
1906 // Display a message confirming if the contact should
1909 int QuestionResponse;
1911 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1913 if (QuestionResponse == wxNO){
1915 // Exit the subroutine
1921 // Delete the contact.
1923 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1925 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1930 // Remove the contact from the list.
1932 lstContacts->DeleteItem(intSelected);
1934 // Update the search windows, removing the deleted
1937 UCNotif *ucd = new UCNotif;
1939 ucd->ContactAccount = ActiveAccount;
1940 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1942 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1943 switer != SearchWindowList.end(); switer++){
1945 // Duplicate the event notification data.
1947 UCNotif *ucd2 = new UCNotif;
1949 ucd2->ContactAccount = ucd->ContactAccount;
1950 ucd2->ContactFilename = ucd->ContactFilename;
1952 // Pass the data to the search window for processing.
1954 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1955 wxCommandEvent schdelete(SE_DELETERESULT);
1956 schdelete.SetClientData(ucd2);
1957 wxPostEvent(frameSCH, schdelete);
1959 // Clear up the pointer prior to variable deletion.
1966 // Clear the wxHTMLWindow.
1968 wxString EmptyPage = wxT("");
1970 htmContactData->SetPage(EmptyPage);
1972 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
1974 wxString wxSplitFilename;
1975 wxString wxSDataURL;
1977 while(wSTFilename.HasMoreTokens()){
1979 wxSplitFilename = wSTFilename.GetNextToken();
1983 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
1985 // Update the ETagDB and mark it as deleted.
1987 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
1989 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
1991 // Get the Data URL.
1993 wxTreeItemIdValue cookie;
1994 wxTreeItemId next = treAccounts->GetRootItem();
1996 wxTreeItemId selectedChild = treAccounts->GetSelection();
1997 wxTreeItemId nextChild;
1999 for (int i = 0; i < prefaccounts.GetCount(); i++){
2002 nextChild = treAccounts->GetFirstChild(next, cookie);
2005 nextChild = treAccounts->GetNextSibling(nextChild);
2008 if (nextChild == selectedChild){
2009 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2015 // Add task to the activity monitor to delete the contact.
2017 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2021 // Clear the variable. Don't delete as it will mess things up.
2023 ContactsFileIndex[intContactSeekNum] = wxT("");
2030 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2032 QRNotif *qrn = (QRNotif *)event.GetClientData();
2034 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);
2036 if (QResponse == wxNO){
2042 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2043 event2.SetInt(*qrn->QResponse);
2044 event2.SetClientData(qrn->PausePtr);
2046 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2048 wxPostEvent(frameActMgr, event2);
2052 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2054 // Remove the contact from the window after syncronising.
2056 // Check which account is currently active in the window.
2057 // If it is different from the one passed to this subroutine then
2058 // exit from the subroutine.
2060 if (Account != ActiveAccount){
2064 long longSelected = -1;
2065 int intSelectedData = 0;
2069 longSelected = lstContacts->GetNextItem(longSelected,
2071 wxLIST_STATE_DONTCARE);
2073 if (longSelected == -1){
2079 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2081 // Compare the filename with the one received.
2082 // If they match then select it.
2084 if (ContactsFileIndex[intSelectedData] == Filename){
2086 // Remove the contact from the window.
2088 lstContacts->DeleteItem(intSelectedData);
2090 // Check if contact is the selected contact in the HTML window and
2091 // if it is then clear the window.
2093 if (ActiveFilename == Filename){
2095 wxString EmptyPage = wxT("");
2096 htmContactData->SetPage(EmptyPage);
2110 void frmMain::SortFNLN( wxCommandEvent& event ) {
2112 wxTreeEvent NullEvent;
2114 LoadContactList(NullEvent);
2118 void frmMain::SortLNFN( wxCommandEvent& event ) {
2120 wxTreeEvent NullEvent;
2122 LoadContactList(NullEvent);
2126 void frmMain::SortNickname( wxCommandEvent& event ) {
2128 wxTreeEvent NullEvent;
2130 LoadContactList(NullEvent);
2134 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2136 wxTreeEvent NullEvent;
2138 LoadContactList(NullEvent);
2142 void frmMain::SortAscending( wxCommandEvent& event ) {
2144 wxTreeEvent NullEvent;
2145 AscendingMode = TRUE;
2146 LoadContactList(NullEvent);
2150 void frmMain::SortDescending( wxCommandEvent& event ) {
2152 wxTreeEvent NullEvent;
2153 AscendingMode = FALSE;
2154 LoadContactList(NullEvent);
2158 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2160 if (stbBottom->IsShown() == TRUE){
2174 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2176 // Display the activity icon.
2178 imgActivityStatus->SetBitmap(*imgActIcon1);
2179 ActivityIconStatus = 0;
2183 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2185 switch (ActivityIconStatus){
2188 imgActivityStatus->SetBitmap(*imgActIcon1);
2189 ActivityIconStatus = 1;
2192 imgActivityStatus->SetBitmap(*imgActIcon2);
2193 ActivityIconStatus = 2;
2196 imgActivityStatus->SetBitmap(*imgActIcon3);
2197 ActivityIconStatus = 3;
2200 imgActivityStatus->SetBitmap(*imgActIcon4);
2201 ActivityIconStatus = 0;
2204 ActivityIconStatus = 0;
2210 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2212 // Display the sleep icon.
2214 imgActivityStatus->SetBitmap(*imgActIconSleep);
2218 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2220 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2228 wxRect rectActivity;
2229 stbBottom->GetFieldRect(1, rectOnline);
2230 stbBottom->GetFieldRect(2, rectSSL);
2231 stbBottom->GetFieldRect(3, rectActivity);
2233 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2234 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2235 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2239 XABViewMode frmMain::GetViewMode(){
2243 xvm.SortMode = SortMode;
2244 xvm.AscendingMode = AscendingMode;
2250 void frmMain::WindowAdd( wxCommandEvent &event ){
2252 WindowData *WData = (WindowData*)event.GetClientData();
2256 if (WData->DataType == 0){
2260 int intID = mnuContactWindows->GetId();
2262 mnuWindow->FindChildItem(intID, &pos);
2263 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2264 mnuNewItem->SetId(WData->WindowID);
2265 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2266 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2267 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2268 mnuWindow->Insert((pos + 1), mnuNewItem);
2269 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2271 } else if (WData->DataType == 1){
2273 // Contact Editor Window
2275 int intID = mnuContactEditorWindows->GetId();
2277 mnuWindow->FindChildItem(intID, &pos);
2278 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2279 mnuNewItem->SetId(WData->WindowID);
2280 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2281 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2282 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2283 mnuWindow->Insert((pos + 1), mnuNewItem);
2284 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2286 } else if (WData->DataType == 2){
2290 int intID = mnuSearchWindows->GetId();
2292 mnuWindow->FindChildItem(intID, &pos);
2293 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2294 mnuNewItem->SetId(WData->WindowID);
2295 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2296 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2297 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2298 mnuWindow->Insert((pos + 1), mnuNewItem);
2299 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2308 void frmMain::WindowEdit( wxCommandEvent &event ){
2310 WindowData *WData = (WindowData*)event.GetClientData();
2312 if (WData->DataType == 0){
2314 // Get the window title and use that.
2316 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2318 wxString WindowTitle = frmContactPtr->GetTitle();
2320 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2322 MenuIter->second->SetItemLabel(WindowTitle);
2324 } else if (WData->DataType == 1){
2326 // Get the window title and use that.
2328 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2330 wxString WindowTitle = frmCEPtr->GetTitle();
2332 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2334 if (WindowTitle.IsEmpty()){
2336 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2340 MenuIter->second->SetItemLabel(WindowTitle);
2351 void frmMain::WindowDelete( wxCommandEvent &event ){
2353 WindowData *WData = (WindowData*)event.GetClientData();
2355 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2357 mnuWindow->Remove(MenuIter->second);
2359 delete MenuIter->second;
2360 MenuIter->second = NULL;
2362 WindowListPointersMenu.erase(WData->WindowID);
2363 WindowListPointers.erase(WData->WindowID);
2364 WindowListType.erase(WData->WindowID);
2371 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2373 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2375 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2377 frmContactPtr->Show();
2378 frmContactPtr->Raise();
2382 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2384 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2386 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2393 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2395 // Look through the Search Window List Pointers, grab the
2396 // window point and show the window.
2398 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2400 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2402 frmSearchPtr->Show();
2403 frmSearchPtr->Raise();
2407 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2409 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2410 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2411 wxPostEvent(frameActMgr, toggconn);
2415 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2417 // Check the account type before continuing.
2419 wxString SeekAccount;
2420 wxString AccTypeLower;
2423 std::map<int, SSLCertCollection>::iterator SSLColIter;
2425 for (int i = 0; i < prefaccounts.GetCount(); i++){
2427 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2428 AccType.Append(prefaccounts.GetAccountType(i));
2429 AccountSSL = prefaccounts.GetAccountSSL(i);
2430 AccTypeLower = AccType.MakeLower();
2431 SeekAccount.Append(wxT("."));
2432 SeekAccount.Append(AccTypeLower);
2434 if (SeekAccount == ActiveAccount){
2436 if (AccTypeLower == wxT("local")){
2442 if (AccountSSL == false){
2448 SSLColIter = AccountSSLData.find(i);
2450 SSLCertCollection SSLCertInfo = SSLColIter->second;
2452 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2453 frameSSLCert->StartCertFrom(0);
2454 frameSSLCert->SetupCerts(SSLCertInfo);
2455 frameSSLCert->ShowModal();
2457 delete frameSSLCert;
2458 frameSSLCert = NULL;
2462 SeekAccount.Clear();
2463 AccTypeLower.Clear();
2470 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2472 // Check the account type before continuing.
2476 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2478 // Check the account type before continuing.
2482 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2484 if (event.GetInt() == 0){
2486 imgConnStatus->SetBitmap(*imgOnline);
2490 imgConnStatus->SetBitmap(*imgOffline);
2496 void frmMain::SetupSSLStatus( int AccountID ){
2498 // Check if account ID given is
2499 // the active account and if not, do nothing.
2502 wxString AccTypeLower;
2504 AccType = prefaccounts.GetAccountType(AccountID);
2505 AccTypeLower = AccType.MakeLower();
2507 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2510 if (AccountIDName != ActiveAccount){
2516 // Check if the account has SSL enabled.
2518 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2520 if (SSLInUse == FALSE){
2522 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2523 imgSSLStatus->SetBitmap(*imgNoSSL);
2527 // Get the SSL Collection Data.
2529 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2531 if (SSLResultIter->second == 1){
2533 imgSSLStatus->SetBitmap(*imgSSLWarning);
2534 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2535 prefaccounts.GetAccountName(AccountID) +
2536 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2539 } else if (SSLResultIter->second == 0){
2541 imgSSLStatus->SetBitmap(*imgSSL);
2542 SSLToolTip->SetTip(wxT("Account '") +
2543 prefaccounts.GetAccountName(AccountID) +
2544 wxT("' secured using SSL\n\nDouble click for more information."));
2552 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2554 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2555 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2556 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2557 wxString AccountName = SSLICNObj->AccountName;
2558 frameISC->LoadData(SSLCCData, AccountName);
2559 frameISC->ShowModal();
2561 int FinalConflictResult = frameISC->GetResult();
2563 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2564 event2.SetClientData(SSLICNObj->QRNotifData);
2565 event2.SetInt(FinalConflictResult);
2570 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2571 wxPostEvent(frameActMgr, event2);
2574 void frmMain::PauseAllTimers(){
2576 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2577 ASTiter != AccountSyncTimers.end(); ASTiter++){
2579 ASTiter->second->Stop();
2585 void frmMain::ResumeAllTimers(){
2587 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2588 ASTiter != AccountSyncTimers.end(); ASTiter++){
2590 ASTiter->second->Start();
2596 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2598 // Delete existing data.
2600 AccountSSLData.erase(AccountID);
2601 AccountSSLResult.erase(AccountID);
2605 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2606 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2610 void frmMain::CheckUpdates( wxCommandEvent& event ){
2612 frmUpdate *frameUpdate = new frmUpdate ( this );
2613 frameUpdate->FetchData();
2614 frameUpdate->ShowModal();
2618 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2620 // Run the import contacts system.
2626 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2628 // Check if an account and at least one contact is selected
2629 // before continuing.
2631 wxArrayString ArrData;
2633 if (ActiveAccount.IsEmpty()){
2639 int ContactSelected = 0;
2640 int ContactsCollected = 0;
2641 long longSelected = -1;
2645 longSelected = lstContacts->GetNextItem(longSelected,
2647 wxLIST_STATE_SELECTED);
2649 if (longSelected == -1){
2655 int FileID = (int)lstContacts->GetItemData(longSelected);
2657 ArrData.Insert(ContactsFileIndex[FileID],
2658 ContactsCollected, 1);
2664 if (ContactSelected == 0){
2670 // Run the export contacts system.
2672 ExportRun(this, &ArrData);
2676 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2677 wxArrayString *ContactsFileIndexPtr){
2679 lstContactsPtr = lstContacts;
2680 ContactsFileIndexPtr = &ContactsFileIndex;
2684 void frmMain::GetSelectedList( wxCommandEvent& event ){
2686 // Get the array of contact filenames.
2688 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2690 // Process them into an array of files.
2692 long longSelected = -1;
2693 int ContactsCollected = 0;
2694 wxString ContactFilename;
2698 longSelected = lstContacts->GetNextItem(longSelected,
2700 wxLIST_STATE_SELECTED);
2702 if (longSelected == -1){
2708 // Get the file information and add to the list.
2710 int FileID = (int)lstContacts->GetItemData(longSelected);
2712 ArrData->Insert(ContactsFileIndex[FileID],
2713 ContactsCollected, 1);
2715 ContactsCollected++;
2716 ContactFilename.Clear();
2724 void frmMain::SyncAccount( wxCommandEvent& event ){
2726 wxString AccNameInc = event.GetString();
2728 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2729 frameActMgr->AddTask(3, wxT(""), AccNameInc,
2730 wxT(""), wxT(""), wxT(""), wxT(""));
2734 void frmMain::ShowHelp( wxCommandEvent& event ){
2736 // Based on the operating system, work out where
2737 // the documentation should be.
2741 #if defined(__HAIKU__)
2743 #elif defined(__WIN32__)
2749 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2751 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2754 #if XSDAB_RELEASE == 0
2756 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2758 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2767 #if XSDAB_RELEASE == 0
2769 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2773 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!"));
2779 void frmMain::ShowImportResults( wxCommandEvent &event ){
2781 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2783 frmImportResults *frmIR = new frmImportResults(this);
2784 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
2795 void frmMain::ReloadContactList( wxCommandEvent &event ){
2797 // Check if the account name given is the current
2798 // account selected.
2800 if (ActiveAccount == event.GetString()){
2802 wxTreeEvent NullEvent;
2803 LoadContactList(NullEvent);
2809 void frmMain::ShowContactMenu( wxMouseEvent& event ){
2811 bool EnableRefresh = FALSE;
2813 if (!ActiveAccount.IsEmpty()){
2815 EnableRefresh = TRUE;
2819 ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
2821 this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);