// 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 ){
// Add a search result.
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 ){
// Update a result.
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){
// Check for duplicate search results.
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){
// Delete the search result.
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;
}