63
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-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: Contacts Model store filtered contact view implementation.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDES
|
|
20 |
#include "CFindViewBase.h"
|
|
21 |
|
|
22 |
// VPbkCntModel
|
|
23 |
#include "CContactStore.h"
|
|
24 |
#include "CRefineView.h"
|
|
25 |
#include "CViewBase.h"
|
|
26 |
#include "CContactLink.h"
|
|
27 |
#include "CContactBookmark.h"
|
|
28 |
|
|
29 |
// VPbkEng
|
|
30 |
#include <CVPbkFieldTypeRefsList.h>
|
|
31 |
#include <CVPbkContactFieldIterator.h>
|
|
32 |
#include <VPbkError.h>
|
|
33 |
#include <CVPbkAsyncCallback.h>
|
|
34 |
#include <MVPbkContactNameConstructionPolicy.h>
|
|
35 |
#include <MVPbkContactFindPolicy.h>
|
|
36 |
#include <VPbkSendEventUtility.h>
|
|
37 |
|
|
38 |
// System includes
|
|
39 |
#include <cntviewbase.h>
|
|
40 |
|
|
41 |
namespace{
|
|
42 |
#ifdef _DEBUG
|
|
43 |
enum TPanic
|
|
44 |
{
|
|
45 |
EPreCond_SetFindStringsL = 1
|
|
46 |
};
|
|
47 |
|
|
48 |
void Panic(TPanic aPanic)
|
|
49 |
{
|
|
50 |
_LIT(KPanicCat, "CFindViewBase");
|
|
51 |
User::Panic(KPanicCat, aPanic);
|
|
52 |
}
|
|
53 |
#endif // _DEBUG
|
|
54 |
} //namespace
|
|
55 |
|
|
56 |
namespace VPbkCntModel {
|
|
57 |
|
|
58 |
// CONSTANTS
|
|
59 |
const TInt KGranularity( 4 );
|
|
60 |
|
|
61 |
// --------------------------------------------------------------------------
|
|
62 |
// CCompareView::CCompareView
|
|
63 |
// --------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
CCompareView::CCompareView( const CContactDatabase& aDb ) :
|
|
66 |
CContactViewBase( aDb )
|
|
67 |
{
|
|
68 |
}
|
|
69 |
|
|
70 |
// --------------------------------------------------------------------------
|
|
71 |
// CCompareView::CompareFieldsL
|
|
72 |
// --------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
TInt CCompareView::CompareFieldsL( const ::CViewContact &aFirst,
|
|
75 |
const ::CViewContact &aSecond )
|
|
76 |
{
|
|
77 |
return CContactViewBase::CompareFieldsL( aFirst, aSecond );
|
|
78 |
}
|
|
79 |
|
|
80 |
// --------------------------------------------------------------------------
|
|
81 |
// CFindViewBase::CFindViewBase
|
|
82 |
// --------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
CFindViewBase::CFindViewBase(
|
|
85 |
MParentViewForFiltering& aParentView,
|
|
86 |
CViewBase& aBaseView,
|
|
87 |
TBool aOwnsContacts ) :
|
|
88 |
iParentView( aParentView ),
|
|
89 |
iBaseView( aBaseView ),
|
|
90 |
iOwnsContacts( aOwnsContacts ),
|
|
91 |
iDestroyed( NULL )
|
|
92 |
{
|
|
93 |
}
|
|
94 |
|
|
95 |
// --------------------------------------------------------------------------
|
|
96 |
// CFindViewBase::BaseConstructL
|
|
97 |
// --------------------------------------------------------------------------
|
|
98 |
//
|
|
99 |
void CFindViewBase::BaseConstructL( const MDesCArray& aFindStrings,
|
|
100 |
MVPbkContactFindPolicy& aFindPolicy,
|
|
101 |
MVPbkContactViewObserver& aExternalViewObserver )
|
|
102 |
{
|
|
103 |
iObserverOp =
|
|
104 |
CVPbkAsyncObjectOperation<MVPbkContactViewObserver>::NewL();
|
|
105 |
iFilterObsOp =
|
|
106 |
CVPbkAsyncObjectOperation<MFilteredViewSupportObserver>::NewL();
|
|
107 |
|
|
108 |
iFindStrings = new(ELeave)CDesCArrayFlat( KGranularity );
|
|
109 |
SetFindStringsL( aFindStrings );
|
|
110 |
|
|
111 |
// Set contact find policy
|
|
112 |
iContactFindPolicy = &aFindPolicy;
|
|
113 |
|
|
114 |
// Add the external observer
|
|
115 |
iObservers.AppendL( &aExternalViewObserver );
|
|
116 |
|
|
117 |
//Create field type list
|
|
118 |
iFieldTypeRefsList = CVPbkFieldTypeRefsList::NewL();
|
|
119 |
|
|
120 |
iViewContact = CViewContact::NewL( iBaseView, SortOrder() );
|
|
121 |
}
|
|
122 |
|
|
123 |
// --------------------------------------------------------------------------
|
|
124 |
// CFindViewBase::~CFindViewBase
|
|
125 |
// --------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
CFindViewBase::~CFindViewBase()
|
|
128 |
{
|
|
129 |
delete iObserverOp;
|
|
130 |
delete iFilterObsOp;
|
|
131 |
ResetContacts();
|
|
132 |
iMatchedContacts.Close();
|
|
133 |
iParentView.RemoveFilteringObserver( *this );
|
|
134 |
iObservers.Close();
|
|
135 |
iFilteringObservers.Close();
|
|
136 |
|
|
137 |
delete iViewContact;
|
|
138 |
delete iFieldTypeRefsList;
|
|
139 |
delete iFindStrings;
|
|
140 |
if ( iDestroyed )
|
|
141 |
{
|
|
142 |
*iDestroyed = ETrue;
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
// --------------------------------------------------------------------------
|
|
147 |
// CFindViewBase::ActivateContactMatchL
|
|
148 |
// --------------------------------------------------------------------------
|
|
149 |
//
|
|
150 |
void CFindViewBase::ActivateContactMatchL()
|
|
151 |
{
|
|
152 |
// Remove first if this called second time when updating.
|
|
153 |
iParentView.RemoveFilteringObserver( *this );
|
|
154 |
// This will cause an asynchrnous view event to this view from the
|
|
155 |
// parent view.
|
|
156 |
iParentView.AddFilteringObserverL( *this );
|
|
157 |
}
|
|
158 |
|
|
159 |
// --------------------------------------------------------------------------
|
|
160 |
// CFindViewBase::ParentObject
|
|
161 |
// --------------------------------------------------------------------------
|
|
162 |
//
|
|
163 |
MVPbkObjectHierarchy& CFindViewBase::ParentObject() const
|
|
164 |
{
|
|
165 |
return iParentView.ParentObject();
|
|
166 |
}
|
|
167 |
|
|
168 |
// --------------------------------------------------------------------------
|
|
169 |
// CFindViewBase::RefreshL
|
|
170 |
// --------------------------------------------------------------------------
|
|
171 |
//
|
|
172 |
void CFindViewBase::RefreshL()
|
|
173 |
{
|
|
174 |
iParentView.RefreshL();
|
|
175 |
}
|
|
176 |
|
|
177 |
// --------------------------------------------------------------------------
|
|
178 |
// CFindViewBase::ContactCountL
|
|
179 |
// --------------------------------------------------------------------------
|
|
180 |
//
|
|
181 |
TInt CFindViewBase::ContactCountL() const
|
|
182 |
{
|
|
183 |
return iMatchedContacts.Count();
|
|
184 |
}
|
|
185 |
|
|
186 |
// --------------------------------------------------------------------------
|
|
187 |
// CFindViewBase::ContactAtL
|
|
188 |
// --------------------------------------------------------------------------
|
|
189 |
//
|
|
190 |
const MVPbkViewContact& CFindViewBase::ContactAtL(
|
|
191 |
TInt aIndex ) const
|
|
192 |
{
|
|
193 |
__ASSERT_ALWAYS( aIndex >= 0,
|
|
194 |
VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
|
|
195 |
|
|
196 |
if ( aIndex >= ContactCountL() )
|
|
197 |
{
|
|
198 |
User::Leave( KErrArgument );
|
|
199 |
}
|
|
200 |
|
|
201 |
const ::CViewContact& viewContact = *iMatchedContacts[ aIndex ];
|
|
202 |
iViewContact->SetViewContact(viewContact);
|
|
203 |
return *iViewContact;
|
|
204 |
}
|
|
205 |
|
|
206 |
// --------------------------------------------------------------------------
|
|
207 |
// CFindViewBase::CreateLinkLC
|
|
208 |
// --------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
MVPbkContactLink* CFindViewBase::CreateLinkLC(
|
|
211 |
TInt aIndex ) const
|
|
212 |
{
|
|
213 |
__ASSERT_ALWAYS( aIndex >= 0,
|
|
214 |
VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
|
|
215 |
|
|
216 |
if ( aIndex >= ContactCountL() )
|
|
217 |
{
|
|
218 |
User::Leave( KErrArgument );
|
|
219 |
}
|
|
220 |
|
|
221 |
TContactItemId contactId = iMatchedContacts[aIndex]->Id();
|
|
222 |
return CContactLink::NewLC( iBaseView.Store(), contactId );
|
|
223 |
}
|
|
224 |
|
|
225 |
// --------------------------------------------------------------------------
|
|
226 |
// CFindViewBase::IndexOfLinkL
|
|
227 |
// --------------------------------------------------------------------------
|
|
228 |
//
|
|
229 |
TInt CFindViewBase::IndexOfLinkL(
|
|
230 |
const MVPbkContactLink& aContactLink ) const
|
|
231 |
{
|
|
232 |
if (&aContactLink.ContactStore() == &iParentView.ContactStore())
|
|
233 |
{
|
|
234 |
const CContactLink& link =
|
|
235 |
static_cast<const CContactLink&>(aContactLink);
|
|
236 |
const TInt count( iMatchedContacts.Count() );
|
|
237 |
for ( TInt i(0); i < count; ++i )
|
|
238 |
{
|
|
239 |
if ( iMatchedContacts[ i ]->Id() == link.ContactId() )
|
|
240 |
{
|
|
241 |
return i;
|
|
242 |
}
|
|
243 |
}
|
|
244 |
}
|
|
245 |
|
|
246 |
return KErrNotFound;
|
|
247 |
}
|
|
248 |
|
|
249 |
// --------------------------------------------------------------------------
|
|
250 |
// CFindViewBase::Type
|
|
251 |
// --------------------------------------------------------------------------
|
|
252 |
//
|
|
253 |
TVPbkContactViewType CFindViewBase::Type() const
|
|
254 |
{
|
|
255 |
return iParentView.Type();
|
|
256 |
}
|
|
257 |
|
|
258 |
// --------------------------------------------------------------------------
|
|
259 |
// CFindViewBase::ChangeSortOrderL
|
|
260 |
// --------------------------------------------------------------------------
|
|
261 |
//
|
|
262 |
void CFindViewBase::ChangeSortOrderL(const MVPbkFieldTypeList& aSortOrder)
|
|
263 |
{
|
|
264 |
iParentView.ChangeSortOrderL( aSortOrder );
|
|
265 |
}
|
|
266 |
|
|
267 |
// --------------------------------------------------------------------------
|
|
268 |
// CFindViewBase::SortOrder
|
|
269 |
// --------------------------------------------------------------------------
|
|
270 |
//
|
|
271 |
const MVPbkFieldTypeList& CFindViewBase::SortOrder() const
|
|
272 |
{
|
|
273 |
return iParentView.SortOrder();
|
|
274 |
}
|
|
275 |
|
|
276 |
// --------------------------------------------------------------------------
|
|
277 |
// CFindViewBase::AddObserverL
|
|
278 |
// --------------------------------------------------------------------------
|
|
279 |
//
|
|
280 |
void CFindViewBase::AddObserverL( MVPbkContactViewObserver& aObserver )
|
|
281 |
{
|
|
282 |
CVPbkAsyncObjectCallback<MVPbkContactViewObserver>* callback =
|
|
283 |
VPbkEngUtils::CreateAsyncObjectCallbackLC(
|
|
284 |
*this,
|
|
285 |
&CFindViewBase::DoAddObserver,
|
|
286 |
&CFindViewBase::DoAddObserverError,
|
|
287 |
aObserver);
|
|
288 |
iObserverOp->CallbackL( callback );
|
|
289 |
CleanupStack::Pop( callback );
|
|
290 |
|
|
291 |
// Insert to first position because events are send in reverse order.
|
|
292 |
iObservers.InsertL( &aObserver, 0 );
|
|
293 |
}
|
|
294 |
|
|
295 |
// --------------------------------------------------------------------------
|
|
296 |
// CFindViewBase::RemoveObserver
|
|
297 |
// --------------------------------------------------------------------------
|
|
298 |
//
|
|
299 |
void CFindViewBase::RemoveObserver(MVPbkContactViewObserver& aObserver)
|
|
300 |
{
|
|
301 |
const TInt index = iObservers.Find( &aObserver );
|
|
302 |
if ( index != KErrNotFound )
|
|
303 |
{
|
|
304 |
iObservers.Remove( index );
|
|
305 |
}
|
|
306 |
}
|
|
307 |
|
|
308 |
// --------------------------------------------------------------------------
|
|
309 |
// CFindViewBase::MatchContactStore
|
|
310 |
// --------------------------------------------------------------------------
|
|
311 |
//
|
|
312 |
TBool CFindViewBase::MatchContactStore(const TDesC& aContactStoreUri) const
|
|
313 |
{
|
|
314 |
return iParentView.MatchContactStore( aContactStoreUri );
|
|
315 |
}
|
|
316 |
|
|
317 |
// --------------------------------------------------------------------------
|
|
318 |
// CFindViewBase::MatchContactStoreDomain
|
|
319 |
// --------------------------------------------------------------------------
|
|
320 |
//
|
|
321 |
TBool CFindViewBase::MatchContactStoreDomain(const TDesC& aContactStoreDomain) const
|
|
322 |
{
|
|
323 |
return iParentView.MatchContactStoreDomain( aContactStoreDomain );
|
|
324 |
}
|
|
325 |
|
|
326 |
// --------------------------------------------------------------------------
|
|
327 |
// CFindViewBase::CreateBookmarkLC
|
|
328 |
// --------------------------------------------------------------------------
|
|
329 |
//
|
|
330 |
MVPbkContactBookmark* CFindViewBase::CreateBookmarkLC(
|
|
331 |
TInt aIndex ) const
|
|
332 |
{
|
|
333 |
__ASSERT_ALWAYS( aIndex >= 0,
|
|
334 |
VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
|
|
335 |
|
|
336 |
TContactItemId contactId = iMatchedContacts[aIndex]->Id();
|
|
337 |
// Link implements also the bookmark interface in this store
|
|
338 |
return CContactBookmark::NewLC( contactId, iBaseView.Store() );
|
|
339 |
}
|
|
340 |
|
|
341 |
// --------------------------------------------------------------------------
|
|
342 |
// CFindViewBase::IndexOfBookmarkL
|
|
343 |
// --------------------------------------------------------------------------
|
|
344 |
//
|
|
345 |
TInt CFindViewBase::IndexOfBookmarkL(
|
|
346 |
const MVPbkContactBookmark& aContactBookmark ) const
|
|
347 |
{
|
|
348 |
// Bookmark is implemented in this store
|
|
349 |
const CContactBookmark* bookmark =
|
|
350 |
dynamic_cast<const CContactBookmark*>(&aContactBookmark);
|
|
351 |
if (bookmark &&
|
|
352 |
&bookmark->ContactStore() == &iParentView.ContactStore() )
|
|
353 |
{
|
|
354 |
const TInt count( iMatchedContacts.Count() );
|
|
355 |
for ( TInt i(0); i < count; ++i )
|
|
356 |
{
|
|
357 |
if ( iMatchedContacts[ i ]->Id() == bookmark->ContactId() )
|
|
358 |
{
|
|
359 |
return i;
|
|
360 |
}
|
|
361 |
}
|
|
362 |
}
|
|
363 |
return KErrNotFound;
|
|
364 |
}
|
|
365 |
|
|
366 |
// --------------------------------------------------------------------------
|
|
367 |
// CFindViewBase::AddFilteringObserverL
|
|
368 |
// --------------------------------------------------------------------------
|
|
369 |
//
|
|
370 |
void CFindViewBase::AddFilteringObserverL(
|
|
371 |
MFilteredViewSupportObserver& aObserver )
|
|
372 |
{
|
|
373 |
// Insert observer in callback function. That ensures that the observer
|
|
374 |
// will always get the event asynchronously.
|
|
375 |
|
|
376 |
CVPbkAsyncObjectCallback<MFilteredViewSupportObserver>* callback =
|
|
377 |
VPbkEngUtils::CreateAsyncObjectCallbackLC(
|
|
378 |
*this,
|
|
379 |
&CFindViewBase::DoAddFilteringObserverL,
|
|
380 |
&CFindViewBase::DoAddFilteringObserverError,
|
|
381 |
aObserver);
|
|
382 |
|
|
383 |
iFilterObsOp->CallbackL( callback );
|
|
384 |
CleanupStack::Pop( callback );
|
|
385 |
}
|
|
386 |
|
|
387 |
// --------------------------------------------------------------------------
|
|
388 |
// CFindViewBase::RemoveFilteringObserver
|
|
389 |
// --------------------------------------------------------------------------
|
|
390 |
//
|
|
391 |
void CFindViewBase::RemoveFilteringObserver(
|
|
392 |
MFilteredViewSupportObserver& aObserver )
|
|
393 |
{
|
|
394 |
iFilterObsOp->CancelCallback( &aObserver );
|
|
395 |
const TInt index( iFilteringObservers.Find( &aObserver ) );
|
|
396 |
if ( index != KErrNotFound )
|
|
397 |
{
|
|
398 |
iFilteringObservers.Remove( index );
|
|
399 |
}
|
|
400 |
}
|
|
401 |
|
|
402 |
// --------------------------------------------------------------------------
|
|
403 |
// CFindViewBase::ViewFiltering
|
|
404 |
// --------------------------------------------------------------------------
|
|
405 |
//
|
|
406 |
MVPbkContactViewFiltering* CFindViewBase::ViewFiltering()
|
|
407 |
{
|
|
408 |
// This view supports further filtering.
|
|
409 |
return this;
|
|
410 |
}
|
|
411 |
|
|
412 |
// --------------------------------------------------------------------------
|
|
413 |
// CFindViewBase::CreateFilteredViewLC
|
|
414 |
// --------------------------------------------------------------------------
|
|
415 |
//
|
|
416 |
MVPbkContactViewBase* CFindViewBase::CreateFilteredViewLC(
|
|
417 |
MVPbkContactViewObserver& aObserver,
|
|
418 |
const MDesCArray& aFindWords,
|
|
419 |
const MVPbkContactBookmarkCollection* /*aAlwaysIncludedContacts*/ )
|
|
420 |
{
|
|
421 |
// NOTE: aAlwaysIncludedContacts is commented because in VPbkCntModel
|
|
422 |
// filtered views are linked. CFindView->CRefineView->CRefineView etc.
|
|
423 |
// Only the CFindView saves the always included contacts and they
|
|
424 |
// are used also by all CRefineView instances through
|
|
425 |
// MAlwaysIncludedContacts interface.
|
|
426 |
CRefineView* refineView = CRefineView::NewLC( aFindWords, *this,
|
|
427 |
iBaseView, aObserver, *iContactFindPolicy,
|
|
428 |
*this );
|
|
429 |
refineView->ActivateContactMatchL();
|
|
430 |
return refineView;
|
|
431 |
}
|
|
432 |
|
|
433 |
// --------------------------------------------------------------------------
|
|
434 |
// CFindViewBase::ContactViewReady
|
|
435 |
// --------------------------------------------------------------------------
|
|
436 |
//
|
|
437 |
void CFindViewBase::ContactViewReady(
|
|
438 |
MVPbkContactViewBase& /*aView*/ )
|
|
439 |
{
|
|
440 |
SendViewStateEventToObservers();
|
|
441 |
}
|
|
442 |
|
|
443 |
// --------------------------------------------------------------------------
|
|
444 |
// CFindViewBase::ContactViewUnavailable
|
|
445 |
// --------------------------------------------------------------------------
|
|
446 |
//
|
|
447 |
void CFindViewBase::ContactViewUnavailable(
|
|
448 |
MVPbkContactViewBase& /*aView*/ )
|
|
449 |
{
|
|
450 |
SendViewStateEventToObservers();
|
|
451 |
}
|
|
452 |
|
|
453 |
// --------------------------------------------------------------------------
|
|
454 |
// CFindViewBase::ContactAddedToView
|
|
455 |
// --------------------------------------------------------------------------
|
|
456 |
//
|
|
457 |
void CFindViewBase::ContactAddedToView(
|
|
458 |
MVPbkContactViewBase& aView,
|
|
459 |
TInt aIndex,
|
|
460 |
const MVPbkContactLink& aContactLink )
|
|
461 |
{
|
|
462 |
TRAPD( error, HandleContactAddedToViewL( aView, aIndex, aContactLink ) );
|
|
463 |
if ( error != KErrNone )
|
|
464 |
{
|
|
465 |
ContactViewError( aView, error, EFalse );
|
|
466 |
}
|
|
467 |
}
|
|
468 |
|
|
469 |
// --------------------------------------------------------------------------
|
|
470 |
// CFindViewBase::ContactRemovedFromView
|
|
471 |
// --------------------------------------------------------------------------
|
|
472 |
//
|
|
473 |
void CFindViewBase::ContactRemovedFromView(
|
|
474 |
MVPbkContactViewBase& aView,
|
|
475 |
TInt aIndex,
|
|
476 |
const MVPbkContactLink& aContactLink )
|
|
477 |
{
|
|
478 |
TRAPD( error, HandleContactRemovedFromViewL( aView, aIndex, aContactLink ) );
|
|
479 |
if ( error != KErrNone )
|
|
480 |
{
|
|
481 |
ContactViewError( aView, error, EFalse );
|
|
482 |
}
|
|
483 |
}
|
|
484 |
|
|
485 |
// --------------------------------------------------------------------------
|
|
486 |
// CFindViewBase::ContactViewError
|
|
487 |
// --------------------------------------------------------------------------
|
|
488 |
//
|
|
489 |
void CFindViewBase::ContactViewError( MVPbkContactViewBase& /*aView*/,
|
|
490 |
TInt aError, TBool aErrorNotified )
|
|
491 |
{
|
|
492 |
iViewReady = EFalse;
|
|
493 |
ResetContacts();
|
|
494 |
SendContactViewErrorEvent( aError, aErrorNotified );
|
|
495 |
}
|
|
496 |
|
|
497 |
// --------------------------------------------------------------------------
|
|
498 |
// CFindViewBase::ContactViewReadyForFiltering
|
|
499 |
// --------------------------------------------------------------------------
|
|
500 |
//
|
|
501 |
void CFindViewBase::ContactViewReadyForFiltering(
|
|
502 |
MParentViewForFiltering& aView )
|
|
503 |
{
|
|
504 |
TRAPD( error, DoContactViewReadyForFilteringL( aView ) );
|
|
505 |
if ( error != KErrNone )
|
|
506 |
{
|
|
507 |
ContactViewError( aView, error, EFalse );
|
|
508 |
}
|
|
509 |
else
|
|
510 |
{
|
|
511 |
ContactViewReady( aView );
|
|
512 |
}
|
|
513 |
}
|
|
514 |
|
|
515 |
// --------------------------------------------------------------------------
|
|
516 |
// CFindViewBase::ContactViewUnavailableForFiltering
|
|
517 |
// --------------------------------------------------------------------------
|
|
518 |
//
|
|
519 |
void CFindViewBase::ContactViewUnavailableForFiltering(
|
|
520 |
MParentViewForFiltering& /*aView*/ )
|
|
521 |
{
|
|
522 |
iViewReady = EFalse;
|
|
523 |
ResetContacts();
|
|
524 |
VPbkEng::SendViewEventToObservers( *this, iFilteringObservers,
|
|
525 |
&MFilteredViewSupportObserver::ContactViewUnavailableForFiltering,
|
|
526 |
&MVPbkContactViewObserver::ContactViewError );
|
|
527 |
}
|
|
528 |
|
|
529 |
// --------------------------------------------------------------------------
|
|
530 |
// CFindViewBase::IsMatchL
|
|
531 |
// --------------------------------------------------------------------------
|
|
532 |
//
|
|
533 |
TBool CFindViewBase::IsMatchL( const MVPbkViewContact& aViewContact )
|
|
534 |
{
|
|
535 |
return iContactFindPolicy->MatchContactNameL( *iFindStrings,
|
|
536 |
aViewContact );
|
|
537 |
}
|
|
538 |
|
|
539 |
// --------------------------------------------------------------------------
|
|
540 |
// CFindViewBase::FindStrings
|
|
541 |
// --------------------------------------------------------------------------
|
|
542 |
//
|
|
543 |
const MDesCArray& CFindViewBase::FindStrings() const
|
|
544 |
{
|
|
545 |
return *iFindStrings;
|
|
546 |
}
|
|
547 |
|
|
548 |
// -------------------------------------------------------------------------
|
|
549 |
// CFindViewBase::SetFindStringsL
|
|
550 |
// --------------------------------------------------------------------------
|
|
551 |
//
|
|
552 |
void CFindViewBase::SetFindStringsL( const MDesCArray& aFindStrings )
|
|
553 |
{
|
|
554 |
__ASSERT_DEBUG( iFindStrings, Panic( EPreCond_SetFindStringsL ) );
|
|
555 |
|
|
556 |
iFindStrings->Reset();
|
|
557 |
const TInt count = aFindStrings.MdcaCount();
|
|
558 |
for ( TInt i = 0; i < count; ++i )
|
|
559 |
{
|
|
560 |
iFindStrings->AppendL( aFindStrings.MdcaPoint( i ) );
|
|
561 |
}
|
|
562 |
}
|
|
563 |
|
|
564 |
// -------------------------------------------------------------------------
|
|
565 |
// CFindViewBase::SendViewStateEventToObservers
|
|
566 |
// --------------------------------------------------------------------------
|
|
567 |
//
|
|
568 |
void CFindViewBase::SendViewStateEventToObservers()
|
|
569 |
{
|
|
570 |
// Cancel any new AddObserverL callbacks to avoid duplicate event
|
|
571 |
// sending.
|
|
572 |
iObserverOp->Purge();
|
|
573 |
|
|
574 |
void (MVPbkContactViewObserver::*notifyFunc)(MVPbkContactViewBase&);
|
|
575 |
notifyFunc = &MVPbkContactViewObserver::ContactViewReady;
|
|
576 |
|
|
577 |
if ( !iViewReady )
|
|
578 |
{
|
|
579 |
notifyFunc = &MVPbkContactViewObserver::ContactViewUnavailable;
|
|
580 |
}
|
|
581 |
|
|
582 |
VPbkEng::SendViewEventToObservers( *this, iObservers,
|
|
583 |
notifyFunc, &MVPbkContactViewObserver::ContactViewError );
|
|
584 |
VPbkEng::SendViewEventToObservers( *this, iFilteringObservers,
|
|
585 |
notifyFunc, &MVPbkContactViewObserver::ContactViewError );
|
|
586 |
}
|
|
587 |
|
|
588 |
// -------------------------------------------------------------------------
|
|
589 |
// CFindViewBase::DoContactViewReadyForFilteringL
|
|
590 |
// --------------------------------------------------------------------------
|
|
591 |
//
|
|
592 |
void CFindViewBase::DoContactViewReadyForFilteringL(
|
|
593 |
MVPbkContactViewBase& /*aView*/ )
|
|
594 |
{
|
|
595 |
ContactMatchL();
|
|
596 |
iViewReady = ETrue;
|
|
597 |
// Send ContactViewReadyForFiltering event so that other views in
|
|
598 |
// stack can rebuild themselves before external observer are notified.
|
|
599 |
VPbkEng::SendViewEventToObservers( *this, iFilteringObservers,
|
|
600 |
&MFilteredViewSupportObserver::ContactViewReadyForFiltering,
|
|
601 |
&MVPbkContactViewObserver::ContactViewError );
|
|
602 |
}
|
|
603 |
|
|
604 |
// --------------------------------------------------------------------------
|
|
605 |
// CFindViewBase::HandleContactAddedToViewL
|
|
606 |
// --------------------------------------------------------------------------
|
|
607 |
//
|
|
608 |
void CFindViewBase::HandleContactAddedToViewL( MVPbkContactViewBase& aView,
|
|
609 |
TInt aIndex, const MVPbkContactLink& aContactLink )
|
|
610 |
{
|
|
611 |
if ( &iParentView == &aView )
|
|
612 |
{
|
|
613 |
// Let sub class do the addition if needed
|
|
614 |
DoContactAddedToViewL( aView, aIndex, aContactLink,
|
|
615 |
iMatchedContacts );
|
|
616 |
|
|
617 |
// Get the index of the new contact in this view.
|
|
618 |
TInt index( IndexOfLinkL( aContactLink ) );
|
|
619 |
if ( index != KErrNotFound )
|
|
620 |
{
|
|
621 |
VPbkEng::SendViewEventToObservers( *this, index, aContactLink,
|
|
622 |
iObservers,
|
|
623 |
&MVPbkContactViewObserver::ContactAddedToView,
|
|
624 |
&MVPbkContactViewObserver::ContactViewError );
|
|
625 |
VPbkEng::SendViewEventToObservers( *this, index, aContactLink,
|
|
626 |
iFilteringObservers,
|
|
627 |
&MVPbkContactViewObserver::ContactAddedToView,
|
|
628 |
&MVPbkContactViewObserver::ContactViewError );
|
|
629 |
}
|
|
630 |
}
|
|
631 |
}
|
|
632 |
|
|
633 |
// --------------------------------------------------------------------------
|
|
634 |
// CFindViewBase::HandleContactRemovedFromViewL
|
|
635 |
// --------------------------------------------------------------------------
|
|
636 |
//
|
|
637 |
void CFindViewBase::HandleContactRemovedFromViewL(
|
|
638 |
MVPbkContactViewBase& aView, TInt /*aIndex*/,
|
|
639 |
const MVPbkContactLink& aContactLink )
|
|
640 |
{
|
|
641 |
if ( &iParentView == &aView )
|
|
642 |
{
|
|
643 |
TInt index = KErrNotFound;
|
|
644 |
|
|
645 |
CCntModelViewContact* removedContact = NULL;
|
|
646 |
CViewContact* viewContact = CViewContact::NewL( iBaseView, SortOrder() );
|
|
647 |
CleanupStack::PushL( viewContact );
|
|
648 |
const TInt count( iMatchedContacts.Count() );
|
|
649 |
for ( TInt i= 0; i < count && !removedContact; ++i )
|
|
650 |
{
|
|
651 |
CCntModelViewContact* contact = iMatchedContacts[i];
|
|
652 |
viewContact->SetViewContact( *contact );
|
|
653 |
|
|
654 |
// Filter away the removed contact
|
|
655 |
if ( aContactLink.RefersTo( *viewContact ) )
|
|
656 |
{
|
|
657 |
// Remove contact from the array
|
|
658 |
iMatchedContacts.Remove( i );
|
|
659 |
// Save the removed index for the observers
|
|
660 |
index = i;
|
|
661 |
// At this point nobody owns removedContact.
|
|
662 |
removedContact = contact;
|
|
663 |
}
|
|
664 |
}
|
|
665 |
CleanupStack::PopAndDestroy( viewContact );
|
|
666 |
TBool takeCareOfOwnership = (removedContact && iOwnsContacts);
|
|
667 |
|
|
668 |
// Notice: we can not delete the contact instance before
|
|
669 |
// all observers have received the event. This is because
|
|
670 |
// in case of CRefineView, iMatchedContacts contains references
|
|
671 |
// to CCntModelViewContact instances. If we delete the contact
|
|
672 |
// before notifying observer then the there will be invalid
|
|
673 |
// pointer.
|
|
674 |
if ( takeCareOfOwnership )
|
|
675 |
{
|
|
676 |
CleanupStack::PushL( removedContact );
|
|
677 |
}
|
|
678 |
|
|
679 |
if ( index != KErrNotFound )
|
|
680 |
{
|
|
681 |
VPbkEng::SendViewEventToObservers( *this, index, aContactLink,
|
|
682 |
iObservers,
|
|
683 |
&MVPbkContactViewObserver::ContactRemovedFromView,
|
|
684 |
&MVPbkContactViewObserver::ContactViewError );
|
|
685 |
VPbkEng::SendViewEventToObservers( *this, index, aContactLink,
|
|
686 |
iFilteringObservers,
|
|
687 |
&MVPbkContactViewObserver::ContactRemovedFromView,
|
|
688 |
&MVPbkContactViewObserver::ContactViewError );
|
|
689 |
}
|
|
690 |
|
|
691 |
if ( takeCareOfOwnership)
|
|
692 |
{
|
|
693 |
// After all observers have received the Removed -event, it's
|
|
694 |
// safe to actually destroy the contact.
|
|
695 |
CleanupStack::PopAndDestroy( removedContact );
|
|
696 |
}
|
|
697 |
}
|
|
698 |
}
|
|
699 |
|
|
700 |
// --------------------------------------------------------------------------
|
|
701 |
// CFindViewBase::DoAddObserver
|
|
702 |
// --------------------------------------------------------------------------
|
|
703 |
//
|
|
704 |
void CFindViewBase::DoAddObserver( MVPbkContactViewObserver& aObserver )
|
|
705 |
{
|
|
706 |
if (iViewReady)
|
|
707 |
{
|
|
708 |
// If this view is ready and there was no error,
|
|
709 |
// tell it to the observer
|
|
710 |
aObserver.ContactViewReady( *this );
|
|
711 |
}
|
|
712 |
else
|
|
713 |
{
|
|
714 |
aObserver.ContactViewUnavailable( *this );
|
|
715 |
}
|
|
716 |
}
|
|
717 |
|
|
718 |
// --------------------------------------------------------------------------
|
|
719 |
// CFindViewBase::DoAddObserverError
|
|
720 |
// --------------------------------------------------------------------------
|
|
721 |
//
|
|
722 |
void CFindViewBase::DoAddObserverError(
|
|
723 |
MVPbkContactViewObserver& /*aObserver*/, TInt /*aError*/ )
|
|
724 |
{
|
|
725 |
// DoAddObserver doesn't leave so nothing to implement here
|
|
726 |
}
|
|
727 |
|
|
728 |
// --------------------------------------------------------------------------
|
|
729 |
// CFindViewBase::DoAddFilteringObserverL
|
|
730 |
// --------------------------------------------------------------------------
|
|
731 |
//
|
|
732 |
void CFindViewBase::DoAddFilteringObserverL(
|
|
733 |
MFilteredViewSupportObserver& aObserver )
|
|
734 |
{
|
|
735 |
// Insert to first position because events are send in reverse order.
|
|
736 |
iFilteringObservers.InsertL( &aObserver, 0 );
|
|
737 |
|
|
738 |
if (iViewReady)
|
|
739 |
{
|
|
740 |
aObserver.ContactViewReadyForFiltering( *this );
|
|
741 |
aObserver.ContactViewReady( *this );
|
|
742 |
}
|
|
743 |
else
|
|
744 |
{
|
|
745 |
aObserver.ContactViewUnavailableForFiltering( *this );
|
|
746 |
aObserver.ContactViewUnavailable( *this );
|
|
747 |
}
|
|
748 |
}
|
|
749 |
|
|
750 |
// --------------------------------------------------------------------------
|
|
751 |
// CFindViewBase::DoAddFilteringObserverError
|
|
752 |
// --------------------------------------------------------------------------
|
|
753 |
//
|
|
754 |
void CFindViewBase::DoAddFilteringObserverError(
|
|
755 |
MFilteredViewSupportObserver& aObserver, TInt aError )
|
|
756 |
{
|
|
757 |
// See DoAddFilteringObserverL. If it leaves then adding the aObserver
|
|
758 |
// failed.
|
|
759 |
aObserver.ContactViewError( *this, aError, EFalse );
|
|
760 |
}
|
|
761 |
|
|
762 |
// --------------------------------------------------------------------------
|
|
763 |
// CFindViewBase::ContactMatchL
|
|
764 |
// --------------------------------------------------------------------------
|
|
765 |
//
|
|
766 |
void CFindViewBase::ContactMatchL()
|
|
767 |
{
|
|
768 |
// Reset current content
|
|
769 |
ResetContacts();
|
|
770 |
// Subclass matches
|
|
771 |
MatchL( iMatchedContacts );
|
|
772 |
}
|
|
773 |
|
|
774 |
|
|
775 |
// --------------------------------------------------------------------------
|
|
776 |
// CFindViewBase::ResetContacts
|
|
777 |
// --------------------------------------------------------------------------
|
|
778 |
//
|
|
779 |
void CFindViewBase::ResetContacts()
|
|
780 |
{
|
|
781 |
if ( iOwnsContacts )
|
|
782 |
{
|
|
783 |
iMatchedContacts.ResetAndDestroy();
|
|
784 |
}
|
|
785 |
else
|
|
786 |
{
|
|
787 |
iMatchedContacts.Reset();
|
|
788 |
}
|
|
789 |
}
|
|
790 |
|
|
791 |
// --------------------------------------------------------------------------
|
|
792 |
// CFindViewBase::SendContactViewErrorEvent
|
|
793 |
// --------------------------------------------------------------------------
|
|
794 |
//
|
|
795 |
void CFindViewBase::SendContactViewErrorEvent( TInt aError,
|
|
796 |
TBool aErrorNotified )
|
|
797 |
{
|
|
798 |
TBool destroy = EFalse;
|
|
799 |
iDestroyed = &destroy;
|
|
800 |
|
|
801 |
// Send first to external observers...
|
|
802 |
VPbkEng::SendEventToObserversWhenNotDestroyed( *this, aError, aErrorNotified, iObservers,
|
|
803 |
&MVPbkContactViewObserver::ContactViewError, destroy );
|
|
804 |
// ...then to internal. This ensures that events come first from lower
|
|
805 |
// level find view.
|
|
806 |
VPbkEng::SendEventToObserversWhenNotDestroyed( *this, aError, aErrorNotified,
|
|
807 |
iFilteringObservers, &MVPbkContactViewObserver::ContactViewError, destroy );
|
|
808 |
|
|
809 |
if ( !destroy )
|
|
810 |
{
|
|
811 |
iDestroyed = NULL;
|
|
812 |
}
|
|
813 |
}
|
|
814 |
} // namespace VPbkCntModel
|
|
815 |
// End of File
|