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"
31 #include "import/frmImportResults.h"
34 #include "common/preferences.h"
35 #include "common/getcontactinfo.h"
36 #include "common/events.h"
37 #include "common/dirs.h"
38 #include "vcard/vcard.h"
39 #include "carddav/carddav.h"
40 #include "contacteditor/frmContactEditor.h"
41 #include "import/import.h"
42 #include "export/export.h"
43 #include "widgets/XABAccountView.h"
47 //extern const wxEventType MyHaremEvent = wxNewEventType();
49 //#define CE_UPDATECONTACTLIST 7700
50 //#define CE_UPDATEACCOUNTLIST 7701
52 DEFINE_EVENT_TYPE(CE_UPDATECONTACTLIST);
53 DEFINE_EVENT_TYPE(CE_UPDATEACCOUNTLIST);
54 DEFINE_EVENT_TYPE(SE_UPDATECONTACTNOTIF);
55 DEFINE_EVENT_TYPE(CE_OPENCONTACT);
56 DEFINE_EVENT_TYPE(CE_EDITCONTACT);
57 DEFINE_EVENT_TYPE(CE_REVEALCONTACT);
58 DEFINE_EVENT_TYPE(CE_REMOVECONTACT);
59 DEFINE_EVENT_TYPE(CE_REMOVESEARCH);
60 DEFINE_EVENT_TYPE(SYNC_EMPTYSERVER);
61 DEFINE_EVENT_TYPE(ACTMGR_START);
62 DEFINE_EVENT_TYPE(ACTMGR_SHUFFLE);
63 DEFINE_EVENT_TYPE(ACTMGR_STOP);
64 DEFINE_EVENT_TYPE(WINDOW_ADD);
65 DEFINE_EVENT_TYPE(WINDOW_EDIT);
66 //DEFINE_EVENT_TYPE(WINDOW_DELETE);
67 DEFINE_EVENT_TYPE(WINDOW_CLOSE);
68 DEFINE_EVENT_TYPE(CONNSTAT_UPDATE);
69 DEFINE_EVENT_TYPE(INVALIDSSLCERT);
70 DEFINE_EVENT_TYPE(GETSELECTEDLIST);
71 DEFINE_EVENT_TYPE(SYNCACCOUNT);
72 DEFINE_EVENT_TYPE(IMPORT_RESULTSSHOW);
74 BEGIN_EVENT_TABLE(frmMain, wxFrame)
75 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
76 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
77 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
78 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
79 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
80 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
81 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
82 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
83 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
84 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
85 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
86 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
87 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
88 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
89 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
90 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
91 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
92 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
93 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
94 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
97 frmMain::frmMain( wxWindow* parent )
102 // Setup the account icons.
104 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
105 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
106 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
107 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
109 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
110 wxBitmap AccInet(icons_accinet_png, -1);
112 wxIAccInet.CopyFromBitmap(AccInet);
114 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
115 wxBitmap AccNIcon(icons_acclocal_png, -1);
117 wxIAccNIcon.CopyFromBitmap(AccNIcon);
119 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
120 wxBitmap AccGrp(icons_accgroup_png, -1);
122 wxIAccGrp.CopyFromBitmap(AccGrp);
124 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
125 wxBitmap AccNone(icons_accnone_png, -1);
127 wxIAccNone.CopyFromBitmap(AccNone);
129 AccountID = AccImgList->Add(wxIAccNIcon);
130 AccountNetID = AccImgList->Add(wxIAccInet);
131 AccountGrpID = AccImgList->Add(wxIAccGrp);
132 AccountNoneID = AccImgList->Add(wxIAccNone);
134 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
136 // Setup the status bar icons.
140 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
141 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
142 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
144 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
145 imgSSL = new wxBitmap(icons_ssl_png, -1);
147 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
148 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
150 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
151 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
155 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
156 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
157 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
158 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
159 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
161 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
162 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
164 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
165 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
167 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
169 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
170 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
172 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
174 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
175 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
177 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
179 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
180 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
182 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
184 // Online/Offline icons.
186 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
187 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
189 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
190 imgOnline = new wxBitmap(icons_online_png, -1);
192 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
193 imgOffline = new wxBitmap(icons_offline_png, -1);
195 // Setup the account view.
197 AccCtrl->SetPopupControl(treAccounts);
198 AccCtrl->SetPopupMaxHeight(175);
199 AccCtrl->SetPopupMinWidth(250);
200 treAccounts->AssignImageList(AccImgList);
203 /*wxStaticBitmap* BeepBoop = new wxStaticBitmap(AccCtrl, wxID_ANY, wxNullBitmap, wxPoint(AccTextCtrlSize.GetX() + 3, AccTextCtrlSize.GetY() + 2), wxDefaultSize, 0);
205 icons_accgroup_png.SetMask(new wxMask(icons_accgroup_png, wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND)));
207 BeepBoop->SetBackgroundColour(AccCtrl->GetBackgroundColour());
208 BeepBoop->SetBitmap(icons_accgroup_png);*/
210 //szrContactList->Insert(0, XABV2, 1, wxEXPAND | wxALL, 0);
212 /*AccControl->UseAltPopupWindow();
213 AccControl->SetPopupControl(treAccounts);
214 AccControl->SetPopupMaxHeight(175);
216 treAccounts->AssignImageList(AccImgList);
217 szrContactList->Insert(0, AccControl, 1, wxEXPAND|wxALL, 0);
218 szrAccList->Add(AccIcon, 0, wxLEFT|wxTOP|wxEXPAND, 3);
222 //szrContactList->Layout();
223 //szrContactList->RecalcSizes();
225 wxListItem ColumnData;
227 ColumnData.SetText(wxT("Name0"));
228 ColumnData.SetWidth(320);
229 lstContacts->InsertColumn(0, ColumnData);
231 //Connect(wxID_ANY, ContactConflictCmdEnv,
232 // ContactConflictEventHandler(frmMain::ConflictResolution), NULL, this);
234 //Connect(wxID_ANY, MyFooCommandEvent,
235 // MyFooEventHandler(frmMain::DoSomething), NULL, this);
237 //Bind(ContactConflictCmdEnv, ContactConflictEventHandler(frmMain::ConflictResolution), this, wxID_ANY);
239 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
240 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
242 #if defined(__HAIKU__)
244 #elif defined(__WIN32__)
246 int stbBottomData [4] = { -1, 8, 8, 8 };
250 int stbBottomData [4] = { -1, 20, 20, 20 };
254 stbBottom->SetFieldsCount(4, stbBottomData);
255 stbBottom->SetMinHeight(16);
260 stbBottom->GetFieldRect(1, rectOnline);
261 stbBottom->GetFieldRect(2, rectSSL);
262 stbBottom->GetFieldRect(3, rectActivity);
264 SSLToolTip = new wxToolTip(wxT(""));
266 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
267 imgConnStatus->SetBitmap(*imgOnline);
268 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
270 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
271 imgSSLStatus->SetBitmap(*imgNoSSL);
272 imgSSLStatus->SetToolTip(SSLToolTip);
273 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
275 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
276 imgActivityStatus->SetBitmap(*imgActIconSleep);
277 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
279 // Setup the window menu.
281 // By default should be:
286 // Contact editor windows:
292 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
293 mnuWindow->Append( mnuContactWindows );
295 mnuWindow->AppendSeparator();
297 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
298 mnuWindow->Append( mnuContactEditorWindows );
300 mnuWindow->AppendSeparator();
302 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
303 mnuWindow->Append( mnuSearchWindows );
305 #if defined(__WIN32__)
310 mnuContactWindows->SetFont(fontstyle);
311 mnuContactEditorWindows->SetFont(fontstyle);
312 mnuSearchWindows->SetFont(fontstyle);
316 mnuContactWindows->Enable(FALSE);
317 mnuContactEditorWindows->Enable(FALSE);
318 mnuSearchWindows->Enable(FALSE);
322 // Hide unimplemented functions.
328 void frmMain::QuitApp( wxCommandEvent& event )
330 //-------------------------------------------------------------------
331 // frmMain::QuitApp: Quits the application by simply closing this
332 // window which causes the exit as frmMain is the main window.
334 // wxCommandEvent Accepts a referenced event command.
335 //-------------------------------------------------------------------
337 //Go through the windows and close each one (be it search
338 //or contact editor). Abort if user wants to cancel.
340 // Close the contact editor windows.
342 // Close the contact windows.
344 // Close the search windows.
346 // Write out the ETag databases.
348 // Save Preferences: Save the window position if that option is enabled.
350 wxString SetFilename = GetUserPrefDir();
352 #if defined(__HAIKU__)
356 #elif defined(__WIN32__)
358 SetFilename.Append(wxT("settings"));
364 SetFilename.Append(wxT("settings"));
368 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
370 bool SaveWindowPos = FALSE;
371 wxString SaveWindowInc;
372 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
374 if (SaveWindowInc == wxT("true")){
376 SaveWindowPos = TRUE;
380 if (SaveWindowPos == TRUE){
382 wxRect frmMainPos = this->GetRect();
384 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
385 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
386 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
387 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
395 //Everything closed... exit.
401 void frmMain::QuitApp()
403 //-------------------------------------------------------------------
404 // frmMain::QuitApp: Quits the application by simply closing this
405 // window which causes the exit as frmMain is the main window.
407 // wxCommandEvent Accepts a referenced event command.
408 //-------------------------------------------------------------------
414 void frmMain::ShowActivityWindow( wxCommandEvent& event )
417 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
418 frameActMgr->OpenWindow();
423 void frmMain::ShowAboutWindow( wxCommandEvent& event )
425 //-------------------------------------------------------------------
426 // frmMain::ShowAboutWindow: Shows the About window as a modal
427 // dialog and then cleans up when finished.
429 // wxCommandEvent Accepts a referenced event command.
430 //-------------------------------------------------------------------
432 frmAbout *frameAbout = new frmAbout ( this );
433 frameAbout->SetupAboutWindow();
434 frameAbout->ShowModal();
440 void frmMain::OpenPreferences( wxCommandEvent& event)
442 //-------------------------------------------------------------------
443 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
444 // dialog and then cleans up when finished.
446 // wxCommandEvent Accepts a referenced event command.
447 //-------------------------------------------------------------------
449 ReloadAccounts = FALSE;
451 frmPreferences *framePreferences = new frmPreferences ( this );
452 framePreferences->SetupPointers(&ReloadAccounts);
453 framePreferences->ShowModal();
454 delete framePreferences;
455 framePreferences = NULL;
457 if (ReloadAccounts == TRUE){
459 // Reload the accounts as a change has been made within
462 this->LoadPreferences();
468 void frmMain::OpenNewABDialog( wxCommandEvent& event)
470 //-------------------------------------------------------------------
471 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
472 // dialog and then cleans up when finished.
474 // wxCommandEvent Accepts a referenced event command.
475 //-------------------------------------------------------------------
477 ReloadAccounts = FALSE;
479 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
480 frameNewAccount->SetupPointers(&ReloadAccounts);
481 frameNewAccount->ShowModal();
482 delete frameNewAccount;
483 frameNewAccount = NULL;
485 if (ReloadAccounts == TRUE){
487 // Reload the accounts as a change has been made within
490 this->LoadPreferences();
496 void frmMain::LoadContactList( wxTreeEvent& event )
499 // Clear all existing variables.
501 lstContacts->DeleteAllItems();
503 treAccounts->SetAccount();
505 wxTreeItemIdValue cookie;
506 wxTreeItemId next = treAccounts->GetRootItem();
507 wxString AccountName;
508 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
509 wxString AccountDirCmb;
510 long selectedaccount = 0;
512 wxTreeItemId selectedChild = treAccounts->GetSelection();
513 wxTreeItemId nextChild;
515 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
516 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
518 int SCImg = treAccounts->GetItemImage(selectedChild);
519 int AccountIndex = 0;
521 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
523 for (int i = 0; i < prefaccounts.GetCount(); i++){
525 if (ActiveItemIcon == 2){
527 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
528 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
529 int ActiveAccountG = AGLiter->second;
531 if (i == ActiveAccountG){
533 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
534 AccountType.Append(prefaccounts.GetAccountType(i));
539 if (AccountType == wxT("CardDAV")){
540 AccountTypeFinal.Append(wxT("carddav"));
542 else if (AccountType == wxT("Local")){
543 imgSSLStatus->SetBitmap(*imgOffline);
544 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
545 AccountTypeFinal.Append(wxT("local"));
556 nextChild = treAccounts->GetFirstChild(next, cookie);
559 nextChild = treAccounts->GetNextSibling(nextChild);
562 AccountName = treAccounts->GetItemText(nextChild);
564 if (nextChild == selectedChild){
565 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
566 AccountType.Append(prefaccounts.GetAccountType(i));
571 if (AccountType == wxT("CardDAV")){
572 AccountTypeFinal.Append(wxT("carddav"));
574 else if (AccountType == wxT("Local")){
575 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
576 AccountTypeFinal.Append(wxT("local"));
585 if (selectedaccount >= prefaccounts.GetCount()){
587 // The account selected isn't there so return.
595 // Open the directory and get the list of .vcf files
596 // in that directory.
598 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
599 ActiveAccountType = AccountType;
601 SetupSSLStatus(AccountIndex);
603 AccountDirFinal.Clear();
604 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
606 ContactsFileIndex.Clear();
608 //wxString vcardfilenamewxs;
609 wxString vCardFilename;
610 wxString vCardFilenameFull;
611 wxString vCardDataString;
612 wxStringTokenizer vcardfileline;
614 wxString setname, setvalue;
615 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
616 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
617 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
618 long ContactIndex = 1;
619 long ContactSeekPoint = 0;
621 wxDir vcardaccdir(AccountDirFinal);
623 // Get the wxTreeItemId and image icon and compare it to the list.
625 if (ActiveItemIcon == AccountGrpID){
627 // It's a group so load the file containing the group and
628 // get the members of the group.
633 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
634 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
635 //std::multimap<wxTreeItemId, int>::iterator AGFiter = AccountGroupTreeId.find(ActiveItemId);
637 Group.LoadFile(AGFiter->second);
639 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
641 for (int i = 0; i < vCardMember.PropCount; i++){
643 vCardMember.PropValues[i].Trim();
644 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
646 wxString NewPropValue;
647 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
648 vCardMember.PropValues[i] = NewPropValue;
655 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
658 if (vCardFilename.Right(4) == wxT(".vcf") ||
659 vCardFilename.Right(4) == wxT(".VCF") ||
660 vCardFilename.Right(5) == wxT(".vcard") ||
661 vCardFilename.Right(5) == wxT(".VCARD")){
664 bool FoundMember = FALSE;
666 vCardFilenameFull.Append(AccountDirFinal);
667 vCardFilenameFull.Append(wxT("/"));
668 vCardFilenameFull.Append(vCardFilename);
670 Person.LoadFile(vCardFilenameFull);
672 UIDCode = Person.Get(wxT("UID"));
674 for (int i = 0; i < vCardMember.PropCount; i++){
676 if (vCardMember.PropValues[i] == UIDCode){
684 if (FoundMember == FALSE){
686 vCardFilename.Clear();
687 vCardFilenameFull.Clear();
688 vCardDataString.Clear();
689 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
694 if (Person.MeetBaseSpecification()){
698 // Split the name into sections.
700 vCardDataString = Person.Get(wxT("N"));
702 vCardName NameData = Person.GetName();
704 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
706 } else if (SortMode == 2){
708 // Split the name into sections.
710 vCardName NameData = Person.GetName();
712 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
714 } else if (SortMode == 3){
716 // Check and make sure that the top most nickname is used.
718 vCardDataString = Person.Get(wxT("NICKNAME"));
720 if (vCardDataString.IsEmpty()){
722 vCardDataString = wxT("(no nickname)");
726 } else if (SortMode == 4){
728 vCardDataString = Person.Get(wxT("FN"));
732 if (AscendingMode == TRUE){
733 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
735 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
744 vCardFilename.Clear();
745 vCardFilenameFull.Clear();
746 vCardDataString.Clear();
747 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
752 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
755 if (vCardFilename.Right(4) == wxT(".vcf") ||
756 vCardFilename.Right(4) == wxT(".VCF") ||
757 vCardFilename.Right(5) == wxT(".vcard") ||
758 vCardFilename.Right(5) == wxT(".VCARD")){
762 vCardFilenameFull.Append(AccountDirFinal);
763 vCardFilenameFull.Append(vCardFilename);
765 Person.LoadFile(vCardFilenameFull);
767 if (Person.MeetBaseSpecification()){
771 // Split the name into sections.
773 vCardDataString = Person.Get(wxT("N"));
775 vCardName NameData = Person.GetName();
777 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
779 } else if (SortMode == 2){
781 // Split the name into sections.
783 vCardName NameData = Person.GetName();
785 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
787 } else if (SortMode == 3){
789 // Check and make sure that the top most nickname is used.
791 vCardDataString = Person.Get(wxT("NICKNAME"));
793 if (vCardDataString.IsEmpty()){
795 vCardDataString = wxT("(no nickname)");
799 } else if (SortMode == 4){
801 vCardDataString = Person.Get(wxT("FN"));
805 if (AscendingMode == TRUE){
806 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
808 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
817 vCardFilename.Clear();
818 vCardFilenameFull.Clear();
819 vCardDataString.Clear();
820 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
827 // Insert the data into the control.
829 if (AscendingMode == TRUE){
830 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
831 iter != vCardNamesAsc.end(); ++iter){
833 wxListItem ContactInfo;
835 ContactInfo.SetId(0);
836 ContactInfo.SetText(_("Mooo"));
837 ContactInfo.SetData(ContactSeekPoint);
838 ContactIndex = lstContacts->InsertItem(ContactInfo);
840 lstContacts->SetItem(ContactIndex, 0, iter->first);
841 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
848 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
849 iter != vCardNamesDsc.end(); ++iter){
851 wxListItem ContactInfo;
853 ContactInfo.SetId(0);
854 ContactInfo.SetText(_("Mooo"));
855 ContactInfo.SetData(ContactSeekPoint);
856 ContactIndex = lstContacts->InsertItem(ContactInfo);
858 lstContacts->SetItem(ContactIndex, 0, iter->first);
859 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
868 void frmMain::ShowContactInfo( wxListEvent& event )
871 long intSelected = -1;
872 long ContactSeekNum = -1;
874 // intSelected = lstContacts->GetSelection();
876 // Check if several contacts have been selected.
878 int ContactTotal = 0;
882 intSelected = lstContacts->GetNextItem(intSelected,
884 wxLIST_STATE_SELECTED);
886 if (intSelected == -1){
896 if (ContactTotal == 0){
897 htmContactData->SetPage(wxT(""));
901 if (ContactTotal > 1){
903 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
904 ActiveFilename.Clear();
909 intSelected = lstContacts->GetNextItem(intSelected,
911 wxLIST_STATE_SELECTED);
913 ContactSeekNum = lstContacts->GetItemData(intSelected);
916 wxString wxSContactString;
917 wxString ContactLine;
920 size_t ContactLineLen;
921 bool ExtraLineSeek = FALSE;
922 int QuoteBreakPoint = 0;
924 bool PropertyFind = FALSE;
925 bool QuoteMode = FALSE;
927 wxString wxSPropertyNextLine;
928 wxString wxSProperty;
929 wxString wxSPropertySeg1;
930 wxString wxSPropertySeg2;
932 // Check if we are using wxWidgets version 2.8 or less and
933 // execute the required command accordingly.
935 #if wxABI_VERSION < 20900
936 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
938 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
941 if (ContactFile.IsOpened() == FALSE){
947 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
951 std::map<int, wxString> ContactFileLines;
952 std::map<int, wxString>::iterator striter;
954 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
956 int ContactLineSeek = 0;
958 while (wSTContactFileLines.HasMoreTokens() == TRUE){
960 ContactLine = wSTContactFileLines.GetNextToken();
961 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
966 if (ContactSeekNum < 0){
970 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
971 iter != ContactFileLines.end(); ++iter){
973 // Find the colon which splits the start bit from the data part.
975 ContactLine = iter->second;
977 while (ExtraLineSeek == TRUE){
979 // Check if there is extra data on the next line
980 // (indicated by space or tab at the start) and add data.
984 if (iter == ContactFileLines.end()){
991 wxSPropertyNextLine = iter->second;
994 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
996 wxSPropertyNextLine.Remove(0, 1);
997 //wxSPropertyNextLine.Trim(FALSE);
998 //ContactLine.Trim();
999 ContactLine.Append(wxSPropertyNextLine);
1004 ExtraLineSeek = FALSE;
1010 ContactLineLen = ContactLine.Len();
1012 // Make sure we are not in quotation mode.
1013 // Make sure colon does not have \ or \\ before it.
1015 for (int i = 0; i <= ContactLineLen; i++){
1017 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1019 PropertyFind = FALSE;
1021 } else if (PropertyFind == TRUE){
1023 wxSProperty.Append(ContactLine.Mid(i, 1));
1027 if (ContactLine.Mid(i, 1) == wxT("\"")){
1029 if (QuoteMode == TRUE){
1041 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1043 QuoteBreakPoint = i;
1050 // Split that line at the point into two variables (ignore the colon).
1052 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1053 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1055 // Insert both into the vCard data file.
1057 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1060 PropertyFind = TRUE;
1061 ExtraLineSeek = TRUE;
1063 QuoteBreakPoint = 0;
1064 ContactLine.Clear();
1065 wxSProperty.Clear();
1069 OldSessionID = SessionID;
1070 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1071 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1072 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1076 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1079 // Check if there is an account selected and if not
1080 // return immediately.
1082 if (ActiveAccount.IsEmpty()){
1088 // Add Pointer to SetupPointers for the ETagDB.
1090 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1091 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1092 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1094 contacticon.CopyFromBitmap(contacticonbmp);
1096 frmContactEditor *ContactEditor = new frmContactEditor( this );
1100 ContactEditor->SetUID(WindowMenuItemID);
1102 WindowData *WData = new WindowData;
1104 WData->DataType = 1;
1105 WData->WindowPointer = (void*)ContactEditor;
1106 WData->WindowID = WindowMenuItemID;
1108 wxCommandEvent addevent(WINDOW_ADD);
1109 addevent.SetClientData(WData);
1110 wxPostEvent(this, addevent);
1112 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1113 ContactEditor->SetupHeaders();
1114 ContactEditor->SetupContact(ActiveAccount);
1115 ContactEditor->SetIcon(contacticon);
1116 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1117 ContactEditor->Show(true);
1121 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1124 // Check if there is an account selected and if not
1125 // return immediately.
1127 int DataCheck = event.GetInt();
1129 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1135 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1136 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1137 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1139 contacticon.CopyFromBitmap(contacticonbmp);
1141 // Check if a contact has been selected.
1143 long intSelected = -1;
1144 long intContactSeekNum = -1;
1146 // intSelected = lstContacts->GetSelection();
1148 intSelected = lstContacts->GetNextItem(intSelected,
1150 wxLIST_STATE_SELECTED);
1152 if (intSelected == -1){
1156 intContactSeekNum = lstContacts->GetItemData(intSelected);
1158 // Get the filename of the selected contact.
1160 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1161 frmContactEditor *ContactEditor = new frmContactEditor( this );
1165 ContactEditor->SetUID(WindowMenuItemID);
1167 WindowData *WData = new WindowData;
1169 WData->DataType = 1;
1170 WData->WindowPointer = (void*)ContactEditor;
1171 WData->WindowID = WindowMenuItemID;
1173 wxCommandEvent addevent(WINDOW_ADD);
1174 addevent.SetClientData(WData);
1175 wxPostEvent(this, addevent);
1177 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1178 ContactEditor->SetupHeaders();
1180 // Check if pointer is NULL (not from the search forms) or not.
1182 if (DataCheck == 0){
1184 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1185 ContactEditor->SetupContact(ActiveAccount);
1189 UCNotif *uc = (UCNotif*)event.GetClientData();
1193 ContactEditor->SetupContact(ActiveAccount);
1194 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1198 ContactEditor->SetupContact(uc->ContactAccount);
1199 ContactEditor->LoadContact(uc->ContactFilename);
1209 ContactEditor->SetIcon(contacticon);
1210 ContactEditor->Show(true);
1214 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1216 // Check if ActiveAccount is empty. If not then check if
1217 // account type is not local otherwise continue.
1219 if (!ActiveAccount.IsEmpty()){
1221 if (ActiveAccountType != wxT("Local")){
1223 // Account type is not local.
1225 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1226 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1227 wxT(""), wxT(""), wxT(""), wxT(""));
1231 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1239 void frmMain::OpenContactInfo( wxListEvent& event )
1242 wxStringTokenizer vcardfileline;
1245 wxString setname, setvalue;
1249 long intSelected = -1;
1250 long intContactSeekNum = -1;
1252 intSelected = lstContacts->GetNextItem(intSelected,
1254 wxLIST_STATE_SELECTED);
1256 intContactSeekNum = lstContacts->GetItemData(intSelected);
1258 if (intContactSeekNum == -1){
1262 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1264 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1265 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1266 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1268 contacticon.CopyFromBitmap(contacticonbmp);
1270 frmContact *Contact = new frmContact( this );
1272 // Add to window list.
1276 Contact->SetUID(WindowMenuItemID);
1278 WindowData *WData = new WindowData;
1280 WData->DataType = 0;
1281 WData->WindowPointer = (void*)Contact;
1282 WData->WindowID = WindowMenuItemID;
1284 wxCommandEvent addevent(WINDOW_ADD);
1285 addevent.SetClientData(WData);
1286 wxPostEvent(this, addevent);
1288 Contact->SetupPointers(&MemoryFileList);
1289 Contact->SetupContactData(&Person);
1291 Contact->SetIcon(contacticon);
1292 Contact->Show(true);
1296 void frmMain::OpenContactInfo( wxCommandEvent& event )
1299 UCNotif *uc = (UCNotif*)event.GetClientData();
1301 wxStringTokenizer vcardfileline;
1304 wxString setname, setvalue;
1307 //std::fstream vcardfile;
1309 Person.LoadFile(uc->ContactFilename);
1311 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1312 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1313 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1315 contacticon.CopyFromBitmap(contacticonbmp);
1317 frmContact *Contact = new frmContact( this );
1319 // Add to window list.
1323 Contact->SetUID(WindowMenuItemID);
1325 WindowData *WData = new WindowData;
1327 WData->DataType = 0;
1328 WData->WindowPointer = (void*)Contact;
1329 WData->WindowID = WindowMenuItemID;
1331 wxCommandEvent addevent(WINDOW_ADD);
1332 addevent.SetClientData(WData);
1333 wxPostEvent(this, addevent);
1335 Contact->SetupPointers(&MemoryFileList);
1336 Contact->SetupContactData(&Person);
1338 Contact->SetIcon(contacticon);
1339 Contact->Show(true);
1344 void frmMain::LoadPreferences( wxActivateEvent& event)
1346 this->LoadPreferences();
1349 void frmMain::LoadPreferences(){
1351 // Load the preferences.
1353 wxString preffilename = GetUserPrefDir();
1355 XABPreferences preferences(preffilename);
1357 // Setup the main window position (if needed).
1359 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1360 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1362 if (SaveWindowPos == TRUE){
1364 this->SetSize(preferences.GetMainWindowData());
1368 treAccounts->DeleteAllItems();
1370 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1372 // Stop all account timers and remove the accounts.
1374 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1375 iter != AccountSyncTimers.end(); iter++){
1377 wxAccountSyncTimer *AccTmrPtr = iter->second;
1385 AccountSyncTimers.clear();
1388 for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
1389 treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
1394 wxString AccDirFull;
1395 wxString AccDirFullSfx;
1397 wxString AccDirFinal;
1398 AccountAccDirList.clear();
1399 AccountGroupList.clear();
1400 AccountGroupFilename.clear();
1401 AccountGroupTreeId.clear();
1402 wxTreeItemId AccountTreeId;
1403 wxTreeItemId GroupTreeId;
1406 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1408 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1409 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1415 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1421 AccDir = preferences.accounts.GetAccountDirectory(i);
1422 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1424 AccDirFull.Append(wxT("."));
1425 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1426 AccDirFullSfx.LowerCase();
1427 AccDirFullSfx.Trim();
1428 AccDirFull.Append(AccDirFullSfx);
1429 AccName = preferences.accounts.GetAccountName(i);
1431 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1433 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1434 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1436 // Check if the directory exists before doing anything.
1440 // Add a new timer using the existing account details.
1442 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1444 ActTmrPtr->SetupData(AccDirFull, AccName);
1445 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1446 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1447 ActTmrPtr->SetOwner(this);
1448 ActTmrPtr->Notify();
1450 // Add the timer to the list of timers.
1452 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1454 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1458 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1462 // Go through the account directory and find contact files with
1463 // 'KIND:group' set and add them to the list of groups for the account.
1465 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1467 wxDir vcardaccdir(AccDirFinal);
1469 wxString vCardFilename;
1470 wxString vCardDataString;
1471 wxString vCardFilenameFull;
1472 //bool ProcFiles = FALSE;
1474 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1477 if (vCardFilename.Right(4) == wxT(".vcf") ||
1478 vCardFilename.Right(4) == wxT(".VCF") ||
1479 vCardFilename.Right(5) == wxT(".vcard") ||
1480 vCardFilename.Right(5) == wxT(".VCARD")){
1484 vCardFilenameFull.Append(AccDirFinal);
1485 vCardFilenameFull.Append(wxT("/"));
1486 vCardFilenameFull.Append(vCardFilename);
1488 Person.LoadFile(vCardFilenameFull);
1490 if (Person.MeetBaseSpecification()){
1492 vCardDataString = Person.Get(wxT("KIND"));
1494 if (vCardDataString == wxT("group")){
1496 // The vCard kind is a group. Add to the account's group list.
1498 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1499 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1500 AccountGroupList.insert(std::make_pair(intGroupID, i));
1501 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1502 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1514 vCardFilename.Clear();
1515 vCardFilenameFull.Clear();
1516 vCardDataString.Clear();
1517 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1521 // Clearup for next account.
1525 AccDirFullSfx.clear();
1526 AccDirFinal.clear();
1531 // Load the account settings as they are needed for connecting
1534 prefaccounts = preferences.accounts;
1538 void frmMain::ConflictResolution(wxCommandEvent& event){
1540 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1541 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1542 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1543 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1544 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1545 //wxString Moo = ClientDataPtr->WriteString();
1546 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1547 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1548 //frameCR->LoadData(vCardConfObj->vCardLocalData, vCardConfObj->vCardServerData, &MemoryFileList);
1549 frameCR->ShowModal();
1551 int FinalConflictResult = frameCR->GetResult();
1553 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1554 event2.SetClientData(vCardConfObj->QRNotifData);
1555 event2.SetInt(FinalConflictResult);
1560 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1561 wxPostEvent(frameActMgr, event2);
1565 void frmMain::UpdateContactList(wxCommandEvent& event){
1567 UCNotif *ucd = (UCNotif*)event.GetClientData();
1569 // Check if the active account is being displayed in the
1570 // main window. If not, skip and delete the data.
1572 long longSelected = -1;
1573 int intSelectedData = 0;
1575 if (ActiveAccount == ucd->ContactAccount){
1577 // Look at the list of contacts and if it matches the
1578 // filename then update the name.
1582 longSelected = lstContacts->GetNextItem(longSelected,
1584 wxLIST_STATE_DONTCARE);
1586 if (longSelected == -1){
1592 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1594 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1596 // Work out which sorting mode we are in.
1600 // First Name, Last Name.
1602 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1604 } else if (SortMode == 2){
1606 // Last Name, First Name.
1608 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1610 } else if (SortMode == 3){
1614 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1616 } else if (SortMode == 4){
1620 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1627 // If the filename is the one loaded into the
1628 // browser control, then update this too.
1630 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1632 wxListEvent nullevent;
1633 ShowContactInfo(nullevent);
1641 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1642 WindowIter != WindowListPointers.end(); WindowIter++){
1644 if (WindowListType[WindowIter->first] != 0){
1650 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1652 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1654 vCard UpdatedPerson;
1655 UpdatedPerson.LoadFile(ucd->ContactFilename);
1656 frmContactPtr->SetupContactData(&UpdatedPerson);
1662 // Send message to search window controller subroutine and
1663 // pass that notification onto the search windows.
1665 // Setup the new pointer to use the existing UCNotif without
1668 UCNotif *ucd2 = ucd;
1670 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1671 sup.SetClientData(ucd2);
1672 wxPostEvent(this, sup);
1674 // Clear up the unused pointer.
1680 void frmMain::UpdateAccountList(wxCommandEvent& event){
1684 void frmMain::SetupPointers(void *ActMgrPtrInc){
1686 ActMgrPtr = ActMgrPtrInc;
1690 void frmMain::SetupForm(){
1692 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1693 frameActMgr->SetupPointers(&ETagProcTimer, this);
1695 // Setup the contact information icons for later.
1697 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1701 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1702 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1703 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1705 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1706 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1707 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1709 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1710 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1711 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1713 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1714 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1715 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1717 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1718 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1719 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1721 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1722 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1723 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1729 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1731 // Go through each of the search windows and
1732 // send the required notification to update the
1733 // contact information.
1735 // Get the event notification data.
1737 UCNotif *ucd = (UCNotif*)event.GetClientData();
1739 // Process each search window giving the new details.
1741 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1742 switer != SearchWindowList.end(); switer++){
1744 // Duplicate the event notification data.
1746 UCNotif *ucd2 = new UCNotif;
1748 ucd2->ContactAccount = ucd->ContactAccount;
1749 ucd2->ContactFilename = ucd->ContactFilename;
1750 ucd2->ContactName = ucd->ContactName;
1751 ucd2->ContactNickname = ucd->ContactNickname;
1752 ucd2->ContactNameArray = ucd->ContactNameArray;
1754 // Pass the data to the search window for processing.
1756 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1757 wxCommandEvent schupdate(SE_UPDATERESULT);
1758 schupdate.SetClientData(ucd2);
1759 wxPostEvent(frameSCH, schupdate);
1761 // Clear up the pointer prior to variable deletion.
1772 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1776 frmSearch *frameSCH = new frmSearch ( this );
1777 frameSCH->SetUID(WindowMenuItemID);
1778 frameSCH->Show(true);
1780 WindowData *WData = new WindowData;
1782 WData->DataType = 2;
1783 WData->WindowPointer = (void*)frameSCH;
1784 WData->WindowID = WindowMenuItemID;
1786 wxCommandEvent addevent(WINDOW_ADD);
1787 addevent.SetClientData(WData);
1788 wxPostEvent(this, addevent);
1790 // Add pointer to the list of open search windows.
1792 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1798 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1800 //frmSearch *frameSCH = static_cast<frmSearch*>(ActMgrPtr);
1801 void *frameSCH = (void*)event.GetClientData();
1803 SearchWindowList.erase(frameSCH);
1809 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1811 void *frameSCH = (void*)event.GetClientData();
1813 SearchWindowList.erase(frameSCH);
1819 void frmMain::UpdateWindowList(wxCommandEvent& event){
1821 // Update the Window List.
1823 // Delete the existing items in the window menu.
1825 // Get the list of contacts.
1827 // Insert a separator.
1829 // Get the list of search windows.
1833 void frmMain::RevealContact(wxCommandEvent& event){
1835 UCNotif *uc = (UCNotif*)event.GetClientData();
1837 // Switch the account to the one passed.
1839 wxTreeItemIdValue cookie;
1840 wxTreeItemId next = treAccounts->GetRootItem();
1841 wxTreeItemId nextChild;
1843 for (int i = 0; i < prefaccounts.GetCount(); i++){
1846 nextChild = treAccounts->GetFirstChild(next, cookie);
1848 nextChild = treAccounts->GetNextSibling(nextChild);
1851 //AccountName = treAccounts->GetItemText(nextChild);
1853 if (uc->ContactAccount == AccountAccDirList[i]){
1856 treAccounts->SelectItem(nextChild, TRUE);
1857 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1863 // Switch the contact to the one passed.
1865 long longSelected = -1;
1866 int intSelectedData = 0;
1870 longSelected = lstContacts->GetNextItem(longSelected,
1872 wxLIST_STATE_DONTCARE);
1874 if (longSelected == -1){
1880 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1882 // Compare the filename with the one received.
1883 // If they match then select it.
1885 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1889 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1890 lstContacts->EnsureVisible(longSelected);
1894 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1902 void frmMain::DeleteContact(wxCommandEvent& event){
1904 // Check if a contact is selected.
1906 long intSelected = -1;
1907 long intContactSeekNum = -1;
1908 wxString wxSContactName;
1910 intSelected = lstContacts->GetNextItem(intSelected,
1912 wxLIST_STATE_SELECTED);
1914 if (intSelected == -1){
1918 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1920 // Get the item data of the contact.
1922 intContactSeekNum = lstContacts->GetItemData(intSelected);
1924 // Get the name of the contact.
1926 wxSContactName = lstContacts->GetItemText(intSelected);
1928 // Display a message confirming if the contact should
1931 int QuestionResponse;
1933 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1935 if (QuestionResponse == wxNO){
1937 // Exit the subroutine
1943 // Delete the contact.
1945 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1947 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1952 // Remove the contact from the list.
1954 lstContacts->DeleteItem(intSelected);
1956 // Update the search windows, removing the deleted
1959 UCNotif *ucd = new UCNotif;
1961 ucd->ContactAccount = ActiveAccount;
1962 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1964 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1965 switer != SearchWindowList.end(); switer++){
1967 // Duplicate the event notification data.
1969 UCNotif *ucd2 = new UCNotif;
1971 ucd2->ContactAccount = ucd->ContactAccount;
1972 ucd2->ContactFilename = ucd->ContactFilename;
1974 // Pass the data to the search window for processing.
1976 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1977 wxCommandEvent schdelete(SE_DELETERESULT);
1978 schdelete.SetClientData(ucd2);
1979 wxPostEvent(frameSCH, schdelete);
1981 // Clear up the pointer prior to variable deletion.
1988 // Clear the wxHTMLWindow.
1990 wxString EmptyPage = wxT("");
1992 htmContactData->SetPage(EmptyPage);
1994 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
1996 wxString wxSplitFilename;
1997 wxString wxSDataURL;
1999 while(wSTFilename.HasMoreTokens()){
2001 wxSplitFilename = wSTFilename.GetNextToken();
2005 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2007 // Update the ETagDB and mark it as deleted.
2009 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2011 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2013 // Get the Data URL.
2015 wxTreeItemIdValue cookie;
2016 wxTreeItemId next = treAccounts->GetRootItem();
2018 wxTreeItemId selectedChild = treAccounts->GetSelection();
2019 wxTreeItemId nextChild;
2021 for (int i = 0; i < prefaccounts.GetCount(); i++){
2024 nextChild = treAccounts->GetFirstChild(next, cookie);
2027 nextChild = treAccounts->GetNextSibling(nextChild);
2030 if (nextChild == selectedChild){
2031 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2037 // Add task to the activity monitor to delete the contact.
2039 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2043 // Clear the variable. Don't delete as it will mess things up.
2045 ContactsFileIndex[intContactSeekNum] = wxT("");
2052 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2054 QRNotif *qrn = (QRNotif *)event.GetClientData();
2056 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);
2058 if (QResponse == wxNO){
2064 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2065 event2.SetInt(*qrn->QResponse);
2066 event2.SetClientData(qrn->PausePtr);
2068 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2070 wxPostEvent(frameActMgr, event2);
2074 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2076 // Remove the contact from the window after syncronising.
2078 // Check which account is currently active in the window.
2079 // If it is different from the one passed to this subroutine then
2080 // exit from the subroutine.
2082 if (Account != ActiveAccount){
2086 long longSelected = -1;
2087 int intSelectedData = 0;
2091 longSelected = lstContacts->GetNextItem(longSelected,
2093 wxLIST_STATE_DONTCARE);
2095 if (longSelected == -1){
2101 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2103 // Compare the filename with the one received.
2104 // If they match then select it.
2106 if (ContactsFileIndex[intSelectedData] == Filename){
2108 // Remove the contact from the window.
2110 lstContacts->DeleteItem(intSelectedData);
2112 // Check if contact is the selected contact in the HTML window and
2113 // if it is then clear the window.
2115 if (ActiveFilename == Filename){
2117 wxString EmptyPage = wxT("");
2118 htmContactData->SetPage(EmptyPage);
2132 void frmMain::SortFNLN( wxCommandEvent& event ) {
2134 wxTreeEvent NullEvent;
2136 LoadContactList(NullEvent);
2140 void frmMain::SortLNFN( wxCommandEvent& event ) {
2142 wxTreeEvent NullEvent;
2144 LoadContactList(NullEvent);
2148 void frmMain::SortNickname( wxCommandEvent& event ) {
2150 wxTreeEvent NullEvent;
2152 LoadContactList(NullEvent);
2156 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2158 wxTreeEvent NullEvent;
2160 LoadContactList(NullEvent);
2164 void frmMain::SortAscending( wxCommandEvent& event ) {
2166 wxTreeEvent NullEvent;
2167 AscendingMode = TRUE;
2168 LoadContactList(NullEvent);
2172 void frmMain::SortDescending( wxCommandEvent& event ) {
2174 wxTreeEvent NullEvent;
2175 AscendingMode = FALSE;
2176 LoadContactList(NullEvent);
2180 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2182 if (stbBottom->IsShown() == TRUE){
2196 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2198 // Display the activity icon.
2200 imgActivityStatus->SetBitmap(*imgActIcon1);
2201 ActivityIconStatus = 0;
2205 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2207 switch (ActivityIconStatus){
2210 imgActivityStatus->SetBitmap(*imgActIcon1);
2211 ActivityIconStatus = 1;
2214 imgActivityStatus->SetBitmap(*imgActIcon2);
2215 ActivityIconStatus = 2;
2218 imgActivityStatus->SetBitmap(*imgActIcon3);
2219 ActivityIconStatus = 3;
2222 imgActivityStatus->SetBitmap(*imgActIcon4);
2223 ActivityIconStatus = 0;
2226 ActivityIconStatus = 0;
2232 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2234 // Display the sleep icon.
2236 imgActivityStatus->SetBitmap(*imgActIconSleep);
2240 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2242 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2250 wxRect rectActivity;
2251 stbBottom->GetFieldRect(1, rectOnline);
2252 stbBottom->GetFieldRect(2, rectSSL);
2253 stbBottom->GetFieldRect(3, rectActivity);
2255 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2256 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2257 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2261 XABViewMode frmMain::GetViewMode(){
2265 xvm.SortMode = SortMode;
2266 xvm.AscendingMode = AscendingMode;
2272 void frmMain::WindowAdd( wxCommandEvent &event ){
2274 WindowData *WData = (WindowData*)event.GetClientData();
2278 if (WData->DataType == 0){
2282 int intID = mnuContactWindows->GetId();
2284 mnuWindow->FindChildItem(intID, &pos);
2285 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact 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, 0));
2290 mnuWindow->Insert((pos + 1), mnuNewItem);
2291 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2293 } else if (WData->DataType == 1){
2295 // Contact Editor Window
2297 int intID = mnuContactEditorWindows->GetId();
2299 mnuWindow->FindChildItem(intID, &pos);
2300 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor 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, 1));
2305 mnuWindow->Insert((pos + 1), mnuNewItem);
2306 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2308 } else if (WData->DataType == 2){
2312 int intID = mnuSearchWindows->GetId();
2314 mnuWindow->FindChildItem(intID, &pos);
2315 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2316 mnuNewItem->SetId(WData->WindowID);
2317 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2318 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2319 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2320 mnuWindow->Insert((pos + 1), mnuNewItem);
2321 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2330 void frmMain::WindowEdit( wxCommandEvent &event ){
2332 WindowData *WData = (WindowData*)event.GetClientData();
2334 if (WData->DataType == 0){
2336 // Get the window title and use that.
2338 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2340 wxString WindowTitle = frmContactPtr->GetTitle();
2342 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2344 MenuIter->second->SetItemLabel(WindowTitle);
2346 //mnuWindow->FindChildItem(intID, &pos);
2347 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2348 //mnuNewItem->SetId(WData->WindowID);
2349 //ContactWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2350 //ContactWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2351 //mnuWindow->Insert((pos + 1), mnuNewItem);
2352 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2354 } else if (WData->DataType == 1){
2356 // Get the window title and use that.
2358 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2360 wxString WindowTitle = frmCEPtr->GetTitle();
2362 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2364 if (WindowTitle.IsEmpty()){
2366 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2370 MenuIter->second->SetItemLabel(WindowTitle);
2374 //mnuWindow->FindChildItem(intID, &pos);
2375 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2376 //mnuNewItem->SetId(WData->WindowID);
2377 //ContactEditorWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2378 //ContactEditorWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2379 //mnuWindow->Insert((pos + 1), mnuNewItem);
2380 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2389 void frmMain::WindowDelete( wxCommandEvent &event ){
2391 WindowData *WData = (WindowData*)event.GetClientData();
2393 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2395 mnuWindow->Remove(MenuIter->second);
2397 delete MenuIter->second;
2398 MenuIter->second = NULL;
2400 WindowListPointersMenu.erase(WData->WindowID);
2401 WindowListPointers.erase(WData->WindowID);
2402 WindowListType.erase(WData->WindowID);
2409 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2411 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2413 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2415 frmContactPtr->Show();
2416 frmContactPtr->Raise();
2420 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2422 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2424 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2431 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2433 // Look through the Search Window List Pointers, grab the
2434 // window point and show the window.
2436 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2438 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2440 frmSearchPtr->Show();
2441 frmSearchPtr->Raise();
2445 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2447 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2448 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2449 wxPostEvent(frameActMgr, toggconn);
2453 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2455 // Check the account type before continuing.
2457 wxString SeekAccount;
2458 wxString AccTypeLower;
2461 std::map<int, SSLCertCollection>::iterator SSLColIter;
2463 for (int i = 0; i < prefaccounts.GetCount(); i++){
2465 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2466 AccType.Append(prefaccounts.GetAccountType(i));
2467 AccountSSL = prefaccounts.GetAccountSSL(i);
2468 AccTypeLower = AccType.MakeLower();
2469 SeekAccount.Append(wxT("."));
2470 SeekAccount.Append(AccTypeLower);
2472 if (SeekAccount == ActiveAccount){
2474 if (AccTypeLower == wxT("local")){
2480 if (AccountSSL == false){
2486 SSLColIter = AccountSSLData.find(i);
2488 SSLCertCollection SSLCertInfo = SSLColIter->second;
2490 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2491 frameSSLCert->StartCertFrom(0);
2492 frameSSLCert->SetupCerts(SSLCertInfo);
2493 frameSSLCert->ShowModal();
2495 delete frameSSLCert;
2496 frameSSLCert = NULL;
2500 SeekAccount.Clear();
2501 AccTypeLower.Clear();
2508 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2510 // Check the account type before continuing.
2514 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2516 // Check the account type before continuing.
2520 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2522 if (event.GetInt() == 0){
2524 imgConnStatus->SetBitmap(*imgOnline);
2528 imgConnStatus->SetBitmap(*imgOffline);
2534 void frmMain::SetupSSLStatus( int AccountID ){
2536 // Check if account ID given is
2537 // the active account and if not, do nothing.
2540 wxString AccTypeLower;
2542 AccType = prefaccounts.GetAccountType(AccountID);
2543 AccTypeLower = AccType.MakeLower();
2545 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2548 if (AccountIDName != ActiveAccount){
2554 // Check if the account has SSL enabled.
2556 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2558 if (SSLInUse == FALSE){
2560 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2561 imgSSLStatus->SetBitmap(*imgNoSSL);
2565 // Get the SSL Collection Data.
2567 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2569 if (SSLResultIter->second == 1){
2571 imgSSLStatus->SetBitmap(*imgSSLWarning);
2572 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2573 prefaccounts.GetAccountName(AccountID) +
2574 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2577 } else if (SSLResultIter->second == 0){
2579 imgSSLStatus->SetBitmap(*imgSSL);
2580 SSLToolTip->SetTip(wxT("Account '") +
2581 prefaccounts.GetAccountName(AccountID) +
2582 wxT("' secured using SSL\n\nDouble click for more information."));
2590 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2592 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2593 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2594 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2595 wxString AccountName = SSLICNObj->AccountName;
2596 frameISC->LoadData(SSLCCData, AccountName);
2597 frameISC->ShowModal();
2599 int FinalConflictResult = frameISC->GetResult();
2601 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2602 event2.SetClientData(SSLICNObj->QRNotifData);
2603 event2.SetInt(FinalConflictResult);
2608 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2609 wxPostEvent(frameActMgr, event2);
2612 void frmMain::PauseAllTimers(){
2614 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2615 ASTiter != AccountSyncTimers.end(); ASTiter++){
2617 ASTiter->second->Stop();
2623 void frmMain::ResumeAllTimers(){
2625 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2626 ASTiter != AccountSyncTimers.end(); ASTiter++){
2628 ASTiter->second->Start();
2634 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2636 // Delete existing data.
2638 AccountSSLData.erase(AccountID);
2639 AccountSSLResult.erase(AccountID);
2643 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2644 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2648 void frmMain::CheckUpdates( wxCommandEvent& event ){
2650 frmUpdate *frameUpdate = new frmUpdate ( this );
2651 frameUpdate->FetchData();
2652 frameUpdate->ShowModal();
2656 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2658 // Run the import contacts system.
2664 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2666 // Check if an account and at least one contact is selected
2667 // before continuing.
2669 wxArrayString ArrData;
2671 if (ActiveAccount.IsEmpty()){
2677 int ContactSelected = 0;
2678 int ContactsCollected = 0;
2679 long longSelected = -1;
2683 longSelected = lstContacts->GetNextItem(longSelected,
2685 wxLIST_STATE_SELECTED);
2687 if (longSelected == -1){
2693 int FileID = (int)lstContacts->GetItemData(longSelected);
2695 ArrData.Insert(ContactsFileIndex[FileID],
2696 ContactsCollected, 1);
2702 if (ContactSelected == 0){
2708 // Run the export contacts system.
2710 ExportRun(this, &ArrData);
2714 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2715 wxArrayString *ContactsFileIndexPtr){
2717 lstContactsPtr = lstContacts;
2718 ContactsFileIndexPtr = &ContactsFileIndex;
2722 void frmMain::GetSelectedList( wxCommandEvent& event ){
2724 // Get the array of contact filenames.
2726 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2728 // Process them into an array of files.
2730 long longSelected = -1;
2731 int ContactsCollected = 0;
2732 wxString ContactFilename;
2736 longSelected = lstContacts->GetNextItem(longSelected,
2738 wxLIST_STATE_SELECTED);
2740 if (longSelected == -1){
2746 // Get the file information and add to the list.
2748 int FileID = (int)lstContacts->GetItemData(longSelected);
2750 ArrData->Insert(ContactsFileIndex[FileID],
2751 ContactsCollected, 1);
2753 ContactsCollected++;
2754 ContactFilename.Clear();
2762 void frmMain::SyncAccount( wxCommandEvent& event ){
2764 wxString *AccNameInc = (wxString*)event.GetClientData();
2766 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2767 frameActMgr->AddTask(3, wxT(""), *AccNameInc,
2768 wxT(""), wxT(""), wxT(""), wxT(""));
2772 void frmMain::ShowHelp( wxCommandEvent& event ){
2774 // Based on the operating system, work out where
2775 // the documentation should be.
2779 #if defined(__HAIKU__)
2781 #elif defined(__WIN32__)
2787 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2789 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2792 #if XSDAB_RELEASE == 0
2794 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2796 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2805 #if XSDAB_RELEASE == 0
2807 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2811 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!"));
2817 void frmMain::ShowImportResults( wxCommandEvent &event ){
2819 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2821 frmImportResults *frmIR = new frmImportResults(this);
2822 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());