|
1 /* |
|
2 * Copyright (c) 2005 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: This file implements all helper classes |
|
15 * for ScreenSaverAnimPlugin |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <DRMHelper.h> |
|
24 #include <coemain.h> |
|
25 #include <apgcli.h> |
|
26 #include <barsread.h> |
|
27 #include <aknnotewrappers.h> |
|
28 #include <centralrepository.h> |
|
29 |
|
30 #include <screensaveranimplugin.rsg> |
|
31 |
|
32 #include "ScreenSaverAnimPluginHelper.h" |
|
33 #include "ScreenSaverAnimPlugin.h" |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CScreenSaverAnimPluginVerifier::CScreenSaverAnimPluginVerifier |
|
39 // C++ default constructor can NOT contain any code, that might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CScreenSaverAnimPluginVerifier::CScreenSaverAnimPluginVerifier( |
|
43 CScreenSaverAnimPlugin* aFileVerify ) : |
|
44 iFileVerify( aFileVerify ) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CScreenSaverAnimPluginVerifier::ConstructL |
|
50 // Symbian 2nd phase constructor can leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CScreenSaverAnimPluginVerifier::ConstructL() |
|
54 { |
|
55 iCoeEnv = CCoeEnv::Static(); |
|
56 iDRMHelper = CDRMHelper::NewL( *iCoeEnv ); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CScreenSaverAnimPluginVerifier::NewL |
|
61 // Two-phased constructor. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CScreenSaverAnimPluginVerifier* CScreenSaverAnimPluginVerifier::NewL( |
|
65 CScreenSaverAnimPlugin* aFileVerify ) |
|
66 { |
|
67 CScreenSaverAnimPluginVerifier* self = new( ELeave ) |
|
68 CScreenSaverAnimPluginVerifier( aFileVerify ); |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop( self ); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CScreenSaverAnimPluginVerifier::~CScreenSaverAnimPluginVerifier |
|
77 // Destructor. |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CScreenSaverAnimPluginVerifier::~CScreenSaverAnimPluginVerifier() |
|
81 { |
|
82 delete iDRMHelper; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CScreenSaverAnimPluginVerifier::IsFileValidL |
|
87 // Empty implementation. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 TBool CScreenSaverAnimPluginVerifier::VerifySelectionL( const MDesCArray* |
|
91 aSelectedFiles ) |
|
92 { |
|
93 |
|
94 TBool canbeautomated( EFalse ); |
|
95 |
|
96 if( aSelectedFiles->MdcaCount()<1 ) |
|
97 { |
|
98 // Download item |
|
99 return ETrue; |
|
100 } |
|
101 |
|
102 // 1. Check whether the drm rights are ok |
|
103 TInt res = 0; |
|
104 iDRMHelper->SetAutomatedType( |
|
105 CDRMHelper::EAutomatedTypeScreenSaver ); |
|
106 res = iDRMHelper->CanSetAutomated( aSelectedFiles->MdcaPoint( 0 ), canbeautomated ); |
|
107 |
|
108 if ( res ) |
|
109 { |
|
110 iDRMHelper->HandleErrorL( res, aSelectedFiles->MdcaPoint( 0 ) ); |
|
111 return canbeautomated; |
|
112 } |
|
113 else if ( !canbeautomated ) |
|
114 { |
|
115 ShowErrorNoteL( R_DRM_PREV_RIGHTS_SET ); |
|
116 return canbeautomated; |
|
117 } |
|
118 |
|
119 // 2. Check whether the file is supported |
|
120 RApaLsSession ls; |
|
121 CleanupClosePushL( ls ); |
|
122 TUid dummyUid( KNullUid ); |
|
123 TDataType dataType; |
|
124 User::LeaveIfError( ls.Connect() ); |
|
125 // find the mimetype |
|
126 User::LeaveIfError( ls.AppForDocument( aSelectedFiles->MdcaPoint( 0 ), |
|
127 dummyUid, dataType ) ); |
|
128 |
|
129 CleanupStack::PopAndDestroy( &ls ); |
|
130 |
|
131 TResourceReader reader; |
|
132 TBool valid( EFalse ); |
|
133 iCoeEnv->CreateResourceReaderLC( reader, |
|
134 R_MIMETYPE_SPECIFIC_PLUGIN_ARRAY ); |
|
135 TInt countResource = reader.ReadInt16(); |
|
136 |
|
137 for ( TInt i = 0; i < countResource; i++ ) |
|
138 { |
|
139 HBufC* newMimeTypeEntry = reader.ReadHBufCL(); |
|
140 TPtr mimePtr( newMimeTypeEntry->Des() ); |
|
141 reader.ReadInt32(); |
|
142 if ( newMimeTypeEntry->Compare( dataType.Des() ) == 0 ) |
|
143 { |
|
144 valid = ETrue; |
|
145 } |
|
146 delete newMimeTypeEntry; |
|
147 } |
|
148 CleanupStack::PopAndDestroy(); // reader |
|
149 |
|
150 if ( !valid ) |
|
151 { |
|
152 // Pop a not supported error message |
|
153 ShowErrorNoteL( R_SANIM_NOT_SUPPORTED ); |
|
154 return EFalse; |
|
155 } |
|
156 |
|
157 //3. Check file for Validity |
|
158 |
|
159 //Display the confirmation query when setting |
|
160 //a DRM protected image as screensaver in General settings. |
|
161 TInt isCancel; |
|
162 isCancel = iDRMHelper->ShowAutomatedNote( aSelectedFiles->MdcaPoint( 0 ) ); |
|
163 if ( KErrCancel == isCancel ) |
|
164 { |
|
165 return EFalse; |
|
166 } |
|
167 |
|
168 |
|
169 TInt validity = KErrNone; |
|
170 TRAPD( err, |
|
171 validity = iFileVerify->CheckFileValidityL( aSelectedFiles->MdcaPoint( 0 ) )); |
|
172 |
|
173 if ( err ) |
|
174 { |
|
175 // Dll may not be present |
|
176 ShowErrorNoteL( R_SANIM_NOT_SUPPORTED ); |
|
177 return EFalse; |
|
178 } |
|
179 |
|
180 if ( validity == KErrNoMemory ) |
|
181 { |
|
182 // Pop up a Corrupted File message |
|
183 CEikonEnv::Static()->HandleError( validity ); |
|
184 return EFalse; |
|
185 } |
|
186 else if ( validity != KErrNone ) |
|
187 { |
|
188 TInt resourceId = R_SANIM_ERROR_WRONG_FORMAT; |
|
189 // Show information note |
|
190 ShowErrorNoteL( resourceId ); |
|
191 return EFalse; |
|
192 } |
|
193 |
|
194 return valid; |
|
195 |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CScreenSaverAnimPluginVerifier::ShowErrorNoteL |
|
200 // Displays the error note |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CScreenSaverAnimPluginVerifier::ShowErrorNoteL( TInt aResourceId ) const |
|
204 { |
|
205 HBufC* errorText = |
|
206 iCoeEnv->AllocReadResourceLC( aResourceId ); |
|
207 CAknInformationNote* note = new( ELeave ) CAknInformationNote( EFalse ); |
|
208 note->ExecuteLD( *errorText ); |
|
209 CleanupStack::PopAndDestroy( errorText ); // errorText |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CScreensaverRepositoryWatcher::NewL |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 CScreensaverRepositoryWatcher* CScreensaverRepositoryWatcher::NewL( |
|
217 const TUid aUid, |
|
218 const TUint32 aKey, |
|
219 CCenRepNotifyHandler::TCenRepKeyType aKeyType, |
|
220 TCallBack aCallBack, |
|
221 CRepository* aRepository ) |
|
222 { |
|
223 CScreensaverRepositoryWatcher* self = new( ELeave ) |
|
224 CScreensaverRepositoryWatcher( aUid, aKey, aCallBack, aRepository ); |
|
225 |
|
226 CleanupStack::PushL( self ); |
|
227 self->ConstructL( aKeyType ); |
|
228 CleanupStack::Pop( self ); |
|
229 |
|
230 return self; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CScreensaverRepositoryWatcher::NewL |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 CScreensaverRepositoryWatcher* CScreensaverRepositoryWatcher::NewL( |
|
238 const TUid aUid, |
|
239 TCallBack aCallBack, |
|
240 CRepository* aRepository ) |
|
241 { |
|
242 CScreensaverRepositoryWatcher* self = new( ELeave ) CScreensaverRepositoryWatcher( |
|
243 aUid, NCentralRepositoryConstants::KInvalidNotificationId, aCallBack, aRepository ); |
|
244 |
|
245 CleanupStack::PushL( self ); |
|
246 self->ConstructL(); |
|
247 CleanupStack::Pop( self ); |
|
248 |
|
249 return self; |
|
250 } |
|
251 |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CScreensaverRepositoryWatcher::~CScreensaverRepositoryWatcher |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 CScreensaverRepositoryWatcher::~CScreensaverRepositoryWatcher() |
|
258 { |
|
259 if ( iNotifyHandler ) |
|
260 { |
|
261 iNotifyHandler->StopListening(); |
|
262 delete iNotifyHandler; |
|
263 } |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CScreensaverRepositoryWatcher::CScreensaverRepositoryWatcher |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 CScreensaverRepositoryWatcher::CScreensaverRepositoryWatcher( |
|
271 const TUid aUid, |
|
272 const TUint32 aKey, |
|
273 TCallBack aCallBack, |
|
274 CRepository* aRepository ) |
|
275 : |
|
276 iUid( aUid ), iKey( aKey ), iCallBack( aCallBack ), iRepository( aRepository ) |
|
277 { |
|
278 } |
|
279 |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CScreensaverRepositoryWatcher::ConstructL |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CScreensaverRepositoryWatcher::ConstructL(CCenRepNotifyHandler::TCenRepKeyType aKeyType) |
|
286 { |
|
287 iNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iRepository, aKeyType, iKey ); |
|
288 iNotifyHandler->StartListeningL(); |
|
289 } |
|
290 |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CScreensaverRepositoryWatcher::ConstructL |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CScreensaverRepositoryWatcher::ConstructL() |
|
297 { |
|
298 iNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iRepository ); |
|
299 iNotifyHandler->StartListeningL(); |
|
300 } |
|
301 |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CScreensaverRepositoryWatcher::ChangedKey |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 TUint32 CScreensaverRepositoryWatcher::ChangedKey() |
|
308 { |
|
309 return iChangedKey; |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CScreensaverRepositoryWatcher::HandleNotifyInt |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 void CScreensaverRepositoryWatcher::HandleNotifyInt( |
|
317 TUint32 aKey, TInt /*aNewValue*/ ) |
|
318 { |
|
319 iChangedKey = aKey; |
|
320 iCallBack.CallBack(); |
|
321 iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId; |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CScreensaverRepositoryWatcher::HandleNotifyString |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 void CScreensaverRepositoryWatcher::HandleNotifyString( TUint32 aKey, |
|
329 const TDesC16& /*aNewValue*/ ) |
|
330 { |
|
331 iChangedKey = aKey; |
|
332 iCallBack.CallBack(); |
|
333 iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId; |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CScreensaverRepositoryWatcher::HandleNotifyGeneric |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 void CScreensaverRepositoryWatcher::HandleNotifyGeneric(TUint32 aKey) |
|
341 { |
|
342 iChangedKey = aKey; |
|
343 iCallBack.CallBack(); |
|
344 iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId; |
|
345 } |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // CScreensaverRepositoryWatcher::HandleNotifyError |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void CScreensaverRepositoryWatcher::HandleNotifyError(TUint32 /*aKey*/, TInt /*aError*/, CCenRepNotifyHandler* /*aHandler*/) |
|
352 { |
|
353 } |
|
354 |
|
355 // End of File |