|
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: SlideshowPlugin utility classes and functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <centralrepository.h> |
|
22 #include <f32fsys.h> |
|
23 #include <eikenv.h> |
|
24 #include <pathinfo.h> |
|
25 #include <DRMHelper.h> |
|
26 #include <caf/caftypes.h> |
|
27 |
|
28 #include "SlideshowPluginUtils.h" |
|
29 |
|
30 _LIT(KSSPDriveLetterMC, "E"); |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // Repository watcher |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CRepositoryWatcher::NewL |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CRepositoryWatcher* CRepositoryWatcher::NewL( |
|
41 const TUid aUid, |
|
42 const TUint32 aKey, |
|
43 CCenRepNotifyHandler::TCenRepKeyType aKeyType, |
|
44 TCallBack aCallBack, |
|
45 CRepository* aRepository) |
|
46 { |
|
47 CRepositoryWatcher* self = new(ELeave) |
|
48 CRepositoryWatcher(aUid, aKey, aCallBack, aRepository); |
|
49 |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(aKeyType); |
|
52 CleanupStack::Pop(self); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CRepositoryWatcher::NewL |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CRepositoryWatcher* CRepositoryWatcher::NewL( |
|
62 const TUid aUid, |
|
63 TCallBack aCallBack, |
|
64 CRepository* aRepository) |
|
65 { |
|
66 CRepositoryWatcher* self = new(ELeave) CRepositoryWatcher( |
|
67 aUid, NCentralRepositoryConstants::KInvalidNotificationId, aCallBack, aRepository); |
|
68 |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop(self); |
|
72 |
|
73 return self; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CRepositoryWatcher::~CRepositoryWatcher |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CRepositoryWatcher::~CRepositoryWatcher() |
|
81 { |
|
82 if ( iNotifyHandler ) |
|
83 { |
|
84 iNotifyHandler->StopListening(); |
|
85 delete iNotifyHandler; |
|
86 } |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CRepositoryWatcher::CRepositoryWatcher |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CRepositoryWatcher::CRepositoryWatcher( |
|
94 const TUid aUid, |
|
95 const TUint32 aKey, |
|
96 TCallBack aCallBack, |
|
97 CRepository* aRepository) |
|
98 : |
|
99 iUid(aUid), iKey(aKey), iCallBack(aCallBack), iRepository(aRepository) |
|
100 { |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CRepositoryWatcher::ConstructL |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void CRepositoryWatcher::ConstructL(CCenRepNotifyHandler::TCenRepKeyType aKeyType) |
|
108 { |
|
109 iNotifyHandler = CCenRepNotifyHandler::NewL(*this, *iRepository, aKeyType, iKey); |
|
110 iNotifyHandler->StartListeningL(); |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CRepositoryWatcher::ConstructL |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 void CRepositoryWatcher::ConstructL() |
|
118 { |
|
119 iNotifyHandler = CCenRepNotifyHandler::NewL(*this, *iRepository); |
|
120 iNotifyHandler->StartListeningL(); |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CRepositoryWatcher::ChangedKey |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 TUint32 CRepositoryWatcher::ChangedKey() |
|
128 { |
|
129 return iChangedKey; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CRepositoryWatcher::HandleNotifyInt |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CRepositoryWatcher::HandleNotifyInt( |
|
137 TUint32 aKey, TInt /*aNewValue*/ ) |
|
138 { |
|
139 iChangedKey = aKey; |
|
140 iCallBack.CallBack(); |
|
141 iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId; |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // CRepositoryWatcher::HandleNotifyString |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 void CRepositoryWatcher::HandleNotifyString( TUint32 aKey, |
|
149 const TDesC16& /*aNewValue*/ ) |
|
150 { |
|
151 iChangedKey = aKey; |
|
152 iCallBack.CallBack(); |
|
153 iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // CRepositoryWatcher::HandleNotifyGeneric |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 void CRepositoryWatcher::HandleNotifyGeneric(TUint32 aKey) |
|
161 { |
|
162 iChangedKey = aKey; |
|
163 iCallBack.CallBack(); |
|
164 iChangedKey = NCentralRepositoryConstants::KInvalidNotificationId; |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CRepositoryWatcher::HandleNotifyError |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CRepositoryWatcher::HandleNotifyError(TUint32 /*aKey*/, TInt /*aError*/, CCenRepNotifyHandler* /*aHandler*/) |
|
172 { |
|
173 } |
|
174 |
|
175 |
|
176 // P & S subscriber |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CPSSubscriber::CPSSubscriber |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 CPSSubscriber::CPSSubscriber(TCallBack aCallBack, RProperty& aProperty) |
|
183 : CActive(EPriorityNormal), iCallBack(aCallBack), iProperty(aProperty) |
|
184 { |
|
185 CActiveScheduler::Add(this); |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // CPSSubscriber::~CPSSubscriber |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 CPSSubscriber::~CPSSubscriber() |
|
193 { |
|
194 Cancel(); |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // CPSSubscriber::SubscribeL |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 void CPSSubscriber::SubscribeL() |
|
202 { |
|
203 if (!IsActive()) |
|
204 { |
|
205 iProperty.Subscribe(iStatus); |
|
206 SetActive(); |
|
207 } |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // CPSSubscriber::StopSubscribe |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 void CPSSubscriber::StopSubscribe() |
|
215 { |
|
216 Cancel(); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // CPSSubscriber::RunL |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void CPSSubscriber::RunL() |
|
224 { |
|
225 if (iStatus.Int() == KErrNone) |
|
226 { |
|
227 iCallBack.CallBack(); |
|
228 SubscribeL(); |
|
229 } |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // CPSSubscriber::DoCancel |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 void CPSSubscriber::DoCancel() |
|
237 { |
|
238 iProperty.Cancel(); |
|
239 } |
|
240 |
|
241 |
|
242 |
|
243 // ========== UTILITIES CLASS =============================== |
|
244 |
|
245 // Checks if memory card is present |
|
246 TBool SlideshowUtil::IsMCPresent() |
|
247 { |
|
248 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
249 |
|
250 TInt error = KErrNone; |
|
251 TDriveInfo driveInfo; |
|
252 TInt res = 0; |
|
253 TInt err = fs.CharToDrive(PathInfo::MemoryCardRootPath()[0], res); |
|
254 error = fs.Drive(driveInfo, res ); |
|
255 |
|
256 // Not present, locked or unknown is bad |
|
257 if ((error != KErrNone) || |
|
258 (driveInfo.iMediaAtt & KMediaAttLocked) || |
|
259 (driveInfo.iType == EMediaNotPresent) || |
|
260 (driveInfo.iType == EMediaUnknown)) |
|
261 { |
|
262 return EFalse; |
|
263 } |
|
264 |
|
265 // Read-only is fine |
|
266 return ETrue; |
|
267 } |
|
268 |
|
269 |
|
270 // Checks if the given file is on memory card |
|
271 TBool SlideshowUtil::IsOnMC(TFileName aFile) |
|
272 { |
|
273 // Grab drive letter from path and compare to memory card drive letter |
|
274 TBuf<1> driveLetterBuf; |
|
275 driveLetterBuf.CopyUC(aFile.Left(1)); |
|
276 |
|
277 if (driveLetterBuf.Compare(KSSPDriveLetterMC) == 0) |
|
278 { |
|
279 return ETrue; |
|
280 } |
|
281 |
|
282 return EFalse; |
|
283 } |
|
284 |
|
285 |
|
286 // Checks that the file has enough DRM rights to be displayed |
|
287 TBool SlideshowUtil::DRMCheck(CDRMHelper *aDRMHelper, TDesC& /* aFileName */) |
|
288 { |
|
289 if (!aDRMHelper) |
|
290 { |
|
291 return EFalse; |
|
292 } |
|
293 |
|
294 return ETrue; |
|
295 } |
|
296 |
|
297 |
|
298 // Checks that the slide has enough DRM rights to be displayed |
|
299 TBool SlideshowUtil::DRMCheck(CDRMHelper *aDRMHelper, CSlideshowSlide* aSlide) |
|
300 { |
|
301 if (!aDRMHelper || !aSlide) |
|
302 { |
|
303 return EFalse; |
|
304 } |
|
305 |
|
306 return (DRMCheck(aDRMHelper, *(aSlide->FileName()))); |
|
307 } |
|
308 |
|
309 |
|
310 // Consumes the slide's DRM rights |
|
311 void SlideshowUtil::DRMConsume(CDRMHelper* aDRMHelper, CSlideshowSlide* aSlide) |
|
312 { |
|
313 if (!aDRMHelper || !aSlide) |
|
314 { |
|
315 return; |
|
316 } |
|
317 |
|
318 aDRMHelper->ConsumeFile2(*(aSlide->FileName()), |
|
319 ContentAccess::EView, |
|
320 CDRMHelper::EStart); |
|
321 aDRMHelper->ConsumeFile2(*(aSlide->FileName()), |
|
322 ContentAccess::EView, |
|
323 CDRMHelper::EFinish); |
|
324 } |
|
325 |
|
326 |
|
327 // End of File |