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_EVENT_TYPE(CE_UPDATECONTACTLIST);
67 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
68 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
69 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
70 DEFINE_EVENT_TYPE(CE_OPENCONTACTLIST);
71 DEFINE_EVENT_TYPE(CE_NEWCONTACT);
72 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
73 DEFINE_EVENT_TYPE(CE_DELETECONTACT);
74 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
75 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
76 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
77 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
78 DEFINE_EVENT_TYPE(ACTMGR_START);
79 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
80 DEFINE_EVENT_TYPE(ACTMGR_STOP);
81 DEFINE_EVENT_TYPE(WINDOW_ADD);
82 DEFINE_EVENT_TYPE(WINDOW_EDIT);
83 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
84 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
85 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
86 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
87 DEFINE_EVENT_TYPE(SYNCACCOUNT);
88 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
89 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
90 DEFINE_EVENT_TYPE(REFRESHADDRESSBOOK);
92 BEGIN_EVENT_TABLE(frmMain, wxFrame)
93 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
94 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
95 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
96 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
97 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
98 EVT_COMMAND(wxID_ANY, CE_OPENCONTACTLIST, frmMain::OpenContactInfoList)
99 EVT_COMMAND(wxID_ANY, CE_NEWCONTACT, frmMain::ShowContactEditorNew)
100 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
101 EVT_COMMAND(wxID_ANY, CE_DELETECONTACT, frmMain::DeleteContact)
102 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
103 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
104 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
105 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
106 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
107 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
108 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
109 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
110 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
111 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
112 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
113 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
114 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
115 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
116 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
117 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
120 frmMain::frmMain( wxWindow* parent )
125 // Setup the account icons.
127 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
128 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
129 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
130 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
132 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
133 wxBitmap AccInet(icons_accinet_png, -1);
135 wxIAccInet.CopyFromBitmap(AccInet);
137 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
138 wxBitmap AccNIcon(icons_acclocal_png, -1);
140 wxIAccNIcon.CopyFromBitmap(AccNIcon);
142 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
143 wxBitmap AccGrp(icons_accgroup_png, -1);
145 wxIAccGrp.CopyFromBitmap(AccGrp);
147 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
148 wxBitmap AccNone(icons_accnone_png, -1);
150 wxIAccNone.CopyFromBitmap(AccNone);
152 AccountID = AccImgList->Add(wxIAccNIcon);
153 AccountNetID = AccImgList->Add(wxIAccInet);
154 AccountGrpID = AccImgList->Add(wxIAccGrp);
155 AccountNoneID = AccImgList->Add(wxIAccNone);
157 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
159 // Setup the status bar icons.
163 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
164 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
165 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
167 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
168 imgSSL = new wxBitmap(icons_ssl_png, -1);
170 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
171 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
173 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
174 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
178 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
179 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
180 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
181 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
182 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
184 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
185 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
187 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
188 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
190 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
192 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
193 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
195 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
197 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
198 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
200 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
202 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
203 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
205 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
207 // Online/Offline icons.
209 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
210 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
212 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
213 imgOnline = new wxBitmap(icons_online_png, -1);
215 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
216 imgOffline = new wxBitmap(icons_offline_png, -1);
218 // Setup the account view.
220 AccCtrl->SetPopupControl(treAccounts);
221 AccCtrl->SetPopupMaxHeight(175);
222 AccCtrl->SetPopupMinWidth(250);
223 treAccounts->AssignImageList(AccImgList);
225 wxListItem ColumnData;
227 ColumnData.SetText(wxT("Name0"));
228 ColumnData.SetWidth(320);
229 lstContacts->InsertColumn(0, ColumnData);
231 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
232 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
234 #if defined(__HAIKU__)
236 #elif defined(__WIN32__)
238 int stbBottomData [4] = { -1, 8, 8, 8 };
242 int stbBottomData [4] = { -1, 20, 20, 20 };
246 stbBottom->SetFieldsCount(4, stbBottomData);
247 stbBottom->SetMinHeight(16);
252 stbBottom->GetFieldRect(1, rectOnline);
253 stbBottom->GetFieldRect(2, rectSSL);
254 stbBottom->GetFieldRect(3, rectActivity);
256 SSLToolTip = new wxToolTip(wxT(""));
258 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
259 imgConnStatus->SetBitmap(*imgOnline);
260 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
262 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
263 imgSSLStatus->SetBitmap(*imgNoSSL);
264 imgSSLStatus->SetToolTip(SSLToolTip);
265 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
267 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
268 imgActivityStatus->SetBitmap(*imgActIconSleep);
269 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
271 // Setup the window menu.
273 // By default should be:
278 // Contact editor windows:
284 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
285 mnuWindow->Append( mnuContactWindows );
287 mnuWindow->AppendSeparator();
289 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
290 mnuWindow->Append( mnuContactEditorWindows );
292 mnuWindow->AppendSeparator();
294 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
295 mnuWindow->Append( mnuSearchWindows );
297 #if defined(__WIN32__)
302 mnuContactWindows->SetFont(fontstyle);
303 mnuContactEditorWindows->SetFont(fontstyle);
304 mnuSearchWindows->SetFont(fontstyle);
308 mnuContactWindows->Enable(FALSE);
309 mnuContactEditorWindows->Enable(FALSE);
310 mnuSearchWindows->Enable(FALSE);
314 // Hide unimplemented functions.
320 void frmMain::QuitApp( wxCloseEvent& event )
327 void frmMain::QuitApp( wxCommandEvent& event )
334 void frmMain::QuitApp()
336 //-------------------------------------------------------------------
337 // frmMain::QuitApp: Quits the application by simply closing this
338 // window which causes the exit as frmMain is the main window.
340 // wxCommandEvent Accepts a referenced event command.
341 //-------------------------------------------------------------------
343 //-------------------------------------------------------------------
344 // frmMain::QuitApp: Quits the application by simply closing this
345 // window which causes the exit as frmMain is the main window.
347 // wxCommandEvent Accepts a referenced event command.
348 //-------------------------------------------------------------------
350 //Go through the windows and close each one (be it search
351 //or contact editor). Abort if user wants to cancel.
353 // Close the contact editor windows.
355 // Close the contact windows.
357 // Close the search windows.
359 // Write out the ETag databases.
361 // Save Preferences: Save the window position if that option is enabled.
363 wxString SetFilename = GetUserPrefDir();
365 #if defined(__HAIKU__)
369 #elif defined(__WIN32__)
371 SetFilename.Append(wxT("settings"));
377 SetFilename.Append(wxT("settings"));
381 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
383 bool SaveWindowPos = FALSE;
384 wxString SaveWindowInc;
385 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
387 if (SaveWindowInc == wxT("true")){
389 SaveWindowPos = TRUE;
393 if (SaveWindowPos == TRUE){
395 wxRect frmMainPos = this->GetRect();
397 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
398 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
399 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
400 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
408 //Everything closed... exit.
416 void frmMain::ShowActivityWindow( wxCommandEvent& event )
419 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
420 frameActMgr->OpenWindow();
425 void frmMain::ShowAboutWindow( wxCommandEvent& event )
427 //-------------------------------------------------------------------
428 // frmMain::ShowAboutWindow: Shows the About window as a modal
429 // dialog and then cleans up when finished.
431 // wxCommandEvent Accepts a referenced event command.
432 //-------------------------------------------------------------------
434 frmAbout *frameAbout = new frmAbout ( this );
435 frameAbout->SetupAboutWindow();
436 frameAbout->ShowModal();
442 void frmMain::OpenPreferences( wxCommandEvent& event)
444 //-------------------------------------------------------------------
445 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
446 // dialog and then cleans up when finished.
448 // wxCommandEvent Accepts a referenced event command.
449 //-------------------------------------------------------------------
451 ReloadAccounts = FALSE;
453 frmPreferences *framePreferences = new frmPreferences ( this );
454 framePreferences->SetupPointers(&ReloadAccounts);
455 framePreferences->ShowModal();
456 delete framePreferences;
457 framePreferences = NULL;
459 if (ReloadAccounts == TRUE){
461 // Reload the accounts as a change has been made within
462 // the application and clear the current contact information.
464 this->LoadPreferences();
465 this->ResetContactInfo();
471 void frmMain::OpenNewABDialog( wxCommandEvent& event)
473 //-------------------------------------------------------------------
474 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
475 // dialog and then cleans up when finished.
477 // wxCommandEvent Accepts a referenced event command.
478 //-------------------------------------------------------------------
480 ReloadAccounts = FALSE;
482 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
483 frameNewAccount->SetupPointers(&ReloadAccounts);
484 frameNewAccount->ShowModal();
485 delete frameNewAccount;
486 frameNewAccount = NULL;
488 if (ReloadAccounts == TRUE){
490 // Reload the accounts as a change has been made within
493 this->LoadPreferences();
499 void frmMain::LoadContactList( wxTreeEvent& event )
502 // Clear all existing variables.
504 lstContacts->DeleteAllItems();
506 treAccounts->SetAccount();
508 wxTreeItemIdValue cookie;
509 wxTreeItemId next = treAccounts->GetRootItem();
510 wxString AccountName;
511 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
512 wxString AccountDirCmb;
513 long selectedaccount = 0;
515 wxTreeItemId selectedChild = treAccounts->GetSelection();
516 wxTreeItemId nextChild;
518 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
519 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
521 int SCImg = treAccounts->GetItemImage(selectedChild);
522 int AccountIndex = 0;
524 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
526 for (int i = 0; i < prefaccounts.GetCount(); i++){
528 if (ActiveItemIcon == 2){
530 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
531 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
532 int ActiveAccountG = AGLiter->second;
534 if (i == ActiveAccountG){
536 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
537 AccountType.Append(prefaccounts.GetAccountType(i));
542 if (AccountType == wxT("CardDAV")){
543 AccountTypeFinal.Append(wxT("carddav"));
545 else if (AccountType == wxT("Local")){
546 imgSSLStatus->SetBitmap(*imgOffline);
547 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
548 AccountTypeFinal.Append(wxT("local"));
559 nextChild = treAccounts->GetFirstChild(next, cookie);
562 nextChild = treAccounts->GetNextSibling(nextChild);
565 AccountName = treAccounts->GetItemText(nextChild);
567 if (nextChild == selectedChild){
568 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
569 AccountType.Append(prefaccounts.GetAccountType(i));
574 if (AccountType == wxT("CardDAV")){
575 AccountTypeFinal.Append(wxT("carddav"));
577 else if (AccountType == wxT("Local")){
578 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
579 AccountTypeFinal.Append(wxT("local"));
588 if (selectedaccount >= prefaccounts.GetCount()){
590 // The account selected isn't there so return.
598 // Open the directory and get the list of .vcf files
599 // in that directory.
601 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
602 ActiveAccountType = AccountType;
604 SetupSSLStatus(AccountIndex);
606 AccountDirFinal.Clear();
607 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
609 ContactsFileIndex.Clear();
611 wxString vCardFilename;
612 wxString vCardFilenameFull;
613 wxString vCardDataString;
614 wxStringTokenizer vcardfileline;
616 wxString setname, setvalue;
617 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
618 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
619 long ContactIndex = 1;
620 long ContactSeekPoint = 0;
622 wxDir vcardaccdir(AccountDirFinal);
624 // Get the wxTreeItemId and image icon and compare it to the list.
626 if (ActiveItemIcon == AccountGrpID){
628 // It's a group so load the file containing the group and
629 // get the members of the group.
634 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
635 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
637 Group.LoadFile(AGFiter->second);
639 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
641 for (int i = 0; i < vCardMember.PropCount; i++){
643 vCardMember.PropValues[i].Trim();
644 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
646 wxString NewPropValue;
647 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
648 vCardMember.PropValues[i] = NewPropValue;
655 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
658 if (vCardFilename.Right(4) == wxT(".vcf") ||
659 vCardFilename.Right(4) == wxT(".VCF") ||
660 vCardFilename.Right(5) == wxT(".vcard") ||
661 vCardFilename.Right(5) == wxT(".VCARD")){
664 bool FoundMember = FALSE;
666 vCardFilenameFull.Append(AccountDirFinal);
667 vCardFilenameFull.Append(wxT("/"));
668 vCardFilenameFull.Append(vCardFilename);
670 Person.LoadFile(vCardFilenameFull);
672 UIDCode = Person.Get(wxT("UID"));
674 for (int i = 0; i < vCardMember.PropCount; i++){
676 if (vCardMember.PropValues[i] == UIDCode){
684 if (FoundMember == FALSE){
686 vCardFilename.Clear();
687 vCardFilenameFull.Clear();
688 vCardDataString.Clear();
689 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
694 if (Person.MeetBaseSpecification()){
698 // Split the name into sections.
700 vCardDataString = Person.Get(wxT("N"));
702 vCardName NameData = Person.GetName();
704 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
706 } else if (SortMode == 2){
708 // Split the name into sections.
710 vCardName NameData = Person.GetName();
712 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
714 } else if (SortMode == 3){
716 // Check and make sure that the top most nickname is used.
718 vCardDataString = Person.Get(wxT("NICKNAME"));
720 if (vCardDataString.IsEmpty()){
722 vCardDataString = wxT("(no nickname)");
726 } else if (SortMode == 4){
728 vCardDataString = Person.Get(wxT("FN"));
732 if (AscendingMode == TRUE){
733 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
735 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
744 vCardFilename.Clear();
745 vCardFilenameFull.Clear();
746 vCardDataString.Clear();
747 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
752 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
755 if (vCardFilename.Right(4) == wxT(".vcf") ||
756 vCardFilename.Right(4) == wxT(".VCF") ||
757 vCardFilename.Right(5) == wxT(".vcard") ||
758 vCardFilename.Right(5) == wxT(".VCARD")){
762 vCardFilenameFull.Append(AccountDirFinal);
763 vCardFilenameFull.Append(vCardFilename);
765 Person.LoadFile(vCardFilenameFull);
767 if (Person.MeetBaseSpecification()){
771 // Split the name into sections.
773 vCardDataString = Person.Get(wxT("N"));
775 vCardName NameData = Person.GetName();
777 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
779 } else if (SortMode == 2){
781 // Split the name into sections.
783 vCardName NameData = Person.GetName();
785 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
787 } else if (SortMode == 3){
789 // Check and make sure that the top most nickname is used.
791 vCardDataString = Person.Get(wxT("NICKNAME"));
793 if (vCardDataString.IsEmpty()){
795 vCardDataString = wxT("(no nickname)");
799 } else if (SortMode == 4){
801 vCardDataString = Person.Get(wxT("FN"));
805 if (AscendingMode == TRUE){
806 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
808 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
817 vCardFilename.Clear();
818 vCardFilenameFull.Clear();
819 vCardDataString.Clear();
820 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
827 // Insert the data into the control.
829 if (AscendingMode == TRUE){
830 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
831 iter != vCardNamesAsc.end(); ++iter){
833 wxListItem ContactInfo;
835 ContactInfo.SetId(0);
836 ContactInfo.SetText(_("Mooo"));
837 ContactInfo.SetData(ContactSeekPoint);
838 ContactIndex = lstContacts->InsertItem(ContactInfo);
840 lstContacts->SetItem(ContactIndex, 0, iter->first);
841 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
848 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
849 iter != vCardNamesDsc.end(); ++iter){
851 wxListItem ContactInfo;
853 ContactInfo.SetId(0);
854 ContactInfo.SetText(_("Mooo"));
855 ContactInfo.SetData(ContactSeekPoint);
856 ContactIndex = lstContacts->InsertItem(ContactInfo);
858 lstContacts->SetItem(ContactIndex, 0, iter->first);
859 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
868 void frmMain::ShowContactInfo( wxListEvent& event )
871 long intSelected = -1;
872 long ContactSeekNum = -1;
874 // Check if several contacts have been selected.
876 int ContactTotal = 0;
880 intSelected = lstContacts->GetNextItem(intSelected,
882 wxLIST_STATE_SELECTED);
884 if (intSelected == -1){
894 if (ContactTotal == 0){
895 htmContactData->SetPage(wxT(""));
899 if (ContactTotal > 1){
901 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
902 ActiveFilename.Clear();
907 intSelected = lstContacts->GetNextItem(intSelected,
909 wxLIST_STATE_SELECTED);
911 ContactSeekNum = lstContacts->GetItemData(intSelected);
914 wxString wxSContactString;
915 wxString ContactLine;
918 size_t ContactLineLen;
919 bool ExtraLineSeek = FALSE;
920 int QuoteBreakPoint = 0;
922 bool PropertyFind = FALSE;
923 bool QuoteMode = FALSE;
925 wxString wxSPropertyNextLine;
926 wxString wxSProperty;
927 wxString wxSPropertySeg1;
928 wxString wxSPropertySeg2;
930 // Check if we are using wxWidgets version 2.8 or less and
931 // execute the required command accordingly.
933 #if wxABI_VERSION < 20900
934 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
936 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
939 if (ContactFile.IsOpened() == FALSE){
945 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
949 std::map<int, wxString> ContactFileLines;
950 std::map<int, wxString>::iterator striter;
952 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
954 int ContactLineSeek = 0;
956 while (wSTContactFileLines.HasMoreTokens() == TRUE){
958 ContactLine = wSTContactFileLines.GetNextToken();
959 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
964 if (ContactSeekNum < 0){
968 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
969 iter != ContactFileLines.end(); ++iter){
971 // Find the colon which splits the start bit from the data part.
973 ContactLine = iter->second;
975 while (ExtraLineSeek == TRUE){
977 // Check if there is extra data on the next line
978 // (indicated by space or tab at the start) and add data.
982 if (iter == ContactFileLines.end()){
989 wxSPropertyNextLine = iter->second;
992 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
994 wxSPropertyNextLine.Remove(0, 1);
995 ContactLine.Append(wxSPropertyNextLine);
1000 ExtraLineSeek = FALSE;
1006 ContactLineLen = ContactLine.Len();
1008 // Make sure we are not in quotation mode.
1009 // Make sure colon does not have \ or \\ before it.
1011 for (int i = 0; i <= ContactLineLen; i++){
1013 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1015 PropertyFind = FALSE;
1017 } else if (PropertyFind == TRUE){
1019 wxSProperty.Append(ContactLine.Mid(i, 1));
1023 if (ContactLine.Mid(i, 1) == wxT("\"")){
1025 if (QuoteMode == TRUE){
1037 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1039 QuoteBreakPoint = i;
1046 // Split that line at the point into two variables (ignore the colon).
1048 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1049 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1051 // Insert both into the vCard data file.
1053 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1056 PropertyFind = TRUE;
1057 ExtraLineSeek = TRUE;
1059 QuoteBreakPoint = 0;
1060 ContactLine.Clear();
1061 wxSProperty.Clear();
1065 OldSessionID = SessionID;
1066 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1067 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1068 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1072 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1075 // Check if there is an account selected and if not
1076 // return immediately.
1078 if (ActiveAccount.IsEmpty()){
1084 // Add Pointer to SetupPointers for the ETagDB.
1086 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1087 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1088 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1090 contacticon.CopyFromBitmap(contacticonbmp);
1092 frmContactEditor *ContactEditor = new frmContactEditor( this );
1096 ContactEditor->SetUID(WindowMenuItemID);
1098 WindowData *WData = new WindowData;
1100 WData->DataType = 1;
1101 WData->WindowPointer = (void*)ContactEditor;
1102 WData->WindowID = WindowMenuItemID;
1104 wxCommandEvent addevent(WINDOW_ADD);
1105 addevent.SetClientData(WData);
1106 wxPostEvent(this, addevent);
1108 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1109 ContactEditor->SetupHeaders();
1110 ContactEditor->SetupContact(ActiveAccount);
1111 ContactEditor->SetIcon(contacticon);
1112 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1113 ContactEditor->Show(true);
1117 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1120 // Check if there is an account selected and if not
1121 // return immediately.
1123 int DataCheck = event.GetInt();
1125 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1131 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1132 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1133 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1135 contacticon.CopyFromBitmap(contacticonbmp);
1137 // Check if a contact has been selected.
1139 long intSelected = -1;
1140 long intContactSeekNum = -1;
1142 intSelected = lstContacts->GetNextItem(intSelected,
1144 wxLIST_STATE_SELECTED);
1146 if (intSelected == -1){
1150 intContactSeekNum = lstContacts->GetItemData(intSelected);
1152 // Get the filename of the selected contact.
1154 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1155 frmContactEditor *ContactEditor = new frmContactEditor( this );
1159 ContactEditor->SetUID(WindowMenuItemID);
1161 WindowData *WData = new WindowData;
1163 WData->DataType = 1;
1164 WData->WindowPointer = (void*)ContactEditor;
1165 WData->WindowID = WindowMenuItemID;
1167 wxCommandEvent addevent(WINDOW_ADD);
1168 addevent.SetClientData(WData);
1169 wxPostEvent(this, addevent);
1171 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1172 ContactEditor->SetupHeaders();
1174 // Check if pointer is NULL (not from the search forms) or not.
1176 if (DataCheck == 0){
1178 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1179 ContactEditor->SetupContact(ActiveAccount);
1183 UCNotif *uc = (UCNotif*)event.GetClientData();
1187 ContactEditor->SetupContact(ActiveAccount);
1188 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1192 ContactEditor->SetupContact(uc->ContactAccount);
1193 ContactEditor->LoadContact(uc->ContactFilename);
1203 ContactEditor->SetIcon(contacticon);
1204 ContactEditor->Show(true);
1208 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
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 wxStringTokenizer vcardfileline;
1239 wxString setname, setvalue;
1243 long intSelected = -1;
1244 long intContactSeekNum = -1;
1246 intSelected = lstContacts->GetNextItem(intSelected,
1248 wxLIST_STATE_SELECTED);
1250 intContactSeekNum = lstContacts->GetItemData(intSelected);
1252 if (intContactSeekNum == -1){
1256 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1258 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1259 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1260 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1262 contacticon.CopyFromBitmap(contacticonbmp);
1264 frmContact *Contact = new frmContact( this );
1266 // Add to window list.
1270 Contact->SetUID(WindowMenuItemID);
1272 WindowData *WData = new WindowData;
1274 WData->DataType = 0;
1275 WData->WindowPointer = (void*)Contact;
1276 WData->WindowID = WindowMenuItemID;
1278 wxCommandEvent addevent(WINDOW_ADD);
1279 addevent.SetClientData(WData);
1280 wxPostEvent(this, addevent);
1282 Contact->SetupPointers(&MemoryFileList);
1283 Contact->SetupContactData(&Person);
1285 Contact->SetIcon(contacticon);
1286 Contact->Show(true);
1290 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1293 OpenContactInfoList(pevent);
1297 void frmMain::OpenContactInfo( wxCommandEvent& event )
1300 UCNotif *uc = (UCNotif*)event.GetClientData();
1302 wxStringTokenizer vcardfileline;
1305 wxString setname, setvalue;
1309 Person.LoadFile(uc->ContactFilename);
1311 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1312 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1313 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1315 contacticon.CopyFromBitmap(contacticonbmp);
1317 frmContact *Contact = new frmContact( this );
1319 // Add to window list.
1323 Contact->SetUID(WindowMenuItemID);
1325 WindowData *WData = new WindowData;
1327 WData->DataType = 0;
1328 WData->WindowPointer = (void*)Contact;
1329 WData->WindowID = WindowMenuItemID;
1331 wxCommandEvent addevent(WINDOW_ADD);
1332 addevent.SetClientData(WData);
1333 wxPostEvent(this, addevent);
1335 Contact->SetupPointers(&MemoryFileList);
1336 Contact->SetupContactData(&Person);
1338 Contact->SetIcon(contacticon);
1339 Contact->Show(true);
1344 void frmMain::LoadPreferences( wxActivateEvent& event)
1346 this->LoadPreferences();
1349 void frmMain::LoadPreferences(){
1351 // Load the preferences.
1353 wxString preffilename = GetUserPrefDir();
1355 XABPreferences preferences(preffilename);
1357 // Setup the main window position (if needed).
1359 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1360 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1362 if (SaveWindowPos == TRUE){
1364 this->SetSize(preferences.GetMainWindowData());
1368 treAccounts->DeleteAllItems();
1370 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1372 // Stop all account timers and remove the accounts.
1374 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1375 iter != AccountSyncTimers.end(); iter++){
1377 wxAccountSyncTimer *AccTmrPtr = iter->second;
1385 AccountSyncTimers.clear();
1388 wxString AccDirFull;
1389 wxString AccDirFullSfx;
1391 wxString AccDirFinal;
1392 AccountAccDirList.clear();
1393 AccountGroupList.clear();
1394 AccountGroupFilename.clear();
1395 AccountGroupTreeId.clear();
1396 wxTreeItemId AccountTreeId;
1397 wxTreeItemId GroupTreeId;
1400 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1402 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1403 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1409 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1415 AccDir = preferences.accounts.GetAccountDirectory(i);
1416 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1418 AccDirFull.Append(wxT("."));
1419 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1420 AccDirFullSfx.LowerCase();
1421 AccDirFullSfx.Trim();
1422 AccDirFull.Append(AccDirFullSfx);
1423 AccName = preferences.accounts.GetAccountName(i);
1425 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1427 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1428 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1430 // TODO: Check if the directory exists before doing anything.
1434 // Add a new timer using the existing account details.
1436 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1438 ActTmrPtr->SetupData(AccDirFull, AccName);
1439 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1440 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1441 ActTmrPtr->SetOwner(this);
1442 ActTmrPtr->Notify();
1444 // Add the timer to the list of timers.
1446 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1448 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1452 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1456 // Go through the account directory and find contact files with
1457 // 'KIND:group' set and add them to the list of groups for the account.
1459 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1461 wxDir vcardaccdir(AccDirFinal);
1463 wxString vCardFilename;
1464 wxString vCardDataString;
1465 wxString vCardFilenameFull;
1467 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1470 if (vCardFilename.Right(4) == wxT(".vcf") ||
1471 vCardFilename.Right(4) == wxT(".VCF") ||
1472 vCardFilename.Right(5) == wxT(".vcard") ||
1473 vCardFilename.Right(5) == wxT(".VCARD")){
1477 vCardFilenameFull.Append(AccDirFinal);
1478 vCardFilenameFull.Append(wxT("/"));
1479 vCardFilenameFull.Append(vCardFilename);
1481 Person.LoadFile(vCardFilenameFull);
1483 if (Person.MeetBaseSpecification()){
1485 vCardDataString = Person.Get(wxT("KIND"));
1487 if (vCardDataString == wxT("group")){
1489 // The vCard kind is a group. Add to the account's group list.
1491 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1492 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1493 AccountGroupList.insert(std::make_pair(intGroupID, i));
1494 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1495 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1507 vCardFilename.Clear();
1508 vCardFilenameFull.Clear();
1509 vCardDataString.Clear();
1510 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1514 // Clearup for next account.
1518 AccDirFullSfx.clear();
1519 AccDirFinal.clear();
1524 // Load the account settings as they are needed for connecting
1527 prefaccounts = preferences.accounts;
1531 void frmMain::ConflictResolution(wxCommandEvent& event){
1533 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1534 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1535 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1536 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1537 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1538 frameCR->ShowModal();
1540 int FinalConflictResult = frameCR->GetResult();
1542 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1543 event2.SetClientData(vCardConfObj->QRNotifData);
1544 event2.SetInt(FinalConflictResult);
1549 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1550 wxPostEvent(frameActMgr, event2);
1554 void frmMain::UpdateContactList(wxCommandEvent& event){
1556 UCNotif *ucd = (UCNotif*)event.GetClientData();
1558 // Check if the active account is being displayed in the
1559 // main window. If not, skip and delete the data.
1561 long longSelected = -1;
1562 int intSelectedData = 0;
1564 if (ActiveAccount == ucd->ContactAccount){
1566 // Look at the list of contacts and if it matches the
1567 // filename then update the name.
1571 longSelected = lstContacts->GetNextItem(longSelected,
1573 wxLIST_STATE_DONTCARE);
1575 if (longSelected == -1){
1581 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1583 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1585 // Work out which sorting mode we are in.
1589 // First Name, Last Name.
1591 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1593 } else if (SortMode == 2){
1595 // Last Name, First Name.
1597 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1599 } else if (SortMode == 3){
1603 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1605 } else if (SortMode == 4){
1609 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1616 // If the filename is the one loaded into the
1617 // browser control, then update this too.
1619 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1621 wxListEvent nullevent;
1622 ShowContactInfo(nullevent);
1630 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1631 WindowIter != WindowListPointers.end(); WindowIter++){
1633 if (WindowListType[WindowIter->first] != 0){
1639 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1641 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1643 vCard UpdatedPerson;
1644 UpdatedPerson.LoadFile(ucd->ContactFilename);
1645 frmContactPtr->SetupContactData(&UpdatedPerson);
1651 // Send message to search window controller subroutine and
1652 // pass that notification onto the search windows.
1654 // Setup the new pointer to use the existing UCNotif without
1657 UCNotif *ucd2 = ucd;
1659 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1660 sup.SetClientData(ucd2);
1661 wxPostEvent(this, sup);
1663 // Clear up the unused pointer.
1669 void frmMain::UpdateAccountList(wxCommandEvent& event){
1673 void frmMain::SetupPointers(void *ActMgrPtrInc){
1675 ActMgrPtr = ActMgrPtrInc;
1679 void frmMain::SetupForm(){
1681 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1682 frameActMgr->SetupPointers(&ETagProcTimer, this);
1684 // Setup the contact information icons for later.
1686 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1690 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1691 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1692 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1694 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1695 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1696 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1698 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1699 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1700 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1702 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1703 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1704 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1706 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1707 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1708 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1710 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1711 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1712 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1718 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1720 // Go through each of the search windows and
1721 // send the required notification to update the
1722 // contact information.
1724 // Get the event notification data.
1726 UCNotif *ucd = (UCNotif*)event.GetClientData();
1728 // Process each search window giving the new details.
1730 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1731 switer != SearchWindowList.end(); switer++){
1733 // Duplicate the event notification data.
1735 UCNotif *ucd2 = new UCNotif;
1737 ucd2->ContactAccount = ucd->ContactAccount;
1738 ucd2->ContactFilename = ucd->ContactFilename;
1739 ucd2->ContactName = ucd->ContactName;
1740 ucd2->ContactNickname = ucd->ContactNickname;
1741 ucd2->ContactNameArray = ucd->ContactNameArray;
1743 // Pass the data to the search window for processing.
1745 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1746 wxCommandEvent schupdate(SE_UPDATERESULT);
1747 schupdate.SetClientData(ucd2);
1748 wxPostEvent(frameSCH, schupdate);
1750 // Clear up the pointer prior to variable deletion.
1761 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1765 frmSearch *frameSCH = new frmSearch ( this );
1766 frameSCH->SetUID(WindowMenuItemID);
1767 frameSCH->Show(true);
1769 WindowData *WData = new WindowData;
1771 WData->DataType = 2;
1772 WData->WindowPointer = (void*)frameSCH;
1773 WData->WindowID = WindowMenuItemID;
1775 wxCommandEvent addevent(WINDOW_ADD);
1776 addevent.SetClientData(WData);
1777 wxPostEvent(this, addevent);
1779 // Add pointer to the list of open search windows.
1781 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1787 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1789 void *frameSCH = (void*)event.GetClientData();
1791 SearchWindowList.erase(frameSCH);
1797 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1799 void *frameSCH = (void*)event.GetClientData();
1801 SearchWindowList.erase(frameSCH);
1807 void frmMain::RevealContact(wxCommandEvent& event){
1809 UCNotif *uc = (UCNotif*)event.GetClientData();
1811 // Switch the account to the one passed.
1813 wxTreeItemIdValue cookie;
1814 wxTreeItemId next = treAccounts->GetRootItem();
1815 wxTreeItemId nextChild;
1817 for (int i = 0; i < prefaccounts.GetCount(); i++){
1820 nextChild = treAccounts->GetFirstChild(next, cookie);
1822 nextChild = treAccounts->GetNextSibling(nextChild);
1825 //AccountName = treAccounts->GetItemText(nextChild);
1827 if (uc->ContactAccount == AccountAccDirList[i]){
1830 treAccounts->SelectItem(nextChild, TRUE);
1831 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1837 // Switch the contact to the one passed.
1839 long longSelected = -1;
1840 int intSelectedData = 0;
1844 longSelected = lstContacts->GetNextItem(longSelected,
1846 wxLIST_STATE_DONTCARE);
1848 if (longSelected == -1){
1854 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1856 // Compare the filename with the one received.
1857 // If they match then select it.
1859 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1863 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1864 lstContacts->EnsureVisible(longSelected);
1868 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1876 void frmMain::DeleteContact(wxCommandEvent& event){
1878 // Check if a contact is selected.
1880 long intSelected = -1;
1881 long intContactSeekNum = -1;
1882 wxString wxSContactName;
1884 intSelected = lstContacts->GetNextItem(intSelected,
1886 wxLIST_STATE_SELECTED);
1888 if (intSelected == -1){
1892 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1894 // Get the item data of the contact.
1896 intContactSeekNum = lstContacts->GetItemData(intSelected);
1898 // Get the name of the contact.
1900 wxSContactName = lstContacts->GetItemText(intSelected);
1902 // Display a message confirming if the contact should
1905 int QuestionResponse;
1907 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1909 if (QuestionResponse == wxNO){
1911 // Exit the subroutine
1917 // Delete the contact.
1919 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1921 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1926 // Remove the contact from the list.
1928 lstContacts->DeleteItem(intSelected);
1930 // Update the search windows, removing the deleted
1933 UCNotif *ucd = new UCNotif;
1935 ucd->ContactAccount = ActiveAccount;
1936 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1938 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1939 switer != SearchWindowList.end(); switer++){
1941 // Duplicate the event notification data.
1943 UCNotif *ucd2 = new UCNotif;
1945 ucd2->ContactAccount = ucd->ContactAccount;
1946 ucd2->ContactFilename = ucd->ContactFilename;
1948 // Pass the data to the search window for processing.
1950 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1951 wxCommandEvent schdelete(SE_DELETERESULT);
1952 schdelete.SetClientData(ucd2);
1953 wxPostEvent(frameSCH, schdelete);
1955 // Clear up the pointer prior to variable deletion.
1962 // Clear the wxHTMLWindow.
1964 wxString EmptyPage = wxT("");
1966 htmContactData->SetPage(EmptyPage);
1968 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
1970 wxString wxSplitFilename;
1971 wxString wxSDataURL;
1973 while(wSTFilename.HasMoreTokens()){
1975 wxSplitFilename = wSTFilename.GetNextToken();
1979 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
1981 // Update the ETagDB and mark it as deleted.
1983 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
1985 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
1987 // Get the Data URL.
1989 wxTreeItemIdValue cookie;
1990 wxTreeItemId next = treAccounts->GetRootItem();
1992 wxTreeItemId selectedChild = treAccounts->GetSelection();
1993 wxTreeItemId nextChild;
1995 for (int i = 0; i < prefaccounts.GetCount(); i++){
1998 nextChild = treAccounts->GetFirstChild(next, cookie);
2001 nextChild = treAccounts->GetNextSibling(nextChild);
2004 if (nextChild == selectedChild){
2005 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2011 // Add task to the activity monitor to delete the contact.
2013 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2017 // Clear the variable. Don't delete as it will mess things up.
2019 ContactsFileIndex[intContactSeekNum] = wxT("");
2026 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2028 QRNotif *qrn = (QRNotif *)event.GetClientData();
2030 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);
2032 if (QResponse == wxNO){
2038 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2039 event2.SetInt(*qrn->QResponse);
2040 event2.SetClientData(qrn->PausePtr);
2042 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2044 wxPostEvent(frameActMgr, event2);
2048 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2050 // Remove the contact from the window after syncronising.
2052 // Check which account is currently active in the window.
2053 // If it is different from the one passed to this subroutine then
2054 // exit from the subroutine.
2056 if (Account != ActiveAccount){
2060 long longSelected = -1;
2061 int intSelectedData = 0;
2065 longSelected = lstContacts->GetNextItem(longSelected,
2067 wxLIST_STATE_DONTCARE);
2069 if (longSelected == -1){
2075 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2077 // Compare the filename with the one received.
2078 // If they match then select it.
2080 if (ContactsFileIndex[intSelectedData] == Filename){
2082 // Remove the contact from the window.
2084 lstContacts->DeleteItem(intSelectedData);
2086 // Check if contact is the selected contact in the HTML window and
2087 // if it is then clear the window.
2089 if (ActiveFilename == Filename){
2091 wxString EmptyPage = wxT("");
2092 htmContactData->SetPage(EmptyPage);
2106 void frmMain::SortFNLN( wxCommandEvent& event ) {
2108 wxTreeEvent NullEvent;
2110 LoadContactList(NullEvent);
2114 void frmMain::SortLNFN( wxCommandEvent& event ) {
2116 wxTreeEvent NullEvent;
2118 LoadContactList(NullEvent);
2122 void frmMain::SortNickname( wxCommandEvent& event ) {
2124 wxTreeEvent NullEvent;
2126 LoadContactList(NullEvent);
2130 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2132 wxTreeEvent NullEvent;
2134 LoadContactList(NullEvent);
2138 void frmMain::SortAscending( wxCommandEvent& event ) {
2140 wxTreeEvent NullEvent;
2141 AscendingMode = TRUE;
2142 LoadContactList(NullEvent);
2146 void frmMain::SortDescending( wxCommandEvent& event ) {
2148 wxTreeEvent NullEvent;
2149 AscendingMode = FALSE;
2150 LoadContactList(NullEvent);
2154 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2156 if (stbBottom->IsShown() == TRUE){
2170 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2172 // Display the activity icon.
2174 imgActivityStatus->SetBitmap(*imgActIcon1);
2175 ActivityIconStatus = 0;
2179 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2181 switch (ActivityIconStatus){
2184 imgActivityStatus->SetBitmap(*imgActIcon1);
2185 ActivityIconStatus = 1;
2188 imgActivityStatus->SetBitmap(*imgActIcon2);
2189 ActivityIconStatus = 2;
2192 imgActivityStatus->SetBitmap(*imgActIcon3);
2193 ActivityIconStatus = 3;
2196 imgActivityStatus->SetBitmap(*imgActIcon4);
2197 ActivityIconStatus = 0;
2200 ActivityIconStatus = 0;
2206 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2208 // Display the sleep icon.
2210 imgActivityStatus->SetBitmap(*imgActIconSleep);
2214 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2216 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2224 wxRect rectActivity;
2225 stbBottom->GetFieldRect(1, rectOnline);
2226 stbBottom->GetFieldRect(2, rectSSL);
2227 stbBottom->GetFieldRect(3, rectActivity);
2229 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2230 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2231 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2235 XABViewMode frmMain::GetViewMode(){
2239 xvm.SortMode = SortMode;
2240 xvm.AscendingMode = AscendingMode;
2246 void frmMain::WindowAdd( wxCommandEvent &event ){
2248 WindowData *WData = (WindowData*)event.GetClientData();
2252 if (WData->DataType == 0){
2256 int intID = mnuContactWindows->GetId();
2258 mnuWindow->FindChildItem(intID, &pos);
2259 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2260 mnuNewItem->SetId(WData->WindowID);
2261 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2262 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2263 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2264 mnuWindow->Insert((pos + 1), mnuNewItem);
2265 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2267 } else if (WData->DataType == 1){
2269 // Contact Editor Window
2271 int intID = mnuContactEditorWindows->GetId();
2273 mnuWindow->FindChildItem(intID, &pos);
2274 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2275 mnuNewItem->SetId(WData->WindowID);
2276 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2277 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2278 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2279 mnuWindow->Insert((pos + 1), mnuNewItem);
2280 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2282 } else if (WData->DataType == 2){
2286 int intID = mnuSearchWindows->GetId();
2288 mnuWindow->FindChildItem(intID, &pos);
2289 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2290 mnuNewItem->SetId(WData->WindowID);
2291 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2292 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2293 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2294 mnuWindow->Insert((pos + 1), mnuNewItem);
2295 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2304 void frmMain::WindowEdit( wxCommandEvent &event ){
2306 WindowData *WData = (WindowData*)event.GetClientData();
2308 if (WData->DataType == 0){
2310 // Get the window title and use that.
2312 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2314 wxString WindowTitle = frmContactPtr->GetTitle();
2316 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2318 MenuIter->second->SetItemLabel(WindowTitle);
2320 } else if (WData->DataType == 1){
2322 // Get the window title and use that.
2324 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2326 wxString WindowTitle = frmCEPtr->GetTitle();
2328 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2330 if (WindowTitle.IsEmpty()){
2332 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2336 MenuIter->second->SetItemLabel(WindowTitle);
2347 void frmMain::WindowDelete( wxCommandEvent &event ){
2349 WindowData *WData = (WindowData*)event.GetClientData();
2351 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2353 mnuWindow->Remove(MenuIter->second);
2355 delete MenuIter->second;
2356 MenuIter->second = NULL;
2358 WindowListPointersMenu.erase(WData->WindowID);
2359 WindowListPointers.erase(WData->WindowID);
2360 WindowListType.erase(WData->WindowID);
2367 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2369 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2371 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2373 frmContactPtr->Show();
2374 frmContactPtr->Raise();
2378 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2380 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2382 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2389 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2391 // Look through the Search Window List Pointers, grab the
2392 // window point and show the window.
2394 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2396 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2398 frmSearchPtr->Show();
2399 frmSearchPtr->Raise();
2403 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2405 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2406 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2407 wxPostEvent(frameActMgr, toggconn);
2411 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2413 // Check the account type before continuing.
2415 wxString SeekAccount;
2416 wxString AccTypeLower;
2419 std::map<int, SSLCertCollection>::iterator SSLColIter;
2421 for (int i = 0; i < prefaccounts.GetCount(); i++){
2423 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2424 AccType.Append(prefaccounts.GetAccountType(i));
2425 AccountSSL = prefaccounts.GetAccountSSL(i);
2426 AccTypeLower = AccType.MakeLower();
2427 SeekAccount.Append(wxT("."));
2428 SeekAccount.Append(AccTypeLower);
2430 if (SeekAccount == ActiveAccount){
2432 if (AccTypeLower == wxT("local")){
2438 if (AccountSSL == false){
2444 SSLColIter = AccountSSLData.find(i);
2446 SSLCertCollection SSLCertInfo = SSLColIter->second;
2448 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2449 frameSSLCert->StartCertFrom(0);
2450 frameSSLCert->SetupCerts(SSLCertInfo);
2451 frameSSLCert->ShowModal();
2453 delete frameSSLCert;
2454 frameSSLCert = NULL;
2458 SeekAccount.Clear();
2459 AccTypeLower.Clear();
2466 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2468 // Check the account type before continuing.
2472 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2474 // Check the account type before continuing.
2478 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2480 if (event.GetInt() == 0){
2482 imgConnStatus->SetBitmap(*imgOnline);
2486 imgConnStatus->SetBitmap(*imgOffline);
2492 void frmMain::SetupSSLStatus( int AccountID ){
2494 // Check if account ID given is
2495 // the active account and if not, do nothing.
2498 wxString AccTypeLower;
2500 AccType = prefaccounts.GetAccountType(AccountID);
2501 AccTypeLower = AccType.MakeLower();
2503 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2506 if (AccountIDName != ActiveAccount){
2512 // Check if the account has SSL enabled.
2514 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2516 if (SSLInUse == FALSE){
2518 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2519 imgSSLStatus->SetBitmap(*imgNoSSL);
2523 // Get the SSL Collection Data.
2525 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2527 if (SSLResultIter->second == 1){
2529 imgSSLStatus->SetBitmap(*imgSSLWarning);
2530 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2531 prefaccounts.GetAccountName(AccountID) +
2532 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2535 } else if (SSLResultIter->second == 0){
2537 imgSSLStatus->SetBitmap(*imgSSL);
2538 SSLToolTip->SetTip(wxT("Account '") +
2539 prefaccounts.GetAccountName(AccountID) +
2540 wxT("' secured using SSL\n\nDouble click for more information."));
2548 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2550 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2551 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2552 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2553 wxString AccountName = SSLICNObj->AccountName;
2554 frameISC->LoadData(SSLCCData, AccountName);
2555 frameISC->ShowModal();
2557 int FinalConflictResult = frameISC->GetResult();
2559 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2560 event2.SetClientData(SSLICNObj->QRNotifData);
2561 event2.SetInt(FinalConflictResult);
2566 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2567 wxPostEvent(frameActMgr, event2);
2570 void frmMain::PauseAllTimers(){
2572 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2573 ASTiter != AccountSyncTimers.end(); ASTiter++){
2575 ASTiter->second->Stop();
2581 void frmMain::ResumeAllTimers(){
2583 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2584 ASTiter != AccountSyncTimers.end(); ASTiter++){
2586 ASTiter->second->Start();
2592 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2594 // Delete existing data.
2596 AccountSSLData.erase(AccountID);
2597 AccountSSLResult.erase(AccountID);
2601 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2602 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2606 void frmMain::CheckUpdates( wxCommandEvent& event ){
2608 frmUpdate *frameUpdate = new frmUpdate ( this );
2609 frameUpdate->FetchData();
2610 frameUpdate->ShowModal();
2614 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2616 // Run the import contacts system.
2622 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2624 // Check if an account and at least one contact is selected
2625 // before continuing.
2627 wxArrayString ArrData;
2629 if (ActiveAccount.IsEmpty()){
2635 int ContactSelected = 0;
2636 int ContactsCollected = 0;
2637 long longSelected = -1;
2641 longSelected = lstContacts->GetNextItem(longSelected,
2643 wxLIST_STATE_SELECTED);
2645 if (longSelected == -1){
2651 int FileID = (int)lstContacts->GetItemData(longSelected);
2653 ArrData.Insert(ContactsFileIndex[FileID],
2654 ContactsCollected, 1);
2660 if (ContactSelected == 0){
2666 // Run the export contacts system.
2668 ExportRun(this, &ArrData);
2672 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2673 wxArrayString *ContactsFileIndexPtr){
2675 lstContactsPtr = lstContacts;
2676 ContactsFileIndexPtr = &ContactsFileIndex;
2680 void frmMain::GetSelectedList( wxCommandEvent& event ){
2682 // Get the array of contact filenames.
2684 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2686 // Process them into an array of files.
2688 long longSelected = -1;
2689 int ContactsCollected = 0;
2690 wxString ContactFilename;
2694 longSelected = lstContacts->GetNextItem(longSelected,
2696 wxLIST_STATE_SELECTED);
2698 if (longSelected == -1){
2704 // Get the file information and add to the list.
2706 int FileID = (int)lstContacts->GetItemData(longSelected);
2708 ArrData->Insert(ContactsFileIndex[FileID],
2709 ContactsCollected, 1);
2711 ContactsCollected++;
2712 ContactFilename.Clear();
2720 void frmMain::SyncAccount( wxCommandEvent& event ){
2722 wxString AccNameInc = event.GetString();
2724 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2725 frameActMgr->AddTask(3, wxT(""), AccNameInc,
2726 wxT(""), wxT(""), wxT(""), wxT(""));
2730 void frmMain::ShowHelp( wxCommandEvent& event ){
2732 // Based on the operating system, work out where
2733 // the documentation should be.
2737 #if defined(__HAIKU__)
2739 #elif defined(__WIN32__)
2745 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2747 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2750 #if XSDAB_RELEASE == 0
2752 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2754 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2763 #if XSDAB_RELEASE == 0
2765 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2769 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!"));
2775 void frmMain::ShowImportResults( wxCommandEvent &event ){
2777 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2779 frmImportResults *frmIR = new frmImportResults(this);
2780 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
2791 void frmMain::ReloadContactList( wxCommandEvent &event ){
2793 // Check if the account name given is the current
2794 // account selected.
2796 if (ActiveAccount == event.GetString()){
2798 wxTreeEvent NullEvent;
2799 LoadContactList(NullEvent);
2805 void frmMain::ShowContactMenu( wxMouseEvent& event ){
2807 bool EnableRefresh = FALSE;
2809 if (!ActiveAccount.IsEmpty()){
2811 EnableRefresh = TRUE;
2815 ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
2817 this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);
2821 void frmMain::ResetContactInfo(){
2823 wxString EmptyPage = wxT("");
2824 htmContactData->SetPage(EmptyPage);
2825 AccCtrl->SetValue("");