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);
73 DEFINE_EVENT_TYPE(RELOADCONTACTLIST);
75 BEGIN_EVENT_TABLE(frmMain, wxFrame)
76 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmMain::ConflictResolution)
77 EVT_COMMAND(wxID_ANY, CE_UPDATECONTACTLIST, frmMain::UpdateContactList)
78 EVT_COMMAND(wxID_ANY, CE_UPDATEACCOUNTLIST, frmMain::UpdateAccountList)
79 EVT_COMMAND(wxID_ANY, SE_UPDATECONTACTNOTIF, frmMain::UpdateSearchContactLists)
80 EVT_COMMAND(wxID_ANY, CE_OPENCONTACT, frmMain::OpenContactInfo)
81 EVT_COMMAND(wxID_ANY, CE_EDITCONTACT, frmMain::ShowContactEditorEdit)
82 EVT_COMMAND(wxID_ANY, CE_REVEALCONTACT, frmMain::RevealContact)
83 EVT_COMMAND(wxID_ANY, CE_REMOVESEARCH, frmMain::RemoveContactsWindowPointer)
84 EVT_COMMAND(wxID_ANY, SYNC_EMPTYSERVER, frmMain::EmptyServerDialog)
85 EVT_COMMAND(wxID_ANY, ACTMGR_START, frmMain::ActivityIconStart)
86 EVT_COMMAND(wxID_ANY, ACTMGR_SHUFFLE, frmMain::ActivityIconShuffle)
87 EVT_COMMAND(wxID_ANY, ACTMGR_STOP, frmMain::ActivityIconStop)
88 EVT_COMMAND(wxID_ANY, WINDOW_ADD, frmMain::WindowAdd)
89 EVT_COMMAND(wxID_ANY, WINDOW_EDIT, frmMain::WindowEdit)
90 EVT_COMMAND(wxID_ANY, WINDOW_CLOSE, frmMain::WindowDelete)
91 EVT_COMMAND(wxID_ANY, CONNSTAT_UPDATE, frmMain::UpdateConnectionStatus)
92 EVT_COMMAND(wxID_ANY, INVALIDSSLCERT, frmMain::InvalidSSLCertificate)
93 EVT_COMMAND(wxID_ANY, GETSELECTEDLIST, frmMain::GetSelectedList)
94 EVT_COMMAND(wxID_ANY, SYNCACCOUNT, frmMain::SyncAccount)
95 EVT_COMMAND(wxID_ANY, IMPORT_RESULTSSHOW, frmMain::ShowImportResults)
96 EVT_COMMAND(wxID_ANY, RELOADCONTACTLIST, frmMain::ReloadContactList)
99 frmMain::frmMain( wxWindow* parent )
104 // Setup the account icons.
106 wxMemoryInputStream astream(icons_accinet_png, sizeof(icons_accinet_png));
107 wxMemoryInputStream bstream(icons_acclocal_png, sizeof(icons_acclocal_png));
108 wxMemoryInputStream cstream(icons_accgroup_png, sizeof(icons_accgroup_png));
109 wxMemoryInputStream dstream(icons_accnone_png, sizeof(icons_accnone_png));
111 wxImage icons_accinet_png(astream, wxBITMAP_TYPE_PNG);
112 wxBitmap AccInet(icons_accinet_png, -1);
114 wxIAccInet.CopyFromBitmap(AccInet);
116 wxImage icons_acclocal_png(bstream, wxBITMAP_TYPE_PNG);
117 wxBitmap AccNIcon(icons_acclocal_png, -1);
119 wxIAccNIcon.CopyFromBitmap(AccNIcon);
121 wxImage icons_accgroup_png(cstream, wxBITMAP_TYPE_PNG);
122 wxBitmap AccGrp(icons_accgroup_png, -1);
124 wxIAccGrp.CopyFromBitmap(AccGrp);
126 wxImage icons_accnone_png(dstream, wxBITMAP_TYPE_PNG);
127 wxBitmap AccNone(icons_accnone_png, -1);
129 wxIAccNone.CopyFromBitmap(AccNone);
131 AccountID = AccImgList->Add(wxIAccNIcon);
132 AccountNetID = AccImgList->Add(wxIAccInet);
133 AccountGrpID = AccImgList->Add(wxIAccGrp);
134 AccountNoneID = AccImgList->Add(wxIAccNone);
136 bmpIcon->SetIcon(AccImgList->GetIcon(AccountNoneID));
138 // Setup the status bar icons.
142 wxMemoryInputStream sslstream(icons_ssl_png, sizeof(icons_ssl_png));
143 wxMemoryInputStream sslwarningstream(icons_sslwarning_png, sizeof(icons_sslwarning_png));
144 wxMemoryInputStream nosslstream(icons_nossl_png, sizeof(icons_nossl_png));
146 wxImage icons_ssl_png(sslstream, wxBITMAP_TYPE_PNG);
147 imgSSL = new wxBitmap(icons_ssl_png, -1);
149 wxImage icons_sslwarning_png(sslwarningstream, wxBITMAP_TYPE_PNG);
150 imgSSLWarning = new wxBitmap(icons_sslwarning_png, -1);
152 wxImage icons_nossl_png(nosslstream, wxBITMAP_TYPE_PNG);
153 imgNoSSL = new wxBitmap(icons_nossl_png, -1);
157 wxMemoryInputStream act1(icons_act1_png, sizeof(icons_act1_png));
158 wxMemoryInputStream act2(icons_act2_png, sizeof(icons_act2_png));
159 wxMemoryInputStream act3(icons_act3_png, sizeof(icons_act3_png));
160 wxMemoryInputStream act4(icons_act4_png, sizeof(icons_act4_png));
161 wxMemoryInputStream actsleep(icons_actsleep_png, sizeof(icons_actsleep_png));
163 wxImage icons_actsleep_png(actsleep, wxBITMAP_TYPE_PNG);
164 imgActIconSleep = new wxBitmap (icons_actsleep_png, -1);
166 wxImage icons_act1_png(act1, wxBITMAP_TYPE_PNG);
167 imgActIcon1 = new wxBitmap (icons_act1_png, -1);
169 wxIAct1icon.CopyFromBitmap(*imgActIcon1);
171 wxImage icons_act2_png(act2, wxBITMAP_TYPE_PNG);
172 imgActIcon2 = new wxBitmap (icons_act2_png, -1);
174 wxIAct2icon.CopyFromBitmap(*imgActIcon2);
176 wxImage icons_act3_png(act3, wxBITMAP_TYPE_PNG);
177 imgActIcon3 = new wxBitmap (icons_act3_png, -1);
179 wxIAct3icon.CopyFromBitmap(*imgActIcon3);
181 wxImage icons_act4_png(act4, wxBITMAP_TYPE_PNG);
182 imgActIcon4 = new wxBitmap (icons_act4_png, -1);
184 wxIAct4icon.CopyFromBitmap(*imgActIcon4);
186 // Online/Offline icons.
188 wxMemoryInputStream onlinestream(icons_online_png, sizeof(icons_online_png));
189 wxMemoryInputStream offlinestream(icons_offline_png, sizeof(icons_offline_png));
191 wxImage icons_online_png(onlinestream, wxBITMAP_TYPE_PNG);
192 imgOnline = new wxBitmap(icons_online_png, -1);
194 wxImage icons_offline_png(offlinestream, wxBITMAP_TYPE_PNG);
195 imgOffline = new wxBitmap(icons_offline_png, -1);
197 // Setup the account view.
199 AccCtrl->SetPopupControl(treAccounts);
200 AccCtrl->SetPopupMaxHeight(175);
201 AccCtrl->SetPopupMinWidth(250);
202 treAccounts->AssignImageList(AccImgList);
205 /*wxStaticBitmap* BeepBoop = new wxStaticBitmap(AccCtrl, wxID_ANY, wxNullBitmap, wxPoint(AccTextCtrlSize.GetX() + 3, AccTextCtrlSize.GetY() + 2), wxDefaultSize, 0);
207 icons_accgroup_png.SetMask(new wxMask(icons_accgroup_png, wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND)));
209 BeepBoop->SetBackgroundColour(AccCtrl->GetBackgroundColour());
210 BeepBoop->SetBitmap(icons_accgroup_png);*/
212 //szrContactList->Insert(0, XABV2, 1, wxEXPAND | wxALL, 0);
214 /*AccControl->UseAltPopupWindow();
215 AccControl->SetPopupControl(treAccounts);
216 AccControl->SetPopupMaxHeight(175);
218 treAccounts->AssignImageList(AccImgList);
219 szrContactList->Insert(0, AccControl, 1, wxEXPAND|wxALL, 0);
220 szrAccList->Add(AccIcon, 0, wxLEFT|wxTOP|wxEXPAND, 3);
224 //szrContactList->Layout();
225 //szrContactList->RecalcSizes();
227 wxListItem ColumnData;
229 ColumnData.SetText(wxT("Name0"));
230 ColumnData.SetWidth(320);
231 lstContacts->InsertColumn(0, ColumnData);
233 //Connect(wxID_ANY, ContactConflictCmdEnv,
234 // ContactConflictEventHandler(frmMain::ConflictResolution), NULL, this);
236 //Connect(wxID_ANY, MyFooCommandEvent,
237 // MyFooEventHandler(frmMain::DoSomething), NULL, this);
239 //Bind(ContactConflictCmdEnv, ContactConflictEventHandler(frmMain::ConflictResolution), this, wxID_ANY);
241 treAccounts->Connect(wxEVT_LEFT_DCLICK, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
242 treAccounts->Connect(wxEVT_TREE_SEL_CHANGED, wxTreeEventHandler(frmMain::LoadContactList), NULL, this);
244 #if defined(__HAIKU__)
246 #elif defined(__WIN32__)
248 int stbBottomData [4] = { -1, 8, 8, 8 };
252 int stbBottomData [4] = { -1, 20, 20, 20 };
256 stbBottom->SetFieldsCount(4, stbBottomData);
257 stbBottom->SetMinHeight(16);
262 stbBottom->GetFieldRect(1, rectOnline);
263 stbBottom->GetFieldRect(2, rectSSL);
264 stbBottom->GetFieldRect(3, rectActivity);
266 SSLToolTip = new wxToolTip(wxT(""));
268 imgConnStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectOnline.GetX()),(rectOnline.GetY())), wxDefaultSize, 0 );
269 imgConnStatus->SetBitmap(*imgOnline);
270 imgConnStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ToggleConnectionStatus ), NULL, this );
272 imgSSLStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectSSL.GetX()),(rectSSL.GetY())), wxDefaultSize, 0 );
273 imgSSLStatus->SetBitmap(*imgNoSSL);
274 imgSSLStatus->SetToolTip(SSLToolTip);
275 imgSSLStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowSSLCertificates ), NULL, this );
277 imgActivityStatus = new wxStaticBitmap(stbBottom, wxID_ANY, wxNullBitmap, wxPoint((rectActivity.GetX()),(rectActivity.GetY())), wxDefaultSize, 0);
278 imgActivityStatus->SetBitmap(*imgActIconSleep);
279 imgActivityStatus->Connect( wxEVT_LEFT_DCLICK, wxCommandEventHandler( frmMain::ShowActivityWindow ), NULL, this );
281 // Setup the window menu.
283 // By default should be:
288 // Contact editor windows:
294 mnuContactWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact windows:") ), wxEmptyString, wxITEM_NORMAL );
295 mnuWindow->Append( mnuContactWindows );
297 mnuWindow->AppendSeparator();
299 mnuContactEditorWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( _("Contact editor windows:") ), wxEmptyString, wxITEM_NORMAL );
300 mnuWindow->Append( mnuContactEditorWindows );
302 mnuWindow->AppendSeparator();
304 mnuSearchWindows = new wxMenuItem( mnuManage, wxID_ANY, wxString( wxT("Search windows:") ), wxEmptyString, wxITEM_NORMAL );
305 mnuWindow->Append( mnuSearchWindows );
307 #if defined(__WIN32__)
312 mnuContactWindows->SetFont(fontstyle);
313 mnuContactEditorWindows->SetFont(fontstyle);
314 mnuSearchWindows->SetFont(fontstyle);
318 mnuContactWindows->Enable(FALSE);
319 mnuContactEditorWindows->Enable(FALSE);
320 mnuSearchWindows->Enable(FALSE);
324 // Hide unimplemented functions.
330 void frmMain::QuitApp( wxCommandEvent& event )
332 //-------------------------------------------------------------------
333 // frmMain::QuitApp: Quits the application by simply closing this
334 // window which causes the exit as frmMain is the main window.
336 // wxCommandEvent Accepts a referenced event command.
337 //-------------------------------------------------------------------
339 //Go through the windows and close each one (be it search
340 //or contact editor). Abort if user wants to cancel.
342 // Close the contact editor windows.
344 // Close the contact windows.
346 // Close the search windows.
348 // Write out the ETag databases.
350 // Save Preferences: Save the window position if that option is enabled.
352 wxString SetFilename = GetUserPrefDir();
354 #if defined(__HAIKU__)
358 #elif defined(__WIN32__)
360 SetFilename.Append(wxT("settings"));
366 SetFilename.Append(wxT("settings"));
370 wxFileConfig *cfgfile = new wxFileConfig("", "", SetFilename);
372 bool SaveWindowPos = FALSE;
373 wxString SaveWindowInc;
374 cfgfile->Read(wxT("SaveWindowPosition"), &SaveWindowInc);
376 if (SaveWindowInc == wxT("true")){
378 SaveWindowPos = TRUE;
382 if (SaveWindowPos == TRUE){
384 wxRect frmMainPos = this->GetRect();
386 cfgfile->Write(wxT("WindowPositionX"), frmMainPos.GetX());
387 cfgfile->Write(wxT("WindowPositionY"), frmMainPos.GetY());
388 cfgfile->Write(wxT("WindowPositionHeight"), frmMainPos.GetHeight());
389 cfgfile->Write(wxT("WindowPositionWidth"), frmMainPos.GetWidth());
397 //Everything closed... exit.
403 void frmMain::QuitApp()
405 //-------------------------------------------------------------------
406 // frmMain::QuitApp: Quits the application by simply closing this
407 // window which causes the exit as frmMain is the main window.
409 // wxCommandEvent Accepts a referenced event command.
410 //-------------------------------------------------------------------
416 void frmMain::ShowActivityWindow( wxCommandEvent& event )
419 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
420 frameActMgr->OpenWindow();
425 void frmMain::ShowAboutWindow( wxCommandEvent& event )
427 //-------------------------------------------------------------------
428 // frmMain::ShowAboutWindow: Shows the About window as a modal
429 // dialog and then cleans up when finished.
431 // wxCommandEvent Accepts a referenced event command.
432 //-------------------------------------------------------------------
434 frmAbout *frameAbout = new frmAbout ( this );
435 frameAbout->SetupAboutWindow();
436 frameAbout->ShowModal();
442 void frmMain::OpenPreferences( wxCommandEvent& event)
444 //-------------------------------------------------------------------
445 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
446 // dialog and then cleans up when finished.
448 // wxCommandEvent Accepts a referenced event command.
449 //-------------------------------------------------------------------
451 ReloadAccounts = FALSE;
453 frmPreferences *framePreferences = new frmPreferences ( this );
454 framePreferences->SetupPointers(&ReloadAccounts);
455 framePreferences->ShowModal();
456 delete framePreferences;
457 framePreferences = NULL;
459 if (ReloadAccounts == TRUE){
461 // Reload the accounts as a change has been made within
464 this->LoadPreferences();
470 void frmMain::OpenNewABDialog( wxCommandEvent& event)
472 //-------------------------------------------------------------------
473 // frmMain::ShowAboutWindow: Opens the Preferences window as a modal
474 // dialog and then cleans up when finished.
476 // wxCommandEvent Accepts a referenced event command.
477 //-------------------------------------------------------------------
479 ReloadAccounts = FALSE;
481 frmNewAccount *frameNewAccount = new frmNewAccount ( this );
482 frameNewAccount->SetupPointers(&ReloadAccounts);
483 frameNewAccount->ShowModal();
484 delete frameNewAccount;
485 frameNewAccount = NULL;
487 if (ReloadAccounts == TRUE){
489 // Reload the accounts as a change has been made within
492 this->LoadPreferences();
498 void frmMain::LoadContactList( wxTreeEvent& event )
501 // Clear all existing variables.
503 lstContacts->DeleteAllItems();
505 treAccounts->SetAccount();
507 wxTreeItemIdValue cookie;
508 wxTreeItemId next = treAccounts->GetRootItem();
509 wxString AccountName;
510 wxString AccountDir, AccountType, AccountDirFinal, AccountTypeFinal;
511 wxString AccountDirCmb;
512 long selectedaccount = 0;
514 wxTreeItemId selectedChild = treAccounts->GetSelection();
515 wxTreeItemId nextChild;
517 wxTreeItemId ActiveItemId = treAccounts->GetFocusedItem();
518 int ActiveItemIcon = treAccounts->GetItemImage(ActiveItemId, wxTreeItemIcon_Normal);
520 int SCImg = treAccounts->GetItemImage(selectedChild);
521 int AccountIndex = 0;
523 bmpIcon->SetIcon(AccImgList->GetIcon(SCImg));
525 for (int i = 0; i < prefaccounts.GetCount(); i++){
527 if (ActiveItemIcon == 2){
529 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
530 std::multimap<int, int>::iterator AGLiter = AccountGroupList.find(AGTiter->second);
531 int ActiveAccountG = AGLiter->second;
533 if (i == ActiveAccountG){
535 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
536 AccountType.Append(prefaccounts.GetAccountType(i));
541 if (AccountType == wxT("CardDAV")){
542 AccountTypeFinal.Append(wxT("carddav"));
544 else if (AccountType == wxT("Local")){
545 imgSSLStatus->SetBitmap(*imgOffline);
546 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
547 AccountTypeFinal.Append(wxT("local"));
558 nextChild = treAccounts->GetFirstChild(next, cookie);
561 nextChild = treAccounts->GetNextSibling(nextChild);
564 AccountName = treAccounts->GetItemText(nextChild);
566 if (nextChild == selectedChild){
567 AccountDir.Append(prefaccounts.GetAccountDirectory(i));
568 AccountType.Append(prefaccounts.GetAccountType(i));
573 if (AccountType == wxT("CardDAV")){
574 AccountTypeFinal.Append(wxT("carddav"));
576 else if (AccountType == wxT("Local")){
577 SSLToolTip->SetTip(wxT("SSL status is not applicable for this account"));
578 AccountTypeFinal.Append(wxT("local"));
587 if (selectedaccount >= prefaccounts.GetCount()){
589 // The account selected isn't there so return.
597 // Open the directory and get the list of .vcf files
598 // in that directory.
600 ActiveAccount = AccountDir + wxT(".") + AccountTypeFinal;
601 ActiveAccountType = AccountType;
603 SetupSSLStatus(AccountIndex);
605 AccountDirFinal.Clear();
606 AccountDirFinal = GetAccountDir(AccountDir + wxT(".") + AccountTypeFinal, FALSE);
608 ContactsFileIndex.Clear();
610 //wxString vcardfilenamewxs;
611 wxString vCardFilename;
612 wxString vCardFilenameFull;
613 wxString vCardDataString;
614 wxStringTokenizer vcardfileline;
616 wxString setname, setvalue;
617 //vCardNames = new std::map<wxString, wxString, std::greater<wxString>>;
618 std::multimap<wxString, wxString, std::greater<wxString>> vCardNamesAsc;
619 std::multimap<wxString, wxString, std::less<wxString>> vCardNamesDsc;
620 long ContactIndex = 1;
621 long ContactSeekPoint = 0;
623 wxDir vcardaccdir(AccountDirFinal);
625 // Get the wxTreeItemId and image icon and compare it to the list.
627 if (ActiveItemIcon == AccountGrpID){
629 // It's a group so load the file containing the group and
630 // get the members of the group.
635 std::multimap<wxTreeItemId, int>::iterator AGTiter = AccountGroupTreeId.find(ActiveItemId);
636 std::multimap<int, wxString>::iterator AGFiter = AccountGroupFilename.find(AGTiter->second);
637 //std::multimap<wxTreeItemId, int>::iterator AGFiter = AccountGroupTreeId.find(ActiveItemId);
639 Group.LoadFile(AGFiter->second);
641 ArrayvCardOutData vCardMember = Group.GetByPartial(wxT("MEMBER"));
643 for (int i = 0; i < vCardMember.PropCount; i++){
645 vCardMember.PropValues[i].Trim();
646 if (vCardMember.PropValues[i].Left(9) == wxT("urn:uuid:")){
648 wxString NewPropValue;
649 NewPropValue = vCardMember.PropValues[i].Mid(9, wxString::npos);
650 vCardMember.PropValues[i] = NewPropValue;
657 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
660 if (vCardFilename.Right(4) == wxT(".vcf") ||
661 vCardFilename.Right(4) == wxT(".VCF") ||
662 vCardFilename.Right(5) == wxT(".vcard") ||
663 vCardFilename.Right(5) == wxT(".VCARD")){
666 bool FoundMember = FALSE;
668 vCardFilenameFull.Append(AccountDirFinal);
669 vCardFilenameFull.Append(wxT("/"));
670 vCardFilenameFull.Append(vCardFilename);
672 Person.LoadFile(vCardFilenameFull);
674 UIDCode = Person.Get(wxT("UID"));
676 for (int i = 0; i < vCardMember.PropCount; i++){
678 if (vCardMember.PropValues[i] == UIDCode){
686 if (FoundMember == FALSE){
688 vCardFilename.Clear();
689 vCardFilenameFull.Clear();
690 vCardDataString.Clear();
691 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
696 if (Person.MeetBaseSpecification()){
700 // Split the name into sections.
702 vCardDataString = Person.Get(wxT("N"));
704 vCardName NameData = Person.GetName();
706 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
708 } else if (SortMode == 2){
710 // Split the name into sections.
712 vCardName NameData = Person.GetName();
714 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
716 } else if (SortMode == 3){
718 // Check and make sure that the top most nickname is used.
720 vCardDataString = Person.Get(wxT("NICKNAME"));
722 if (vCardDataString.IsEmpty()){
724 vCardDataString = wxT("(no nickname)");
728 } else if (SortMode == 4){
730 vCardDataString = Person.Get(wxT("FN"));
734 if (AscendingMode == TRUE){
735 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
737 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
746 vCardFilename.Clear();
747 vCardFilenameFull.Clear();
748 vCardDataString.Clear();
749 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
754 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
757 if (vCardFilename.Right(4) == wxT(".vcf") ||
758 vCardFilename.Right(4) == wxT(".VCF") ||
759 vCardFilename.Right(5) == wxT(".vcard") ||
760 vCardFilename.Right(5) == wxT(".VCARD")){
764 vCardFilenameFull.Append(AccountDirFinal);
765 vCardFilenameFull.Append(vCardFilename);
767 Person.LoadFile(vCardFilenameFull);
769 if (Person.MeetBaseSpecification()){
773 // Split the name into sections.
775 vCardDataString = Person.Get(wxT("N"));
777 vCardName NameData = Person.GetName();
779 vCardDataString = NameData.Forename + wxT(" ") + NameData.Surname;
781 } else if (SortMode == 2){
783 // Split the name into sections.
785 vCardName NameData = Person.GetName();
787 vCardDataString = NameData.Surname + wxT(", ") + NameData.Forename;
789 } else if (SortMode == 3){
791 // Check and make sure that the top most nickname is used.
793 vCardDataString = Person.Get(wxT("NICKNAME"));
795 if (vCardDataString.IsEmpty()){
797 vCardDataString = wxT("(no nickname)");
801 } else if (SortMode == 4){
803 vCardDataString = Person.Get(wxT("FN"));
807 if (AscendingMode == TRUE){
808 vCardNamesAsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
810 vCardNamesDsc.insert(std::make_pair(vCardDataString, vCardFilenameFull));
819 vCardFilename.Clear();
820 vCardFilenameFull.Clear();
821 vCardDataString.Clear();
822 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
829 // Insert the data into the control.
831 if (AscendingMode == TRUE){
832 for (std::map<wxString, wxString>::iterator iter = vCardNamesAsc.begin();
833 iter != vCardNamesAsc.end(); ++iter){
835 wxListItem ContactInfo;
837 ContactInfo.SetId(0);
838 ContactInfo.SetText(_("Mooo"));
839 ContactInfo.SetData(ContactSeekPoint);
840 ContactIndex = lstContacts->InsertItem(ContactInfo);
842 lstContacts->SetItem(ContactIndex, 0, iter->first);
843 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
850 for (std::map<wxString, wxString>::iterator iter = vCardNamesDsc.begin();
851 iter != vCardNamesDsc.end(); ++iter){
853 wxListItem ContactInfo;
855 ContactInfo.SetId(0);
856 ContactInfo.SetText(_("Mooo"));
857 ContactInfo.SetData(ContactSeekPoint);
858 ContactIndex = lstContacts->InsertItem(ContactInfo);
860 lstContacts->SetItem(ContactIndex, 0, iter->first);
861 ContactsFileIndex.Insert(iter->second, ContactSeekPoint);
870 void frmMain::ShowContactInfo( wxListEvent& event )
873 long intSelected = -1;
874 long ContactSeekNum = -1;
876 // intSelected = lstContacts->GetSelection();
878 // Check if several contacts have been selected.
880 int ContactTotal = 0;
884 intSelected = lstContacts->GetNextItem(intSelected,
886 wxLIST_STATE_SELECTED);
888 if (intSelected == -1){
898 if (ContactTotal == 0){
899 htmContactData->SetPage(wxT(""));
903 if (ContactTotal > 1){
905 htmContactData->SetPage(wxString::Format(wxT("%i contacts selected."), ContactTotal));
906 ActiveFilename.Clear();
911 intSelected = lstContacts->GetNextItem(intSelected,
913 wxLIST_STATE_SELECTED);
915 ContactSeekNum = lstContacts->GetItemData(intSelected);
918 wxString wxSContactString;
919 wxString ContactLine;
922 size_t ContactLineLen;
923 bool ExtraLineSeek = FALSE;
924 int QuoteBreakPoint = 0;
926 bool PropertyFind = FALSE;
927 bool QuoteMode = FALSE;
929 wxString wxSPropertyNextLine;
930 wxString wxSProperty;
931 wxString wxSPropertySeg1;
932 wxString wxSPropertySeg2;
934 // Check if we are using wxWidgets version 2.8 or less and
935 // execute the required command accordingly.
937 #if wxABI_VERSION < 20900
938 ContactFile.Open(ContactsFileIndex[ContactSeekNum].c_str(), wxT("r"));
940 ContactFile.Open(ContactsFileIndex[ContactSeekNum], wxT("r"));
943 if (ContactFile.IsOpened() == FALSE){
949 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
953 std::map<int, wxString> ContactFileLines;
954 std::map<int, wxString>::iterator striter;
956 wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
958 int ContactLineSeek = 0;
960 while (wSTContactFileLines.HasMoreTokens() == TRUE){
962 ContactLine = wSTContactFileLines.GetNextToken();
963 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
968 if (ContactSeekNum < 0){
972 for (std::map<int, wxString>::iterator iter = ContactFileLines.begin();
973 iter != ContactFileLines.end(); ++iter){
975 // Find the colon which splits the start bit from the data part.
977 ContactLine = iter->second;
979 while (ExtraLineSeek == TRUE){
981 // Check if there is extra data on the next line
982 // (indicated by space or tab at the start) and add data.
986 if (iter == ContactFileLines.end()){
993 wxSPropertyNextLine = iter->second;
996 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
998 wxSPropertyNextLine.Remove(0, 1);
999 //wxSPropertyNextLine.Trim(FALSE);
1000 //ContactLine.Trim();
1001 ContactLine.Append(wxSPropertyNextLine);
1006 ExtraLineSeek = FALSE;
1012 ContactLineLen = ContactLine.Len();
1014 // Make sure we are not in quotation mode.
1015 // Make sure colon does not have \ or \\ before it.
1017 for (int i = 0; i <= ContactLineLen; i++){
1019 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
1021 PropertyFind = FALSE;
1023 } else if (PropertyFind == TRUE){
1025 wxSProperty.Append(ContactLine.Mid(i, 1));
1029 if (ContactLine.Mid(i, 1) == wxT("\"")){
1031 if (QuoteMode == TRUE){
1043 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
1045 QuoteBreakPoint = i;
1052 // Split that line at the point into two variables (ignore the colon).
1054 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
1055 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
1057 // Insert both into the vCard data file.
1059 Person.AddRaw(wxSPropertySeg1, wxSPropertySeg2);
1062 PropertyFind = TRUE;
1063 ExtraLineSeek = TRUE;
1065 QuoteBreakPoint = 0;
1066 ContactLine.Clear();
1067 wxSProperty.Clear();
1071 OldSessionID = SessionID;
1072 SessionID = wxString::Format(wxT("%i"), rand() % 32768);
1073 LoadContactData(&Person, htmContactData, SessionID, OldSessionID, &MemoryFileList);
1074 ActiveFilename = ContactsFileIndex[ContactSeekNum];
1078 void frmMain::ShowContactEditorNew( wxCommandEvent& event )
1081 // Check if there is an account selected and if not
1082 // return immediately.
1084 if (ActiveAccount.IsEmpty()){
1090 // Add Pointer to SetupPointers for the ETagDB.
1092 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1093 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1094 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1096 contacticon.CopyFromBitmap(contacticonbmp);
1098 frmContactEditor *ContactEditor = new frmContactEditor( this );
1102 ContactEditor->SetUID(WindowMenuItemID);
1104 WindowData *WData = new WindowData;
1106 WData->DataType = 1;
1107 WData->WindowPointer = (void*)ContactEditor;
1108 WData->WindowID = WindowMenuItemID;
1110 wxCommandEvent addevent(WINDOW_ADD);
1111 addevent.SetClientData(WData);
1112 wxPostEvent(this, addevent);
1114 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1115 ContactEditor->SetupHeaders();
1116 ContactEditor->SetupContact(ActiveAccount);
1117 ContactEditor->SetIcon(contacticon);
1118 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1119 ContactEditor->Show(true);
1123 void frmMain::ShowContactEditorEdit( wxCommandEvent& event )
1126 // Check if there is an account selected and if not
1127 // return immediately.
1129 int DataCheck = event.GetInt();
1131 if (ActiveAccount.IsEmpty() && DataCheck == 0){
1137 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1138 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1139 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1141 contacticon.CopyFromBitmap(contacticonbmp);
1143 // Check if a contact has been selected.
1145 long intSelected = -1;
1146 long intContactSeekNum = -1;
1148 // intSelected = lstContacts->GetSelection();
1150 intSelected = lstContacts->GetNextItem(intSelected,
1152 wxLIST_STATE_SELECTED);
1154 if (intSelected == -1){
1158 intContactSeekNum = lstContacts->GetItemData(intSelected);
1160 // Get the filename of the selected contact.
1162 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1163 frmContactEditor *ContactEditor = new frmContactEditor( this );
1167 ContactEditor->SetUID(WindowMenuItemID);
1169 WindowData *WData = new WindowData;
1171 WData->DataType = 1;
1172 WData->WindowPointer = (void*)ContactEditor;
1173 WData->WindowID = WindowMenuItemID;
1175 wxCommandEvent addevent(WINDOW_ADD);
1176 addevent.SetClientData(WData);
1177 wxPostEvent(this, addevent);
1179 ContactEditor->SetupPointers(frameActMgr, &ETagProcTimer, this);
1180 ContactEditor->SetupHeaders();
1182 // Check if pointer is NULL (not from the search forms) or not.
1184 if (DataCheck == 0){
1186 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1187 ContactEditor->SetupContact(ActiveAccount);
1191 UCNotif *uc = (UCNotif*)event.GetClientData();
1195 ContactEditor->SetupContact(ActiveAccount);
1196 ContactEditor->LoadContact(ContactsFileIndex[intContactSeekNum]);
1200 ContactEditor->SetupContact(uc->ContactAccount);
1201 ContactEditor->LoadContact(uc->ContactFilename);
1211 ContactEditor->SetIcon(contacticon);
1212 ContactEditor->Show(true);
1216 void frmMain::RefreshAddressBook( wxCommandEvent& event ){
1218 // Check if ActiveAccount is empty. If not then check if
1219 // account type is not local otherwise continue.
1221 if (!ActiveAccount.IsEmpty()){
1223 if (ActiveAccountType != wxT("Local")){
1225 // Account type is not local.
1227 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1228 frameActMgr->AddTask(3, wxT(""), ActiveAccount,
1229 wxT(""), wxT(""), wxT(""), wxT(""));
1233 wxMessageBox(_("The refresh address book command is not supported with this type of account."), wxT("Not supported for this type of account"));
1241 void frmMain::OpenContactInfo( wxListEvent& event )
1244 wxStringTokenizer vcardfileline;
1247 wxString setname, setvalue;
1251 long intSelected = -1;
1252 long intContactSeekNum = -1;
1254 intSelected = lstContacts->GetNextItem(intSelected,
1256 wxLIST_STATE_SELECTED);
1258 intContactSeekNum = lstContacts->GetItemData(intSelected);
1260 if (intContactSeekNum == -1){
1264 Person.LoadFile(ContactsFileIndex[intContactSeekNum]);
1266 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1267 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1268 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1270 contacticon.CopyFromBitmap(contacticonbmp);
1272 frmContact *Contact = new frmContact( this );
1274 // Add to window list.
1278 Contact->SetUID(WindowMenuItemID);
1280 WindowData *WData = new WindowData;
1282 WData->DataType = 0;
1283 WData->WindowPointer = (void*)Contact;
1284 WData->WindowID = WindowMenuItemID;
1286 wxCommandEvent addevent(WINDOW_ADD);
1287 addevent.SetClientData(WData);
1288 wxPostEvent(this, addevent);
1290 Contact->SetupPointers(&MemoryFileList);
1291 Contact->SetupContactData(&Person);
1293 Contact->SetIcon(contacticon);
1294 Contact->Show(true);
1298 void frmMain::OpenContactInfo( wxCommandEvent& event )
1301 UCNotif *uc = (UCNotif*)event.GetClientData();
1303 wxStringTokenizer vcardfileline;
1306 wxString setname, setvalue;
1309 //std::fstream vcardfile;
1311 Person.LoadFile(uc->ContactFilename);
1313 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1314 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1315 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1317 contacticon.CopyFromBitmap(contacticonbmp);
1319 frmContact *Contact = new frmContact( this );
1321 // Add to window list.
1325 Contact->SetUID(WindowMenuItemID);
1327 WindowData *WData = new WindowData;
1329 WData->DataType = 0;
1330 WData->WindowPointer = (void*)Contact;
1331 WData->WindowID = WindowMenuItemID;
1333 wxCommandEvent addevent(WINDOW_ADD);
1334 addevent.SetClientData(WData);
1335 wxPostEvent(this, addevent);
1337 Contact->SetupPointers(&MemoryFileList);
1338 Contact->SetupContactData(&Person);
1340 Contact->SetIcon(contacticon);
1341 Contact->Show(true);
1346 void frmMain::LoadPreferences( wxActivateEvent& event)
1348 this->LoadPreferences();
1351 void frmMain::LoadPreferences(){
1353 // Load the preferences.
1355 wxString preffilename = GetUserPrefDir();
1357 XABPreferences preferences(preffilename);
1359 // Setup the main window position (if needed).
1361 bool SaveWindowPos = preferences.GetBoolData(wxT("SaveWindowPosition"));
1362 bool HideLocalABs = preferences.GetBoolData(wxT("HideLocalAddressBooks"));
1364 if (SaveWindowPos == TRUE){
1366 this->SetSize(preferences.GetMainWindowData());
1370 treAccounts->DeleteAllItems();
1372 wxTreeItemId RootNode = treAccounts->AddRoot(wxT("Root Item"), AccountNoneID);
1374 // Stop all account timers and remove the accounts.
1376 for (std::map<wxString, wxAccountSyncTimer*>::iterator iter = AccountSyncTimers.begin();
1377 iter != AccountSyncTimers.end(); iter++){
1379 wxAccountSyncTimer *AccTmrPtr = iter->second;
1387 AccountSyncTimers.clear();
1390 for (int i = (preferences.accounts.GetCount() - 1); i > 0; --i){
1391 treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i));
1396 wxString AccDirFull;
1397 wxString AccDirFullSfx;
1399 wxString AccDirFinal;
1400 AccountAccDirList.clear();
1401 AccountGroupList.clear();
1402 AccountGroupFilename.clear();
1403 AccountGroupTreeId.clear();
1404 wxTreeItemId AccountTreeId;
1405 wxTreeItemId GroupTreeId;
1408 for (int i = 0; i < preferences.accounts.GetCount(); i++){
1410 if ((preferences.accounts.GetAccountType(i) == wxT("Local") ||
1411 preferences.accounts.GetAccountType(i) == wxT("local")) && HideLocalABs == TRUE){
1417 if (preferences.accounts.GetAccountDirectory(i).IsEmpty()){
1423 AccDir = preferences.accounts.GetAccountDirectory(i);
1424 AccDirFull = preferences.accounts.GetAccountDirectory(i);
1426 AccDirFull.Append(wxT("."));
1427 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
1428 AccDirFullSfx.LowerCase();
1429 AccDirFullSfx.Trim();
1430 AccDirFull.Append(AccDirFullSfx);
1431 AccName = preferences.accounts.GetAccountName(i);
1433 AccountAccDirList.insert(std::make_pair(i, AccDirFull));
1435 if (preferences.accounts.GetAccountType(i) == wxT("CardDAV") ||
1436 preferences.accounts.GetAccountType(i) == wxT("carddav")){
1438 // Check if the directory exists before doing anything.
1442 // Add a new timer using the existing account details.
1444 wxAccountSyncTimer *ActTmrPtr = new wxAccountSyncTimer;
1446 ActTmrPtr->SetupData(AccDirFull, AccName);
1447 ActTmrPtr->SetupPointers(this, ActMgrPtr, ETagProcTimer.GetPointer(AccDirFull));
1448 ActTmrPtr->Start((int)(preferences.accounts.GetAccountRefresh(i) * 1000));
1449 ActTmrPtr->SetOwner(this);
1450 ActTmrPtr->Notify();
1452 // Add the timer to the list of timers.
1454 AccountSyncTimers.insert(std::make_pair(AccDirFull, ActTmrPtr));
1456 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountNetID, -1);
1460 AccountTreeId = treAccounts->AppendItem(RootNode, preferences.accounts.GetAccountName(i), AccountID, -1);
1464 // Go through the account directory and find contact files with
1465 // 'KIND:group' set and add them to the list of groups for the account.
1467 AccDirFinal = GetAccountDir(AccDirFull, FALSE);
1469 wxDir vcardaccdir(AccDirFinal);
1471 wxString vCardFilename;
1472 wxString vCardDataString;
1473 wxString vCardFilenameFull;
1474 //bool ProcFiles = FALSE;
1476 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
1479 if (vCardFilename.Right(4) == wxT(".vcf") ||
1480 vCardFilename.Right(4) == wxT(".VCF") ||
1481 vCardFilename.Right(5) == wxT(".vcard") ||
1482 vCardFilename.Right(5) == wxT(".VCARD")){
1486 vCardFilenameFull.Append(AccDirFinal);
1487 vCardFilenameFull.Append(wxT("/"));
1488 vCardFilenameFull.Append(vCardFilename);
1490 Person.LoadFile(vCardFilenameFull);
1492 if (Person.MeetBaseSpecification()){
1494 vCardDataString = Person.Get(wxT("KIND"));
1496 if (vCardDataString == wxT("group")){
1498 // The vCard kind is a group. Add to the account's group list.
1500 GroupTreeId = treAccounts->AppendItem(AccountTreeId, Person.Get(wxT("FN")), AccountGrpID, -1);
1501 treAccounts->SetItemHasChildren(AccountTreeId, TRUE);
1502 AccountGroupList.insert(std::make_pair(intGroupID, i));
1503 AccountGroupFilename.insert(std::make_pair(intGroupID, vCardFilenameFull));
1504 AccountGroupTreeId.insert(std::make_pair(GroupTreeId, intGroupID));
1516 vCardFilename.Clear();
1517 vCardFilenameFull.Clear();
1518 vCardDataString.Clear();
1519 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1523 // Clearup for next account.
1527 AccDirFullSfx.clear();
1528 AccDirFinal.clear();
1533 // Load the account settings as they are needed for connecting
1536 prefaccounts = preferences.accounts;
1540 void frmMain::ConflictResolution(wxCommandEvent& event){
1542 frmConflictResolution *frameCR = new frmConflictResolution ( this );
1543 vCardConflictObj *vCardConfObj = (vCardConflictObj*)event.GetClientData();
1544 vCard *ClientDataPtr = vCardConfObj->vCardLocalData;
1545 vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1546 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1547 //wxString Moo = ClientDataPtr->WriteString();
1548 //vCard *ServerDataPtr = vCardConfObj->vCardServerData;
1549 frameCR->LoadData(ClientDataPtr, ServerDataPtr, &MemoryFileList);
1550 //frameCR->LoadData(vCardConfObj->vCardLocalData, vCardConfObj->vCardServerData, &MemoryFileList);
1551 frameCR->ShowModal();
1553 int FinalConflictResult = frameCR->GetResult();
1555 wxCommandEvent event2(ACTMGR_RESUMEPROC);
1556 event2.SetClientData(vCardConfObj->QRNotifData);
1557 event2.SetInt(FinalConflictResult);
1562 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1563 wxPostEvent(frameActMgr, event2);
1567 void frmMain::UpdateContactList(wxCommandEvent& event){
1569 UCNotif *ucd = (UCNotif*)event.GetClientData();
1571 // Check if the active account is being displayed in the
1572 // main window. If not, skip and delete the data.
1574 long longSelected = -1;
1575 int intSelectedData = 0;
1577 if (ActiveAccount == ucd->ContactAccount){
1579 // Look at the list of contacts and if it matches the
1580 // filename then update the name.
1584 longSelected = lstContacts->GetNextItem(longSelected,
1586 wxLIST_STATE_DONTCARE);
1588 if (longSelected == -1){
1594 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1596 if (ucd->ContactFilename == ContactsFileIndex[intSelectedData]){
1598 // Work out which sorting mode we are in.
1602 // First Name, Last Name.
1604 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Forename + wxT(" ") + ucd->ContactNameArray.Surname);
1606 } else if (SortMode == 2){
1608 // Last Name, First Name.
1610 lstContacts->SetItem(longSelected, 0, ucd->ContactNameArray.Surname + wxT(", ") + ucd->ContactNameArray.Forename);
1612 } else if (SortMode == 3){
1616 lstContacts->SetItem(longSelected, 0, ucd->ContactNickname);
1618 } else if (SortMode == 4){
1622 lstContacts->SetItem(longSelected, 0, ucd->ContactName);
1629 // If the filename is the one loaded into the
1630 // browser control, then update this too.
1632 if (ActiveFilename == ContactsFileIndex[intSelectedData]){
1634 wxListEvent nullevent;
1635 ShowContactInfo(nullevent);
1643 for (std::map<int, void*>::iterator WindowIter = WindowListPointers.begin();
1644 WindowIter != WindowListPointers.end(); WindowIter++){
1646 if (WindowListType[WindowIter->first] != 0){
1652 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
1654 if (frmContactPtr->GetFilename() == ucd->ContactFilename){
1656 vCard UpdatedPerson;
1657 UpdatedPerson.LoadFile(ucd->ContactFilename);
1658 frmContactPtr->SetupContactData(&UpdatedPerson);
1664 // Send message to search window controller subroutine and
1665 // pass that notification onto the search windows.
1667 // Setup the new pointer to use the existing UCNotif without
1670 UCNotif *ucd2 = ucd;
1672 wxCommandEvent sup(SE_UPDATECONTACTNOTIF);
1673 sup.SetClientData(ucd2);
1674 wxPostEvent(this, sup);
1676 // Clear up the unused pointer.
1682 void frmMain::UpdateAccountList(wxCommandEvent& event){
1686 void frmMain::SetupPointers(void *ActMgrPtrInc){
1688 ActMgrPtr = ActMgrPtrInc;
1692 void frmMain::SetupForm(){
1694 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1695 frameActMgr->SetupPointers(&ETagProcTimer, this);
1697 // Setup the contact information icons for later.
1699 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1703 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1704 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1705 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1707 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1708 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1709 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1711 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1712 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1713 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1715 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1716 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1717 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1719 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1720 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1721 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1723 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1724 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1725 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1731 void frmMain::UpdateSearchContactLists(wxCommandEvent& event){
1733 // Go through each of the search windows and
1734 // send the required notification to update the
1735 // contact information.
1737 // Get the event notification data.
1739 UCNotif *ucd = (UCNotif*)event.GetClientData();
1741 // Process each search window giving the new details.
1743 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1744 switer != SearchWindowList.end(); switer++){
1746 // Duplicate the event notification data.
1748 UCNotif *ucd2 = new UCNotif;
1750 ucd2->ContactAccount = ucd->ContactAccount;
1751 ucd2->ContactFilename = ucd->ContactFilename;
1752 ucd2->ContactName = ucd->ContactName;
1753 ucd2->ContactNickname = ucd->ContactNickname;
1754 ucd2->ContactNameArray = ucd->ContactNameArray;
1756 // Pass the data to the search window for processing.
1758 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1759 wxCommandEvent schupdate(SE_UPDATERESULT);
1760 schupdate.SetClientData(ucd2);
1761 wxPostEvent(frameSCH, schupdate);
1763 // Clear up the pointer prior to variable deletion.
1774 void frmMain::OpenFindContactsWindow(wxCommandEvent& event){
1778 frmSearch *frameSCH = new frmSearch ( this );
1779 frameSCH->SetUID(WindowMenuItemID);
1780 frameSCH->Show(true);
1782 WindowData *WData = new WindowData;
1784 WData->DataType = 2;
1785 WData->WindowPointer = (void*)frameSCH;
1786 WData->WindowID = WindowMenuItemID;
1788 wxCommandEvent addevent(WINDOW_ADD);
1789 addevent.SetClientData(WData);
1790 wxPostEvent(this, addevent);
1792 // Add pointer to the list of open search windows.
1794 SearchWindowList.insert(std::make_pair(frameSCH, wxT("Search")));
1800 void frmMain::RemoveContactsWindowPointer(wxCommandEvent& event){
1802 //frmSearch *frameSCH = static_cast<frmSearch*>(ActMgrPtr);
1803 void *frameSCH = (void*)event.GetClientData();
1805 SearchWindowList.erase(frameSCH);
1811 void frmMain::RemoveContactEditorWindowPointer(wxCommandEvent& event){
1813 void *frameSCH = (void*)event.GetClientData();
1815 SearchWindowList.erase(frameSCH);
1821 void frmMain::UpdateWindowList(wxCommandEvent& event){
1823 // Update the Window List.
1825 // Delete the existing items in the window menu.
1827 // Get the list of contacts.
1829 // Insert a separator.
1831 // Get the list of search windows.
1835 void frmMain::RevealContact(wxCommandEvent& event){
1837 UCNotif *uc = (UCNotif*)event.GetClientData();
1839 // Switch the account to the one passed.
1841 wxTreeItemIdValue cookie;
1842 wxTreeItemId next = treAccounts->GetRootItem();
1843 wxTreeItemId nextChild;
1845 for (int i = 0; i < prefaccounts.GetCount(); i++){
1848 nextChild = treAccounts->GetFirstChild(next, cookie);
1850 nextChild = treAccounts->GetNextSibling(nextChild);
1853 //AccountName = treAccounts->GetItemText(nextChild);
1855 if (uc->ContactAccount == AccountAccDirList[i]){
1858 treAccounts->SelectItem(nextChild, TRUE);
1859 AccCtrl->SetText(treAccounts->GetItemText(nextChild));
1865 // Switch the contact to the one passed.
1867 long longSelected = -1;
1868 int intSelectedData = 0;
1872 longSelected = lstContacts->GetNextItem(longSelected,
1874 wxLIST_STATE_DONTCARE);
1876 if (longSelected == -1){
1882 intSelectedData = (int)lstContacts->GetItemData(longSelected);
1884 // Compare the filename with the one received.
1885 // If they match then select it.
1887 if (ContactsFileIndex[intSelectedData] == uc->ContactFilename){
1891 lstContacts->SetItemState(longSelected, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1892 lstContacts->EnsureVisible(longSelected);
1896 lstContacts->SetItemState(longSelected, 0, wxLIST_STATE_SELECTED);
1904 void frmMain::DeleteContact(wxCommandEvent& event){
1906 // Check if a contact is selected.
1908 long intSelected = -1;
1909 long intContactSeekNum = -1;
1910 wxString wxSContactName;
1912 intSelected = lstContacts->GetNextItem(intSelected,
1914 wxLIST_STATE_SELECTED);
1916 if (intSelected == -1){
1920 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
1922 // Get the item data of the contact.
1924 intContactSeekNum = lstContacts->GetItemData(intSelected);
1926 // Get the name of the contact.
1928 wxSContactName = lstContacts->GetItemText(intSelected);
1930 // Display a message confirming if the contact should
1933 int QuestionResponse;
1935 QuestionResponse = wxMessageBox(_("Are you sure you want to delete this contact?"), _("Delete contact"), wxYES_NO, this);
1937 if (QuestionResponse == wxNO){
1939 // Exit the subroutine
1945 // Delete the contact.
1947 if (!wxRemoveFile(ContactsFileIndex[intContactSeekNum])){
1949 wxMessageBox(_("Unable to delete the contact."), _("Cannot delete contact"), wxOK, this);
1954 // Remove the contact from the list.
1956 lstContacts->DeleteItem(intSelected);
1958 // Update the search windows, removing the deleted
1961 UCNotif *ucd = new UCNotif;
1963 ucd->ContactAccount = ActiveAccount;
1964 ucd->ContactFilename = ContactsFileIndex[intContactSeekNum];
1966 for (std::map<void*,wxString>::iterator switer = SearchWindowList.begin();
1967 switer != SearchWindowList.end(); switer++){
1969 // Duplicate the event notification data.
1971 UCNotif *ucd2 = new UCNotif;
1973 ucd2->ContactAccount = ucd->ContactAccount;
1974 ucd2->ContactFilename = ucd->ContactFilename;
1976 // Pass the data to the search window for processing.
1978 frmSearch *frameSCH = static_cast<frmSearch*>(switer->first);
1979 wxCommandEvent schdelete(SE_DELETERESULT);
1980 schdelete.SetClientData(ucd2);
1981 wxPostEvent(frameSCH, schdelete);
1983 // Clear up the pointer prior to variable deletion.
1990 // Clear the wxHTMLWindow.
1992 wxString EmptyPage = wxT("");
1994 htmContactData->SetPage(EmptyPage);
1996 wxStringTokenizer wSTFilename(ContactsFileIndex[intContactSeekNum], wxT("/"));
1998 wxString wxSplitFilename;
1999 wxString wxSDataURL;
2001 while(wSTFilename.HasMoreTokens()){
2003 wxSplitFilename = wSTFilename.GetNextToken();
2007 if (ActiveAccountType == wxT("CardDAV") || ActiveAccountType == wxT("carddav")){
2009 // Update the ETagDB and mark it as deleted.
2011 ETagDB *ETagDBPtr = ETagProcTimer.GetPointer(ActiveAccount);
2013 ETagDBPtr->UpdateETag(wxSplitFilename, wxT("DELETED"));
2015 // Get the Data URL.
2017 wxTreeItemIdValue cookie;
2018 wxTreeItemId next = treAccounts->GetRootItem();
2020 wxTreeItemId selectedChild = treAccounts->GetSelection();
2021 wxTreeItemId nextChild;
2023 for (int i = 0; i < prefaccounts.GetCount(); i++){
2026 nextChild = treAccounts->GetFirstChild(next, cookie);
2029 nextChild = treAccounts->GetNextSibling(nextChild);
2032 if (nextChild == selectedChild){
2033 wxSDataURL = prefaccounts.GetAccountDirPrefix(i) + wxT("/") + wxSplitFilename;
2039 // Add task to the activity monitor to delete the contact.
2041 frameActMgr->AddTask(2, wxSContactName, ActiveAccount, wxSDataURL, wxSplitFilename, ContactsFileIndex[intContactSeekNum], wxT(""));
2045 // Clear the variable. Don't delete as it will mess things up.
2047 ContactsFileIndex[intContactSeekNum] = wxT("");
2054 void frmMain::EmptyServerDialog(wxCommandEvent& event){
2056 QRNotif *qrn = (QRNotif *)event.GetClientData();
2058 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);
2060 if (QResponse == wxNO){
2066 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2067 event2.SetInt(*qrn->QResponse);
2068 event2.SetClientData(qrn->PausePtr);
2070 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2072 wxPostEvent(frameActMgr, event2);
2076 void frmMain::DeleteContactSync(wxString &Account, wxString &Filename){
2078 // Remove the contact from the window after syncronising.
2080 // Check which account is currently active in the window.
2081 // If it is different from the one passed to this subroutine then
2082 // exit from the subroutine.
2084 if (Account != ActiveAccount){
2088 long longSelected = -1;
2089 int intSelectedData = 0;
2093 longSelected = lstContacts->GetNextItem(longSelected,
2095 wxLIST_STATE_DONTCARE);
2097 if (longSelected == -1){
2103 intSelectedData = (int)lstContacts->GetItemData(longSelected);
2105 // Compare the filename with the one received.
2106 // If they match then select it.
2108 if (ContactsFileIndex[intSelectedData] == Filename){
2110 // Remove the contact from the window.
2112 lstContacts->DeleteItem(intSelectedData);
2114 // Check if contact is the selected contact in the HTML window and
2115 // if it is then clear the window.
2117 if (ActiveFilename == Filename){
2119 wxString EmptyPage = wxT("");
2120 htmContactData->SetPage(EmptyPage);
2134 void frmMain::SortFNLN( wxCommandEvent& event ) {
2136 wxTreeEvent NullEvent;
2138 LoadContactList(NullEvent);
2142 void frmMain::SortLNFN( wxCommandEvent& event ) {
2144 wxTreeEvent NullEvent;
2146 LoadContactList(NullEvent);
2150 void frmMain::SortNickname( wxCommandEvent& event ) {
2152 wxTreeEvent NullEvent;
2154 LoadContactList(NullEvent);
2158 void frmMain::SortDisplayAs( wxCommandEvent& event ) {
2160 wxTreeEvent NullEvent;
2162 LoadContactList(NullEvent);
2166 void frmMain::SortAscending( wxCommandEvent& event ) {
2168 wxTreeEvent NullEvent;
2169 AscendingMode = TRUE;
2170 LoadContactList(NullEvent);
2174 void frmMain::SortDescending( wxCommandEvent& event ) {
2176 wxTreeEvent NullEvent;
2177 AscendingMode = FALSE;
2178 LoadContactList(NullEvent);
2182 void frmMain::ToggleStatusBar( wxCommandEvent& event ) {
2184 if (stbBottom->IsShown() == TRUE){
2198 void frmMain::ActivityIconStart( wxCommandEvent& event ){
2200 // Display the activity icon.
2202 imgActivityStatus->SetBitmap(*imgActIcon1);
2203 ActivityIconStatus = 0;
2207 void frmMain::ActivityIconShuffle( wxCommandEvent& event ){
2209 switch (ActivityIconStatus){
2212 imgActivityStatus->SetBitmap(*imgActIcon1);
2213 ActivityIconStatus = 1;
2216 imgActivityStatus->SetBitmap(*imgActIcon2);
2217 ActivityIconStatus = 2;
2220 imgActivityStatus->SetBitmap(*imgActIcon3);
2221 ActivityIconStatus = 3;
2224 imgActivityStatus->SetBitmap(*imgActIcon4);
2225 ActivityIconStatus = 0;
2228 ActivityIconStatus = 0;
2234 void frmMain::ActivityIconStop( wxCommandEvent& event ){
2236 // Display the sleep icon.
2238 imgActivityStatus->SetBitmap(*imgActIconSleep);
2242 void frmMain::UpdateSBIconPlacement( wxSizeEvent& event ){
2244 if (imgConnStatus == 0 || imgSSLStatus == 0 || imgActivityStatus == 0){
2252 wxRect rectActivity;
2253 stbBottom->GetFieldRect(1, rectOnline);
2254 stbBottom->GetFieldRect(2, rectSSL);
2255 stbBottom->GetFieldRect(3, rectActivity);
2257 imgConnStatus->Move(rectOnline.GetX(),rectOnline.GetY());
2258 imgSSLStatus->Move(rectSSL.GetX(),rectSSL.GetY());
2259 imgActivityStatus->Move(rectActivity.GetX(),rectActivity.GetY());
2263 XABViewMode frmMain::GetViewMode(){
2267 xvm.SortMode = SortMode;
2268 xvm.AscendingMode = AscendingMode;
2274 void frmMain::WindowAdd( wxCommandEvent &event ){
2276 WindowData *WData = (WindowData*)event.GetClientData();
2280 if (WData->DataType == 0){
2284 int intID = mnuContactWindows->GetId();
2286 mnuWindow->FindChildItem(intID, &pos);
2287 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2288 mnuNewItem->SetId(WData->WindowID);
2289 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2290 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2291 WindowListType.insert(std::make_pair(WData->WindowID, 0));
2292 mnuWindow->Insert((pos + 1), mnuNewItem);
2293 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2295 } else if (WData->DataType == 1){
2297 // Contact Editor Window
2299 int intID = mnuContactEditorWindows->GetId();
2301 mnuWindow->FindChildItem(intID, &pos);
2302 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Contact Editor Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2303 mnuNewItem->SetId(WData->WindowID);
2304 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2305 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2306 WindowListType.insert(std::make_pair(WData->WindowID, 1));
2307 mnuWindow->Insert((pos + 1), mnuNewItem);
2308 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2310 } else if (WData->DataType == 2){
2314 int intID = mnuSearchWindows->GetId();
2316 mnuWindow->FindChildItem(intID, &pos);
2317 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, wxT("Search Window #") + wxString::Format(wxT("%i"), WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2318 mnuNewItem->SetId(WData->WindowID);
2319 WindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2320 WindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2321 WindowListType.insert(std::make_pair(WData->WindowID, 2));
2322 mnuWindow->Insert((pos + 1), mnuNewItem);
2323 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowSearchWindow));
2332 void frmMain::WindowEdit( wxCommandEvent &event ){
2334 WindowData *WData = (WindowData*)event.GetClientData();
2336 if (WData->DataType == 0){
2338 // Get the window title and use that.
2340 frmContact *frmContactPtr = static_cast<frmContact*>(WData->WindowPointer);
2342 wxString WindowTitle = frmContactPtr->GetTitle();
2344 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2346 MenuIter->second->SetItemLabel(WindowTitle);
2348 //mnuWindow->FindChildItem(intID, &pos);
2349 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2350 //mnuNewItem->SetId(WData->WindowID);
2351 //ContactWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2352 //ContactWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2353 //mnuWindow->Insert((pos + 1), mnuNewItem);
2354 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactWindow));
2356 } else if (WData->DataType == 1){
2358 // Get the window title and use that.
2360 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WData->WindowPointer);
2362 wxString WindowTitle = frmCEPtr->GetTitle();
2364 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2366 if (WindowTitle.IsEmpty()){
2368 MenuIter->second->SetItemLabel(_("Unnamed Contact"));
2372 MenuIter->second->SetItemLabel(WindowTitle);
2376 //mnuWindow->FindChildItem(intID, &pos);
2377 //wxMenuItem *mnuNewItem = new wxMenuItem(NULL, WData->WindowID, WindowTitle, WData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
2378 //mnuNewItem->SetId(WData->WindowID);
2379 //ContactEditorWindowListPointersMenu.insert(std::make_pair(WData->WindowID, mnuNewItem));
2380 //ContactEditorWindowListPointers.insert(std::make_pair(WData->WindowID, WData->WindowPointer));
2381 //mnuWindow->Insert((pos + 1), mnuNewItem);
2382 //this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowContactEditorWindow));
2391 void frmMain::WindowDelete( wxCommandEvent &event ){
2393 WindowData *WData = (WindowData*)event.GetClientData();
2395 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(WData->WindowID);
2397 mnuWindow->Remove(MenuIter->second);
2399 delete MenuIter->second;
2400 MenuIter->second = NULL;
2402 WindowListPointersMenu.erase(WData->WindowID);
2403 WindowListPointers.erase(WData->WindowID);
2404 WindowListType.erase(WData->WindowID);
2411 void frmMain::ShowContactWindow( wxCommandEvent &event ){
2413 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2415 frmContact *frmContactPtr = static_cast<frmContact*>(WindowIter->second);
2417 frmContactPtr->Show();
2418 frmContactPtr->Raise();
2422 void frmMain::ShowContactEditorWindow( wxCommandEvent &event ){
2424 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2426 frmContactEditor *frmCEPtr = static_cast<frmContactEditor*>(WindowIter->second);
2433 void frmMain::ShowSearchWindow( wxCommandEvent &event ){
2435 // Look through the Search Window List Pointers, grab the
2436 // window point and show the window.
2438 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
2440 frmSearch *frmSearchPtr = static_cast<frmSearch*>(WindowIter->second);
2442 frmSearchPtr->Show();
2443 frmSearchPtr->Raise();
2447 void frmMain::ToggleConnectionStatus( wxCommandEvent &event ){
2449 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2450 wxCommandEvent toggconn(ACTMGR_TOGGLECONN);
2451 wxPostEvent(frameActMgr, toggconn);
2455 void frmMain::ShowSSLCertificates( wxCommandEvent &event ){
2457 // Check the account type before continuing.
2459 wxString SeekAccount;
2460 wxString AccTypeLower;
2463 std::map<int, SSLCertCollection>::iterator SSLColIter;
2465 for (int i = 0; i < prefaccounts.GetCount(); i++){
2467 SeekAccount.Append(prefaccounts.GetAccountDirectory(i));
2468 AccType.Append(prefaccounts.GetAccountType(i));
2469 AccountSSL = prefaccounts.GetAccountSSL(i);
2470 AccTypeLower = AccType.MakeLower();
2471 SeekAccount.Append(wxT("."));
2472 SeekAccount.Append(AccTypeLower);
2474 if (SeekAccount == ActiveAccount){
2476 if (AccTypeLower == wxT("local")){
2482 if (AccountSSL == false){
2488 SSLColIter = AccountSSLData.find(i);
2490 SSLCertCollection SSLCertInfo = SSLColIter->second;
2492 frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this );
2493 frameSSLCert->StartCertFrom(0);
2494 frameSSLCert->SetupCerts(SSLCertInfo);
2495 frameSSLCert->ShowModal();
2497 delete frameSSLCert;
2498 frameSSLCert = NULL;
2502 SeekAccount.Clear();
2503 AccTypeLower.Clear();
2510 void frmMain::ShowSSLInfo( wxCommandEvent &event ){
2512 // Check the account type before continuing.
2516 void frmMain::HideSSLInfo( wxCommandEvent &event ){
2518 // Check the account type before continuing.
2522 void frmMain::UpdateConnectionStatus( wxCommandEvent &event ){
2524 if (event.GetInt() == 0){
2526 imgConnStatus->SetBitmap(*imgOnline);
2530 imgConnStatus->SetBitmap(*imgOffline);
2536 void frmMain::SetupSSLStatus( int AccountID ){
2538 // Check if account ID given is
2539 // the active account and if not, do nothing.
2542 wxString AccTypeLower;
2544 AccType = prefaccounts.GetAccountType(AccountID);
2545 AccTypeLower = AccType.MakeLower();
2547 wxString AccountIDName = prefaccounts.GetAccountDirectory(AccountID) + wxT(".") +
2550 if (AccountIDName != ActiveAccount){
2556 // Check if the account has SSL enabled.
2558 bool SSLInUse = prefaccounts.GetAccountSSL(AccountID);
2560 if (SSLInUse == FALSE){
2562 SSLToolTip->SetTip(wxT("SSL is not enabled for this account"));
2563 imgSSLStatus->SetBitmap(*imgNoSSL);
2567 // Get the SSL Collection Data.
2569 std::map<int,int>::iterator SSLResultIter = AccountSSLResult.find(AccountID);
2571 if (SSLResultIter->second == 1){
2573 imgSSLStatus->SetBitmap(*imgSSLWarning);
2574 SSLToolTip->SetTip(wxT("Invalid certificate(s) received for '") +
2575 prefaccounts.GetAccountName(AccountID) +
2576 wxT("' (Connection denied by user)\n\nDouble click for more information."));
2579 } else if (SSLResultIter->second == 0){
2581 imgSSLStatus->SetBitmap(*imgSSL);
2582 SSLToolTip->SetTip(wxT("Account '") +
2583 prefaccounts.GetAccountName(AccountID) +
2584 wxT("' secured using SSL\n\nDouble click for more information."));
2592 void frmMain::InvalidSSLCertificate( wxCommandEvent &event ){
2594 frmInvalidSSLCertificate *frameISC = new frmInvalidSSLCertificate ( this );
2595 SSLInvalidCertNotifObj *SSLICNObj = (SSLInvalidCertNotifObj*)event.GetClientData();
2596 SSLCertCollection SSLCCData = SSLICNObj->CertCollection;
2597 wxString AccountName = SSLICNObj->AccountName;
2598 frameISC->LoadData(SSLCCData, AccountName);
2599 frameISC->ShowModal();
2601 int FinalConflictResult = frameISC->GetResult();
2603 wxCommandEvent event2(ACTMGR_RESUMEPROC);
2604 event2.SetClientData(SSLICNObj->QRNotifData);
2605 event2.SetInt(FinalConflictResult);
2610 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2611 wxPostEvent(frameActMgr, event2);
2614 void frmMain::PauseAllTimers(){
2616 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2617 ASTiter != AccountSyncTimers.end(); ASTiter++){
2619 ASTiter->second->Stop();
2625 void frmMain::ResumeAllTimers(){
2627 for (std::map<wxString, wxAccountSyncTimer*>::iterator ASTiter = AccountSyncTimers.begin();
2628 ASTiter != AccountSyncTimers.end(); ASTiter++){
2630 ASTiter->second->Start();
2636 void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
2638 // Delete existing data.
2640 AccountSSLData.erase(AccountID);
2641 AccountSSLResult.erase(AccountID);
2645 AccountSSLData.insert(std::make_pair(AccountID, SSLCertInc));
2646 AccountSSLResult.insert(std::make_pair(AccountID, SSLStatus));
2650 void frmMain::CheckUpdates( wxCommandEvent& event ){
2652 frmUpdate *frameUpdate = new frmUpdate ( this );
2653 frameUpdate->FetchData();
2654 frameUpdate->ShowModal();
2658 void frmMain::OpenImportDialog( wxCommandEvent& event ){
2660 // Run the import contacts system.
2666 void frmMain::OpenExportDialog( wxCommandEvent& event ){
2668 // Check if an account and at least one contact is selected
2669 // before continuing.
2671 wxArrayString ArrData;
2673 if (ActiveAccount.IsEmpty()){
2679 int ContactSelected = 0;
2680 int ContactsCollected = 0;
2681 long longSelected = -1;
2685 longSelected = lstContacts->GetNextItem(longSelected,
2687 wxLIST_STATE_SELECTED);
2689 if (longSelected == -1){
2695 int FileID = (int)lstContacts->GetItemData(longSelected);
2697 ArrData.Insert(ContactsFileIndex[FileID],
2698 ContactsCollected, 1);
2704 if (ContactSelected == 0){
2710 // Run the export contacts system.
2712 ExportRun(this, &ArrData);
2716 void frmMain::GetListControl(wxListCtrl *lstContactsPtr,
2717 wxArrayString *ContactsFileIndexPtr){
2719 lstContactsPtr = lstContacts;
2720 ContactsFileIndexPtr = &ContactsFileIndex;
2724 void frmMain::GetSelectedList( wxCommandEvent& event ){
2726 // Get the array of contact filenames.
2728 wxArrayString *ArrData = (wxArrayString*)event.GetClientData();
2730 // Process them into an array of files.
2732 long longSelected = -1;
2733 int ContactsCollected = 0;
2734 wxString ContactFilename;
2738 longSelected = lstContacts->GetNextItem(longSelected,
2740 wxLIST_STATE_SELECTED);
2742 if (longSelected == -1){
2748 // Get the file information and add to the list.
2750 int FileID = (int)lstContacts->GetItemData(longSelected);
2752 ArrData->Insert(ContactsFileIndex[FileID],
2753 ContactsCollected, 1);
2755 ContactsCollected++;
2756 ContactFilename.Clear();
2764 void frmMain::SyncAccount( wxCommandEvent& event ){
2766 wxString AccNameInc = event.GetString();
2768 frmActivityMgr *frameActMgr = static_cast<frmActivityMgr*>(ActMgrPtr);
2769 frameActMgr->AddTask(3, wxT(""), AccNameInc,
2770 wxT(""), wxT(""), wxT(""), wxT(""));
2774 void frmMain::ShowHelp( wxCommandEvent& event ){
2776 // Based on the operating system, work out where
2777 // the documentation should be.
2781 #if defined(__HAIKU__)
2783 #elif defined(__WIN32__)
2789 if (wxFileExists("/usr/share/doc/xestiaab/index.html")){
2791 wxLaunchDefaultBrowser(wxT("file:///usr/share/doc/xestiaab/index.html"));
2794 #if XSDAB_RELEASE == 0
2796 } else if (wxFileExists("/usr/local/share/doc/xestiaab/index.html")){
2798 wxLaunchDefaultBrowser(wxT("file:///usr/local/share/doc/xestiaab/index.html"));
2807 #if XSDAB_RELEASE == 0
2809 wxMessageBox(_("The help documentation is not available.\n\nYou can view the documentation that came with your source package."), _("Help documentation missing!"));
2813 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!"));
2819 void frmMain::ShowImportResults( wxCommandEvent &event ){
2821 std::map<int,wxString> *ResultData = (std::map<int,wxString>*)event.GetClientData();
2823 frmImportResults *frmIR = new frmImportResults(this);
2824 frmIR->LoadData(ResultData, event.GetInt(), (int)event.GetExtraLong());
2835 void frmMain::ReloadContactList( wxCommandEvent &event ){
2837 // Check if the account name given is the current
2838 // account selected.
2840 if (ActiveAccount == event.GetString()){
2842 wxTreeEvent NullEvent;
2843 LoadContactList(NullEvent);