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 |
|
|
18 |
|
|
19 |
#include "CVPbkFilteredContactView.h"
|
|
20 |
#include <MVPbkFieldType.h>
|
|
21 |
#include <CVPbkSortOrder.h>
|
|
22 |
#include <CVPbkAsyncCallback.h>
|
|
23 |
#include <MVPbkContactSelector.h>
|
|
24 |
#include <MVPbkViewContact.h>
|
|
25 |
#include <CVPbkAsyncOperation.h>
|
|
26 |
#include <VPbkError.h>
|
|
27 |
#include "CVPbkFindView.h"
|
|
28 |
|
|
29 |
#include <VPbkDebug.h>
|
|
30 |
|
|
31 |
|
|
32 |
namespace {
|
|
33 |
const TInt KObserverArrayGranularity = 4;
|
|
34 |
|
|
35 |
// ---------------------------------------------------------------------------
|
|
36 |
// Event sending function for one reference parameter
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
template <class NotifyFunc>
|
|
40 |
void SendEventToObservers(MVPbkContactViewBase& aView,
|
|
41 |
RPointerArray<MVPbkContactViewObserver>& iObservers,
|
|
42 |
NotifyFunc aNotifyFunc)
|
|
43 |
{
|
|
44 |
const TInt count = iObservers.Count();
|
|
45 |
for (TInt i = 0; i < count; ++i)
|
|
46 |
{
|
|
47 |
MVPbkContactViewObserver* observer = iObservers[i];
|
|
48 |
(observer->*aNotifyFunc)(aView);
|
|
49 |
}
|
|
50 |
}
|
|
51 |
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
// Event sending functions for 3 parameters
|
|
54 |
// ---------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
template <class NotifyFunc, class ParamType1, class ParamType2>
|
|
57 |
void SendEventToObservers(MVPbkContactViewBase& aView,
|
|
58 |
RPointerArray<MVPbkContactViewObserver>& iObservers,
|
|
59 |
NotifyFunc aNotifyFunc,
|
|
60 |
ParamType1 aParam1,
|
|
61 |
const ParamType2& aParam2)
|
|
62 |
{
|
|
63 |
for (TInt i = 0; i < iObservers.Count(); ++i)
|
|
64 |
{
|
|
65 |
MVPbkContactViewObserver* observer = iObservers[i];
|
|
66 |
(observer->*aNotifyFunc)(aView, aParam1, aParam2);
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
} // namespace
|
|
71 |
|
|
72 |
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
// CVPbkFilteredContactView::CVPbkFilteredContactView
|
|
75 |
// ---------------------------------------------------------------------------
|
|
76 |
//
|
|
77 |
CVPbkFilteredContactView::CVPbkFilteredContactView(
|
|
78 |
MVPbkContactViewBase& aBaseView,
|
|
79 |
MVPbkContactSelector& aContactSelector,
|
|
80 |
const MVPbkFieldTypeList* aMasterFieldTypeList ) :
|
|
81 |
iBaseView(aBaseView),
|
|
82 |
iContactSelector(aContactSelector),
|
|
83 |
iMasterFieldTypeList( aMasterFieldTypeList ),
|
|
84 |
iObservers( KObserverArrayGranularity )
|
|
85 |
{
|
|
86 |
}
|
|
87 |
|
|
88 |
// ---------------------------------------------------------------------------
|
|
89 |
// CVPbkFilteredContactView::ConstructL
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
inline void CVPbkFilteredContactView::ConstructL(
|
|
93 |
MVPbkContactViewObserver& aObserver )
|
|
94 |
{
|
|
95 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
96 |
("CVPbkFilteredContactView::ConstructL(0x%x)"), this);
|
|
97 |
|
|
98 |
iObservers.InsertInAddressOrder( &aObserver );
|
|
99 |
iAsyncOperation = new(ELeave) VPbkEngUtils::CVPbkAsyncOperation;
|
|
100 |
iBaseView.AddObserverL(*this);
|
|
101 |
|
|
102 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
103 |
("CVPbkFilteredContactView::ConstructL(0x%x) end"), this);
|
|
104 |
}
|
|
105 |
|
|
106 |
// ---------------------------------------------------------------------------
|
|
107 |
// CVPbkFilteredContactView::NewL
|
|
108 |
// ---------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
EXPORT_C CVPbkFilteredContactView* CVPbkFilteredContactView::NewL(
|
|
111 |
MVPbkContactViewBase& aBaseView,
|
|
112 |
MVPbkContactViewObserver& aObserver,
|
|
113 |
MVPbkContactSelector& aContactSelector)
|
|
114 |
{
|
|
115 |
CVPbkFilteredContactView* self = new(ELeave) CVPbkFilteredContactView
|
|
116 |
(aBaseView, aContactSelector, NULL );
|
|
117 |
CleanupStack::PushL(self);
|
|
118 |
self->ConstructL( aObserver );
|
|
119 |
CleanupStack::Pop(self);
|
|
120 |
return self;
|
|
121 |
}
|
|
122 |
|
|
123 |
// ---------------------------------------------------------------------------
|
|
124 |
// CVPbkFilteredContactView::NewL
|
|
125 |
// ---------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
EXPORT_C CVPbkFilteredContactView* CVPbkFilteredContactView::NewL(
|
|
128 |
MVPbkContactViewBase& aBaseView,
|
|
129 |
MVPbkContactViewObserver& aObserver,
|
|
130 |
MVPbkContactSelector& aContactSelector,
|
|
131 |
const MVPbkFieldTypeList& aMasterFieldTypeList )
|
|
132 |
{
|
|
133 |
CVPbkFilteredContactView* self = new(ELeave) CVPbkFilteredContactView
|
|
134 |
(aBaseView, aContactSelector, &aMasterFieldTypeList );
|
|
135 |
CleanupStack::PushL(self);
|
|
136 |
self->ConstructL( aObserver );
|
|
137 |
CleanupStack::Pop(self);
|
|
138 |
return self;
|
|
139 |
}
|
|
140 |
|
|
141 |
// ---------------------------------------------------------------------------
|
|
142 |
// CVPbkFilteredContactView::~CVPbkFilteredContactView
|
|
143 |
// ---------------------------------------------------------------------------
|
|
144 |
//
|
|
145 |
CVPbkFilteredContactView::~CVPbkFilteredContactView()
|
|
146 |
{
|
|
147 |
iObservers.Close();
|
|
148 |
iContactMapping.Reset();
|
|
149 |
delete iAsyncOperation;
|
|
150 |
iBaseView.RemoveObserver(*this);
|
|
151 |
}
|
|
152 |
|
|
153 |
// ---------------------------------------------------------------------------
|
|
154 |
// CVPbkFilteredContactView::Type
|
|
155 |
// ---------------------------------------------------------------------------
|
|
156 |
//
|
|
157 |
TVPbkContactViewType CVPbkFilteredContactView::Type() const
|
|
158 |
{
|
|
159 |
return iBaseView.Type();
|
|
160 |
}
|
|
161 |
|
|
162 |
// ---------------------------------------------------------------------------
|
|
163 |
// CVPbkFilteredContactView::ChangeSortOrderL
|
|
164 |
// ---------------------------------------------------------------------------
|
|
165 |
//
|
|
166 |
void CVPbkFilteredContactView::ChangeSortOrderL(
|
|
167 |
const MVPbkFieldTypeList& aSortOrder )
|
|
168 |
{
|
|
169 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
170 |
("CVPbkFilteredContactView::ChangeSortOrderL(0x%x)"), &aSortOrder);
|
|
171 |
|
|
172 |
iBaseView.ChangeSortOrderL(aSortOrder);
|
|
173 |
}
|
|
174 |
|
|
175 |
// ---------------------------------------------------------------------------
|
|
176 |
// CVPbkFilteredContactView::SortOrder
|
|
177 |
// ---------------------------------------------------------------------------
|
|
178 |
//
|
|
179 |
const MVPbkFieldTypeList& CVPbkFilteredContactView::SortOrder() const
|
|
180 |
{
|
|
181 |
return iBaseView.SortOrder();
|
|
182 |
}
|
|
183 |
|
|
184 |
// ---------------------------------------------------------------------------
|
|
185 |
// CVPbkFilteredContactView::RefreshL
|
|
186 |
// ---------------------------------------------------------------------------
|
|
187 |
//
|
|
188 |
void CVPbkFilteredContactView::RefreshL()
|
|
189 |
{
|
|
190 |
iBaseView.RefreshL();
|
|
191 |
}
|
|
192 |
|
|
193 |
// ---------------------------------------------------------------------------
|
|
194 |
// CVPbkFilteredContactView::ContactCountL
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
//
|
|
197 |
TInt CVPbkFilteredContactView::ContactCountL() const
|
|
198 |
{
|
|
199 |
return iContactMapping.Count();
|
|
200 |
}
|
|
201 |
|
|
202 |
// ---------------------------------------------------------------------------
|
|
203 |
// CVPbkFilteredContactView::ContactAtL
|
|
204 |
// ---------------------------------------------------------------------------
|
|
205 |
//
|
|
206 |
const MVPbkViewContact& CVPbkFilteredContactView::ContactAtL(
|
|
207 |
TInt aIndex ) const
|
|
208 |
{
|
|
209 |
__ASSERT_ALWAYS( aIndex >= 0,
|
|
210 |
VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
|
|
211 |
if ( aIndex >= iContactMapping.Count() )
|
|
212 |
{
|
|
213 |
User::Leave( KErrArgument );
|
|
214 |
}
|
|
215 |
|
|
216 |
return iBaseView.ContactAtL(iContactMapping[aIndex]);
|
|
217 |
}
|
|
218 |
|
|
219 |
// ---------------------------------------------------------------------------
|
|
220 |
// CVPbkFilteredContactView::CreateLinkLC
|
|
221 |
// ---------------------------------------------------------------------------
|
|
222 |
//
|
|
223 |
MVPbkContactLink* CVPbkFilteredContactView::CreateLinkLC( TInt aIndex ) const
|
|
224 |
{
|
|
225 |
__ASSERT_ALWAYS( aIndex >= 0,
|
|
226 |
VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
|
|
227 |
if ( aIndex >= iContactMapping.Count() )
|
|
228 |
{
|
|
229 |
User::Leave( KErrArgument );
|
|
230 |
}
|
|
231 |
|
|
232 |
return iBaseView.ContactAtL(iContactMapping[aIndex]).CreateLinkLC();
|
|
233 |
}
|
|
234 |
|
|
235 |
// ---------------------------------------------------------------------------
|
|
236 |
// CVPbkFilteredContactView::IndexOfLinkL
|
|
237 |
// ---------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
TInt CVPbkFilteredContactView::IndexOfLinkL(
|
|
240 |
const MVPbkContactLink& aContactLink ) const
|
|
241 |
{
|
|
242 |
TInt baseIndex = iBaseView.IndexOfLinkL(aContactLink);
|
|
243 |
return iContactMapping.Find(baseIndex);
|
|
244 |
}
|
|
245 |
|
|
246 |
// ---------------------------------------------------------------------------
|
|
247 |
// CVPbkFilteredContactView::AddObserverL
|
|
248 |
// ---------------------------------------------------------------------------
|
|
249 |
//
|
|
250 |
void CVPbkFilteredContactView::AddObserverL(
|
|
251 |
MVPbkContactViewObserver& aObserver )
|
|
252 |
{
|
|
253 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
254 |
("CVPbkFilteredContactView::AddObserverL(0x%x)"), &aObserver);
|
|
255 |
|
|
256 |
TInt err( iObservers.InsertInAddressOrder( &aObserver ) );
|
|
257 |
if ( err != KErrNone && err != KErrAlreadyExists )
|
|
258 |
{
|
|
259 |
User::Leave( err );
|
|
260 |
}
|
|
261 |
|
|
262 |
VPbkEngUtils::MAsyncCallback* notifyObserver =
|
|
263 |
VPbkEngUtils::CreateAsyncCallbackLC(*this,
|
|
264 |
&CVPbkFilteredContactView::DoAddObserverL,
|
|
265 |
&CVPbkFilteredContactView::AddObserverError,
|
|
266 |
aObserver);
|
|
267 |
iAsyncOperation->CallbackL(notifyObserver);
|
|
268 |
CleanupStack::Pop(notifyObserver);
|
|
269 |
|
|
270 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
271 |
("CVPbkFilteredContactView::AddObserverL(0x%x) end"), &aObserver);
|
|
272 |
}
|
|
273 |
|
|
274 |
// ---------------------------------------------------------------------------
|
|
275 |
// CVPbkFilteredContactView::DoAddObserverL
|
|
276 |
// ---------------------------------------------------------------------------
|
|
277 |
//
|
|
278 |
void CVPbkFilteredContactView::DoAddObserverL(
|
|
279 |
MVPbkContactViewObserver& aObserver )
|
|
280 |
{
|
|
281 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
282 |
("CVPbkFilteredContactView::DoAddObserverL(0x%x)"), &aObserver);
|
|
283 |
|
|
284 |
// Check if aObserver is still observer of this view
|
|
285 |
if ( iObservers.FindInAddressOrder( &aObserver ) != KErrNotFound )
|
|
286 |
{
|
|
287 |
if (iIsReady)
|
|
288 |
{
|
|
289 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
290 |
("CVPbkFilteredContactView::DoAddObserverL(0x%x) contact view ready"),
|
|
291 |
&aObserver);
|
|
292 |
|
|
293 |
// If this view is ready and there was no error,
|
|
294 |
// tell it to the observer
|
|
295 |
aObserver.ContactViewReady(*this);
|
|
296 |
}
|
|
297 |
}
|
|
298 |
// If this view was not ready and there was no error,
|
|
299 |
// observer will be called back in ContactViewReady
|
|
300 |
|
|
301 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
302 |
("CVPbkFilteredContactView::DoAddObserverL(0x%x) end"), &aObserver);
|
|
303 |
}
|
|
304 |
|
|
305 |
// ---------------------------------------------------------------------------
|
|
306 |
// CVPbkFilteredContactView::AddObserverError
|
|
307 |
// ---------------------------------------------------------------------------
|
|
308 |
//
|
|
309 |
void CVPbkFilteredContactView::AddObserverError(
|
|
310 |
MVPbkContactViewObserver& aObserver, TInt aError )
|
|
311 |
{
|
|
312 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
313 |
("CVPbkFilteredContactView::AddObserverError(0x%x, %d)"), &aObserver, aError);
|
|
314 |
|
|
315 |
aObserver.ContactViewError(*this, aError, EFalse);
|
|
316 |
}
|
|
317 |
|
|
318 |
// ---------------------------------------------------------------------------
|
|
319 |
// CVPbkFilteredContactView::RemoveObserver
|
|
320 |
// ---------------------------------------------------------------------------
|
|
321 |
//
|
|
322 |
void CVPbkFilteredContactView::RemoveObserver(
|
|
323 |
MVPbkContactViewObserver& aObserver )
|
|
324 |
{
|
|
325 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
326 |
("CVPbkFilteredContactView::RemoveObserverError(0x%x)"), &aObserver);
|
|
327 |
|
|
328 |
const TInt index = iObservers.FindInAddressOrder( &aObserver );
|
|
329 |
if (index != KErrNotFound)
|
|
330 |
{
|
|
331 |
iObservers.Remove(index);
|
|
332 |
}
|
|
333 |
}
|
|
334 |
|
|
335 |
// ---------------------------------------------------------------------------
|
|
336 |
// CVPbkFilteredContactView::MatchContactStore
|
|
337 |
// ---------------------------------------------------------------------------
|
|
338 |
//
|
|
339 |
TBool CVPbkFilteredContactView::MatchContactStore(
|
|
340 |
const TDesC& aContactStoreUri ) const
|
|
341 |
{
|
|
342 |
return iBaseView.MatchContactStore(aContactStoreUri);
|
|
343 |
}
|
|
344 |
|
|
345 |
// ---------------------------------------------------------------------------
|
|
346 |
// CVPbkFilteredContactView::MatchContactStoreDomain
|
|
347 |
// ---------------------------------------------------------------------------
|
|
348 |
//
|
|
349 |
TBool CVPbkFilteredContactView::MatchContactStoreDomain(
|
|
350 |
const TDesC& aContactStoreDomain ) const
|
|
351 |
{
|
|
352 |
return iBaseView.MatchContactStoreDomain(aContactStoreDomain);
|
|
353 |
}
|
|
354 |
|
|
355 |
// ---------------------------------------------------------------------------
|
|
356 |
// CVPbkFilteredContactView::CreateBookmarkLC
|
|
357 |
// ---------------------------------------------------------------------------
|
|
358 |
//
|
|
359 |
MVPbkContactBookmark* CVPbkFilteredContactView::CreateBookmarkLC(
|
|
360 |
TInt aIndex ) const
|
|
361 |
{
|
|
362 |
__ASSERT_ALWAYS( aIndex >= 0,
|
|
363 |
VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
|
|
364 |
|
|
365 |
return iBaseView.ContactAtL(iContactMapping[aIndex]).CreateBookmarkLC();
|
|
366 |
}
|
|
367 |
|
|
368 |
// ---------------------------------------------------------------------------
|
|
369 |
// CVPbkFilteredContactView::IndexOfBookmarkL
|
|
370 |
// ---------------------------------------------------------------------------
|
|
371 |
//
|
|
372 |
TInt CVPbkFilteredContactView::IndexOfBookmarkL(
|
|
373 |
const MVPbkContactBookmark& aContactBookmark ) const
|
|
374 |
{
|
|
375 |
TInt baseIndex = iBaseView.IndexOfBookmarkL(aContactBookmark);
|
|
376 |
return iContactMapping.Find(baseIndex);
|
|
377 |
}
|
|
378 |
|
|
379 |
// ---------------------------------------------------------------------------
|
|
380 |
// CVPbkFilteredContactView::ViewFiltering
|
|
381 |
// ---------------------------------------------------------------------------
|
|
382 |
//
|
|
383 |
MVPbkContactViewFiltering* CVPbkFilteredContactView::ViewFiltering()
|
|
384 |
{
|
|
385 |
if ( iMasterFieldTypeList )
|
|
386 |
{
|
|
387 |
return this;
|
|
388 |
}
|
|
389 |
return NULL;
|
|
390 |
}
|
|
391 |
|
|
392 |
// ---------------------------------------------------------------------------
|
|
393 |
// CVPbkFilteredContactView::CreateFilteredViewLC
|
|
394 |
// ---------------------------------------------------------------------------
|
|
395 |
//
|
|
396 |
MVPbkContactViewBase* CVPbkFilteredContactView::CreateFilteredViewLC(
|
|
397 |
MVPbkContactViewObserver& aObserver,
|
|
398 |
const MDesCArray& aFindWords,
|
|
399 |
const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
|
|
400 |
{
|
|
401 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
402 |
("CVPbkFilteredContactView::CreateFilteredViewLC(0x%x)"), this);
|
|
403 |
|
|
404 |
if ( iMasterFieldTypeList )
|
|
405 |
{
|
|
406 |
return CVPbkFindView::NewLC( *this,
|
|
407 |
aObserver,
|
|
408 |
aFindWords,
|
|
409 |
aAlwaysIncludedContacts,
|
|
410 |
*iMasterFieldTypeList );
|
|
411 |
}
|
|
412 |
return NULL;
|
|
413 |
}
|
|
414 |
|
|
415 |
// ---------------------------------------------------------------------------
|
|
416 |
// CVPbkFilteredContactView::UpdateFilterL
|
|
417 |
// ---------------------------------------------------------------------------
|
|
418 |
//
|
|
419 |
void CVPbkFilteredContactView::UpdateFilterL(
|
|
420 |
const MDesCArray& /*aFindWords*/,
|
|
421 |
const MVPbkContactBookmarkCollection* /*aAlwaysIncludedContacts*/ )
|
|
422 |
{
|
|
423 |
User::Leave( KErrNotSupported );
|
|
424 |
}
|
|
425 |
|
|
426 |
// ---------------------------------------------------------------------------
|
|
427 |
// CVPbkFilteredContactView::BuildViewMappingL
|
|
428 |
// ---------------------------------------------------------------------------
|
|
429 |
//
|
|
430 |
void CVPbkFilteredContactView::BuildViewMappingL()
|
|
431 |
{
|
|
432 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
433 |
("CVPbkFilteredContactView::BuildViewMappingL(0x%x)"), this);
|
|
434 |
|
|
435 |
iContactMapping.Reset();
|
|
436 |
|
|
437 |
MVPbkOptimizedSelector* optimizedSelector =
|
|
438 |
static_cast<MVPbkOptimizedSelector*>(
|
|
439 |
iContactSelector.ContactSelectorExtension(
|
|
440 |
KVPbkOptimizedSelectorExtensionUid ) );
|
|
441 |
|
|
442 |
const TInt count = iBaseView.ContactCountL();
|
|
443 |
for (TInt i = 0; i < count; ++i)
|
|
444 |
{
|
|
445 |
if (iContactSelector.IsContactIncluded(iBaseView.ContactAtL(i)))
|
|
446 |
{
|
|
447 |
iContactMapping.AppendL(i);
|
|
448 |
}
|
|
449 |
|
|
450 |
if( optimizedSelector && !optimizedSelector->Continue() )
|
|
451 |
{
|
|
452 |
// we doesn't need use selector anymore -> include rest of contacts
|
|
453 |
for (TInt j = i+1; j < count; ++j )
|
|
454 |
{
|
|
455 |
iContactMapping.AppendL(j);
|
|
456 |
}
|
|
457 |
break;
|
|
458 |
}
|
|
459 |
|
|
460 |
}
|
|
461 |
|
|
462 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
463 |
("CVPbkFilteredContactView::BuildViewMappingL(0x%x) end"), this);
|
|
464 |
}
|
|
465 |
|
|
466 |
// ---------------------------------------------------------------------------
|
|
467 |
// CVPbkFilteredContactView::HandleBuildViewMapping
|
|
468 |
// ---------------------------------------------------------------------------
|
|
469 |
//
|
|
470 |
void CVPbkFilteredContactView::HandleBuildViewMapping()
|
|
471 |
{
|
|
472 |
TRAPD( res, BuildViewMappingL() );
|
|
473 |
if ( res == KErrNone )
|
|
474 |
{
|
|
475 |
// Mapping was succesfully built. Send ready event
|
|
476 |
SendEventToObservers( *this, iObservers,
|
|
477 |
&MVPbkContactViewObserver::ContactViewReady );
|
|
478 |
}
|
|
479 |
else
|
|
480 |
{
|
|
481 |
// Building the mapping failed. Leave mappings as they are and
|
|
482 |
// send error
|
|
483 |
SendEventToObservers( *this, iObservers,
|
|
484 |
&MVPbkContactViewObserver::ContactViewError, res, EFalse );
|
|
485 |
}
|
|
486 |
}
|
|
487 |
|
|
488 |
// ---------------------------------------------------------------------------
|
|
489 |
// From class MVPbkContactViewBase.
|
|
490 |
// CVPbkFilteredContactView::ContactViewReady
|
|
491 |
// ---------------------------------------------------------------------------
|
|
492 |
//
|
|
493 |
void CVPbkFilteredContactView::ContactViewReady( MVPbkContactViewBase& aView )
|
|
494 |
{
|
|
495 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
496 |
("CVPbkFilteredContactView::ContactViewReady(0x%x)"), &aView);
|
|
497 |
|
|
498 |
iIsReady = ETrue;
|
|
499 |
HandleBuildViewMapping();
|
|
500 |
|
|
501 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
502 |
("CVPbkFilteredContactView::ContactViewReady(0x%x) end"), &aView);
|
|
503 |
}
|
|
504 |
|
|
505 |
// ---------------------------------------------------------------------------
|
|
506 |
// From class MVPbkContactViewBase.
|
|
507 |
// CVPbkFilteredContactView::ContactViewUnavailable
|
|
508 |
// ---------------------------------------------------------------------------
|
|
509 |
//
|
|
510 |
void CVPbkFilteredContactView::ContactViewUnavailable(
|
|
511 |
MVPbkContactViewBase& aView )
|
|
512 |
{
|
|
513 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
514 |
("CVPbkFilteredContactView::ContactViewUnavailable(0x%x)"), &aView);
|
|
515 |
|
|
516 |
iIsReady = EFalse;
|
|
517 |
SendEventToObservers
|
|
518 |
(*this, iObservers, &MVPbkContactViewObserver::ContactViewUnavailable);
|
|
519 |
|
|
520 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
521 |
("CVPbkFilteredContactView::ContactViewUnavailable(0x%x)"), &aView);
|
|
522 |
}
|
|
523 |
|
|
524 |
// ---------------------------------------------------------------------------
|
|
525 |
// From class MVPbkContactViewBase.
|
|
526 |
// CVPbkFilteredContactView::ContactViewError
|
|
527 |
// ---------------------------------------------------------------------------
|
|
528 |
//
|
|
529 |
void CVPbkFilteredContactView::ContactViewError( MVPbkContactViewBase& aView,
|
|
530 |
TInt aError, TBool aErrorNotified )
|
|
531 |
{
|
|
532 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
533 |
("CVPbkFilteredContactView::ContactViewError(0x%x)"), &aView);
|
|
534 |
|
|
535 |
iIsReady = EFalse;
|
|
536 |
SendEventToObservers(*this, iObservers,
|
|
537 |
&MVPbkContactViewObserver::ContactViewError, aError, aErrorNotified);
|
|
538 |
|
|
539 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
540 |
("CVPbkFilteredContactView::ContactViewError(0x%x)"), &aView);
|
|
541 |
}
|
|
542 |
|
|
543 |
// ---------------------------------------------------------------------------
|
|
544 |
// From class MVPbkContactViewBase.
|
|
545 |
// CVPbkFilteredContactView::ContactAddedToView
|
|
546 |
// ---------------------------------------------------------------------------
|
|
547 |
//
|
|
548 |
void CVPbkFilteredContactView::ContactAddedToView
|
|
549 |
(MVPbkContactViewBase& /*aView*/, TInt aIndex,
|
|
550 |
const MVPbkContactLink& aContactLink)
|
|
551 |
{
|
|
552 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
553 |
("CVPbkFilteredContactView::ContactAddedToView(0x%x %d)"), this, aIndex);
|
|
554 |
|
|
555 |
TInt filteredIndex(0);
|
|
556 |
TRAPD( res, filteredIndex = UpdateViewMappingAfterAddingL( aIndex ) );
|
|
557 |
if ( res == KErrNone )
|
|
558 |
{
|
|
559 |
if ( filteredIndex != KErrNotFound )
|
|
560 |
{
|
|
561 |
// Mapping was succesfully updated and the new contact
|
|
562 |
// belongs to the filtered view.
|
|
563 |
SendEventToObservers( *this, iObservers,
|
|
564 |
&MVPbkContactViewObserver::ContactAddedToView, filteredIndex,
|
|
565 |
aContactLink );
|
|
566 |
}
|
|
567 |
}
|
|
568 |
else
|
|
569 |
{
|
|
570 |
SendEventToObservers( *this, iObservers,
|
|
571 |
&MVPbkContactViewObserver::ContactViewError, res, EFalse );
|
|
572 |
}
|
|
573 |
|
|
574 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
575 |
("CVPbkFilteredContactView::ContactAddedToView(0x%x)"), this);
|
|
576 |
}
|
|
577 |
|
|
578 |
// ---------------------------------------------------------------------------
|
|
579 |
// From class MVPbkContactViewBase.
|
|
580 |
// CVPbkFilteredContactView::ContactRemovedFromView
|
|
581 |
// ---------------------------------------------------------------------------
|
|
582 |
//
|
|
583 |
void CVPbkFilteredContactView::ContactRemovedFromView(
|
|
584 |
MVPbkContactViewBase& /*aView*/, TInt aIndex,
|
|
585 |
const MVPbkContactLink& aContactLink)
|
|
586 |
{
|
|
587 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
588 |
("CVPbkFilteredContactView::ContactRemovedFromView(0x%x %d)"), this, aIndex);
|
|
589 |
|
|
590 |
const TInt filteredIndex = UpdateViewMappingAfterDeleting( aIndex );
|
|
591 |
if ( filteredIndex != KErrNotFound )
|
|
592 |
{
|
|
593 |
// Mapping was succesfully updated and the contact removed from the mapping
|
|
594 |
SendEventToObservers( *this, iObservers,
|
|
595 |
&MVPbkContactViewObserver::ContactRemovedFromView, filteredIndex,
|
|
596 |
aContactLink );
|
|
597 |
}
|
|
598 |
else
|
|
599 |
{
|
|
600 |
const TInt count = iObservers.Count();
|
|
601 |
|
|
602 |
for( TInt i = 0; i < count; i++ )
|
|
603 |
{
|
|
604 |
MVPbkContactViewObserver* observer = iObservers[i];
|
|
605 |
|
|
606 |
TAny* extension = observer->ContactViewObserverExtension(
|
|
607 |
KVPbkContactViewObserverExtension2Uid );
|
|
608 |
|
|
609 |
if( extension )
|
|
610 |
{
|
|
611 |
MVPbkContactViewObserverExtension* contactViewExtension =
|
|
612 |
static_cast<MVPbkContactViewObserverExtension*>( extension );
|
|
613 |
|
|
614 |
if( contactViewExtension )
|
|
615 |
{
|
|
616 |
contactViewExtension->FilteredContactRemovedFromView( *this );
|
|
617 |
}
|
|
618 |
}
|
|
619 |
}
|
|
620 |
}
|
|
621 |
|
|
622 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING
|
|
623 |
("CVPbkFilteredContactView::ContactRemovedFromView(0x%x)"), this);
|
|
624 |
}
|
|
625 |
|
|
626 |
// ---------------------------------------------------------------------------
|
|
627 |
// CVPbkFilteredContactView::UpdateViewMappingAfterAdding
|
|
628 |
//
|
|
629 |
// Update the mapping when a new contact is added to the base view
|
|
630 |
// Returns its mapped index if it is added to the mapping
|
|
631 |
// or KErrNotFound if it's filtered out
|
|
632 |
// ---------------------------------------------------------------------------
|
|
633 |
//
|
|
634 |
TInt CVPbkFilteredContactView::UpdateViewMappingAfterAddingL( TInt aBaseIndex )
|
|
635 |
{
|
|
636 |
// protect against ghost contacts. Can happen if last of the contacts is
|
|
637 |
// deleted or changed into own card immediately after creation.
|
|
638 |
if ( iBaseView.ContactCountL() <= aBaseIndex )
|
|
639 |
{
|
|
640 |
return KErrNotFound;
|
|
641 |
}
|
|
642 |
|
|
643 |
// first update the mapping for all elements which > aBaseIndex
|
|
644 |
TInt filteredIndex;
|
|
645 |
// find first elemnt which >= aBaseIndex
|
|
646 |
// NOTE: if iContactMapping contains aBaseIndex element,
|
|
647 |
// it refers to a view contact which is already at aBaseIndex+1
|
|
648 |
TInt err = iContactMapping.FindInOrder( aBaseIndex, filteredIndex );
|
|
649 |
for ( TInt i = filteredIndex; i < iContactMapping.Count(); ++i )
|
|
650 |
{
|
|
651 |
++iContactMapping[i];
|
|
652 |
}
|
|
653 |
|
|
654 |
// addd a new contact to the mapping
|
|
655 |
if ( iContactSelector.IsContactIncluded( iBaseView.ContactAtL (aBaseIndex) ) )
|
|
656 |
{
|
|
657 |
User::LeaveIfError( iContactMapping.Insert( aBaseIndex, filteredIndex ) );
|
|
658 |
}
|
|
659 |
else
|
|
660 |
{
|
|
661 |
filteredIndex = KErrNotFound;
|
|
662 |
}
|
|
663 |
|
|
664 |
return filteredIndex;
|
|
665 |
}
|
|
666 |
|
|
667 |
// ---------------------------------------------------------------------------
|
|
668 |
// CVPbkFilteredContactView::UpdateViewMappingAfterDeleting
|
|
669 |
//
|
|
670 |
// Update the mapping when a new contact is deleted from the base view
|
|
671 |
// Returns its mapped index if it was removed from the mapping
|
|
672 |
// or KErrNotFound otherwise
|
|
673 |
// ---------------------------------------------------------------------------
|
|
674 |
//
|
|
675 |
TInt CVPbkFilteredContactView::UpdateViewMappingAfterDeleting( TInt aBaseIndex )
|
|
676 |
{
|
|
677 |
// if the contact is in mappings, filteredIndex contains its index
|
|
678 |
// otherwise, the index of the next element greater than aIndex
|
|
679 |
TInt filteredIndex;
|
|
680 |
const TInt err = iContactMapping.FindInOrder( aBaseIndex, filteredIndex );
|
|
681 |
|
|
682 |
// mapping should be updated in any case even if deleted contact
|
|
683 |
// is not in the mapping
|
|
684 |
// because all items in the mappings which > aIndex should be updated
|
|
685 |
for ( TInt i = filteredIndex; i < iContactMapping.Count(); ++i )
|
|
686 |
{
|
|
687 |
// Subtract one because one contact was deleted
|
|
688 |
// from the list before the current index
|
|
689 |
--iContactMapping[i];
|
|
690 |
}
|
|
691 |
|
|
692 |
if ( err == KErrNone )
|
|
693 |
{
|
|
694 |
iContactMapping.Remove( filteredIndex );
|
|
695 |
}
|
|
696 |
else
|
|
697 |
{
|
|
698 |
filteredIndex = KErrNotFound;
|
|
699 |
}
|
|
700 |
|
|
701 |
return filteredIndex;
|
|
702 |
}
|
|
703 |
|
|
704 |
// End of File
|