|
1 /* |
|
2 * Copyright (c) 2007-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: The settings model for the slideshow |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // CLASS HEADER |
|
23 #include "shwsettingsmodel.h" |
|
24 |
|
25 // EXTERNAL INCLUDES |
|
26 #include <centralrepository.h> |
|
27 |
|
28 // INTERNAL INCLUDES |
|
29 #include <glxlog.h> |
|
30 #include <glxtracer.h> |
|
31 #include "shwconstants.hrh" |
|
32 #include "shwconstants.h" |
|
33 |
|
34 // LOCAL CONSTANTS NAMESPACE |
|
35 namespace |
|
36 { |
|
37 // CenRep Key Ids |
|
38 const TUint32 KShwMusicOnOffKey = 0x00000001; |
|
39 const TUint32 KShwMusicNamePathKey = 0x00000002; |
|
40 const TUint32 KShwTransitionDelayKey= 0x00000003; |
|
41 const TUint32 KShwTransitionTypeKey = 0x00000004; |
|
42 const TUint32 KShwTransitionIndexKey= 0x00000005; |
|
43 const TUint32 KShwPlayOrder = 0x00000006; |
|
44 } |
|
45 |
|
46 /** |
|
47 * CShwCenRepWatcher |
|
48 * CShwSettingsModel containted class for observing changes in central |
|
49 * repository values |
|
50 * @internal reviewed 08/06/2007 by Kimmo Hoikka |
|
51 */ |
|
52 NONSHARABLE_CLASS( CShwSettingsModel::CShwCenRepWatcher ) |
|
53 : public CActive |
|
54 { |
|
55 public: // Constructors and destructor |
|
56 |
|
57 /** |
|
58 * Symbian Constructor. |
|
59 * @param aRepositoryUid uid of Central Repository file |
|
60 * @param aId id of the Central Repository key |
|
61 * @param aObserver obersver - only supplied when the owner is |
|
62 * interested in changes in key value |
|
63 * @return contructed object |
|
64 */ |
|
65 static CShwCenRepWatcher* NewL(const TUid& aRepositoryUid, |
|
66 TUint32 aId ); |
|
67 /** |
|
68 * Destructor. |
|
69 */ |
|
70 ~CShwCenRepWatcher(); |
|
71 |
|
72 public: // API |
|
73 |
|
74 /** |
|
75 * Get current value as integer. |
|
76 * @return Current value of the key as a TInt |
|
77 */ |
|
78 TInt KeyValueL() const; |
|
79 |
|
80 /** |
|
81 * Get current value as 16 bit descriptor. |
|
82 * @param return value of the key in the descriptor |
|
83 */ |
|
84 void KeyValueL(TDes& aKeyValue) const; |
|
85 |
|
86 /** |
|
87 * Set integer value |
|
88 * @param aNewValue New value for the key |
|
89 */ |
|
90 void SetKeyValueL(const TInt aNewValue); |
|
91 |
|
92 /** |
|
93 * Set string value |
|
94 * @param aNewValue New 16 bit descriptor value for the key |
|
95 */ |
|
96 void SetKeyValueL(const TDesC& aNewValue); |
|
97 |
|
98 private: // Implementation |
|
99 |
|
100 /** |
|
101 * C++ constructor. |
|
102 * @param aRepositoryUid uid of CenRep file |
|
103 * @param aId id of the key |
|
104 * @param aObserver obersver |
|
105 * @return contructed object |
|
106 */ |
|
107 CShwCenRepWatcher(const TUid& aRepositoryUid, TUint32 aId ); |
|
108 |
|
109 /** |
|
110 * 2nd phase constructor |
|
111 */ |
|
112 void ConstructL(); |
|
113 |
|
114 protected: // from CActive |
|
115 |
|
116 /** |
|
117 * @ref CActive::RunL |
|
118 */ |
|
119 void RunL(); |
|
120 |
|
121 /** |
|
122 * @ref CActive::DoCancel |
|
123 */ |
|
124 void DoCancel(); |
|
125 |
|
126 private: // Implementation |
|
127 |
|
128 // Own: the central repository API |
|
129 CRepository* iRepository; |
|
130 // the central repository identifier |
|
131 TUid iRepositoryUid; |
|
132 // the key id |
|
133 TUint32 iId; |
|
134 |
|
135 }; |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // Two-phased constructor. |
|
139 // ----------------------------------------------------------------------------- |
|
140 CShwSettingsModel::CShwCenRepWatcher* CShwSettingsModel::CShwCenRepWatcher::NewL |
|
141 (const TUid& aRepositoryUid, |
|
142 TUint32 aId ) |
|
143 { |
|
144 TRACER("CShwSettingsModel::CShwCenRepWatcher::NewL"); |
|
145 GLX_LOG_INFO("CShwSettingsModel::CShwCenRepWatcher::NewL"); |
|
146 |
|
147 CShwCenRepWatcher* self = |
|
148 new(ELeave) CShwCenRepWatcher( aRepositoryUid, aId ); |
|
149 CleanupStack::PushL( self ); |
|
150 self->ConstructL(); |
|
151 CleanupStack::Pop( self ); |
|
152 return self; |
|
153 } |
|
154 |
|
155 inline CShwSettingsModel::CShwCenRepWatcher::CShwCenRepWatcher( |
|
156 const TUid& aRepositoryUid, TUint32 aId ) |
|
157 : CActive(EPriorityStandard), |
|
158 iRepositoryUid(aRepositoryUid), |
|
159 iId(aId) |
|
160 { |
|
161 } |
|
162 |
|
163 // ---------------------------------------------------------------------------- |
|
164 // Symbian 2nd phase constructor |
|
165 // ---------------------------------------------------------------------------- |
|
166 void CShwSettingsModel::CShwCenRepWatcher::ConstructL() |
|
167 { |
|
168 TRACER("CShwSettingsModel::CShwCenRepWatcher::ConstructL"); |
|
169 GLX_LOG_INFO("CShwSettingsModel::CShwCenRepWatcher::ConstructL"); |
|
170 iRepository = CRepository::NewL(iRepositoryUid); |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------------------------------- |
|
174 // Destructor |
|
175 // ---------------------------------------------------------------------------- |
|
176 CShwSettingsModel::CShwCenRepWatcher::~CShwCenRepWatcher() |
|
177 { |
|
178 TRACER("CShwSettingsModel::CShwCenRepWatcher::~CShwCenRepWatcher"); |
|
179 GLX_LOG_INFO("CShwSettingsModel::CShwCenRepWatcher::~CShwCenRepWatcher"); |
|
180 Cancel(); |
|
181 delete iRepository; |
|
182 } |
|
183 |
|
184 // ---------------------------------------------------------------------------- |
|
185 // CShwCenRepWatcher::KeyValueL |
|
186 // ---------------------------------------------------------------------------- |
|
187 TInt CShwSettingsModel::CShwCenRepWatcher::KeyValueL() const |
|
188 { |
|
189 TRACER("CShwSettingsModel::CShwCenRepWatcher::KeyValueL() const"); |
|
190 GLX_LOG_INFO("CShwSettingsModel::CShwCenRepWatcher::KeyValueL() const"); |
|
191 TInt retVal = KErrNone; |
|
192 User::LeaveIfError( iRepository->Get(iId, retVal) ); |
|
193 return retVal; |
|
194 } |
|
195 |
|
196 // ---------------------------------------------------------------------------- |
|
197 // CShwCenRepWatcher::KeyValueL |
|
198 // ---------------------------------------------------------------------------- |
|
199 void CShwSettingsModel::CShwCenRepWatcher::KeyValueL(TDes& aKeyValue) const |
|
200 { |
|
201 TRACER("CShwSettingsModel::CShwCenRepWatcher::KeyValueL"); |
|
202 GLX_LOG_INFO("CShwSettingsModel::CShwCenRepWatcher::KeyValueL"); |
|
203 User::LeaveIfError( iRepository->Get(iId, aKeyValue) ); |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // CShwCenRepWatcher::SetKeyValueL |
|
208 // ---------------------------------------------------------------------------- |
|
209 void CShwSettingsModel::CShwCenRepWatcher::SetKeyValueL(const TInt aNewValue) |
|
210 { |
|
211 TRACER("CShwSettingsModel::CShwCenRepWatcher::SetKeyValueL(const TInt aNewValue)"); |
|
212 GLX_LOG_INFO("CShwSettingsModel::CShwCenRepWatcher::SetKeyValueL(const TInt aNewValue)"); |
|
213 User::LeaveIfError( iRepository->Set(iId, aNewValue) ); |
|
214 } |
|
215 |
|
216 // ---------------------------------------------------------------------------- |
|
217 // CShwCenRepWatcher::SetKeyValueL |
|
218 // ---------------------------------------------------------------------------- |
|
219 void CShwSettingsModel::CShwCenRepWatcher::SetKeyValueL(const TDesC& aNewValue) |
|
220 { |
|
221 TRACER("CShwSettingsModel::CShwCenRepWatcher::SetKeyValueL"); |
|
222 GLX_LOG_INFO("CShwSettingsModel::CShwCenRepWatcher::SetKeyValueL"); |
|
223 User::LeaveIfError( iRepository->Set(iId, aNewValue) ); |
|
224 } |
|
225 |
|
226 // ---------------------------------------------------------------------------- |
|
227 // CShwCenRepWatcher::RunL |
|
228 // ---------------------------------------------------------------------------- |
|
229 void CShwSettingsModel::CShwCenRepWatcher::RunL() |
|
230 { |
|
231 TRACER("CShwSettingsModel::CShwCenRepWatcher::SetKeyValueL"); |
|
232 GLX_LOG_INFO("CShwSettingsModel::CShwCenRepWatcher::RunL"); |
|
233 User::LeaveIfError(iRepository->NotifyRequest(iId, iStatus)); |
|
234 SetActive(); |
|
235 } |
|
236 |
|
237 // ---------------------------------------------------------------------------- |
|
238 // CShwCenRepWatcher::DoCancel |
|
239 // ---------------------------------------------------------------------------- |
|
240 void CShwSettingsModel::CShwCenRepWatcher::DoCancel() |
|
241 { |
|
242 TRACER("CShwSettingsModel::CShwCenRepWatcher::DoCancel"); |
|
243 GLX_LOG_INFO("CShwSettingsModel::CShwCenRepWatcher::DoCancel"); |
|
244 iRepository->NotifyCancel( iId ); |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------------------------------- |
|
248 // Symbian 2 phase constructor |
|
249 // ---------------------------------------------------------------------------- |
|
250 EXPORT_C CShwSettingsModel* CShwSettingsModel::NewL() |
|
251 { |
|
252 TRACER("CShwSettingsModel::NewL"); |
|
253 GLX_LOG_INFO("CShwSettingsModel::NewL"); |
|
254 |
|
255 CShwSettingsModel* self = new(ELeave) CShwSettingsModel(); |
|
256 CleanupStack::PushL(self); |
|
257 self->ConstructL(); |
|
258 CleanupStack::Pop(); |
|
259 return self; |
|
260 } |
|
261 |
|
262 // ---------------------------------------------------------------------------- |
|
263 // Destructor |
|
264 // ---------------------------------------------------------------------------- |
|
265 EXPORT_C CShwSettingsModel::~CShwSettingsModel() |
|
266 { |
|
267 TRACER("CShwSettingsModel::~CShwSettingsModel"); |
|
268 GLX_LOG_INFO("CShwSettingsModel::~CShwSettingsModel"); |
|
269 delete iPlayOrder; |
|
270 delete iMusicOnOffWatcher; |
|
271 delete iMusicNamePathWatcher; |
|
272 delete iTransDelayWatcher; |
|
273 delete iTransTypeWatcher; |
|
274 delete iTransIndexWatcher; |
|
275 } |
|
276 |
|
277 // ---------------------------------------------------------------------------- |
|
278 // C++ default constructor |
|
279 // ---------------------------------------------------------------------------- |
|
280 inline CShwSettingsModel::CShwSettingsModel() |
|
281 { |
|
282 } |
|
283 |
|
284 // ---------------------------------------------------------------------------- |
|
285 // Two-phased constructor. |
|
286 // ---------------------------------------------------------------------------- |
|
287 void CShwSettingsModel::ConstructL() |
|
288 { |
|
289 TRACER("CShwSettingsModel::ConstructL"); |
|
290 GLX_LOG_INFO("CShwSettingsModel::ConstructL"); |
|
291 const TInt KEngineId = 0x200071D3; |
|
292 const TUid KEngineUid = TUid::Uid( KEngineId ); |
|
293 iPlayOrder = CShwCenRepWatcher::NewL(KEngineUid, |
|
294 KShwPlayOrder ); |
|
295 iMusicOnOffWatcher = CShwCenRepWatcher::NewL(KEngineUid, |
|
296 KShwMusicOnOffKey ); |
|
297 iMusicNamePathWatcher = CShwCenRepWatcher::NewL(KEngineUid, |
|
298 KShwMusicNamePathKey ); |
|
299 iTransDelayWatcher = CShwCenRepWatcher::NewL(KEngineUid, |
|
300 KShwTransitionDelayKey ); |
|
301 iTransTypeWatcher = CShwCenRepWatcher::NewL(KEngineUid, |
|
302 KShwTransitionTypeKey ); |
|
303 iTransIndexWatcher = CShwCenRepWatcher::NewL(KEngineUid, |
|
304 KShwTransitionIndexKey ); |
|
305 } |
|
306 |
|
307 // ---------------------------------------------------------------------------- |
|
308 // CShwSettingsModel::PlayOrderL |
|
309 // returns persisted play order |
|
310 // ---------------------------------------------------------------------------- |
|
311 // |
|
312 EXPORT_C TInt CShwSettingsModel::PlayOrderL() |
|
313 { |
|
314 TRACER("CShwSettingsModel::PlayOrderL"); |
|
315 GLX_LOG_INFO("CShwSettingsModel::PlayOrderL"); |
|
316 TInt playState = iPlayOrder->KeyValueL(); |
|
317 ASSERT(playState == 0 || playState == 1); |
|
318 return playState; |
|
319 } |
|
320 |
|
321 // ---------------------------------------------------------------------------- |
|
322 // CShwSettingsModel::SavePlayOrderL |
|
323 // Persist the play order state |
|
324 // ---------------------------------------------------------------------------- |
|
325 // |
|
326 EXPORT_C void CShwSettingsModel::SavePlayOrderL(TInt aPlayOrder) |
|
327 { |
|
328 TRACER("CShwSettingsModel::SavePlayOrderL"); |
|
329 GLX_LOG_INFO("CShwSettingsModel::SaveMusicStateL"); |
|
330 |
|
331 ASSERT(aPlayOrder == 0 || aPlayOrder == 1); |
|
332 iPlayOrder->SetKeyValueL(aPlayOrder); |
|
333 } |
|
334 |
|
335 // ---------------------------------------------------------------------------- |
|
336 // CShwSettingsModel::SaveMusicOnOff |
|
337 // Persist the music on/off state |
|
338 // ---------------------------------------------------------------------------- |
|
339 EXPORT_C void CShwSettingsModel::SaveMusicStateL(TInt aMusicState) |
|
340 { |
|
341 TRACER("CShwSettingsModel::SaveMusicStateL"); |
|
342 GLX_LOG_INFO("CShwSettingsModel::SaveMusicStateL"); |
|
343 |
|
344 ASSERT(aMusicState == 0 || aMusicState == 1); |
|
345 iMusicOnOffWatcher->SetKeyValueL(aMusicState); |
|
346 } |
|
347 |
|
348 // ---------------------------------------------------------------------------- |
|
349 // CShwSettingsModel::MusicOnL |
|
350 // returns persisted the music on/off state |
|
351 // ---------------------------------------------------------------------------- |
|
352 EXPORT_C TInt CShwSettingsModel::MusicOnL() const |
|
353 { |
|
354 TRACER("CShwSettingsModel::MusicOnL"); |
|
355 GLX_LOG_INFO("CShwSettingsModel::MusicOnL"); |
|
356 TInt musicState = iMusicOnOffWatcher->KeyValueL(); |
|
357 ASSERT(musicState == 0 || musicState == 1); |
|
358 return musicState; |
|
359 } |
|
360 |
|
361 // ---------------------------------------------------------------------------- |
|
362 // CShwSettingsModel::SaveMusicNamePathL |
|
363 // Persist the name & path to the music file |
|
364 // ---------------------------------------------------------------------------- |
|
365 EXPORT_C void CShwSettingsModel::SaveMusicNamePathL(const TDesC& aMusicNamePath) |
|
366 { |
|
367 TRACER("CShwSettingsModel::SaveMusicNamePathL"); |
|
368 GLX_LOG_INFO("CShwSettingsModel::SaveMusicNamePathL"); |
|
369 // allow setting also empty value (there used to be an if here...) |
|
370 iMusicNamePathWatcher->SetKeyValueL( aMusicNamePath ); |
|
371 } |
|
372 |
|
373 // ---------------------------------------------------------------------------- |
|
374 // CShwSettingsModel::MusicNamePathL |
|
375 // returns persisted value of the music file name and path |
|
376 // ---------------------------------------------------------------------------- |
|
377 EXPORT_C void CShwSettingsModel::MusicNamePathL(TDes& aMusicNamePath) const |
|
378 { |
|
379 TRACER("CShwSettingsModel::MusicNamePathL"); |
|
380 GLX_LOG_INFO("CShwSettingsModel::MusicNamePathL"); |
|
381 iMusicNamePathWatcher->KeyValueL(aMusicNamePath); |
|
382 } |
|
383 |
|
384 // ---------------------------------------------------------------------------- |
|
385 // CShwSettingsModel::SaveTransDelayL |
|
386 // Persist the value for transition delay between slide |
|
387 // ---------------------------------------------------------------------------- |
|
388 EXPORT_C void CShwSettingsModel::SaveTransDelayL( TInt aTransDelay ) |
|
389 { |
|
390 TRACER("CShwSettingsModel::SaveTransDelayL"); |
|
391 GLX_LOG_INFO1("CShwSettingsModel::SaveTransDelayL %d", aTransDelay ); |
|
392 // check we are inside bounds |
|
393 aTransDelay = Max( aTransDelay, KMinTransDelay ); |
|
394 aTransDelay = Min( aTransDelay, KMaxTransDelay ); |
|
395 iTransDelayWatcher->SetKeyValueL(aTransDelay); |
|
396 } |
|
397 |
|
398 // ---------------------------------------------------------------------------- |
|
399 // CShwSettingsModel::TransDelayL |
|
400 // returns persisted transition delay value |
|
401 // ---------------------------------------------------------------------------- |
|
402 EXPORT_C TInt CShwSettingsModel::TransDelayL() const |
|
403 { |
|
404 TRACER("CShwSettingsModel::TransDelayL"); |
|
405 TInt transDelay = iTransDelayWatcher->KeyValueL(); |
|
406 GLX_LOG_INFO1( "CShwSettingsModel::TransDelayL %d", transDelay ); |
|
407 return transDelay; |
|
408 } |
|
409 |
|
410 // ---------------------------------------------------------------------------- |
|
411 // CShwSettingsModel::SaveTransitionType |
|
412 // Persist the transition effect type ECOM UID and index |
|
413 // ---------------------------------------------------------------------------- |
|
414 EXPORT_C void CShwSettingsModel::SaveTransitionTypeL(const TUid aEffectUid, |
|
415 const TUint aEffectIndex) |
|
416 { |
|
417 TRACER("CShwSettingsModel::SaveTransitionTypeL"); |
|
418 GLX_LOG_INFO("CShwSettingsModel::SaveTransitionTypeL"); |
|
419 iTransTypeWatcher->SetKeyValueL(aEffectUid.iUid); |
|
420 iTransIndexWatcher->SetKeyValueL(aEffectIndex); |
|
421 } |
|
422 |
|
423 |
|
424 // ---------------------------------------------------------------------------- |
|
425 // CShwSettingsModel::TransitionTypeL |
|
426 // returns persisted transition effect type ECOM UID and |
|
427 // index |
|
428 // ---------------------------------------------------------------------------- |
|
429 EXPORT_C void CShwSettingsModel::TransitionTypeL(TUid& aEffectUid, |
|
430 TUint& aEffectIndex) const |
|
431 { |
|
432 TRACER("CShwSettingsModel::TransitionTypeL"); |
|
433 GLX_LOG_INFO("CShwSettingsModel::TransitionTypeL"); |
|
434 aEffectUid.iUid = iTransTypeWatcher->KeyValueL(); |
|
435 aEffectIndex = iTransIndexWatcher->KeyValueL(); |
|
436 } |
|
437 |
|
438 // End of File |
|
439 |
|
440 |
|
441 |
|
442 |