3 #include "frmContact.h"
4 #include "search/XABSearchPanel.h"
5 #include "search/frmSearchAccounts.h"
6 #include "common/preferences.h"
7 #include "common/dirs.h"
8 #include "vcard/vcard.h"
11 #include <wx/fs_mem.h>
12 #include <wx/tokenzr.h>
15 DEFINE_EVENT_TYPE(SE_ADDSEARCHSETTING);
16 DEFINE_EVENT_TYPE(SE_REMOVESEARCHSETTING);
17 DEFINE_EVENT_TYPE(SE_RELOADACCOUNTS);
18 DEFINE_EVENT_TYPE(SE_ADDRESULT);
19 DEFINE_EVENT_TYPE(SE_SBUPDATE);
20 DEFINE_EVENT_TYPE(SE_SEARCHFINISHED);
21 DEFINE_EVENT_TYPE(SE_UPDATERESULT);
22 DEFINE_EVENT_TYPE(SE_DELETERESULT);
23 DEFINE_EVENT_TYPE(SE_OPENCONTACT);
24 DEFINE_EVENT_TYPE(SE_EDITCONTACT);
25 DEFINE_EVENT_TYPE(SE_REVEALCONTACT);
27 BEGIN_EVENT_TABLE(frmSearch, wxFrame)
28 EVT_COMMAND(wxID_ANY, SE_ADDSEARCHSETTING, frmSearch::AddSearchSetting)
29 EVT_COMMAND(wxID_ANY, SE_REMOVESEARCHSETTING, frmSearch::RemoveSearchSetting)
30 EVT_COMMAND(wxID_ANY, SE_RELOADACCOUNTS, frmSearch::ReloadAccountList)
31 EVT_COMMAND(wxID_ANY, SE_ADDRESULT, frmSearch::AddResult)
32 EVT_COMMAND(wxID_ANY, SE_SBUPDATE, frmSearch::SearchBarUpdate)
33 EVT_COMMAND(wxID_ANY, SE_SEARCHFINISHED, frmSearch::SearchFinished)
34 EVT_COMMAND(wxID_ANY, SE_UPDATERESULT, frmSearch::UpdateResult)
35 EVT_COMMAND(wxID_ANY, SE_DELETERESULT, frmSearch::DeleteResult)
36 EVT_COMMAND(wxID_ANY, SE_OPENCONTACT, frmSearch::OpenContact)
37 EVT_COMMAND(wxID_ANY, SE_EDITCONTACT, frmSearch::EditContact)
38 EVT_COMMAND(wxID_ANY, SE_REVEALCONTACT, frmSearch::RevealContact)
41 frmSearch::frmSearch( wxWindow* parent )
43 frmSearchADT( parent )
46 XABSearchPanel *InitPanel = new XABSearchPanel( tabSearch );
47 InitPanel->EnableButtons(TRUE, FALSE);
48 InitPanel->SetupPointers(this);
49 InitPanel->SetupInteger(ScrollGen);
50 szrSearch->Add(InitPanel, 1, wxEXPAND, 0);
51 szrSearch->Fit(tabSearch);
52 SearchFrames.insert(std::make_pair(ScrollGen, InitPanel));
55 // Get the list of accounts and mark them as true.
57 wxString preffilename = GetUserPrefDir();
59 XABPreferences preferences(preffilename);
63 wxString AccDirFullSfx;
65 for (int i = 0; i < preferences.accounts.GetCount(); i++){
66 AccDir = preferences.accounts.GetAccountDirectory(i);
67 AccDirFull = preferences.accounts.GetAccountDirectory(i);
69 AccDirFull.Append(wxT("."));
70 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
71 AccDirFullSfx.LowerCase();
73 AccDirFull.Append(AccDirFullSfx);
74 SearchAccountsPaths.insert(std::make_pair(AccDir, AccDirFull));
75 SearchAccounts.insert(std::make_pair(AccDir, TRUE));
76 SearchAccountsNames.insert(std::make_pair(AccDir,
77 preferences.accounts.GetAccountName(i)));
79 AccDirFullSfx.clear();
87 item.SetText(_("Name"));
90 lstResults->InsertColumn(0, item);
93 item.SetText(_("Nickname"));
96 lstResults->InsertColumn(1, item);
99 item.SetText(_("Account"));
102 lstResults->InsertColumn(2, item);
106 void frmSearch::SelectAccounts( wxCommandEvent& event )
109 // Create the form and display as modal.
111 frmSearchAccounts *frameSAccount = new frmSearchAccounts ( this );
112 frameSAccount->LoadSearchAccounts(&SearchAccounts, &SearchAccountsNames);
113 frameSAccount->ShowModal();
114 delete frameSAccount;
115 frameSAccount = NULL;
119 void frmSearch::SearchContactsThread(){
121 // Go through each account and find contacts based on the
124 std::map<wxString,bool>::iterator SAiter;
125 std::map<wxString,wxString>::iterator SAPiter;
126 int intResultFound = 0;
128 for (std::map<wxString, wxString>::iterator SALiter = SearchAccountsNames.begin();
129 SALiter != SearchAccountsNames.end();
132 // Double check that we are searching in this account.
133 // If not, skip to the next one.
135 SAiter = SearchAccounts.find(SALiter->first);
136 SAPiter = SearchAccountsPaths.find(SAiter->first);
139 if (SAiter->second == FALSE){
141 // Not looking in this account. Go to next account.
147 wxCommandEvent sbupdate (SE_SBUPDATE);
149 wxString *SBData = new wxString;
150 *SBData = _("Searching ") + SALiter->second + _("...");
152 sbupdate.SetClientData(SBData);
153 wxPostEvent(this, sbupdate);
155 if (StopMode == FALSE){
157 wxCommandEvent sbstop (SE_SBUPDATE);
159 wxString *SBStopStr = new wxString;
160 *SBStopStr = _("Search stopped.");
162 sbstop.SetClientData(SBStopStr);
163 wxPostEvent(this, sbstop);
168 // Get the list of contact files and process each
171 wxString AccountDir = GetAccountDir(SAPiter->second, FALSE);
173 wxString vcardfilenamewxs;
174 wxStringTokenizer vcardfileline;
176 wxString setname, setvalue;
177 long ContactIndex = 1;
178 long ContactSeekPoint = 0;
179 wxString vCardFilename;
180 wxString vCardFilenameFull;
182 if (wxDirExists(AccountDir)){
184 wxDir vcardaccdir(AccountDir);
186 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
189 if (StopMode == FALSE){
191 wxCommandEvent sbstop(SE_SBUPDATE);
193 wxString *SBStopStr = new wxString;
194 *SBStopStr = _("Search stopped.");
196 sbstop.SetClientData(SBStopStr);
197 wxPostEvent(this, sbstop);
202 if (vCardFilename.Right(4) == wxT(".vcf") ||
203 vCardFilename.Right(4) == wxT(".VCF") ||
204 vCardFilename.Right(5) == wxT(".vcard") ||
205 vCardFilename.Right(5) == wxT(".VCARD")){
208 vCardFilenameFull.Append(AccountDir);
209 vCardFilenameFull.Append(vCardFilename);
211 Person.LoadFile(vCardFilenameFull);
213 vcardfilenamewxs = vCardFilenameFull;
215 // Check if file has version 4.0, first name (FN)
216 // begin and end vCard portions.
218 // Don't search unless these conditions have been met.
220 if (Person.MeetBaseSpecification()){
222 // Go through each of the search settings and check
223 // if they match with contact details.
225 // If it matches then add to the search results.
231 ArrayvCardOutData ArrayData;
232 ArrayvCardOutData NicknameArrayData;
233 vCardName NameArray = Person.GetName();
234 wxString ContactFinalNickname;
235 NicknameArrayData = Person.GetByPartial(wxT("NICKNAME"));
237 if (NicknameArrayData.PropCount != 0){
238 ContactFinalNickname = NicknameArrayData.PropValues[0];
241 for (std::map<int, void*>::iterator siter = SearchFrames.begin();
242 siter != SearchFrames.end(); siter++){
244 // Get the settings from the form.
246 XABSearchPanel *XABSPPtr = static_cast<XABSearchPanel*>(siter->second);
248 // Get Selected Option and Setting.
250 SelOpt = XABSPPtr->GetSelectionOption();
254 StrOpt = XABSPPtr->GetStringSetting();
255 StrOptLen = StrOpt.Len();
257 if (SelOpt == 0 || SelOpt == 4 || SelOpt == 8){
259 // Matching string that beings with...
261 // Double check the std::map inserts for each section.
265 // Get the forename from the first N.
267 if (NameArray.Forename.Mid(0, StrOptLen) == StrOpt){
269 if (CheckDuplicate(vcardfilenamewxs,
271 &SearchResultAccount,
272 &SearchResultFilename) == TRUE){
278 ArrayData.PropData.Clear();
279 ArrayData.PropValues.Clear();
280 ArrayData.PropCount = 0;
285 SRNotif *sradd = new SRNotif;
286 sradd->ContactName = NameArray;
287 sradd->ContactNickname = ContactFinalNickname;
288 sradd->ContactAccount = SAPiter->second;
289 sradd->ContactAccountName = SALiter->second;
290 sradd->ContactFullFilename = vcardfilenamewxs;
291 sradd->SearchResultID = intResultFound;
293 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
294 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
298 wxCommandEvent sraddenv(SE_ADDRESULT);
299 sraddenv.SetClientData(sradd);
300 wxPostEvent(this, sraddenv);
304 } else if (SelOpt == 4){
306 if (NameArray.Surname.Mid(0, StrOptLen) == StrOpt){
308 if (CheckDuplicate(vcardfilenamewxs,
310 &SearchResultAccount,
311 &SearchResultFilename) == TRUE){
317 ArrayData.PropData.Clear();
318 ArrayData.PropValues.Clear();
319 ArrayData.PropCount = 0;
324 SRNotif *sradd = new SRNotif;
325 sradd->ContactName = NameArray;
326 sradd->ContactNickname = ContactFinalNickname;
327 sradd->ContactAccount = SAPiter->second;
328 sradd->ContactAccountName = SALiter->second;
329 sradd->ContactFullFilename = vcardfilenamewxs;
330 sradd->SearchResultID = intResultFound;
332 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
333 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
337 wxCommandEvent sraddenv(SE_ADDRESULT);
338 sraddenv.SetClientData(sradd);
339 wxPostEvent(this, sraddenv);
343 } else if (SelOpt == 8){
345 wxString NicknameData;
347 for (int i = 0; i < NicknameArrayData.PropCount; i++){
349 NicknameData = NicknameArrayData.PropValues[i];
351 if (NicknameData.Mid(0, StrOptLen) == StrOpt){
353 if (CheckDuplicate(vcardfilenamewxs,
355 &SearchResultAccount,
356 &SearchResultFilename) == TRUE){
362 ArrayData.PropData.Clear();
363 ArrayData.PropValues.Clear();
364 ArrayData.PropCount = 0;
369 SRNotif *sradd = new SRNotif;
370 sradd->ContactName = NameArray;
371 sradd->ContactNickname = ContactFinalNickname;
372 sradd->ContactAccount = SAPiter->second;
373 sradd->ContactAccountName = SALiter->second;
374 sradd->ContactFullFilename = vcardfilenamewxs;
375 sradd->SearchResultID = intResultFound;
377 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
378 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
382 wxCommandEvent sraddenv(SE_ADDRESULT);
383 sraddenv.SetClientData(sradd);
384 wxPostEvent(this, sraddenv);
394 } else if (SelOpt == 1 || SelOpt == 5 || SelOpt == 9){
396 // Matching string that ends with...
400 // Check the forename.
402 if (NameArray.Forename.Right(StrOptLen) == StrOpt){
404 if (CheckDuplicate(vcardfilenamewxs,
406 &SearchResultAccount,
407 &SearchResultFilename) == TRUE){
413 ArrayData.PropData.Clear();
414 ArrayData.PropValues.Clear();
415 ArrayData.PropCount = 0;
420 SRNotif *sradd = new SRNotif;
421 sradd->ContactName = NameArray;
422 sradd->ContactNickname = ContactFinalNickname;
423 sradd->ContactAccount = SAPiter->second;
424 sradd->ContactAccountName = SALiter->second;
425 sradd->ContactFullFilename = vcardfilenamewxs;
426 sradd->SearchResultID = intResultFound;
428 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
429 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
433 wxCommandEvent sraddenv(SE_ADDRESULT);
434 sraddenv.SetClientData(sradd);
435 wxPostEvent(this, sraddenv);
439 } else if (SelOpt == 5){
441 if (NameArray.Surname.Right(StrOptLen) == StrOpt){
443 if (CheckDuplicate(vcardfilenamewxs,
445 &SearchResultAccount,
446 &SearchResultFilename) == TRUE){
452 ArrayData.PropData.Clear();
453 ArrayData.PropValues.Clear();
454 ArrayData.PropCount = 0;
459 SRNotif *sradd = new SRNotif;
460 sradd->ContactName = NameArray;
461 sradd->ContactNickname = ContactFinalNickname;
462 sradd->ContactAccount = SAPiter->second;
463 sradd->ContactAccountName = SALiter->second;
464 sradd->ContactFullFilename = vcardfilenamewxs;
465 sradd->SearchResultID = intResultFound;
467 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
468 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
472 wxCommandEvent sraddenv(SE_ADDRESULT);
473 sraddenv.SetClientData(sradd);
474 wxPostEvent(this, sraddenv);
478 } else if (SelOpt == 9){
480 wxString NicknameData;
482 for (int i = 0; i < NicknameArrayData.PropCount; i++){
484 NicknameData = NicknameArrayData.PropValues[i];
487 if (NicknameData.Right(StrOptLen) == StrOpt){
489 if (CheckDuplicate(vcardfilenamewxs,
491 &SearchResultAccount,
492 &SearchResultFilename) == TRUE){
498 ArrayData.PropData.Clear();
499 ArrayData.PropValues.Clear();
500 ArrayData.PropCount = 0;
505 SRNotif *sradd = new SRNotif;
506 sradd->ContactName = NameArray;
507 sradd->ContactNickname = ContactFinalNickname;
508 sradd->ContactAccount = SAPiter->second;
509 sradd->ContactAccountName = SALiter->second;
510 sradd->ContactFullFilename = vcardfilenamewxs;
511 sradd->SearchResultID = intResultFound;
513 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
514 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
518 wxCommandEvent sraddenv(SE_ADDRESULT);
519 sraddenv.SetClientData(sradd);
520 wxPostEvent(this, sraddenv);
530 } else if (SelOpt == 2 || SelOpt == 6 || SelOpt == 10){
532 // Matching string that contains...
536 if (NameArray.Forename.Find(StrOpt) != wxNOT_FOUND){
538 if (CheckDuplicate(vcardfilenamewxs,
540 &SearchResultAccount,
541 &SearchResultFilename) == TRUE){
547 ArrayData.PropData.Clear();
548 ArrayData.PropValues.Clear();
549 ArrayData.PropCount = 0;
554 SRNotif *sradd = new SRNotif;
555 sradd->ContactName = NameArray;
556 sradd->ContactNickname = ContactFinalNickname;
557 sradd->ContactAccount = SAPiter->second;
558 sradd->ContactAccountName = SALiter->second;
559 sradd->ContactFullFilename = vcardfilenamewxs;
560 sradd->SearchResultID = intResultFound;
562 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
563 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
567 wxCommandEvent sraddenv(SE_ADDRESULT);
568 sraddenv.SetClientData(sradd);
569 wxPostEvent(this, sraddenv);
573 } else if (SelOpt == 6){
575 if (NameArray.Surname.Find(StrOpt) != wxNOT_FOUND){
577 if (CheckDuplicate(vcardfilenamewxs,
579 &SearchResultAccount,
580 &SearchResultFilename) == TRUE){
586 ArrayData.PropData.Clear();
587 ArrayData.PropValues.Clear();
588 ArrayData.PropCount = 0;
593 SRNotif *sradd = new SRNotif;
594 sradd->ContactName = NameArray;
595 sradd->ContactNickname = ContactFinalNickname;
596 sradd->ContactAccount = SAPiter->second;
597 sradd->ContactAccountName = SALiter->second;
598 sradd->ContactFullFilename = vcardfilenamewxs;
599 sradd->SearchResultID = intResultFound;
601 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
602 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
606 wxCommandEvent sraddenv(SE_ADDRESULT);
607 sraddenv.SetClientData(sradd);
608 wxPostEvent(this, sraddenv);
612 } else if (SelOpt == 10){
614 wxString NicknameData;
616 for (int i = 0; i < NicknameArrayData.PropCount; i++){
618 NicknameData = NicknameArrayData.PropValues[i];
621 if (NicknameData.Find(StrOpt) != wxNOT_FOUND){
623 if (CheckDuplicate(vcardfilenamewxs,
625 &SearchResultAccount,
626 &SearchResultFilename) == TRUE){
632 ArrayData.PropData.Clear();
633 ArrayData.PropValues.Clear();
634 ArrayData.PropCount = 0;
639 SRNotif *sradd = new SRNotif;
640 sradd->ContactName = NameArray;
641 sradd->ContactNickname = ContactFinalNickname;
642 sradd->ContactAccount = SAPiter->second;
643 sradd->ContactAccountName = SALiter->second;
644 sradd->ContactFullFilename = vcardfilenamewxs;
645 sradd->SearchResultID = intResultFound;
647 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
648 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
652 wxCommandEvent sraddenv(SE_ADDRESULT);
653 sraddenv.SetClientData(sradd);
654 wxPostEvent(this, sraddenv);
664 } else if (SelOpt == 3 || SelOpt == 7 || SelOpt == 11){
666 // Matching String that doesn't contain...
670 // Process the nickname data.
672 if (NameArray.Forename.Find(StrOpt) == wxNOT_FOUND){
674 if (CheckDuplicate(vcardfilenamewxs,
676 &SearchResultAccount,
677 &SearchResultFilename) == TRUE){
683 ArrayData.PropData.Clear();
684 ArrayData.PropValues.Clear();
685 ArrayData.PropCount = 0;
690 SRNotif *sradd = new SRNotif;
691 sradd->ContactName = NameArray;
692 sradd->ContactNickname = ContactFinalNickname;
693 sradd->ContactAccount = SAPiter->second;
694 sradd->ContactAccountName = SALiter->second;
695 sradd->ContactFullFilename = vcardfilenamewxs;
696 sradd->SearchResultID = intResultFound;
698 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
699 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
703 wxCommandEvent sraddenv(SE_ADDRESULT);
704 sraddenv.SetClientData(sradd);
705 wxPostEvent(this, sraddenv);
709 } else if (SelOpt == 7){
711 if (!NameArray.Surname.Find(StrOpt) == wxNOT_FOUND){
713 if (CheckDuplicate(vcardfilenamewxs,
715 &SearchResultAccount,
716 &SearchResultFilename) == TRUE){
722 ArrayData.PropData.Clear();
723 ArrayData.PropValues.Clear();
724 ArrayData.PropCount = 0;
729 SRNotif *sradd = new SRNotif;
730 sradd->ContactName = NameArray;
731 sradd->ContactNickname = ContactFinalNickname;
732 sradd->ContactAccount = SAPiter->second;
733 sradd->ContactAccountName = SALiter->second;
734 sradd->ContactFullFilename = vcardfilenamewxs;
735 sradd->SearchResultID = intResultFound;
737 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
738 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
742 wxCommandEvent sraddenv(SE_ADDRESULT);
743 sraddenv.SetClientData(sradd);
744 wxPostEvent(this, sraddenv);
748 } else if (SelOpt == 11){
750 wxString NicknameData;
752 for (int i = 0; i < NicknameArrayData.PropCount; i++){
754 NicknameData = NicknameArrayData.PropValues[i];
757 if (NicknameData.Find(StrOpt) == wxNOT_FOUND){
759 if (CheckDuplicate(vcardfilenamewxs,
761 &SearchResultAccount,
762 &SearchResultFilename) == TRUE){
768 ArrayData.PropData.Clear();
769 ArrayData.PropValues.Clear();
770 ArrayData.PropCount = 0;
775 SRNotif *sradd = new SRNotif;
776 sradd->ContactName = NameArray;
777 sradd->ContactNickname = ContactFinalNickname;
778 sradd->ContactAccount = SAPiter->second;
779 sradd->ContactAccountName = SALiter->second;
780 sradd->ContactFullFilename = vcardfilenamewxs;
781 sradd->SearchResultID = intResultFound;
783 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
784 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
788 wxCommandEvent sraddenv(SE_ADDRESULT);
789 sraddenv.SetClientData(sradd);
790 wxPostEvent(this, sraddenv);
804 chkOpt = XABSPPtr->GetCheckboxSetting();
808 // Search should check if it has a photo or not.
810 ArrayData = Person.GetByPartial(wxT("PHOTO"));
812 if ((ArrayData.PropCount >= 1 &&
814 (ArrayData.PropCount == 0 &&
817 if (CheckDuplicate(vcardfilenamewxs,
819 &SearchResultAccount,
820 &SearchResultFilename) == TRUE){
826 ArrayData.PropData.Clear();
827 ArrayData.PropValues.Clear();
828 ArrayData.PropCount = 0;
833 SRNotif *sradd = new SRNotif;
835 sradd->ContactName = NameArray;
836 sradd->ContactNickname = ContactFinalNickname;
837 sradd->ContactAccount = SAPiter->second;
838 sradd->ContactAccountName = SALiter->second;
839 sradd->ContactFullFilename = vcardfilenamewxs;
840 sradd->SearchResultID = intResultFound;
842 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
843 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
847 wxCommandEvent sraddenv(SE_ADDRESULT);
848 sraddenv.SetClientData(sradd);
849 wxPostEvent(this, sraddenv);
853 } else if (SelOpt == 13){
855 // Search should check if it has a logo or not.
857 ArrayData = Person.GetByPartial(wxT("LOGO"));
859 if ((ArrayData.PropCount >= 1 &&
861 (ArrayData.PropCount == 0 &&
864 if (CheckDuplicate(vcardfilenamewxs,
866 &SearchResultAccount,
867 &SearchResultFilename) == TRUE){
873 ArrayData.PropData.Clear();
874 ArrayData.PropValues.Clear();
875 ArrayData.PropCount = 0;
880 SRNotif *sradd = new SRNotif;
882 sradd->ContactName = NameArray;
883 sradd->ContactNickname = ContactFinalNickname;
884 sradd->ContactAccount = SAPiter->second;
885 sradd->ContactAccountName = SALiter->second;
886 sradd->ContactFullFilename = vcardfilenamewxs;
887 sradd->SearchResultID = intResultFound;
889 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
890 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
894 wxCommandEvent sraddenv(SE_ADDRESULT);
895 sraddenv.SetClientData(sradd);
896 wxPostEvent(this, sraddenv);
900 } else if (SelOpt == 14){
902 // Search should check if it has sound or not.
904 ArrayData = Person.GetByPartial(wxT("SOUND"));
906 if ((ArrayData.PropCount >= 1 &&
908 (ArrayData.PropCount == 0 &&
911 if (CheckDuplicate(vcardfilenamewxs,
913 &SearchResultAccount,
914 &SearchResultFilename) == TRUE){
920 ArrayData.PropData.Clear();
921 ArrayData.PropValues.Clear();
922 ArrayData.PropCount = 0;
927 SRNotif *sradd = new SRNotif;
929 sradd->ContactName = NameArray;
930 sradd->ContactNickname = ContactFinalNickname;
931 sradd->ContactAccount = SAPiter->second;
932 sradd->ContactAccountName = SALiter->second;
933 sradd->ContactFullFilename = vcardfilenamewxs;
934 sradd->SearchResultID = intResultFound;
936 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
937 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
941 wxCommandEvent sraddenv(SE_ADDRESULT);
942 sraddenv.SetClientData(sradd);
943 wxPostEvent(this, sraddenv);
955 ArrayData.PropData.Clear();
956 ArrayData.PropValues.Clear();
957 ArrayData.PropCount = 0;
967 vCardFilename.Clear();
968 vCardFilenameFull.Clear();
969 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
979 // Finished searching... clear up.
981 wxCommandEvent sbfinstr (SE_SBUPDATE);
983 wxString *SBFinish = new wxString;
985 if (intResultFound == 0){
987 *SBFinish = _("No contacts found.");
989 } else if (intResultFound == 1){
991 *SBFinish = _("1 contact found.");
995 *SBFinish = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
999 sbfinstr.SetClientData(SBFinish);
1000 wxPostEvent(this, sbfinstr);
1002 wxCommandEvent sbfinish (SE_SEARCHFINISHED);
1003 wxPostEvent(this, sbfinish);
1007 void frmSearch::SearchContacts( wxCommandEvent& event )
1010 // Change the button to stop.
1012 if (StopMode == FALSE){
1014 // Clear the list of search results.
1016 lstResults->DeleteAllItems();
1017 SearchResultAccount.clear();
1018 SearchResultFilename.clear();
1020 // Button clicked on as 'Search'.
1022 DisableAllSearchSettings(TRUE);
1024 btnSearch->SetLabel(_("Stop"));
1026 // Spawn a thread so that searching can proceed
1027 // without blocking the GUI (and allow the
1028 // search to stop when needed).
1030 std::thread SearchThread(&frmSearch::SearchContactsThread, this);
1031 SearchThread.detach();
1035 // Button clicked on as 'Stop'.
1038 btnSearch->SetLabel(_("Search"));
1039 DisableAllSearchSettings(FALSE);
1045 void frmSearch::ResetContacts( wxCommandEvent& event )
1048 // Clear all the search settings.
1050 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1051 iter != SearchFrames.end(); ++iter){
1053 XABSearchPanel *XABSPPtr;
1055 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1056 szrSearch->Detach(XABSPPtr);
1058 // Remove the frame from the memory and the list.
1063 SearchFrames.erase(iter->first);
1067 // Clear the list of search results.
1069 lstResults->DeleteAllItems();
1071 // Clear the account settings.
1073 for (std::map<wxString, bool>::iterator iter = SearchAccounts.begin();
1074 iter != SearchAccounts.end(); iter++){
1076 iter->second = TRUE;
1080 // Add a search settings with the default things.
1084 XABSearchPanel *NewPanel = new XABSearchPanel( tabSearch );
1085 NewPanel->EnableButtons(TRUE, FALSE);
1086 NewPanel->SetupPointers(this);
1087 NewPanel->SetupInteger(ScrollGen);
1088 szrSearch->Add(NewPanel, 1, wxEXPAND, 0);
1089 szrSearch->Fit(tabSearch);
1090 SearchFrames.insert(std::make_pair(ScrollGen, NewPanel));
1095 void frmSearch::AddSearchSetting( wxCommandEvent& event )
1098 // Add a search setting frame to the list.
1100 XABSearchPanel *NewPanel = new XABSearchPanel( tabSearch );
1101 NewPanel->EnableButtons(TRUE, TRUE);
1102 NewPanel->SetupPointers(this);
1103 NewPanel->SetupInteger(ScrollGen);
1104 szrSearch->Add(NewPanel, 1, wxEXPAND|wxGROW, 5);
1105 //szrSearch->Fit(tabSearch);
1106 szrSearch->FitInside(tabSearch);
1107 szrSearch->Layout();
1108 szrSearch->RecalcSizes();
1109 tabSearch->Layout();
1110 SearchFrames.insert(std::make_pair(ScrollGen, NewPanel));
1113 // Check if number of search settings is 15 (or over).
1114 // If it is, disable the option of adding extra settings
1115 // for all frames until one is removed.
1117 XABSearchPanel *XABSPPtr;
1119 if (SearchFrames.size() >= 15){
1121 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1122 iter != SearchFrames.end(); ++iter){
1124 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1126 XABSPPtr->EnableButtons(FALSE, TRUE);
1130 } else if (SearchFrames.size() >= 2){
1132 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1133 iter != SearchFrames.end(); ++iter){
1135 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1137 XABSPPtr->EnableButtons(TRUE, TRUE);
1143 //tabSearch->SetScrollbar(wxVERTICAL, 32768, 25, 32768, false);
1144 tabSearch->Update();
1145 //tabSearch->ScrollToLine(tabSearch->GetLineCount());
1149 void frmSearch::RemoveSearchSetting( wxCommandEvent& event )
1152 // Get the integer from the event.
1154 std::map<int,void*>::iterator iter;
1155 iter = SearchFrames.find(event.GetInt());
1157 // Remove a search setting frame from the list.
1159 XABSearchPanel *XABSPPtr;
1160 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1162 szrSearch->Detach(XABSPPtr);
1164 // Remove the frame from the memory and the list.
1166 SearchFrames.erase(event.GetInt());
1171 //szrSearch->Fit(tabSearch);
1173 if (SearchFrames.size() < 15 && SearchFrames.size() > 1){
1175 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1176 iter != SearchFrames.end(); ++iter){
1178 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1180 XABSPPtr->EnableButtons(TRUE, TRUE);
1184 } else if (SearchFrames.size() == 1){
1186 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1187 iter != SearchFrames.end(); ++iter){
1189 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1191 XABSPPtr->EnableButtons(TRUE, FALSE);
1197 szrSearch->FitInside(tabSearch);
1198 szrSearch->Layout();
1199 szrSearch->RecalcSizes();
1200 tabSearch->Layout();
1204 void frmSearch::ReloadAccountList( wxCommandEvent& event ){
1206 // Currently unimplemented.
1210 void frmSearch::AddResult( wxCommandEvent& event ){
1212 SRNotif *srnotif = (SRNotif*)event.GetClientData();
1214 // Process Data and add to the list of results.
1218 // Setup the contact name.
1220 wxString ContactNameFinal;
1222 if (!srnotif->ContactName.Title.IsEmpty()){
1224 ContactNameFinal.append(srnotif->ContactName.Title);
1225 ContactNameFinal.Trim();
1226 ContactNameFinal.append(wxT(" "));
1230 if (!srnotif->ContactName.Forename.IsEmpty()){
1232 ContactNameFinal.append(srnotif->ContactName.Forename);
1233 ContactNameFinal.Trim();
1234 ContactNameFinal.append(wxT(" "));
1238 if (!srnotif->ContactName.Surname.IsEmpty()){
1240 ContactNameFinal.append(srnotif->ContactName.Surname);
1241 ContactNameFinal.Trim();
1242 ContactNameFinal.append(wxT(" "));
1246 if (!srnotif->ContactName.Suffix.IsEmpty()){
1248 ContactNameFinal.append(srnotif->ContactName.Suffix);
1249 ContactNameFinal.Trim();
1254 item.SetText(ContactNameFinal);
1255 item.SetData(srnotif->SearchResultID);
1257 long ListCtrlIndex = lstResults->InsertItem(item);
1259 //SearchResultAccount.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactAccount));
1260 //SearchResultFilename.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactFullFilename));
1262 srnotif->ContactNickname.Trim();
1264 lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname);
1265 lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName);
1272 void frmSearch::SearchBarUpdate( wxCommandEvent& event ){
1274 wxString *SBData = (wxString*)event.GetClientData();
1276 stbBottom->SetStatusText(*SBData, 0);
1283 void frmSearch::SearchFinished( wxCommandEvent& event ){
1286 btnSearch->SetLabel(_("Search"));
1287 DisableAllSearchSettings(FALSE);
1291 void frmSearch::DisableAllSearchSettings(bool Enable){
1293 for (std::map<int, void*>::iterator siter = SearchFrames.begin();
1294 siter != SearchFrames.end(); siter++){
1296 XABSearchPanel *XABSPPtr = static_cast<XABSearchPanel*>(siter->second);
1298 if (Enable == FALSE){
1300 wxCommandEvent enboxes(XABSP_ENABLECONTROLS);
1301 wxPostEvent(XABSPPtr, enboxes);
1303 } else if (Enable == TRUE){
1305 wxCommandEvent disboxes(XABSP_DISABLECONTROLS);
1306 wxPostEvent(XABSPPtr, disboxes);
1314 void frmSearch::OpenContact( wxCommandEvent& event ){
1316 // Check if a contact has been selected.
1318 long intSelected = -1;
1319 int intSelectedData = 0;
1320 long intContactSeekNum = -1;
1322 intSelected = lstResults->GetNextItem(intSelected,
1324 wxLIST_STATE_SELECTED);
1326 if (intSelected == -1){
1330 intContactSeekNum = lstResults->GetItemData(intSelected);
1332 if (SearchMode == TRUE){
1334 wxMessageBox(SearchResultFilename[intContactSeekNum]);
1338 Person.LoadFile(SearchResultFilename[intContactSeekNum]);
1340 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1341 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1342 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1344 contacticon.CopyFromBitmap(contacticonbmp);
1346 frmContact *Contact = new frmContact( this );
1348 Contact->SetupPointers(&SearchModeMemoryFSPtr);
1349 Contact->SetupContactData(&Person);
1351 Contact->SetIcon(contacticon);
1352 Contact->Show(true);
1356 UCNotif *uc = new UCNotif;
1358 uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1359 uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1361 wxCommandEvent oc(CE_OPENCONTACT);
1362 oc.SetClientData(uc);
1363 wxPostEvent(this->GetParent(), oc);
1369 void frmSearch::EditContact( wxCommandEvent& event ){
1371 // Check if a contact has been selected.
1373 long intSelected = -1;
1374 int intSelectedData = 0;
1375 long intContactSeekNum = -1;
1377 intSelected = lstResults->GetNextItem(intSelected,
1379 wxLIST_STATE_SELECTED);
1381 if (intSelected == -1){
1385 intContactSeekNum = lstResults->GetItemData(intSelected);
1387 UCNotif *uc = new UCNotif;
1389 uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1390 uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1392 wxCommandEvent ec(CE_EDITCONTACT);
1393 ec.SetClientData(uc);
1395 wxPostEvent(this->GetParent(), ec);
1399 void frmSearch::RevealContact( wxCommandEvent& event ){
1401 // Check if a contact has been selected.
1403 long intSelected = -1;
1404 int intSelectedData = 0;
1405 long intContactSeekNum = -1;
1407 intSelected = lstResults->GetNextItem(intSelected,
1409 wxLIST_STATE_SELECTED);
1411 if (intSelected == -1){
1415 intContactSeekNum = lstResults->GetItemData(intSelected);
1417 UCNotif *uc = new UCNotif;
1419 uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1420 uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1422 wxCommandEvent rc(CE_REVEALCONTACT);
1423 rc.SetClientData(uc);
1425 wxPostEvent(this->GetParent(), rc);
1429 void frmSearch::CloseWindow( wxCloseEvent& event ){
1431 // Hide the window so users don't panic
1432 // whilst clearing up.
1438 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1439 iter != SearchFrames.end(); ++iter){
1441 XABSearchPanel *XABSPPtr;
1443 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1444 szrSearch->Detach(XABSPPtr);
1446 // Remove the frame from the memory and the list.
1453 SearchFrames.clear();
1457 WindowData *WData = new WindowData;
1459 WData->DataType = 2;
1460 WData->WindowPointer = this;
1461 WData->WindowID = SearchUID;
1463 wxCommandEvent delevent(WINDOW_CLOSE);
1464 delevent.SetClientData(WData);
1465 wxPostEvent(GetParent(), delevent);
1467 wxCommandEvent rs(CE_REMOVESEARCH);
1468 wxPostEvent(this, rs);
1476 void frmSearch::CloseWindow( wxCommandEvent& event ){
1482 void frmSearch::UpdateResult( wxCommandEvent& event ){
1484 UCNotif *uc = (UCNotif*)event.GetClientData();
1486 long longSelected = -1;
1487 int intSelectedData = 0;
1491 longSelected = lstResults->GetNextItem(longSelected,
1493 wxLIST_STATE_DONTCARE);
1495 if (longSelected == -1){
1501 // Get the filename/ID information.
1503 intSelectedData = lstResults->GetItemData(longSelected);
1505 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
1507 // Process the contact name
1509 wxString ContactNameFinal;
1511 if (!uc->ContactNameArray.Title.IsEmpty()){
1513 ContactNameFinal.append(uc->ContactNameArray.Title);
1514 ContactNameFinal.Trim();
1515 ContactNameFinal.append(wxT(" "));
1519 if (!uc->ContactNameArray.Forename.IsEmpty()){
1521 ContactNameFinal.append(uc->ContactNameArray.Forename);
1522 ContactNameFinal.Trim();
1523 ContactNameFinal.append(wxT(" "));
1527 if (!uc->ContactNameArray.Surname.IsEmpty()){
1529 ContactNameFinal.append(uc->ContactNameArray.Surname);
1530 ContactNameFinal.Trim();
1531 ContactNameFinal.append(wxT(" "));
1535 if (!uc->ContactNameArray.Suffix.IsEmpty()){
1537 ContactNameFinal.append(uc->ContactNameArray.Suffix);
1538 ContactNameFinal.Trim();
1542 lstResults->SetItem(longSelected, 0, ContactNameFinal);
1543 lstResults->SetItem(longSelected, 1, uc->ContactNickname);
1554 bool frmSearch::CheckDuplicate(wxString Filename,
1556 std::map<long,wxString> *SRAcc,
1557 std::map<long,wxString> *SRFN){
1559 std::map<long,wxString>::iterator fniter;
1561 // Check comparison code.
1563 for (std::map<long,wxString>::iterator aciter = SRAcc->begin();
1564 aciter != SRAcc->end(); aciter++){
1566 fniter = SRFN->find(aciter->first);
1568 if (Filename == fniter->second &&
1569 Account == aciter->second){
1581 void frmSearch::DeleteResult(wxCommandEvent &event){
1583 UCNotif *uc = (UCNotif*)event.GetClientData();
1585 long longSelected = -1;
1586 int intSelectedData = 0;
1590 longSelected = lstResults->GetNextItem(longSelected,
1592 wxLIST_STATE_DONTCARE);
1594 if (longSelected == -1){
1600 // Get the filename/ID information.
1602 intSelectedData = lstResults->GetItemData(longSelected);
1604 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
1606 // Delete the result from the search list and
1607 // update the total search results.
1609 // Remove DeleteResultEvent and find out where the uc
1610 // data is still being used as it crashes on delete.
1612 lstResults->DeleteItem(longSelected);
1614 // Update the number of search results.
1616 wxCommandEvent sbu(SE_SBUPDATE);
1617 wxString *SBUpdate = new wxString;
1619 // Get the number of results.
1621 int intResultFound = lstResults->GetItemCount();
1623 // Prepare the status bar message.
1625 if (intResultFound == 0){
1627 *SBUpdate = _("No contacts found.");
1629 } else if (intResultFound == 1){
1631 *SBUpdate = _("1 contact found.");
1635 *SBUpdate = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
1639 sbu.SetClientData(SBUpdate);
1640 wxPostEvent(this, sbu);
1653 void frmSearch::SetUID(int UID){
1659 void frmSearch::SetSearchMode(bool SearchModeIn){
1661 SearchMode = SearchModeIn;
1663 if (SearchMode == TRUE){
1665 mnuContactEdit->Enable(FALSE);
1666 mnuContactReveal->Enable(FALSE);
1668 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1671 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1672 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1673 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1675 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1676 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1677 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1679 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1680 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1681 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1683 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1684 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1685 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1687 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1688 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1689 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1691 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1692 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1693 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1697 mnuContactEdit->Enable(TRUE);
1698 mnuContactReveal->Enable(TRUE);
1704 void frmSearch::ShowContactMenu( wxMouseEvent& event ){
1706 ContactMenu->SetupPointers(this, lstResults);
1708 PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);