|
1 /* |
|
2 * Copyright (c) 2008 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: avatar selection handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "cvimpstuiavatarselectionhandler.h" |
|
23 #include "vimpstui.hrh" |
|
24 #include "vimpstutilsdialog.h" |
|
25 #include "tvimpstconsts.h" |
|
26 |
|
27 #include <StringLoader.h> |
|
28 #include <vimpstuires.rsg> |
|
29 #include <NewFileServiceClient.h> |
|
30 #include <AiwGenericParam.h> |
|
31 #include <MGFetch.h> |
|
32 #include <DocumentHandler.h> |
|
33 #include <eikenv.h> |
|
34 #include <imageconversion.h> |
|
35 #include <aknnavi.h> |
|
36 #include <aknappui.h> |
|
37 #include <avkon.rsg> |
|
38 #include <caf/content.h> |
|
39 #include <caf/manager.h> // content access |
|
40 #include "uiservicetabtracer.h" |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CAvatarSelectionHandler::CAvatarSelectionHandler |
|
46 // C++ default constructor can NOT contain any code, that |
|
47 // might leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CAvatarSelectionHandler::CAvatarSelectionHandler() |
|
51 : CActive( CActive::EPriorityLow ) |
|
52 { |
|
53 CActiveScheduler::Add( this ); |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CAvatarSelectionHandler::ConstructL |
|
58 // Symbian 2nd phase constructor can leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void CAvatarSelectionHandler::ConstructL() |
|
62 { |
|
63 TRACER_AUTO; |
|
64 User::LeaveIfError(iApaSession.Connect() ); |
|
65 |
|
66 // create dochandler |
|
67 iDocHandler = CDocumentHandler::NewL(); |
|
68 iDocHandler->SetExitObserver( this); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CAvatarSelectionHandler::NewL |
|
73 // Two-phased constructor. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CAvatarSelectionHandler* CAvatarSelectionHandler::NewLC() |
|
77 |
|
78 { |
|
79 TRACER_AUTO; |
|
80 CAvatarSelectionHandler* self = new( ELeave ) CAvatarSelectionHandler(); |
|
81 |
|
82 CleanupStack::PushL(self); |
|
83 self->ConstructL(); |
|
84 |
|
85 return self; |
|
86 } |
|
87 |
|
88 // Destructor |
|
89 CAvatarSelectionHandler::~CAvatarSelectionHandler() |
|
90 { |
|
91 Cancel(); |
|
92 |
|
93 delete iDecoder; |
|
94 iDecoder = NULL; |
|
95 |
|
96 delete iDocHandler; |
|
97 iDocHandler = NULL; |
|
98 |
|
99 iApaSession.Close(); |
|
100 if (iWait.IsStarted() ) |
|
101 { |
|
102 iWait.AsyncStop(); |
|
103 } |
|
104 delete iMimeType; |
|
105 } |
|
106 |
|
107 //----------------------------------------------------------------------------- |
|
108 // CAvatarSelectionHandler::RunL |
|
109 // ( Other items commented in header ) |
|
110 //----------------------------------------------------------------------------- |
|
111 void CAvatarSelectionHandler::RunL() |
|
112 { |
|
113 if (iWait.IsStarted() ) |
|
114 { |
|
115 iWait.AsyncStop(); |
|
116 } |
|
117 } |
|
118 |
|
119 //----------------------------------------------------------------------------- |
|
120 // CAvatarSelectionHandler::DoCancel |
|
121 // ( Other items commented in header ) |
|
122 //----------------------------------------------------------------------------- |
|
123 void CAvatarSelectionHandler::DoCancel() |
|
124 { |
|
125 iDecoder->Cancel(); |
|
126 } |
|
127 |
|
128 //----------------------------------------------------------------------------- |
|
129 // CAvatarSelectionHandler::RunError |
|
130 // ( Other items commented in header ) |
|
131 //----------------------------------------------------------------------------- |
|
132 TInt CAvatarSelectionHandler::RunError(TInt aError) |
|
133 { |
|
134 if (IsActive() ) |
|
135 { |
|
136 iStatus = aError; |
|
137 Cancel(); |
|
138 } |
|
139 |
|
140 if (aError == KErrNoMemory) |
|
141 { |
|
142 CActiveScheduler::Current()->Error(KErrNoMemory); |
|
143 } |
|
144 |
|
145 return KErrNone; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------- |
|
149 // CAvatarSelectionHandler::HandleServerAppExit |
|
150 // (other items were commented in a header). |
|
151 // --------------------------------------------------------- |
|
152 // |
|
153 void CAvatarSelectionHandler::HandleServerAppExit(TInt aReason) |
|
154 { |
|
155 TRACER_AUTO; |
|
156 iServerAppExitReason = aReason; |
|
157 if (iWait.IsStarted() ) |
|
158 { |
|
159 iWait.AsyncStop(); |
|
160 } |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------- |
|
164 // CAvatarSelectionHandler::VerifySelectedFilesL |
|
165 // (other items were commented in a header). |
|
166 // --------------------------------------------------------- |
|
167 // |
|
168 TBool CAvatarSelectionHandler::VerifySelectedFilesL( const MDesCArray* aSelectedFiles ) |
|
169 |
|
170 { |
|
171 TRACER_AUTO; |
|
172 if( aSelectedFiles && aSelectedFiles->MdcaCount() ) |
|
173 { |
|
174 TPtrC filename( aSelectedFiles->MdcaPoint(0) ); // since muliselection is not allowed |
|
175 //take the only file in the array |
|
176 TInt value( KErrNone ); |
|
177 ContentAccess::CContent* content = ContentAccess::CContent::NewL( filename ); |
|
178 // check for protetected image |
|
179 TInt err( content->GetAttribute( ContentAccess::EIsProtected, value ) ); |
|
180 delete content; |
|
181 |
|
182 if( err == KErrNone && value ) // protected |
|
183 { |
|
184 // show note |
|
185 ShowErrorL(EProtected); |
|
186 } |
|
187 else // not protected |
|
188 { |
|
189 delete iDecoder; // delete decoder if there is any |
|
190 iDecoder = NULL; |
|
191 |
|
192 TInt params(CImageDecoder::EPreferFastDecode); |
|
193 TRAPD( err, iDecoder = CImageDecoder::FileNewL( |
|
194 CEikonEnv::Static()->FsSession(),filename, |
|
195 static_cast<CImageDecoder::TOptions>(params) )); |
|
196 if( err == KErrNone ) |
|
197 { |
|
198 // file seems ok, try to decode image |
|
199 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap(); |
|
200 CleanupStack::PushL( bitmap ); |
|
201 |
|
202 TFrameInfo frame = iDecoder->FrameInfo(); |
|
203 TSize decodeSize( 60,60 ); |
|
204 |
|
205 TInt bitmaperr = bitmap->Create( decodeSize, frame.iFrameDisplayMode ); |
|
206 |
|
207 if( bitmaperr ) |
|
208 { // any bit mapp error throw error and return EFalse |
|
209 CActiveScheduler::Current()->Error( bitmaperr ); |
|
210 CleanupStack::PopAndDestroy( bitmap ); |
|
211 return EFalse; |
|
212 } |
|
213 // start converting |
|
214 iDecoder->Convert( &iStatus, *bitmap ); |
|
215 if( !IsActive() ) |
|
216 { |
|
217 SetActive(); |
|
218 } |
|
219 |
|
220 // and wait until it's finished |
|
221 if( !iWait.IsStarted() ) |
|
222 { |
|
223 iWait.Start(); // iWait is not an active object |
|
224 } |
|
225 |
|
226 TInt statuscode = iStatus.Int(); |
|
227 CleanupStack::PopAndDestroy( bitmap ); |
|
228 |
|
229 if( statuscode == KErrCorrupt ) // image corrupted |
|
230 { |
|
231 // show note |
|
232 ShowErrorL( ECorrupted ); |
|
233 return EFalse; |
|
234 } |
|
235 |
|
236 return ETrue; // selected file is ok ,return ETrue |
|
237 } |
|
238 else |
|
239 { |
|
240 ShowErrorL( ECorrupted ); |
|
241 } |
|
242 |
|
243 } |
|
244 |
|
245 } |
|
246 return EFalse; // no files or protected file return EFalse |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------- |
|
250 // CAvatarSelectionHandler::DecodeSize |
|
251 // (other items were commented in a header). |
|
252 // --------------------------------------------------------- |
|
253 // |
|
254 TSize CAvatarSelectionHandler::DecodeSize(const TSize& aSize) |
|
255 { |
|
256 TRACER_AUTO; |
|
257 // 1:1 is always valid ratio for decode scaling |
|
258 TInt lastValidRatio( 1); |
|
259 for (TInt ratio(KDecodeScaleRatioMin); ratio <= KDecodeScaleRatioMax; ratio<<= 1) |
|
260 { |
|
261 if (aSize.iWidth % ratio + aSize.iHeight % ratio == 0) |
|
262 { |
|
263 // this ratio is valid |
|
264 lastValidRatio = ratio; |
|
265 } |
|
266 } |
|
267 |
|
268 // return the size scaled with correct ratio |
|
269 return TSize(aSize.iWidth / lastValidRatio, aSize.iHeight |
|
270 / lastValidRatio); |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------- |
|
274 // CAvatarSelectionHandler::HandleAvatarSelectionL() |
|
275 // (other items were commented in a header). |
|
276 // --------------------------------------------------------- |
|
277 // |
|
278 HBufC* CAvatarSelectionHandler::HandleAvatarSelectionL(TInt aCommand ) |
|
279 { |
|
280 TRACER_AUTO; |
|
281 HBufC* selectedFile = NULL; |
|
282 switch (aCommand) |
|
283 { |
|
284 case ECmdAvatarGallery: |
|
285 { |
|
286 CDesCArray* files = new( ELeave )CDesCArrayFlat(1); |
|
287 CleanupStack::PushL(files); |
|
288 CDesCArray* mimeTypes = new ( ELeave ) CDesCArrayFlat(1 ); |
|
289 CleanupStack::PushL( mimeTypes ); |
|
290 |
|
291 mimeTypes->AppendL( KJPegType ); |
|
292 mimeTypes->AppendL( KGifType ); |
|
293 mimeTypes->AppendL( KPngType ); |
|
294 |
|
295 HBufC* softkey = CCoeEnv::Static()->AllocReadResourceLC( |
|
296 R_QTN_SERVTAB_GALLERY_LSK_SELECT); |
|
297 |
|
298 HBufC* title = CCoeEnv::Static()->AllocReadResourceLC( |
|
299 R_QTN_SERVTAB_GALLERY_TITLE_AVATAR); |
|
300 // This is to clear the NaviPane(Pane where Service Tabs are displayed) |
|
301 // before launching the avatar selection dialogue from photos fetcher. |
|
302 // since photos fetcher does't take care of clearing the Navi pane. |
|
303 CEikStatusPane* statusPane = CEikonEnv::Static()->AppUiFactory()->StatusPane(); // Get the StatusPane |
|
304 CAknNavigationControlContainer* naviPane = static_cast<CAknNavigationControlContainer*>(statusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) ); |
|
305 CAknNavigationDecorator* naviDecoration = naviPane->Top(); // Get the current NaviPane |
|
306 naviPane->PushDefaultL( EFalse ); // Clear the NaviPane |
|
307 // Launching Avatar Selection |
|
308 if (MGFetch::RunL( *files, EImageFile, EFalse, *softkey, |
|
309 *title, mimeTypes , NULL) ) |
|
310 { |
|
311 if(VerifySelectedFilesL(files)) |
|
312 { |
|
313 selectedFile = (files->MdcaPoint(0)).AllocL(); // alloclate for first filename |
|
314 StoreMimeTypeL(*selectedFile); // get the mime type and store |
|
315 } |
|
316 } |
|
317 CleanupStack::PopAndDestroy( 4); // title, softkey ,mimeTypes ,files |
|
318 naviPane->PushL(*naviDecoration); // Restoring the previous Navipane |
|
319 break; |
|
320 } |
|
321 case ECmdAvatarNewPhoto: |
|
322 { |
|
323 CDesCArray* fileNames = new( ELeave )CDesCArrayFlat(1); |
|
324 CleanupStack::PushL(fileNames); |
|
325 CNewFileServiceClient* newFile = NewFileServiceFactory::NewClientL(); |
|
326 CleanupStack::PushL(newFile); |
|
327 |
|
328 CAiwGenericParamList* params = CAiwGenericParamList::NewLC(); |
|
329 |
|
330 |
|
331 TBool okToSend = EFalse; |
|
332 TRAPD( err, okToSend = |
|
333 newFile->NewFileL( *fileNames, params, ENewFileServiceImage, EFalse ) ); |
|
334 |
|
335 if (err) |
|
336 { |
|
337 // restore state |
|
338 User::LeaveIfError(err); |
|
339 } |
|
340 |
|
341 if (okToSend) |
|
342 { |
|
343 selectedFile = ( fileNames->MdcaPoint(0)).AllocL(); // alloclate for first filename |
|
344 StoreMimeTypeL(*selectedFile); // get the mime type and store |
|
345 } |
|
346 |
|
347 CleanupStack::PopAndDestroy( 3, fileNames); // params, newFile, fileNames |
|
348 |
|
349 break; |
|
350 } |
|
351 } |
|
352 return selectedFile; |
|
353 } |
|
354 // --------------------------------------------------------- |
|
355 // CAvatarSelectionHandler::ShowErrorL |
|
356 // (other items were commented in a header). |
|
357 // --------------------------------------------------------- |
|
358 // |
|
359 void CAvatarSelectionHandler::ShowErrorL(TErrorType aErrorType) |
|
360 { |
|
361 TRACER_AUTO; |
|
362 switch( aErrorType ) |
|
363 { |
|
364 case EProtected: |
|
365 { |
|
366 HBufC* prompt = StringLoader::LoadLC( R_QTN_SERVTAB_GALLERY_ERROR_DRMFILE ); |
|
367 VIMPSTUtilsDialog::DisplayErrorNoteL( *prompt ) ; |
|
368 CleanupStack::PopAndDestroy(prompt); |
|
369 break; |
|
370 } |
|
371 case ECorrupted: |
|
372 { |
|
373 HBufC* prompt = StringLoader::LoadLC( R_QTN_SERVTAB_GALLERY_ERROR_BADFILE ); |
|
374 VIMPSTUtilsDialog::DisplayErrorNoteL( *prompt ) ; |
|
375 CleanupStack::PopAndDestroy(prompt); |
|
376 break; |
|
377 } |
|
378 } |
|
379 |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------- |
|
383 // CAvatarSelectionHandler::MimeTypeL |
|
384 // (other items were commented in a header). |
|
385 // --------------------------------------------------------- |
|
386 // |
|
387 void CAvatarSelectionHandler::StoreMimeTypeL(const TDesC& aFilename) |
|
388 { |
|
389 TRACER_AUTO; |
|
390 TUid dummyUid( KNullUid ); |
|
391 TDataType dataType; |
|
392 User::LeaveIfError( iApaSession.AppForDocument( |
|
393 aFilename, |
|
394 dummyUid, dataType ) ); |
|
395 |
|
396 iMimeType = dataType.Des8().AllocL(); |
|
397 } |
|
398 |
|
399 // --------------------------------------------------------- |
|
400 // CAvatarSelectionHandler::MimeTypeL |
|
401 // (other items were commented in a header). |
|
402 // --------------------------------------------------------- |
|
403 // |
|
404 const TDesC8& CAvatarSelectionHandler::MimeTypeL() |
|
405 { |
|
406 return *iMimeType; |
|
407 } |
|
408 // End of File |