430 CleanupStack::Pop(); // link |
430 CleanupStack::Pop(); // link |
431 // set default icon index |
431 // set default icon index |
432 item->SetIconArrayIndexAndId( iDefaultIconIndex,iDefaultIconId ); |
432 item->SetIconArrayIndexAndId( iDefaultIconIndex,iDefaultIconId ); |
433 item->SetHasThumbnail( ETrue ); |
433 item->SetHasThumbnail( ETrue ); |
434 iContactThumbnails[ aListboxIndex ] = item; |
434 iContactThumbnails[ aListboxIndex ] = item; |
|
435 iIsCacheClean = EFalse; |
435 } |
436 } |
436 |
437 |
437 // if item has a thumbnail image, but it is not loaded yet ( queue ) |
438 // if item has a thumbnail image, but it is not loaded yet ( queue ) |
438 if( item->HasThumbnail() && !item->GetBitmap() ) |
439 if( item->HasThumbnail() && !item->GetBitmap() ) |
439 { |
440 { |
608 if( iView ) |
609 if( iView ) |
609 { |
610 { |
610 iView->AddObserverL( *this ); |
611 iView->AddObserverL( *this ); |
611 iView->AddStackObserverL( *this ); |
612 iView->AddStackObserverL( *this ); |
612 } |
613 } |
613 Reset(); |
614 FlushCache(); |
614 } |
615 } |
615 |
616 |
616 // -------------------------------------------------------------------------- |
617 // -------------------------------------------------------------------------- |
617 // CPbk2ThumbnailManager::RemoveThumbnail() |
618 // CPbk2ThumbnailManager::RemoveThumbnail() |
618 // -------------------------------------------------------------------------- |
619 // -------------------------------------------------------------------------- |
918 { |
919 { |
919 // remove from priority array |
920 // remove from priority array |
920 iPriorityArray.Remove( 0 ); |
921 iPriorityArray.Remove( 0 ); |
921 |
922 |
922 //remove icon from Pbk2IconArray |
923 //remove icon from Pbk2IconArray |
923 if( iIconArray ) |
924 if( iIconArray && rem->GetIconArrayIndex() != iDefaultIconIndex ) |
924 { |
925 { |
925 iIconArray->RemoveIcon( rem->GetIconId() ); |
926 iIconArray->RemoveIcon( rem->GetIconId() ); |
926 } |
927 } |
927 // remove memory allocations from heap |
928 // remove memory allocations from heap |
928 rem->DeleteBitmap(); |
929 rem->DeleteBitmap(); |
1023 // -------------------------------------------------------------------------- |
1024 // -------------------------------------------------------------------------- |
1024 // CPbk2ThumbnailManager::DoContactViewReadyL |
1025 // CPbk2ThumbnailManager::DoContactViewReadyL |
1025 // -------------------------------------------------------------------------- |
1026 // -------------------------------------------------------------------------- |
1026 // |
1027 // |
1027 void CPbk2ThumbnailManager::DoContactViewReadyL( MVPbkContactViewBase& aView ) |
1028 void CPbk2ThumbnailManager::DoContactViewReadyL( MVPbkContactViewBase& aView ) |
1028 { |
1029 { |
1029 // get contact count |
1030 FlushCache(); |
1030 const TInt thumbnailCount = iContactThumbnails.Count(); |
1031 PreCreateThumbnailArrayL( aView ); |
1031 if( thumbnailCount == 0 ) |
|
1032 { |
|
1033 PreCreateThumbnailArrayL( aView ); |
|
1034 } |
|
1035 else |
|
1036 { |
|
1037 // Check if view count has changed |
|
1038 if ( aView.ContactCountL() != thumbnailCount ) |
|
1039 { |
|
1040 if( iLoadingQueue.Count() > 0 ) |
|
1041 { |
|
1042 // store item that is currently in processing |
|
1043 iInProgressItemToBeRemoved = iLoadingQueue[0]; |
|
1044 } |
|
1045 |
|
1046 for ( TInt i = thumbnailCount - 1; i >= 0; --i ) |
|
1047 { |
|
1048 CPbk2TmItem* item = iContactThumbnails[i]; |
|
1049 if ( item ) |
|
1050 { |
|
1051 // check that the icon is not a default icon |
|
1052 if( iIconArray && item->GetIconArrayIndex() != iDefaultIconIndex ) |
|
1053 { |
|
1054 // inform icon array to remove the icon |
|
1055 iIconArray->RemoveIcon( item->GetIconId() ); |
|
1056 } |
|
1057 |
|
1058 if ( iInProgressItemToBeRemoved == item ) |
|
1059 { |
|
1060 // prevent item from being deleted later |
|
1061 iContactThumbnails[i] = NULL; |
|
1062 } |
|
1063 } |
|
1064 } |
|
1065 |
|
1066 // reset and recreate arrays |
|
1067 iLoadingQueue.Reset(); |
|
1068 iPriorityArray.Reset(); |
|
1069 PreCreateThumbnailArrayL( aView ); |
|
1070 } |
|
1071 } |
|
1072 } |
1032 } |
1073 |
1033 |
1074 // -------------------------------------------------------------------------- |
1034 // -------------------------------------------------------------------------- |
1075 // CPbk2ThumbnailManager::PreCreateThumbnailArrayL |
1035 // CPbk2ThumbnailManager::PreCreateThumbnailArrayL |
1076 // -------------------------------------------------------------------------- |
1036 // -------------------------------------------------------------------------- |
1084 iContactThumbnails.AppendL( NULL ); |
1044 iContactThumbnails.AppendL( NULL ); |
1085 } |
1045 } |
1086 } |
1046 } |
1087 |
1047 |
1088 // -------------------------------------------------------------------------- |
1048 // -------------------------------------------------------------------------- |
|
1049 // CPbk2ThumbnailManager::FlushCache |
|
1050 // -------------------------------------------------------------------------- |
|
1051 // |
|
1052 void CPbk2ThumbnailManager::FlushCache() |
|
1053 { |
|
1054 // reset operations |
|
1055 delete iRetrieveOperation; |
|
1056 iRetrieveOperation = NULL; |
|
1057 delete iThumbOperation; |
|
1058 iThumbOperation = NULL; |
|
1059 iState = EIdle; |
|
1060 |
|
1061 if( !iIsCacheClean ) // prevent unnecessary work if cache is already cleaned |
|
1062 { |
|
1063 iIsCacheClean = ETrue; |
|
1064 const TInt count = iContactThumbnails.Count(); |
|
1065 for ( TInt i = count - 1; i >= 0; --i ) |
|
1066 { |
|
1067 CPbk2TmItem* item = iContactThumbnails[i]; |
|
1068 if ( item ) |
|
1069 { |
|
1070 // check that the icon is not a default icon |
|
1071 if( iIconArray && item->GetIconArrayIndex() != iDefaultIconIndex ) |
|
1072 { |
|
1073 iIconArray->RemoveIcon( item->GetIconId() ); |
|
1074 } |
|
1075 |
|
1076 delete item; |
|
1077 iContactThumbnails[i] = NULL; |
|
1078 } |
|
1079 } |
|
1080 } |
|
1081 |
|
1082 // reset loading queue and cache priority |
|
1083 iLoadingQueue.Reset(); |
|
1084 iPriorityArray.Reset(); |
|
1085 } |
|
1086 |
|
1087 // -------------------------------------------------------------------------- |
1089 // CPbk2ThumbnailManager::ContactViewUnavailable |
1088 // CPbk2ThumbnailManager::ContactViewUnavailable |
1090 // -------------------------------------------------------------------------- |
1089 // -------------------------------------------------------------------------- |
1091 // |
1090 // |
1092 void CPbk2ThumbnailManager::ContactViewUnavailable( |
1091 void CPbk2ThumbnailManager::ContactViewUnavailable( |
1093 MVPbkContactViewBase& /*aView*/ ) |
1092 MVPbkContactViewBase& /*aView*/ ) |
1100 // -------------------------------------------------------------------------- |
1099 // -------------------------------------------------------------------------- |
1101 // |
1100 // |
1102 void CPbk2ThumbnailManager::ContactAddedToView( |
1101 void CPbk2ThumbnailManager::ContactAddedToView( |
1103 MVPbkContactViewBase& /*aView*/, |
1102 MVPbkContactViewBase& /*aView*/, |
1104 TInt aIndex, |
1103 TInt aIndex, |
1105 const MVPbkContactLink& aContactLink ) |
1104 const MVPbkContactLink& /*aContactLink*/ ) |
1106 { |
1105 { |
1107 CPbk2TmItem* item = NULL; |
1106 // Because contact events and contact view are not always in sync we need to |
1108 TRAPD( err, |
1107 // flush the whole cache. |
1109 { |
1108 FlushCache(); |
1110 item = CPbk2TmItem::NewL( aContactLink.CloneLC(), aIndex ); |
1109 iContactThumbnails.Insert( NULL, aIndex ); |
1111 CleanupStack::Pop(); |
|
1112 }); |
|
1113 if( KErrNone == err ) |
|
1114 { |
|
1115 // set default icon index |
|
1116 item->SetIconArrayIndexAndId( iDefaultIconIndex, iDefaultIconId ); |
|
1117 item->SetHasThumbnail( ETrue ); |
|
1118 iContactThumbnails.Insert( item, aIndex ); |
|
1119 } |
|
1120 ResetIndexes(); |
|
1121 } |
1110 } |
1122 |
1111 |
1123 // -------------------------------------------------------------------------- |
1112 // -------------------------------------------------------------------------- |
1124 // CPbk2ThumbnailManager::ContactRemovedFromView |
1113 // CPbk2ThumbnailManager::ContactRemovedFromView |
1125 // -------------------------------------------------------------------------- |
1114 // -------------------------------------------------------------------------- |
1126 // |
1115 // |
1127 void CPbk2ThumbnailManager::ContactRemovedFromView( |
1116 void CPbk2ThumbnailManager::ContactRemovedFromView( |
1128 MVPbkContactViewBase& /*aView*/, |
1117 MVPbkContactViewBase& /*aView*/, |
1129 TInt aIndex, |
1118 TInt aIndex, |
1130 const MVPbkContactLink& aContactLink ) |
1119 const MVPbkContactLink& /*aContactLink*/ ) |
1131 { |
1120 { |
1132 RemoveThumbnail( aContactLink, aIndex ); |
1121 // Because contact events and contact view are not always in sync we need to |
|
1122 // flush the whole cache. |
|
1123 FlushCache(); |
|
1124 iContactThumbnails.Remove( aIndex ); |
1133 } |
1125 } |
1134 |
1126 |
1135 // -------------------------------------------------------------------------- |
1127 // -------------------------------------------------------------------------- |
1136 // CPbk2ThumbnailManager::ContactViewError |
1128 // CPbk2ThumbnailManager::ContactViewError |
1137 // -------------------------------------------------------------------------- |
1129 // -------------------------------------------------------------------------- |