1 // frmMain.cpp - Main window form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
25 #include <wx/tokenzr.h>
27 #include <wx/mstream.h>
28 #include <wx/fs_mem.h>
30 #include <wx/filesys.h>
32 #include <wx/stdpaths.h>
33 #include <wx/fileconf.h>
34 #include <wx/gdicmn.h>
40 #include "frmPreferences.h"
41 #include "frmNewAccount.h"
42 #include "actmgr/frmActivityMgr.h"
43 #include "frmContact.h"
44 #include "frmConflictResolution.h"
45 #include "frmInvalidSSLCertificate.h"
46 #include "search/frmSearch.h"
47 #include "frmSSLCertificate.h"
48 #include "frmUpdate.h"
49 #include "import/frmImportResults.h"
52 #include "common/preferences.h"
53 #include "common/getcontactinfo.h"
54 #include "common/events.h"
55 #include "common/dirs.h"
56 #include "vcard/vcard.h"
57 #include "carddav/carddav.h"
58 #include "contacteditor/frmContactEditor.h"
59 #include "import/import.h"
60 #include "export/export.h"
61 #include "widgets/XABContactMenu.h"
62 #include "widgets/XABAccountView.h"
66 //extern const wxEventType MyHaremEvent = wxNewEventType();
68 //#define CE_UPDATECONTACTLIST 7700
69 //#define CE_UPDATEACCOUNTLIST 7701
71 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
72 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
73 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
74 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
75 DEFINE_EVENT_TYPE(CE_OPENCONTACTLIST);
76 DEFINE_EVENT_TYPE(CE_NEWCONTACT);
77 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
78 DEFINE_EVENT_TYPE(CE_DELETECONTACT);
79 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
80 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
81 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
82 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
83 DEFINE_EVENT_TYPE(ACTMGR_START);
84 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
85 DEFINE_EVENT_TYPE(ACTMGR_STOP);
86 DEFINE_EVENT_TYPE(WINDOW_ADD);
87 DEFINE_EVENT_TYPE(WINDOW_EDIT);
88 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
89 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
90 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
91 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
92 DEFINE_EVENT_TYPE(SYNCACCOUNT);
93 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
94 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
95 DEFINE_EVENT_TYPE(REFRESHADDRESSBOOK);
97 BEGIN_EVENT_TABLE(frmMain, wxFrame)
98 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
99 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
100 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
101 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
102 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
103 EVT_COMMAND(wxID_ANY, CE_OPENCONTACTLIST, frmMain::OpenContactInfoList)
104 EVT_COMMAND(wxID_ANY, CE_NEWCONTACT, frmMain::ShowContactEditorNew)
105 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
106 EVT_COMMAND(wxID_ANY, CE_DELETECONTACT, frmMain::DeleteContact)
107 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
108 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
109 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
110 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
111 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
112 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
113 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
114 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
115 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
116 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
117 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
118 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
119 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
120 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
121 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
122 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
125 frmMain::frmMain( wxWindow* parent )
130 // Setup the account icons.
132 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
133 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
134 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
135 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
137 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
138 wxBitmap AccInet(icons_accinet_png, -1);
140 wxIAccInet.CopyFromBitmap(AccInet);
142 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
143 wxBitmap AccNIcon(icons_acclocal_png, -1);
145 wxIAccNIcon.CopyFromBitmap(AccNIcon);
147 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
148 wxBitmap AccGrp(icons_accgroup_png, -1);
150 wxIAccGrp.CopyFromBitmap(AccGrp);
152 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
153 wxBitmap AccNone(icons_accnone_png, -1);
155 wxIAccNone.CopyFromBitmap(AccNone);
157 AccountID = AccImgList->Add(wxIAccNIcon);
158 AccountNetID = AccImgList->Add(wxIAccInet);
159 AccountGrpID = AccImgList->Add(wxIAccGrp);
160 AccountNoneID = AccImgList->Add(wxIAccNone);
162 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
164 // Setup the status bar icons.
168 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
169 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
170 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
172 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
173 imgSSL = new wxBitmap(icons_ssl_png, -1);
175 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
176 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
178 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
179 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
183 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
184 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
185 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
186 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
187 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
189 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
190 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
192 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
193 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
195 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
197 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
198 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
200 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
202 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
203 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
205 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
207 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
208 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
210 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
212 // Online/Offline icons.
214 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
215 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
217 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
218 imgOnline = new wxBitmap(icons_online_png, -1);
220 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
221 imgOffline = new wxBitmap(icons_offline_png, -1);
223 // Setup the account view.
225 AccCtrl->SetPopupControl(treAccounts);
226 AccCtrl->SetPopupMaxHeight(175);
227 AccCtrl->SetPopupMinWidth(250);
228 treAccounts->AssignImageList(AccImgList);
230 wxListItem ColumnData;
232 ColumnData.SetText(wxT("Name0"));
233 ColumnData.SetWidth(320);
234 lstContacts->InsertColumn(0, ColumnData);
236 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
237 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
239 #if defined(__HAIKU__)
241 #elif defined(__WIN32__)
243 int stbBottomData [4] = { -1, 8, 8, 8 };
247 int stbBottomData [4] = { -1, 20, 20, 20 };
251 stbBottom->SetFieldsCount(4, stbBottomData);
252 stbBottom->SetMinHeight(16);
257 stbBottom->GetFieldRect(1, rectOnline);
258 stbBottom->GetFieldRect(2, rectSSL);
259 stbBottom->GetFieldRect(3, rectActivity);
261 SSLToolTip = new wxToolTip(wxT(""));
263 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
264 imgConnStatus->SetBitmap(*imgOnline);
265 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
267 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
268 imgSSLStatus->SetBitmap(*imgNoSSL);
269 imgSSLStatus->SetToolTip(SSLToolTip);
270 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
272 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
273 imgActivityStatus->SetBitmap(*imgActIconSleep);
274 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
276 // Setup the window menu.
278 // By default should be:
283 // Contact editor windows:
289 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
290 mnuWindow->Append( mnuContactWindows );
292 mnuWindow->AppendSeparator();
294 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
295 mnuWindow->Append( mnuContactEditorWindows );
297 mnuWindow->AppendSeparator();
299 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
300 mnuWindow->Append( mnuSearchWindows );
302 #if defined(__WIN32__)
307 mnuContactWindows->SetFont(fontstyle);
308 mnuContactEditorWindows->SetFont(fontstyle);
309 mnuSearchWindows->SetFont(fontstyle);
313 mnuContactWindows->Enable(FALSE);
314 mnuContactEditorWindows->Enable(FALSE);
315 mnuSearchWindows->Enable(FALSE);
319 // Hide unimplemented functions.
325 void frmMain::QuitApp( wxCloseEvent& event )
332 void frmMain::QuitApp( wxCommandEvent& event )
339 void frmMain::QuitApp()
341 //-------------------------------------------------------------------
342 // frmMain::QuitApp: Quits the application by simply closing this
343 // window which causes the exit as frmMain is the main window.
345 // wxCommandEvent Accepts a referenced event command.
346 //-------------------------------------------------------------------
348 //-------------------------------------------------------------------
349 // frmMain::QuitApp: Quits the application by simply closing this
350 // window which causes the exit as frmMain is the main window.
352 // wxCommandEvent Accepts a referenced event command.
353 //-------------------------------------------------------------------
355 //Go through the windows and close each one (be it search
356 //or contact editor). Abort if user wants to cancel.
358 // Close the contact editor windows.
360 // Close the contact windows.
362 // Close the search windows.
364 // Write out the ETag databases.
366 // Save Preferences: Save the window position if that option is enabled.
368 wxString SetFilename = GetUserPrefDir();
370 #if defined(__HAIKU__)
374 #elif defined(__WIN32__)
376 SetFilename.Append(wxT("settings"));
382 SetFilename.Append(wxT("settings"));
386 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
388 bool SaveWindowPos = FALSE;
389 wxString SaveWindowInc;
390 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
392 if (SaveWindowInc == wxT("true")){
394 SaveWindowPos = TRUE;
398 if (SaveWindowPos == TRUE){
400 wxRect frmMainPos = this->GetRect();
402 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
403 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
404 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
405 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
413 //Everything closed... exit.
421 void frmMain::ShowActivityWindow( wxCommandEvent& event )
424 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
425 frameActMgr->OpenWindow();
430 void frmMain::ShowAboutWindow( wxCommandEvent& event )
432 //-------------------------------------------------------------------
433 // frmMain::ShowAboutWindow: Shows the About window as a modal
434 // dialog and then cleans up when finished.
436 // wxCommandEvent Accepts a referenced event command.
437 //-------------------------------------------------------------------
439 frmAbout *frameAbout = new frmAbout ( this );
440 frameAbout->SetupAboutWindow();
441 frameAbout->ShowModal();
447 void frmMain::OpenPreferences( wxCommandEvent& event)
449 //-------------------------------------------------------------------
450 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
451 // dialog and then cleans up when finished.
453 // wxCommandEvent Accepts a referenced event command.
454 //-------------------------------------------------------------------
456 ReloadAccounts = FALSE;
458 frmPreferences *framePreferences = new frmPreferences ( this );
459 framePreferences->SetupPointers(&ReloadAccounts);
460 framePreferences->ShowModal();
461 delete framePreferences;
462 framePreferences = NULL;
464 if (ReloadAccounts == TRUE){
466 // Reload the accounts as a change has been made within
467 // the application and clear the current contact information.
469 this->LoadPreferences();
470 this->ResetContactInfo();
476 void frmMain::OpenNewABDialog( wxCommandEvent& event)
478 //-------------------------------------------------------------------
479 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
480 // dialog and then cleans up when finished.
482 // wxCommandEvent Accepts a referenced event command.
483 //-------------------------------------------------------------------
485 ReloadAccounts = FALSE;
487 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
488 frameNewAccount->SetupPointers(&ReloadAccounts);
489 frameNewAccount->ShowModal();
490 delete frameNewAccount;
491 frameNewAccount = NULL;
493 if (ReloadAccounts == TRUE){
495 // Reload the accounts as a change has been made within
498 this->LoadPreferences();
504 void frmMain::LoadContactList( wxTreeEvent& event )
507 // Clear all existing variables.
509 lstContacts->DeleteAllItems();
511 treAccounts->SetAccount();
513 wxTreeItemIdValue cookie;
514 wxTreeItemId next = treAccounts->GetRootItem();
515 wxString AccountName;
516 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
517 wxString AccountDirCmb;
518 long selectedaccount = 0;
520 wxTreeItemId selectedChild = treAccounts->GetSelection();
521 wxTreeItemId nextChild;
523 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
524 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
526 int SCImg = treAccounts->GetItemImage(selectedChild);
527 int AccountIndex = 0;
529 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
531 for (int i = 0; i < prefaccounts.GetCount(); i++){
533 if (ActiveItemIcon == 2){
535 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
536 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
537 int ActiveAccountG = AGLiter->second;
539 if (i == ActiveAccountG){
541 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
542 AccountType.Append(prefaccounts.GetAccountType(i));
547 if (AccountType == wxT("CardDAV")){
548 AccountTypeFinal.Append(wxT("carddav"));
550 else if (AccountType == wxT("Local")){
551 imgSSLStatus->SetBitmap(*imgOffline);
552 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
553 AccountTypeFinal.Append(wxT("local"));
564 nextChild = treAccounts->GetFirstChild(next, cookie);
567 nextChild = treAccounts->GetNextSibling(nextChild);
570 AccountName = treAccounts->GetItemText(nextChild);
572 if (nextChild == selectedChild){
573 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
574 AccountType.Append(prefaccounts.GetAccountType(i));
579 if (AccountType == wxT("CardDAV")){
580 AccountTypeFinal.Append(wxT("carddav"));
582 else if (AccountType == wxT("Local")){
583 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
584 AccountTypeFinal.Append(wxT("local"));
593 if (selectedaccount >= prefaccounts.GetCount()){
595 // The account selected isn't there so return.
603 // Open the directory and get the list of .vcf files
604 // in that directory.
606 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
607 ActiveAccountType = AccountType;
609 SetupSSLStatus(AccountIndex);
611 AccountDirFinal.Clear();
612 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
614 ContactsFileIndex.Clear();
616 wxString vCardFilename;
617 wxString vCardFilenameFull;
618 wxString vCardDataString;
619 wxStringTokenizer vcardfileline;
621 wxString setname, setvalue;
622 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
623 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
624 long ContactIndex = 1;
625 long ContactSeekPoint = 0;
627 wxDir vcardaccdir(AccountDirFinal);
629 // Get the wxTreeItemId and image icon and compare it to the list.
631 if (ActiveItemIcon == AccountGrpID){
633 // It's a group so load the file containing the group and
634 // get the members of the group.
639 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
640 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
642 Group.LoadFile(AGFiter->second);
644 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
646 for (int i = 0; i < vCardMember.PropCount; i++){
648 vCardMember.PropValues[i].Trim();
649 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
651 wxString NewPropValue;
652 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
653 vCardMember.PropValues[i] = NewPropValue;
660 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
663 if (vCardFilename.Right(4) == wxT(".vcf") ||
664 vCardFilename.Right(4) == wxT(".VCF") ||
665 vCardFilename.Right(5) == wxT(".vcard") ||
666 vCardFilename.Right(5) == wxT(".VCARD")){
669 bool FoundMember = FALSE;
671 vCardFilenameFull.Append(AccountDirFinal);
672 vCardFilenameFull.Append(wxT("/"));
673 vCardFilenameFull.Append(vCardFilename);
675 Person.LoadFile(vCardFilenameFull);
677 UIDCode = Person.Get(wxT("UID"));
679 for (int i = 0; i < vCardMember.PropCount; i++){
681 if (vCardMember.PropValues[i] == UIDCode){
689 if (FoundMember == FALSE){
691 vCardFilename.Clear();
692 vCardFilenameFull.Clear();
693 vCardDataString.Clear();
694 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
699 if (Person.MeetBaseSpecification()){
703 // Split the name into sections.
705 vCardDataString = Person.Get(wxT("N"));
707 vCardName NameData = Person.GetName();
709 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
711 } else if (SortMode == 2){
713 // Split the name into sections.
715 vCardName NameData = Person.GetName();
717 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
719 } else if (SortMode == 3){
721 // Check and make sure that the top most nickname is used.
723 vCardDataString = Person.Get(wxT("NICKNAME"));
725 if (vCardDataString.IsEmpty()){
727 vCardDataString = wxT("(no nickname)");
731 } else if (SortMode == 4){
733 vCardDataString = Person.Get(wxT("FN"));
737 if (AscendingMode == TRUE){
738 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
740 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
749 vCardFilename.Clear();
750 vCardFilenameFull.Clear();
751 vCardDataString.Clear();
752 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
757 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
760 if (vCardFilename.Right(4) == wxT(".vcf") ||
761 vCardFilename.Right(4) == wxT(".VCF") ||
762 vCardFilename.Right(5) == wxT(".vcard") ||
763 vCardFilename.Right(5) == wxT(".VCARD")){
767 vCardFilenameFull.Append(AccountDirFinal);
768 vCardFilenameFull.Append(vCardFilename);
770 Person.LoadFile(vCardFilenameFull);
772 if (Person.MeetBaseSpecification()){
776 // Split the name into sections.
778 vCardDataString = Person.Get(wxT("N"));
780 vCardName NameData = Person.GetName();
782 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
784 } else if (SortMode == 2){
786 // Split the name into sections.
788 vCardName NameData = Person.GetName();
790 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
792 } else if (SortMode == 3){
794 // Check and make sure that the top most nickname is used.
796 vCardDataString = Person.Get(wxT("NICKNAME"));
798 if (vCardDataString.IsEmpty()){
800 vCardDataString = wxT("(no nickname)");
804 } else if (SortMode == 4){
806 vCardDataString = Person.Get(wxT("FN"));
810 if (AscendingMode == TRUE){
811 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
813 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
822 vCardFilename.Clear();
823 vCardFilenameFull.Clear();
824 vCardDataString.Clear();
825 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
832 // Insert the data into the control.
834 if (AscendingMode == TRUE){
835 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
836 iter != vCardNamesAsc.end(); ++iter){
838 wxListItem ContactInfo;
840 ContactInfo.SetId(0);
841 ContactInfo.SetText(_("Mooo"));
842 ContactInfo.SetData(ContactSeekPoint);
843 ContactIndex = lstContacts->InsertItem(ContactInfo);
845 lstContacts->SetItem(ContactIndex, 0, iter->first);
846 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
853 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
854 iter != vCardNamesDsc.end(); ++iter){
856 wxListItem ContactInfo;
858 ContactInfo.SetId(0);
859 ContactInfo.SetText(_("Mooo"));
860 ContactInfo.SetData(ContactSeekPoint);
861 ContactIndex = lstContacts->InsertItem(ContactInfo);
863 lstContacts->SetItem(ContactIndex, 0, iter->first);
864 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
873 void frmMain::ShowContactInfo( wxListEvent& event )
876 long intSelected = -1;
877 long ContactSeekNum = -1;
879 // Check if several contacts have been selected.
881 int ContactTotal = 0;
885 intSelected = lstContacts->GetNextItem(intSelected,
887 wxLIST_STATE_SELECTED);
889 if (intSelected == -1){
899 if (ContactTotal == 0){
900 htmContactData->SetPage(wxT(""));
904 if (ContactTotal > 1){
906 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
907 ActiveFilename.Clear();
912 intSelected = lstContacts->GetNextItem(intSelected,
914 wxLIST_STATE_SELECTED);
916 ContactSeekNum = lstContacts->GetItemData(intSelected);
919 wxString wxSContactString;
920 wxString ContactLine;
923 size_t ContactLineLen;
924 bool ExtraLineSeek = FALSE;
925 int QuoteBreakPoint = 0;
927 bool PropertyFind = FALSE;
928 bool QuoteMode = FALSE;
930 wxString wxSPropertyNextLine;
931 wxString wxSProperty;
932 wxString wxSPropertySeg1;
933 wxString wxSPropertySeg2;
935 // Check if we are using wxWidgets version 2.8 or less and
936 // execute the required command accordingly.
938 #if wxABI_VERSION < 20900
939 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
941 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
944 if (ContactFile.IsOpened() == FALSE){
950 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
954 std::map<int, wxString> ContactFileLines;
955 std::map<int, wxString>::iterator striter;
957 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
959 int ContactLineSeek = 0;
961 while (wSTContactFileLines.HasMoreTokens() == TRUE){
963 ContactLine = wSTContactFileLines.GetNextToken();
964 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
969 if (ContactSeekNum < 0){
973 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
974 iter != ContactFileLines.end(); ++iter){
976 // Find the colon which splits the start bit from the data part.
978 ContactLine = iter->second;
980 while (ExtraLineSeek == TRUE){
982 // Check if there is extra data on the next line
983 // (indicated by space or tab at the start) and add data.
987 if (iter == ContactFileLines.end()){
994 wxSPropertyNextLine = iter->second;
997 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
999 wxSPropertyNextLine.Remove(0, 1);
1000 ContactLine.Append(wxSPropertyNextLine);
1005 ExtraLineSeek = FALSE;
1011 ContactLineLen = ContactLine.Len();
1013 // Make sure we are not in quotation mode.
1014 // Make sure colon does not have \ or \\ before it.
1016 for (int i = 0; i <= ContactLineLen; i++){
1018 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1020 PropertyFind = FALSE;
1022 } else if (PropertyFind == TRUE){
1024 wxSProperty.Append(ContactLine.Mid(i, 1));
1028 if (ContactLine.Mid(i, 1) == wxT("\"")){
1030 if (QuoteMode == TRUE){
1042 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1044 QuoteBreakPoint = i;
1051 // Split that line at the point into two variables (ignore the colon).
1053 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1054 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1056 // Insert both into the vCard data file.
1058 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1061 PropertyFind = TRUE;
1062 ExtraLineSeek = TRUE;
1064 QuoteBreakPoint = 0;
1065 ContactLine.Clear();
1066 wxSProperty.Clear();
1070 OldSessionID = SessionID;
1071 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1072 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1073 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1077 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1080 // Check if there is an account selected and if not
1081 // return immediately.
1083 if (ActiveAccount.IsEmpty()){
1089 // Add Pointer to SetupPointers for the ETagDB.
1091 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1092 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1093 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1095 contacticon.CopyFromBitmap(contacticonbmp);
1097 frmContactEditor *ContactEditor = new frmContactEditor( this );
1101 ContactEditor->SetUID(WindowMenuItemID);
1103 WindowData *WData = new WindowData;
1105 WData->DataType = 1;
1106 WData->WindowPointer = (void*)ContactEditor;
1107 WData->WindowID = WindowMenuItemID;
1109 wxCommandEvent addevent(WINDOW_ADD);
1110 addevent.SetClientData(WData);
1111 wxPostEvent(this, addevent);
1113 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1114 ContactEditor->SetupHeaders();
1115 ContactEditor->SetupContact(ActiveAccount);
1116 ContactEditor->SetIcon(contacticon);
1117 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1118 ContactEditor->Show(true);
1122 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1125 // Check if there is an account selected and if not
1126 // return immediately.
1128 int DataCheck = event.GetInt();
1130 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1136 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1137 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1138 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1140 contacticon.CopyFromBitmap(contacticonbmp);
1142 // Check if a contact has been selected.
1144 long intSelected = -1;
1145 long intContactSeekNum = -1;
1147 intSelected = lstContacts->GetNextItem(intSelected,
1149 wxLIST_STATE_SELECTED);
1151 if (intSelected == -1){
1155 intContactSeekNum = lstContacts->GetItemData(intSelected);
1157 // Get the filename of the selected contact.
1159 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1160 frmContactEditor *ContactEditor = new frmContactEditor( this );
1164 ContactEditor->SetUID(WindowMenuItemID);
1166 WindowData *WData = new WindowData;
1168 WData->DataType = 1;
1169 WData->WindowPointer = (void*)ContactEditor;
1170 WData->WindowID = WindowMenuItemID;
1172 wxCommandEvent addevent(WINDOW_ADD);
1173 addevent.SetClientData(WData);
1174 wxPostEvent(this, addevent);
1176 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1177 ContactEditor->SetupHeaders();
1179 // Check if pointer is NULL (not from the search forms) or not.
1181 if (DataCheck == 0){
1183 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1184 ContactEditor->SetupContact(ActiveAccount);
1188 UCNotif *uc = (UCNotif*)event.GetClientData();
1192 ContactEditor->SetupContact(ActiveAccount);
1193 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1197 ContactEditor->SetupContact(uc->ContactAccount);
1198 ContactEditor->LoadContact(uc->ContactFilename);
1208 ContactEditor->SetIcon(contacticon);
1209 ContactEditor->Show(true);
1213 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1215 // Check if ActiveAccount is empty. If not then check if
1216 // account type is not local otherwise continue.
1218 if (!ActiveAccount.IsEmpty()){
1220 if (ActiveAccountType != wxT("Local")){
1222 // Account type is not local.
1224 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1225 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1226 wxT(""), wxT(""), wxT(""), wxT(""));
1230 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1238 void frmMain::OpenContactInfoList( wxListEvent& event )
1241 wxStringTokenizer vcardfileline;
1244 wxString setname, setvalue;
1248 long intSelected = -1;
1249 long intContactSeekNum = -1;
1251 intSelected = lstContacts->GetNextItem(intSelected,
1253 wxLIST_STATE_SELECTED);
1255 intContactSeekNum = lstContacts->GetItemData(intSelected);
1257 if (intContactSeekNum == -1){
1261 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1263 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1264 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1265 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1267 contacticon.CopyFromBitmap(contacticonbmp);
1269 frmContact *Contact = new frmContact( this );
1271 // Add to window list.
1275 Contact->SetUID(WindowMenuItemID);
1277 WindowData *WData = new WindowData;
1279 WData->DataType = 0;
1280 WData->WindowPointer = (void*)Contact;
1281 WData->WindowID = WindowMenuItemID;
1283 wxCommandEvent addevent(WINDOW_ADD);
1284 addevent.SetClientData(WData);
1285 wxPostEvent(this, addevent);
1287 Contact->SetupPointers(&MemoryFileList);
1288 Contact->SetupContactData(&Person);
1290 Contact->SetIcon(contacticon);
1291 Contact->Show(true);
1295 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1298 OpenContactInfoList(pevent);
1302 void frmMain::OpenContactInfo( wxCommandEvent& event )
1305 UCNotif *uc = (UCNotif*)event.GetClientData();
1307 wxStringTokenizer vcardfileline;
1310 wxString setname, setvalue;
1314 Person.LoadFile(uc->ContactFilename);
1316 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1317 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1318 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1320 contacticon.CopyFromBitmap(contacticonbmp);
1322 frmContact *Contact = new frmContact( this );
1324 // Add to window list.
1328 Contact->SetUID(WindowMenuItemID);
1330 WindowData *WData = new WindowData;
1332 WData->DataType = 0;
1333 WData->WindowPointer = (void*)Contact;
1334 WData->WindowID = WindowMenuItemID;
1336 wxCommandEvent addevent(WINDOW_ADD);
1337 addevent.SetClientData(WData);
1338 wxPostEvent(this, addevent);
1340 Contact->SetupPointers(&MemoryFileList);
1341 Contact->SetupContactData(&Person);
1343 Contact->SetIcon(contacticon);
1344 Contact->Show(true);
1349 void frmMain::LoadPreferences( wxActivateEvent& event)
1351 this->LoadPreferences();
1354 void frmMain::LoadPreferences(){
1356 // Load the preferences.
1358 wxString preffilename = GetUserPrefDir();
1360 XABPreferences preferences(preffilename);
1362 // Setup the main window position (if needed).
1364 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1365 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1367 if (SaveWindowPos == TRUE){
1369 this->SetSize(preferences.GetMainWindowData());
1373 treAccounts->DeleteAllItems();
1375 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1377 // Stop all account timers and remove the accounts.
1379 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1380 iter != AccountSyncTimers.end(); iter++){
1382 wxAccountSyncTimer *AccTmrPtr = iter->second;
1390 AccountSyncTimers.clear();
1393 wxString AccDirFull;
1394 wxString AccDirFullSfx;
1396 wxString AccDirFinal;
1397 AccountAccDirList.clear();
1398 AccountGroupList.clear();
1399 AccountGroupFilename.clear();
1400 AccountGroupTreeId.clear();
1401 wxTreeItemId AccountTreeId;
1402 wxTreeItemId GroupTreeId;
1405 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1407 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1408 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1414 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1420 AccDir = preferences.accounts.GetAccountDirectory(i);
1421 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1423 AccDirFull.Append(wxT("."));
1424 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1425 AccDirFullSfx.LowerCase();
1426 AccDirFullSfx.Trim();
1427 AccDirFull.Append(AccDirFullSfx);
1428 AccName = preferences.accounts.GetAccountName(i);
1430 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1432 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1433 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1435 // TODO: Check if the directory exists before doing anything.
1439 // Add a new timer using the existing account details.
1441 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1443 ActTmrPtr->SetupData(AccDirFull, AccName);
1444 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1445 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1446 ActTmrPtr->SetOwner(this);
1447 ActTmrPtr->Notify();
1449 // Add the timer to the list of timers.
1451 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1453 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1457 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1461 // Go through the account directory and find contact files with
1462 // 'KIND:group' set and add them to the list of groups for the account.
1464 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1466 wxDir vcardaccdir(AccDirFinal);
1468 wxString vCardFilename;
1469 wxString vCardDataString;
1470 wxString vCardFilenameFull;
1472 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1475 if (vCardFilename.Right(4) == wxT(".vcf") ||
1476 vCardFilename.Right(4) == wxT(".VCF") ||
1477 vCardFilename.Right(5) == wxT(".vcard") ||
1478 vCardFilename.Right(5) == wxT(".VCARD")){
1482 vCardFilenameFull.Append(AccDirFinal);
1483 vCardFilenameFull.Append(wxT("/"));
1484 vCardFilenameFull.Append(vCardFilename);
1486 Person.LoadFile(vCardFilenameFull);
1488 if (Person.MeetBaseSpecification()){
1490 vCardDataString = Person.Get(wxT("KIND"));
1492 if (vCardDataString == wxT("group")){
1494 // The vCard kind is a group. Add to the account's group list.
1496 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1497 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1498 AccountGroupList.insert(std::make_pair(intGroupID, i));
1499 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1500 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1512 vCardFilename.Clear();
1513 vCardFilenameFull.Clear();
1514 vCardDataString.Clear();
1515 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1519 // Clearup for next account.
1523 AccDirFullSfx.clear();
1524 AccDirFinal.clear();
1529 // Load the account settings as they are needed for connecting
1532 prefaccounts = preferences.accounts;
1536 void frmMain::ConflictResolution(wxCommandEvent& event){
1538 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1539 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1540 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1541 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1542 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1543 frameCR->ShowModal();
1545 int FinalConflictResult = frameCR->GetResult();
1547 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1548 event2.SetClientData(vCardConfObj->QRNotifData);
1549 event2.SetInt(FinalConflictResult);
1554 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1555 wxPostEvent(frameActMgr, event2);
1559 void frmMain::UpdateContactList(wxCommandEvent& event){
1561 UCNotif *ucd = (UCNotif*)event.GetClientData();
1563 // Check if the active account is being displayed in the
1564 // main window. If not, skip and delete the data.
1566 long longSelected = -1;
1567 int intSelectedData = 0;
1569 if (ActiveAccount == ucd->ContactAccount){
1571 // Look at the list of contacts and if it matches the
1572 // filename then update the name.
1576 longSelected = lstContacts->GetNextItem(longSelected,
1578 wxLIST_STATE_DONTCARE);
1580 if (longSelected == -1){
1586 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1588 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1590 // Work out which sorting mode we are in.
1594 // First Name, Last Name.
1596 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1598 } else if (SortMode == 2){
1600 // Last Name, First Name.
1602 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1604 } else if (SortMode == 3){
1608 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1610 } else if (SortMode == 4){
1614 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1621 // If the filename is the one loaded into the
1622 // browser control, then update this too.
1624 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1626 wxListEvent nullevent;
1627 ShowContactInfo(nullevent);
1635 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1636 WindowIter != WindowListPointers.end(); WindowIter++){
1638 if (WindowListType[WindowIter->first] != 0){
1644 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1646 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1648 vCard UpdatedPerson;
1649 UpdatedPerson.LoadFile(ucd->ContactFilename);
1650 frmContactPtr->SetupContactData(&UpdatedPerson);
1656 // Send message to search window controller subroutine and
1657 // pass that notification onto the search windows.
1659 // Setup the new pointer to use the existing UCNotif without
1662 UCNotif *ucd2 = ucd;
1664 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1665 sup.SetClientData(ucd2);
1666 wxPostEvent(this, sup);
1668 // Clear up the unused pointer.
1674 void frmMain::UpdateAccountList(wxCommandEvent& event){
1678 void frmMain::SetupPointers(void *ActMgrPtrInc){
1680 ActMgrPtr = ActMgrPtrInc;
1684 void frmMain::SetupForm(){
1686 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1687 frameActMgr->SetupPointers(&ETagProcTimer, this);
1689 // Setup the contact information icons for later.
1691 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1695 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1696 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1697 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1699 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1700 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1701 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1703 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1704 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1705 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1707 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1708 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1709 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1711 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1712 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1713 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1715 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1716 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1717 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1723 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1725 // Go through each of the search windows and
1726 // send the required notification to update the
1727 // contact information.
1729 // Get the event notification data.
1731 UCNotif *ucd = (UCNotif*)event.GetClientData();
1733 // Process each search window giving the new details.
1735 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1736 switer != SearchWindowList.end(); switer++){
1738 // Duplicate the event notification data.
1740 UCNotif *ucd2 = new UCNotif;
1742 ucd2->ContactAccount = ucd->ContactAccount;
1743 ucd2->ContactFilename = ucd->ContactFilename;
1744 ucd2->ContactName = ucd->ContactName;
1745 ucd2->ContactNickname = ucd->ContactNickname;
1746 ucd2->ContactNameArray = ucd->ContactNameArray;
1748 // Pass the data to the search window for processing.
1750 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1751 wxCommandEvent schupdate(SE_UPDATERESULT);
1752 schupdate.SetClientData(ucd2);
1753 wxPostEvent(frameSCH, schupdate);
1755 // Clear up the pointer prior to variable deletion.
1766 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1770 frmSearch *frameSCH = new frmSearch ( this );
1771 frameSCH->SetUID(WindowMenuItemID);
1772 frameSCH->Show(true);
1774 WindowData *WData = new WindowData;
1776 WData->DataType = 2;
1777 WData->WindowPointer = (void*)frameSCH;
1778 WData->WindowID = WindowMenuItemID;
1780 wxCommandEvent addevent(WINDOW_ADD);
1781 addevent.SetClientData(WData);
1782 wxPostEvent(this, addevent);
1784 // Add pointer to the list of open search windows.
1786 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1792 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1794 void *frameSCH = (void*)event.GetClientData();
1796 SearchWindowList.erase(frameSCH);
1802 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1804 void *frameSCH = (void*)event.GetClientData();
1806 SearchWindowList.erase(frameSCH);
1812 void frmMain::RevealContact(wxCommandEvent& event){
1814 UCNotif *uc = (UCNotif*)event.GetClientData();
1816 // Switch the account to the one passed.
1818 wxTreeItemIdValue cookie;
1819 wxTreeItemId next = treAccounts->GetRootItem();
1820 wxTreeItemId nextChild;
1822 for (int i = 0; i < prefaccounts.GetCount(); i++){
1825 nextChild = treAccounts->GetFirstChild(next, cookie);
1827 nextChild = treAccounts->GetNextSibling(nextChild);
1830 //AccountName = treAccounts->GetItemText(nextChild);
1832 if (uc->ContactAccount == AccountAccDirList[i]){
1835 treAccounts->SelectItem(nextChild, TRUE);
1836 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1842 // Switch the contact to the one passed.
1844 long longSelected = -1;
1845 int intSelectedData = 0;
1849 longSelected = lstContacts->GetNextItem(longSelected,
1851 wxLIST_STATE_DONTCARE);
1853 if (longSelected == -1){
1859 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1861 // Compare the filename with the one received.
1862 // If they match then select it.
1864 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1868 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1869 lstContacts->EnsureVisible(longSelected);
1873 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1881 void frmMain::DeleteContact(wxCommandEvent& event){
1883 // Check if a contact is selected.
1885 long intSelected = -1;
1886 long intContactSeekNum = -1;
1887 wxString wxSContactName;
1889 intSelected = lstContacts->GetNextItem(intSelected,
1891 wxLIST_STATE_SELECTED);
1893 if (intSelected == -1){
1897 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1899 // Get the item data of the contact.
1901 intContactSeekNum = lstContacts->GetItemData(intSelected);
1903 // Get the name of the contact.
1905 wxSContactName = lstContacts->GetItemText(intSelected);
1907 // Display a message confirming if the contact should
1910 int QuestionResponse;
1912 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1914 if (QuestionResponse == wxNO){
1916 // Exit the subroutine
1922 // Delete the contact.
1924 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1926 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1931 // Remove the contact from the list.
1933 lstContacts->DeleteItem(intSelected);
1935 // Update the search windows, removing the deleted
1938 UCNotif *ucd = new UCNotif;
1940 ucd->ContactAccount = ActiveAccount;
1941 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1943 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1944 switer != SearchWindowList.end(); switer++){
1946 // Duplicate the event notification data.
1948 UCNotif *ucd2 = new UCNotif;
1950 ucd2->ContactAccount = ucd->ContactAccount;
1951 ucd2->ContactFilename = ucd->ContactFilename;
1953 // Pass the data to the search window for processing.
1955 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1956 wxCommandEvent schdelete(SE_DELETERESULT);
1957 schdelete.SetClientData(ucd2);
1958 wxPostEvent(frameSCH, schdelete);
1960 // Clear up the pointer prior to variable deletion.
1967 // Clear the wxHTMLWindow.
1969 wxString EmptyPage = wxT("");
1971 htmContactData->SetPage(EmptyPage);
1973 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
1975 wxString wxSplitFilename;
1976 wxString wxSDataURL;
1978 while(wSTFilename.HasMoreTokens()){
1980 wxSplitFilename = wSTFilename.GetNextToken();
1984 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
1986 // Update the ETagDB and mark it as deleted.
1988 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
1990 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
1992 // Get the Data URL.
1994 wxTreeItemIdValue cookie;
1995 wxTreeItemId next = treAccounts->GetRootItem();
1997 wxTreeItemId selectedChild = treAccounts->GetSelection();
1998 wxTreeItemId nextChild;
2000 for (int i = 0; i < prefaccounts.GetCount(); i++){
2003 nextChild = treAccounts->GetFirstChild(next, cookie);
2006 nextChild = treAccounts->GetNextSibling(nextChild);
2009 if (nextChild == selectedChild){
2010 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2016 // Add task to the activity monitor to delete the contact.
2018 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2022 // Clear the variable. Don't delete as it will mess things up.
2024 ContactsFileIndex[intContactSeekNum] = wxT("");
2031 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2033 QRNotif *qrn = (QRNotif *)event.GetClientData();
2035 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);
2037 if (QResponse == wxNO){
2043 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2044 event2.SetInt(*qrn->QResponse);
2045 event2.SetClientData(qrn->PausePtr);
2047 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2049 wxPostEvent(frameActMgr, event2);
2053 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2055 // Remove the contact from the window after syncronising.
2057 // Check which account is currently active in the window.
2058 // If it is different from the one passed to this subroutine then
2059 // exit from the subroutine.
2061 if (Account != ActiveAccount){
2065 long longSelected = -1;
2066 int intSelectedData = 0;
2070 longSelected = lstContacts->GetNextItem(longSelected,
2072 wxLIST_STATE_DONTCARE);
2074 if (longSelected == -1){
2080 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2082 // Compare the filename with the one received.
2083 // If they match then select it.
2085 if (ContactsFileIndex[intSelectedData] == Filename){
2087 // Remove the contact from the window.
2089 lstContacts->DeleteItem(intSelectedData);
2091 // Check if contact is the selected contact in the HTML window and
2092 // if it is then clear the window.
2094 if (ActiveFilename == Filename){
2096 wxString EmptyPage = wxT("");
2097 htmContactData->SetPage(EmptyPage);
2111 void frmMain::SortFNLN( wxCommandEvent& event ) {
2113 wxTreeEvent NullEvent;
2115 LoadContactList(NullEvent);
2119 void frmMain::SortLNFN( wxCommandEvent& event ) {
2121 wxTreeEvent NullEvent;
2123 LoadContactList(NullEvent);
2127 void frmMain::SortNickname( wxCommandEvent& event ) {
2129 wxTreeEvent NullEvent;
2131 LoadContactList(NullEvent);
2135 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2137 wxTreeEvent NullEvent;
2139 LoadContactList(NullEvent);
2143 void frmMain::SortAscending( wxCommandEvent& event ) {
2145 wxTreeEvent NullEvent;
2146 AscendingMode = TRUE;
2147 LoadContactList(NullEvent);
2151 void frmMain::SortDescending( wxCommandEvent& event ) {
2153 wxTreeEvent NullEvent;
2154 AscendingMode = FALSE;
2155 LoadContactList(NullEvent);
2159 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2161 if (stbBottom->IsShown() == TRUE){
2175 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2177 // Display the activity icon.
2179 imgActivityStatus->SetBitmap(*imgActIcon1);
2180 ActivityIconStatus = 0;
2184 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2186 switch (ActivityIconStatus){
2189 imgActivityStatus->SetBitmap(*imgActIcon1);
2190 ActivityIconStatus = 1;
2193 imgActivityStatus->SetBitmap(*imgActIcon2);
2194 ActivityIconStatus = 2;
2197 imgActivityStatus->SetBitmap(*imgActIcon3);
2198 ActivityIconStatus = 3;
2201 imgActivityStatus->SetBitmap(*imgActIcon4);
2202 ActivityIconStatus = 0;
2205 ActivityIconStatus = 0;
2211 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2213 // Display the sleep icon.
2215 imgActivityStatus->SetBitmap(*imgActIconSleep);
2219 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2221 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2229 wxRect rectActivity;
2230 stbBottom->GetFieldRect(1, rectOnline);
2231 stbBottom->GetFieldRect(2, rectSSL);
2232 stbBottom->GetFieldRect(3, rectActivity);
2234 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2235 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2236 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2240 XABViewMode frmMain::GetViewMode(){
2244 xvm.SortMode = SortMode;
2245 xvm.AscendingMode = AscendingMode;
2251 void frmMain::WindowAdd( wxCommandEvent &event ){
2253 WindowData *WData = (WindowData*)event.GetClientData();
2257 if (WData->DataType == 0){
2261 int intID = mnuContactWindows->GetId();
2263 mnuWindow->FindChildItem(intID, &pos);
2264 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2265 mnuNewItem->SetId(WData->WindowID);
2266 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2267 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2268 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2269 mnuWindow->Insert((pos + 1), mnuNewItem);
2270 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2272 } else if (WData->DataType == 1){
2274 // Contact Editor Window
2276 int intID = mnuContactEditorWindows->GetId();
2278 mnuWindow->FindChildItem(intID, &pos);
2279 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2280 mnuNewItem->SetId(WData->WindowID);
2281 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2282 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2283 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2284 mnuWindow->Insert((pos + 1), mnuNewItem);
2285 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2287 } else if (WData->DataType == 2){
2291 int intID = mnuSearchWindows->GetId();
2293 mnuWindow->FindChildItem(intID, &pos);
2294 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2295 mnuNewItem->SetId(WData->WindowID);
2296 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2297 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2298 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2299 mnuWindow->Insert((pos + 1), mnuNewItem);
2300 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2309 void frmMain::WindowEdit( wxCommandEvent &event ){
2311 WindowData *WData = (WindowData*)event.GetClientData();
2313 if (WData->DataType == 0){
2315 // Get the window title and use that.
2317 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2319 wxString WindowTitle = frmContactPtr->GetTitle();
2321 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2323 MenuIter->second->SetItemLabel(WindowTitle);
2325 } else if (WData->DataType == 1){
2327 // Get the window title and use that.
2329 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2331 wxString WindowTitle = frmCEPtr->GetTitle();
2333 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2335 if (WindowTitle.IsEmpty()){
2337 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2341 MenuIter->second->SetItemLabel(WindowTitle);
2352 void frmMain::WindowDelete( wxCommandEvent &event ){
2354 WindowData *WData = (WindowData*)event.GetClientData();
2356 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2358 mnuWindow->Remove(MenuIter->second);
2360 delete MenuIter->second;
2361 MenuIter->second = NULL;
2363 WindowListPointersMenu.erase(WData->WindowID);
2364 WindowListPointers.erase(WData->WindowID);
2365 WindowListType.erase(WData->WindowID);
2372 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2374 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2376 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2378 frmContactPtr->Show();
2379 frmContactPtr->Raise();
2383 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2385 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2387 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2394 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2396 // Look through the Search Window List Pointers, grab the
2397 // window point and show the window.
2399 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2401 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2403 frmSearchPtr->Show();
2404 frmSearchPtr->Raise();
2408 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2410 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2411 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2412 wxPostEvent(frameActMgr, toggconn);
2416 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2418 // Check the account type before continuing.
2420 wxString SeekAccount;
2421 wxString AccTypeLower;
2424 std::map<int, SSLCertCollection>::iterator SSLColIter;
2426 for (int i = 0; i < prefaccounts.GetCount(); i++){
2428 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2429 AccType.Append(prefaccounts.GetAccountType(i));
2430 AccountSSL = prefaccounts.GetAccountSSL(i);
2431 AccTypeLower = AccType.MakeLower();
2432 SeekAccount.Append(wxT("."));
2433 SeekAccount.Append(AccTypeLower);
2435 if (SeekAccount == ActiveAccount){
2437 if (AccTypeLower == wxT("local")){
2443 if (AccountSSL == false){
2449 SSLColIter = AccountSSLData.find(i);
2451 SSLCertCollection SSLCertInfo = SSLColIter->second;
2453 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2454 frameSSLCert->StartCertFrom(0);
2455 frameSSLCert->SetupCerts(SSLCertInfo);
2456 frameSSLCert->ShowModal();
2458 delete frameSSLCert;
2459 frameSSLCert = NULL;
2463 SeekAccount.Clear();
2464 AccTypeLower.Clear();
2471 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2473 // Check the account type before continuing.
2477 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2479 // Check the account type before continuing.
2483 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2485 if (event.GetInt() == 0){
2487 imgConnStatus->SetBitmap(*imgOnline);
2491 imgConnStatus->SetBitmap(*imgOffline);
2497 void frmMain::SetupSSLStatus( int AccountID ){
2499 // Check if account ID given is
2500 // the active account and if not, do nothing.
2503 wxString AccTypeLower;
2505 AccType = prefaccounts.GetAccountType(AccountID);
2506 AccTypeLower = AccType.MakeLower();
2508 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2511 if (AccountIDName != ActiveAccount){
2517 // Check if the account has SSL enabled.
2519 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2521 if (SSLInUse == FALSE){
2523 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2524 imgSSLStatus->SetBitmap(*imgNoSSL);
2528 // Get the SSL Collection Data.
2530 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2532 if (SSLResultIter->second == 1){
2534 imgSSLStatus->SetBitmap(*imgSSLWarning);
2535 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2536 prefaccounts.GetAccountName(AccountID) +
2537 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2540 } else if (SSLResultIter->second == 0){
2542 imgSSLStatus->SetBitmap(*imgSSL);
2543 SSLToolTip->SetTip(wxT("Account '") +
2544 prefaccounts.GetAccountName(AccountID) +
2545 wxT("' secured using SSL\n\nDouble click for more information."));
2553 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2555 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2556 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2557 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2558 wxString AccountName = SSLICNObj->AccountName;
2559 frameISC->LoadData(SSLCCData, AccountName);
2560 frameISC->ShowModal();
2562 int FinalConflictResult = frameISC->GetResult();
2564 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2565 event2.SetClientData(SSLICNObj->QRNotifData);
2566 event2.SetInt(FinalConflictResult);
2571 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2572 wxPostEvent(frameActMgr, event2);
2575 void frmMain::PauseAllTimers(){
2577 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2578 ASTiter != AccountSyncTimers.end(); ASTiter++){
2580 ASTiter->second->Stop();
2586 void frmMain::ResumeAllTimers(){
2588 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2589 ASTiter != AccountSyncTimers.end(); ASTiter++){
2591 ASTiter->second->Start();
2597 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2599 // Delete existing data.
2601 AccountSSLData.erase(AccountID);
2602 AccountSSLResult.erase(AccountID);
2606 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2607 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2611 void frmMain::CheckUpdates( wxCommandEvent& event ){
2613 frmUpdate *frameUpdate = new frmUpdate ( this );
2614 frameUpdate->FetchData();
2615 frameUpdate->ShowModal();
2619 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2621 // Run the import contacts system.
2627 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2629 // Check if an account and at least one contact is selected
2630 // before continuing.
2632 wxArrayString ArrData;
2634 if (ActiveAccount.IsEmpty()){
2640 int ContactSelected = 0;
2641 int ContactsCollected = 0;
2642 long longSelected = -1;
2646 longSelected = lstContacts->GetNextItem(longSelected,
2648 wxLIST_STATE_SELECTED);
2650 if (longSelected == -1){
2656 int FileID = (int)lstContacts->GetItemData(longSelected);
2658 ArrData.Insert(ContactsFileIndex[FileID],
2659 ContactsCollected, 1);
2665 if (ContactSelected == 0){
2671 // Run the export contacts system.
2673 ExportRun(this, &ArrData);
2677 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2678 wxArrayString *ContactsFileIndexPtr){
2680 lstContactsPtr = lstContacts;
2681 ContactsFileIndexPtr = &ContactsFileIndex;
2685 void frmMain::GetSelectedList( wxCommandEvent& event ){
2687 // Get the array of contact filenames.
2689 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2691 // Process them into an array of files.
2693 long longSelected = -1;
2694 int ContactsCollected = 0;
2695 wxString ContactFilename;
2699 longSelected = lstContacts->GetNextItem(longSelected,
2701 wxLIST_STATE_SELECTED);
2703 if (longSelected == -1){
2709 // Get the file information and add to the list.
2711 int FileID = (int)lstContacts->GetItemData(longSelected);
2713 ArrData->Insert(ContactsFileIndex[FileID],
2714 ContactsCollected, 1);
2716 ContactsCollected++;
2717 ContactFilename.Clear();
2725 void frmMain::SyncAccount( wxCommandEvent& event ){
2727 wxString AccNameInc = event.GetString();
2729 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2730 frameActMgr->AddTask(3, wxT(""), AccNameInc,
2731 wxT(""), wxT(""), wxT(""), wxT(""));
2735 void frmMain::ShowHelp( wxCommandEvent& event ){
2737 // Based on the operating system, work out where
2738 // the documentation should be.
2742 #if defined(__HAIKU__)
2744 #elif defined(__WIN32__)
2750 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2752 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2755 #if XSDAB_RELEASE == 0
2757 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2759 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2768 #if XSDAB_RELEASE == 0
2770 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2774 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!"));
2780 void frmMain::ShowImportResults( wxCommandEvent &event ){
2782 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2784 frmImportResults *frmIR = new frmImportResults(this);
2785 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
2796 void frmMain::ReloadContactList( wxCommandEvent &event ){
2798 // Check if the account name given is the current
2799 // account selected.
2801 if (ActiveAccount == event.GetString()){
2803 wxTreeEvent NullEvent;
2804 LoadContactList(NullEvent);
2810 void frmMain::ShowContactMenu( wxMouseEvent& event ){
2812 bool EnableRefresh = FALSE;
2814 if (!ActiveAccount.IsEmpty()){
2816 EnableRefresh = TRUE;
2820 ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
2822 this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
2826 void frmMain::ResetContactInfo(){
2828 wxString EmptyPage = wxT("");
2829 htmContactData->SetPage(EmptyPage);
2830 AccCtrl->SetValue("");