|
1 /* |
|
2 * Copyright (c) 2009 - 2010 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: MCS plugin publisher |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <ecom/ecom.h> |
|
20 #include <ecom/implementationproxy.h> |
|
21 #include <gulicon.h> |
|
22 #include <mcsmenuitem.h> |
|
23 |
|
24 // User includes |
|
25 #include <aicontentobserver.h> |
|
26 #include <aistrcnv.h> |
|
27 #include <aiutility.h> |
|
28 #include <aipluginsettings.h> |
|
29 #include "carouselpluginuids.hrh" |
|
30 #include "carouselplugin.h" |
|
31 #include "carouselplugindata.h" |
|
32 #include "carouselpluginengine.h" |
|
33 |
|
34 // Constants |
|
35 const TUint KPluginNameSeprator = '/'; |
|
36 |
|
37 const TInt KImplUidMCSPlugin = AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_CAROUSELPLUGIN; |
|
38 |
|
39 _LIT( KEventNameLaunchByIndex, "LaunchByIndex" ); |
|
40 _LIT( KEventNameShowSettings, "ShowSettings" ); |
|
41 _LIT( KContentItemTypeText, "text" ); |
|
42 _LIT( KContentItemTypeImage, "image" ); |
|
43 _LIT( KContentItemTypeData, "data" ); |
|
44 |
|
45 const TImplementationProxy KImplementationTable[] = |
|
46 { |
|
47 IMPLEMENTATION_PROXY_ENTRY( KImplUidMCSPlugin, CCarouselPlugin::NewL ) |
|
48 }; |
|
49 |
|
50 class CPublishItem : public CBase |
|
51 { |
|
52 public: |
|
53 ~CPublishItem(); |
|
54 CPublishItem(); |
|
55 |
|
56 CGulIcon* icon; |
|
57 HBufC* text; |
|
58 TBool last; |
|
59 }; |
|
60 |
|
61 CPublishItem::CPublishItem() |
|
62 { |
|
63 |
|
64 } |
|
65 |
|
66 CPublishItem::~CPublishItem() |
|
67 { |
|
68 delete text; |
|
69 } |
|
70 |
|
71 // ======== LOCAL FUNCTIONS ======== |
|
72 |
|
73 // ======== MEMBER FUNCTIONS ======== |
|
74 // ---------------------------------------------------------------------------- |
|
75 // CMCSPlugin::NewL |
|
76 // |
|
77 // ---------------------------------------------------------------------------- |
|
78 // |
|
79 CCarouselPlugin* CCarouselPlugin::NewL() |
|
80 { |
|
81 CCarouselPlugin* self = new ( ELeave ) CCarouselPlugin; |
|
82 CleanupStack::PushL( self ); |
|
83 self->ConstructL(); |
|
84 CleanupStack::Pop( self ); |
|
85 |
|
86 return self; |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // CMCSPlugin::CMCSPlugin |
|
91 // |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 CCarouselPlugin::CCarouselPlugin() |
|
95 { |
|
96 } |
|
97 |
|
98 // ---------------------------------------------------------------------------- |
|
99 // CMCSPlugin::ConstructL |
|
100 // |
|
101 // ---------------------------------------------------------------------------- |
|
102 // |
|
103 void CCarouselPlugin::ConstructL() |
|
104 { |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // Destructor |
|
109 // Deletes all data created to heap |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 CCarouselPlugin::~CCarouselPlugin() |
|
113 { |
|
114 Release( iContent ); |
|
115 |
|
116 delete iEngine; |
|
117 iObservers.Close(); |
|
118 |
|
119 DeleteContentModel(); |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CMCSPlugin::PublishL |
|
124 // Publishes the all the items |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 void CCarouselPlugin::PublishL() |
|
128 { |
|
129 TInt err( KErrNone ); |
|
130 TInt observers( iObservers.Count() ); |
|
131 TInt transactionId( reinterpret_cast<TInt>( this ) ); |
|
132 TInt menuItems ( iEngine->MenuItemCount() ); |
|
133 |
|
134 for ( TInt i = 0; i < observers; i++ ) |
|
135 { |
|
136 MAiContentObserver* observer( iObservers[ i ] ); |
|
137 err = observer->StartTransaction( transactionId ); |
|
138 |
|
139 if ( err == KErrNotSupported ) |
|
140 { |
|
141 return; |
|
142 } |
|
143 |
|
144 // Publish content to all items |
|
145 for ( TInt j = 0; j < menuItems; j++ ) |
|
146 { |
|
147 // Index has to start from 1 ( j + 1 ) |
|
148 PublishLItemL( *observer, iEngine->MenuDataL( j ), ( j + 1 ) ); |
|
149 }// shortcut count |
|
150 |
|
151 if ( err == KErrNone ) |
|
152 { |
|
153 err = observer->Commit( transactionId ); |
|
154 |
|
155 if ( err == KErrNotSupported ) |
|
156 { |
|
157 return; |
|
158 } |
|
159 } |
|
160 }//observers |
|
161 |
|
162 // Set all items not dirty. |
|
163 for ( TInt j = 0; j < menuItems; j++ ) |
|
164 { |
|
165 iEngine->MenuDataL( j ).SetDirty( EFalse ); |
|
166 } |
|
167 } |
|
168 |
|
169 // ---------------------------------------------------------------------------- |
|
170 // CMCSPlugin::PublishLItemL |
|
171 // Publishes one item to given index |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 void CCarouselPlugin::PublishLItemL( MAiContentObserver& aObserver, |
|
175 CCarouselData& aData, TInt aIndex ) |
|
176 { |
|
177 if( !aData.IsDirty() ) |
|
178 { |
|
179 return; |
|
180 } |
|
181 |
|
182 CMenuItem* item = iEngine->FetchMenuItemL( aData ); |
|
183 CleanupStack::PushL( item ); |
|
184 |
|
185 if ( iContentModel[0].type == KAiContentTypeData ) |
|
186 { |
|
187 if(TPtrC16( ( const TText16* ) iContentModel[ 0 ].cid ) == _L("widget") ) |
|
188 { |
|
189 CGulIcon* icon( iEngine->ItemIconL( item, _L("icon"))); |
|
190 icon->SetBitmapsOwnedExternally( ETrue ); |
|
191 aObserver.Publish( *this, 0, TPckgC<TAny*>( icon ), aIndex - 1 ); |
|
192 } |
|
193 } |
|
194 CleanupStack::PopAndDestroy( item ); |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // PublishEditorItemsL |
|
199 // |
|
200 // ---------------------------------------------------------------------------- |
|
201 // |
|
202 void CCarouselPlugin::PublishEditorItemsL() |
|
203 {/* |
|
204 RArray<TMenuItem> items = iEngine->MenuItemsL(); |
|
205 CleanupClosePushL( items ); |
|
206 |
|
207 TInt count( items.Count()); |
|
208 for( TInt i = 0; i < count; i++ ) |
|
209 { |
|
210 CMenuItem* item( iEngine->FetchMenuItemL( items[i])); |
|
211 CleanupStack::PushL( item ); |
|
212 CGulIcon* icon( iEngine->ItemIconL( *item, _L("icon"))); |
|
213 TPtrC name( iEngine->ItemTextL( *item, _L("long_name") )); |
|
214 CPublishItem* pItem = new CPublishItem; |
|
215 pItem->icon = icon; |
|
216 pItem->text = name.AllocL(); |
|
217 if( i < count - 1 ) |
|
218 { |
|
219 pItem->last = EFalse; |
|
220 } |
|
221 else |
|
222 { |
|
223 pItem->last = ETrue; |
|
224 } |
|
225 iObservers[0]->Publish( *this, 0, TPckgC<TAny*>( pItem), i ); |
|
226 delete pItem; |
|
227 CleanupStack::PopAndDestroy( item ); |
|
228 } |
|
229 CleanupStack::PopAndDestroy( &items ); |
|
230 */ |
|
231 } |
|
232 |
|
233 // ---------------------------------------------------------------------------- |
|
234 // CMCSPlugin::Start |
|
235 // |
|
236 // ---------------------------------------------------------------------------- |
|
237 // |
|
238 void CCarouselPlugin::Start( TStartReason /*aReason*/ ) |
|
239 { |
|
240 |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------------------------- |
|
244 // CMCSPlugin::Stop |
|
245 // |
|
246 // ---------------------------------------------------------------------------- |
|
247 // |
|
248 void CCarouselPlugin::Stop( TStopReason /*aReason*/ ) |
|
249 { |
|
250 |
|
251 } |
|
252 |
|
253 // ---------------------------------------------------------------------------- |
|
254 // CMCSPlugin::Resume |
|
255 // |
|
256 // ---------------------------------------------------------------------------- |
|
257 // |
|
258 void CCarouselPlugin::Resume( TResumeReason aReason ) |
|
259 { |
|
260 if ( aReason == EForeground ) |
|
261 { |
|
262 iEngine->SetBackupRestore( EFalse ); |
|
263 |
|
264 if ( PublishRequired() ) |
|
265 { |
|
266 TRAP_IGNORE( PublishL() ); |
|
267 } |
|
268 } |
|
269 } |
|
270 |
|
271 // ---------------------------------------------------------------------------- |
|
272 // CMCSPlugin::Suspend |
|
273 // |
|
274 // ---------------------------------------------------------------------------- |
|
275 // |
|
276 void CCarouselPlugin::Suspend( TSuspendReason aReason ) |
|
277 { |
|
278 if ( aReason == EGeneralThemeChange ) |
|
279 { |
|
280 TInt dataCount( iEngine->MenuItemCount() ); |
|
281 |
|
282 for ( TInt i = 0; i < dataCount; i++ ) |
|
283 { |
|
284 TRAP_IGNORE( iEngine->MenuDataL( i ).SetDirty( ETrue ) ); |
|
285 } |
|
286 } |
|
287 else if ( aReason == EBackupRestore ) |
|
288 { |
|
289 // Prevent item launching during backup / restore |
|
290 iEngine->SetBackupRestore( ETrue ); |
|
291 } |
|
292 } |
|
293 |
|
294 // ---------------------------------------------------------------------------- |
|
295 // CMCSPlugin::SubscribeL |
|
296 // |
|
297 // ---------------------------------------------------------------------------- |
|
298 // |
|
299 void CCarouselPlugin::SubscribeL( MAiContentObserver& aObserver ) |
|
300 { |
|
301 iObservers.AppendL( &aObserver ); |
|
302 } |
|
303 |
|
304 // ---------------------------------------------------------------------------- |
|
305 // CMCSPlugin::ConfigureL |
|
306 // |
|
307 // ---------------------------------------------------------------------------- |
|
308 // |
|
309 void CCarouselPlugin::ConfigureL( RAiSettingsItemArray& aSettings ) |
|
310 { |
|
311 iEngine = CCarouselPluginEngine::NewL( *this, PublisherInfo().Namespace() ); |
|
312 |
|
313 TLinearOrder<MAiPluginSettings> sortMethod( CCarouselPlugin::CompareItems ); |
|
314 RAiSettingsItemArray contentItemsArr; |
|
315 |
|
316 TInt count( aSettings.Count() ); |
|
317 |
|
318 for ( TInt i = 0; i < count; i++ ) |
|
319 { |
|
320 MAiPluginSettings* setting( aSettings[ i ] ); |
|
321 |
|
322 if( setting->AiPluginItemType() == EAiPluginContentItem ) |
|
323 { |
|
324 MAiPluginContentItem& contItem( setting->AiPluginContentItem() ); |
|
325 TPtrC name( contItem.Name() ); |
|
326 TPtrC type( contItem.Type() ); |
|
327 |
|
328 contentItemsArr.InsertInOrder( setting, sortMethod ); |
|
329 } |
|
330 } |
|
331 |
|
332 iDataCount = contentItemsArr.Count(); |
|
333 |
|
334 if ( iDataCount > 0 ) |
|
335 { |
|
336 // Create the dynamic content Model |
|
337 DeleteContentModel(); |
|
338 |
|
339 iContentModel = new ( ELeave ) TAiContentItem[ iDataCount ]; |
|
340 |
|
341 for ( TInt i = 0; i < iDataCount; i++ ) |
|
342 { |
|
343 iContentModel[i].id = i; |
|
344 |
|
345 MAiPluginContentItem& contentItem( |
|
346 contentItemsArr[ i ]->AiPluginContentItem() ); |
|
347 |
|
348 if( contentItem.Type() == KContentItemTypeText ) |
|
349 { |
|
350 // text |
|
351 iContentModel[i].type = KAiContentTypeText; |
|
352 } |
|
353 if( contentItem.Type() == KContentItemTypeImage ) |
|
354 { |
|
355 // image |
|
356 iContentModel[i].type = KAiContentTypeBitmap; |
|
357 } |
|
358 else if(contentItem.Type() == KContentItemTypeData ) |
|
359 { |
|
360 // data |
|
361 iContentModel[i].type = KAiContentTypeData; |
|
362 } |
|
363 |
|
364 TInt pos( contentItem.Name().Locate( KPluginNameSeprator ) ); |
|
365 |
|
366 HBufC* contentId = HBufC::NewL( contentItem.Name().Length() ); |
|
367 CleanupStack::PushL( contentId ); |
|
368 |
|
369 TPtr ptr( contentId->Des() ); |
|
370 ptr = contentItem.Name().Mid( pos + 1 ); |
|
371 |
|
372 TInt sizeOfContentId( ptr.Size() + sizeof( wchar_t ) ); |
|
373 |
|
374 iContentModel[i].cid = |
|
375 static_cast<const wchar_t*>( User::AllocL( sizeOfContentId ) ); |
|
376 |
|
377 Mem::Copy( ( TAny* )iContentModel[i].cid, |
|
378 ptr.PtrZ(), sizeOfContentId ); |
|
379 |
|
380 CleanupStack::PopAndDestroy( contentId ); |
|
381 } |
|
382 |
|
383 iContent = AiUtility::CreateContentItemArrayIteratorL( |
|
384 iContentModel, iDataCount ); |
|
385 } |
|
386 |
|
387 contentItemsArr.Reset(); |
|
388 // We own the array so destroy it |
|
389 aSettings.ResetAndDestroy(); |
|
390 } |
|
391 |
|
392 // ---------------------------------------------------------------------------- |
|
393 // CMCSPlugin::GetProperty |
|
394 // |
|
395 // ---------------------------------------------------------------------------- |
|
396 // |
|
397 TAny* CCarouselPlugin::GetProperty( TProperty aProperty ) |
|
398 { |
|
399 if( aProperty == EPublisherContent ) |
|
400 { |
|
401 return static_cast< MAiContentItemIterator* >( iContent ); |
|
402 } |
|
403 |
|
404 return NULL; |
|
405 } |
|
406 |
|
407 // ---------------------------------------------------------------------------- |
|
408 // CMCSPlugin::HandleEvent |
|
409 // |
|
410 // ---------------------------------------------------------------------------- |
|
411 // |
|
412 void CCarouselPlugin::HandleEvent( const TDesC& aEventName, const TDesC& aParam ) |
|
413 { |
|
414 if( aEventName == KEventNameLaunchByIndex ) |
|
415 { |
|
416 TInt32 index; |
|
417 AiUtility::ParseInt( index, aParam ); |
|
418 |
|
419 TRAP_IGNORE( iEngine->LaunchItemL( index - 1 ) ); |
|
420 } |
|
421 else if( aEventName == KEventNameShowSettings ) |
|
422 { |
|
423 TRAP_IGNORE( iEngine->ShowSettingsL() ); |
|
424 } |
|
425 else if( aEventName == _L("ShowEditor")) |
|
426 { |
|
427 TRAP_IGNORE( PublishEditorItemsL() ); |
|
428 } |
|
429 } |
|
430 |
|
431 // ---------------------------------------------------------------------------- |
|
432 // CMCSPlugin::CompareItems |
|
433 // |
|
434 // ---------------------------------------------------------------------------- |
|
435 // |
|
436 TInt CCarouselPlugin::CompareItems( const MAiPluginSettings& aFirst, |
|
437 const MAiPluginSettings& aSecond ) |
|
438 { |
|
439 MAiPluginSettings& first = const_cast<MAiPluginSettings&>(aFirst); |
|
440 MAiPluginSettings& second = const_cast<MAiPluginSettings&>(aSecond); |
|
441 return first.AiPluginContentItem().Name().CompareC(second.AiPluginContentItem().Name()); |
|
442 } |
|
443 |
|
444 // ---------------------------------------------------------------------------- |
|
445 // CMCSPlugin::DeleteContentModel |
|
446 // |
|
447 // ---------------------------------------------------------------------------- |
|
448 // |
|
449 void CCarouselPlugin::DeleteContentModel() |
|
450 { |
|
451 if( iContentModel ) |
|
452 { |
|
453 for ( TInt i = 0; i < iDataCount; i++ ) |
|
454 { |
|
455 if( iContentModel[i].cid ) |
|
456 { |
|
457 TAny* cell = static_cast<TAny*>( const_cast<wchar_t*>( iContentModel[i].cid ) ); |
|
458 User::Free( cell ); // Originally allocated with User::Alloc, so delete |
|
459 // with correlating method. |
|
460 iContentModel[i].cid = NULL; |
|
461 } |
|
462 } |
|
463 |
|
464 delete iContentModel; |
|
465 iContentModel = NULL; |
|
466 } |
|
467 } |
|
468 |
|
469 // ---------------------------------------------------------------------------- |
|
470 // CMCSPlugin::PublishRequired |
|
471 // |
|
472 // ---------------------------------------------------------------------------- |
|
473 // |
|
474 TBool CCarouselPlugin::PublishRequired() const |
|
475 { |
|
476 TInt count( iEngine->MenuItemCount() ); |
|
477 |
|
478 TBool retval( EFalse ); |
|
479 |
|
480 for ( TInt i = 0; !retval && i < count; i++ ) |
|
481 { |
|
482 TRAP_IGNORE( retval = iEngine->MenuDataL( i ).IsDirty() ); |
|
483 } |
|
484 |
|
485 |
|
486 return retval; |
|
487 } |
|
488 |
|
489 // ======== GLOBAL FUNCTIONS ======== |
|
490 // ---------------------------------------------------------------------------- |
|
491 // Constructs and returns an application object. |
|
492 // ---------------------------------------------------------------------------- |
|
493 // |
|
494 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
495 TInt& aTableCount ) |
|
496 { |
|
497 aTableCount = sizeof( KImplementationTable ) / |
|
498 sizeof( TImplementationProxy ); |
|
499 return KImplementationTable; |
|
500 } |
|
501 |
|
502 // End of file |