|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "MemSpyExportBitmapsToMemoryCardDialog.h" |
|
19 |
|
20 // System includes |
|
21 #include <eikprogi.h> |
|
22 #include <AknWaitDialog.h> |
|
23 #include <AknQueryDialog.h> |
|
24 #include <coemain.h> |
|
25 #include <eikenv.h> |
|
26 #include <avkon.hrh> |
|
27 #include <memspyui.rsg> |
|
28 |
|
29 // Engine includes |
|
30 #include <memspy/engine/memspyengine.h> |
|
31 #include <memspy/engine/memspyengineobjectthread.h> |
|
32 #include <memspy/engine/memspyengineobjectprocess.h> |
|
33 #include <memspy/engine/memspyengineobjectcontainer.h> |
|
34 #include <memspy/engine/memspyenginehelperchunk.h> |
|
35 #include <memspy/engine/memspyenginehelpercodesegment.h> |
|
36 #include <memspy/engine/memspyenginehelperheap.h> |
|
37 #include <memspy/engine/memspyenginehelperstack.h> |
|
38 #include <memspy/engine/memspyenginehelperthread.h> |
|
39 #include <memspy/engine/memspyenginehelperprocess.h> |
|
40 #include <memspy/engine/memspyenginehelperfbserv.h> |
|
41 |
|
42 // Driver includes |
|
43 #include <memspy/driver/memspydriverenumerationsshared.h> |
|
44 |
|
45 // Literal constants |
|
46 _LIT( KMemSpyBitmapExportFolderAndFileName, "e:\\MemSpy\\Images\\%04d%02d%02d_%02d.%02d.%02d\\"); |
|
47 |
|
48 |
|
49 CMemSpyExportBitmapsToMemoryCardDialog::CMemSpyExportBitmapsToMemoryCardDialog( RFs& aFsSession, const CMemSpyEngineFbServBitmapArray& aBitmaps ) |
|
50 : CActive(EPriorityIdle), iFsSession(aFsSession), iBitmaps(aBitmaps) |
|
51 { |
|
52 CActiveScheduler::Add(this); |
|
53 } |
|
54 |
|
55 |
|
56 CMemSpyExportBitmapsToMemoryCardDialog::~CMemSpyExportBitmapsToMemoryCardDialog() |
|
57 { |
|
58 Cancel(); |
|
59 // |
|
60 delete iProgressDialog; |
|
61 // |
|
62 iMimeTypeArray.ResetAndDestroy(); |
|
63 iMimeTypeArray.Close(); |
|
64 // |
|
65 if ( iEncoder ) |
|
66 { |
|
67 iEncoder->Cancel(); |
|
68 } |
|
69 delete iEncoder; |
|
70 delete iFolderName; |
|
71 delete iBmpMimeType; |
|
72 } |
|
73 |
|
74 |
|
75 void CMemSpyExportBitmapsToMemoryCardDialog::ConstructL() |
|
76 { |
|
77 // Check card is ready |
|
78 if ( CheckMemoryCardAvailableL( iFsSession ) == EFalse ) |
|
79 { |
|
80 User::Leave( KErrNotReady ); |
|
81 } |
|
82 |
|
83 // Get mime type for BMP file |
|
84 IdentifyBmpMimeTypeL(); |
|
85 |
|
86 // Prepare unique empty folder |
|
87 PrepareFolderNameSpecL(); |
|
88 |
|
89 // Prepare UI stuff |
|
90 iProgressDialog = new( ELeave ) CAknProgressDialog( reinterpret_cast< CEikDialog** >( &iProgressDialog ) ); |
|
91 iProgressDialog->SetCallback( this ); |
|
92 iProgressDialog->SetGloballyCapturing( ETrue ); |
|
93 iProgressDialog->PrepareLC( R_MEMSPY_EXPORT_TO_MEMORYCARD_DIALOG ); |
|
94 // |
|
95 iProgressInfo = iProgressDialog->GetProgressInfoL( ); |
|
96 iProgressInfo->SetFinalValue( iBitmaps.Count() ); |
|
97 // |
|
98 iProgressDialog->MakeVisible( ETrue ); // Visible right away |
|
99 // |
|
100 iDialogDismissed = EFalse; |
|
101 iProgressInfo->SetAndDraw( 0 ); |
|
102 |
|
103 // Start the process rolling... |
|
104 CompleteSelf(KErrNone); |
|
105 |
|
106 // |
|
107 iProgressDialog->RunLD( ); |
|
108 } |
|
109 |
|
110 |
|
111 CMemSpyExportBitmapsToMemoryCardDialog* CMemSpyExportBitmapsToMemoryCardDialog::NewL( RFs& aFsSession, const CMemSpyEngineFbServBitmapArray& aBitmaps ) |
|
112 { |
|
113 CMemSpyExportBitmapsToMemoryCardDialog* self = new(ELeave) CMemSpyExportBitmapsToMemoryCardDialog( aFsSession, aBitmaps ); |
|
114 CleanupStack::PushL( self ); |
|
115 self->ConstructL(); |
|
116 CleanupStack::Pop( self ); |
|
117 return self; |
|
118 } |
|
119 |
|
120 |
|
121 void CMemSpyExportBitmapsToMemoryCardDialog::Cancel() |
|
122 { |
|
123 CActive::Cancel(); |
|
124 } |
|
125 |
|
126 |
|
127 TBool CMemSpyExportBitmapsToMemoryCardDialog::CheckMemoryCardAvailableL( RFs& aFsSession ) |
|
128 { |
|
129 TBool available = EFalse; |
|
130 // |
|
131 TDriveInfo driveInfo; |
|
132 if ( aFsSession.Drive( driveInfo, EDriveE ) == KErrNone ) |
|
133 { |
|
134 // Other checks needed? |
|
135 available = ETrue; |
|
136 } |
|
137 // |
|
138 return available; |
|
139 } |
|
140 |
|
141 |
|
142 void CMemSpyExportBitmapsToMemoryCardDialog::RunL() |
|
143 { |
|
144 const TInt error = iStatus.Int(); |
|
145 User::LeaveIfError( error ); |
|
146 |
|
147 if ( !iDialogDismissed ) |
|
148 { |
|
149 // Do we have more items to process? |
|
150 if ( TryToExportSingleBitmapL() ) |
|
151 { |
|
152 _LIT(KTextFormat, "Saving image\n%d/%d"); |
|
153 TBuf<128> buf; |
|
154 buf.Format( KTextFormat, iBitmapIndex, iBitmaps.Count() ); |
|
155 // |
|
156 iProgressDialog->SetTextL( buf ); |
|
157 iProgressInfo->SetAndDraw( iBitmapIndex ); |
|
158 iProgressDialog->DrawDeferred(); |
|
159 } |
|
160 else |
|
161 { |
|
162 // We're done - RunL will not be called again |
|
163 if (iProgressInfo) |
|
164 { |
|
165 const TInt finalValue = iProgressInfo->Info().iFinalValue; |
|
166 iProgressInfo->SetAndDraw( finalValue ); |
|
167 // |
|
168 delete iProgressDialog; |
|
169 iProgressDialog = NULL; |
|
170 // |
|
171 delete this; |
|
172 } |
|
173 } |
|
174 |
|
175 User::ResetInactivityTime(); |
|
176 } |
|
177 else |
|
178 { |
|
179 delete iProgressDialog; |
|
180 iProgressDialog = NULL; |
|
181 // |
|
182 delete this; |
|
183 } |
|
184 } |
|
185 |
|
186 |
|
187 void CMemSpyExportBitmapsToMemoryCardDialog::DoCancel() |
|
188 { |
|
189 if ( iEncoder ) |
|
190 { |
|
191 iEncoder->Cancel(); |
|
192 } |
|
193 |
|
194 iDialogDismissed = ETrue; |
|
195 } |
|
196 |
|
197 |
|
198 TInt CMemSpyExportBitmapsToMemoryCardDialog::RunError( TInt /*aError*/ ) |
|
199 { |
|
200 TRAP_IGNORE( |
|
201 |
|
202 // Try the next image |
|
203 if ( TryToExportSingleBitmapL() == EFalse ) |
|
204 { |
|
205 iDialogDismissed = ETrue; |
|
206 delete this; |
|
207 } |
|
208 ); |
|
209 // |
|
210 return KErrNone; |
|
211 } |
|
212 |
|
213 |
|
214 void CMemSpyExportBitmapsToMemoryCardDialog::DialogDismissedL( TInt /*aButtonId*/ ) |
|
215 { |
|
216 iDialogDismissed = ETrue; |
|
217 iProgressDialog = NULL; |
|
218 } |
|
219 |
|
220 |
|
221 void CMemSpyExportBitmapsToMemoryCardDialog::CompleteSelf( TInt aError ) |
|
222 { |
|
223 TRequestStatus* status = &iStatus; |
|
224 User::RequestComplete( status, aError ); |
|
225 SetActive(); |
|
226 } |
|
227 |
|
228 |
|
229 void CMemSpyExportBitmapsToMemoryCardDialog::ExportBitmapL( const CMemSpyEngineFbServBitmap& aBitmap ) |
|
230 { |
|
231 // Create a filename |
|
232 TFileName fileName( *iFolderName ); |
|
233 aBitmap.GetExportableFileNameL( fileName ); |
|
234 |
|
235 // Create encoder object... |
|
236 CImageEncoder* encoder = CImageEncoder::FileNewL( iFsSession, fileName, *iBmpMimeType ); |
|
237 delete iEncoder; |
|
238 iEncoder = encoder; |
|
239 |
|
240 // Start operation |
|
241 iEncoder->Convert( &iStatus, aBitmap.Bitmap() ); |
|
242 SetActive(); |
|
243 } |
|
244 |
|
245 |
|
246 void CMemSpyExportBitmapsToMemoryCardDialog::IdentifyBmpMimeTypeL() |
|
247 { |
|
248 _LIT(KBmpExtension, ".bmp"); |
|
249 CImageEncoder::GetFileTypesL( iMimeTypeArray ); |
|
250 // |
|
251 const TInt count = iMimeTypeArray.Count(); |
|
252 // |
|
253 for( TInt i=0; i<count; i++ ) |
|
254 { |
|
255 CFileExtensionMIMEType* extension = iMimeTypeArray[ i ]; |
|
256 if ( extension->FileExtension().FindF( KBmpExtension ) >= 0 ) |
|
257 { |
|
258 // Found it - save mime type info |
|
259 iBmpMimeType = extension->MIMEType().AllocL(); |
|
260 iMimeTypeArray.ResetAndDestroy(); |
|
261 iMimeTypeArray.Close(); |
|
262 return; |
|
263 } |
|
264 } |
|
265 // |
|
266 User::Leave( KErrNotFound ); |
|
267 } |
|
268 |
|
269 |
|
270 void CMemSpyExportBitmapsToMemoryCardDialog::PrepareFolderNameSpecL() |
|
271 { |
|
272 delete iFolderName; |
|
273 iFolderName = NULL; |
|
274 |
|
275 // Make a unique filename format specifier. |
|
276 TTime now; |
|
277 now.HomeTime(); |
|
278 const TDateTime dt( now.DateTime() ); |
|
279 |
|
280 // Build it up... |
|
281 iFolderName = HBufC::NewL( KMaxFileName ); |
|
282 TPtr pName( iFolderName->Des() ); |
|
283 pName.Format( KMemSpyBitmapExportFolderAndFileName, dt.Year(), dt.Month()+1, dt.Day()+1, dt.Hour(), dt.Minute(), dt.Second()); |
|
284 |
|
285 // Create directory |
|
286 const TInt error = iFsSession.MkDirAll( pName ); |
|
287 User::LeaveIfError( error ); |
|
288 } |
|
289 |
|
290 |
|
291 TBool CMemSpyExportBitmapsToMemoryCardDialog::TryToExportSingleBitmapL() |
|
292 { |
|
293 TBool startedExport = EFalse; |
|
294 |
|
295 const TInt count = iBitmaps.Count(); |
|
296 for( ; ( iBitmapIndex < count ) && ( startedExport == EFalse ); iBitmapIndex++ ) |
|
297 { |
|
298 const CMemSpyEngineFbServBitmap& memSpyBitmap = iBitmaps.At( iBitmapIndex ); |
|
299 const CFbsBitmap& fbsBitmap = memSpyBitmap.Bitmap(); |
|
300 const TSize size( fbsBitmap.SizeInPixels() ); |
|
301 |
|
302 // We don't want to export bitmaps which have a zero-pixel dimension. |
|
303 if ( size.iHeight > 0 && size.iWidth > 0 ) |
|
304 { |
|
305 // This completes the object's request status and will therefore |
|
306 // result in a further call to RunL() when the export to BMP |
|
307 // is completed. |
|
308 ExportBitmapL( memSpyBitmap ); |
|
309 |
|
310 // And indicate we managed to start an operation... |
|
311 startedExport = ETrue; |
|
312 } |
|
313 } |
|
314 // |
|
315 return startedExport; |
|
316 } |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |