|
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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "wrtharvester.h" |
|
21 #include "wrtharvesterregistryaccess.h" |
|
22 #include "wrtharvesterpsnotifier.h" |
|
23 #include "wrtharvesterpublisherobserver.h" |
|
24 |
|
25 #include "wrtharvesterconst.h" |
|
26 #include <widgetregistryconstants.h> |
|
27 |
|
28 #include <implementationproxy.h> |
|
29 |
|
30 #include <LiwServiceHandler.h> |
|
31 #include <LiwVariant.h> |
|
32 #include <LiwGenericParam.h> |
|
33 #include <e32property.h> //Publish & Subscribe |
|
34 #include <AknTaskList.h> |
|
35 #include <apaid.h> |
|
36 #include <apacmdln.h> |
|
37 #include <s32mem.h> |
|
38 |
|
39 |
|
40 // TODO Check these types, should they be definedin sapidatapluginconst.h? |
|
41 _LIT( KTemplatedWidget, "ai3templatedwidget"); |
|
42 _LIT8( KMySelected, "selected"); |
|
43 _LIT8( KMyActionMap, "action_map" ); |
|
44 _LIT8( KMyItem, "item" ); |
|
45 _LIT8( KMyAdd, "Add" ); |
|
46 _LIT8( KMyDelete, "Delete" ); |
|
47 _LIT8( KMyItemId, "item_id" ); |
|
48 _LIT8( KMyImage, "image" ); |
|
49 _LIT( KMyContType, "wideimage" ); |
|
50 _LIT8( KMyResultName,"mydata" ); |
|
51 _LIT( KMyActionName, "data" ); |
|
52 // ============================= LOCAL FUNCTIONS =============================== |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // ta |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 static HBufC* GetAppNameLC( RApaLsSession& aSession, const TUid& aUid ) |
|
59 { |
|
60 TApaAppInfo info; |
|
61 User::LeaveIfError( aSession.GetAppInfo( info, aUid ) ); |
|
62 |
|
63 return info.iFullName.AllocLC(); |
|
64 } |
|
65 |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // |
|
69 // ---------------------------------------------------------------------------- |
|
70 // |
|
71 static void HandleWidgetCommandL( |
|
72 RApaLsSession& aSession, |
|
73 const TDesC& aWidget, |
|
74 const TUid& aUid, |
|
75 TUint32 aOperation ) |
|
76 { |
|
77 const TInt size( 2* aWidget.Length() + 3*sizeof( TUint32 ) ); |
|
78 |
|
79 // Message format is <filenameLength><unicode_filename><someintegervalue> |
|
80 CApaCommandLine* cmd( CApaCommandLine::NewLC() ); |
|
81 HBufC8* opaque( HBufC8::NewLC( size ) ); |
|
82 |
|
83 RDesWriteStream stream; |
|
84 TPtr8 des( opaque->Des() ); |
|
85 |
|
86 stream.Open( des ); |
|
87 CleanupClosePushL( stream ); |
|
88 |
|
89 // Generate the command. |
|
90 stream.WriteUint32L( aUid.iUid ); |
|
91 stream.WriteUint32L( aWidget.Length() ); |
|
92 stream.WriteL( reinterpret_cast< const TUint8* >( aWidget.Ptr() ), |
|
93 aWidget.Size() ); |
|
94 |
|
95 stream.WriteInt32L( aOperation ); |
|
96 |
|
97 CleanupStack::PopAndDestroy( &stream ); |
|
98 |
|
99 // Generate command. |
|
100 cmd->SetCommandL( EApaCommandBackgroundAndWithoutViews ); |
|
101 cmd->SetOpaqueDataL( *opaque ); |
|
102 |
|
103 CleanupStack::PopAndDestroy( opaque ); |
|
104 |
|
105 cmd->SetExecutableNameL( KLauncherApp ); |
|
106 |
|
107 User::LeaveIfError( aSession.StartApp( *cmd ) ); |
|
108 CleanupStack::PopAndDestroy( cmd ); |
|
109 } |
|
110 |
|
111 // Map the interface UIDs to implementation factory functions |
|
112 const TImplementationProxy ImplementationTable[] = |
|
113 { |
|
114 IMPLEMENTATION_PROXY_ENTRY( 0xA12345FE, CWrtHarvester::NewL ) |
|
115 }; |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // Exported proxy for instantiation method resolution |
|
119 // ---------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
122 TInt& aTableCount ) |
|
123 { |
|
124 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
125 return ImplementationTable; |
|
126 } |
|
127 |
|
128 // ============================ MEMBER FUNCTIONS ============================== |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // Constructor |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 CWrtHarvester::CWrtHarvester( MLiwInterface* aCPSInterface ): |
|
135 iCPSInterface( aCPSInterface ) |
|
136 { |
|
137 } |
|
138 |
|
139 // ---------------------------------------------------------------------------- |
|
140 // Symbian 2nd phase constructor can leave. |
|
141 // ---------------------------------------------------------------------------- |
|
142 // |
|
143 void CWrtHarvester::ConstructL() |
|
144 { |
|
145 User::LeaveIfError( iApaSession.Connect() ); |
|
146 iWidgetUIListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetUIState ); |
|
147 iWidgetRegListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetRegAltered ); |
|
148 iWidgetMMCListener = CWrtHarvesterPSNotifier::NewL( this, EWidgetMMCAltered ); |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // Two-phased constructor. |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 CWrtHarvester* CWrtHarvester::NewL( MLiwInterface* aCPSInterface ) |
|
156 { |
|
157 CWrtHarvester* self = new ( ELeave ) CWrtHarvester( aCPSInterface ); |
|
158 CleanupStack::PushL(self); |
|
159 self->ConstructL(); |
|
160 CleanupStack::Pop(self); |
|
161 return self; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // Destructor |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 CWrtHarvester::~CWrtHarvester() |
|
169 { |
|
170 iObservers.ResetAll(); |
|
171 delete iWidgetUIListener; |
|
172 delete iWidgetRegListener; |
|
173 delete iWidgetMMCListener; |
|
174 iWidgetUids.Close(); |
|
175 iApaSession.Close(); |
|
176 } |
|
177 |
|
178 // ---------------------------------------------------------------------------- |
|
179 // |
|
180 // ---------------------------------------------------------------------------- |
|
181 // |
|
182 void CWrtHarvester::UpdateL() |
|
183 { |
|
184 UpdatePublishersL(); |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------------------------- |
|
188 // |
|
189 // ---------------------------------------------------------------------------- |
|
190 // |
|
191 void CWrtHarvester::HandlePublisherNotificationL( const TDesC& aContentId, const TDesC8& aTrigger ) |
|
192 { |
|
193 TUid uid( iRegistryAccess.WidgetUid( aContentId ) ); |
|
194 if( aTrigger == KActive() ) |
|
195 { |
|
196 StartWidgetL( uid ); |
|
197 } |
|
198 else |
|
199 { |
|
200 TWidgetOperations operation( Uninitialized ); |
|
201 if ( aTrigger == KDeActive ) |
|
202 { |
|
203 operation = Deactivate; |
|
204 } |
|
205 else if( aTrigger == KSuspend ) |
|
206 { |
|
207 operation = WidgetSuspend; |
|
208 } |
|
209 else if( aTrigger == KResume ) |
|
210 { |
|
211 operation = WidgetResume; |
|
212 } |
|
213 else if( aTrigger == KMySelected ) |
|
214 { |
|
215 operation = WidgetSelect; |
|
216 } |
|
217 LaunchWidgetL( operation, uid ); |
|
218 } |
|
219 } |
|
220 |
|
221 // ---------------------------------------------------------------------------- |
|
222 // |
|
223 // ---------------------------------------------------------------------------- |
|
224 // |
|
225 void CWrtHarvester::UpdatePublishersL() |
|
226 { |
|
227 RPointerArray< HBufC > bundleNames; |
|
228 |
|
229 // The array contain references. |
|
230 CleanupClosePushL( bundleNames ); |
|
231 |
|
232 iRegistryAccess.WidgetBundleNamesL( bundleNames ); |
|
233 |
|
234 // Remove observer and CPS registry entry of uninstalled widget |
|
235 for( TInt i = 0; i < iObservers.Count(); i++ ) |
|
236 { |
|
237 TBool found( EFalse ); |
|
238 for( TInt j = 0; j < bundleNames.Count(); j++ ) |
|
239 { |
|
240 if( iObservers[i]->Name() == bundleNames[j] ) |
|
241 { |
|
242 found = ETrue; |
|
243 break; |
|
244 } |
|
245 } |
|
246 if( found == EFalse ) |
|
247 { |
|
248 RemovePublisherL( KTemplatedWidget, iObservers[i]->Name(), KMyContType ); |
|
249 delete iObservers[i]; |
|
250 iObservers.Remove( i ); |
|
251 } |
|
252 } |
|
253 |
|
254 for( TInt i = bundleNames.Count() - 1; i >= 0; --i ) |
|
255 { |
|
256 TInt id = RegisterPublisherL( |
|
257 KTemplatedWidget, |
|
258 *( bundleNames[ i ] ), |
|
259 KMyContType, |
|
260 KMyImage ); |
|
261 |
|
262 if( id != KErrNotFound ) |
|
263 { |
|
264 RequestForNotificationL( KTemplatedWidget, *( bundleNames[ i ] ), KMyContType ); |
|
265 } |
|
266 } |
|
267 |
|
268 CleanupStack::PopAndDestroy( &bundleNames ); |
|
269 } |
|
270 |
|
271 // ---------------------------------------------------------------------------- |
|
272 // |
|
273 // ---------------------------------------------------------------------------- |
|
274 // |
|
275 TInt CWrtHarvester::RegisterPublisherL( |
|
276 const TDesC& aPublisherId, |
|
277 const TDesC& aContentId, |
|
278 const TDesC& aContentType, |
|
279 const TDesC8& aResultType ) |
|
280 { |
|
281 TInt id( KErrNotFound ); |
|
282 if( iCPSInterface ) |
|
283 { |
|
284 CLiwGenericParamList* inparam( CLiwGenericParamList::NewLC() ); |
|
285 CLiwGenericParamList* outparam( CLiwGenericParamList::NewLC() ); |
|
286 |
|
287 TLiwGenericParam type( KType, TLiwVariant( KPubData )); |
|
288 inparam->AppendL( type ); |
|
289 CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
290 CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC(); |
|
291 CLiwDefaultMap* actionmap( NULL ); |
|
292 |
|
293 // Create the data map for publisher registry |
|
294 cpdatamap->InsertL( KContentType, TLiwVariant( aContentType )); |
|
295 cpdatamap->InsertL( KContentId, TLiwVariant( aContentId )); |
|
296 cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId )); |
|
297 datamap->InsertL( KMyResultName, TLiwVariant( aResultType )); |
|
298 |
|
299 cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) ); |
|
300 |
|
301 // Create the action map for publisher registry |
|
302 actionmap = CLiwDefaultMap::NewLC(); |
|
303 actionmap->InsertL(KActive, TLiwVariant( KMyActionName )); |
|
304 actionmap->InsertL(KDeActive, TLiwVariant( KMyActionName )); |
|
305 actionmap->InsertL(KSuspend, TLiwVariant( KMyActionName )); |
|
306 actionmap->InsertL(KResume, TLiwVariant( KMyActionName )); |
|
307 actionmap->InsertL(KMySelected, TLiwVariant( KMyActionName )); |
|
308 |
|
309 cpdatamap->InsertL( KMyActionMap, TLiwVariant(actionmap)); |
|
310 CleanupStack::PopAndDestroy( actionmap ); |
|
311 |
|
312 TLiwGenericParam item( KMyItem, TLiwVariant( cpdatamap )); |
|
313 inparam->AppendL( item ); |
|
314 |
|
315 iCPSInterface->ExecuteCmdL( KMyAdd , *inparam, *outparam); |
|
316 id = ExtractItemId(*outparam); |
|
317 |
|
318 CleanupStack::PopAndDestroy( datamap ); |
|
319 CleanupStack::PopAndDestroy( cpdatamap ); |
|
320 item.Reset(); |
|
321 type.Reset(); |
|
322 CleanupStack::PopAndDestroy(outparam); |
|
323 CleanupStack::PopAndDestroy(inparam); |
|
324 } |
|
325 return id; |
|
326 } |
|
327 |
|
328 // ---------------------------------------------------------------------------- |
|
329 // |
|
330 // ---------------------------------------------------------------------------- |
|
331 // |
|
332 void CWrtHarvester::RemovePublisherL( const TDesC& aPublisherId, const TDesC& aContentId, |
|
333 const TDesC& aContentType ) |
|
334 { |
|
335 if( iCPSInterface ) |
|
336 { |
|
337 CLiwGenericParamList* inparam = CLiwGenericParamList::NewLC(); |
|
338 CLiwGenericParamList* outparam = CLiwGenericParamList::NewLC(); |
|
339 TLiwGenericParam type( KType, TLiwVariant( KPubData )); |
|
340 inparam->AppendL( type ); |
|
341 CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
342 CLiwDefaultMap* datamap = CLiwDefaultMap::NewLC(); |
|
343 |
|
344 // Create data map |
|
345 cpdatamap->InsertL( KContentType, TLiwVariant( aContentType )); |
|
346 cpdatamap->InsertL( KContentId, TLiwVariant( aContentId )); |
|
347 cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId )); |
|
348 |
|
349 cpdatamap->InsertL( KDataMap, TLiwVariant(datamap) ); |
|
350 |
|
351 TLiwGenericParam item( KMyItem, TLiwVariant( cpdatamap )); |
|
352 inparam->AppendL( item ); |
|
353 iCPSInterface->ExecuteCmdL( KMyDelete , *inparam, *outparam); |
|
354 |
|
355 CleanupStack::PopAndDestroy( datamap ); |
|
356 CleanupStack::PopAndDestroy( cpdatamap ); |
|
357 item.Reset(); |
|
358 type.Reset(); |
|
359 CleanupStack::PopAndDestroy(outparam); |
|
360 CleanupStack::PopAndDestroy(inparam); |
|
361 } |
|
362 } |
|
363 |
|
364 // ---------------------------------------------------------------------------- |
|
365 // |
|
366 // ---------------------------------------------------------------------------- |
|
367 // |
|
368 void CWrtHarvester::RequestForNotificationL( const TDesC& aPublisherId, const TDesC& aContentId, |
|
369 const TDesC& aContentType ) |
|
370 { |
|
371 // Preventing duplicate entries. |
|
372 for( TInt i = 0; i < iObservers.Count(); i++ ) |
|
373 { |
|
374 if( iObservers[i]->Name() == aContentId ) |
|
375 { |
|
376 return; |
|
377 } |
|
378 } |
|
379 |
|
380 CWrtHarvesterPublisherObserver* observer( NULL ); |
|
381 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
382 |
|
383 filter->InsertL( KPublisherId, TLiwVariant( aPublisherId ) ); |
|
384 filter->InsertL( KContentId, TLiwVariant( aContentId ) ); |
|
385 filter->InsertL( KContentType, TLiwVariant( aContentType ) ); |
|
386 filter->InsertL( KOperation, TLiwVariant( KExecute )); |
|
387 |
|
388 observer = CWrtHarvesterPublisherObserver::NewLC( aContentId, this ); |
|
389 observer->RegisterL(filter); |
|
390 |
|
391 iObservers.AppendL( observer ); |
|
392 |
|
393 CleanupStack::Pop( observer ); |
|
394 |
|
395 CleanupStack::PopAndDestroy(filter); |
|
396 } |
|
397 |
|
398 // ---------------------------------------------------------------------------- |
|
399 // |
|
400 // ---------------------------------------------------------------------------- |
|
401 // |
|
402 void CWrtHarvester::StartWidgetL( TUid aUid ) |
|
403 { |
|
404 iWidgetUids.Append( aUid ); |
|
405 TryLaunchNextWidgetL(); |
|
406 } |
|
407 |
|
408 // ---------------------------------------------------------------------------- |
|
409 // |
|
410 // ---------------------------------------------------------------------------- |
|
411 // |
|
412 void CWrtHarvester::TryLaunchNextWidgetL() |
|
413 { |
|
414 TInt value = KErrNone; |
|
415 TInt error = iWidgetUIListener->GetValue(value); |
|
416 if( error == KErrNone && value == 1 && iWidgetUids.Count() != 0 ) |
|
417 { |
|
418 // Set value to 0 so that next widget is not launched before Widget App sets value to 1. |
|
419 iWidgetUIListener->SetValue( 0 ); |
|
420 //Always launch the first widget |
|
421 LaunchWidgetL( LaunchMiniview, iWidgetUids[0] ); |
|
422 iWidgetUids.Remove( 0 ); |
|
423 } |
|
424 } |
|
425 |
|
426 // ---------------------------------------------------------------------------- |
|
427 // |
|
428 // ---------------------------------------------------------------------------- |
|
429 // |
|
430 TInt CWrtHarvester::ExtractItemId( const CLiwGenericParamList& aInParamList ) |
|
431 { |
|
432 TInt result ( KErrNotFound ); |
|
433 TInt pos( 0 ); |
|
434 aInParamList.FindFirst( pos, KMyItemId ); |
|
435 if( pos != KErrNotFound ) |
|
436 { |
|
437 // item id present - extract and return |
|
438 TUint uResult = 0; |
|
439 if ( aInParamList[pos].Value().Get( uResult ) ) |
|
440 { |
|
441 result = uResult; |
|
442 } |
|
443 } |
|
444 return result; |
|
445 } |
|
446 |
|
447 // ---------------------------------------------------------------------------- |
|
448 // |
|
449 // ---------------------------------------------------------------------------- |
|
450 // |
|
451 void CWrtHarvester::LaunchWidgetL( TWidgetOperations aOperation, TUid aUid ) |
|
452 { |
|
453 HBufC* widgetName( GetAppNameLC( iApaSession, aUid) ); |
|
454 HandleWidgetCommandL( iApaSession, *widgetName, aUid, aOperation ); |
|
455 CleanupStack::PopAndDestroy( widgetName ); |
|
456 } |
|
457 |
|
458 // End of File |
|
459 |