|
1 /* |
|
2 * Copyright (c) 2006-2009 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: SAT Active Idle publisher |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ecom/ecom.h> |
|
20 #include <ecom/implementationproxy.h> |
|
21 #include <aicontentobserver.h> |
|
22 #include <aiutility.h> |
|
23 #include <aipluginsettings.h> |
|
24 #include <flogger.h> |
|
25 #include <AknUtils.h> |
|
26 #include <gulicon.h> // For CGulIcon |
|
27 #include <fbs.h> // For CFbsBitmap |
|
28 #include <SATInternalPSKeys.h> |
|
29 |
|
30 #include "aisatcontentmodel.h" |
|
31 #include "caisatplugin.h" |
|
32 #include "caisatengine.h" |
|
33 #include "tflogger.h" |
|
34 |
|
35 const TImplementationProxy KImplementationTable[] = |
|
36 { |
|
37 //lint -e{611,1924} Warning "Suspicious cast" can not be avoided. |
|
38 IMPLEMENTATION_PROXY_ENTRY( KImplUidSatPlugin, CAiSatPlugin::NewL ) |
|
39 }; |
|
40 |
|
41 // static cleanup function |
|
42 static void TransactionCleanup( TAny* aAny ) |
|
43 { |
|
44 static_cast<MAiContentObserver*>( aAny )-> |
|
45 CancelTransaction( KImplUidSatPlugin ); |
|
46 } |
|
47 |
|
48 // ============================ MEMBER FUNCTIONS ============================= |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Symbian 2nd phase constructor can leave |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CAiSatPlugin* CAiSatPlugin::NewL() |
|
55 { |
|
56 TFLOGSTRING( "CAiSatPlugin::NewL() starts" ) |
|
57 |
|
58 CAiSatPlugin* self = new ( ELeave ) CAiSatPlugin; |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop( self ); |
|
62 |
|
63 TFLOGSTRING( "CAiSatPlugin::NewL() exits" ) |
|
64 return self; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // Destructor |
|
69 // Deletes all data created to heap |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CAiSatPlugin::~CAiSatPlugin() |
|
73 { |
|
74 TFLOGSTRING( "CAiSatPlugin::~CAiSatPlugin() starts" ) |
|
75 |
|
76 Release( iContent ); |
|
77 iContent = NULL; |
|
78 |
|
79 Release( iResources ); |
|
80 iResources = NULL; |
|
81 |
|
82 Release( iEvents ); |
|
83 iEvents = NULL; |
|
84 |
|
85 delete iEngine; |
|
86 iEngine = NULL; |
|
87 |
|
88 iObservers.Close(); |
|
89 |
|
90 TFLOGSTRING( "CAiSatPlugin::~CAiSatPlugin() exits" ) |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // Publish a icon to the idle area. |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 TInt CAiSatPlugin::PublishIcon( |
|
98 MAiContentObserver& aObserver, |
|
99 CGulIcon* aIcon ) |
|
100 { |
|
101 TFLOGSTRING( "CAiSatPlugin::PublishIcon() starts" ) |
|
102 |
|
103 TInt error( KErrNotSupported ); |
|
104 |
|
105 // Check whether the icon can be published or not. |
|
106 if ( aIcon && aObserver.CanPublish( *this, KSatContent[ESatContentIcon].id, |
|
107 ESatContentIcon ) ) |
|
108 { |
|
109 // If the icon can be published, and then publish it. |
|
110 error = aObserver.Publish( *this, KSatContent[ESatContentIcon].id, |
|
111 TPckgC<TAny*>( aIcon ), ESatContentIcon ); |
|
112 } |
|
113 |
|
114 TFLOGSTRING2( "CAiSatPlugin::PublishIcon() exits, error: %d", error ) |
|
115 |
|
116 return error; |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // Clean idle area icon |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 TInt CAiSatPlugin::CleanIcon( MAiContentObserver& aObserver ) |
|
124 { |
|
125 TFLOGSTRING( "CAiSatPlugin::CleanIcon() starts" ) |
|
126 TInt error( KErrNotSupported ); |
|
127 |
|
128 error = aObserver.Clean( *this, KSatContent[ESatContentIcon].id, |
|
129 ESatContentIcon ); |
|
130 |
|
131 TFLOGSTRING2( "CAiSatPlugin::CleanIcon() exits, error %d", error ) |
|
132 return error; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // Publish a SetUpIdleModeText string. |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CAiSatPlugin::PublishText( MAiContentObserver& aObserver, |
|
140 const TDesC& aText ) |
|
141 { |
|
142 TFLOGSTRING( "CAiSatPlugin::PublishText() starts" ) |
|
143 TFLOGSTRING2( "CAiSatPlugin::PublishText() length %i", aText.Length() ) |
|
144 |
|
145 TInt error( KErrNotSupported ); |
|
146 |
|
147 // Check whether the SetUpIdleModeText string can be published or not |
|
148 if ( aText.Length() && |
|
149 aObserver.CanPublish( *this, KSatContent[ESatContentText].id, |
|
150 ESatContentText ) ) |
|
151 { |
|
152 // If SetUpIdleModeText can be published, and then publish it. |
|
153 error = aObserver.Publish( *this, KSatContent[ESatContentText].id, |
|
154 aText, ESatContentText ); |
|
155 } |
|
156 TFLOGSTRING2( "CAiSatPlugin::PublishText() exits, error: \ |
|
157 %d", error ) |
|
158 |
|
159 return error; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // Clean idle area text |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 TInt CAiSatPlugin::CleanText( MAiContentObserver& aObserver ) |
|
167 { |
|
168 TFLOGSTRING( "CAiSatPlugin::CleanText() starts" ) |
|
169 TInt error( KErrNotSupported ); |
|
170 |
|
171 error = aObserver.Clean( *this, KSatContent[ESatContentText].id, |
|
172 ESatContentText ); |
|
173 |
|
174 TFLOGSTRING2( "CAiSatPlugin::CleanText() exits, error %d", error ) |
|
175 |
|
176 return error; |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // Publishes the SAT Set Up Idle Mode Text and or Icon |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 void CAiSatPlugin::PublishSatL() |
|
184 { |
|
185 TFLOGSTRING( "CAiSatPlugin::PublishSatL() starts" ) |
|
186 |
|
187 TInt error( KErrNone ); |
|
188 TInt iconError( KErrNone ); |
|
189 TInt textError( KErrNone ); |
|
190 TInt observers( iObservers.Count() ); |
|
191 TInt transactionId( KImplUidSatPlugin ); |
|
192 MAiContentObserver* observer( NULL ); |
|
193 CGulIcon* icon( NULL ); // The icon for publishing. |
|
194 TInt i( 0 ); |
|
195 TBool commitNeeded( EFalse ); |
|
196 |
|
197 // Publish sat data to all observers. |
|
198 TFLOGSTRING2( "CAiSatPlugin::PublishSatL() observer count: %i", observers ) |
|
199 for ( i = 0; i < observers; i++ ) |
|
200 { |
|
201 commitNeeded = EFalse; |
|
202 observer = iObservers[i]; |
|
203 TFLOGSTRING2( "CAiSatPlugin::PublishSatL() observer id: %i", observer ) |
|
204 |
|
205 // Start publish transaciton. |
|
206 error = observer->StartTransaction( transactionId ); |
|
207 TCleanupItem item( TransactionCleanup, observer ); |
|
208 CleanupStack::PushL( item ); |
|
209 |
|
210 // Publish icon and text to idle mode area. |
|
211 iEngine->ContentIconL( icon ); |
|
212 TPtrC text( KNullDesC ); |
|
213 iEngine->ContentText( text ); |
|
214 if ( !icon && !text.Length() ) // Nothing |
|
215 { |
|
216 if ( !iDupIcon ) |
|
217 { |
|
218 error = CleanIcon( *observer ); |
|
219 commitNeeded = ETrue; |
|
220 } |
|
221 if ( !iDupText ) |
|
222 { |
|
223 error = CleanText( *observer ); |
|
224 commitNeeded = ETrue; |
|
225 } |
|
226 } |
|
227 else if ( icon && !text.Length() ) // Icon only |
|
228 { |
|
229 if ( !iDupIcon ) |
|
230 { |
|
231 error = CleanIcon( *observer ); |
|
232 iconError = PublishIcon( *observer, icon ); |
|
233 commitNeeded = ETrue; |
|
234 } |
|
235 if ( !iDupText ) |
|
236 { |
|
237 error = CleanText( *observer ); |
|
238 commitNeeded = ETrue; |
|
239 } |
|
240 } |
|
241 else if ( !icon && text.Length() ) // Text only |
|
242 { |
|
243 if ( !iDupIcon ) |
|
244 { |
|
245 error = CleanIcon( *observer ); |
|
246 commitNeeded = ETrue; |
|
247 } |
|
248 if ( !iDupText ) |
|
249 { |
|
250 error = CleanText( *observer ); |
|
251 textError = PublishText( *observer, text ); |
|
252 commitNeeded = ETrue; |
|
253 } |
|
254 } |
|
255 else // Text and icon |
|
256 { |
|
257 if ( !iDupIcon ) |
|
258 { |
|
259 error = CleanIcon( *observer ); |
|
260 iconError = PublishIcon( *observer, icon ); |
|
261 commitNeeded = ETrue; |
|
262 } |
|
263 if ( !iDupText ) |
|
264 { |
|
265 error = CleanText( *observer ); |
|
266 textError = PublishText( *observer, text ); |
|
267 commitNeeded = ETrue; |
|
268 } |
|
269 } |
|
270 |
|
271 // Commit the publishing of the icon and text. |
|
272 if ( !textError && !iconError && commitNeeded ) |
|
273 { |
|
274 TFLOGSTRING( "CAiSatPlugin::PublishSatL() commit transaction" ) |
|
275 error = observer->Commit( transactionId ); |
|
276 } |
|
277 else |
|
278 { |
|
279 TFLOGSTRING( "CAiSatPlugin::PublishSatL() cancel transaction" ) |
|
280 error = observer->CancelTransaction( transactionId ); |
|
281 } |
|
282 CleanupStack::Pop(); |
|
283 } |
|
284 |
|
285 TFLOGSTRING( "CAiSatPlugin::PublishSatL() exits" ) |
|
286 } |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 // From class CAiContentPublisher |
|
290 // Plug-in is requested to unload its engines due backup operation |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 void CAiSatPlugin::Stop( TAiTransitionReason /* aReason */ ) |
|
294 { |
|
295 TFLOGSTRING( "CAiSatPlugin::Stop starts - exits" ) |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // From class CAiContentPublisher |
|
300 // Plug-in is instructed that it is allowed to consume CPU resources |
|
301 // --------------------------------------------------------------------------- |
|
302 // |
|
303 void CAiSatPlugin::Resume( TAiTransitionReason aReason ) |
|
304 { |
|
305 TFLOGSTRING2( "CAiSatPlugin::Resume reason %d", aReason ) |
|
306 |
|
307 if ( EAiIdleForeground == aReason && !iEngine ) |
|
308 { |
|
309 TRAP_IGNORE( iEngine = CAiSatEngine::NewL( *this ) ) |
|
310 } |
|
311 |
|
312 // If we change the Home Screen Theme we will got a EAiSystemStartup as |
|
313 // aReason. |
|
314 else if ( ( EAiGeneralThemeChanged == aReason || |
|
315 EAiSystemStartup == aReason ) && |
|
316 iEngine ) |
|
317 { |
|
318 TRAP_IGNORE( UpdateSatL() ) |
|
319 } |
|
320 |
|
321 TFLOGSTRING( "CAiSatPlugin::Resume() exits" ) |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // From class CAiContentPublisher |
|
326 // Plug-in is instructed that it is not allowed to consume CPU resources |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 void CAiSatPlugin::Suspend( TAiTransitionReason /* aReason */ ) |
|
330 { |
|
331 TFLOGSTRING( "CAiSatPlugin::Suspend starts - exits" ) |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------------------------- |
|
335 // From class CAiContentPublisher |
|
336 // The plug-in MUST maintain a registry of subscribers and send |
|
337 // notification to all of them whenever the state changes or new content |
|
338 // is available |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 void CAiSatPlugin::SubscribeL( MAiContentObserver& aObserver ) |
|
342 { |
|
343 TFLOGSTRING( "CAiSatPlugin::SubscribeL() starts" ) |
|
344 |
|
345 iObservers.AppendL( &aObserver ); |
|
346 |
|
347 TFLOGSTRING( "CAiSatPlugin::SubscribeL() exits" ) |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // From class CAiContentPublisher |
|
352 // Plug-ins take ownership of the settings array, so it must either |
|
353 // store it in a member or free it. |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 void CAiSatPlugin::ConfigureL( RAiSettingsItemArray& aSettings ) |
|
357 { |
|
358 TFLOGSTRING( "CAiSatPlugin::ConfigureL() starts" ) |
|
359 |
|
360 TInt count = aSettings.Count(); |
|
361 TFLOGSTRING2( "CAiSatPlugin::ConfigureL count: %d", count ) |
|
362 if ( count > 0 ) |
|
363 { |
|
364 TInt i( 0 ); |
|
365 for ( i = 0; i < count; i++ ) |
|
366 { |
|
367 MAiPluginSettings* settings = aSettings[i]; |
|
368 MAiPluginSettingsItem& item = settings->AiPluginSettingsItem(); |
|
369 item.SetValueL( item.Value(), EFalse ); |
|
370 } |
|
371 TFLOGSTRING2( "CAiSatPlugin::ConfigureL i: %d", i ) |
|
372 } |
|
373 |
|
374 TFLOGSTRING( "CAiSatPlugin::ConfigureL() exits" ) |
|
375 } |
|
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // From class CAiContentPublisher |
|
379 // Returns the extension interface. Actual type depends on the passed |
|
380 // aUid argument. |
|
381 // --------------------------------------------------------------------------- |
|
382 // |
|
383 TAny* CAiSatPlugin::Extension( TUid aUid ) |
|
384 { |
|
385 TFLOGSTRING( "CAiSatPlugin::Extension() starts" ) |
|
386 |
|
387 MAiPropertyExtension* extension = NULL; |
|
388 |
|
389 if ( KExtensionUidProperty == aUid ) |
|
390 { |
|
391 extension = static_cast<MAiPropertyExtension*>( this ); |
|
392 } |
|
393 |
|
394 TFLOGSTRING( "CAiSatPlugin::Extension() exits" ) |
|
395 return extension; |
|
396 } |
|
397 |
|
398 // --------------------------------------------------------------------------- |
|
399 // From class MAiPropertyExtension |
|
400 // Read property of publisher plug-in. |
|
401 // --------------------------------------------------------------------------- |
|
402 // |
|
403 TAny* CAiSatPlugin::GetPropertyL( TInt aProperty ) |
|
404 { |
|
405 TFLOGSTRING( "CAiSatPlugin::GetPropertyL() starts" ) |
|
406 |
|
407 TAny* property = NULL; |
|
408 TFLOGSTRING2( "CAiSatPlugin::GetPropertyL aProperty: %d", aProperty ) |
|
409 switch ( aProperty ) |
|
410 { |
|
411 case EAiPublisherInfo: |
|
412 { |
|
413 property = static_cast<TAiPublisherInfo*>( &iInfo ); |
|
414 break; |
|
415 } |
|
416 |
|
417 case EAiPublisherContent: |
|
418 { |
|
419 property = static_cast<MAiContentItemIterator*>( iContent ); |
|
420 break; |
|
421 } |
|
422 |
|
423 case EAiPublisherResources: |
|
424 { |
|
425 property = static_cast<MAiContentItemIterator*>( iResources ); |
|
426 break; |
|
427 } |
|
428 |
|
429 case EAiPublisherEvents: |
|
430 { |
|
431 property = static_cast<MAiContentItemIterator*>( iEvents ); |
|
432 break; |
|
433 } |
|
434 default: |
|
435 break; |
|
436 } |
|
437 |
|
438 TFLOGSTRING( "CAiSatPlugin::GetPropertyL() exits" ) |
|
439 |
|
440 return property; |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // From class MAiPropertyExtension |
|
445 // Write property value to optimize the content model. |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 void CAiSatPlugin::SetPropertyL( TInt aProperty, TAny* aValue ) |
|
449 { |
|
450 TFLOGSTRING( "CAiSatPlugin::SetPropertyL() starts" ) |
|
451 |
|
452 if ( EAiPublisherInfo == aProperty ) |
|
453 { |
|
454 TFLOGSTRING( "CAiSatPlugin::SetPropertyL() EAiPublisherInfo" ) |
|
455 const TAiPublisherInfo* info = |
|
456 static_cast<const TAiPublisherInfo*>( aValue ); |
|
457 if ( info ) |
|
458 { |
|
459 iInfo = *info; |
|
460 } |
|
461 } |
|
462 |
|
463 TFLOGSTRING( "CAiSatPlugin::SetPropertyL() exits" ) |
|
464 } |
|
465 |
|
466 // --------------------------------------------------------- |
|
467 // This method is called from the engine, when the P&S |
|
468 // data content has been changed. Method call is made through |
|
469 // the MPluginAPI interface. |
|
470 // --------------------------------------------------------- |
|
471 // |
|
472 void CAiSatPlugin::NotifyContentUpdate() |
|
473 { |
|
474 TFLOGSTRING( "CAiSatPlugin::NotifyContentUpdate() starts" ) |
|
475 |
|
476 if ( iEngine ) |
|
477 { |
|
478 // Get the idle mode data first. |
|
479 TRAP_IGNORE( iEngine->PrepareIdleModeDataL( iDupIcon, iDupText ) ); |
|
480 |
|
481 // Send response to client side |
|
482 TRAP_IGNORE( iEngine->HandleNotifyL() ); |
|
483 |
|
484 // Publish set up idle mode data |
|
485 TRAP_IGNORE( PublishSatL() ); |
|
486 } |
|
487 |
|
488 TFLOGSTRING( "CAiSatPlugin::NotifyContentUpdate() exits" ) |
|
489 } |
|
490 |
|
491 // --------------------------------------------------------------------------- |
|
492 // Default constructor |
|
493 // --------------------------------------------------------------------------- |
|
494 // |
|
495 CAiSatPlugin::CAiSatPlugin() |
|
496 { |
|
497 TFLOGSTRING( "CAiSatPlugin::CAiSatPlugin() starts-exits" ) |
|
498 } |
|
499 |
|
500 // --------------------------------------------------------------------------- |
|
501 // Symbian 2nd phase constructor can leave |
|
502 // --------------------------------------------------------------------------- |
|
503 // |
|
504 void CAiSatPlugin::ConstructL() |
|
505 { |
|
506 TFLOGSTRING( "CAiSatPlugin::ConstructL() starts" ) |
|
507 |
|
508 _LIT(KSatName, "SAT"); |
|
509 |
|
510 iInfo.iUid.iUid = AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_SATPLUGIN; |
|
511 iInfo.iName.Copy( KSatName ); |
|
512 |
|
513 iContent = AiUtility::CreateContentItemArrayIteratorL( KSatContent ); |
|
514 iResources = AiUtility::CreateContentItemArrayIteratorL( KSatResources ); |
|
515 iEvents = AiUtility::CreateContentItemArrayIteratorL( KSatEvents ); |
|
516 |
|
517 iEngine = CAiSatEngine::NewL( *this ); |
|
518 |
|
519 TFLOGSTRING( "CAiSatPlugin::ConstructL() exits" ) |
|
520 } |
|
521 |
|
522 // --------------------------------------------------------------------------- |
|
523 // Update idle area when plug in reload. |
|
524 // --------------------------------------------------------------------------- |
|
525 // |
|
526 void CAiSatPlugin::UpdateSatL() |
|
527 { |
|
528 TFLOGSTRING( "CAiSatPlugin::UpdateSatL() starts" ) |
|
529 iEngine->PrepareIdleModeDataL( iDupIcon, iDupText ); |
|
530 PublishSatL(); |
|
531 TFLOGSTRING( "CAiSatPlugin::UpdateSatL() exits" ) |
|
532 } |
|
533 |
|
534 // ============================ GLOBAL FUNCTIONS ============================= |
|
535 |
|
536 // --------------------------------------------------------------------------- |
|
537 // Constructs and returns an application object. |
|
538 // --------------------------------------------------------------------------- |
|
539 // |
|
540 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
541 TInt& aTableCount ) |
|
542 { |
|
543 TFLOGSTRING( "CAiSatPlugin::ImplementationGroupProxy() starts-exits" ) |
|
544 aTableCount = |
|
545 sizeof( KImplementationTable ) / sizeof( TImplementationProxy ); |
|
546 |
|
547 return KImplementationTable; |
|
548 } |