menucontentsrv/srvsrc/mcsgetlisttreecreator.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2008 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32cmn.h> 
       
    19 #include <liwcommon.h>
       
    20 #include <liwgenericparam.h>
       
    21 #include <s32mem.h>
       
    22 #include "mcsgetlisttreecreator.h"
       
    23 
       
    24 // ---------------------------------------------------------
       
    25 // CMcsGetlistTreeCreator::NewL
       
    26 // ---------------------------------------------------------
       
    27 //
       
    28 CMcsGetlistTreeCreator* CMcsGetlistTreeCreator::NewL( CMenuSrvEng& aEng )
       
    29 	{
       
    30 	CMcsGetlistTreeCreator* self;
       
    31 	self = new ( ELeave ) CMcsGetlistTreeCreator( aEng );
       
    32 	CleanupStack::PushL( self );
       
    33 	self->ConstructL();
       
    34 	CleanupStack::Pop( self );
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 // ---------------------------------------------------------
       
    39 // CMcsGetlistTreeCreator::~CMcsGetlistTreeCreator
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 CMcsGetlistTreeCreator::~CMcsGetlistTreeCreator()
       
    43     {
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CMcsGetlistTreeCreator::CMcsGetlistTreeCreator
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 CMcsGetlistTreeCreator::CMcsGetlistTreeCreator( CMenuSrvEng& aEng ):
       
    51 	CMcsGetListCreatorInterface(aEng)
       
    52     {
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------
       
    56 // CMcsGetlistTreeCreator::ConstructL
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 void CMcsGetlistTreeCreator::ConstructL()
       
    60     {
       
    61     CMcsGetListCreatorInterface::ConstructL();
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CMcsGetlistTreeCreator::CreateLC
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 CLiwDefaultList* CMcsGetlistTreeCreator::CreateLC(
       
    69 	RArray<TMenuItem>& aIdsArray,
       
    70 	CDesC16Array* aRequiredAttributes,
       
    71 	CDesC16Array* aIgnoredAttributes )
       
    72 	{
       
    73 	CLiwDefaultList* list = CLiwDefaultList::NewLC();
       
    74 	iRequiredAttributes = aRequiredAttributes;
       
    75 	iIgnoredAttributes = aIgnoredAttributes;
       
    76 	TInt index = 0;
       
    77 	if ( aIdsArray.Count() )
       
    78 		{
       
    79 		BuildTreeListL( aIdsArray, *list, index, aIdsArray[0].Parent() );
       
    80 		}
       
    81 
       
    82 	return list;
       
    83 	}
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Build List for Output paremeter in a tree format
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CMcsGetlistTreeCreator::BuildTreeListL( RArray<TMenuItem>& aIdsArray,
       
    90 		CLiwDefaultList& aList,	TInt& aIndex, TInt aParentId )
       
    91 	{
       
    92 	TBool buildlist = ETrue ;
       
    93 	TInt  prevId = 0;
       
    94 	TInt  arrCount = aIdsArray.Count();
       
    95 
       
    96 	for( TInt index = aIndex; index < arrCount &&  buildlist; ++index )
       
    97 		{
       
    98 		CLiwDefaultMap* map = CLiwDefaultMap::NewLC();
       
    99 
       
   100 		if( aParentId == aIdsArray[index].Parent() )
       
   101 			{
       
   102 			buildlist = ETrue;
       
   103 			// Build Map
       
   104 			BuildMapL( aIdsArray[index], iRequiredAttributes,
       
   105 						iIgnoredAttributes, map );
       
   106 			aList.AppendL(TLiwVariant(map));
       
   107 
       
   108 			}
       
   109 		else
       
   110 			{
       
   111 			if( prevId ==  aIdsArray[index].Parent() )
       
   112 				{
       
   113 				// Recursive Child List
       
   114 				CLiwDefaultList *childlist = CLiwDefaultList::NewL();
       
   115 				CleanupStack::PushL( childlist );
       
   116 				// Build Child List
       
   117 				BuildTreeListL( aIdsArray, *childlist, index, aIdsArray[index].Parent() );
       
   118 				InsertChildListL(aList, childlist);
       
   119 				CleanupStack::Pop( childlist );
       
   120 				childlist->DecRef();
       
   121 				}
       
   122 			else
       
   123 				{
       
   124 				// Return from recursive list
       
   125 				buildlist = EFalse;
       
   126 				aIndex = index-1;
       
   127 				}
       
   128 			}
       
   129 
       
   130 
       
   131 		prevId = aIdsArray[index].Id();
       
   132 
       
   133 		CleanupStack::PopAndDestroy( map );
       
   134 		}
       
   135 	}
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // Insert Children list to last item in tree list
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CMcsGetlistTreeCreator::InsertChildListL(CLiwDefaultList& aList,
       
   142 		CLiwDefaultList* aChildList)
       
   143 	{
       
   144 	TInt index = aList.Count() - 1;
       
   145 
       
   146 	// Get last item from aList
       
   147 	TLiwVariant livVar;
       
   148 	livVar.PushL();
       
   149 	aList.AtL(index, livVar);
       
   150 	CLiwDefaultMap* map = CLiwDefaultMap::NewLC();
       
   151 	livVar.Get(*map);
       
   152 
       
   153 	// Insert children list to that item
       
   154 	map->InsertL(KChildren, TLiwVariant(aChildList));
       
   155 
       
   156 	// Remove last item form a list and add a new one
       
   157 	aList.Remove(index);
       
   158 	aList.AppendL(TLiwVariant(map) );
       
   159 
       
   160 	CleanupStack::Pop(map);
       
   161 	map->DecRef();
       
   162 	CleanupStack::PopAndDestroy(&livVar);
       
   163 	}
       
   164 //  End of File