3 #include "search/XABSearchPanel.h"
4 #include "search/frmSearchAccounts.h"
5 #include "common/preferences.h"
6 #include "common/dirs.h"
7 #include "vcard/vcard.h"
10 /*#include <boost/filesystem.hpp>
11 #include <boost/filesystem/fstream.hpp>
12 #include <boost/filesystem/path.hpp>*/
13 #include <wx/tokenzr.h>
16 DEFINE_EVENT_TYPE(SE_ADDSEARCHSETTING);
17 DEFINE_EVENT_TYPE(SE_REMOVESEARCHSETTING);
18 DEFINE_EVENT_TYPE(SE_RELOADACCOUNTS);
19 DEFINE_EVENT_TYPE(SE_ADDRESULT);
20 DEFINE_EVENT_TYPE(SE_SBUPDATE);
21 DEFINE_EVENT_TYPE(SE_SEARCHFINISHED);
22 DEFINE_EVENT_TYPE(SE_UPDATERESULT);
23 DEFINE_EVENT_TYPE(SE_DELETERESULT);
25 BEGIN_EVENT_TABLE(frmSearch, wxFrame)
26 EVT_COMMAND(wxID_ANY, SE_ADDSEARCHSETTING, frmSearch::AddSearchSetting)
27 EVT_COMMAND(wxID_ANY, SE_REMOVESEARCHSETTING, frmSearch::RemoveSearchSetting)
28 EVT_COMMAND(wxID_ANY, SE_RELOADACCOUNTS, frmSearch::ReloadAccountList)
29 EVT_COMMAND(wxID_ANY, SE_ADDRESULT, frmSearch::AddResult)
30 EVT_COMMAND(wxID_ANY, SE_SBUPDATE, frmSearch::SearchBarUpdate)
31 EVT_COMMAND(wxID_ANY, SE_SEARCHFINISHED, frmSearch::SearchFinished)
32 EVT_COMMAND(wxID_ANY, SE_UPDATERESULT, frmSearch::UpdateResult)
33 EVT_COMMAND(wxID_ANY, SE_DELETERESULT, frmSearch::DeleteResult)
36 //namespace boostfs = boost::filesystem;
38 frmSearch::frmSearch( wxWindow* parent )
40 frmSearchADT( parent )
43 XABSearchPanel *InitPanel = new XABSearchPanel( tabSearch );
44 InitPanel->EnableButtons(TRUE, FALSE);
45 InitPanel->SetupPointers(this);
46 InitPanel->SetupInteger(ScrollGen);
47 szrSearch->Add(InitPanel, 1, wxEXPAND, 0);
48 szrSearch->Fit(tabSearch);
49 SearchFrames.insert(std::make_pair(ScrollGen, InitPanel));
52 // Get the list of accounts and mark them as true.
54 wxString preffilename = GetUserPrefDir();
56 XABPreferences preferences(preffilename);
60 wxString AccDirFullSfx;
62 for (int i = 0; i < preferences.accounts.GetCount(); i++){
63 AccDir = preferences.accounts.GetAccountDirectory(i);
64 AccDirFull = preferences.accounts.GetAccountDirectory(i);
66 AccDirFull.Append(wxT("."));
67 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
68 AccDirFullSfx.LowerCase();
70 AccDirFull.Append(AccDirFullSfx);
71 SearchAccountsPaths.insert(std::make_pair(AccDir, AccDirFull));
72 SearchAccounts.insert(std::make_pair(AccDir, TRUE));
73 SearchAccountsNames.insert(std::make_pair(AccDir,
74 preferences.accounts.GetAccountName(i)));
76 AccDirFullSfx.clear();
84 item.SetText(_("Name"));
87 lstResults->InsertColumn(0, item);
90 item.SetText(_("Nickname"));
93 lstResults->InsertColumn(1, item);
96 item.SetText(_("Account"));
99 lstResults->InsertColumn(2, item);
103 void frmSearch::SelectAccounts( wxCommandEvent& event )
106 // Create the form and display as modal.
108 frmSearchAccounts *frameSAccount = new frmSearchAccounts ( this );
109 frameSAccount->LoadSearchAccounts(&SearchAccounts, &SearchAccountsNames);
110 frameSAccount->ShowModal();
111 delete frameSAccount;
112 frameSAccount = NULL;
116 void frmSearch::SearchContactsThread(){
118 // Go through each account and find contacts based on the
121 std::map<wxString,bool>::iterator SAiter;
122 std::map<wxString,wxString>::iterator SAPiter;
123 int intResultFound = 0;
125 for (std::map<wxString, wxString>::iterator SALiter = SearchAccountsNames.begin();
126 SALiter != SearchAccountsNames.end();
129 // Double check that we are searching in this account.
130 // If not, skip to the next one.
132 SAiter = SearchAccounts.find(SALiter->first);
133 SAPiter = SearchAccountsPaths.find(SAiter->first);
136 if (SAiter->second == FALSE){
138 // Not looking in this account. Go to next account.
144 wxCommandEvent sbupdate (SE_SBUPDATE);
146 wxString *SBData = new wxString;
147 *SBData = _("Searching ") + SALiter->second + _("...");
149 sbupdate.SetClientData(SBData);
150 wxPostEvent(this, sbupdate);
152 if (StopMode == FALSE){
154 wxCommandEvent sbstop (SE_SBUPDATE);
156 wxString *SBStopStr = new wxString;
157 *SBStopStr = _("Search stopped.");
159 sbstop.SetClientData(SBStopStr);
160 wxPostEvent(this, sbstop);
165 // Get the list of contact files and process each
168 wxString AccountDir = GetAccountDir(SAPiter->second, FALSE);
170 //boostfs::path vcarddir(AccountDir.c_str());
171 //boostfs::directory_iterator dir_end;
173 //boostfs::path vcardfilename;
174 wxString vcardfilenamewxs;
175 wxStringTokenizer vcardfileline;
178 wxString setname, setvalue;
179 long ContactIndex = 1;
180 long ContactSeekPoint = 0;
181 wxString vCardFilename;
182 wxString vCardFilenameFull;
184 //if (boostfs::exists(vcarddir)){
185 if (wxDirExists(AccountDir)){
187 wxDir vcardaccdir(AccountDir);
189 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
191 //for (boostfs::directory_iterator vcarddir_iter(vcarddir);
192 // vcarddir_iter != dir_end ; ++vcarddir_iter){
194 if (StopMode == FALSE){
196 wxCommandEvent sbstop(SE_SBUPDATE);
198 wxString *SBStopStr = new wxString;
199 *SBStopStr = _("Search stopped.");
201 sbstop.SetClientData(SBStopStr);
202 wxPostEvent(this, sbstop);
207 if (vCardFilename.Right(4) == wxT(".vcf") ||
208 vCardFilename.Right(4) == wxT(".VCF") ||
209 vCardFilename.Right(5) == wxT(".vcard") ||
210 vCardFilename.Right(5) == wxT(".VCARD")){
213 vCardFilenameFull.Append(AccountDir);
214 vCardFilenameFull.Append(vCardFilename);
217 Person.LoadFile(vCardFilenameFull);
219 /*if (boostfs::path(vcarddir_iter->path()).extension() == ".vcf" ||
220 boostfs::path(vcarddir_iter->path()).extension() == ".VCF" ||
221 boostfs::path(vcarddir_iter->path()).extension() == ".vcard" ||
222 boostfs::path(vcarddir_iter->path()).extension() == ".VCARD"){*/
224 vcardfilenamewxs = vCardFilenameFull;
227 std::fstream vcardfile;
229 vcardfilename = boostfs::path(vcarddir_iter->path()).filename();
230 vcardfilenamewxs.Append(AccountDir);
231 vcardfilenamewxs.Append(wxString::FromUTF8(vcardfilename.c_str()));
233 // Open the vCard file up and get the setting names and values from the
236 vcardfile.open(vcardfilenamewxs.mb_str(), std::ios::in);
238 while(getline(vcardfile, l)){
243 lwxs.Append(wxString::FromUTF8(l.c_str()));
244 vcardfileline.SetString(lwxs, wxT(":"));
245 setname = vcardfileline.GetNextToken();
246 setvalue = vcardfileline.GetString();
248 Person.Add(setname, setvalue, TRUE);
254 // Check if file has version 4.0, first name (FN)
255 // begin and end vCard portions.
257 // Don't search unless these conditions have been met.
259 if (Person.MeetBaseSpecification()){
261 // Go through each of the search settings and check
262 // if they match with contact details.
264 // If it matches then add to the search results.
270 ArrayvCardOutData ArrayData;
271 ArrayvCardOutData NicknameArrayData;
272 vCardName NameArray = Person.GetName();
273 wxString ContactFinalNickname;
274 NicknameArrayData = Person.GetByPartial(wxT("NICKNAME"));
276 if (NicknameArrayData.PropCount != 0){
277 ContactFinalNickname = NicknameArrayData.PropValues[0];
280 for (std::map<int, void*>::iterator siter = SearchFrames.begin();
281 siter != SearchFrames.end(); siter++){
283 // Get the settings from the form.
285 XABSearchPanel *XABSPPtr = static_cast<XABSearchPanel*>(siter->second);
287 // Get Selected Option and Setting.
289 SelOpt = XABSPPtr->GetSelectionOption();
293 StrOpt = XABSPPtr->GetStringSetting();
294 StrOptLen = StrOpt.Len();
296 if (SelOpt == 0 || SelOpt == 4 || SelOpt == 8){
298 // Matching string that beings with...
300 // Double check the std::map inserts for each section.
304 // Get the forename from the first N.
306 if (NameArray.Forename.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 == 4){
345 if (NameArray.Surname.Mid(0, StrOptLen) == StrOpt){
347 if (CheckDuplicate(vcardfilenamewxs,
349 &SearchResultAccount,
350 &SearchResultFilename) == TRUE){
356 ArrayData.PropData.Clear();
357 ArrayData.PropValues.Clear();
358 ArrayData.PropCount = 0;
363 SRNotif *sradd = new SRNotif;
364 sradd->ContactName = NameArray;
365 sradd->ContactNickname = ContactFinalNickname;
366 sradd->ContactAccount = SAPiter->second;
367 sradd->ContactAccountName = SALiter->second;
368 sradd->ContactFullFilename = vcardfilenamewxs;
369 sradd->SearchResultID = intResultFound;
371 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
372 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
376 wxCommandEvent sraddenv(SE_ADDRESULT);
377 sraddenv.SetClientData(sradd);
378 wxPostEvent(this, sraddenv);
382 } else if (SelOpt == 8){
384 wxString NicknameData;
386 for (int i = 0; i < NicknameArrayData.PropCount; i++){
388 NicknameData = NicknameArrayData.PropValues[i];
390 if (NicknameData.Mid(0, StrOptLen) == StrOpt){
392 if (CheckDuplicate(vcardfilenamewxs,
394 &SearchResultAccount,
395 &SearchResultFilename) == TRUE){
401 ArrayData.PropData.Clear();
402 ArrayData.PropValues.Clear();
403 ArrayData.PropCount = 0;
408 SRNotif *sradd = new SRNotif;
409 sradd->ContactName = NameArray;
410 sradd->ContactNickname = ContactFinalNickname;
411 sradd->ContactAccount = SAPiter->second;
412 sradd->ContactAccountName = SALiter->second;
413 sradd->ContactFullFilename = vcardfilenamewxs;
414 sradd->SearchResultID = intResultFound;
416 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
417 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
421 wxCommandEvent sraddenv(SE_ADDRESULT);
422 sraddenv.SetClientData(sradd);
423 wxPostEvent(this, sraddenv);
433 } else if (SelOpt == 1 || SelOpt == 5 || SelOpt == 9){
435 // Matching string that ends with...
439 // Check the forename.
441 if (NameArray.Forename.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 == 5){
480 if (NameArray.Surname.Right(StrOptLen) == StrOpt){
482 if (CheckDuplicate(vcardfilenamewxs,
484 &SearchResultAccount,
485 &SearchResultFilename) == TRUE){
491 ArrayData.PropData.Clear();
492 ArrayData.PropValues.Clear();
493 ArrayData.PropCount = 0;
498 SRNotif *sradd = new SRNotif;
499 sradd->ContactName = NameArray;
500 sradd->ContactNickname = ContactFinalNickname;
501 sradd->ContactAccount = SAPiter->second;
502 sradd->ContactAccountName = SALiter->second;
503 sradd->ContactFullFilename = vcardfilenamewxs;
504 sradd->SearchResultID = intResultFound;
506 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
507 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
511 wxCommandEvent sraddenv(SE_ADDRESULT);
512 sraddenv.SetClientData(sradd);
513 wxPostEvent(this, sraddenv);
517 } else if (SelOpt == 9){
519 wxString NicknameData;
521 for (int i = 0; i < NicknameArrayData.PropCount; i++){
523 NicknameData = NicknameArrayData.PropValues[i];
526 if (NicknameData.Right(StrOptLen) == StrOpt){
528 if (CheckDuplicate(vcardfilenamewxs,
530 &SearchResultAccount,
531 &SearchResultFilename) == TRUE){
537 ArrayData.PropData.Clear();
538 ArrayData.PropValues.Clear();
539 ArrayData.PropCount = 0;
544 SRNotif *sradd = new SRNotif;
545 sradd->ContactName = NameArray;
546 sradd->ContactNickname = ContactFinalNickname;
547 sradd->ContactAccount = SAPiter->second;
548 sradd->ContactAccountName = SALiter->second;
549 sradd->ContactFullFilename = vcardfilenamewxs;
550 sradd->SearchResultID = intResultFound;
552 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
553 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
557 wxCommandEvent sraddenv(SE_ADDRESULT);
558 sraddenv.SetClientData(sradd);
559 wxPostEvent(this, sraddenv);
569 } else if (SelOpt == 2 || SelOpt == 6 || SelOpt == 10){
571 // Matching string that contains...
575 if (NameArray.Forename.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 == 6){
614 if (NameArray.Surname.Find(StrOpt) != wxNOT_FOUND){
616 if (CheckDuplicate(vcardfilenamewxs,
618 &SearchResultAccount,
619 &SearchResultFilename) == TRUE){
625 ArrayData.PropData.Clear();
626 ArrayData.PropValues.Clear();
627 ArrayData.PropCount = 0;
632 SRNotif *sradd = new SRNotif;
633 sradd->ContactName = NameArray;
634 sradd->ContactNickname = ContactFinalNickname;
635 sradd->ContactAccount = SAPiter->second;
636 sradd->ContactAccountName = SALiter->second;
637 sradd->ContactFullFilename = vcardfilenamewxs;
638 sradd->SearchResultID = intResultFound;
640 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
641 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
645 wxCommandEvent sraddenv(SE_ADDRESULT);
646 sraddenv.SetClientData(sradd);
647 wxPostEvent(this, sraddenv);
651 } else if (SelOpt == 10){
653 wxString NicknameData;
655 for (int i = 0; i < NicknameArrayData.PropCount; i++){
657 NicknameData = NicknameArrayData.PropValues[i];
660 if (NicknameData.Find(StrOpt) != wxNOT_FOUND){
662 if (CheckDuplicate(vcardfilenamewxs,
664 &SearchResultAccount,
665 &SearchResultFilename) == TRUE){
671 ArrayData.PropData.Clear();
672 ArrayData.PropValues.Clear();
673 ArrayData.PropCount = 0;
678 SRNotif *sradd = new SRNotif;
679 sradd->ContactName = NameArray;
680 sradd->ContactNickname = ContactFinalNickname;
681 sradd->ContactAccount = SAPiter->second;
682 sradd->ContactAccountName = SALiter->second;
683 sradd->ContactFullFilename = vcardfilenamewxs;
684 sradd->SearchResultID = intResultFound;
686 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
687 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
691 wxCommandEvent sraddenv(SE_ADDRESULT);
692 sraddenv.SetClientData(sradd);
693 wxPostEvent(this, sraddenv);
703 } else if (SelOpt == 3 || SelOpt == 7 || SelOpt == 11){
705 // Matching String that doesn't contain...
709 // Process the nickname data.
711 if (NameArray.Forename.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 == 7){
750 if (!NameArray.Surname.Find(StrOpt) == wxNOT_FOUND){
752 if (CheckDuplicate(vcardfilenamewxs,
754 &SearchResultAccount,
755 &SearchResultFilename) == TRUE){
761 ArrayData.PropData.Clear();
762 ArrayData.PropValues.Clear();
763 ArrayData.PropCount = 0;
768 SRNotif *sradd = new SRNotif;
769 sradd->ContactName = NameArray;
770 sradd->ContactNickname = ContactFinalNickname;
771 sradd->ContactAccount = SAPiter->second;
772 sradd->ContactAccountName = SALiter->second;
773 sradd->ContactFullFilename = vcardfilenamewxs;
774 sradd->SearchResultID = intResultFound;
776 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
777 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
781 wxCommandEvent sraddenv(SE_ADDRESULT);
782 sraddenv.SetClientData(sradd);
783 wxPostEvent(this, sraddenv);
787 } else if (SelOpt == 11){
789 wxString NicknameData;
791 for (int i = 0; i < NicknameArrayData.PropCount; i++){
793 NicknameData = NicknameArrayData.PropValues[i];
796 if (NicknameData.Find(StrOpt) == wxNOT_FOUND){
798 if (CheckDuplicate(vcardfilenamewxs,
800 &SearchResultAccount,
801 &SearchResultFilename) == TRUE){
807 ArrayData.PropData.Clear();
808 ArrayData.PropValues.Clear();
809 ArrayData.PropCount = 0;
814 SRNotif *sradd = new SRNotif;
815 sradd->ContactName = NameArray;
816 sradd->ContactNickname = ContactFinalNickname;
817 sradd->ContactAccount = SAPiter->second;
818 sradd->ContactAccountName = SALiter->second;
819 sradd->ContactFullFilename = vcardfilenamewxs;
820 sradd->SearchResultID = intResultFound;
822 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
823 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
827 wxCommandEvent sraddenv(SE_ADDRESULT);
828 sraddenv.SetClientData(sradd);
829 wxPostEvent(this, sraddenv);
843 chkOpt = XABSPPtr->GetCheckboxSetting();
847 // Search should check if it has a photo or not.
849 ArrayData = Person.GetByPartial(wxT("PHOTO"));
851 if ((ArrayData.PropCount >= 1 &&
853 (ArrayData.PropCount == 0 &&
856 if (CheckDuplicate(vcardfilenamewxs,
858 &SearchResultAccount,
859 &SearchResultFilename) == TRUE){
865 ArrayData.PropData.Clear();
866 ArrayData.PropValues.Clear();
867 ArrayData.PropCount = 0;
872 SRNotif *sradd = new SRNotif;
874 sradd->ContactName = NameArray;
875 sradd->ContactNickname = ContactFinalNickname;
876 sradd->ContactAccount = SAPiter->second;
877 sradd->ContactAccountName = SALiter->second;
878 sradd->ContactFullFilename = vcardfilenamewxs;
879 sradd->SearchResultID = intResultFound;
881 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
882 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
886 wxCommandEvent sraddenv(SE_ADDRESULT);
887 sraddenv.SetClientData(sradd);
888 wxPostEvent(this, sraddenv);
892 } else if (SelOpt == 13){
894 // Search should check if it has a logo or not.
896 ArrayData = Person.GetByPartial(wxT("LOGO"));
898 if ((ArrayData.PropCount >= 1 &&
900 (ArrayData.PropCount == 0 &&
903 if (CheckDuplicate(vcardfilenamewxs,
905 &SearchResultAccount,
906 &SearchResultFilename) == TRUE){
912 ArrayData.PropData.Clear();
913 ArrayData.PropValues.Clear();
914 ArrayData.PropCount = 0;
919 SRNotif *sradd = new SRNotif;
921 sradd->ContactName = NameArray;
922 sradd->ContactNickname = ContactFinalNickname;
923 sradd->ContactAccount = SAPiter->second;
924 sradd->ContactAccountName = SALiter->second;
925 sradd->ContactFullFilename = vcardfilenamewxs;
926 sradd->SearchResultID = intResultFound;
928 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
929 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
933 wxCommandEvent sraddenv(SE_ADDRESULT);
934 sraddenv.SetClientData(sradd);
935 wxPostEvent(this, sraddenv);
939 } else if (SelOpt == 14){
941 // Search should check if it has sound or not.
943 ArrayData = Person.GetByPartial(wxT("SOUND"));
945 if ((ArrayData.PropCount >= 1 &&
947 (ArrayData.PropCount == 0 &&
950 if (CheckDuplicate(vcardfilenamewxs,
952 &SearchResultAccount,
953 &SearchResultFilename) == TRUE){
959 ArrayData.PropData.Clear();
960 ArrayData.PropValues.Clear();
961 ArrayData.PropCount = 0;
966 SRNotif *sradd = new SRNotif;
968 sradd->ContactName = NameArray;
969 sradd->ContactNickname = ContactFinalNickname;
970 sradd->ContactAccount = SAPiter->second;
971 sradd->ContactAccountName = SALiter->second;
972 sradd->ContactFullFilename = vcardfilenamewxs;
973 sradd->SearchResultID = intResultFound;
975 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
976 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
980 wxCommandEvent sraddenv(SE_ADDRESULT);
981 sraddenv.SetClientData(sradd);
982 wxPostEvent(this, sraddenv);
994 ArrayData.PropData.Clear();
995 ArrayData.PropValues.Clear();
996 ArrayData.PropCount = 0;
1006 vCardFilename.Clear();
1007 vCardFilenameFull.Clear();
1008 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1018 // Finished searching... clear up.
1020 wxCommandEvent sbfinstr (SE_SBUPDATE);
1022 wxString *SBFinish = new wxString;
1024 if (intResultFound == 0){
1026 *SBFinish = _("No contacts found.");
1028 } else if (intResultFound == 1){
1030 *SBFinish = _("1 contact found.");
1034 *SBFinish = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
1038 sbfinstr.SetClientData(SBFinish);
1039 wxPostEvent(this, sbfinstr);
1041 wxCommandEvent sbfinish (SE_SEARCHFINISHED);
1042 wxPostEvent(this, sbfinish);
1046 void frmSearch::SearchContacts( wxCommandEvent& event )
1049 // Change the button to stop.
1051 if (StopMode == FALSE){
1053 // Clear the list of search results.
1055 lstResults->DeleteAllItems();
1056 SearchResultAccount.clear();
1057 SearchResultFilename.clear();
1059 // Button clicked on as 'Search'.
1061 DisableAllSearchSettings(TRUE);
1063 btnSearch->SetLabel(_("Stop"));
1065 // Spawn a thread so that searching can proceed
1066 // without blocking the GUI (and allow the
1067 // search to stop when needed).
1069 std::thread SearchThread(&frmSearch::SearchContactsThread, this);
1070 SearchThread.detach();
1074 // Button clicked on as 'Stop'.
1077 btnSearch->SetLabel(_("Search"));
1078 DisableAllSearchSettings(FALSE);
1084 void frmSearch::ResetContacts( wxCommandEvent& event )
1087 // Clear all the search settings.
1089 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1090 iter != SearchFrames.end(); ++iter){
1092 XABSearchPanel *XABSPPtr;
1094 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1095 szrSearch->Detach(XABSPPtr);
1097 // Remove the frame from the memory and the list.
1102 SearchFrames.erase(iter->first);
1106 // Clear the list of search results.
1108 lstResults->DeleteAllItems();
1110 // Clear the account settings.
1112 for (std::map<wxString, bool>::iterator iter = SearchAccounts.begin();
1113 iter != SearchAccounts.end(); iter++){
1115 iter->second = TRUE;
1119 // Add a search settings with the default things.
1123 XABSearchPanel *NewPanel = new XABSearchPanel( tabSearch );
1124 NewPanel->EnableButtons(TRUE, FALSE);
1125 NewPanel->SetupPointers(this);
1126 NewPanel->SetupInteger(ScrollGen);
1127 szrSearch->Add(NewPanel, 1, wxEXPAND, 0);
1128 szrSearch->Fit(tabSearch);
1129 SearchFrames.insert(std::make_pair(ScrollGen, NewPanel));
1134 void frmSearch::AddSearchSetting( wxCommandEvent& event )
1137 // Add a search setting frame to the list.
1139 XABSearchPanel *NewPanel = new XABSearchPanel( tabSearch );
1140 NewPanel->EnableButtons(TRUE, TRUE);
1141 NewPanel->SetupPointers(this);
1142 NewPanel->SetupInteger(ScrollGen);
1143 szrSearch->Add(NewPanel, 1, wxEXPAND|wxGROW, 5);
1144 //szrSearch->Fit(tabSearch);
1145 szrSearch->FitInside(tabSearch);
1146 szrSearch->Layout();
1147 szrSearch->RecalcSizes();
1148 tabSearch->Layout();
1149 SearchFrames.insert(std::make_pair(ScrollGen, NewPanel));
1152 // Check if number of search settings is 15 (or over).
1153 // If it is, disable the option of adding extra settings
1154 // for all frames until one is removed.
1156 XABSearchPanel *XABSPPtr;
1158 if (SearchFrames.size() >= 15){
1160 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1161 iter != SearchFrames.end(); ++iter){
1163 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1165 XABSPPtr->EnableButtons(FALSE, TRUE);
1169 } else if (SearchFrames.size() >= 2){
1171 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1172 iter != SearchFrames.end(); ++iter){
1174 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1176 XABSPPtr->EnableButtons(TRUE, TRUE);
1182 //tabSearch->SetScrollbar(wxVERTICAL, 32768, 25, 32768, false);
1183 tabSearch->Update();
1184 //tabSearch->ScrollToLine(tabSearch->GetLineCount());
1188 void frmSearch::RemoveSearchSetting( wxCommandEvent& event )
1191 // Get the integer from the event.
1193 std::map<int,void*>::iterator iter;
1194 iter = SearchFrames.find(event.GetInt());
1196 // Remove a search setting frame from the list.
1198 XABSearchPanel *XABSPPtr;
1199 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1201 szrSearch->Detach(XABSPPtr);
1203 // Remove the frame from the memory and the list.
1205 SearchFrames.erase(event.GetInt());
1210 //szrSearch->Fit(tabSearch);
1212 if (SearchFrames.size() < 15 && SearchFrames.size() > 1){
1214 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1215 iter != SearchFrames.end(); ++iter){
1217 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1219 XABSPPtr->EnableButtons(TRUE, TRUE);
1223 } else if (SearchFrames.size() == 1){
1225 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1226 iter != SearchFrames.end(); ++iter){
1228 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1230 XABSPPtr->EnableButtons(TRUE, FALSE);
1236 szrSearch->FitInside(tabSearch);
1237 szrSearch->Layout();
1238 szrSearch->RecalcSizes();
1239 tabSearch->Layout();
1243 void frmSearch::ReloadAccountList( wxCommandEvent& event ){
1247 void frmSearch::AddResult( wxCommandEvent& event ){
1249 SRNotif *srnotif = (SRNotif*)event.GetClientData();
1251 // Process Data and add to the list of results.
1255 // Setup the contact name.
1257 wxString ContactNameFinal;
1259 if (!srnotif->ContactName.Title.IsEmpty()){
1261 ContactNameFinal.append(srnotif->ContactName.Title);
1262 ContactNameFinal.Trim();
1263 ContactNameFinal.append(wxT(" "));
1267 if (!srnotif->ContactName.Forename.IsEmpty()){
1269 ContactNameFinal.append(srnotif->ContactName.Forename);
1270 ContactNameFinal.Trim();
1271 ContactNameFinal.append(wxT(" "));
1275 if (!srnotif->ContactName.Surname.IsEmpty()){
1277 ContactNameFinal.append(srnotif->ContactName.Surname);
1278 ContactNameFinal.Trim();
1279 ContactNameFinal.append(wxT(" "));
1283 if (!srnotif->ContactName.Suffix.IsEmpty()){
1285 ContactNameFinal.append(srnotif->ContactName.Suffix);
1286 ContactNameFinal.Trim();
1291 item.SetText(ContactNameFinal);
1292 item.SetData(srnotif->SearchResultID);
1294 long ListCtrlIndex = lstResults->InsertItem(item);
1296 //SearchResultAccount.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactAccount));
1297 //SearchResultFilename.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactFullFilename));
1299 srnotif->ContactNickname.Trim();
1301 lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname);
1302 lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName);
1309 void frmSearch::SearchBarUpdate( wxCommandEvent& event ){
1311 wxString *SBData = (wxString*)event.GetClientData();
1313 stbBottom->SetStatusText(*SBData, 0);
1320 void frmSearch::SearchFinished( wxCommandEvent& event ){
1323 btnSearch->SetLabel(_("Search"));
1324 DisableAllSearchSettings(FALSE);
1328 void frmSearch::DisableAllSearchSettings(bool Enable){
1330 for (std::map<int, void*>::iterator siter = SearchFrames.begin();
1331 siter != SearchFrames.end(); siter++){
1333 XABSearchPanel *XABSPPtr = static_cast<XABSearchPanel*>(siter->second);
1335 if (Enable == FALSE){
1337 wxCommandEvent enboxes(XABSP_ENABLECONTROLS);
1338 wxPostEvent(XABSPPtr, enboxes);
1340 } else if (Enable == TRUE){
1342 wxCommandEvent disboxes(XABSP_DISABLECONTROLS);
1343 wxPostEvent(XABSPPtr, disboxes);
1351 void frmSearch::OpenContact( wxCommandEvent& event ){
1353 // Check if a contact has been selected.
1355 long intSelected = -1;
1356 int intSelectedData = 0;
1357 long intContactSeekNum = -1;
1359 intSelected = lstResults->GetNextItem(intSelected,
1361 wxLIST_STATE_SELECTED);
1363 if (intSelected == -1){
1367 intContactSeekNum = lstResults->GetItemData(intSelected);
1369 UCNotif *uc = new UCNotif;
1371 uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1372 uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1374 wxCommandEvent oc(CE_OPENCONTACT);
1375 oc.SetClientData(uc);
1376 wxPostEvent(this->GetParent(), oc);
1380 void frmSearch::EditContact( wxCommandEvent& event ){
1382 // Check if a contact has been selected.
1384 long intSelected = -1;
1385 int intSelectedData = 0;
1386 long intContactSeekNum = -1;
1388 intSelected = lstResults->GetNextItem(intSelected,
1390 wxLIST_STATE_SELECTED);
1392 if (intSelected == -1){
1396 intContactSeekNum = lstResults->GetItemData(intSelected);
1398 UCNotif *uc = new UCNotif;
1400 uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1401 uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1403 wxCommandEvent ec(CE_EDITCONTACT);
1404 ec.SetClientData(uc);
1406 wxPostEvent(this->GetParent(), ec);
1410 void frmSearch::RevealContact( wxCommandEvent& event ){
1412 // Check if a contact has been selected.
1414 long intSelected = -1;
1415 int intSelectedData = 0;
1416 long intContactSeekNum = -1;
1418 intSelected = lstResults->GetNextItem(intSelected,
1420 wxLIST_STATE_SELECTED);
1422 if (intSelected == -1){
1426 intContactSeekNum = lstResults->GetItemData(intSelected);
1428 UCNotif *uc = new UCNotif;
1430 uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1431 uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1433 wxCommandEvent rc(CE_REVEALCONTACT);
1434 rc.SetClientData(uc);
1436 wxPostEvent(this->GetParent(), rc);
1440 void frmSearch::CloseWindow( wxCloseEvent& event ){
1442 // Hide the window so users don't panic
1443 // whilst clearing up.
1449 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1450 iter != SearchFrames.end(); ++iter){
1452 XABSearchPanel *XABSPPtr;
1454 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1455 szrSearch->Detach(XABSPPtr);
1457 // Remove the frame from the memory and the list.
1464 SearchFrames.clear();
1468 WindowData *WData = new WindowData;
1470 WData->DataType = 2;
1471 WData->WindowPointer = this;
1472 WData->WindowID = SearchUID;
1474 wxCommandEvent delevent(WINDOW_CLOSE);
1475 delevent.SetClientData(WData);
1476 wxPostEvent(GetParent(), delevent);
1478 wxCommandEvent rs(CE_REMOVESEARCH);
1479 wxPostEvent(this, rs);
1487 void frmSearch::CloseWindow( wxCommandEvent& event ){
1493 void frmSearch::UpdateResult( wxCommandEvent& event ){
1495 UCNotif *uc = (UCNotif*)event.GetClientData();
1497 long longSelected = -1;
1498 int intSelectedData = 0;
1502 longSelected = lstResults->GetNextItem(longSelected,
1504 wxLIST_STATE_DONTCARE);
1506 if (longSelected == -1){
1512 // Get the filename/ID information.
1514 intSelectedData = lstResults->GetItemData(longSelected);
1516 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
1518 // Process the contact name
1520 wxString ContactNameFinal;
1522 if (!uc->ContactNameArray.Title.IsEmpty()){
1524 ContactNameFinal.append(uc->ContactNameArray.Title);
1525 ContactNameFinal.Trim();
1526 ContactNameFinal.append(wxT(" "));
1530 if (!uc->ContactNameArray.Forename.IsEmpty()){
1532 ContactNameFinal.append(uc->ContactNameArray.Forename);
1533 ContactNameFinal.Trim();
1534 ContactNameFinal.append(wxT(" "));
1538 if (!uc->ContactNameArray.Surname.IsEmpty()){
1540 ContactNameFinal.append(uc->ContactNameArray.Surname);
1541 ContactNameFinal.Trim();
1542 ContactNameFinal.append(wxT(" "));
1546 if (!uc->ContactNameArray.Suffix.IsEmpty()){
1548 ContactNameFinal.append(uc->ContactNameArray.Suffix);
1549 ContactNameFinal.Trim();
1553 lstResults->SetItem(longSelected, 0, ContactNameFinal);
1554 lstResults->SetItem(longSelected, 1, uc->ContactNickname);
1565 bool frmSearch::CheckDuplicate(wxString Filename,
1567 std::map<long,wxString> *SRAcc,
1568 std::map<long,wxString> *SRFN){
1570 std::map<long,wxString>::iterator fniter;
1572 // Check comparison code.
1574 for (std::map<long,wxString>::iterator aciter = SRAcc->begin();
1575 aciter != SRAcc->end(); aciter++){
1577 fniter = SRFN->find(aciter->first);
1579 if (Filename == fniter->second &&
1580 Account == aciter->second){
1592 void frmSearch::DeleteResult(wxCommandEvent &event){
1594 UCNotif *uc = (UCNotif*)event.GetClientData();
1596 long longSelected = -1;
1597 int intSelectedData = 0;
1601 longSelected = lstResults->GetNextItem(longSelected,
1603 wxLIST_STATE_DONTCARE);
1605 if (longSelected == -1){
1611 // Get the filename/ID information.
1613 intSelectedData = lstResults->GetItemData(longSelected);
1615 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
1617 // Delete the result from the search list and
1618 // update the total search results.
1620 // Remove DeleteResultEvent and find out where the uc
1621 // data is still being used as it crashes on delete.
1623 lstResults->DeleteItem(longSelected);
1625 // Update the number of search results.
1627 wxCommandEvent sbu(SE_SBUPDATE);
1628 wxString *SBUpdate = new wxString;
1630 // Get the number of results.
1632 int intResultFound = lstResults->GetItemCount();
1634 // Prepare the status bar message.
1636 if (intResultFound == 0){
1638 *SBUpdate = _("No contacts found.");
1640 } else if (intResultFound == 1){
1642 *SBUpdate = _("1 contact found.");
1646 *SBUpdate = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
1650 sbu.SetClientData(SBUpdate);
1651 wxPostEvent(this, sbu);
1664 void frmSearch::SetUID(int UID){