idlehomescreen/xmluicontroller/src/newstickercallbackhandler.cpp
branchRCL_3
changeset 54 1b758917cafc
parent 50 137ebc85284b
child 59 d721605b30d0
equal deleted inserted replaced
50:137ebc85284b 54:1b758917cafc
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Callback handler for newsticker component callbacks
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "newstickercallbackhandler.h"
       
    20 #include "aifweventhandler.h"
       
    21 #include "aiconsts.h"
       
    22 #include "aixmluiconstants.h"
       
    23 #include "aistrcnv.h"
       
    24 
       
    25 using namespace AiXmlUiController;
       
    26 
       
    27 const TInt KRadix = 10;
       
    28 const TText16 KPluginEventParameterSeparator = ',';
       
    29 const TText16 KEventParameterTerminator = ')';
       
    30 
       
    31 static TInt IndexLength( TInt aIndex )
       
    32     {
       
    33     TInt length = 0;
       
    34 
       
    35     if ( aIndex < 0 )
       
    36         {
       
    37         ++length;
       
    38         }
       
    39 
       
    40     do
       
    41         {
       
    42         aIndex /= KRadix;
       
    43         ++length;
       
    44         }
       
    45     while ( aIndex != 0 );
       
    46 
       
    47     return length;
       
    48     }
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 CNewstickerCallbackHandler::CNewstickerCallbackHandler( MAiFwEventHandler& aFwEventHandler )
       
    53     : iFwEventHandler( aFwEventHandler )
       
    54     {
       
    55     }
       
    56 
       
    57 CNewstickerCallbackHandler* CNewstickerCallbackHandler::NewLC( MAiFwEventHandler& aFwEventHandler )
       
    58     {
       
    59     CNewstickerCallbackHandler* self = new( ELeave ) CNewstickerCallbackHandler( aFwEventHandler );
       
    60     CleanupStack::PushL( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 
       
    65 CNewstickerCallbackHandler::~CNewstickerCallbackHandler()
       
    66     {
       
    67     delete iEventBuffer;
       
    68     }
       
    69 
       
    70 
       
    71 void CNewstickerCallbackHandler::TitleScrolledL( const TDesC& aPublisherName,
       
    72                                                  const TDesC& aPublishingClass,
       
    73                                                  TInt aIndex )
       
    74     {
       
    75     SendEventToNewstickerPluginL( AiUiDef::xml::event::KNewstickerTitleScrolled,
       
    76                                     aPublisherName,
       
    77                                     aPublishingClass,
       
    78                                     aIndex);
       
    79     }
       
    80 
       
    81 void CNewstickerCallbackHandler::TitleToScrollL( const TDesC& aPublisherName,
       
    82                                                  const TDesC& aPublishingClass,
       
    83                                                  TInt aIndex )
       
    84     {
       
    85     SendEventToNewstickerPluginL( AiUiDef::xml::event::KNewstickerTitleToScroll,
       
    86                                     aPublisherName,
       
    87                                     aPublishingClass,
       
    88                                     aIndex);
       
    89     }
       
    90 
       
    91 
       
    92 void CNewstickerCallbackHandler::SendEventToNewstickerPluginL( const TDesC& aEvent,
       
    93                                                         const TDesC& aPublisherName,
       
    94                                                         const TDesC& aPublishingClass,
       
    95                                                         TInt aIndex)
       
    96     {
       
    97         // Calculate event buffer length
       
    98     TInt length = aPublisherName.Length()
       
    99                   + KPluginEventSeparatorLength
       
   100                   + aEvent.Length()
       
   101                   + KEventParameterSeparatorLength
       
   102                   + aPublishingClass.Length()
       
   103                   + KEventParameterSeparatorLength
       
   104                   + IndexLength( aIndex )
       
   105                   + KEventParameterSeparatorLength;
       
   106 
       
   107     // Allocate event buffer
       
   108     TPtr event = AiUtility::EnsureBufMaxLengthL( iEventBuffer, length );
       
   109 
       
   110     // Create event string
       
   111     event.Zero();
       
   112     event.Append( aPublisherName );
       
   113     event.Append( KPluginEventSeparator );
       
   114     event.Append( aEvent );
       
   115     event.Append( KEventParameterSeparator );
       
   116     event.Append( aPublishingClass );
       
   117     event.Append( KPluginEventParameterSeparator );
       
   118     event.AppendNum( aIndex );
       
   119     event.Append( KEventParameterTerminator );
       
   120 
       
   121     // Send event to plugin
       
   122     // TODO: fix namespace
       
   123     iFwEventHandler.HandlePluginEvent( event );
       
   124     }