|
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 //register for service table notifications |
|
207 RArray<TUint> serviceIds; |
|
208 CleanupClosePushL( serviceIds ); |
|
209 iSpNotifyChange = CSPNotifyChange::NewL( *this ); |
|
210 iSpNotifyChange->NotifyChangeL( serviceIds ); |
|
211 CleanupStack::PopAndDestroy( &serviceIds ) ; |
|
212 |
|
213 TInt serviceCount = iServiceIds.Count(); |
|
214 TRACE_SWP(TXT("CServiceWidgetPlugin::UpdateL() serviceCount %d"), serviceCount ); |
|
215 iServiceManagers.ResetAndDestroy(); |
|
216 if( serviceCount ) |
|
217 { |
|
218 for( TInt i=0; i < serviceCount; i++ ) |
|
219 { |
|
220 TRACE_SWP(TXT("CServiceWidgetPlugin::UpdateL() service id %d"), iServiceIds[i] ); |
|
221 |
|
222 CServiceWidgetServiceManager* servicemanager = CServiceWidgetServiceManager::NewL( iServiceIds[i], |
|
223 *iContentPublisher,*iSettingsStore ); |
|
224 CleanupStack::PushL( servicemanager ); |
|
225 servicemanager->RegisterWidgetL(); |
|
226 iServiceManagers.Append(servicemanager); |
|
227 CleanupStack::Pop(servicemanager ); |
|
228 TRACE_SWP(TXT("CServiceWidgetPlugin::UpdateL() service manager created for %d" ) , iServiceIds[i] ); |
|
229 }//End for |
|
230 } |
|
231 TRACE_SWP(TXT("CServiceWidgetPlugin::UpdateL() End") ); |
|
232 } |
|
233 |
|
234 |
|
235 // ---------------------------------------------------------------------------- |
|
236 // This function Validates all serviceManagers and add or delete as per service |
|
237 // CServiceWidgetPlugin::ValidateAllServicesL |
|
238 // ---------------------------------------------------------------------------- |
|
239 // |
|
240 void CServiceWidgetPlugin::ValidateAllServicesL() |
|
241 { |
|
242 TRACE_SWP(TXT("CServiceWidgetPlugin::ValidateAllServicesL() Start") ); |
|
243 TInt count = iServiceIds.Count(); |
|
244 //If all services are deleted then unregister all widget first and then delete |
|
245 //ServiceManager |
|
246 if( count == 0 ) |
|
247 { |
|
248 TInt serviceCount = iServiceManagers.Count(); |
|
249 for( TInt i=0; i<serviceCount; i++ ) |
|
250 { |
|
251 iServiceManagers[ i ]->UnregisterWidgetL(); |
|
252 } |
|
253 iServiceManagers.ResetAndDestroy(); |
|
254 } |
|
255 else |
|
256 { |
|
257 // check first all deleted services and remove their manager. |
|
258 TBool servicemanagerFound = EFalse; |
|
259 TInt serviceCount = iServiceManagers.Count(); |
|
260 for( TInt i = 0; i<serviceCount; i++) |
|
261 { |
|
262 servicemanagerFound = EFalse; |
|
263 for( TInt j=0; j<count; j++ ) |
|
264 { |
|
265 if( iServiceIds[ j ] == iServiceManagers[i]->ServiceId() ) |
|
266 { |
|
267 servicemanagerFound = ETrue; |
|
268 break; |
|
269 } |
|
270 }//End for J |
|
271 if( !servicemanagerFound ) |
|
272 { |
|
273 // Delete service manager |
|
274 CServiceWidgetServiceManager* servicemanager = iServiceManagers[ i ]; |
|
275 //Unregister widget |
|
276 servicemanager->UnregisterWidgetL(); |
|
277 TRACE_SWP(TXT("CServiceWidgetContentPublisher::RegisterWidgetPublishers() UnRegistered widget servID %d"),iServiceManagers[i]->ServiceId() ); |
|
278 iServiceManagers.Remove( i ); |
|
279 delete servicemanager; |
|
280 servicemanager = NULL; |
|
281 iServiceManagers.Compress(); |
|
282 serviceCount = serviceCount-1; |
|
283 } |
|
284 }//End For i |
|
285 // Check for new services and create their manager if not exist |
|
286 for( TInt i=0; i<count; i++) |
|
287 { |
|
288 servicemanagerFound = EFalse; |
|
289 serviceCount = iServiceManagers.Count(); |
|
290 for( TInt j=0; j<serviceCount; j++ ) |
|
291 { |
|
292 if( iServiceIds[ i ] == iServiceManagers[j]->ServiceId() ) |
|
293 { |
|
294 servicemanagerFound = ETrue; |
|
295 break; |
|
296 } |
|
297 }//End For J |
|
298 if( !servicemanagerFound ) |
|
299 { |
|
300 // create new service manager |
|
301 CServiceWidgetServiceManager* servicemanager = CServiceWidgetServiceManager::NewL( iServiceIds[ i ], |
|
302 *iContentPublisher,*iSettingsStore ); |
|
303 CleanupStack::PushL( servicemanager ); |
|
304 //Register widget to HS |
|
305 servicemanager->RegisterWidgetL(); |
|
306 iServiceManagers.Append(servicemanager); |
|
307 CleanupStack::Pop(servicemanager ); |
|
308 } |
|
309 }//End for i |
|
310 }//End Else |
|
311 TRACE_SWP(TXT("CServiceWidgetPlugin::ValidateAllServicesL() End") ); |
|
312 }//End ValidateAllServicesL |
|
313 |
|
314 // ----------------------------------------------------------------------------------- |
|
315 // CServiceWidgetPlugin::HandleServiceEventL |
|
316 // This function handles all homescreen callbacks (publisher received callback events |
|
317 // from homescreen and directed them to plugin to take appropriate action.) |
|
318 // ----------------------------------------------------------------------------------- |
|
319 // |
|
320 void CServiceWidgetPlugin::HandleServiceEventL(const TDesC& aPublisherId, const TDesC8& aEvent,TDesC& aInstId ) |
|
321 { |
|
322 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Start") ); |
|
323 CServiceWidgetServiceManager* servicemanager = NULL; |
|
324 TInt serviceCount = iServiceManagers.Count(); |
|
325 TInt index = KErrNotFound; |
|
326 //First identify which manager is supposed to handle event |
|
327 for( index=0; index<serviceCount; index++ ) |
|
328 { |
|
329 if( iServiceManagers[ index]->ServiceName().Compare( aPublisherId ) == 0 ) |
|
330 { |
|
331 servicemanager = iServiceManagers[ index ]; |
|
332 break; |
|
333 } |
|
334 } |
|
335 //Take action based on Event |
|
336 if( servicemanager && (index < serviceCount) && (index >=0) ) |
|
337 { |
|
338 if( aEvent.Compare( KActive ) == 0 ) |
|
339 { |
|
340 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Active Event") ); |
|
341 // this publisher widget is added into homescreen. |
|
342 // publish content to widget ,widget is ready to use |
|
343 servicemanager->ActivateWidgetL(aInstId); |
|
344 } |
|
345 else if( aEvent.Compare( KResume ) == 0 ) |
|
346 { |
|
347 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Resume Event") ); |
|
348 servicemanager->WidgetSuspended( EFalse ); |
|
349 // Home screen is in foreground or back light is on now. |
|
350 // publishing / removing data now will be immediately updated in your widget. |
|
351 // this publisher widget is added into homescreen. |
|
352 // publich content to widget ,widget is ready to use |
|
353 servicemanager->UpdateContentsL(); |
|
354 } |
|
355 else if( aEvent.Compare( KSuspend ) == 0 || aEvent.Compare( KInactive ) == 0 ) |
|
356 { |
|
357 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Suspend Event") ); |
|
358 // Home screen is in back ground or back light is off. |
|
359 // don't publish new data now it won't be updated in your widget. |
|
360 // widget is suspended |
|
361 // Home screen page is switched |
|
362 // // don't publish new data now it won't be updated in your widget. |
|
363 // // widget is suspended and in Inactive state |
|
364 servicemanager->WidgetSuspended( ETrue ); |
|
365 } |
|
366 else if( aEvent.Compare( KDeActive ) == 0 ) |
|
367 { |
|
368 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Deactive Event") ); |
|
369 // this publisher widget is removed from homescreen. |
|
370 // remove the last data published to homescreen. |
|
371 // So that when the user add widget again it won't show the old data. |
|
372 servicemanager->DeactivateWidgetL(aInstId); |
|
373 } |
|
374 else if( aEvent.Compare( KSelected ) == 0 ) |
|
375 { |
|
376 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() Selected Event") ); |
|
377 // this publisher widget is clicked from homescreen. |
|
378 servicemanager->ExecuteActionL(); |
|
379 } |
|
380 } |
|
381 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleServiceEventL() End") ); |
|
382 }//End HandleServiceEventL |
|
383 |
|
384 |
|
385 ////////////////////////////////////////////////////////////// |
|
386 // --------------------------------------------------------------------------- |
|
387 // CServiceWidgetPlugin::HandleNotifyChange() |
|
388 // --------------------------------------------------------------------------- |
|
389 // |
|
390 void CServiceWidgetPlugin::HandleNotifyChange( |
|
391 TServiceId /*aServiceId*/ ) |
|
392 { |
|
393 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleNotifyChange() start") ); |
|
394 //This function will be triggred if any change in any service |
|
395 TRAP_IGNORE( // Read the service id if any installed |
|
396 ReadServiceIdsL(); |
|
397 ValidateAllServicesL(); |
|
398 ); |
|
399 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleNotifyChange() end") ); |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------------------------- |
|
403 // CServiceWidgetPlugin::HandleError() |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 void CServiceWidgetPlugin::HandleError( TInt /*aError*/ ) |
|
407 { |
|
408 TRACE_SWP(TXT("CServiceWidgetPlugin::HandleError() start/end") ); |
|
409 } |
|
410 |
|
411 // --------------------------------------------------------------------------- |
|
412 // From class MAiPropertyExtension |
|
413 // Read property of publisher plug-in. |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 TAny* CServiceWidgetPlugin::GetPropertyL( TInt aProperty ) |
|
417 { |
|
418 TRACE_SWP(TXT("CServiceWidgetPlugin::GetPropertyL() start") ); |
|
419 TAny* property = NULL; |
|
420 |
|
421 switch ( aProperty ) |
|
422 { |
|
423 case EAiPublisherInfo: |
|
424 { |
|
425 property = static_cast<TAiPublisherInfo*>( &iInfo ); |
|
426 break; |
|
427 } |
|
428 } |
|
429 TRACE_SWP(TXT("CServiceWidgetPlugin::GetPropertyL() end") ); |
|
430 return property; |
|
431 } |
|
432 |
|
433 // --------------------------------------------------------------------------- |
|
434 // From class MAiPropertyExtension |
|
435 // Write property value to optimize the content model. |
|
436 // --------------------------------------------------------------------------- |
|
437 // |
|
438 void CServiceWidgetPlugin::SetPropertyL( TInt aProperty, TAny* aValue ) |
|
439 { |
|
440 TRACE_SWP(TXT("CServiceWidgetPlugin::SetPropertyL() start") ); |
|
441 switch ( aProperty ) |
|
442 { |
|
443 case EAiPublisherInfo: |
|
444 { |
|
445 if( aValue ) |
|
446 { |
|
447 const TAiPublisherInfo* info = static_cast<const TAiPublisherInfo*>( aValue ); |
|
448 iInfo.iName.Copy(info->iName); |
|
449 iInfo.iNamespace.Copy(info->iNamespace); |
|
450 } |
|
451 break; |
|
452 } |
|
453 default: |
|
454 break; |
|
455 } |
|
456 TRACE_SWP(TXT("CServiceWidgetPlugin::SetPropertyL() end") ); |
|
457 } |
|
458 // End of File |