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 "contacteditor/frmContactEditor.h"
58 #include "import/import.h"
59 #include "export/export.h"
60 #include "widgets/XABContactMenu.h"
61 #include "widgets/XABAccountView.h"
65 // Define the event types.
67 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
68 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
69 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
70 DEFINE_EVENT_TYPE(CE_OPENCONTACTLIST);
71 DEFINE_EVENT_TYPE(CE_NEWCONTACT);
72 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
73 DEFINE_EVENT_TYPE(CE_DELETECONTACT);
74 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
75 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
76 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
77 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
78 DEFINE_EVENT_TYPE(ACTMGR_START);
79 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
80 DEFINE_EVENT_TYPE(ACTMGR_STOP);
81 DEFINE_EVENT_TYPE(WINDOW_ADD);
82 DEFINE_EVENT_TYPE(WINDOW_EDIT);
83 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
84 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
85 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
86 DEFINE_EVENT_TYPE(INVALIDSSLCERTSTRING);
87 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
88 DEFINE_EVENT_TYPE(SYNCACCOUNT);
89 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
90 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
91 DEFINE_EVENT_TYPE(REFRESHADDRESSBOOK);
92 #if defined(__APPLE__)
93 DEFINE_EVENT_TYPE(INVALIDSSLTRUST);
96 // Setup the event table using the event types.
98 BEGIN_EVENT_TABLE(frmMain, wxFrame)
99 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
100 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
101 EVT_COMMAND(wxID_ANY, 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, INVALIDSSLCERTSTRING, frmMain::InvalidSSLCertificateString)
119 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
120 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
121 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
122 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
123 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
124 #if defined(__APPLE__)
125 EVT_COMMAND(wxID_ANY, INVALIDSSLTRUST, frmMain::DisplayTrustPanel)
129 frmMain::frmMain( wxWindow* parent )
134 // Setup the account icons.
136 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
137 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
138 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
139 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
140 wxMemoryInputStream estream(icons_accunsupported_png, sizeof(icons_accunsupported_png));
142 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
143 wxBitmap AccInet(icons_accinet_png, -1);
145 wxIAccInet.CopyFromBitmap(AccInet);
147 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
148 wxBitmap AccNIcon(icons_acclocal_png, -1);
150 wxIAccNIcon.CopyFromBitmap(AccNIcon);
152 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
153 wxBitmap AccGrp(icons_accgroup_png, -1);
155 wxIAccGrp.CopyFromBitmap(AccGrp);
157 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
158 wxBitmap AccNone(icons_accnone_png, -1);
160 wxIAccNone.CopyFromBitmap(AccNone);
162 wxImage icons_accunsupported_png(estream, wxBITMAP_TYPE_PNG);
163 wxBitmap AccUnsupported(icons_accunsupported_png, -1);
164 wxIcon wxIAccUnsupported;
165 wxIAccUnsupported.CopyFromBitmap(AccUnsupported);
167 AccountID = AccImgList->Add(wxIAccNIcon);
168 AccountNetID = AccImgList->Add(wxIAccInet);
169 AccountGrpID = AccImgList->Add(wxIAccGrp);
170 AccountNoneID = AccImgList->Add(wxIAccNone);
171 AccountUnsupportedID = AccImgList->Add(wxIAccUnsupported);
173 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
175 // Setup the status bar icons.
179 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
180 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
181 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
183 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
184 imgSSL = new wxBitmap(icons_ssl_png, -1);
186 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
187 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
189 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
190 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
194 wxMemoryInputStream addaddressbook(toolbar_addaddressbook_png, sizeof(toolbar_addaddressbook_png));
195 wxMemoryInputStream preferences(toolbar_preferences_png, sizeof(toolbar_preferences_png));
196 wxMemoryInputStream searchcontacts(toolbar_searchcontacts_png, sizeof(toolbar_searchcontacts_png));
197 wxMemoryInputStream addcontact(toolbar_addcontact_png, sizeof(toolbar_addcontact_png));
198 wxMemoryInputStream editcontact(toolbar_editcontact_png, sizeof(toolbar_editcontact_png));
199 wxMemoryInputStream deletecontact(toolbar_deletecontact_png, sizeof(toolbar_deletecontact_png));
201 wxImage toolbar_addaddressbook_png(addaddressbook, wxBITMAP_TYPE_PNG);
202 imgAddAddressBook = new wxBitmap (toolbar_addaddressbook_png, -1);
203 tblMain->SetToolNormalBitmap(tbtNewAccount->GetId(), *imgAddAddressBook);
205 wxImage toolbar_preferences_png(preferences, wxBITMAP_TYPE_PNG);
206 imgPreferences = new wxBitmap (toolbar_preferences_png, -1);
207 tblMain->SetToolNormalBitmap(tbtPreferences->GetId(), *imgPreferences);
209 wxImage toolbar_searchcontacts_png(searchcontacts, wxBITMAP_TYPE_PNG);
210 imgSearchContacts = new wxBitmap (toolbar_searchcontacts_png, -1);
211 tblMain->SetToolNormalBitmap(tbtSearch->GetId(), *imgSearchContacts);
213 wxImage toolbar_addcontact_png(addcontact, wxBITMAP_TYPE_PNG);
214 imgAddContact = new wxBitmap (toolbar_addcontact_png, -1);
215 tblMain->SetToolNormalBitmap(tbtAddContact->GetId(), *imgAddContact);
217 wxImage toolbar_editcontact_png(editcontact, wxBITMAP_TYPE_PNG);
218 imgEditContact = new wxBitmap (toolbar_editcontact_png, -1);
219 tblMain->SetToolNormalBitmap(tbtEditContact->GetId(), *imgEditContact);
221 wxImage toolbar_deletecontact_png(deletecontact, wxBITMAP_TYPE_PNG);
222 imgDeleteContact = new wxBitmap (toolbar_deletecontact_png, -1);
223 tblMain->SetToolNormalBitmap(tbtDeleteContact->GetId(), *imgDeleteContact);
227 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
228 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
229 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
230 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
231 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
233 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
234 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
236 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
237 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
239 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
241 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
242 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
244 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
246 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
247 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
249 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
251 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
252 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
254 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
256 // Online/Offline icons.
258 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
259 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
261 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
262 imgOnline = new wxBitmap(icons_online_png, -1);
264 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
265 imgOffline = new wxBitmap(icons_offline_png, -1);
267 // Setup the account view.
269 AccCtrl->SetPopupControl(treAccounts);
270 AccCtrl->SetPopupMaxHeight(175);
271 AccCtrl->SetPopupMinWidth(250);
272 treAccounts->AssignImageList(AccImgList);
274 wxListItem ColumnData;
276 ColumnData.SetText(wxT("Name0"));
277 ColumnData.SetWidth(320);
278 lstContacts->InsertColumn(0, ColumnData);
280 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
281 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
283 #if defined(__HAIKU__)
285 #elif defined(__WIN32__)
287 int stbBottomData [4] = { -1, 8, 8, 8 };
291 int stbBottomData [4] = { -1, 20, 20, 20 };
295 stbBottom->SetFieldsCount(4, stbBottomData);
296 stbBottom->SetMinHeight(16);
301 stbBottom->GetFieldRect(1, rectOnline);
302 stbBottom->GetFieldRect(2, rectSSL);
303 stbBottom->GetFieldRect(3, rectActivity);
305 SSLToolTip = new wxToolTip(wxT(""));
307 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
308 imgConnStatus->SetBitmap(*imgOnline);
309 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
311 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
312 imgSSLStatus->SetBitmap(*imgNoSSL);
313 imgSSLStatus->SetToolTip(SSLToolTip);
314 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
316 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
317 imgActivityStatus->SetBitmap(*imgActIconSleep);
318 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
320 // Setup the window menu.
322 // By default should be:
327 // Contact editor windows:
333 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
334 mnuWindow->Append( mnuContactWindows );
336 mnuWindow->AppendSeparator();
338 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
339 mnuWindow->Append( mnuContactEditorWindows );
341 mnuWindow->AppendSeparator();
343 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
344 mnuWindow->Append( mnuSearchWindows );
346 #if defined(__WIN32__)
351 mnuContactWindows->SetFont(fontstyle);
352 mnuContactEditorWindows->SetFont(fontstyle);
353 mnuSearchWindows->SetFont(fontstyle);
357 mnuContactWindows->Enable(FALSE);
358 mnuContactEditorWindows->Enable(FALSE);
359 mnuSearchWindows->Enable(FALSE);
363 // Hide unimplemented functions.
369 void frmMain::QuitApp( wxCloseEvent& event )
372 // Run the QuitApp function.
378 void frmMain::QuitApp( wxCommandEvent& event )
381 // Run the QuitApp function.
387 void frmMain::QuitApp()
390 // Function to run when quitting.
392 // Write out the ETag databases.
394 ETagProcTimer.Stop();
395 ETagProcTimer.Notify();
397 // Save Preferences: Save the window position if that option is enabled.
399 wxString SetFilename = GetUserPrefDir();
401 #if defined(__HAIKU__)
405 #elif defined(__WIN32__)
407 SetFilename.Append(wxT("settings"));
413 SetFilename.Append(wxT("settings"));
417 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
419 bool SaveWindowPos = FALSE;
420 wxString SaveWindowInc;
421 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
423 if (SaveWindowInc == wxT("true")){
425 SaveWindowPos = TRUE;
429 if (SaveWindowPos == TRUE){
431 wxRect frmMainPos = GetRect();
433 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
434 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
435 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
436 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
443 // Everything closed... exit.
451 void frmMain::ShowActivityWindow( wxCommandEvent& event )
454 // Open the activity manager window.
456 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
457 frameActMgr->OpenWindow();
462 void frmMain::ShowAboutWindow( wxCommandEvent& event )
465 // Show the about window.
467 frmAbout *frameAbout = new frmAbout ( this );
468 frameAbout->SetupAboutWindow();
469 frameAbout->ShowModal();
475 void frmMain::OpenPreferences( wxCommandEvent& event)
478 // Close all windows first.
480 if (CloseAllWindows() == false)
485 // Open the preferences window.
487 ReloadAccounts = FALSE;
489 frmPreferences *framePreferences = new frmPreferences ( this );
490 framePreferences->SetupPointers(&ReloadAccounts);
491 framePreferences->ShowModal();
492 delete framePreferences;
493 framePreferences = NULL;
495 if (ReloadAccounts == TRUE){
497 // Reload the accounts as a change has been made within
498 // the application and clear the current contact information.
500 this->LoadPreferences(true);
501 this->ResetContactInfo();
507 void frmMain::OpenNewABDialog( wxCommandEvent& event)
510 // Open the new account dialog.
512 ReloadAccounts = FALSE;
514 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
515 frameNewAccount->SetupPointers(&ReloadAccounts);
516 frameNewAccount->ShowModal();
517 delete frameNewAccount;
518 frameNewAccount = NULL;
520 if (ReloadAccounts == TRUE){
522 // Reload the accounts as a change has been made within
525 this->LoadPreferences(true);
531 void frmMain::LoadContactList( wxTreeEvent& event )
534 // Load the contact list.
536 // Clear all existing variables.
538 lstContacts->DeleteAllItems();
540 treAccounts->SetAccount();
542 wxTreeItemIdValue cookie;
543 wxTreeItemId next = treAccounts->GetRootItem();
544 wxString AccountName;
545 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
546 wxString AccountDirCmb;
547 long selectedaccount = 0;
549 wxTreeItemId selectedChild = treAccounts->GetSelection();
550 wxTreeItemId nextChild;
552 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
553 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
555 int SCImg = treAccounts->GetItemImage(selectedChild);
556 int AccountIndex = 0;
558 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
560 // Process each account.
562 for (int i = 0; i < prefaccounts.GetCount(); i++){
564 if (ActiveItemIcon == 2){
566 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
567 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
568 int ActiveAccountG = AGLiter->second;
570 if (i == ActiveAccountG){
572 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
573 AccountType.Append(prefaccounts.GetAccountType(i));
578 if (AccountType == wxT("CardDAV")){
579 AccountTypeFinal.Append(wxT("carddav"));
580 } else if (AccountType == wxT("Local")){
581 imgSSLStatus->SetBitmap(*imgOffline);
582 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
583 AccountTypeFinal.Append(wxT("local"));
585 imgSSLStatus->SetBitmap(*imgOffline);
586 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
587 AccountTypeFinal.Append(AccountType.Lower());
598 nextChild = treAccounts->GetFirstChild(next, cookie);
600 nextChild = treAccounts->GetNextSibling(nextChild);
603 AccountName = treAccounts->GetItemText(nextChild);
605 if (nextChild == selectedChild){
607 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
608 AccountType.Append(prefaccounts.GetAccountType(i));
613 if (AccountType == wxT("CardDAV")){
614 AccountTypeFinal.Append(wxT("carddav"));
615 } else if (AccountType == wxT("Local")){
616 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
617 AccountTypeFinal.Append(wxT("local"));
619 AccountTypeFinal.Append(AccountType.Lower());
628 if (selectedaccount >= prefaccounts.GetCount()){
630 // The account selected isn't there so return.
638 // Open the directory and get the list of .vcf files
639 // in that directory.
641 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
642 ActiveAccountType = AccountType;
644 SetupSSLStatus(AccountIndex);
646 AccountDirFinal.Clear();
647 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
649 ContactsFileIndex.Clear();
651 wxString vCardFilename;
652 wxString vCardFilenameFull;
653 wxString vCardDataString;
654 wxStringTokenizer vcardfileline;
656 wxString setname, setvalue;
657 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
658 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
659 long ContactIndex = 1;
660 long ContactSeekPoint = 0;
662 wxDir vcardaccdir(AccountDirFinal);
664 // Get the wxTreeItemId and image icon and compare it to the list.
666 if (ActiveItemIcon == AccountGrpID){
668 // It's a group so load the file containing the group and
669 // get the members of the group.
674 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
675 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
677 Group.LoadFile(AGFiter->second);
679 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
681 for (int i = 0; i < vCardMember.PropCount; i++){
683 vCardMember.PropValues[i].Trim();
684 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
686 wxString NewPropValue;
687 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
688 vCardMember.PropValues[i] = NewPropValue;
694 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
698 if (vCardFilename.Right(4) == wxT(".vcf") ||
699 vCardFilename.Right(4) == wxT(".VCF") ||
700 vCardFilename.Right(5) == wxT(".vcard") ||
701 vCardFilename.Right(5) == wxT(".VCARD")){
704 bool FoundMember = FALSE;
706 vCardFilenameFull.Append(AccountDirFinal);
707 vCardFilenameFull.Append(wxT("/"));
708 vCardFilenameFull.Append(vCardFilename);
710 Person.LoadFile(vCardFilenameFull);
712 UIDCode = Person.Get(wxT("UID"));
714 for (int i = 0; i < vCardMember.PropCount; i++){
716 if (vCardMember.PropValues[i] == UIDCode){
724 if (FoundMember == FALSE){
726 vCardFilename.Clear();
727 vCardFilenameFull.Clear();
728 vCardDataString.Clear();
729 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
734 if (Person.MeetBaseSpecification()){
738 // Split the name into sections.
740 vCardDataString = Person.Get(wxT("N"));
742 vCardName NameData = Person.GetName();
744 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
746 } else if (SortMode == 2){
748 // Split the name into sections.
750 vCardName NameData = Person.GetName();
752 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
754 } else if (SortMode == 3){
756 // Check and make sure that the top most nickname is used.
758 vCardDataString = Person.Get(wxT("NICKNAME"));
760 if (vCardDataString.IsEmpty()){
762 vCardDataString = wxT("(no nickname)");
766 } else if (SortMode == 4){
768 vCardDataString = Person.Get(wxT("FN"));
772 if (AscendingMode == TRUE){
773 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
775 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
782 vCardFilename.Clear();
783 vCardFilenameFull.Clear();
784 vCardDataString.Clear();
785 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
791 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
794 if (vCardFilename.Right(4) == wxT(".vcf") ||
795 vCardFilename.Right(4) == wxT(".VCF") ||
796 vCardFilename.Right(5) == wxT(".vcard") ||
797 vCardFilename.Right(5) == wxT(".VCARD")){
801 vCardFilenameFull.Append(AccountDirFinal);
802 vCardFilenameFull.Append(vCardFilename);
804 Person.LoadFile(vCardFilenameFull);
806 if (Person.MeetBaseSpecification()){
810 // Split the name into sections.
812 vCardDataString = Person.Get(wxT("N"));
814 vCardName NameData = Person.GetName();
816 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
818 } else if (SortMode == 2){
820 // Split the name into sections.
822 vCardName NameData = Person.GetName();
824 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
826 } else if (SortMode == 3){
828 // Check and make sure that the top most nickname is used.
830 vCardDataString = Person.Get(wxT("NICKNAME"));
832 if (vCardDataString.IsEmpty()){
834 vCardDataString = wxT("(no nickname)");
838 } else if (SortMode == 4){
840 vCardDataString = Person.Get(wxT("FN"));
844 if (AscendingMode == TRUE){
846 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
850 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
858 vCardFilename.Clear();
859 vCardFilenameFull.Clear();
860 vCardDataString.Clear();
861 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
868 // Insert the data into the control.
870 if (AscendingMode == TRUE){
871 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
872 iter != vCardNamesAsc.end(); ++iter){
874 wxListItem ContactInfo;
876 ContactInfo.SetId(0);
877 ContactInfo.SetText(_("Mooo"));
878 ContactInfo.SetData(ContactSeekPoint);
879 ContactIndex = lstContacts->InsertItem(ContactInfo);
881 lstContacts->SetItem(ContactIndex, 0, iter->first);
883 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
890 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
891 iter != vCardNamesDsc.end(); ++iter){
893 wxListItem ContactInfo;
895 ContactInfo.SetId(0);
896 ContactInfo.SetText(_("Mooo"));
897 ContactInfo.SetData(ContactSeekPoint);
898 ContactIndex = lstContacts->InsertItem(ContactInfo);
900 lstContacts->SetItem(ContactIndex, 0, iter->first);
901 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
910 void frmMain::ShowContactInfo( wxListEvent& event )
913 // Display the contact information.
915 long intSelected = -1;
916 long ContactSeekNum = -1;
918 // Check if several contacts have been selected.
920 int ContactTotal = 0;
924 intSelected = lstContacts->GetNextItem(intSelected,
926 wxLIST_STATE_SELECTED);
928 if (intSelected == -1){
938 if (ContactTotal == 0){
939 htmContactData->SetPage(wxT(""));
943 if (ContactTotal > 1){
945 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
946 ActiveFilename.Clear();
951 intSelected = lstContacts->GetNextItem(intSelected,
953 wxLIST_STATE_SELECTED);
955 ContactSeekNum = lstContacts->GetItemData(intSelected);
958 wxString wxSContactString;
959 wxString ContactLine;
962 size_t ContactLineLen;
963 bool ExtraLineSeek = FALSE;
964 int QuoteBreakPoint = 0;
966 bool PropertyFind = FALSE;
967 bool QuoteMode = FALSE;
969 wxString wxSPropertyNextLine;
970 wxString wxSProperty;
971 wxString wxSPropertySeg1;
972 wxString wxSPropertySeg2;
974 // Check if we are using wxWidgets version 2.8 or less and
975 // execute the required command accordingly.
977 #if wxABI_VERSION < 20900
978 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
980 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
983 if (ContactFile.IsOpened() == FALSE){
989 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
993 std::map<int, wxString> ContactFileLines;
994 std::map<int, wxString>::iterator striter;
996 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
998 int ContactLineSeek = 0;
1000 while (wSTContactFileLines.HasMoreTokens() == TRUE){
1002 ContactLine = wSTContactFileLines.GetNextToken();
1003 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
1008 if (ContactSeekNum < 0){
1012 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
1013 iter != ContactFileLines.end(); ++iter){
1015 // Find the colon which splits the start bit from the data part.
1017 ContactLine = iter->second;
1019 while (ExtraLineSeek == TRUE){
1021 // Check if there is extra data on the next line
1022 // (indicated by space or tab at the start) and add data.
1026 if (iter == ContactFileLines.end()){
1033 wxSPropertyNextLine = iter->second;
1036 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
1038 wxSPropertyNextLine.Remove(0, 1);
1039 ContactLine.Append(wxSPropertyNextLine);
1044 ExtraLineSeek = FALSE;
1050 ContactLineLen = ContactLine.Len();
1052 // Make sure we are not in quotation mode.
1053 // Make sure colon does not have \ or \\ before it.
1055 for (int i = 0; i <= ContactLineLen; i++){
1057 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1059 PropertyFind = FALSE;
1061 } else if (PropertyFind == TRUE){
1063 wxSProperty.Append(ContactLine.Mid(i, 1));
1067 if (ContactLine.Mid(i, 1) == wxT("\"")){
1069 if (QuoteMode == TRUE){
1081 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1083 QuoteBreakPoint = i;
1090 // Split that line at the point into two variables (ignore the colon).
1092 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1093 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1095 // Insert both into the vCard data file.
1097 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1100 PropertyFind = TRUE;
1101 ExtraLineSeek = TRUE;
1103 QuoteBreakPoint = 0;
1104 ContactLine.Clear();
1105 wxSProperty.Clear();
1109 OldSessionID = SessionID;
1110 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1111 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList, ContactBackgroundColour);
1112 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1116 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1119 // Open a contact editor window to write a new contact with.
1121 // Check if there is an account selected and if not
1122 // return immediately.
1124 if (ActiveAccount.IsEmpty()){
1130 // Check if the account type is a valid account type, otherwise
1131 // display an error message.
1133 if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
1134 ActiveAccountType != "Local" && ActiveAccountType != "local"){
1136 wxMessageBox(_("Cannot add a new contact as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
1141 // Add Pointer to SetupPointers for the ETagDB.
1143 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1144 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1145 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1147 contacticon.CopyFromBitmap(contacticonbmp);
1149 frmContactEditor *ContactEditor = new frmContactEditor( this );
1153 ContactEditor->SetUID(WindowMenuItemID);
1155 WindowData *WData = new WindowData;
1157 WData->DataType = 1;
1158 WData->WindowPointer = (void*)ContactEditor;
1159 WData->WindowID = WindowMenuItemID;
1161 wxCommandEvent addevent(WINDOW_ADD);
1162 addevent.SetClientData(WData);
1163 wxPostEvent(this, addevent);
1165 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1166 ContactEditor->SetupHeaders();
1167 ContactEditor->SetupContact(ActiveAccount);
1168 ContactEditor->SetIcon(contacticon);
1169 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1170 ContactEditor->Show(true);
1174 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1177 // Open a contact editor window for editing an existing contact
1180 // Check if there is an account selected and if not
1181 // return immediately.
1183 int DataCheck = event.GetInt();
1185 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1191 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1192 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1193 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1195 contacticon.CopyFromBitmap(contacticonbmp);
1197 // Check if a contact has been selected.
1199 long intSelected = -1;
1200 long intContactSeekNum = -1;
1202 intSelected = lstContacts->GetNextItem(intSelected,
1204 wxLIST_STATE_SELECTED);
1206 if (intSelected == -1){
1212 intContactSeekNum = lstContacts->GetItemData(intSelected);
1214 // Get the filename of the selected contact.
1216 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1217 frmContactEditor *ContactEditor = new frmContactEditor( this );
1221 ContactEditor->SetUID(WindowMenuItemID);
1223 WindowData *WData = new WindowData;
1225 WData->DataType = 1;
1226 WData->WindowPointer = (void*)ContactEditor;
1227 WData->WindowID = WindowMenuItemID;
1229 wxCommandEvent addevent(WINDOW_ADD);
1230 addevent.SetClientData(WData);
1231 wxPostEvent(this, addevent);
1233 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1234 ContactEditor->SetupHeaders();
1236 if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
1237 ActiveAccountType != "Local" && ActiveAccountType != "local"){
1239 ContactEditor->SetupAccountData(true);
1243 // Check if pointer is NULL (not from the search forms) or not.
1245 if (DataCheck == 0){
1247 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1248 ContactEditor->SetupContact(ActiveAccount);
1252 UCNotif *uc = (UCNotif*)event.GetClientData();
1256 ContactEditor->SetupContact(ActiveAccount);
1257 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1261 ContactEditor->SetupContact(uc->ContactAccount);
1262 ContactEditor->LoadContact(uc->ContactFilename);
1271 ContactEditor->SetIcon(contacticon);
1272 ContactEditor->Show(true);
1276 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1278 // Refresh the address book data.
1280 // Check if ActiveAccount is empty. If not then check if
1281 // account type is not local otherwise continue.
1283 if (!ActiveAccount.IsEmpty()){
1285 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
1287 // Account type is not local.
1289 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1290 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1291 wxT(""), wxT(""), wxT(""), wxT(""));
1295 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported"), wxICON_ERROR);
1303 void frmMain::OpenContactInfoList( wxListEvent& event )
1306 // Open the contact information window.
1308 wxStringTokenizer vcardfileline;
1311 wxString setname, setvalue;
1315 long intSelected = -1;
1316 long intContactSeekNum = -1;
1318 intSelected = lstContacts->GetNextItem(intSelected,
1320 wxLIST_STATE_SELECTED);
1322 intContactSeekNum = lstContacts->GetItemData(intSelected);
1324 if (intContactSeekNum == -1){
1330 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1332 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1333 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1334 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1336 contacticon.CopyFromBitmap(contacticonbmp);
1338 frmContact *Contact = new frmContact( this );
1340 // Add to window list.
1344 Contact->SetUID(WindowMenuItemID);
1346 WindowData *WData = new WindowData;
1348 WData->DataType = 0;
1349 WData->WindowPointer = (void*)Contact;
1350 WData->WindowID = WindowMenuItemID;
1352 wxCommandEvent addevent(WINDOW_ADD);
1353 addevent.SetClientData(WData);
1354 wxPostEvent(this, addevent);
1356 Contact->SetupPointers(&MemoryFileList);
1357 Contact->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1358 Contact->SetupContactData(&Person);
1360 Contact->SetIcon(contacticon);
1361 Contact->Show(true);
1365 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1367 // Open a list of contact information windows.
1370 OpenContactInfoList(pevent);
1374 void frmMain::OpenContactInfo( wxCommandEvent& event )
1377 // Open the contact information window.
1379 UCNotif *uc = (UCNotif*)event.GetClientData();
1381 wxStringTokenizer vcardfileline;
1384 wxString setname, setvalue;
1388 Person.LoadFile(uc->ContactFilename);
1390 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1391 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1392 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1394 contacticon.CopyFromBitmap(contacticonbmp);
1396 frmContact *Contact = new frmContact( this );
1398 // Add to window list.
1402 Contact->SetUID(WindowMenuItemID);
1404 WindowData *WData = new WindowData;
1406 WData->DataType = 0;
1407 WData->WindowPointer = (void*)Contact;
1408 WData->WindowID = WindowMenuItemID;
1410 wxCommandEvent addevent(WINDOW_ADD);
1411 addevent.SetClientData(WData);
1412 wxPostEvent(this, addevent);
1414 Contact->SetupPointers(&MemoryFileList);
1415 Contact->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1416 Contact->SetupContactData(&Person);
1418 Contact->SetIcon(contacticon);
1419 Contact->Show(true);
1424 void frmMain::LoadPreferences( wxActivateEvent& event)
1427 // Load the preferences.
1429 this->LoadPreferences(true);
1433 void frmMain::LoadPreferences(bool skipWindowSizeReload){
1435 // Load the preferences.
1437 wxString preffilename = GetUserPrefDir();
1439 XABPreferences preferences(preffilename);
1441 // Clear the active account/filename information and account list.
1444 ActiveAccountType = "";
1445 ActiveFilename = "";
1446 lstContacts->DeleteAllItems();
1448 // Setup the main window position (if needed).
1450 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1451 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1452 bool UseBackgroundContactColour = preferences.GetBoolData(wxT("UseBackgroundContactColour"));
1454 if (SaveWindowPos == true && skipWindowSizeReload == false){
1456 this->SetSize(preferences.GetMainWindowData());
1460 if (UseBackgroundContactColour == true){
1462 ContactBackgroundColour = preferences.GetBackgroundContactColourData();
1466 ContactBackgroundColour = wxTransparentColour;
1470 treAccounts->DeleteAllItems();
1472 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1474 // Stop all account timers and remove the accounts.
1476 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1477 iter != AccountSyncTimers.end(); iter++){
1479 wxAccountSyncTimer *AccTmrPtr = iter->second;
1487 #if defined(__WIN32__)
1489 for (std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.begin();
1490 CertificateIter != AccountCertificateData.end(); CertificateIter++){
1492 CertFreeCertificateContext(CertificateIter->second);
1496 AccountCertificateData.clear();
1500 AccountSyncTimers.clear();
1503 wxString AccDirFull;
1504 wxString AccDirFullSfx;
1506 wxString AccDirFinal;
1507 AccountAccDirList.clear();
1508 AccountGroupList.clear();
1509 AccountGroupFilename.clear();
1510 AccountGroupTreeId.clear();
1511 wxTreeItemId AccountTreeId;
1512 wxTreeItemId GroupTreeId;
1515 // Relaod the accounts for the ETagProcTimer.
1517 ETagProcTimer.ReloadAccounts();
1519 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1521 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1522 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == true){
1528 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1534 AccDir = preferences.accounts.GetAccountDirectory(i);
1535 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1537 AccDirFull.Append(wxT("."));
1538 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1539 AccDirFullSfx.LowerCase();
1540 AccDirFullSfx.Trim();
1541 AccDirFull.Append(AccDirFullSfx);
1542 AccName = preferences.accounts.GetAccountName(i);
1544 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1546 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1547 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1549 // TODO: Check if the directory exists before doing anything.
1553 // Add a new timer using the existing account details.
1555 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1557 ActTmrPtr->SetupData(AccDirFull, AccName);
1558 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1559 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1560 ActTmrPtr->SetOwner(this);
1561 ActTmrPtr->Notify();
1563 // Add the timer to the list of timers.
1565 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1567 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1569 } else if (preferences.accounts.GetAccountType(i) == wxT("Local") ||
1570 preferences.accounts.GetAccountType(i) == wxT("local")) {
1572 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1576 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountUnsupportedID, -1);
1580 // Go through the account directory and find contact files with
1581 // 'KIND:group' set and add them to the list of groups for the account.
1583 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1585 wxDir vcardaccdir(AccDirFinal);
1587 wxString vCardFilename;
1588 wxString vCardDataString;
1589 wxString vCardFilenameFull;
1591 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1595 if (vCardFilename.Right(4) == wxT(".vcf") ||
1596 vCardFilename.Right(4) == wxT(".VCF") ||
1597 vCardFilename.Right(5) == wxT(".vcard") ||
1598 vCardFilename.Right(5) == wxT(".VCARD")){
1602 vCardFilenameFull.Append(AccDirFinal);
1603 vCardFilenameFull.Append(wxT("/"));
1604 vCardFilenameFull.Append(vCardFilename);
1606 Person.LoadFile(vCardFilenameFull);
1608 if (Person.MeetBaseSpecification()){
1610 vCardDataString = Person.Get(wxT("KIND"));
1612 if (vCardDataString == wxT("group")){
1614 // The vCard kind is a group. Add to the account's group list.
1616 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1617 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1618 AccountGroupList.insert(std::make_pair(intGroupID, i));
1619 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1620 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1630 vCardFilename.Clear();
1631 vCardFilenameFull.Clear();
1632 vCardDataString.Clear();
1633 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1637 // Clearup for next account.
1641 AccDirFullSfx.clear();
1642 AccDirFinal.clear();
1647 // Load the account settings as they are needed for connecting
1650 prefaccounts = preferences.accounts;
1654 void frmMain::ConflictResolution(wxCommandEvent& event){
1656 // Display the conflict resolution window.
1658 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1659 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1660 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1661 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1662 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList, ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1663 frameCR->ShowModal();
1665 int FinalConflictResult = frameCR->GetResult();
1667 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1668 event2.SetClientData(vCardConfObj->QRNotifData);
1669 event2.SetInt(FinalConflictResult);
1674 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1675 wxPostEvent(frameActMgr, event2);
1679 void frmMain::UpdateContactList(wxCommandEvent& event){
1681 // Update the contact list in the main window.
1683 UCNotif *ucd = (UCNotif*)event.GetClientData();
1685 // Check if the active account is being displayed in the
1686 // main window. If not, skip and delete the data.
1688 long longSelected = -1;
1689 int intSelectedData = 0;
1691 if (ActiveAccount == ucd->ContactAccount){
1693 // Look at the list of contacts and if it matches the
1694 // filename then update the name.
1698 longSelected = lstContacts->GetNextItem(longSelected,
1700 wxLIST_STATE_DONTCARE);
1702 if (longSelected == -1){
1708 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1710 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1712 // Work out which sorting mode we are in.
1716 // First Name, Last Name.
1718 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1720 } else if (SortMode == 2){
1722 // Last Name, First Name.
1724 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1726 } else if (SortMode == 3){
1730 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1732 } else if (SortMode == 4){
1736 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1743 // If the filename is the one loaded into the
1744 // browser control, then update this too.
1746 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1748 wxListEvent nullevent;
1749 ShowContactInfo(nullevent);
1757 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1758 WindowIter != WindowListPointers.end(); WindowIter++){
1760 if (WindowListType[WindowIter->first] != 0){
1766 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1768 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1770 vCard UpdatedPerson;
1771 UpdatedPerson.LoadFile(ucd->ContactFilename);
1772 frmContactPtr->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1773 frmContactPtr->SetupContactData(&UpdatedPerson);
1779 // Send message to search window controller subroutine and
1780 // pass that notification onto the search windows.
1782 // Setup the new pointer to use the existing UCNotif without
1785 UCNotif *ucd2 = ucd;
1787 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1788 sup.SetClientData(ucd2);
1789 wxPostEvent(this, sup);
1791 // Clear up the unused pointer.
1797 void frmMain::SetupPointers(void *ActMgrPtrInc){
1799 // Setup the pointers for the main window.
1801 ActMgrPtr = ActMgrPtrInc;
1805 void frmMain::SetupForm(){
1807 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1808 frameActMgr->SetupPointers(&ETagProcTimer, this);
1810 // Setup the contact information icons for later.
1812 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1816 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1817 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1818 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1820 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1821 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1822 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1824 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1825 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1826 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1828 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1829 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1830 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1832 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1833 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1834 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1836 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1837 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1838 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1840 LoadPreferences(false);
1844 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1846 // Update the contact lists in the search windows.
1848 // Go through each of the search windows and
1849 // send the required notification to update the
1850 // contact information.
1852 // Get the event notification data.
1854 UCNotif *ucd = (UCNotif*)event.GetClientData();
1856 // Process each search window giving the new details.
1858 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1859 switer != SearchWindowList.end(); switer++){
1861 // Duplicate the event notification data.
1863 UCNotif *ucd2 = new UCNotif;
1865 ucd2->ContactAccount = ucd->ContactAccount;
1866 ucd2->ContactFilename = ucd->ContactFilename;
1867 ucd2->ContactName = ucd->ContactName;
1868 ucd2->ContactNickname = ucd->ContactNickname;
1869 ucd2->ContactNameArray = ucd->ContactNameArray;
1871 // Pass the data to the search window for processing.
1873 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1874 wxCommandEvent schupdate(SE_UPDATERESULT);
1875 schupdate.SetClientData(ucd2);
1876 wxPostEvent(frameSCH, schupdate);
1878 // Clear up the pointer prior to variable deletion.
1889 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1891 // Open a new search window.
1895 frmSearch *frameSCH = new frmSearch ( this );
1896 frameSCH->SetUID(WindowMenuItemID);
1897 frameSCH->Show(true);
1899 WindowData *WData = new WindowData;
1901 WData->DataType = 2;
1902 WData->WindowPointer = (void*)frameSCH;
1903 WData->WindowID = WindowMenuItemID;
1905 wxCommandEvent addevent(WINDOW_ADD);
1906 addevent.SetClientData(WData);
1907 wxPostEvent(this, addevent);
1909 // Add pointer to the list of open search windows.
1911 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1917 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1919 // Remove the pointer for a contact window from the
1922 void *frameSCH = (void*)event.GetClientData();
1924 SearchWindowList.erase(frameSCH);
1930 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1932 // Remove the pointer for a contact editor window from
1935 void *frameSCH = (void*)event.GetClientData();
1937 SearchWindowList.erase(frameSCH);
1943 void frmMain::RevealContact(wxCommandEvent& event){
1945 // Reveal a contact in the main window.
1947 UCNotif *uc = (UCNotif*)event.GetClientData();
1949 // Switch the account to the one passed.
1951 wxTreeItemIdValue cookie;
1952 wxTreeItemId next = treAccounts->GetRootItem();
1953 wxTreeItemId nextChild;
1955 for (int i = 0; i < prefaccounts.GetCount(); i++){
1958 nextChild = treAccounts->GetFirstChild(next, cookie);
1960 nextChild = treAccounts->GetNextSibling(nextChild);
1963 if (uc->ContactAccount == AccountAccDirList[i]){
1965 treAccounts->SelectItem(nextChild, TRUE);
1966 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1972 // Switch the contact to the one passed.
1974 long longSelected = -1;
1975 int intSelectedData = 0;
1979 longSelected = lstContacts->GetNextItem(longSelected,
1981 wxLIST_STATE_DONTCARE);
1983 if (longSelected == -1){
1989 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1991 // Compare the filename with the one received.
1992 // If they match then select it.
1994 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1998 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1999 lstContacts->EnsureVisible(longSelected);
2003 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
2011 void frmMain::DeleteContact(wxCommandEvent& event){
2013 // Delete a contact from the main window.
2015 // Check if a contact is selected.
2017 long intSelected = -1;
2018 long intContactSeekNum = -1;
2019 wxString wxSContactName;
2021 intSelected = lstContacts->GetNextItem(intSelected,
2023 wxLIST_STATE_SELECTED);
2025 if (intSelected == -1){
2029 // Check if the account type is a valid account type, otherwise
2030 // display an error message.
2032 if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
2033 ActiveAccountType != "Local" && ActiveAccountType != "local"){
2035 wxMessageBox(_("Cannot delete contact as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
2040 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2042 // Get the item data of the contact.
2044 intContactSeekNum = lstContacts->GetItemData(intSelected);
2046 // Get the name of the contact.
2048 wxSContactName = lstContacts->GetItemText(intSelected);
2050 // Display a message confirming if the contact should
2053 int QuestionResponse;
2055 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
2057 if (QuestionResponse == wxNO){
2059 // Exit the subroutine
2065 // Delete the contact.
2067 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
2069 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
2074 // Remove the contact from the list.
2076 lstContacts->DeleteItem(intSelected);
2078 // Update the search windows, removing the deleted
2081 UCNotif *ucd = new UCNotif;
2083 ucd->ContactAccount = ActiveAccount;
2084 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
2086 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
2087 switer != SearchWindowList.end(); switer++){
2089 // Duplicate the event notification data.
2091 UCNotif *ucd2 = new UCNotif;
2093 ucd2->ContactAccount = ucd->ContactAccount;
2094 ucd2->ContactFilename = ucd->ContactFilename;
2096 // Pass the data to the search window for processing.
2098 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
2099 wxCommandEvent schdelete(SE_DELETERESULT);
2100 schdelete.SetClientData(ucd2);
2101 wxPostEvent(frameSCH, schdelete);
2103 // Clear up the pointer prior to variable deletion.
2110 // Clear the wxHTMLWindow.
2112 wxString EmptyPage = wxT("");
2114 htmContactData->SetPage(EmptyPage);
2116 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2118 wxString wxSplitFilename;
2119 wxString wxSDataURL;
2121 while(wSTFilename.HasMoreTokens()){
2123 wxSplitFilename = wSTFilename.GetNextToken();
2127 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2129 // Update the ETagDB and mark it as deleted.
2131 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2133 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2135 // Get the Data URL.
2137 wxTreeItemIdValue cookie;
2138 wxTreeItemId next = treAccounts->GetRootItem();
2140 wxTreeItemId selectedChild = treAccounts->GetSelection();
2141 wxTreeItemId nextChild;
2143 for (int i = 0; i < prefaccounts.GetCount(); i++){
2146 nextChild = treAccounts->GetFirstChild(next, cookie);
2148 nextChild = treAccounts->GetNextSibling(nextChild);
2151 if (nextChild == selectedChild){
2153 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2160 // Add task to the activity monitor to delete the contact.
2162 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2166 // Clear the variable. Don't delete as it will mess things up.
2168 ContactsFileIndex[intContactSeekNum] = wxT("");
2175 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2177 // Display this message when the server information has changed
2180 QRNotif *qrn = (QRNotif *)event.GetClientData();
2182 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);
2184 if (QResponse == wxNO){
2190 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2191 event2.SetInt(*qrn->QResponse);
2192 event2.SetClientData(qrn->PausePtr);
2194 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2196 wxPostEvent(frameActMgr, event2);
2200 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2202 // Remove the contact from the window after syncronising.
2204 // Check which account is currently active in the window.
2205 // If it is different from the one passed to this subroutine then
2206 // exit from the subroutine.
2208 if (Account != ActiveAccount){
2212 long longSelected = -1;
2213 int intSelectedData = 0;
2217 longSelected = lstContacts->GetNextItem(longSelected,
2219 wxLIST_STATE_DONTCARE);
2221 if (longSelected == -1){
2227 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2229 // Compare the filename with the one received.
2230 // If they match then select it.
2232 if (ContactsFileIndex[intSelectedData] == Filename){
2234 // Remove the contact from the window.
2236 lstContacts->DeleteItem(intSelectedData);
2238 // Check if contact is the selected contact in the HTML window and
2239 // if it is then clear the window.
2241 if (ActiveFilename == Filename){
2243 wxString EmptyPage = wxT("");
2244 htmContactData->SetPage(EmptyPage);
2258 void frmMain::SortFNLN( wxCommandEvent& event ) {
2260 // Sort first name then last name.
2262 wxTreeEvent NullEvent;
2264 LoadContactList(NullEvent);
2268 void frmMain::SortLNFN( wxCommandEvent& event ) {
2270 // Sort last name then first name.
2272 wxTreeEvent NullEvent;
2274 LoadContactList(NullEvent);
2278 void frmMain::SortNickname( wxCommandEvent& event ) {
2280 // Sort by nickname.
2282 wxTreeEvent NullEvent;
2284 LoadContactList(NullEvent);
2288 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2290 // Sort by Display As name.
2292 wxTreeEvent NullEvent;
2294 LoadContactList(NullEvent);
2298 void frmMain::SortAscending( wxCommandEvent& event ) {
2302 wxTreeEvent NullEvent;
2303 AscendingMode = TRUE;
2304 LoadContactList(NullEvent);
2308 void frmMain::SortDescending( wxCommandEvent& event ) {
2312 wxTreeEvent NullEvent;
2313 AscendingMode = FALSE;
2314 LoadContactList(NullEvent);
2318 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2320 // Toggle the appearance of the status bar.
2322 if (stbBottom->IsShown() == TRUE){
2336 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2338 // Display the activity icon.
2340 imgActivityStatus->SetBitmap(*imgActIcon1);
2341 ActivityIconStatus = 0;
2345 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2347 // Shuffle through the activity icons.
2349 switch (ActivityIconStatus){
2352 imgActivityStatus->SetBitmap(*imgActIcon1);
2353 ActivityIconStatus = 1;
2356 imgActivityStatus->SetBitmap(*imgActIcon2);
2357 ActivityIconStatus = 2;
2360 imgActivityStatus->SetBitmap(*imgActIcon3);
2361 ActivityIconStatus = 3;
2364 imgActivityStatus->SetBitmap(*imgActIcon4);
2365 ActivityIconStatus = 0;
2368 ActivityIconStatus = 0;
2374 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2376 // Display the sleep icon.
2378 imgActivityStatus->SetBitmap(*imgActIconSleep);
2382 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2384 // Set the placement of the status bar icons.
2386 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2394 wxRect rectActivity;
2395 stbBottom->GetFieldRect(1, rectOnline);
2396 stbBottom->GetFieldRect(2, rectSSL);
2397 stbBottom->GetFieldRect(3, rectActivity);
2399 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2400 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2401 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2405 XABViewMode frmMain::GetViewMode(){
2407 // Set the view mode of the contact list.
2411 xvm.SortMode = SortMode;
2412 xvm.AscendingMode = AscendingMode;
2418 void frmMain::WindowAdd( wxCommandEvent &event ){
2420 // Add a window to the window list.
2422 WindowData *WData = (WindowData*)event.GetClientData();
2426 if (WData->DataType == 0){
2430 int intID = mnuContactWindows->GetId();
2432 mnuWindow->FindChildItem(intID, &pos);
2433 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2434 mnuNewItem->SetId(WData->WindowID);
2435 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2436 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2437 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2438 mnuWindow->Insert((pos + 1), mnuNewItem);
2439 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2441 } else if (WData->DataType == 1){
2443 // Contact Editor Window
2445 int intID = mnuContactEditorWindows->GetId();
2447 mnuWindow->FindChildItem(intID, &pos);
2448 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2449 mnuNewItem->SetId(WData->WindowID);
2450 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2451 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2452 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2453 mnuWindow->Insert((pos + 1), mnuNewItem);
2454 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2456 } else if (WData->DataType == 2){
2460 int intID = mnuSearchWindows->GetId();
2462 mnuWindow->FindChildItem(intID, &pos);
2463 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2464 mnuNewItem->SetId(WData->WindowID);
2465 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2466 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2467 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2468 mnuWindow->Insert((pos + 1), mnuNewItem);
2469 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2478 void frmMain::WindowEdit( wxCommandEvent &event ){
2480 // Edit a window in the window list.
2482 WindowData *WData = (WindowData*)event.GetClientData();
2484 if (WData->DataType == 0){
2486 // Get the window title and use that.
2488 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2490 wxString WindowTitle = frmContactPtr->GetTitle();
2492 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2494 MenuIter->second->SetItemLabel(WindowTitle);
2496 } else if (WData->DataType == 1){
2498 // Get the window title and use that.
2500 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2502 wxString WindowTitle = frmCEPtr->GetTitle();
2504 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2506 if (WindowTitle.IsEmpty()){
2508 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2512 MenuIter->second->SetItemLabel(WindowTitle);
2523 void frmMain::WindowDelete( wxCommandEvent &event ){
2525 // Delete a window from the window list.
2527 WindowData *WData = (WindowData*)event.GetClientData();
2529 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2531 mnuWindow->Remove(MenuIter->second);
2533 delete MenuIter->second;
2534 MenuIter->second = NULL;
2536 WindowListPointersMenu.erase(WData->WindowID);
2537 WindowListPointers.erase(WData->WindowID);
2538 WindowListType.erase(WData->WindowID);
2545 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2547 // Show a contact window from the window list.
2549 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2551 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2553 frmContactPtr->Show();
2554 frmContactPtr->Raise();
2558 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2560 // Show a contact editor window from the window list.
2562 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2564 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2571 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2573 // Show a search window from the window list.
2575 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2577 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2579 frmSearchPtr->Show();
2580 frmSearchPtr->Raise();
2584 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2586 // Toggle the online/offline connection status.
2588 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2589 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2590 wxPostEvent(frameActMgr, toggconn);
2594 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2596 // Check the account type before continuing.
2598 wxString SeekAccount;
2599 wxString AccTypeLower;
2603 #if defined(__APPLE__)
2605 std::map<int, SecTrustRef>::iterator SSLTrustIter;
2607 for (int i = 0; i < prefaccounts.GetCount(); i++){
2609 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2610 AccType.Append(prefaccounts.GetAccountType(i));
2611 AccountSSL = prefaccounts.GetAccountSSL(i);
2612 AccTypeLower = AccType.MakeLower();
2613 SeekAccount.Append(wxT("."));
2614 SeekAccount.Append(AccTypeLower);
2616 if (SeekAccount == ActiveAccount){
2618 if (AccTypeLower == wxT("local")){
2624 if (AccountSSL == false){
2630 SSLTrustIter = AccountTrustData.find(i);
2632 // Setup and display the form.
2634 DisplayCertificate(SSLTrustIter->second);
2638 SeekAccount.Clear();
2639 AccTypeLower.Clear();
2644 #elif defined(__WIN32__)
2646 std::map<int, PCCERT_CONTEXT>::iterator SSLCertificateIter;
2648 for (int i = 0; i < prefaccounts.GetCount(); i++){
2650 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2651 AccType.Append(prefaccounts.GetAccountType(i));
2652 AccountSSL = prefaccounts.GetAccountSSL(i);
2653 AccTypeLower = AccType.MakeLower();
2654 SeekAccount.Append(wxT("."));
2655 SeekAccount.Append(AccTypeLower);
2657 if (SeekAccount == ActiveAccount){
2659 if (AccTypeLower == wxT("local")){
2665 if (AccountSSL == false){
2671 SSLCertificateIter = AccountCertificateData.find(i);
2673 // Setup and display the form.
2675 if (SSLCertificateIter->second->pCertInfo == NULL){
2677 wxMessageBox("No certificate information is available due to invalid connection details, connection being in progress or invalid certificate data received.");
2681 BOOL ModifiedCertificateData;
2682 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(SSLCertificateIter->second, (HWND)this->GetHandle());
2684 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
2685 wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
2690 //DisplayCertificate(SSLTrustIter->second);
2694 SeekAccount.Clear();
2695 AccTypeLower.Clear();
2702 std::map<int, SSLCertCollectionString>::iterator SSLColIter;
2704 for (int i = 0; i < prefaccounts.GetCount(); i++){
2706 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2707 AccType.Append(prefaccounts.GetAccountType(i));
2708 AccountSSL = prefaccounts.GetAccountSSL(i);
2709 AccTypeLower = AccType.MakeLower();
2710 SeekAccount.Append(wxT("."));
2711 SeekAccount.Append(AccTypeLower);
2713 if (SeekAccount == ActiveAccount){
2715 if (AccTypeLower == wxT("local")){
2721 if (AccountSSL == false){
2727 SSLColIter = AccountSSLData.find(i);
2729 SSLCertCollectionString SSLCertInfo = SSLColIter->second;
2731 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2732 frameSSLCert->StartCertFrom(0);
2733 frameSSLCert->SetupCertsString(SSLCertInfo);
2734 frameSSLCert->ShowModal();
2736 delete frameSSLCert;
2737 frameSSLCert = NULL;
2741 SeekAccount.Clear();
2742 AccTypeLower.Clear();
2751 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2753 // Check the account type before continuing.
2757 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2759 // Check the account type before continuing.
2763 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2765 if (event.GetInt() == 0){
2767 imgConnStatus->SetBitmap(*imgOnline);
2771 imgConnStatus->SetBitmap(*imgOffline);
2777 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2779 // Display the form for showing an invalid SSL certificate.
2781 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2782 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2783 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2784 wxString AccountName = SSLICNObj->AccountName;
2785 frameISC->LoadData(SSLCCData, AccountName);
2786 frameISC->ShowModal();
2788 int FinalConflictResult = frameISC->GetResult();
2790 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2791 event2.SetClientData(SSLICNObj->QRNotifData);
2792 event2.SetInt(FinalConflictResult);
2797 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2798 wxPostEvent(frameActMgr, event2);
2802 void frmMain::InvalidSSLCertificateString( wxCommandEvent &event ){
2804 // Display the form for showing an invalid SSL certificate.
2806 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2807 SSLInvalidCertNotifObjString *SSLICNObj = (SSLInvalidCertNotifObjString*)event.GetClientData();
2808 SSLCertCollectionString SSLCCData = SSLICNObj->CertCollection;
2809 wxString AccountName = SSLICNObj->AccountName;
2810 frameISC->LoadData(SSLCCData, AccountName);
2811 frameISC->ShowModal();
2813 int FinalConflictResult = frameISC->GetResult();
2815 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2816 event2.SetClientData(SSLICNObj->QRNotifData);
2817 event2.SetInt(FinalConflictResult);
2822 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2823 wxPostEvent(frameActMgr, event2);
2827 void frmMain::PauseAllTimers(){
2829 // Pause all the account timers.
2831 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2832 ASTiter != AccountSyncTimers.end(); ASTiter++){
2834 ASTiter->second->Stop();
2840 void frmMain::ResumeAllTimers(){
2842 // Resume all the account timers.
2844 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2845 ASTiter != AccountSyncTimers.end(); ASTiter++){
2847 ASTiter->second->Start();
2853 #if defined(__APPLE__)
2855 #elif defined(__WIN32__)
2857 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEXT CertificateContext){
2859 // Delete existing data.
2861 std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.find(AccountID);
2863 if (CertificateIter != AccountCertificateData.end()){
2864 CertFreeCertificateContext(CertificateIter->second);
2867 AccountCertificateData.erase(AccountID);
2868 AccountSSLResult.erase(AccountID);
2872 AccountCertificateData.insert(std::make_pair(AccountID, CertificateContext));
2873 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2879 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollectionString SSLCertInc){
2881 // Delete existing data.
2883 AccountSSLData.erase(AccountID);
2884 AccountSSLResult.erase(AccountID);
2888 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2889 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2895 void frmMain::SetupSSLStatus( int AccountID ){
2897 // Check if account ID given is
2898 // the active account and if not, do nothing.
2901 wxString AccTypeLower;
2903 AccType = prefaccounts.GetAccountType(AccountID);
2904 AccTypeLower = AccType.MakeLower();
2906 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2909 if (AccountIDName != ActiveAccount){
2915 // Check the account type is a supported account type.
2917 if (AccType != "CardDAV" && AccType != "carddav" &&
2918 AccType != "Local" && AccType != "local"){
2920 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2921 imgSSLStatus->SetBitmap(*imgNoSSL);
2926 // Check if the account has SSL enabled.
2928 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2930 if (SSLInUse == FALSE){
2932 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2933 imgSSLStatus->SetBitmap(*imgNoSSL);
2937 // Get the SSL Collection Data.
2939 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2941 // Check if a result value has been set.
2943 if (SSLResultIter == AccountSSLResult.end()){
2945 imgSSLStatus->SetBitmap(*imgSSLWarning);
2946 SSLToolTip->SetTip(wxT("Unable to determine SSL information for the '") + prefaccounts.GetAccountName(AccountID) + wxT("' account."));
2951 if (SSLResultIter->second == 1){
2953 imgSSLStatus->SetBitmap(*imgSSLWarning);
2954 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2955 prefaccounts.GetAccountName(AccountID) +
2956 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2958 } else if (SSLResultIter->second == 0){
2960 imgSSLStatus->SetBitmap(*imgSSL);
2961 SSLToolTip->SetTip(wxT("Account '") +
2962 prefaccounts.GetAccountName(AccountID) +
2963 wxT("' secured using SSL\n\nDouble click for more information."));
2971 void frmMain::CheckUpdates( wxCommandEvent& event ){
2973 // Check for updates to Xestia Address Book.
2975 frmUpdate *frameUpdate = new frmUpdate ( this );
2976 frameUpdate->FetchData();
2977 frameUpdate->ShowModal();
2981 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2983 // Run the import contacts function.
2989 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2991 // Check if an account and at least one contact is selected
2992 // before continuing.
2994 wxArrayString ArrData;
2996 if (ActiveAccount.IsEmpty()){
3002 int ContactSelected = 0;
3003 int ContactsCollected = 0;
3004 long longSelected = -1;
3008 longSelected = lstContacts->GetNextItem(longSelected,
3010 wxLIST_STATE_SELECTED);
3012 if (longSelected == -1){
3018 int FileID = (int)lstContacts->GetItemData(longSelected);
3020 ArrData.Insert(ContactsFileIndex[FileID],
3021 ContactsCollected, 1);
3027 if (ContactSelected == 0){
3033 // Run the export contacts system.
3035 ExportRun(this, &ArrData);
3039 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
3040 wxArrayString *ContactsFileIndexPtr){
3042 // Set the list control pointers.
3044 lstContactsPtr = lstContacts;
3045 ContactsFileIndexPtr = &ContactsFileIndex;
3049 void frmMain::GetSelectedList( wxCommandEvent& event ){
3051 // Get the array of contact filenames.
3053 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
3055 // Process them into an array of files.
3057 long longSelected = -1;
3058 int ContactsCollected = 0;
3059 wxString ContactFilename;
3063 longSelected = lstContacts->GetNextItem(longSelected,
3065 wxLIST_STATE_SELECTED);
3067 if (longSelected == -1){
3073 // Get the file information and add to the list.
3075 int FileID = (int)lstContacts->GetItemData(longSelected);
3077 ArrData->Insert(ContactsFileIndex[FileID],
3078 ContactsCollected, 1);
3080 ContactsCollected++;
3081 ContactFilename.Clear();
3089 void frmMain::SyncAccount( wxCommandEvent& event ){
3091 // Syncronise the selected account.
3093 wxString AccNameInc = event.GetString();
3095 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
3096 frameActMgr->AddTask(3, wxT(""), AccNameInc,
3097 wxT(""), wxT(""), wxT(""), wxT(""));
3101 void frmMain::ShowHelp( wxCommandEvent& event ){
3103 // Based on the operating system, work out where
3104 // the documentation should be.
3108 #if defined(__HAIKU__)
3110 #elif defined(__WIN32__)
3116 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
3118 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
3121 #if XSDAB_RELEASE == 0
3123 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
3125 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
3134 #if XSDAB_RELEASE == 0
3136 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
3140 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!"));
3146 void frmMain::ShowImportResults( wxCommandEvent &event ){
3148 // Show the results of importing contacts.
3150 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
3152 frmImportResults *frmIR = new frmImportResults(this);
3153 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
3164 void frmMain::ReloadContactList( wxCommandEvent &event ){
3166 // Check if the account name given is the current
3167 // account selected.
3169 if (ActiveAccount == event.GetString()){
3171 wxTreeEvent NullEvent;
3172 LoadContactList(NullEvent);
3178 void frmMain::ShowContactMenu( wxMouseEvent& event ){
3180 // Show the contact menu when a right click occurs
3181 // in the contacts list.
3183 bool EnableRefresh = FALSE;
3185 if (!ActiveAccount.IsEmpty() && (ActiveAccountType == "CardDAV" ||
3186 ActiveAccountType == "carddav" ||
3187 ActiveAccountType == "Local" ||
3188 ActiveAccountType == "local")){
3190 EnableRefresh = TRUE;
3194 ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
3196 this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
3200 void frmMain::ResetContactInfo(){
3202 // Reset the contact information to an empty page.
3204 wxString EmptyPage = wxT("");
3205 htmContactData->SetPage(EmptyPage);
3206 AccCtrl->SetValue("");
3210 bool frmMain::CloseAllWindows()
3212 // Attempt to close all windows.
3214 if (WindowListPointersMenu.size() == 0)
3219 if (wxMessageBox(_("Before preforming the action, all windows that are open will need to close. Do you wish to continue?"), _("Close All Windowss"), wxYES_NO) == wxYES)
3221 for(std::map<int, void*>::iterator windowIter = WindowListPointers.begin();
3222 windowIter != WindowListPointers.end(); windowIter++)
3224 wxWindow *windowPointer = static_cast<wxWindow*>(windowIter->second);
3225 windowPointer->Close();