|
1 /* |
|
2 * Copyright (c) 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: This is a plugin implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "cservicewidgetplugin.h" |
|
21 |
|
22 #include <implementationproxy.h> |
|
23 #include "servicewidgetutils.h" |
|
24 #include "servicewidgetpluginuids.hrh" |
|
25 #include "servicewidgetcpglobals.h" |
|
26 #include "cservicewidgetservicemanager.h" |
|
27 #include "cservicewidgetcontentpublisher.h" |
|
28 #include "swpdebugtrace.h" |
|
29 #include <spsettings.h> |
|
30 #include <spproperty.h> |
|
31 #include <cvimpstsettingsstore.h> |
|
32 #include <servicewidgetpluginres.rsg> |
|
33 #include <bautils.h> |
|
34 #include <eikenv.h> |
|
35 #include <spnotifychange.h> |
|
36 |
|
37 // Provide a key pair value table for ECOM. |
|
38 // Used to identify the correct construction function for the requested interface |
|
39 |
|
40 const TImplementationProxy ImplementationTable[] = |
|
41 { |
|
42 IMPLEMENTATION_PROXY_ENTRY( AI_UID_DLL_SERVICEWIDGETPUBLISHER_PLUGIN, |
|
43 CServiceWidgetPlugin::NewL ) |
|
44 }; |
|
45 |
|
46 // ======== GLOBAL FUNCTIONS ======== |
|
47 // Return an instance of the proxy table. |
|
48 |
|
49 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount ) |
|
50 { |
|
51 aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy ); |
|
52 return ImplementationTable; |
|
53 } |
|
54 |
|
55 // ============================ MEMBER FUNCTIONS =============================== |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CServiceWidgetPlugin::NewL |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CServiceWidgetPlugin* CServiceWidgetPlugin::NewL() |
|
62 { |
|
63 TRACE_SWP(TXT("CServiceWidgetPlugin::NewL() start") ); |
|
64 CServiceWidgetPlugin* self = new( ELeave )CServiceWidgetPlugin; |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(); |
|
67 CleanupStack::Pop(self); |
|
68 TRACE_SWP(TXT("CServiceWidgetPlugin::NewL() End") ); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CServiceWidgetPlugin::NewL |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CServiceWidgetPlugin::CServiceWidgetPlugin() |
|
77 { |
|
78 TRACE_SWP(TXT("CServiceWidgetPlugin::CServiceWidgetPlugin() Start") ); |
|
79 iEnv = CCoeEnv::Static(); |
|
80 TRACE_SWP(TXT("CServiceWidgetPlugin::CServiceWidgetPlugin() End") ); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CServiceWidgetPlugin::ConstructL |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CServiceWidgetPlugin::ConstructL() |
|
88 { |
|
89 TRACE_SWP(TXT("CServiceWidgetPlugin::ConstructL() Start") ); |
|
90 iContentPublisher = CServiceWidgetContentPublisher::NewL( *this ); |
|
91 TRACE_SWP(TXT("CServiceWidgetContentPublisher created succesfully") ); |
|
92 iSettingsStore = CVIMPSTSettingsStore::NewL(); |
|
93 TRACE_SWP(TXT("CServiceWidgetPlugin iSettingsStore created succesfully") ); |
|
94 // read service ids |
|
95 ReadServiceIdsL(); |
|
96 TRACE_SWP(TXT(" CServiceWidgetPlugin ReadServiceIdsL excuted") ); |
|
97 LoadResourceFileL(); |
|
98 TRACE_SWP(TXT(" CServiceWidgetPlugin LoadResourceFileL excuted") ); |
|
99 TRACE_SWP(TXT("CServiceWidgetPlugin::ConstructL() End") ); |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CServiceWidgetPlugin::NewL |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CServiceWidgetPlugin::~CServiceWidgetPlugin() |
|
107 { |
|
108 TRACE_SWP(TXT("CServiceWidgetPlugin::~CServiceWidgetPlugin() Start") ); |
|
109 delete iSpNotifyChange; |
|
110 iServiceManagers.ResetAndDestroy(); |
|
111 delete iSettingsStore; |
|
112 delete iContentPublisher; |
|
113 iServiceIds.Reset(); |
|
114 |
|
115 if( iEnv ) |
|
116 { |
|
117 iEnv->DeleteResourceFile( iResourceOffset ); |
|
118 } |
|
119 TRACE_SWP(TXT("CServiceWidgetPlugin::~CServiceWidgetPlugin() End") ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CServiceWidgetPlugin::ReadServiceIdsL |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CServiceWidgetPlugin::ReadServiceIdsL() |
|
127 { |
|
128 TRACE_SWP(TXT("CServiceWidgetPlugin::ReadServiceIdsL() Start") ); |
|
129 CSPSettings* settings = CSPSettings::NewLC(); |
|
130 ///////////////////////Get Service Id//////////////// |
|
131 RArray<TServiceId> services; |
|
132 CleanupClosePushL( services ); |
|
133 //Get the all configured service ID in services array |
|
134 settings->FindServiceIdsL( services ); |
|
135 const TInt serviceCount = services.Count(); |
|
136 iServiceIds.Reset(); |
|
137 //Append all the service ID in which service tab is interested in iServiceIds array |
|
138 TRACE_SWP(TXT("CServiceWidgetPlugin::ReadServiceIdsL() serviceCount %d"), serviceCount ); |
|
139 for ( TInt i( 0 ); i < serviceCount; i++ ) |
|
140 { |
|
141 TInt refContactUid = KErrNotFound; |
|
142 CSPProperty* property = CSPProperty::NewLC(); |
|
143 settings->FindPropertyL( services[i],EPropertyContactViewPluginId,*property ); |
|
144 if ( property ) |
|
145 { |
|
146 property->GetValue( refContactUid ); |
|
147 } |
|
148 CleanupStack::PopAndDestroy( property ); |
|
149 if ( (TUid::Uid( refContactUid ) == TUid::Uid( KMECOIMPLEMENTATIONUID )) |
|
150 || (TUid::Uid( refContactUid ) == TUid::Uid( KIMServicetabPluginUid ) ) |
|
151 || (TUid::Uid( refContactUid ) == TUid::Uid( 0x2002B334 ) )) |
|
152 { |
|
153 TRACE_SWP(TXT("CServiceWidgetPlugin::ReadServiceIdsL() valid service id %d"), services[i] ); |
|
154 iServiceIds.Append( services[i] ); |
|
155 } |
|
156 } |
|
157 CleanupStack::PopAndDestroy( &services); //services |
|
158 CleanupStack::PopAndDestroy( settings ); //settings |
|
159 TRACE_SWP(TXT("CServiceWidgetPlugin::ReadServiceIdsL() End ") ); |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CServiceWidgetPlugin::LoadResourceFileL |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void CServiceWidgetPlugin::LoadResourceFileL() |
|
167 { |
|
168 TRACE_SWP(TXT("CServiceWidgetPlugin::LoadResourceFileL() Start") ); |
|
169 if( iEnv ) |
|
170 { |
|
171 TRACE_SWP(TXT("CServiceWidgetPlugin::LoadResourceFileL() iEnv is valid") ); |
|
172 TFileName path; |
|
173 Dll::FileName(path); //get the location of the dll |
|
174 TDriveName drive( TParsePtrC( path ).Drive( ) ); // solve drive |
|
175 TRACE_SWP(TXT("CServiceWidgetPlugin::LoadResourceFileL() TParsePtrC called") ); |
|
176 // leave to stack, LC method |
|
177 HBufC* resourceFilePath = HBufC::NewLC( KSW_RESOURCE_MAX_LENGTH ); |
|
178 TPtr ptr( resourceFilePath->Des() ); |
|
179 TRACE_SWP(TXT("CServiceWidgetPlugin::LoadResourceFileL() resourceFilePath called") ); |
|
180 ptr.Zero(); |
|
181 ptr.Append( KResourceDrive() ); |
|
182 ptr.Append( KResourceFileName() ); |
|
183 // NearestLanguageFile takes only TFileName |
|
184 path.Zero(); |
|
185 path.Append( *resourceFilePath ); |
|
186 TRACE_SWP(TXT("CServiceWidgetPlugin::LoadResourceFileL() path.Append called") ); |
|
187 if ( path.Length() != 0 ) |
|
188 { |
|
189 TRACE_SWP(TXT("CServiceWidgetPlugin::LoadResourceFileL() path length not zero") ); |
|
190 BaflUtils::NearestLanguageFile( iEnv->FsSession(), path ); |
|
191 } |
|
192 CleanupStack::PopAndDestroy(resourceFilePath); // resourceFilePath |
|
193 TRACE_SWP(TXT("CServiceWidgetPlugin::LoadResourceFileL() resourceFilePath deleted") ); |
|
194 iResourceOffset = iEnv->AddResourceFileL(path); |
|
195 TRACE_SWP(TXT("CServiceWidgetPlugin::LoadResourceFileL() AddResourceFileL called") ); |
|
196 } |
|
197 TRACE_SWP(TXT("CServiceWidgetPlugin::LoadResourceFileL() End") ); |
|
198 } |
|
199 // ---------------------------------------------------------------------------- |
|
200 // This function updates information in CPS storage |
|
201 // ---------------------------------------------------------------------------- |
|
202 // |
|
203 void CServiceWidgetPlugin::UpdateL() |
|
204 { |
|
205 TRACE_SWP(TXT("CServiceWidgetPlugin::UpdateL() Start") ); |
|
206 //Unregisrer all previously registered services. |
|
207 if(iContentPublisher) |
|
208 { |
|
209 iContentPublisher->UnregisterAllWidgetsL(&iServiceIds); |
|
210 } |
|
211 //register for service table notifications |
|
212 RArray<TUint> serviceIds; |
|
213 CleanupClosePushL( serviceIds ); |
|
214 iSpNotifyChange = CSPNotifyChange::NewL( *this ); |
|
215 iSpNotifyChange->NotifyChangeL( serviceIds ); |
|
216 CleanupStack::PopAndDestroy( &serviceIds ) ; |
|
217 |
|
218 TInt serviceCount = iServiceIds.Count(); |
|
219 TRACE_SWP(TXT("CServiceWidgetPlugin::UpdateL() serviceCount %d"), serviceCount ); |
|
220 iServiceManagers.ResetAndDestroy(); |
|
221 if( serviceCount ) |
|
222 { |
|
223 for( TInt i=0; i < serviceCount; i++ ) |
|
224 { |
|
225 TRACE_SWP(TXT("CServiceWidgetPlugin::UpdateL() service id %d"), iServiceIds[i] ); |
|
226 |
|
227 CServiceWidgetServiceManager* servicemanager = CServiceWidgetServiceManager::NewL( iServiceIds[i], |
|
228 *iContentPublisher,*iSettingsStore ); |
|
229 CleanupStack::PushL( servicemanager ); |
|
230 servicemanager->RegisterWidgetL(); |
|
231 iServiceManagers.Append(servicemanager); |
|
232 CleanupStack::Pop(servicemanager ); |
|
233 TRACE_SWP(TXT("CServiceWidgetPlugin::UpdateL() service manager created for %d" ) , iServiceIds[i] ); |
|
234 }//End for |
|
235 } |
|
236 TRACE_SWP(TXT("CServiceWidgetPlugin::UpdateL() End") ); |
|
237 } |
|
238 |
|
239 |
|
240 // ---------------------------------------------------------------------------- |
|
241 // This function Validates all serviceManagers and add or delete as per service |
|
242 // CServiceWidgetPlugin::ValidateAllServicesL |
|
243 // ---------------------------------------------------------------------------- |
|
244 // |
|
245 void CServiceWidgetPlugin::ValidateAllServicesL() |
|
246 { |
|
247 TRACE_SWP(TXT("CServiceWidgetPlugin::ValidateAllServicesL() Start") ); |
|
248 TInt count = iServiceIds.Count(); |
|
249 //If all services are deleted then unregister all widget first and then delete |
|
250 //ServiceManager |
|
251 if( count == 0 ) |
|
252 { |
|
253 TInt serviceCount = iServiceManagers.Count(); |
|
254 for( TInt i=0; i<serviceCount; i++ ) |
|
255 { |
|
256 iServiceManagers[ i ]->UnregisterWidgetL(); |
|
257 } |
|
258 iServiceManagers.ResetAndDestroy(); |
|
259 } |
|
260 else |
|
261 { |
|
262 // check first all deleted services and remove their manager. |
|
263 TBool servicemanagerFound = EFalse; |
|
264 TInt serviceCount = iServiceManagers.Count(); |
|
265 for( TInt i = 0; i<serviceCount; i++) |
|
266 { |
|
267 servicemanagerFound = EFalse; |
|
268 for( TInt j=0; j<count; j++ ) |
|
269 { |
|
270 if( iServiceIds[ j ] == iServiceManagers[i]->ServiceId() ) |
|
271 { |
|
272 servicemanagerFound = ETrue; |
|
273 break; |
|
274 } |
|
275 }//End for J |
|
276 if( !servicemanagerFound ) |
|
277 { |
|
278 // Delete service manager |
|
279 CServiceWidgetServiceManager* servicemanager = iServiceManagers[ i ]; |
|
280 //Unregister widget |
|
281 servicemanager->UnregisterWidgetL(); |
|
282 TRACE_SWP(TXT("CServiceWidgetContentPublisher::RegisterWidgetPublishers() UnRegistered widget servID %d"),iServiceManagers[i]->ServiceId() ); |
|
283 iServiceManagers.Remove( i ); |
|
284 delete servicemanager; |
|
285 servicemanager = NULL; |
|
286 iServiceManagers.Compress(); |
|
287 serviceCount = serviceCount-1; |
|
288 } |
|
289 }//End For i |
|
290 // Check for new services and create their manager if not exist |
|
291 for( TInt i=0; i<count; i++) |
|
292 { |
|
293 servicemanagerFound = EFalse; |
|
294 serviceCount = iServiceManagers.Count(); |
|
295 for( TInt j=0; j<serviceCount; j++ ) |
|
296 { |
|
297 if( iServiceIds[ i ] == iServiceManagers[j]->ServiceId() ) |
|
298 { |
|
299 servicemanagerFound = ETrue; |
|
300 break; |
|
301 } |
|
302 }//End For J |
|
303 if( !servicemanagerFound ) |
|
304 { |
|
305 // create new service manager |
|
306 CServiceWidgetServiceManager* servicemanager = CServiceWidgetServiceManager::NewL( iServiceIds[ i ], |
|
307 *iContentPublisher,*iSettingsStore ); |
|
308 CleanupStack::PushL( servicemanager ); |
|
309 //Register widget to HS |
|
310 servicemanager->RegisterWidgetL(); |
|
311 iServiceManagers.Append(servicemanager); |
|
312 CleanupStack::Pop(servicemanager ); |
|
313 } |
|
314 }//End for i |
|
315 }//End Else |
|
316 TRACE_SWP(TXT("CServiceWidgetPlugin::ValidateAllServicesL() End") ); |
|
317 }//End ValidateAllServicesL |
|
318 |
|
319 // ----------------------------------------------------------------------------------- |
|
320 // CServiceWidgetPlugin::HandleServiceEventL |
|
321 // This function handles all homescreen callbacks (publisher received callback events |
|
322 // from homescreen and directed them to plugin to take appropriate action.) |
|
323 // ----------------------------------------------------------------------------------- |
|
324 // |
|
325 void CServiceWidgetPlugin::HandleServiceEventL(const TDesC& aPublisherId, const TDesC8& aEvent,TDesC& aInstId ) |
|
326 { |
|
327 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Start") ); |
|
328 CServiceWidgetServiceManager* servicemanager = NULL; |
|
329 TInt serviceCount = iServiceManagers.Count(); |
|
330 TInt index = KErrNotFound; |
|
331 //First identify which manager is supposed to handle event |
|
332 for( index=0; index<serviceCount; index++ ) |
|
333 { |
|
334 if( iServiceManagers[ index]->ServiceName().Compare( aPublisherId ) == 0 ) |
|
335 { |
|
336 servicemanager = iServiceManagers[ index ]; |
|
337 break; |
|
338 } |
|
339 } |
|
340 //Take action based on Event |
|
341 if( servicemanager && (index < serviceCount) && (index >=0) ) |
|
342 { |
|
343 if( aEvent.Compare( KActive ) == 0 ) |
|
344 { |
|
345 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Active Event") ); |
|
346 // this publisher widget is added into homescreen. |
|
347 // publish content to widget ,widget is ready to use |
|
348 servicemanager->ActivateWidgetL(aInstId); |
|
349 } |
|
350 else if( aEvent.Compare( KResume ) == 0 ) |
|
351 { |
|
352 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Resume Event") ); |
|
353 servicemanager->WidgetSuspended( EFalse ); |
|
354 // Home screen is in foreground or back light is on now. |
|
355 // publishing / removing data now will be immediately updated in your widget. |
|
356 // this publisher widget is added into homescreen. |
|
357 // publich content to widget ,widget is ready to use |
|
358 servicemanager->UpdateContentsL(); |
|
359 } |
|
360 else if( aEvent.Compare( KSuspend ) == 0 || aEvent.Compare( KInactive ) == 0 ) |
|
361 { |
|
362 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Suspend Event") ); |
|
363 // Home screen is in back ground or back light is off. |
|
364 // don't publish new data now it won't be updated in your widget. |
|
365 // widget is suspended |
|
366 // Home screen page is switched |
|
367 // // don't publish new data now it won't be updated in your widget. |
|
368 // // widget is suspended and in Inactive state |
|
369 servicemanager->WidgetSuspended( ETrue ); |
|
370 } |
|
371 else if( aEvent.Compare( KDeActive ) == 0 ) |
|
372 { |
|
373 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Deactive Event") ); |
|
374 // this publisher widget is removed from homescreen. |
|
375 // remove the last data published to homescreen. |
|
376 // So that when the user add widget again it won't show the old data. |
|
377 servicemanager->DeactivateWidgetL(aInstId); |
|
378 } |
|
379 else if( aEvent.Compare( KSelected ) == 0 ) |
|
380 { |
|
381 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Selected Event") ); |
|
382 // this publisher widget is clicked from homescreen. |
|
383 servicemanager->ExecuteActionL(); |
|
384 } |
|
385 } |
|
386 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() End") ); |
|
387 }//End HandleServiceEventL |
|
388 |
|
389 |
|
390 ////////////////////////////////////////////////////////////// |
|
391 // --------------------------------------------------------------------------- |
|
392 // CServiceWidgetPlugin::HandleNotifyChange() |
|
393 // --------------------------------------------------------------------------- |
|
394 // |
|
395 void CServiceWidgetPlugin::HandleNotifyChange( |
|
396 TServiceId /*aServiceId*/ ) |
|
397 { |
|
398 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleNotifyChange() start") ); |
|
399 //This function will be triggred if any change in any service |
|
400 TRAP_IGNORE( // Read the service id if any installed |
|
401 ReadServiceIdsL(); |
|
402 ValidateAllServicesL(); |
|
403 ); |
|
404 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleNotifyChange() end") ); |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------------------------- |
|
408 // CServiceWidgetPlugin::HandleError() |
|
409 // --------------------------------------------------------------------------- |
|
410 // |
|
411 void CServiceWidgetPlugin::HandleError( TInt /*aError*/ ) |
|
412 { |
|
413 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleError() start/end") ); |
|
414 } |
|
415 |
|
416 // --------------------------------------------------------------------------- |
|
417 // From class MAiPropertyExtension |
|
418 // Read property of publisher plug-in. |
|
419 // --------------------------------------------------------------------------- |
|
420 // |
|
421 /*TAny* CServiceWidgetPlugin::GetPropertyL( TInt aProperty ) |
|
422 { |
|
423 TRACE_SWP(TXT("CServiceWidgetPlugin::GetPropertyL() start") ); |
|
424 TAny* property = NULL; |
|
425 |
|
426 switch ( aProperty ) |
|
427 { |
|
428 case EAiPublisherInfo: |
|
429 { |
|
430 property = static_cast<TAiPublisherInfo*>( &iInfo ); |
|
431 break; |
|
432 } |
|
433 } |
|
434 TRACE_SWP(TXT("CServiceWidgetPlugin::GetPropertyL() end") ); |
|
435 return property; |
|
436 } |
|
437 |
|
438 // --------------------------------------------------------------------------- |
|
439 // From class MAiPropertyExtension |
|
440 // Write property value to optimize the content model. |
|
441 // --------------------------------------------------------------------------- |
|
442 // |
|
443 void CServiceWidgetPlugin::SetPropertyL( TInt aProperty, TAny* aValue ) |
|
444 { |
|
445 TRACE_SWP(TXT("CServiceWidgetPlugin::SetPropertyL() start") ); |
|
446 switch ( aProperty ) |
|
447 { |
|
448 case EAiPublisherInfo: |
|
449 { |
|
450 if( aValue ) |
|
451 { |
|
452 const TAiPublisherInfo* info = static_cast<const TAiPublisherInfo*>( aValue ); |
|
453 iInfo.iName.Copy(info->iName); |
|
454 iInfo.iNamespace.Copy(info->iNamespace); |
|
455 } |
|
456 break; |
|
457 } |
|
458 default: |
|
459 break; |
|
460 } |
|
461 TRACE_SWP(TXT("CServiceWidgetPlugin::SetPropertyL() end") ); |
|
462 }*/ |
|
463 // End of File |