1 /* |
|
2 * Copyright (c) 2008-2010 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: Helper class for implementing one-click upload support |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <gulicon.h> |
|
20 #include <akntoolbar.h> |
|
21 #include <aknbutton.h> |
|
22 |
|
23 #include <AiwServiceHandler.h> |
|
24 #include <cameraapp.rsg> |
|
25 #include <vgacamsettings.rsg> |
|
26 #include <centralrepository.h> |
|
27 |
|
28 #include "camoneclickuploadutility.h" |
|
29 #include "camlogging.h" |
|
30 #include "CamPanic.h" |
|
31 #include "Cam.hrh" |
|
32 |
|
33 #include <cameraapp.mbg> |
|
34 #include "CamUtility.h" |
|
35 |
|
36 const TUid KShareOnlineCrUid = { 0x2002CC1F }; |
|
37 const TUint32 KShareCrApplicationVersion = 0x01010020; |
|
38 const TInt KCamShareOnlineVersionBufLen = 12; |
|
39 const TVersion KShareOnlineMinimumVersion( 5, 0, 0 ); |
|
40 const TUid KOpenModeOneClick = { 2 }; |
|
41 const TUid KCmdGetOneClickToolTip = { 15 }; |
|
42 const TUid KOpenModeShareSettings = { 11 }; |
|
43 |
|
44 const TUint32 KShareImageServiceIconFileName = 0x00000002; |
|
45 const TUint32 KShareVideoServiceIconFileName = 0x00000003; |
|
46 const TUint32 KShareCommonServiceIconFileName = 0x00000004; |
|
47 |
|
48 |
|
49 // ======== MEMBER FUNCTIONS ======== |
|
50 |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Two-phased constructor. |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CCamOneClickUploadUtility* CCamOneClickUploadUtility::NewL() |
|
57 { |
|
58 CCamOneClickUploadUtility* self = |
|
59 new ( ELeave ) CCamOneClickUploadUtility(); |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // C++ constructor |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CCamOneClickUploadUtility::CCamOneClickUploadUtility() |
|
71 { |
|
72 // No implementation needed |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // 2nd phase constructor |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CCamOneClickUploadUtility::ConstructL() |
|
80 { |
|
81 PRINT( _L( "Camera => CCamOneClickUploadUtility::ConstructL()" ) ); |
|
82 #ifndef __WINSCW__ |
|
83 // iUploadSupported is zeroed by CBase constructor. |
|
84 // If a leave occurs here, it is left as EFalse. |
|
85 // If InitializeAiwL() succeeds, it is set to ETrue. |
|
86 TRAP_IGNORE( |
|
87 { |
|
88 CheckVersionL(); |
|
89 InitializeAiwL(); |
|
90 ButtonTooltipL(); |
|
91 iUploadSupported = ETrue; |
|
92 } ); |
|
93 #else |
|
94 iUploadSupported = EFalse; |
|
95 #endif // __WINSCW__ |
|
96 PRINT1( _L( "Camera <> iUploadSupported = %d" ), iUploadSupported ); |
|
97 PRINT( _L( "Camera <= CCamOneClickUploadUtility::ConstructL()" ) ); |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // Destructor |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 CCamOneClickUploadUtility::~CCamOneClickUploadUtility() |
|
106 { |
|
107 delete iAiwServiceHandler; |
|
108 delete iTooltip; |
|
109 |
|
110 if ( iDecoder ) |
|
111 delete iDecoder; |
|
112 } |
|
113 |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // Check if one-click upload is supported |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 TBool CCamOneClickUploadUtility::OneClickUploadSupported() const |
|
120 { |
|
121 return iUploadSupported; |
|
122 } |
|
123 |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // Upload a file |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CCamOneClickUploadUtility::UploadL( const TDesC& aFilename ) |
|
130 { |
|
131 PRINT( _L( "Camera => CCamOneClickUploadUtility::UploadL(TDesC&)" ) ); |
|
132 |
|
133 CDesC16ArrayFlat* array = new ( ELeave ) CDesC16ArrayFlat( 1 ); |
|
134 CleanupStack::PushL( array ); |
|
135 |
|
136 array->AppendL( aFilename ); |
|
137 |
|
138 UploadL( *array ); |
|
139 |
|
140 CleanupStack::PopAndDestroy( array ); |
|
141 |
|
142 PRINT( _L( "Camera <= CCamOneClickUploadUtility::UploadL(TDesC&)" ) ); |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // Upload multiple files |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CCamOneClickUploadUtility::UploadL( const MDesC16Array& aFilenames ) |
|
150 { |
|
151 PRINT( _L( "Camera => CCamOneClickUploadUtility::UploadL(MDesC16Array&)" ) ); |
|
152 |
|
153 __ASSERT_ALWAYS( iAiwServiceHandler, CamPanic( ECamPanicNullPointer ) ); |
|
154 |
|
155 CAiwGenericParamList& paramList = iAiwServiceHandler->InParamListL(); |
|
156 paramList.Reset(); |
|
157 |
|
158 TAiwVariant openVariant( KOpenModeOneClick ); |
|
159 TAiwGenericParam openParam( EGenericParamModeActivation, openVariant ); |
|
160 paramList.AppendL( openParam ); |
|
161 |
|
162 for ( TInt i = 0; i < aFilenames.MdcaCount(); i++ ) |
|
163 { |
|
164 TPtrC filename = aFilenames.MdcaPoint( i ); |
|
165 PRINT1( _L( "Camera <> adding file %S" ), &filename ); |
|
166 TAiwVariant variant( filename ); |
|
167 TAiwGenericParam param( EGenericParamFile, variant ); |
|
168 paramList.AppendL( param ); |
|
169 } |
|
170 |
|
171 iAiwServiceHandler->ExecuteServiceCmdL( |
|
172 KAiwCmdUpload, |
|
173 paramList, |
|
174 iAiwServiceHandler->OutParamListL() ); |
|
175 |
|
176 PRINT( _L( "Camera <= CCamOneClickUploadUtility::UploadL(MDesC16Array&)" ) ); |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // Get the tooltip text for one-click upload button. |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 const TDesC& CCamOneClickUploadUtility::ButtonTooltipL() |
|
184 { |
|
185 __ASSERT_ALWAYS( iAiwServiceHandler, CamPanic( ECamPanicNullPointer ) ); |
|
186 |
|
187 if ( iTooltip ) |
|
188 { |
|
189 return *iTooltip; |
|
190 } |
|
191 |
|
192 CAiwGenericParamList& paramList = iAiwServiceHandler->InParamListL(); |
|
193 paramList.Reset(); |
|
194 |
|
195 TAiwVariant openVariant( KCmdGetOneClickToolTip ); |
|
196 TAiwGenericParam openParam( EGenericParamModeActivation, openVariant ); |
|
197 paramList.AppendL( openParam ); |
|
198 |
|
199 CAiwGenericParamList& outParamList = iAiwServiceHandler->OutParamListL(); |
|
200 outParamList.Reset(); |
|
201 iAiwServiceHandler->ExecuteServiceCmdL( |
|
202 KAiwCmdUpload, paramList, outParamList ); |
|
203 |
|
204 TInt index = 0; |
|
205 const TAiwGenericParam* res = outParamList.FindFirst( |
|
206 index, |
|
207 EGenericParamNoteItem, |
|
208 EVariantTypeDesC ); |
|
209 |
|
210 if ( !res ) |
|
211 { |
|
212 User::Leave( KErrArgument ); |
|
213 } |
|
214 |
|
215 delete iTooltip; |
|
216 iTooltip = NULL; |
|
217 iTooltip = res->Value().AsDes().AllocL(); |
|
218 return *iTooltip; |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // Launch Share settings view |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void CCamOneClickUploadUtility::LaunchShareSettings() |
|
226 { |
|
227 PRINT( _L("Camera => CCamOneClickUploadUtility::LaunchShareSettings") ); |
|
228 |
|
229 CAiwGenericParamList& paramList = iAiwServiceHandler->InParamListL(); |
|
230 paramList.Reset(); |
|
231 |
|
232 TAiwVariant openVariant( KOpenModeShareSettings ); |
|
233 TAiwGenericParam openParam( EGenericParamModeActivation, openVariant ); |
|
234 paramList.AppendL( openParam ); |
|
235 iAiwServiceHandler->ExecuteServiceCmdL( KAiwCmdView, |
|
236 paramList, iAiwServiceHandler->OutParamListL() ); |
|
237 |
|
238 PRINT( _L("Camera <= CCamOneClickUploadUtility::LaunchShareSettings") ); |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // Check Share Online version |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 void CCamOneClickUploadUtility::CheckVersionL() |
|
246 { |
|
247 PRINT( _L( "Camera => CCamOneClickUploadUtility::CheckVersionL()" ) ); |
|
248 |
|
249 CRepository* rep = CRepository::NewLC( KShareOnlineCrUid ); |
|
250 TBuf<KCamShareOnlineVersionBufLen> versionBuf; |
|
251 User::LeaveIfError( rep->Get( KShareCrApplicationVersion, versionBuf ) ); |
|
252 TVersion version( 0, 0, 0 ); |
|
253 TLex lex( versionBuf ); |
|
254 User::LeaveIfError( lex.Val( version.iMajor ) ); |
|
255 if ( lex.Get() != TChar('.') ) |
|
256 { |
|
257 User::Leave( KErrCorrupt ); |
|
258 } |
|
259 User::LeaveIfError( lex.Val( version.iMinor ) ); |
|
260 if ( lex.Get() != TChar('.') ) |
|
261 { |
|
262 User::Leave( KErrCorrupt ); |
|
263 } |
|
264 User::LeaveIfError( lex.Val( version.iBuild ) ); |
|
265 |
|
266 PRINT3( _L( "Camera <> CCamOneClickUploadUtility::CheckVersionL() - share online %d.%d.%d" ), version.iMajor, version.iMinor, version.iBuild ); |
|
267 |
|
268 // Compare version number and leave if the detected |
|
269 // version is less than KShareOnlineMinimumVersion. |
|
270 if ( version.iMajor < KShareOnlineMinimumVersion.iMajor ) |
|
271 { |
|
272 User::LeaveIfError( KErrNotSupported ); |
|
273 } |
|
274 else if ( version.iMajor == KShareOnlineMinimumVersion.iMajor ) |
|
275 { |
|
276 if ( version.iMinor < KShareOnlineMinimumVersion.iMinor ) |
|
277 { |
|
278 User::LeaveIfError( KErrNotSupported ); |
|
279 } |
|
280 else if ( version.iMinor == KShareOnlineMinimumVersion.iMinor ) |
|
281 { |
|
282 if ( version.iBuild < KShareOnlineMinimumVersion.iBuild ) |
|
283 { |
|
284 User::LeaveIfError( KErrNotSupported ); |
|
285 } |
|
286 else |
|
287 { |
|
288 // Version is supported, fall through |
|
289 } |
|
290 } |
|
291 else |
|
292 { |
|
293 // Version is supported, fall through |
|
294 } |
|
295 } |
|
296 else |
|
297 { |
|
298 // Version is supported, fall through |
|
299 } |
|
300 |
|
301 CleanupStack::PopAndDestroy( rep ); |
|
302 |
|
303 PRINT( _L( "Camera <= CCamOneClickUploadUtility::CheckVersionL()" ) ); |
|
304 } |
|
305 |
|
306 |
|
307 // --------------------------------------------------------------------------- |
|
308 // Initialize AIW framework |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 void CCamOneClickUploadUtility::InitializeAiwL() |
|
312 { |
|
313 __ASSERT_DEBUG( !iAiwServiceHandler, CamPanic( ECamPanicResourceLeak ) ); |
|
314 |
|
315 iAiwServiceHandler = CAiwServiceHandler::NewL(); |
|
316 iAiwServiceHandler->AttachL( R_CAM_ONE_CLICK_UPLOAD_INTEREST ); |
|
317 iAiwServiceHandler->AttachL( R_CAM_AIW_VIEW_INTEREST ); |
|
318 PRINT( _L("Camera <> CCamOneClickUploadUtility::InitializeAiwL - initialized") ); |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // Get the icon for Share AP item |
|
323 // --------------------------------------------------------------------------- |
|
324 // |
|
325 void CCamOneClickUploadUtility::CurrentIconPathL( TCamCameraMode aMode, TDes& aPath ) |
|
326 { |
|
327 PRINT1( _L("Camera => CCamOneClickUploadUtility::CurrentIconPathL mode:%d"), aMode ); |
|
328 TUint32 serviceIconId = KShareCommonServiceIconFileName; |
|
329 |
|
330 if ( ECamControllerVideo == aMode ) |
|
331 { |
|
332 serviceIconId = KShareVideoServiceIconFileName; |
|
333 } |
|
334 else // image |
|
335 { |
|
336 serviceIconId = KShareImageServiceIconFileName; |
|
337 } |
|
338 |
|
339 CRepository* rep = CRepository::NewLC( KShareOnlineCrUid ); |
|
340 User::LeaveIfError( rep->Get( serviceIconId, aPath ) ); |
|
341 CleanupStack::PopAndDestroy( rep ); |
|
342 PRINT1( _L("Camera <= CCamOneClickUploadUtility::CurrentIconPathL: %S"), &aPath ); |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CCamOneClickUploadUtility::UpdateUploadIconL |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 void CCamOneClickUploadUtility::UpdateUploadIconL( CAknToolbar *aToolbar, |
|
350 TCamCameraMode aMode ) |
|
351 { |
|
352 PRINT( _L("Camera => CCamOneClickUploadUtility::UpdateUploadIconL") ); |
|
353 |
|
354 TFileName currIcon; |
|
355 CurrentIconPathL( aMode, currIcon ); |
|
356 |
|
357 // If the icons are different then load the icon |
|
358 PRINT1( _L("Camera <> current icon: %S"), &iIconFileName ); |
|
359 if ( currIcon.Compare(iIconFileName) != 0 ) |
|
360 { |
|
361 PRINT( _L("Camera <> Decoding icon") ); |
|
362 iToolbar = aToolbar; |
|
363 TRAPD( err, DecodeIconL( &currIcon ) ); |
|
364 if ( err ) |
|
365 { |
|
366 PRINT1( _L("Camera <> CamOneClickUploadUtility - Icon decoding failed: %d"), err ); |
|
367 } |
|
368 } |
|
369 else |
|
370 { |
|
371 if ( aToolbar && iIconImage ) |
|
372 { |
|
373 PRINT( _L("Camera <> Copying icon") ); |
|
374 CAknButton* button = dynamic_cast<CAknButton*>( |
|
375 aToolbar->ControlOrNull( ECamCmdOneClickUpload ) ); |
|
376 if ( button ) |
|
377 { |
|
378 CAknButtonState* state = button->State(); |
|
379 CGulIcon *icon; |
|
380 if ( iIconMask ) |
|
381 { |
|
382 PRINT( _L("Camera <> Mask available") ); |
|
383 icon = CGulIcon::NewL( iIconImage, iIconMask ); |
|
384 } |
|
385 else |
|
386 { |
|
387 icon = CGulIcon::NewL( iIconImage ); |
|
388 } |
|
389 state->SetIcon( icon ); |
|
390 icon->SetBitmapsOwnedExternally( ETrue ); |
|
391 |
|
392 aToolbar->DrawNow(); |
|
393 } |
|
394 } |
|
395 } |
|
396 PRINT( _L("Camera <= CCamOneClickUploadUtility::UpdateUploadIconL") ); |
|
397 } |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // CCamOneClickUploadUtility::DecodeIconL() |
|
401 // ----------------------------------------------------------------------------- |
|
402 // |
|
403 void CCamOneClickUploadUtility::DecodeIconL( TDesC* aPath ) |
|
404 { |
|
405 PRINT1( _L("Camera => CCamOneClickUploadUtility::DecodeIconL: %S"), aPath ); |
|
406 |
|
407 if ( !iDecoder ) |
|
408 { |
|
409 iDecoder = CCamImageDecoder::NewL( *this ); |
|
410 } |
|
411 |
|
412 TSize size( 44, 44 ); |
|
413 CAknButton* button = dynamic_cast<CAknButton*>( |
|
414 iToolbar->ControlOrNull( ECamCmdDelete ) ); |
|
415 if ( button ) |
|
416 { |
|
417 CAknButtonState* state = button->State(); |
|
418 if ( state ) |
|
419 { |
|
420 const CGulIcon* icon = state->Icon(); |
|
421 if ( icon ) |
|
422 { |
|
423 CFbsBitmap* bitmap = icon->Bitmap(); |
|
424 if ( bitmap ) |
|
425 { |
|
426 if ( bitmap->SizeInPixels().iHeight > 0 ) |
|
427 { |
|
428 size = bitmap->SizeInPixels(); |
|
429 } |
|
430 } |
|
431 } |
|
432 } |
|
433 } |
|
434 iDecoder->StartIconConversionL( aPath, size ); |
|
435 |
|
436 // Mark the given file as the icon in use when decoding has started |
|
437 iIconFileName.Copy( *aPath ); |
|
438 |
|
439 PRINT( _L("Camera <= CCamOneClickUploadUtility::DecodeIconL") ); |
|
440 } |
|
441 |
|
442 // --------------------------------------------------------------------------- |
|
443 // Image decoding complete notificationL |
|
444 // --------------------------------------------------------------------------- |
|
445 // |
|
446 void CCamOneClickUploadUtility::ImageDecodedL( TInt aStatus, const CFbsBitmap* aBitmap, const CFbsBitmap* aMask ) |
|
447 { |
|
448 PRINT( _L("Camera => CCamOneClickUploadUtility::ImageDecodedL") ); |
|
449 |
|
450 if ( aStatus == KErrNone ) |
|
451 { |
|
452 delete iIconImage; |
|
453 delete iIconMask; |
|
454 iIconImage = NULL; |
|
455 iIconMask = NULL; |
|
456 |
|
457 iIconImage = new (ELeave) CFbsBitmap; |
|
458 iIconImage->Duplicate( aBitmap->Handle() ); |
|
459 |
|
460 if ( aMask ) |
|
461 { |
|
462 iIconMask = new (ELeave) CFbsBitmap; |
|
463 iIconMask->Duplicate( aMask->Handle() ); |
|
464 } |
|
465 |
|
466 if ( iToolbar ) |
|
467 { |
|
468 PRINT( _L("Camera <> Ready to add icon to toolbar") ); |
|
469 |
|
470 CAknButton* uploadButton = |
|
471 static_cast<CAknButton*> (iToolbar->ControlOrNull(ECamCmdOneClickUpload)); |
|
472 |
|
473 if ( uploadButton ) |
|
474 { |
|
475 PRINT( _L("Camera <> Creating new icon") ); |
|
476 CGulIcon *icon(NULL); |
|
477 if ( iIconMask ) |
|
478 { |
|
479 PRINT( _L("Camera <> Mask available") ); |
|
480 icon = CGulIcon::NewL( iIconImage, iIconMask ); |
|
481 } |
|
482 else |
|
483 { |
|
484 icon = CGulIcon::NewL( iIconImage ); |
|
485 } |
|
486 |
|
487 icon->SetBitmapsOwnedExternally( ETrue ); |
|
488 uploadButton->State()->SetIcon( icon ); |
|
489 } |
|
490 iToolbar->DrawNow(); |
|
491 } |
|
492 } |
|
493 else |
|
494 { |
|
495 PRINT1( _L("Camera <> CCamOneClickUploadUtility::ImageDecoded - err:%d"), aStatus ); |
|
496 } |
|
497 |
|
498 PRINT( _L("Camera <= CCamOneClickUploadUtility::ImageDecoded") ); |
|
499 } |
|