idlefw/plugins/shortcutplugin/src/caiscutshortcut.cpp
branchRCL_3
changeset 9 d0529222e3f0
parent 4 1a2a00e78665
child 10 5ef93ea513cb
child 18 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 9:d0529222e3f0
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Implementation for a shortcut.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aicontentobserver.h>
       
    20 #include <gulicon.h>            // For CGulIcon
       
    21 #include <fbs.h>                // For CFbsBitmap
       
    22 #include <e32property.h>            // For RProperty
       
    23 
       
    24 #include <activeidle2domainpskeys.h>
       
    25 #include "aiscutcontentmodel.h"
       
    26 #include "caiscutshortcut.h"
       
    27 #include "aiscutdefs.h"
       
    28 #include "caiscuttargetapp.h"
       
    29 #include "caiscuttargetbkm.h"
       
    30 #include "caiscuttargethttp.h"
       
    31 #include "caiscuttargetmessagingview.h"
       
    32 #include "caiscuttargetnewmsg.h"
       
    33 #include "caiscuttargetkeylock.h"
       
    34 #include "caiscuttargetempty.h"
       
    35 #include "aiscutpluginprivatecrkeys.h"
       
    36 
       
    37 #include "debug.h"
       
    38 
       
    39 
       
    40 // ======== MEMBER FUNCTIONS ========
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CAiScutShortcut::CAiScutShortcut(TInt aId, CAiScutEngine& aEngine)
       
    47 	: CTimer( CActive::EPriorityLow )
       
    48 	, iId(aId)
       
    49     , iEngine(aEngine)
       
    50 {
       
    51 }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CAiScutShortcut::ConstructL(const TDesC& aTarget)
       
    58 {
       
    59     iDefaultTarget = CreateTargetL(aTarget, EFalse);
       
    60 
       
    61     if (!iDefaultTarget)
       
    62     {
       
    63         iDefaultTarget = CAiScutTargetEmpty::NewL(iEngine, EScutUnknown, aTarget);
       
    64     }
       
    65     CTimer::ConstructL();
       
    66     CActiveScheduler::Add( this );
       
    67 }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CAiScutShortcut* CAiScutShortcut::NewLC(TInt aId, const TDesC& aTarget,
       
    74     CAiScutEngine& aEngine)
       
    75 {
       
    76     CAiScutShortcut* self = new (ELeave) CAiScutShortcut(aId, aEngine);
       
    77     CleanupStack::PushL(self);
       
    78     self->ConstructL(aTarget);
       
    79     return self;
       
    80 }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CAiScutShortcut* CAiScutShortcut::NewL(TInt aId, const TDesC& aTarget,
       
    87     CAiScutEngine& aEngine)
       
    88 {
       
    89     CAiScutShortcut* self = CAiScutShortcut::NewLC(aId, aTarget, aEngine);
       
    90     CleanupStack::Pop(self);
       
    91     return self;
       
    92 }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CAiScutShortcut::~CAiScutShortcut()
       
    99 {
       
   100 	Cancel();
       
   101     delete iDefaultTarget;
       
   102     delete iUserTarget;
       
   103     delete iRetiredTarget;
       
   104 }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // Returns the shortcut id.
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 TInt32 CAiScutShortcut::Id() const
       
   111 {
       
   112     return iId;
       
   113 }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // Publishes the shortcut content, non leaving version.
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CAiScutShortcut::Publish(
       
   120     MAiPropertyExtension& aPlugin, MAiContentObserver& aObserver)
       
   121 {
       
   122     TRAPD(err, PublishL(aPlugin, aObserver));
       
   123     //Possible forcing done already so reset the flag
       
   124     iForcePublish = EFalse;
       
   125     if (err == KErrNone)
       
   126     {
       
   127         delete iRetiredTarget;
       
   128         iRetiredTarget = NULL;
       
   129         iLastPublishedTarget = iActiveTarget;
       
   130     }
       
   131     else
       
   132     {
       
   133         // Publish failed, roll back to previous content.
       
   134         TInt transactionId = reinterpret_cast<TInt>(this);
       
   135         aObserver.CancelTransaction(transactionId);
       
   136 
       
   137         // Delete the new target and put the retired one back to work.
       
   138         if (iRetiredTarget)
       
   139         {
       
   140             delete iUserTarget;
       
   141             iUserTarget = iRetiredTarget;
       
   142             iRetiredTarget = NULL;
       
   143         }
       
   144 
       
   145         iActiveTarget = iLastPublishedTarget;
       
   146     }
       
   147 
       
   148     
       
   149 }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // Checks if the application or messaging view pointed to can be launched.
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 TBool CAiScutShortcut::CheckAccessL(TInt aCheckType)
       
   156 {
       
   157     TBool userTargetAccessible = EFalse;
       
   158 
       
   159 	__PRINT( __DBG_FORMAT( "XAI: CAiScutShortcut::CheckAccessL( %d )"), aCheckType);
       
   160 
       
   161     // First try the user setting if it is defined.
       
   162     if (iUserTarget && iUserTarget->IsAccessibleL(aCheckType))
       
   163     {
       
   164         iActiveTarget = iUserTarget;
       
   165         userTargetAccessible = ETrue;
       
   166     }
       
   167 
       
   168     if (!userTargetAccessible)
       
   169     {
       
   170 
       
   171 		__PRINTS("XAI:   *** user target NOT accessible ***");
       
   172         // User setting was not accessible or not defined, try the default.
       
   173         if (iDefaultTarget->IsAccessibleL(aCheckType))
       
   174         {
       
   175             iActiveTarget = iDefaultTarget;
       
   176         }
       
   177         else
       
   178         {
       
   179             // The default is not accessible either, the shortcut is empty.
       
   180             iActiveTarget = NULL;
       
   181 
       
   182 			__PRINTS( "XAI:   *** default target NOT accessible ***");
       
   183         }
       
   184     }
       
   185 
       
   186     if (iActiveTarget)
       
   187 	{
       
   188 		return ETrue;
       
   189 	}
       
   190 	else
       
   191 	{
       
   192 		return EFalse;
       
   193 	}    
       
   194 }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TBool CAiScutShortcut::IsTargetChanged() const
       
   201 {
       
   202     // We need to publish if target changed during access checking.
       
   203     return (iLastPublishedTarget != iActiveTarget);
       
   204 }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // Changes the shortcut target to the user defined setting.
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CAiScutShortcut::SetUserTarget(const TDesC& aNewTarget)
       
   211 {
       
   212 
       
   213 	TPtrC defaultTarget(iDefaultTarget->Definition());
       
   214 	__PRINTS( "XAI: CAiScutShortcut::SetUserTarget");
       
   215 	__PRINT( __DBG_FORMAT( "XAI:   id             = 0x%x"), iId);
       
   216 	__PRINT( __DBG_FORMAT( "XAI:   default target = '%S'"),   &defaultTarget);
       
   217 	__PRINT( __DBG_FORMAT("XAI:   new target     = '%S'"),   &aNewTarget);
       
   218 	if (iUserTarget)
       
   219 		{
       
   220 		TPtrC userTarget(iUserTarget->Definition());
       
   221 		__PRINT( __DBG_FORMAT("XAI:   user target    = '%S'"),   &userTarget);
       
   222 		}
       
   223 		
       
   224 	
       
   225     if (iUserTarget && (aNewTarget.CompareC(iUserTarget->Definition()) == 0))
       
   226     {
       
   227         return;
       
   228     }
       
   229 
       
   230 
       
   231     // Creating the new target might leave, so it is done before the old target
       
   232     // is deleted to ensure that the shortcut object remains in a consistent state
       
   233     // in case of a leave. If target creation leaves, nothing has changed.
       
   234     //
       
   235     // As a side effect this means that the new target is allocated to a different
       
   236     // memory address than the old one, the address of the old target will not be re-used
       
   237     // by this target. That doesn't mean anything for the plug-in, but it helps the
       
   238     // plug-in tester to notice premature target deletion, since the address will still
       
   239     // contain 0xDEDEDEDE instead of the new target.
       
   240     CAiScutTarget* tempTarget = NULL;
       
   241 
       
   242     TRAPD(err, tempTarget = CreateTargetL(aNewTarget, ETrue));
       
   243 
       
   244     if (err == KErrNone)
       
   245     {
       
   246         DeleteUserTarget();
       
   247         iUserTarget = tempTarget;
       
   248     }
       
   249 }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // Deletes the user target.
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CAiScutShortcut::DeleteUserTarget()
       
   256 {
       
   257     if (iUserTarget)
       
   258     {
       
   259 
       
   260 		__PRINTS("XAI: CAiScutShortcut::DeleteUserTarget");
       
   261 
       
   262         if (iLastPublishedTarget == iUserTarget && !(iId & KScutFlagBitNonVisible))
       
   263         {
       
   264             // Previous user target was the last published target so the Ai framework
       
   265             // is still using the icon pointer. Deleting the target now would cause a
       
   266             // KERN-EXEC 3 panic when the framework tries to access the deleted icon.
       
   267             // The target must be kept alive until the new target has been successfully
       
   268             // published and the framework is no longer using its icon.
       
   269             // This is unnecessary for non-visible shortcuts because they are not published.
       
   270             iRetiredTarget = iUserTarget;
       
   271             iUserTarget = NULL;
       
   272 
       
   273 			__PRINTS("XAI:   iUserTarget = NULL");
       
   274 
       
   275         }
       
   276 
       
   277         if (iActiveTarget == iUserTarget)
       
   278         {
       
   279             // Previous user target was the active target. We don't know if the new
       
   280             // user target is accessible, so the shortcut is effectively empty until
       
   281             // the access check has been run.
       
   282             iActiveTarget = NULL;
       
   283         }
       
   284 
       
   285         delete iUserTarget;
       
   286         iUserTarget = NULL;
       
   287 
       
   288 		__PRINTS( "XAI:   delete iUserTarget");
       
   289     }
       
   290 }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // Launches the shortcut.
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 void CAiScutShortcut::LaunchL()
       
   297 {
       
   298 	Cancel();
       
   299 	RProperty::Set( 
       
   300         KPSUidAiInformation, 
       
   301         KActiveIdleLaunch, 
       
   302         EPSAiLaunchIsActive );
       
   303 
       
   304     if (iActiveTarget)
       
   305     {
       
   306     	TRAP_IGNORE( iActiveTarget->BeginEffectL() ); //start a full screen effect
       
   307         iActiveTarget->LaunchL();
       
   308     }
       
   309   
       
   310     // When preparing for backup, the plugin is suspended and calling After() would
       
   311     // cause a crash
       
   312     if ( IsAdded() )
       
   313     {	
       
   314     	After(1000000);
       
   315     }
       
   316 }
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // Launches the shortcut.
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CAiScutShortcut::LaunchL(const TDesC8& aMessage)
       
   323 {
       
   324 	Cancel();
       
   325 	RProperty::Set( 
       
   326         KPSUidAiInformation, 
       
   327         KActiveIdleLaunch, 
       
   328         EPSAiLaunchIsActive );
       
   329 
       
   330     if (iActiveTarget)
       
   331     {
       
   332     	TRAP_IGNORE( iActiveTarget->BeginEffectL() ); //start a full screen effect
       
   333         iActiveTarget->LaunchL(aMessage);
       
   334     }
       
   335   
       
   336     // When preparing for backup, the plugin is suspended and calling After() would
       
   337     // cause a crash
       
   338     if ( IsAdded() )
       
   339     {	
       
   340     	After(1000000);
       
   341     }
       
   342 }
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 void CAiScutShortcut::SetToBePublished(TBool aFlag)
       
   349 {
       
   350     if ( !iForcePublish )
       
   351         {
       
   352         iNeedsToBePublished = aFlag;                
       
   353         }
       
   354     else
       
   355         {
       
   356         iNeedsToBePublished = iForcePublish;
       
   357         }
       
   358 }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 TBool CAiScutShortcut::NeedsToBePublished()
       
   365 {
       
   366     return iNeedsToBePublished;
       
   367 }
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // Return shortcut type.
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 TShortcutType CAiScutShortcut::Type() const
       
   374 {
       
   375     if (iUserTarget)
       
   376     {
       
   377         return iUserTarget->Type();
       
   378     }
       
   379     else
       
   380     {
       
   381         return iDefaultTarget->Type();
       
   382     }
       
   383 }
       
   384 
       
   385 // ---------------------------------------------------------------------------
       
   386 // Return application uid of this shortcut.
       
   387 // ---------------------------------------------------------------------------
       
   388 //
       
   389 TUid CAiScutShortcut::AppUid() const
       
   390 {
       
   391     if (iUserTarget)
       
   392     {
       
   393         return iUserTarget->AppUid();
       
   394     }
       
   395     else
       
   396     {
       
   397         return iDefaultTarget->AppUid();
       
   398     }
       
   399 }
       
   400 void CAiScutShortcut::SetIcon(TAiScutIcon aIcon)
       
   401     {
       
   402     switch(aIcon.iDestination)
       
   403         {      
       
   404         case EScutDestinationSoftkey:
       
   405             SetSoftkeyIcon(aIcon);
       
   406             break;
       
   407         case EScutDestinationToolbar:
       
   408             SetToolbarIcon(aIcon);
       
   409             break;
       
   410         case EScutDestinationNormal:
       
   411             SetOverrideIcon(aIcon);
       
   412             break;
       
   413         default:
       
   414             break;
       
   415         }
       
   416     }
       
   417 void CAiScutShortcut::SetOverrideIcon(TAiScutIcon aIcon)
       
   418 {   
       
   419     if (iUserTarget)
       
   420     {
       
   421         iUserTarget->SetOverrideIcon(aIcon);
       
   422     }
       
   423     else
       
   424     {
       
   425         iDefaultTarget->SetOverrideIcon(aIcon);
       
   426     }
       
   427 }
       
   428 
       
   429 void CAiScutShortcut::SetSoftkeyIcon(TAiScutIcon aIcon)
       
   430 {   
       
   431     if (iUserTarget)
       
   432     {
       
   433         iUserTarget->SetSoftkeyIcon(aIcon);
       
   434     }
       
   435     else
       
   436     {
       
   437         iDefaultTarget->SetSoftkeyIcon(aIcon);
       
   438     }
       
   439 }
       
   440 
       
   441 
       
   442 void CAiScutShortcut::SetToolbarIcon(TAiScutIcon aIcon)
       
   443 {   
       
   444     if (iUserTarget)
       
   445     {
       
   446         iUserTarget->SetToolbarIcon(aIcon);
       
   447     }
       
   448     else
       
   449     {
       
   450         iDefaultTarget->SetToolbarIcon(aIcon);
       
   451     }
       
   452 }
       
   453 
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // Creates a shortcut target object.
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459 CAiScutTarget* CAiScutShortcut::CreateTargetL(
       
   460     const TDesC& aDefinition, TBool aCreateUserTarget)
       
   461 {
       
   462 
       
   463 	__PRINTS("XAI: CAiScutShortcut::CreateTargetL");
       
   464 	__PRINT( __DBG_FORMAT("XAI:   id = 0x%x, target = '%S'"), iId, &aDefinition);
       
   465 
       
   466     CAiScutTarget* target = NULL;
       
   467     TAiScutParser parser;
       
   468     TInt err = parser.Parse(aDefinition);
       
   469 
       
   470     if (parser.IsValid())
       
   471     {
       
   472         TShortcutType type = parser.Type();
       
   473         
       
   474         switch (type)
       
   475         {
       
   476         case EScutApplication:
       
   477         case EScutChangeTheme:
       
   478         case EScutApplicationView:
       
   479         case EScutApplicationWithParams:
       
   480         case EScutLogsMissedCallsView:
       
   481         case EScutLogsDialledCallsView:
       
   482         case EScutLogsReceivedCallsView:
       
   483         case EScutLogsMainView:
       
   484             target = CAiScutTargetApp::NewL(iEngine, type, parser);
       
   485             break;
       
   486 
       
   487         case EScutNewMsgType:
       
   488         case EScutNewMessage:
       
   489         case EScutNewEmail:
       
   490 #ifdef __SYNCML_DS_EMAIL
       
   491         case EScutNewSyncMLMail:
       
   492 #endif
       
   493         case EScutNewPostcard:
       
   494         case EScutNewAudioMsg:
       
   495             target = CAiScutTargetNewMsg::NewL(iEngine, type, parser);
       
   496             break;
       
   497 
       
   498         case EScutMailbox:
       
   499             target = CAiScutTargetMessagingView::NewL(iEngine, type, parser);
       
   500             break;
       
   501 
       
   502         case EScutWebAddress:
       
   503             target = CAiScutTargetHttp::NewL(iEngine, type, parser);
       
   504             break;
       
   505 
       
   506         case EScutKeylock:
       
   507             target = CAiScutTargetKeyLock::NewL(iEngine, type, aDefinition);
       
   508             break;
       
   509 
       
   510         case EScutNoEffect:
       
   511             target = CAiScutTargetEmpty::NewL(iEngine, type, aDefinition);
       
   512             break;
       
   513 
       
   514         case EScutBookmark:
       
   515             target = CAiScutTargetBkm::NewL(iEngine, type, parser);
       
   516             break;
       
   517 
       
   518         case EScutConnectivityStatusView:
       
   519             target = CAiScutTargetApp::NewL(iEngine, EScutApplicationView, parser);
       
   520             break;
       
   521 
       
   522         case EScutApplicationManagerView:
       
   523             target = CAiScutTargetApp::NewL(iEngine, EScutApplicationView, parser);
       
   524             break;
       
   525 
       
   526         default:
       
   527             break;
       
   528         }
       
   529     }
       
   530 
       
   531     if (!target && aCreateUserTarget)
       
   532     {
       
   533         // treat unknown user targets as web addresses.
       
   534         target = CAiScutTargetHttp::NewL(iEngine, EScutWebAddress, parser);
       
   535     }
       
   536 
       
   537     if (!target)
       
   538     {
       
   539 		__PRINTS( "XAI:   *** empty target ***");
       
   540     }
       
   541     
       
   542     
       
   543     return target;
       
   544 }
       
   545 
       
   546 // -----------------------------------------------------------------------------
       
   547 // Publishes the shortcut content, leaving version.
       
   548 // -----------------------------------------------------------------------------
       
   549 //
       
   550 void CAiScutShortcut::PublishL(
       
   551     MAiPropertyExtension& aPlugin, MAiContentObserver& aObserver)
       
   552     {
       
   553     TInt err = KErrNone;
       
   554     TBool cbaIconPublished = EFalse;
       
   555 
       
   556 	__PRINT( __DBG_FORMAT("XAI: CAiScutShortcut::PublishL 0x%x"), iId);
       
   557 
       
   558     // Publish caption if the framework can handle it.
       
   559     if (!aObserver.CanPublish(
       
   560         aPlugin, KAiScutContent[EAiScutContentShortcutCaption].id, iId))
       
   561         {
       
   562         err = KErrNotSupported;
       
   563         }
       
   564     else
       
   565         {
       
   566         err = PublishCaption(
       
   567             aPlugin, aObserver, KAiScutContent[EAiScutContentShortcutCaption].id);
       
   568 
       
   569         if (err != KErrNone)
       
   570         	__PRINT( __DBG_FORMAT( "XAI:   publish caption err = %d"), err);
       
   571         }
       
   572 
       
   573     // Publish short caption if the framework can handle it.
       
   574     if (!aObserver.CanPublish(
       
   575         aPlugin, KAiScutContent[EAiScutContentShortcutShortCaption].id, iId))
       
   576         {
       
   577         err = KErrNotSupported;
       
   578         }
       
   579     else
       
   580         {
       
   581         err = PublishCaption(
       
   582             aPlugin, aObserver, KAiScutContent[EAiScutContentShortcutShortCaption].id);
       
   583 
       
   584         if (err != KErrNone)
       
   585 	        __PRINT( __DBG_FORMAT( "XAI:   publish short caption err = %d"), err);
       
   586         }
       
   587 
       
   588     /** softkeys **/
       
   589       // Publish short caption if the framework can handle it.
       
   590     if (!aObserver.CanPublish(
       
   591         aPlugin, KAiScutContent[EAiScutContentShortcutSkIcon].id, iId))
       
   592         {
       
   593         err = KErrNotSupported;
       
   594         }
       
   595     else
       
   596         {
       
   597         err = PublishIcon(
       
   598             aPlugin, aObserver, KAiScutContent[EAiScutContentShortcutSkIcon].id);
       
   599         
       
   600         if ( err == KErrNone )
       
   601             {
       
   602             cbaIconPublished = ETrue;
       
   603             }
       
   604         if (err != KErrNone) 
       
   605         	__PRINT( __DBG_FORMAT("XAI:   publish icon err = %d"), err);
       
   606         }
       
   607     
       
   608     // No CBA icon published so publish the caption
       
   609     if ( !cbaIconPublished )
       
   610         {        
       
   611         // Publish sk caption if the framework can handle it.
       
   612         if (!aObserver.CanPublish(
       
   613             aPlugin, KAiScutContent[EAiScutContentShortcutSkCaption].id, iId))
       
   614             {
       
   615             err = KErrNotSupported;
       
   616             }
       
   617         else
       
   618             {
       
   619             err = PublishCaption(
       
   620                 aPlugin, aObserver, KAiScutContent[EAiScutContentShortcutSkCaption].id);
       
   621 
       
   622             if (err != KErrNone)
       
   623     	        __PRINT( __DBG_FORMAT( "XAI:   publish short caption err = %d"), err);
       
   624             }
       
   625         }
       
   626     
       
   627     /** end of softkeys **/
       
   628     
       
   629     // Publish MSK caption if the framework can handle it.
       
   630     if (!aObserver.CanPublish(
       
   631         aPlugin, KAiScutContent[EAiScutContentShortcutMskCaption].id, iId))
       
   632         {
       
   633         err = KErrNotSupported;
       
   634         }
       
   635     else
       
   636         {
       
   637         err = PublishCaption(
       
   638             aPlugin, aObserver, KAiScutContent[EAiScutContentShortcutMskCaption].id);
       
   639 
       
   640         if (err != KErrNone)
       
   641         	__PRINT( __DBG_FORMAT( "XAI:   publish msk caption err = %d"), err);
       
   642         }
       
   643 
       
   644     // Publish icon if the framework can handle it.
       
   645     if (!aObserver.CanPublish(
       
   646         aPlugin, KAiScutContent[EAiScutContentShortcutIcon].id, iId))
       
   647         {
       
   648         err = KErrNotSupported;
       
   649         }
       
   650     else
       
   651         {
       
   652         err = PublishIcon(
       
   653             aPlugin, aObserver, KAiScutContent[EAiScutContentShortcutIcon].id);
       
   654 
       
   655         if (err != KErrNone) 
       
   656         	__PRINT( __DBG_FORMAT("XAI:   publish icon err = %d"), err);
       
   657         }
       
   658 
       
   659     // Publish toolbar caption if the framework can handle it.
       
   660     if (!aObserver.CanPublish(
       
   661         aPlugin, KAiScutContent[EAiScutContentShortcutToolbarCaption].id, iId))
       
   662         {
       
   663         err = KErrNotSupported;
       
   664         }
       
   665     else
       
   666         {
       
   667         err = PublishCaption(
       
   668             aPlugin, aObserver, KAiScutContent[EAiScutContentShortcutToolbarCaption].id);
       
   669 
       
   670         if (err != KErrNone)
       
   671         	__PRINT( __DBG_FORMAT( "XAI:   publish toolbar caption err = %d"), err);
       
   672         }
       
   673 
       
   674     // Publish the toolbar icon if the framework can handle it    
       
   675     if (!aObserver.CanPublish(
       
   676         aPlugin, KAiScutContent[EAiScutContentShortcutToolbarIcon].id, iId))
       
   677         {
       
   678         err = KErrNotSupported;
       
   679         }
       
   680     else
       
   681         {
       
   682         err = PublishIcon(
       
   683             aPlugin, aObserver, KAiScutContent[EAiScutContentShortcutToolbarIcon].id);
       
   684         
       
   685         if (err != KErrNone) 
       
   686         	__PRINT( __DBG_FORMAT("XAI:   publish toolbar icon err = %d"), err);
       
   687         }
       
   688     }
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // Publishes shortcut caption.
       
   692 // -----------------------------------------------------------------------------
       
   693 //
       
   694 TInt CAiScutShortcut::PublishCaption(MAiPropertyExtension& aPlugin,
       
   695     MAiContentObserver& aObserver, TInt aCaptionContentId) const
       
   696 {
       
   697     TInt err = KErrNone;
       
   698 
       
   699     if (iId == KRightSoftkeyId)
       
   700     {
       
   701         if (iActiveCall)
       
   702         {
       
   703             TInt backCaptionResId = KAiScutResources[EAiScutResourceBackCaption].id;
       
   704             err = aObserver.Publish(aPlugin, aCaptionContentId, backCaptionResId, iId);
       
   705             return err;
       
   706         }
       
   707     }
       
   708 
       
   709     if (!iActiveTarget)
       
   710     {
       
   711         // Publish the EmptyCaption resource id.
       
   712         TInt emptyCaptionResId = KAiScutResources[EAiScutResourceEmptyCaption].id;
       
   713         err = aObserver.Publish(aPlugin, aCaptionContentId, emptyCaptionResId, iId);
       
   714     }
       
   715     else
       
   716     {
       
   717         TPtrC captionDes;
       
   718         TInt captionResId = 0;
       
   719         TAiScutAppTitleType titleType = EAiScutLongTitle;
       
   720         if (aCaptionContentId == KAiScutContent[EAiScutContentShortcutShortCaption].id ||
       
   721             aCaptionContentId == KAiScutContent[EAiScutContentShortcutSkCaption].id || 
       
   722             aCaptionContentId == KAiScutContent[EAiScutContentShortcutToolbarCaption].id)
       
   723         {
       
   724             titleType = EAiScutSkeyTitle;
       
   725         }
       
   726         else if (aCaptionContentId == KAiScutContent[EAiScutContentShortcutMskCaption].id)
       
   727         {
       
   728             titleType = EAiScutMskTitle;
       
   729         }
       
   730 
       
   731         captionResId = iActiveTarget->GetCaption(captionDes, titleType);
       
   732 
       
   733         if (captionResId == 0)
       
   734         {
       
   735             // Publish descriptor.
       
   736             err = aObserver.Publish(aPlugin, aCaptionContentId, captionDes, iId);
       
   737         }
       
   738         else if (captionResId > 0)
       
   739         {
       
   740             // Publish resource.
       
   741             err = aObserver.Publish(aPlugin, aCaptionContentId, captionResId, iId);
       
   742             
       
   743             __PRINT( __DBG_FORMAT("XAI:   publish resource = %d"), captionResId);
       
   744         }
       
   745     }
       
   746 
       
   747     return err;
       
   748 }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // Publishes shortcut icon.
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 TInt CAiScutShortcut::PublishIcon(MAiPropertyExtension& aPlugin,
       
   755     MAiContentObserver& aObserver, TInt aIconContentId )
       
   756 {
       
   757     TInt emptyIconResId = KAiScutResources[EAiScutResourceEmptyIcon].id;
       
   758     TInt err = KErrNone;
       
   759     // In case of an active call cancel the SK icon publication
       
   760     // to RSK
       
   761     if ( iActiveCall && iId == KRightSoftkeyId )
       
   762         {
       
   763         return KErrCancel;
       
   764         }
       
   765     if (!iActiveTarget)
       
   766     {
       
   767         // Publish the EmptyIcon resource id.
       
   768 
       
   769         __PRINT( __DBG_FORMAT( "XAI: PublishIcon publish empty #1 = %d"), emptyIconResId);
       
   770 
       
   771         err = aObserver.Publish(aPlugin, aIconContentId, emptyIconResId, iId);
       
   772     }
       
   773     else
       
   774     {
       
   775         CGulIcon* iconPtr = NULL;
       
   776         TInt iconResId = 0;
       
   777         //  Normal icon
       
   778         if (aIconContentId == KAiScutContent[EAiScutContentShortcutIcon].id)
       
   779             {
       
   780             iconResId = iActiveTarget->GetIcon(iconPtr);
       
   781             }
       
   782         // Soft key icon
       
   783         else if ( aIconContentId == KAiScutContent[EAiScutContentShortcutSkIcon].id )
       
   784             {
       
   785             iconResId = iActiveTarget->GetSoftkeyIcon(iconPtr);
       
   786             }
       
   787         else if ( aIconContentId == KAiScutContent[EAiScutContentShortcutToolbarIcon].id )
       
   788             {
       
   789             iconResId = iActiveTarget->GetToolbarIcon(iconPtr);            
       
   790             }
       
   791 
       
   792         // No error, continue with the publish
       
   793         if (iconResId == 0)
       
   794         {
       
   795             if (iconPtr)
       
   796             {
       
   797                 // Publish pointer.
       
   798                 err = aObserver.PublishPtr(aPlugin, aIconContentId, iconPtr, iId);
       
   799                     
       
   800                 if( err != KErrNone )
       
   801                     {
       
   802                     delete iconPtr;
       
   803                     }
       
   804             }
       
   805             else
       
   806             {
       
   807                 // The target hasn't been able to initialize its icon, publish the empty icon.
       
   808 
       
   809                 __PRINT( __DBG_FORMAT("XAI: PublishIcon publish empty #2 = %d"), emptyIconResId);
       
   810 
       
   811                 err = aObserver.Publish(aPlugin, aIconContentId, emptyIconResId, iId);
       
   812             }
       
   813         }
       
   814         // Publish by resource
       
   815         else if (iconResId > 0)
       
   816         {
       
   817             // Publish resource.
       
   818 
       
   819             __PRINT( __DBG_FORMAT("XAI: PublishIcon publish resource = %d"), iconResId);
       
   820 
       
   821             err = aObserver.Publish(aPlugin, aIconContentId, iconResId, iId);
       
   822         }
       
   823         // < 0 error occurred, return it
       
   824         else
       
   825             {
       
   826             err = iconResId;
       
   827             }
       
   828     }
       
   829 
       
   830     return err;
       
   831 }
       
   832 
       
   833 // -----------------------------------------------------------------------------
       
   834 // Set call state
       
   835 // -----------------------------------------------------------------------------
       
   836 //
       
   837 void CAiScutShortcut::SetCallState(TBool aStatus)
       
   838 {
       
   839     // Call state changed force the publish of RSK    
       
   840     if ( iActiveCall != aStatus )
       
   841         {
       
   842         if ( iId == KRightSoftkeyId )
       
   843             {
       
   844             iForcePublish = ETrue;
       
   845             }
       
   846         }
       
   847     iActiveCall = aStatus;
       
   848 }
       
   849 
       
   850 TPtrC CAiScutShortcut::ActiveDefinition()
       
   851     {
       
   852     if( iUserTarget )
       
   853         {
       
   854         return iUserTarget->Definition();
       
   855         }
       
   856     if( iDefaultTarget )
       
   857         {
       
   858         return iDefaultTarget->Definition();
       
   859         }
       
   860     return TPtrC();
       
   861     }
       
   862     
       
   863 // ---------------------------------------------------------------------------
       
   864 // Return the possible additional id
       
   865 // ---------------------------------------------------------------------------
       
   866 //    
       
   867 TUid CAiScutShortcut::AdditionalUid() const
       
   868     {
       
   869     if( iUserTarget )
       
   870         {
       
   871         return iUserTarget->AdditionalUid();
       
   872         }
       
   873     if( iDefaultTarget )
       
   874         {
       
   875         return iDefaultTarget->AdditionalUid();
       
   876         }
       
   877     return TUid::Uid(-1);
       
   878     }
       
   879 
       
   880 // ---------------------------------------------------------------------------
       
   881 // CActive
       
   882 // ---------------------------------------------------------------------------
       
   883 //   
       
   884 TInt CAiScutShortcut::RunError(TInt /*aError*/)
       
   885     {
       
   886     return KErrNone;
       
   887     }
       
   888 
       
   889 // ---------------------------------------------------------------------------
       
   890 // CActive
       
   891 // ---------------------------------------------------------------------------
       
   892 //   
       
   893 void CAiScutShortcut::DoCancel()
       
   894     {
       
   895     CTimer::DoCancel();
       
   896     RProperty::Set( 
       
   897         KPSUidAiInformation, 
       
   898         KActiveIdleLaunch, 
       
   899         EPSAiLaunchNotActive );
       
   900     }
       
   901 
       
   902 // ---------------------------------------------------------------------------
       
   903 // CActive
       
   904 // ---------------------------------------------------------------------------
       
   905 //
       
   906 void CAiScutShortcut::RunL()
       
   907     {
       
   908     RProperty::Set( 
       
   909         KPSUidAiInformation, 
       
   910         KActiveIdleLaunch, 
       
   911         EPSAiLaunchNotActive );
       
   912     }
       
   913 // End of File.