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