Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated Activity Manager
[xestiaab/.git] / source / frmSearch.cpp
1 #include "frmSearch.h"
2 #include "frmMain.h"
3 #include "search/XABSearchPanel.h"
4 #include "search/frmSearchAccounts.h"
5 #include "common/preferences.h"
6 #include "common/dirs.h"
7 #include "vcard/vcard.h"
9 #include <thread>
10 /*#include <boost/filesystem.hpp>
11 #include <boost/filesystem/fstream.hpp>
12 #include <boost/filesystem/path.hpp>*/
13 #include <wx/tokenzr.h>
14 #include <wx/dir.h>
16 DEFINE_EVENT_TYPE(SE_ADDSEARCHSETTING);
17 DEFINE_EVENT_TYPE(SE_REMOVESEARCHSETTING);
18 DEFINE_EVENT_TYPE(SE_RELOADACCOUNTS);
19 DEFINE_EVENT_TYPE(SE_ADDRESULT);
20 DEFINE_EVENT_TYPE(SE_SBUPDATE);
21 DEFINE_EVENT_TYPE(SE_SEARCHFINISHED);
22 DEFINE_EVENT_TYPE(SE_UPDATERESULT);
23 DEFINE_EVENT_TYPE(SE_DELETERESULT);
25 BEGIN_EVENT_TABLE(frmSearch, wxFrame)
26   EVT_COMMAND(wxID_ANY, SE_ADDSEARCHSETTING, frmSearch::AddSearchSetting)
27   EVT_COMMAND(wxID_ANY, SE_REMOVESEARCHSETTING, frmSearch::RemoveSearchSetting)
28   EVT_COMMAND(wxID_ANY, SE_RELOADACCOUNTS, frmSearch::ReloadAccountList)
29   EVT_COMMAND(wxID_ANY, SE_ADDRESULT, frmSearch::AddResult)
30   EVT_COMMAND(wxID_ANY, SE_SBUPDATE, frmSearch::SearchBarUpdate)
31   EVT_COMMAND(wxID_ANY, SE_SEARCHFINISHED, frmSearch::SearchFinished)
32   EVT_COMMAND(wxID_ANY, SE_UPDATERESULT, frmSearch::UpdateResult)
33   EVT_COMMAND(wxID_ANY, SE_DELETERESULT, frmSearch::DeleteResult)
34 END_EVENT_TABLE()
36 //namespace boostfs = boost::filesystem;
38 frmSearch::frmSearch( wxWindow* parent )
39 :
40 frmSearchADT( parent )
41 {
42         
43         XABSearchPanel *InitPanel = new XABSearchPanel( tabSearch );
44         InitPanel->EnableButtons(TRUE, FALSE);
45         InitPanel->SetupPointers(this);
46         InitPanel->SetupInteger(ScrollGen);
47         szrSearch->Add(InitPanel, 1, wxEXPAND, 0);
48         szrSearch->Fit(tabSearch);
49         SearchFrames.insert(std::make_pair(ScrollGen, InitPanel));
50         ScrollGen++;
51         
52         // Get the list of accounts and mark them as true.
54         wxString preffilename = GetUserPrefDir();
56         XABPreferences preferences(preffilename);       
57         
58         wxString AccDir;
59         wxString AccDirFull;
60         wxString AccDirFullSfx;
61         
62         for (int i = 0; i < preferences.accounts.GetCount(); i++){
63                 AccDir = preferences.accounts.GetAccountDirectory(i);
64                 AccDirFull = preferences.accounts.GetAccountDirectory(i);
65                 AccDirFull.Trim();
66                 AccDirFull.Append(wxT("."));
67                 AccDirFullSfx.Append(preferences.accounts.GetAccountType(i));
68                 AccDirFullSfx.LowerCase();
69                 AccDirFullSfx.Trim();
70                 AccDirFull.Append(AccDirFullSfx);
71                 SearchAccountsPaths.insert(std::make_pair(AccDir, AccDirFull));
72                 SearchAccounts.insert(std::make_pair(AccDir, TRUE));
73                 SearchAccountsNames.insert(std::make_pair(AccDir,
74                         preferences.accounts.GetAccountName(i)));
75                 AccDirFull.clear();
76                 AccDirFullSfx.clear();
77                 AccDir.clear();
78         }
79         
80         // Setup the columns.
81         
82         wxListItem item;
83         item.SetId(0);
84         item.SetText(_("Name"));
85         item.SetWidth(228);
86         
87         lstResults->InsertColumn(0, item);
88         
89         item.SetId(1);
90         item.SetText(_("Nickname"));
91         item.SetWidth(128);
92         
93         lstResults->InsertColumn(1, item);
94         
95         item.SetId(2);
96         item.SetText(_("Account"));
97         item.SetWidth(128);
98         
99         lstResults->InsertColumn(2, item);
100         
103 void frmSearch::SelectAccounts( wxCommandEvent& event )
106         // Create the form and display as modal.
108         frmSearchAccounts *frameSAccount = new frmSearchAccounts ( this );
109         frameSAccount->LoadSearchAccounts(&SearchAccounts, &SearchAccountsNames);
110         frameSAccount->ShowModal();
111         delete frameSAccount;
112         frameSAccount = NULL;
116 void frmSearch::SearchContactsThread(){
118         // Go through each account and find contacts based on the
119         // matched settings.
120         
121         std::map<wxString,bool>::iterator SAiter;
122         std::map<wxString,wxString>::iterator SAPiter;
123         int intResultFound = 0;
124         
125         for (std::map<wxString, wxString>::iterator SALiter = SearchAccountsNames.begin(); 
126                 SALiter != SearchAccountsNames.end();
127                 SALiter++){
128         
129                 // Double check that we are searching in this account.
130                 // If not, skip to the next one.
131                 
132                 SAiter = SearchAccounts.find(SALiter->first);
133                 SAPiter = SearchAccountsPaths.find(SAiter->first);
134                 
135                 
136                 if (SAiter->second == FALSE){
137                 
138                         // Not looking in this account. Go to next account.
139                 
140                         continue;
141                 
142                 }
143                 
144                 wxCommandEvent sbupdate (SE_SBUPDATE);
145                 
146                 wxString *SBData = new wxString;
147                 *SBData = _("Searching ") + SALiter->second + _("...");
148                 
149                 sbupdate.SetClientData(SBData);         
150                 wxPostEvent(this, sbupdate);
151                 
152                 if (StopMode == FALSE){
153                 
154                         wxCommandEvent sbstop (SE_SBUPDATE);
155                 
156                         wxString *SBStopStr = new wxString;
157                         *SBStopStr = _("Search stopped.");
158                 
159                         sbstop.SetClientData(SBStopStr);                
160                         wxPostEvent(this, sbstop);
161                         return;
162                 
163                 }
164                 
165                 // Get the list of contact files and process each
166                 // one of them.
167                 
168                 wxString AccountDir = GetAccountDir(SAPiter->second, FALSE);
169                 
170                 //boostfs::path vcarddir(AccountDir.c_str());
171                 //boostfs::directory_iterator dir_end;    
173                 //boostfs::path vcardfilename;
174                 wxString vcardfilenamewxs;
175                 wxStringTokenizer vcardfileline;
176                 //std::string l;
177                 wxString lwxs;
178                 wxString setname, setvalue;
179                 long ContactIndex = 1;
180                 long ContactSeekPoint = 0;
181                 wxString vCardFilename;
182                 wxString vCardFilenameFull;
183                 
184                 //if (boostfs::exists(vcarddir)){
185                 if (wxDirExists(AccountDir)){
186                 
187                         wxDir vcardaccdir(AccountDir);
188                 
189                         bool ProcFiles = vcardaccdir.GetFirst(&vCardFilename, wxEmptyString, wxDIR_FILES);
190                         while(ProcFiles){
191                         //for (boostfs::directory_iterator vcarddir_iter(vcarddir);
192                         //     vcarddir_iter != dir_end ; ++vcarddir_iter){
194                                 if (StopMode == FALSE){
196                                         wxCommandEvent sbstop(SE_SBUPDATE);
198                                         wxString *SBStopStr = new wxString;
199                                         *SBStopStr = _("Search stopped.");
201                                         sbstop.SetClientData(SBStopStr);
202                                         wxPostEvent(this, sbstop);
203                                         return;
205                                 }
207                                 if (vCardFilename.Right(4) == wxT(".vcf") || 
208                                         vCardFilename.Right(4) == wxT(".VCF") || 
209                                         vCardFilename.Right(5) == wxT(".vcard") || 
210                                         vCardFilename.Right(5) == wxT(".VCARD")){
211         
212                                         vCard Person;           
213                                         vCardFilenameFull.Append(AccountDir);
214                                         vCardFilenameFull.Append(vCardFilename);
217                                         Person.LoadFile(vCardFilenameFull);
219                                     /*if (boostfs::path(vcarddir_iter->path()).extension() == ".vcf" ||
220                                         boostfs::path(vcarddir_iter->path()).extension() == ".VCF" ||
221                                         boostfs::path(vcarddir_iter->path()).extension() == ".vcard" ||
222                                         boostfs::path(vcarddir_iter->path()).extension() == ".VCARD"){*/
223                 
224                                         vcardfilenamewxs = vCardFilenameFull;
225                 
226                                         /*vCard Person;
227                                         std::fstream vcardfile;
229                                         vcardfilename = boostfs::path(vcarddir_iter->path()).filename();
230                                         vcardfilenamewxs.Append(AccountDir);            
231                                         vcardfilenamewxs.Append(wxString::FromUTF8(vcardfilename.c_str()));         
232             
233                                         // Open the vCard file up and get the setting names and values from the
234                                         // file.
235                 
236                                         vcardfile.open(vcardfilenamewxs.mb_str(), std::ios::in);
237                 
238                                         while(getline(vcardfile, l)){
239                   
240                                             lwxs.Clear();
241                                             setname.Clear();
242                                             setvalue.Clear();
243                                             lwxs.Append(wxString::FromUTF8(l.c_str()));
244                                             vcardfileline.SetString(lwxs, wxT(":"));
245                                             setname = vcardfileline.GetNextToken();
246                                             setvalue = vcardfileline.GetString();
247                     
248                                             Person.Add(setname, setvalue, TRUE);
249                                     
250                                         }
251                 
252                                         vcardfile.close();*/
254                                         // Check if file has version 4.0, first name (FN)
255                                         // begin and end vCard portions.
256                 
257                                         // Don't search unless these conditions have been met.          
258                 
259                                         if (Person.MeetBaseSpecification()){
260                 
261                                                 // Go through each of the search settings and check
262                                                 // if they match with contact details.
263                                         
264                                                 // If it matches then add to the search results.
265                                         
266                                                 int SelOpt = 0;
267                                                 bool chkOpt = FALSE;
268                                                 wxString StrOpt;
269                                                 int StrOptLen = 0;
270                                                 ArrayvCardOutData ArrayData;
271                                                 ArrayvCardOutData NicknameArrayData;
272                                                 vCardName NameArray = Person.GetName();
273                                                 wxString ContactFinalNickname;
274                                                 NicknameArrayData = Person.GetByPartial(wxT("NICKNAME"));
275                                         
276                                                 if (NicknameArrayData.PropCount != 0){
277                                                         ContactFinalNickname = NicknameArrayData.PropValues[0];
278                                                 }               
279                                         
280                                                 for (std::map<int, void*>::iterator siter = SearchFrames.begin();
281                                                 siter != SearchFrames.end(); siter++){
282                                         
283                                                         // Get the settings from the form.
284                                                 
285                                                         XABSearchPanel *XABSPPtr = static_cast<XABSearchPanel*>(siter->second);
286                                                 
287                                                         // Get Selected Option and Setting.
288                                                 
289                                                         SelOpt = XABSPPtr->GetSelectionOption();
290                                                 
291                                                         if (SelOpt < 12){
292                                                 
293                                                                 StrOpt = XABSPPtr->GetStringSetting();
294                                                                 StrOptLen = StrOpt.Len();
295                                                 
296                                                                 if (SelOpt == 0 || SelOpt == 4 || SelOpt == 8){
297                                                 
298                                                                         // Matching string that beings with...
299                                                                 
300                                                                         // Double check the std::map inserts for each section.
301                                                                 
302                                                                         if (SelOpt == 0){
303                                                                 
304                                                                                 // Get the forename from the first N.
305                                                                 
306                                                                                 if (NameArray.Forename.Mid(0, StrOptLen) == StrOpt){
307                                                                         
308                                                                                         if (CheckDuplicate(vcardfilenamewxs,
309                                                                                                 SAPiter->second, 
310                                                                                                 &SearchResultAccount,
311                                                                                                 &SearchResultFilename) == TRUE){
312                                                                                 
313                                                                                                 SelOpt = 0;
314                                                                                                 chkOpt = FALSE;
315                                                                                                 StrOpt.Clear();
316                                                                                                 StrOptLen = 0;
317                                                                                                 ArrayData.PropData.Clear();
318                                                                                                 ArrayData.PropValues.Clear();
319                                                                                                 ArrayData.PropCount = 0;
320                                                                                                 continue;
321                                                                                         
322                                                                                         }
323                                                                         
324                                                                                         SRNotif *sradd = new SRNotif;
325                                                                                         sradd->ContactName = NameArray;
326                                                                                         sradd->ContactNickname = ContactFinalNickname;
327                                                                                         sradd->ContactAccount = SAPiter->second;
328                                                                                         sradd->ContactAccountName = SALiter->second;
329                                                                                         sradd->ContactFullFilename = vcardfilenamewxs;
330                                                                                         sradd->SearchResultID = intResultFound;
331                                                                         
332                                                                                         SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
333                                                                                         SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
334                                                                         
335                                                                                         intResultFound++;
336                                                                         
337                                                                                         wxCommandEvent sraddenv(SE_ADDRESULT);
338                                                                                         sraddenv.SetClientData(sradd);
339                                                                                         wxPostEvent(this, sraddenv);
340                                                                         
341                                                                                 }
342                                                                 
343                                                                         } else if (SelOpt == 4){
344                                                                 
345                                                                                 if (NameArray.Surname.Mid(0, StrOptLen) == StrOpt){
346                                                                         
347                                                                                         if (CheckDuplicate(vcardfilenamewxs,
348                                                                                                 SAPiter->second, 
349                                                                                                 &SearchResultAccount,
350                                                                                                 &SearchResultFilename) == TRUE){
351                                                                                 
352                                                                                                 SelOpt = 0;
353                                                                                                 chkOpt = FALSE;
354                                                                                                 StrOpt.Clear();
355                                                                                                 StrOptLen = 0;
356                                                                                                 ArrayData.PropData.Clear();
357                                                                                                 ArrayData.PropValues.Clear();
358                                                                                                 ArrayData.PropCount = 0;
359                                                                                                 continue;
360                                                                                         
361                                                                                         }
362                                                                         
363                                                                                         SRNotif *sradd = new SRNotif;
364                                                                                         sradd->ContactName = NameArray;
365                                                                                         sradd->ContactNickname = ContactFinalNickname;
366                                                                                         sradd->ContactAccount = SAPiter->second;
367                                                                                         sradd->ContactAccountName = SALiter->second;
368                                                                                         sradd->ContactFullFilename = vcardfilenamewxs;
369                                                                                         sradd->SearchResultID = intResultFound;
370                                                                         
371                                                                                         SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
372                                                                                         SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
373                                                                         
374                                                                                         intResultFound++;
375                                                                         
376                                                                                         wxCommandEvent sraddenv(SE_ADDRESULT);
377                                                                                         sraddenv.SetClientData(sradd);
378                                                                                         wxPostEvent(this, sraddenv);
379                                                                         
380                                                                                 }
381                                                                 
382                                                                         } else if (SelOpt == 8){
383                                                                 
384                                                                                 wxString NicknameData;
385                                                                         
386                                                                                 for (int i = 0; i < NicknameArrayData.PropCount; i++){
387                                                                         
388                                                                                         NicknameData = NicknameArrayData.PropValues[i];
390                                                                                         if (NicknameData.Mid(0, StrOptLen) == StrOpt){
391                                                                                 
392                                                                                                 if (CheckDuplicate(vcardfilenamewxs,
393                                                                                                         SAPiter->second, 
394                                                                                                         &SearchResultAccount,
395                                                                                                         &SearchResultFilename) == TRUE){
396                                                                                 
397                                                                                                         SelOpt = 0;
398                                                                                                         chkOpt = FALSE;
399                                                                                                         StrOpt.Clear();
400                                                                                                         StrOptLen = 0;
401                                                                                                         ArrayData.PropData.Clear();
402                                                                                                         ArrayData.PropValues.Clear();
403                                                                                                         ArrayData.PropCount = 0;
404                                                                                                         continue;
405                                                                                         
406                                                                                                 }
407                                                                                 
408                                                                                                 SRNotif *sradd = new SRNotif;
409                                                                                                 sradd->ContactName = NameArray;
410                                                                                                 sradd->ContactNickname = ContactFinalNickname;
411                                                                                                 sradd->ContactAccount = SAPiter->second;
412                                                                                                 sradd->ContactAccountName = SALiter->second;
413                                                                                                 sradd->ContactFullFilename = vcardfilenamewxs;
414                                                                                                 sradd->SearchResultID = intResultFound;
415                                                                         
416                                                                                                 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
417                                                                                                 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
418                                                                         
419                                                                                                 intResultFound++;
420                                                                         
421                                                                                                 wxCommandEvent sraddenv(SE_ADDRESULT);
422                                                                                                 sraddenv.SetClientData(sradd);
423                                                                                                 wxPostEvent(this, sraddenv);
424                                                                                         
425                                                                                                 break;
426                                                                                 
427                                                                                         }
428                                                                 
429                                                                                 }
430                                                                 
431                                                                         }
432                                                 
433                                                                 } else if (SelOpt == 1 || SelOpt == 5 || SelOpt == 9){
434                                                 
435                                                                         // Matching string that ends with...
436                                                                 
437                                                                         if (SelOpt == 1){
438                                                                 
439                                                                                 // Check the forename.
440                                                                         
441                                                                                 if (NameArray.Forename.Right(StrOptLen) == StrOpt){
442                                                                         
443                                                                                         if (CheckDuplicate(vcardfilenamewxs,
444                                                                                                 SAPiter->second, 
445                                                                                                 &SearchResultAccount,
446                                                                                                 &SearchResultFilename) == TRUE){
447                                                                                 
448                                                                                                 SelOpt = 0;
449                                                                                                 chkOpt = FALSE;
450                                                                                                 StrOpt.Clear();
451                                                                                                 StrOptLen = 0;
452                                                                                                 ArrayData.PropData.Clear();
453                                                                                                 ArrayData.PropValues.Clear();
454                                                                                                 ArrayData.PropCount = 0;
455                                                                                                 continue;
456                                                                                         
457                                                                                         }
458                                                                         
459                                                                                         SRNotif *sradd = new SRNotif;
460                                                                                         sradd->ContactName = NameArray;
461                                                                                         sradd->ContactNickname = ContactFinalNickname;
462                                                                                         sradd->ContactAccount = SAPiter->second;
463                                                                                         sradd->ContactAccountName = SALiter->second;
464                                                                                         sradd->ContactFullFilename = vcardfilenamewxs;
465                                                                                         sradd->SearchResultID = intResultFound;
466                                                                         
467                                                                                         SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
468                                                                                         SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
469                                                                         
470                                                                                         intResultFound++;
471                                                                         
472                                                                                         wxCommandEvent sraddenv(SE_ADDRESULT);
473                                                                                         sraddenv.SetClientData(sradd);
474                                                                                         wxPostEvent(this, sraddenv);
475                                                                         
476                                                                                 }
477                                                                 
478                                                                         } else if (SelOpt == 5){
479                                                                 
480                                                                                 if (NameArray.Surname.Right(StrOptLen) == StrOpt){
481                                                                         
482                                                                                         if (CheckDuplicate(vcardfilenamewxs,
483                                                                                                 SAPiter->second, 
484                                                                                                 &SearchResultAccount,
485                                                                                                 &SearchResultFilename) == TRUE){
486                                                                                 
487                                                                                                 SelOpt = 0;
488                                                                                                 chkOpt = FALSE;
489                                                                                                 StrOpt.Clear();
490                                                                                                 StrOptLen = 0;
491                                                                                                 ArrayData.PropData.Clear();
492                                                                                                 ArrayData.PropValues.Clear();
493                                                                                                 ArrayData.PropCount = 0;
494                                                                                                 continue;
495                                                                                         
496                                                                                         }
497                                                                         
498                                                                                         SRNotif *sradd = new SRNotif;
499                                                                                         sradd->ContactName = NameArray;
500                                                                                         sradd->ContactNickname = ContactFinalNickname;
501                                                                                         sradd->ContactAccount = SAPiter->second;
502                                                                                         sradd->ContactAccountName = SALiter->second;
503                                                                                         sradd->ContactFullFilename = vcardfilenamewxs;
504                                                                                         sradd->SearchResultID = intResultFound;
505                                                                         
506                                                                                         SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
507                                                                                         SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
508                                                                         
509                                                                                         intResultFound++;
510                                                                         
511                                                                                         wxCommandEvent sraddenv(SE_ADDRESULT);
512                                                                                         sraddenv.SetClientData(sradd);
513                                                                                         wxPostEvent(this, sraddenv);
514                                                                         
515                                                                                 }
516                                                                 
517                                                                         } else if (SelOpt == 9){
518                                                                 
519                                                                                 wxString NicknameData;
520                                                                         
521                                                                                 for (int i = 0; i < NicknameArrayData.PropCount; i++){
522                                                                         
523                                                                                         NicknameData = NicknameArrayData.PropValues[i];
524                                                                                         NicknameData.Trim();
526                                                                                         if (NicknameData.Right(StrOptLen) == StrOpt){
527                                                                                 
528                                                                                                 if (CheckDuplicate(vcardfilenamewxs,
529                                                                                                         SAPiter->second, 
530                                                                                                         &SearchResultAccount,
531                                                                                                         &SearchResultFilename) == TRUE){
532                                                                                 
533                                                                                                         SelOpt = 0;
534                                                                                                         chkOpt = FALSE;
535                                                                                                         StrOpt.Clear();
536                                                                                                         StrOptLen = 0;
537                                                                                                         ArrayData.PropData.Clear();
538                                                                                                         ArrayData.PropValues.Clear();
539                                                                                                         ArrayData.PropCount = 0;
540                                                                                                         continue;
541                                                                                         
542                                                                                                 }
543                                                                                 
544                                                                                                 SRNotif *sradd = new SRNotif;
545                                                                                                 sradd->ContactName = NameArray;
546                                                                                                 sradd->ContactNickname = ContactFinalNickname;
547                                                                                                 sradd->ContactAccount = SAPiter->second;
548                                                                                                 sradd->ContactAccountName = SALiter->second;
549                                                                                                 sradd->ContactFullFilename = vcardfilenamewxs;
550                                                                                                 sradd->SearchResultID = intResultFound;
551                                                                         
552                                                                                                 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
553                                                                                                 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
554                                                                         
555                                                                                                 intResultFound++;
556                                                                         
557                                                                                                 wxCommandEvent sraddenv(SE_ADDRESULT);
558                                                                                                 sraddenv.SetClientData(sradd);
559                                                                                                 wxPostEvent(this, sraddenv);
560                                                                                         
561                                                                                                 break;
562                                                                                 
563                                                                                         }
564                                                                 
565                                                                                 }
566                                                                 
567                                                                         }
568                                                 
569                                                                 } else if (SelOpt == 2 || SelOpt == 6 || SelOpt == 10){
570                                                 
571                                                                         // Matching string that contains...
572                                                 
573                                                                         if (SelOpt == 2){
574                                                                 
575                                                                                 if (NameArray.Forename.Find(StrOpt) != wxNOT_FOUND){
576                                                                         
577                                                                                         if (CheckDuplicate(vcardfilenamewxs,
578                                                                                                 SAPiter->second, 
579                                                                                                 &SearchResultAccount,
580                                                                                                 &SearchResultFilename) == TRUE){
581                                                                                 
582                                                                                                 SelOpt = 0;
583                                                                                                 chkOpt = FALSE;
584                                                                                                 StrOpt.Clear();
585                                                                                                 StrOptLen = 0;
586                                                                                                 ArrayData.PropData.Clear();
587                                                                                                 ArrayData.PropValues.Clear();
588                                                                                                 ArrayData.PropCount = 0;
589                                                                                                 continue;
590                                                                                         
591                                                                                         }
592                                                                         
593                                                                                         SRNotif *sradd = new SRNotif;
594                                                                                         sradd->ContactName = NameArray;
595                                                                                         sradd->ContactNickname = ContactFinalNickname;
596                                                                                         sradd->ContactAccount = SAPiter->second;
597                                                                                         sradd->ContactAccountName = SALiter->second;
598                                                                                         sradd->ContactFullFilename = vcardfilenamewxs;
599                                                                                         sradd->SearchResultID = intResultFound;
600                                                                         
601                                                                                         SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
602                                                                                         SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
603                                                                         
604                                                                                         intResultFound++;
605                                                                         
606                                                                                         wxCommandEvent sraddenv(SE_ADDRESULT);
607                                                                                         sraddenv.SetClientData(sradd);
608                                                                                         wxPostEvent(this, sraddenv);
609                                                                         
610                                                                                 }
611                                                                 
612                                                                         } else if (SelOpt == 6){
613                                                                 
614                                                                                 if (NameArray.Surname.Find(StrOpt) != wxNOT_FOUND){
615                                                                         
616                                                                                         if (CheckDuplicate(vcardfilenamewxs,
617                                                                                                 SAPiter->second, 
618                                                                                                 &SearchResultAccount,
619                                                                                                 &SearchResultFilename) == TRUE){
620                                                                                 
621                                                                                                 SelOpt = 0;
622                                                                                                 chkOpt = FALSE;
623                                                                                                 StrOpt.Clear();
624                                                                                                 StrOptLen = 0;
625                                                                                                 ArrayData.PropData.Clear();
626                                                                                                 ArrayData.PropValues.Clear();
627                                                                                                 ArrayData.PropCount = 0;
628                                                                                                 continue;
629                                                                                         
630                                                                                         }
631                                                                         
632                                                                                         SRNotif *sradd = new SRNotif;
633                                                                                         sradd->ContactName = NameArray;
634                                                                                         sradd->ContactNickname = ContactFinalNickname;
635                                                                                         sradd->ContactAccount = SAPiter->second;
636                                                                                         sradd->ContactAccountName = SALiter->second;
637                                                                                         sradd->ContactFullFilename = vcardfilenamewxs;
638                                                                                         sradd->SearchResultID = intResultFound;
639                                                                         
640                                                                                         SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
641                                                                                         SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
642                                                                         
643                                                                                         intResultFound++;
644                                                                         
645                                                                                         wxCommandEvent sraddenv(SE_ADDRESULT);
646                                                                                         sraddenv.SetClientData(sradd);
647                                                                                         wxPostEvent(this, sraddenv);
648                                                                         
649                                                                                 }
650                                                                 
651                                                                         } else if (SelOpt == 10){
652                                                                 
653                                                                                 wxString NicknameData;
654                                                                         
655                                                                                 for (int i = 0; i < NicknameArrayData.PropCount; i++){
656                                                                         
657                                                                                         NicknameData = NicknameArrayData.PropValues[i];
658                                                                                         NicknameData.Trim();
660                                                                                         if (NicknameData.Find(StrOpt) != wxNOT_FOUND){
661                                                                                 
662                                                                                                 if (CheckDuplicate(vcardfilenamewxs,
663                                                                                                         SAPiter->second, 
664                                                                                                         &SearchResultAccount,
665                                                                                                         &SearchResultFilename) == TRUE){
666                                                                                 
667                                                                                                         SelOpt = 0;
668                                                                                                         chkOpt = FALSE;
669                                                                                                         StrOpt.Clear();
670                                                                                                         StrOptLen = 0;
671                                                                                                         ArrayData.PropData.Clear();
672                                                                                                         ArrayData.PropValues.Clear();
673                                                                                                         ArrayData.PropCount = 0;
674                                                                                                         continue;
675                                                                                         
676                                                                                                 }
677                                                                                 
678                                                                                                 SRNotif *sradd = new SRNotif;
679                                                                                                 sradd->ContactName = NameArray;
680                                                                                                 sradd->ContactNickname = ContactFinalNickname;
681                                                                                                 sradd->ContactAccount = SAPiter->second;
682                                                                                                 sradd->ContactAccountName = SALiter->second;
683                                                                                                 sradd->ContactFullFilename = vcardfilenamewxs;
684                                                                                                 sradd->SearchResultID = intResultFound;
685                                                                         
686                                                                                                 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
687                                                                                                 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
688                                                                         
689                                                                                                 intResultFound++;
690                                                                         
691                                                                                                 wxCommandEvent sraddenv(SE_ADDRESULT);
692                                                                                                 sraddenv.SetClientData(sradd);
693                                                                                                 wxPostEvent(this, sraddenv);
694                                                                                         
695                                                                                                 break;
696                                                                                 
697                                                                                         }
698                                                                 
699                                                                                 }
700                                                                 
701                                                                         }
702                                                 
703                                                                 } else if (SelOpt == 3 || SelOpt == 7 || SelOpt == 11){
704                                                 
705                                                                         // Matching String that doesn't contain...
706                                                 
707                                                                         if (SelOpt == 3){
708                                                                 
709                                                                                 // Process the nickname data.
710                                                                 
711                                                                                 if (NameArray.Forename.Find(StrOpt) == wxNOT_FOUND){
712                                                                         
713                                                                                         if (CheckDuplicate(vcardfilenamewxs,
714                                                                                                 SAPiter->second, 
715                                                                                                 &SearchResultAccount,
716                                                                                                 &SearchResultFilename) == TRUE){
717                                                                                 
718                                                                                                 SelOpt = 0;
719                                                                                                 chkOpt = FALSE;
720                                                                                                 StrOpt.Clear();
721                                                                                                 StrOptLen = 0;
722                                                                                                 ArrayData.PropData.Clear();
723                                                                                                 ArrayData.PropValues.Clear();
724                                                                                                 ArrayData.PropCount = 0;
725                                                                                                 continue;
726                                                                                         
727                                                                                         }
728                                                                         
729                                                                                         SRNotif *sradd = new SRNotif;
730                                                                                         sradd->ContactName = NameArray;
731                                                                                         sradd->ContactNickname = ContactFinalNickname;
732                                                                                         sradd->ContactAccount = SAPiter->second;
733                                                                                         sradd->ContactAccountName = SALiter->second;
734                                                                                         sradd->ContactFullFilename = vcardfilenamewxs;
735                                                                                         sradd->SearchResultID = intResultFound;
736                                                                         
737                                                                                         SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
738                                                                                         SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
739                                                                         
740                                                                                         intResultFound++;
741                                                                         
742                                                                                         wxCommandEvent sraddenv(SE_ADDRESULT);
743                                                                                         sraddenv.SetClientData(sradd);
744                                                                                         wxPostEvent(this, sraddenv);
745                                                                         
746                                                                                 }
747                                                                 
748                                                                         } else if (SelOpt == 7){
749                                                                 
750                                                                                 if (!NameArray.Surname.Find(StrOpt) == wxNOT_FOUND){
751                                                                         
752                                                                                         if (CheckDuplicate(vcardfilenamewxs,
753                                                                                                 SAPiter->second, 
754                                                                                                 &SearchResultAccount,
755                                                                                                 &SearchResultFilename) == TRUE){
756                                                                                 
757                                                                                                 SelOpt = 0;
758                                                                                                 chkOpt = FALSE;
759                                                                                                 StrOpt.Clear();
760                                                                                                 StrOptLen = 0;
761                                                                                                 ArrayData.PropData.Clear();
762                                                                                                 ArrayData.PropValues.Clear();
763                                                                                                 ArrayData.PropCount = 0;
764                                                                                                 continue;
765                                                                                         
766                                                                                         }
767                                                                         
768                                                                                         SRNotif *sradd = new SRNotif;
769                                                                                         sradd->ContactName = NameArray;
770                                                                                         sradd->ContactNickname = ContactFinalNickname;
771                                                                                         sradd->ContactAccount = SAPiter->second;
772                                                                                         sradd->ContactAccountName = SALiter->second;
773                                                                                         sradd->ContactFullFilename = vcardfilenamewxs;
774                                                                                         sradd->SearchResultID = intResultFound;
775                                                                         
776                                                                                         SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
777                                                                                         SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
778                                                                         
779                                                                                         intResultFound++;
780                                                                         
781                                                                                         wxCommandEvent sraddenv(SE_ADDRESULT);
782                                                                                         sraddenv.SetClientData(sradd);
783                                                                                         wxPostEvent(this, sraddenv);
784                                                                         
785                                                                                 }
786                                                                 
787                                                                         } else if (SelOpt == 11){
788                                                                 
789                                                                                 wxString NicknameData;
790                                                                         
791                                                                                 for (int i = 0; i < NicknameArrayData.PropCount; i++){
792                                                                         
793                                                                                         NicknameData = NicknameArrayData.PropValues[i];
794                                                                                         NicknameData.Trim();
796                                                                                         if (NicknameData.Find(StrOpt) == wxNOT_FOUND){
797                                                                                 
798                                                                                                 if (CheckDuplicate(vcardfilenamewxs,
799                                                                                                         SAPiter->second, 
800                                                                                                         &SearchResultAccount,
801                                                                                                         &SearchResultFilename) == TRUE){
802                                                                                 
803                                                                                                         SelOpt = 0;
804                                                                                                         chkOpt = FALSE;
805                                                                                                         StrOpt.Clear();
806                                                                                                         StrOptLen = 0;
807                                                                                                         ArrayData.PropData.Clear();
808                                                                                                         ArrayData.PropValues.Clear();
809                                                                                                         ArrayData.PropCount = 0;
810                                                                                                         continue;
811                                                                                         
812                                                                                                 }
813                                                                                 
814                                                                                                 SRNotif *sradd = new SRNotif;
815                                                                                                 sradd->ContactName = NameArray;
816                                                                                                 sradd->ContactNickname = ContactFinalNickname;
817                                                                                                 sradd->ContactAccount = SAPiter->second;
818                                                                                                 sradd->ContactAccountName = SALiter->second;
819                                                                                                 sradd->ContactFullFilename = vcardfilenamewxs;
820                                                                                                 sradd->SearchResultID = intResultFound;
821                                                                         
822                                                                                                 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
823                                                                                                 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
824                                                                         
825                                                                                                 intResultFound++;
826                                                                         
827                                                                                                 wxCommandEvent sraddenv(SE_ADDRESULT);
828                                                                                                 sraddenv.SetClientData(sradd);
829                                                                                                 wxPostEvent(this, sraddenv);
830                                                                                         
831                                                                                                 break;
832                                                                                 
833                                                                                         }
834                                                                 
835                                                                                 }
836                                                                 
837                                                                         }
838                                                 
839                                                                 }
840                                                 
841                                                         } else {
843                                                                 chkOpt = XABSPPtr->GetCheckboxSetting();
844                                                         
845                                                                 if (SelOpt == 12){
846                                                         
847                                                                         // Search should check if it has a photo or not.
848                                                         
849                                                                         ArrayData = Person.GetByPartial(wxT("PHOTO"));
850                                                         
851                                                                         if ((ArrayData.PropCount >= 1 &&
852                                                                         chkOpt == TRUE) || 
853                                                                         (ArrayData.PropCount == 0 &&
854                                                                         chkOpt == FALSE)){
855                                                                 
856                                                                                 if (CheckDuplicate(vcardfilenamewxs,
857                                                                                         SAPiter->second, 
858                                                                                         &SearchResultAccount,
859                                                                                         &SearchResultFilename) == TRUE){
860                                                                         
861                                                                                         SelOpt = 0;
862                                                                                         chkOpt = FALSE;
863                                                                                         StrOpt.Clear();
864                                                                                         StrOptLen = 0;
865                                                                                         ArrayData.PropData.Clear();
866                                                                                         ArrayData.PropValues.Clear();
867                                                                                         ArrayData.PropCount = 0;
868                                                                                         continue;
869                                                                                 
870                                                                                 }
871                                                                 
872                                                                                 SRNotif *sradd = new SRNotif;
873                                                                 
874                                                                                 sradd->ContactName = NameArray;
875                                                                                 sradd->ContactNickname = ContactFinalNickname;
876                                                                                 sradd->ContactAccount = SAPiter->second;
877                                                                                 sradd->ContactAccountName = SALiter->second;
878                                                                                 sradd->ContactFullFilename = vcardfilenamewxs;
879                                                                                 sradd->SearchResultID = intResultFound;
880                                                                         
881                                                                                 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
882                                                                                 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
883                                                                         
884                                                                                 intResultFound++;
885                                                                         
886                                                                                 wxCommandEvent sraddenv(SE_ADDRESULT);
887                                                                                 sraddenv.SetClientData(sradd);
888                                                                                 wxPostEvent(this, sraddenv);
889                                                                 
890                                                                         }
891                                                         
892                                                                 } else if (SelOpt == 13){
893                                                         
894                                                                         // Search should check if it has a logo or not.
895                                                                 
896                                                                         ArrayData = Person.GetByPartial(wxT("LOGO"));
897                                                         
898                                                                         if ((ArrayData.PropCount >= 1 &&
899                                                                         chkOpt == TRUE) || 
900                                                                         (ArrayData.PropCount == 0 &&
901                                                                         chkOpt == FALSE)){
902                                                                 
903                                                                                 if (CheckDuplicate(vcardfilenamewxs,
904                                                                                         SAPiter->second, 
905                                                                                         &SearchResultAccount,
906                                                                                         &SearchResultFilename) == TRUE){
907                                                                         
908                                                                                         SelOpt = 0;
909                                                                                         chkOpt = FALSE;
910                                                                                         StrOpt.Clear();
911                                                                                         StrOptLen = 0;
912                                                                                         ArrayData.PropData.Clear();
913                                                                                         ArrayData.PropValues.Clear();
914                                                                                         ArrayData.PropCount = 0;
915                                                                                         continue;
916                                                                                 
917                                                                                 }
918                                                                 
919                                                                                 SRNotif *sradd = new SRNotif;
920                                                                 
921                                                                                 sradd->ContactName = NameArray;
922                                                                                 sradd->ContactNickname = ContactFinalNickname;
923                                                                                 sradd->ContactAccount = SAPiter->second;
924                                                                                 sradd->ContactAccountName = SALiter->second;
925                                                                                 sradd->ContactFullFilename = vcardfilenamewxs;
926                                                                                 sradd->SearchResultID = intResultFound;
927                                                                         
928                                                                                 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
929                                                                                 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
930                                                                         
931                                                                                 intResultFound++;
932                                                                         
933                                                                                 wxCommandEvent sraddenv(SE_ADDRESULT);
934                                                                                 sraddenv.SetClientData(sradd);
935                                                                                 wxPostEvent(this, sraddenv);
936                                                                 
937                                                                         }
938                                                         
939                                                                 } else if (SelOpt == 14){
940                                                         
941                                                                         // Search should check if it has sound or not.
942                                                                 
943                                                                         ArrayData = Person.GetByPartial(wxT("SOUND"));
944                                                         
945                                                                         if ((ArrayData.PropCount >= 1 &&
946                                                                         chkOpt == TRUE) || 
947                                                                         (ArrayData.PropCount == 0 &&
948                                                                         chkOpt == FALSE)){
949                                                                 
950                                                                                 if (CheckDuplicate(vcardfilenamewxs,
951                                                                                         SAPiter->second, 
952                                                                                         &SearchResultAccount,
953                                                                                         &SearchResultFilename) == TRUE){
954                                                                         
955                                                                                         SelOpt = 0;
956                                                                                         chkOpt = FALSE;
957                                                                                         StrOpt.Clear();
958                                                                                         StrOptLen = 0;
959                                                                                         ArrayData.PropData.Clear();
960                                                                                         ArrayData.PropValues.Clear();
961                                                                                         ArrayData.PropCount = 0;
962                                                                                         continue;
963                                                                                 
964                                                                                 }
965                                                                 
966                                                                                 SRNotif *sradd = new SRNotif;
967                                                                 
968                                                                                 sradd->ContactName = NameArray;
969                                                                                 sradd->ContactNickname = ContactFinalNickname;
970                                                                                 sradd->ContactAccount = SAPiter->second;
971                                                                                 sradd->ContactAccountName = SALiter->second;
972                                                                                 sradd->ContactFullFilename = vcardfilenamewxs;
973                                                                                 sradd->SearchResultID = intResultFound;
974                                                                         
975                                                                                 SearchResultAccount.insert(std::make_pair(sradd->SearchResultID, sradd->ContactAccount));
976                                                                                 SearchResultFilename.insert(std::make_pair(sradd->SearchResultID, sradd->ContactFullFilename));
977                                                                         
978                                                                                 intResultFound++;
979                                                                         
980                                                                                 wxCommandEvent sraddenv(SE_ADDRESULT);
981                                                                                 sraddenv.SetClientData(sradd);
982                                                                                 wxPostEvent(this, sraddenv);
983                                                                 
984                                                                         }
985                                                         
986                                                                 }
987                                                 
988                                                         }
989                                         
990                                                         SelOpt = 0;
991                                                         chkOpt = FALSE;
992                                                         StrOpt.Clear();
993                                                         StrOptLen = 0;
994                                                         ArrayData.PropData.Clear();
995                                                         ArrayData.PropValues.Clear();
996                                                         ArrayData.PropCount = 0;
997                                                                                                 
998                                                 }
999                 
1000                                         } else {
1001                 
1002                                         }
1003                 
1004                                 }
1006                                 vCardFilename.Clear();
1007                                 vCardFilenameFull.Clear();
1008                                 ProcFiles = vcardaccdir.GetNext(&vCardFilename);
1009           
1010                         }
1011         
1012                 } else {
1014                 }
1015                 
1016         }
1017         
1018         // Finished searching... clear up.
1019         
1020         wxCommandEvent sbfinstr (SE_SBUPDATE);
1021                 
1022         wxString *SBFinish = new wxString;
1023         
1024         if (intResultFound == 0){
1025         
1026                 *SBFinish = _("No contacts found.");
1027         
1028         } else if (intResultFound == 1){
1029         
1030                 *SBFinish = _("1 contact found.");
1031         
1032         } else {
1033         
1034                 *SBFinish = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
1035         
1036         }
1037                 
1038         sbfinstr.SetClientData(SBFinish);
1039         wxPostEvent(this, sbfinstr);
1041         wxCommandEvent sbfinish (SE_SEARCHFINISHED);
1042         wxPostEvent(this, sbfinish);
1046 void frmSearch::SearchContacts( wxCommandEvent& event )
1049         // Change the button to stop.
1050         
1051         if (StopMode == FALSE){
1052         
1053                 // Clear the list of search results.
1054                 
1055                 lstResults->DeleteAllItems();
1056                 SearchResultAccount.clear();
1057                 SearchResultFilename.clear();
1058         
1059                 // Button clicked on as 'Search'.
1060         
1061                 DisableAllSearchSettings(TRUE);
1062                 StopMode = TRUE;
1063                 btnSearch->SetLabel(_("Stop")); 
1064                 
1065                 // Spawn a thread so that searching can proceed
1066                 // without blocking the GUI (and allow the
1067                 // search to stop when needed).
1068                 
1069                 std::thread SearchThread(&frmSearch::SearchContactsThread, this);
1070                 SearchThread.detach();
1071         
1072         } else {
1073         
1074                 // Button clicked on as 'Stop'.
1075         
1076                 StopMode = FALSE;
1077                 btnSearch->SetLabel(_("Search"));
1078                 DisableAllSearchSettings(FALSE);
1079         
1080         }
1084 void frmSearch::ResetContacts( wxCommandEvent& event )
1087         // Clear all the search settings.
1089         for (std::map<int,void*>::iterator iter = SearchFrames.begin(); 
1090          iter != SearchFrames.end(); ++iter){
1091          
1092                 XABSearchPanel *XABSPPtr;
1093          
1094                 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1095                 szrSearch->Detach(XABSPPtr);
1097                 // Remove the frame from the memory and the list.
1098         
1099                 delete XABSPPtr;
1100                 XABSPPtr = NULL;
1101                 
1102                 SearchFrames.erase(iter->first);
1103                  
1104         }
1105         
1106         // Clear the list of search results.
1107         
1108         lstResults->DeleteAllItems();
1109         
1110         // Clear the account settings.
1112         for (std::map<wxString, bool>::iterator iter = SearchAccounts.begin();
1113                 iter != SearchAccounts.end(); iter++){
1114         
1115                 iter->second = TRUE;
1116                 
1117         }
1119         // Add a search settings with the default things.
1120         
1121         ScrollGen = 0;
1123         XABSearchPanel *NewPanel = new XABSearchPanel( tabSearch );
1124         NewPanel->EnableButtons(TRUE, FALSE);
1125         NewPanel->SetupPointers(this);
1126         NewPanel->SetupInteger(ScrollGen);
1127         szrSearch->Add(NewPanel, 1, wxEXPAND, 0);
1128         szrSearch->Fit(tabSearch);
1129         SearchFrames.insert(std::make_pair(ScrollGen, NewPanel));
1130         ScrollGen++;
1134 void frmSearch::AddSearchSetting( wxCommandEvent& event )
1137         // Add a search setting frame to the list.
1139         XABSearchPanel *NewPanel = new XABSearchPanel( tabSearch );
1140         NewPanel->EnableButtons(TRUE, TRUE);
1141         NewPanel->SetupPointers(this);
1142         NewPanel->SetupInteger(ScrollGen);
1143         szrSearch->Add(NewPanel, 1, wxEXPAND|wxGROW, 5);
1144         //szrSearch->Fit(tabSearch);
1145         szrSearch->FitInside(tabSearch);
1146         szrSearch->Layout();
1147         szrSearch->RecalcSizes();
1148         tabSearch->Layout();
1149         SearchFrames.insert(std::make_pair(ScrollGen, NewPanel));
1150         ScrollGen++;
1151         
1152         // Check if number of search settings is 15 (or over).
1153         // If it is, disable the option of adding extra settings
1154         // for all frames until one is removed.
1156         XABSearchPanel *XABSPPtr;
1157         
1158         if (SearchFrames.size() >= 15){
1159         
1160                 for (std::map<int,void*>::iterator iter = SearchFrames.begin(); 
1161                 iter != SearchFrames.end(); ++iter){
1162          
1163                         XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1164          
1165                         XABSPPtr->EnableButtons(FALSE, TRUE);
1166          
1167                 }
1168         
1169         } else if (SearchFrames.size() >= 2){
1171                 for (std::map<int,void*>::iterator iter = SearchFrames.begin(); 
1172                 iter != SearchFrames.end(); ++iter){
1173          
1174                         XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1175          
1176                         XABSPPtr->EnableButtons(TRUE, TRUE);
1177          
1178                 }
1179         
1180         }
1182         //tabSearch->SetScrollbar(wxVERTICAL, 32768, 25, 32768, false);
1183         tabSearch->Update();
1184         //tabSearch->ScrollToLine(tabSearch->GetLineCount());
1185         
1188 void frmSearch::RemoveSearchSetting( wxCommandEvent& event )
1191         // Get the integer from the event.
1192         
1193         std::map<int,void*>::iterator iter;
1194         iter = SearchFrames.find(event.GetInt());
1196         // Remove a search setting frame from the list.
1198         XABSearchPanel *XABSPPtr;
1199         XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1200         
1201         szrSearch->Detach(XABSPPtr);
1203         // Remove the frame from the memory and the list.
1205         SearchFrames.erase(event.GetInt());
1206         
1207         delete XABSPPtr;
1208         XABSPPtr = NULL;
1209         
1210         //szrSearch->Fit(tabSearch);
1211         
1212         if (SearchFrames.size() < 15 && SearchFrames.size() > 1){
1213         
1214                 for (std::map<int,void*>::iterator iter = SearchFrames.begin(); 
1215                 iter != SearchFrames.end(); ++iter){
1216          
1217                         XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1218          
1219                         XABSPPtr->EnableButtons(TRUE, TRUE);
1220          
1221                 }
1222         
1223         } else if (SearchFrames.size() == 1){
1225                 for (std::map<int,void*>::iterator iter = SearchFrames.begin(); 
1226                 iter != SearchFrames.end(); ++iter){
1227          
1228                         XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1229          
1230                         XABSPPtr->EnableButtons(TRUE, FALSE);
1231          
1232                 }
1233         
1234         }
1236         szrSearch->FitInside(tabSearch);
1237         szrSearch->Layout();
1238         szrSearch->RecalcSizes();
1239         tabSearch->Layout();
1243 void frmSearch::ReloadAccountList( wxCommandEvent& event ){
1247 void frmSearch::AddResult( wxCommandEvent& event ){
1249         SRNotif *srnotif = (SRNotif*)event.GetClientData();
1250         
1251         // Process Data and add to the list of results.
1252         
1253         wxListItem item;
1254         
1255         // Setup the contact name.
1256         
1257         wxString ContactNameFinal;
1258         
1259         if (!srnotif->ContactName.Title.IsEmpty()){
1260         
1261                 ContactNameFinal.append(srnotif->ContactName.Title);
1262                 ContactNameFinal.Trim();
1263                 ContactNameFinal.append(wxT(" "));
1264         
1265         }
1266         
1267         if (!srnotif->ContactName.Forename.IsEmpty()){
1268         
1269                 ContactNameFinal.append(srnotif->ContactName.Forename);
1270                 ContactNameFinal.Trim();
1271                 ContactNameFinal.append(wxT(" "));
1272         
1273         }
1275         if (!srnotif->ContactName.Surname.IsEmpty()){
1276         
1277                 ContactNameFinal.append(srnotif->ContactName.Surname);
1278                 ContactNameFinal.Trim();
1279                 ContactNameFinal.append(wxT(" "));
1280         
1281         }
1282         
1283         if (!srnotif->ContactName.Suffix.IsEmpty()){
1284         
1285                 ContactNameFinal.append(srnotif->ContactName.Suffix);
1286                 ContactNameFinal.Trim();
1287         
1288         }
1289         
1290         item.SetId(0);
1291         item.SetText(ContactNameFinal);
1292         item.SetData(srnotif->SearchResultID);
1293         
1294         long ListCtrlIndex = lstResults->InsertItem(item);
1295         
1296         //SearchResultAccount.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactAccount));
1297         //SearchResultFilename.insert(std::make_pair(srnotif->SearchResultID, srnotif->ContactFullFilename));
1298         
1299         srnotif->ContactNickname.Trim();
1301         lstResults->SetItem(ListCtrlIndex, 1, srnotif->ContactNickname);
1302         lstResults->SetItem(ListCtrlIndex, 2, srnotif->ContactAccountName);     
1303         
1304         delete srnotif;
1305         srnotif = NULL;
1309 void frmSearch::SearchBarUpdate( wxCommandEvent& event ){
1311         wxString *SBData = (wxString*)event.GetClientData();
1313         stbBottom->SetStatusText(*SBData, 0);
1314         
1315         delete SBData;
1316         SBData = NULL;
1320 void frmSearch::SearchFinished( wxCommandEvent& event ){
1322         StopMode = FALSE;
1323         btnSearch->SetLabel(_("Search"));
1324         DisableAllSearchSettings(FALSE);
1328 void frmSearch::DisableAllSearchSettings(bool Enable){
1330         for (std::map<int, void*>::iterator siter = SearchFrames.begin();
1331                 siter != SearchFrames.end(); siter++){
1332         
1333                 XABSearchPanel *XABSPPtr = static_cast<XABSearchPanel*>(siter->second);
1334                 
1335                 if (Enable == FALSE){
1336                 
1337                         wxCommandEvent enboxes(XABSP_ENABLECONTROLS);
1338                         wxPostEvent(XABSPPtr, enboxes);
1339                 
1340                 } else if (Enable == TRUE){
1341                 
1342                         wxCommandEvent disboxes(XABSP_DISABLECONTROLS);
1343                         wxPostEvent(XABSPPtr, disboxes);
1344                 
1345                 }
1346                 
1347         }
1351 void frmSearch::OpenContact( wxCommandEvent& event ){
1352         
1353         // Check if a contact has been selected.
1355         long intSelected = -1;
1356         int intSelectedData = 0;
1357         long intContactSeekNum = -1;
1359         intSelected = lstResults->GetNextItem(intSelected, 
1360                 wxLIST_NEXT_ALL,
1361                 wxLIST_STATE_SELECTED);
1363         if (intSelected == -1){
1364                 return;
1365         }
1367         intContactSeekNum = lstResults->GetItemData(intSelected);
1369         UCNotif *uc = new UCNotif;
1371         uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1372         uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1374         wxCommandEvent oc(CE_OPENCONTACT);
1375         oc.SetClientData(uc);
1376         wxPostEvent(this->GetParent(), oc);
1380 void frmSearch::EditContact( wxCommandEvent& event ){
1382         // Check if a contact has been selected.
1384         long intSelected = -1;
1385         int intSelectedData = 0;
1386         long intContactSeekNum = -1;
1388         intSelected = lstResults->GetNextItem(intSelected, 
1389                 wxLIST_NEXT_ALL,
1390                 wxLIST_STATE_SELECTED);
1392         if (intSelected == -1){
1393                 return;
1394         }
1396         intContactSeekNum = lstResults->GetItemData(intSelected);
1398         UCNotif *uc = new UCNotif;
1400         uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1401         uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1403         wxCommandEvent ec(CE_EDITCONTACT);
1404         ec.SetClientData(uc);
1405         ec.SetInt(1);
1406         wxPostEvent(this->GetParent(), ec);
1410 void frmSearch::RevealContact( wxCommandEvent& event ){
1412         // Check if a contact has been selected.
1414         long intSelected = -1;
1415         int intSelectedData = 0;
1416         long intContactSeekNum = -1;
1418         intSelected = lstResults->GetNextItem(intSelected, 
1419                 wxLIST_NEXT_ALL,
1420                 wxLIST_STATE_SELECTED);
1422         if (intSelected == -1){
1423                 return;
1424         }
1426         intContactSeekNum = lstResults->GetItemData(intSelected);
1428         UCNotif *uc = new UCNotif;
1430         uc->ContactAccount = SearchResultAccount[intContactSeekNum];
1431         uc->ContactFilename = SearchResultFilename[intContactSeekNum];
1433         wxCommandEvent rc(CE_REVEALCONTACT);
1434         rc.SetClientData(uc);
1435         rc.SetInt(1);
1436         wxPostEvent(this->GetParent(), rc);
1440 void frmSearch::CloseWindow( wxCloseEvent& event ){
1442         // Hide the window so users don't panic
1443         // whilst clearing up.
1445         this->Hide();
1446         
1447         // Clear up.
1448         
1449         for (std::map<int,void*>::iterator iter = SearchFrames.begin(); 
1450          iter != SearchFrames.end(); ++iter){
1451          
1452                 XABSearchPanel *XABSPPtr;
1453          
1454                 XABSPPtr = static_cast<XABSearchPanel*>(iter->second);
1455                 szrSearch->Detach(XABSPPtr);
1457                 // Remove the frame from the memory and the list.
1458         
1459                 delete XABSPPtr;
1460                 XABSPPtr = NULL;
1461                  
1462         }
1464         SearchFrames.clear();
1465         
1466         // Close window.
1467         
1468         WindowData *WData = new WindowData;
1470         WData->DataType = 2;
1471         WData->WindowPointer = this;
1472         WData->WindowID = SearchUID;
1474         wxCommandEvent delevent(WINDOW_CLOSE);
1475         delevent.SetClientData(WData);
1476         wxPostEvent(GetParent(), delevent);
1477                 
1478         wxCommandEvent rs(CE_REMOVESEARCH);
1479         wxPostEvent(this, rs);
1480         
1481         WData = NULL;
1482         
1483         this->Destroy();
1487 void frmSearch::CloseWindow( wxCommandEvent& event ){
1489         this->Close();
1493 void frmSearch::UpdateResult( wxCommandEvent& event ){
1495         UCNotif *uc = (UCNotif*)event.GetClientData();
1496         
1497         long longSelected = -1;
1498         int intSelectedData = 0;
1499                 
1500         for (;;){
1502                 longSelected = lstResults->GetNextItem(longSelected, 
1503                         wxLIST_NEXT_ALL,
1504                         wxLIST_STATE_DONTCARE);
1505                 
1506                 if (longSelected == -1){
1507                 
1508                         break;
1509                 
1510                 }
1511                 
1512                 // Get the filename/ID information.
1513                 
1514                 intSelectedData = lstResults->GetItemData(longSelected);
1515                 
1516                 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
1517                 
1518                         // Process the contact name
1519                 
1520                         wxString ContactNameFinal;
1521                         
1522                         if (!uc->ContactNameArray.Title.IsEmpty()){
1523         
1524                                 ContactNameFinal.append(uc->ContactNameArray.Title);
1525                                 ContactNameFinal.Trim();
1526                                 ContactNameFinal.append(wxT(" "));
1527         
1528                         }
1529         
1530                         if (!uc->ContactNameArray.Forename.IsEmpty()){
1531         
1532                                 ContactNameFinal.append(uc->ContactNameArray.Forename);
1533                                 ContactNameFinal.Trim();
1534                                 ContactNameFinal.append(wxT(" "));
1535         
1536                         }
1538                         if (!uc->ContactNameArray.Surname.IsEmpty()){
1539         
1540                                 ContactNameFinal.append(uc->ContactNameArray.Surname);
1541                                 ContactNameFinal.Trim();
1542                                 ContactNameFinal.append(wxT(" "));
1543         
1544                         }
1545         
1546                         if (!uc->ContactNameArray.Suffix.IsEmpty()){
1547         
1548                                 ContactNameFinal.append(uc->ContactNameArray.Suffix);
1549                                 ContactNameFinal.Trim();
1550         
1551                         }
1552                 
1553                         lstResults->SetItem(longSelected, 0, ContactNameFinal);
1554                         lstResults->SetItem(longSelected, 1, uc->ContactNickname);
1555                 
1556                 }
1557         
1558         }
1559         
1560         delete uc;
1561         uc = NULL;
1565 bool frmSearch::CheckDuplicate(wxString Filename,
1566         wxString Account, 
1567         std::map<long,wxString> *SRAcc,
1568         std::map<long,wxString> *SRFN){
1569         
1570         std::map<long,wxString>::iterator fniter;
1571         
1572         // Check comparison code.
1573         
1574         for (std::map<long,wxString>::iterator aciter = SRAcc->begin();
1575                 aciter != SRAcc->end(); aciter++){
1576                 
1577                 fniter = SRFN->find(aciter->first);
1579                 if (Filename == fniter->second && 
1580                         Account == aciter->second){
1581                 
1582                         return TRUE;
1583                         
1584                 }
1585                 
1586         }
1587         
1588         return FALSE;
1589         
1592 void frmSearch::DeleteResult(wxCommandEvent &event){
1594         UCNotif *uc = (UCNotif*)event.GetClientData();
1596         long longSelected = -1;
1597         int intSelectedData = 0;
1598                 
1599         for (;;){
1601                 longSelected = lstResults->GetNextItem(longSelected, 
1602                         wxLIST_NEXT_ALL,
1603                         wxLIST_STATE_DONTCARE);
1604                 
1605                 if (longSelected == -1){
1606                 
1607                         break;
1608                 
1609                 }
1610                 
1611                 // Get the filename/ID information.
1612                 
1613                 intSelectedData = lstResults->GetItemData(longSelected);
1614                 
1615                 if (uc->ContactFilename == SearchResultFilename[intSelectedData]){
1616                 
1617                         // Delete the result from the search list and
1618                         // update the total search results.
1620                         // Remove DeleteResultEvent and find out where the uc
1621                         // data is still being used as it crashes on delete. 
1623                         lstResults->DeleteItem(longSelected);
1624                         
1625                         // Update the number of search results.
1626                                                 
1627                         wxCommandEvent sbu(SE_SBUPDATE);
1628                         wxString *SBUpdate = new wxString;
1630                         // Get the number of results.
1632                         int intResultFound = lstResults->GetItemCount();
1633         
1634                         // Prepare the status bar message.
1635         
1636                         if (intResultFound == 0){
1637         
1638                                 *SBUpdate = _("No contacts found.");
1639         
1640                         } else if (intResultFound == 1){
1641         
1642                                 *SBUpdate = _("1 contact found.");
1643         
1644                         } else {
1645         
1646                                 *SBUpdate = wxString::Format(wxT("%i"), intResultFound) + _(" contacts found.");
1647         
1648                         }
1649                 
1650                         sbu.SetClientData(SBUpdate);
1651                         wxPostEvent(this, sbu);
1652                 
1653                         break;
1654                 
1655                 }
1656         
1657         }
1659         delete uc;
1660         uc = NULL;
1664 void frmSearch::SetUID(int UID){
1666         SearchUID = UID;
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