|
1 /* |
|
2 * Copyright (c) 2009 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: The engine class of MCS plugin. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "mcspluginengine.h" |
|
21 |
|
22 #include <gulicon.h> |
|
23 #include <AknsItemID.h> |
|
24 #include <gslauncher.h> |
|
25 #include <aisystemuids.hrh> |
|
26 |
|
27 #include <mcsmenuitem.h> |
|
28 #include <mcsmenufilter.h> |
|
29 #include <mcsmenuoperation.h> |
|
30 #include <mcsmenuiconutility.h> |
|
31 #include <ActiveFavouritesDbNotifier.h> |
|
32 #include <FavouritesItemList.h> |
|
33 |
|
34 #include <bautils.h> |
|
35 #include <StringLoader.h> |
|
36 #include <aknnotedialog.h> |
|
37 #include <avkon.rsg> |
|
38 #include <mcspluginres.rsg> |
|
39 #include "mcsplugin.h" |
|
40 #include "mcsplugindata.h" |
|
41 #include "mcspluginuids.hrh" |
|
42 |
|
43 #include <apgtask.h> |
|
44 #include <apgcli.h> |
|
45 #include <apacmdln.h> |
|
46 #include <gfxtranseffect/gfxtranseffect.h> // For Transition effect |
|
47 #include <akntranseffect.h> |
|
48 |
|
49 #include <AknsConstants.h> |
|
50 _LIT( KMyMenuData, "matrixmenudata" ); |
|
51 _LIT( KSkin, "skin" ); |
|
52 _LIT( KMif, "mif" ); |
|
53 _LIT( KResourceDrive, "Z:" ); |
|
54 _LIT( KResourceFile, "mcspluginres.rsc" ); |
|
55 _LIT( KResPath, "\\resource\\" ); |
|
56 _LIT( KMenuAttrRefcount, "ref_count" ); |
|
57 _LIT( KMMApplication, "mm://" ); |
|
58 _LIT( KHideExit, "?exit=hide" ); |
|
59 _LIT( KHideExit2, "&exit=hide" ); |
|
60 _LIT( KSetFocusString, "!setfocus?applicationgroup_name=" ); |
|
61 _LIT( KApplicationGroupName, "applicationgroup_name" ); |
|
62 _LIT( KSuiteName, "suite_name" ); |
|
63 _LIT( KIcon, "icon" ); |
|
64 _LIT( KMenuAttrUndefUid, "0x99999991" ); |
|
65 |
|
66 const TUid KHomescreenUid = { AI_UID3_AIFW_COMMON }; |
|
67 const TUid KMMUid = { 0x101F4CD2 }; |
|
68 |
|
69 // ======== LOCAL FUNCTIONS ======== |
|
70 |
|
71 static TPtrC NextIdToken( TLex& aLexer ) |
|
72 { |
|
73 aLexer.SkipSpace(); |
|
74 aLexer.Mark(); |
|
75 while( !aLexer.Eos() && !aLexer.Peek().IsSpace() && aLexer.Peek() != ')' ) |
|
76 { |
|
77 aLexer.Inc(); |
|
78 } |
|
79 return aLexer.MarkedToken(); |
|
80 } |
|
81 |
|
82 // ============================ MEMBER FUNCTIONS =============================== |
|
83 // --------------------------------------------------------- |
|
84 // Default constructor |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 CMCSPluginEngine::CMCSPluginEngine( CMCSPlugin& aPlugin, const TDesC8& aInstanceUid ) |
|
88 : iPlugin( aPlugin ), iInstanceUid( aInstanceUid ), |
|
89 iSuspend( EFalse ) |
|
90 { |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // Two-phased constructor. |
|
95 // Create instance of concrete ECOM interface implementation |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 CMCSPluginEngine* CMCSPluginEngine::NewL( CMCSPlugin& aPlugin, const TDesC8& aInstanceUid ) |
|
99 { |
|
100 CMCSPluginEngine* self = new( ELeave ) CMCSPluginEngine( aPlugin, aInstanceUid ); |
|
101 CleanupStack::PushL( self ); |
|
102 self->ConstructL(); |
|
103 CleanupStack::Pop( self ); |
|
104 |
|
105 return self; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // Symbian 2nd phase constructor can leave |
|
110 // --------------------------------------------------------- |
|
111 // |
|
112 void CMCSPluginEngine::ConstructL() |
|
113 { |
|
114 TFullName resourceFile( KResourceDrive ); |
|
115 resourceFile.Append( KResPath ); |
|
116 resourceFile.Append( KResourceFile ); |
|
117 BaflUtils::NearestLanguageFile( |
|
118 CCoeEnv::Static()->FsSession(), |
|
119 resourceFile ); |
|
120 iResourceOffset = |
|
121 CCoeEnv::Static()->AddResourceFileL( resourceFile ); |
|
122 InitL(); |
|
123 StartObservingL(); |
|
124 } |
|
125 |
|
126 |
|
127 // --------------------------------------------------------- |
|
128 // Destructor. |
|
129 // --------------------------------------------------------- |
|
130 // |
|
131 CMCSPluginEngine::~CMCSPluginEngine() |
|
132 { |
|
133 StopObserving(); |
|
134 |
|
135 delete iPluginData; |
|
136 iNotifier.Close(); |
|
137 iMenu.Close(); |
|
138 //iWatcher->Cancel(); |
|
139 delete iWatcher; |
|
140 delete iNotifyWatcher; |
|
141 CCoeEnv::Static()->DeleteResourceFile( iResourceOffset ); |
|
142 } |
|
143 |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CMCSPluginEngine::InitL() |
|
150 { |
|
151 iMenu.OpenL( KMyMenuData ); |
|
152 iPluginData = CMCSPluginData::NewL( *this, iInstanceUid ); |
|
153 iWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::EOperation ); |
|
154 TInt err = iNotifier.Open( iMenu ); |
|
155 if ( err == KErrNone ) |
|
156 { |
|
157 iNotifyWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::ENotify ); |
|
158 iNotifier.Notify( 0, |
|
159 RMenuNotifier::EItemsAddedRemoved | |
|
160 RMenuNotifier::EItemsReordered | |
|
161 RMenuNotifier::EItemAttributeChanged, |
|
162 iNotifyWatcher->iStatus ); |
|
163 iNotifyWatcher->WatchNotify( this ); |
|
164 } |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // Tells the settings container to start observing for changes |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CMCSPluginEngine::StartObservingL() |
|
172 { |
|
173 // registering to bookmarks db. changes observing |
|
174 User::LeaveIfError( iBookmarkSession.Connect() ); |
|
175 User::LeaveIfError( iBookmarkDb.Open( iBookmarkSession, KBrowserBookmarks ) ); |
|
176 |
|
177 iBookmarkDbObserver = new (ELeave) CActiveFavouritesDbNotifier( |
|
178 iBookmarkDb, *this ); |
|
179 iBookmarkDbObserver->Start(); |
|
180 |
|
181 // registering to mailbox db. changes observing |
|
182 iMsvSession = CMsvSession::OpenAsObserverL( *this) ; |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // Tells the settings container to stop observing for changes |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 void CMCSPluginEngine::StopObserving() |
|
190 { |
|
191 if ( iBookmarkDbObserver ) |
|
192 { |
|
193 delete iBookmarkDbObserver; |
|
194 iBookmarkDbObserver = NULL; |
|
195 } |
|
196 iBookmarkDb.Close(); |
|
197 iBookmarkSession.Close(); |
|
198 |
|
199 if ( iMsvSession ) |
|
200 { |
|
201 delete iMsvSession; |
|
202 iMsvSession = NULL; |
|
203 } |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 TMCSData& CMCSPluginEngine::MenuDataL( const TInt& aIndex ) |
|
211 { |
|
212 return iPluginData->DataItemL( aIndex ); |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 TInt CMCSPluginEngine::MenuItemCount() |
|
220 { |
|
221 return iPluginData->DataCount(); |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // Returns the menu item header, which matches the given filter. |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 TMenuItem CMCSPluginEngine::FindMenuItemL( CMenuFilter& aFilter ) |
|
229 { |
|
230 TMenuItem item; |
|
231 const TInt root = iMenu.RootFolderL(); |
|
232 RArray<TMenuItem> items; |
|
233 CleanupClosePushL( items ); |
|
234 iMenu.GetItemsL( items, root, &aFilter, ETrue ); |
|
235 if( items.Count() > 0 ) |
|
236 { |
|
237 |
|
238 item = items[0]; |
|
239 } |
|
240 |
|
241 CleanupStack::PopAndDestroy( &items ); |
|
242 return item; |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // Returns the actual menu item for the given header. |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 CMenuItem* CMCSPluginEngine::FetchMenuItemL( const TMenuItem& aMenuItem ) |
|
250 { |
|
251 return CMenuItem::OpenL( iMenu, aMenuItem ); |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // Returns MCS default icon if attribute is 'icon' else parses the |
|
256 // skin definition from attribute and sets attributes to aMenuItem. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 CGulIcon* CMCSPluginEngine::ItemIconL( CMenuItem& aMenuItem, const TDesC& aAttr ) |
|
260 { |
|
261 CAknIcon* icon( NULL ); |
|
262 CGulIcon* gIcon( NULL ); |
|
263 TBool exists( ETrue ); |
|
264 if( aAttr != KIcon ) |
|
265 { |
|
266 // Resolve secondary icon definition from attribute |
|
267 TPtrC iconDef = aMenuItem.GetAttributeL( aAttr, exists ); |
|
268 if( exists ) |
|
269 { |
|
270 exists = ConstructMenuItemForIconL( iconDef, aMenuItem ); |
|
271 } |
|
272 } |
|
273 if( exists ) |
|
274 { |
|
275 icon = MenuIconUtility::GetItemIconL( aMenuItem ); |
|
276 if( icon ) |
|
277 { |
|
278 CleanupStack::PushL( icon ); |
|
279 gIcon = CGulIcon::NewL(icon->Bitmap(), icon->Mask()); |
|
280 // Detach and delete |
|
281 icon->SetBitmap( NULL ); |
|
282 icon->SetMask( NULL ); |
|
283 CleanupStack::PopAndDestroy( icon ); |
|
284 } |
|
285 } |
|
286 return gIcon; |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // Returns text string for the given attribute |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 TPtrC CMCSPluginEngine::ItemTextL( CMenuItem& aMenuItem, const TDesC& aAttr ) |
|
294 { |
|
295 TBool exists( KErrNotFound ); |
|
296 TPtrC name = aMenuItem.GetAttributeL( aAttr, exists ); |
|
297 if( exists ) |
|
298 { |
|
299 return name; |
|
300 } |
|
301 else |
|
302 { |
|
303 return KNullDesC(); |
|
304 } |
|
305 } |
|
306 |
|
307 // --------------------------------------------------------------------------- |
|
308 // Calls the open command for the given menu item header |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 void CMCSPluginEngine::LaunchItemL( const TInt& aIndex ) |
|
312 { |
|
313 |
|
314 if ( iSuspend ) |
|
315 { |
|
316 HBufC* temp = StringLoader::LoadLC( R_MCS_DISABLE_OPEN_ITEM ); |
|
317 |
|
318 CAknNoteDialog* dialog = new (ELeave) CAknNoteDialog( |
|
319 CAknNoteDialog::EConfirmationTone, |
|
320 CAknNoteDialog::ENoTimeout ); |
|
321 dialog->SetTextL( temp->Des() ); |
|
322 dialog->ExecuteDlgLD( R_MCS_DISABLE_OPEN_ITEM_DLG ); |
|
323 CleanupStack::PopAndDestroy( temp ); |
|
324 return; |
|
325 } |
|
326 if( iWatcher->IsActive()) |
|
327 { |
|
328 return; |
|
329 } |
|
330 |
|
331 |
|
332 TMCSData& dataItem = iPluginData->DataItemL( aIndex ); |
|
333 CMenuItem* item = CMenuItem::OpenL( iMenu, dataItem.MenuItem()); |
|
334 CleanupStack::PushL( item ); |
|
335 TPtrC type = item->Type(); |
|
336 |
|
337 // run suite/folder |
|
338 if ( type == KMenuTypeSuite || type == KMenuTypeFolder ) |
|
339 { |
|
340 |
|
341 // message for MM application |
|
342 HBufC8* message; |
|
343 |
|
344 if ( type == KMenuTypeSuite ) |
|
345 { |
|
346 // prepare message for launching suite |
|
347 TBool hasSuiteName = EFalse; |
|
348 TPtrC suiteName = item->GetAttributeL( KSuiteName, hasSuiteName ); |
|
349 if ( !hasSuiteName ) |
|
350 { |
|
351 CleanupStack::PopAndDestroy( item ); |
|
352 return; |
|
353 } |
|
354 message = HBufC8::NewLC( KMMApplication().Length() + |
|
355 suiteName.Length() + |
|
356 KHideExit().Length() ); |
|
357 |
|
358 message->Des().Copy( KMMApplication ); |
|
359 message->Des().Append( suiteName ); |
|
360 message->Des().Append( KHideExit ); |
|
361 } |
|
362 else |
|
363 { |
|
364 // prepare message for launching folder |
|
365 TBool hasApplicationGroupName = EFalse; |
|
366 TPtrC applicationGroupName = item->GetAttributeL( KApplicationGroupName, |
|
367 hasApplicationGroupName ); |
|
368 if ( !hasApplicationGroupName ) |
|
369 { |
|
370 CleanupStack::PopAndDestroy( item ); |
|
371 return; |
|
372 } |
|
373 message = HBufC8::NewLC( KMMApplication().Length() + |
|
374 KSetFocusString().Length() + |
|
375 applicationGroupName.Length() + |
|
376 KHideExit2().Length() ); |
|
377 |
|
378 message->Des().Copy( KMMApplication ); |
|
379 message->Des().Append( KSetFocusString ); |
|
380 message->Des().Append( applicationGroupName ); |
|
381 message->Des().Append( KHideExit2 ); |
|
382 } |
|
383 |
|
384 // find MM application |
|
385 TApaTaskList taskList( CCoeEnv::Static()->WsSession() ); |
|
386 TApaTask task = taskList.FindApp( KMMUid ); |
|
387 |
|
388 if ( task.Exists() ) |
|
389 { |
|
390 // MM is already running in background - send APA Message |
|
391 task.SendMessage( TUid::Uid( KUidApaMessageSwitchOpenFileValue ), *message ); |
|
392 } |
|
393 else |
|
394 { |
|
395 // MM not running yet - use Command Line Tail |
|
396 RApaLsSession appArcSession; |
|
397 CleanupClosePushL( appArcSession ); |
|
398 User::LeaveIfError( appArcSession.Connect() ); |
|
399 TApaAppInfo appInfo; |
|
400 TInt err = appArcSession.GetAppInfo( appInfo, KMMUid ); |
|
401 if ( err == KErrNone ) |
|
402 { |
|
403 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
404 cmdLine->SetExecutableNameL( appInfo.iFullName ); |
|
405 cmdLine->SetCommandL( EApaCommandRun ); |
|
406 cmdLine->SetTailEndL( *message ); |
|
407 appArcSession.StartApp( *cmdLine ); |
|
408 CleanupStack::PopAndDestroy( cmdLine ); |
|
409 } |
|
410 CleanupStack::PopAndDestroy( &appArcSession ); |
|
411 } |
|
412 CleanupStack::PopAndDestroy( message ); |
|
413 } |
|
414 else |
|
415 { |
|
416 TBool exists( EFalse ); |
|
417 TPtrC desc( item->GetAttributeL( KMenuAttrUid, exists ) ); |
|
418 |
|
419 if( exists ) |
|
420 { |
|
421 _LIT( KPrefix, "0x" ); |
|
422 const TInt pos( desc.FindF( KPrefix ) ); |
|
423 |
|
424 if( pos != KErrNotFound ) |
|
425 { |
|
426 TLex lex( desc.Mid( pos + KPrefix().Length() ) ); |
|
427 // Hex parsing needs unsigned int |
|
428 TUint32 value = 0; |
|
429 const TInt parseResult = lex.Val( value, EHex ); |
|
430 |
|
431 if ( parseResult == KErrNone ) |
|
432 { |
|
433 TUid uid( KNullUid ); |
|
434 TInt32 value32( value ); |
|
435 uid.iUid = value32; |
|
436 |
|
437 if( uid != KNullUid ) |
|
438 { |
|
439 //start a full screen effect |
|
440 GfxTransEffect::BeginFullScreen( |
|
441 AknTransEffect::EApplicationStart, |
|
442 TRect(0,0,0,0), |
|
443 AknTransEffect::EParameterType, |
|
444 AknTransEffect::GfxTransParam( uid, |
|
445 AknTransEffect::TParameter::EActivateExplicitContinue )); |
|
446 } |
|
447 } |
|
448 } |
|
449 } |
|
450 |
|
451 // run application/shortcut/bookmark |
|
452 CMenuOperation* operation = item->HandleCommandL( |
|
453 KMenuCmdOpen, KNullDesC8, iWatcher->iStatus ); |
|
454 iWatcher->Watch( operation ); |
|
455 } |
|
456 CleanupStack::PopAndDestroy( item ); |
|
457 } |
|
458 |
|
459 // --------------------------------------------------------------------------- |
|
460 // Handle the change in Menu Content |
|
461 // --------------------------------------------------------------------------- |
|
462 // |
|
463 void CMCSPluginEngine::HandleNotifyL() |
|
464 { |
|
465 TInt count( iPluginData->DataCount()); |
|
466 for( TInt i = 0; i < count; i++ ) |
|
467 { |
|
468 TMCSData& data = iPluginData->DataItemL(i); |
|
469 // Check that all the data still exist is MCS, if flag is hidden or |
|
470 // missing, we have to remove data from UI |
|
471 CMenuItem* menuItem = CMenuItem::OpenL( iMenu, data.MenuItem().Id() ); |
|
472 CleanupStack::PushL( menuItem ); |
|
473 if ( !menuItem || |
|
474 ( menuItem->Flags() & TMenuItem::EHidden ) || |
|
475 ( menuItem->Flags() & TMenuItem::EMissing ) ) |
|
476 { |
|
477 // Get the replacement for hidden data |
|
478 CMenuFilter* filter = CMenuFilter::NewL(); |
|
479 CleanupStack::PushL( filter ); |
|
480 // 'Undefined' item |
|
481 filter->HaveAttributeL( KMenuAttrUid, KMenuAttrUndefUid ); |
|
482 TMenuItem undefItem = FindMenuItemL( *filter ); |
|
483 iPluginData->ReplaceMenuItemL( i, undefItem ); |
|
484 iPluginData->SaveSettingsL( i, *FetchMenuItemL(undefItem) ); |
|
485 CleanupStack::PopAndDestroy( filter ); |
|
486 } |
|
487 CleanupStack::PopAndDestroy( menuItem ); |
|
488 menuItem = NULL; |
|
489 } |
|
490 // Notification must be activated again |
|
491 iNotifyWatcher->Cancel(); |
|
492 iNotifier.Notify( 0, |
|
493 RMenuNotifier::EItemsAddedRemoved | |
|
494 RMenuNotifier::EItemsReordered | |
|
495 RMenuNotifier::EItemAttributeChanged, |
|
496 iNotifyWatcher->iStatus ); |
|
497 |
|
498 iNotifyWatcher->WatchNotify( this ); |
|
499 // Publish changed data |
|
500 iPlugin.PublishL(); |
|
501 } |
|
502 |
|
503 // --------------------------------------------------------------------------- |
|
504 // From class MMsvSessionObserver. |
|
505 // Handles an event from the message server. |
|
506 // --------------------------------------------------------------------------- |
|
507 // |
|
508 void CMCSPluginEngine::HandleSessionEventL( |
|
509 TMsvSessionEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
510 { |
|
511 switch ( aEvent ) |
|
512 { |
|
513 case EMsvEntriesDeleted: |
|
514 // fall-through intended here |
|
515 case EMsvEntriesChanged: |
|
516 { |
|
517 |
|
518 } |
|
519 break; |
|
520 default: |
|
521 break; |
|
522 } |
|
523 } |
|
524 |
|
525 // ----------------------------------------------------------------------------- |
|
526 // From class MFavouritesDbObserver. |
|
527 // Handles database event. |
|
528 // ----------------------------------------------------------------------------- |
|
529 // |
|
530 void CMCSPluginEngine::HandleFavouritesDbEventL( RDbNotifier::TEvent aEvent ) |
|
531 { |
|
532 switch ( aEvent ) |
|
533 { |
|
534 case RDbNotifier::ERollback: |
|
535 // fall-through intended here |
|
536 case RDbNotifier::ERecover: |
|
537 // fall-through intended here |
|
538 case RDbNotifier::ECommit: |
|
539 { |
|
540 // Get list of favourites bookmarks |
|
541 CFavouritesItemList* favItems = |
|
542 new (ELeave) CFavouritesItemList(); |
|
543 CleanupStack::PushL( favItems ); |
|
544 TInt err = iBookmarkDb.GetAll( *favItems, KFavouritesNullUid, |
|
545 CFavouritesItem::EItem ); |
|
546 if ( err != KErrNone ) |
|
547 { |
|
548 ASSERT(0); |
|
549 } |
|
550 TInt count_fav = favItems->Count(); |
|
551 |
|
552 // Do for each plugin data (4x times) |
|
553 TInt count_data( iPluginData->DataCount() ); |
|
554 for ( TInt item_index = 0; item_index < count_data; item_index++ ) |
|
555 { |
|
556 // Get item ID and open its menu related item |
|
557 TMCSData& data = iPluginData->DataItemL( item_index ); |
|
558 TInt itemID( data.MenuItem().Id() ); |
|
559 CMenuItem* menuItem = CMenuItem::OpenL( iMenu, itemID ); |
|
560 CleanupStack::PushL( menuItem ); |
|
561 |
|
562 // Get URL aatribute |
|
563 TBool attrExists = EFalse; |
|
564 TPtrC url = menuItem->GetAttributeL( _L("url"), attrExists ); |
|
565 // If bookmark... |
|
566 if ( attrExists ) |
|
567 { |
|
568 // Get bookmark UID |
|
569 TPtrC uid_item_ptr = menuItem->GetAttributeL( |
|
570 KMenuAttrUid, attrExists ); |
|
571 |
|
572 // Compare with each item in fav. bookmarks list |
|
573 TBool itemExists = EFalse; |
|
574 for ( TInt fav_index = count_fav - 1; fav_index >= 0; fav_index-- ) // newest on top |
|
575 { |
|
576 // Get list item UID |
|
577 TUid uid_fav = TUid::Uid( favItems->At( fav_index )->Uid() ); |
|
578 if ( uid_fav.Name() == uid_item_ptr ) |
|
579 { |
|
580 // Bookmark still exist in fav. bookmarks list |
|
581 itemExists = ETrue; |
|
582 break; |
|
583 } |
|
584 } |
|
585 |
|
586 if ( !itemExists ) |
|
587 { |
|
588 // If item not axist any more, replace it by undefined icon |
|
589 CMenuFilter* filter = CMenuFilter::NewL(); |
|
590 CleanupStack::PushL( filter ); |
|
591 // 'Undefined' item |
|
592 filter->HaveAttributeL( KMenuAttrUid, |
|
593 KMenuAttrUndefUid ); |
|
594 TMenuItem undefItem = FindMenuItemL( *filter ); |
|
595 iPluginData->ReplaceMenuItemL( item_index, undefItem ); |
|
596 iPluginData->SaveSettingsL( item_index, *FetchMenuItemL( |
|
597 undefItem ) ); |
|
598 CleanupStack::PopAndDestroy( filter ); |
|
599 } |
|
600 } |
|
601 CleanupStack::PopAndDestroy( menuItem ); |
|
602 } |
|
603 CleanupStack::PopAndDestroy( favItems ); |
|
604 } |
|
605 break; |
|
606 default: |
|
607 break; |
|
608 } |
|
609 } |
|
610 |
|
611 // --------------------------------------------------------------------------- |
|
612 // Resumes the engine |
|
613 // --------------------------------------------------------------------------- |
|
614 // |
|
615 void CMCSPluginEngine::ResumeL() |
|
616 { |
|
617 iSuspend = EFalse; |
|
618 } |
|
619 |
|
620 // --------------------------------------------------------------------------- |
|
621 // Suspends the engine |
|
622 // --------------------------------------------------------------------------- |
|
623 // |
|
624 void CMCSPluginEngine::Suspend() |
|
625 { |
|
626 iSuspend = ETrue; |
|
627 } |
|
628 |
|
629 // --------------------------------------------------------------------------- |
|
630 // Launch General Settings plugin |
|
631 // --------------------------------------------------------------------------- |
|
632 // |
|
633 void CMCSPluginEngine::ShowSettingsL() |
|
634 { |
|
635 TUid uid = {AI_UID_ECOM_IMPLEMENTATION_SETTINGS_MCSPLUGIN}; |
|
636 CGSLauncher* l = CGSLauncher::NewLC(); |
|
637 l->LaunchGSViewL ( uid, |
|
638 KHomescreenUid, |
|
639 iInstanceUid ); |
|
640 CleanupStack::PopAndDestroy( l ); |
|
641 |
|
642 } |
|
643 // --------------------------------------------------------------------------- |
|
644 // ResolveSkinItemId |
|
645 // Syntax: skin(major minor):mif(filename bimapId maskId) |
|
646 // --------------------------------------------------------------------------- |
|
647 // |
|
648 TBool CMCSPluginEngine::ConstructMenuItemForIconL( const TDesC& aPath, CMenuItem& aMenuItem ) |
|
649 { |
|
650 TInt pos = aPath.Locate( ':' ); |
|
651 if( pos == KErrNotFound ) |
|
652 { |
|
653 pos = aPath.Length(); |
|
654 } |
|
655 TPtrC skin = aPath.Left( pos ); |
|
656 TInt sf = skin.FindF( KSkin ); |
|
657 if( sf == KErrNotFound ) |
|
658 { |
|
659 return EFalse; |
|
660 } |
|
661 TPtrC temp = skin.Mid( sf + KSkin().Length()); |
|
662 TLex input( temp ); |
|
663 input.SkipSpace(); |
|
664 if( !input.Eos() && input.Peek() == '(') |
|
665 { |
|
666 input.Inc(); |
|
667 } |
|
668 TPtrC majorId = NextIdToken( input ); |
|
669 TPtrC minorId = NextIdToken( input ); |
|
670 aMenuItem.SetAttributeL( KMenuAttrIconSkinMajorId, majorId ); |
|
671 aMenuItem.SetAttributeL( KMenuAttrIconSkinMinorId, minorId ); |
|
672 |
|
673 //TPtrC mif = aPath.Mid( pos + 1 ); |
|
674 //TInt mf = mif.FindF( KMif ); |
|
675 if( aPath.Length() > pos && (aPath.Mid( pos + 1 ).FindF( KMif ) != KErrNotFound )) |
|
676 { |
|
677 TPtrC mif = aPath.Mid( pos + 1 ); |
|
678 TInt mf = mif.FindF( KMif ); |
|
679 //TPtrC temp1 = mif.Mid( mf+ KMif().Length()); |
|
680 TLex input1( mif.Mid( mf+ KMif().Length()) ); |
|
681 input1.SkipSpace(); |
|
682 if( !input1.Eos() && input1.Peek() == '(') |
|
683 { |
|
684 input1.Inc(); |
|
685 } |
|
686 TPtrC file = NextIdToken( input1 ); |
|
687 TPtrC bitmapId = NextIdToken( input1 ); |
|
688 TPtrC maskId = NextIdToken( input1 ); |
|
689 aMenuItem.SetAttributeL( KMenuAttrIconFile, file ); |
|
690 aMenuItem.SetAttributeL( KMenuAttrIconId, bitmapId ); |
|
691 aMenuItem.SetAttributeL( KMenuAttrMaskId, maskId ); |
|
692 } |
|
693 return ETrue; |
|
694 } |
|
695 |
|
696 // --------------------------------------------------------------------------- |
|
697 // Called during plugin desctruction |
|
698 // Decrements reference counters of all run-time generated items |
|
699 // and deletes those which have reference counter == 0 |
|
700 // --------------------------------------------------------------------------- |
|
701 // |
|
702 void CMCSPluginEngine::CleanMCSItemsL() |
|
703 { |
|
704 const TInt count( iPluginData->DataCount() ); |
|
705 for( TInt i = 0; i < count; i++ ) |
|
706 { |
|
707 TMCSData& data = iPluginData->DataItemL(i); |
|
708 |
|
709 CMenuItem* menuItem = CMenuItem::OpenL( iMenu, data.MenuItem().Id() ); |
|
710 if( !menuItem ) |
|
711 { |
|
712 continue; |
|
713 } |
|
714 CleanupStack::PushL( menuItem ); |
|
715 |
|
716 // check if ref_count attribute exists |
|
717 TBool exists = EFalse; |
|
718 TPtrC param = menuItem->GetAttributeL( KMenuAttrRefcount, exists ); |
|
719 if( exists ) |
|
720 { |
|
721 const TInt references = UpdateMenuItemsRefCountL( menuItem, -1 ); |
|
722 |
|
723 // Create a nested loop inside CActiveScheduler. |
|
724 CActiveSchedulerWait* wait = new (ELeave) CActiveSchedulerWait; |
|
725 CleanupStack::PushL( wait ); |
|
726 |
|
727 if( references > 0 ) |
|
728 { |
|
729 // if counter is still > 0, update its value in MCS |
|
730 CMenuOperation* op = menuItem->SaveL( iWatcher->iStatus ); |
|
731 iWatcher->StopAndWatch( op, wait ); |
|
732 |
|
733 // Start the nested scheduler loop. |
|
734 wait->Start(); |
|
735 } |
|
736 else |
|
737 { |
|
738 // counter reached 0 -> item is not referenced by any shortcut |
|
739 // so remove it from MCS |
|
740 if( !iWatcher->IsActive() ) |
|
741 { |
|
742 CMenuOperation* op = iMenu.RemoveL( menuItem->Id(), iWatcher->iStatus ); |
|
743 iWatcher->StopAndWatch( op, wait ); |
|
744 |
|
745 // Start the nested scheduler loop. |
|
746 wait->Start(); |
|
747 } |
|
748 } |
|
749 |
|
750 CleanupStack::PopAndDestroy( wait ); |
|
751 wait = NULL; |
|
752 } |
|
753 |
|
754 CleanupStack::PopAndDestroy( menuItem ); |
|
755 menuItem = NULL; |
|
756 } |
|
757 } |
|
758 |
|
759 |
|
760 // --------------------------------------------------------------------------- |
|
761 // Helper method. Adds a given constant to a value of reference counter |
|
762 // --------------------------------------------------------------------------- |
|
763 // |
|
764 TInt CMCSPluginEngine::UpdateMenuItemsRefCountL( CMenuItem* aItem, |
|
765 const TInt aValueToAdd ) |
|
766 { |
|
767 TBool exists = EFalse; |
|
768 CleanupStack::PushL( aItem ); |
|
769 TPtrC param = aItem->GetAttributeL( KMenuAttrRefcount, exists ); |
|
770 CleanupStack::Pop( aItem ); |
|
771 if ( exists ) |
|
772 { |
|
773 TInt references; |
|
774 TLex16 lextmp( param ); |
|
775 lextmp.Val( references ); |
|
776 references += aValueToAdd; |
|
777 TBuf<128> buf; |
|
778 buf.NumUC( references ); |
|
779 |
|
780 // set new ref_count |
|
781 CleanupStack::PushL( aItem ); |
|
782 aItem->SetAttributeL( KMenuAttrRefcount, buf); |
|
783 CleanupStack::Pop( aItem ); |
|
784 // return new ref_count |
|
785 return references; |
|
786 } |
|
787 return -1; |
|
788 } |