|
1 /* |
|
2 * Copyright (c) 2005-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: Wallpaper setting utility class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include <AknsWallpaperUtils.h> |
|
21 #include <AknsSrvClient.h> |
|
22 #include <AknSkinsInternalCRKeys.h> |
|
23 #include <centralrepository.h> |
|
24 #include <DRMHelper.h> |
|
25 #include <DRMRights.h> |
|
26 #include <caf/manager.h> |
|
27 #include <coemain.h> |
|
28 #include <StringLoader.h> |
|
29 #include <AknWaitDialog.h> |
|
30 #include <AknWaitNoteWrapper.h> |
|
31 #include <babitflags.h> |
|
32 |
|
33 // CONSTANTS |
|
34 #if defined(RD_SLIDESHOW_WALLPAPER) |
|
35 // No wallpaper defined. |
|
36 const TInt KAknsWpNone = 0; |
|
37 // Image type wallpaper defined. |
|
38 const TInt KAknsWpImage = 1; |
|
39 #endif //RD_SLIDESHOW_WALLPAPER |
|
40 |
|
41 |
|
42 _LIT( KAknsSkinSrvSvgFileExt, ".svg" ); |
|
43 |
|
44 |
|
45 // Background process class. |
|
46 class CAknsWPUTask : public CBase, public MAknBackgroundProcess |
|
47 { |
|
48 public: // Construction |
|
49 CAknsWPUTask(RAknsSrvSession* aSkinSrvSession, |
|
50 CRepository* aSkinsRepository, |
|
51 const TDesC& aFilename) |
|
52 : iSkinSrvSession(aSkinSrvSession), |
|
53 iSkinsRepository(aSkinsRepository), |
|
54 iWPUErr( KErrNone ) |
|
55 { |
|
56 iInternalState.ClearAll(); |
|
57 iFilename = aFilename; |
|
58 } |
|
59 |
|
60 public: // From MAknBackgroundProcess |
|
61 TBool IsProcessDone() const |
|
62 { |
|
63 if ( iInternalState.IsSet( EAknsWpuSetWallpaper ) && |
|
64 iInternalState.IsSet( EAknsWpuTestDecode ) ) |
|
65 { |
|
66 return ETrue; |
|
67 } |
|
68 return EFalse; |
|
69 } |
|
70 |
|
71 void StepL() |
|
72 { |
|
73 if( IsProcessDone() ) |
|
74 { |
|
75 iInternalState.ClearAll(); |
|
76 return; |
|
77 } |
|
78 if ( iInternalState.IsClear( EAknsWpuTestDecode ) ) |
|
79 { |
|
80 DecodeWallpaperImageL( iFilename, *iSkinSrvSession ); |
|
81 iInternalState.Set( EAknsWpuTestDecode ); |
|
82 } |
|
83 else if ( iInternalState.IsClear( EAknsWpuSetWallpaper ) ) |
|
84 { |
|
85 iWPUErr = iSkinSrvSession->SetIdleWallpaper(iFilename); |
|
86 if (!iWPUErr) |
|
87 { |
|
88 iWPUErr = iSkinsRepository->Set(KPslnIdleBackgroundImagePath, iFilename); |
|
89 #if defined(RD_SLIDESHOW_WALLPAPER) |
|
90 if (iFilename.Length() > 0) |
|
91 { |
|
92 iWPUErr = iSkinsRepository->Set(KPslnWallpaperType, KAknsWpImage ); |
|
93 } |
|
94 else |
|
95 { |
|
96 iWPUErr = iSkinsRepository->Set(KPslnWallpaperType, KAknsWpNone ); |
|
97 } |
|
98 #endif //RD_SLIDESHOW_WALLPAPER |
|
99 } |
|
100 iInternalState.Set( EAknsWpuSetWallpaper ); |
|
101 } |
|
102 } |
|
103 void DialogDismissedL(TInt aButtonId ) |
|
104 { |
|
105 if ( aButtonId == KErrNotFound ) |
|
106 { |
|
107 // operation was cancelled |
|
108 } |
|
109 aButtonId++; |
|
110 } |
|
111 private: |
|
112 // ----------------------------------------------------------------------------- |
|
113 // Decodes selected image. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void DecodeWallpaperImageL( const TDesC& aFilename, RAknsSrvSession& aSkinSrvSession ) |
|
117 { |
|
118 if (aFilename.Length() > 0) |
|
119 { |
|
120 // check if the image is corrupted |
|
121 CFbsBitmap* bmp = NULL; |
|
122 CFbsBitmap* mask = NULL; |
|
123 // no way currently of checking corrupted svg:s |
|
124 if ((aFilename.Right(4)).CompareF( KAknsSkinSrvSvgFileExt )) |
|
125 { |
|
126 aSkinSrvSession.DecodeWallpaperImageL(aFilename, TSize(-1,-1), bmp, mask); |
|
127 } |
|
128 } |
|
129 } |
|
130 |
|
131 |
|
132 private: // Data |
|
133 /* |
|
134 * Internal state of the class. |
|
135 */ |
|
136 enum TPslnModelState |
|
137 { |
|
138 // initial state |
|
139 EAknsWpuModelStateInitial = 0x00000000, |
|
140 // do test decode for the image |
|
141 EAknsWpuTestDecode = 0x00000001, |
|
142 // set wallpaper |
|
143 EAknsWpuSetWallpaper = 0x00000002 }; |
|
144 TBitFlags iInternalState; |
|
145 |
|
146 // Filename for wallpaper. |
|
147 TFileName iFilename; |
|
148 |
|
149 // Skin server session. |
|
150 RAknsSrvSession* iSkinSrvSession; |
|
151 |
|
152 // Repository where to store wallpaper settings. |
|
153 CRepository* iSkinsRepository; |
|
154 |
|
155 public: // Public data |
|
156 |
|
157 // Error code, if any. |
|
158 TInt iWPUErr; |
|
159 }; |
|
160 |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // Checks if given file is DRM protected. |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 TBool IsDRMProtectedL(const TDesC& aFilename) |
|
167 { |
|
168 TBool isProtected(EFalse); |
|
169 TInt value = KErrNone; |
|
170 |
|
171 ContentAccess::CContent* content = ContentAccess::CContent::NewLC( aFilename ); |
|
172 User::LeaveIfError( content->GetAttribute( ContentAccess::EIsProtected, value ) ); |
|
173 if ( value ) |
|
174 { |
|
175 isProtected = ETrue; |
|
176 } |
|
177 CleanupStack::PopAndDestroy( content ); |
|
178 return isProtected; |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // Checks if given file can be set DRM automated content. |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TBool QueryAndSetAutomatedL(const TDesC& aFileName, CCoeEnv* aCoeEnv) |
|
186 { |
|
187 TBool set(ETrue); |
|
188 |
|
189 CDRMHelper* helper = NULL; |
|
190 if (!aCoeEnv) |
|
191 { |
|
192 helper = CDRMHelper::NewLC(); |
|
193 } |
|
194 else |
|
195 { |
|
196 helper = CDRMHelper::NewLC(*aCoeEnv); |
|
197 } |
|
198 TBool cansetautomated(EFalse); |
|
199 |
|
200 TInt result = helper->CanSetAutomated(aFileName, cansetautomated); |
|
201 if (!cansetautomated && result == KErrCANoRights) |
|
202 { |
|
203 if (aCoeEnv) |
|
204 { |
|
205 User::LeaveIfError(helper->HandleErrorL( result, |
|
206 aFileName ) ); |
|
207 } |
|
208 |
|
209 User::Leave(result); |
|
210 } |
|
211 if (!cansetautomated) |
|
212 { |
|
213 User::Leave(KAknsWpuErrorPreviewOnly); |
|
214 } |
|
215 |
|
216 CDRMHelperRightsConstraints* playconst = NULL; |
|
217 CDRMHelperRightsConstraints* dispconst = NULL; |
|
218 CDRMHelperRightsConstraints* execconst = NULL; |
|
219 CDRMHelperRightsConstraints* printconst = NULL; |
|
220 TBool expired(EFalse); |
|
221 TBool sendingallowed(EFalse); |
|
222 helper->GetRightsDetailsL( aFileName, |
|
223 CDRMRights::EDisplay, expired, sendingallowed, |
|
224 playconst, dispconst, execconst, printconst); |
|
225 delete playconst; |
|
226 delete execconst; |
|
227 delete printconst; |
|
228 CleanupStack::PushL(dispconst); |
|
229 |
|
230 if (dispconst->FullRights()) |
|
231 { |
|
232 set = ETrue; |
|
233 // Set the Fullrights content as automated also |
|
234 // and ignore the result... |
|
235 helper->SetAutomatedType(CDRMHelper::EAutomatedTypeWallpaper); |
|
236 if (!aCoeEnv) |
|
237 { |
|
238 helper->SetAutomatedSilent(aFileName, ETrue); |
|
239 } |
|
240 else |
|
241 { |
|
242 helper->SetAutomated( aFileName ); |
|
243 } |
|
244 } |
|
245 else |
|
246 { |
|
247 TInt res = KErrNone; |
|
248 helper->SetAutomatedType(CDRMHelper::EAutomatedTypeWallpaper); |
|
249 if (!aCoeEnv) |
|
250 { |
|
251 res = helper->SetAutomatedSilent( aFileName, ETrue ); |
|
252 } |
|
253 else |
|
254 { |
|
255 res = helper->SetAutomated( aFileName ); |
|
256 } |
|
257 |
|
258 if (res == KErrCancel) |
|
259 { |
|
260 set = EFalse; |
|
261 } |
|
262 else |
|
263 { |
|
264 User::LeaveIfError( res ); |
|
265 User::LeaveIfError( helper->ConsumeFile2(aFileName, CDRMRights::EDisplay, CDRMHelper::EStart) ); |
|
266 User::LeaveIfError( helper->ConsumeFile2(aFileName, CDRMRights::EDisplay, CDRMHelper::EFinish) ); |
|
267 |
|
268 set = ETrue; |
|
269 } |
|
270 } |
|
271 |
|
272 CleanupStack::PopAndDestroy(2); //helper, dispconst |
|
273 return set; |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // Sets image file as still image wallpaper. |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 void DoSetIdleWallpaperL(const TDesC& aFilename, CCoeEnv* aCoeEnv, TInt aWaitNoteTextResourceID, TInt aWaitNoteResourceID) |
|
281 { |
|
282 if (aFilename.Length() > 0) |
|
283 { |
|
284 RFs fs; |
|
285 TEntry fileentry; |
|
286 User::LeaveIfError(fs.Connect()); |
|
287 CleanupClosePushL(fs); |
|
288 User::LeaveIfError(fs.Entry(aFilename, fileentry)); |
|
289 if (fileentry.iSize == 0) |
|
290 { |
|
291 User::Leave(KErrCorrupt); |
|
292 } |
|
293 CleanupStack::PopAndDestroy(); // fs |
|
294 } |
|
295 |
|
296 |
|
297 RAknsSrvSession skinsrv; |
|
298 User::LeaveIfError(skinsrv.Connect()); |
|
299 CleanupClosePushL(skinsrv); |
|
300 CRepository* skinsrep = CRepository::NewL(KCRUidPersonalisation); |
|
301 CleanupStack::PushL(skinsrep); |
|
302 if (aFilename.Length()>0 && IsDRMProtectedL(aFilename)) |
|
303 { |
|
304 if (!QueryAndSetAutomatedL(aFilename, aCoeEnv)) |
|
305 { |
|
306 CleanupStack::PopAndDestroy(2); |
|
307 User::Leave(KErrCancel); |
|
308 } |
|
309 } |
|
310 if (aCoeEnv && (aWaitNoteTextResourceID && aWaitNoteResourceID)) |
|
311 { |
|
312 HBufC* noteText = StringLoader::LoadLC( aWaitNoteTextResourceID); |
|
313 CAknsWPUTask* wputask = new (ELeave) CAknsWPUTask(&skinsrv, skinsrep, aFilename); |
|
314 CleanupStack::PushL(wputask); |
|
315 CAknWaitNoteWrapper* wrapper = CAknWaitNoteWrapper::NewL(); |
|
316 CleanupDeletePushL(wrapper); |
|
317 |
|
318 TRAPD( executeErr, |
|
319 wrapper->ExecuteL( |
|
320 aWaitNoteResourceID, *wputask, *noteText, ETrue ) ); |
|
321 |
|
322 User::LeaveIfError(wputask->iWPUErr); |
|
323 |
|
324 CleanupStack::PopAndDestroy(3); // wrapper, wputask, noteText |
|
325 User::LeaveIfError( executeErr ); |
|
326 } |
|
327 else |
|
328 { |
|
329 // no "opening" note as no coeenv is given |
|
330 User::LeaveIfError(skinsrv.SetIdleWallpaper(aFilename)); |
|
331 User::LeaveIfError(skinsrep->Set(KPslnIdleBackgroundImagePath, aFilename)); |
|
332 #if defined(RD_SLIDESHOW_WALLPAPER) |
|
333 if (aFilename.Length() > 0) |
|
334 { |
|
335 User::LeaveIfError(skinsrep->Set(KPslnWallpaperType, KAknsWpImage)); |
|
336 } |
|
337 else |
|
338 { |
|
339 User::LeaveIfError(skinsrep->Set(KPslnWallpaperType, KAknsWpNone)); |
|
340 } |
|
341 #endif // RD_SLIDESHOW_WALLPAPER |
|
342 } |
|
343 |
|
344 CleanupStack::PopAndDestroy(2); // skinsrv, skinsrep |
|
345 } |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // Public API for setting image as wallpaper. |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 EXPORT_C TInt AknsWallpaperUtils::SetIdleWallpaper(const TDesC& aFilename, CCoeEnv* aCoeEnv, TInt aWaitNoteTextResourceID, TInt aWaitNoteResourceID) |
|
352 { |
|
353 TInt err(KErrNone); |
|
354 TRAP(err, DoSetIdleWallpaperL(aFilename, aCoeEnv, aWaitNoteTextResourceID, aWaitNoteResourceID)); |
|
355 return err; |
|
356 } |
|
357 |
|
358 #if defined(RD_SLIDESHOW_WALLPAPER) |
|
359 void ValidateEntriesL( CDesCArray& /*aSelectedFiles*/ , CCoeEnv* /*aCoeEnv*/ ) |
|
360 { |
|
361 } |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // Sets set of images as slideset wallpaper. |
|
365 // If there is only one image, it is set as normal wallpaper. |
|
366 // If there are no images in the slideset, then set as None. |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 void DoSetSlidesetWallpaperL(CDesCArray& aSelectedFiles, CCoeEnv* aCoeEnv, TInt aWaitNoteTextResourceID, TInt aWaitNoteResourceID) |
|
370 { |
|
371 TInt count = aSelectedFiles.MdcaCount(); |
|
372 if (!count) |
|
373 { |
|
374 DoSetIdleWallpaperL(KNullDesC, aCoeEnv, aWaitNoteTextResourceID, aWaitNoteResourceID); |
|
375 return; |
|
376 } |
|
377 // only one file, set it as normal wp. |
|
378 if (count == 1) |
|
379 { |
|
380 DoSetIdleWallpaperL(aSelectedFiles.MdcaPoint(0), aCoeEnv, aWaitNoteTextResourceID, aWaitNoteResourceID); |
|
381 } |
|
382 ValidateEntriesL( aSelectedFiles , aCoeEnv ); |
|
383 |
|
384 RAknsSrvSession skinsrv; |
|
385 User::LeaveIfError(skinsrv.Connect()); |
|
386 CleanupClosePushL(skinsrv); |
|
387 CRepository* skinsrep = CRepository::NewL(KCRUidPersonalisation); |
|
388 CleanupStack::PushL(skinsrep); |
|
389 User::LeaveIfError(skinsrv.SetSlideSetWallpaper(aSelectedFiles)); |
|
390 if (count != 1) |
|
391 { |
|
392 User::LeaveIfError(skinsrep->Set(KPslnWallpaperType, 2)); |
|
393 } |
|
394 CleanupStack::PopAndDestroy(2); // skinsrep, skinsrv |
|
395 |
|
396 } |
|
397 #endif //RD_SLIDESHOW_WALLPAPER |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // Public API for setting slide set wallpaper. |
|
401 // ----------------------------------------------------------------------------- |
|
402 // |
|
403 EXPORT_C TInt AknsWallpaperUtils::SetSlidesetWallpaper(CDesCArray& /*aSelectedFiles*/, CCoeEnv* /*aCoeEnv*/, TInt /*aWaitNoteTextResourceID*/, TInt /*aWaitNoteResourceID*/) |
|
404 { |
|
405 //deprecated for 9.2 page specific wallpaper |
|
406 return KErrNotSupported; |
|
407 } |
|
408 |
|
409 // End of file |
|
410 |