idlehomescreen/xmluicontroller/src/texttransactionelement.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:  Text transaction element
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    "texttransactionelement.h"
       
    20 #include    "aixmluiutils.h"
       
    21 
       
    22 #include    "xntype.h"
       
    23 #include    "xnproperty.h"
       
    24 #include    "xntext.h"
       
    25 #include    "xnmenuadapter.h"
       
    26 #include    "xnnewsticker.h"
       
    27 //#include    <xnmarquee.h>
       
    28 #include    "mxncomponentinterface.h"
       
    29 #include    "xnnodeappif.h"
       
    30 #include    "xnuiengineappif.h"
       
    31 #include    "xnproperty.h"
       
    32 #include    "xndompropertyvalue.h"
       
    33 #include    "xnvolumecontrol.h"
       
    34 #include    "aistrcnv.h"
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 using namespace AiXmlUiController;
       
    39 using namespace XnTextInterface;
       
    40 
       
    41 CTextTransactionElement::CTextTransactionElement(AiUtility::CContentPriorityMap& aContentPriorityMap)
       
    42     : CTransactionElement(aContentPriorityMap)
       
    43     {
       
    44     }    
       
    45 
       
    46 CTextTransactionElement* CTextTransactionElement::NewL(AiUtility::CContentPriorityMap& aContentPriorityMap)
       
    47     {
       
    48     CTextTransactionElement* self = new( ELeave ) CTextTransactionElement(aContentPriorityMap);
       
    49     
       
    50     return self;
       
    51     }
       
    52 
       
    53 CTextTransactionElement::~CTextTransactionElement()
       
    54     {
       
    55     if (iNewText)
       
    56         {
       
    57         delete iNewText;
       
    58         iNewText = NULL;
       
    59         }
       
    60     }
       
    61 
       
    62 void CTextTransactionElement::InitializeL( CXnNodeAppIf& aTarget, const TDesC& aText )
       
    63     {
       
    64     CheckTypeL( aTarget );
       
    65     SetTarget( aTarget );
       
    66     
       
    67     if (iNewText)
       
    68         {
       
    69         delete iNewText;
       
    70         iNewText = NULL;
       
    71         }
       
    72     iNewText = aText.AllocL();    
       
    73     }
       
    74 
       
    75 void CTextTransactionElement::UpdateDataL()
       
    76     {
       
    77     // Set new text
       
    78     SetTextL();
       
    79     
       
    80     // Update content priority
       
    81     UpdateContentPriorityL();
       
    82     }
       
    83     
       
    84 void CTextTransactionElement::Reset()
       
    85     {
       
    86     CTransactionElement::Reset();
       
    87     
       
    88     
       
    89     if (iNewText)   
       
    90         {
       
    91         delete iNewText;
       
    92         iNewText = NULL;
       
    93         }
       
    94     }
       
    95 
       
    96 TBool CTextTransactionElement::IsSupported( CXnNodeAppIf& aTarget )
       
    97     {
       
    98     CXnType* typeInfo = aTarget.Type();
       
    99     
       
   100     if ( !typeInfo )
       
   101         {
       
   102         return EFalse;
       
   103         }
       
   104     
       
   105     const TDesC8& type = typeInfo->Type();
       
   106     
       
   107     // Text element, menu item, newsticker, and marquee supported
       
   108     return ( type == XnTextInterface::MXnTextInterface::Type() ||
       
   109              type == KXnMenuItem ||
       
   110              type == KXnMenu ||
       
   111              type == XnPropertyNames::softkey::KNodeName || 
       
   112              type == XnPropertyNames::volumecontrol::KSlider /*||
       
   113              type == XnNewstickerInterface::MXnNewstickerInterface::Type() ||
       
   114              type == XnMarqueeInterface::MXnMarqueeInterface::Type() */);
       
   115     }
       
   116 
       
   117 void CTextTransactionElement::CheckTypeL( CXnNodeAppIf& aTarget )
       
   118     {
       
   119     if ( !IsSupported( aTarget ) )
       
   120         {
       
   121         User::Leave( KErrNotSupported );
       
   122         }
       
   123     }
       
   124 
       
   125 void CTextTransactionElement::SetTextL()
       
   126     {
       
   127     // Get type info
       
   128     const TDesC8& type = LeaveIfNull( Target().Type(), KErrNotSupported )->Type();
       
   129     
       
   130     if ( type == XnTextInterface::MXnTextInterface::Type() ) // text element
       
   131         {
       
   132         // Get control interface
       
   133         XnTextInterface::MXnTextInterface* textControl = NULL;
       
   134         XnComponentInterface::MakeInterfaceL( textControl, Target() );
       
   135         LeaveIfNull( textControl, KErrNotSupported );
       
   136         
       
   137         // Set text
       
   138         
       
   139         textControl->SetTextL( *iNewText );
       
   140         }
       
   141        
       
   142  // Menu softkey texts
       
   143     else if ( type == XnPropertyNames::softkey::KNodeName)
       
   144         {
       
   145         CXnNodeAppIf& target = Target();
       
   146         // Set the label of the softkey
       
   147         CXnDomPropertyValue* propertyValue =
       
   148             CXnDomPropertyValue::NewL( target.UiEngineL()->StringPool() );
       
   149     
       
   150         CleanupStack::PushL( propertyValue );
       
   151     
       
   152         // Convert unicode to UTF-8
       
   153         HBufC8* textBuf = NULL;
       
   154         
       
   155         textBuf = AiUtility::CopyToBufferL( textBuf, *iNewText );
       
   156         CleanupStack::PushL( textBuf );
       
   157         
       
   158         propertyValue->SetStringValueL( CXnDomPropertyValue::EString,
       
   159                                         *textBuf );
       
   160     
       
   161         CleanupStack::PopAndDestroy( textBuf );
       
   162         
       
   163         CXnProperty* newProperty = CXnProperty::NewL( XnPropertyNames::menu::KLabel,
       
   164                                                       propertyValue,
       
   165                                                       target.UiEngineL()->StringPool() );
       
   166         CleanupStack::Pop( propertyValue );
       
   167         
       
   168         CleanupStack::PushL( newProperty );
       
   169 
       
   170         target.SetPropertyL( newProperty );
       
   171         
       
   172         CleanupStack::Pop( newProperty );
       
   173         target.UiEngineL()->RefreshMenuL(); 
       
   174        
       
   175         }            
       
   176         
       
   177     else if ( type == XnPropertyNames::volumecontrol::KSlider ) // slider
       
   178         {
       
   179         // Get volume control interface
       
   180         XnVolumeControlInterface::MXnVolumeControlInterface* volumeControl = NULL;
       
   181         XnComponentInterface::MakeInterfaceL( volumeControl, Target() );
       
   182         LeaveIfNull( volumeControl, KErrNotSupported );
       
   183         
       
   184         TInt32 volume = 0;
       
   185         
       
   186         User::LeaveIfError( AiUtility::ParseInt( volume, *iNewText ) );
       
   187         volumeControl->SetValue( volume );
       
   188         }
       
   189 /*    else if ( type == XnNewstickerInterface::MXnNewstickerInterface::Type() )
       
   190         {
       
   191         // Get Newsticker control interface
       
   192         XnNewstickerInterface::MXnNewstickerInterface* newsTicker = NULL;
       
   193         XnComponentInterface::MakeInterfaceL( newsTicker, Target() );
       
   194         LeaveIfNull( newsTicker, KErrNotSupported );
       
   195         
       
   196         // Append new title
       
   197         newsTicker->ClearTitles();
       
   198         newsTicker->AppendTitleL( iNewText );
       
   199         }
       
   200     else if ( type == XnMarqueeInterface::MXnMarqueeInterface::Type() )
       
   201         {
       
   202         // Get marquee interface
       
   203         XnMarqueeInterface::MXnMarqueeInterface* marquee = NULL;
       
   204         XnComponentInterface::MakeInterfaceL( marquee, Target() );
       
   205         LeaveIfNull( marquee, KErrNotSupported );
       
   206         
       
   207         // Set new text
       
   208         marquee->SetTextL( iNewText );
       
   209         }*/
       
   210     else
       
   211         {
       
   212         User::Leave( KErrNotSupported );
       
   213         }
       
   214     }
       
   215     
       
   216 //  End of File