menucontentsrv/srvsrc/mcsgetlistcreatorinterface.cpp
branchRCL_3
changeset 23 ace62b58f4b2
parent 0 79c6a41cd166
equal deleted inserted replaced
22:1b207dd38b72 23:ace62b58f4b2
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <e32cmn.h>
    18 #include <e32cmn.h>
    19 #include <liwcommon.h>
    19 #include <liwcommon.h>
    20 #include <liwgenericparam.h>
    20 #include <liwgenericparam.h>
    21 #include "mcsgetlistcreatorinterface.h"
    21 #include "mcsgetlistcreatorinterface.h"
    22 #include "menusrveng.h"
    22 #include "menusrveng.h"
    23 
    23 
    24 _LIT( KMenuAttrSuiteName, "suite_name" );
       
    25 
       
    26 /**
       
    27  * Class for getting attributes for installed suite items
       
    28  * @since S60 v5.0
       
    29  */
       
    30 NONSHARABLE_CLASS( CMcsSuiteGetAttrStrategy ) :
       
    31 	public CMcsGetAttrStrategy
       
    32 	{
       
    33 public:
       
    34 
       
    35 	/**
       
    36 	 * Constructor.
       
    37 	 */
       
    38 	CMcsSuiteGetAttrStrategy( CMenuSrvEng& aEng );
       
    39 
       
    40 	/**
       
    41 	 * Destructor.
       
    42 	 */
       
    43 	virtual ~CMcsSuiteGetAttrStrategy();
       
    44 
       
    45 	/**
       
    46 	 * TODO: add comments
       
    47 	 */
       
    48 	void PrepareL(TInt aId);
       
    49 
       
    50 	/**
       
    51 	 * GetAttributeL.
       
    52 	 */
       
    53 	void GetAttributeL(const TDesC& aAttrName,
       
    54 		        TBool& aAttrExists, TDes& aAttrVal );
       
    55 
       
    56 private:
       
    57 	RBuf iSuiteName; ///< Name of a suite for actual strategy. Own.
       
    58 	};
       
    59 
       
    60 /**
       
    61  * Class for getting attributes for non suite items / not installed suite items
       
    62  * @since S60 v5.0
       
    63  */
       
    64 NONSHARABLE_CLASS( CMcsMainGetAttrStrategy ) :
       
    65 	public CMcsGetAttrStrategy
       
    66 	{
       
    67 public:
       
    68 
       
    69 	/**
       
    70 	 * Constructor.
       
    71 	 */
       
    72 	CMcsMainGetAttrStrategy ( CMenuSrvEng& aEng );
       
    73 
       
    74 	/**
       
    75 	 * TODO: add comments
       
    76 	 */
       
    77 	void PrepareL(TInt aId);
       
    78 
       
    79 	/**
       
    80 	 * GetAttributeL.
       
    81 	 */
       
    82 	void GetAttributeL(const TDesC& aAttrName,
       
    83 		        TBool& aAttrExists, TDes& aAttrVal );
       
    84 
       
    85 private:
       
    86 	TInt iId; ///< a id of an item for actual strategy.
       
    87 	};
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CMcsGetAttrStrategy::CMcsGetAttrStrategy
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 CMcsGetAttrStrategy::CMcsGetAttrStrategy( CMenuSrvEng& aEng ) :
       
    95 	iEng(aEng)
       
    96 	{
       
    97 	}
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CMcsGetAttrStrategy::~CMcsGetAttrStrategy
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 CMcsGetAttrStrategy::~CMcsGetAttrStrategy()
       
   105 	{
       
   106 	}
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // CMcsSuiteGetAttrStrategy::CMcsGetSuiteAttributeStrategy
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 CMcsSuiteGetAttrStrategy::CMcsSuiteGetAttrStrategy( CMenuSrvEng& aEng ) :
       
   113 	CMcsGetAttrStrategy(aEng)
       
   114 	{
       
   115 	}
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // CMcsSuiteGetAttrStrategy::~CMcsSuiteGetAttrStrategy
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 CMcsSuiteGetAttrStrategy::~CMcsSuiteGetAttrStrategy()
       
   122 	{
       
   123 	iSuiteName.Close();
       
   124 	}
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // CMcsSuiteGetAttrStrategy::Prepare
       
   128 // ---------------------------------------------------------
       
   129 //
       
   130 void CMcsSuiteGetAttrStrategy::PrepareL(TInt aId)
       
   131 	{
       
   132 	TBool suiteNameExists;
       
   133 	iSuiteName.Close();
       
   134 	iSuiteName.CreateL( KMenuMaxAttrValueLen );
       
   135 	iEng.GetAttributeL(aId, KMenuAttrSuiteName, suiteNameExists, iSuiteName);
       
   136 	}
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // CMcsSuiteGetAttrStrategy::GetAttributeL
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 void CMcsSuiteGetAttrStrategy::GetAttributeL(const TDesC& aAttrName,
       
   143         TBool& aAttrExists, TDes& aAttrVal )
       
   144 	{
       
   145 	iEng.GetSuiteAttribute(iSuiteName, aAttrName, aAttrExists, aAttrVal);
       
   146 	}
       
   147 
       
   148 // ---------------------------------------------------------
       
   149 // CMcsSuiteGetAttrStrategy::CMcsGetSuiteAttributeStrategy
       
   150 // ---------------------------------------------------------
       
   151 //
       
   152 CMcsMainGetAttrStrategy::CMcsMainGetAttrStrategy( CMenuSrvEng& aEng ) :
       
   153 	CMcsGetAttrStrategy(aEng)
       
   154 	{
       
   155 	}
       
   156 
       
   157 // ---------------------------------------------------------
       
   158 // CMcsMainGetAttrStrategy::Prepare
       
   159 // ---------------------------------------------------------
       
   160 //
       
   161 void CMcsMainGetAttrStrategy::PrepareL(TInt aId)
       
   162 	{
       
   163 	iId = aId;
       
   164 	}
       
   165 
       
   166 // ---------------------------------------------------------
       
   167 // CMcsGetSuiteAttributeStrategy::GetAttributeL
       
   168 // ---------------------------------------------------------
       
   169 //
       
   170 void CMcsMainGetAttrStrategy::GetAttributeL(const TDesC& aAttrName,
       
   171         TBool& aAttrExists, TDes& aAttrVal )
       
   172 	{
       
   173 	iEng.GetAttributeL (iId, aAttrName, aAttrExists, aAttrVal);
       
   174 	}
       
   175 
       
   176 // ---------------------------------------------------------
    24 // ---------------------------------------------------------
   177 // CMcsGetListCreatorInterface::~CMcsGetListCreatorInterface
    25 // CMcsGetListCreatorInterface::~CMcsGetListCreatorInterface
   178 // ---------------------------------------------------------
    26 // ---------------------------------------------------------
   179 //
    27 //
   180 CMcsGetListCreatorInterface::~CMcsGetListCreatorInterface()
    28 CMcsGetListCreatorInterface::~CMcsGetListCreatorInterface()
   181     {
    29     {
   182     delete iNormalGetter;
       
   183     delete iSuiteGetter;
       
   184     }
    30     }
   185 
    31 
   186 // ---------------------------------------------------------
    32 // ---------------------------------------------------------
   187 // CMcsGetListCreatorInterface::CMcsGetListCreatorInterface
    33 // CMcsGetListCreatorInterface::CMcsGetListCreatorInterface
   188 // ---------------------------------------------------------
    34 // ---------------------------------------------------------
   196 // CMcsGetListCreatorInterface::ConstructL
    42 // CMcsGetListCreatorInterface::ConstructL
   197 // ---------------------------------------------------------
    43 // ---------------------------------------------------------
   198 //
    44 //
   199 void CMcsGetListCreatorInterface::ConstructL()
    45 void CMcsGetListCreatorInterface::ConstructL()
   200     {
    46     {
   201     iActualGetter = NULL;
       
   202     iSuiteGetter = new(ELeave) CMcsSuiteGetAttrStrategy(iEng);
       
   203     iNormalGetter = new(ELeave) CMcsMainGetAttrStrategy(iEng);
       
   204     }
    47     }
   205 
    48 
   206 // ---------------------------------------------------------
    49 // ---------------------------------------------------------
   207 // CMcsGetListCreatorInterface::BuildMapL
    50 // CMcsGetListCreatorInterface::BuildMapL
   208 // ---------------------------------------------------------
    51 // ---------------------------------------------------------
   209 //
    52 //
   210 void CMcsGetListCreatorInterface::BuildMapL(
    53 void CMcsGetListCreatorInterface::BuildMapL(
   211 		const TMenuItem& aMenuItem, CDesC16Array* aRequiredAttributes,
    54 		const TMenuItem& aMenuItem, CDesC16Array* aRequiredAttributes,
   212 		CDesC16Array* aIgnoredAttributes, CLiwDefaultMap* aMap )
    55 		CDesC16Array* aIgnoredAttributes, CLiwDefaultMap* aMap )
   213 	{
    56 	{
   214 	SetGetterStrategyL( aMenuItem.Id() );
    57 	SetItemIdL( aMenuItem.Id() );
   215 	AddFundamentalAttributesL( aMenuItem, aMap );
    58 	AddFundamentalAttributesL( aMenuItem, aMap );
   216 
    59 
   217 	if( aRequiredAttributes->MdcaCount() &&
    60 	if( aRequiredAttributes->MdcaCount() &&
   218 			aIgnoredAttributes->MdcaCount() == KErrNone )
    61 			aIgnoredAttributes->MdcaCount() == KErrNone )
   219 	    {
    62 	    {
   298 	    if( aRequiredAttributes->MdcaPoint(i).Compare( running ) == KErrNone )
   141 	    if( aRequiredAttributes->MdcaPoint(i).Compare( running ) == KErrNone )
   299 	        {
   142 	        {
   300 	        if ( aMenuItem.Type() == KMenuTypeApp() ||
   143 	        if ( aMenuItem.Type() == KMenuTypeApp() ||
   301 	        		aMenuItem.Type() == KMenuTypeFolder() )
   144 	        		aMenuItem.Type() == KMenuTypeFolder() )
   302 	            {
   145 	            {
   303 	            iActualGetter->GetAttributeL( KRunningStatus, exists, attrvalue );
   146 	            iEng.GetAttributeL( iId, KRunningStatus, exists, attrvalue );
   304 	            aMap->InsertL( KRunning, TLiwVariant( exists ) );
   147 	            aMap->InsertL( KRunning, TLiwVariant( exists ) );
   305 	            }
   148 	            }
   306 	        }
   149 	        }
   307 	    else if( aRequiredAttributes->MdcaPoint(i).Compare( bitmap ) == KErrNone )
   150 	    else if( aRequiredAttributes->MdcaPoint(i).Compare( bitmap ) == KErrNone )
   308 	        {
   151 	        {
   312 	        {
   155 	        {
   313 	        findMask = ETrue;
   156 	        findMask = ETrue;
   314 	        }
   157 	        }
   315 	    else
   158 	    else
   316 	        {
   159 	        {
   317 	        iActualGetter->GetAttributeL(
   160             iEng.GetAttributeL(
   318 	        		aRequiredAttributes->MdcaPoint(i), exists, attrvalue );
   161                     iId, aRequiredAttributes->MdcaPoint(i), exists, attrvalue );
       
   162 
   319 	        if( exists )
   163 	        if( exists )
   320 	            {
   164 	            {
   321 	            TBuf8<KMenuMaxAttrNameLen> attrname;
   165 	            TBuf8<KMenuMaxAttrNameLen> attrname;
   322 	            attrname.Copy( aRequiredAttributes->MdcaPoint(i) );
   166 	            attrname.Copy( aRequiredAttributes->MdcaPoint(i) );
   323 	            aMap->InsertL( attrname, TLiwVariant( attrvalue ) );
   167 	            aMap->InsertL( attrname, TLiwVariant( attrvalue ) );
   353         {
   197         {
   354         TBuf<KMenuMaxAttrNameLen> running;
   198         TBuf<KMenuMaxAttrNameLen> running;
   355         running.Copy( KRunning );
   199         running.Copy( KRunning );
   356         if( aIgnoredAttributes->Find( running, pos ) != KErrNone )
   200         if( aIgnoredAttributes->Find( running, pos ) != KErrNone )
   357             {
   201             {
   358             iActualGetter->GetAttributeL(KRunningStatus, exists, attrvalue );
   202             iEng.GetAttributeL( iId, KRunningStatus, exists, attrvalue );
   359             aMap->InsertL( KRunning, TLiwVariant( exists ) );
   203             aMap->InsertL( KRunning, TLiwVariant( exists ) );
   360             }
   204             }
   361         }
   205         }
   362 
   206 
   363     RArray<TPtrC> attrNameList;
   207     RArray<TPtrC> attrNameList;
   366 
   210 
   367     for( TInt i = 0; i< attrNameList.Count(); i++ )
   211     for( TInt i = 0; i< attrNameList.Count(); i++ )
   368         {
   212         {
   369         if( aIgnoredAttributes->Find( attrNameList[i], pos ) != KErrNone )
   213         if( aIgnoredAttributes->Find( attrNameList[i], pos ) != KErrNone )
   370             {
   214             {
   371             iActualGetter->GetAttributeL(attrNameList[i], exists, attrvalue );
   215             iEng.GetAttributeL( iId, attrNameList[i], exists, attrvalue );
   372             if( exists )
   216             if( exists )
   373                 {
   217                 {
   374                 TBuf8<KMenuMaxAttrNameLen> attrname;
   218                 TBuf8<KMenuMaxAttrNameLen> attrname;
   375                 attrname.Copy( attrNameList[i] );
   219                 attrname.Copy( attrNameList[i] );
   376                 aMap->InsertL( attrname, TLiwVariant( attrvalue ) );
   220                 aMap->InsertL( attrname, TLiwVariant( attrvalue ) );
   423         if( aRequiredAttributes->MdcaPoint(i).Compare( running ) == KErrNone
   267         if( aRequiredAttributes->MdcaPoint(i).Compare( running ) == KErrNone
   424             && aIgnoredAttributes->Find( running, pos ) != KErrNone )
   268             && aIgnoredAttributes->Find( running, pos ) != KErrNone )
   425             {
   269             {
   426             if ( aMenuItem.Type() == KMenuTypeApp() || aMenuItem.Type() == KMenuTypeFolder() )
   270             if ( aMenuItem.Type() == KMenuTypeApp() || aMenuItem.Type() == KMenuTypeFolder() )
   427                 {
   271                 {
   428                 iActualGetter->GetAttributeL( KRunningStatus, exists, attrvalue );
   272                 iEng.GetAttributeL( iId, KRunningStatus, exists, attrvalue );
   429                 aMap->InsertL( KRunning, TLiwVariant( exists ) );
   273                 aMap->InsertL( KRunning, TLiwVariant( exists ) );
   430                 }
   274                 }
   431             }
   275             }
   432         else if( aRequiredAttributes->MdcaPoint(i).Compare( bitmap ) == KErrNone
   276         else if( aRequiredAttributes->MdcaPoint(i).Compare( bitmap ) == KErrNone
   433                 && aIgnoredAttributes->Find( bitmap, pos ) != KErrNone )
   277                 && aIgnoredAttributes->Find( bitmap, pos ) != KErrNone )
   439             {
   283             {
   440             findMask = ETrue;
   284             findMask = ETrue;
   441             }
   285             }
   442         else if( aIgnoredAttributes->Find( aRequiredAttributes->MdcaPoint(i), pos ) != KErrNone )
   286         else if( aIgnoredAttributes->Find( aRequiredAttributes->MdcaPoint(i), pos ) != KErrNone )
   443             {
   287             {
   444             iActualGetter->GetAttributeL( aRequiredAttributes->MdcaPoint(i), exists, attrvalue );
   288             iEng.GetAttributeL(
       
   289                     iId, aRequiredAttributes->MdcaPoint(i), exists, attrvalue );
   445             if( exists )
   290             if( exists )
   446                 {
   291                 {
   447                 TBuf8<KMenuMaxAttrNameLen> attrname;
   292                 TBuf8<KMenuMaxAttrNameLen> attrname;
   448                 attrname.Copy( aRequiredAttributes->MdcaPoint(i) );
   293                 attrname.Copy( aRequiredAttributes->MdcaPoint(i) );
   449                 aMap->InsertL( attrname, TLiwVariant( attrvalue ) );
   294                 aMap->InsertL( attrname, TLiwVariant( attrvalue ) );
   473 	CleanupClosePushL( attrvalue );
   318 	CleanupClosePushL( attrvalue );
   474 
   319 
   475 	if ( aMenuItem.Type() == KMenuTypeApp() ||
   320 	if ( aMenuItem.Type() == KMenuTypeApp() ||
   476 			aMenuItem.Type() == KMenuTypeFolder() )
   321 			aMenuItem.Type() == KMenuTypeFolder() )
   477 	    {
   322 	    {
   478         iActualGetter->GetAttributeL( KRunningStatus, exists, attrvalue );
   323         iEng.GetAttributeL( iId, KRunningStatus, exists, attrvalue );
   479         aMap->InsertL( KRunning, TLiwVariant( exists ) );
   324         aMap->InsertL( KRunning, TLiwVariant( exists ) );
   480 	    }
   325 	    }
   481 	RArray<TPtrC> attrNameList;
   326 	RArray<TPtrC> attrNameList;
   482 	CleanupClosePushL(attrNameList);
   327 	CleanupClosePushL(attrNameList);
   483     iEng.GetAttributeListL( aMenuItem.Id(), attrNameList );
   328     iEng.GetAttributeListL( aMenuItem.Id(), attrNameList );
   484 
   329 
   485 	for(TInt i = 0;i< attrNameList.Count();i++)
   330 	for(TInt i = 0;i< attrNameList.Count();i++)
   486 	    {
   331 	    {
   487 	    TBuf8<KMenuMaxAttrNameLen> attrname;
   332 	    TBuf8<KMenuMaxAttrNameLen> attrname;
   488 	    attrname.Copy( attrNameList[i] );
   333 	    attrname.Copy( attrNameList[i] );
   489         iActualGetter->GetAttributeL( attrNameList[i], exists, attrvalue );
   334         iEng.GetAttributeL( iId, attrNameList[i], exists, attrvalue );
   490 	    if(exists)
   335 	    if(exists)
   491 	        {
   336 	        {
   492 	        attrname.Copy(attrNameList[i]);
   337 	        attrname.Copy(attrNameList[i]);
   493 	        aMap->InsertL( attrname, TLiwVariant( attrvalue ) );
   338 	        aMap->InsertL( attrname, TLiwVariant( attrvalue ) );
   494 	        }
   339 	        }
   497    	FillIconAttributesMapL( aMenuItem, iconAttrMap );
   342    	FillIconAttributesMapL( aMenuItem, iconAttrMap );
   498    	aMap->InsertL( KIconAttributes, TLiwVariant( iconAttrMap ) );
   343    	aMap->InsertL( KIconAttributes, TLiwVariant( iconAttrMap ) );
   499    	CleanupStack::PopAndDestroy( iconAttrMap );
   344    	CleanupStack::PopAndDestroy( iconAttrMap );
   500 	CleanupStack::PopAndDestroy(&attrNameList);
   345 	CleanupStack::PopAndDestroy(&attrNameList);
   501 	CleanupStack::PopAndDestroy( &attrvalue );
   346 	CleanupStack::PopAndDestroy( &attrvalue );
   502 
       
   503 	}
   347 	}
   504 
   348 
   505 // ---------------------------------------------------------
   349 // ---------------------------------------------------------
   506 // CMcsGetListCreatorInterface::FillIconAttributesMapL
   350 // CMcsGetListCreatorInterface::FillIconAttributesMapL
   507 // ---------------------------------------------------------
   351 // ---------------------------------------------------------
   536 	TBool exists;
   380 	TBool exists;
   537 	TBuf8<KMenuMaxAttrNameLen> attrName;
   381 	TBuf8<KMenuMaxAttrNameLen> attrName;
   538 	RBuf attrvalue;
   382 	RBuf attrvalue;
   539     attrvalue.CreateL( KMenuMaxAttrValueLen );
   383     attrvalue.CreateL( KMenuMaxAttrValueLen );
   540 	CleanupClosePushL( attrvalue );
   384 	CleanupClosePushL( attrvalue );
   541 	iActualGetter->GetAttributeL(aAttrName, exists, attrvalue );
   385     iEng.GetAttributeL( iId, aAttrName, exists, attrvalue );
   542 	if ( exists )
   386 	if ( exists )
   543 		{
   387 		{
   544 		attrName.Copy( aAttrName );
   388 		attrName.Copy( aAttrName );
   545 		aMap->InsertL(attrName, TLiwVariant( attrvalue ) );
   389 		aMap->InsertL(attrName, TLiwVariant( attrvalue ) );
   546 		}
   390 		}
   549 
   393 
   550 // ---------------------------------------------------------
   394 // ---------------------------------------------------------
   551 // CMcsGetListCreatorInterface::SetGetterStrategyL
   395 // CMcsGetListCreatorInterface::SetGetterStrategyL
   552 // ---------------------------------------------------------
   396 // ---------------------------------------------------------
   553 //
   397 //
   554 void CMcsGetListCreatorInterface::SetGetterStrategyL(TInt aId)
   398 void CMcsGetListCreatorInterface::SetItemIdL( TInt aId )
   555 	{
   399 	{
   556 	TBool suiteNameExists;
   400 	iId = aId;
   557 	RBuf name;
       
   558 	name.CreateL( KMenuMaxAttrValueLen );
       
   559 	CleanupClosePushL( name );
       
   560 
       
   561 	iEng.GetAttributeL(aId, KMenuAttrSuiteName, suiteNameExists, name);
       
   562 	if (suiteNameExists && iEng.InstalledSuiteExist(name))
       
   563 		{
       
   564 		iActualGetter = iSuiteGetter;
       
   565 		}
       
   566 	else
       
   567 		{
       
   568 		iActualGetter = iNormalGetter;
       
   569 		}
       
   570 	iActualGetter->PrepareL(aId);
       
   571 	CleanupStack::PopAndDestroy(&name);
       
   572 	}
   401 	}
   573 //  End of File
   402 //  End of File