idlehomescreen/xmluicontroller/src/databuffertransactionelement.cpp
changeset 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     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:  Data buffer transaction element
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    "databuffertransactionelement.h"
       
    20 #include    "aixmluiutils.h"
       
    21 
       
    22 #include    "xntype.h"
       
    23 #include    "xntext.h"
       
    24 #include    "xnnewsticker.h"
       
    25 #include    "xnmenuadapter.h"
       
    26 #include    "mxncomponentinterface.h"
       
    27 #include    "xnvolumecontrol.h"
       
    28 #include    "xnnodeappif.h"
       
    29 #include    "xnuiengineappif.h"
       
    30 #include    "xnproperty.h"
       
    31 #include    "xndompropertyvalue.h"
       
    32 #include    "aistrcnv.h"
       
    33 #include    "aixmluiconstants.h"
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 using namespace AiXmlUiController;
       
    38 using namespace XnTextInterface;
       
    39 
       
    40 CDataBufferTransactionElement::CDataBufferTransactionElement(AiUtility::CContentPriorityMap& aContentPriorityMap)
       
    41     : CTransactionElement(aContentPriorityMap)
       
    42     {
       
    43     }    
       
    44 
       
    45 CDataBufferTransactionElement* CDataBufferTransactionElement::NewL(AiUtility::CContentPriorityMap& aContentPriorityMap)
       
    46     {
       
    47     CDataBufferTransactionElement* self = new( ELeave ) CDataBufferTransactionElement(aContentPriorityMap);
       
    48     
       
    49     return self;
       
    50     }
       
    51 
       
    52 CDataBufferTransactionElement::~CDataBufferTransactionElement()
       
    53     {
       
    54     }
       
    55 
       
    56 void CDataBufferTransactionElement::InitializeL( CXnNodeAppIf& aTarget, const TDesC8& aData )
       
    57     {
       
    58     CheckTypeL( aTarget );
       
    59     SetTarget( aTarget );
       
    60     iNewData.Set( aData );
       
    61     }
       
    62 
       
    63 void CDataBufferTransactionElement::UpdateDataL()
       
    64     {
       
    65     // Set new text
       
    66     SetDataL();
       
    67     
       
    68     // Update content priority
       
    69     UpdateContentPriorityL();
       
    70     }
       
    71     
       
    72 void CDataBufferTransactionElement::Reset()
       
    73     {
       
    74     CTransactionElement::Reset();
       
    75     
       
    76     iNewData.Set( KNullDesC8);
       
    77     }
       
    78 
       
    79 TBool CDataBufferTransactionElement::IsSupported( CXnNodeAppIf& aTarget,
       
    80                                                   const TDesC8& aContentType )
       
    81     {
       
    82     // Get target type info
       
    83     CXnType* typeInfo = aTarget.Type();
       
    84     
       
    85     if ( !typeInfo )
       
    86         {
       
    87         return EFalse;
       
    88         }
       
    89     
       
    90     const TDesC8& type = typeInfo->Type();
       
    91     
       
    92     if ( aContentType == KContentTypeText ) // Text
       
    93         {
       
    94         // Text element and menu item supports
       
    95         return ( type == XnTextInterface::MXnTextInterface::Type() ||
       
    96                  type == KXnMenuItem || 
       
    97                  type == KXnMenu ||
       
    98                  type == XnPropertyNames::softkey::KNodeName ||
       
    99                  type == XnPropertyNames::volumecontrol::KSlider );
       
   100         }
       
   101     else if ( aContentType == KContentTypeImageSvg ) // SVG image
       
   102         {
       
   103         // Newsticker support
       
   104         return ( type == XnNewstickerInterface::MXnNewstickerInterface::Type() );
       
   105         }
       
   106         
       
   107     return EFalse;
       
   108     }
       
   109 
       
   110 void CDataBufferTransactionElement::CheckTypeL( CXnNodeAppIf& aTarget )
       
   111     {
       
   112     // Get type info
       
   113     const TDesC8& type = LeaveIfNull( aTarget.Type(), KErrNotSupported )->Type();
       
   114     
       
   115     // Text element, menu item, and newsticker supported
       
   116     if ( type != XnTextInterface::MXnTextInterface::Type() &&
       
   117          type != KXnMenuItem &&
       
   118          type != KXnMenu &&
       
   119          type != XnPropertyNames::softkey::KNodeName && 
       
   120          type != XnPropertyNames::volumecontrol::KSlider &&
       
   121          type != XnNewstickerInterface::MXnNewstickerInterface::Type() )
       
   122         {
       
   123         User::Leave( KErrNotSupported );
       
   124         }
       
   125     }
       
   126 
       
   127 void CDataBufferTransactionElement::SetDataL()
       
   128     {
       
   129     // Get type info
       
   130     const TDesC8& type = LeaveIfNull( Target().Type(), KErrNotSupported )->Type();
       
   131     
       
   132     if ( type == XnTextInterface::MXnTextInterface::Type() ) // Text element
       
   133         {
       
   134         // Set character data directly to target
       
   135         Target().SetPCDataL( iNewData );
       
   136         }
       
   137     else if (  type == XnPropertyNames::softkey::KNodeName ||
       
   138             type == KXnMenuItem || 
       
   139             type == KXnMenu ) // menu item
       
   140         {
       
   141         // Update label attribute value.
       
   142         
       
   143         // 
       
   144         CXnNodeAppIf& target = Target();
       
   145         
       
   146         // Create new new label attribute value
       
   147         CXnDomPropertyValue* propertyValue =
       
   148             CXnDomPropertyValue::NewL( target.UiEngineL()->StringPool() );
       
   149     
       
   150         CleanupStack::PushL( propertyValue );
       
   151     
       
   152         propertyValue->SetStringValueL( CXnDomPropertyValue::EString,
       
   153                                         iNewData );
       
   154     
       
   155         CXnProperty* newProperty = CXnProperty::NewL( XnPropertyNames::menu::KLabel,
       
   156                                                       propertyValue,
       
   157                                                       target.UiEngineL()->StringPool() );
       
   158         CleanupStack::Pop( propertyValue );
       
   159         
       
   160         CleanupStack::PushL( newProperty );
       
   161 
       
   162         // Set label attribute
       
   163         target.SetPropertyL( newProperty );
       
   164         
       
   165         CleanupStack::Pop( newProperty );
       
   166         
       
   167         // Refresh menu
       
   168         target.UiEngineL()->RefreshMenuL();
       
   169         }
       
   170     else if ( type == XnPropertyNames::volumecontrol::KSlider ) // slider
       
   171         {
       
   172         // Get volume control interface
       
   173         XnVolumeControlInterface::MXnVolumeControlInterface* volumeControl = NULL;
       
   174         XnComponentInterface::MakeInterfaceL( volumeControl, Target() );
       
   175         LeaveIfNull( volumeControl, KErrNotSupported );
       
   176         
       
   177         TInt32 volume = 0;
       
   178         User::LeaveIfError( AiUtility::ParseInt( volume, iNewData ) );
       
   179         volumeControl->SetValue( volume );
       
   180         }
       
   181     else if ( type == XnNewstickerInterface::MXnNewstickerInterface::Type() )
       
   182         {
       
   183         // Get newsticker interface
       
   184         XnNewstickerInterface::MXnNewstickerInterface* newsTicker = NULL;
       
   185         XnComponentInterface::MakeInterfaceL( newsTicker, Target() );
       
   186         LeaveIfNull( newsTicker, KErrNotSupported );
       
   187         
       
   188         // Append new SVG title
       
   189         newsTicker->AppendSvgTitleL( iNewData );
       
   190         }
       
   191     else
       
   192         {
       
   193         User::Leave( KErrNotSupported );
       
   194         }
       
   195     }
       
   196     
       
   197 //  End of File