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>
35 //#include <boost/filesystem/fstream.hpp>
41 #include "frmPreferences.h"
42 #include "frmNewAccount.h"
43 #include "frmActivityMgr.h"
44 #include "frmContact.h"
45 #include "frmConflictResolution.h"
46 #include "frmInvalidSSLCertificate.h"
47 #include "frmSearch.h"
48 #include "frmSSLCertificate.h"
49 #include "frmUpdate.h"
50 #include "import/frmImportResults.h"
53 #include "common/preferences.h"
54 #include "common/getcontactinfo.h"
55 #include "common/events.h"
56 #include "common/dirs.h"
57 #include "vcard/vcard.h"
58 #include "carddav/carddav.h"
59 #include "contacteditor/frmContactEditor.h"
60 #include "import/import.h"
61 #include "export/export.h"
62 #include "widgets/XABContactMenu.h"
63 #include "widgets/XABAccountView.h"
67 //extern const wxEventType MyHaremEvent = wxNewEventType();
69 //#define CE_UPDATECONTACTLIST 7700
70 //#define CE_UPDATEACCOUNTLIST 7701
72 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
73 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
74 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
75 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
76 DEFINE_EVENT_TYPE(CE_OPENCONTACTLIST);
77 DEFINE_EVENT_TYPE(CE_NEWCONTACT);
78 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
79 DEFINE_EVENT_TYPE(CE_DELETECONTACT);
80 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
81 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
82 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
83 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
84 DEFINE_EVENT_TYPE(ACTMGR_START);
85 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
86 DEFINE_EVENT_TYPE(ACTMGR_STOP);
87 DEFINE_EVENT_TYPE(WINDOW_ADD);
88 DEFINE_EVENT_TYPE(WINDOW_EDIT);
89 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
90 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
91 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
92 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
93 DEFINE_EVENT_TYPE(SYNCACCOUNT);
94 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
95 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
96 DEFINE_EVENT_TYPE(REFRESHADDRESSBOOK);
98 BEGIN_EVENT_TABLE(frmMain, wxFrame)
99 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
100 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
101 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
102 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
103 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
104 EVT_COMMAND(wxID_ANY, CE_OPENCONTACTLIST, frmMain::OpenContactInfoList)
105 EVT_COMMAND(wxID_ANY, CE_NEWCONTACT, frmMain::ShowContactEditorNew)
106 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
107 EVT_COMMAND(wxID_ANY, CE_DELETECONTACT, frmMain::DeleteContact)
108 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
109 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
110 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
111 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
112 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
113 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
114 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
115 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
116 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
117 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
118 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
119 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
120 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
121 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
122 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
123 EVT_COMMAND(wxID_ANY, REFRESHADDRESSBOOK, frmMain::RefreshAddressBook)
126 frmMain::frmMain( wxWindow* parent )
131 // Setup the account icons.
133 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
134 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
135 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
136 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
138 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
139 wxBitmap AccInet(icons_accinet_png, -1);
141 wxIAccInet.CopyFromBitmap(AccInet);
143 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
144 wxBitmap AccNIcon(icons_acclocal_png, -1);
146 wxIAccNIcon.CopyFromBitmap(AccNIcon);
148 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
149 wxBitmap AccGrp(icons_accgroup_png, -1);
151 wxIAccGrp.CopyFromBitmap(AccGrp);
153 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
154 wxBitmap AccNone(icons_accnone_png, -1);
156 wxIAccNone.CopyFromBitmap(AccNone);
158 AccountID = AccImgList->Add(wxIAccNIcon);
159 AccountNetID = AccImgList->Add(wxIAccInet);
160 AccountGrpID = AccImgList->Add(wxIAccGrp);
161 AccountNoneID = AccImgList->Add(wxIAccNone);
163 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
165 // Setup the status bar icons.
169 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
170 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
171 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
173 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
174 imgSSL = new wxBitmap(icons_ssl_png, -1);
176 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
177 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
179 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
180 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
184 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
185 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
186 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
187 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
188 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
190 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
191 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
193 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
194 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
196 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
198 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
199 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
201 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
203 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
204 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
206 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
208 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
209 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
211 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
213 // Online/Offline icons.
215 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
216 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
218 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
219 imgOnline = new wxBitmap(icons_online_png, -1);
221 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
222 imgOffline = new wxBitmap(icons_offline_png, -1);
224 // Setup the account view.
226 AccCtrl->SetPopupControl(treAccounts);
227 AccCtrl->SetPopupMaxHeight(175);
228 AccCtrl->SetPopupMinWidth(250);
229 treAccounts->AssignImageList(AccImgList);
232 /*wxStaticBitmap* BeepBoop = new wxStaticBitmap(AccCtrl, wxID_ANY, wxNullBitmap, wxPoint(AccTextCtrlSize.GetX() + 3, AccTextCtrlSize.GetY() + 2), wxDefaultSize, 0);
234 icons_accgroup_png.SetMask(new wxMask(icons_accgroup_png, wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND)));
236 BeepBoop->SetBackgroundColour(AccCtrl->GetBackgroundColour());
237 BeepBoop->SetBitmap(icons_accgroup_png);*/
239 //szrContactList->Insert(0, XABV2, 1, wxEXPAND | wxALL, 0);
241 /*AccControl->UseAltPopupWindow();
242 AccControl->SetPopupControl(treAccounts);
243 AccControl->SetPopupMaxHeight(175);
245 treAccounts->AssignImageList(AccImgList);
246 szrContactList->Insert(0, AccControl, 1, wxEXPAND|wxALL, 0);
247 szrAccList->Add(AccIcon, 0, wxLEFT|wxTOP|wxEXPAND, 3);
251 //szrContactList->Layout();
252 //szrContactList->RecalcSizes();
254 wxListItem ColumnData;
256 ColumnData.SetText(wxT("Name0"));
257 ColumnData.SetWidth(320);
258 lstContacts->InsertColumn(0, ColumnData);
260 //Connect(wxID_ANY, ContactConflictCmdEnv,
261 // ContactConflictEventHandler(frmMain::ConflictResolution), NULL, this);
263 //Connect(wxID_ANY, MyFooCommandEvent,
264 // MyFooEventHandler(frmMain::DoSomething), NULL, this);
266 //Bind(ContactConflictCmdEnv, ContactConflictEventHandler(frmMain::ConflictResolution), this, wxID_ANY);
268 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
269 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
271 #if defined(__HAIKU__)
273 #elif defined(__WIN32__)
275 int stbBottomData [4] = { -1, 8, 8, 8 };
279 int stbBottomData [4] = { -1, 20, 20, 20 };
283 stbBottom->SetFieldsCount(4, stbBottomData);
284 stbBottom->SetMinHeight(16);
289 stbBottom->GetFieldRect(1, rectOnline);
290 stbBottom->GetFieldRect(2, rectSSL);
291 stbBottom->GetFieldRect(3, rectActivity);
293 SSLToolTip = new wxToolTip(wxT(""));
295 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
296 imgConnStatus->SetBitmap(*imgOnline);
297 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
299 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
300 imgSSLStatus->SetBitmap(*imgNoSSL);
301 imgSSLStatus->SetToolTip(SSLToolTip);
302 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
304 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
305 imgActivityStatus->SetBitmap(*imgActIconSleep);
306 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
308 // Setup the window menu.
310 // By default should be:
315 // Contact editor windows:
321 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
322 mnuWindow->Append( mnuContactWindows );
324 mnuWindow->AppendSeparator();
326 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
327 mnuWindow->Append( mnuContactEditorWindows );
329 mnuWindow->AppendSeparator();
331 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
332 mnuWindow->Append( mnuSearchWindows );
334 #if defined(__WIN32__)
339 mnuContactWindows->SetFont(fontstyle);
340 mnuContactEditorWindows->SetFont(fontstyle);
341 mnuSearchWindows->SetFont(fontstyle);
345 mnuContactWindows->Enable(FALSE);
346 mnuContactEditorWindows->Enable(FALSE);
347 mnuSearchWindows->Enable(FALSE);
351 // Hide unimplemented functions.
357 void frmMain::QuitApp( wxCloseEvent& event )
364 void frmMain::QuitApp( wxCommandEvent& event )
371 void frmMain::QuitApp()
373 //-------------------------------------------------------------------
374 // frmMain::QuitApp: Quits the application by simply closing this
375 // window which causes the exit as frmMain is the main window.
377 // wxCommandEvent Accepts a referenced event command.
378 //-------------------------------------------------------------------
380 //-------------------------------------------------------------------
381 // frmMain::QuitApp: Quits the application by simply closing this
382 // window which causes the exit as frmMain is the main window.
384 // wxCommandEvent Accepts a referenced event command.
385 //-------------------------------------------------------------------
387 //Go through the windows and close each one (be it search
388 //or contact editor). Abort if user wants to cancel.
390 // Close the contact editor windows.
392 // Close the contact windows.
394 // Close the search windows.
396 // Write out the ETag databases.
398 // Save Preferences: Save the window position if that option is enabled.
400 wxString SetFilename = GetUserPrefDir();
402 #if defined(__HAIKU__)
406 #elif defined(__WIN32__)
408 SetFilename.Append(wxT("settings"));
414 SetFilename.Append(wxT("settings"));
418 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
420 bool SaveWindowPos = FALSE;
421 wxString SaveWindowInc;
422 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
424 if (SaveWindowInc == wxT("true")){
426 SaveWindowPos = TRUE;
430 if (SaveWindowPos == TRUE){
432 wxRect frmMainPos = this->GetRect();
434 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
435 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
436 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
437 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
445 //Everything closed... exit.
453 void frmMain::ShowActivityWindow( wxCommandEvent& event )
456 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
457 frameActMgr->OpenWindow();
462 void frmMain::ShowAboutWindow( wxCommandEvent& event )
464 //-------------------------------------------------------------------
465 // frmMain::ShowAboutWindow: Shows the About window as a modal
466 // dialog and then cleans up when finished.
468 // wxCommandEvent Accepts a referenced event command.
469 //-------------------------------------------------------------------
471 frmAbout *frameAbout = new frmAbout ( this );
472 frameAbout->SetupAboutWindow();
473 frameAbout->ShowModal();
479 void frmMain::OpenPreferences( wxCommandEvent& event)
481 //-------------------------------------------------------------------
482 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
483 // dialog and then cleans up when finished.
485 // wxCommandEvent Accepts a referenced event command.
486 //-------------------------------------------------------------------
488 ReloadAccounts = FALSE;
490 frmPreferences *framePreferences = new frmPreferences ( this );
491 framePreferences->SetupPointers(&ReloadAccounts);
492 framePreferences->ShowModal();
493 delete framePreferences;
494 framePreferences = NULL;
496 if (ReloadAccounts == TRUE){
498 // Reload the accounts as a change has been made within
501 this->LoadPreferences();
507 void frmMain::OpenNewABDialog( wxCommandEvent& event)
509 //-------------------------------------------------------------------
510 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
511 // dialog and then cleans up when finished.
513 // wxCommandEvent Accepts a referenced event command.
514 //-------------------------------------------------------------------
516 ReloadAccounts = FALSE;
518 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
519 frameNewAccount->SetupPointers(&ReloadAccounts);
520 frameNewAccount->ShowModal();
521 delete frameNewAccount;
522 frameNewAccount = NULL;
524 if (ReloadAccounts == TRUE){
526 // Reload the accounts as a change has been made within
529 this->LoadPreferences();
535 void frmMain::LoadContactList( wxTreeEvent& event )
538 // Clear all existing variables.
540 lstContacts->DeleteAllItems();
542 treAccounts->SetAccount();
544 wxTreeItemIdValue cookie;
545 wxTreeItemId next = treAccounts->GetRootItem();
546 wxString AccountName;
547 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
548 wxString AccountDirCmb;
549 long selectedaccount = 0;
551 wxTreeItemId selectedChild = treAccounts->GetSelection();
552 wxTreeItemId nextChild;
554 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
555 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
557 int SCImg = treAccounts->GetItemImage(selectedChild);
558 int AccountIndex = 0;
560 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
562 for (int i = 0; i < prefaccounts.GetCount(); i++){
564 if (ActiveItemIcon == 2){
566 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
567 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
568 int ActiveAccountG = AGLiter->second;
570 if (i == ActiveAccountG){
572 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
573 AccountType.Append(prefaccounts.GetAccountType(i));
578 if (AccountType == wxT("CardDAV")){
579 AccountTypeFinal.Append(wxT("carddav"));
581 else if (AccountType == wxT("Local")){
582 imgSSLStatus->SetBitmap(*imgOffline);
583 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
584 AccountTypeFinal.Append(wxT("local"));
595 nextChild = treAccounts->GetFirstChild(next, cookie);
598 nextChild = treAccounts->GetNextSibling(nextChild);
601 AccountName = treAccounts->GetItemText(nextChild);
603 if (nextChild == selectedChild){
604 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
605 AccountType.Append(prefaccounts.GetAccountType(i));
610 if (AccountType == wxT("CardDAV")){
611 AccountTypeFinal.Append(wxT("carddav"));
613 else if (AccountType == wxT("Local")){
614 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
615 AccountTypeFinal.Append(wxT("local"));
624 if (selectedaccount >= prefaccounts.GetCount()){
626 // The account selected isn't there so return.
634 // Open the directory and get the list of .vcf files
635 // in that directory.
637 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
638 ActiveAccountType = AccountType;
640 SetupSSLStatus(AccountIndex);
642 AccountDirFinal.Clear();
643 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
645 ContactsFileIndex.Clear();
647 //wxString vcardfilenamewxs;
648 wxString vCardFilename;
649 wxString vCardFilenameFull;
650 wxString vCardDataString;
651 wxStringTokenizer vcardfileline;
653 wxString setname, setvalue;
654 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
655 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
656 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
657 long ContactIndex = 1;
658 long ContactSeekPoint = 0;
660 wxDir vcardaccdir(AccountDirFinal);
662 // Get the wxTreeItemId and image icon and compare it to the list.
664 if (ActiveItemIcon == AccountGrpID){
666 // It's a group so load the file containing the group and
667 // get the members of the group.
672 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
673 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
674 //std::multimap<wxTreeItemId, int>::iterator AGFiter = AccountGroupTreeId.find(ActiveItemId);
676 Group.LoadFile(AGFiter->second);
678 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
680 for (int i = 0; i < vCardMember.PropCount; i++){
682 vCardMember.PropValues[i].Trim();
683 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
685 wxString NewPropValue;
686 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
687 vCardMember.PropValues[i] = NewPropValue;
694 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
697 if (vCardFilename.Right(4) == wxT(".vcf") ||
698 vCardFilename.Right(4) == wxT(".VCF") ||
699 vCardFilename.Right(5) == wxT(".vcard") ||
700 vCardFilename.Right(5) == wxT(".VCARD")){
703 bool FoundMember = FALSE;
705 vCardFilenameFull.Append(AccountDirFinal);
706 vCardFilenameFull.Append(wxT("/"));
707 vCardFilenameFull.Append(vCardFilename);
709 Person.LoadFile(vCardFilenameFull);
711 UIDCode = Person.Get(wxT("UID"));
713 for (int i = 0; i < vCardMember.PropCount; i++){
715 if (vCardMember.PropValues[i] == UIDCode){
723 if (FoundMember == FALSE){
725 vCardFilename.Clear();
726 vCardFilenameFull.Clear();
727 vCardDataString.Clear();
728 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
733 if (Person.MeetBaseSpecification()){
737 // Split the name into sections.
739 vCardDataString = Person.Get(wxT("N"));
741 vCardName NameData = Person.GetName();
743 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
745 } else if (SortMode == 2){
747 // Split the name into sections.
749 vCardName NameData = Person.GetName();
751 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
753 } else if (SortMode == 3){
755 // Check and make sure that the top most nickname is used.
757 vCardDataString = Person.Get(wxT("NICKNAME"));
759 if (vCardDataString.IsEmpty()){
761 vCardDataString = wxT("(no nickname)");
765 } else if (SortMode == 4){
767 vCardDataString = Person.Get(wxT("FN"));
771 if (AscendingMode == TRUE){
772 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
774 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
783 vCardFilename.Clear();
784 vCardFilenameFull.Clear();
785 vCardDataString.Clear();
786 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
791 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
794 if (vCardFilename.Right(4) == wxT(".vcf") ||
795 vCardFilename.Right(4) == wxT(".VCF") ||
796 vCardFilename.Right(5) == wxT(".vcard") ||
797 vCardFilename.Right(5) == wxT(".VCARD")){
801 vCardFilenameFull.Append(AccountDirFinal);
802 vCardFilenameFull.Append(vCardFilename);
804 Person.LoadFile(vCardFilenameFull);
806 if (Person.MeetBaseSpecification()){
810 // Split the name into sections.
812 vCardDataString = Person.Get(wxT("N"));
814 vCardName NameData = Person.GetName();
816 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
818 } else if (SortMode == 2){
820 // Split the name into sections.
822 vCardName NameData = Person.GetName();
824 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
826 } else if (SortMode == 3){
828 // Check and make sure that the top most nickname is used.
830 vCardDataString = Person.Get(wxT("NICKNAME"));
832 if (vCardDataString.IsEmpty()){
834 vCardDataString = wxT("(no nickname)");
838 } else if (SortMode == 4){
840 vCardDataString = Person.Get(wxT("FN"));
844 if (AscendingMode == TRUE){
845 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
847 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
856 vCardFilename.Clear();
857 vCardFilenameFull.Clear();
858 vCardDataString.Clear();
859 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
866 // Insert the data into the control.
868 if (AscendingMode == TRUE){
869 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
870 iter != vCardNamesAsc.end(); ++iter){
872 wxListItem ContactInfo;
874 ContactInfo.SetId(0);
875 ContactInfo.SetText(_("Mooo"));
876 ContactInfo.SetData(ContactSeekPoint);
877 ContactIndex = lstContacts->InsertItem(ContactInfo);
879 lstContacts->SetItem(ContactIndex, 0, iter->first);
880 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
887 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
888 iter != vCardNamesDsc.end(); ++iter){
890 wxListItem ContactInfo;
892 ContactInfo.SetId(0);
893 ContactInfo.SetText(_("Mooo"));
894 ContactInfo.SetData(ContactSeekPoint);
895 ContactIndex = lstContacts->InsertItem(ContactInfo);
897 lstContacts->SetItem(ContactIndex, 0, iter->first);
898 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
907 void frmMain::ShowContactInfo( wxListEvent& event )
910 long intSelected = -1;
911 long ContactSeekNum = -1;
913 // intSelected = lstContacts->GetSelection();
915 // Check if several contacts have been selected.
917 int ContactTotal = 0;
921 intSelected = lstContacts->GetNextItem(intSelected,
923 wxLIST_STATE_SELECTED);
925 if (intSelected == -1){
935 if (ContactTotal == 0){
936 htmContactData->SetPage(wxT(""));
940 if (ContactTotal > 1){
942 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
943 ActiveFilename.Clear();
948 intSelected = lstContacts->GetNextItem(intSelected,
950 wxLIST_STATE_SELECTED);
952 ContactSeekNum = lstContacts->GetItemData(intSelected);
955 wxString wxSContactString;
956 wxString ContactLine;
959 size_t ContactLineLen;
960 bool ExtraLineSeek = FALSE;
961 int QuoteBreakPoint = 0;
963 bool PropertyFind = FALSE;
964 bool QuoteMode = FALSE;
966 wxString wxSPropertyNextLine;
967 wxString wxSProperty;
968 wxString wxSPropertySeg1;
969 wxString wxSPropertySeg2;
971 // Check if we are using wxWidgets version 2.8 or less and
972 // execute the required command accordingly.
974 #if wxABI_VERSION < 20900
975 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
977 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
980 if (ContactFile.IsOpened() == FALSE){
986 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
990 std::map<int, wxString> ContactFileLines;
991 std::map<int, wxString>::iterator striter;
993 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
995 int ContactLineSeek = 0;
997 while (wSTContactFileLines.HasMoreTokens() == TRUE){
999 ContactLine = wSTContactFileLines.GetNextToken();
1000 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
1005 if (ContactSeekNum < 0){
1009 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
1010 iter != ContactFileLines.end(); ++iter){
1012 // Find the colon which splits the start bit from the data part.
1014 ContactLine = iter->second;
1016 while (ExtraLineSeek == TRUE){
1018 // Check if there is extra data on the next line
1019 // (indicated by space or tab at the start) and add data.
1023 if (iter == ContactFileLines.end()){
1030 wxSPropertyNextLine = iter->second;
1033 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
1035 wxSPropertyNextLine.Remove(0, 1);
1036 //wxSPropertyNextLine.Trim(FALSE);
1037 //ContactLine.Trim();
1038 ContactLine.Append(wxSPropertyNextLine);
1043 ExtraLineSeek = FALSE;
1049 ContactLineLen = ContactLine.Len();
1051 // Make sure we are not in quotation mode.
1052 // Make sure colon does not have \ or \\ before it.
1054 for (int i = 0; i <= ContactLineLen; i++){
1056 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1058 PropertyFind = FALSE;
1060 } else if (PropertyFind == TRUE){
1062 wxSProperty.Append(ContactLine.Mid(i, 1));
1066 if (ContactLine.Mid(i, 1) == wxT("\"")){
1068 if (QuoteMode == TRUE){
1080 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1082 QuoteBreakPoint = i;
1089 // Split that line at the point into two variables (ignore the colon).
1091 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1092 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1094 // Insert both into the vCard data file.
1096 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1099 PropertyFind = TRUE;
1100 ExtraLineSeek = TRUE;
1102 QuoteBreakPoint = 0;
1103 ContactLine.Clear();
1104 wxSProperty.Clear();
1108 OldSessionID = SessionID;
1109 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1110 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1111 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1115 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1118 // Check if there is an account selected and if not
1119 // return immediately.
1121 if (ActiveAccount.IsEmpty()){
1127 // Add Pointer to SetupPointers for the ETagDB.
1129 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1130 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1131 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1133 contacticon.CopyFromBitmap(contacticonbmp);
1135 frmContactEditor *ContactEditor = new frmContactEditor( this );
1139 ContactEditor->SetUID(WindowMenuItemID);
1141 WindowData *WData = new WindowData;
1143 WData->DataType = 1;
1144 WData->WindowPointer = (void*)ContactEditor;
1145 WData->WindowID = WindowMenuItemID;
1147 wxCommandEvent addevent(WINDOW_ADD);
1148 addevent.SetClientData(WData);
1149 wxPostEvent(this, addevent);
1151 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1152 ContactEditor->SetupHeaders();
1153 ContactEditor->SetupContact(ActiveAccount);
1154 ContactEditor->SetIcon(contacticon);
1155 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1156 ContactEditor->Show(true);
1160 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1163 // Check if there is an account selected and if not
1164 // return immediately.
1166 int DataCheck = event.GetInt();
1168 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1174 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1175 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1176 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1178 contacticon.CopyFromBitmap(contacticonbmp);
1180 // Check if a contact has been selected.
1182 long intSelected = -1;
1183 long intContactSeekNum = -1;
1185 // intSelected = lstContacts->GetSelection();
1187 intSelected = lstContacts->GetNextItem(intSelected,
1189 wxLIST_STATE_SELECTED);
1191 if (intSelected == -1){
1195 intContactSeekNum = lstContacts->GetItemData(intSelected);
1197 // Get the filename of the selected contact.
1199 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1200 frmContactEditor *ContactEditor = new frmContactEditor( this );
1204 ContactEditor->SetUID(WindowMenuItemID);
1206 WindowData *WData = new WindowData;
1208 WData->DataType = 1;
1209 WData->WindowPointer = (void*)ContactEditor;
1210 WData->WindowID = WindowMenuItemID;
1212 wxCommandEvent addevent(WINDOW_ADD);
1213 addevent.SetClientData(WData);
1214 wxPostEvent(this, addevent);
1216 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1217 ContactEditor->SetupHeaders();
1219 // Check if pointer is NULL (not from the search forms) or not.
1221 if (DataCheck == 0){
1223 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1224 ContactEditor->SetupContact(ActiveAccount);
1228 UCNotif *uc = (UCNotif*)event.GetClientData();
1232 ContactEditor->SetupContact(ActiveAccount);
1233 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1237 ContactEditor->SetupContact(uc->ContactAccount);
1238 ContactEditor->LoadContact(uc->ContactFilename);
1248 ContactEditor->SetIcon(contacticon);
1249 ContactEditor->Show(true);
1253 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1255 // Check if ActiveAccount is empty. If not then check if
1256 // account type is not local otherwise continue.
1258 if (!ActiveAccount.IsEmpty()){
1260 if (ActiveAccountType != wxT("Local")){
1262 // Account type is not local.
1264 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1265 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1266 wxT(""), wxT(""), wxT(""), wxT(""));
1270 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1278 void frmMain::OpenContactInfoList( wxListEvent& event )
1281 wxStringTokenizer vcardfileline;
1284 wxString setname, setvalue;
1288 long intSelected = -1;
1289 long intContactSeekNum = -1;
1291 intSelected = lstContacts->GetNextItem(intSelected,
1293 wxLIST_STATE_SELECTED);
1295 intContactSeekNum = lstContacts->GetItemData(intSelected);
1297 if (intContactSeekNum == -1){
1301 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1303 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1304 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1305 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1307 contacticon.CopyFromBitmap(contacticonbmp);
1309 frmContact *Contact = new frmContact( this );
1311 // Add to window list.
1315 Contact->SetUID(WindowMenuItemID);
1317 WindowData *WData = new WindowData;
1319 WData->DataType = 0;
1320 WData->WindowPointer = (void*)Contact;
1321 WData->WindowID = WindowMenuItemID;
1323 wxCommandEvent addevent(WINDOW_ADD);
1324 addevent.SetClientData(WData);
1325 wxPostEvent(this, addevent);
1327 Contact->SetupPointers(&MemoryFileList);
1328 Contact->SetupContactData(&Person);
1330 Contact->SetIcon(contacticon);
1331 Contact->Show(true);
1335 void frmMain::OpenContactInfoList( wxCommandEvent& event ){
1338 OpenContactInfoList(pevent);
1342 void frmMain::OpenContactInfo( wxCommandEvent& event )
1345 UCNotif *uc = (UCNotif*)event.GetClientData();
1347 wxStringTokenizer vcardfileline;
1350 wxString setname, setvalue;
1353 //std::fstream vcardfile;
1355 Person.LoadFile(uc->ContactFilename);
1357 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1358 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1359 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1361 contacticon.CopyFromBitmap(contacticonbmp);
1363 frmContact *Contact = new frmContact( this );
1365 // Add to window list.
1369 Contact->SetUID(WindowMenuItemID);
1371 WindowData *WData = new WindowData;
1373 WData->DataType = 0;
1374 WData->WindowPointer = (void*)Contact;
1375 WData->WindowID = WindowMenuItemID;
1377 wxCommandEvent addevent(WINDOW_ADD);
1378 addevent.SetClientData(WData);
1379 wxPostEvent(this, addevent);
1381 Contact->SetupPointers(&MemoryFileList);
1382 Contact->SetupContactData(&Person);
1384 Contact->SetIcon(contacticon);
1385 Contact->Show(true);
1390 void frmMain::LoadPreferences( wxActivateEvent& event)
1392 this->LoadPreferences();
1395 void frmMain::LoadPreferences(){
1397 // Load the preferences.
1399 wxString preffilename = GetUserPrefDir();
1401 XABPreferences preferences(preffilename);
1403 // Setup the main window position (if needed).
1405 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1406 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1408 if (SaveWindowPos == TRUE){
1410 this->SetSize(preferences.GetMainWindowData());
1414 treAccounts->DeleteAllItems();
1416 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1418 // Stop all account timers and remove the accounts.
1420 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1421 iter != AccountSyncTimers.end(); iter++){
1423 wxAccountSyncTimer *AccTmrPtr = iter->second;
1431 AccountSyncTimers.clear();
1434 for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
1435 treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
1440 wxString AccDirFull;
1441 wxString AccDirFullSfx;
1443 wxString AccDirFinal;
1444 AccountAccDirList.clear();
1445 AccountGroupList.clear();
1446 AccountGroupFilename.clear();
1447 AccountGroupTreeId.clear();
1448 wxTreeItemId AccountTreeId;
1449 wxTreeItemId GroupTreeId;
1452 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1454 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1455 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1461 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1467 AccDir = preferences.accounts.GetAccountDirectory(i);
1468 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1470 AccDirFull.Append(wxT("."));
1471 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1472 AccDirFullSfx.LowerCase();
1473 AccDirFullSfx.Trim();
1474 AccDirFull.Append(AccDirFullSfx);
1475 AccName = preferences.accounts.GetAccountName(i);
1477 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1479 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1480 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1482 // Check if the directory exists before doing anything.
1486 // Add a new timer using the existing account details.
1488 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1490 ActTmrPtr->SetupData(AccDirFull, AccName);
1491 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1492 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1493 ActTmrPtr->SetOwner(this);
1494 ActTmrPtr->Notify();
1496 // Add the timer to the list of timers.
1498 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1500 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1504 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1508 // Go through the account directory and find contact files with
1509 // 'KIND:group' set and add them to the list of groups for the account.
1511 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1513 wxDir vcardaccdir(AccDirFinal);
1515 wxString vCardFilename;
1516 wxString vCardDataString;
1517 wxString vCardFilenameFull;
1518 //bool ProcFiles = FALSE;
1520 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1523 if (vCardFilename.Right(4) == wxT(".vcf") ||
1524 vCardFilename.Right(4) == wxT(".VCF") ||
1525 vCardFilename.Right(5) == wxT(".vcard") ||
1526 vCardFilename.Right(5) == wxT(".VCARD")){
1530 vCardFilenameFull.Append(AccDirFinal);
1531 vCardFilenameFull.Append(wxT("/"));
1532 vCardFilenameFull.Append(vCardFilename);
1534 Person.LoadFile(vCardFilenameFull);
1536 if (Person.MeetBaseSpecification()){
1538 vCardDataString = Person.Get(wxT("KIND"));
1540 if (vCardDataString == wxT("group")){
1542 // The vCard kind is a group. Add to the account's group list.
1544 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1545 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1546 AccountGroupList.insert(std::make_pair(intGroupID, i));
1547 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1548 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1560 vCardFilename.Clear();
1561 vCardFilenameFull.Clear();
1562 vCardDataString.Clear();
1563 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1567 // Clearup for next account.
1571 AccDirFullSfx.clear();
1572 AccDirFinal.clear();
1577 // Load the account settings as they are needed for connecting
1580 prefaccounts = preferences.accounts;
1584 void frmMain::ConflictResolution(wxCommandEvent& event){
1586 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1587 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1588 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1589 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1590 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1591 //wxString Moo = ClientDataPtr->WriteString();
1592 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1593 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1594 //frameCR->LoadData(vCardConfObj->vCardLocalData, vCardConfObj->vCardServerData, &MemoryFileList);
1595 frameCR->ShowModal();
1597 int FinalConflictResult = frameCR->GetResult();
1599 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1600 event2.SetClientData(vCardConfObj->QRNotifData);
1601 event2.SetInt(FinalConflictResult);
1606 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1607 wxPostEvent(frameActMgr, event2);
1611 void frmMain::UpdateContactList(wxCommandEvent& event){
1613 UCNotif *ucd = (UCNotif*)event.GetClientData();
1615 // Check if the active account is being displayed in the
1616 // main window. If not, skip and delete the data.
1618 long longSelected = -1;
1619 int intSelectedData = 0;
1621 if (ActiveAccount == ucd->ContactAccount){
1623 // Look at the list of contacts and if it matches the
1624 // filename then update the name.
1628 longSelected = lstContacts->GetNextItem(longSelected,
1630 wxLIST_STATE_DONTCARE);
1632 if (longSelected == -1){
1638 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1640 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1642 // Work out which sorting mode we are in.
1646 // First Name, Last Name.
1648 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1650 } else if (SortMode == 2){
1652 // Last Name, First Name.
1654 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1656 } else if (SortMode == 3){
1660 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1662 } else if (SortMode == 4){
1666 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1673 // If the filename is the one loaded into the
1674 // browser control, then update this too.
1676 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1678 wxListEvent nullevent;
1679 ShowContactInfo(nullevent);
1687 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1688 WindowIter != WindowListPointers.end(); WindowIter++){
1690 if (WindowListType[WindowIter->first] != 0){
1696 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1698 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1700 vCard UpdatedPerson;
1701 UpdatedPerson.LoadFile(ucd->ContactFilename);
1702 frmContactPtr->SetupContactData(&UpdatedPerson);
1708 // Send message to search window controller subroutine and
1709 // pass that notification onto the search windows.
1711 // Setup the new pointer to use the existing UCNotif without
1714 UCNotif *ucd2 = ucd;
1716 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1717 sup.SetClientData(ucd2);
1718 wxPostEvent(this, sup);
1720 // Clear up the unused pointer.
1726 void frmMain::UpdateAccountList(wxCommandEvent& event){
1730 void frmMain::SetupPointers(void *ActMgrPtrInc){
1732 ActMgrPtr = ActMgrPtrInc;
1736 void frmMain::SetupForm(){
1738 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1739 frameActMgr->SetupPointers(&ETagProcTimer, this);
1741 // Setup the contact information icons for later.
1743 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1747 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1748 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1749 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1751 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1752 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1753 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1755 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1756 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1757 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1759 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1760 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1761 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1763 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1764 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1765 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1767 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1768 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1769 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1775 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1777 // Go through each of the search windows and
1778 // send the required notification to update the
1779 // contact information.
1781 // Get the event notification data.
1783 UCNotif *ucd = (UCNotif*)event.GetClientData();
1785 // Process each search window giving the new details.
1787 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1788 switer != SearchWindowList.end(); switer++){
1790 // Duplicate the event notification data.
1792 UCNotif *ucd2 = new UCNotif;
1794 ucd2->ContactAccount = ucd->ContactAccount;
1795 ucd2->ContactFilename = ucd->ContactFilename;
1796 ucd2->ContactName = ucd->ContactName;
1797 ucd2->ContactNickname = ucd->ContactNickname;
1798 ucd2->ContactNameArray = ucd->ContactNameArray;
1800 // Pass the data to the search window for processing.
1802 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1803 wxCommandEvent schupdate(SE_UPDATERESULT);
1804 schupdate.SetClientData(ucd2);
1805 wxPostEvent(frameSCH, schupdate);
1807 // Clear up the pointer prior to variable deletion.
1818 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1822 frmSearch *frameSCH = new frmSearch ( this );
1823 frameSCH->SetUID(WindowMenuItemID);
1824 frameSCH->Show(true);
1826 WindowData *WData = new WindowData;
1828 WData->DataType = 2;
1829 WData->WindowPointer = (void*)frameSCH;
1830 WData->WindowID = WindowMenuItemID;
1832 wxCommandEvent addevent(WINDOW_ADD);
1833 addevent.SetClientData(WData);
1834 wxPostEvent(this, addevent);
1836 // Add pointer to the list of open search windows.
1838 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1844 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1846 //frmSearch *frameSCH = static_cast<frmSearch*>(ActMgrPtr);
1847 void *frameSCH = (void*)event.GetClientData();
1849 SearchWindowList.erase(frameSCH);
1855 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1857 void *frameSCH = (void*)event.GetClientData();
1859 SearchWindowList.erase(frameSCH);
1865 void frmMain::UpdateWindowList(wxCommandEvent& event){
1867 // Update the Window List.
1869 // Delete the existing items in the window menu.
1871 // Get the list of contacts.
1873 // Insert a separator.
1875 // Get the list of search windows.
1879 void frmMain::RevealContact(wxCommandEvent& event){
1881 UCNotif *uc = (UCNotif*)event.GetClientData();
1883 // Switch the account to the one passed.
1885 wxTreeItemIdValue cookie;
1886 wxTreeItemId next = treAccounts->GetRootItem();
1887 wxTreeItemId nextChild;
1889 for (int i = 0; i < prefaccounts.GetCount(); i++){
1892 nextChild = treAccounts->GetFirstChild(next, cookie);
1894 nextChild = treAccounts->GetNextSibling(nextChild);
1897 //AccountName = treAccounts->GetItemText(nextChild);
1899 if (uc->ContactAccount == AccountAccDirList[i]){
1902 treAccounts->SelectItem(nextChild, TRUE);
1903 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1909 // Switch the contact to the one passed.
1911 long longSelected = -1;
1912 int intSelectedData = 0;
1916 longSelected = lstContacts->GetNextItem(longSelected,
1918 wxLIST_STATE_DONTCARE);
1920 if (longSelected == -1){
1926 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1928 // Compare the filename with the one received.
1929 // If they match then select it.
1931 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1935 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1936 lstContacts->EnsureVisible(longSelected);
1940 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1948 void frmMain::DeleteContact(wxCommandEvent& event){
1950 // Check if a contact is selected.
1952 long intSelected = -1;
1953 long intContactSeekNum = -1;
1954 wxString wxSContactName;
1956 intSelected = lstContacts->GetNextItem(intSelected,
1958 wxLIST_STATE_SELECTED);
1960 if (intSelected == -1){
1964 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1966 // Get the item data of the contact.
1968 intContactSeekNum = lstContacts->GetItemData(intSelected);
1970 // Get the name of the contact.
1972 wxSContactName = lstContacts->GetItemText(intSelected);
1974 // Display a message confirming if the contact should
1977 int QuestionResponse;
1979 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1981 if (QuestionResponse == wxNO){
1983 // Exit the subroutine
1989 // Delete the contact.
1991 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1993 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1998 // Remove the contact from the list.
2000 lstContacts->DeleteItem(intSelected);
2002 // Update the search windows, removing the deleted
2005 UCNotif *ucd = new UCNotif;
2007 ucd->ContactAccount = ActiveAccount;
2008 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
2010 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
2011 switer != SearchWindowList.end(); switer++){
2013 // Duplicate the event notification data.
2015 UCNotif *ucd2 = new UCNotif;
2017 ucd2->ContactAccount = ucd->ContactAccount;
2018 ucd2->ContactFilename = ucd->ContactFilename;
2020 // Pass the data to the search window for processing.
2022 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
2023 wxCommandEvent schdelete(SE_DELETERESULT);
2024 schdelete.SetClientData(ucd2);
2025 wxPostEvent(frameSCH, schdelete);
2027 // Clear up the pointer prior to variable deletion.
2034 // Clear the wxHTMLWindow.
2036 wxString EmptyPage = wxT("");
2038 htmContactData->SetPage(EmptyPage);
2040 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
2042 wxString wxSplitFilename;
2043 wxString wxSDataURL;
2045 while(wSTFilename.HasMoreTokens()){
2047 wxSplitFilename = wSTFilename.GetNextToken();
2051 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2053 // Update the ETagDB and mark it as deleted.
2055 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2057 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2059 // Get the Data URL.
2061 wxTreeItemIdValue cookie;
2062 wxTreeItemId next = treAccounts->GetRootItem();
2064 wxTreeItemId selectedChild = treAccounts->GetSelection();
2065 wxTreeItemId nextChild;
2067 for (int i = 0; i < prefaccounts.GetCount(); i++){
2070 nextChild = treAccounts->GetFirstChild(next, cookie);
2073 nextChild = treAccounts->GetNextSibling(nextChild);
2076 if (nextChild == selectedChild){
2077 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2083 // Add task to the activity monitor to delete the contact.
2085 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2089 // Clear the variable. Don't delete as it will mess things up.
2091 ContactsFileIndex[intContactSeekNum] = wxT("");
2098 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2100 QRNotif *qrn = (QRNotif *)event.GetClientData();
2102 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);
2104 if (QResponse == wxNO){
2110 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2111 event2.SetInt(*qrn->QResponse);
2112 event2.SetClientData(qrn->PausePtr);
2114 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2116 wxPostEvent(frameActMgr, event2);
2120 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2122 // Remove the contact from the window after syncronising.
2124 // Check which account is currently active in the window.
2125 // If it is different from the one passed to this subroutine then
2126 // exit from the subroutine.
2128 if (Account != ActiveAccount){
2132 long longSelected = -1;
2133 int intSelectedData = 0;
2137 longSelected = lstContacts->GetNextItem(longSelected,
2139 wxLIST_STATE_DONTCARE);
2141 if (longSelected == -1){
2147 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2149 // Compare the filename with the one received.
2150 // If they match then select it.
2152 if (ContactsFileIndex[intSelectedData] == Filename){
2154 // Remove the contact from the window.
2156 lstContacts->DeleteItem(intSelectedData);
2158 // Check if contact is the selected contact in the HTML window and
2159 // if it is then clear the window.
2161 if (ActiveFilename == Filename){
2163 wxString EmptyPage = wxT("");
2164 htmContactData->SetPage(EmptyPage);
2178 void frmMain::SortFNLN( wxCommandEvent& event ) {
2180 wxTreeEvent NullEvent;
2182 LoadContactList(NullEvent);
2186 void frmMain::SortLNFN( wxCommandEvent& event ) {
2188 wxTreeEvent NullEvent;
2190 LoadContactList(NullEvent);
2194 void frmMain::SortNickname( wxCommandEvent& event ) {
2196 wxTreeEvent NullEvent;
2198 LoadContactList(NullEvent);
2202 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2204 wxTreeEvent NullEvent;
2206 LoadContactList(NullEvent);
2210 void frmMain::SortAscending( wxCommandEvent& event ) {
2212 wxTreeEvent NullEvent;
2213 AscendingMode = TRUE;
2214 LoadContactList(NullEvent);
2218 void frmMain::SortDescending( wxCommandEvent& event ) {
2220 wxTreeEvent NullEvent;
2221 AscendingMode = FALSE;
2222 LoadContactList(NullEvent);
2226 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2228 if (stbBottom->IsShown() == TRUE){
2242 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2244 // Display the activity icon.
2246 imgActivityStatus->SetBitmap(*imgActIcon1);
2247 ActivityIconStatus = 0;
2251 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2253 switch (ActivityIconStatus){
2256 imgActivityStatus->SetBitmap(*imgActIcon1);
2257 ActivityIconStatus = 1;
2260 imgActivityStatus->SetBitmap(*imgActIcon2);
2261 ActivityIconStatus = 2;
2264 imgActivityStatus->SetBitmap(*imgActIcon3);
2265 ActivityIconStatus = 3;
2268 imgActivityStatus->SetBitmap(*imgActIcon4);
2269 ActivityIconStatus = 0;
2272 ActivityIconStatus = 0;
2278 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2280 // Display the sleep icon.
2282 imgActivityStatus->SetBitmap(*imgActIconSleep);
2286 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2288 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2296 wxRect rectActivity;
2297 stbBottom->GetFieldRect(1, rectOnline);
2298 stbBottom->GetFieldRect(2, rectSSL);
2299 stbBottom->GetFieldRect(3, rectActivity);
2301 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2302 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2303 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2307 XABViewMode frmMain::GetViewMode(){
2311 xvm.SortMode = SortMode;
2312 xvm.AscendingMode = AscendingMode;
2318 void frmMain::WindowAdd( wxCommandEvent &event ){
2320 WindowData *WData = (WindowData*)event.GetClientData();
2324 if (WData->DataType == 0){
2328 int intID = mnuContactWindows->GetId();
2330 mnuWindow->FindChildItem(intID, &pos);
2331 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2332 mnuNewItem->SetId(WData->WindowID);
2333 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2334 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2335 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2336 mnuWindow->Insert((pos + 1), mnuNewItem);
2337 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2339 } else if (WData->DataType == 1){
2341 // Contact Editor Window
2343 int intID = mnuContactEditorWindows->GetId();
2345 mnuWindow->FindChildItem(intID, &pos);
2346 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2347 mnuNewItem->SetId(WData->WindowID);
2348 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2349 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2350 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2351 mnuWindow->Insert((pos + 1), mnuNewItem);
2352 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2354 } else if (WData->DataType == 2){
2358 int intID = mnuSearchWindows->GetId();
2360 mnuWindow->FindChildItem(intID, &pos);
2361 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2362 mnuNewItem->SetId(WData->WindowID);
2363 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2364 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2365 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2366 mnuWindow->Insert((pos + 1), mnuNewItem);
2367 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2376 void frmMain::WindowEdit( wxCommandEvent &event ){
2378 WindowData *WData = (WindowData*)event.GetClientData();
2380 if (WData->DataType == 0){
2382 // Get the window title and use that.
2384 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2386 wxString WindowTitle = frmContactPtr->GetTitle();
2388 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2390 MenuIter->second->SetItemLabel(WindowTitle);
2392 //mnuWindow->FindChildItem(intID, &pos);
2393 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2394 //mnuNewItem->SetId(WData->WindowID);
2395 //ContactWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2396 //ContactWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2397 //mnuWindow->Insert((pos + 1), mnuNewItem);
2398 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2400 } else if (WData->DataType == 1){
2402 // Get the window title and use that.
2404 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2406 wxString WindowTitle = frmCEPtr->GetTitle();
2408 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2410 if (WindowTitle.IsEmpty()){
2412 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2416 MenuIter->second->SetItemLabel(WindowTitle);
2420 //mnuWindow->FindChildItem(intID, &pos);
2421 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2422 //mnuNewItem->SetId(WData->WindowID);
2423 //ContactEditorWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2424 //ContactEditorWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2425 //mnuWindow->Insert((pos + 1), mnuNewItem);
2426 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2435 void frmMain::WindowDelete( wxCommandEvent &event ){
2437 WindowData *WData = (WindowData*)event.GetClientData();
2439 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2441 mnuWindow->Remove(MenuIter->second);
2443 delete MenuIter->second;
2444 MenuIter->second = NULL;
2446 WindowListPointersMenu.erase(WData->WindowID);
2447 WindowListPointers.erase(WData->WindowID);
2448 WindowListType.erase(WData->WindowID);
2455 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2457 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2459 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2461 frmContactPtr->Show();
2462 frmContactPtr->Raise();
2466 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2468 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2470 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2477 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2479 // Look through the Search Window List Pointers, grab the
2480 // window point and show the window.
2482 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2484 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2486 frmSearchPtr->Show();
2487 frmSearchPtr->Raise();
2491 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2493 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2494 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2495 wxPostEvent(frameActMgr, toggconn);
2499 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2501 // Check the account type before continuing.
2503 wxString SeekAccount;
2504 wxString AccTypeLower;
2507 std::map<int, SSLCertCollection>::iterator SSLColIter;
2509 for (int i = 0; i < prefaccounts.GetCount(); i++){
2511 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2512 AccType.Append(prefaccounts.GetAccountType(i));
2513 AccountSSL = prefaccounts.GetAccountSSL(i);
2514 AccTypeLower = AccType.MakeLower();
2515 SeekAccount.Append(wxT("."));
2516 SeekAccount.Append(AccTypeLower);
2518 if (SeekAccount == ActiveAccount){
2520 if (AccTypeLower == wxT("local")){
2526 if (AccountSSL == false){
2532 SSLColIter = AccountSSLData.find(i);
2534 SSLCertCollection SSLCertInfo = SSLColIter->second;
2536 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2537 frameSSLCert->StartCertFrom(0);
2538 frameSSLCert->SetupCerts(SSLCertInfo);
2539 frameSSLCert->ShowModal();
2541 delete frameSSLCert;
2542 frameSSLCert = NULL;
2546 SeekAccount.Clear();
2547 AccTypeLower.Clear();
2554 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2556 // Check the account type before continuing.
2560 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2562 // Check the account type before continuing.
2566 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2568 if (event.GetInt() == 0){
2570 imgConnStatus->SetBitmap(*imgOnline);
2574 imgConnStatus->SetBitmap(*imgOffline);
2580 void frmMain::SetupSSLStatus( int AccountID ){
2582 // Check if account ID given is
2583 // the active account and if not, do nothing.
2586 wxString AccTypeLower;
2588 AccType = prefaccounts.GetAccountType(AccountID);
2589 AccTypeLower = AccType.MakeLower();
2591 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2594 if (AccountIDName != ActiveAccount){
2600 // Check if the account has SSL enabled.
2602 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2604 if (SSLInUse == FALSE){
2606 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2607 imgSSLStatus->SetBitmap(*imgNoSSL);
2611 // Get the SSL Collection Data.
2613 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2615 if (SSLResultIter->second == 1){
2617 imgSSLStatus->SetBitmap(*imgSSLWarning);
2618 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2619 prefaccounts.GetAccountName(AccountID) +
2620 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2623 } else if (SSLResultIter->second == 0){
2625 imgSSLStatus->SetBitmap(*imgSSL);
2626 SSLToolTip->SetTip(wxT("Account '") +
2627 prefaccounts.GetAccountName(AccountID) +
2628 wxT("' secured using SSL\n\nDouble click for more information."));
2636 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2638 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2639 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2640 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2641 wxString AccountName = SSLICNObj->AccountName;
2642 frameISC->LoadData(SSLCCData, AccountName);
2643 frameISC->ShowModal();
2645 int FinalConflictResult = frameISC->GetResult();
2647 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2648 event2.SetClientData(SSLICNObj->QRNotifData);
2649 event2.SetInt(FinalConflictResult);
2654 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2655 wxPostEvent(frameActMgr, event2);
2658 void frmMain::PauseAllTimers(){
2660 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2661 ASTiter != AccountSyncTimers.end(); ASTiter++){
2663 ASTiter->second->Stop();
2669 void frmMain::ResumeAllTimers(){
2671 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2672 ASTiter != AccountSyncTimers.end(); ASTiter++){
2674 ASTiter->second->Start();
2680 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2682 // Delete existing data.
2684 AccountSSLData.erase(AccountID);
2685 AccountSSLResult.erase(AccountID);
2689 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2690 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2694 void frmMain::CheckUpdates( wxCommandEvent& event ){
2696 frmUpdate *frameUpdate = new frmUpdate ( this );
2697 frameUpdate->FetchData();
2698 frameUpdate->ShowModal();
2702 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2704 // Run the import contacts system.
2710 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2712 // Check if an account and at least one contact is selected
2713 // before continuing.
2715 wxArrayString ArrData;
2717 if (ActiveAccount.IsEmpty()){
2723 int ContactSelected = 0;
2724 int ContactsCollected = 0;
2725 long longSelected = -1;
2729 longSelected = lstContacts->GetNextItem(longSelected,
2731 wxLIST_STATE_SELECTED);
2733 if (longSelected == -1){
2739 int FileID = (int)lstContacts->GetItemData(longSelected);
2741 ArrData.Insert(ContactsFileIndex[FileID],
2742 ContactsCollected, 1);
2748 if (ContactSelected == 0){
2754 // Run the export contacts system.
2756 ExportRun(this, &ArrData);
2760 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2761 wxArrayString *ContactsFileIndexPtr){
2763 lstContactsPtr = lstContacts;
2764 ContactsFileIndexPtr = &ContactsFileIndex;
2768 void frmMain::GetSelectedList( wxCommandEvent& event ){
2770 // Get the array of contact filenames.
2772 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2774 // Process them into an array of files.
2776 long longSelected = -1;
2777 int ContactsCollected = 0;
2778 wxString ContactFilename;
2782 longSelected = lstContacts->GetNextItem(longSelected,
2784 wxLIST_STATE_SELECTED);
2786 if (longSelected == -1){
2792 // Get the file information and add to the list.
2794 int FileID = (int)lstContacts->GetItemData(longSelected);
2796 ArrData->Insert(ContactsFileIndex[FileID],
2797 ContactsCollected, 1);
2799 ContactsCollected++;
2800 ContactFilename.Clear();
2808 void frmMain::SyncAccount( wxCommandEvent& event ){
2810 wxString AccNameInc = event.GetString();
2812 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2813 frameActMgr->AddTask(3, wxT(""), AccNameInc,
2814 wxT(""), wxT(""), wxT(""), wxT(""));
2818 void frmMain::ShowHelp( wxCommandEvent& event ){
2820 // Based on the operating system, work out where
2821 // the documentation should be.
2825 #if defined(__HAIKU__)
2827 #elif defined(__WIN32__)
2833 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2835 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2838 #if XSDAB_RELEASE == 0
2840 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2842 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2851 #if XSDAB_RELEASE == 0
2853 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2857 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!"));
2863 void frmMain::ShowImportResults( wxCommandEvent &event ){
2865 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2867 frmImportResults *frmIR = new frmImportResults(this);
2868 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
2879 void frmMain::ReloadContactList( wxCommandEvent &event ){
2881 // Check if the account name given is the current
2882 // account selected.
2884 if (ActiveAccount == event.GetString()){
2886 wxTreeEvent NullEvent;
2887 LoadContactList(NullEvent);
2893 void frmMain::ShowContactMenu( wxMouseEvent& event ){
2895 bool EnableRefresh = FALSE;
2897 if (!ActiveAccount.IsEmpty()){
2899 EnableRefresh = TRUE;
2903 ContactMenu->SetupPointers(this, lstContacts, EnableRefresh);
2905 this->PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);