1 // frmMain.cpp - Main window form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
25 #include <wx/tokenzr.h>
27 #include <wx/mstream.h>
28 #include <wx/fs_mem.h>
30 #include <wx/filesys.h>
32 #include <wx/stdpaths.h>
33 #include <wx/fileconf.h>
34 #include <wx/gdicmn.h>
40 #include "frmPreferences.h"
41 #include "frmNewAccount.h"
42 #include "actmgr/frmActivityMgr.h"
43 #include "frmContact.h"
44 #include "frmConflictResolution.h"
45 #include "frmInvalidSSLCertificate.h"
46 #include "search/frmSearch.h"
47 #include "frmSSLCertificate.h"
48 #include "frmUpdate.h"
49 #include "import/frmImportResults.h"
52 #include "common/preferences.h"
53 #include "common/getcontactinfo.h"
54 #include "common/events.h"
55 #include "common/dirs.h"
56 #include "vcard/vcard.h"
57 #include "carddav/carddav.h"
58 #include "contacteditor/frmContactEditor.h"
59 #include "import/import.h"
60 #include "export/export.h"
61 #include "widgets/XABContactMenu.h"
62 #include "widgets/XABAccountView.h"
66 //extern const wxEventType MyHaremEvent = wxNewEventType();
68 //#define CE_UPDATECONTACTLIST 7700
69 //#define CE_UPDATEACCOUNTLIST 7701
71 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
72 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
73 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
74 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
75 DEFINE_EVENT_TYPE(CE_OPENCONTACTLIST);
76 DEFINE_EVENT_TYPE(CE_NEWCONTACT);
77 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
78 DEFINE_EVENT_TYPE(CE_DELETECONTACT);
79 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
80 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
81 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
82 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
83 DEFINE_EVENT_TYPE(ACTMGR_START);
84 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
85 DEFINE_EVENT_TYPE(ACTMGR_STOP);
86 DEFINE_EVENT_TYPE(WINDOW_ADD);
87 DEFINE_EVENT_TYPE(WINDOW_EDIT);
88 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
89 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
90 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
91 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
92 DEFINE_EVENT_TYPE(SYNCACCOUNT);
93 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
94 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
95 DEFINE_EVENT_TYPE(REFRESHADDRESSBOOK);
97 BEGIN_EVENT_TABLE(frmMain, wxFrame)
98 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
99 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
100 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
101 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
102 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
103 EVT_COMMAND(wxID_ANY, CE_OPENCONTACTLIST, frmMain::OpenContactInfoList)
104 EVT_COMMAND(wxID_ANY, CE_NEWCONTACT, frmMain::ShowContactEditorNew)
105 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
106 EVT_COMMAND(wxID_ANY, CE_DELETECONTACT, frmMain::DeleteContact)
107 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
108 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
109 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
110 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
111 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
112 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
113 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
114 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
115 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
116 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
117 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
118 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
119 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
120 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
121 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
122 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
125 frmMain::frmMain( wxWindow* parent )
130 // Setup the account icons.
132 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
133 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
134 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
135 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
137 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
138 wxBitmap AccInet(icons_accinet_png, -1);
140 wxIAccInet.CopyFromBitmap(AccInet);
142 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
143 wxBitmap AccNIcon(icons_acclocal_png, -1);
145 wxIAccNIcon.CopyFromBitmap(AccNIcon);
147 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
148 wxBitmap AccGrp(icons_accgroup_png, -1);
150 wxIAccGrp.CopyFromBitmap(AccGrp);
152 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
153 wxBitmap AccNone(icons_accnone_png, -1);
155 wxIAccNone.CopyFromBitmap(AccNone);
157 AccountID = AccImgList->Add(wxIAccNIcon);
158 AccountNetID = AccImgList->Add(wxIAccInet);
159 AccountGrpID = AccImgList->Add(wxIAccGrp);
160 AccountNoneID = AccImgList->Add(wxIAccNone);
162 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
164 // Setup the status bar icons.
168 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
169 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
170 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
172 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
173 imgSSL = new wxBitmap(icons_ssl_png, -1);
175 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
176 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
178 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
179 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
183 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
184 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
185 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
186 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
187 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
189 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
190 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
192 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
193 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
195 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
197 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
198 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
200 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
202 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
203 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
205 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
207 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
208 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
210 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
212 // Online/Offline icons.
214 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
215 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
217 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
218 imgOnline = new wxBitmap(icons_online_png, -1);
220 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
221 imgOffline = new wxBitmap(icons_offline_png, -1);
223 // Setup the account view.
225 AccCtrl->SetPopupControl(treAccounts);
226 AccCtrl->SetPopupMaxHeight(175);
227 AccCtrl->SetPopupMinWidth(250);
228 treAccounts->AssignImageList(AccImgList);
231 /*wxStaticBitmap* BeepBoop = new wxStaticBitmap(AccCtrl, wxID_ANY, wxNullBitmap, wxPoint(AccTextCtrlSize.GetX() + 3, AccTextCtrlSize.GetY() + 2), wxDefaultSize, 0);
233 icons_accgroup_png.SetMask(new wxMask(icons_accgroup_png, wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND)));
235 BeepBoop->SetBackgroundColour(AccCtrl->GetBackgroundColour());
236 BeepBoop->SetBitmap(icons_accgroup_png);*/
238 //szrContactList->Insert(0, XABV2, 1, wxEXPAND | wxALL, 0);
240 /*AccControl->UseAltPopupWindow();
241 AccControl->SetPopupControl(treAccounts);
242 AccControl->SetPopupMaxHeight(175);
244 treAccounts->AssignImageList(AccImgList);
245 szrContactList->Insert(0, AccControl, 1, wxEXPAND|wxALL, 0);
246 szrAccList->Add(AccIcon, 0, wxLEFT|wxTOP|wxEXPAND, 3);
250 //szrContactList->Layout();
251 //szrContactList->RecalcSizes();
253 wxListItem ColumnData;
255 ColumnData.SetText(wxT("Name0"));
256 ColumnData.SetWidth(320);
257 lstContacts->InsertColumn(0, ColumnData);
259 //Connect(wxID_ANY, ContactConflictCmdEnv,
260 // ContactConflictEventHandler(frmMain::ConflictResolution), NULL, this);
262 //Connect(wxID_ANY, MyFooCommandEvent,
263 // MyFooEventHandler(frmMain::DoSomething), NULL, this);
265 //Bind(ContactConflictCmdEnv, ContactConflictEventHandler(frmMain::ConflictResolution), this, wxID_ANY);
267 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
268 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
270 #if defined(__HAIKU__)
272 #elif defined(__WIN32__)
274 int stbBottomData [4] = { -1, 8, 8, 8 };
278 int stbBottomData [4] = { -1, 20, 20, 20 };
282 stbBottom->SetFieldsCount(4, stbBottomData);
283 stbBottom->SetMinHeight(16);
288 stbBottom->GetFieldRect(1, rectOnline);
289 stbBottom->GetFieldRect(2, rectSSL);
290 stbBottom->GetFieldRect(3, rectActivity);
292 SSLToolTip = new wxToolTip(wxT(""));
294 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
295 imgConnStatus->SetBitmap(*imgOnline);
296 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
298 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
299 imgSSLStatus->SetBitmap(*imgNoSSL);
300 imgSSLStatus->SetToolTip(SSLToolTip);
301 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
303 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
304 imgActivityStatus->SetBitmap(*imgActIconSleep);
305 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
307 // Setup the window menu.
309 // By default should be:
314 // Contact editor windows:
320 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
321 mnuWindow->Append( mnuContactWindows );
323 mnuWindow->AppendSeparator();
325 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
326 mnuWindow->Append( mnuContactEditorWindows );
328 mnuWindow->AppendSeparator();
330 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
331 mnuWindow->Append( mnuSearchWindows );
333 #if defined(__WIN32__)
338 mnuContactWindows->SetFont(fontstyle);
339 mnuContactEditorWindows->SetFont(fontstyle);
340 mnuSearchWindows->SetFont(fontstyle);
344 mnuContactWindows->Enable(FALSE);
345 mnuContactEditorWindows->Enable(FALSE);
346 mnuSearchWindows->Enable(FALSE);
350 // Hide unimplemented functions.
356 void frmMain::QuitApp( wxCloseEvent& event )
363 void frmMain::QuitApp( wxCommandEvent& event )
370 void frmMain::QuitApp()
372 //-------------------------------------------------------------------
373 // frmMain::QuitApp: Quits the application by simply closing this
374 // window which causes the exit as frmMain is the main window.
376 // wxCommandEvent Accepts a referenced event command.
377 //-------------------------------------------------------------------
379 //-------------------------------------------------------------------
380 // frmMain::QuitApp: Quits the application by simply closing this
381 // window which causes the exit as frmMain is the main window.
383 // wxCommandEvent Accepts a referenced event command.
384 //-------------------------------------------------------------------
386 //Go through the windows and close each one (be it search
387 //or contact editor). Abort if user wants to cancel.
389 // Close the contact editor windows.
391 // Close the contact windows.
393 // Close the search windows.
395 // Write out the ETag databases.
397 // Save Preferences: Save the window position if that option is enabled.
399 wxString SetFilename = GetUserPrefDir();
401 #if defined(__HAIKU__)
405 #elif defined(__WIN32__)
407 SetFilename.Append(wxT("settings"));
413 SetFilename.Append(wxT("settings"));
417 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
419 bool SaveWindowPos = FALSE;
420 wxString SaveWindowInc;
421 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
423 if (SaveWindowInc == wxT("true")){
425 SaveWindowPos = TRUE;
429 if (SaveWindowPos == TRUE){
431 wxRect frmMainPos = this->GetRect();
433 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
434 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
435 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
436 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
444 //Everything closed... exit.
452 void frmMain::ShowActivityWindow( wxCommandEvent& event )
455 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
456 frameActMgr->OpenWindow();
461 void frmMain::ShowAboutWindow( wxCommandEvent& event )
463 //-------------------------------------------------------------------
464 // frmMain::ShowAboutWindow: Shows the About window as a modal
465 // dialog and then cleans up when finished.
467 // wxCommandEvent Accepts a referenced event command.
468 //-------------------------------------------------------------------
470 frmAbout *frameAbout = new frmAbout ( this );
471 frameAbout->SetupAboutWindow();
472 frameAbout->ShowModal();
478 void frmMain::OpenPreferences( wxCommandEvent& event)
480 //-------------------------------------------------------------------
481 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
482 // dialog and then cleans up when finished.
484 // wxCommandEvent Accepts a referenced event command.
485 //-------------------------------------------------------------------
487 ReloadAccounts = FALSE;
489 frmPreferences *framePreferences = new frmPreferences ( this );
490 framePreferences->SetupPointers(&ReloadAccounts);
491 framePreferences->ShowModal();
492 delete framePreferences;
493 framePreferences = NULL;
495 if (ReloadAccounts == TRUE){
497 // Reload the accounts as a change has been made within
500 this->LoadPreferences();
506 void frmMain::OpenNewABDialog( wxCommandEvent& event)
508 //-------------------------------------------------------------------
509 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
510 // dialog and then cleans up when finished.
512 // wxCommandEvent Accepts a referenced event command.
513 //-------------------------------------------------------------------
515 ReloadAccounts = FALSE;
517 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
518 frameNewAccount->SetupPointers(&ReloadAccounts);
519 frameNewAccount->ShowModal();
520 delete frameNewAccount;
521 frameNewAccount = NULL;
523 if (ReloadAccounts == TRUE){
525 // Reload the accounts as a change has been made within
528 this->LoadPreferences();
534 void frmMain::LoadContactList( wxTreeEvent& event )
537 // Clear all existing variables.
539 lstContacts->DeleteAllItems();
541 treAccounts->SetAccount();
543 wxTreeItemIdValue cookie;
544 wxTreeItemId next = treAccounts->GetRootItem();
545 wxString AccountName;
546 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
547 wxString AccountDirCmb;
548 long selectedaccount = 0;
550 wxTreeItemId selectedChild = treAccounts->GetSelection();
551 wxTreeItemId nextChild;
553 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
554 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
556 int SCImg = treAccounts->GetItemImage(selectedChild);
557 int AccountIndex = 0;
559 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
561 for (int i = 0; i < prefaccounts.GetCount(); i++){
563 if (ActiveItemIcon == 2){
565 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
566 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
567 int ActiveAccountG = AGLiter->second;
569 if (i == ActiveAccountG){
571 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
572 AccountType.Append(prefaccounts.GetAccountType(i));
577 if (AccountType == wxT("CardDAV")){
578 AccountTypeFinal.Append(wxT("carddav"));
580 else if (AccountType == wxT("Local")){
581 imgSSLStatus->SetBitmap(*imgOffline);
582 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
583 AccountTypeFinal.Append(wxT("local"));
594 nextChild = treAccounts->GetFirstChild(next, cookie);
597 nextChild = treAccounts->GetNextSibling(nextChild);
600 AccountName = treAccounts->GetItemText(nextChild);
602 if (nextChild == selectedChild){
603 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
604 AccountType.Append(prefaccounts.GetAccountType(i));
609 if (AccountType == wxT("CardDAV")){
610 AccountTypeFinal.Append(wxT("carddav"));
612 else if (AccountType == wxT("Local")){
613 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
614 AccountTypeFinal.Append(wxT("local"));
623 if (selectedaccount >= prefaccounts.GetCount()){
625 // The account selected isn't there so return.
633 // Open the directory and get the list of .vcf files
634 // in that directory.
636 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
637 ActiveAccountType = AccountType;
639 SetupSSLStatus(AccountIndex);
641 AccountDirFinal.Clear();
642 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
644 ContactsFileIndex.Clear();
646 //wxString vcardfilenamewxs;
647 wxString vCardFilename;
648 wxString vCardFilenameFull;
649 wxString vCardDataString;
650 wxStringTokenizer vcardfileline;
652 wxString setname, setvalue;
653 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
654 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
655 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
656 long ContactIndex = 1;
657 long ContactSeekPoint = 0;
659 wxDir vcardaccdir(AccountDirFinal);
661 // Get the wxTreeItemId and image icon and compare it to the list.
663 if (ActiveItemIcon == AccountGrpID){
665 // It's a group so load the file containing the group and
666 // get the members of the group.
671 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
672 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
673 //std::multimap<wxTreeItemId, int>::iterator AGFiter = AccountGroupTreeId.find(ActiveItemId);
675 Group.LoadFile(AGFiter->second);
677 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
679 for (int i = 0; i < vCardMember.PropCount; i++){
681 vCardMember.PropValues[i].Trim();
682 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
684 wxString NewPropValue;
685 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
686 vCardMember.PropValues[i] = NewPropValue;
693 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
696 if (vCardFilename.Right(4) == wxT(".vcf") ||
697 vCardFilename.Right(4) == wxT(".VCF") ||
698 vCardFilename.Right(5) == wxT(".vcard") ||
699 vCardFilename.Right(5) == wxT(".VCARD")){
702 bool FoundMember = FALSE;
704 vCardFilenameFull.Append(AccountDirFinal);
705 vCardFilenameFull.Append(wxT("/"));
706 vCardFilenameFull.Append(vCardFilename);
708 Person.LoadFile(vCardFilenameFull);
710 UIDCode = Person.Get(wxT("UID"));
712 for (int i = 0; i < vCardMember.PropCount; i++){
714 if (vCardMember.PropValues[i] == UIDCode){
722 if (FoundMember == FALSE){
724 vCardFilename.Clear();
725 vCardFilenameFull.Clear();
726 vCardDataString.Clear();
727 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
732 if (Person.MeetBaseSpecification()){
736 // Split the name into sections.
738 vCardDataString = Person.Get(wxT("N"));
740 vCardName NameData = Person.GetName();
742 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
744 } else if (SortMode == 2){
746 // Split the name into sections.
748 vCardName NameData = Person.GetName();
750 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
752 } else if (SortMode == 3){
754 // Check and make sure that the top most nickname is used.
756 vCardDataString = Person.Get(wxT("NICKNAME"));
758 if (vCardDataString.IsEmpty()){
760 vCardDataString = wxT("(no nickname)");
764 } else if (SortMode == 4){
766 vCardDataString = Person.Get(wxT("FN"));
770 if (AscendingMode == TRUE){
771 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
773 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
782 vCardFilename.Clear();
783 vCardFilenameFull.Clear();
784 vCardDataString.Clear();
785 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
790 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
793 if (vCardFilename.Right(4) == wxT(".vcf") ||
794 vCardFilename.Right(4) == wxT(".VCF") ||
795 vCardFilename.Right(5) == wxT(".vcard") ||
796 vCardFilename.Right(5) == wxT(".VCARD")){
800 vCardFilenameFull.Append(AccountDirFinal);
801 vCardFilenameFull.Append(vCardFilename);
803 Person.LoadFile(vCardFilenameFull);
805 if (Person.MeetBaseSpecification()){
809 // Split the name into sections.
811 vCardDataString = Person.Get(wxT("N"));
813 vCardName NameData = Person.GetName();
815 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
817 } else if (SortMode == 2){
819 // Split the name into sections.
821 vCardName NameData = Person.GetName();
823 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
825 } else if (SortMode == 3){
827 // Check and make sure that the top most nickname is used.
829 vCardDataString = Person.Get(wxT("NICKNAME"));
831 if (vCardDataString.IsEmpty()){
833 vCardDataString = wxT("(no nickname)");
837 } else if (SortMode == 4){
839 vCardDataString = Person.Get(wxT("FN"));
843 if (AscendingMode == TRUE){
844 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
846 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
855 vCardFilename.Clear();
856 vCardFilenameFull.Clear();
857 vCardDataString.Clear();
858 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
865 // Insert the data into the control.
867 if (AscendingMode == TRUE){
868 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
869 iter != vCardNamesAsc.end(); ++iter){
871 wxListItem ContactInfo;
873 ContactInfo.SetId(0);
874 ContactInfo.SetText(_("Mooo"));
875 ContactInfo.SetData(ContactSeekPoint);
876 ContactIndex = lstContacts->InsertItem(ContactInfo);
878 lstContacts->SetItem(ContactIndex, 0, iter->first);
879 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
886 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
887 iter != vCardNamesDsc.end(); ++iter){
889 wxListItem ContactInfo;
891 ContactInfo.SetId(0);
892 ContactInfo.SetText(_("Mooo"));
893 ContactInfo.SetData(ContactSeekPoint);
894 ContactIndex = lstContacts->InsertItem(ContactInfo);
896 lstContacts->SetItem(ContactIndex, 0, iter->first);
897 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
906 void frmMain::ShowContactInfo( wxListEvent& event )
909 long intSelected = -1;
910 long ContactSeekNum = -1;
912 // intSelected = lstContacts->GetSelection();
914 // Check if several contacts have been selected.
916 int ContactTotal = 0;
920 intSelected = lstContacts->GetNextItem(intSelected,
922 wxLIST_STATE_SELECTED);
924 if (intSelected == -1){
934 if (ContactTotal == 0){
935 htmContactData->SetPage(wxT(""));
939 if (ContactTotal > 1){
941 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
942 ActiveFilename.Clear();
947 intSelected = lstContacts->GetNextItem(intSelected,
949 wxLIST_STATE_SELECTED);
951 ContactSeekNum = lstContacts->GetItemData(intSelected);
954 wxString wxSContactString;
955 wxString ContactLine;
958 size_t ContactLineLen;
959 bool ExtraLineSeek = FALSE;
960 int QuoteBreakPoint = 0;
962 bool PropertyFind = FALSE;
963 bool QuoteMode = FALSE;
965 wxString wxSPropertyNextLine;
966 wxString wxSProperty;
967 wxString wxSPropertySeg1;
968 wxString wxSPropertySeg2;
970 // Check if we are using wxWidgets version 2.8 or less and
971 // execute the required command accordingly.
973 #if wxABI_VERSION < 20900
974 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
976 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
979 if (ContactFile.IsOpened() == FALSE){
985 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
989 std::map<int, wxString> ContactFileLines;
990 std::map<int, wxString>::iterator striter;
992 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
994 int ContactLineSeek = 0;
996 while (wSTContactFileLines.HasMoreTokens() == TRUE){
998 ContactLine = wSTContactFileLines.GetNextToken();
999 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
1004 if (ContactSeekNum < 0){
1008 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
1009 iter != ContactFileLines.end(); ++iter){
1011 // Find the colon which splits the start bit from the data part.
1013 ContactLine = iter->second;
1015 while (ExtraLineSeek == TRUE){
1017 // Check if there is extra data on the next line
1018 // (indicated by space or tab at the start) and add data.
1022 if (iter == ContactFileLines.end()){
1029 wxSPropertyNextLine = iter->second;
1032 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
1034 wxSPropertyNextLine.Remove(0, 1);
1035 //wxSPropertyNextLine.Trim(FALSE);
1036 //ContactLine.Trim();
1037 ContactLine.Append(wxSPropertyNextLine);
1042 ExtraLineSeek = FALSE;
1048 ContactLineLen = ContactLine.Len();
1050 // Make sure we are not in quotation mode.
1051 // Make sure colon does not have \ or \\ before it.
1053 for (int i = 0; i <= ContactLineLen; i++){
1055 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1057 PropertyFind = FALSE;
1059 } else if (PropertyFind == TRUE){
1061 wxSProperty.Append(ContactLine.Mid(i, 1));
1065 if (ContactLine.Mid(i, 1) == wxT("\"")){
1067 if (QuoteMode == TRUE){
1079 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1081 QuoteBreakPoint = i;
1088 // Split that line at the point into two variables (ignore the colon).
1090 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1091 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1093 // Insert both into the vCard data file.
1095 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1098 PropertyFind = TRUE;
1099 ExtraLineSeek = TRUE;
1101 QuoteBreakPoint = 0;
1102 ContactLine.Clear();
1103 wxSProperty.Clear();
1107 OldSessionID = SessionID;
1108 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1109 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1110 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1114 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1117 // Check if there is an account selected and if not
1118 // return immediately.
1120 if (ActiveAccount.IsEmpty()){
1126 // Add Pointer to SetupPointers for the ETagDB.
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 frmContactEditor *ContactEditor = new frmContactEditor( this );
1138 ContactEditor->SetUID(WindowMenuItemID);
1140 WindowData *WData = new WindowData;
1142 WData->DataType = 1;
1143 WData->WindowPointer = (void*)ContactEditor;
1144 WData->WindowID = WindowMenuItemID;
1146 wxCommandEvent addevent(WINDOW_ADD);
1147 addevent.SetClientData(WData);
1148 wxPostEvent(this, addevent);
1150 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1151 ContactEditor->SetupHeaders();
1152 ContactEditor->SetupContact(ActiveAccount);
1153 ContactEditor->SetIcon(contacticon);
1154 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1155 ContactEditor->Show(true);
1159 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1162 // Check if there is an account selected and if not
1163 // return immediately.
1165 int DataCheck = event.GetInt();
1167 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1173 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1174 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1175 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1177 contacticon.CopyFromBitmap(contacticonbmp);
1179 // Check if a contact has been selected.
1181 long intSelected = -1;
1182 long intContactSeekNum = -1;
1184 // intSelected = lstContacts->GetSelection();
1186 intSelected = lstContacts->GetNextItem(intSelected,
1188 wxLIST_STATE_SELECTED);
1190 if (intSelected == -1){
1194 intContactSeekNum = lstContacts->GetItemData(intSelected);
1196 // Get the filename of the selected contact.
1198 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1199 frmContactEditor *ContactEditor = new frmContactEditor( this );
1203 ContactEditor->SetUID(WindowMenuItemID);
1205 WindowData *WData = new WindowData;
1207 WData->DataType = 1;
1208 WData->WindowPointer = (void*)ContactEditor;
1209 WData->WindowID = WindowMenuItemID;
1211 wxCommandEvent addevent(WINDOW_ADD);
1212 addevent.SetClientData(WData);
1213 wxPostEvent(this, addevent);
1215 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1216 ContactEditor->SetupHeaders();
1218 // Check if pointer is NULL (not from the search forms) or not.
1220 if (DataCheck == 0){
1222 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1223 ContactEditor->SetupContact(ActiveAccount);
1227 UCNotif *uc = (UCNotif*)event.GetClientData();
1231 ContactEditor->SetupContact(ActiveAccount);
1232 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1236 ContactEditor->SetupContact(uc->ContactAccount);
1237 ContactEditor->LoadContact(uc->ContactFilename);
1247 ContactEditor->SetIcon(contacticon);
1248 ContactEditor->Show(true);
1252 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1254 // Check if ActiveAccount is empty. If not then check if
1255 // account type is not local otherwise continue.
1257 if (!ActiveAccount.IsEmpty()){
1259 if (ActiveAccountType != wxT("Local")){
1261 // Account type is not local.
1263 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1264 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1265 wxT(""), wxT(""), wxT(""), wxT(""));
1269 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1277 void frmMain::OpenContactInfoList( wxListEvent& event )
1280 wxStringTokenizer vcardfileline;
1283 wxString setname, setvalue;
1287 long intSelected = -1;
1288 long intContactSeekNum = -1;
1290 intSelected = lstContacts->GetNextItem(intSelected,
1292 wxLIST_STATE_SELECTED);
1294 intContactSeekNum = lstContacts->GetItemData(intSelected);
1296 if (intContactSeekNum == -1){
1300 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1302 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1303 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1304 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1306 contacticon.CopyFromBitmap(contacticonbmp);
1308 frmContact *Contact = new frmContact( this );
1310 // Add to window list.
1314 Contact->SetUID(WindowMenuItemID);
1316 WindowData *WData = new WindowData;
1318 WData->DataType = 0;
1319 WData->WindowPointer = (void*)Contact;
1320 WData->WindowID = WindowMenuItemID;
1322 wxCommandEvent addevent(WINDOW_ADD);
1323 addevent.SetClientData(WData);
1324 wxPostEvent(this, addevent);
1326 Contact->SetupPointers(&MemoryFileList);
1327 Contact->SetupContactData(&Person);
1329 Contact->SetIcon(contacticon);
1330 Contact->Show(true);
1334 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1337 OpenContactInfoList(pevent);
1341 void frmMain::OpenContactInfo( wxCommandEvent& event )
1344 UCNotif *uc = (UCNotif*)event.GetClientData();
1346 wxStringTokenizer vcardfileline;
1349 wxString setname, setvalue;
1352 //std::fstream vcardfile;
1354 Person.LoadFile(uc->ContactFilename);
1356 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1357 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1358 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1360 contacticon.CopyFromBitmap(contacticonbmp);
1362 frmContact *Contact = new frmContact( this );
1364 // Add to window list.
1368 Contact->SetUID(WindowMenuItemID);
1370 WindowData *WData = new WindowData;
1372 WData->DataType = 0;
1373 WData->WindowPointer = (void*)Contact;
1374 WData->WindowID = WindowMenuItemID;
1376 wxCommandEvent addevent(WINDOW_ADD);
1377 addevent.SetClientData(WData);
1378 wxPostEvent(this, addevent);
1380 Contact->SetupPointers(&MemoryFileList);
1381 Contact->SetupContactData(&Person);
1383 Contact->SetIcon(contacticon);
1384 Contact->Show(true);
1389 void frmMain::LoadPreferences( wxActivateEvent& event)
1391 this->LoadPreferences();
1394 void frmMain::LoadPreferences(){
1396 // Load the preferences.
1398 wxString preffilename = GetUserPrefDir();
1400 XABPreferences preferences(preffilename);
1402 // Setup the main window position (if needed).
1404 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1405 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1407 if (SaveWindowPos == TRUE){
1409 this->SetSize(preferences.GetMainWindowData());
1413 treAccounts->DeleteAllItems();
1415 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1417 // Stop all account timers and remove the accounts.
1419 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1420 iter != AccountSyncTimers.end(); iter++){
1422 wxAccountSyncTimer *AccTmrPtr = iter->second;
1430 AccountSyncTimers.clear();
1433 wxString AccDirFull;
1434 wxString AccDirFullSfx;
1436 wxString AccDirFinal;
1437 AccountAccDirList.clear();
1438 AccountGroupList.clear();
1439 AccountGroupFilename.clear();
1440 AccountGroupTreeId.clear();
1441 wxTreeItemId AccountTreeId;
1442 wxTreeItemId GroupTreeId;
1445 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1447 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1448 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1454 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1460 AccDir = preferences.accounts.GetAccountDirectory(i);
1461 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1463 AccDirFull.Append(wxT("."));
1464 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1465 AccDirFullSfx.LowerCase();
1466 AccDirFullSfx.Trim();
1467 AccDirFull.Append(AccDirFullSfx);
1468 AccName = preferences.accounts.GetAccountName(i);
1470 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1472 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1473 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1475 // TODO: Check if the directory exists before doing anything.
1479 // Add a new timer using the existing account details.
1481 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1483 ActTmrPtr->SetupData(AccDirFull, AccName);
1484 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1485 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1486 ActTmrPtr->SetOwner(this);
1487 ActTmrPtr->Notify();
1489 // Add the timer to the list of timers.
1491 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1493 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1497 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1501 // Go through the account directory and find contact files with
1502 // 'KIND:group' set and add them to the list of groups for the account.
1504 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1506 wxDir vcardaccdir(AccDirFinal);
1508 wxString vCardFilename;
1509 wxString vCardDataString;
1510 wxString vCardFilenameFull;
1512 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1515 if (vCardFilename.Right(4) == wxT(".vcf") ||
1516 vCardFilename.Right(4) == wxT(".VCF") ||
1517 vCardFilename.Right(5) == wxT(".vcard") ||
1518 vCardFilename.Right(5) == wxT(".VCARD")){
1522 vCardFilenameFull.Append(AccDirFinal);
1523 vCardFilenameFull.Append(wxT("/"));
1524 vCardFilenameFull.Append(vCardFilename);
1526 Person.LoadFile(vCardFilenameFull);
1528 if (Person.MeetBaseSpecification()){
1530 vCardDataString = Person.Get(wxT("KIND"));
1532 if (vCardDataString == wxT("group")){
1534 // The vCard kind is a group. Add to the account's group list.
1536 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1537 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1538 AccountGroupList.insert(std::make_pair(intGroupID, i));
1539 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1540 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1552 vCardFilename.Clear();
1553 vCardFilenameFull.Clear();
1554 vCardDataString.Clear();
1555 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1559 // Clearup for next account.
1563 AccDirFullSfx.clear();
1564 AccDirFinal.clear();
1569 // Load the account settings as they are needed for connecting
1572 prefaccounts = preferences.accounts;
1576 void frmMain::ConflictResolution(wxCommandEvent& event){
1578 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1579 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1580 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1581 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1582 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1583 frameCR->ShowModal();
1585 int FinalConflictResult = frameCR->GetResult();
1587 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1588 event2.SetClientData(vCardConfObj->QRNotifData);
1589 event2.SetInt(FinalConflictResult);
1594 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1595 wxPostEvent(frameActMgr, event2);
1599 void frmMain::UpdateContactList(wxCommandEvent& event){
1601 UCNotif *ucd = (UCNotif*)event.GetClientData();
1603 // Check if the active account is being displayed in the
1604 // main window. If not, skip and delete the data.
1606 long longSelected = -1;
1607 int intSelectedData = 0;
1609 if (ActiveAccount == ucd->ContactAccount){
1611 // Look at the list of contacts and if it matches the
1612 // filename then update the name.
1616 longSelected = lstContacts->GetNextItem(longSelected,
1618 wxLIST_STATE_DONTCARE);
1620 if (longSelected == -1){
1626 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1628 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1630 // Work out which sorting mode we are in.
1634 // First Name, Last Name.
1636 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1638 } else if (SortMode == 2){
1640 // Last Name, First Name.
1642 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1644 } else if (SortMode == 3){
1648 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1650 } else if (SortMode == 4){
1654 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1661 // If the filename is the one loaded into the
1662 // browser control, then update this too.
1664 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1666 wxListEvent nullevent;
1667 ShowContactInfo(nullevent);
1675 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1676 WindowIter != WindowListPointers.end(); WindowIter++){
1678 if (WindowListType[WindowIter->first] != 0){
1684 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1686 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1688 vCard UpdatedPerson;
1689 UpdatedPerson.LoadFile(ucd->ContactFilename);
1690 frmContactPtr->SetupContactData(&UpdatedPerson);
1696 // Send message to search window controller subroutine and
1697 // pass that notification onto the search windows.
1699 // Setup the new pointer to use the existing UCNotif without
1702 UCNotif *ucd2 = ucd;
1704 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1705 sup.SetClientData(ucd2);
1706 wxPostEvent(this, sup);
1708 // Clear up the unused pointer.
1714 void frmMain::UpdateAccountList(wxCommandEvent& event){
1718 void frmMain::SetupPointers(void *ActMgrPtrInc){
1720 ActMgrPtr = ActMgrPtrInc;
1724 void frmMain::SetupForm(){
1726 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1727 frameActMgr->SetupPointers(&ETagProcTimer, this);
1729 // Setup the contact information icons for later.
1731 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1735 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1736 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1737 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1739 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1740 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1741 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1743 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1744 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1745 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1747 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1748 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1749 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1751 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1752 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1753 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1755 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1756 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1757 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1763 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1765 // Go through each of the search windows and
1766 // send the required notification to update the
1767 // contact information.
1769 // Get the event notification data.
1771 UCNotif *ucd = (UCNotif*)event.GetClientData();
1773 // Process each search window giving the new details.
1775 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1776 switer != SearchWindowList.end(); switer++){
1778 // Duplicate the event notification data.
1780 UCNotif *ucd2 = new UCNotif;
1782 ucd2->ContactAccount = ucd->ContactAccount;
1783 ucd2->ContactFilename = ucd->ContactFilename;
1784 ucd2->ContactName = ucd->ContactName;
1785 ucd2->ContactNickname = ucd->ContactNickname;
1786 ucd2->ContactNameArray = ucd->ContactNameArray;
1788 // Pass the data to the search window for processing.
1790 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1791 wxCommandEvent schupdate(SE_UPDATERESULT);
1792 schupdate.SetClientData(ucd2);
1793 wxPostEvent(frameSCH, schupdate);
1795 // Clear up the pointer prior to variable deletion.
1806 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1810 frmSearch *frameSCH = new frmSearch ( this );
1811 frameSCH->SetUID(WindowMenuItemID);
1812 frameSCH->Show(true);
1814 WindowData *WData = new WindowData;
1816 WData->DataType = 2;
1817 WData->WindowPointer = (void*)frameSCH;
1818 WData->WindowID = WindowMenuItemID;
1820 wxCommandEvent addevent(WINDOW_ADD);
1821 addevent.SetClientData(WData);
1822 wxPostEvent(this, addevent);
1824 // Add pointer to the list of open search windows.
1826 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1832 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1834 void *frameSCH = (void*)event.GetClientData();
1836 SearchWindowList.erase(frameSCH);
1842 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1844 void *frameSCH = (void*)event.GetClientData();
1846 SearchWindowList.erase(frameSCH);
1852 void frmMain::RevealContact(wxCommandEvent& event){
1854 UCNotif *uc = (UCNotif*)event.GetClientData();
1856 // Switch the account to the one passed.
1858 wxTreeItemIdValue cookie;
1859 wxTreeItemId next = treAccounts->GetRootItem();
1860 wxTreeItemId nextChild;
1862 for (int i = 0; i < prefaccounts.GetCount(); i++){
1865 nextChild = treAccounts->GetFirstChild(next, cookie);
1867 nextChild = treAccounts->GetNextSibling(nextChild);
1870 //AccountName = treAccounts->GetItemText(nextChild);
1872 if (uc->ContactAccount == AccountAccDirList[i]){
1875 treAccounts->SelectItem(nextChild, TRUE);
1876 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1882 // Switch the contact to the one passed.
1884 long longSelected = -1;
1885 int intSelectedData = 0;
1889 longSelected = lstContacts->GetNextItem(longSelected,
1891 wxLIST_STATE_DONTCARE);
1893 if (longSelected == -1){
1899 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1901 // Compare the filename with the one received.
1902 // If they match then select it.
1904 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1908 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1909 lstContacts->EnsureVisible(longSelected);
1913 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1921 void frmMain::DeleteContact(wxCommandEvent& event){
1923 // Check if a contact is selected.
1925 long intSelected = -1;
1926 long intContactSeekNum = -1;
1927 wxString wxSContactName;
1929 intSelected = lstContacts->GetNextItem(intSelected,
1931 wxLIST_STATE_SELECTED);
1933 if (intSelected == -1){
1937 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1939 // Get the item data of the contact.
1941 intContactSeekNum = lstContacts->GetItemData(intSelected);
1943 // Get the name of the contact.
1945 wxSContactName = lstContacts->GetItemText(intSelected);
1947 // Display a message confirming if the contact should
1950 int QuestionResponse;
1952 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1954 if (QuestionResponse == wxNO){
1956 // Exit the subroutine
1962 // Delete the contact.
1964 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1966 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1971 // Remove the contact from the list.
1973 lstContacts->DeleteItem(intSelected);
1975 // Update the search windows, removing the deleted
1978 UCNotif *ucd = new UCNotif;
1980 ucd->ContactAccount = ActiveAccount;
1981 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1983 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1984 switer != SearchWindowList.end(); switer++){
1986 // Duplicate the event notification data.
1988 UCNotif *ucd2 = new UCNotif;
1990 ucd2->ContactAccount = ucd->ContactAccount;
1991 ucd2->ContactFilename = ucd->ContactFilename;
1993 // Pass the data to the search window for processing.
1995 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1996 wxCommandEvent schdelete(SE_DELETERESULT);
1997 schdelete.SetClientData(ucd2);
1998 wxPostEvent(frameSCH, schdelete);
2000 // Clear up the pointer prior to variable deletion.
2007 // Clear the wxHTMLWindow.
2009 wxString EmptyPage = wxT("");
2011 htmContactData->SetPage(EmptyPage);
2013 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2015 wxString wxSplitFilename;
2016 wxString wxSDataURL;
2018 while(wSTFilename.HasMoreTokens()){
2020 wxSplitFilename = wSTFilename.GetNextToken();
2024 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2026 // Update the ETagDB and mark it as deleted.
2028 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2030 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2032 // Get the Data URL.
2034 wxTreeItemIdValue cookie;
2035 wxTreeItemId next = treAccounts->GetRootItem();
2037 wxTreeItemId selectedChild = treAccounts->GetSelection();
2038 wxTreeItemId nextChild;
2040 for (int i = 0; i < prefaccounts.GetCount(); i++){
2043 nextChild = treAccounts->GetFirstChild(next, cookie);
2046 nextChild = treAccounts->GetNextSibling(nextChild);
2049 if (nextChild == selectedChild){
2050 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2056 // Add task to the activity monitor to delete the contact.
2058 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2062 // Clear the variable. Don't delete as it will mess things up.
2064 ContactsFileIndex[intContactSeekNum] = wxT("");
2071 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2073 QRNotif *qrn = (QRNotif *)event.GetClientData();
2075 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);
2077 if (QResponse == wxNO){
2083 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2084 event2.SetInt(*qrn->QResponse);
2085 event2.SetClientData(qrn->PausePtr);
2087 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2089 wxPostEvent(frameActMgr, event2);
2093 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2095 // Remove the contact from the window after syncronising.
2097 // Check which account is currently active in the window.
2098 // If it is different from the one passed to this subroutine then
2099 // exit from the subroutine.
2101 if (Account != ActiveAccount){
2105 long longSelected = -1;
2106 int intSelectedData = 0;
2110 longSelected = lstContacts->GetNextItem(longSelected,
2112 wxLIST_STATE_DONTCARE);
2114 if (longSelected == -1){
2120 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2122 // Compare the filename with the one received.
2123 // If they match then select it.
2125 if (ContactsFileIndex[intSelectedData] == Filename){
2127 // Remove the contact from the window.
2129 lstContacts->DeleteItem(intSelectedData);
2131 // Check if contact is the selected contact in the HTML window and
2132 // if it is then clear the window.
2134 if (ActiveFilename == Filename){
2136 wxString EmptyPage = wxT("");
2137 htmContactData->SetPage(EmptyPage);
2151 void frmMain::SortFNLN( wxCommandEvent& event ) {
2153 wxTreeEvent NullEvent;
2155 LoadContactList(NullEvent);
2159 void frmMain::SortLNFN( wxCommandEvent& event ) {
2161 wxTreeEvent NullEvent;
2163 LoadContactList(NullEvent);
2167 void frmMain::SortNickname( wxCommandEvent& event ) {
2169 wxTreeEvent NullEvent;
2171 LoadContactList(NullEvent);
2175 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2177 wxTreeEvent NullEvent;
2179 LoadContactList(NullEvent);
2183 void frmMain::SortAscending( wxCommandEvent& event ) {
2185 wxTreeEvent NullEvent;
2186 AscendingMode = TRUE;
2187 LoadContactList(NullEvent);
2191 void frmMain::SortDescending( wxCommandEvent& event ) {
2193 wxTreeEvent NullEvent;
2194 AscendingMode = FALSE;
2195 LoadContactList(NullEvent);
2199 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2201 if (stbBottom->IsShown() == TRUE){
2215 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2217 // Display the activity icon.
2219 imgActivityStatus->SetBitmap(*imgActIcon1);
2220 ActivityIconStatus = 0;
2224 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2226 switch (ActivityIconStatus){
2229 imgActivityStatus->SetBitmap(*imgActIcon1);
2230 ActivityIconStatus = 1;
2233 imgActivityStatus->SetBitmap(*imgActIcon2);
2234 ActivityIconStatus = 2;
2237 imgActivityStatus->SetBitmap(*imgActIcon3);
2238 ActivityIconStatus = 3;
2241 imgActivityStatus->SetBitmap(*imgActIcon4);
2242 ActivityIconStatus = 0;
2245 ActivityIconStatus = 0;
2251 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2253 // Display the sleep icon.
2255 imgActivityStatus->SetBitmap(*imgActIconSleep);
2259 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2261 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2269 wxRect rectActivity;
2270 stbBottom->GetFieldRect(1, rectOnline);
2271 stbBottom->GetFieldRect(2, rectSSL);
2272 stbBottom->GetFieldRect(3, rectActivity);
2274 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2275 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2276 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2280 XABViewMode frmMain::GetViewMode(){
2284 xvm.SortMode = SortMode;
2285 xvm.AscendingMode = AscendingMode;
2291 void frmMain::WindowAdd( wxCommandEvent &event ){
2293 WindowData *WData = (WindowData*)event.GetClientData();
2297 if (WData->DataType == 0){
2301 int intID = mnuContactWindows->GetId();
2303 mnuWindow->FindChildItem(intID, &pos);
2304 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2305 mnuNewItem->SetId(WData->WindowID);
2306 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2307 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2308 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2309 mnuWindow->Insert((pos + 1), mnuNewItem);
2310 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2312 } else if (WData->DataType == 1){
2314 // Contact Editor Window
2316 int intID = mnuContactEditorWindows->GetId();
2318 mnuWindow->FindChildItem(intID, &pos);
2319 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2320 mnuNewItem->SetId(WData->WindowID);
2321 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2322 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2323 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2324 mnuWindow->Insert((pos + 1), mnuNewItem);
2325 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2327 } else if (WData->DataType == 2){
2331 int intID = mnuSearchWindows->GetId();
2333 mnuWindow->FindChildItem(intID, &pos);
2334 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2335 mnuNewItem->SetId(WData->WindowID);
2336 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2337 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2338 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2339 mnuWindow->Insert((pos + 1), mnuNewItem);
2340 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2349 void frmMain::WindowEdit( wxCommandEvent &event ){
2351 WindowData *WData = (WindowData*)event.GetClientData();
2353 if (WData->DataType == 0){
2355 // Get the window title and use that.
2357 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2359 wxString WindowTitle = frmContactPtr->GetTitle();
2361 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2363 MenuIter->second->SetItemLabel(WindowTitle);
2365 } else if (WData->DataType == 1){
2367 // Get the window title and use that.
2369 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2371 wxString WindowTitle = frmCEPtr->GetTitle();
2373 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2375 if (WindowTitle.IsEmpty()){
2377 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2381 MenuIter->second->SetItemLabel(WindowTitle);
2392 void frmMain::WindowDelete( wxCommandEvent &event ){
2394 WindowData *WData = (WindowData*)event.GetClientData();
2396 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2398 mnuWindow->Remove(MenuIter->second);
2400 delete MenuIter->second;
2401 MenuIter->second = NULL;
2403 WindowListPointersMenu.erase(WData->WindowID);
2404 WindowListPointers.erase(WData->WindowID);
2405 WindowListType.erase(WData->WindowID);
2412 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2414 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2416 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2418 frmContactPtr->Show();
2419 frmContactPtr->Raise();
2423 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2425 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2427 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2434 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2436 // Look through the Search Window List Pointers, grab the
2437 // window point and show the window.
2439 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2441 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2443 frmSearchPtr->Show();
2444 frmSearchPtr->Raise();
2448 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2450 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2451 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2452 wxPostEvent(frameActMgr, toggconn);
2456 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2458 // Check the account type before continuing.
2460 wxString SeekAccount;
2461 wxString AccTypeLower;
2464 std::map<int, SSLCertCollection>::iterator SSLColIter;
2466 for (int i = 0; i < prefaccounts.GetCount(); i++){
2468 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2469 AccType.Append(prefaccounts.GetAccountType(i));
2470 AccountSSL = prefaccounts.GetAccountSSL(i);
2471 AccTypeLower = AccType.MakeLower();
2472 SeekAccount.Append(wxT("."));
2473 SeekAccount.Append(AccTypeLower);
2475 if (SeekAccount == ActiveAccount){
2477 if (AccTypeLower == wxT("local")){
2483 if (AccountSSL == false){
2489 SSLColIter = AccountSSLData.find(i);
2491 SSLCertCollection SSLCertInfo = SSLColIter->second;
2493 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2494 frameSSLCert->StartCertFrom(0);
2495 frameSSLCert->SetupCerts(SSLCertInfo);
2496 frameSSLCert->ShowModal();
2498 delete frameSSLCert;
2499 frameSSLCert = NULL;
2503 SeekAccount.Clear();
2504 AccTypeLower.Clear();
2511 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2513 // Check the account type before continuing.
2517 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2519 // Check the account type before continuing.
2523 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2525 if (event.GetInt() == 0){
2527 imgConnStatus->SetBitmap(*imgOnline);
2531 imgConnStatus->SetBitmap(*imgOffline);
2537 void frmMain::SetupSSLStatus( int AccountID ){
2539 // Check if account ID given is
2540 // the active account and if not, do nothing.
2543 wxString AccTypeLower;
2545 AccType = prefaccounts.GetAccountType(AccountID);
2546 AccTypeLower = AccType.MakeLower();
2548 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2551 if (AccountIDName != ActiveAccount){
2557 // Check if the account has SSL enabled.
2559 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2561 if (SSLInUse == FALSE){
2563 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2564 imgSSLStatus->SetBitmap(*imgNoSSL);
2568 // Get the SSL Collection Data.
2570 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2572 if (SSLResultIter->second == 1){
2574 imgSSLStatus->SetBitmap(*imgSSLWarning);
2575 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2576 prefaccounts.GetAccountName(AccountID) +
2577 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2580 } else if (SSLResultIter->second == 0){
2582 imgSSLStatus->SetBitmap(*imgSSL);
2583 SSLToolTip->SetTip(wxT("Account '") +
2584 prefaccounts.GetAccountName(AccountID) +
2585 wxT("' secured using SSL\n\nDouble click for more information."));
2593 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2595 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2596 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2597 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2598 wxString AccountName = SSLICNObj->AccountName;
2599 frameISC->LoadData(SSLCCData, AccountName);
2600 frameISC->ShowModal();
2602 int FinalConflictResult = frameISC->GetResult();
2604 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2605 event2.SetClientData(SSLICNObj->QRNotifData);
2606 event2.SetInt(FinalConflictResult);
2611 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2612 wxPostEvent(frameActMgr, event2);
2615 void frmMain::PauseAllTimers(){
2617 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2618 ASTiter != AccountSyncTimers.end(); ASTiter++){
2620 ASTiter->second->Stop();
2626 void frmMain::ResumeAllTimers(){
2628 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2629 ASTiter != AccountSyncTimers.end(); ASTiter++){
2631 ASTiter->second->Start();
2637 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2639 // Delete existing data.
2641 AccountSSLData.erase(AccountID);
2642 AccountSSLResult.erase(AccountID);
2646 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2647 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2651 void frmMain::CheckUpdates( wxCommandEvent& event ){
2653 frmUpdate *frameUpdate = new frmUpdate ( this );
2654 frameUpdate->FetchData();
2655 frameUpdate->ShowModal();
2659 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2661 // Run the import contacts system.
2667 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2669 // Check if an account and at least one contact is selected
2670 // before continuing.
2672 wxArrayString ArrData;
2674 if (ActiveAccount.IsEmpty()){
2680 int ContactSelected = 0;
2681 int ContactsCollected = 0;
2682 long longSelected = -1;
2686 longSelected = lstContacts->GetNextItem(longSelected,
2688 wxLIST_STATE_SELECTED);
2690 if (longSelected == -1){
2696 int FileID = (int)lstContacts->GetItemData(longSelected);
2698 ArrData.Insert(ContactsFileIndex[FileID],
2699 ContactsCollected, 1);
2705 if (ContactSelected == 0){
2711 // Run the export contacts system.
2713 ExportRun(this, &ArrData);
2717 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2718 wxArrayString *ContactsFileIndexPtr){
2720 lstContactsPtr = lstContacts;
2721 ContactsFileIndexPtr = &ContactsFileIndex;
2725 void frmMain::GetSelectedList( wxCommandEvent& event ){
2727 // Get the array of contact filenames.
2729 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2731 // Process them into an array of files.
2733 long longSelected = -1;
2734 int ContactsCollected = 0;
2735 wxString ContactFilename;
2739 longSelected = lstContacts->GetNextItem(longSelected,
2741 wxLIST_STATE_SELECTED);
2743 if (longSelected == -1){
2749 // Get the file information and add to the list.
2751 int FileID = (int)lstContacts->GetItemData(longSelected);
2753 ArrData->Insert(ContactsFileIndex[FileID],
2754 ContactsCollected, 1);
2756 ContactsCollected++;
2757 ContactFilename.Clear();
2765 void frmMain::SyncAccount( wxCommandEvent& event ){
2767 wxString AccNameInc = event.GetString();
2769 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2770 frameActMgr->AddTask(3, wxT(""), AccNameInc,
2771 wxT(""), wxT(""), wxT(""), wxT(""));
2775 void frmMain::ShowHelp( wxCommandEvent& event ){
2777 // Based on the operating system, work out where
2778 // the documentation should be.
2782 #if defined(__HAIKU__)
2784 #elif defined(__WIN32__)
2790 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2792 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2795 #if XSDAB_RELEASE == 0
2797 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2799 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2808 #if XSDAB_RELEASE == 0
2810 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2814 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!"));
2820 void frmMain::ShowImportResults( wxCommandEvent &event ){
2822 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2824 frmImportResults *frmIR = new frmImportResults(this);
2825 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
2836 void frmMain::ReloadContactList( wxCommandEvent &event ){
2838 // Check if the account name given is the current
2839 // account selected.
2841 if (ActiveAccount == event.GetString()){
2843 wxTreeEvent NullEvent;
2844 LoadContactList(NullEvent);
2850 void frmMain::ShowContactMenu( wxMouseEvent& event ){
2852 bool EnableRefresh = FALSE;
2854 if (!ActiveAccount.IsEmpty()){
2856 EnableRefresh = TRUE;
2860 ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
2862 this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);