From 5dc723f34826fbf69af3900e8118ef85c22ad32b Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Mon, 30 Nov 2015 12:41:44 +0000 Subject: [PATCH] frmSearch.cpp split into 4 C++ source files for easier management. --- source/search/frmSearch-contact.cpp | 144 +++++ source/search/frmSearch-process.cpp | 910 ++++++++++++++++++++++++++++ source/search/frmSearch-result.cpp | 254 ++++++++ 3 files changed, 1308 insertions(+) create mode 100644 source/search/frmSearch-contact.cpp create mode 100644 source/search/frmSearch-process.cpp create mode 100644 source/search/frmSearch-result.cpp diff --git a/source/search/frmSearch-contact.cpp b/source/search/frmSearch-contact.cpp new file mode 100644 index 0000000..f5c18b8 --- /dev/null +++ b/source/search/frmSearch-contact.cpp @@ -0,0 +1,144 @@ +// frmSearch-contact.cpp - Search contact 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 + +#include "frmSearch.h" +#include "../frmMain.h" +#include "../frmContact.h" + +void frmSearch::OpenContact( wxCommandEvent& event ){ + + // Check if a contact has been selected. + + long intSelected = -1; + int intSelectedData = 0; + long intContactSeekNum = -1; + + intSelected = lstResults->GetNextItem(intSelected, + wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); + + if (intSelected == -1){ + return; + } + + intContactSeekNum = lstResults->GetItemData(intSelected); + + if (SearchMode == TRUE){ + + wxMessageBox(SearchResultFilename[intContactSeekNum]); + + vCard Person; + + Person.LoadFile(SearchResultFilename[intContactSeekNum]); + + wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png)); + wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG); + wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1); + wxIcon contacticon; + contacticon.CopyFromBitmap(contacticonbmp); + + frmContact *Contact = new frmContact( this ); + + Contact->SetupPointers(&SearchModeMemoryFSPtr); + Contact->SetupContactData(&Person); + + Contact->SetIcon(contacticon); + Contact->Show(true); + + } else { + + UCNotif *uc = new UCNotif; + + uc->ContactAccount = SearchResultAccount[intContactSeekNum]; + uc->ContactFilename = SearchResultFilename[intContactSeekNum]; + + wxCommandEvent oc(CE_OPENCONTACT); + oc.SetClientData(uc); + wxPostEvent(this->GetParent(), oc); + + } + +} + +void frmSearch::EditContact( wxCommandEvent& event ){ + + // Check if a contact has been selected. + + long intSelected = -1; + int intSelectedData = 0; + long intContactSeekNum = -1; + + intSelected = lstResults->GetNextItem(intSelected, + wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); + + if (intSelected == -1){ + return; + } + + intContactSeekNum = lstResults->GetItemData(intSelected); + + UCNotif *uc = new UCNotif; + + uc->ContactAccount = SearchResultAccount[intContactSeekNum]; + uc->ContactFilename = SearchResultFilename[intContactSeekNum]; + + wxCommandEvent ec(CE_EDITCONTACT); + ec.SetClientData(uc); + ec.SetInt(1); + wxPostEvent(this->GetParent(), ec); + +} + +void frmSearch::RevealContact( wxCommandEvent& event ){ + + // Check if a contact has been selected. + + long intSelected = -1; + int intSelectedData = 0; + long intContactSeekNum = -1; + + intSelected = lstResults->GetNextItem(intSelected, + wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); + + if (intSelected == -1){ + return; + } + + intContactSeekNum = lstResults->GetItemData(intSelected); + + UCNotif *uc = new UCNotif; + + uc->ContactAccount = SearchResultAccount[intContactSeekNum]; + uc->ContactFilename = SearchResultFilename[intContactSeekNum]; + + wxCommandEvent rc(CE_REVEALCONTACT); + rc.SetClientData(uc); + rc.SetInt(1); + wxPostEvent(this->GetParent(), rc); + +} + +void frmSearch::ShowContactMenu( wxMouseEvent& event ){ + + ContactMenu->SetupPointers(this, lstResults); + + PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition); + +} \ No newline at end of file diff --git a/source/search/frmSearch-process.cpp b/source/search/frmSearch-process.cpp new file mode 100644 index 0000000..b111d05 --- /dev/null +++ b/source/search/frmSearch-process.cpp @@ -0,0 +1,910 @@ +// 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 + +#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::iterator SAiter; + std::map::iterator SAPiter; + int intResultFound = 0; + + for (std::map::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::iterator siter = SearchFrames.begin(); + siter != SearchFrames.end(); siter++){ + + // Get the settings from the form. + + XABSearchPanel *XABSPPtr = static_cast(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 diff --git a/source/search/frmSearch-result.cpp b/source/search/frmSearch-result.cpp new file mode 100644 index 0000000..6216af1 --- /dev/null +++ b/source/search/frmSearch-result.cpp @@ -0,0 +1,254 @@ +// 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 + +#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 *SRAcc, + std::map *SRFN){ + + std::map::iterator fniter; + + // Check comparison code. + + for (std::map::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; + +} -- 2.39.5