X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=blobdiff_plain;f=source%2Fsearch%2FfrmSearch.cpp;h=9e4d8aa6a0622cf705b0f5a9faac4f3172c5bbcc;hp=542b646f7db54b874e19f117665cc6765426644f;hb=9802970e8be1fe9511ad9a9d0eb9ffe8d2cfea41;hpb=43a294d863a3cbcd825889adaa702f3a79dd7aa2 diff --git a/source/search/frmSearch.cpp b/source/search/frmSearch.cpp index 542b646..9e4d8aa 100644 --- a/source/search/frmSearch.cpp +++ b/source/search/frmSearch.cpp @@ -1,16 +1,32 @@ +// frmSearch.cpp - Search form. +// +// (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" -#include "search/XABSearchPanel.h" -#include "search/frmSearchAccounts.h" -#include "common/preferences.h" -#include "common/dirs.h" -#include "vcard/vcard.h" +#include "../frmMain.h" +#include "../frmContact.h" +#include "frmSearchAccounts.h" +#include "../common/preferences.h" +#include "../common/dirs.h" +#include "../vcard/vcard.h" #include -#include -#include -#include + +#define SEARCHSETTINGS_MAX 15 DEFINE_EVENT_TYPE(SE_ADDSEARCHSETTING); DEFINE_EVENT_TYPE(SE_REMOVESEARCHSETTING); @@ -43,6 +59,8 @@ frmSearch::frmSearch( wxWindow* parent ) frmSearchADT( parent ) { + // Setup the search window. + XABSearchPanel *InitPanel = new XABSearchPanel( tabSearch ); InitPanel->EnableButtons(TRUE, FALSE); InitPanel->SetupPointers(this); @@ -116,897 +134,34 @@ void frmSearch::SelectAccounts( wxCommandEvent& event ) } -void frmSearch::SearchContactsThread(){ +void frmSearch::SearchContacts( wxCommandEvent& event ) +{ - // Go through each account and find contacts based on the - // matched settings. + // Check if any accounts has been selected. - 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")){ + bool AccountsFound = false; - 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 { + for (std::map::iterator saiter = SearchAccounts.begin(); + saiter != SearchAccounts.end(); saiter++){ - } - - } - - vCardFilename.Clear(); - vCardFilenameFull.Clear(); - ProcFiles = vcardaccdir.GetNext(&vCardFilename); - - } - - } else { - + if (saiter->second == true){ + + AccountsFound = true; + break; + } - + } - // Finished searching... clear up. + if (AccountsFound == false){ - wxCommandEvent sbfinstr (SE_SBUPDATE); + wxMessageBox(_("No accounts have been selected to search contacts for."), + _("No accounts selected"), + wxOK|wxICON_ERROR); + return; - 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); - -} - -void frmSearch::SearchContacts( wxCommandEvent& event ) -{ - + // Change the button to stop. if (StopMode == FALSE){ @@ -1102,7 +257,6 @@ void frmSearch::AddSearchSetting( wxCommandEvent& event ) NewPanel->SetupPointers(this); NewPanel->SetupInteger(ScrollGen); szrSearch->Add(NewPanel, 1, wxEXPAND|wxGROW, 5); - //szrSearch->Fit(tabSearch); szrSearch->FitInside(tabSearch); szrSearch->Layout(); szrSearch->RecalcSizes(); @@ -1110,13 +264,13 @@ void frmSearch::AddSearchSetting( wxCommandEvent& event ) SearchFrames.insert(std::make_pair(ScrollGen, NewPanel)); ScrollGen++; - // Check if number of search settings is 15 (or over). + // Check if number of search settings is SEARCHSETTINGS_MAX (or over). // If it is, disable the option of adding extra settings // for all frames until one is removed. XABSearchPanel *XABSPPtr; - if (SearchFrames.size() >= 15){ + if (SearchFrames.size() >= SEARCHSETTINGS_MAX){ for (std::map::iterator iter = SearchFrames.begin(); iter != SearchFrames.end(); ++iter){ @@ -1149,13 +303,13 @@ void frmSearch::AddSearchSetting( wxCommandEvent& event ) void frmSearch::RemoveSearchSetting( wxCommandEvent& event ) { + // Remove a search setting frame from the list. + // Get the integer from the event. std::map::iterator iter; iter = SearchFrames.find(event.GetInt()); - // Remove a search setting frame from the list. - XABSearchPanel *XABSPPtr; XABSPPtr = static_cast(iter->second); @@ -1168,9 +322,7 @@ void frmSearch::RemoveSearchSetting( wxCommandEvent& event ) delete XABSPPtr; XABSPPtr = NULL; - //szrSearch->Fit(tabSearch); - - if (SearchFrames.size() < 15 && SearchFrames.size() > 1){ + if (SearchFrames.size() < SEARCHSETTINGS_MAX && SearchFrames.size() > 1){ for (std::map::iterator iter = SearchFrames.begin(); iter != SearchFrames.end(); ++iter){ @@ -1207,70 +359,10 @@ void frmSearch::ReloadAccountList( wxCommandEvent& event ){ } -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)); +void frmSearch::SearchBarUpdate( wxCommandEvent& event ){ - srnotif->ContactNickname.Trim(); - - lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname); - lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName); + // Update the status bar. - delete srnotif; - srnotif = NULL; - -} - -void frmSearch::SearchBarUpdate( wxCommandEvent& event ){ - wxString *SBData = (wxString*)event.GetClientData(); stbBottom->SetStatusText(*SBData, 0); @@ -1282,6 +374,9 @@ void frmSearch::SearchBarUpdate( wxCommandEvent& event ){ void frmSearch::SearchFinished( wxCommandEvent& event ){ + // Reset the search button and unlock the search + // panel buttons. + StopMode = FALSE; btnSearch->SetLabel(_("Search")); DisableAllSearchSettings(FALSE); @@ -1290,6 +385,35 @@ void frmSearch::SearchFinished( wxCommandEvent& event ){ void frmSearch::DisableAllSearchSettings(bool Enable){ + // Check if there is only one search value. If there is, only enable + // the add button if this is the case. + + if (SearchFrames.size() == 1){ + + XABSearchPanel *XABSPPtr = static_cast(SearchFrames.begin()->second); + XABSPPtr->EnableButtons(TRUE, FALSE); + return; + + } + + // Check if there is SEARCHSETTINGS_MAX controls set or more, only + // enable the remove button if this is the case. + + if (SearchFrames.size() >= SEARCHSETTINGS_MAX){ + + for (std::map::iterator siter = SearchFrames.begin(); + siter != SearchFrames.end(); siter++){ + + XABSearchPanel *XABSPPtr = static_cast(SearchFrames.begin()->second); + XABSPPtr->EnableButtons(FALSE, TRUE); + + } + return; + + } + + // More than one control, so process them. + for (std::map::iterator siter = SearchFrames.begin(); siter != SearchFrames.end(); siter++){ @@ -1311,121 +435,6 @@ void frmSearch::DisableAllSearchSettings(bool Enable){ } -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::CloseWindow( wxCloseEvent& event ){ // Hide the window so users don't panic @@ -1454,210 +463,49 @@ void frmSearch::CloseWindow( wxCloseEvent& event ){ // Close window. - WindowData *WData = new WindowData; - - WData->DataType = 2; - WData->WindowPointer = this; - WData->WindowID = SearchUID; - - wxCommandEvent delevent(WINDOW_CLOSE); - delevent.SetClientData(WData); - wxPostEvent(GetParent(), delevent); - - wxCommandEvent rs(CE_REMOVESEARCH); - wxPostEvent(this, rs); + if (SearchMode == false){ - WData = NULL; - - this->Destroy(); - -} - -void frmSearch::CloseWindow( wxCommandEvent& event ){ - - this->Close(); - -} + WindowData *WData = new WindowData; -void frmSearch::UpdateResult( wxCommandEvent& event ){ + WData->DataType = 2; + WData->WindowPointer = this; + WData->WindowID = SearchUID; - 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; - - } + wxCommandEvent delevent(WINDOW_CLOSE); + delevent.SetClientData(WData); + wxPostEvent(GetParent(), delevent); - // 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()){ + wxCommandEvent rs(CE_REMOVESEARCH); + wxPostEvent(this, rs); - 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(); - - } + WData = NULL; - 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); + this->Destroy(); - 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. +void frmSearch::CloseWindow( wxCommandEvent& event ){ - 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."); + // Close this window. - } - - sbu.SetClientData(SBUpdate); - wxPostEvent(this, sbu); - - break; - - } - - } - - delete uc; - uc = NULL; + this->Close(); } void frmSearch::SetUID(int UID){ + // Set the UID of the search window. + SearchUID = UID; } void frmSearch::SetSearchMode(bool SearchModeIn){ + // Set the search mode of the window. + SearchMode = SearchModeIn; if (SearchMode == TRUE){ @@ -1699,12 +547,4 @@ void frmSearch::SetSearchMode(bool SearchModeIn){ } -} - -void frmSearch::ShowContactMenu( wxMouseEvent& event ){ - - ContactMenu->SetupPointers(this, lstResults); - - PopupMenu(ContactMenu->MenuPointer(), wxDefaultPosition); - } \ No newline at end of file