1 // frmMain.cpp - Main window form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
25 #include <wx/tokenzr.h>
27 #include <wx/mstream.h>
28 #include <wx/fs_mem.h>
30 #include <wx/filesys.h>
32 #include <wx/stdpaths.h>
33 #include <wx/fileconf.h>
34 #include <wx/gdicmn.h>
40 #include "frmPreferences.h"
41 #include "frmNewAccount.h"
42 #include "actmgr/frmActivityMgr.h"
43 #include "frmContact.h"
44 #include "frmConflictResolution.h"
45 #include "frmInvalidSSLCertificate.h"
46 #include "search/frmSearch.h"
47 #include "frmSSLCertificate.h"
48 #include "frmUpdate.h"
49 #include "import/frmImportResults.h"
52 #include "common/preferences.h"
53 #include "common/getcontactinfo.h"
54 #include "common/events.h"
55 #include "common/dirs.h"
56 #include "vcard/vcard.h"
57 #include "carddav/carddav.h"
58 #include "contacteditor/frmContactEditor.h"
59 #include "import/import.h"
60 #include "export/export.h"
61 #include "widgets/XABContactMenu.h"
62 #include "widgets/XABAccountView.h"
66 // Define the event types.
68 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
69 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
70 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
71 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
72 DEFINE_EVENT_TYPE(CE_OPENCONTACTLIST);
73 DEFINE_EVENT_TYPE(CE_NEWCONTACT);
74 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
75 DEFINE_EVENT_TYPE(CE_DELETECONTACT);
76 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
77 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
78 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
79 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
80 DEFINE_EVENT_TYPE(ACTMGR_START);
81 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
82 DEFINE_EVENT_TYPE(ACTMGR_STOP);
83 DEFINE_EVENT_TYPE(WINDOW_ADD);
84 DEFINE_EVENT_TYPE(WINDOW_EDIT);
85 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
86 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
87 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
88 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
89 DEFINE_EVENT_TYPE(SYNCACCOUNT);
90 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
91 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
92 DEFINE_EVENT_TYPE(REFRESHADDRESSBOOK);
93 #if defined(__APPLE__)
94 DEFINE_EVENT_TYPE(INVALIDSSLTRUST);
97 // Setup the event table using the event types.
99 BEGIN_EVENT_TABLE(frmMain, wxFrame)
100 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
101 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
102 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
103 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
104 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
105 EVT_COMMAND(wxID_ANY, CE_OPENCONTACTLIST, frmMain::OpenContactInfoList)
106 EVT_COMMAND(wxID_ANY, CE_NEWCONTACT, frmMain::ShowContactEditorNew)
107 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
108 EVT_COMMAND(wxID_ANY, CE_DELETECONTACT, frmMain::DeleteContact)
109 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
110 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
111 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
112 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
113 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
114 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
115 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
116 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
117 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
118 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
119 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
120 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
121 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
122 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
123 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
124 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
125 #if defined(__APPLE__)
126 EVT_COMMAND(wxID_ANY, INVALIDSSLTRUST, frmMain::DisplayTrustPanel)
130 frmMain::frmMain( wxWindow* parent )
135 // Setup the account icons.
137 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
138 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
139 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
140 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_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 AccountID = AccImgList->Add(wxIAccNIcon);
163 AccountNetID = AccImgList->Add(wxIAccInet);
164 AccountGrpID = AccImgList->Add(wxIAccGrp);
165 AccountNoneID = AccImgList->Add(wxIAccNone);
167 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
169 // Setup the status bar icons.
173 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
174 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
175 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
177 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
178 imgSSL = new wxBitmap(icons_ssl_png, -1);
180 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
181 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
183 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
184 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
188 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
189 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
190 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
191 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
192 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
194 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
195 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
197 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
198 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
200 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
202 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
203 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
205 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
207 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
208 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
210 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
212 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
213 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
215 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
217 // Online/Offline icons.
219 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
220 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
222 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
223 imgOnline = new wxBitmap(icons_online_png, -1);
225 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
226 imgOffline = new wxBitmap(icons_offline_png, -1);
228 // Setup the account view.
230 AccCtrl->SetPopupControl(treAccounts);
231 AccCtrl->SetPopupMaxHeight(175);
232 AccCtrl->SetPopupMinWidth(250);
233 treAccounts->AssignImageList(AccImgList);
235 wxListItem ColumnData;
237 ColumnData.SetText(wxT("Name0"));
238 ColumnData.SetWidth(320);
239 lstContacts->InsertColumn(0, ColumnData);
241 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
242 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
244 #if defined(__HAIKU__)
246 #elif defined(__WIN32__)
248 int stbBottomData [4] = { -1, 16, 16, 16 };
252 int stbBottomData [4] = { -1, 20, 20, 20 };
256 stbBottom->SetFieldsCount(4, stbBottomData);
257 stbBottom->SetMinHeight(16);
262 stbBottom->GetFieldRect(1, rectOnline);
263 stbBottom->GetFieldRect(2, rectSSL);
264 stbBottom->GetFieldRect(3, rectActivity);
266 SSLToolTip = new wxToolTip(wxT(""));
268 #if defined(__WIN32__)
270 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint(rectOnline.GetX(),rectOnline.GetY()), wxDefaultSize, 0 );
271 imgConnStatus->SetBitmap(*imgOnline);
272 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
274 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
275 imgSSLStatus->SetBitmap(*imgNoSSL);
276 imgSSLStatus->SetToolTip(SSLToolTip);
277 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
279 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
280 imgActivityStatus->SetBitmap(*imgActIconSleep);
281 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
285 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()), (rectOnline.GetY())), wxDefaultSize, 0);
286 imgConnStatus->SetBitmap(*imgOnline);
287 imgConnStatus->Connect(wxEVT_LEFT_DCLICK, wxCommandEventHandler(frmMain::ToggleConnectionStatus), NULL, this);
289 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()), (rectSSL.GetY())), wxDefaultSize, 0);
290 imgSSLStatus->SetBitmap(*imgNoSSL);
291 imgSSLStatus->SetToolTip(SSLToolTip);
292 imgSSLStatus->Connect(wxEVT_LEFT_DCLICK, wxCommandEventHandler(frmMain::ShowSSLCertificates), NULL, this);
294 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()), (rectActivity.GetY())), wxDefaultSize, 0);
295 imgActivityStatus->SetBitmap(*imgActIconSleep);
296 imgActivityStatus->Connect(wxEVT_LEFT_DCLICK, wxCommandEventHandler(frmMain::ShowActivityWindow), NULL, this);
300 // Setup the window menu.
302 // By default should be:
307 // Contact editor windows:
313 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
314 mnuWindow->Append( mnuContactWindows );
316 mnuWindow->AppendSeparator();
318 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
319 mnuWindow->Append( mnuContactEditorWindows );
321 mnuWindow->AppendSeparator();
323 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
324 mnuWindow->Append( mnuSearchWindows );
326 #if defined(__WIN32__)
331 mnuContactWindows->SetFont(fontstyle);
332 mnuContactEditorWindows->SetFont(fontstyle);
333 mnuSearchWindows->SetFont(fontstyle);
337 mnuContactWindows->Enable(FALSE);
338 mnuContactEditorWindows->Enable(FALSE);
339 mnuSearchWindows->Enable(FALSE);
343 // Hide unimplemented functions.
349 void frmMain::QuitApp( wxCloseEvent& event )
352 // Run the QuitApp function.
358 void frmMain::QuitApp( wxCommandEvent& event )
361 // Run the QuitApp function.
367 void frmMain::QuitApp()
370 // Function to run when quitting.
372 //Go through the windows and close each one (be it search
373 //or contact editor). Abort if user wants to cancel.
375 // Close the contact editor windows.
377 // Close the contact windows.
379 // Close the search windows.
381 // Write out the ETag databases.
383 // Save Preferences: Save the window position if that option is enabled.
385 wxString SetFilename = GetUserPrefDir();
387 #if defined(__HAIKU__)
391 #elif defined(__WIN32__)
393 SetFilename.Append(wxT("settings"));
399 SetFilename.Append(wxT("settings"));
403 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
405 bool SaveWindowPos = FALSE;
406 wxString SaveWindowInc;
407 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
409 if (SaveWindowInc == wxT("true")){
411 SaveWindowPos = TRUE;
415 if (SaveWindowPos == TRUE){
417 wxRect frmMainPos = this->GetRect();
419 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
420 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
421 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
422 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
429 //Everything closed... exit.
437 void frmMain::ShowActivityWindow( wxCommandEvent& event )
440 // Open the activity manager window.
442 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
443 frameActMgr->OpenWindow();
448 void frmMain::ShowAboutWindow( wxCommandEvent& event )
451 // Show the about window.
453 frmAbout *frameAbout = new frmAbout ( this );
454 frameAbout->SetupAboutWindow();
455 frameAbout->ShowModal();
461 void frmMain::OpenPreferences( wxCommandEvent& event)
464 // Open the preferences window.
466 ReloadAccounts = FALSE;
468 frmPreferences *framePreferences = new frmPreferences ( this );
469 framePreferences->SetupPointers(&ReloadAccounts);
470 framePreferences->ShowModal();
471 delete framePreferences;
472 framePreferences = NULL;
474 if (ReloadAccounts == TRUE){
476 // Reload the accounts as a change has been made within
477 // the application and clear the current contact information.
479 this->LoadPreferences();
480 this->ResetContactInfo();
486 void frmMain::OpenNewABDialog( wxCommandEvent& event)
489 // Open the new account dialog.
491 ReloadAccounts = FALSE;
493 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
494 frameNewAccount->SetupPointers(&ReloadAccounts);
495 frameNewAccount->ShowModal();
496 delete frameNewAccount;
497 frameNewAccount = NULL;
499 if (ReloadAccounts == TRUE){
501 // Reload the accounts as a change has been made within
504 this->LoadPreferences();
510 void frmMain::LoadContactList( wxTreeEvent& event )
513 // Load the contact list.
515 // Clear all existing variables.
517 lstContacts->DeleteAllItems();
519 treAccounts->SetAccount();
521 wxTreeItemIdValue cookie;
522 wxTreeItemId next = treAccounts->GetRootItem();
523 wxString AccountName;
524 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
525 wxString AccountDirCmb;
526 long selectedaccount = 0;
528 wxTreeItemId selectedChild = treAccounts->GetSelection();
529 wxTreeItemId nextChild;
531 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
532 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
534 int SCImg = treAccounts->GetItemImage(selectedChild);
535 int AccountIndex = 0;
537 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
539 // Process each account.
541 for (int i = 0; i < prefaccounts.GetCount(); i++){
543 if (ActiveItemIcon == 2){
545 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
546 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
547 int ActiveAccountG = AGLiter->second;
549 if (i == ActiveAccountG){
551 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
552 AccountType.Append(prefaccounts.GetAccountType(i));
557 if (AccountType == wxT("CardDAV")){
558 AccountTypeFinal.Append(wxT("carddav"));
559 } else if (AccountType == wxT("Local")){
560 imgSSLStatus->SetBitmap(*imgOffline);
561 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
562 AccountTypeFinal.Append(wxT("local"));
573 nextChild = treAccounts->GetFirstChild(next, cookie);
575 nextChild = treAccounts->GetNextSibling(nextChild);
578 AccountName = treAccounts->GetItemText(nextChild);
580 if (nextChild == selectedChild){
582 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
583 AccountType.Append(prefaccounts.GetAccountType(i));
588 if (AccountType == wxT("CardDAV")){
589 AccountTypeFinal.Append(wxT("carddav"));
590 } else if (AccountType == wxT("Local")){
591 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
592 AccountTypeFinal.Append(wxT("local"));
601 if (selectedaccount >= prefaccounts.GetCount()){
603 // The account selected isn't there so return.
611 // Open the directory and get the list of .vcf files
612 // in that directory.
614 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
615 ActiveAccountType = AccountType;
617 SetupSSLStatus(AccountIndex);
619 AccountDirFinal.Clear();
620 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
622 ContactsFileIndex.Clear();
624 wxString vCardFilename;
625 wxString vCardFilenameFull;
626 wxString vCardDataString;
627 wxStringTokenizer vcardfileline;
629 wxString setname, setvalue;
630 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
631 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
632 long ContactIndex = 1;
633 long ContactSeekPoint = 0;
635 wxDir vcardaccdir(AccountDirFinal);
637 // Get the wxTreeItemId and image icon and compare it to the list.
639 if (ActiveItemIcon == AccountGrpID){
641 // It's a group so load the file containing the group and
642 // get the members of the group.
647 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
648 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
650 Group.LoadFile(AGFiter->second);
652 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
654 for (int i = 0; i < vCardMember.PropCount; i++){
656 vCardMember.PropValues[i].Trim();
657 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
659 wxString NewPropValue;
660 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
661 vCardMember.PropValues[i] = NewPropValue;
667 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
671 if (vCardFilename.Right(4) == wxT(".vcf") ||
672 vCardFilename.Right(4) == wxT(".VCF") ||
673 vCardFilename.Right(5) == wxT(".vcard") ||
674 vCardFilename.Right(5) == wxT(".VCARD")){
677 bool FoundMember = FALSE;
679 vCardFilenameFull.Append(AccountDirFinal);
680 vCardFilenameFull.Append(wxT("/"));
681 vCardFilenameFull.Append(vCardFilename);
683 Person.LoadFile(vCardFilenameFull);
685 UIDCode = Person.Get(wxT("UID"));
687 for (int i = 0; i < vCardMember.PropCount; i++){
689 if (vCardMember.PropValues[i] == UIDCode){
697 if (FoundMember == FALSE){
699 vCardFilename.Clear();
700 vCardFilenameFull.Clear();
701 vCardDataString.Clear();
702 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
707 if (Person.MeetBaseSpecification()){
711 // Split the name into sections.
713 vCardDataString = Person.Get(wxT("N"));
715 vCardName NameData = Person.GetName();
717 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
719 } else if (SortMode == 2){
721 // Split the name into sections.
723 vCardName NameData = Person.GetName();
725 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
727 } else if (SortMode == 3){
729 // Check and make sure that the top most nickname is used.
731 vCardDataString = Person.Get(wxT("NICKNAME"));
733 if (vCardDataString.IsEmpty()){
735 vCardDataString = wxT("(no nickname)");
739 } else if (SortMode == 4){
741 vCardDataString = Person.Get(wxT("FN"));
745 if (AscendingMode == TRUE){
746 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
748 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
755 vCardFilename.Clear();
756 vCardFilenameFull.Clear();
757 vCardDataString.Clear();
758 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
764 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
767 if (vCardFilename.Right(4) == wxT(".vcf") ||
768 vCardFilename.Right(4) == wxT(".VCF") ||
769 vCardFilename.Right(5) == wxT(".vcard") ||
770 vCardFilename.Right(5) == wxT(".VCARD")){
774 vCardFilenameFull.Append(AccountDirFinal);
775 vCardFilenameFull.Append(vCardFilename);
777 Person.LoadFile(vCardFilenameFull);
779 if (Person.MeetBaseSpecification()){
783 // Split the name into sections.
785 vCardDataString = Person.Get(wxT("N"));
787 vCardName NameData = Person.GetName();
789 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
791 } else if (SortMode == 2){
793 // Split the name into sections.
795 vCardName NameData = Person.GetName();
797 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
799 } else if (SortMode == 3){
801 // Check and make sure that the top most nickname is used.
803 vCardDataString = Person.Get(wxT("NICKNAME"));
805 if (vCardDataString.IsEmpty()){
807 vCardDataString = wxT("(no nickname)");
811 } else if (SortMode == 4){
813 vCardDataString = Person.Get(wxT("FN"));
817 if (AscendingMode == TRUE){
819 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
823 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
831 vCardFilename.Clear();
832 vCardFilenameFull.Clear();
833 vCardDataString.Clear();
834 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
841 // Insert the data into the control.
843 if (AscendingMode == TRUE){
844 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
845 iter != vCardNamesAsc.end(); ++iter){
847 wxListItem ContactInfo;
849 ContactInfo.SetId(0);
850 ContactInfo.SetText(_("Mooo"));
851 ContactInfo.SetData(ContactSeekPoint);
852 ContactIndex = lstContacts->InsertItem(ContactInfo);
854 lstContacts->SetItem(ContactIndex, 0, iter->first);
856 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
863 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
864 iter != vCardNamesDsc.end(); ++iter){
866 wxListItem ContactInfo;
868 ContactInfo.SetId(0);
869 ContactInfo.SetText(_("Mooo"));
870 ContactInfo.SetData(ContactSeekPoint);
871 ContactIndex = lstContacts->InsertItem(ContactInfo);
873 lstContacts->SetItem(ContactIndex, 0, iter->first);
874 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
883 void frmMain::ShowContactInfo( wxListEvent& event )
886 // Display the contact information.
888 long intSelected = -1;
889 long ContactSeekNum = -1;
891 // Check if several contacts have been selected.
893 int ContactTotal = 0;
897 intSelected = lstContacts->GetNextItem(intSelected,
899 wxLIST_STATE_SELECTED);
901 if (intSelected == -1){
911 if (ContactTotal == 0){
912 htmContactData->SetPage(wxT(""));
916 if (ContactTotal > 1){
918 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
919 ActiveFilename.Clear();
924 intSelected = lstContacts->GetNextItem(intSelected,
926 wxLIST_STATE_SELECTED);
928 ContactSeekNum = lstContacts->GetItemData(intSelected);
931 wxString wxSContactString;
932 wxString ContactLine;
935 size_t ContactLineLen;
936 bool ExtraLineSeek = FALSE;
937 int QuoteBreakPoint = 0;
939 bool PropertyFind = FALSE;
940 bool QuoteMode = FALSE;
942 wxString wxSPropertyNextLine;
943 wxString wxSProperty;
944 wxString wxSPropertySeg1;
945 wxString wxSPropertySeg2;
947 // Check if we are using wxWidgets version 2.8 or less and
948 // execute the required command accordingly.
950 #if wxABI_VERSION < 20900
951 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
953 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
956 if (ContactFile.IsOpened() == FALSE){
962 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
966 std::map<int, wxString> ContactFileLines;
967 std::map<int, wxString>::iterator striter;
969 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
971 int ContactLineSeek = 0;
973 while (wSTContactFileLines.HasMoreTokens() == TRUE){
975 ContactLine = wSTContactFileLines.GetNextToken();
976 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
981 if (ContactSeekNum < 0){
985 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
986 iter != ContactFileLines.end(); ++iter){
988 // Find the colon which splits the start bit from the data part.
990 ContactLine = iter->second;
992 while (ExtraLineSeek == TRUE){
994 // Check if there is extra data on the next line
995 // (indicated by space or tab at the start) and add data.
999 if (iter == ContactFileLines.end()){
1006 wxSPropertyNextLine = iter->second;
1009 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
1011 wxSPropertyNextLine.Remove(0, 1);
1012 ContactLine.Append(wxSPropertyNextLine);
1017 ExtraLineSeek = FALSE;
1023 ContactLineLen = ContactLine.Len();
1025 // Make sure we are not in quotation mode.
1026 // Make sure colon does not have \ or \\ before it.
1028 for (int i = 0; i <= ContactLineLen; i++){
1030 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1032 PropertyFind = FALSE;
1034 } else if (PropertyFind == TRUE){
1036 wxSProperty.Append(ContactLine.Mid(i, 1));
1040 if (ContactLine.Mid(i, 1) == wxT("\"")){
1042 if (QuoteMode == TRUE){
1054 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1056 QuoteBreakPoint = i;
1063 // Split that line at the point into two variables (ignore the colon).
1065 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1066 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1068 // Insert both into the vCard data file.
1070 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1073 PropertyFind = TRUE;
1074 ExtraLineSeek = TRUE;
1076 QuoteBreakPoint = 0;
1077 ContactLine.Clear();
1078 wxSProperty.Clear();
1082 OldSessionID = SessionID;
1083 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1084 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1085 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1089 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1092 // Open a contact editor window to write a new contact with.
1094 // Check if there is an account selected and if not
1095 // return immediately.
1097 if (ActiveAccount.IsEmpty()){
1103 // Add Pointer to SetupPointers for the ETagDB.
1105 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1106 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1107 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1109 contacticon.CopyFromBitmap(contacticonbmp);
1111 frmContactEditor *ContactEditor = new frmContactEditor( this );
1115 ContactEditor->SetUID(WindowMenuItemID);
1117 WindowData *WData = new WindowData;
1119 WData->DataType = 1;
1120 WData->WindowPointer = (void*)ContactEditor;
1121 WData->WindowID = WindowMenuItemID;
1123 wxCommandEvent addevent(WINDOW_ADD);
1124 addevent.SetClientData(WData);
1125 wxPostEvent(this, addevent);
1127 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1128 ContactEditor->SetupHeaders();
1129 ContactEditor->SetupContact(ActiveAccount);
1130 ContactEditor->SetIcon(contacticon);
1131 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1132 ContactEditor->Show(true);
1136 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1139 // Open a contact editor window for editing an existing contact
1142 // Check if there is an account selected and if not
1143 // return immediately.
1145 int DataCheck = event.GetInt();
1147 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1153 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1154 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1155 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1157 contacticon.CopyFromBitmap(contacticonbmp);
1159 // Check if a contact has been selected.
1161 long intSelected = -1;
1162 long intContactSeekNum = -1;
1164 intSelected = lstContacts->GetNextItem(intSelected,
1166 wxLIST_STATE_SELECTED);
1168 if (intSelected == -1){
1174 intContactSeekNum = lstContacts->GetItemData(intSelected);
1176 // Get the filename of the selected contact.
1178 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1179 frmContactEditor *ContactEditor = new frmContactEditor( this );
1183 ContactEditor->SetUID(WindowMenuItemID);
1185 WindowData *WData = new WindowData;
1187 WData->DataType = 1;
1188 WData->WindowPointer = (void*)ContactEditor;
1189 WData->WindowID = WindowMenuItemID;
1191 wxCommandEvent addevent(WINDOW_ADD);
1192 addevent.SetClientData(WData);
1193 wxPostEvent(this, addevent);
1195 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1196 ContactEditor->SetupHeaders();
1198 // Check if pointer is NULL (not from the search forms) or not.
1200 if (DataCheck == 0){
1202 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1203 ContactEditor->SetupContact(ActiveAccount);
1207 UCNotif *uc = (UCNotif*)event.GetClientData();
1211 ContactEditor->SetupContact(ActiveAccount);
1212 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1216 ContactEditor->SetupContact(uc->ContactAccount);
1217 ContactEditor->LoadContact(uc->ContactFilename);
1226 ContactEditor->SetIcon(contacticon);
1227 ContactEditor->Show(true);
1231 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1233 // Refresh the address book data.
1235 // Check if ActiveAccount is empty. If not then check if
1236 // account type is not local otherwise continue.
1238 if (!ActiveAccount.IsEmpty()){
1240 if (ActiveAccountType != wxT("Local")){
1242 // Account type is not local.
1244 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1245 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1246 wxT(""), wxT(""), wxT(""), wxT(""));
1250 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1258 void frmMain::OpenContactInfoList( wxListEvent& event )
1261 // Open the contact information window.
1263 wxStringTokenizer vcardfileline;
1266 wxString setname, setvalue;
1270 long intSelected = -1;
1271 long intContactSeekNum = -1;
1273 intSelected = lstContacts->GetNextItem(intSelected,
1275 wxLIST_STATE_SELECTED);
1277 intContactSeekNum = lstContacts->GetItemData(intSelected);
1279 if (intContactSeekNum == -1){
1285 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1287 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1288 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1289 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1291 contacticon.CopyFromBitmap(contacticonbmp);
1293 frmContact *Contact = new frmContact( this );
1295 // Add to window list.
1299 Contact->SetUID(WindowMenuItemID);
1301 WindowData *WData = new WindowData;
1303 WData->DataType = 0;
1304 WData->WindowPointer = (void*)Contact;
1305 WData->WindowID = WindowMenuItemID;
1307 wxCommandEvent addevent(WINDOW_ADD);
1308 addevent.SetClientData(WData);
1309 wxPostEvent(this, addevent);
1311 Contact->SetupPointers(&MemoryFileList);
1312 Contact->SetupContactData(&Person);
1314 Contact->SetIcon(contacticon);
1315 Contact->Show(true);
1319 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1321 // Open a list of contact information windows.
1324 OpenContactInfoList(pevent);
1328 void frmMain::OpenContactInfo( wxCommandEvent& event )
1331 // Open the contact information window.
1333 UCNotif *uc = (UCNotif*)event.GetClientData();
1335 wxStringTokenizer vcardfileline;
1338 wxString setname, setvalue;
1342 Person.LoadFile(uc->ContactFilename);
1344 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1345 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1346 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1348 contacticon.CopyFromBitmap(contacticonbmp);
1350 frmContact *Contact = new frmContact( this );
1352 // Add to window list.
1356 Contact->SetUID(WindowMenuItemID);
1358 WindowData *WData = new WindowData;
1360 WData->DataType = 0;
1361 WData->WindowPointer = (void*)Contact;
1362 WData->WindowID = WindowMenuItemID;
1364 wxCommandEvent addevent(WINDOW_ADD);
1365 addevent.SetClientData(WData);
1366 wxPostEvent(this, addevent);
1368 Contact->SetupPointers(&MemoryFileList);
1369 Contact->SetupContactData(&Person);
1371 Contact->SetIcon(contacticon);
1372 Contact->Show(true);
1377 void frmMain::LoadPreferences( wxActivateEvent& event)
1380 // Load the preferences.
1382 this->LoadPreferences();
1386 void frmMain::LoadPreferences(){
1388 // Load the preferences.
1390 wxString preffilename = GetUserPrefDir();
1392 XABPreferences preferences(preffilename);
1394 // Setup the main window position (if needed).
1396 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1397 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1399 if (SaveWindowPos == TRUE){
1401 this->SetSize(preferences.GetMainWindowData());
1405 treAccounts->DeleteAllItems();
1407 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1409 // Stop all account timers and remove the accounts.
1411 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1412 iter != AccountSyncTimers.end(); iter++){
1414 wxAccountSyncTimer *AccTmrPtr = iter->second;
1422 #if defined(__WIN32__)
1424 for (std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.begin();
1425 CertificateIter != AccountCertificateData.end(); CertificateIter++){
1427 CertFreeCertificateContext(CertificateIter->second);
1431 AccountCertificateData.clear();
1435 AccountSyncTimers.clear();
1438 wxString AccDirFull;
1439 wxString AccDirFullSfx;
1441 wxString AccDirFinal;
1442 AccountAccDirList.clear();
1443 AccountGroupList.clear();
1444 AccountGroupFilename.clear();
1445 AccountGroupTreeId.clear();
1446 wxTreeItemId AccountTreeId;
1447 wxTreeItemId GroupTreeId;
1450 // Relaod the accounts for the ETagProcTimer.
1452 ETagProcTimer.ReloadAccounts();
1454 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1456 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1457 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1463 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1469 AccDir = preferences.accounts.GetAccountDirectory(i);
1470 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1472 AccDirFull.Append(wxT("."));
1473 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1474 AccDirFullSfx.LowerCase();
1475 AccDirFullSfx.Trim();
1476 AccDirFull.Append(AccDirFullSfx);
1477 AccName = preferences.accounts.GetAccountName(i);
1479 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1481 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1482 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1484 // TODO: Check if the directory exists before doing anything.
1488 // Add a new timer using the existing account details.
1490 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1492 ActTmrPtr->SetupData(AccDirFull, AccName);
1493 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1494 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1495 ActTmrPtr->SetOwner(this);
1496 ActTmrPtr->Notify();
1498 // Add the timer to the list of timers.
1500 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1502 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1506 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1510 // Go through the account directory and find contact files with
1511 // 'KIND:group' set and add them to the list of groups for the account.
1513 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1515 wxDir vcardaccdir(AccDirFinal);
1517 wxString vCardFilename;
1518 wxString vCardDataString;
1519 wxString vCardFilenameFull;
1521 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1525 if (vCardFilename.Right(4) == wxT(".vcf") ||
1526 vCardFilename.Right(4) == wxT(".VCF") ||
1527 vCardFilename.Right(5) == wxT(".vcard") ||
1528 vCardFilename.Right(5) == wxT(".VCARD")){
1532 vCardFilenameFull.Append(AccDirFinal);
1533 vCardFilenameFull.Append(wxT("/"));
1534 vCardFilenameFull.Append(vCardFilename);
1536 Person.LoadFile(vCardFilenameFull);
1538 if (Person.MeetBaseSpecification()){
1540 vCardDataString = Person.Get(wxT("KIND"));
1542 if (vCardDataString == wxT("group")){
1544 // The vCard kind is a group. Add to the account's group list.
1546 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1547 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1548 AccountGroupList.insert(std::make_pair(intGroupID, i));
1549 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1550 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1560 vCardFilename.Clear();
1561 vCardFilenameFull.Clear();
1562 vCardDataString.Clear();
1563 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1567 // Clearup for next account.
1571 AccDirFullSfx.clear();
1572 AccDirFinal.clear();
1577 // Load the account settings as they are needed for connecting
1580 prefaccounts = preferences.accounts;
1584 void frmMain::ConflictResolution(wxCommandEvent& event){
1586 // Display the conflict resolution window.
1588 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1589 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1590 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1591 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1592 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1593 frameCR->ShowModal();
1595 int FinalConflictResult = frameCR->GetResult();
1597 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1598 event2.SetClientData(vCardConfObj->QRNotifData);
1599 event2.SetInt(FinalConflictResult);
1604 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1605 wxPostEvent(frameActMgr, event2);
1609 void frmMain::UpdateContactList(wxCommandEvent& event){
1611 // Update the contact list in the main window.
1613 UCNotif *ucd = (UCNotif*)event.GetClientData();
1615 // Check if the active account is being displayed in the
1616 // main window. If not, skip and delete the data.
1618 long longSelected = -1;
1619 int intSelectedData = 0;
1621 if (ActiveAccount == ucd->ContactAccount){
1623 // Look at the list of contacts and if it matches the
1624 // filename then update the name.
1628 longSelected = lstContacts->GetNextItem(longSelected,
1630 wxLIST_STATE_DONTCARE);
1632 if (longSelected == -1){
1638 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1640 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1642 // Work out which sorting mode we are in.
1646 // First Name, Last Name.
1648 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1650 } else if (SortMode == 2){
1652 // Last Name, First Name.
1654 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1656 } else if (SortMode == 3){
1660 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1662 } else if (SortMode == 4){
1666 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1673 // If the filename is the one loaded into the
1674 // browser control, then update this too.
1676 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1678 wxListEvent nullevent;
1679 ShowContactInfo(nullevent);
1687 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1688 WindowIter != WindowListPointers.end(); WindowIter++){
1690 if (WindowListType[WindowIter->first] != 0){
1696 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1698 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1700 vCard UpdatedPerson;
1701 UpdatedPerson.LoadFile(ucd->ContactFilename);
1702 frmContactPtr->SetupContactData(&UpdatedPerson);
1708 // Send message to search window controller subroutine and
1709 // pass that notification onto the search windows.
1711 // Setup the new pointer to use the existing UCNotif without
1714 UCNotif *ucd2 = ucd;
1716 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1717 sup.SetClientData(ucd2);
1718 wxPostEvent(this, sup);
1720 // Clear up the unused pointer.
1726 void frmMain::UpdateAccountList(wxCommandEvent& event){
1728 // Update the account list (currently unimplemented).
1732 void frmMain::SetupPointers(void *ActMgrPtrInc){
1734 // Setup the pointers for the main window.
1736 ActMgrPtr = ActMgrPtrInc;
1740 void frmMain::SetupForm(){
1742 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1743 frameActMgr->SetupPointers(&ETagProcTimer, this);
1745 // Setup the contact information icons for later.
1747 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1751 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1752 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1753 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1755 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1756 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1757 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1759 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1760 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1761 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1763 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1764 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1765 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1767 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1768 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1769 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1771 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1772 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1773 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1779 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1781 // Update the contact lists in the search windows.
1783 // Go through each of the search windows and
1784 // send the required notification to update the
1785 // contact information.
1787 // Get the event notification data.
1789 UCNotif *ucd = (UCNotif*)event.GetClientData();
1791 // Process each search window giving the new details.
1793 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1794 switer != SearchWindowList.end(); switer++){
1796 // Duplicate the event notification data.
1798 UCNotif *ucd2 = new UCNotif;
1800 ucd2->ContactAccount = ucd->ContactAccount;
1801 ucd2->ContactFilename = ucd->ContactFilename;
1802 ucd2->ContactName = ucd->ContactName;
1803 ucd2->ContactNickname = ucd->ContactNickname;
1804 ucd2->ContactNameArray = ucd->ContactNameArray;
1806 // Pass the data to the search window for processing.
1808 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1809 wxCommandEvent schupdate(SE_UPDATERESULT);
1810 schupdate.SetClientData(ucd2);
1811 wxPostEvent(frameSCH, schupdate);
1813 // Clear up the pointer prior to variable deletion.
1824 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1826 // Open a new search window.
1830 frmSearch *frameSCH = new frmSearch ( this );
1831 frameSCH->SetUID(WindowMenuItemID);
1832 frameSCH->Show(true);
1834 WindowData *WData = new WindowData;
1836 WData->DataType = 2;
1837 WData->WindowPointer = (void*)frameSCH;
1838 WData->WindowID = WindowMenuItemID;
1840 wxCommandEvent addevent(WINDOW_ADD);
1841 addevent.SetClientData(WData);
1842 wxPostEvent(this, addevent);
1844 // Add pointer to the list of open search windows.
1846 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1852 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1854 // Remove the pointer for a contact window from the
1857 void *frameSCH = (void*)event.GetClientData();
1859 SearchWindowList.erase(frameSCH);
1865 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1867 // Remove the pointer for a contact editor window from
1870 void *frameSCH = (void*)event.GetClientData();
1872 SearchWindowList.erase(frameSCH);
1878 void frmMain::RevealContact(wxCommandEvent& event){
1880 // Reveal a contact in the main window.
1882 UCNotif *uc = (UCNotif*)event.GetClientData();
1884 // Switch the account to the one passed.
1886 wxTreeItemIdValue cookie;
1887 wxTreeItemId next = treAccounts->GetRootItem();
1888 wxTreeItemId nextChild;
1890 for (int i = 0; i < prefaccounts.GetCount(); i++){
1893 nextChild = treAccounts->GetFirstChild(next, cookie);
1895 nextChild = treAccounts->GetNextSibling(nextChild);
1898 if (uc->ContactAccount == AccountAccDirList[i]){
1900 treAccounts->SelectItem(nextChild, TRUE);
1901 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1907 // Switch the contact to the one passed.
1909 long longSelected = -1;
1910 int intSelectedData = 0;
1914 longSelected = lstContacts->GetNextItem(longSelected,
1916 wxLIST_STATE_DONTCARE);
1918 if (longSelected == -1){
1924 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1926 // Compare the filename with the one received.
1927 // If they match then select it.
1929 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1933 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1934 lstContacts->EnsureVisible(longSelected);
1938 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1946 void frmMain::DeleteContact(wxCommandEvent& event){
1948 // Delete a contact from the main window.
1950 // Check if a contact is selected.
1952 long intSelected = -1;
1953 long intContactSeekNum = -1;
1954 wxString wxSContactName;
1956 intSelected = lstContacts->GetNextItem(intSelected,
1958 wxLIST_STATE_SELECTED);
1960 if (intSelected == -1){
1964 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1966 // Get the item data of the contact.
1968 intContactSeekNum = lstContacts->GetItemData(intSelected);
1970 // Get the name of the contact.
1972 wxSContactName = lstContacts->GetItemText(intSelected);
1974 // Display a message confirming if the contact should
1977 int QuestionResponse;
1979 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1981 if (QuestionResponse == wxNO){
1983 // Exit the subroutine
1989 // Delete the contact.
1991 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1993 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1998 // Remove the contact from the list.
2000 lstContacts->DeleteItem(intSelected);
2002 // Update the search windows, removing the deleted
2005 UCNotif *ucd = new UCNotif;
2007 ucd->ContactAccount = ActiveAccount;
2008 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
2010 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
2011 switer != SearchWindowList.end(); switer++){
2013 // Duplicate the event notification data.
2015 UCNotif *ucd2 = new UCNotif;
2017 ucd2->ContactAccount = ucd->ContactAccount;
2018 ucd2->ContactFilename = ucd->ContactFilename;
2020 // Pass the data to the search window for processing.
2022 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
2023 wxCommandEvent schdelete(SE_DELETERESULT);
2024 schdelete.SetClientData(ucd2);
2025 wxPostEvent(frameSCH, schdelete);
2027 // Clear up the pointer prior to variable deletion.
2034 // Clear the wxHTMLWindow.
2036 wxString EmptyPage = wxT("");
2038 htmContactData->SetPage(EmptyPage);
2040 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2042 wxString wxSplitFilename;
2043 wxString wxSDataURL;
2045 while(wSTFilename.HasMoreTokens()){
2047 wxSplitFilename = wSTFilename.GetNextToken();
2051 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2053 // Update the ETagDB and mark it as deleted.
2055 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2057 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2059 // Get the Data URL.
2061 wxTreeItemIdValue cookie;
2062 wxTreeItemId next = treAccounts->GetRootItem();
2064 wxTreeItemId selectedChild = treAccounts->GetSelection();
2065 wxTreeItemId nextChild;
2067 for (int i = 0; i < prefaccounts.GetCount(); i++){
2070 nextChild = treAccounts->GetFirstChild(next, cookie);
2072 nextChild = treAccounts->GetNextSibling(nextChild);
2075 if (nextChild == selectedChild){
2077 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2083 // Add task to the activity monitor to delete the contact.
2085 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2089 // Clear the variable. Don't delete as it will mess things up.
2091 ContactsFileIndex[intContactSeekNum] = wxT("");
2098 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2100 // Display this message when the server information has changed
2103 QRNotif *qrn = (QRNotif *)event.GetClientData();
2105 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);
2107 if (QResponse == wxNO){
2113 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2114 event2.SetInt(*qrn->QResponse);
2115 event2.SetClientData(qrn->PausePtr);
2117 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2119 wxPostEvent(frameActMgr, event2);
2123 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2125 // Remove the contact from the window after syncronising.
2127 // Check which account is currently active in the window.
2128 // If it is different from the one passed to this subroutine then
2129 // exit from the subroutine.
2131 if (Account != ActiveAccount){
2135 long longSelected = -1;
2136 int intSelectedData = 0;
2140 longSelected = lstContacts->GetNextItem(longSelected,
2142 wxLIST_STATE_DONTCARE);
2144 if (longSelected == -1){
2150 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2152 // Compare the filename with the one received.
2153 // If they match then select it.
2155 if (ContactsFileIndex[intSelectedData] == Filename){
2157 // Remove the contact from the window.
2159 lstContacts->DeleteItem(intSelectedData);
2161 // Check if contact is the selected contact in the HTML window and
2162 // if it is then clear the window.
2164 if (ActiveFilename == Filename){
2166 wxString EmptyPage = wxT("");
2167 htmContactData->SetPage(EmptyPage);
2181 void frmMain::SortFNLN( wxCommandEvent& event ) {
2183 // Sort first name then last name.
2185 wxTreeEvent NullEvent;
2187 LoadContactList(NullEvent);
2191 void frmMain::SortLNFN( wxCommandEvent& event ) {
2193 // Sort last name then first name.
2195 wxTreeEvent NullEvent;
2197 LoadContactList(NullEvent);
2201 void frmMain::SortNickname( wxCommandEvent& event ) {
2203 // Sort by nickname.
2205 wxTreeEvent NullEvent;
2207 LoadContactList(NullEvent);
2211 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2213 // Sort by Display As name.
2215 wxTreeEvent NullEvent;
2217 LoadContactList(NullEvent);
2221 void frmMain::SortAscending( wxCommandEvent& event ) {
2225 wxTreeEvent NullEvent;
2226 AscendingMode = TRUE;
2227 LoadContactList(NullEvent);
2231 void frmMain::SortDescending( wxCommandEvent& event ) {
2235 wxTreeEvent NullEvent;
2236 AscendingMode = FALSE;
2237 LoadContactList(NullEvent);
2241 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2243 // Toggle the appearance of the status bar.
2245 if (stbBottom->IsShown() == TRUE){
2259 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2261 // Display the activity icon.
2263 imgActivityStatus->SetBitmap(*imgActIcon1);
2264 ActivityIconStatus = 0;
2268 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2270 // Shuffle through the activity icons.
2272 switch (ActivityIconStatus){
2275 imgActivityStatus->SetBitmap(*imgActIcon1);
2276 ActivityIconStatus = 1;
2279 imgActivityStatus->SetBitmap(*imgActIcon2);
2280 ActivityIconStatus = 2;
2283 imgActivityStatus->SetBitmap(*imgActIcon3);
2284 ActivityIconStatus = 3;
2287 imgActivityStatus->SetBitmap(*imgActIcon4);
2288 ActivityIconStatus = 0;
2291 ActivityIconStatus = 0;
2297 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2299 // Display the sleep icon.
2301 imgActivityStatus->SetBitmap(*imgActIconSleep);
2305 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2307 // Set the placement of the status bar icons.
2309 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2317 wxRect rectActivity;
2318 stbBottom->GetFieldRect(1, rectOnline);
2319 stbBottom->GetFieldRect(2, rectSSL);
2320 stbBottom->GetFieldRect(3, rectActivity);
2322 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2323 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2324 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2328 XABViewMode frmMain::GetViewMode(){
2330 // Set the view mode of the contact list.
2334 xvm.SortMode = SortMode;
2335 xvm.AscendingMode = AscendingMode;
2341 void frmMain::WindowAdd( wxCommandEvent &event ){
2343 // Add a window to the window list.
2345 WindowData *WData = (WindowData*)event.GetClientData();
2349 if (WData->DataType == 0){
2353 int intID = mnuContactWindows->GetId();
2355 mnuWindow->FindChildItem(intID, &pos);
2356 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2357 mnuNewItem->SetId(WData->WindowID);
2358 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2359 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2360 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2361 mnuWindow->Insert((pos + 1), mnuNewItem);
2362 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2364 } else if (WData->DataType == 1){
2366 // Contact Editor Window
2368 int intID = mnuContactEditorWindows->GetId();
2370 mnuWindow->FindChildItem(intID, &pos);
2371 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2372 mnuNewItem->SetId(WData->WindowID);
2373 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2374 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2375 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2376 mnuWindow->Insert((pos + 1), mnuNewItem);
2377 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2379 } else if (WData->DataType == 2){
2383 int intID = mnuSearchWindows->GetId();
2385 mnuWindow->FindChildItem(intID, &pos);
2386 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2387 mnuNewItem->SetId(WData->WindowID);
2388 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2389 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2390 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2391 mnuWindow->Insert((pos + 1), mnuNewItem);
2392 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2401 void frmMain::WindowEdit( wxCommandEvent &event ){
2403 // Edit a window in the window list.
2405 WindowData *WData = (WindowData*)event.GetClientData();
2407 if (WData->DataType == 0){
2409 // Get the window title and use that.
2411 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2413 wxString WindowTitle = frmContactPtr->GetTitle();
2415 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2417 MenuIter->second->SetItemLabel(WindowTitle);
2419 } else if (WData->DataType == 1){
2421 // Get the window title and use that.
2423 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2425 wxString WindowTitle = frmCEPtr->GetTitle();
2427 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2429 if (WindowTitle.IsEmpty()){
2431 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2435 MenuIter->second->SetItemLabel(WindowTitle);
2446 void frmMain::WindowDelete( wxCommandEvent &event ){
2448 // Delete a window from the window list.
2450 WindowData *WData = (WindowData*)event.GetClientData();
2452 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2454 mnuWindow->Remove(MenuIter->second);
2456 delete MenuIter->second;
2457 MenuIter->second = NULL;
2459 WindowListPointersMenu.erase(WData->WindowID);
2460 WindowListPointers.erase(WData->WindowID);
2461 WindowListType.erase(WData->WindowID);
2468 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2470 // Show a contact window from the window list.
2472 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2474 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2476 frmContactPtr->Show();
2477 frmContactPtr->Raise();
2481 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2483 // Show a contact editor window from the window list.
2485 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2487 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2494 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2496 // Show a search window from the window list.
2498 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2500 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2502 frmSearchPtr->Show();
2503 frmSearchPtr->Raise();
2507 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2509 // Toggle the online/offline connection status.
2511 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2512 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2513 wxPostEvent(frameActMgr, toggconn);
2517 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2519 // Check the account type before continuing.
2521 wxString SeekAccount;
2522 wxString AccTypeLower;
2526 #if defined(__APPLE__)
2528 std::map<int, SecTrustRef>::iterator SSLTrustIter;
2530 for (int i = 0; i < prefaccounts.GetCount(); i++){
2532 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2533 AccType.Append(prefaccounts.GetAccountType(i));
2534 AccountSSL = prefaccounts.GetAccountSSL(i);
2535 AccTypeLower = AccType.MakeLower();
2536 SeekAccount.Append(wxT("."));
2537 SeekAccount.Append(AccTypeLower);
2539 if (SeekAccount == ActiveAccount){
2541 if (AccTypeLower == wxT("local")){
2547 if (AccountSSL == false){
2553 SSLTrustIter = AccountTrustData.find(i);
2555 // Setup and display the form.
2557 DisplayCertificate(SSLTrustIter->second);
2561 SeekAccount.Clear();
2562 AccTypeLower.Clear();
2567 #elif defined(__WIN32__)
2569 std::map<int, PCCERT_CONTEXT>::iterator SSLCertificateIter;
2571 for (int i = 0; i < prefaccounts.GetCount(); i++){
2573 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2574 AccType.Append(prefaccounts.GetAccountType(i));
2575 AccountSSL = prefaccounts.GetAccountSSL(i);
2576 AccTypeLower = AccType.MakeLower();
2577 SeekAccount.Append(wxT("."));
2578 SeekAccount.Append(AccTypeLower);
2580 if (SeekAccount == ActiveAccount){
2582 if (AccTypeLower == wxT("local")){
2588 if (AccountSSL == false){
2594 SSLCertificateIter = AccountCertificateData.find(i);
2596 // Setup and display the form.
2598 if (SSLCertificateIter->second->pCertInfo == NULL){
2600 wxMessageBox("No certificate information is available due to invalid connection details, connection being in progress or invalid certificate data received.");
2604 BOOL ModifiedCertificateData;
2605 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(SSLCertificateIter->second, (HWND)this->GetHandle());
2607 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
2608 wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
2613 //DisplayCertificate(SSLTrustIter->second);
2617 SeekAccount.Clear();
2618 AccTypeLower.Clear();
2625 std::map<int, SSLCertCollection>::iterator SSLColIter;
2627 for (int i = 0; i < prefaccounts.GetCount(); i++){
2629 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2630 AccType.Append(prefaccounts.GetAccountType(i));
2631 AccountSSL = prefaccounts.GetAccountSSL(i);
2632 AccTypeLower = AccType.MakeLower();
2633 SeekAccount.Append(wxT("."));
2634 SeekAccount.Append(AccTypeLower);
2636 if (SeekAccount == ActiveAccount){
2638 if (AccTypeLower == wxT("local")){
2644 if (AccountSSL == false){
2650 SSLColIter = AccountSSLData.find(i);
2652 SSLCertCollection SSLCertInfo = SSLColIter->second;
2654 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2655 frameSSLCert->StartCertFrom(0);
2656 frameSSLCert->SetupCerts(SSLCertInfo);
2657 frameSSLCert->ShowModal();
2659 delete frameSSLCert;
2660 frameSSLCert = NULL;
2664 SeekAccount.Clear();
2665 AccTypeLower.Clear();
2674 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2676 // Check the account type before continuing.
2680 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2682 // Check the account type before continuing.
2686 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2688 if (event.GetInt() == 0){
2690 imgConnStatus->SetBitmap(*imgOnline);
2694 imgConnStatus->SetBitmap(*imgOffline);
2700 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2702 // Display the form for showing an invalid SSL certificate.
2704 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2705 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2706 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2707 wxString AccountName = SSLICNObj->AccountName;
2708 frameISC->LoadData(SSLCCData, AccountName);
2709 frameISC->ShowModal();
2711 int FinalConflictResult = frameISC->GetResult();
2713 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2714 event2.SetClientData(SSLICNObj->QRNotifData);
2715 event2.SetInt(FinalConflictResult);
2720 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2721 wxPostEvent(frameActMgr, event2);
2725 void frmMain::PauseAllTimers(){
2727 // Pause all the account timers.
2729 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2730 ASTiter != AccountSyncTimers.end(); ASTiter++){
2732 ASTiter->second->Stop();
2738 void frmMain::ResumeAllTimers(){
2740 // Resume all the account timers.
2742 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2743 ASTiter != AccountSyncTimers.end(); ASTiter++){
2745 ASTiter->second->Start();
2751 #if defined(__APPLE__)
2753 #elif defined(__WIN32__)
2755 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEXT CertificateContext){
2757 // Delete existing data.
2759 std::map<int, PCCERT_CONTEXT>::iterator CertificateIter = AccountCertificateData.find(AccountID);
2761 if (CertificateIter != AccountCertificateData.end()){
2762 CertFreeCertificateContext(CertificateIter->second);
2765 AccountCertificateData.erase(AccountID);
2766 AccountSSLResult.erase(AccountID);
2770 AccountCertificateData.insert(std::make_pair(AccountID, CertificateContext));
2771 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2777 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2779 // Delete existing data.
2781 AccountSSLData.erase(AccountID);
2782 AccountSSLResult.erase(AccountID);
2786 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2787 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2793 void frmMain::SetupSSLStatus( int AccountID ){
2795 // Check if account ID given is
2796 // the active account and if not, do nothing.
2799 wxString AccTypeLower;
2801 AccType = prefaccounts.GetAccountType(AccountID);
2802 AccTypeLower = AccType.MakeLower();
2804 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2807 if (AccountIDName != ActiveAccount){
2813 // Check if the account has SSL enabled.
2815 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2817 if (SSLInUse == FALSE){
2819 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2820 imgSSLStatus->SetBitmap(*imgNoSSL);
2824 // Get the SSL Collection Data.
2826 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2828 // Check if a result value has been set.
2830 if (SSLResultIter == AccountSSLResult.end()){
2832 imgSSLStatus->SetBitmap(*imgSSLWarning);
2833 SSLToolTip->SetTip(wxT("Unable to determine SSL information for the '") + prefaccounts.GetAccountName(AccountID) + wxT("' account."));
2838 if (SSLResultIter->second == 1){
2840 imgSSLStatus->SetBitmap(*imgSSLWarning);
2841 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2842 prefaccounts.GetAccountName(AccountID) +
2843 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2845 } else if (SSLResultIter->second == 0){
2847 imgSSLStatus->SetBitmap(*imgSSL);
2848 SSLToolTip->SetTip(wxT("Account '") +
2849 prefaccounts.GetAccountName(AccountID) +
2850 wxT("' secured using SSL\n\nDouble click for more information."));
2858 void frmMain::CheckUpdates( wxCommandEvent& event ){
2860 // Check for updates to Xestia Address Book.
2862 frmUpdate *frameUpdate = new frmUpdate ( this );
2863 frameUpdate->FetchData();
2864 frameUpdate->ShowModal();
2868 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2870 // Run the import contacts function.
2876 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2878 // Check if an account and at least one contact is selected
2879 // before continuing.
2881 wxArrayString ArrData;
2883 if (ActiveAccount.IsEmpty()){
2889 int ContactSelected = 0;
2890 int ContactsCollected = 0;
2891 long longSelected = -1;
2895 longSelected = lstContacts->GetNextItem(longSelected,
2897 wxLIST_STATE_SELECTED);
2899 if (longSelected == -1){
2905 int FileID = (int)lstContacts->GetItemData(longSelected);
2907 ArrData.Insert(ContactsFileIndex[FileID],
2908 ContactsCollected, 1);
2914 if (ContactSelected == 0){
2920 // Run the export contacts system.
2922 ExportRun(this, &ArrData);
2926 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2927 wxArrayString *ContactsFileIndexPtr){
2929 // Set the list control pointers.
2931 lstContactsPtr = lstContacts;
2932 ContactsFileIndexPtr = &ContactsFileIndex;
2936 void frmMain::GetSelectedList( wxCommandEvent& event ){
2938 // Get the array of contact filenames.
2940 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2942 // Process them into an array of files.
2944 long longSelected = -1;
2945 int ContactsCollected = 0;
2946 wxString ContactFilename;
2950 longSelected = lstContacts->GetNextItem(longSelected,
2952 wxLIST_STATE_SELECTED);
2954 if (longSelected == -1){
2960 // Get the file information and add to the list.
2962 int FileID = (int)lstContacts->GetItemData(longSelected);
2964 ArrData->Insert(ContactsFileIndex[FileID],
2965 ContactsCollected, 1);
2967 ContactsCollected++;
2968 ContactFilename.Clear();
2976 void frmMain::SyncAccount( wxCommandEvent& event ){
2978 // Syncronise the selected account.
2980 wxString AccNameInc = event.GetString();
2982 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2983 frameActMgr->AddTask(3, wxT(""), AccNameInc,
2984 wxT(""), wxT(""), wxT(""), wxT(""));
2988 void frmMain::ShowHelp( wxCommandEvent& event ){
2990 // Based on the operating system, work out where
2991 // the documentation should be.
2995 #if defined(__HAIKU__)
2997 #elif defined(__WIN32__)
3003 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
3005 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
3008 #if XSDAB_RELEASE == 0
3010 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
3012 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
3021 #if XSDAB_RELEASE == 0
3023 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
3027 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!"));
3033 void frmMain::ShowImportResults( wxCommandEvent &event ){
3035 // Show the results of importing contacts.
3037 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
3039 frmImportResults *frmIR = new frmImportResults(this);
3040 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
3051 void frmMain::ReloadContactList( wxCommandEvent &event ){
3053 // Check if the account name given is the current
3054 // account selected.
3056 if (ActiveAccount == event.GetString()){
3058 wxTreeEvent NullEvent;
3059 LoadContactList(NullEvent);
3065 void frmMain::ShowContactMenu( wxMouseEvent& event ){
3067 // Show the contact menu when a right click occurs
3068 // in the contacts list.
3070 bool EnableRefresh = FALSE;
3072 if (!ActiveAccount.IsEmpty()){
3074 EnableRefresh = TRUE;
3078 ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
3080 this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
3084 void frmMain::ResetContactInfo(){
3086 // Reset the contact information to an empty page.
3088 wxString EmptyPage = wxT("");
3089 htmContactData->SetPage(EmptyPage);
3090 AccCtrl->SetValue("");