idlehomescreen/xmluirendering/uiengine/src/xnlistquerydialogadapter.cpp
changeset 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2009 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:  List query dialog adapter and data interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  System includes
       
    20 #include <e32base.h>
       
    21 #include <aknlistquerydialog.h>
       
    22 #include <utf.h>
       
    23 #include <xnuiengine.rsg>
       
    24 
       
    25 // User includes
       
    26 #include "xnappuiadapter.h"
       
    27 #include "xnlistquerydialogadapter.h"
       
    28 #include "xnnodepluginif.h"
       
    29 #include "xntype.h"
       
    30 #include "xnproperty.h"
       
    31 #include "xnuiengine.h"
       
    32 #include "xnodt.h"
       
    33 #include "xndomdocument.h"
       
    34 #include "xndomnode.h"
       
    35 #include "xndomlist.h"
       
    36 #include "xndomattribute.h"
       
    37 
       
    38 // ======== LOCAL FUNCTIONS ========
       
    39 // ---------------------------------------------------------------------------
       
    40 // Finds recursively node by type
       
    41 // @return    returns pointer to desired node, NULL if nothing found 
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CXnDomNode* FindNodeByType( CXnDomNode* aNode, const TDesC8& aName )
       
    45     {
       
    46     if ( aNode == NULL )
       
    47         {
       
    48         return NULL;
       
    49         }
       
    50 
       
    51     if ( aNode->Name() == aName )
       
    52         {
       
    53         return aNode;
       
    54         }
       
    55 
       
    56     CXnDomList& list( aNode->ChildNodes() );
       
    57 
       
    58     for ( TInt i = 0; i < list.Length() ; i++ )
       
    59         {
       
    60         CXnDomNode* retval( FindNodeByType(
       
    61                 static_cast< CXnDomNode* >( list.Item( i ) ), aName ) );
       
    62 
       
    63         if ( retval )
       
    64             {
       
    65             return retval;
       
    66             }
       
    67         }
       
    68 
       
    69     return NULL;
       
    70     }
       
    71 
       
    72 // ============================ MEMBER FUNCTIONS ===============================
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // Symbian static 1st phase constructor
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CXnListQueryDialog* CXnListQueryDialog::NewL()
       
    79     {
       
    80     CXnListQueryDialog* self = new( ELeave ) CXnListQueryDialog;
       
    81 
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();
       
    84     CleanupStack::Pop();
       
    85 
       
    86     return self;    
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // Symbian 2nd phase constructor can leave.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CXnListQueryDialog::ConstructL()
       
    94     {
       
    95     CXnComponent::ConstructL();
       
    96     }
       
    97     
       
    98 // -----------------------------------------------------------------------------
       
    99 // C++ default constructor
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 CXnListQueryDialog::CXnListQueryDialog()
       
   103     {
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // C++ destructor
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 CXnListQueryDialog::~CXnListQueryDialog()
       
   111     {
       
   112     }
       
   113     
       
   114 // ---------------------------------------------------------
       
   115 // Replaces or appends item into list
       
   116 // ---------------------------------------------------------
       
   117 //
       
   118 void CXnListQueryDialog::ReplaceItemL( const TDesC& aText, TInt aIndex )
       
   119     {
       
   120     (static_cast<CXnListQueryDialogAdapter*>(ControlAdapter()))->ReplaceItemL( aText, aIndex );
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------
       
   124 // Inserts or appends item into list
       
   125 // ---------------------------------------------------------
       
   126 //
       
   127 void CXnListQueryDialog::InsertItemL( const TDesC& aText, TInt aIndex )
       
   128     {
       
   129     (static_cast<CXnListQueryDialogAdapter*>(ControlAdapter()))->InsertItemL( aText, aIndex );
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------
       
   133 // Deletes item from the list
       
   134 // ---------------------------------------------------------
       
   135 //
       
   136 void CXnListQueryDialog::DeleteItem( TInt aIndex )
       
   137     {
       
   138     return (static_cast<CXnListQueryDialogAdapter*>(ControlAdapter()))->DeleteItem( aIndex );   
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // ---------------------------------------------------------
       
   143 XnComponentInterface::MXnComponentInterface* CXnListQueryDialog::MakeInterfaceL(const TDesC8& aType)
       
   144     {
       
   145     if (aType != XnListQueryDialogInterface::KType)
       
   146         {
       
   147         return NULL;
       
   148         }
       
   149     XnListQueryDialogInterface::MXnListQueryDialogInterface* interface =
       
   150         static_cast<XnListQueryDialogInterface::MXnListQueryDialogInterface*>( this );
       
   151     return interface;
       
   152     }  
       
   153 
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // Two-phased constructor. Can leave.
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 CXnListQueryDialogAdapter* CXnListQueryDialogAdapter::NewL( CXnNodePluginIf& aNode )
       
   160     {
       
   161     CXnListQueryDialogAdapter* self = 
       
   162         new ( ELeave ) CXnListQueryDialogAdapter( aNode );
       
   163     CleanupStack::PushL( self );
       
   164     self->ConstructL();
       
   165     CleanupStack::Pop( self );
       
   166     return self;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // Destructor.
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 CXnListQueryDialogAdapter::~CXnListQueryDialogAdapter()
       
   174     {
       
   175     delete iItemArray;
       
   176     iStaticItems.Close();
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // C++ default constructor. Must not leave.
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 CXnListQueryDialogAdapter::CXnListQueryDialogAdapter( CXnNodePluginIf& aNode )
       
   184     : iNode( aNode )
       
   185     {
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // 2nd phase constructor. Can leave.
       
   190 // -----------------------------------------------------------------------------
       
   191 //    
       
   192 void CXnListQueryDialogAdapter::ConstructL()
       
   193     {
       
   194     CXnControlAdapter::ConstructL( iNode );
       
   195     iItemArray = new ( ELeave ) CDesCArrayFlat( 8 );
       
   196     // find normal menu items and dynamic menu items
       
   197     // Only one dynamic item allowed
       
   198     RPointerArray< CXnNodePluginIf > children( iNode.ChildrenL() );
       
   199     CleanupClosePushL( children );
       
   200     for ( TInt i = 0; i < children.Count(); i++ )
       
   201         {
       
   202         CXnNodePluginIf* node( children[i] );
       
   203         if ( node->Type()->Type() == XnPropertyNames::menu::KMenuItem)
       
   204             {
       
   205             iStaticItems.AppendL( node );
       
   206             CXnProperty* labelProp = node->GetPropertyL( XnPropertyNames::menu::KLabel );
       
   207             if( labelProp )
       
   208                 {
       
   209                 HBufC* label( labelProp->StringValueL());
       
   210                 CleanupStack::PushL( label );
       
   211                 iItemArray->AppendL( *label );
       
   212                 CleanupStack::PopAndDestroy( label );
       
   213                 }
       
   214             }
       
   215         else if( node->Type()->Type() == XnPropertyNames::menu::KDynMenuItem )
       
   216             {
       
   217             iDynamicItem = node;
       
   218             }
       
   219         }
       
   220     CleanupStack::PopAndDestroy( &children );
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // Replaces or appends item into list
       
   225 // -----------------------------------------------------------------------------
       
   226 // 
       
   227 void CXnListQueryDialogAdapter::ReplaceItemL(const TDesC& aText, TInt aIndex )
       
   228     {
       
   229     aIndex += iStaticItems.Count();
       
   230     TInt count( iItemArray->Count());
       
   231     if( aIndex >= count )
       
   232         {
       
   233         iItemArray->AppendL( aText );
       
   234         }
       
   235     else
       
   236         {
       
   237         iItemArray->Delete( aIndex );
       
   238         iItemArray->InsertL( aIndex, aText );
       
   239         }
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // Inserts or appends item into list
       
   244 // -----------------------------------------------------------------------------
       
   245 // 
       
   246 void CXnListQueryDialogAdapter::InsertItemL(const TDesC& aText, TInt aIndex )
       
   247     {
       
   248     aIndex += iStaticItems.Count();
       
   249     TInt count( iItemArray->Count());
       
   250     if( count < aIndex )
       
   251         {
       
   252         aIndex = count;
       
   253         }
       
   254     iItemArray->InsertL( aIndex, aText );
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // Deletes item from the list
       
   259 // -----------------------------------------------------------------------------
       
   260 // 
       
   261 void CXnListQueryDialogAdapter::DeleteItem( TInt aIndex )
       
   262     {
       
   263     aIndex += iStaticItems.Count();
       
   264     if( aIndex < iItemArray->Count())
       
   265         {
       
   266         iItemArray->Delete( aIndex );
       
   267         }    
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // Displays the list query dialog
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 void CXnListQueryDialogAdapter::TryDisplayingDialogL( )
       
   275     {
       
   276     CXnAppUiAdapter& appui( static_cast< CXnAppUiAdapter& >( *iAvkonAppUi ) );
       
   277     
       
   278     appui.HideFocus();
       
   279     
       
   280     TInt selectedIndex( 0 );
       
   281     
       
   282     CAknListQueryDialog* query =
       
   283        new ( ELeave ) CAknListQueryDialog( &selectedIndex );
       
   284 
       
   285     query->PrepareLC( R_XML_LISTQUERY );
       
   286 /* Not tested
       
   287     CAknPopupHeadingPane* heading( query->QueryHeading() );
       
   288     if ( heading )
       
   289         {
       
   290         CXnProperty* prop( iNode.GetPropertyL(
       
   291             XnPropertyNames::listquerydialog::KS60Heading ) );
       
   292 
       
   293         if ( prop )
       
   294             {
       
   295             HBufC* header( prop->StringValueL() );
       
   296             CleanupStack::Push( header );
       
   297             heading->SetTextL( *header );
       
   298             CleanupStack::PopAndDestroy( header );
       
   299             }
       
   300         else
       
   301             {
       
   302             heading->SetTextL( KNullDesC() );
       
   303             }
       
   304         }
       
   305 */
       
   306     query->SetItemTextArray( iItemArray );
       
   307     query->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   308 
       
   309     if ( query->RunLD() )
       
   310         {
       
   311         ActivateItemL( selectedIndex );
       
   312         }
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // Runs the activate event for the item node 
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 void CXnListQueryDialogAdapter::ActivateItemL( TInt aIndex )
       
   320     {
       
   321     if( aIndex < iStaticItems.Count())
       
   322         {
       
   323         iStaticItems[aIndex]->Node().SetStateL( 
       
   324                 XnPropertyNames::style::common::KActive );
       
   325         iStaticItems[aIndex]->Node().UnsetStateL( 
       
   326                 XnPropertyNames::style::common::KActive );
       
   327         }
       
   328     else
       
   329         {
       
   330         ModifyDynamicEventL( aIndex - iStaticItems.Count());
       
   331         iDynamicItem->Node().SetStateL( 
       
   332                         XnPropertyNames::style::common::KActive );
       
   333         iDynamicItem->Node().UnsetStateL( 
       
   334                 XnPropertyNames::style::common::KActive );
       
   335         }
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // Replaces the '#' char by index in event. Syntax "(#"
       
   340 // -----------------------------------------------------------------------------
       
   341 //
       
   342 void CXnListQueryDialogAdapter::ModifyDynamicEventL( TInt aIndex )
       
   343     {
       
   344     CXnDomNode* eventNode = FindNodeByType( iDynamicItem->Node().DomNode(), XnPropertyNames::action::KEvent );
       
   345 
       
   346     CXnDomAttribute* attribute = static_cast<CXnDomAttribute*> 
       
   347         (eventNode->AttributeList().FindByName( XnPropertyNames::action::event::KName ));
       
   348     
       
   349     HBufC8* nameStr( attribute->Value().AllocLC());
       
   350     TPtr8 namePtr = nameStr->Des();
       
   351     
       
   352     //Find '(' char
       
   353     TInt pos = namePtr.Locate('(');
       
   354     TBuf8<4> index;
       
   355     index.AppendNum( aIndex );
       
   356     namePtr.Replace( pos+1, 1, index );
       
   357     
       
   358     attribute->SetValueL( namePtr );
       
   359     CleanupStack::PopAndDestroy( nameStr );
       
   360     }
       
   361 
       
   362 //  End of File