1 // frmSearch.cpp - Search form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmSearch.h"
21 #include "frmContact.h"
22 #include "search/XABSearchPanel.h"
23 #include "search/frmSearchAccounts.h"
24 #include "common/preferences.h"
25 #include "common/dirs.h"
26 #include "vcard/vcard.h"
29 #include <wx/fs_mem.h>
30 #include <wx/tokenzr.h>
33 DEFINE_EVENT_TYPE(SE_ADDSEARCHSETTING);
34 DEFINE_EVENT_TYPE(SE_REMOVESEARCHSETTING);
35 DEFINE_EVENT_TYPE(SE_RELOADACCOUNTS);
36 DEFINE_EVENT_TYPE(SE_ADDRESULT);
37 DEFINE_EVENT_TYPE(SE_SBUPDATE);
38 DEFINE_EVENT_TYPE(SE_SEARCHFINISHED);
39 DEFINE_EVENT_TYPE(SE_UPDATERESULT);
40 DEFINE_EVENT_TYPE(SE_DELETERESULT);
41 DEFINE_EVENT_TYPE(SE_OPENCONTACT);
42 DEFINE_EVENT_TYPE(SE_EDITCONTACT);
43 DEFINE_EVENT_TYPE(SE_REVEALCONTACT);
45 BEGIN_EVENT_TABLE(frmSearch, wxFrame)
46 EVT_COMMAND(wxID_ANY, SE_ADDSEARCHSETTING, frmSearch::AddSearchSetting)
47 EVT_COMMAND(wxID_ANY, SE_REMOVESEARCHSETTING, frmSearch::RemoveSearchSetting)
48 EVT_COMMAND(wxID_ANY, SE_RELOADACCOUNTS, frmSearch::ReloadAccountList)
49 EVT_COMMAND(wxID_ANY, SE_ADDRESULT, frmSearch::AddResult)
50 EVT_COMMAND(wxID_ANY, SE_SBUPDATE, frmSearch::SearchBarUpdate)
51 EVT_COMMAND(wxID_ANY, SE_SEARCHFINISHED, frmSearch::SearchFinished)
52 EVT_COMMAND(wxID_ANY, SE_UPDATERESULT, frmSearch::UpdateResult)
53 EVT_COMMAND(wxID_ANY, SE_DELETERESULT, frmSearch::DeleteResult)
54 EVT_COMMAND(wxID_ANY, SE_OPENCONTACT, frmSearch::OpenContact)
55 EVT_COMMAND(wxID_ANY, SE_EDITCONTACT, frmSearch::EditContact)
56 EVT_COMMAND(wxID_ANY, SE_REVEALCONTACT, frmSearch::RevealContact)
59 frmSearch::frmSearch( wxWindow* parent )
61 frmSearchADT( parent )
64 XABSearchPanel *InitPanel = new XABSearchPanel( tabSearch );
65 InitPanel->EnableButtons(TRUE, FALSE);
66 InitPanel->SetupPointers(this);
67 InitPanel->SetupInteger(ScrollGen);
68 szrSearch->Add(InitPanel, 1, wxEXPAND, 0);
69 szrSearch->Fit(tabSearch);
70 SearchFrames.insert(std::make_pair(ScrollGen, InitPanel));
73 // Get the list of accounts and mark them as true.
75 wxString preffilename = GetUserPrefDir();
77 XABPreferences preferences(preffilename);
81 wxString AccDirFullSfx;
83 for (int i = 0; i < preferences.accounts.GetCount(); i++){
84 AccDir = preferences.accounts.GetAccountDirectory(i);
85 AccDirFull = preferences.accounts.GetAccountDirectory(i);
87 AccDirFull.Append(wxT("."));
88 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
89 AccDirFullSfx.LowerCase();
91 AccDirFull.Append(AccDirFullSfx);
92 SearchAccountsPaths.insert(std::make_pair(AccDir, AccDirFull));
93 SearchAccounts.insert(std::make_pair(AccDir, TRUE));
94 SearchAccountsNames.insert(std::make_pair(AccDir,
95 preferences.accounts.GetAccountName(i)));
97 AccDirFullSfx.clear();
101 // Setup the columns.
105 item.SetText(_("Name"));
108 lstResults->InsertColumn(0, item);
111 item.SetText(_("Nickname"));
114 lstResults->InsertColumn(1, item);
117 item.SetText(_("Account"));
120 lstResults->InsertColumn(2, item);
124 void frmSearch::SelectAccounts( wxCommandEvent& event )
127 // Create the form and display as modal.
129 frmSearchAccounts *frameSAccount = new frmSearchAccounts ( this );
130 frameSAccount->LoadSearchAccounts(&SearchAccounts, &SearchAccountsNames);
131 frameSAccount->ShowModal();
132 delete frameSAccount;
133 frameSAccount = NULL;
137 void frmSearch::SearchContactsThread(){
139 // Go through each account and find contacts based on the
142 std::map<wxString,bool>::iterator SAiter;
143 std::map<wxString,wxString>::iterator SAPiter;
144 int intResultFound = 0;
146 for (std::map<wxString, wxString>::iterator SALiter = SearchAccountsNames.begin();
147 SALiter != SearchAccountsNames.end();
150 // Double check that we are searching in this account.
151 // If not, skip to the next one.
153 SAiter = SearchAccounts.find(SALiter->first);
154 SAPiter = SearchAccountsPaths.find(SAiter->first);
157 if (SAiter->second == FALSE){
159 // Not looking in this account. Go to next account.
165 wxCommandEvent sbupdate (SE_SBUPDATE);
167 wxString *SBData = new wxString;
168 *SBData = _("Searching ") + SALiter->second + _("...");
170 sbupdate.SetClientData(SBData);
171 wxPostEvent(this, sbupdate);
173 if (StopMode == FALSE){
175 wxCommandEvent sbstop (SE_SBUPDATE);
177 wxString *SBStopStr = new wxString;
178 *SBStopStr = _("Search stopped.");
180 sbstop.SetClientData(SBStopStr);
181 wxPostEvent(this, sbstop);
186 // Get the list of contact files and process each
189 wxString AccountDir = GetAccountDir(SAPiter->second, FALSE);
191 wxString vcardfilenamewxs;
192 wxStringTokenizer vcardfileline;
195 wxString setname, setvalue;
196 long ContactIndex = 1;
197 long ContactSeekPoint = 0;
198 wxString vCardFilename;
199 wxString vCardFilenameFull;
201 if (wxDirExists(AccountDir)){
203 wxDir vcardaccdir(AccountDir);
205 bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
208 if (StopMode == FALSE){
210 wxCommandEvent sbstop(SE_SBUPDATE);
212 wxString *SBStopStr = new wxString;
213 *SBStopStr = _("Search stopped.");
215 sbstop.SetClientData(SBStopStr);
216 wxPostEvent(this, sbstop);
221 if (vCardFilename.Right(4) == wxT(".vcf") ||
222 vCardFilename.Right(4) == wxT(".VCF") ||
223 vCardFilename.Right(5) == wxT(".vcard") ||
224 vCardFilename.Right(5) == wxT(".VCARD")){
227 vCardFilenameFull.Append(AccountDir);
228 vCardFilenameFull.Append(vCardFilename);
231 Person.LoadFile(vCardFilenameFull);
233 vcardfilenamewxs = vCardFilenameFull;
235 // Open the vCard file up and get the setting names and values from the
238 vcardfile.open(vcardfilenamewxs.mb_str(), std::ios::in);
240 while(getline(vcardfile, l)){
245 lwxs.Append(wxString::FromUTF8(l.c_str()));
246 vcardfileline.SetString(lwxs, wxT(":"));
247 setname = vcardfileline.GetNextToken();
248 setvalue = vcardfileline.GetString();
250 Person.Add(setname, setvalue, TRUE);
256 // Check if file has version 4.0, first name (FN)
257 // begin and end vCard portions.
259 // Don't search unless these conditions have been met.
261 if (Person.MeetBaseSpecification()){
263 // Go through each of the search settings and check
264 // if they match with contact details.
266 // If it matches then add to the search results.
272 ArrayvCardOutData ArrayData;
273 ArrayvCardOutData NicknameArrayData;
274 vCardName NameArray = Person.GetName();
275 wxString ContactFinalNickname;
276 NicknameArrayData = Person.GetByPartial(wxT("NICKNAME"));
278 if (NicknameArrayData.PropCount != 0){
279 ContactFinalNickname = NicknameArrayData.PropValues[0];
282 for (std::map<int, void*>::iterator siter = SearchFrames.begin();
283 siter != SearchFrames.end(); siter++){
285 // Get the settings from the form.
287 XABSearchPanel *XABSPPtr = static_cast<XABSearchPanel*>(siter->second);
289 // Get Selected Option and Setting.
291 SelOpt = XABSPPtr->GetSelectionOption();
295 StrOpt = XABSPPtr->GetStringSetting();
296 StrOptLen = StrOpt.Len();
298 if (SelOpt == 0 || SelOpt == 4 || SelOpt == 8){
300 // Matching string that beings with...
302 // Double check the std::map inserts for each section.
306 // Get the forename from the first N.
308 if (NameArray.Forename.Mid(0, StrOptLen) == StrOpt){
310 if (CheckDuplicate(vcardfilenamewxs,
312 &SearchResultAccount,
313 &SearchResultFilename) == TRUE){
319 ArrayData.PropData.Clear();
320 ArrayData.PropValues.Clear();
321 ArrayData.PropCount = 0;
326 SRNotif *sradd = new SRNotif;
327 sradd->ContactName = NameArray;
328 sradd->ContactNickname = ContactFinalNickname;
329 sradd->ContactAccount = SAPiter->second;
330 sradd->ContactAccountName = SALiter->second;
331 sradd->ContactFullFilename = vcardfilenamewxs;
332 sradd->SearchResultID = intResultFound;
334 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
335 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
339 wxCommandEvent sraddenv(SE_ADDRESULT);
340 sraddenv.SetClientData(sradd);
341 wxPostEvent(this, sraddenv);
345 } else if (SelOpt == 4){
347 if (NameArray.Surname.Mid(0, StrOptLen) == StrOpt){
349 if (CheckDuplicate(vcardfilenamewxs,
351 &SearchResultAccount,
352 &SearchResultFilename) == TRUE){
358 ArrayData.PropData.Clear();
359 ArrayData.PropValues.Clear();
360 ArrayData.PropCount = 0;
365 SRNotif *sradd = new SRNotif;
366 sradd->ContactName = NameArray;
367 sradd->ContactNickname = ContactFinalNickname;
368 sradd->ContactAccount = SAPiter->second;
369 sradd->ContactAccountName = SALiter->second;
370 sradd->ContactFullFilename = vcardfilenamewxs;
371 sradd->SearchResultID = intResultFound;
373 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
374 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
378 wxCommandEvent sraddenv(SE_ADDRESULT);
379 sraddenv.SetClientData(sradd);
380 wxPostEvent(this, sraddenv);
384 } else if (SelOpt == 8){
386 wxString NicknameData;
388 for (int i = 0; i < NicknameArrayData.PropCount; i++){
390 NicknameData = NicknameArrayData.PropValues[i];
392 if (NicknameData.Mid(0, StrOptLen) == StrOpt){
394 if (CheckDuplicate(vcardfilenamewxs,
396 &SearchResultAccount,
397 &SearchResultFilename) == TRUE){
403 ArrayData.PropData.Clear();
404 ArrayData.PropValues.Clear();
405 ArrayData.PropCount = 0;
410 SRNotif *sradd = new SRNotif;
411 sradd->ContactName = NameArray;
412 sradd->ContactNickname = ContactFinalNickname;
413 sradd->ContactAccount = SAPiter->second;
414 sradd->ContactAccountName = SALiter->second;
415 sradd->ContactFullFilename = vcardfilenamewxs;
416 sradd->SearchResultID = intResultFound;
418 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
419 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
423 wxCommandEvent sraddenv(SE_ADDRESULT);
424 sraddenv.SetClientData(sradd);
425 wxPostEvent(this, sraddenv);
435 } else if (SelOpt == 1 || SelOpt == 5 || SelOpt == 9){
437 // Matching string that ends with...
441 // Check the forename.
443 if (NameArray.Forename.Right(StrOptLen) == StrOpt){
445 if (CheckDuplicate(vcardfilenamewxs,
447 &SearchResultAccount,
448 &SearchResultFilename) == TRUE){
454 ArrayData.PropData.Clear();
455 ArrayData.PropValues.Clear();
456 ArrayData.PropCount = 0;
461 SRNotif *sradd = new SRNotif;
462 sradd->ContactName = NameArray;
463 sradd->ContactNickname = ContactFinalNickname;
464 sradd->ContactAccount = SAPiter->second;
465 sradd->ContactAccountName = SALiter->second;
466 sradd->ContactFullFilename = vcardfilenamewxs;
467 sradd->SearchResultID = intResultFound;
469 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
470 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
474 wxCommandEvent sraddenv(SE_ADDRESULT);
475 sraddenv.SetClientData(sradd);
476 wxPostEvent(this, sraddenv);
480 } else if (SelOpt == 5){
482 if (NameArray.Surname.Right(StrOptLen) == StrOpt){
484 if (CheckDuplicate(vcardfilenamewxs,
486 &SearchResultAccount,
487 &SearchResultFilename) == TRUE){
493 ArrayData.PropData.Clear();
494 ArrayData.PropValues.Clear();
495 ArrayData.PropCount = 0;
500 SRNotif *sradd = new SRNotif;
501 sradd->ContactName = NameArray;
502 sradd->ContactNickname = ContactFinalNickname;
503 sradd->ContactAccount = SAPiter->second;
504 sradd->ContactAccountName = SALiter->second;
505 sradd->ContactFullFilename = vcardfilenamewxs;
506 sradd->SearchResultID = intResultFound;
508 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
509 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
513 wxCommandEvent sraddenv(SE_ADDRESULT);
514 sraddenv.SetClientData(sradd);
515 wxPostEvent(this, sraddenv);
519 } else if (SelOpt == 9){
521 wxString NicknameData;
523 for (int i = 0; i < NicknameArrayData.PropCount; i++){
525 NicknameData = NicknameArrayData.PropValues[i];
528 if (NicknameData.Right(StrOptLen) == StrOpt){
530 if (CheckDuplicate(vcardfilenamewxs,
532 &SearchResultAccount,
533 &SearchResultFilename) == TRUE){
539 ArrayData.PropData.Clear();
540 ArrayData.PropValues.Clear();
541 ArrayData.PropCount = 0;
546 SRNotif *sradd = new SRNotif;
547 sradd->ContactName = NameArray;
548 sradd->ContactNickname = ContactFinalNickname;
549 sradd->ContactAccount = SAPiter->second;
550 sradd->ContactAccountName = SALiter->second;
551 sradd->ContactFullFilename = vcardfilenamewxs;
552 sradd->SearchResultID = intResultFound;
554 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
555 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
559 wxCommandEvent sraddenv(SE_ADDRESULT);
560 sraddenv.SetClientData(sradd);
561 wxPostEvent(this, sraddenv);
571 } else if (SelOpt == 2 || SelOpt == 6 || SelOpt == 10){
573 // Matching string that contains...
577 if (NameArray.Forename.Find(StrOpt) != wxNOT_FOUND){
579 if (CheckDuplicate(vcardfilenamewxs,
581 &SearchResultAccount,
582 &SearchResultFilename) == TRUE){
588 ArrayData.PropData.Clear();
589 ArrayData.PropValues.Clear();
590 ArrayData.PropCount = 0;
595 SRNotif *sradd = new SRNotif;
596 sradd->ContactName = NameArray;
597 sradd->ContactNickname = ContactFinalNickname;
598 sradd->ContactAccount = SAPiter->second;
599 sradd->ContactAccountName = SALiter->second;
600 sradd->ContactFullFilename = vcardfilenamewxs;
601 sradd->SearchResultID = intResultFound;
603 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
604 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
608 wxCommandEvent sraddenv(SE_ADDRESULT);
609 sraddenv.SetClientData(sradd);
610 wxPostEvent(this, sraddenv);
614 } else if (SelOpt == 6){
616 if (NameArray.Surname.Find(StrOpt) != wxNOT_FOUND){
618 if (CheckDuplicate(vcardfilenamewxs,
620 &SearchResultAccount,
621 &SearchResultFilename) == TRUE){
627 ArrayData.PropData.Clear();
628 ArrayData.PropValues.Clear();
629 ArrayData.PropCount = 0;
634 SRNotif *sradd = new SRNotif;
635 sradd->ContactName = NameArray;
636 sradd->ContactNickname = ContactFinalNickname;
637 sradd->ContactAccount = SAPiter->second;
638 sradd->ContactAccountName = SALiter->second;
639 sradd->ContactFullFilename = vcardfilenamewxs;
640 sradd->SearchResultID = intResultFound;
642 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
643 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
647 wxCommandEvent sraddenv(SE_ADDRESULT);
648 sraddenv.SetClientData(sradd);
649 wxPostEvent(this, sraddenv);
653 } else if (SelOpt == 10){
655 wxString NicknameData;
657 for (int i = 0; i < NicknameArrayData.PropCount; i++){
659 NicknameData = NicknameArrayData.PropValues[i];
662 if (NicknameData.Find(StrOpt) != wxNOT_FOUND){
664 if (CheckDuplicate(vcardfilenamewxs,
666 &SearchResultAccount,
667 &SearchResultFilename) == TRUE){
673 ArrayData.PropData.Clear();
674 ArrayData.PropValues.Clear();
675 ArrayData.PropCount = 0;
680 SRNotif *sradd = new SRNotif;
681 sradd->ContactName = NameArray;
682 sradd->ContactNickname = ContactFinalNickname;
683 sradd->ContactAccount = SAPiter->second;
684 sradd->ContactAccountName = SALiter->second;
685 sradd->ContactFullFilename = vcardfilenamewxs;
686 sradd->SearchResultID = intResultFound;
688 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
689 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
693 wxCommandEvent sraddenv(SE_ADDRESULT);
694 sraddenv.SetClientData(sradd);
695 wxPostEvent(this, sraddenv);
705 } else if (SelOpt == 3 || SelOpt == 7 || SelOpt == 11){
707 // Matching String that doesn't contain...
711 // Process the nickname data.
713 if (NameArray.Forename.Find(StrOpt) == wxNOT_FOUND){
715 if (CheckDuplicate(vcardfilenamewxs,
717 &SearchResultAccount,
718 &SearchResultFilename) == TRUE){
724 ArrayData.PropData.Clear();
725 ArrayData.PropValues.Clear();
726 ArrayData.PropCount = 0;
731 SRNotif *sradd = new SRNotif;
732 sradd->ContactName = NameArray;
733 sradd->ContactNickname = ContactFinalNickname;
734 sradd->ContactAccount = SAPiter->second;
735 sradd->ContactAccountName = SALiter->second;
736 sradd->ContactFullFilename = vcardfilenamewxs;
737 sradd->SearchResultID = intResultFound;
739 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
740 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
744 wxCommandEvent sraddenv(SE_ADDRESULT);
745 sraddenv.SetClientData(sradd);
746 wxPostEvent(this, sraddenv);
750 } else if (SelOpt == 7){
752 if (!NameArray.Surname.Find(StrOpt) == wxNOT_FOUND){
754 if (CheckDuplicate(vcardfilenamewxs,
756 &SearchResultAccount,
757 &SearchResultFilename) == TRUE){
763 ArrayData.PropData.Clear();
764 ArrayData.PropValues.Clear();
765 ArrayData.PropCount = 0;
770 SRNotif *sradd = new SRNotif;
771 sradd->ContactName = NameArray;
772 sradd->ContactNickname = ContactFinalNickname;
773 sradd->ContactAccount = SAPiter->second;
774 sradd->ContactAccountName = SALiter->second;
775 sradd->ContactFullFilename = vcardfilenamewxs;
776 sradd->SearchResultID = intResultFound;
778 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
779 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
783 wxCommandEvent sraddenv(SE_ADDRESULT);
784 sraddenv.SetClientData(sradd);
785 wxPostEvent(this, sraddenv);
789 } else if (SelOpt == 11){
791 wxString NicknameData;
793 for (int i = 0; i < NicknameArrayData.PropCount; i++){
795 NicknameData = NicknameArrayData.PropValues[i];
798 if (NicknameData.Find(StrOpt) == wxNOT_FOUND){
800 if (CheckDuplicate(vcardfilenamewxs,
802 &SearchResultAccount,
803 &SearchResultFilename) == TRUE){
809 ArrayData.PropData.Clear();
810 ArrayData.PropValues.Clear();
811 ArrayData.PropCount = 0;
816 SRNotif *sradd = new SRNotif;
817 sradd->ContactName = NameArray;
818 sradd->ContactNickname = ContactFinalNickname;
819 sradd->ContactAccount = SAPiter->second;
820 sradd->ContactAccountName = SALiter->second;
821 sradd->ContactFullFilename = vcardfilenamewxs;
822 sradd->SearchResultID = intResultFound;
824 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
825 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
829 wxCommandEvent sraddenv(SE_ADDRESULT);
830 sraddenv.SetClientData(sradd);
831 wxPostEvent(this, sraddenv);
845 chkOpt = XABSPPtr->GetCheckboxSetting();
849 // Search should check if it has a photo or not.
851 ArrayData = Person.GetByPartial(wxT("PHOTO"));
853 if ((ArrayData.PropCount >= 1 &&
855 (ArrayData.PropCount == 0 &&
858 if (CheckDuplicate(vcardfilenamewxs,
860 &SearchResultAccount,
861 &SearchResultFilename) == TRUE){
867 ArrayData.PropData.Clear();
868 ArrayData.PropValues.Clear();
869 ArrayData.PropCount = 0;
874 SRNotif *sradd = new SRNotif;
876 sradd->ContactName = NameArray;
877 sradd->ContactNickname = ContactFinalNickname;
878 sradd->ContactAccount = SAPiter->second;
879 sradd->ContactAccountName = SALiter->second;
880 sradd->ContactFullFilename = vcardfilenamewxs;
881 sradd->SearchResultID = intResultFound;
883 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
884 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
888 wxCommandEvent sraddenv(SE_ADDRESULT);
889 sraddenv.SetClientData(sradd);
890 wxPostEvent(this, sraddenv);
894 } else if (SelOpt == 13){
896 // Search should check if it has a logo or not.
898 ArrayData = Person.GetByPartial(wxT("LOGO"));
900 if ((ArrayData.PropCount >= 1 &&
902 (ArrayData.PropCount == 0 &&
905 if (CheckDuplicate(vcardfilenamewxs,
907 &SearchResultAccount,
908 &SearchResultFilename) == TRUE){
914 ArrayData.PropData.Clear();
915 ArrayData.PropValues.Clear();
916 ArrayData.PropCount = 0;
921 SRNotif *sradd = new SRNotif;
923 sradd->ContactName = NameArray;
924 sradd->ContactNickname = ContactFinalNickname;
925 sradd->ContactAccount = SAPiter->second;
926 sradd->ContactAccountName = SALiter->second;
927 sradd->ContactFullFilename = vcardfilenamewxs;
928 sradd->SearchResultID = intResultFound;
930 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
931 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
935 wxCommandEvent sraddenv(SE_ADDRESULT);
936 sraddenv.SetClientData(sradd);
937 wxPostEvent(this, sraddenv);
941 } else if (SelOpt == 14){
943 // Search should check if it has sound or not.
945 ArrayData = Person.GetByPartial(wxT("SOUND"));
947 if ((ArrayData.PropCount >= 1 &&
949 (ArrayData.PropCount == 0 &&
952 if (CheckDuplicate(vcardfilenamewxs,
954 &SearchResultAccount,
955 &SearchResultFilename) == TRUE){
961 ArrayData.PropData.Clear();
962 ArrayData.PropValues.Clear();
963 ArrayData.PropCount = 0;
968 SRNotif *sradd = new SRNotif;
970 sradd->ContactName = NameArray;
971 sradd->ContactNickname = ContactFinalNickname;
972 sradd->ContactAccount = SAPiter->second;
973 sradd->ContactAccountName = SALiter->second;
974 sradd->ContactFullFilename = vcardfilenamewxs;
975 sradd->SearchResultID = intResultFound;
977 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
978 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
982 wxCommandEvent sraddenv(SE_ADDRESULT);
983 sraddenv.SetClientData(sradd);
984 wxPostEvent(this, sraddenv);
996 ArrayData.PropData.Clear();
997 ArrayData.PropValues.Clear();
998 ArrayData.PropCount = 0;
1008 vCardFilename.Clear();
1009 vCardFilenameFull.Clear();
1010 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1020 // Finished searching... clear up.
1022 wxCommandEvent sbfinstr (SE_SBUPDATE);
1024 wxString *SBFinish = new wxString;
1026 if (intResultFound == 0){
1028 *SBFinish = _("No contacts found.");
1030 } else if (intResultFound == 1){
1032 *SBFinish = _("1 contact found.");
1036 *SBFinish = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
1040 sbfinstr.SetClientData(SBFinish);
1041 wxPostEvent(this, sbfinstr);
1043 wxCommandEvent sbfinish (SE_SEARCHFINISHED);
1044 wxPostEvent(this, sbfinish);
1048 void frmSearch::SearchContacts( wxCommandEvent& event )
1051 // Change the button to stop.
1053 if (StopMode == FALSE){
1055 // Clear the list of search results.
1057 lstResults->DeleteAllItems();
1058 SearchResultAccount.clear();
1059 SearchResultFilename.clear();
1061 // Button clicked on as 'Search'.
1063 DisableAllSearchSettings(TRUE);
1065 btnSearch->SetLabel(_("Stop"));
1067 // Spawn a thread so that searching can proceed
1068 // without blocking the GUI (and allow the
1069 // search to stop when needed).
1071 std::thread SearchThread(&frmSearch::SearchContactsThread, this);
1072 SearchThread.detach();
1076 // Button clicked on as 'Stop'.
1079 btnSearch->SetLabel(_("Search"));
1080 DisableAllSearchSettings(FALSE);
1086 void frmSearch::ResetContacts( wxCommandEvent& event )
1089 // Clear all the search settings.
1091 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1092 iter != SearchFrames.end(); ++iter){
1094 XABSearchPanel *XABSPPtr;
1096 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1097 szrSearch->Detach(XABSPPtr);
1099 // Remove the frame from the memory and the list.
1104 SearchFrames.erase(iter->first);
1108 // Clear the list of search results.
1110 lstResults->DeleteAllItems();
1112 // Clear the account settings.
1114 for (std::map<wxString, bool>::iterator iter = SearchAccounts.begin();
1115 iter != SearchAccounts.end(); iter++){
1117 iter->second = TRUE;
1121 // Add a search settings with the default things.
1125 XABSearchPanel *NewPanel = new XABSearchPanel( tabSearch );
1126 NewPanel->EnableButtons(TRUE, FALSE);
1127 NewPanel->SetupPointers(this);
1128 NewPanel->SetupInteger(ScrollGen);
1129 szrSearch->Add(NewPanel, 1, wxEXPAND, 0);
1130 szrSearch->Fit(tabSearch);
1131 SearchFrames.insert(std::make_pair(ScrollGen, NewPanel));
1136 void frmSearch::AddSearchSetting( wxCommandEvent& event )
1139 // Add a search setting frame to the list.
1141 XABSearchPanel *NewPanel = new XABSearchPanel( tabSearch );
1142 NewPanel->EnableButtons(TRUE, TRUE);
1143 NewPanel->SetupPointers(this);
1144 NewPanel->SetupInteger(ScrollGen);
1145 szrSearch->Add(NewPanel, 1, wxEXPAND|wxGROW, 5);
1146 //szrSearch->Fit(tabSearch);
1147 szrSearch->FitInside(tabSearch);
1148 szrSearch->Layout();
1149 szrSearch->RecalcSizes();
1150 tabSearch->Layout();
1151 SearchFrames.insert(std::make_pair(ScrollGen, NewPanel));
1154 // Check if number of search settings is 15 (or over).
1155 // If it is, disable the option of adding extra settings
1156 // for all frames until one is removed.
1158 XABSearchPanel *XABSPPtr;
1160 if (SearchFrames.size() >= 15){
1162 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1163 iter != SearchFrames.end(); ++iter){
1165 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1167 XABSPPtr->EnableButtons(FALSE, TRUE);
1171 } else if (SearchFrames.size() >= 2){
1173 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1174 iter != SearchFrames.end(); ++iter){
1176 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1178 XABSPPtr->EnableButtons(TRUE, TRUE);
1184 //tabSearch->SetScrollbar(wxVERTICAL, 32768, 25, 32768, false);
1185 tabSearch->Update();
1186 //tabSearch->ScrollToLine(tabSearch->GetLineCount());
1190 void frmSearch::RemoveSearchSetting( wxCommandEvent& event )
1193 // Get the integer from the event.
1195 std::map<int,void*>::iterator iter;
1196 iter = SearchFrames.find(event.GetInt());
1198 // Remove a search setting frame from the list.
1200 XABSearchPanel *XABSPPtr;
1201 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1203 szrSearch->Detach(XABSPPtr);
1205 // Remove the frame from the memory and the list.
1207 SearchFrames.erase(event.GetInt());
1212 //szrSearch->Fit(tabSearch);
1214 if (SearchFrames.size() < 15 && SearchFrames.size() > 1){
1216 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1217 iter != SearchFrames.end(); ++iter){
1219 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1221 XABSPPtr->EnableButtons(TRUE, TRUE);
1225 } else if (SearchFrames.size() == 1){
1227 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1228 iter != SearchFrames.end(); ++iter){
1230 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1232 XABSPPtr->EnableButtons(TRUE, FALSE);
1238 szrSearch->FitInside(tabSearch);
1239 szrSearch->Layout();
1240 szrSearch->RecalcSizes();
1241 tabSearch->Layout();
1245 void frmSearch::ReloadAccountList( wxCommandEvent& event ){
1247 // Currently unimplemented.
1251 void frmSearch::AddResult( wxCommandEvent& event ){
1253 SRNotif *srnotif = (SRNotif*)event.GetClientData();
1255 // Process Data and add to the list of results.
1259 // Setup the contact name.
1261 wxString ContactNameFinal;
1263 if (!srnotif->ContactName.Title.IsEmpty()){
1265 ContactNameFinal.append(srnotif->ContactName.Title);
1266 ContactNameFinal.Trim();
1267 ContactNameFinal.append(wxT(" "));
1271 if (!srnotif->ContactName.Forename.IsEmpty()){
1273 ContactNameFinal.append(srnotif->ContactName.Forename);
1274 ContactNameFinal.Trim();
1275 ContactNameFinal.append(wxT(" "));
1279 if (!srnotif->ContactName.Surname.IsEmpty()){
1281 ContactNameFinal.append(srnotif->ContactName.Surname);
1282 ContactNameFinal.Trim();
1283 ContactNameFinal.append(wxT(" "));
1287 if (!srnotif->ContactName.Suffix.IsEmpty()){
1289 ContactNameFinal.append(srnotif->ContactName.Suffix);
1290 ContactNameFinal.Trim();
1295 item.SetText(ContactNameFinal);
1296 item.SetData(srnotif->SearchResultID);
1298 long ListCtrlIndex = lstResults->InsertItem(item);
1300 //SearchResultAccount.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactAccount));
1301 //SearchResultFilename.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactFullFilename));
1303 srnotif->ContactNickname.Trim();
1305 lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname);
1306 lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName);
1313 void frmSearch::SearchBarUpdate( wxCommandEvent& event ){
1315 wxString *SBData = (wxString*)event.GetClientData();
1317 stbBottom->SetStatusText(*SBData, 0);
1324 void frmSearch::SearchFinished( wxCommandEvent& event ){
1327 btnSearch->SetLabel(_("Search"));
1328 DisableAllSearchSettings(FALSE);
1332 void frmSearch::DisableAllSearchSettings(bool Enable){
1334 for (std::map<int, void*>::iterator siter = SearchFrames.begin();
1335 siter != SearchFrames.end(); siter++){
1337 XABSearchPanel *XABSPPtr = static_cast<XABSearchPanel*>(siter->second);
1339 if (Enable == FALSE){
1341 wxCommandEvent enboxes(XABSP_ENABLECONTROLS);
1342 wxPostEvent(XABSPPtr, enboxes);
1344 } else if (Enable == TRUE){
1346 wxCommandEvent disboxes(XABSP_DISABLECONTROLS);
1347 wxPostEvent(XABSPPtr, disboxes);
1355 void frmSearch::OpenContact( wxCommandEvent& event ){
1357 // Check if a contact has been selected.
1359 long intSelected = -1;
1360 int intSelectedData = 0;
1361 long intContactSeekNum = -1;
1363 intSelected = lstResults->GetNextItem(intSelected,
1365 wxLIST_STATE_SELECTED);
1367 if (intSelected == -1){
1371 intContactSeekNum = lstResults->GetItemData(intSelected);
1373 if (SearchMode == TRUE){
1375 wxMessageBox(SearchResultFilename[intContactSeekNum]);
1379 Person.LoadFile(SearchResultFilename[intContactSeekNum]);
1381 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
1382 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
1383 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
1385 contacticon.CopyFromBitmap(contacticonbmp);
1387 frmContact *Contact = new frmContact( this );
1389 Contact->SetupPointers(&SearchModeMemoryFSPtr);
1390 Contact->SetupContactData(&Person);
1392 Contact->SetIcon(contacticon);
1393 Contact->Show(true);
1397 UCNotif *uc = new UCNotif;
1399 uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1400 uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1402 wxCommandEvent oc(CE_OPENCONTACT);
1403 oc.SetClientData(uc);
1404 wxPostEvent(this->GetParent(), oc);
1410 void frmSearch::EditContact( 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 ec(CE_EDITCONTACT);
1434 ec.SetClientData(uc);
1436 wxPostEvent(this->GetParent(), ec);
1440 void frmSearch::RevealContact( wxCommandEvent& event ){
1442 // Check if a contact has been selected.
1444 long intSelected = -1;
1445 int intSelectedData = 0;
1446 long intContactSeekNum = -1;
1448 intSelected = lstResults->GetNextItem(intSelected,
1450 wxLIST_STATE_SELECTED);
1452 if (intSelected == -1){
1456 intContactSeekNum = lstResults->GetItemData(intSelected);
1458 UCNotif *uc = new UCNotif;
1460 uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1461 uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1463 wxCommandEvent rc(CE_REVEALCONTACT);
1464 rc.SetClientData(uc);
1466 wxPostEvent(this->GetParent(), rc);
1470 void frmSearch::CloseWindow( wxCloseEvent& event ){
1472 // Hide the window so users don't panic
1473 // whilst clearing up.
1479 for (std::map<int,void*>::iterator iter = SearchFrames.begin();
1480 iter != SearchFrames.end(); ++iter){
1482 XABSearchPanel *XABSPPtr;
1484 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1485 szrSearch->Detach(XABSPPtr);
1487 // Remove the frame from the memory and the list.
1494 SearchFrames.clear();
1498 WindowData *WData = new WindowData;
1500 WData->DataType = 2;
1501 WData->WindowPointer = this;
1502 WData->WindowID = SearchUID;
1504 wxCommandEvent delevent(WINDOW_CLOSE);
1505 delevent.SetClientData(WData);
1506 wxPostEvent(GetParent(), delevent);
1508 wxCommandEvent rs(CE_REMOVESEARCH);
1509 wxPostEvent(this, rs);
1517 void frmSearch::CloseWindow( wxCommandEvent& event ){
1523 void frmSearch::UpdateResult( wxCommandEvent& event ){
1525 UCNotif *uc = (UCNotif*)event.GetClientData();
1527 long longSelected = -1;
1528 int intSelectedData = 0;
1532 longSelected = lstResults->GetNextItem(longSelected,
1534 wxLIST_STATE_DONTCARE);
1536 if (longSelected == -1){
1542 // Get the filename/ID information.
1544 intSelectedData = lstResults->GetItemData(longSelected);
1546 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
1548 // Process the contact name
1550 wxString ContactNameFinal;
1552 if (!uc->ContactNameArray.Title.IsEmpty()){
1554 ContactNameFinal.append(uc->ContactNameArray.Title);
1555 ContactNameFinal.Trim();
1556 ContactNameFinal.append(wxT(" "));
1560 if (!uc->ContactNameArray.Forename.IsEmpty()){
1562 ContactNameFinal.append(uc->ContactNameArray.Forename);
1563 ContactNameFinal.Trim();
1564 ContactNameFinal.append(wxT(" "));
1568 if (!uc->ContactNameArray.Surname.IsEmpty()){
1570 ContactNameFinal.append(uc->ContactNameArray.Surname);
1571 ContactNameFinal.Trim();
1572 ContactNameFinal.append(wxT(" "));
1576 if (!uc->ContactNameArray.Suffix.IsEmpty()){
1578 ContactNameFinal.append(uc->ContactNameArray.Suffix);
1579 ContactNameFinal.Trim();
1583 lstResults->SetItem(longSelected, 0, ContactNameFinal);
1584 lstResults->SetItem(longSelected, 1, uc->ContactNickname);
1595 bool frmSearch::CheckDuplicate(wxString Filename,
1597 std::map<long,wxString> *SRAcc,
1598 std::map<long,wxString> *SRFN){
1600 std::map<long,wxString>::iterator fniter;
1602 // Check comparison code.
1604 for (std::map<long,wxString>::iterator aciter = SRAcc->begin();
1605 aciter != SRAcc->end(); aciter++){
1607 fniter = SRFN->find(aciter->first);
1609 if (Filename == fniter->second &&
1610 Account == aciter->second){
1622 void frmSearch::DeleteResult(wxCommandEvent &event){
1624 UCNotif *uc = (UCNotif*)event.GetClientData();
1626 long longSelected = -1;
1627 int intSelectedData = 0;
1631 longSelected = lstResults->GetNextItem(longSelected,
1633 wxLIST_STATE_DONTCARE);
1635 if (longSelected == -1){
1641 // Get the filename/ID information.
1643 intSelectedData = lstResults->GetItemData(longSelected);
1645 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
1647 // Delete the result from the search list and
1648 // update the total search results.
1650 // Remove DeleteResultEvent and find out where the uc
1651 // data is still being used as it crashes on delete.
1653 lstResults->DeleteItem(longSelected);
1655 // Update the number of search results.
1657 wxCommandEvent sbu(SE_SBUPDATE);
1658 wxString *SBUpdate = new wxString;
1660 // Get the number of results.
1662 int intResultFound = lstResults->GetItemCount();
1664 // Prepare the status bar message.
1666 if (intResultFound == 0){
1668 *SBUpdate = _("No contacts found.");
1670 } else if (intResultFound == 1){
1672 *SBUpdate = _("1 contact found.");
1676 *SBUpdate = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
1680 sbu.SetClientData(SBUpdate);
1681 wxPostEvent(this, sbu);
1694 void frmSearch::SetUID(int UID){
1700 void frmSearch::SetSearchMode(bool SearchModeIn){
1702 SearchMode = SearchModeIn;
1704 if (SearchMode == TRUE){
1706 mnuContactEdit->Enable(FALSE);
1707 mnuContactReveal->Enable(FALSE);
1709 wxFileSystem::AddHandler(new wxMemoryFSHandler);
1712 wxMemoryInputStream ciptostream(icons_cipto_png, sizeof(icons_cipto_png));
1713 ciicon_png.LoadFile(ciptostream, wxBITMAP_TYPE_PNG);
1714 wxMemoryFSHandler::AddFile(wxT("cipto.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1716 wxMemoryInputStream cilogstream(icons_cilog_png, sizeof(icons_cilog_png));
1717 ciicon_png.LoadFile(cilogstream, wxBITMAP_TYPE_PNG);
1718 wxMemoryFSHandler::AddFile(wxT("cilog.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1720 wxMemoryInputStream cisndstream(icons_cisnd_png, sizeof(icons_cisnd_png));
1721 ciicon_png.LoadFile(cisndstream, wxBITMAP_TYPE_PNG);
1722 wxMemoryFSHandler::AddFile(wxT("cisnd.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1724 wxMemoryInputStream cikeystream(icons_cikey_png, sizeof(icons_cikey_png));
1725 ciicon_png.LoadFile(cikeystream, wxBITMAP_TYPE_PNG);
1726 wxMemoryFSHandler::AddFile(wxT("cikey.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1728 wxMemoryInputStream civenstream(icons_civen_png, sizeof(icons_civen_png));
1729 ciicon_png.LoadFile(civenstream, wxBITMAP_TYPE_PNG);
1730 wxMemoryFSHandler::AddFile(wxT("civen.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1732 wxMemoryInputStream ciextstream(icons_ciext_png, sizeof(icons_ciext_png));
1733 ciicon_png.LoadFile(ciextstream, wxBITMAP_TYPE_PNG);
1734 wxMemoryFSHandler::AddFile(wxT("ciext.png"), ciicon_png, wxBITMAP_TYPE_PNG);
1738 mnuContactEdit->Enable(TRUE);
1739 mnuContactReveal->Enable(TRUE);
1745 void frmSearch::ShowContactMenu( wxMouseEvent& event ){
1747 ContactMenu->SetupPointers(this, lstResults);
1749 PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition);