1 // frmSearch-result.cpp - Search result subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmSearch.h"
20 #include "../frmMain.h"
21 #include "../frmContact.h"
23 void frmSearch::AddResult( wxCommandEvent& event ){
25 // Add a search result.
27 SRNotif *srnotif = (SRNotif*)event.GetClientData();
29 // Process Data and add to the list of results.
33 // Setup the contact name.
35 wxString ContactNameFinal;
37 if (!srnotif->ContactName.Title.IsEmpty()){
39 ContactNameFinal.append(srnotif->ContactName.Title);
40 ContactNameFinal.Trim();
41 ContactNameFinal.append(wxT(" "));
45 if (!srnotif->ContactName.Forename.IsEmpty()){
47 ContactNameFinal.append(srnotif->ContactName.Forename);
48 ContactNameFinal.Trim();
49 ContactNameFinal.append(wxT(" "));
53 if (!srnotif->ContactName.Surname.IsEmpty()){
55 ContactNameFinal.append(srnotif->ContactName.Surname);
56 ContactNameFinal.Trim();
57 ContactNameFinal.append(wxT(" "));
61 if (!srnotif->ContactName.Suffix.IsEmpty()){
63 ContactNameFinal.append(srnotif->ContactName.Suffix);
64 ContactNameFinal.Trim();
69 item.SetText(ContactNameFinal);
70 item.SetData(srnotif->SearchResultID);
72 long ListCtrlIndex = lstResults->InsertItem(item);
74 //SearchResultAccount.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactAccount));
75 //SearchResultFilename.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactFullFilename));
77 srnotif->ContactNickname.Trim();
79 lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname);
80 lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName);
87 void frmSearch::UpdateResult( wxCommandEvent& event ){
91 UCNotif *uc = (UCNotif*)event.GetClientData();
93 long longSelected = -1;
94 int intSelectedData = 0;
98 longSelected = lstResults->GetNextItem(longSelected,
100 wxLIST_STATE_DONTCARE);
102 if (longSelected == -1){
108 // Get the filename/ID information.
110 intSelectedData = lstResults->GetItemData(longSelected);
112 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
114 // Process the contact name
116 wxString ContactNameFinal;
118 if (!uc->ContactNameArray.Title.IsEmpty()){
120 ContactNameFinal.append(uc->ContactNameArray.Title);
121 ContactNameFinal.Trim();
122 ContactNameFinal.append(wxT(" "));
126 if (!uc->ContactNameArray.Forename.IsEmpty()){
128 ContactNameFinal.append(uc->ContactNameArray.Forename);
129 ContactNameFinal.Trim();
130 ContactNameFinal.append(wxT(" "));
134 if (!uc->ContactNameArray.Surname.IsEmpty()){
136 ContactNameFinal.append(uc->ContactNameArray.Surname);
137 ContactNameFinal.Trim();
138 ContactNameFinal.append(wxT(" "));
142 if (!uc->ContactNameArray.Suffix.IsEmpty()){
144 ContactNameFinal.append(uc->ContactNameArray.Suffix);
145 ContactNameFinal.Trim();
149 lstResults->SetItem(longSelected, 0, ContactNameFinal);
150 lstResults->SetItem(longSelected, 1, uc->ContactNickname);
161 bool frmSearch::CheckDuplicate(wxString Filename,
163 std::map<long,wxString> *SRAcc,
164 std::map<long,wxString> *SRFN){
166 // Check for duplicate search results.
168 std::map<long,wxString>::iterator fniter;
170 // Check comparison code.
172 for (std::map<long,wxString>::iterator aciter = SRAcc->begin();
173 aciter != SRAcc->end(); aciter++){
175 fniter = SRFN->find(aciter->first);
177 if (Filename == fniter->second &&
178 Account == aciter->second){
190 void frmSearch::DeleteResult(wxCommandEvent &event){
192 // Delete the search result.
194 UCNotif *uc = (UCNotif*)event.GetClientData();
196 long longSelected = -1;
197 int intSelectedData = 0;
201 longSelected = lstResults->GetNextItem(longSelected,
203 wxLIST_STATE_DONTCARE);
205 if (longSelected == -1){
211 // Get the filename/ID information.
213 intSelectedData = lstResults->GetItemData(longSelected);
215 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
217 // Delete the result from the search list and
218 // update the total search results.
220 // Remove DeleteResultEvent and find out where the uc
221 // data is still being used as it crashes on delete.
223 lstResults->DeleteItem(longSelected);
225 // Update the number of search results.
227 wxCommandEvent sbu(SE_SBUPDATE);
228 wxString *SBUpdate = new wxString;
230 // Get the number of results.
232 int intResultFound = lstResults->GetItemCount();
234 // Prepare the status bar message.
236 if (intResultFound == 0){
238 *SBUpdate = _("No contacts found.");
240 } else if (intResultFound == 1){
242 *SBUpdate = _("1 contact found.");
246 *SBUpdate = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
250 sbu.SetClientData(SBUpdate);
251 wxPostEvent(this, sbu);