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 // Setup the main window position (if needed).
1443 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1444 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1445 bool UseBackgroundContactColour = preferences.GetBoolData(wxT("UseBackgroundContactColour"));
1447 if (SaveWindowPos == true && skipWindowSizeReload == false){
1449 this->SetSize(preferences.GetMainWindowData());
1453 if (UseBackgroundContactColour == true){
1455 ContactBackgroundColour = preferences.GetBackgroundContactColourData();
1459 ContactBackgroundColour = wxTransparentColour;
1463 treAccounts->DeleteAllItems();
1465 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1467 // Stop all account timers and remove the accounts.
1469 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1470 iter != AccountSyncTimers.end(); iter++){
1472 wxAccountSyncTimer *AccTmrPtr = iter->second;
1480 #if defined(__WIN32__)
1482 for (std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.begin();
1483 CertificateIter != AccountCertificateData.end(); CertificateIter++){
1485 CertFreeCertificateContext(CertificateIter->second);
1489 AccountCertificateData.clear();
1493 AccountSyncTimers.clear();
1496 wxString AccDirFull;
1497 wxString AccDirFullSfx;
1499 wxString AccDirFinal;
1500 AccountAccDirList.clear();
1501 AccountGroupList.clear();
1502 AccountGroupFilename.clear();
1503 AccountGroupTreeId.clear();
1504 wxTreeItemId AccountTreeId;
1505 wxTreeItemId GroupTreeId;
1508 // Relaod the accounts for the ETagProcTimer.
1510 ETagProcTimer.ReloadAccounts();
1512 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1514 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1515 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == true){
1521 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1527 AccDir = preferences.accounts.GetAccountDirectory(i);
1528 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1530 AccDirFull.Append(wxT("."));
1531 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1532 AccDirFullSfx.LowerCase();
1533 AccDirFullSfx.Trim();
1534 AccDirFull.Append(AccDirFullSfx);
1535 AccName = preferences.accounts.GetAccountName(i);
1537 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1539 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1540 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1542 // TODO: Check if the directory exists before doing anything.
1546 // Add a new timer using the existing account details.
1548 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1550 ActTmrPtr->SetupData(AccDirFull, AccName);
1551 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1552 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1553 ActTmrPtr->SetOwner(this);
1554 ActTmrPtr->Notify();
1556 // Add the timer to the list of timers.
1558 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1560 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1562 } else if (preferences.accounts.GetAccountType(i) == wxT("Local") ||
1563 preferences.accounts.GetAccountType(i) == wxT("local")) {
1565 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1569 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountUnsupportedID, -1);
1573 // Go through the account directory and find contact files with
1574 // 'KIND:group' set and add them to the list of groups for the account.
1576 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1578 wxDir vcardaccdir(AccDirFinal);
1580 wxString vCardFilename;
1581 wxString vCardDataString;
1582 wxString vCardFilenameFull;
1584 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1588 if (vCardFilename.Right(4) == wxT(".vcf") ||
1589 vCardFilename.Right(4) == wxT(".VCF") ||
1590 vCardFilename.Right(5) == wxT(".vcard") ||
1591 vCardFilename.Right(5) == wxT(".VCARD")){
1595 vCardFilenameFull.Append(AccDirFinal);
1596 vCardFilenameFull.Append(wxT("/"));
1597 vCardFilenameFull.Append(vCardFilename);
1599 Person.LoadFile(vCardFilenameFull);
1601 if (Person.MeetBaseSpecification()){
1603 vCardDataString = Person.Get(wxT("KIND"));
1605 if (vCardDataString == wxT("group")){
1607 // The vCard kind is a group. Add to the account's group list.
1609 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1610 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1611 AccountGroupList.insert(std::make_pair(intGroupID, i));
1612 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1613 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1623 vCardFilename.Clear();
1624 vCardFilenameFull.Clear();
1625 vCardDataString.Clear();
1626 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1630 // Clearup for next account.
1634 AccDirFullSfx.clear();
1635 AccDirFinal.clear();
1640 // Load the account settings as they are needed for connecting
1643 prefaccounts = preferences.accounts;
1647 void frmMain::ConflictResolution(wxCommandEvent& event){
1649 // Display the conflict resolution window.
1651 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1652 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1653 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1654 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1655 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList, ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1656 frameCR->ShowModal();
1658 int FinalConflictResult = frameCR->GetResult();
1660 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1661 event2.SetClientData(vCardConfObj->QRNotifData);
1662 event2.SetInt(FinalConflictResult);
1667 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1668 wxPostEvent(frameActMgr, event2);
1672 void frmMain::UpdateContactList(wxCommandEvent& event){
1674 // Update the contact list in the main window.
1676 UCNotif *ucd = (UCNotif*)event.GetClientData();
1678 // Check if the active account is being displayed in the
1679 // main window. If not, skip and delete the data.
1681 long longSelected = -1;
1682 int intSelectedData = 0;
1684 if (ActiveAccount == ucd->ContactAccount){
1686 // Look at the list of contacts and if it matches the
1687 // filename then update the name.
1691 longSelected = lstContacts->GetNextItem(longSelected,
1693 wxLIST_STATE_DONTCARE);
1695 if (longSelected == -1){
1701 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1703 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1705 // Work out which sorting mode we are in.
1709 // First Name, Last Name.
1711 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1713 } else if (SortMode == 2){
1715 // Last Name, First Name.
1717 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1719 } else if (SortMode == 3){
1723 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1725 } else if (SortMode == 4){
1729 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1736 // If the filename is the one loaded into the
1737 // browser control, then update this too.
1739 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1741 wxListEvent nullevent;
1742 ShowContactInfo(nullevent);
1750 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1751 WindowIter != WindowListPointers.end(); WindowIter++){
1753 if (WindowListType[WindowIter->first] != 0){
1759 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1761 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1763 vCard UpdatedPerson;
1764 UpdatedPerson.LoadFile(ucd->ContactFilename);
1765 frmContactPtr->SetBackgroundColour(ContactBackgroundColour.GetAsString(wxC2S_CSS_SYNTAX));
1766 frmContactPtr->SetupContactData(&UpdatedPerson);
1772 // Send message to search window controller subroutine and
1773 // pass that notification onto the search windows.
1775 // Setup the new pointer to use the existing UCNotif without
1778 UCNotif *ucd2 = ucd;
1780 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1781 sup.SetClientData(ucd2);
1782 wxPostEvent(this, sup);
1784 // Clear up the unused pointer.
1790 void frmMain::SetupPointers(void *ActMgrPtrInc){
1792 // Setup the pointers for the main window.
1794 ActMgrPtr = ActMgrPtrInc;
1798 void frmMain::SetupForm(){
1800 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1801 frameActMgr->SetupPointers(&ETagProcTimer, this);
1803 // Setup the contact information icons for later.
1805 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1809 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1810 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1811 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1813 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1814 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1815 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1817 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1818 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1819 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1821 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1822 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1823 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1825 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1826 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1827 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1829 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1830 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1831 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1833 LoadPreferences(false);
1837 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1839 // Update the contact lists in the search windows.
1841 // Go through each of the search windows and
1842 // send the required notification to update the
1843 // contact information.
1845 // Get the event notification data.
1847 UCNotif *ucd = (UCNotif*)event.GetClientData();
1849 // Process each search window giving the new details.
1851 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1852 switer != SearchWindowList.end(); switer++){
1854 // Duplicate the event notification data.
1856 UCNotif *ucd2 = new UCNotif;
1858 ucd2->ContactAccount = ucd->ContactAccount;
1859 ucd2->ContactFilename = ucd->ContactFilename;
1860 ucd2->ContactName = ucd->ContactName;
1861 ucd2->ContactNickname = ucd->ContactNickname;
1862 ucd2->ContactNameArray = ucd->ContactNameArray;
1864 // Pass the data to the search window for processing.
1866 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1867 wxCommandEvent schupdate(SE_UPDATERESULT);
1868 schupdate.SetClientData(ucd2);
1869 wxPostEvent(frameSCH, schupdate);
1871 // Clear up the pointer prior to variable deletion.
1882 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1884 // Open a new search window.
1888 frmSearch *frameSCH = new frmSearch ( this );
1889 frameSCH->SetUID(WindowMenuItemID);
1890 frameSCH->Show(true);
1892 WindowData *WData = new WindowData;
1894 WData->DataType = 2;
1895 WData->WindowPointer = (void*)frameSCH;
1896 WData->WindowID = WindowMenuItemID;
1898 wxCommandEvent addevent(WINDOW_ADD);
1899 addevent.SetClientData(WData);
1900 wxPostEvent(this, addevent);
1902 // Add pointer to the list of open search windows.
1904 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1910 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1912 // Remove the pointer for a contact window from the
1915 void *frameSCH = (void*)event.GetClientData();
1917 SearchWindowList.erase(frameSCH);
1923 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1925 // Remove the pointer for a contact editor window from
1928 void *frameSCH = (void*)event.GetClientData();
1930 SearchWindowList.erase(frameSCH);
1936 void frmMain::RevealContact(wxCommandEvent& event){
1938 // Reveal a contact in the main window.
1940 UCNotif *uc = (UCNotif*)event.GetClientData();
1942 // Switch the account to the one passed.
1944 wxTreeItemIdValue cookie;
1945 wxTreeItemId next = treAccounts->GetRootItem();
1946 wxTreeItemId nextChild;
1948 for (int i = 0; i < prefaccounts.GetCount(); i++){
1951 nextChild = treAccounts->GetFirstChild(next, cookie);
1953 nextChild = treAccounts->GetNextSibling(nextChild);
1956 if (uc->ContactAccount == AccountAccDirList[i]){
1958 treAccounts->SelectItem(nextChild, TRUE);
1959 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1965 // Switch the contact to the one passed.
1967 long longSelected = -1;
1968 int intSelectedData = 0;
1972 longSelected = lstContacts->GetNextItem(longSelected,
1974 wxLIST_STATE_DONTCARE);
1976 if (longSelected == -1){
1982 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1984 // Compare the filename with the one received.
1985 // If they match then select it.
1987 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1991 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1992 lstContacts->EnsureVisible(longSelected);
1996 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
2004 void frmMain::DeleteContact(wxCommandEvent& event){
2006 // Delete a contact from the main window.
2008 // Check if a contact is selected.
2010 long intSelected = -1;
2011 long intContactSeekNum = -1;
2012 wxString wxSContactName;
2014 intSelected = lstContacts->GetNextItem(intSelected,
2016 wxLIST_STATE_SELECTED);
2018 if (intSelected == -1){
2022 // Check if the account type is a valid account type, otherwise
2023 // display an error message.
2025 if (ActiveAccountType != "CardDAV" && ActiveAccountType != "carddav" &&
2026 ActiveAccountType != "Local" && ActiveAccountType != "local"){
2028 wxMessageBox(_("Cannot delete contact as the account type is unsupported."), _("Unsupported account type"), wxICON_ERROR);
2033 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2035 // Get the item data of the contact.
2037 intContactSeekNum = lstContacts->GetItemData(intSelected);
2039 // Get the name of the contact.
2041 wxSContactName = lstContacts->GetItemText(intSelected);
2043 // Display a message confirming if the contact should
2046 int QuestionResponse;
2048 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
2050 if (QuestionResponse == wxNO){
2052 // Exit the subroutine
2058 // Delete the contact.
2060 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
2062 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
2067 // Remove the contact from the list.
2069 lstContacts->DeleteItem(intSelected);
2071 // Update the search windows, removing the deleted
2074 UCNotif *ucd = new UCNotif;
2076 ucd->ContactAccount = ActiveAccount;
2077 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
2079 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
2080 switer != SearchWindowList.end(); switer++){
2082 // Duplicate the event notification data.
2084 UCNotif *ucd2 = new UCNotif;
2086 ucd2->ContactAccount = ucd->ContactAccount;
2087 ucd2->ContactFilename = ucd->ContactFilename;
2089 // Pass the data to the search window for processing.
2091 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
2092 wxCommandEvent schdelete(SE_DELETERESULT);
2093 schdelete.SetClientData(ucd2);
2094 wxPostEvent(frameSCH, schdelete);
2096 // Clear up the pointer prior to variable deletion.
2103 // Clear the wxHTMLWindow.
2105 wxString EmptyPage = wxT("");
2107 htmContactData->SetPage(EmptyPage);
2109 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2111 wxString wxSplitFilename;
2112 wxString wxSDataURL;
2114 while(wSTFilename.HasMoreTokens()){
2116 wxSplitFilename = wSTFilename.GetNextToken();
2120 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2122 // Update the ETagDB and mark it as deleted.
2124 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2126 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2128 // Get the Data URL.
2130 wxTreeItemIdValue cookie;
2131 wxTreeItemId next = treAccounts->GetRootItem();
2133 wxTreeItemId selectedChild = treAccounts->GetSelection();
2134 wxTreeItemId nextChild;
2136 for (int i = 0; i < prefaccounts.GetCount(); i++){
2139 nextChild = treAccounts->GetFirstChild(next, cookie);
2141 nextChild = treAccounts->GetNextSibling(nextChild);
2144 if (nextChild == selectedChild){
2146 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2153 // Add task to the activity monitor to delete the contact.
2155 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2159 // Clear the variable. Don't delete as it will mess things up.
2161 ContactsFileIndex[intContactSeekNum] = wxT("");
2168 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2170 // Display this message when the server information has changed
2173 QRNotif *qrn = (QRNotif *)event.GetClientData();
2175 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);
2177 if (QResponse == wxNO){
2183 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2184 event2.SetInt(*qrn->QResponse);
2185 event2.SetClientData(qrn->PausePtr);
2187 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2189 wxPostEvent(frameActMgr, event2);
2193 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2195 // Remove the contact from the window after syncronising.
2197 // Check which account is currently active in the window.
2198 // If it is different from the one passed to this subroutine then
2199 // exit from the subroutine.
2201 if (Account != ActiveAccount){
2205 long longSelected = -1;
2206 int intSelectedData = 0;
2210 longSelected = lstContacts->GetNextItem(longSelected,
2212 wxLIST_STATE_DONTCARE);
2214 if (longSelected == -1){
2220 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2222 // Compare the filename with the one received.
2223 // If they match then select it.
2225 if (ContactsFileIndex[intSelectedData] == Filename){
2227 // Remove the contact from the window.
2229 lstContacts->DeleteItem(intSelectedData);
2231 // Check if contact is the selected contact in the HTML window and
2232 // if it is then clear the window.
2234 if (ActiveFilename == Filename){
2236 wxString EmptyPage = wxT("");
2237 htmContactData->SetPage(EmptyPage);
2251 void frmMain::SortFNLN( wxCommandEvent& event ) {
2253 // Sort first name then last name.
2255 wxTreeEvent NullEvent;
2257 LoadContactList(NullEvent);
2261 void frmMain::SortLNFN( wxCommandEvent& event ) {
2263 // Sort last name then first name.
2265 wxTreeEvent NullEvent;
2267 LoadContactList(NullEvent);
2271 void frmMain::SortNickname( wxCommandEvent& event ) {
2273 // Sort by nickname.
2275 wxTreeEvent NullEvent;
2277 LoadContactList(NullEvent);
2281 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2283 // Sort by Display As name.
2285 wxTreeEvent NullEvent;
2287 LoadContactList(NullEvent);
2291 void frmMain::SortAscending( wxCommandEvent& event ) {
2295 wxTreeEvent NullEvent;
2296 AscendingMode = TRUE;
2297 LoadContactList(NullEvent);
2301 void frmMain::SortDescending( wxCommandEvent& event ) {
2305 wxTreeEvent NullEvent;
2306 AscendingMode = FALSE;
2307 LoadContactList(NullEvent);
2311 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2313 // Toggle the appearance of the status bar.
2315 if (stbBottom->IsShown() == TRUE){
2329 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2331 // Display the activity icon.
2333 imgActivityStatus->SetBitmap(*imgActIcon1);
2334 ActivityIconStatus = 0;
2338 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2340 // Shuffle through the activity icons.
2342 switch (ActivityIconStatus){
2345 imgActivityStatus->SetBitmap(*imgActIcon1);
2346 ActivityIconStatus = 1;
2349 imgActivityStatus->SetBitmap(*imgActIcon2);
2350 ActivityIconStatus = 2;
2353 imgActivityStatus->SetBitmap(*imgActIcon3);
2354 ActivityIconStatus = 3;
2357 imgActivityStatus->SetBitmap(*imgActIcon4);
2358 ActivityIconStatus = 0;
2361 ActivityIconStatus = 0;
2367 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2369 // Display the sleep icon.
2371 imgActivityStatus->SetBitmap(*imgActIconSleep);
2375 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2377 // Set the placement of the status bar icons.
2379 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2387 wxRect rectActivity;
2388 stbBottom->GetFieldRect(1, rectOnline);
2389 stbBottom->GetFieldRect(2, rectSSL);
2390 stbBottom->GetFieldRect(3, rectActivity);
2392 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2393 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2394 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2398 XABViewMode frmMain::GetViewMode(){
2400 // Set the view mode of the contact list.
2404 xvm.SortMode = SortMode;
2405 xvm.AscendingMode = AscendingMode;
2411 void frmMain::WindowAdd( wxCommandEvent &event ){
2413 // Add a window to the window list.
2415 WindowData *WData = (WindowData*)event.GetClientData();
2419 if (WData->DataType == 0){
2423 int intID = mnuContactWindows->GetId();
2425 mnuWindow->FindChildItem(intID, &pos);
2426 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2427 mnuNewItem->SetId(WData->WindowID);
2428 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2429 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2430 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2431 mnuWindow->Insert((pos + 1), mnuNewItem);
2432 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2434 } else if (WData->DataType == 1){
2436 // Contact Editor Window
2438 int intID = mnuContactEditorWindows->GetId();
2440 mnuWindow->FindChildItem(intID, &pos);
2441 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2442 mnuNewItem->SetId(WData->WindowID);
2443 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2444 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2445 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2446 mnuWindow->Insert((pos + 1), mnuNewItem);
2447 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2449 } else if (WData->DataType == 2){
2453 int intID = mnuSearchWindows->GetId();
2455 mnuWindow->FindChildItem(intID, &pos);
2456 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2457 mnuNewItem->SetId(WData->WindowID);
2458 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2459 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2460 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2461 mnuWindow->Insert((pos + 1), mnuNewItem);
2462 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2471 void frmMain::WindowEdit( wxCommandEvent &event ){
2473 // Edit a window in the window list.
2475 WindowData *WData = (WindowData*)event.GetClientData();
2477 if (WData->DataType == 0){
2479 // Get the window title and use that.
2481 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2483 wxString WindowTitle = frmContactPtr->GetTitle();
2485 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2487 MenuIter->second->SetItemLabel(WindowTitle);
2489 } else if (WData->DataType == 1){
2491 // Get the window title and use that.
2493 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2495 wxString WindowTitle = frmCEPtr->GetTitle();
2497 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2499 if (WindowTitle.IsEmpty()){
2501 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2505 MenuIter->second->SetItemLabel(WindowTitle);
2516 void frmMain::WindowDelete( wxCommandEvent &event ){
2518 // Delete a window from the window list.
2520 WindowData *WData = (WindowData*)event.GetClientData();
2522 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2524 mnuWindow->Remove(MenuIter->second);
2526 delete MenuIter->second;
2527 MenuIter->second = NULL;
2529 WindowListPointersMenu.erase(WData->WindowID);
2530 WindowListPointers.erase(WData->WindowID);
2531 WindowListType.erase(WData->WindowID);
2538 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2540 // Show a contact window from the window list.
2542 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2544 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2546 frmContactPtr->Show();
2547 frmContactPtr->Raise();
2551 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2553 // Show a contact editor window from the window list.
2555 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2557 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2564 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2566 // Show a search window from the window list.
2568 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2570 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2572 frmSearchPtr->Show();
2573 frmSearchPtr->Raise();
2577 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2579 // Toggle the online/offline connection status.
2581 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2582 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2583 wxPostEvent(frameActMgr, toggconn);
2587 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2589 // Check the account type before continuing.
2591 wxString SeekAccount;
2592 wxString AccTypeLower;
2596 #if defined(__APPLE__)
2598 std::map<int, SecTrustRef>::iterator SSLTrustIter;
2600 for (int i = 0; i < prefaccounts.GetCount(); i++){
2602 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2603 AccType.Append(prefaccounts.GetAccountType(i));
2604 AccountSSL = prefaccounts.GetAccountSSL(i);
2605 AccTypeLower = AccType.MakeLower();
2606 SeekAccount.Append(wxT("."));
2607 SeekAccount.Append(AccTypeLower);
2609 if (SeekAccount == ActiveAccount){
2611 if (AccTypeLower == wxT("local")){
2617 if (AccountSSL == false){
2623 SSLTrustIter = AccountTrustData.find(i);
2625 // Setup and display the form.
2627 DisplayCertificate(SSLTrustIter->second);
2631 SeekAccount.Clear();
2632 AccTypeLower.Clear();
2637 #elif defined(__WIN32__)
2639 std::map<int, PCCERT_CONTEXT>::iterator SSLCertificateIter;
2641 for (int i = 0; i < prefaccounts.GetCount(); i++){
2643 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2644 AccType.Append(prefaccounts.GetAccountType(i));
2645 AccountSSL = prefaccounts.GetAccountSSL(i);
2646 AccTypeLower = AccType.MakeLower();
2647 SeekAccount.Append(wxT("."));
2648 SeekAccount.Append(AccTypeLower);
2650 if (SeekAccount == ActiveAccount){
2652 if (AccTypeLower == wxT("local")){
2658 if (AccountSSL == false){
2664 SSLCertificateIter = AccountCertificateData.find(i);
2666 // Setup and display the form.
2668 if (SSLCertificateIter->second->pCertInfo == NULL){
2670 wxMessageBox("No certificate information is available due to invalid connection details, connection being in progress or invalid certificate data received.");
2674 BOOL ModifiedCertificateData;
2675 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(SSLCertificateIter->second, (HWND)this->GetHandle());
2677 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
2678 wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
2683 //DisplayCertificate(SSLTrustIter->second);
2687 SeekAccount.Clear();
2688 AccTypeLower.Clear();
2695 std::map<int, SSLCertCollectionString>::iterator SSLColIter;
2697 for (int i = 0; i < prefaccounts.GetCount(); i++){
2699 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2700 AccType.Append(prefaccounts.GetAccountType(i));
2701 AccountSSL = prefaccounts.GetAccountSSL(i);
2702 AccTypeLower = AccType.MakeLower();
2703 SeekAccount.Append(wxT("."));
2704 SeekAccount.Append(AccTypeLower);
2706 if (SeekAccount == ActiveAccount){
2708 if (AccTypeLower == wxT("local")){
2714 if (AccountSSL == false){
2720 SSLColIter = AccountSSLData.find(i);
2722 SSLCertCollectionString SSLCertInfo = SSLColIter->second;
2724 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2725 frameSSLCert->StartCertFrom(0);
2726 frameSSLCert->SetupCertsString(SSLCertInfo);
2727 frameSSLCert->ShowModal();
2729 delete frameSSLCert;
2730 frameSSLCert = NULL;
2734 SeekAccount.Clear();
2735 AccTypeLower.Clear();
2744 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2746 // Check the account type before continuing.
2750 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2752 // Check the account type before continuing.
2756 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2758 if (event.GetInt() == 0){
2760 imgConnStatus->SetBitmap(*imgOnline);
2764 imgConnStatus->SetBitmap(*imgOffline);
2770 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2772 // Display the form for showing an invalid SSL certificate.
2774 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2775 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2776 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2777 wxString AccountName = SSLICNObj->AccountName;
2778 frameISC->LoadData(SSLCCData, AccountName);
2779 frameISC->ShowModal();
2781 int FinalConflictResult = frameISC->GetResult();
2783 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2784 event2.SetClientData(SSLICNObj->QRNotifData);
2785 event2.SetInt(FinalConflictResult);
2790 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2791 wxPostEvent(frameActMgr, event2);
2795 void frmMain::InvalidSSLCertificateString( wxCommandEvent &event ){
2797 // Display the form for showing an invalid SSL certificate.
2799 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2800 SSLInvalidCertNotifObjString *SSLICNObj = (SSLInvalidCertNotifObjString*)event.GetClientData();
2801 SSLCertCollectionString SSLCCData = SSLICNObj->CertCollection;
2802 wxString AccountName = SSLICNObj->AccountName;
2803 frameISC->LoadData(SSLCCData, AccountName);
2804 frameISC->ShowModal();
2806 int FinalConflictResult = frameISC->GetResult();
2808 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2809 event2.SetClientData(SSLICNObj->QRNotifData);
2810 event2.SetInt(FinalConflictResult);
2815 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2816 wxPostEvent(frameActMgr, event2);
2820 void frmMain::PauseAllTimers(){
2822 // Pause all the account timers.
2824 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2825 ASTiter != AccountSyncTimers.end(); ASTiter++){
2827 ASTiter->second->Stop();
2833 void frmMain::ResumeAllTimers(){
2835 // Resume all the account timers.
2837 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2838 ASTiter != AccountSyncTimers.end(); ASTiter++){
2840 ASTiter->second->Start();
2846 #if defined(__APPLE__)
2848 #elif defined(__WIN32__)
2850 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEXT CertificateContext){
2852 // Delete existing data.
2854 std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.find(AccountID);
2856 if (CertificateIter != AccountCertificateData.end()){
2857 CertFreeCertificateContext(CertificateIter->second);
2860 AccountCertificateData.erase(AccountID);
2861 AccountSSLResult.erase(AccountID);
2865 AccountCertificateData.insert(std::make_pair(AccountID, CertificateContext));
2866 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2872 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollectionString SSLCertInc){
2874 // Delete existing data.
2876 AccountSSLData.erase(AccountID);
2877 AccountSSLResult.erase(AccountID);
2881 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2882 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2888 void frmMain::SetupSSLStatus( int AccountID ){
2890 // Check if account ID given is
2891 // the active account and if not, do nothing.
2894 wxString AccTypeLower;
2896 AccType = prefaccounts.GetAccountType(AccountID);
2897 AccTypeLower = AccType.MakeLower();
2899 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2902 if (AccountIDName != ActiveAccount){
2908 // Check the account type is a supported account type.
2910 if (AccType != "CardDAV" && AccType != "carddav" &&
2911 AccType != "Local" && AccType != "local"){
2913 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2914 imgSSLStatus->SetBitmap(*imgNoSSL);
2919 // Check if the account has SSL enabled.
2921 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2923 if (SSLInUse == FALSE){
2925 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2926 imgSSLStatus->SetBitmap(*imgNoSSL);
2930 // Get the SSL Collection Data.
2932 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2934 // Check if a result value has been set.
2936 if (SSLResultIter == AccountSSLResult.end()){
2938 imgSSLStatus->SetBitmap(*imgSSLWarning);
2939 SSLToolTip->SetTip(wxT("Unable to determine SSL information for the '") + prefaccounts.GetAccountName(AccountID) + wxT("' account."));
2944 if (SSLResultIter->second == 1){
2946 imgSSLStatus->SetBitmap(*imgSSLWarning);
2947 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2948 prefaccounts.GetAccountName(AccountID) +
2949 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2951 } else if (SSLResultIter->second == 0){
2953 imgSSLStatus->SetBitmap(*imgSSL);
2954 SSLToolTip->SetTip(wxT("Account '") +
2955 prefaccounts.GetAccountName(AccountID) +
2956 wxT("' secured using SSL\n\nDouble click for more information."));
2964 void frmMain::CheckUpdates( wxCommandEvent& event ){
2966 // Check for updates to Xestia Address Book.
2968 frmUpdate *frameUpdate = new frmUpdate ( this );
2969 frameUpdate->FetchData();
2970 frameUpdate->ShowModal();
2974 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2976 // Run the import contacts function.
2982 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2984 // Check if an account and at least one contact is selected
2985 // before continuing.
2987 wxArrayString ArrData;
2989 if (ActiveAccount.IsEmpty()){
2995 int ContactSelected = 0;
2996 int ContactsCollected = 0;
2997 long longSelected = -1;
3001 longSelected = lstContacts->GetNextItem(longSelected,
3003 wxLIST_STATE_SELECTED);
3005 if (longSelected == -1){
3011 int FileID = (int)lstContacts->GetItemData(longSelected);
3013 ArrData.Insert(ContactsFileIndex[FileID],
3014 ContactsCollected, 1);
3020 if (ContactSelected == 0){
3026 // Run the export contacts system.
3028 ExportRun(this, &ArrData);
3032 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
3033 wxArrayString *ContactsFileIndexPtr){
3035 // Set the list control pointers.
3037 lstContactsPtr = lstContacts;
3038 ContactsFileIndexPtr = &ContactsFileIndex;
3042 void frmMain::GetSelectedList( wxCommandEvent& event ){
3044 // Get the array of contact filenames.
3046 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
3048 // Process them into an array of files.
3050 long longSelected = -1;
3051 int ContactsCollected = 0;
3052 wxString ContactFilename;
3056 longSelected = lstContacts->GetNextItem(longSelected,
3058 wxLIST_STATE_SELECTED);
3060 if (longSelected == -1){
3066 // Get the file information and add to the list.
3068 int FileID = (int)lstContacts->GetItemData(longSelected);
3070 ArrData->Insert(ContactsFileIndex[FileID],
3071 ContactsCollected, 1);
3073 ContactsCollected++;
3074 ContactFilename.Clear();
3082 void frmMain::SyncAccount( wxCommandEvent& event ){
3084 // Syncronise the selected account.
3086 wxString AccNameInc = event.GetString();
3088 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
3089 frameActMgr->AddTask(3, wxT(""), AccNameInc,
3090 wxT(""), wxT(""), wxT(""), wxT(""));
3094 void frmMain::ShowHelp( wxCommandEvent& event ){
3096 // Based on the operating system, work out where
3097 // the documentation should be.
3101 #if defined(__HAIKU__)
3103 #elif defined(__WIN32__)
3109 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
3111 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
3114 #if XSDAB_RELEASE == 0
3116 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
3118 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
3127 #if XSDAB_RELEASE == 0
3129 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
3133 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!"));
3139 void frmMain::ShowImportResults( wxCommandEvent &event ){
3141 // Show the results of importing contacts.
3143 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
3145 frmImportResults *frmIR = new frmImportResults(this);
3146 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
3157 void frmMain::ReloadContactList( wxCommandEvent &event ){
3159 // Check if the account name given is the current
3160 // account selected.
3162 if (ActiveAccount == event.GetString()){
3164 wxTreeEvent NullEvent;
3165 LoadContactList(NullEvent);
3171 void frmMain::ShowContactMenu( wxMouseEvent& event ){
3173 // Show the contact menu when a right click occurs
3174 // in the contacts list.
3176 bool EnableRefresh = FALSE;
3178 if (!ActiveAccount.IsEmpty() && (ActiveAccountType == "CardDAV" ||
3179 ActiveAccountType == "carddav" ||
3180 ActiveAccountType == "Local" ||
3181 ActiveAccountType == "local")){
3183 EnableRefresh = TRUE;
3187 ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
3189 this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
3193 void frmMain::ResetContactInfo(){
3195 // Reset the contact information to an empty page.
3197 wxString EmptyPage = wxT("");
3198 htmContactData->SetPage(EmptyPage);
3199 AccCtrl->SetValue("");
3203 bool frmMain::CloseAllWindows()
3205 // Attempt to close all windows.
3207 if (WindowListPointersMenu.size() == 0)
3212 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)
3214 for(std::map<int, void*>::iterator windowIter = WindowListPointers.begin();
3215 windowIter != WindowListPointers.end(); windowIter++)
3217 wxWindow *windowPointer = static_cast<wxWindow*>(windowIter->second);
3218 windowPointer->Close();