--- /dev/null
+// frmSearch-process.cpp - Search process subroutines.
+//
+// (c) 2012-2015 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
+
+#include "frmSearch.h"
+#include "../common/preferences.h"
+#include "../common/dirs.h"
+#include "../vcard/vcard.h"
+
+void frmSearch::SearchContactsThread(){
+
+ // Go through each account and find contacts based on the
+ // matched settings.
+
+ std::map<wxString,bool>::iterator SAiter;
+ std::map<wxString,wxString>::iterator SAPiter;
+ int intResultFound = 0;
+
+ for (std::map<wxString, wxString>::iterator SALiter = SearchAccountsNames.begin();
+ SALiter != SearchAccountsNames.end();
+ SALiter++){
+
+ // Double check that we are searching in this account.
+ // If not, skip to the next one.
+
+ SAiter = SearchAccounts.find(SALiter->first);
+ SAPiter = SearchAccountsPaths.find(SAiter->first);
+
+
+ if (SAiter->second == FALSE){
+
+ // Not looking in this account. Go to next account.
+
+ continue;
+
+ }
+
+ wxCommandEvent sbupdate (SE_SBUPDATE);
+
+ wxString *SBData = new wxString;
+ *SBData = _("Searching ") + SALiter->second + _("...");
+
+ sbupdate.SetClientData(SBData);
+ wxPostEvent(this, sbupdate);
+
+ if (StopMode == FALSE){
+
+ wxCommandEvent sbstop (SE_SBUPDATE);
+
+ wxString *SBStopStr = new wxString;
+ *SBStopStr = _("Search stopped.");
+
+ sbstop.SetClientData(SBStopStr);
+ wxPostEvent(this, sbstop);
+ return;
+
+ }
+
+ // Get the list of contact files and process each
+ // one of them.
+
+ wxString AccountDir = GetAccountDir(SAPiter->second, FALSE);
+
+ wxString vcardfilenamewxs;
+ wxStringTokenizer vcardfileline;
+ wxString lwxs;
+ wxString setname, setvalue;
+ long ContactIndex = 1;
+ long ContactSeekPoint = 0;
+ wxString vCardFilename;
+ wxString vCardFilenameFull;
+
+ if (wxDirExists(AccountDir)){
+
+ wxDir vcardaccdir(AccountDir);
+
+ bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
+ while(ProcFiles){
+
+ if (StopMode == FALSE){
+
+ wxCommandEvent sbstop(SE_SBUPDATE);
+
+ wxString *SBStopStr = new wxString;
+ *SBStopStr = _("Search stopped.");
+
+ sbstop.SetClientData(SBStopStr);
+ wxPostEvent(this, sbstop);
+ return;
+
+ }
+
+ if (vCardFilename.Right(4) == wxT(".vcf") ||
+ vCardFilename.Right(4) == wxT(".VCF") ||
+ vCardFilename.Right(5) == wxT(".vcard") ||
+ vCardFilename.Right(5) == wxT(".VCARD")){
+
+ vCard Person;
+ vCardFilenameFull.Append(AccountDir);
+ vCardFilenameFull.Append(vCardFilename);
+
+ Person.LoadFile(vCardFilenameFull);
+
+ vcardfilenamewxs = vCardFilenameFull;
+
+ // Check if file has version 4.0, first name (FN)
+ // begin and end vCard portions.
+
+ // Don't search unless these conditions have been met.
+
+ if (Person.MeetBaseSpecification()){
+
+ // Go through each of the search settings and check
+ // if they match with contact details.
+
+ // If it matches then add to the search results.
+
+ int SelOpt = 0;
+ bool chkOpt = FALSE;
+ wxString StrOpt;
+ int StrOptLen = 0;
+ ArrayvCardOutData ArrayData;
+ ArrayvCardOutData NicknameArrayData;
+ vCardName NameArray = Person.GetName();
+ wxString ContactFinalNickname;
+ NicknameArrayData = Person.GetByPartial(wxT("NICKNAME"));
+
+ if (NicknameArrayData.PropCount != 0){
+ ContactFinalNickname = NicknameArrayData.PropValues[0];
+ }
+
+ for (std::map<int, void*>::iterator siter = SearchFrames.begin();
+ siter != SearchFrames.end(); siter++){
+
+ // Get the settings from the form.
+
+ XABSearchPanel *XABSPPtr = static_cast<XABSearchPanel*>(siter->second);
+
+ // Get Selected Option and Setting.
+
+ SelOpt = XABSPPtr->GetSelectionOption();
+
+ if (SelOpt < 12){
+
+ StrOpt = XABSPPtr->GetStringSetting();
+ StrOptLen = StrOpt.Len();
+
+ if (SelOpt == 0 || SelOpt == 4 || SelOpt == 8){
+
+ // Matching string that beings with...
+
+ // Double check the std::map inserts for each section.
+
+ if (SelOpt == 0){
+
+ // Get the forename from the first N.
+
+ if (NameArray.Forename.Mid(0, StrOptLen) == StrOpt){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 4){
+
+ if (NameArray.Surname.Mid(0, StrOptLen) == StrOpt){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 8){
+
+ wxString NicknameData;
+
+ for (int i = 0; i < NicknameArrayData.PropCount; i++){
+
+ NicknameData = NicknameArrayData.PropValues[i];
+
+ if (NicknameData.Mid(0, StrOptLen) == StrOpt){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ break;
+
+ }
+
+ }
+
+ }
+
+ } else if (SelOpt == 1 || SelOpt == 5 || SelOpt == 9){
+
+ // Matching string that ends with...
+
+ if (SelOpt == 1){
+
+ // Check the forename.
+
+ if (NameArray.Forename.Right(StrOptLen) == StrOpt){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 5){
+
+ if (NameArray.Surname.Right(StrOptLen) == StrOpt){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 9){
+
+ wxString NicknameData;
+
+ for (int i = 0; i < NicknameArrayData.PropCount; i++){
+
+ NicknameData = NicknameArrayData.PropValues[i];
+ NicknameData.Trim();
+
+ if (NicknameData.Right(StrOptLen) == StrOpt){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ break;
+
+ }
+
+ }
+
+ }
+
+ } else if (SelOpt == 2 || SelOpt == 6 || SelOpt == 10){
+
+ // Matching string that contains...
+
+ if (SelOpt == 2){
+
+ if (NameArray.Forename.Find(StrOpt) != wxNOT_FOUND){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 6){
+
+ if (NameArray.Surname.Find(StrOpt) != wxNOT_FOUND){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 10){
+
+ wxString NicknameData;
+
+ for (int i = 0; i < NicknameArrayData.PropCount; i++){
+
+ NicknameData = NicknameArrayData.PropValues[i];
+ NicknameData.Trim();
+
+ if (NicknameData.Find(StrOpt) != wxNOT_FOUND){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ break;
+
+ }
+
+ }
+
+ }
+
+ } else if (SelOpt == 3 || SelOpt == 7 || SelOpt == 11){
+
+ // Matching String that doesn't contain...
+
+ if (SelOpt == 3){
+
+ // Process the nickname data.
+
+ if (NameArray.Forename.Find(StrOpt) == wxNOT_FOUND){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 7){
+
+ if (!NameArray.Surname.Find(StrOpt) == wxNOT_FOUND){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 11){
+
+ wxString NicknameData;
+
+ for (int i = 0; i < NicknameArrayData.PropCount; i++){
+
+ NicknameData = NicknameArrayData.PropValues[i];
+ NicknameData.Trim();
+
+ if (NicknameData.Find(StrOpt) == wxNOT_FOUND){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ break;
+
+ }
+
+ }
+
+ }
+
+ }
+
+ } else {
+
+ chkOpt = XABSPPtr->GetCheckboxSetting();
+
+ if (SelOpt == 12){
+
+ // Search should check if it has a photo or not.
+
+ ArrayData = Person.GetByPartial(wxT("PHOTO"));
+
+ if ((ArrayData.PropCount >= 1 &&
+ chkOpt == TRUE) ||
+ (ArrayData.PropCount == 0 &&
+ chkOpt == FALSE)){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 13){
+
+ // Search should check if it has a logo or not.
+
+ ArrayData = Person.GetByPartial(wxT("LOGO"));
+
+ if ((ArrayData.PropCount >= 1 &&
+ chkOpt == TRUE) ||
+ (ArrayData.PropCount == 0 &&
+ chkOpt == FALSE)){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ } else if (SelOpt == 14){
+
+ // Search should check if it has sound or not.
+
+ ArrayData = Person.GetByPartial(wxT("SOUND"));
+
+ if ((ArrayData.PropCount >= 1 &&
+ chkOpt == TRUE) ||
+ (ArrayData.PropCount == 0 &&
+ chkOpt == FALSE)){
+
+ if (CheckDuplicate(vcardfilenamewxs,
+ SAPiter->second,
+ &SearchResultAccount,
+ &SearchResultFilename) == TRUE){
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+ continue;
+
+ }
+
+ SRNotif *sradd = new SRNotif;
+
+ sradd->ContactName = NameArray;
+ sradd->ContactNickname = ContactFinalNickname;
+ sradd->ContactAccount = SAPiter->second;
+ sradd->ContactAccountName = SALiter->second;
+ sradd->ContactFullFilename = vcardfilenamewxs;
+ sradd->SearchResultID = intResultFound;
+
+ SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
+ SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
+
+ intResultFound++;
+
+ wxCommandEvent sraddenv(SE_ADDRESULT);
+ sraddenv.SetClientData(sradd);
+ wxPostEvent(this, sraddenv);
+
+ }
+
+ }
+
+ }
+
+ SelOpt = 0;
+ chkOpt = FALSE;
+ StrOpt.Clear();
+ StrOptLen = 0;
+ ArrayData.PropData.Clear();
+ ArrayData.PropValues.Clear();
+ ArrayData.PropCount = 0;
+
+ }
+
+ } else {
+
+ }
+
+ }
+
+ vCardFilename.Clear();
+ vCardFilenameFull.Clear();
+ ProcFiles = vcardaccdir.GetNext(&vCardFilename);
+
+ }
+
+ } else {
+
+ }
+
+ }
+
+ // Finished searching... clear up.
+
+ wxCommandEvent sbfinstr (SE_SBUPDATE);
+
+ wxString *SBFinish = new wxString;
+
+ if (intResultFound == 0){
+
+ *SBFinish = _("No contacts found.");
+
+ } else if (intResultFound == 1){
+
+ *SBFinish = _("1 contact found.");
+
+ } else {
+
+ *SBFinish = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
+
+ }
+
+ sbfinstr.SetClientData(SBFinish);
+ wxPostEvent(this, sbfinstr);
+
+ wxCommandEvent sbfinish (SE_SEARCHFINISHED);
+ wxPostEvent(this, sbfinish);
+
+}
\ No newline at end of file
--- /dev/null
+// frmSearch-result.cpp - Search result subroutines.
+//
+// (c) 2012-2015 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
+
+#include "frmSearch.h"
+#include "../frmMain.h"
+#include "../frmContact.h"
+
+void frmSearch::AddResult( wxCommandEvent& event ){
+
+ SRNotif *srnotif = (SRNotif*)event.GetClientData();
+
+ // Process Data and add to the list of results.
+
+ wxListItem item;
+
+ // Setup the contact name.
+
+ wxString ContactNameFinal;
+
+ if (!srnotif->ContactName.Title.IsEmpty()){
+
+ ContactNameFinal.append(srnotif->ContactName.Title);
+ ContactNameFinal.Trim();
+ ContactNameFinal.append(wxT(" "));
+
+ }
+
+ if (!srnotif->ContactName.Forename.IsEmpty()){
+
+ ContactNameFinal.append(srnotif->ContactName.Forename);
+ ContactNameFinal.Trim();
+ ContactNameFinal.append(wxT(" "));
+
+ }
+
+ if (!srnotif->ContactName.Surname.IsEmpty()){
+
+ ContactNameFinal.append(srnotif->ContactName.Surname);
+ ContactNameFinal.Trim();
+ ContactNameFinal.append(wxT(" "));
+
+ }
+
+ if (!srnotif->ContactName.Suffix.IsEmpty()){
+
+ ContactNameFinal.append(srnotif->ContactName.Suffix);
+ ContactNameFinal.Trim();
+
+ }
+
+ item.SetId(0);
+ item.SetText(ContactNameFinal);
+ item.SetData(srnotif->SearchResultID);
+
+ long ListCtrlIndex = lstResults->InsertItem(item);
+
+ //SearchResultAccount.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactAccount));
+ //SearchResultFilename.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactFullFilename));
+
+ srnotif->ContactNickname.Trim();
+
+ lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname);
+ lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName);
+
+ delete srnotif;
+ srnotif = NULL;
+
+}
+
+void frmSearch::UpdateResult( wxCommandEvent& event ){
+
+ UCNotif *uc = (UCNotif*)event.GetClientData();
+
+ long longSelected = -1;
+ int intSelectedData = 0;
+
+ for (;;){
+
+ longSelected = lstResults->GetNextItem(longSelected,
+ wxLIST_NEXT_ALL,
+ wxLIST_STATE_DONTCARE);
+
+ if (longSelected == -1){
+
+ break;
+
+ }
+
+ // Get the filename/ID information.
+
+ intSelectedData = lstResults->GetItemData(longSelected);
+
+ if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
+
+ // Process the contact name
+
+ wxString ContactNameFinal;
+
+ if (!uc->ContactNameArray.Title.IsEmpty()){
+
+ ContactNameFinal.append(uc->ContactNameArray.Title);
+ ContactNameFinal.Trim();
+ ContactNameFinal.append(wxT(" "));
+
+ }
+
+ if (!uc->ContactNameArray.Forename.IsEmpty()){
+
+ ContactNameFinal.append(uc->ContactNameArray.Forename);
+ ContactNameFinal.Trim();
+ ContactNameFinal.append(wxT(" "));
+
+ }
+
+ if (!uc->ContactNameArray.Surname.IsEmpty()){
+
+ ContactNameFinal.append(uc->ContactNameArray.Surname);
+ ContactNameFinal.Trim();
+ ContactNameFinal.append(wxT(" "));
+
+ }
+
+ if (!uc->ContactNameArray.Suffix.IsEmpty()){
+
+ ContactNameFinal.append(uc->ContactNameArray.Suffix);
+ ContactNameFinal.Trim();
+
+ }
+
+ lstResults->SetItem(longSelected, 0, ContactNameFinal);
+ lstResults->SetItem(longSelected, 1, uc->ContactNickname);
+
+ }
+
+ }
+
+ delete uc;
+ uc = NULL;
+
+}
+
+bool frmSearch::CheckDuplicate(wxString Filename,
+ wxString Account,
+ std::map<long,wxString> *SRAcc,
+ std::map<long,wxString> *SRFN){
+
+ std::map<long,wxString>::iterator fniter;
+
+ // Check comparison code.
+
+ for (std::map<long,wxString>::iterator aciter = SRAcc->begin();
+ aciter != SRAcc->end(); aciter++){
+
+ fniter = SRFN->find(aciter->first);
+
+ if (Filename == fniter->second &&
+ Account == aciter->second){
+
+ return TRUE;
+
+ }
+
+ }
+
+ return FALSE;
+
+}
+
+void frmSearch::DeleteResult(wxCommandEvent &event){
+
+ UCNotif *uc = (UCNotif*)event.GetClientData();
+
+ long longSelected = -1;
+ int intSelectedData = 0;
+
+ for (;;){
+
+ longSelected = lstResults->GetNextItem(longSelected,
+ wxLIST_NEXT_ALL,
+ wxLIST_STATE_DONTCARE);
+
+ if (longSelected == -1){
+
+ break;
+
+ }
+
+ // Get the filename/ID information.
+
+ intSelectedData = lstResults->GetItemData(longSelected);
+
+ if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
+
+ // Delete the result from the search list and
+ // update the total search results.
+
+ // Remove DeleteResultEvent and find out where the uc
+ // data is still being used as it crashes on delete.
+
+ lstResults->DeleteItem(longSelected);
+
+ // Update the number of search results.
+
+ wxCommandEvent sbu(SE_SBUPDATE);
+ wxString *SBUpdate = new wxString;
+
+ // Get the number of results.
+
+ int intResultFound = lstResults->GetItemCount();
+
+ // Prepare the status bar message.
+
+ if (intResultFound == 0){
+
+ *SBUpdate = _("No contacts found.");
+
+ } else if (intResultFound == 1){
+
+ *SBUpdate = _("1 contact found.");
+
+ } else {
+
+ *SBUpdate = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
+
+ }
+
+ sbu.SetClientData(SBUpdate);
+ wxPostEvent(this, sbu);
+
+ break;
+
+ }
+
+ }
+
+ delete uc;
+ uc = NULL;
+
+}