62 |
62 |
63 // iBuffer max size is EMaxListBoxText = 256 |
63 // iBuffer max size is EMaxListBoxText = 256 |
64 // -> max length for name data is 100 and max lenght for status data is 100 |
64 // -> max length for name data is 100 and max lenght for status data is 100 |
65 // rest 56 are reserved for icon data |
65 // rest 56 are reserved for icon data |
66 const TInt KMaxTxtLength = 100; |
66 const TInt KMaxTxtLength = 100; |
67 |
|
68 const TInt KDataElementCacheSize = 20; |
|
69 } |
67 } |
70 |
|
71 /** |
|
72 * Cache for data elements, cache is made to avoid performance problems that |
|
73 * caused in cases when avkon implementation calls multiple times MdcaPoint function with same index |
|
74 * Cached items must be deleted when there is any change in contact list. |
|
75 */ |
|
76 NONSHARABLE_CLASS( CDataElementCache ) : |
|
77 public CBase, |
|
78 public MVPbkContactViewObserver, |
|
79 public MPbk2FilteredViewStackObserver |
|
80 { |
|
81 public: |
|
82 static CDataElementCache* NewL(MPbk2FilteredViewStack& aView); |
|
83 ~CDataElementCache(); |
|
84 |
|
85 void AppendL( CPbk2ContactViewDoubleListboxDataElement* aDataElement ); |
|
86 CPbk2ContactViewDoubleListboxDataElement* Element( TInt aListIndex ); |
|
87 |
|
88 private: // From MVPbkContactViewObserver |
|
89 void ContactViewReady( |
|
90 MVPbkContactViewBase& aView ); |
|
91 void ContactViewUnavailable( |
|
92 MVPbkContactViewBase& aView ); |
|
93 void ContactAddedToView( |
|
94 MVPbkContactViewBase& aView, |
|
95 TInt aIndex, |
|
96 const MVPbkContactLink& aContactLink ); |
|
97 void ContactRemovedFromView( |
|
98 MVPbkContactViewBase& aView, |
|
99 TInt aIndex, |
|
100 const MVPbkContactLink& aContactLink ); |
|
101 void ContactViewError( |
|
102 MVPbkContactViewBase& aView, |
|
103 TInt aError, |
|
104 TBool aErrorNotified ); |
|
105 |
|
106 private: // From MPbk2FilteredViewStackObserver |
|
107 void TopViewChangedL( |
|
108 MVPbkContactViewBase& aOldView ); |
|
109 void TopViewUpdatedL(); |
|
110 void BaseViewChangedL(); |
|
111 void ViewStackError( |
|
112 TInt aError ); |
|
113 void ContactAddedToBaseView( |
|
114 MVPbkContactViewBase& aBaseView, |
|
115 TInt aIndex, |
|
116 const MVPbkContactLink& aContactLink ); |
|
117 |
|
118 private: |
|
119 inline CDataElementCache( MPbk2FilteredViewStack& aView ); |
|
120 inline void ConstructL(); |
|
121 inline void Reset(); |
|
122 |
|
123 private: |
|
124 RPointerArray<CPbk2ContactViewDoubleListboxDataElement> iCache; |
|
125 MPbk2FilteredViewStack& iView; |
|
126 }; |
|
127 |
|
128 // -------------------------------------------------------------------------- |
|
129 // CDataElementCache::NewL |
|
130 // -------------------------------------------------------------------------- |
|
131 // |
|
132 CDataElementCache* CDataElementCache::NewL( MPbk2FilteredViewStack& aView ) |
|
133 { |
|
134 CDataElementCache* self = new (ELeave) CDataElementCache(aView); |
|
135 CleanupStack::PushL( self ); |
|
136 self->ConstructL(); |
|
137 CleanupStack::Pop( self ); |
|
138 return self; |
|
139 } |
|
140 |
|
141 // -------------------------------------------------------------------------- |
|
142 // CDataElementCache::CDataElementCache |
|
143 // -------------------------------------------------------------------------- |
|
144 // |
|
145 inline CDataElementCache::CDataElementCache( MPbk2FilteredViewStack& aView ) |
|
146 : iCache( KDataElementCacheSize ), |
|
147 iView( aView ) |
|
148 { |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------- |
|
152 // CDataElementCache::ConstructL |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 inline void CDataElementCache::ConstructL() |
|
156 { |
|
157 iView.AddObserverL(*this); |
|
158 iView.AddStackObserverL(*this); |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // CDataElementCache::~CDataElementCache |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 CDataElementCache::~CDataElementCache() |
|
166 { |
|
167 Reset(); |
|
168 iView.RemoveObserver(*this); |
|
169 iView.RemoveStackObserver(*this); |
|
170 } |
|
171 |
|
172 // -------------------------------------------------------------------------- |
|
173 // CDataElementCache::AppendL |
|
174 // -------------------------------------------------------------------------- |
|
175 // |
|
176 void CDataElementCache::AppendL( |
|
177 CPbk2ContactViewDoubleListboxDataElement* aDataElement ) |
|
178 { |
|
179 iCache.InsertL( aDataElement, 0 ); |
|
180 const TInt cacheItemCount( iCache.Count() ); |
|
181 if( cacheItemCount > KDataElementCacheSize ) |
|
182 { |
|
183 delete iCache[cacheItemCount - 1]; |
|
184 iCache.Remove(cacheItemCount - 1); |
|
185 } |
|
186 } |
|
187 |
|
188 // -------------------------------------------------------------------------- |
|
189 // CDataElementCache::Reset |
|
190 // -------------------------------------------------------------------------- |
|
191 // |
|
192 inline void CDataElementCache::Reset() |
|
193 { |
|
194 iCache.ResetAndDestroy(); |
|
195 } |
|
196 |
|
197 // -------------------------------------------------------------------------- |
|
198 // CDataElementCache::Element |
|
199 // -------------------------------------------------------------------------- |
|
200 // |
|
201 CPbk2ContactViewDoubleListboxDataElement* |
|
202 CDataElementCache::Element( TInt aListIndex ) |
|
203 { |
|
204 const TInt cacheItemCount( iCache.Count() ); |
|
205 for( TInt i = 0 ; i < cacheItemCount ; ++i ) |
|
206 { |
|
207 CPbk2ContactViewDoubleListboxDataElement* p = iCache[i]; |
|
208 if( p->ListIndex() == aListIndex ) |
|
209 { |
|
210 return p; |
|
211 } |
|
212 } |
|
213 return NULL; |
|
214 } |
|
215 |
|
216 // -------------------------------------------------------------------------- |
|
217 // CDataElementCache::ContactViewReady |
|
218 // -------------------------------------------------------------------------- |
|
219 // |
|
220 void CDataElementCache::ContactViewReady( |
|
221 MVPbkContactViewBase& /*aView*/ ) |
|
222 { |
|
223 Reset(); |
|
224 } |
|
225 |
|
226 // -------------------------------------------------------------------------- |
|
227 // CDataElementCache::ContactViewUnavailable |
|
228 // -------------------------------------------------------------------------- |
|
229 // |
|
230 void CDataElementCache::ContactViewUnavailable( |
|
231 MVPbkContactViewBase& /*aView*/ ) |
|
232 { |
|
233 Reset(); |
|
234 } |
|
235 |
|
236 // -------------------------------------------------------------------------- |
|
237 // CDataElementCache::ContactAddedToView |
|
238 // -------------------------------------------------------------------------- |
|
239 // |
|
240 void CDataElementCache::ContactAddedToView( |
|
241 MVPbkContactViewBase& /*aView*/, |
|
242 TInt /*aIndex*/, |
|
243 const MVPbkContactLink& /*aContactLink*/ ) |
|
244 { |
|
245 Reset(); |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CDataElementCache::ContactRemovedFromView |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 void CDataElementCache::ContactRemovedFromView( |
|
253 MVPbkContactViewBase& /*aView*/, |
|
254 TInt /*aIndex*/, |
|
255 const MVPbkContactLink& /*aContactLink*/ ) |
|
256 { |
|
257 Reset(); |
|
258 } |
|
259 |
|
260 // -------------------------------------------------------------------------- |
|
261 // CDataElementCache::ContactViewError |
|
262 // -------------------------------------------------------------------------- |
|
263 // |
|
264 void CDataElementCache::ContactViewError( |
|
265 MVPbkContactViewBase& /*aView*/, |
|
266 TInt /*aError*/, |
|
267 TBool /*aErrorNotified*/ ) |
|
268 { |
|
269 Reset(); |
|
270 } |
|
271 |
|
272 // -------------------------------------------------------------------------- |
|
273 // CDataElementCache::TopViewChangedL |
|
274 // -------------------------------------------------------------------------- |
|
275 // |
|
276 void CDataElementCache::TopViewChangedL( |
|
277 MVPbkContactViewBase& /*aOldView*/ ) |
|
278 { |
|
279 Reset(); |
|
280 } |
|
281 |
|
282 // -------------------------------------------------------------------------- |
|
283 // CDataElementCache::TopViewUpdatedL |
|
284 // -------------------------------------------------------------------------- |
|
285 // |
|
286 void CDataElementCache::TopViewUpdatedL() |
|
287 { |
|
288 Reset(); |
|
289 } |
|
290 |
|
291 // -------------------------------------------------------------------------- |
|
292 // CDataElementCache::BaseViewChangedL |
|
293 // -------------------------------------------------------------------------- |
|
294 // |
|
295 void CDataElementCache::BaseViewChangedL() |
|
296 { |
|
297 Reset(); |
|
298 } |
|
299 |
|
300 // -------------------------------------------------------------------------- |
|
301 // CDataElementCache::ViewStackError |
|
302 // -------------------------------------------------------------------------- |
|
303 // |
|
304 void CDataElementCache::ViewStackError( |
|
305 TInt /*aError*/ ) |
|
306 { |
|
307 Reset(); |
|
308 } |
|
309 |
|
310 // -------------------------------------------------------------------------- |
|
311 // CDataElementCache::ContactAddedToBaseView |
|
312 // -------------------------------------------------------------------------- |
|
313 // |
|
314 void CDataElementCache::ContactAddedToBaseView( |
|
315 MVPbkContactViewBase& /*aBaseView*/, |
|
316 TInt /*aIndex*/, |
|
317 const MVPbkContactLink& /*aContactLink*/ ) |
|
318 { |
|
319 Reset(); |
|
320 } |
|
321 |
|
322 |
68 |
323 // -------------------------------------------------------------------------- |
69 // -------------------------------------------------------------------------- |
324 // CPbk2ContactViewDoubleListBoxModel::CPbk2ContactViewDoubleListBoxModel |
70 // CPbk2ContactViewDoubleListBoxModel::CPbk2ContactViewDoubleListBoxModel |
325 // -------------------------------------------------------------------------- |
71 // -------------------------------------------------------------------------- |
326 // |
72 // |
327 CPbk2ContactViewDoubleListBoxModel::CPbk2ContactViewDoubleListBoxModel( |
73 CPbk2ContactViewDoubleListBoxModel::CPbk2ContactViewDoubleListBoxModel( |
328 CPbk2ContactViewListBoxModel::TParams& aParams, |
74 CPbk2ContactViewListBoxModel::TParams& aParams, |
329 CPbk2ThumbnailManager& aThumbManager, |
75 CPbk2ThumbnailManager& aThumbManager ) : |
330 MPbk2FilteredViewStack& aFilteredViewStack ) : |
|
331 CPbk2ContactViewListBoxModel( aParams ), |
76 CPbk2ContactViewListBoxModel( aParams ), |
332 iThumbManager( aThumbManager ), |
77 iThumbManager( aThumbManager ) |
333 iFilteredViewStack( aFilteredViewStack ) |
|
334 { |
78 { |
335 TAny* object = aParams.iUiExtension->ContactUiControlExtensionExtension |
79 TAny* object = aParams.iUiExtension->ContactUiControlExtensionExtension |
336 ( TUid::Uid( KPbk2ContactUiControlExtensionExtensionUID ) ); |
80 ( TUid::Uid( KPbk2ContactUiControlExtensionExtensionUID ) ); |
337 iDoubleListExtensionPoint = |
81 iDoubleListExtensionPoint = |
338 static_cast<MPbk2ContactUiControlDoubleListboxExtension*>( object ); |
82 static_cast<MPbk2ContactUiControlDoubleListboxExtension*>( object ); |
342 // CPbk2ContactViewDoubleListBoxModel::~CPbk2ContactViewDoubleListBoxModel |
86 // CPbk2ContactViewDoubleListBoxModel::~CPbk2ContactViewDoubleListBoxModel |
343 // -------------------------------------------------------------------------- |
87 // -------------------------------------------------------------------------- |
344 // |
88 // |
345 CPbk2ContactViewDoubleListBoxModel::~CPbk2ContactViewDoubleListBoxModel() |
89 CPbk2ContactViewDoubleListBoxModel::~CPbk2ContactViewDoubleListBoxModel() |
346 { |
90 { |
347 delete iDataElementCache; |
|
348 } |
91 } |
349 |
92 |
350 // -------------------------------------------------------------------------- |
93 // -------------------------------------------------------------------------- |
351 // CPbk2ContactViewDoubleListBoxModel::NewL |
94 // CPbk2ContactViewDoubleListBoxModel::NewL |
352 // -------------------------------------------------------------------------- |
95 // -------------------------------------------------------------------------- |
353 // |
96 // |
354 CPbk2ContactViewDoubleListBoxModel* CPbk2ContactViewDoubleListBoxModel::NewL( |
97 CPbk2ContactViewDoubleListBoxModel* CPbk2ContactViewDoubleListBoxModel::NewL( |
355 CPbk2ContactViewListBoxModel::TParams& aParams, |
98 CPbk2ContactViewListBoxModel::TParams& aParams, |
356 CPbk2ThumbnailManager& aThumbManager, |
99 CPbk2ThumbnailManager& aThumbManager ) |
357 MPbk2FilteredViewStack& aFilteredViewStack ) |
|
358 { |
100 { |
359 CPbk2ContactViewDoubleListBoxModel* self = |
101 CPbk2ContactViewDoubleListBoxModel* self = |
360 new ( ELeave ) CPbk2ContactViewDoubleListBoxModel( |
102 new ( ELeave ) CPbk2ContactViewDoubleListBoxModel( |
361 aParams, aThumbManager, aFilteredViewStack ); |
103 aParams, aThumbManager ); |
362 |
104 |
363 CleanupStack::PushL(self); |
105 CleanupStack::PushL(self); |
364 self->ConstructL( aParams.iStoreProperties, aParams.iUiExtension ); |
106 self->ConstructL( aParams.iStoreProperties, aParams.iUiExtension ); |
365 self->iDataElementCache = CDataElementCache::NewL( aFilteredViewStack ); |
|
366 CleanupStack::Pop(); |
107 CleanupStack::Pop(); |
367 return self; |
108 return self; |
368 } |
109 } |
369 |
110 |
370 // -------------------------------------------------------------------------- |
111 // -------------------------------------------------------------------------- |
374 void CPbk2ContactViewDoubleListBoxModel::FormatBufferL( const TInt aIndex ) const |
115 void CPbk2ContactViewDoubleListBoxModel::FormatBufferL( const TInt aIndex ) const |
375 { |
116 { |
376 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
117 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
377 ("CPbk2ContactViewDoubleListBoxModel::FormatBufferL(0x%x,%d), begin"), |
118 ("CPbk2ContactViewDoubleListBoxModel::FormatBufferL(0x%x,%d), begin"), |
378 this); |
119 this); |
379 CPbk2ContactViewDoubleListboxDataElement* element = |
120 |
380 iDataElementCache->Element( aIndex ); |
121 const MVPbkViewContact& contact = iView->ContactAtL(aIndex); |
381 if( element ) |
122 FormatBufferForContactL(contact, aIndex ); |
382 { |
|
383 FormatBufferForElementDataL(*element, aIndex); |
|
384 } |
|
385 else |
|
386 { |
|
387 const MVPbkViewContact& contact = iView->ContactAtL(aIndex); |
|
388 FormatBufferForContactL(contact, aIndex ); |
|
389 } |
|
390 |
123 |
391 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
124 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
392 ("CPbk2ContactViewDoubleListBoxModel::FormatBufferL(0x%x,%d), end"), |
125 ("CPbk2ContactViewDoubleListBoxModel::FormatBufferL(0x%x,%d), end"), |
393 this); |
126 this); |
394 } |
127 } |
395 |
128 |
396 |
129 |
397 // -------------------------------------------------------------------------- |
130 // -------------------------------------------------------------------------- |
398 // CPbk2ContactViewDoubleListBoxModel::FormatBufferForElementDataL |
131 // CPbk2ContactViewDoubleListBoxModel::FetchDataFromExtension |
399 // -------------------------------------------------------------------------- |
132 // -------------------------------------------------------------------------- |
400 // |
133 // |
401 void CPbk2ContactViewDoubleListBoxModel::FetchDataFromExtension( |
134 void CPbk2ContactViewDoubleListBoxModel::FetchDataFromExtension( |
402 CPbk2ContactViewDoubleListboxDataElement& aDataElement, |
135 CPbk2ContactViewDoubleListboxDataElement& aDataElement, |
403 TInt aIndex ) const |
136 TInt aIndex, |
|
137 const MVPbkContactLink& aLink ) const |
404 { |
138 { |
405 // Get element data from extension |
139 // Get element data from extension |
406 // |
140 // |
407 if( iDoubleListExtensionPoint ) |
141 if( iDoubleListExtensionPoint ) |
408 { |
142 { |
409 TRAPD( err, |
143 TRAPD( err, |
410 iDoubleListExtensionPoint->FormatDataL( |
144 iDoubleListExtensionPoint->FormatDataL( |
411 *(aDataElement.ContactLink()), aDataElement ) ); |
145 aLink, aDataElement ) ); |
412 if( err ) |
146 if( err ) |
413 { |
147 { |
414 // extension's errors are ignored. |
148 // extension's errors are ignored. |
415 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING( |
149 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING( |
416 "CPbk2ContactViewDoubleListBoxModel::FormatBufferForElementDataL format error %d"), |
150 "CPbk2ContactViewDoubleListBoxModel::FetchDataFromExtension format error %d"), |
417 err ); |
151 err ); |
418 } |
152 } |
419 } |
153 } |
420 |
154 |
421 // Clip secondary text if it's a phone number |
155 // Clip secondary text if it's a phone number |
429 secondary, aIndex, KSecondaryTextColumn ); |
163 secondary, aIndex, KSecondaryTextColumn ); |
430 } |
164 } |
431 } |
165 } |
432 |
166 |
433 // -------------------------------------------------------------------------- |
167 // -------------------------------------------------------------------------- |
434 // CPbk2ContactViewDoubleListBoxModel::FormatBufferForElementDataL |
|
435 // -------------------------------------------------------------------------- |
|
436 // |
|
437 void CPbk2ContactViewDoubleListBoxModel::FormatBufferForElementDataL( |
|
438 CPbk2ContactViewDoubleListboxDataElement& aDataElement, |
|
439 TInt aIndex ) const |
|
440 { |
|
441 FetchDataFromExtension(aDataElement, aIndex); |
|
442 |
|
443 // start fill the new buffer for the avkon list |
|
444 iBuffer.Zero(); |
|
445 |
|
446 AppendThumbnailL( aDataElement, aIndex ); |
|
447 |
|
448 // The cached element needs to be updated when the presence icon is changed |
|
449 RArray<TPbk2IconId> ids; |
|
450 CleanupClosePushL( ids ); |
|
451 const MVPbkViewContact& contact = iView->ContactAtL( aIndex ); |
|
452 iContactIcons->GetIconIdsForContactL( contact, ids ); |
|
453 |
|
454 // If no icon was found, append an empty icon |
|
455 if( ids.Count() == 0 ) |
|
456 { |
|
457 ids.Append( iEmptyIconId ); |
|
458 } |
|
459 |
|
460 aDataElement.SetIconId( MPbk2DoubleListboxDataElement::EMainIcon, ids[ 0 ] ); |
|
461 CleanupStack::PopAndDestroy( &ids ); |
|
462 |
|
463 // Format line buffer based on element's content |
|
464 FormatBufferFromElement( aDataElement ); |
|
465 } |
|
466 |
|
467 // -------------------------------------------------------------------------- |
|
468 // CPbk2ContactViewDoubleListBoxModel::FormatBufferForContactL |
168 // CPbk2ContactViewDoubleListBoxModel::FormatBufferForContactL |
469 // -------------------------------------------------------------------------- |
169 // -------------------------------------------------------------------------- |
470 // |
170 // |
471 void CPbk2ContactViewDoubleListBoxModel::FormatBufferForContactL( |
171 void CPbk2ContactViewDoubleListBoxModel::FormatBufferForContactL( |
472 const MVPbkViewContact& aViewContact, |
172 const MVPbkViewContact& aViewContact, |
473 TInt aIndex ) const |
173 TInt aIndex ) const |
474 { |
174 { |
475 MVPbkContactLink* link = aViewContact.CreateLinkLC(); |
|
476 CPbk2ContactViewDoubleListboxDataElement* element = |
175 CPbk2ContactViewDoubleListboxDataElement* element = |
477 CPbk2ContactViewDoubleListboxDataElement::NewL( link, aIndex ); |
176 CPbk2ContactViewDoubleListboxDataElement::NewLC(); |
478 if( link ) |
|
479 { |
|
480 CleanupStack::Pop(); // link |
|
481 } |
|
482 CleanupStack::PushL( element ); |
|
483 |
177 |
484 // get data for element |
178 // get data for element |
485 // get user name |
179 // get user name |
486 HBufC* name = NULL; |
180 HBufC* name = NULL; |
487 if( FeatureManager::FeatureSupported( KFeatureIdFfContactsCompanyNames )) |
181 if( FeatureManager::FeatureSupported( KFeatureIdFfContactsCompanyNames )) |