Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmPreferences: Removed std::cout printing contact background colour
[xestiaab/.git] / source / search / frmSearch-result.cpp
1 // frmSearch-result.cpp - Search result subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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.
26         
27         SRNotif *srnotif = (SRNotif*)event.GetClientData();
28         
29         // Process Data and add to the list of results.
30         
31         wxListItem item;
32         
33         // Setup the contact name.
34         
35         wxString ContactNameFinal;
36         
37         if (!srnotif->ContactName.Title.IsEmpty()){
38         
39                 ContactNameFinal.append(srnotif->ContactName.Title);
40                 ContactNameFinal.Trim();
41                 ContactNameFinal.append(wxT(" "));
42         
43         }
44         
45         if (!srnotif->ContactName.Forename.IsEmpty()){
46         
47                 ContactNameFinal.append(srnotif->ContactName.Forename);
48                 ContactNameFinal.Trim();
49                 ContactNameFinal.append(wxT(" "));
50         
51         }
53         if (!srnotif->ContactName.Surname.IsEmpty()){
54         
55                 ContactNameFinal.append(srnotif->ContactName.Surname);
56                 ContactNameFinal.Trim();
57                 ContactNameFinal.append(wxT(" "));
58         
59         }
60         
61         if (!srnotif->ContactName.Suffix.IsEmpty()){
62         
63                 ContactNameFinal.append(srnotif->ContactName.Suffix);
64                 ContactNameFinal.Trim();
65         
66         }
67         
68         item.SetId(0);
69         item.SetText(ContactNameFinal);
70         item.SetData(srnotif->SearchResultID);
71         
72         long ListCtrlIndex = lstResults->InsertItem(item);
73         
74         //SearchResultAccount.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactAccount));
75         //SearchResultFilename.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactFullFilename));
76         
77         srnotif->ContactNickname.Trim();
79         lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname);
80         lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName);     
81         
82         delete srnotif;
83         srnotif = NULL;
85 }
87 void frmSearch::UpdateResult( wxCommandEvent& event ){
89         // Update a result.
90         
91         UCNotif *uc = (UCNotif*)event.GetClientData();
92         
93         long longSelected = -1;
94         int intSelectedData = 0;
95                 
96         for (;;){
98                 longSelected = lstResults->GetNextItem(longSelected, 
99                         wxLIST_NEXT_ALL,
100                         wxLIST_STATE_DONTCARE);
101                 
102                 if (longSelected == -1){
103                 
104                         break;
105                 
106                 }
107                 
108                 // Get the filename/ID information.
109                 
110                 intSelectedData = lstResults->GetItemData(longSelected);
111                 
112                 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
113                 
114                         // Process the contact name
115                 
116                         wxString ContactNameFinal;
117                         
118                         if (!uc->ContactNameArray.Title.IsEmpty()){
119         
120                                 ContactNameFinal.append(uc->ContactNameArray.Title);
121                                 ContactNameFinal.Trim();
122                                 ContactNameFinal.append(wxT(" "));
123         
124                         }
125         
126                         if (!uc->ContactNameArray.Forename.IsEmpty()){
127         
128                                 ContactNameFinal.append(uc->ContactNameArray.Forename);
129                                 ContactNameFinal.Trim();
130                                 ContactNameFinal.append(wxT(" "));
131         
132                         }
134                         if (!uc->ContactNameArray.Surname.IsEmpty()){
135         
136                                 ContactNameFinal.append(uc->ContactNameArray.Surname);
137                                 ContactNameFinal.Trim();
138                                 ContactNameFinal.append(wxT(" "));
139         
140                         }
141         
142                         if (!uc->ContactNameArray.Suffix.IsEmpty()){
143         
144                                 ContactNameFinal.append(uc->ContactNameArray.Suffix);
145                                 ContactNameFinal.Trim();
146         
147                         }
148                 
149                         lstResults->SetItem(longSelected, 0, ContactNameFinal);
150                         lstResults->SetItem(longSelected, 1, uc->ContactNickname);
151                 
152                 }
153         
154         }
155         
156         delete uc;
157         uc = NULL;
161 bool frmSearch::CheckDuplicate(wxString Filename,
162         wxString Account, 
163         std::map<long,wxString> *SRAcc,
164         std::map<long,wxString> *SRFN){
165         
166         // Check for duplicate search results.
167                 
168         std::map<long,wxString>::iterator fniter;
169         
170         // Check comparison code.
171         
172         for (std::map<long,wxString>::iterator aciter = SRAcc->begin();
173                 aciter != SRAcc->end(); aciter++){
174                 
175                 fniter = SRFN->find(aciter->first);
177                 if (Filename == fniter->second && 
178                         Account == aciter->second){
179                 
180                         return TRUE;
181                         
182                 }
183                 
184         }
185         
186         return FALSE;
187         
190 void frmSearch::DeleteResult(wxCommandEvent &event){
192         // Delete the search result.
193         
194         UCNotif *uc = (UCNotif*)event.GetClientData();
196         long longSelected = -1;
197         int intSelectedData = 0;
198                 
199         for (;;){
201                 longSelected = lstResults->GetNextItem(longSelected, 
202                         wxLIST_NEXT_ALL,
203                         wxLIST_STATE_DONTCARE);
204                 
205                 if (longSelected == -1){
206                 
207                         break;
208                 
209                 }
210                 
211                 // Get the filename/ID information.
212                 
213                 intSelectedData = lstResults->GetItemData(longSelected);
214                 
215                 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
216                 
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);
224                         
225                         // Update the number of search results.
226                                                 
227                         wxCommandEvent sbu(SE_SBUPDATE);
228                         wxString *SBUpdate = new wxString;
230                         // Get the number of results.
232                         int intResultFound = lstResults->GetItemCount();
233         
234                         // Prepare the status bar message.
235         
236                         if (intResultFound == 0){
237         
238                                 *SBUpdate = _("No contacts found.");
239         
240                         } else if (intResultFound == 1){
241         
242                                 *SBUpdate = _("1 contact found.");
243         
244                         } else {
245         
246                                 *SBUpdate = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
247         
248                         }
249                 
250                         sbu.SetClientData(SBUpdate);
251                         wxPostEvent(this, sbu);
252                 
253                         break;
254                 
255                 }
256         
257         }
259         delete uc;
260         uc = NULL;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy