1 /* |
|
2 * Copyright (c) 2007-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: Active object that manages saving and deletion of images* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CAMIMAGESAVEACTIVE_H |
|
21 #define CAMIMAGESAVEACTIVE_H |
|
22 |
|
23 // INCLUDES |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <badesca.h> |
|
27 #include <f32file.h> |
|
28 #include <thumbnailmanager.h> |
|
29 #include <thumbnailmanagerobserver.h> |
|
30 |
|
31 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__) |
|
32 #include <harvesterclient.h> |
|
33 #endif // defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__) |
|
34 |
|
35 // DATA TYPES |
|
36 /** |
|
37 * Save event type |
|
38 */ |
|
39 enum TCamSaveEvent |
|
40 { |
|
41 ECamSaveEventStarted, |
|
42 ECamSaveEventComplete, |
|
43 ECamSaveEventBurstComplete, |
|
44 ECamSaveEventUserCancelled, |
|
45 ECamSaveEventDeleted, |
|
46 ECamSaveEventSaveError, |
|
47 ECamSaveEventCriticalError |
|
48 }; |
|
49 |
|
50 // CONSTANTS |
|
51 #ifdef _DEBUG |
|
52 const TUint16* const KCamSaveEventNames[] = |
|
53 { |
|
54 (const TUint16* const)_S16("ECamSaveEventStarted"), |
|
55 (const TUint16* const)_S16("ECamSaveEventComplete"), |
|
56 (const TUint16* const)_S16("ECamSaveEventBurstComplete"), |
|
57 (const TUint16* const)_S16("ECamSaveEventUserCancelled"), |
|
58 (const TUint16* const)_S16("ECamSaveEventDeleted") |
|
59 }; |
|
60 #endif |
|
61 |
|
62 // FORWARD DECLARATIONS |
|
63 class CAknProgressDialog; |
|
64 class CEikProgressInfo; |
|
65 class CCamBufferShare; |
|
66 class CCamAppController; |
|
67 class CCamBurstCaptureArray; |
|
68 |
|
69 // CLASS DECLARATIONS |
|
70 |
|
71 /** |
|
72 * Abstract API for image save observer. |
|
73 * Provides an asynchronous 'callback' method to inform derived classes |
|
74 * that the save operation has been completed. |
|
75 * |
|
76 * @since 2.8 |
|
77 */ |
|
78 class MCamImageSaveObserver |
|
79 { |
|
80 public: |
|
81 /** |
|
82 * The image saving operation has completed |
|
83 * @since 2.8 |
|
84 * @param aEvent the type of event |
|
85 */ |
|
86 virtual void HandleSaveEvent( TCamSaveEvent aEvent ) = 0; |
|
87 |
|
88 /** |
|
89 * |
|
90 */ |
|
91 virtual void HandleFileHarvestingComplete() = 0; |
|
92 }; |
|
93 |
|
94 /** |
|
95 * Class to manage the asynchronous saving and synchronous deletion |
|
96 * of images. |
|
97 * @since 2.8 |
|
98 */ |
|
99 class CCamImageSaveActive : public CActive |
|
100 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__) |
|
101 ,private MHarvestObserver |
|
102 #endif // defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__) |
|
103 , public MThumbnailManagerObserver |
|
104 { |
|
105 public: // Constructors and destructor |
|
106 |
|
107 /** |
|
108 * Two-phased constructor. |
|
109 * @since 2.8 |
|
110 * @param aObserver Informed when image saving has completed |
|
111 */ |
|
112 static CCamImageSaveActive* NewL( MCamImageSaveObserver& aObserver, |
|
113 CCamAppController& aController ); |
|
114 |
|
115 /** |
|
116 * Destructor. |
|
117 */ |
|
118 virtual ~CCamImageSaveActive(); |
|
119 |
|
120 public: // Functions from base classes |
|
121 |
|
122 /** |
|
123 * From CActive, cancels the active object |
|
124 * Deletes all files remaining in the save arrays except any currently |
|
125 * saving file. If currently saving, the active object waits until the |
|
126 * save completes then performs cleanup.. This method is synchronous |
|
127 * even when it involves a wait for save completion. |
|
128 * @since 2.8 |
|
129 */ |
|
130 void Cancel(); |
|
131 |
|
132 public: // New functions |
|
133 |
|
134 /** |
|
135 * A request for a file to be saved asynchronously, will be scheduled |
|
136 * immediately if no other save is current, otherwise the save is queued |
|
137 * @since 2.8 |
|
138 * @param aFilename the full path and filename to save the image to |
|
139 * @param aImageData the image data to save |
|
140 * @return Whether or not the image data has been successfully added |
|
141 * to the pending save list. |
|
142 */ |
|
143 TBool AddToSave( const TDesC& aFilename, |
|
144 CCamBufferShare* aImageData ); |
|
145 |
|
146 /** |
|
147 * A request for a file to be deleted. Will prevent any pending save. |
|
148 * If the file to delete is currently saving the deletion will occur |
|
149 * when the save operation completes. |
|
150 * @since 2.8 |
|
151 * @param aFilename the full path and name of the file to be deleted |
|
152 * @param aSaveRequested whether or not a previous request to save this file |
|
153 * has been made. |
|
154 * @return System wide error code to indicate success or failure of the deletion |
|
155 */ |
|
156 TInt DeleteFile( const TDesC& aFilename, TBool aSaveRequested ); |
|
157 |
|
158 /** |
|
159 * Returns whether a particular file has already been saved. |
|
160 * @since 2.8 |
|
161 * @param aFilename the name of the file to check. |
|
162 * @return ETrue if the file has been saved. |
|
163 */ |
|
164 TBool AlreadySavedFile( const TDesC& aFilename ) const; |
|
165 |
|
166 /** |
|
167 * Returns whether a particular file is in the process of being saved. |
|
168 * @since 2.8 |
|
169 * @param aFilename the name of the file to check. |
|
170 * @return ETrue if the file is in the process of being saved. |
|
171 */ |
|
172 TBool CurrentlySavingFile( const TDesC& aFilename ) const; |
|
173 |
|
174 /** |
|
175 * A request for the progress note to be displayed |
|
176 * @since 2.8 |
|
177 * @param aExpectedImages the number of images to be saved |
|
178 */ |
|
179 void DisplayProgressNote( TInt aExpectedImages ); |
|
180 |
|
181 /** |
|
182 * A request for the progress note to be dismissed when the save completes |
|
183 * @since 2.8 |
|
184 */ |
|
185 void DismissProgressNote(); |
|
186 |
|
187 /** |
|
188 * Set the "Add to album" setting for photos |
|
189 * determines whether or not photos are added to the default capture album |
|
190 * after a successful save |
|
191 * @since 2.8 |
|
192 * @param aAdding ETrue if "Add to album" is on, otherwise EFalse |
|
193 */ |
|
194 void SetAddImageToAlbum( const TBool aAdding, |
|
195 const TUint32 aDefaultAlbumId ); |
|
196 |
|
197 /** |
|
198 * Add the specified file to the default capture album |
|
199 * Called internally for images when save completes. Called externally for |
|
200 * videos as video saving is handled elsewhere. Calls AddToAlbumL(). |
|
201 * @since 2.8 |
|
202 * @param aFilename The photo or video to add to the capture album |
|
203 * @param aPhoto Indicates if the specified file is a photo or video |
|
204 */ |
|
205 void AddToAlbum( const TDesC& aFilename, |
|
206 const TBool aPhoto, |
|
207 const TUint32 aDefaultAlbumId ); |
|
208 |
|
209 /** |
|
210 * The number of items in the saving arrays |
|
211 * @since 2.8 |
|
212 * @return A count of items |
|
213 */ |
|
214 TInt Count() const; |
|
215 |
|
216 /** |
|
217 * Retrieves the file size of the specified file. |
|
218 * @since 3.0 |
|
219 * @param aFilename The file to return the size of. |
|
220 * @return The size of the file in bytes, or KErrNotFound |
|
221 */ |
|
222 TInt FileSize( const TDesC& aFilename ) const; |
|
223 |
|
224 /** |
|
225 * Stores filename and snapshot handle for thumbnail creation |
|
226 */ |
|
227 void CreateThumbnailsL( const CCamBurstCaptureArray& aArray ); |
|
228 |
|
229 /** |
|
230 * Calls thumbnailmanager to create thumbnails |
|
231 */ |
|
232 void DoCreateThumbnailL(); |
|
233 |
|
234 /** |
|
235 * Cancels thumbnail creation for a given snapshot. |
|
236 * @param aSnapshotIndex Index of the snapshot in burst array. |
|
237 */ |
|
238 void CancelThumbnail( TInt aSnapshotIndex ); |
|
239 |
|
240 void ForceCancel(); |
|
241 /** |
|
242 * From MThumbnailManagerObserver, not used |
|
243 */ |
|
244 void ThumbnailPreviewReady( MThumbnailData& aThumbnail, |
|
245 TThumbnailRequestId aId ); |
|
246 |
|
247 /** |
|
248 * From MThumbnailManagerObserver, not used |
|
249 */ |
|
250 void ThumbnailReady( TInt aError, |
|
251 MThumbnailData& aThumbnail, |
|
252 TThumbnailRequestId aId ); |
|
253 |
|
254 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__) |
|
255 /* |
|
256 * RegisterForHarvesterEvents |
|
257 */ |
|
258 void RegisterForHarvesterEvents(); |
|
259 |
|
260 /* |
|
261 * DeRegisterHarverterClientEvents |
|
262 */ |
|
263 void DeRegisterHarverterClientEvents(); |
|
264 |
|
265 private: // From MHarvestObserver |
|
266 |
|
267 /* |
|
268 * HarvestingComplete |
|
269 */ |
|
270 void HarvestingComplete( TDesC& aURI |
|
271 #ifdef RD_MDS_2_5 |
|
272 , TInt aError |
|
273 #endif //RD_MDS_2_5 |
|
274 ); |
|
275 |
|
276 #endif // defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__) |
|
277 |
|
278 private: |
|
279 |
|
280 /** |
|
281 * Constructor |
|
282 * @since 2.8 |
|
283 * @param aObserver Informed when image saving has completed |
|
284 */ |
|
285 CCamImageSaveActive( MCamImageSaveObserver& aObserver, |
|
286 CCamAppController& aController ); |
|
287 |
|
288 /** |
|
289 * 2nd phase construction |
|
290 * @since 2.8 |
|
291 */ |
|
292 void ConstructL(); |
|
293 |
|
294 /** |
|
295 * Schedule to run immediately |
|
296 * @since 2.8 |
|
297 */ |
|
298 void SetActiveAndCompleteRequest(); |
|
299 |
|
300 /** |
|
301 * Cancels the active object |
|
302 * @since 2.8 |
|
303 */ |
|
304 void DoCancel(); |
|
305 |
|
306 /** |
|
307 * Perform the next scheduled task |
|
308 * @since 2.8 |
|
309 */ |
|
310 void RunL(); |
|
311 |
|
312 /** |
|
313 * Handle leave in RunL. |
|
314 * @param aError The error (leave) code from RunL. |
|
315 */ |
|
316 TInt RunError( TInt aError ); |
|
317 |
|
318 /** |
|
319 * Tidy up after a previous save has completed |
|
320 * @param aDoFlush Should an asyncrhonous flush be done |
|
321 * @since 2.8 |
|
322 */ |
|
323 void CompleteSaveOperation( TBool aDoFlush ); |
|
324 |
|
325 /** |
|
326 * Carry out the next pending save operation |
|
327 * @since 2.8 |
|
328 */ |
|
329 void DoSaveL(); |
|
330 |
|
331 /** |
|
332 * Display the progress note |
|
333 * @since 2.8 |
|
334 */ |
|
335 void DoDisplayProgressNoteL(); |
|
336 |
|
337 /** |
|
338 * Dismiss the progress note when the saves have completed |
|
339 * @since 2.8 |
|
340 */ |
|
341 void DoDismissProgressNote(); |
|
342 |
|
343 /** |
|
344 * Indicate to observers that saving has completed |
|
345 * @param aEvent the cause of completion |
|
346 * @since 2.8 |
|
347 */ |
|
348 void ReportToObserver( TCamSaveEvent aEvent ); |
|
349 |
|
350 /** |
|
351 * Helper method to release all the shared buffers in the array. |
|
352 */ |
|
353 void ReleaseAllAndDestroy( RPointerArray<CCamBufferShare>& aArray ); |
|
354 |
|
355 |
|
356 private: |
|
357 |
|
358 MCamImageSaveObserver& iObserver; // informed when image saving has completed |
|
359 CCamAppController& iController; |
|
360 |
|
361 CDesCArray* iSaveArray; // reserved filenames |
|
362 RPointerArray<CCamBufferShare> iImageArray; // image data (order reflects iSaveArray) |
|
363 CDesCArray* iNameArray; // filenames for thumbnail creation |
|
364 RPointerArray<CFbsBitmap> iSnapArray; // snapshots for thumbnail creation |
|
365 CThumbnailManager* iManager; // TN manager |
|
366 |
|
367 RFile iFile; // Handle to a file object |
|
368 TBool iSaveCurrent; // Indicates if a saving operation is ongoing |
|
369 TBool iDeleteCurrent; // If the currently saving file needs deleting |
|
370 TBool iDoCancel; // If further saves should be cancelled |
|
371 TBool iShowNote; // If the progress note should be displayed |
|
372 TBool iDismissNote; // If the progress note should be dismissed |
|
373 // when all saves complete |
|
374 TInt iExpectedImages; // The number of images expected for progress info |
|
375 TInt iSaveProgressCount; // The count of images saved for this progress |
|
376 TBool iCompletedBurst; // If a set of burst images has completed |
|
377 CActiveSchedulerWait iWait; // To make asychronous synchronous during cancellation |
|
378 // Progress note shown when the applicaiton must wait for saving to complete |
|
379 CAknProgressDialog* iSaveProgressDialog; |
|
380 // The progress bar shown in iSaveProgressDialog |
|
381 CEikProgressInfo* iSaveProgressInfo; |
|
382 TBool iAddImageToAlbum; // Whether or not images should be added to album |
|
383 TUint32 iDefaultAlbumId; // To store the default album id from appcontroller |
|
384 TBool iFlushing; |
|
385 RArray<TThumbnailRequestId> iThumbnailRequests; // thumbnail request ids |
|
386 |
|
387 #if defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__) |
|
388 RHarvesterClient iHarvesterClient; |
|
389 TBool iRegisteredForHarvesterEvents; |
|
390 TBool iHarvesterClientConnected; |
|
391 #endif // defined(RD_MDS_2_5) && !defined(__WINSCW__) && !defined(__WINS__) |
|
392 }; |
|
393 |
|
394 #endif // CAMIMAGESAVEACTIVE_H |
|
395 |
|
396 // End of File |
|