Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmSearch.cpp split into 4 C++ source files for easier management.
[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         SRNotif *srnotif = (SRNotif*)event.GetClientData();
26         
27         // Process Data and add to the list of results.
28         
29         wxListItem item;
30         
31         // Setup the contact name.
32         
33         wxString ContactNameFinal;
34         
35         if (!srnotif->ContactName.Title.IsEmpty()){
36         
37                 ContactNameFinal.append(srnotif->ContactName.Title);
38                 ContactNameFinal.Trim();
39                 ContactNameFinal.append(wxT(" "));
40         
41         }
42         
43         if (!srnotif->ContactName.Forename.IsEmpty()){
44         
45                 ContactNameFinal.append(srnotif->ContactName.Forename);
46                 ContactNameFinal.Trim();
47                 ContactNameFinal.append(wxT(" "));
48         
49         }
51         if (!srnotif->ContactName.Surname.IsEmpty()){
52         
53                 ContactNameFinal.append(srnotif->ContactName.Surname);
54                 ContactNameFinal.Trim();
55                 ContactNameFinal.append(wxT(" "));
56         
57         }
58         
59         if (!srnotif->ContactName.Suffix.IsEmpty()){
60         
61                 ContactNameFinal.append(srnotif->ContactName.Suffix);
62                 ContactNameFinal.Trim();
63         
64         }
65         
66         item.SetId(0);
67         item.SetText(ContactNameFinal);
68         item.SetData(srnotif->SearchResultID);
69         
70         long ListCtrlIndex = lstResults->InsertItem(item);
71         
72         //SearchResultAccount.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactAccount));
73         //SearchResultFilename.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactFullFilename));
74         
75         srnotif->ContactNickname.Trim();
77         lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname);
78         lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName);     
79         
80         delete srnotif;
81         srnotif = NULL;
83 }
85 void frmSearch::UpdateResult( wxCommandEvent& event ){
87         UCNotif *uc = (UCNotif*)event.GetClientData();
88         
89         long longSelected = -1;
90         int intSelectedData = 0;
91                 
92         for (;;){
94                 longSelected = lstResults->GetNextItem(longSelected, 
95                         wxLIST_NEXT_ALL,
96                         wxLIST_STATE_DONTCARE);
97                 
98                 if (longSelected == -1){
99                 
100                         break;
101                 
102                 }
103                 
104                 // Get the filename/ID information.
105                 
106                 intSelectedData = lstResults->GetItemData(longSelected);
107                 
108                 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
109                 
110                         // Process the contact name
111                 
112                         wxString ContactNameFinal;
113                         
114                         if (!uc->ContactNameArray.Title.IsEmpty()){
115         
116                                 ContactNameFinal.append(uc->ContactNameArray.Title);
117                                 ContactNameFinal.Trim();
118                                 ContactNameFinal.append(wxT(" "));
119         
120                         }
121         
122                         if (!uc->ContactNameArray.Forename.IsEmpty()){
123         
124                                 ContactNameFinal.append(uc->ContactNameArray.Forename);
125                                 ContactNameFinal.Trim();
126                                 ContactNameFinal.append(wxT(" "));
127         
128                         }
130                         if (!uc->ContactNameArray.Surname.IsEmpty()){
131         
132                                 ContactNameFinal.append(uc->ContactNameArray.Surname);
133                                 ContactNameFinal.Trim();
134                                 ContactNameFinal.append(wxT(" "));
135         
136                         }
137         
138                         if (!uc->ContactNameArray.Suffix.IsEmpty()){
139         
140                                 ContactNameFinal.append(uc->ContactNameArray.Suffix);
141                                 ContactNameFinal.Trim();
142         
143                         }
144                 
145                         lstResults->SetItem(longSelected, 0, ContactNameFinal);
146                         lstResults->SetItem(longSelected, 1, uc->ContactNickname);
147                 
148                 }
149         
150         }
151         
152         delete uc;
153         uc = NULL;
157 bool frmSearch::CheckDuplicate(wxString Filename,
158         wxString Account, 
159         std::map<long,wxString> *SRAcc,
160         std::map<long,wxString> *SRFN){
161         
162         std::map<long,wxString>::iterator fniter;
163         
164         // Check comparison code.
165         
166         for (std::map<long,wxString>::iterator aciter = SRAcc->begin();
167                 aciter != SRAcc->end(); aciter++){
168                 
169                 fniter = SRFN->find(aciter->first);
171                 if (Filename == fniter->second && 
172                         Account == aciter->second){
173                 
174                         return TRUE;
175                         
176                 }
177                 
178         }
179         
180         return FALSE;
181         
184 void frmSearch::DeleteResult(wxCommandEvent &event){
186         UCNotif *uc = (UCNotif*)event.GetClientData();
188         long longSelected = -1;
189         int intSelectedData = 0;
190                 
191         for (;;){
193                 longSelected = lstResults->GetNextItem(longSelected, 
194                         wxLIST_NEXT_ALL,
195                         wxLIST_STATE_DONTCARE);
196                 
197                 if (longSelected == -1){
198                 
199                         break;
200                 
201                 }
202                 
203                 // Get the filename/ID information.
204                 
205                 intSelectedData = lstResults->GetItemData(longSelected);
206                 
207                 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
208                 
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);
216                         
217                         // Update the number of search results.
218                                                 
219                         wxCommandEvent sbu(SE_SBUPDATE);
220                         wxString *SBUpdate = new wxString;
222                         // Get the number of results.
224                         int intResultFound = lstResults->GetItemCount();
225         
226                         // Prepare the status bar message.
227         
228                         if (intResultFound == 0){
229         
230                                 *SBUpdate = _("No contacts found.");
231         
232                         } else if (intResultFound == 1){
233         
234                                 *SBUpdate = _("1 contact found.");
235         
236                         } else {
237         
238                                 *SBUpdate = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
239         
240                         }
241                 
242                         sbu.SetClientData(SBUpdate);
243                         wxPostEvent(this, sbu);
244                 
245                         break;
246                 
247                 }
248         
249         }
251         delete uc;
252         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