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