|
1 /* |
|
2 * Copyright (c) 2009 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: Thumbnail manager for the social phonebook. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CPBK2THUMBNAILMANAGER_H_ |
|
19 #define CPBK2THUMBNAILMANAGER_H_ |
|
20 |
|
21 // external includes |
|
22 #include <e32base.h> |
|
23 #include <MVPbkSingleContactOperationObserver.h> |
|
24 #include <MPbk2ImageOperationObservers.h> |
|
25 #include <MVPbkContactViewObserver.h> |
|
26 #include <TPbk2IconId.h> |
|
27 |
|
28 |
|
29 //FORWARD declaration |
|
30 class CPbk2ImageManager; |
|
31 class CVPbkContactManager; |
|
32 class MVPbkContactOperationBase; |
|
33 class MVPbkContactLink; |
|
34 class MVPbkStoreContact; |
|
35 class MVPbkBaseContact; |
|
36 class MVPbkFieldType; |
|
37 class CPbk2TmItem; |
|
38 class CPbk2IconArray; |
|
39 |
|
40 //internal state of the loader |
|
41 enum TTMLoadingState |
|
42 { |
|
43 ELoading, |
|
44 EIdle |
|
45 }; |
|
46 |
|
47 // state for determining whether to optimize or not |
|
48 enum TTMOptimizationState |
|
49 { |
|
50 EOptimize, |
|
51 ENoOptimization |
|
52 }; |
|
53 |
|
54 /* |
|
55 * Observer class for the manager |
|
56 */ |
|
57 class MPbk2ThumbnailManagerObserver |
|
58 { |
|
59 public: |
|
60 |
|
61 /* |
|
62 * This is called after all thumbnails from the loading queue is loaded. |
|
63 */ |
|
64 virtual void LoadingFinished() = 0; |
|
65 |
|
66 /* |
|
67 * Informs observer that loading of thumbnail is complete |
|
68 * Param@ aError, KErrNone if success, KErrNotFound if not found. |
|
69 * param@ index on listbox or KErrNotFound if not found |
|
70 */ |
|
71 virtual void ThumbnailLoadingComplete( TInt aError, TInt aIndex ) = 0; |
|
72 |
|
73 /* |
|
74 * Informs the observer that thumbnail has been deleted from the manager's array. Listbox index is the index |
|
75 * that is given when thumbnail is asked to be loaded |
|
76 */ |
|
77 virtual void ThumbnailRemoved( const MVPbkContactLink& aLink, TInt aIndex ) = 0; |
|
78 |
|
79 }; |
|
80 |
|
81 |
|
82 /* |
|
83 * Class for loading contact thumbnails |
|
84 */ |
|
85 NONSHARABLE_CLASS( CPbk2ThumbnailManager ) : public CBase, |
|
86 public MVPbkSingleContactOperationObserver, |
|
87 public MPbk2ImageGetObserver, |
|
88 public MVPbkContactViewObserver |
|
89 { |
|
90 public: // constructor & destructor |
|
91 |
|
92 IMPORT_C static CPbk2ThumbnailManager* NewL( CVPbkContactManager& aContactManager ); |
|
93 virtual ~CPbk2ThumbnailManager(); |
|
94 |
|
95 |
|
96 public: // new functions |
|
97 |
|
98 /* |
|
99 * Sets observer for the manager |
|
100 */ |
|
101 void SetObserver( MPbk2ThumbnailManagerObserver& aObserver ); |
|
102 |
|
103 /* |
|
104 * Removes observer |
|
105 */ |
|
106 void RemoveObserver(); |
|
107 |
|
108 |
|
109 /* |
|
110 * Returns icon index from Pbk2IconArray for double listbox index. |
|
111 * If icon is not set, default icon index is returned |
|
112 */ |
|
113 TInt GetPbkIconIndex( TInt aListboxIndex, const MVPbkBaseContact& aContactLink ); |
|
114 |
|
115 /* |
|
116 * Setter for default icon ID |
|
117 */ |
|
118 void SetDefaultIconId( TPbk2IconId aDefaultIconId ); |
|
119 |
|
120 /* |
|
121 * Returns default icon id |
|
122 */ |
|
123 const TPbk2IconId& GetDefaultIconId(); |
|
124 |
|
125 /* |
|
126 * Setter for Pbk2IconArray. Thumbnail manager doesn't own the array. |
|
127 */ |
|
128 void SetPbkIconArray( CPbk2IconArray* aIconArray ); |
|
129 |
|
130 /* |
|
131 * Removes icon array from the manager. Doesn't destroy the arrray |
|
132 */ |
|
133 void RemoveIconArray(); |
|
134 |
|
135 /* |
|
136 * Returns number of loaded thumbnails |
|
137 */ |
|
138 TInt ThumbnailCount(); |
|
139 |
|
140 /* |
|
141 * Adds contact to the array and starts loading the thumbnail for it. |
|
142 * If loading is already in progress, contact is added to queue. |
|
143 * |
|
144 */ |
|
145 void LoadThumbnailL( const MVPbkContactLink& aContactLink, TInt aListboxIndex ); |
|
146 |
|
147 /* |
|
148 * Removes contact from loader's array and deletes the thumbnail. |
|
149 * Returns KErrNone or KErrNotFound. |
|
150 */ |
|
151 TInt RemoveThumbnail( const MVPbkContactLink& aContactLink, TInt aListboxIndex ); |
|
152 |
|
153 /** |
|
154 * Reset thumbnail manager. Clear cache and cancel all ongoing operations. |
|
155 */ |
|
156 void Reset(); |
|
157 |
|
158 /* |
|
159 * Setter for thumbnail icon size |
|
160 */ |
|
161 void SetThumbnailIconSize( TSize aSize ); |
|
162 |
|
163 /* |
|
164 * Getter for thumbnail icon size |
|
165 */ |
|
166 const TSize& GetThumbnailIconSize(); |
|
167 |
|
168 private: // new functions |
|
169 |
|
170 /* |
|
171 * If contact is added to middle of the list, increase indexes that are added after the given index |
|
172 */ |
|
173 void IncreaseIndexes( TInt aListboxIndex ); |
|
174 |
|
175 /* |
|
176 * If contact is removed from middle of the list, decrease indexes that are added after the given index |
|
177 */ |
|
178 void DecreaseIndexes( TInt aListboxIndex ); |
|
179 |
|
180 /* |
|
181 * Removes allready loaded thumbnail from the last position of the priorization array. |
|
182 * Removes also image from Pbk2IconArray and iContactThumbnails. |
|
183 */ |
|
184 void MakeRoomForNextThumbnail(); |
|
185 |
|
186 /* |
|
187 * Finds correct item from the iContactThumbnails based on the base contact |
|
188 */ |
|
189 CPbk2TmItem* FindItem( const MVPbkBaseContact& aContactLink ); |
|
190 /* |
|
191 * Starts loading of the contact thumbnails. |
|
192 */ |
|
193 void StartLoading(); |
|
194 |
|
195 /* |
|
196 * Loads the thumbnail for the contact |
|
197 */ |
|
198 void DoLoadThumbnail( MVPbkBaseContact& aContact ); |
|
199 |
|
200 /* |
|
201 * Duplicates the bitmap handle |
|
202 */ |
|
203 CFbsBitmap* DuplicateBitmapL( CFbsBitmap* aSourceBitmap ); |
|
204 |
|
205 /* |
|
206 * Reads file type for the contact image |
|
207 */ |
|
208 void ReadFieldTypeL(); |
|
209 |
|
210 /** |
|
211 * Append bitmap into icon array |
|
212 */ |
|
213 void AppendIconL( TPbk2IconId& aIcon, CFbsBitmap* aBitmap ); |
|
214 |
|
215 /* |
|
216 * Icon indexes must be updated after icon(s) are removed from the icon array |
|
217 */ |
|
218 void UpdateIconIndexes( ); |
|
219 |
|
220 /** |
|
221 * Handle view ready events |
|
222 */ |
|
223 void DoContactViewReadyL( MVPbkContactViewBase& aView ); |
|
224 |
|
225 private: // From MVPbkSingleContactOperationObserver |
|
226 void VPbkSingleContactOperationComplete( |
|
227 MVPbkContactOperationBase& aOperation, |
|
228 MVPbkStoreContact* aContact ); |
|
229 |
|
230 void VPbkSingleContactOperationFailed( |
|
231 MVPbkContactOperationBase& aOperation, |
|
232 TInt aError ); |
|
233 |
|
234 private: // From MPbk2ImageGetObserver |
|
235 void Pbk2ImageGetComplete( |
|
236 MPbk2ImageOperation& aOperation, |
|
237 CFbsBitmap* aBitmap ); |
|
238 void Pbk2ImageGetFailed( |
|
239 MPbk2ImageOperation& aOperation, |
|
240 TInt aError ); |
|
241 |
|
242 private: // From MVPbkContactViewObserver |
|
243 void ContactViewReady( MVPbkContactViewBase& aView ); |
|
244 void ContactViewUnavailable( MVPbkContactViewBase& aView ); |
|
245 void ContactAddedToView( |
|
246 MVPbkContactViewBase& aView, |
|
247 TInt aIndex, |
|
248 const MVPbkContactLink& aContactLink ); |
|
249 void ContactRemovedFromView( |
|
250 MVPbkContactViewBase& aView, |
|
251 TInt aIndex, |
|
252 const MVPbkContactLink& aContactLink ); |
|
253 void ContactViewError( |
|
254 MVPbkContactViewBase& aView, |
|
255 TInt aError, |
|
256 TBool aErrorNotified ); |
|
257 |
|
258 |
|
259 private: //constructors |
|
260 CPbk2ThumbnailManager( CVPbkContactManager& aContactManager ); |
|
261 void ConstructL(); |
|
262 |
|
263 private: //data |
|
264 |
|
265 //OWN: thumbnail size |
|
266 TSize iIconSize; |
|
267 |
|
268 // internal state |
|
269 TTMLoadingState iState; |
|
270 |
|
271 /// Own: thumbnails |
|
272 RPointerArray<CPbk2TmItem> iContactThumbnails; |
|
273 |
|
274 /// Own: Loading queue for the thumbnails |
|
275 RPointerArray<CPbk2TmItem> iLoadingQueue; |
|
276 |
|
277 /// Own: Thumbnail manager |
|
278 CPbk2ImageManager* iManager; |
|
279 |
|
280 // ref: |
|
281 CVPbkContactManager& iContactManager; |
|
282 |
|
283 /// Own: Retrieve operation |
|
284 MVPbkContactOperationBase* iRetrieveOperation; |
|
285 |
|
286 /// Own: Store contact |
|
287 MVPbkStoreContact* iStoreContact; |
|
288 |
|
289 /// Own: Asynchronous thumbnail operation |
|
290 MPbk2ImageOperation* iThumbOperation; |
|
291 |
|
292 // REF: observer for the loader |
|
293 MPbk2ThumbnailManagerObserver* iObserver; |
|
294 |
|
295 /// Ref: Field type |
|
296 const MVPbkFieldType* iFieldType; |
|
297 |
|
298 //REF: listbox icon array |
|
299 CPbk2IconArray* iIconArray; |
|
300 |
|
301 // default icon index and id |
|
302 TInt iDefaultIconIndex; |
|
303 TPbk2IconId iDefaultIconId; |
|
304 // icon index counter |
|
305 TInt iIconIdCounter; |
|
306 // loading priority. |
|
307 RArray<MVPbkContactLink*> iPriorityArray; |
|
308 /// Own: Holds the item whose thumbnail load is in progress |
|
309 /// This item needs to be removed when its safe |
|
310 CPbk2TmItem* iInProgressItemToBeRemoved; |
|
311 }; |
|
312 |
|
313 #endif /* CPBK2THUMBNAILMANAGER_H_ */ |