|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <eikenv.h> |
|
23 #include <bautils.h> |
|
24 #include <e32math.h> |
|
25 |
|
26 #include "ImageEditorError.h" |
|
27 #include "ImageEditorImageController.h" |
|
28 #include "ImageEditorPluginManager.h" |
|
29 #include "ImageEditorImageHandler.h" |
|
30 #include "ResolutionUtil.h" |
|
31 #include "ImageEditorPanics.h" |
|
32 #include "SystemParameters.h" |
|
33 #include "imageeditordebugutils.h" |
|
34 #include "editorversion.h" |
|
35 #include "commondefs.h" |
|
36 |
|
37 |
|
38 // CONSTANTS |
|
39 |
|
40 // Panic category |
|
41 _LIT(KComponentName, "CImageController"); |
|
42 |
|
43 //============================================================================= |
|
44 CImageController * CImageController::NewL ( |
|
45 MImageControllerObserver * aObserver, |
|
46 CImageEditorPluginManager * aManager |
|
47 ) |
|
48 { |
|
49 CImageController * self = new (ELeave) CImageController; |
|
50 CleanupStack::PushL (self); |
|
51 self->ConstructL (aObserver, aManager); |
|
52 CleanupStack::Pop(); // self |
|
53 return self; |
|
54 } |
|
55 |
|
56 //============================================================================= |
|
57 CImageController::~CImageController () |
|
58 { |
|
59 LOG(KImageEditorLogFile, "CImageController::~CImageController() starting..."); |
|
60 |
|
61 Cancel(); |
|
62 DeletePreviewBitmap(); |
|
63 delete iImageHandler; |
|
64 iManager = NULL; |
|
65 iObserver = NULL; |
|
66 |
|
67 LOG(KImageEditorLogFile, "CImageController::~CImageController() finished."); |
|
68 } |
|
69 |
|
70 //============================================================================= |
|
71 void CImageController::ConstructL ( |
|
72 MImageControllerObserver * aObserver, |
|
73 CImageEditorPluginManager * aManager |
|
74 ) |
|
75 { |
|
76 CActiveScheduler::Add (this); |
|
77 iObserver = aObserver; |
|
78 iManager = aManager; |
|
79 iImageHandler = CImageEditorImageHandler::NewL (); |
|
80 iQuality = KDefaultSavedJpegQuality; |
|
81 iJpegImage = EFalse; |
|
82 iIsCancelled = EFalse; |
|
83 LOG(KImageEditorLogFile, "CImageController: Image controller created"); |
|
84 } |
|
85 |
|
86 |
|
87 //============================================================================= |
|
88 void CImageController::LoadImageL (const TDesC & aFileName) |
|
89 { |
|
90 LOGFMT(KImageEditorLogFile, "CImageController: Loading image %S", &aFileName); |
|
91 |
|
92 iOperation = MImageControllerObserver::EOperationCodeLoad; |
|
93 iIsCancelled = EFalse; |
|
94 |
|
95 // If active, cancel |
|
96 if ( IsActive() ) |
|
97 { |
|
98 Cancel(); |
|
99 } |
|
100 |
|
101 // Create new CFbsBitmap |
|
102 DeletePreviewBitmap(); |
|
103 CreatePreviewBitmapL(); |
|
104 |
|
105 TBool useIPECodec = EFalse; |
|
106 // try open first with IPE ICL codec |
|
107 LOG (KImageEditorLogFile, "CImageController::LoadImageL() -- try open image with ICL"); |
|
108 |
|
109 // Create new TFileName and store it |
|
110 iManager->SetImageName (aFileName); |
|
111 |
|
112 // Load RAJPEG image |
|
113 TRAPD ( err, iManager->LoadImageL( useIPECodec ) ); |
|
114 if ( KErrNone == err ) |
|
115 { |
|
116 LOG (KImageEditorLogFile, "CImageController::LoadImageL() -- image opened with ICL"); |
|
117 // Force RunL() |
|
118 CompleteRequest(); |
|
119 } |
|
120 else |
|
121 { |
|
122 LOG (KImageEditorLogFile, "CImageController::LoadImageL() -- failed open image with ICL"); |
|
123 // Try with IPE codec |
|
124 useIPECodec = ETrue; |
|
125 } |
|
126 |
|
127 if ( useIPECodec ) |
|
128 { |
|
129 // If JPEG source image, try opening with IPE JPEG filter |
|
130 iJpegImage = iImageHandler->IsRajpegImageL (aFileName); |
|
131 |
|
132 if ( !iJpegImage ) |
|
133 { |
|
134 iObserver->OperationReadyL ( iOperation, KSIEEIncompatibleImage ); |
|
135 } |
|
136 else |
|
137 { |
|
138 LOG(KImageEditorLogFile, "CImageController::LoadImageL() -- open JPEG image with IPE"); |
|
139 |
|
140 // Create new TFileName and store it |
|
141 iManager->SetImageName (aFileName); |
|
142 |
|
143 // Load RAJPEG image |
|
144 TRAPD (err, iManager->LoadImageL( useIPECodec )); |
|
145 if (KErrNone == err) |
|
146 { |
|
147 // Force RunL() |
|
148 CompleteRequest(); |
|
149 } |
|
150 else if ((KSIEEIncompatibleImage == err) || (KErrNotSupported == err)) |
|
151 { |
|
152 LOG (KImageEditorLogFile, "CImageController::LoadImageL() -- JPEG not supported"); |
|
153 iObserver->OperationReadyL ( iOperation, err ); |
|
154 } |
|
155 // Added because system runs out of memory if jpeg size is too big |
|
156 // (around 5 Mb) |
|
157 else if ( KErrNoMemory == err ) |
|
158 { |
|
159 LOG (KImageEditorLogFile, "CImageController::LoadImageL() -- Not enough memory to use IPE"); |
|
160 iObserver->OperationReadyL ( iOperation, err ); |
|
161 } |
|
162 else |
|
163 { |
|
164 User::Leave (err); |
|
165 } |
|
166 } |
|
167 } |
|
168 |
|
169 } |
|
170 |
|
171 //============================================================================= |
|
172 void CImageController::SaveImageL (const TDesC & /*aFileName*/) |
|
173 { |
|
174 |
|
175 LOG(KImageEditorLogFile, "CImageController: Saving image"); |
|
176 |
|
177 // Start saving operation |
|
178 iOperation = MImageControllerObserver::EOperationCodeBlockSave; |
|
179 iSavedPercentage = 1; |
|
180 iSavedPercentageOld = 1; |
|
181 iIsCancelled = EFalse; |
|
182 iManager->PrepareAsyncSaveL (iQuality); |
|
183 |
|
184 // Force RunL() |
|
185 CompleteRequest(); |
|
186 } |
|
187 |
|
188 //============================================================================= |
|
189 TInt CImageController::RenameImage ( |
|
190 const TDesC & aFileNameSrc, |
|
191 const TDesC & aFileNameDst |
|
192 ) const |
|
193 { |
|
194 return iImageHandler->RenameImage (aFileNameSrc, aFileNameDst); |
|
195 } |
|
196 |
|
197 //============================================================================= |
|
198 TInt CImageController::DeleteImage (const TDesC & aFileName) const |
|
199 { |
|
200 return iImageHandler->DeleteImage (aFileName); |
|
201 } |
|
202 |
|
203 //============================================================================= |
|
204 void CImageController::DoCancel() |
|
205 { |
|
206 LOG(KImageEditorLogFile, "CImageController::DoCancel"); |
|
207 |
|
208 if( IsActive() ) |
|
209 { |
|
210 iImageHandler->CleanupConverters(); |
|
211 } |
|
212 } |
|
213 |
|
214 //============================================================================= |
|
215 void CImageController::CancelOperation (TBool aForce) |
|
216 { |
|
217 LOGFMT(KImageEditorLogFile, "CImageController::CancelImageController: iOperation == %d", iOperation); |
|
218 |
|
219 iIsCancelled = ETrue; |
|
220 |
|
221 // Handle cancelling block save |
|
222 if (aForce) |
|
223 { |
|
224 CompleteRequest(); |
|
225 } |
|
226 } |
|
227 |
|
228 //============================================================================= |
|
229 void CImageController::RunL () |
|
230 { |
|
231 |
|
232 switch (iOperation) |
|
233 { |
|
234 /// Loading images |
|
235 case MImageControllerObserver::EOperationCodeLoad: |
|
236 { |
|
237 LOG(KImageEditorLogFile, "CImageController: Loading completed"); |
|
238 iObserver->OperationReadyL ( iOperation, iStatus.Int() ); |
|
239 break; |
|
240 } |
|
241 |
|
242 case MImageControllerObserver::EOperationCodeBlockLoad: |
|
243 { |
|
244 LOG(KImageEditorLogFile, "CImageController: Loading completed"); |
|
245 iObserver->OperationReadyL ( iOperation, iStatus.Int() ); |
|
246 break; |
|
247 } |
|
248 |
|
249 /// Block saving images |
|
250 case MImageControllerObserver::EOperationCodeBlockSave: |
|
251 { |
|
252 // Handle cancelling block save |
|
253 if (iIsCancelled) |
|
254 { |
|
255 LOG(KImageEditorLogFile, "CImageController: Saving cancelled"); |
|
256 iManager->SaveAbortL(); |
|
257 iObserver->OperationReadyL ( iOperation, KErrCancel ); |
|
258 } |
|
259 |
|
260 else |
|
261 { |
|
262 // Increment progress bar |
|
263 if ( iSavedPercentage > iSavedPercentageOld ) |
|
264 { |
|
265 iObserver->IncrementProgressBarL (iSavedPercentage - iSavedPercentageOld); |
|
266 iSavedPercentageOld = iSavedPercentage; |
|
267 } |
|
268 |
|
269 // Save next block |
|
270 iSavedPercentage = iManager->SaveBlockL(); |
|
271 |
|
272 // Complete? |
|
273 if (iSavedPercentage == 100) |
|
274 { |
|
275 // Save completed |
|
276 LOG(KImageEditorLogFile, "CImageController: Saving completed"); |
|
277 iManager->FinishAsyncSaveL(); |
|
278 iObserver->OperationReadyL ( iOperation, iStatus.Int() ); |
|
279 } |
|
280 |
|
281 // Save next block |
|
282 else |
|
283 { |
|
284 CompleteRequest(); |
|
285 |
|
286 } |
|
287 } |
|
288 break; |
|
289 } |
|
290 |
|
291 /// Saving images |
|
292 case MImageControllerObserver::EOperationCodeSave: |
|
293 { |
|
294 iObserver->OperationReadyL ( iOperation, iStatus.Int() ); |
|
295 break; |
|
296 } |
|
297 /// Deleting images |
|
298 case MImageControllerObserver::EOperationCodeDelete: |
|
299 /// Renaming images |
|
300 case MImageControllerObserver::EOperationCodeRename: |
|
301 /// Searching images |
|
302 case MImageControllerObserver::EOperationCodeSearch: |
|
303 default: |
|
304 { |
|
305 User::Panic(KComponentName, EImageEditorPanicUnexpectedCommand); |
|
306 break; |
|
307 } |
|
308 } |
|
309 } |
|
310 |
|
311 //============================================================================= |
|
312 CImageController::CImageController () : |
|
313 CActive (CActive::EPriorityStandard) |
|
314 { |
|
315 |
|
316 } |
|
317 |
|
318 |
|
319 //============================================================================= |
|
320 void CImageController::CreatePreviewBitmapL () |
|
321 { |
|
322 LOG(KImageEditorLogFile, "CImageController: Creating preview bitmap"); |
|
323 // Get current screen rect |
|
324 TRect rect; |
|
325 CResolutionUtil::Self()->GetClientRect(rect); |
|
326 TSize size = rect.Size(); |
|
327 |
|
328 LOG(KImageEditorLogFile, "CImageController: Resolution read"); |
|
329 LOGFMT(KImageEditorLogFile, " Width: %d", size.iWidth); |
|
330 LOGFMT(KImageEditorLogFile, " Height: %d", size.iHeight); |
|
331 |
|
332 // Create bitmap |
|
333 if (iPreview) |
|
334 { |
|
335 delete iPreview; |
|
336 iPreview = NULL; |
|
337 } |
|
338 |
|
339 iPreview = new (ELeave) CFbsBitmap; |
|
340 User::LeaveIfError ( iPreview->Create ( size, EColor16M) ); |
|
341 |
|
342 // Set bitmap |
|
343 iManager->SetPreviewImage (iPreview); |
|
344 } |
|
345 |
|
346 //============================================================================= |
|
347 void CImageController::DeletePreviewBitmap() |
|
348 { |
|
349 LOG(KImageEditorLogFile, "CImageController: Deleting preview bitmap"); |
|
350 delete iPreview; |
|
351 iPreview = NULL; |
|
352 iManager->SetPreviewImage (NULL); |
|
353 } |
|
354 |
|
355 //============================================================================= |
|
356 void CImageController::CompleteRequest() |
|
357 { |
|
358 if ( IsActive() ) |
|
359 { |
|
360 Cancel(); |
|
361 } |
|
362 TRequestStatus * p = &iStatus; |
|
363 SetActive(); |
|
364 User::RequestComplete (p, KErrNone); |
|
365 } |
|
366 |
|
367 //============================================================================= |
|
368 void CImageController::CalculateProgressInterval (TInt aBlockCount) |
|
369 { |
|
370 const TInt KMaxProgressSteps = 25; |
|
371 |
|
372 iProgressBarInterval = 1; |
|
373 while( (aBlockCount / iProgressBarInterval) > KMaxProgressSteps ) |
|
374 { |
|
375 iProgressBarInterval++; |
|
376 } |
|
377 |
|
378 LOGFMT(KImageEditorLogFile, "CImageController: Progress bar interval: %d", iProgressBarInterval); |
|
379 } |
|
380 |
|
381 // End of File |