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 SRNotif *srnotif = (SRNotif*)event.GetClientData();
27 // Process Data and add to the list of results.
31 // Setup the contact name.
33 wxString ContactNameFinal;
35 if (!srnotif->ContactName.Title.IsEmpty()){
37 ContactNameFinal.append(srnotif->ContactName.Title);
38 ContactNameFinal.Trim();
39 ContactNameFinal.append(wxT(" "));
43 if (!srnotif->ContactName.Forename.IsEmpty()){
45 ContactNameFinal.append(srnotif->ContactName.Forename);
46 ContactNameFinal.Trim();
47 ContactNameFinal.append(wxT(" "));
51 if (!srnotif->ContactName.Surname.IsEmpty()){
53 ContactNameFinal.append(srnotif->ContactName.Surname);
54 ContactNameFinal.Trim();
55 ContactNameFinal.append(wxT(" "));
59 if (!srnotif->ContactName.Suffix.IsEmpty()){
61 ContactNameFinal.append(srnotif->ContactName.Suffix);
62 ContactNameFinal.Trim();
67 item.SetText(ContactNameFinal);
68 item.SetData(srnotif->SearchResultID);
70 long ListCtrlIndex = lstResults->InsertItem(item);
72 //SearchResultAccount.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactAccount));
73 //SearchResultFilename.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactFullFilename));
75 srnotif->ContactNickname.Trim();
77 lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname);
78 lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName);
85 void frmSearch::UpdateResult( wxCommandEvent& event ){
87 UCNotif *uc = (UCNotif*)event.GetClientData();
89 long longSelected = -1;
90 int intSelectedData = 0;
94 longSelected = lstResults->GetNextItem(longSelected,
96 wxLIST_STATE_DONTCARE);
98 if (longSelected == -1){
104 // Get the filename/ID information.
106 intSelectedData = lstResults->GetItemData(longSelected);
108 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
110 // Process the contact name
112 wxString ContactNameFinal;
114 if (!uc->ContactNameArray.Title.IsEmpty()){
116 ContactNameFinal.append(uc->ContactNameArray.Title);
117 ContactNameFinal.Trim();
118 ContactNameFinal.append(wxT(" "));
122 if (!uc->ContactNameArray.Forename.IsEmpty()){
124 ContactNameFinal.append(uc->ContactNameArray.Forename);
125 ContactNameFinal.Trim();
126 ContactNameFinal.append(wxT(" "));
130 if (!uc->ContactNameArray.Surname.IsEmpty()){
132 ContactNameFinal.append(uc->ContactNameArray.Surname);
133 ContactNameFinal.Trim();
134 ContactNameFinal.append(wxT(" "));
138 if (!uc->ContactNameArray.Suffix.IsEmpty()){
140 ContactNameFinal.append(uc->ContactNameArray.Suffix);
141 ContactNameFinal.Trim();
145 lstResults->SetItem(longSelected, 0, ContactNameFinal);
146 lstResults->SetItem(longSelected, 1, uc->ContactNickname);
157 bool frmSearch::CheckDuplicate(wxString Filename,
159 std::map<long,wxString> *SRAcc,
160 std::map<long,wxString> *SRFN){
162 std::map<long,wxString>::iterator fniter;
164 // Check comparison code.
166 for (std::map<long,wxString>::iterator aciter = SRAcc->begin();
167 aciter != SRAcc->end(); aciter++){
169 fniter = SRFN->find(aciter->first);
171 if (Filename == fniter->second &&
172 Account == aciter->second){
184 void frmSearch::DeleteResult(wxCommandEvent &event){
186 UCNotif *uc = (UCNotif*)event.GetClientData();
188 long longSelected = -1;
189 int intSelectedData = 0;
193 longSelected = lstResults->GetNextItem(longSelected,
195 wxLIST_STATE_DONTCARE);
197 if (longSelected == -1){
203 // Get the filename/ID information.
205 intSelectedData = lstResults->GetItemData(longSelected);
207 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
209 // Delete the result from the search list and
210 // update the total search results.
212 // Remove DeleteResultEvent and find out where the uc
213 // data is still being used as it crashes on delete.
215 lstResults->DeleteItem(longSelected);
217 // Update the number of search results.
219 wxCommandEvent sbu(SE_SBUPDATE);
220 wxString *SBUpdate = new wxString;
222 // Get the number of results.
224 int intResultFound = lstResults->GetItemCount();
226 // Prepare the status bar message.
228 if (intResultFound == 0){
230 *SBUpdate = _("No contacts found.");
232 } else if (intResultFound == 1){
234 *SBUpdate = _("1 contact found.");
238 *SBUpdate = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
242 sbu.SetClientData(SBUpdate);
243 wxPostEvent(this, sbu);