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