7 #include <wx/tokenzr.h>
9 #include <wx/mstream.h>
10 #include <wx/fs_mem.h>
12 #include <wx/filesys.h>
14 #include <wx/stdpaths.h>
15 #include <wx/fileconf.h>
16 //#include <boost/filesystem/fstream.hpp>
22 #include "frmPreferences.h"
23 #include "frmNewAccount.h"
24 #include "frmActivityMgr.h"
25 #include "frmContact.h"
26 #include "frmConflictResolution.h"
27 #include "frmInvalidSSLCertificate.h"
28 #include "frmSearch.h"
29 #include "frmSSLCertificate.h"
30 #include "frmUpdate.h"
33 #include "common/preferences.h"
34 #include "common/getcontactinfo.h"
35 #include "common/events.h"
36 #include "common/dirs.h"
37 #include "vcard/vcard.h"
38 #include "carddav/carddav.h"
39 #include "contacteditor/frmContactEditor.h"
40 #include "import/import.h"
41 #include "export/export.h"
42 #include "widgets/XABAccountView.h"
46 //extern const wxEventType MyHaremEvent = wxNewEventType();
48 //#define CE_UPDATECONTACTLIST 7700
49 //#define CE_UPDATEACCOUNTLIST 7701
51 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
52 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
53 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
54 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
55 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
56 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
57 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
58 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
59 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
60 DEFINE_EVENT_TYPE(ACTMGR_START);
61 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
62 DEFINE_EVENT_TYPE(ACTMGR_STOP);
63 DEFINE_EVENT_TYPE(WINDOW_ADD);
64 DEFINE_EVENT_TYPE(WINDOW_EDIT);
65 //DEFINE_EVENT_TYPE(WINDOW_DELETE);
66 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
67 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
68 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
69 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
70 DEFINE_EVENT_TYPE(SYNCACCOUNT);
72 BEGIN_EVENT_TABLE(frmMain, wxFrame)
73 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
74 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
75 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
76 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
77 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
78 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
79 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
80 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
81 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
82 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
83 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
84 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
85 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
86 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
87 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
88 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
89 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
90 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
91 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
94 frmMain::frmMain( wxWindow* parent )
99 // Setup the account icons.
101 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
102 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
103 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
104 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
106 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
107 wxBitmap AccInet(icons_accinet_png, -1);
109 wxIAccInet.CopyFromBitmap(AccInet);
111 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
112 wxBitmap AccNIcon(icons_acclocal_png, -1);
114 wxIAccNIcon.CopyFromBitmap(AccNIcon);
116 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
117 wxBitmap AccGrp(icons_accgroup_png, -1);
119 wxIAccGrp.CopyFromBitmap(AccGrp);
121 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
122 wxBitmap AccNone(icons_accnone_png, -1);
124 wxIAccNone.CopyFromBitmap(AccNone);
126 AccountID = AccImgList->Add(wxIAccNIcon);
127 AccountNetID = AccImgList->Add(wxIAccInet);
128 AccountGrpID = AccImgList->Add(wxIAccGrp);
129 AccountNoneID = AccImgList->Add(wxIAccNone);
131 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
133 // Setup the status bar icons.
137 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
138 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
139 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
141 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
142 imgSSL = new wxBitmap(icons_ssl_png, -1);
144 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
145 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
147 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
148 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
152 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
153 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
154 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
155 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
156 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
158 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
159 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
161 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
162 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
164 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
166 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
167 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
169 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
171 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
172 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
174 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
176 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
177 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
179 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
181 // Online/Offline icons.
183 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
184 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
186 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
187 imgOnline = new wxBitmap(icons_online_png, -1);
189 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
190 imgOffline = new wxBitmap(icons_offline_png, -1);
192 // Setup the account view.
194 AccCtrl->SetPopupControl(treAccounts);
195 AccCtrl->SetPopupMaxHeight(175);
196 AccCtrl->SetPopupMinWidth(250);
197 treAccounts->AssignImageList(AccImgList);
200 /*wxStaticBitmap* BeepBoop = new wxStaticBitmap(AccCtrl, wxID_ANY, wxNullBitmap, wxPoint(AccTextCtrlSize.GetX() + 3, AccTextCtrlSize.GetY() + 2), wxDefaultSize, 0);
202 icons_accgroup_png.SetMask(new wxMask(icons_accgroup_png, wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND)));
204 BeepBoop->SetBackgroundColour(AccCtrl->GetBackgroundColour());
205 BeepBoop->SetBitmap(icons_accgroup_png);*/
207 //szrContactList->Insert(0, XABV2, 1, wxEXPAND | wxALL, 0);
209 /*AccControl->UseAltPopupWindow();
210 AccControl->SetPopupControl(treAccounts);
211 AccControl->SetPopupMaxHeight(175);
213 treAccounts->AssignImageList(AccImgList);
214 szrContactList->Insert(0, AccControl, 1, wxEXPAND|wxALL, 0);
215 szrAccList->Add(AccIcon, 0, wxLEFT|wxTOP|wxEXPAND, 3);
219 //szrContactList->Layout();
220 //szrContactList->RecalcSizes();
222 wxListItem ColumnData;
224 ColumnData.SetText(wxT("Name0"));
225 ColumnData.SetWidth(320);
226 lstContacts->InsertColumn(0, ColumnData);
228 //Connect(wxID_ANY, ContactConflictCmdEnv,
229 // ContactConflictEventHandler(frmMain::ConflictResolution), NULL, this);
231 //Connect(wxID_ANY, MyFooCommandEvent,
232 // MyFooEventHandler(frmMain::DoSomething), NULL, this);
234 //Bind(ContactConflictCmdEnv, ContactConflictEventHandler(frmMain::ConflictResolution), this, wxID_ANY);
236 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
237 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
239 #if defined(__HAIKU__)
241 #elif defined(__WIN32__)
243 int stbBottomData [4] = { -1, 8, 8, 8 };
247 int stbBottomData [4] = { -1, 20, 20, 20 };
251 stbBottom->SetFieldsCount(4, stbBottomData);
252 stbBottom->SetMinHeight(16);
257 stbBottom->GetFieldRect(1, rectOnline);
258 stbBottom->GetFieldRect(2, rectSSL);
259 stbBottom->GetFieldRect(3, rectActivity);
261 SSLToolTip = new wxToolTip(wxT(""));
263 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
264 imgConnStatus->SetBitmap(*imgOnline);
265 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
267 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
268 imgSSLStatus->SetBitmap(*imgNoSSL);
269 imgSSLStatus->SetToolTip(SSLToolTip);
270 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
272 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
273 imgActivityStatus->SetBitmap(*imgActIconSleep);
274 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
276 // Setup the window menu.
278 // By default should be:
283 // Contact editor windows:
289 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
290 mnuWindow->Append( mnuContactWindows );
292 mnuWindow->AppendSeparator();
294 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
295 mnuWindow->Append( mnuContactEditorWindows );
297 mnuWindow->AppendSeparator();
299 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
300 mnuWindow->Append( mnuSearchWindows );
302 #if defined(__WIN32__)
307 mnuContactWindows->SetFont(fontstyle);
308 mnuContactEditorWindows->SetFont(fontstyle);
309 mnuSearchWindows->SetFont(fontstyle);
313 mnuContactWindows->Enable(FALSE);
314 mnuContactEditorWindows->Enable(FALSE);
315 mnuSearchWindows->Enable(FALSE);
319 // Hide unimplemented functions.
325 void frmMain::QuitApp( wxCommandEvent& event )
327 //-------------------------------------------------------------------
328 // frmMain::QuitApp: Quits the application by simply closing this
329 // window which causes the exit as frmMain is the main window.
331 // wxCommandEvent Accepts a referenced event command.
332 //-------------------------------------------------------------------
334 //Go through the windows and close each one (be it search
335 //or contact editor). Abort if user wants to cancel.
337 // Close the contact editor windows.
339 // Close the contact windows.
341 // Close the search windows.
343 // Write out the ETag databases.
345 // Save Preferences: Save the window position if that option is enabled.
347 wxString SetFilename = GetUserPrefDir();
349 #if defined(__HAIKU__)
353 #elif defined(__WIN32__)
355 SetFilename.Append(wxT("settings"));
361 SetFilename.Append(wxT("settings"));
365 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
367 bool SaveWindowPos = FALSE;
368 wxString SaveWindowInc;
369 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
371 if (SaveWindowInc == wxT("true")){
373 SaveWindowPos = TRUE;
377 if (SaveWindowPos == TRUE){
379 wxRect frmMainPos = this->GetRect();
381 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
382 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
383 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
384 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
392 //Everything closed... exit.
398 void frmMain::QuitApp()
400 //-------------------------------------------------------------------
401 // frmMain::QuitApp: Quits the application by simply closing this
402 // window which causes the exit as frmMain is the main window.
404 // wxCommandEvent Accepts a referenced event command.
405 //-------------------------------------------------------------------
411 void frmMain::ShowActivityWindow( wxCommandEvent& event )
414 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
415 frameActMgr->OpenWindow();
420 void frmMain::ShowAboutWindow( wxCommandEvent& event )
422 //-------------------------------------------------------------------
423 // frmMain::ShowAboutWindow: Shows the About window as a modal
424 // dialog and then cleans up when finished.
426 // wxCommandEvent Accepts a referenced event command.
427 //-------------------------------------------------------------------
429 frmAbout *frameAbout = new frmAbout ( this );
430 frameAbout->SetupAboutWindow();
431 frameAbout->ShowModal();
437 void frmMain::OpenPreferences( wxCommandEvent& event)
439 //-------------------------------------------------------------------
440 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
441 // dialog and then cleans up when finished.
443 // wxCommandEvent Accepts a referenced event command.
444 //-------------------------------------------------------------------
446 ReloadAccounts = FALSE;
448 frmPreferences *framePreferences = new frmPreferences ( this );
449 framePreferences->SetupPointers(&ReloadAccounts);
450 framePreferences->ShowModal();
451 delete framePreferences;
452 framePreferences = NULL;
454 if (ReloadAccounts == TRUE){
456 // Reload the accounts as a change has been made within
459 this->LoadPreferences();
465 void frmMain::OpenNewABDialog( wxCommandEvent& event)
467 //-------------------------------------------------------------------
468 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
469 // dialog and then cleans up when finished.
471 // wxCommandEvent Accepts a referenced event command.
472 //-------------------------------------------------------------------
474 ReloadAccounts = FALSE;
476 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
477 frameNewAccount->SetupPointers(&ReloadAccounts);
478 frameNewAccount->ShowModal();
479 delete frameNewAccount;
480 frameNewAccount = NULL;
482 if (ReloadAccounts == TRUE){
484 // Reload the accounts as a change has been made within
487 this->LoadPreferences();
493 void frmMain::LoadContactList( wxTreeEvent& event )
496 // Clear all existing variables.
498 lstContacts->DeleteAllItems();
500 treAccounts->SetAccount();
502 wxTreeItemIdValue cookie;
503 wxTreeItemId next = treAccounts->GetRootItem();
504 wxString AccountName;
505 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
506 wxString AccountDirCmb;
507 long selectedaccount = 0;
509 wxTreeItemId selectedChild = treAccounts->GetSelection();
510 wxTreeItemId nextChild;
512 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
513 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
515 int SCImg = treAccounts->GetItemImage(selectedChild);
516 int AccountIndex = 0;
518 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
520 for (int i = 0; i < prefaccounts.GetCount(); i++){
522 if (ActiveItemIcon == 2){
524 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
525 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
526 int ActiveAccountG = AGLiter->second;
528 if (i == ActiveAccountG){
530 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
531 AccountType.Append(prefaccounts.GetAccountType(i));
536 if (AccountType == wxT("CardDAV")){
537 AccountTypeFinal.Append(wxT("carddav"));
539 else if (AccountType == wxT("Local")){
540 imgSSLStatus->SetBitmap(*imgOffline);
541 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
542 AccountTypeFinal.Append(wxT("local"));
553 nextChild = treAccounts->GetFirstChild(next, cookie);
556 nextChild = treAccounts->GetNextSibling(nextChild);
559 AccountName = treAccounts->GetItemText(nextChild);
561 if (nextChild == selectedChild){
562 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
563 AccountType.Append(prefaccounts.GetAccountType(i));
568 if (AccountType == wxT("CardDAV")){
569 AccountTypeFinal.Append(wxT("carddav"));
571 else if (AccountType == wxT("Local")){
572 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
573 AccountTypeFinal.Append(wxT("local"));
582 if (selectedaccount >= prefaccounts.GetCount()){
584 // The account selected isn't there so return.
592 // Open the directory and get the list of .vcf files
593 // in that directory.
595 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
596 ActiveAccountType = AccountType;
598 SetupSSLStatus(AccountIndex);
600 AccountDirFinal.Clear();
601 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
603 ContactsFileIndex.Clear();
605 //wxString vcardfilenamewxs;
606 wxString vCardFilename;
607 wxString vCardFilenameFull;
608 wxString vCardDataString;
609 wxStringTokenizer vcardfileline;
611 wxString setname, setvalue;
612 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
613 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
614 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
615 long ContactIndex = 1;
616 long ContactSeekPoint = 0;
618 wxDir vcardaccdir(AccountDirFinal);
620 // Get the wxTreeItemId and image icon and compare it to the list.
622 if (ActiveItemIcon == AccountGrpID){
624 // It's a group so load the file containing the group and
625 // get the members of the group.
630 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
631 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
632 //std::multimap<wxTreeItemId, int>::iterator AGFiter = AccountGroupTreeId.find(ActiveItemId);
634 Group.LoadFile(AGFiter->second);
636 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
638 for (int i = 0; i < vCardMember.PropCount; i++){
640 vCardMember.PropValues[i].Trim();
641 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
643 wxString NewPropValue;
644 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
645 vCardMember.PropValues[i] = NewPropValue;
652 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
655 if (vCardFilename.Right(4) == wxT(".vcf") ||
656 vCardFilename.Right(4) == wxT(".VCF") ||
657 vCardFilename.Right(5) == wxT(".vcard") ||
658 vCardFilename.Right(5) == wxT(".VCARD")){
661 bool FoundMember = FALSE;
663 vCardFilenameFull.Append(AccountDirFinal);
664 vCardFilenameFull.Append(wxT("/"));
665 vCardFilenameFull.Append(vCardFilename);
667 Person.LoadFile(vCardFilenameFull);
669 UIDCode = Person.Get(wxT("UID"));
671 for (int i = 0; i < vCardMember.PropCount; i++){
673 if (vCardMember.PropValues[i] == UIDCode){
681 if (FoundMember == FALSE){
683 vCardFilename.Clear();
684 vCardFilenameFull.Clear();
685 vCardDataString.Clear();
686 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
691 if (Person.MeetBaseSpecification()){
695 // Split the name into sections.
697 vCardDataString = Person.Get(wxT("N"));
699 vCardName NameData = Person.GetName();
701 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
703 } else if (SortMode == 2){
705 // Split the name into sections.
707 vCardName NameData = Person.GetName();
709 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
711 } else if (SortMode == 3){
713 // Check and make sure that the top most nickname is used.
715 vCardDataString = Person.Get(wxT("NICKNAME"));
717 if (vCardDataString.IsEmpty()){
719 vCardDataString = wxT("(no nickname)");
723 } else if (SortMode == 4){
725 vCardDataString = Person.Get(wxT("FN"));
729 if (AscendingMode == TRUE){
730 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
732 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
741 vCardFilename.Clear();
742 vCardFilenameFull.Clear();
743 vCardDataString.Clear();
744 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
749 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
752 if (vCardFilename.Right(4) == wxT(".vcf") ||
753 vCardFilename.Right(4) == wxT(".VCF") ||
754 vCardFilename.Right(5) == wxT(".vcard") ||
755 vCardFilename.Right(5) == wxT(".VCARD")){
759 vCardFilenameFull.Append(AccountDirFinal);
760 vCardFilenameFull.Append(wxT("/"));
761 vCardFilenameFull.Append(vCardFilename);
763 Person.LoadFile(vCardFilenameFull);
765 if (Person.MeetBaseSpecification()){
769 // Split the name into sections.
771 vCardDataString = Person.Get(wxT("N"));
773 vCardName NameData = Person.GetName();
775 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
777 } else if (SortMode == 2){
779 // Split the name into sections.
781 vCardName NameData = Person.GetName();
783 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
785 } else if (SortMode == 3){
787 // Check and make sure that the top most nickname is used.
789 vCardDataString = Person.Get(wxT("NICKNAME"));
791 if (vCardDataString.IsEmpty()){
793 vCardDataString = wxT("(no nickname)");
797 } else if (SortMode == 4){
799 vCardDataString = Person.Get(wxT("FN"));
803 if (AscendingMode == TRUE){
804 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
806 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
815 vCardFilename.Clear();
816 vCardFilenameFull.Clear();
817 vCardDataString.Clear();
818 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
825 // Insert the data into the control.
827 if (AscendingMode == TRUE){
828 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
829 iter != vCardNamesAsc.end(); ++iter){
831 wxListItem ContactInfo;
833 ContactInfo.SetId(0);
834 ContactInfo.SetText(_("Mooo"));
835 ContactInfo.SetData(ContactSeekPoint);
836 ContactIndex = lstContacts->InsertItem(ContactInfo);
838 lstContacts->SetItem(ContactIndex, 0, iter->first);
839 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
846 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
847 iter != vCardNamesDsc.end(); ++iter){
849 wxListItem ContactInfo;
851 ContactInfo.SetId(0);
852 ContactInfo.SetText(_("Mooo"));
853 ContactInfo.SetData(ContactSeekPoint);
854 ContactIndex = lstContacts->InsertItem(ContactInfo);
856 lstContacts->SetItem(ContactIndex, 0, iter->first);
857 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
866 void frmMain::ShowContactInfo( wxListEvent& event )
869 long intSelected = -1;
870 long ContactSeekNum = -1;
872 // intSelected = lstContacts->GetSelection();
874 // Check if several contacts have been selected.
876 int ContactTotal = 0;
880 intSelected = lstContacts->GetNextItem(intSelected,
882 wxLIST_STATE_SELECTED);
884 if (intSelected == -1){
894 if (ContactTotal == 0){
895 htmContactData->SetPage(wxT(""));
899 if (ContactTotal > 1){
901 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
902 ActiveFilename.Clear();
907 intSelected = lstContacts->GetNextItem(intSelected,
909 wxLIST_STATE_SELECTED);
911 ContactSeekNum = lstContacts->GetItemData(intSelected);
914 wxString wxSContactString;
915 wxString ContactLine;
918 size_t ContactLineLen;
919 bool ExtraLineSeek = FALSE;
920 int QuoteBreakPoint = 0;
922 bool PropertyFind = FALSE;
923 bool QuoteMode = FALSE;
925 wxString wxSPropertyNextLine;
926 wxString wxSProperty;
927 wxString wxSPropertySeg1;
928 wxString wxSPropertySeg2;
930 // Check if we are using wxWidgets version 2.8 or less and
931 // execute the required command accordingly.
933 #if wxABI_VERSION < 20900
934 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
936 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
939 if (ContactFile.IsOpened() == FALSE){
945 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
949 std::map<int, wxString> ContactFileLines;
950 std::map<int, wxString>::iterator striter;
952 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
954 int ContactLineSeek = 0;
956 while (wSTContactFileLines.HasMoreTokens() == TRUE){
958 ContactLine = wSTContactFileLines.GetNextToken();
959 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
964 if (ContactSeekNum < 0){
968 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
969 iter != ContactFileLines.end(); ++iter){
971 // Find the colon which splits the start bit from the data part.
973 ContactLine = iter->second;
975 while (ExtraLineSeek == TRUE){
977 // Check if there is extra data on the next line
978 // (indicated by space or tab at the start) and add data.
982 if (iter == ContactFileLines.end()){
989 wxSPropertyNextLine = iter->second;
992 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
994 wxSPropertyNextLine.Remove(0, 1);
995 //wxSPropertyNextLine.Trim(FALSE);
996 //ContactLine.Trim();
997 ContactLine.Append(wxSPropertyNextLine);
1002 ExtraLineSeek = FALSE;
1008 ContactLineLen = ContactLine.Len();
1010 // Make sure we are not in quotation mode.
1011 // Make sure colon does not have \ or \\ before it.
1013 for (int i = 0; i <= ContactLineLen; i++){
1015 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1017 PropertyFind = FALSE;
1019 } else if (PropertyFind == TRUE){
1021 wxSProperty.Append(ContactLine.Mid(i, 1));
1025 if (ContactLine.Mid(i, 1) == wxT("\"")){
1027 if (QuoteMode == TRUE){
1039 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1041 QuoteBreakPoint = i;
1048 // Split that line at the point into two variables (ignore the colon).
1050 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1051 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1053 // Insert both into the vCard data file.
1055 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1058 PropertyFind = TRUE;
1059 ExtraLineSeek = TRUE;
1061 QuoteBreakPoint = 0;
1062 ContactLine.Clear();
1063 wxSProperty.Clear();
1067 OldSessionID = SessionID;
1068 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1069 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1070 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1074 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1077 // Check if there is an account selected and if not
1078 // return immediately.
1080 if (ActiveAccount.IsEmpty()){
1086 // Add Pointer to SetupPointers for the ETagDB.
1088 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1089 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1090 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1092 contacticon.CopyFromBitmap(contacticonbmp);
1094 frmContactEditor *ContactEditor = new frmContactEditor( this );
1098 ContactEditor->SetUID(WindowMenuItemID);
1100 WindowData *WData = new WindowData;
1102 WData->DataType = 1;
1103 WData->WindowPointer = (void*)ContactEditor;
1104 WData->WindowID = WindowMenuItemID;
1106 wxCommandEvent addevent(WINDOW_ADD);
1107 addevent.SetClientData(WData);
1108 wxPostEvent(this, addevent);
1110 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1111 ContactEditor->SetupHeaders();
1112 ContactEditor->SetupContact(ActiveAccount);
1113 ContactEditor->SetIcon(contacticon);
1114 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1115 ContactEditor->Show(true);
1119 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1122 // Check if there is an account selected and if not
1123 // return immediately.
1125 int DataCheck = event.GetInt();
1127 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1133 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1134 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1135 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1137 contacticon.CopyFromBitmap(contacticonbmp);
1139 // Check if a contact has been selected.
1141 long intSelected = -1;
1142 long intContactSeekNum = -1;
1144 // intSelected = lstContacts->GetSelection();
1146 intSelected = lstContacts->GetNextItem(intSelected,
1148 wxLIST_STATE_SELECTED);
1150 if (intSelected == -1){
1154 intContactSeekNum = lstContacts->GetItemData(intSelected);
1156 // Get the filename of the selected contact.
1158 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1159 frmContactEditor *ContactEditor = new frmContactEditor( this );
1163 ContactEditor->SetUID(WindowMenuItemID);
1165 WindowData *WData = new WindowData;
1167 WData->DataType = 1;
1168 WData->WindowPointer = (void*)ContactEditor;
1169 WData->WindowID = WindowMenuItemID;
1171 wxCommandEvent addevent(WINDOW_ADD);
1172 addevent.SetClientData(WData);
1173 wxPostEvent(this, addevent);
1175 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1176 ContactEditor->SetupHeaders();
1178 // Check if pointer is NULL (not from the search forms) or not.
1180 if (DataCheck == 0){
1182 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1183 ContactEditor->SetupContact(ActiveAccount);
1187 UCNotif *uc = (UCNotif*)event.GetClientData();
1191 ContactEditor->SetupContact(ActiveAccount);
1192 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1196 ContactEditor->SetupContact(uc->ContactAccount);
1197 ContactEditor->LoadContact(uc->ContactFilename);
1207 ContactEditor->SetIcon(contacticon);
1208 ContactEditor->Show(true);
1212 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1214 // TODO: Check Account Type.
1216 if (!ActiveAccount.IsEmpty()){
1218 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1219 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1220 wxT(""), wxT(""), wxT(""), wxT(""));
1226 void frmMain::OpenContactInfo( wxListEvent& event )
1229 wxStringTokenizer vcardfileline;
1232 wxString setname, setvalue;
1236 long intSelected = -1;
1237 long intContactSeekNum = -1;
1239 intSelected = lstContacts->GetNextItem(intSelected,
1241 wxLIST_STATE_SELECTED);
1243 intContactSeekNum = lstContacts->GetItemData(intSelected);
1245 if (intContactSeekNum == -1){
1249 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1251 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1252 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1253 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1255 contacticon.CopyFromBitmap(contacticonbmp);
1257 frmContact *Contact = new frmContact( this );
1259 // Add to window list.
1263 Contact->SetUID(WindowMenuItemID);
1265 WindowData *WData = new WindowData;
1267 WData->DataType = 0;
1268 WData->WindowPointer = (void*)Contact;
1269 WData->WindowID = WindowMenuItemID;
1271 wxCommandEvent addevent(WINDOW_ADD);
1272 addevent.SetClientData(WData);
1273 wxPostEvent(this, addevent);
1275 Contact->SetupPointers(&MemoryFileList);
1276 Contact->SetupContactData(&Person);
1278 Contact->SetIcon(contacticon);
1279 Contact->Show(true);
1283 void frmMain::OpenContactInfo( wxCommandEvent& event )
1286 UCNotif *uc = (UCNotif*)event.GetClientData();
1288 wxStringTokenizer vcardfileline;
1291 wxString setname, setvalue;
1294 //std::fstream vcardfile;
1296 Person.LoadFile(uc->ContactFilename);
1298 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1299 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1300 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1302 contacticon.CopyFromBitmap(contacticonbmp);
1304 frmContact *Contact = new frmContact( this );
1306 // Add to window list.
1310 Contact->SetUID(WindowMenuItemID);
1312 WindowData *WData = new WindowData;
1314 WData->DataType = 0;
1315 WData->WindowPointer = (void*)Contact;
1316 WData->WindowID = WindowMenuItemID;
1318 wxCommandEvent addevent(WINDOW_ADD);
1319 addevent.SetClientData(WData);
1320 wxPostEvent(this, addevent);
1322 Contact->SetupPointers(&MemoryFileList);
1323 Contact->SetupContactData(&Person);
1325 Contact->SetIcon(contacticon);
1326 Contact->Show(true);
1331 void frmMain::LoadPreferences( wxActivateEvent& event)
1333 this->LoadPreferences();
1336 void frmMain::LoadPreferences(){
1338 // Load the preferences.
1340 wxString preffilename = GetUserPrefDir();
1342 XABPreferences preferences(preffilename);
1344 // Setup the main window position (if needed).
1346 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1347 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1349 if (SaveWindowPos == TRUE){
1351 this->SetSize(preferences.GetMainWindowData());
1355 treAccounts->DeleteAllItems();
1357 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1359 // Stop all account timers and remove the accounts.
1361 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1362 iter != AccountSyncTimers.end(); iter++){
1364 wxAccountSyncTimer *AccTmrPtr = iter->second;
1372 AccountSyncTimers.clear();
1375 for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
1376 treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
1381 wxString AccDirFull;
1382 wxString AccDirFullSfx;
1384 wxString AccDirFinal;
1385 AccountAccDirList.clear();
1386 AccountGroupList.clear();
1387 AccountGroupFilename.clear();
1388 AccountGroupTreeId.clear();
1389 wxTreeItemId AccountTreeId;
1390 wxTreeItemId GroupTreeId;
1393 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1395 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1396 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1402 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1408 AccDir = preferences.accounts.GetAccountDirectory(i);
1409 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1411 AccDirFull.Append(wxT("."));
1412 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1413 AccDirFullSfx.LowerCase();
1414 AccDirFullSfx.Trim();
1415 AccDirFull.Append(AccDirFullSfx);
1416 AccName = preferences.accounts.GetAccountName(i);
1418 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1420 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1421 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1423 // Check if the directory exists before doing anything.
1427 // Add a new timer using the existing account details.
1429 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1431 ActTmrPtr->SetupData(AccDirFull, AccName);
1432 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1433 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1434 ActTmrPtr->SetOwner(this);
1435 ActTmrPtr->Notify();
1437 // Add the timer to the list of timers.
1439 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1441 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1445 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1449 // Go through the account directory and find contact files with
1450 // 'KIND:group' set and add them to the list of groups for the account.
1452 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1454 wxDir vcardaccdir(AccDirFinal);
1456 wxString vCardFilename;
1457 wxString vCardDataString;
1458 wxString vCardFilenameFull;
1459 //bool ProcFiles = FALSE;
1461 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1464 if (vCardFilename.Right(4) == wxT(".vcf") ||
1465 vCardFilename.Right(4) == wxT(".VCF") ||
1466 vCardFilename.Right(5) == wxT(".vcard") ||
1467 vCardFilename.Right(5) == wxT(".VCARD")){
1471 vCardFilenameFull.Append(AccDirFinal);
1472 vCardFilenameFull.Append(wxT("/"));
1473 vCardFilenameFull.Append(vCardFilename);
1475 Person.LoadFile(vCardFilenameFull);
1477 if (Person.MeetBaseSpecification()){
1479 vCardDataString = Person.Get(wxT("KIND"));
1481 if (vCardDataString == wxT("group")){
1483 // The vCard kind is a group. Add to the account's group list.
1485 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1486 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1487 AccountGroupList.insert(std::make_pair(intGroupID, i));
1488 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1489 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1501 vCardFilename.Clear();
1502 vCardFilenameFull.Clear();
1503 vCardDataString.Clear();
1504 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1508 // Clearup for next account.
1512 AccDirFullSfx.clear();
1513 AccDirFinal.clear();
1518 // Load the account settings as they are needed for connecting
1521 prefaccounts = preferences.accounts;
1525 void frmMain::ConflictResolution(wxCommandEvent& event){
1527 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1528 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1529 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1530 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1531 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1532 //wxString Moo = ClientDataPtr->WriteString();
1533 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1534 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1535 //frameCR->LoadData(vCardConfObj->vCardLocalData, vCardConfObj->vCardServerData, &MemoryFileList);
1536 frameCR->ShowModal();
1538 int FinalConflictResult = frameCR->GetResult();
1540 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1541 event2.SetClientData(vCardConfObj->QRNotifData);
1542 event2.SetInt(FinalConflictResult);
1547 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1548 wxPostEvent(frameActMgr, event2);
1552 void frmMain::UpdateContactList(wxCommandEvent& event){
1554 UCNotif *ucd = (UCNotif*)event.GetClientData();
1556 // Check if the active account is being displayed in the
1557 // main window. If not, skip and delete the data.
1559 long longSelected = -1;
1560 int intSelectedData = 0;
1562 if (ActiveAccount == ucd->ContactAccount){
1564 // Look at the list of contacts and if it matches the
1565 // filename then update the name.
1569 longSelected = lstContacts->GetNextItem(longSelected,
1571 wxLIST_STATE_DONTCARE);
1573 if (longSelected == -1){
1579 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1581 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1583 // Work out which sorting mode we are in.
1587 // First Name, Last Name.
1589 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1591 } else if (SortMode == 2){
1593 // Last Name, First Name.
1595 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1597 } else if (SortMode == 3){
1601 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1603 } else if (SortMode == 4){
1607 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1614 // If the filename is the one loaded into the
1615 // browser control, then update this too.
1617 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1619 wxListEvent nullevent;
1620 ShowContactInfo(nullevent);
1628 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1629 WindowIter != WindowListPointers.end(); WindowIter++){
1631 if (WindowListType[WindowIter->first] != 0){
1637 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1639 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1641 vCard UpdatedPerson;
1642 UpdatedPerson.LoadFile(ucd->ContactFilename);
1643 frmContactPtr->SetupContactData(&UpdatedPerson);
1649 // Send message to search window controller subroutine and
1650 // pass that notification onto the search windows.
1652 // Setup the new pointer to use the existing UCNotif without
1655 UCNotif *ucd2 = ucd;
1657 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1658 sup.SetClientData(ucd2);
1659 wxPostEvent(this, sup);
1661 // Clear up the unused pointer.
1667 void frmMain::UpdateAccountList(wxCommandEvent& event){
1671 void frmMain::SetupPointers(void *ActMgrPtrInc){
1673 ActMgrPtr = ActMgrPtrInc;
1677 void frmMain::SetupForm(){
1679 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1680 frameActMgr->SetupPointers(&ETagProcTimer, this);
1682 // Setup the contact information icons for later.
1684 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1688 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1689 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1690 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1692 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1693 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1694 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1696 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1697 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1698 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1700 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1701 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1702 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1704 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1705 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1706 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1708 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1709 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1710 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1716 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1718 // Go through each of the search windows and
1719 // send the required notification to update the
1720 // contact information.
1722 // Get the event notification data.
1724 UCNotif *ucd = (UCNotif*)event.GetClientData();
1726 // Process each search window giving the new details.
1728 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1729 switer != SearchWindowList.end(); switer++){
1731 // Duplicate the event notification data.
1733 UCNotif *ucd2 = new UCNotif;
1735 ucd2->ContactAccount = ucd->ContactAccount;
1736 ucd2->ContactFilename = ucd->ContactFilename;
1737 ucd2->ContactName = ucd->ContactName;
1738 ucd2->ContactNickname = ucd->ContactNickname;
1739 ucd2->ContactNameArray = ucd->ContactNameArray;
1741 // Pass the data to the search window for processing.
1743 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1744 wxCommandEvent schupdate(SE_UPDATERESULT);
1745 schupdate.SetClientData(ucd2);
1746 wxPostEvent(frameSCH, schupdate);
1748 // Clear up the pointer prior to variable deletion.
1759 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1763 frmSearch *frameSCH = new frmSearch ( this );
1764 frameSCH->SetUID(WindowMenuItemID);
1765 frameSCH->Show(true);
1767 WindowData *WData = new WindowData;
1769 WData->DataType = 2;
1770 WData->WindowPointer = (void*)frameSCH;
1771 WData->WindowID = WindowMenuItemID;
1773 wxCommandEvent addevent(WINDOW_ADD);
1774 addevent.SetClientData(WData);
1775 wxPostEvent(this, addevent);
1777 // Add pointer to the list of open search windows.
1779 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1785 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1787 //frmSearch *frameSCH = static_cast<frmSearch*>(ActMgrPtr);
1788 void *frameSCH = (void*)event.GetClientData();
1790 SearchWindowList.erase(frameSCH);
1796 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1798 void *frameSCH = (void*)event.GetClientData();
1800 SearchWindowList.erase(frameSCH);
1806 void frmMain::UpdateWindowList(wxCommandEvent& event){
1808 // Update the Window List.
1810 // Delete the existing items in the window menu.
1812 // Get the list of contacts.
1814 // Insert a separator.
1816 // Get the list of search windows.
1820 void frmMain::RevealContact(wxCommandEvent& event){
1822 UCNotif *uc = (UCNotif*)event.GetClientData();
1824 // Switch the account to the one passed.
1826 wxTreeItemIdValue cookie;
1827 wxTreeItemId next = treAccounts->GetRootItem();
1828 wxTreeItemId nextChild;
1830 for (int i = 0; i < prefaccounts.GetCount(); i++){
1833 nextChild = treAccounts->GetFirstChild(next, cookie);
1835 nextChild = treAccounts->GetNextSibling(nextChild);
1838 //AccountName = treAccounts->GetItemText(nextChild);
1840 if (uc->ContactAccount == AccountAccDirList[i]){
1843 treAccounts->SelectItem(nextChild, TRUE);
1844 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1850 // Switch the contact to the one passed.
1852 long longSelected = -1;
1853 int intSelectedData = 0;
1857 longSelected = lstContacts->GetNextItem(longSelected,
1859 wxLIST_STATE_DONTCARE);
1861 if (longSelected == -1){
1867 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1869 // Compare the filename with the one received.
1870 // If they match then select it.
1872 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1876 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1877 lstContacts->EnsureVisible(longSelected);
1887 void frmMain::DeleteContact(wxCommandEvent& event){
1889 // Check if a contact is selected.
1891 long intSelected = -1;
1892 long intContactSeekNum = -1;
1893 wxString wxSContactName;
1895 intSelected = lstContacts->GetNextItem(intSelected,
1897 wxLIST_STATE_SELECTED);
1899 if (intSelected == -1){
1903 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1905 // Get the item data of the contact.
1907 intContactSeekNum = lstContacts->GetItemData(intSelected);
1909 // Get the name of the contact.
1911 wxSContactName = lstContacts->GetItemText(intSelected);
1913 // Display a message confirming if the contact should
1916 int QuestionResponse;
1918 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1920 if (QuestionResponse == wxNO){
1922 // Exit the subroutine
1928 // Delete the contact.
1930 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1932 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1937 // Remove the contact from the list.
1939 lstContacts->DeleteItem(intSelected);
1941 // Update the search windows, removing the deleted
1944 UCNotif *ucd = new UCNotif;
1946 ucd->ContactAccount = ActiveAccount;
1947 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1949 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1950 switer != SearchWindowList.end(); switer++){
1952 // Duplicate the event notification data.
1954 UCNotif *ucd2 = new UCNotif;
1956 ucd2->ContactAccount = ucd->ContactAccount;
1957 ucd2->ContactFilename = ucd->ContactFilename;
1959 // Pass the data to the search window for processing.
1961 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1962 wxCommandEvent schdelete(SE_DELETERESULT);
1963 schdelete.SetClientData(ucd2);
1964 wxPostEvent(frameSCH, schdelete);
1966 // Clear up the pointer prior to variable deletion.
1973 // Clear the wxHTMLWindow.
1975 wxString EmptyPage = wxT("");
1977 htmContactData->SetPage(EmptyPage);
1979 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
1981 wxString wxSplitFilename;
1982 wxString wxSDataURL;
1984 while(wSTFilename.HasMoreTokens()){
1986 wxSplitFilename = wSTFilename.GetNextToken();
1990 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
1992 // Update the ETagDB and mark it as deleted.
1994 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
1996 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
1998 // Get the Data URL.
2000 wxTreeItemIdValue cookie;
2001 wxTreeItemId next = treAccounts->GetRootItem();
2003 wxTreeItemId selectedChild = treAccounts->GetSelection();
2004 wxTreeItemId nextChild;
2006 for (int i = 0; i < prefaccounts.GetCount(); i++){
2009 nextChild = treAccounts->GetFirstChild(next, cookie);
2012 nextChild = treAccounts->GetNextSibling(nextChild);
2015 if (nextChild == selectedChild){
2016 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2022 // Add task to the activity monitor to delete the contact.
2024 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2028 // Clear the variable. Don't delete as it will mess things up.
2030 ContactsFileIndex[intContactSeekNum] = wxT("");
2037 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2039 QRNotif *qrn = (QRNotif *)event.GetClientData();
2041 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);
2043 if (QResponse == wxNO){
2049 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2050 event2.SetInt(*qrn->QResponse);
2051 event2.SetClientData(qrn->PausePtr);
2053 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2055 wxPostEvent(frameActMgr, event2);
2059 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2061 // Remove the contact from the window after syncronising.
2063 // Check which account is currently active in the window.
2064 // If it is different from the one passed to this subroutine then
2065 // exit from the subroutine.
2067 if (Account != ActiveAccount){
2071 long longSelected = -1;
2072 int intSelectedData = 0;
2076 longSelected = lstContacts->GetNextItem(longSelected,
2078 wxLIST_STATE_DONTCARE);
2080 if (longSelected == -1){
2086 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2088 // Compare the filename with the one received.
2089 // If they match then select it.
2091 if (ContactsFileIndex[intSelectedData] == Filename){
2093 // Remove the contact from the window.
2095 lstContacts->DeleteItem(intSelectedData);
2097 // Check if contact is the selected contact in the HTML window and
2098 // if it is then clear the window.
2100 if (ActiveFilename == Filename){
2102 wxString EmptyPage = wxT("");
2103 htmContactData->SetPage(EmptyPage);
2117 void frmMain::SortFNLN( wxCommandEvent& event ) {
2119 wxTreeEvent NullEvent;
2121 LoadContactList(NullEvent);
2125 void frmMain::SortLNFN( wxCommandEvent& event ) {
2127 wxTreeEvent NullEvent;
2129 LoadContactList(NullEvent);
2133 void frmMain::SortNickname( wxCommandEvent& event ) {
2135 wxTreeEvent NullEvent;
2137 LoadContactList(NullEvent);
2141 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2143 wxTreeEvent NullEvent;
2145 LoadContactList(NullEvent);
2149 void frmMain::SortAscending( wxCommandEvent& event ) {
2151 wxTreeEvent NullEvent;
2152 AscendingMode = TRUE;
2153 LoadContactList(NullEvent);
2157 void frmMain::SortDescending( wxCommandEvent& event ) {
2159 wxTreeEvent NullEvent;
2160 AscendingMode = FALSE;
2161 LoadContactList(NullEvent);
2165 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2167 if (stbBottom->IsShown() == TRUE){
2181 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2183 // Display the activity icon.
2185 imgActivityStatus->SetBitmap(*imgActIcon1);
2186 ActivityIconStatus = 0;
2190 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2192 switch (ActivityIconStatus){
2195 imgActivityStatus->SetBitmap(*imgActIcon1);
2196 ActivityIconStatus = 1;
2199 imgActivityStatus->SetBitmap(*imgActIcon2);
2200 ActivityIconStatus = 2;
2203 imgActivityStatus->SetBitmap(*imgActIcon3);
2204 ActivityIconStatus = 3;
2207 imgActivityStatus->SetBitmap(*imgActIcon4);
2208 ActivityIconStatus = 0;
2211 ActivityIconStatus = 0;
2217 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2219 // Display the sleep icon.
2221 imgActivityStatus->SetBitmap(*imgActIconSleep);
2225 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2227 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2235 wxRect rectActivity;
2236 stbBottom->GetFieldRect(1, rectOnline);
2237 stbBottom->GetFieldRect(2, rectSSL);
2238 stbBottom->GetFieldRect(3, rectActivity);
2240 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2241 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2242 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2246 XABViewMode frmMain::GetViewMode(){
2250 xvm.SortMode = SortMode;
2251 xvm.AscendingMode = AscendingMode;
2257 void frmMain::WindowAdd( wxCommandEvent &event ){
2259 WindowData *WData = (WindowData*)event.GetClientData();
2263 if (WData->DataType == 0){
2267 int intID = mnuContactWindows->GetId();
2269 mnuWindow->FindChildItem(intID, &pos);
2270 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2271 mnuNewItem->SetId(WData->WindowID);
2272 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2273 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2274 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2275 mnuWindow->Insert((pos + 1), mnuNewItem);
2276 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2278 } else if (WData->DataType == 1){
2280 // Contact Editor Window
2282 int intID = mnuContactEditorWindows->GetId();
2284 mnuWindow->FindChildItem(intID, &pos);
2285 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2286 mnuNewItem->SetId(WData->WindowID);
2287 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2288 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2289 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2290 mnuWindow->Insert((pos + 1), mnuNewItem);
2291 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2293 } else if (WData->DataType == 2){
2297 int intID = mnuSearchWindows->GetId();
2299 mnuWindow->FindChildItem(intID, &pos);
2300 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2301 mnuNewItem->SetId(WData->WindowID);
2302 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2303 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2304 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2305 mnuWindow->Insert((pos + 1), mnuNewItem);
2306 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2315 void frmMain::WindowEdit( wxCommandEvent &event ){
2317 WindowData *WData = (WindowData*)event.GetClientData();
2319 if (WData->DataType == 0){
2321 // Get the window title and use that.
2323 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2325 wxString WindowTitle = frmContactPtr->GetTitle();
2327 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2329 MenuIter->second->SetItemLabel(WindowTitle);
2331 //mnuWindow->FindChildItem(intID, &pos);
2332 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2333 //mnuNewItem->SetId(WData->WindowID);
2334 //ContactWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2335 //ContactWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
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 // Get the window title and use that.
2343 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2345 wxString WindowTitle = frmCEPtr->GetTitle();
2347 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2349 if (WindowTitle.IsEmpty()){
2351 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2355 MenuIter->second->SetItemLabel(WindowTitle);
2359 //mnuWindow->FindChildItem(intID, &pos);
2360 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2361 //mnuNewItem->SetId(WData->WindowID);
2362 //ContactEditorWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2363 //ContactEditorWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2364 //mnuWindow->Insert((pos + 1), mnuNewItem);
2365 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2374 void frmMain::WindowDelete( wxCommandEvent &event ){
2376 WindowData *WData = (WindowData*)event.GetClientData();
2378 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2380 mnuWindow->Remove(MenuIter->second);
2382 delete MenuIter->second;
2383 MenuIter->second = NULL;
2385 WindowListPointersMenu.erase(WData->WindowID);
2386 WindowListPointers.erase(WData->WindowID);
2387 WindowListType.erase(WData->WindowID);
2394 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2396 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2398 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2400 frmContactPtr->Show();
2401 frmContactPtr->Raise();
2405 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2407 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2409 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2416 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2418 // Look through the Search Window List Pointers, grab the
2419 // window point and show the window.
2421 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2423 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2425 frmSearchPtr->Show();
2426 frmSearchPtr->Raise();
2430 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2432 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2433 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2434 wxPostEvent(frameActMgr, toggconn);
2438 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2440 // Check the account type before continuing.
2442 wxString SeekAccount;
2443 wxString AccTypeLower;
2446 std::map<int, SSLCertCollection>::iterator SSLColIter;
2448 for (int i = 0; i < prefaccounts.GetCount(); i++){
2450 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2451 AccType.Append(prefaccounts.GetAccountType(i));
2452 AccountSSL = prefaccounts.GetAccountSSL(i);
2453 AccTypeLower = AccType.MakeLower();
2454 SeekAccount.Append(wxT("."));
2455 SeekAccount.Append(AccTypeLower);
2457 if (SeekAccount == ActiveAccount){
2459 if (AccTypeLower == wxT("local")){
2465 if (AccountSSL == false){
2471 SSLColIter = AccountSSLData.find(i);
2473 SSLCertCollection SSLCertInfo = SSLColIter->second;
2475 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2476 frameSSLCert->StartCertFrom(0);
2477 frameSSLCert->SetupCerts(SSLCertInfo);
2478 frameSSLCert->ShowModal();
2480 delete frameSSLCert;
2481 frameSSLCert = NULL;
2485 SeekAccount.Clear();
2486 AccTypeLower.Clear();
2493 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2495 // Check the account type before continuing.
2499 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2501 // Check the account type before continuing.
2505 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2507 if (event.GetInt() == 0){
2509 imgConnStatus->SetBitmap(*imgOnline);
2513 imgConnStatus->SetBitmap(*imgOffline);
2519 void frmMain::SetupSSLStatus( int AccountID ){
2521 // Check if account ID given is
2522 // the active account and if not, do nothing.
2525 wxString AccTypeLower;
2527 AccType = prefaccounts.GetAccountType(AccountID);
2528 AccTypeLower = AccType.MakeLower();
2530 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2533 if (AccountIDName != ActiveAccount){
2539 // Check if the account has SSL enabled.
2541 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2543 if (SSLInUse == FALSE){
2545 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2546 imgSSLStatus->SetBitmap(*imgNoSSL);
2550 // Get the SSL Collection Data.
2552 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2554 if (SSLResultIter->second == 1){
2556 imgSSLStatus->SetBitmap(*imgSSLWarning);
2557 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2558 prefaccounts.GetAccountName(AccountID) +
2559 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2562 } else if (SSLResultIter->second == 0){
2564 imgSSLStatus->SetBitmap(*imgSSL);
2565 SSLToolTip->SetTip(wxT("Account '") +
2566 prefaccounts.GetAccountName(AccountID) +
2567 wxT("' secured using SSL\n\nDouble click for more information."));
2575 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2577 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2578 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2579 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2580 wxString AccountName = SSLICNObj->AccountName;
2581 frameISC->LoadData(SSLCCData, AccountName);
2582 frameISC->ShowModal();
2584 int FinalConflictResult = frameISC->GetResult();
2586 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2587 event2.SetClientData(SSLICNObj->QRNotifData);
2588 event2.SetInt(FinalConflictResult);
2593 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2594 wxPostEvent(frameActMgr, event2);
2597 void frmMain::PauseAllTimers(){
2599 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2600 ASTiter != AccountSyncTimers.end(); ASTiter++){
2602 ASTiter->second->Stop();
2608 void frmMain::ResumeAllTimers(){
2610 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2611 ASTiter != AccountSyncTimers.end(); ASTiter++){
2613 ASTiter->second->Start();
2619 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2621 // Delete existing data.
2623 AccountSSLData.erase(AccountID);
2624 AccountSSLResult.erase(AccountID);
2628 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2629 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2633 void frmMain::CheckUpdates( wxCommandEvent& event ){
2635 frmUpdate *frameUpdate = new frmUpdate ( this );
2636 frameUpdate->FetchData();
2637 frameUpdate->ShowModal();
2641 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2643 // Run the import contacts system.
2649 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2651 // Check if an account and at least one contact is selected
2652 // before continuing.
2654 wxArrayString ArrData;
2656 if (ActiveAccount.IsEmpty()){
2662 int ContactSelected = 0;
2663 int ContactsCollected = 0;
2664 long longSelected = -1;
2668 longSelected = lstContacts->GetNextItem(longSelected,
2670 wxLIST_STATE_SELECTED);
2672 if (longSelected == -1){
2678 int FileID = (int)lstContacts->GetItemData(longSelected);
2680 ArrData.Insert(ContactsFileIndex[FileID],
2681 ContactsCollected, 1);
2687 if (ContactSelected == 0){
2693 // Run the export contacts system.
2695 ExportRun(this, &ArrData);
2699 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2700 wxArrayString *ContactsFileIndexPtr){
2702 lstContactsPtr = lstContacts;
2703 ContactsFileIndexPtr = &ContactsFileIndex;
2707 void frmMain::GetSelectedList( wxCommandEvent& event ){
2709 // Get the array of contact filenames.
2711 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2713 // Process them into an array of files.
2715 long longSelected = -1;
2716 int ContactsCollected = 0;
2717 wxString ContactFilename;
2721 longSelected = lstContacts->GetNextItem(longSelected,
2723 wxLIST_STATE_SELECTED);
2725 if (longSelected == -1){
2731 // Get the file information and add to the list.
2733 int FileID = (int)lstContacts->GetItemData(longSelected);
2735 ArrData->Insert(ContactsFileIndex[FileID],
2736 ContactsCollected, 1);
2738 ContactsCollected++;
2739 ContactFilename.Clear();
2747 void frmMain::SyncAccount( wxCommandEvent& event ){
2749 wxString *AccNameInc = (wxString*)event.GetClientData();
2751 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2752 frameActMgr->AddTask(3, wxT(""), *AccNameInc,
2753 wxT(""), wxT(""), wxT(""), wxT(""));
2757 void frmMain::ShowHelp( wxCommandEvent& event ){
2759 // Based on the operating system, work out where
2760 // the documentation should be.
2764 #if defined(__HAIKU__)
2766 #elif defined(__WIN32__)
2772 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2774 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2777 #if XSDAB_RELEASE == 0
2779 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2781 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2790 #if XSDAB_RELEASE == 0
2792 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2796 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!"));