|
1 /* |
|
2 * Copyright (c) 2004-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: Implementation of Call Image plugin. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <AiwCommon.h> // AIW classes and definitions. |
|
22 #include <AiwCommon.hrh> // AIW constants. |
|
23 #include <AiwMenu.h> // AIW Menu pane. |
|
24 #include <aiwcallimageplugin.rsg> |
|
25 #include <pslninternalcrkeys.h> |
|
26 #include <centralrepository.h> |
|
27 #include <data_caging_path_literals.hrh> |
|
28 #include <aknnotedialog.h> |
|
29 #include <DRMHelper.h> |
|
30 #include <bautils.h> |
|
31 #include <drmutility.h> |
|
32 #include <AknsSrvClient.h> |
|
33 |
|
34 #include "aiwcallimageplugin.h" // This class interface. |
|
35 #include "aiwcallimageplugin.hrh" // AiwCallImagePlugin constants. |
|
36 |
|
37 |
|
38 |
|
39 // CONSTANTS |
|
40 |
|
41 // Drive letter. |
|
42 _LIT( KResourceDrive, "z:" ); |
|
43 |
|
44 // Path to compiled resource file. |
|
45 _LIT( KCallImageResFile, "aiwcallimageplugin.rsc" ); |
|
46 |
|
47 // Call Image mime types. |
|
48 _LIT( KCallImagePluginMimeTypeImage, "IMAGE" ); |
|
49 _LIT( KCallImagePluginMimeTypeOTABitmap, "IMAGE/X-OTA-BITMAP" ); |
|
50 _LIT( KCallImagePluginSeparator, "/" ); |
|
51 // Extension for scalable vector graphics file. |
|
52 _LIT( KAknsSkinSrvSvgFileExt, ".svg" ); |
|
53 |
|
54 // ============================ MEMBER FUNCTIONS =============================== |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CAiwCallImagePlugin::CAiwCallImagePlugin |
|
58 // |
|
59 // C++ constructor can NOT contain any code, that might leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CAiwCallImagePlugin::CAiwCallImagePlugin() |
|
63 { |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CAiwCallImagePlugin::NewL |
|
68 // |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CAiwCallImagePlugin* CAiwCallImagePlugin::NewL() |
|
73 { |
|
74 CAiwCallImagePlugin* self = new( ELeave ) CAiwCallImagePlugin; |
|
75 return self; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CAiwCallImagePlugin::~CAiwCallImagePlugin |
|
80 // |
|
81 // Destructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CAiwCallImagePlugin::~CAiwCallImagePlugin() |
|
85 { |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CAiwCallImagePlugin::InitialiseL |
|
90 // |
|
91 // |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CAiwCallImagePlugin::InitialiseL( |
|
95 MAiwNotifyCallback& /*aFrameworkCallback*/, |
|
96 const RCriteriaArray& /*aInterest*/) |
|
97 { |
|
98 // Stub. Not used. |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CAiwCallImagePlugin::HandleServiceCmdL |
|
103 // |
|
104 // |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CAiwCallImagePlugin::HandleServiceCmdL( |
|
108 const TInt& aCmdId, |
|
109 const CAiwGenericParamList& aInParamList, |
|
110 CAiwGenericParamList& /*aOutParamList*/, |
|
111 TUint aCmdOptions, |
|
112 const MAiwNotifyCallback* /*aCallback*/ ) |
|
113 { |
|
114 |
|
115 // Cancel bit must always be checked. Support can be implemented if necessary. |
|
116 if( aCmdOptions & KAiwOptCancel ) |
|
117 { |
|
118 return; |
|
119 } |
|
120 |
|
121 // Handle only call command. |
|
122 if ( aCmdId == KAiwCmdAssign ) |
|
123 { |
|
124 // Check if there is call image path parameter. |
|
125 TInt index = 0; |
|
126 const TAiwGenericParam* genericParam = NULL; |
|
127 |
|
128 genericParam = aInParamList.FindFirst( |
|
129 index, |
|
130 EGenericParamFile, |
|
131 EVariantTypeDesC ); |
|
132 |
|
133 if ( index >= 0 && genericParam ) |
|
134 { |
|
135 User::LeaveIfError( SetCallImagePathL( genericParam ) ); |
|
136 } |
|
137 } |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CAiwCallImagePlugin::SetCallImagePathL |
|
142 // |
|
143 // |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TInt CAiwCallImagePlugin::SetCallImagePathL( const TAiwGenericParam* aPathParam ) |
|
147 { |
|
148 TInt error( KErrNone ); |
|
149 TBool drm( EFalse ); |
|
150 TBool iDrmProtected( EFalse ); |
|
151 RFile fileHandle; |
|
152 TUint fileMode = EFileShareReadersOrWriters | EFileStream | EFileRead; |
|
153 RFs fs = CCoeEnv::Static()->FsSession(); |
|
154 |
|
155 User::LeaveIfError(fileHandle.Open(fs, aPathParam->Value().AsDes(), fileMode)); |
|
156 CleanupClosePushL(fileHandle); |
|
157 |
|
158 DRM::CDrmUtility* drmUtil = DRM::CDrmUtility::NewLC(); |
|
159 iDrmProtected = drmUtil->IsProtectedL(fileHandle); |
|
160 |
|
161 CleanupStack::PopAndDestroy(2); // fileHandle, drmUtil |
|
162 |
|
163 if( !iDrmProtected ) |
|
164 { |
|
165 CDRMHelper* drmHelper = CDRMHelper::NewL( *CCoeEnv::Static() ); |
|
166 drmHelper->CanSetAutomated( aPathParam->Value().AsDes(), drm ); |
|
167 delete drmHelper; |
|
168 } |
|
169 |
|
170 //Before setting image, check is the image corruputed |
|
171 RAknsSrvSession skinsrv; |
|
172 User::LeaveIfError( skinsrv.Connect() ); |
|
173 CleanupClosePushL( skinsrv ); |
|
174 CFbsBitmap* bmp = NULL; |
|
175 CFbsBitmap* mask = NULL; |
|
176 // no way currently of checking corrupted svg:s |
|
177 if ( ( aPathParam->Value().AsDes().Right( 4 ) ).CompareF( KAknsSkinSrvSvgFileExt ) ) |
|
178 { |
|
179 // (-1, -1) means that image is just decoded, not used |
|
180 TRAP( error, skinsrv.DecodeWallpaperImageL( aPathParam->Value().AsDes(), TSize(-1,-1), bmp, mask ) ); |
|
181 if( error ) |
|
182 { |
|
183 //File is corrupted |
|
184 ShowNoteL( error ); |
|
185 CleanupStack::PopAndDestroy( &skinsrv ); |
|
186 //Need to return KErrNone because there would happen a Leave upper in callstack. This how |
|
187 //AIW plugin can show more accurate error note. |
|
188 return KErrNone; |
|
189 } |
|
190 } |
|
191 CleanupStack::PopAndDestroy( &skinsrv ); |
|
192 |
|
193 CRepository* pathCen = CRepository::NewL ( KCRUidThemes ); |
|
194 CleanupStack::PushL( pathCen ); |
|
195 if ( drm ) |
|
196 { |
|
197 error = pathCen->Set( KThemesCallImagePath, aPathParam->Value().AsDes() ); |
|
198 // If path setting fails do not set image support on. |
|
199 if ( error == KErrNone ) |
|
200 { |
|
201 error = pathCen->Set( KThemesCallImageSetting, ETrue ); |
|
202 } |
|
203 ShowNoteL( error ); |
|
204 } |
|
205 else // drm check failed show error note |
|
206 { |
|
207 ShowDRMErrorNoteL(); |
|
208 } |
|
209 |
|
210 CleanupStack::PopAndDestroy(); // pathCen |
|
211 |
|
212 return error; |
|
213 } |
|
214 |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CAiwCallImagePlugin::ShowDRMErrorNoteL |
|
218 // |
|
219 // |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CAiwCallImagePlugin::ShowDRMErrorNoteL() |
|
223 { |
|
224 // Resource file definition. |
|
225 TFileName callImageRsc( KResourceDrive ); |
|
226 callImageRsc.Append( KDC_RESOURCE_FILES_DIR ); |
|
227 callImageRsc.Append( KCallImageResFile ); |
|
228 |
|
229 CCoeEnv* env = CCoeEnv::Static(); |
|
230 BaflUtils::NearestLanguageFile( env->FsSession(), callImageRsc ); |
|
231 TInt resourceOffSet = env->AddResourceFileL( callImageRsc ); |
|
232 |
|
233 CAknNoteDialog* dlg = new(ELeave) CAknNoteDialog; |
|
234 CAknNoteDialog::TTimeout timeout = CAknNoteDialog::ELongTimeout; |
|
235 dlg->SetTone( CAknNoteDialog::EErrorTone ); |
|
236 dlg->PrepareLC( R_CALL_IMAGE_DRM_NOTE ); |
|
237 dlg->SetTimeout( timeout ); |
|
238 dlg->RunDlgLD(); |
|
239 // Free resource. |
|
240 env->DeleteResourceFile( resourceOffSet ); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CAiwCallImagePlugin::ShowNoteL |
|
245 // |
|
246 // |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CAiwCallImagePlugin::ShowNoteL( TInt aError ) |
|
250 { |
|
251 TInt resourceId = R_CALL_IMAGE_OK_NOTE; |
|
252 // Resource file definition. |
|
253 TFileName callImageRsc( KResourceDrive ); |
|
254 callImageRsc.Append( KDC_RESOURCE_FILES_DIR ); |
|
255 callImageRsc.Append( KCallImageResFile ); |
|
256 |
|
257 CCoeEnv* env = CCoeEnv::Static(); |
|
258 BaflUtils::NearestLanguageFile( env->FsSession(), callImageRsc ); |
|
259 TInt resourceOffSet = env->AddResourceFileL( callImageRsc ); |
|
260 |
|
261 CAknNoteDialog* dlg = new(ELeave) CAknNoteDialog; |
|
262 CAknNoteDialog::TTimeout timeout = CAknNoteDialog::ELongTimeout; |
|
263 |
|
264 if ( aError != KErrNone ) |
|
265 { |
|
266 resourceId = R_CALL_IMAGE_ERROR_NOTE; |
|
267 dlg->SetTone( CAknNoteDialog::EErrorTone ); |
|
268 } |
|
269 dlg->PrepareLC( resourceId ); |
|
270 dlg->SetTimeout( timeout ); |
|
271 dlg->RunDlgLD(); |
|
272 // Free resource. |
|
273 env->DeleteResourceFile( resourceOffSet ); |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CAiwCallImagePlugin::InitializeMenuPaneL |
|
278 // |
|
279 // |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CAiwCallImagePlugin::InitializeMenuPaneL( |
|
283 CAiwMenuPane& aMenuPane, |
|
284 TInt aIndex, |
|
285 TInt /* aCascadeId */, |
|
286 const CAiwGenericParamList& aInParamList ) |
|
287 { |
|
288 TPtrC mimeTypeString = GetAiwParamAsDescriptor(aInParamList, EGenericParamMIMEType); |
|
289 |
|
290 // Insert menu only if supported MIME type is given |
|
291 if ( ( mimeTypeString != KNullDesC ) && |
|
292 (IsMimeTypeSupportedL(mimeTypeString) ) ) |
|
293 { |
|
294 // Resource file definition. |
|
295 TFileName resFile( KResourceDrive ); |
|
296 resFile.Append( KDC_RESOURCE_FILES_DIR ); |
|
297 resFile.Append( KCallImageResFile ); |
|
298 |
|
299 aMenuPane.AddMenuItemsL( |
|
300 resFile, |
|
301 R_CALL_IMAGE_MENU, |
|
302 KAiwCmdAssign, |
|
303 aIndex); |
|
304 } |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CAiwCallImagePlugin::HandleMenuCmdL |
|
309 // |
|
310 // |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 void CAiwCallImagePlugin::HandleMenuCmdL( |
|
314 TInt aMenuCmdId, |
|
315 const CAiwGenericParamList& aInParamList, |
|
316 CAiwGenericParamList& aOutParamList, |
|
317 TUint aCmdOptions, |
|
318 const MAiwNotifyCallback* aCallback ) |
|
319 { |
|
320 // Cancel bit must always be checked. Support can be implemented if necessary. |
|
321 if( aCmdOptions & KAiwOptCancel ) |
|
322 { |
|
323 return; |
|
324 } |
|
325 |
|
326 // Handle only call image command. |
|
327 if ( aMenuCmdId == ECallImage ) |
|
328 { |
|
329 // Menu commands are handled as service commands. |
|
330 HandleServiceCmdL( |
|
331 KAiwCmdAssign, |
|
332 aInParamList, |
|
333 aOutParamList, |
|
334 aCmdOptions, |
|
335 aCallback ); |
|
336 } |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // Implements getting a AIW parameter as descriptor. |
|
341 // |
|
342 // |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 TPtrC CAiwCallImagePlugin::GetAiwParamAsDescriptor( |
|
346 const CAiwGenericParamList& aParamList, |
|
347 TGenericParamId aParamType) |
|
348 { |
|
349 TInt index(0); |
|
350 const TAiwGenericParam* genericParam = NULL; |
|
351 genericParam = aParamList.FindFirst( |
|
352 index, |
|
353 aParamType, |
|
354 EVariantTypeDesC ); |
|
355 |
|
356 if ( index >= 0 && genericParam ) |
|
357 { |
|
358 // Get the data |
|
359 return genericParam->Value().AsDes(); |
|
360 } |
|
361 else |
|
362 { |
|
363 return KNullDesC(); |
|
364 } |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // Implements checking if a given MIME type is supported or not. |
|
369 // |
|
370 // |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 TBool CAiwCallImagePlugin::IsMimeTypeSupportedL( const TDesC& aMimeTypeString ) |
|
374 { |
|
375 // Check for a type separator in the string |
|
376 TInt pos = aMimeTypeString.Find( KCallImagePluginSeparator ); |
|
377 |
|
378 // Leave if no separator was found.. the MIME |
|
379 // standard requires it |
|
380 if ( pos == KErrNotFound ) |
|
381 { |
|
382 User::Leave( KErrArgument ); |
|
383 } |
|
384 |
|
385 // Copy the full Mime type string (needed for uppercase) |
|
386 HBufC* fullBuf = aMimeTypeString.AllocLC(); |
|
387 TPtr fullString = fullBuf->Des(); |
|
388 fullString.UpperCase(); |
|
389 |
|
390 // Construct the compare string |
|
391 TPtrC compareString( aMimeTypeString.Left( pos ) ); |
|
392 |
|
393 TBool ret(EFalse); |
|
394 |
|
395 // Perform the comparison |
|
396 // Mime type case: IMAGE/* except IMAGE/X-OTA-BITMAP |
|
397 if ( compareString.CompareF( KCallImagePluginMimeTypeImage ) == 0 && |
|
398 !( fullString.CompareF( KCallImagePluginMimeTypeOTABitmap ) == 0 ) ) |
|
399 { |
|
400 ret = ETrue; |
|
401 } |
|
402 |
|
403 CleanupStack::PopAndDestroy( fullBuf ); |
|
404 |
|
405 return ret; |
|
406 } |
|
407 |
|
408 // End of file |