63
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Filtered contact view
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include <eikenv.h>
|
|
18 |
#include "CVPbkFindView.h"
|
|
19 |
#include <MVPbkFieldType.h>
|
|
20 |
#include <CVPbkSortOrder.h>
|
|
21 |
#include <CVPbkAsyncCallback.h>
|
|
22 |
#include <MVPbkViewContact.h>
|
|
23 |
#include <CVPbkAsyncOperation.h>
|
|
24 |
#include <VPbkError.h>
|
|
25 |
|
|
26 |
#include <CVPbkContactFindPolicy.h>
|
|
27 |
#include <MVPbkContactBookmarkCollection.h>
|
|
28 |
#include <CVPbkContactFieldIterator.h>
|
|
29 |
#include <MVPbkContactFieldData.h>
|
|
30 |
#include <MVPbkContactFieldTextData.h>
|
|
31 |
|
|
32 |
|
|
33 |
#include <VPbkDebug.h>
|
|
34 |
|
|
35 |
namespace {
|
|
36 |
const TInt KObserverArrayGranularity( 4 );
|
|
37 |
const TInt KGranularity( 2 );
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// Event sending function for one reference parameter
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
template <class NotifyFunc>
|
|
44 |
void SendEventToObservers(MVPbkContactViewBase& aView,
|
|
45 |
RPointerArray<MVPbkContactViewObserver>& iObservers,
|
|
46 |
NotifyFunc aNotifyFunc)
|
|
47 |
{
|
|
48 |
const TInt count = iObservers.Count();
|
|
49 |
for (TInt i = count - 1; i >= 0; --i)
|
|
50 |
{
|
|
51 |
MVPbkContactViewObserver* observer = iObservers[i];
|
|
52 |
(observer->*aNotifyFunc)(aView);
|
|
53 |
}
|
|
54 |
}
|
|
55 |
|
|
56 |
// ---------------------------------------------------------------------------
|
|
57 |
// Event sending functions for 3 parameters
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
//
|
|
60 |
template <class NotifyFunc, class ParamType1, class ParamType2>
|
|
61 |
void SendEventToObservers(MVPbkContactViewBase& aView,
|
|
62 |
RPointerArray<MVPbkContactViewObserver>& iObservers,
|
|
63 |
NotifyFunc aNotifyFunc,
|
|
64 |
ParamType1 aParam1,
|
|
65 |
const ParamType2& aParam2)
|
|
66 |
{
|
|
67 |
const TInt count = iObservers.Count();
|
|
68 |
for (TInt i = count - 1; i >= 0; --i)
|
|
69 |
{
|
|
70 |
MVPbkContactViewObserver* observer = iObservers[i];
|
|
71 |
(observer->*aNotifyFunc)(aView, aParam1, aParam2);
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
} // namespace
|
|
76 |
|
|
77 |
|
|
78 |
// ---------------------------------------------------------------------------
|
|
79 |
// CVPbkFindView::CVPbkFindView
|
|
80 |
// ---------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
CVPbkFindView::CVPbkFindView(
|
|
83 |
MVPbkContactViewBase& aBaseView,
|
|
84 |
const MVPbkFieldTypeList* aMasterFieldTypeList ) :
|
|
85 |
iBaseView(aBaseView),
|
|
86 |
iMasterFieldTypeList( aMasterFieldTypeList ),
|
|
87 |
iObservers( KObserverArrayGranularity )
|
|
88 |
{
|
|
89 |
}
|
|
90 |
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
// CVPbkFindView::ConstructL
|
|
93 |
// ---------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
inline void CVPbkFindView::ConstructL(
|
|
96 |
const MDesCArray& aFindWords,
|
|
97 |
const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
|
|
98 |
{
|
|
99 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
100 |
("CVPbkFindView::ConstructL(0x%x)"), this);
|
|
101 |
|
|
102 |
iAsyncOperation = new(ELeave) VPbkEngUtils::CVPbkAsyncOperation;
|
|
103 |
|
|
104 |
iFindStrings = new(ELeave)CDesCArrayFlat( KGranularity );
|
|
105 |
SetFindStringsL( aFindWords );
|
|
106 |
|
|
107 |
SetAlwaysIncludedContactsL( aAlwaysIncludedContacts );
|
|
108 |
|
|
109 |
|
|
110 |
CEikonEnv* eikonEnv = CEikonEnv::Static();
|
|
111 |
|
|
112 |
if ( eikonEnv )
|
|
113 |
{
|
|
114 |
CVPbkContactFindPolicy::TParam param =
|
|
115 |
CVPbkContactFindPolicy::TParam(
|
|
116 |
*iMasterFieldTypeList,
|
|
117 |
eikonEnv->FsSession() );
|
|
118 |
|
|
119 |
// Create contact find policy
|
|
120 |
iContactFindPolicy = CVPbkContactFindPolicy::NewL( param );
|
|
121 |
}
|
|
122 |
|
|
123 |
iBaseView.AddObserverL(*this);
|
|
124 |
|
|
125 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
126 |
("CVPbkFindView::ConstructL(0x%x) end"), this);
|
|
127 |
}
|
|
128 |
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
// CVPbkFindView::NewL
|
|
131 |
// ---------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
CVPbkFindView* CVPbkFindView::NewLC(
|
|
134 |
MVPbkContactViewBase& aBaseView,
|
|
135 |
MVPbkContactViewObserver& aObserver,
|
|
136 |
const MDesCArray& aFindWords,
|
|
137 |
const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts,
|
|
138 |
const MVPbkFieldTypeList& aMasterFieldTypeList )
|
|
139 |
{
|
|
140 |
CVPbkFindView* self =
|
|
141 |
new(ELeave) CVPbkFindView(
|
|
142 |
aBaseView, &aMasterFieldTypeList );
|
|
143 |
CleanupStack::PushL(self);
|
|
144 |
self->ConstructL( aFindWords, aAlwaysIncludedContacts );
|
|
145 |
self->AddObserverL(aObserver);
|
|
146 |
return self;
|
|
147 |
}
|
|
148 |
|
|
149 |
// ---------------------------------------------------------------------------
|
|
150 |
// CVPbkFindView::~CVPbkFindView
|
|
151 |
// ---------------------------------------------------------------------------
|
|
152 |
//
|
|
153 |
CVPbkFindView::~CVPbkFindView()
|
|
154 |
{
|
|
155 |
iContactMapping.Reset();
|
|
156 |
iBaseView.RemoveObserver(*this);
|
|
157 |
iObservers.Close();
|
|
158 |
delete iFindStrings;
|
|
159 |
delete iContactFindPolicy;
|
|
160 |
delete iAsyncOperation;
|
|
161 |
}
|
|
162 |
|
|
163 |
// ---------------------------------------------------------------------------
|
|
164 |
// CVPbkFindView::Type
|
|
165 |
// ---------------------------------------------------------------------------
|
|
166 |
//
|
|
167 |
TVPbkContactViewType CVPbkFindView::Type() const
|
|
168 |
{
|
|
169 |
return iBaseView.Type();
|
|
170 |
}
|
|
171 |
|
|
172 |
// ---------------------------------------------------------------------------
|
|
173 |
// CVPbkFindView::ChangeSortOrderL
|
|
174 |
// ---------------------------------------------------------------------------
|
|
175 |
//
|
|
176 |
void CVPbkFindView::ChangeSortOrderL(
|
|
177 |
const MVPbkFieldTypeList& aSortOrder )
|
|
178 |
{
|
|
179 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
180 |
("CVPbkFindView::ChangeSortOrderL(0x%x)"), &aSortOrder);
|
|
181 |
|
|
182 |
iBaseView.ChangeSortOrderL(aSortOrder);
|
|
183 |
}
|
|
184 |
|
|
185 |
// ---------------------------------------------------------------------------
|
|
186 |
// CVPbkFindView::SortOrder
|
|
187 |
// ---------------------------------------------------------------------------
|
|
188 |
//
|
|
189 |
const MVPbkFieldTypeList& CVPbkFindView::SortOrder() const
|
|
190 |
{
|
|
191 |
return iBaseView.SortOrder();
|
|
192 |
}
|
|
193 |
|
|
194 |
// ---------------------------------------------------------------------------
|
|
195 |
// CVPbkFindView::RefreshL
|
|
196 |
// ---------------------------------------------------------------------------
|
|
197 |
//
|
|
198 |
void CVPbkFindView::RefreshL()
|
|
199 |
{
|
|
200 |
iBaseView.RefreshL();
|
|
201 |
}
|
|
202 |
|
|
203 |
// ---------------------------------------------------------------------------
|
|
204 |
// CVPbkFindView::ContactCountL
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
TInt CVPbkFindView::ContactCountL() const
|
|
208 |
{
|
|
209 |
return iContactMapping.Count();
|
|
210 |
}
|
|
211 |
|
|
212 |
// ---------------------------------------------------------------------------
|
|
213 |
// CVPbkFindView::ContactAtL
|
|
214 |
// ---------------------------------------------------------------------------
|
|
215 |
//
|
|
216 |
const MVPbkViewContact& CVPbkFindView::ContactAtL(
|
|
217 |
TInt aIndex ) const
|
|
218 |
{
|
|
219 |
__ASSERT_ALWAYS( aIndex >= 0,
|
|
220 |
VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
|
|
221 |
if ( aIndex >= iContactMapping.Count() )
|
|
222 |
{
|
|
223 |
User::Leave( KErrArgument );
|
|
224 |
}
|
|
225 |
|
|
226 |
return iBaseView.ContactAtL(iContactMapping[aIndex]);
|
|
227 |
}
|
|
228 |
|
|
229 |
// ---------------------------------------------------------------------------
|
|
230 |
// CVPbkFindView::CreateLinkLC
|
|
231 |
// ---------------------------------------------------------------------------
|
|
232 |
//
|
|
233 |
MVPbkContactLink* CVPbkFindView::CreateLinkLC( TInt aIndex ) const
|
|
234 |
{
|
|
235 |
__ASSERT_ALWAYS( aIndex >= 0,
|
|
236 |
VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
|
|
237 |
if ( aIndex >= iContactMapping.Count() )
|
|
238 |
{
|
|
239 |
User::Leave( KErrArgument );
|
|
240 |
}
|
|
241 |
|
|
242 |
return iBaseView.ContactAtL(iContactMapping[aIndex]).CreateLinkLC();
|
|
243 |
}
|
|
244 |
|
|
245 |
// ---------------------------------------------------------------------------
|
|
246 |
// CVPbkFindView::IndexOfLinkL
|
|
247 |
// ---------------------------------------------------------------------------
|
|
248 |
//
|
|
249 |
TInt CVPbkFindView::IndexOfLinkL(
|
|
250 |
const MVPbkContactLink& aContactLink ) const
|
|
251 |
{
|
|
252 |
TInt baseIndex = iBaseView.IndexOfLinkL(aContactLink);
|
|
253 |
return iContactMapping.Find(baseIndex);
|
|
254 |
}
|
|
255 |
|
|
256 |
// ---------------------------------------------------------------------------
|
|
257 |
// CVPbkFindView::AddObserverL
|
|
258 |
// ---------------------------------------------------------------------------
|
|
259 |
//
|
|
260 |
void CVPbkFindView::AddObserverL(
|
|
261 |
MVPbkContactViewObserver& aObserver )
|
|
262 |
{
|
|
263 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
264 |
("CVPbkFindView::AddObserverL(0x%x)"), &aObserver);
|
|
265 |
|
|
266 |
VPbkEngUtils::MAsyncCallback* notifyObserver =
|
|
267 |
VPbkEngUtils::CreateAsyncCallbackLC(*this,
|
|
268 |
&CVPbkFindView::DoAddObserverL,
|
|
269 |
&CVPbkFindView::AddObserverError,
|
|
270 |
aObserver);
|
|
271 |
iAsyncOperation->CallbackL(notifyObserver);
|
|
272 |
CleanupStack::Pop(notifyObserver);
|
|
273 |
|
|
274 |
/// Insert to first position because event are send in reverse order.
|
|
275 |
/// Last inserted gets notifcation last.
|
|
276 |
iObservers.InsertL( &aObserver, 0 );
|
|
277 |
|
|
278 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
279 |
("CVPbkFindView::AddObserverL(0x%x) end"), &aObserver);
|
|
280 |
}
|
|
281 |
|
|
282 |
// ---------------------------------------------------------------------------
|
|
283 |
// CVPbkFindView::DoAddObserverL
|
|
284 |
// ---------------------------------------------------------------------------
|
|
285 |
//
|
|
286 |
void CVPbkFindView::DoAddObserverL(
|
|
287 |
MVPbkContactViewObserver& aObserver )
|
|
288 |
{
|
|
289 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
290 |
("CVPbkFindView::DoAddObserverL(0x%x)"), &aObserver);
|
|
291 |
|
|
292 |
if ( iObservers.Find( &aObserver ) != KErrNotFound )
|
|
293 |
{
|
|
294 |
if ( iIsReady )
|
|
295 |
{
|
|
296 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
297 |
("CVPbkFindView::DoAddObserverL(0x%x) contact view ready"),
|
|
298 |
&aObserver);
|
|
299 |
|
|
300 |
// If this view is ready and there was no error,
|
|
301 |
// tell it to the observer
|
|
302 |
aObserver.ContactViewReady( *this );
|
|
303 |
}
|
|
304 |
else
|
|
305 |
{
|
|
306 |
aObserver.ContactViewUnavailable( *this );
|
|
307 |
}
|
|
308 |
}
|
|
309 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
310 |
("CVPbkFindView::DoAddObserverL(0x%x) end"), &aObserver);
|
|
311 |
}
|
|
312 |
|
|
313 |
// ---------------------------------------------------------------------------
|
|
314 |
// CVPbkFindView::AddObserverError
|
|
315 |
// ---------------------------------------------------------------------------
|
|
316 |
//
|
|
317 |
void CVPbkFindView::AddObserverError(
|
|
318 |
MVPbkContactViewObserver& aObserver, TInt aError )
|
|
319 |
{
|
|
320 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
321 |
("CVPbkFindView::AddObserverError(0x%x, %d)"), &aObserver, aError);
|
|
322 |
|
|
323 |
aObserver.ContactViewError(*this, aError, EFalse);
|
|
324 |
}
|
|
325 |
|
|
326 |
// ---------------------------------------------------------------------------
|
|
327 |
// CVPbkFindView::RemoveObserver
|
|
328 |
// ---------------------------------------------------------------------------
|
|
329 |
//
|
|
330 |
void CVPbkFindView::RemoveObserver(
|
|
331 |
MVPbkContactViewObserver& aObserver )
|
|
332 |
{
|
|
333 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
334 |
("CVPbkFindView::RemoveObserverError(0x%x)"), &aObserver);
|
|
335 |
|
|
336 |
const TInt index = iObservers.Find( &aObserver );
|
|
337 |
if (index != KErrNotFound)
|
|
338 |
{
|
|
339 |
iObservers.Remove(index);
|
|
340 |
}
|
|
341 |
}
|
|
342 |
|
|
343 |
// ---------------------------------------------------------------------------
|
|
344 |
// CVPbkFindView::MatchContactStore
|
|
345 |
// ---------------------------------------------------------------------------
|
|
346 |
//
|
|
347 |
TBool CVPbkFindView::MatchContactStore(
|
|
348 |
const TDesC& aContactStoreUri ) const
|
|
349 |
{
|
|
350 |
return iBaseView.MatchContactStore(aContactStoreUri);
|
|
351 |
}
|
|
352 |
|
|
353 |
// ---------------------------------------------------------------------------
|
|
354 |
// CVPbkFindView::MatchContactStoreDomain
|
|
355 |
// ---------------------------------------------------------------------------
|
|
356 |
//
|
|
357 |
TBool CVPbkFindView::MatchContactStoreDomain(
|
|
358 |
const TDesC& aContactStoreDomain ) const
|
|
359 |
{
|
|
360 |
return iBaseView.MatchContactStoreDomain(aContactStoreDomain);
|
|
361 |
}
|
|
362 |
|
|
363 |
// ---------------------------------------------------------------------------
|
|
364 |
// CVPbkFindView::CreateBookmarkLC
|
|
365 |
// ---------------------------------------------------------------------------
|
|
366 |
//
|
|
367 |
MVPbkContactBookmark* CVPbkFindView::CreateBookmarkLC(
|
|
368 |
TInt aIndex ) const
|
|
369 |
{
|
|
370 |
return iBaseView.ContactAtL(iContactMapping[aIndex]).CreateBookmarkLC();
|
|
371 |
}
|
|
372 |
|
|
373 |
// ---------------------------------------------------------------------------
|
|
374 |
// CVPbkFindView::IndexOfBookmarkL
|
|
375 |
// ---------------------------------------------------------------------------
|
|
376 |
//
|
|
377 |
TInt CVPbkFindView::IndexOfBookmarkL(
|
|
378 |
const MVPbkContactBookmark& aContactBookmark ) const
|
|
379 |
{
|
|
380 |
TInt baseIndex = iBaseView.IndexOfBookmarkL(aContactBookmark);
|
|
381 |
return iContactMapping.Find(baseIndex);
|
|
382 |
}
|
|
383 |
|
|
384 |
// ---------------------------------------------------------------------------
|
|
385 |
// CVPbkFindView::ViewFiltering
|
|
386 |
// ---------------------------------------------------------------------------
|
|
387 |
//
|
|
388 |
MVPbkContactViewFiltering* CVPbkFindView::ViewFiltering()
|
|
389 |
{
|
|
390 |
return this;
|
|
391 |
}
|
|
392 |
|
|
393 |
// ---------------------------------------------------------------------------
|
|
394 |
// CVPbkFindView::CreateFilteredViewLC
|
|
395 |
// ---------------------------------------------------------------------------
|
|
396 |
//
|
|
397 |
MVPbkContactViewBase* CVPbkFindView::CreateFilteredViewLC(
|
|
398 |
MVPbkContactViewObserver& aObserver,
|
|
399 |
const MDesCArray& aFindWords,
|
|
400 |
const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
|
|
401 |
{
|
|
402 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
403 |
("CVPbkFindView::CreateFilteredViewLC(0x%x)"), this);
|
|
404 |
|
|
405 |
return CVPbkFindView::NewLC( *this,
|
|
406 |
aObserver,
|
|
407 |
aFindWords,
|
|
408 |
aAlwaysIncludedContacts,
|
|
409 |
*iMasterFieldTypeList );
|
|
410 |
}
|
|
411 |
|
|
412 |
// ---------------------------------------------------------------------------
|
|
413 |
// CVPbkFindView::UpdateFilterL
|
|
414 |
// ---------------------------------------------------------------------------
|
|
415 |
//
|
|
416 |
void CVPbkFindView::UpdateFilterL(
|
|
417 |
const MDesCArray& aFindWords,
|
|
418 |
const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
|
|
419 |
{
|
|
420 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
421 |
("CVPbkFindView::UpdateFilterL(0x%x)"), this);
|
|
422 |
|
|
423 |
SetFindStringsL( aFindWords );
|
|
424 |
SetAlwaysIncludedContactsL( aAlwaysIncludedContacts );
|
|
425 |
|
|
426 |
// Remove first if this called second time when updating.
|
|
427 |
iBaseView.RemoveObserver( *this );
|
|
428 |
// This will cause an asynchrnous view event to this view from the
|
|
429 |
// parent view.
|
|
430 |
iBaseView.AddObserverL( *this );
|
|
431 |
}
|
|
432 |
|
|
433 |
// ---------------------------------------------------------------------------
|
|
434 |
// CVPbkFindView::BuildViewMappingL
|
|
435 |
// ---------------------------------------------------------------------------
|
|
436 |
//
|
|
437 |
void CVPbkFindView::BuildViewMappingL()
|
|
438 |
{
|
|
439 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
440 |
("CVPbkFindView::BuildViewMappingL(0x%x)"), this);
|
|
441 |
|
|
442 |
iContactMapping.Reset();
|
|
443 |
|
|
444 |
// Append always included contact
|
|
445 |
if ( iAlwaysIncludedContacts )
|
|
446 |
{
|
|
447 |
const TInt alwaysIncluded( iAlwaysIncludedContacts->Count() );
|
|
448 |
for ( TInt i(0); i < alwaysIncluded; ++i )
|
|
449 |
{
|
|
450 |
TInt index(
|
|
451 |
iBaseView.IndexOfBookmarkL(
|
|
452 |
iAlwaysIncludedContacts->At( i ) ) );
|
|
453 |
if ( index > KErrNotFound )
|
|
454 |
{
|
|
455 |
User::LeaveIfError( iContactMapping.InsertInOrder(index) );
|
|
456 |
}
|
|
457 |
}
|
|
458 |
}
|
|
459 |
|
|
460 |
// Append matched contacts
|
|
461 |
const TInt countContacts = iBaseView.ContactCountL();
|
|
462 |
for (TInt i(0); i < countContacts; ++i)
|
|
463 |
{
|
|
464 |
const MVPbkViewContact& contact = iBaseView.ContactAtL( i );
|
|
465 |
|
|
466 |
TBool match( ETrue );
|
|
467 |
|
|
468 |
if ( iContactFindPolicy &&
|
|
469 |
!iContactFindPolicy->MatchContactNameL( *iFindStrings, contact ))
|
|
470 |
{
|
|
471 |
match = EFalse;
|
|
472 |
}
|
|
473 |
|
|
474 |
if ( match && iContactMapping.FindInOrder( i ) == KErrNotFound )
|
|
475 |
{
|
|
476 |
User::LeaveIfError( iContactMapping.InsertInOrder( i ) );
|
|
477 |
}
|
|
478 |
}
|
|
479 |
|
|
480 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
481 |
("CVPbkFindView::BuildViewMappingL(0x%x) end"), this);
|
|
482 |
}
|
|
483 |
|
|
484 |
// ---------------------------------------------------------------------------
|
|
485 |
// CVPbkFindView::HandleBuildViewMapping
|
|
486 |
// ---------------------------------------------------------------------------
|
|
487 |
//
|
|
488 |
void CVPbkFindView::HandleBuildViewMapping()
|
|
489 |
{
|
|
490 |
TRAPD( res, BuildViewMappingL() );
|
|
491 |
if ( res == KErrNone )
|
|
492 |
{
|
|
493 |
// Mapping was succesfully built. Send ready event
|
|
494 |
SendViewEventToObservers(
|
|
495 |
&MVPbkContactViewObserver::ContactViewReady );
|
|
496 |
}
|
|
497 |
else
|
|
498 |
{
|
|
499 |
// Building the mapping failed. Leave mappings as they are and
|
|
500 |
// send error
|
|
501 |
SendViewErrorEventToObservers( res, EFalse );
|
|
502 |
}
|
|
503 |
}
|
|
504 |
|
|
505 |
// ---------------------------------------------------------------------------
|
|
506 |
// From class MVPbkContactViewBase.
|
|
507 |
// CVPbkFindView::ContactViewReady
|
|
508 |
// ---------------------------------------------------------------------------
|
|
509 |
//
|
|
510 |
void CVPbkFindView::ContactViewReady( MVPbkContactViewBase& aView )
|
|
511 |
{
|
|
512 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
513 |
("CVPbkFindView::ContactViewReady(0x%x)"), &aView);
|
|
514 |
|
|
515 |
iIsReady = ETrue;
|
|
516 |
HandleBuildViewMapping();
|
|
517 |
|
|
518 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
519 |
("CVPbkFindView::ContactViewReady(0x%x) end"), &aView);
|
|
520 |
}
|
|
521 |
|
|
522 |
// ---------------------------------------------------------------------------
|
|
523 |
// From class MVPbkContactViewBase.
|
|
524 |
// CVPbkFindView::ContactViewUnavailable
|
|
525 |
// ---------------------------------------------------------------------------
|
|
526 |
//
|
|
527 |
void CVPbkFindView::ContactViewUnavailable(
|
|
528 |
MVPbkContactViewBase& aView )
|
|
529 |
{
|
|
530 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
531 |
("CVPbkFindView::ContactViewUnavailable(0x%x)"), &aView);
|
|
532 |
|
|
533 |
iIsReady = EFalse;
|
|
534 |
SendViewEventToObservers(
|
|
535 |
&MVPbkContactViewObserver::ContactViewUnavailable );
|
|
536 |
|
|
537 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
538 |
("CVPbkFindView::ContactViewUnavailable(0x%x)"), &aView);
|
|
539 |
}
|
|
540 |
|
|
541 |
// ---------------------------------------------------------------------------
|
|
542 |
// From class MVPbkContactViewBase.
|
|
543 |
// CVPbkFindView::ContactViewError
|
|
544 |
// ---------------------------------------------------------------------------
|
|
545 |
//
|
|
546 |
void CVPbkFindView::ContactViewError( MVPbkContactViewBase& aView,
|
|
547 |
TInt aError, TBool aErrorNotified )
|
|
548 |
{
|
|
549 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
550 |
("CVPbkFindView::ContactViewError(0x%x)"), &aView);
|
|
551 |
|
|
552 |
iIsReady = EFalse;
|
|
553 |
SendViewErrorEventToObservers( aError, aErrorNotified );
|
|
554 |
|
|
555 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
556 |
("CVPbkFindView::ContactViewError(0x%x)"), &aView);
|
|
557 |
}
|
|
558 |
|
|
559 |
// ---------------------------------------------------------------------------
|
|
560 |
// From class MVPbkContactViewBase.
|
|
561 |
// CVPbkFindView::ContactAddedToView
|
|
562 |
// ---------------------------------------------------------------------------
|
|
563 |
//
|
|
564 |
void CVPbkFindView::ContactAddedToView
|
|
565 |
(MVPbkContactViewBase& /*aView*/, TInt aIndex,
|
|
566 |
const MVPbkContactLink& aContactLink)
|
|
567 |
{
|
|
568 |
// To keep indexes in iContactMapping up to date rebuild mappings.
|
|
569 |
TRAPD( res, BuildViewMappingL() );
|
|
570 |
if ( res == KErrNone )
|
|
571 |
{
|
|
572 |
// Do a binary search to mapping
|
|
573 |
TInt index = iContactMapping.FindInOrder( aIndex );
|
|
574 |
if ( index != KErrNotFound )
|
|
575 |
{
|
|
576 |
// Mapping was succesfully updated and the new contact
|
|
577 |
// belongs to filter.
|
|
578 |
SendEventToObservers( *this, iObservers,
|
|
579 |
&MVPbkContactViewObserver::ContactAddedToView, index,
|
|
580 |
aContactLink );
|
|
581 |
}
|
|
582 |
}
|
|
583 |
else
|
|
584 |
{
|
|
585 |
SendViewErrorEventToObservers( res, EFalse );
|
|
586 |
}
|
|
587 |
}
|
|
588 |
|
|
589 |
// ---------------------------------------------------------------------------
|
|
590 |
// From class MVPbkContactViewBase.
|
|
591 |
// CVPbkFindView::ContactRemovedFromView
|
|
592 |
// ---------------------------------------------------------------------------
|
|
593 |
//
|
|
594 |
void CVPbkFindView::ContactRemovedFromView(
|
|
595 |
MVPbkContactViewBase& /*aView*/, TInt aIndex,
|
|
596 |
const MVPbkContactLink& aContactLink)
|
|
597 |
{
|
|
598 |
// Do a binary search to mapping
|
|
599 |
TInt index = iContactMapping.FindInOrder( aIndex );
|
|
600 |
|
|
601 |
// To keep indexes in iContactMapping up to date rebuild mappings.
|
|
602 |
TRAPD( res, BuildViewMappingL() );
|
|
603 |
if ( res == KErrNone )
|
|
604 |
{
|
|
605 |
if ( index != KErrNotFound )
|
|
606 |
{
|
|
607 |
// Mapping was succesfully updated and the new contact
|
|
608 |
// belongs to filter.
|
|
609 |
SendEventToObservers( *this, iObservers,
|
|
610 |
&MVPbkContactViewObserver::ContactRemovedFromView, index,
|
|
611 |
aContactLink );
|
|
612 |
}
|
|
613 |
}
|
|
614 |
else
|
|
615 |
{
|
|
616 |
SendViewErrorEventToObservers( res, EFalse );
|
|
617 |
}
|
|
618 |
}
|
|
619 |
|
|
620 |
// --------------------------------------------------------------------------
|
|
621 |
// CVPbkFindView::SetFindStringsL
|
|
622 |
// --------------------------------------------------------------------------
|
|
623 |
//
|
|
624 |
void CVPbkFindView::SetFindStringsL( const MDesCArray& aFindWords )
|
|
625 |
{
|
|
626 |
iFindStrings->Reset();
|
|
627 |
|
|
628 |
const TInt count( aFindWords.MdcaCount() );
|
|
629 |
for ( TInt i(0); i < count; ++i )
|
|
630 |
{
|
|
631 |
iFindStrings->AppendL( aFindWords.MdcaPoint( i ) );
|
|
632 |
}
|
|
633 |
}
|
|
634 |
|
|
635 |
// --------------------------------------------------------------------------
|
|
636 |
// CVPbkFindView::SetAlwaysIncludedContactsL
|
|
637 |
// --------------------------------------------------------------------------
|
|
638 |
//
|
|
639 |
void CVPbkFindView::SetAlwaysIncludedContactsL(
|
|
640 |
const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
|
|
641 |
{
|
|
642 |
iAlwaysIncludedContacts = aAlwaysIncludedContacts;
|
|
643 |
}
|
|
644 |
|
|
645 |
// --------------------------------------------------------------------------
|
|
646 |
// CVPbkFindView::SendViewEventToObservers
|
|
647 |
// --------------------------------------------------------------------------
|
|
648 |
//
|
|
649 |
void CVPbkFindView::SendViewEventToObservers(
|
|
650 |
void( MVPbkContactViewObserver::* aObserverFunc)( MVPbkContactViewBase& ) )
|
|
651 |
{
|
|
652 |
// Cancel async operation to avoid duplicate event sending to observers
|
|
653 |
iAsyncOperation->Purge();
|
|
654 |
SendEventToObservers( *this, iObservers, aObserverFunc );
|
|
655 |
}
|
|
656 |
|
|
657 |
// --------------------------------------------------------------------------
|
|
658 |
// CVPbkFindView::SendViewErrorEventToObservers
|
|
659 |
// --------------------------------------------------------------------------
|
|
660 |
//
|
|
661 |
void CVPbkFindView::SendViewErrorEventToObservers( TInt aError, TBool
|
|
662 |
aErrorNotified )
|
|
663 |
{
|
|
664 |
// Cancel async operation to avoid duplicate event sending to observers
|
|
665 |
iAsyncOperation->Purge();
|
|
666 |
SendEventToObservers( *this, iObservers,
|
|
667 |
&MVPbkContactViewObserver::ContactViewError,
|
|
668 |
aError, aErrorNotified );
|
|
669 |
}
|
|
670 |
// End of File
|