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