idlefw/plugins/shortcutplugin/src/caiscutextsession.cpp
branchRCL_3
changeset 8 d0529222e3f0
parent 4 1a2a00e78665
child 11 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 8: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:  Shortcut plug-in xSP extension session class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32mem.h>
       
    20 #include <badesca.h>
       
    21 #include <gulicon.h>
       
    22 #include <fbs.h>
       
    23 
       
    24 #include <aiscutextdefs.h>
       
    25 
       
    26 #include "caiscutextsession.h"
       
    27 #include "maiscutextmessagehandler.h"
       
    28 
       
    29 #include  "caiscutextserver.h"
       
    30 
       
    31 
       
    32 // ======== MEMBER FUNCTIONS ========
       
    33 
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CAiScutExtSession::CAiScutExtSession( MAiScutExtMessageHandler& aObserver )
       
    40     : iObserver( aObserver )
       
    41     {
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CAiScutExtSession::~CAiScutExtSession()
       
    49     {
       
    50     CAiScutExtServer* server = const_cast<CAiScutExtServer*>(
       
    51         dynamic_cast<const CAiScutExtServer*>( Server() ) );
       
    52 
       
    53     if( iTargetDefinition && server )
       
    54         {
       
    55         TRAP_IGNORE(
       
    56             iObserver.HandleResetPopupLineArrayL( *iTargetDefinition );
       
    57             iObserver.HandleResetIconL( *iTargetDefinition );
       
    58             );
       
    59         }
       
    60 
       
    61     delete iTargetDefinition;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CAiScutExtSession::ServiceL( const RMessage2& aMessage )
       
    69     {
       
    70     CAiScutExtServer* server = const_cast<CAiScutExtServer*>(
       
    71         dynamic_cast<const CAiScutExtServer*>( Server() ) );
       
    72 
       
    73     __ASSERT_ALWAYS( server, User::Leave( KErrCorrupt ) );
       
    74 
       
    75     TUid uid;
       
    76     if( !server->HasConnectedBefore(uid, aMessage) )
       
    77         {
       
    78         server->ShowTipMessage( uid );
       
    79         }
       
    80 
       
    81     TRAPD( err, DispatchMessageL( aMessage ) );
       
    82 
       
    83     if( !aMessage.IsNull() )
       
    84         {
       
    85         aMessage.Complete( err );
       
    86         }
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CAiScutExtSession::DispatchMessageL( const RMessage2& aMessage )
       
    94     {
       
    95     switch ( aMessage.Function() )
       
    96         {
       
    97         case EAiScutExtServSetTargetDefinition:
       
    98             {
       
    99             SetTargetDefinitionL( aMessage );
       
   100             break;
       
   101             }
       
   102         case EAiScutExtServSetPopupText:
       
   103             {
       
   104             SetPopupTextL( aMessage );
       
   105             break;
       
   106             }
       
   107         case EAiScutExtServResetPopupText:
       
   108             {
       
   109             ResetPopupTextL( aMessage );
       
   110             break;
       
   111             }
       
   112         case EAiScutExtServSetIcon:
       
   113             {
       
   114             SetIconL( aMessage );
       
   115             break;
       
   116             }
       
   117         case EAiScutExtServResetIcon:
       
   118             {
       
   119             ResetIconL( aMessage );
       
   120             break;
       
   121             }
       
   122         case EAiScutExtServIsInShortcuts:
       
   123             {
       
   124             IsInShortcutsL( aMessage );
       
   125             break;
       
   126             }
       
   127         case EAiScutExtServIssuePutInShortcuts:
       
   128             {
       
   129             IssuePutInShortcutsL( aMessage );
       
   130             break;
       
   131             }
       
   132         default:
       
   133             {
       
   134             User::Leave( KErrNotSupported );
       
   135             }
       
   136         }
       
   137     }
       
   138 
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CAiScutExtSession::SetTargetDefinitionL( const RMessage2& aMessage )
       
   145     {
       
   146     HBufC* targetStringBuf = HBufC::NewLC( aMessage.GetDesLengthL( 0 ) );
       
   147     TPtr targetString( targetStringBuf->Des() );
       
   148     aMessage.ReadL( 0, targetString, 0 );
       
   149     delete iTargetDefinition;
       
   150     iTargetDefinition = targetStringBuf;
       
   151     CleanupStack::Pop( targetStringBuf );
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CAiScutExtSession::SetPopupTextL( const RMessage2& aMessage )
       
   159     {
       
   160     if( !iTargetDefinition )
       
   161         {
       
   162         return;
       
   163         }
       
   164     HBufC8* marshalledLineArrayBuf = HBufC8::NewLC(
       
   165         aMessage.GetDesLengthL( 0 ) );
       
   166     TPtr8 marshalledLineArray( marshalledLineArrayBuf->Des() );
       
   167     aMessage.ReadL( 0, marshalledLineArray, 0 );
       
   168 
       
   169     RDesReadStream stream( marshalledLineArray );
       
   170     CleanupClosePushL( stream );
       
   171 
       
   172     const TInt lineCount = stream.ReadUint8L();
       
   173     __ASSERT_ALWAYS( lineCount >= 0 && lineCount <= KMaxPopupTextLines,
       
   174         User::Leave( KErrArgument ) );
       
   175 
       
   176     CDesCArray* array = new( ELeave ) CDesCArrayFlat(
       
   177         lineCount > 0 ? lineCount : 1 );
       
   178     CleanupStack::PushL( array );
       
   179 
       
   180     for( TInt i = 0; i < lineCount; i++ )
       
   181         {
       
   182         HBufC* lineBuf = HBufC::NewLC( stream, KMaxTInt );
       
   183         array->AppendL( *lineBuf );
       
   184         CleanupStack::PopAndDestroy( lineBuf );
       
   185         }
       
   186 
       
   187     iObserver.HandleSetPopupLineArrayL( *iTargetDefinition, array );  //Takes ownership of array
       
   188 
       
   189     CleanupStack::Pop( array );
       
   190     CleanupStack::PopAndDestroy( &stream );
       
   191     CleanupStack::PopAndDestroy( marshalledLineArrayBuf );
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CAiScutExtSession::ResetPopupTextL( const RMessage2& /*aMessage*/ )
       
   199     {
       
   200     if( iTargetDefinition )
       
   201         {
       
   202         iObserver.HandleResetPopupLineArrayL( *iTargetDefinition );
       
   203         }
       
   204     }
       
   205 
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 void CAiScutExtSession::SetIconL( const RMessage2& aMessage )
       
   212     {
       
   213     if( !iTargetDefinition )
       
   214         {
       
   215         return;
       
   216         }
       
   217     HBufC8* marshallBuf = HBufC8::NewLC( aMessage.GetDesLengthL( 0 ) );
       
   218     TPtr8 marshalledData( marshallBuf->Des() );
       
   219     aMessage.ReadL( 0, marshalledData, 0 );
       
   220 
       
   221     RDesReadStream stream( marshalledData );
       
   222     CleanupClosePushL( stream );
       
   223 
       
   224     CFbsBitmap* bitmap = new( ELeave ) CFbsBitmap;
       
   225     CleanupStack::PushL( bitmap );
       
   226     bitmap->InternalizeL( stream );
       
   227 
       
   228     CFbsBitmap* mask = new( ELeave ) CFbsBitmap;
       
   229     CleanupStack::PushL( mask );
       
   230     mask->InternalizeL( stream );
       
   231 
       
   232     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   233     CleanupStack::Pop( 2, bitmap );
       
   234     CleanupStack::PushL( icon );
       
   235 
       
   236     iObserver.HandleSetIconL( *iTargetDefinition, icon );
       
   237 
       
   238     CleanupStack::Pop( icon );
       
   239 
       
   240     CleanupStack::PopAndDestroy( &stream );
       
   241     CleanupStack::PopAndDestroy( marshallBuf );
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 void CAiScutExtSession::ResetIconL( const RMessage2& /*aMessage*/ )
       
   249     {
       
   250     if( iTargetDefinition )
       
   251         {
       
   252         iObserver.HandleResetIconL( *iTargetDefinition );
       
   253         }
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 void CAiScutExtSession::IsInShortcutsL( const RMessage2& aMessage )
       
   261     {
       
   262     if( iTargetDefinition )
       
   263         {
       
   264         TBool isInShortcuts = iObserver.HandleIsInShortcutsL( *iTargetDefinition );
       
   265 
       
   266         TPtr8 isInShortcutsDes(
       
   267             reinterpret_cast< TUint8* >( &isInShortcuts ),
       
   268             sizeof( isInShortcuts ),
       
   269             sizeof( isInShortcuts ) );
       
   270         aMessage.WriteL( 0, isInShortcutsDes, 0 );
       
   271         }
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CAiScutExtSession::IssuePutInShortcutsL( const RMessage2& /*aMessage*/ )
       
   279     {
       
   280     if( iTargetDefinition )
       
   281         {
       
   282         iObserver.HandleIssuePutInShortcutsL( *iTargetDefinition );
       
   283         }
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CAiScutExtSession::PanicClient(
       
   291     const RMessage2& aMessage, TInt aPanicCode ) const
       
   292     {
       
   293     aMessage.Panic( KAiScutExtServerName, aPanicCode );
       
   294     }
       
   295 
       
   296 // End of File.