|
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: Implementation of Screen Saver Plugin |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <eikenv.h> |
|
22 #include <bautils.h> |
|
23 #include <AknUtils.h> |
|
24 #include <data_caging_path_literals.hrh> |
|
25 #include <MProfileEngine.h> |
|
26 #include <MProfile.h> |
|
27 #include <MProfileName.h> |
|
28 #include <Profile.hrh> // profile ID |
|
29 #include <StringLoader.h> |
|
30 |
|
31 #include <mpxscreensaverplugin.rsg> |
|
32 #include <mpxscreensaverplugin.mbg> |
|
33 #include <mpxplaybackutility.h> |
|
34 #include <mpxplaybackmessage.h> |
|
35 #include <mpxmedia.h> |
|
36 #include <mpxmediageneraldefs.h> |
|
37 #include <mpxmessagegeneraldefs.h> |
|
38 #include <mpxlog.h> |
|
39 #include <mpxuser.h> |
|
40 |
|
41 #include "mpxscreensaverplugin.hrh" |
|
42 #include "mpxscreensaverplugincontainer.h" |
|
43 #include "mpxscreensaverplugin.h" |
|
44 |
|
45 // Constants |
|
46 const TInt KTimerInterval = 30000000; // 30 seconds |
|
47 const TInt KTimerForceNextUpdateInterval = 1000; // 1 milli second |
|
48 |
|
49 _LIT( KResourceFileName, "mpxscreensaverplugin.rsc" ); |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CMPXScreenSaverPlugin::NewL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CMPXScreenSaverPlugin* CMPXScreenSaverPlugin::NewL() |
|
56 { |
|
57 MPX_FUNC( "CMPXScreenSaverPlugin::NewL" ); |
|
58 CMPXScreenSaverPlugin* self = new ( ELeave ) CMPXScreenSaverPlugin(); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // CMPXScreenSaverPlugin::~CMPXScreenSaverPlugin |
|
67 // ---------------------------------------------------------------------------- |
|
68 // |
|
69 CMPXScreenSaverPlugin::~CMPXScreenSaverPlugin() |
|
70 { |
|
71 MPX_DEBUG1( "CMPXScreenSaverPlugin::~CMPXScreenSaverPlugin START" ); |
|
72 if ( iResourceOffset != 0 ) |
|
73 { |
|
74 iEikEnv->DeleteResourceFile( iResourceOffset ); |
|
75 } |
|
76 if ( iPlaybackUtility ) |
|
77 { |
|
78 iPlaybackUtility->Close(); |
|
79 } |
|
80 |
|
81 if ( iProfileEngine ) |
|
82 { |
|
83 iProfileEngine->Release(); |
|
84 } |
|
85 |
|
86 if ( iContainer ) |
|
87 { |
|
88 delete iContainer; |
|
89 } |
|
90 |
|
91 delete iDisplayName; |
|
92 |
|
93 MPX_DEBUG1( "CMPXScreenSaverPlugin::~CMPXScreenSaverPlugin END" ); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CMPXScreenSaverPlugin::InitializeL |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 TInt CMPXScreenSaverPlugin::InitializeL( MScreensaverPluginHost *aHost ) |
|
101 { |
|
102 MPX_FUNC( "CMPXScreenSaverPlugin::InitializeL" ); |
|
103 if ( !aHost ) |
|
104 { |
|
105 return KErrCancel; |
|
106 } |
|
107 iScreenSaverHost = aHost; |
|
108 iScreenSaverHost->OverrideStandardIndicators(); |
|
109 iScreenSaverHost->UseRefreshTimer( ETrue ); |
|
110 iScreenSaverHost->SetRefreshTimerValue( KTimerInterval ); |
|
111 |
|
112 CreateContainerL(); |
|
113 |
|
114 return KErrNone; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CMPXScreenSaverPlugin::Draw |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 TInt CMPXScreenSaverPlugin::Draw( CWindowGc& aGc ) |
|
122 { |
|
123 MPX_FUNC( "CMPXScreenSaverPlugin::Draw" ); |
|
124 |
|
125 TInt status = KErrNone; |
|
126 TIndicatorPayload result; |
|
127 |
|
128 // EScreensaverEventStarting event should come before draw |
|
129 // iContainer should be available |
|
130 // Check for missed calls |
|
131 status = iScreenSaverHost->GetIndicatorPayload( |
|
132 EScreensaverIndicatorIndexNewMissedCalls, result ); |
|
133 MPX_DEBUG2( "CMPXScreenSaverPlugin::Draw status = %d", status ); |
|
134 MPX_DEBUG4( "CMPXScreenSaverPlugin::Draw EScreensaverIndicatorIndexNewMissedCalls iType = %d, iInteger = %d, iIsDisplayed = %d", result.iType, result.iInteger, result.iIsDisplayed ); |
|
135 if ( KErrNone == status) |
|
136 { |
|
137 iContainer->SetParam( MPXScreenSaverPluginParamMissedCall, |
|
138 result.iInteger ); |
|
139 } |
|
140 |
|
141 // Check for new messages |
|
142 status = iScreenSaverHost->GetIndicatorPayload( |
|
143 EScreensaverIndicatorIndexNewMessages, result ); |
|
144 MPX_DEBUG2( "CMPXScreenSaverPlugin::Draw status = %d", status ); |
|
145 MPX_DEBUG4( "CMPXScreenSaverPlugin::Draw EScreensaverIndicatorIndexNewMessages iType = %d, iInteger = %d, iIsDisplayed = %d", result.iType, result.iInteger, result.iIsDisplayed ); |
|
146 if ( KErrNone == status ) |
|
147 { |
|
148 iContainer->SetParam( MPXScreenSaverPluginParamNewMessage, |
|
149 result.iInteger ); |
|
150 } |
|
151 |
|
152 // Check for new instant messages |
|
153 status = iScreenSaverHost->GetIndicatorPayload( |
|
154 EScreensaverIndicatorIndexChatMessage, result ); |
|
155 MPX_DEBUG2( "CMPXScreenSaverPlugin::Draw status = %d", status ); |
|
156 MPX_DEBUG4( "CMPXScreenSaverPlugin::Draw EScreensaverIndicatorIndexChatMessage iType = %d, iInteger = %d, iIsDisplayed = %d", result.iType, result.iInteger, result.iIsDisplayed ); |
|
157 if ( KErrNone == status ) |
|
158 { |
|
159 iContainer->SetParam( MPXScreenSaverPluginParamInstantMessage, |
|
160 result.iIsDisplayed ? 1: 0 ); |
|
161 } |
|
162 |
|
163 // Check for new email |
|
164 status = iScreenSaverHost->GetIndicatorPayload( |
|
165 EScreensaverIndicatorIndexEmail, result ); |
|
166 MPX_DEBUG2( "CMPXScreenSaverPlugin::Draw status = %d", status ); |
|
167 MPX_DEBUG4( "CMPXScreenSaverPlugin::Draw EScreensaverIndicatorIndexEmail iType = %d, iInteger = %d, iIsDisplayed = %d", result.iType, result.iInteger, result.iIsDisplayed ); |
|
168 if ( KErrNone == status ) |
|
169 { |
|
170 iContainer->SetParam( MPXScreenSaverPluginParamEmail, |
|
171 result.iIsDisplayed ? 1: 0 ); |
|
172 } |
|
173 |
|
174 // Check for new voice messages |
|
175 status = iScreenSaverHost->GetIndicatorPayload( |
|
176 EScreensaverIndicatorIndexVoicemail, result ); |
|
177 MPX_DEBUG2( "CMPXScreenSaverPlugin::Draw status = %d", status ); |
|
178 MPX_DEBUG4( "CMPXScreenSaverPlugin::Draw EScreensaverIndicatorIndexVoicemail iType = %d, iInteger = %d, iIsDisplayed = %d", result.iType, result.iInteger, result.iIsDisplayed ); |
|
179 if ( KErrNone == status ) |
|
180 { |
|
181 iContainer->SetParam( MPXScreenSaverPluginParamVoiceMessage, |
|
182 result.iIsDisplayed ? 1: 0 ); |
|
183 } |
|
184 |
|
185 // Check for keyguard |
|
186 status = iScreenSaverHost->GetIndicatorPayload( |
|
187 EScreensaverIndicatorIndexKeyGuardState, result ); |
|
188 MPX_DEBUG2( "CMPXScreenSaverPlugin::Draw status = %d", status ); |
|
189 MPX_DEBUG4( "CMPXScreenSaverPlugin::Draw EScreensaverIndicatorIndexKeyGuardState iType = %d, iInteger = %d, iIsDisplayed = %d", result.iType, result.iInteger, result.iIsDisplayed ); |
|
190 if ( KErrNone == status ) |
|
191 { |
|
192 iContainer->SetParam( MPXScreenSaverPluginParamKeyguard, |
|
193 result.iIsDisplayed ? 1: 0 ); |
|
194 } |
|
195 |
|
196 TRAP_IGNORE( iContainer->DrawL( aGc, iPlaybackState ) ); |
|
197 |
|
198 if ( iTimerChanged ) |
|
199 { |
|
200 MPX_DEBUG1( "CMPXScreenSaverPlugin::Draw Revert back to original timer" ); |
|
201 iScreenSaverHost->SetRefreshTimerValue( KTimerInterval ); |
|
202 iScreenSaverHost->UseRefreshTimer( ETrue ); |
|
203 iTimerChanged = EFalse; |
|
204 } |
|
205 |
|
206 return status; |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CMPXScreenSaverPlugin::Name |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 const TDesC16& CMPXScreenSaverPlugin::Name() const |
|
214 { |
|
215 MPX_FUNC( "CMPXScreenSaverPlugin::Name" ); |
|
216 if ( iDisplayName ) |
|
217 { |
|
218 return *iDisplayName; |
|
219 } |
|
220 else |
|
221 { |
|
222 return KNullDesC; |
|
223 } |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CMPXScreenSaverPlugin::Capabilities |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 TInt CMPXScreenSaverPlugin::Capabilities() |
|
231 { |
|
232 MPX_FUNC( "CMPXScreenSaverPlugin::Capabilities" ); |
|
233 return EScpCapsNone; |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CMPXScreenSaverPlugin::PluginFunction |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 TInt CMPXScreenSaverPlugin::PluginFunction( |
|
241 TScPluginCaps /*aFunction*/, |
|
242 TAny* /*aParam*/) |
|
243 { |
|
244 MPX_FUNC( "CMPXScreenSaverPlugin::PluginFunction" ); |
|
245 return KErrNone; |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CMPXScreenSaverPlugin::HandleScreensaverEventL |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 TInt CMPXScreenSaverPlugin::HandleScreensaverEventL( |
|
253 TScreensaverEvent aEvent, |
|
254 TAny* /*aData*/ ) |
|
255 { |
|
256 MPX_DEBUG2( "-->CMPXScreenSaverPlugin::HandleScreensaverEventL event = %d", aEvent ); |
|
257 |
|
258 if ( aEvent == EScreensaverEventDisplayChanged ) |
|
259 { |
|
260 if ( iContainer ) |
|
261 { |
|
262 iContainer->RefreshDisplayInfo(); |
|
263 } |
|
264 } |
|
265 else if ( aEvent == EScreensaverEventStarting ) |
|
266 { |
|
267 if ( !iContainer ) |
|
268 { |
|
269 CreateContainerL(); |
|
270 } |
|
271 MProfile* profile = iProfileEngine->ActiveProfileL(); |
|
272 if( profile ) |
|
273 { |
|
274 if ( iProfileEngine->ActiveProfileId() != EProfileGeneralId ) |
|
275 { |
|
276 // active profile is not general profile |
|
277 const MProfileName& profileName = profile->ProfileName(); |
|
278 TRAP_IGNORE( iContainer->SetProfileNameL( profileName.Name(), ETrue ) ); |
|
279 } |
|
280 else |
|
281 { |
|
282 TRAP_IGNORE( iContainer->SetProfileNameL( KNullDesC, EFalse ) ); |
|
283 } |
|
284 iContainer->SetParam( MPXScreenSaverPluginParamIsSilent, |
|
285 profile->IsSilent() ); |
|
286 profile->Release(); |
|
287 } |
|
288 profile = NULL; |
|
289 } |
|
290 else if ( aEvent == EScreensaverEventStopping ) |
|
291 { |
|
292 delete iContainer; |
|
293 iContainer = NULL; |
|
294 } |
|
295 MPX_DEBUG1( "<--CMPXScreenSaverPlugin::HandleScreensaverEventL" ); |
|
296 return KErrNone; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CMPXScreenSaverPlugin::CMPXScreenSaverPlugin |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 CMPXScreenSaverPlugin::CMPXScreenSaverPlugin(): |
|
304 iPlaybackState( EPbStateNotInitialised ) |
|
305 { |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CMPXScreenSaverPlugin::ConstructL |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 void CMPXScreenSaverPlugin::ConstructL() |
|
313 { |
|
314 MPX_FUNC( "CMPXScreenSaverPlugin::ConstructL" ); |
|
315 iEikEnv = CEikonEnv::Static(); |
|
316 TParse lParse; |
|
317 lParse.Set( KResourceFileName, &KDC_APP_RESOURCE_DIR, NULL); |
|
318 TFileName resourceFile( lParse.FullName() ); |
|
319 User::LeaveIfError( MPXUser::CompleteWithDllPath( resourceFile ) ); |
|
320 |
|
321 BaflUtils::NearestLanguageFile( iEikEnv->FsSession(), resourceFile ); |
|
322 iResourceOffset = iEikEnv->AddResourceFileL( resourceFile ); |
|
323 |
|
324 iPlaybackUtility = MMPXPlaybackUtility::NewL( KPbModeActivePlayer, this ); |
|
325 iProfileEngine = CreateProfileEngineL(); |
|
326 iDisplayName = StringLoader::LoadL( R_MPX_SCREENSAVER_DISPLAY_NAME ); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // From MMPXPlaybackObserver |
|
331 // Handle playback message. |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 void CMPXScreenSaverPlugin::HandlePlaybackMessage( |
|
335 CMPXMessage* aMessage, TInt aError ) |
|
336 { |
|
337 if ( aError == KErrNone && aMessage ) |
|
338 { |
|
339 TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) ); |
|
340 } |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------------------------- |
|
344 // From MMPXPlaybackCallback |
|
345 // Handle playback property. |
|
346 // --------------------------------------------------------------------------- |
|
347 // |
|
348 void CMPXScreenSaverPlugin::HandlePropertyL( |
|
349 TMPXPlaybackProperty /* aProperty */, |
|
350 TInt /* aValue */, |
|
351 TInt /* aError */ ) |
|
352 { |
|
353 // do nothing |
|
354 } |
|
355 |
|
356 // --------------------------------------------------------------------------- |
|
357 // From MMPXPlaybackCallback |
|
358 // Method is called continously until aComplete=ETrue, signifying that |
|
359 // it is done and there will be no more callbacks |
|
360 // Only new items are passed each time |
|
361 // --------------------------------------------------------------------------- |
|
362 // |
|
363 void CMPXScreenSaverPlugin::HandleSubPlayerNamesL( |
|
364 TUid /* aPlayer */, |
|
365 const MDesCArray* /* aSubPlayers */, |
|
366 TBool /* aComplete */, |
|
367 TInt /* aError */ ) |
|
368 { |
|
369 // do nothing |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------------------------- |
|
373 // From MMPXPlaybackCallback |
|
374 // Handle media properties. |
|
375 // Notes: The client is responsible for delete the object of aProperties. |
|
376 // --------------------------------------------------------------------------- |
|
377 // |
|
378 void CMPXScreenSaverPlugin::HandleMediaL( |
|
379 const CMPXMedia& aMedia, |
|
380 TInt aError ) |
|
381 { |
|
382 TRAP_IGNORE( DoHandleMediaL( aMedia, aError ) ); |
|
383 } |
|
384 |
|
385 // --------------------------------------------------------------------------- |
|
386 // Handle playback message. |
|
387 // --------------------------------------------------------------------------- |
|
388 // |
|
389 void CMPXScreenSaverPlugin::DoHandlePlaybackMessageL( |
|
390 const CMPXMessage& aMessage ) |
|
391 { |
|
392 MPX_FUNC( "CMPXScreenSaverPlugin::DoHandlePlaybackMessageL" ); |
|
393 TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
394 if ( KMPXMessageGeneral == id ) |
|
395 { |
|
396 TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) ); |
|
397 TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) ); |
|
398 switch ( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) ) |
|
399 { |
|
400 case TMPXPlaybackMessage::EStateChanged: |
|
401 { |
|
402 MPX_DEBUG2( "CMPXScreenSaverPlugin::DoHandlePlaybackMessageL - EStateChanged(%d)", type ); |
|
403 |
|
404 TMPXPlaybackState state = |
|
405 static_cast<TMPXPlaybackState>( type ); |
|
406 DoHandleStateChangedL( state ); |
|
407 break; |
|
408 } |
|
409 case TMPXPlaybackMessage::EMediaChanged: |
|
410 { |
|
411 MPX_DEBUG2( "CMPXScreenSaverPlugin::DoHandlePlaybackMessageL - EMediaChanged(%d)", type ); |
|
412 MMPXSource* s( iPlaybackUtility->Source() ); |
|
413 if ( s ) |
|
414 { |
|
415 RArray<TMPXAttribute> attrs; |
|
416 CleanupClosePushL(attrs); |
|
417 attrs.Append( KMPXMediaGeneralTitle ); |
|
418 s->MediaL( attrs.Array(), *this ); |
|
419 CleanupStack::PopAndDestroy( &attrs ); |
|
420 } |
|
421 break; |
|
422 } |
|
423 case TMPXPlaybackMessage::EActivePlayerChanged: |
|
424 { |
|
425 MPX_DEBUG3( "CMPXScreenSaverPlugin::DoHandlePlaybackMessageL - Active player changed(%d, %d)", type, data ); |
|
426 if ( type && data ) |
|
427 { |
|
428 // binded to active player, change state to active |
|
429 DoHandleStateChangedL( EPbStatePlaying ); |
|
430 // refresh media property |
|
431 MMPXSource* s = iPlaybackUtility->Source(); |
|
432 if ( s ) |
|
433 { |
|
434 RArray<TMPXAttribute> attrs; |
|
435 CleanupClosePushL(attrs); |
|
436 attrs.Append( KMPXMediaGeneralTitle ); |
|
437 s->MediaL( attrs.Array(), *this ); |
|
438 CleanupStack::PopAndDestroy( &attrs ); |
|
439 } |
|
440 } |
|
441 break; |
|
442 } |
|
443 default: |
|
444 { |
|
445 break; |
|
446 } |
|
447 } |
|
448 } |
|
449 } |
|
450 |
|
451 // --------------------------------------------------------------------------- |
|
452 // Handle media properties. |
|
453 // Notes: The client is responsible for delete the object of aProperties. |
|
454 // --------------------------------------------------------------------------- |
|
455 // |
|
456 void CMPXScreenSaverPlugin::DoHandleMediaL( |
|
457 const CMPXMedia& aMedia, |
|
458 TInt aError ) |
|
459 { |
|
460 MPX_FUNC( "CMPXScreenSaverPlugin::DoHandleMediaL" ); |
|
461 if ( iContainer && KErrNone == aError) |
|
462 { |
|
463 iContainer->SetSongPropertiesL( aMedia ); |
|
464 // force a redraw after title update |
|
465 iScreenSaverHost->SetRefreshTimerValue( KTimerForceNextUpdateInterval ); |
|
466 iScreenSaverHost->UseRefreshTimer( ETrue ); |
|
467 iTimerChanged = ETrue; |
|
468 } |
|
469 } |
|
470 |
|
471 // --------------------------------------------------------------------------- |
|
472 // Handle playback state changed. |
|
473 // --------------------------------------------------------------------------- |
|
474 // |
|
475 void CMPXScreenSaverPlugin::DoHandleStateChangedL( |
|
476 TMPXPlaybackState aState ) |
|
477 { |
|
478 MPX_FUNC( "CMPXScreenSaverPlugin::DoHandleStateChangedL" ); |
|
479 iPlaybackState = aState; |
|
480 |
|
481 // force a redraw after play state change |
|
482 iScreenSaverHost->SetRefreshTimerValue( KTimerForceNextUpdateInterval ); |
|
483 iScreenSaverHost->UseRefreshTimer( ETrue ); |
|
484 iTimerChanged = ETrue; |
|
485 } |
|
486 |
|
487 // --------------------------------------------------------------------------- |
|
488 // create container. |
|
489 // --------------------------------------------------------------------------- |
|
490 // |
|
491 void CMPXScreenSaverPlugin::CreateContainerL() |
|
492 { |
|
493 MPX_FUNC( "CMPXScreenSaverPlugin::CreateContainerL" ); |
|
494 |
|
495 iContainer = new ( ELeave ) |
|
496 CMPXScreenSaverPluginContainer( iScreenSaverHost ); |
|
497 iContainer->ConstructL(); |
|
498 |
|
499 iPlaybackState = iPlaybackUtility->StateL(); |
|
500 |
|
501 // get current playing song (if any) |
|
502 MMPXSource* s = iPlaybackUtility->Source(); |
|
503 if ( s ) |
|
504 { |
|
505 RArray<TMPXAttribute> attrs; |
|
506 CleanupClosePushL(attrs); |
|
507 attrs.Append( KMPXMediaGeneralTitle ); |
|
508 s->MediaL( attrs.Array(), *this ); |
|
509 CleanupStack::PopAndDestroy( &attrs ); |
|
510 } |
|
511 } |
|
512 |
|
513 // End Of file. |
|
514 |