20
|
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 |
#include "MPbk2FilteredViewStack.h"
|
|
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 |
public MPbk2FilteredViewStackObserver
|
|
90 |
{
|
|
91 |
public: // constructor & destructor
|
|
92 |
|
|
93 |
IMPORT_C static CPbk2ThumbnailManager* NewL( CVPbkContactManager& aContactManager );
|
|
94 |
virtual ~CPbk2ThumbnailManager();
|
|
95 |
|
|
96 |
|
|
97 |
public: // new functions
|
|
98 |
|
|
99 |
/*
|
|
100 |
* Sets observer for the manager
|
|
101 |
*/
|
|
102 |
void SetObserver( MPbk2ThumbnailManagerObserver& aObserver );
|
|
103 |
|
|
104 |
/*
|
|
105 |
* Removes observer
|
|
106 |
*/
|
|
107 |
void RemoveObserver();
|
|
108 |
|
|
109 |
|
|
110 |
/*
|
|
111 |
* Returns icon index from Pbk2IconArray for double listbox index.
|
|
112 |
* If icon is not set, default icon index is returned
|
|
113 |
*/
|
|
114 |
TInt GetPbkIconIndexL( TInt aListboxIndex, const MVPbkContactLink& aContactLink );
|
|
115 |
|
|
116 |
/*
|
|
117 |
* Setter for default icon ID
|
|
118 |
*/
|
|
119 |
void SetDefaultIconId( TPbk2IconId aDefaultIconId );
|
|
120 |
|
|
121 |
/*
|
|
122 |
* Returns default icon id
|
|
123 |
*/
|
|
124 |
const TPbk2IconId& GetDefaultIconId();
|
|
125 |
|
|
126 |
/*
|
|
127 |
* Setter for Pbk2IconArray. Thumbnail manager doesn't own the array.
|
|
128 |
*/
|
|
129 |
void SetPbkIconArray( CPbk2IconArray* aIconArray );
|
|
130 |
|
|
131 |
/*
|
|
132 |
* Removes icon array from the manager. Doesn't destroy the arrray
|
|
133 |
*/
|
|
134 |
void RemoveIconArray();
|
|
135 |
|
|
136 |
/*
|
|
137 |
* Returns number of loaded thumbnails
|
|
138 |
*/
|
|
139 |
TInt ThumbnailCount();
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Reset thumbnail manager. Clear cache and cancel all ongoing operations.
|
|
143 |
* NOTICE: Does not remove icons from icon array.
|
|
144 |
*/
|
|
145 |
void Reset();
|
|
146 |
|
|
147 |
/*
|
|
148 |
* Setter for thumbnail icon size
|
|
149 |
*/
|
|
150 |
void SetThumbnailIconSize( TSize aSize );
|
|
151 |
|
|
152 |
/*
|
|
153 |
* Getter for thumbnail icon size
|
|
154 |
*/
|
|
155 |
const TSize& GetThumbnailIconSize();
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Set view for thumbnail manager. Thumbnail manager will start observing the
|
|
159 |
* view and update it's internal state accordingly. Remove view by setting it
|
|
160 |
* to NULL.
|
|
161 |
*/
|
|
162 |
void SetContactViewL( MPbk2FilteredViewStack* aView );
|
|
163 |
|
|
164 |
private: // new functions
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Removes contact from loader's array and deletes the thumbnail.
|
|
168 |
*/
|
|
169 |
void RemoveThumbnail( const MVPbkContactLink& aContactLink, TInt aListboxIndex );
|
|
170 |
|
|
171 |
/*
|
|
172 |
* reset listbox indexes to match the array order
|
|
173 |
*/
|
|
174 |
void ResetIndexes();
|
|
175 |
|
|
176 |
/*
|
|
177 |
* Removes allready loaded thumbnail from the last position of the priorization array.
|
|
178 |
* Removes also image from Pbk2IconArray and iContactThumbnails.
|
|
179 |
*/
|
|
180 |
void MakeRoomForNextThumbnail();
|
|
181 |
|
|
182 |
/*
|
|
183 |
* Starts loading of the contact thumbnails.
|
|
184 |
*/
|
|
185 |
void StartLoading();
|
|
186 |
|
|
187 |
/*
|
|
188 |
* Loads the thumbnail for the contact
|
|
189 |
*/
|
|
190 |
void DoLoadThumbnail( MVPbkBaseContact& aContact );
|
|
191 |
|
|
192 |
/*
|
|
193 |
* Duplicates the bitmap handle
|
|
194 |
*/
|
|
195 |
CFbsBitmap* DuplicateBitmapL( CFbsBitmap* aSourceBitmap );
|
|
196 |
|
|
197 |
/*
|
|
198 |
* Reads file type for the contact image
|
|
199 |
*/
|
|
200 |
void ReadFieldTypeL();
|
|
201 |
|
|
202 |
/**
|
|
203 |
* Append bitmap into icon array
|
|
204 |
*/
|
|
205 |
void AppendIconL( TPbk2IconId& aIcon, CFbsBitmap* aBitmap );
|
|
206 |
|
|
207 |
/*
|
|
208 |
* Icon indexes must be updated after icon(s) are removed from the icon array
|
|
209 |
*/
|
|
210 |
void UpdateIconIndexes( );
|
|
211 |
|
|
212 |
/**
|
|
213 |
* Handle view ready events
|
|
214 |
*/
|
|
215 |
void DoContactViewReadyL( MVPbkContactViewBase& aView );
|
|
216 |
|
|
217 |
/**
|
|
218 |
* Create empty thumbnail item array reflecting the aView.
|
|
219 |
*/
|
|
220 |
void PreCreateThumbnailArrayL( MVPbkContactViewBase& aView );
|
|
221 |
|
|
222 |
/**
|
|
223 |
* Flush cached thumbnails and cancel all ongoing and scheduled operations.
|
|
224 |
* Remove icons from icon array if available.
|
|
225 |
*/
|
|
226 |
void FlushCache();
|
|
227 |
|
|
228 |
private: // From MVPbkSingleContactOperationObserver
|
|
229 |
void VPbkSingleContactOperationComplete(
|
|
230 |
MVPbkContactOperationBase& aOperation,
|
|
231 |
MVPbkStoreContact* aContact );
|
|
232 |
|
|
233 |
void VPbkSingleContactOperationFailed(
|
|
234 |
MVPbkContactOperationBase& aOperation,
|
|
235 |
TInt aError );
|
|
236 |
|
|
237 |
private: // From MPbk2ImageGetObserver
|
|
238 |
void Pbk2ImageGetComplete(
|
|
239 |
MPbk2ImageOperation& aOperation,
|
|
240 |
CFbsBitmap* aBitmap );
|
|
241 |
void Pbk2ImageGetFailed(
|
|
242 |
MPbk2ImageOperation& aOperation,
|
|
243 |
TInt aError );
|
|
244 |
|
|
245 |
private: // From MVPbkContactViewObserver
|
|
246 |
void ContactViewReady( MVPbkContactViewBase& aView );
|
|
247 |
void ContactViewUnavailable( MVPbkContactViewBase& aView );
|
|
248 |
void ContactAddedToView(
|
|
249 |
MVPbkContactViewBase& aView,
|
|
250 |
TInt aIndex,
|
|
251 |
const MVPbkContactLink& aContactLink );
|
|
252 |
void ContactRemovedFromView(
|
|
253 |
MVPbkContactViewBase& aView,
|
|
254 |
TInt aIndex,
|
|
255 |
const MVPbkContactLink& aContactLink );
|
|
256 |
void ContactViewError(
|
|
257 |
MVPbkContactViewBase& aView,
|
|
258 |
TInt aError,
|
|
259 |
TBool aErrorNotified );
|
|
260 |
|
|
261 |
private: // From MPbk2FilteredViewStackObserver
|
|
262 |
void TopViewChangedL( MVPbkContactViewBase& aOldView );
|
|
263 |
void TopViewUpdatedL();
|
|
264 |
void BaseViewChangedL();
|
|
265 |
void ViewStackError( TInt aError );
|
|
266 |
void ContactAddedToBaseView(
|
|
267 |
MVPbkContactViewBase& aBaseView,
|
|
268 |
TInt aIndex,
|
|
269 |
const MVPbkContactLink& aContactLink );
|
|
270 |
|
|
271 |
|
|
272 |
private: //constructors
|
|
273 |
CPbk2ThumbnailManager( CVPbkContactManager& aContactManager );
|
|
274 |
void ConstructL();
|
|
275 |
|
|
276 |
private: //data
|
|
277 |
|
|
278 |
//OWN: thumbnail size
|
|
279 |
TSize iIconSize;
|
|
280 |
|
|
281 |
// internal state
|
|
282 |
TTMLoadingState iState;
|
|
283 |
|
|
284 |
/// Own: thumbnails
|
|
285 |
RPointerArray<CPbk2TmItem> iContactThumbnails;
|
|
286 |
|
|
287 |
/// Own: Loading queue for the thumbnails
|
|
288 |
RPointerArray<CPbk2TmItem> iLoadingQueue;
|
|
289 |
|
|
290 |
/// Own: Thumbnail manager
|
|
291 |
CPbk2ImageManager* iManager;
|
|
292 |
|
|
293 |
// ref:
|
|
294 |
CVPbkContactManager& iContactManager;
|
|
295 |
|
|
296 |
/// Own: Retrieve operation
|
|
297 |
MVPbkContactOperationBase* iRetrieveOperation;
|
|
298 |
|
|
299 |
/// Own: Store contact
|
|
300 |
MVPbkStoreContact* iStoreContact;
|
|
301 |
|
|
302 |
/// Own: Asynchronous thumbnail operation
|
|
303 |
MPbk2ImageOperation* iThumbOperation;
|
|
304 |
|
|
305 |
// REF: observer for the loader
|
|
306 |
MPbk2ThumbnailManagerObserver* iObserver;
|
|
307 |
|
|
308 |
/// Ref: Field type
|
|
309 |
const MVPbkFieldType* iFieldType;
|
|
310 |
|
|
311 |
//REF: listbox icon array
|
|
312 |
CPbk2IconArray* iIconArray;
|
|
313 |
|
|
314 |
// default icon index and id
|
|
315 |
TInt iDefaultIconIndex;
|
|
316 |
TPbk2IconId iDefaultIconId;
|
|
317 |
// icon index counter
|
|
318 |
TInt iIconIdCounter;
|
|
319 |
// loading priority.
|
|
320 |
RArray<MVPbkContactLink*> iPriorityArray;
|
|
321 |
/// Own: Holds the item whose thumbnail load is in progress
|
|
322 |
/// This item needs to be removed when its safe
|
|
323 |
CPbk2TmItem* iInProgressItemToBeRemoved;
|
|
324 |
/// Not own. Filtered view of contacts.
|
|
325 |
MPbk2FilteredViewStack* iView;
|
|
326 |
/// Flag whether cache is clean. Used to prevent unnecessary work when cleaning
|
|
327 |
/// is requested repeatedly
|
|
328 |
TBool iIsCacheClean;
|
|
329 |
};
|
|
330 |
|
|
331 |
#endif /* CPBK2THUMBNAILMANAGER_H_ */
|