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);
94 // Setup the event table using the event types.
96 BEGIN_EVENT_TABLE(frmMain, wxFrame)
97 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
98 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
99 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
100 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
101 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
102 EVT_COMMAND(wxID_ANY, CE_OPENCONTACTLIST, frmMain::OpenContactInfoList)
103 EVT_COMMAND(wxID_ANY, CE_NEWCONTACT, frmMain::ShowContactEditorNew)
104 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
105 EVT_COMMAND(wxID_ANY, CE_DELETECONTACT, frmMain::DeleteContact)
106 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
107 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
108 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
109 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
110 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
111 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
112 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
113 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
114 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
115 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
116 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
117 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
118 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
119 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
120 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
121 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
124 frmMain::frmMain( wxWindow* parent )
129 // Setup the account icons.
131 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
132 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
133 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
134 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
136 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
137 wxBitmap AccInet(icons_accinet_png, -1);
139 wxIAccInet.CopyFromBitmap(AccInet);
141 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
142 wxBitmap AccNIcon(icons_acclocal_png, -1);
144 wxIAccNIcon.CopyFromBitmap(AccNIcon);
146 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
147 wxBitmap AccGrp(icons_accgroup_png, -1);
149 wxIAccGrp.CopyFromBitmap(AccGrp);
151 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
152 wxBitmap AccNone(icons_accnone_png, -1);
154 wxIAccNone.CopyFromBitmap(AccNone);
156 AccountID = AccImgList->Add(wxIAccNIcon);
157 AccountNetID = AccImgList->Add(wxIAccInet);
158 AccountGrpID = AccImgList->Add(wxIAccGrp);
159 AccountNoneID = AccImgList->Add(wxIAccNone);
161 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
163 // Setup the status bar icons.
167 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
168 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
169 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
171 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
172 imgSSL = new wxBitmap(icons_ssl_png, -1);
174 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
175 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
177 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
178 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
182 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
183 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
184 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
185 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
186 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
188 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
189 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
191 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
192 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
194 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
196 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
197 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
199 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
201 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
202 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
204 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
206 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
207 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
209 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
211 // Online/Offline icons.
213 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
214 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
216 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
217 imgOnline = new wxBitmap(icons_online_png, -1);
219 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
220 imgOffline = new wxBitmap(icons_offline_png, -1);
222 // Setup the account view.
224 AccCtrl->SetPopupControl(treAccounts);
225 AccCtrl->SetPopupMaxHeight(175);
226 AccCtrl->SetPopupMinWidth(250);
227 treAccounts->AssignImageList(AccImgList);
229 wxListItem ColumnData;
231 ColumnData.SetText(wxT("Name0"));
232 ColumnData.SetWidth(320);
233 lstContacts->InsertColumn(0, ColumnData);
235 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
236 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
238 #if defined(__HAIKU__)
240 #elif defined(__WIN32__)
242 int stbBottomData [4] = { -1, 8, 8, 8 };
246 int stbBottomData [4] = { -1, 20, 20, 20 };
250 stbBottom->SetFieldsCount(4, stbBottomData);
251 stbBottom->SetMinHeight(16);
256 stbBottom->GetFieldRect(1, rectOnline);
257 stbBottom->GetFieldRect(2, rectSSL);
258 stbBottom->GetFieldRect(3, rectActivity);
260 SSLToolTip = new wxToolTip(wxT(""));
262 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
263 imgConnStatus->SetBitmap(*imgOnline);
264 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
266 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
267 imgSSLStatus->SetBitmap(*imgNoSSL);
268 imgSSLStatus->SetToolTip(SSLToolTip);
269 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
271 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
272 imgActivityStatus->SetBitmap(*imgActIconSleep);
273 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
275 // Setup the window menu.
277 // By default should be:
282 // Contact editor windows:
288 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
289 mnuWindow->Append( mnuContactWindows );
291 mnuWindow->AppendSeparator();
293 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
294 mnuWindow->Append( mnuContactEditorWindows );
296 mnuWindow->AppendSeparator();
298 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
299 mnuWindow->Append( mnuSearchWindows );
301 #if defined(__WIN32__)
306 mnuContactWindows->SetFont(fontstyle);
307 mnuContactEditorWindows->SetFont(fontstyle);
308 mnuSearchWindows->SetFont(fontstyle);
312 mnuContactWindows->Enable(FALSE);
313 mnuContactEditorWindows->Enable(FALSE);
314 mnuSearchWindows->Enable(FALSE);
318 // Hide unimplemented functions.
324 void frmMain::QuitApp( wxCloseEvent& event )
327 // Run the QuitApp function.
333 void frmMain::QuitApp( wxCommandEvent& event )
336 // Run the QuitApp function.
342 void frmMain::QuitApp()
345 // Function to run when quitting.
347 //Go through the windows and close each one (be it search
348 //or contact editor). Abort if user wants to cancel.
350 // Close the contact editor windows.
352 // Close the contact windows.
354 // Close the search windows.
356 // Write out the ETag databases.
358 // Save Preferences: Save the window position if that option is enabled.
360 wxString SetFilename = GetUserPrefDir();
362 #if defined(__HAIKU__)
366 #elif defined(__WIN32__)
368 SetFilename.Append(wxT("settings"));
374 SetFilename.Append(wxT("settings"));
378 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
380 bool SaveWindowPos = FALSE;
381 wxString SaveWindowInc;
382 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
384 if (SaveWindowInc == wxT("true")){
386 SaveWindowPos = TRUE;
390 if (SaveWindowPos == TRUE){
392 wxRect frmMainPos = this->GetRect();
394 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
395 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
396 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
397 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
404 //Everything closed... exit.
412 void frmMain::ShowActivityWindow( wxCommandEvent& event )
415 // Open the activity manager window.
417 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
418 frameActMgr->OpenWindow();
423 void frmMain::ShowAboutWindow( wxCommandEvent& event )
426 // Show the about window.
428 frmAbout *frameAbout = new frmAbout ( this );
429 frameAbout->SetupAboutWindow();
430 frameAbout->ShowModal();
436 void frmMain::OpenPreferences( wxCommandEvent& event)
439 // Open the preferences window.
441 ReloadAccounts = FALSE;
443 frmPreferences *framePreferences = new frmPreferences ( this );
444 framePreferences->SetupPointers(&ReloadAccounts);
445 framePreferences->ShowModal();
446 delete framePreferences;
447 framePreferences = NULL;
449 if (ReloadAccounts == TRUE){
451 // Reload the accounts as a change has been made within
452 // the application and clear the current contact information.
454 this->LoadPreferences();
455 this->ResetContactInfo();
461 void frmMain::OpenNewABDialog( wxCommandEvent& event)
464 // Open the new account dialog.
466 ReloadAccounts = FALSE;
468 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
469 frameNewAccount->SetupPointers(&ReloadAccounts);
470 frameNewAccount->ShowModal();
471 delete frameNewAccount;
472 frameNewAccount = NULL;
474 if (ReloadAccounts == TRUE){
476 // Reload the accounts as a change has been made within
479 this->LoadPreferences();
485 void frmMain::LoadContactList( wxTreeEvent& event )
488 // Load the contact list.
490 // Clear all existing variables.
492 lstContacts->DeleteAllItems();
494 treAccounts->SetAccount();
496 wxTreeItemIdValue cookie;
497 wxTreeItemId next = treAccounts->GetRootItem();
498 wxString AccountName;
499 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
500 wxString AccountDirCmb;
501 long selectedaccount = 0;
503 wxTreeItemId selectedChild = treAccounts->GetSelection();
504 wxTreeItemId nextChild;
506 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
507 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
509 int SCImg = treAccounts->GetItemImage(selectedChild);
510 int AccountIndex = 0;
512 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
514 // Process each account.
516 for (int i = 0; i < prefaccounts.GetCount(); i++){
518 if (ActiveItemIcon == 2){
520 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
521 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
522 int ActiveAccountG = AGLiter->second;
524 if (i == ActiveAccountG){
526 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
527 AccountType.Append(prefaccounts.GetAccountType(i));
532 if (AccountType == wxT("CardDAV")){
533 AccountTypeFinal.Append(wxT("carddav"));
534 } else if (AccountType == wxT("Local")){
535 imgSSLStatus->SetBitmap(*imgOffline);
536 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
537 AccountTypeFinal.Append(wxT("local"));
548 nextChild = treAccounts->GetFirstChild(next, cookie);
550 nextChild = treAccounts->GetNextSibling(nextChild);
553 AccountName = treAccounts->GetItemText(nextChild);
555 if (nextChild == selectedChild){
557 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
558 AccountType.Append(prefaccounts.GetAccountType(i));
563 if (AccountType == wxT("CardDAV")){
564 AccountTypeFinal.Append(wxT("carddav"));
565 } else if (AccountType == wxT("Local")){
566 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
567 AccountTypeFinal.Append(wxT("local"));
576 if (selectedaccount >= prefaccounts.GetCount()){
578 // The account selected isn't there so return.
586 // Open the directory and get the list of .vcf files
587 // in that directory.
589 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
590 ActiveAccountType = AccountType;
592 SetupSSLStatus(AccountIndex);
594 AccountDirFinal.Clear();
595 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
597 ContactsFileIndex.Clear();
599 wxString vCardFilename;
600 wxString vCardFilenameFull;
601 wxString vCardDataString;
602 wxStringTokenizer vcardfileline;
604 wxString setname, setvalue;
605 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
606 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
607 long ContactIndex = 1;
608 long ContactSeekPoint = 0;
610 wxDir vcardaccdir(AccountDirFinal);
612 // Get the wxTreeItemId and image icon and compare it to the list.
614 if (ActiveItemIcon == AccountGrpID){
616 // It's a group so load the file containing the group and
617 // get the members of the group.
622 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
623 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
625 Group.LoadFile(AGFiter->second);
627 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
629 for (int i = 0; i < vCardMember.PropCount; i++){
631 vCardMember.PropValues[i].Trim();
632 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
634 wxString NewPropValue;
635 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
636 vCardMember.PropValues[i] = NewPropValue;
642 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
646 if (vCardFilename.Right(4) == wxT(".vcf") ||
647 vCardFilename.Right(4) == wxT(".VCF") ||
648 vCardFilename.Right(5) == wxT(".vcard") ||
649 vCardFilename.Right(5) == wxT(".VCARD")){
652 bool FoundMember = FALSE;
654 vCardFilenameFull.Append(AccountDirFinal);
655 vCardFilenameFull.Append(wxT("/"));
656 vCardFilenameFull.Append(vCardFilename);
658 Person.LoadFile(vCardFilenameFull);
660 UIDCode = Person.Get(wxT("UID"));
662 for (int i = 0; i < vCardMember.PropCount; i++){
664 if (vCardMember.PropValues[i] == UIDCode){
672 if (FoundMember == FALSE){
674 vCardFilename.Clear();
675 vCardFilenameFull.Clear();
676 vCardDataString.Clear();
677 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
682 if (Person.MeetBaseSpecification()){
686 // Split the name into sections.
688 vCardDataString = Person.Get(wxT("N"));
690 vCardName NameData = Person.GetName();
692 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
694 } else if (SortMode == 2){
696 // Split the name into sections.
698 vCardName NameData = Person.GetName();
700 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
702 } else if (SortMode == 3){
704 // Check and make sure that the top most nickname is used.
706 vCardDataString = Person.Get(wxT("NICKNAME"));
708 if (vCardDataString.IsEmpty()){
710 vCardDataString = wxT("(no nickname)");
714 } else if (SortMode == 4){
716 vCardDataString = Person.Get(wxT("FN"));
720 if (AscendingMode == TRUE){
721 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
723 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
730 vCardFilename.Clear();
731 vCardFilenameFull.Clear();
732 vCardDataString.Clear();
733 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
739 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
742 if (vCardFilename.Right(4) == wxT(".vcf") ||
743 vCardFilename.Right(4) == wxT(".VCF") ||
744 vCardFilename.Right(5) == wxT(".vcard") ||
745 vCardFilename.Right(5) == wxT(".VCARD")){
749 vCardFilenameFull.Append(AccountDirFinal);
750 vCardFilenameFull.Append(vCardFilename);
752 Person.LoadFile(vCardFilenameFull);
754 if (Person.MeetBaseSpecification()){
758 // Split the name into sections.
760 vCardDataString = Person.Get(wxT("N"));
762 vCardName NameData = Person.GetName();
764 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
766 } else if (SortMode == 2){
768 // Split the name into sections.
770 vCardName NameData = Person.GetName();
772 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
774 } else if (SortMode == 3){
776 // Check and make sure that the top most nickname is used.
778 vCardDataString = Person.Get(wxT("NICKNAME"));
780 if (vCardDataString.IsEmpty()){
782 vCardDataString = wxT("(no nickname)");
786 } else if (SortMode == 4){
788 vCardDataString = Person.Get(wxT("FN"));
792 if (AscendingMode == TRUE){
794 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
798 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
806 vCardFilename.Clear();
807 vCardFilenameFull.Clear();
808 vCardDataString.Clear();
809 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
816 // Insert the data into the control.
818 if (AscendingMode == TRUE){
819 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
820 iter != vCardNamesAsc.end(); ++iter){
822 wxListItem ContactInfo;
824 ContactInfo.SetId(0);
825 ContactInfo.SetText(_("Mooo"));
826 ContactInfo.SetData(ContactSeekPoint);
827 ContactIndex = lstContacts->InsertItem(ContactInfo);
829 lstContacts->SetItem(ContactIndex, 0, iter->first);
831 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
838 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
839 iter != vCardNamesDsc.end(); ++iter){
841 wxListItem ContactInfo;
843 ContactInfo.SetId(0);
844 ContactInfo.SetText(_("Mooo"));
845 ContactInfo.SetData(ContactSeekPoint);
846 ContactIndex = lstContacts->InsertItem(ContactInfo);
848 lstContacts->SetItem(ContactIndex, 0, iter->first);
849 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
858 void frmMain::ShowContactInfo( wxListEvent& event )
861 // Display the contact information.
863 long intSelected = -1;
864 long ContactSeekNum = -1;
866 // Check if several contacts have been selected.
868 int ContactTotal = 0;
872 intSelected = lstContacts->GetNextItem(intSelected,
874 wxLIST_STATE_SELECTED);
876 if (intSelected == -1){
886 if (ContactTotal == 0){
887 htmContactData->SetPage(wxT(""));
891 if (ContactTotal > 1){
893 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
894 ActiveFilename.Clear();
899 intSelected = lstContacts->GetNextItem(intSelected,
901 wxLIST_STATE_SELECTED);
903 ContactSeekNum = lstContacts->GetItemData(intSelected);
906 wxString wxSContactString;
907 wxString ContactLine;
910 size_t ContactLineLen;
911 bool ExtraLineSeek = FALSE;
912 int QuoteBreakPoint = 0;
914 bool PropertyFind = FALSE;
915 bool QuoteMode = FALSE;
917 wxString wxSPropertyNextLine;
918 wxString wxSProperty;
919 wxString wxSPropertySeg1;
920 wxString wxSPropertySeg2;
922 // Check if we are using wxWidgets version 2.8 or less and
923 // execute the required command accordingly.
925 #if wxABI_VERSION < 20900
926 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
928 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
931 if (ContactFile.IsOpened() == FALSE){
937 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
941 std::map<int, wxString> ContactFileLines;
942 std::map<int, wxString>::iterator striter;
944 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
946 int ContactLineSeek = 0;
948 while (wSTContactFileLines.HasMoreTokens() == TRUE){
950 ContactLine = wSTContactFileLines.GetNextToken();
951 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
956 if (ContactSeekNum < 0){
960 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
961 iter != ContactFileLines.end(); ++iter){
963 // Find the colon which splits the start bit from the data part.
965 ContactLine = iter->second;
967 while (ExtraLineSeek == TRUE){
969 // Check if there is extra data on the next line
970 // (indicated by space or tab at the start) and add data.
974 if (iter == ContactFileLines.end()){
981 wxSPropertyNextLine = iter->second;
984 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
986 wxSPropertyNextLine.Remove(0, 1);
987 ContactLine.Append(wxSPropertyNextLine);
992 ExtraLineSeek = FALSE;
998 ContactLineLen = ContactLine.Len();
1000 // Make sure we are not in quotation mode.
1001 // Make sure colon does not have \ or \\ before it.
1003 for (int i = 0; i <= ContactLineLen; i++){
1005 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1007 PropertyFind = FALSE;
1009 } else if (PropertyFind == TRUE){
1011 wxSProperty.Append(ContactLine.Mid(i, 1));
1015 if (ContactLine.Mid(i, 1) == wxT("\"")){
1017 if (QuoteMode == TRUE){
1029 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1031 QuoteBreakPoint = i;
1038 // Split that line at the point into two variables (ignore the colon).
1040 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1041 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1043 // Insert both into the vCard data file.
1045 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1048 PropertyFind = TRUE;
1049 ExtraLineSeek = TRUE;
1051 QuoteBreakPoint = 0;
1052 ContactLine.Clear();
1053 wxSProperty.Clear();
1057 OldSessionID = SessionID;
1058 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1059 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1060 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1064 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1067 // Open a contact editor window to write a new contact with.
1069 // Check if there is an account selected and if not
1070 // return immediately.
1072 if (ActiveAccount.IsEmpty()){
1078 // Add Pointer to SetupPointers for the ETagDB.
1080 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1081 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1082 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1084 contacticon.CopyFromBitmap(contacticonbmp);
1086 frmContactEditor *ContactEditor = new frmContactEditor( this );
1090 ContactEditor->SetUID(WindowMenuItemID);
1092 WindowData *WData = new WindowData;
1094 WData->DataType = 1;
1095 WData->WindowPointer = (void*)ContactEditor;
1096 WData->WindowID = WindowMenuItemID;
1098 wxCommandEvent addevent(WINDOW_ADD);
1099 addevent.SetClientData(WData);
1100 wxPostEvent(this, addevent);
1102 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1103 ContactEditor->SetupHeaders();
1104 ContactEditor->SetupContact(ActiveAccount);
1105 ContactEditor->SetIcon(contacticon);
1106 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1107 ContactEditor->Show(true);
1111 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1114 // Open a contact editor window for editing an existing contact
1117 // Check if there is an account selected and if not
1118 // return immediately.
1120 int DataCheck = event.GetInt();
1122 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1128 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1129 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1130 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1132 contacticon.CopyFromBitmap(contacticonbmp);
1134 // Check if a contact has been selected.
1136 long intSelected = -1;
1137 long intContactSeekNum = -1;
1139 intSelected = lstContacts->GetNextItem(intSelected,
1141 wxLIST_STATE_SELECTED);
1143 if (intSelected == -1){
1149 intContactSeekNum = lstContacts->GetItemData(intSelected);
1151 // Get the filename of the selected contact.
1153 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1154 frmContactEditor *ContactEditor = new frmContactEditor( this );
1158 ContactEditor->SetUID(WindowMenuItemID);
1160 WindowData *WData = new WindowData;
1162 WData->DataType = 1;
1163 WData->WindowPointer = (void*)ContactEditor;
1164 WData->WindowID = WindowMenuItemID;
1166 wxCommandEvent addevent(WINDOW_ADD);
1167 addevent.SetClientData(WData);
1168 wxPostEvent(this, addevent);
1170 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1171 ContactEditor->SetupHeaders();
1173 // Check if pointer is NULL (not from the search forms) or not.
1175 if (DataCheck == 0){
1177 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1178 ContactEditor->SetupContact(ActiveAccount);
1182 UCNotif *uc = (UCNotif*)event.GetClientData();
1186 ContactEditor->SetupContact(ActiveAccount);
1187 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1191 ContactEditor->SetupContact(uc->ContactAccount);
1192 ContactEditor->LoadContact(uc->ContactFilename);
1201 ContactEditor->SetIcon(contacticon);
1202 ContactEditor->Show(true);
1206 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1208 // Refresh the address book data.
1210 // Check if ActiveAccount is empty. If not then check if
1211 // account type is not local otherwise continue.
1213 if (!ActiveAccount.IsEmpty()){
1215 if (ActiveAccountType != wxT("Local")){
1217 // Account type is not local.
1219 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1220 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1221 wxT(""), wxT(""), wxT(""), wxT(""));
1225 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1233 void frmMain::OpenContactInfoList( wxListEvent& event )
1236 // Open the contact information window.
1238 wxStringTokenizer vcardfileline;
1241 wxString setname, setvalue;
1245 long intSelected = -1;
1246 long intContactSeekNum = -1;
1248 intSelected = lstContacts->GetNextItem(intSelected,
1250 wxLIST_STATE_SELECTED);
1252 intContactSeekNum = lstContacts->GetItemData(intSelected);
1254 if (intContactSeekNum == -1){
1260 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1262 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1263 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1264 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1266 contacticon.CopyFromBitmap(contacticonbmp);
1268 frmContact *Contact = new frmContact( this );
1270 // Add to window list.
1274 Contact->SetUID(WindowMenuItemID);
1276 WindowData *WData = new WindowData;
1278 WData->DataType = 0;
1279 WData->WindowPointer = (void*)Contact;
1280 WData->WindowID = WindowMenuItemID;
1282 wxCommandEvent addevent(WINDOW_ADD);
1283 addevent.SetClientData(WData);
1284 wxPostEvent(this, addevent);
1286 Contact->SetupPointers(&MemoryFileList);
1287 Contact->SetupContactData(&Person);
1289 Contact->SetIcon(contacticon);
1290 Contact->Show(true);
1294 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1296 // Open a list of contact information windows.
1299 OpenContactInfoList(pevent);
1303 void frmMain::OpenContactInfo( wxCommandEvent& event )
1306 // Open the contact information window.
1308 UCNotif *uc = (UCNotif*)event.GetClientData();
1310 wxStringTokenizer vcardfileline;
1313 wxString setname, setvalue;
1317 Person.LoadFile(uc->ContactFilename);
1319 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1320 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1321 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1323 contacticon.CopyFromBitmap(contacticonbmp);
1325 frmContact *Contact = new frmContact( this );
1327 // Add to window list.
1331 Contact->SetUID(WindowMenuItemID);
1333 WindowData *WData = new WindowData;
1335 WData->DataType = 0;
1336 WData->WindowPointer = (void*)Contact;
1337 WData->WindowID = WindowMenuItemID;
1339 wxCommandEvent addevent(WINDOW_ADD);
1340 addevent.SetClientData(WData);
1341 wxPostEvent(this, addevent);
1343 Contact->SetupPointers(&MemoryFileList);
1344 Contact->SetupContactData(&Person);
1346 Contact->SetIcon(contacticon);
1347 Contact->Show(true);
1352 void frmMain::LoadPreferences( wxActivateEvent& event)
1355 // Load the preferences.
1357 this->LoadPreferences();
1361 void frmMain::LoadPreferences(){
1363 // Load the preferences.
1365 wxString preffilename = GetUserPrefDir();
1367 XABPreferences preferences(preffilename);
1369 // Setup the main window position (if needed).
1371 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1372 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1374 if (SaveWindowPos == TRUE){
1376 this->SetSize(preferences.GetMainWindowData());
1380 treAccounts->DeleteAllItems();
1382 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1384 // Stop all account timers and remove the accounts.
1386 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1387 iter != AccountSyncTimers.end(); iter++){
1389 wxAccountSyncTimer *AccTmrPtr = iter->second;
1397 AccountSyncTimers.clear();
1400 wxString AccDirFull;
1401 wxString AccDirFullSfx;
1403 wxString AccDirFinal;
1404 AccountAccDirList.clear();
1405 AccountGroupList.clear();
1406 AccountGroupFilename.clear();
1407 AccountGroupTreeId.clear();
1408 wxTreeItemId AccountTreeId;
1409 wxTreeItemId GroupTreeId;
1412 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1414 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1415 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1421 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1427 AccDir = preferences.accounts.GetAccountDirectory(i);
1428 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1430 AccDirFull.Append(wxT("."));
1431 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1432 AccDirFullSfx.LowerCase();
1433 AccDirFullSfx.Trim();
1434 AccDirFull.Append(AccDirFullSfx);
1435 AccName = preferences.accounts.GetAccountName(i);
1437 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1439 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1440 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1442 // TODO: Check if the directory exists before doing anything.
1446 // Add a new timer using the existing account details.
1448 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1450 ActTmrPtr->SetupData(AccDirFull, AccName);
1451 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1452 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1453 ActTmrPtr->SetOwner(this);
1454 ActTmrPtr->Notify();
1456 // Add the timer to the list of timers.
1458 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1460 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1464 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1468 // Go through the account directory and find contact files with
1469 // 'KIND:group' set and add them to the list of groups for the account.
1471 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1473 wxDir vcardaccdir(AccDirFinal);
1475 wxString vCardFilename;
1476 wxString vCardDataString;
1477 wxString vCardFilenameFull;
1479 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1483 if (vCardFilename.Right(4) == wxT(".vcf") ||
1484 vCardFilename.Right(4) == wxT(".VCF") ||
1485 vCardFilename.Right(5) == wxT(".vcard") ||
1486 vCardFilename.Right(5) == wxT(".VCARD")){
1490 vCardFilenameFull.Append(AccDirFinal);
1491 vCardFilenameFull.Append(wxT("/"));
1492 vCardFilenameFull.Append(vCardFilename);
1494 Person.LoadFile(vCardFilenameFull);
1496 if (Person.MeetBaseSpecification()){
1498 vCardDataString = Person.Get(wxT("KIND"));
1500 if (vCardDataString == wxT("group")){
1502 // The vCard kind is a group. Add to the account's group list.
1504 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1505 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1506 AccountGroupList.insert(std::make_pair(intGroupID, i));
1507 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1508 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1518 vCardFilename.Clear();
1519 vCardFilenameFull.Clear();
1520 vCardDataString.Clear();
1521 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1525 // Clearup for next account.
1529 AccDirFullSfx.clear();
1530 AccDirFinal.clear();
1535 // Load the account settings as they are needed for connecting
1538 prefaccounts = preferences.accounts;
1542 void frmMain::ConflictResolution(wxCommandEvent& event){
1544 // Display the conflict resolution window.
1546 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1547 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1548 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1549 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1550 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1551 frameCR->ShowModal();
1553 int FinalConflictResult = frameCR->GetResult();
1555 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1556 event2.SetClientData(vCardConfObj->QRNotifData);
1557 event2.SetInt(FinalConflictResult);
1562 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1563 wxPostEvent(frameActMgr, event2);
1567 void frmMain::UpdateContactList(wxCommandEvent& event){
1569 // Update the contact list in the main window.
1571 UCNotif *ucd = (UCNotif*)event.GetClientData();
1573 // Check if the active account is being displayed in the
1574 // main window. If not, skip and delete the data.
1576 long longSelected = -1;
1577 int intSelectedData = 0;
1579 if (ActiveAccount == ucd->ContactAccount){
1581 // Look at the list of contacts and if it matches the
1582 // filename then update the name.
1586 longSelected = lstContacts->GetNextItem(longSelected,
1588 wxLIST_STATE_DONTCARE);
1590 if (longSelected == -1){
1596 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1598 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1600 // Work out which sorting mode we are in.
1604 // First Name, Last Name.
1606 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1608 } else if (SortMode == 2){
1610 // Last Name, First Name.
1612 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1614 } else if (SortMode == 3){
1618 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1620 } else if (SortMode == 4){
1624 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1631 // If the filename is the one loaded into the
1632 // browser control, then update this too.
1634 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1636 wxListEvent nullevent;
1637 ShowContactInfo(nullevent);
1645 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1646 WindowIter != WindowListPointers.end(); WindowIter++){
1648 if (WindowListType[WindowIter->first] != 0){
1654 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1656 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1658 vCard UpdatedPerson;
1659 UpdatedPerson.LoadFile(ucd->ContactFilename);
1660 frmContactPtr->SetupContactData(&UpdatedPerson);
1666 // Send message to search window controller subroutine and
1667 // pass that notification onto the search windows.
1669 // Setup the new pointer to use the existing UCNotif without
1672 UCNotif *ucd2 = ucd;
1674 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1675 sup.SetClientData(ucd2);
1676 wxPostEvent(this, sup);
1678 // Clear up the unused pointer.
1684 void frmMain::UpdateAccountList(wxCommandEvent& event){
1686 // Update the account list (currently unimplemented).
1690 void frmMain::SetupPointers(void *ActMgrPtrInc){
1692 // Setup the pointers for the main window.
1694 ActMgrPtr = ActMgrPtrInc;
1698 void frmMain::SetupForm(){
1700 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1701 frameActMgr->SetupPointers(&ETagProcTimer, this);
1703 // Setup the contact information icons for later.
1705 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1709 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1710 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1711 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1713 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1714 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1715 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1717 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1718 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1719 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1721 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1722 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1723 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1725 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1726 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1727 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1729 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1730 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1731 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1737 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1739 // Update the contact lists in the search windows.
1741 // Go through each of the search windows and
1742 // send the required notification to update the
1743 // contact information.
1745 // Get the event notification data.
1747 UCNotif *ucd = (UCNotif*)event.GetClientData();
1749 // Process each search window giving the new details.
1751 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1752 switer != SearchWindowList.end(); switer++){
1754 // Duplicate the event notification data.
1756 UCNotif *ucd2 = new UCNotif;
1758 ucd2->ContactAccount = ucd->ContactAccount;
1759 ucd2->ContactFilename = ucd->ContactFilename;
1760 ucd2->ContactName = ucd->ContactName;
1761 ucd2->ContactNickname = ucd->ContactNickname;
1762 ucd2->ContactNameArray = ucd->ContactNameArray;
1764 // Pass the data to the search window for processing.
1766 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1767 wxCommandEvent schupdate(SE_UPDATERESULT);
1768 schupdate.SetClientData(ucd2);
1769 wxPostEvent(frameSCH, schupdate);
1771 // Clear up the pointer prior to variable deletion.
1782 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1784 // Open a new search window.
1788 frmSearch *frameSCH = new frmSearch ( this );
1789 frameSCH->SetUID(WindowMenuItemID);
1790 frameSCH->Show(true);
1792 WindowData *WData = new WindowData;
1794 WData->DataType = 2;
1795 WData->WindowPointer = (void*)frameSCH;
1796 WData->WindowID = WindowMenuItemID;
1798 wxCommandEvent addevent(WINDOW_ADD);
1799 addevent.SetClientData(WData);
1800 wxPostEvent(this, addevent);
1802 // Add pointer to the list of open search windows.
1804 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1810 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1812 // Remove the pointer for a contact window from the
1815 void *frameSCH = (void*)event.GetClientData();
1817 SearchWindowList.erase(frameSCH);
1823 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1825 // Remove the pointer for a contact editor window from
1828 void *frameSCH = (void*)event.GetClientData();
1830 SearchWindowList.erase(frameSCH);
1836 void frmMain::RevealContact(wxCommandEvent& event){
1838 // Reveal a contact in the main window.
1840 UCNotif *uc = (UCNotif*)event.GetClientData();
1842 // Switch the account to the one passed.
1844 wxTreeItemIdValue cookie;
1845 wxTreeItemId next = treAccounts->GetRootItem();
1846 wxTreeItemId nextChild;
1848 for (int i = 0; i < prefaccounts.GetCount(); i++){
1851 nextChild = treAccounts->GetFirstChild(next, cookie);
1853 nextChild = treAccounts->GetNextSibling(nextChild);
1856 if (uc->ContactAccount == AccountAccDirList[i]){
1858 treAccounts->SelectItem(nextChild, TRUE);
1859 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1865 // Switch the contact to the one passed.
1867 long longSelected = -1;
1868 int intSelectedData = 0;
1872 longSelected = lstContacts->GetNextItem(longSelected,
1874 wxLIST_STATE_DONTCARE);
1876 if (longSelected == -1){
1882 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1884 // Compare the filename with the one received.
1885 // If they match then select it.
1887 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1891 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1892 lstContacts->EnsureVisible(longSelected);
1896 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1904 void frmMain::DeleteContact(wxCommandEvent& event){
1906 // Delete a contact from the main window.
1908 // Check if a contact is selected.
1910 long intSelected = -1;
1911 long intContactSeekNum = -1;
1912 wxString wxSContactName;
1914 intSelected = lstContacts->GetNextItem(intSelected,
1916 wxLIST_STATE_SELECTED);
1918 if (intSelected == -1){
1922 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1924 // Get the item data of the contact.
1926 intContactSeekNum = lstContacts->GetItemData(intSelected);
1928 // Get the name of the contact.
1930 wxSContactName = lstContacts->GetItemText(intSelected);
1932 // Display a message confirming if the contact should
1935 int QuestionResponse;
1937 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1939 if (QuestionResponse == wxNO){
1941 // Exit the subroutine
1947 // Delete the contact.
1949 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1951 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1956 // Remove the contact from the list.
1958 lstContacts->DeleteItem(intSelected);
1960 // Update the search windows, removing the deleted
1963 UCNotif *ucd = new UCNotif;
1965 ucd->ContactAccount = ActiveAccount;
1966 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1968 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1969 switer != SearchWindowList.end(); switer++){
1971 // Duplicate the event notification data.
1973 UCNotif *ucd2 = new UCNotif;
1975 ucd2->ContactAccount = ucd->ContactAccount;
1976 ucd2->ContactFilename = ucd->ContactFilename;
1978 // Pass the data to the search window for processing.
1980 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1981 wxCommandEvent schdelete(SE_DELETERESULT);
1982 schdelete.SetClientData(ucd2);
1983 wxPostEvent(frameSCH, schdelete);
1985 // Clear up the pointer prior to variable deletion.
1992 // Clear the wxHTMLWindow.
1994 wxString EmptyPage = wxT("");
1996 htmContactData->SetPage(EmptyPage);
1998 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2000 wxString wxSplitFilename;
2001 wxString wxSDataURL;
2003 while(wSTFilename.HasMoreTokens()){
2005 wxSplitFilename = wSTFilename.GetNextToken();
2009 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2011 // Update the ETagDB and mark it as deleted.
2013 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2015 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2017 // Get the Data URL.
2019 wxTreeItemIdValue cookie;
2020 wxTreeItemId next = treAccounts->GetRootItem();
2022 wxTreeItemId selectedChild = treAccounts->GetSelection();
2023 wxTreeItemId nextChild;
2025 for (int i = 0; i < prefaccounts.GetCount(); i++){
2028 nextChild = treAccounts->GetFirstChild(next, cookie);
2030 nextChild = treAccounts->GetNextSibling(nextChild);
2033 if (nextChild == selectedChild){
2035 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2041 // Add task to the activity monitor to delete the contact.
2043 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2047 // Clear the variable. Don't delete as it will mess things up.
2049 ContactsFileIndex[intContactSeekNum] = wxT("");
2056 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2058 // Display this message when the server information has changed
2061 QRNotif *qrn = (QRNotif *)event.GetClientData();
2063 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);
2065 if (QResponse == wxNO){
2071 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2072 event2.SetInt(*qrn->QResponse);
2073 event2.SetClientData(qrn->PausePtr);
2075 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2077 wxPostEvent(frameActMgr, event2);
2081 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2083 // Remove the contact from the window after syncronising.
2085 // Check which account is currently active in the window.
2086 // If it is different from the one passed to this subroutine then
2087 // exit from the subroutine.
2089 if (Account != ActiveAccount){
2093 long longSelected = -1;
2094 int intSelectedData = 0;
2098 longSelected = lstContacts->GetNextItem(longSelected,
2100 wxLIST_STATE_DONTCARE);
2102 if (longSelected == -1){
2108 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2110 // Compare the filename with the one received.
2111 // If they match then select it.
2113 if (ContactsFileIndex[intSelectedData] == Filename){
2115 // Remove the contact from the window.
2117 lstContacts->DeleteItem(intSelectedData);
2119 // Check if contact is the selected contact in the HTML window and
2120 // if it is then clear the window.
2122 if (ActiveFilename == Filename){
2124 wxString EmptyPage = wxT("");
2125 htmContactData->SetPage(EmptyPage);
2139 void frmMain::SortFNLN( wxCommandEvent& event ) {
2141 // Sort first name then last name.
2143 wxTreeEvent NullEvent;
2145 LoadContactList(NullEvent);
2149 void frmMain::SortLNFN( wxCommandEvent& event ) {
2151 // Sort last name then first name.
2153 wxTreeEvent NullEvent;
2155 LoadContactList(NullEvent);
2159 void frmMain::SortNickname( wxCommandEvent& event ) {
2161 // Sort by nickname.
2163 wxTreeEvent NullEvent;
2165 LoadContactList(NullEvent);
2169 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2171 // Sort by Display As name.
2173 wxTreeEvent NullEvent;
2175 LoadContactList(NullEvent);
2179 void frmMain::SortAscending( wxCommandEvent& event ) {
2183 wxTreeEvent NullEvent;
2184 AscendingMode = TRUE;
2185 LoadContactList(NullEvent);
2189 void frmMain::SortDescending( wxCommandEvent& event ) {
2193 wxTreeEvent NullEvent;
2194 AscendingMode = FALSE;
2195 LoadContactList(NullEvent);
2199 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2201 // Toggle the appearance of the status bar.
2203 if (stbBottom->IsShown() == TRUE){
2217 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2219 // Display the activity icon.
2221 imgActivityStatus->SetBitmap(*imgActIcon1);
2222 ActivityIconStatus = 0;
2226 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2228 // Shuffle through the activity icons.
2230 switch (ActivityIconStatus){
2233 imgActivityStatus->SetBitmap(*imgActIcon1);
2234 ActivityIconStatus = 1;
2237 imgActivityStatus->SetBitmap(*imgActIcon2);
2238 ActivityIconStatus = 2;
2241 imgActivityStatus->SetBitmap(*imgActIcon3);
2242 ActivityIconStatus = 3;
2245 imgActivityStatus->SetBitmap(*imgActIcon4);
2246 ActivityIconStatus = 0;
2249 ActivityIconStatus = 0;
2255 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2257 // Display the sleep icon.
2259 imgActivityStatus->SetBitmap(*imgActIconSleep);
2263 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2265 // Set the placement of the status bar icons.
2267 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2275 wxRect rectActivity;
2276 stbBottom->GetFieldRect(1, rectOnline);
2277 stbBottom->GetFieldRect(2, rectSSL);
2278 stbBottom->GetFieldRect(3, rectActivity);
2280 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2281 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2282 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2286 XABViewMode frmMain::GetViewMode(){
2288 // Set the view mode of the contact list.
2292 xvm.SortMode = SortMode;
2293 xvm.AscendingMode = AscendingMode;
2299 void frmMain::WindowAdd( wxCommandEvent &event ){
2301 // Add a window to the window list.
2303 WindowData *WData = (WindowData*)event.GetClientData();
2307 if (WData->DataType == 0){
2311 int intID = mnuContactWindows->GetId();
2313 mnuWindow->FindChildItem(intID, &pos);
2314 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2315 mnuNewItem->SetId(WData->WindowID);
2316 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2317 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2318 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2319 mnuWindow->Insert((pos + 1), mnuNewItem);
2320 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2322 } else if (WData->DataType == 1){
2324 // Contact Editor Window
2326 int intID = mnuContactEditorWindows->GetId();
2328 mnuWindow->FindChildItem(intID, &pos);
2329 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2330 mnuNewItem->SetId(WData->WindowID);
2331 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2332 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2333 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2334 mnuWindow->Insert((pos + 1), mnuNewItem);
2335 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2337 } else if (WData->DataType == 2){
2341 int intID = mnuSearchWindows->GetId();
2343 mnuWindow->FindChildItem(intID, &pos);
2344 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2345 mnuNewItem->SetId(WData->WindowID);
2346 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2347 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2348 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2349 mnuWindow->Insert((pos + 1), mnuNewItem);
2350 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2359 void frmMain::WindowEdit( wxCommandEvent &event ){
2361 // Edit a window in the window list.
2363 WindowData *WData = (WindowData*)event.GetClientData();
2365 if (WData->DataType == 0){
2367 // Get the window title and use that.
2369 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2371 wxString WindowTitle = frmContactPtr->GetTitle();
2373 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2375 MenuIter->second->SetItemLabel(WindowTitle);
2377 } else if (WData->DataType == 1){
2379 // Get the window title and use that.
2381 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2383 wxString WindowTitle = frmCEPtr->GetTitle();
2385 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2387 if (WindowTitle.IsEmpty()){
2389 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2393 MenuIter->second->SetItemLabel(WindowTitle);
2404 void frmMain::WindowDelete( wxCommandEvent &event ){
2406 // Delete a window from the window list.
2408 WindowData *WData = (WindowData*)event.GetClientData();
2410 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2412 mnuWindow->Remove(MenuIter->second);
2414 delete MenuIter->second;
2415 MenuIter->second = NULL;
2417 WindowListPointersMenu.erase(WData->WindowID);
2418 WindowListPointers.erase(WData->WindowID);
2419 WindowListType.erase(WData->WindowID);
2426 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2428 // Show a contact window from the window list.
2430 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2432 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2434 frmContactPtr->Show();
2435 frmContactPtr->Raise();
2439 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2441 // Show a contact editor window from the window list.
2443 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2445 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2452 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2454 // Show a search window from the window list.
2456 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2458 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2460 frmSearchPtr->Show();
2461 frmSearchPtr->Raise();
2465 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2467 // Toggle the online/offline connection status.
2469 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2470 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2471 wxPostEvent(frameActMgr, toggconn);
2475 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2477 // Check the account type before continuing.
2479 wxString SeekAccount;
2480 wxString AccTypeLower;
2483 std::map<int, SSLCertCollection>::iterator SSLColIter;
2485 for (int i = 0; i < prefaccounts.GetCount(); i++){
2487 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2488 AccType.Append(prefaccounts.GetAccountType(i));
2489 AccountSSL = prefaccounts.GetAccountSSL(i);
2490 AccTypeLower = AccType.MakeLower();
2491 SeekAccount.Append(wxT("."));
2492 SeekAccount.Append(AccTypeLower);
2494 if (SeekAccount == ActiveAccount){
2496 if (AccTypeLower == wxT("local")){
2502 if (AccountSSL == false){
2508 SSLColIter = AccountSSLData.find(i);
2510 SSLCertCollection SSLCertInfo = SSLColIter->second;
2512 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2513 frameSSLCert->StartCertFrom(0);
2514 frameSSLCert->SetupCerts(SSLCertInfo);
2515 frameSSLCert->ShowModal();
2517 delete frameSSLCert;
2518 frameSSLCert = NULL;
2522 SeekAccount.Clear();
2523 AccTypeLower.Clear();
2530 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2532 // Check the account type before continuing.
2536 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2538 // Check the account type before continuing.
2542 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2544 if (event.GetInt() == 0){
2546 imgConnStatus->SetBitmap(*imgOnline);
2550 imgConnStatus->SetBitmap(*imgOffline);
2556 void frmMain::SetupSSLStatus( int AccountID ){
2558 // Check if account ID given is
2559 // the active account and if not, do nothing.
2562 wxString AccTypeLower;
2564 AccType = prefaccounts.GetAccountType(AccountID);
2565 AccTypeLower = AccType.MakeLower();
2567 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2570 if (AccountIDName != ActiveAccount){
2576 // Check if the account has SSL enabled.
2578 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2580 if (SSLInUse == FALSE){
2582 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2583 imgSSLStatus->SetBitmap(*imgNoSSL);
2587 // Get the SSL Collection Data.
2589 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2591 if (SSLResultIter->second == 1){
2593 imgSSLStatus->SetBitmap(*imgSSLWarning);
2594 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2595 prefaccounts.GetAccountName(AccountID) +
2596 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2598 } else if (SSLResultIter->second == 0){
2600 imgSSLStatus->SetBitmap(*imgSSL);
2601 SSLToolTip->SetTip(wxT("Account '") +
2602 prefaccounts.GetAccountName(AccountID) +
2603 wxT("' secured using SSL\n\nDouble click for more information."));
2611 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2613 // Display the form for showing an invalid SSL certificate.
2615 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2616 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2617 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2618 wxString AccountName = SSLICNObj->AccountName;
2619 frameISC->LoadData(SSLCCData, AccountName);
2620 frameISC->ShowModal();
2622 int FinalConflictResult = frameISC->GetResult();
2624 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2625 event2.SetClientData(SSLICNObj->QRNotifData);
2626 event2.SetInt(FinalConflictResult);
2631 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2632 wxPostEvent(frameActMgr, event2);
2635 void frmMain::PauseAllTimers(){
2637 // Pause all the account timers.
2639 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2640 ASTiter != AccountSyncTimers.end(); ASTiter++){
2642 ASTiter->second->Stop();
2648 void frmMain::ResumeAllTimers(){
2650 // Resume all the account timers.
2652 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2653 ASTiter != AccountSyncTimers.end(); ASTiter++){
2655 ASTiter->second->Start();
2661 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2663 // Delete existing data.
2665 AccountSSLData.erase(AccountID);
2666 AccountSSLResult.erase(AccountID);
2670 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2671 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2675 void frmMain::CheckUpdates( wxCommandEvent& event ){
2677 // Check for updates to Xestia Address Book.
2679 frmUpdate *frameUpdate = new frmUpdate ( this );
2680 frameUpdate->FetchData();
2681 frameUpdate->ShowModal();
2685 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2687 // Run the import contacts function.
2693 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2695 // Check if an account and at least one contact is selected
2696 // before continuing.
2698 wxArrayString ArrData;
2700 if (ActiveAccount.IsEmpty()){
2706 int ContactSelected = 0;
2707 int ContactsCollected = 0;
2708 long longSelected = -1;
2712 longSelected = lstContacts->GetNextItem(longSelected,
2714 wxLIST_STATE_SELECTED);
2716 if (longSelected == -1){
2722 int FileID = (int)lstContacts->GetItemData(longSelected);
2724 ArrData.Insert(ContactsFileIndex[FileID],
2725 ContactsCollected, 1);
2731 if (ContactSelected == 0){
2737 // Run the export contacts system.
2739 ExportRun(this, &ArrData);
2743 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2744 wxArrayString *ContactsFileIndexPtr){
2746 // Set the list control pointers.
2748 lstContactsPtr = lstContacts;
2749 ContactsFileIndexPtr = &ContactsFileIndex;
2753 void frmMain::GetSelectedList( wxCommandEvent& event ){
2755 // Get the array of contact filenames.
2757 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2759 // Process them into an array of files.
2761 long longSelected = -1;
2762 int ContactsCollected = 0;
2763 wxString ContactFilename;
2767 longSelected = lstContacts->GetNextItem(longSelected,
2769 wxLIST_STATE_SELECTED);
2771 if (longSelected == -1){
2777 // Get the file information and add to the list.
2779 int FileID = (int)lstContacts->GetItemData(longSelected);
2781 ArrData->Insert(ContactsFileIndex[FileID],
2782 ContactsCollected, 1);
2784 ContactsCollected++;
2785 ContactFilename.Clear();
2793 void frmMain::SyncAccount( wxCommandEvent& event ){
2795 // Syncronise the selected account.
2797 wxString AccNameInc = event.GetString();
2799 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2800 frameActMgr->AddTask(3, wxT(""), AccNameInc,
2801 wxT(""), wxT(""), wxT(""), wxT(""));
2805 void frmMain::ShowHelp( wxCommandEvent& event ){
2807 // Based on the operating system, work out where
2808 // the documentation should be.
2812 #if defined(__HAIKU__)
2814 #elif defined(__WIN32__)
2820 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2822 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2825 #if XSDAB_RELEASE == 0
2827 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2829 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2838 #if XSDAB_RELEASE == 0
2840 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2844 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!"));
2850 void frmMain::ShowImportResults( wxCommandEvent &event ){
2852 // Show the results of importing contacts.
2854 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2856 frmImportResults *frmIR = new frmImportResults(this);
2857 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
2868 void frmMain::ReloadContactList( wxCommandEvent &event ){
2870 // Check if the account name given is the current
2871 // account selected.
2873 if (ActiveAccount == event.GetString()){
2875 wxTreeEvent NullEvent;
2876 LoadContactList(NullEvent);
2882 void frmMain::ShowContactMenu( wxMouseEvent& event ){
2884 // Show the contact menu when a right click occurs
2885 // in the contacts list.
2887 bool EnableRefresh = FALSE;
2889 if (!ActiveAccount.IsEmpty()){
2891 EnableRefresh = TRUE;
2895 ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
2897 this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
2901 void frmMain::ResetContactInfo(){
2903 // Reset the contact information to an empty page.
2905 wxString EmptyPage = wxT("");
2906 htmContactData->SetPage(EmptyPage);
2907 AccCtrl->SetValue("");