imservices/ossprotocoladaptation/src/search/csearchkeystore.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 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:  This class handles dynamic search label-key pair storing.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "csearchkeystore.h"
       
    20 #include "ossprotocolpluginlogger.h"
       
    21 
       
    22 /*!	/file
       
    23 *	/brief Implimentation of interfaces defined in csearchkeystore.h
       
    24 */
       
    25 
       
    26 /*!	/brief documented in the header file
       
    27 */
       
    28 CSearchKeyStore* CSearchKeyStore::NewL() 
       
    29 	{
       
    30 	LOGGER ( TXT("::CSearchKeyStore NewL Start") );		
       
    31 	
       
    32 	CSearchKeyStore* self = new ( ELeave ) CSearchKeyStore;
       
    33 	
       
    34 	CleanupStack::PushL( self );
       
    35 	self->ConstructL();
       
    36 	CleanupStack::Pop( self );
       
    37 	
       
    38 	
       
    39 	LOGGER ( TXT("::CSearchKeyStore NewL End") );		
       
    40 	return self;
       
    41 	
       
    42 	}
       
    43 
       
    44 /*!	/brief documented in the header file
       
    45 */	
       
    46 CSearchKeyStore::CSearchKeyStore()	
       
    47 	{
       
    48 		
       
    49 	}	
       
    50 
       
    51 /*!	/brief documented in the header file
       
    52 */
       
    53 CSearchKeyStore::~CSearchKeyStore()
       
    54 	{
       
    55 	LOGGER ( TXT("::CSearchKeyStore ~CSearchKeyStore Start") );	
       
    56 		
       
    57 	//Close the hash map
       
    58 	//<todo> any leaks here?
       
    59 	iEnumLabels.Close();
       
    60 	
       
    61 	//<todo> any leaks here?
       
    62 	//Close the hash map
       
    63 	iSupportedLabels.Close();
       
    64 
       
    65 	
       
    66 	//reset and destroy
       
    67 	iNotSupportedLabels.ResetAndDestroy();
       
    68 	
       
    69 	delete iLabelKeyHashRep;
       
    70 	
       
    71 	LOGGER ( TXT("::CSearchKeyStore ~CSearchKeyStore End") );		
       
    72 	}
       
    73 	
       
    74 /*!	/brief documented in the header file
       
    75 */
       
    76 void CSearchKeyStore::MapLabelsToEnumL( RPointerArray<TDesC>& aLabels )
       
    77 	{
       
    78 	LOGGER ( TXT("::CSearchKeyStore MapLabelsToEnum Start") );	
       
    79 	
       
    80 	RArray<TBool> enumBool;
       
    81 	//TO avoid excessive computation, we mark enumBool[i] if 
       
    82 	//a label is already attched to that enum
       
    83 	for ( TInt i = 0; i < iEnumLabels.Count(); i++ )
       
    84 		{
       
    85 		//unmark all of it
       
    86 		enumBool.Append( 0 );
       
    87 		}
       
    88 		
       
    89 	for ( TInt i = 0; i < aLabels.Count(); i++ )
       
    90 		{
       
    91 		//Boolean to say if the label we are matching is supported
       
    92 		TBool supported = EFalse;
       
    93 		
       
    94 		//Iterate thru the hash table of cenrep labels
       
    95 		THashMapIter<TInt, TPtr16> iter( iEnumLabels );
       
    96 		//Initialize to 0
       
    97 		TInt j = 0;
       
    98 		//Loop till thr is a key
       
    99 		while( NULL != iter.NextKey() )
       
   100 			{
       
   101 			//Check if a label has been assigned to the enum
       
   102 			if ( enumBool[j] )
       
   103 				{
       
   104 				j++;
       
   105 				continue;
       
   106 				}
       
   107 			//If not
       
   108 			//Get the possible labels for this enum from cen rep
       
   109 			TPtr16 bufPtr = *(iter.CurrentValue());
       
   110 			
       
   111 			TBuf<1024> buf;
       
   112 			//LC is not leaving/cleanup
       
   113 			//It converts the aLabels to lower case 
       
   114 			buf.CopyLC( *( aLabels[i] ) );
       
   115 			
       
   116 			//Match if the current label from isoserver is in the enum labels
       
   117 			TInt match = bufPtr.Find( buf );
       
   118 			
       
   119 			if ( KErrNotFound != match )
       
   120 				{
       
   121 				//If a match is found, mark the corresponding enum 
       
   122 				enumBool[j]	= 1;			
       
   123 				TSearchKey enumvalue = ( TSearchKey )*( iter.CurrentKey() );
       
   124 				//Add to supported labels hash key and label
       
   125 				iSupportedLabels.InsertL( enumvalue, 
       
   126 							aLabels[i]->AllocL()->Des() );
       
   127 				//Set the flag as supported, so that it is not added in
       
   128 				//not supported label
       
   129 				supported = ETrue;
       
   130 				//Break from the loop
       
   131 				//Get next label try to match to the cen rep labels(supported enums)
       
   132 				break;
       
   133 				}			
       
   134 			//update the enum index tracker		
       
   135 			j++;
       
   136 			}
       
   137 		//If the label has not matched to any of the supported enum labels
       
   138 		//add that to not supported list
       
   139 		if ( EFalse == supported ) 
       
   140 			{
       
   141 			//Add to not supported labels				
       
   142 			iNotSupportedLabels.Append( ( aLabels[i]->AllocL() ) );		
       
   143 			}
       
   144 			
       
   145 		
       
   146 		}
       
   147 		
       
   148 	LOGGER ( TXT("::CSearchKeyStore MapLabelsToEnum End") );		
       
   149 	}
       
   150 
       
   151 /*!	/brief documented in the header file
       
   152 */	
       
   153 HBufC* CSearchKeyStore::GetLabelFromEnumL( TSearchKey aEnum )
       
   154 	{
       
   155 	LOGGER ( TXT("::CSearchKeyStore GetLabelFromEnum Start") );	
       
   156 	
       
   157 	TPtr* buf = NULL;
       
   158 	//Find if the labels corresponding to enum is there
       
   159 	//and return the alloced label.
       
   160 	//Ownership is transfered to the callee
       
   161 	buf = iSupportedLabels.Find( aEnum );
       
   162 	if ( buf )	
       
   163 		{
       
   164 		return buf->AllocL();
       
   165 		}
       
   166 		
       
   167 	LOGGER ( TXT("::CSearchKeyStore GetLabelFromEnum End") );
       
   168 		
       
   169 	return NULL;
       
   170 	
       
   171 	}
       
   172 
       
   173 /*!	/brief documented in the header file
       
   174 */	
       
   175 void CSearchKeyStore::ConstructL()	
       
   176 	{
       
   177 	LOGGER ( TXT("::CSearchKeyStore ConstructL Start") );
       
   178 	
       
   179 	iLabelKeyHashRep = CRepository::NewL( KLabelKeyStoreHash );
       
   180 	TBuf<1024> buf;
       
   181 	
       
   182 	//Read all the labels supported for localization from cen rep
       
   183 	//and have a map for the enum and search field
       
   184 	for ( TInt i = 0; i < NO_OF_KEYS_SUPPORTED; i++ ) 
       
   185 		{
       
   186 		iLabelKeyHashRep->Get( ( TSearchKey )( i ), buf );
       
   187 		iEnumLabels.InsertL( ( TSearchKey )( EUserFirstName + i ), buf.AllocL()->Des() );
       
   188 		}
       
   189 		
       
   190 	LOGGER ( TXT("::CSearchKeyStore ConstructL End") );	
       
   191 	}
       
   192 /*!	/brief Get the supported enums
       
   193 *	/return An array of pointers to the supported enums
       
   194 */
       
   195 RPointerArray<TSearchKey> CSearchKeyStore::GetSupportedEnums()
       
   196 	{
       
   197 	LOGGER ( TXT("::CSearchKeyStore GetSupportedEnums Start") );
       
   198 	
       
   199 	RPointerArray<TSearchKey> supportedEnums;
       
   200 	THashMapIter<TInt, TPtr16> iter( iSupportedLabels );
       
   201 	
       
   202 	while ( NULL != iter.NextKey() )
       
   203 		{
       
   204 		
       
   205 		supportedEnums.Append( ( TSearchKey* )iter.CurrentKey() );
       
   206 		
       
   207 		}
       
   208 		
       
   209 	LOGGER ( TXT("::CSearchKeyStore GetSupportedEnums End") );
       
   210 	
       
   211 	return supportedEnums;
       
   212 		
       
   213 	}
       
   214 
       
   215 /*!	/brief This function returns a handle to the array of not
       
   216 *	supported label strings. Not supported here means that
       
   217 *	there are no logical strings in UI for these labels
       
   218 *	/return const handle to not supported strings
       
   219 */
       
   220 
       
   221 const RPointerArray<TDesC> CSearchKeyStore::GetNotSupportedLabels()
       
   222 	{
       
   223 	LOGGER ( TXT("::CSearchKeyStore GetNotSupportedLabels Start") );
       
   224 	
       
   225 	return iNotSupportedLabels;		
       
   226 	}
       
   227 //End of file