|
1 /* |
|
2 * Copyright (c) 2006 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 utility for Common UI |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <eikenv.h> |
|
22 #include <mpxmedia.h> |
|
23 #include <mpxmediadrmdefs.h> |
|
24 #include <mpxmediageneraldefs.h> |
|
25 #include <caf/caferr.h> |
|
26 #include <mpxcommonui.rsg> |
|
27 #include <StringLoader.h> |
|
28 // S60 Specific |
|
29 |
|
30 #include <mpxconstants.h> |
|
31 #include "mpxdrmuihelper.h" |
|
32 #include "mpxcommonuihelper.h" |
|
33 #include "mpxlog.h" |
|
34 |
|
35 #ifdef CAMESE_IN_DRM_UTILITY |
|
36 #include <drmutility.h> |
|
37 #include <drmuihandling.h> |
|
38 #include <drmerrorhandling.h> |
|
39 #include <caf/caf.h> |
|
40 #include <caf/data.h> |
|
41 #include <caf/caftypes.h> |
|
42 #else |
|
43 #include <drmhelper.h> |
|
44 #endif |
|
45 |
|
46 // ======== MEMBER FUNCTIONS ======== |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Two-phased constructor. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CMPXDrmUiHelper* CMPXDrmUiHelper::NewL( CMPXCommonUiHelper* aHelper ) |
|
53 { |
|
54 CMPXDrmUiHelper* self = new ( ELeave ) CMPXDrmUiHelper( aHelper ); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL(); |
|
57 CleanupStack::Pop(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Symbian 2nd phase constructor can leave. |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 void CMPXDrmUiHelper::ConstructL() |
|
66 { |
|
67 CCoeEnv* coeEnv = CEikonEnv::Static(); |
|
68 #ifdef CAMESE_IN_DRM_UTILITY |
|
69 iDrmUiHandler = DRM::CDrmUiHandling::NewL(); |
|
70 #else |
|
71 iDrmHelper = CDRMHelper::NewL( *coeEnv ); |
|
72 #endif |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // C++ default constructor can NOT contain any code, that |
|
77 // might leave. |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CMPXDrmUiHelper::CMPXDrmUiHelper( CMPXCommonUiHelper* aHelper ) |
|
81 : iCommonUiHelper( aHelper ) |
|
82 { |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Destructor |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CMPXDrmUiHelper::~CMPXDrmUiHelper() |
|
90 { |
|
91 #ifdef CAMESE_IN_DRM_UTILITY |
|
92 delete iDrmUiHandler; |
|
93 #else |
|
94 delete iDrmHelper; |
|
95 #endif |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // Handles displaying the error message for given error code |
|
100 // according to the media object provided |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 TInt CMPXDrmUiHelper::HandleDrmErrorL( |
|
104 TInt aError, |
|
105 const CMPXMedia* aMedia, /*=NULL*/ |
|
106 RFile* aFile /*=NULL*/ ) |
|
107 { |
|
108 MPX_DEBUG2("CMPXDrmUiHelper::HandleErrorL(%d) entering", aError); |
|
109 |
|
110 TInt ret( KErrNone ); |
|
111 if ( aMedia ) |
|
112 { |
|
113 if ( aMedia->IsSupported( KMPXMediaDrmType ) ) |
|
114 { |
|
115 #ifdef CAMESE_IN_DRM_UTILITY |
|
116 // all cases will be handled with same logic now |
|
117 ret = HandleOMAErrorL( aError, aMedia, aFile ); |
|
118 #else |
|
119 TMPXMediaDrmType type( |
|
120 aMedia->ValueTObjectL<TMPXMediaDrmType>( KMPXMediaDrmType )); |
|
121 |
|
122 if ( EMPXDrmTypeOMA == type ) |
|
123 { |
|
124 ret = HandleOMAErrorL( aError, aMedia, aFile ); |
|
125 } |
|
126 else if ( EMPXDrmTypeWMA == type ) |
|
127 { |
|
128 ret = HandleWMAErrorL( aError, aMedia, aFile ); |
|
129 } |
|
130 #endif |
|
131 } |
|
132 } |
|
133 |
|
134 MPX_DEBUG2("CMPXDrmUiHelper::HandleErrorL() exiting, returning %d", ret); |
|
135 return ret; |
|
136 } |
|
137 |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // Handles OMA specific error messages |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 TInt CMPXDrmUiHelper::HandleOMAErrorL( |
|
144 TInt aError, |
|
145 const CMPXMedia* aMedia, |
|
146 RFile* aFile ) |
|
147 { |
|
148 MPX_DEBUG2("CMPXDrmUiHelper::HandleOMAErrorL(%d) entering", aError); |
|
149 HBufC8* previewUrl = NULL; |
|
150 |
|
151 // Get filename of media |
|
152 TInt ret( KErrNone ); |
|
153 TFileName filename( KNullDesC ); |
|
154 if ( aMedia->IsSupported( KMPXMediaGeneralUri ) ) |
|
155 { |
|
156 filename = aMedia->ValueText( KMPXMediaGeneralUri ); |
|
157 } |
|
158 |
|
159 TBool useFile( EFalse ); |
|
160 if ( aFile ) |
|
161 { |
|
162 if ( aFile->SubSessionHandle() ) |
|
163 { |
|
164 useFile = ETrue; |
|
165 } |
|
166 } |
|
167 #ifdef CAMESE_IN_DRM_UTILITY |
|
168 switch ( aError ) |
|
169 { |
|
170 case KMPXRightsAboutToExpire: |
|
171 case KErrCANoRights: |
|
172 { |
|
173 iRightsValid = EFalse; |
|
174 |
|
175 // This will ask from user if new rights are acquired |
|
176 if ( useFile ) |
|
177 { |
|
178 iDrmUiHandler->CheckRightsAmountL( *aFile, |
|
179 ContentAccess::EPlay, this ); |
|
180 } |
|
181 else if ( filename.CompareF( KNullDesC ) != 0 ) |
|
182 { |
|
183 ContentAccess::TVirtualPathPtr virtualPath( filename, ContentAccess::KDefaultContentObject ); |
|
184 ContentAccess::CData* content( NULL ); |
|
185 TRAPD( r, content = ContentAccess::CData::NewL( |
|
186 virtualPath, ContentAccess::EPeek, |
|
187 ContentAccess::EContentShareReadWrite ) ); |
|
188 if ( r == KErrInUse ) |
|
189 { |
|
190 content = ContentAccess::CData::NewL( virtualPath, ContentAccess::EPeek, |
|
191 ContentAccess::EContentShareReadOnly ); |
|
192 } |
|
193 else |
|
194 { |
|
195 User::LeaveIfError( r ); |
|
196 } |
|
197 CleanupStack::PushL( content ); |
|
198 |
|
199 iDrmUiHandler->CheckRightsAmountL( *content, |
|
200 ContentAccess::EPlay, this ); |
|
201 |
|
202 CleanupStack::PopAndDestroy( content ); |
|
203 } |
|
204 if( !iRightsValid ) |
|
205 { |
|
206 // Rights still not valid. Cancel the operation. |
|
207 ret = KErrCancel; |
|
208 } |
|
209 break; |
|
210 } |
|
211 default: |
|
212 { |
|
213 if ( useFile ) |
|
214 { |
|
215 DRM::MDrmErrorHandling& errorHandler = iDrmUiHandler->GetErrorHandler(); |
|
216 errorHandler.HandleErrorL( *aFile, ContentAccess::EPlay, aError, NULL ); |
|
217 } |
|
218 else if ( filename.CompareF( KNullDesC ) != 0 ) |
|
219 { |
|
220 ContentAccess::TVirtualPathPtr virtualPath( filename, ContentAccess::KDefaultContentObject ); |
|
221 ContentAccess::CData* content( NULL ); |
|
222 TRAPD( r, content = ContentAccess::CData::NewL( |
|
223 virtualPath, ContentAccess::EPeek, |
|
224 ContentAccess::EContentShareReadWrite ) ); |
|
225 if ( r == KErrInUse ) |
|
226 { |
|
227 content = ContentAccess::CData::NewL( virtualPath, ContentAccess::EPeek, |
|
228 ContentAccess::EContentShareReadOnly ); |
|
229 } |
|
230 else |
|
231 { |
|
232 User::LeaveIfError( r ); |
|
233 } |
|
234 CleanupStack::PushL( content ); |
|
235 |
|
236 DRM::MDrmErrorHandling& errorHandler = iDrmUiHandler->GetErrorHandler(); |
|
237 errorHandler.HandleErrorL( *content, ContentAccess::EPlay, aError, NULL ); |
|
238 |
|
239 CleanupStack::PopAndDestroy( content ); |
|
240 } |
|
241 break; |
|
242 } |
|
243 #else |
|
244 switch ( aError ) |
|
245 { |
|
246 case KMPXRightsAboutToExpire: |
|
247 { |
|
248 if ( useFile ) |
|
249 { |
|
250 ret = iDrmHelper->CheckRightsAmountL( *aFile ); |
|
251 } |
|
252 else if ( filename.CompareF( KNullDesC ) != 0 ) |
|
253 { |
|
254 ret = iDrmHelper->CheckRightsAmountL( filename ); |
|
255 } |
|
256 break; |
|
257 } |
|
258 default: |
|
259 { |
|
260 if ( useFile ) |
|
261 { |
|
262 ret = iDrmHelper->HandleErrorOrPreviewL( aError, *aFile, previewUrl ); |
|
263 if( previewUrl ) |
|
264 { |
|
265 delete previewUrl; |
|
266 } |
|
267 } |
|
268 else if ( filename.CompareF( KNullDesC ) != 0 ) |
|
269 { |
|
270 ret = iDrmHelper->HandleErrorOrPreviewL( aError, filename, previewUrl ); |
|
271 if( previewUrl ) |
|
272 { |
|
273 delete previewUrl; |
|
274 } |
|
275 } |
|
276 break; |
|
277 } |
|
278 |
|
279 #endif |
|
280 } |
|
281 |
|
282 MPX_DEBUG2("CMPXDrmUiHelper::HandleOMAErrorL(%d) exiting, returning %d", ret); |
|
283 return ret; |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // Handles WMA specific error messages |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 TInt CMPXDrmUiHelper::HandleWMAErrorL( |
|
291 TInt aError, |
|
292 const CMPXMedia* aMedia, |
|
293 RFile* /*aFile*/ ) |
|
294 { |
|
295 MPX_DEBUG2("CMPXDrmUiHelper::HandleWMAErrorL(%d) entering", aError); |
|
296 |
|
297 TInt ret( KErrNone ); |
|
298 HBufC* notificationText( NULL ); |
|
299 |
|
300 // Get filename of media |
|
301 TFileName filename( KNullDesC ); |
|
302 if ( aMedia->IsSupported( KMPXMediaGeneralUri ) ) |
|
303 { |
|
304 filename = aMedia->ValueText( KMPXMediaGeneralUri ); |
|
305 } |
|
306 |
|
307 switch ( aError ) |
|
308 { |
|
309 case KMPXRightsAboutToExpire: |
|
310 { |
|
311 /* |
|
312 if ( aMedia->IsSupported( EMPXMediaDrmRightsType )) |
|
313 { |
|
314 TMPXMediaDrmRightsType type = |
|
315 aMedia->ValueTObject<TMPXMediaDrmRightsType>( |
|
316 EMPXMediaDrmRightsType ); |
|
317 switch ( type ) |
|
318 { |
|
319 case EMPXDrmRightsTypeTime: |
|
320 { |
|
321 TTime endTime = *aMedia->Value<TTime>( |
|
322 EMPXMediaDrmEndTime ); |
|
323 TTime currentTime; |
|
324 currentTime.HomeTime(); |
|
325 TTimeIntervalDays daysRemain = |
|
326 endTime.DaysFrom( currentTime ); |
|
327 TInt days( daysRemain.Int() ); |
|
328 if ( days < 1 ) |
|
329 { |
|
330 notificationText = StringLoader::LoadLC( |
|
331 R_MPX_CUI_WMDRM_RIGHTS_ABOUT_EXPIRE_NOTIFICATION ); |
|
332 } |
|
333 else if ( days == 1 ) |
|
334 { |
|
335 notificationText = StringLoader::LoadLC( |
|
336 R_MPX_CUI_WMDRM_RIGHTS_ABOUT_EXPIRE_ONE_DAY_NOTIFICATION ); |
|
337 } |
|
338 else |
|
339 { |
|
340 notificationText = StringLoader::LoadLC( |
|
341 R_MUSICPLAYER_CUI_WMDRM_RIGHTS_ABOUT_EXPIRE_MULTIPLE_DAY_NOTIFICATION ); |
|
342 } |
|
343 break; |
|
344 } // end case EMPXDrmRightsTypeTime |
|
345 case EMPXDrmRightsTypeCount: |
|
346 case EMPXDrmRightsTypeTimeCount: |
|
347 { |
|
348 TUint32 count( |
|
349 aMedia->ValueTObject<TUint32>( |
|
350 EMPXMediaDrmCount )); |
|
351 if ( count <= KMPXWmaDrmAboutToExpireCount ) |
|
352 { |
|
353 if ( count == 1 ) |
|
354 { |
|
355 notificationText = StringLoader::LoadLC( |
|
356 R_MUSICPLAYER_CUI_WMDRM_RIGHTS_ACTIVATION_KEY_ONE_COUNT_NOTIFICATION ); |
|
357 } |
|
358 else if ( count > 1 ) |
|
359 { |
|
360 notificationText = StringLoader::LoadLC( |
|
361 R_MUSICPLAYER_CUI_WMDRM_RIGHTS_ACTIVATION_KEY_MORE_THAN_ONE_COUNT_NOTIFICATION ); |
|
362 } |
|
363 } |
|
364 } // end case EMPXDrmRightsTypeCount, EMPXDrmRightsTypeTimeCount |
|
365 default: |
|
366 { |
|
367 // do nothing |
|
368 break; |
|
369 } |
|
370 } |
|
371 } |
|
372 */ |
|
373 } // end case KMPXRightsAboutToExpire |
|
374 case KErrCANotSupported: |
|
375 case KErrCANoPermission: |
|
376 case KErrCANoRights: |
|
377 // case KErrCANoAgent: |
|
378 // case KErrCAOutOfRange: |
|
379 // case KErrCAPendingRights: |
|
380 // case KErrCASizeNotDetermined: |
|
381 // case KErrCANewFileHandleRequired: |
|
382 { |
|
383 if ( filename.CompareF( KNullDesC ) != 0 ) |
|
384 { |
|
385 TParsePtrC parse( filename ); |
|
386 notificationText = StringLoader::LoadLC( |
|
387 R_MPX_DRM_EXPIRED_PLAYBACK, parse.Name() ); |
|
388 iCommonUiHelper->DisplayInfoNoteL( *notificationText ); |
|
389 CleanupStack::PopAndDestroy( notificationText ); |
|
390 notificationText = NULL; |
|
391 } |
|
392 break; |
|
393 } |
|
394 default: |
|
395 { |
|
396 break; |
|
397 } |
|
398 } |
|
399 |
|
400 MPX_DEBUG2("CMPXDrmUiHelper::HandleWMAErrorL(%d) exiting, returning %d", ret); |
|
401 return ret; |
|
402 } |
|
403 #ifdef CAMESE_IN_DRM_UTILITY |
|
404 // ---------------------------------------------------------------------------- |
|
405 // Called when valid rights are found |
|
406 // ---------------------------------------------------------------------------- |
|
407 // |
|
408 DRM::TCheckRightsAction CMPXDrmUiHelper::RightsLeft( |
|
409 TInt /*aOperationId*/, |
|
410 TBool /*aUnconstrained*/, |
|
411 TTimeIntervalSeconds /*aTime*/, |
|
412 TInt /*aCounts*/, |
|
413 TTimeIntervalSeconds /*aAccumulated*/ ) |
|
414 { |
|
415 iRightsValid = ETrue; |
|
416 return DRM::EUHCheckRightsActionIgnore; |
|
417 } |
|
418 |
|
419 // ---------------------------------------------------------------------------- |
|
420 // Called when there is no valid rights |
|
421 // ---------------------------------------------------------------------------- |
|
422 // |
|
423 DRM::TCheckRightsAction CMPXDrmUiHelper::RightsNotValid( |
|
424 TInt /*aOperationId*/, |
|
425 DRM::TCheckRightsStatus /*aRightsStatus*/, |
|
426 TInt /*aReason*/ ) |
|
427 { |
|
428 iRightsValid = EFalse; |
|
429 |
|
430 // DrmUiHandling will ask for more rights |
|
431 return DRM::EUHCheckRightsActionDefault; |
|
432 } |
|
433 |
|
434 // ---------------------------------------------------------------------------- |
|
435 // Unused observation method |
|
436 // ---------------------------------------------------------------------------- |
|
437 // |
|
438 DRM::TEmbeddedPreviewAction CMPXDrmUiHelper::EmbeddedPreviewAvailable( |
|
439 TInt /*aOperationId*/, |
|
440 const TDesC& /*aUniqueId*/, |
|
441 TInt /*aRightsStatus*/, |
|
442 TInt /*aReason*/ ) |
|
443 { |
|
444 return DRM::EUEmbeddedPreviewActionIgnore; |
|
445 } |
|
446 |
|
447 // ---------------------------------------------------------------------------- |
|
448 // Unused observation method |
|
449 // ---------------------------------------------------------------------------- |
|
450 // |
|
451 DRM::TPreviewRightsAction CMPXDrmUiHelper::PreviewRightsUrlAvailable( |
|
452 TInt /*aOperationId*/, |
|
453 const TDesC& /*aPreviewRightsUrl*/, |
|
454 TInt /*aRightsStatus*/, |
|
455 TInt /*aReason*/ ) |
|
456 { |
|
457 return DRM::EUPreviewRightsActionIgnore; |
|
458 } |
|
459 |
|
460 // ---------------------------------------------------------------------------- |
|
461 // Unused observation method |
|
462 // ---------------------------------------------------------------------------- |
|
463 // |
|
464 DRM::TSilentRightsAction CMPXDrmUiHelper::SilentRightsUrlAvailable( |
|
465 TInt /*aOperationId*/, |
|
466 const TDesC& /*aSilentRightsUrl*/, |
|
467 TInt /*aRightsStatus*/, |
|
468 TInt /*aReason*/ ) |
|
469 { |
|
470 return DRM::EUSilentRightsActionDefault; |
|
471 } |
|
472 |
|
473 // ---------------------------------------------------------------------------- |
|
474 // Unused observation method |
|
475 // ---------------------------------------------------------------------------- |
|
476 // |
|
477 DRM::TRightsAction CMPXDrmUiHelper::RightsUrlAvailable( |
|
478 TInt /*aOperationId*/, |
|
479 const TDesC& /*aRightsUrl*/, |
|
480 TInt /*aRightsStatus*/, |
|
481 TInt /*aReason*/, |
|
482 TInt /*aUrlType*/ ) |
|
483 { |
|
484 return DRM::EURightsActionDefault; |
|
485 } |
|
486 |
|
487 // ---------------------------------------------------------------------------- |
|
488 // Unused observation method |
|
489 // ---------------------------------------------------------------------------- |
|
490 // |
|
491 void CMPXDrmUiHelper::PreviewRightsAvailable( |
|
492 TInt /*aOperationId*/, |
|
493 TInt /*aError*/ ) |
|
494 { |
|
495 } |
|
496 |
|
497 // ---------------------------------------------------------------------------- |
|
498 // Unused observation method |
|
499 // ---------------------------------------------------------------------------- |
|
500 // |
|
501 void CMPXDrmUiHelper::SilentRightsAvailable( |
|
502 TInt /*aOperationId*/, |
|
503 TInt /*aError*/ ) |
|
504 { |
|
505 } |
|
506 |
|
507 // ---------------------------------------------------------------------------- |
|
508 // Unused observation method |
|
509 // ---------------------------------------------------------------------------- |
|
510 // |
|
511 void CMPXDrmUiHelper::RightsAvailable( |
|
512 TInt /*aOperationId*/, |
|
513 TInt /*aError*/ ) |
|
514 { |
|
515 } |
|
516 |
|
517 // ---------------------------------------------------------------------------- |
|
518 // Unused observation method |
|
519 // ---------------------------------------------------------------------------- |
|
520 // |
|
521 void CMPXDrmUiHelper::PlayEmbeddedPreviewSelected( |
|
522 TInt /*aOperationId*/, |
|
523 const TDesC& /*aUniqueId*/ ) |
|
524 { |
|
525 } |
|
526 |
|
527 // ---------------------------------------------------------------------------- |
|
528 // Unused observation method |
|
529 // ---------------------------------------------------------------------------- |
|
530 // |
|
531 void CMPXDrmUiHelper::OperationCompleted( |
|
532 TInt /*aOperationId*/, TInt /*aOperationStatus*/ ) |
|
533 { |
|
534 } |
|
535 #endif |
|
536 // End of File |