uiservicetab/vimpstui/src/cvimpstuisearchfieldarray.cpp
branchRCL_3
changeset 28 3104fc151679
parent 27 2b7283837edb
child 29 9a48e301e94b
equal deleted inserted replaced
27:2b7283837edb 28:3104fc151679
     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:  search fields array implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cvimpstuisearchfieldaray.h"
       
    20 
       
    21 #include "mvimpstsearchuibuilder.h"
       
    22 #include "cvimpstuisearchfield.h"
       
    23 
       
    24 // System includes
       
    25 #include <barsread.h>
       
    26 #include <coemain.h>
       
    27 #include <eikcapc.h>
       
    28 #include <eikedwin.h>
       
    29 #include <AknUtils.h>
       
    30 #include "uiservicetabtracer.h"
       
    31 
       
    32 // --------------------------------------------------------------------------
       
    33 // CVIMPSTUiSearchFieldArray::CVIMPSTUiSearchFieldArray
       
    34 // --------------------------------------------------------------------------
       
    35 //
       
    36 inline CVIMPSTUiSearchFieldArray::CVIMPSTUiSearchFieldArray():
       
    37 	 iSelectedSearchType( EIMBasicSearch )
       
    38     {
       
    39     }
       
    40 
       
    41 // --------------------------------------------------------------------------
       
    42 // CVIMPSTUiSearchFieldArray::~CVIMPSTUiSearchFieldArray
       
    43 // --------------------------------------------------------------------------
       
    44 //
       
    45 CVIMPSTUiSearchFieldArray::~CVIMPSTUiSearchFieldArray()
       
    46     {
       
    47     iFieldArray.ResetAndDestroy();
       
    48     }
       
    49 
       
    50 // --------------------------------------------------------------------------
       
    51 // CVIMPSTUiSearchFieldArray::NewL
       
    52 // --------------------------------------------------------------------------
       
    53 //
       
    54 CVIMPSTUiSearchFieldArray* CVIMPSTUiSearchFieldArray::NewL()
       
    55     {
       
    56     CVIMPSTUiSearchFieldArray* self = 
       
    57         new ( ELeave ) CVIMPSTUiSearchFieldArray( );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // --------------------------------------------------------------------------
       
    65 // CVIMPSTUiSearchFieldArray::ConstructL
       
    66 // --------------------------------------------------------------------------
       
    67 //
       
    68 inline void CVIMPSTUiSearchFieldArray::ConstructL()
       
    69     {
       
    70     
       
    71     }
       
    72     
       
    73 // --------------------------------------------------------------------------
       
    74 // CVIMPSTUiSearchFieldArray::CreateFieldsFromContactL
       
    75 // --------------------------------------------------------------------------
       
    76 //
       
    77 TInt CVIMPSTUiSearchFieldArray::CreateFieldsL( const TDesC& aLebal, 
       
    78 											TVIMPSTSearchDataFieldType aFieldDataType ,
       
    79 											TIMPSTSearchFieldTypes aFieldType /*= EIMAdvancedSearch*/, 
       
    80 											TVIMPSTEnums::TVIMPSTSearchKey aSearchKey/* = EVIMPSTSearchKeyUknown*/  )
       
    81     {
       
    82 	TRACER_AUTO;
       
    83     MVIMPSTUiSearchField* newField = CVIMPSTUiSearchField::NewL( aLebal, aFieldDataType, aFieldType , aSearchKey);
       
    84     
       
    85     iFieldArray.Append( newField ); // ownership to array
       
    86     
       
    87 	return newField->ControlId();
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 // CVIMPSTUiSearchFieldArray::InsertFieldsL
       
    92 // --------------------------------------------------------------------------
       
    93 //
       
    94 TInt CVIMPSTUiSearchFieldArray::InsertFieldsL(TInt aIndex, const TDesC& aLebal, 
       
    95 											TVIMPSTSearchDataFieldType aFieldDataType ,
       
    96 											TIMPSTSearchFieldTypes aFieldType /*= EIMAdvancedSearch*/, 
       
    97 											TVIMPSTEnums::TVIMPSTSearchKey aSearchKey/* = EVIMPSTSearchKeyUknown*/ )
       
    98     {
       
    99 	TRACER_AUTO;
       
   100     MVIMPSTUiSearchField* newField = CVIMPSTUiSearchField::NewL( aLebal, aFieldDataType, aFieldType, aSearchKey );
       
   101     
       
   102     iFieldArray.InsertL( newField ,aIndex); // ownership to array
       
   103     
       
   104 	return newField->ControlId();
       
   105     }
       
   106 // --------------------------------------------------------------------------
       
   107 // CVIMPSTUiSearchFieldArray::AreAllUiFieldsEmpty
       
   108 // --------------------------------------------------------------------------
       
   109 //
       
   110 TBool CVIMPSTUiSearchFieldArray::AreAllUiFieldsEmpty() const
       
   111     {
       
   112 	TRACER_AUTO;
       
   113     const TInt count = iFieldArray.Count();
       
   114     
       
   115     for(TInt i = 0; i < count; ++i)
       
   116         {        
       
   117         TPtrC text = iFieldArray[i]->FieldData() ;
       
   118         if ( text.Length() > 0)
       
   119             {
       
   120             return EFalse;
       
   121             }
       
   122         
       
   123         }
       
   124     return ETrue;
       
   125     }
       
   126 
       
   127 // --------------------------------------------------------------------------
       
   128 // CVIMPSTUiSearchFieldArray::AreAllUiControlsEmptyL
       
   129 // --------------------------------------------------------------------------
       
   130 //
       
   131 TBool CVIMPSTUiSearchFieldArray::AreAllUiControlsEmptyL() const
       
   132     {
       
   133 	TRACER_AUTO;
       
   134     const TInt count = iFieldArray.Count();
       
   135     
       
   136     for(TInt i = 0; i < count; ++i)
       
   137         {        
       
   138         HBufC* text = iFieldArray[i]->ControlTextL() ;
       
   139         if ( text && text->Length() )
       
   140             {
       
   141             return EFalse;
       
   142             }
       
   143         
       
   144         }
       
   145     return ETrue;
       
   146     }
       
   147 
       
   148 // --------------------------------------------------------------------------
       
   149 // CVIMPSTUiSearchFieldArray::ResetFieldData
       
   150 // --------------------------------------------------------------------------
       
   151 //
       
   152 void CVIMPSTUiSearchFieldArray::ResetFieldData() 
       
   153     {
       
   154 	TRACER_AUTO;
       
   155     const TInt count = iFieldArray.Count();
       
   156    
       
   157     for(TInt i = 0; i < count; ++i)
       
   158         {        
       
   159         TInt len = iFieldArray[i]->FieldData().Length() ;
       
   160         if ( len > 0)
       
   161             {
       
   162             iFieldArray[i]->ResetFieldData();
       
   163             }
       
   164         
       
   165         }
       
   166     
       
   167     }
       
   168 
       
   169 // --------------------------------------------------------------------------
       
   170 // CVIMPSTUiSearchFieldArray::CreateUiFieldsFromArrayL
       
   171 // --------------------------------------------------------------------------
       
   172 //
       
   173 void CVIMPSTUiSearchFieldArray::CreateUiFieldsFromArrayL(MVIMPSTSearchUiBuilder& aUiBuilder )
       
   174 	{
       
   175 	TRACER_AUTO;
       
   176 	iUiBuilder = NULL; 
       
   177 	iUiBuilder = &aUiBuilder;
       
   178 	
       
   179 	TInt count = Count();
       
   180 	
       
   181 	for( TInt i = 0 ; i< count; i++ )
       
   182 		{
       
   183 		MVIMPSTUiSearchField* field = iFieldArray[i];
       
   184 	
       
   185 		CreateUiFieldsL( *field );
       
   186 
       
   187 		}
       
   188 	}
       
   189 // --------------------------------------------------------------------------
       
   190 // CVIMPSTUiSearchFieldArray::CreateUiFieldsFromArrayL
       
   191 // --------------------------------------------------------------------------
       
   192 //
       
   193 void CVIMPSTUiSearchFieldArray::CreateUiFieldsL(MVIMPSTUiSearchField& aField )
       
   194 	{
       
   195 	TRACER_AUTO;
       
   196 	switch( aField.FieldDataType() )
       
   197 		{
       
   198 
       
   199 		case EVIMPSTEdwinNumber :
       
   200 			{
       
   201 			// if number field
       
   202 			break;
       
   203 			}
       
   204 		case EVIMPSTEdwinEmail :
       
   205 			{
       
   206 			// if email field
       
   207 			break;
       
   208 			}
       
   209 			
       
   210 		case EVIMPSTEdwinMobile:
       
   211 			{
       
   212 			// if mobile field
       
   213 			break;
       
   214 			}
       
   215 		case EVIMPSTEdwinText :
       
   216 		default:
       
   217 			{
       
   218 			// default field type is text 
       
   219 			// Create and insert a line in the dialog
       
   220 			iControl = NULL;
       
   221 			iCaptionedCtrl = NULL;
       
   222 			
       
   223 			iControl = static_cast<CEikEdwin*>(iUiBuilder->CreateLineL( aField.FieldLabel(), aField.ControlId(), EEikCtEdwin) );
       
   224 
       
   225 			// Control is now owned by the dialog
       
   226 			TInt maxFieldLength = 100 ;
       
   227 			AknEditUtils::ConstructEditingL(iControl, maxFieldLength,
       
   228 			maxFieldLength, EAknEditorTextCase | EAknEditorCharactersUpperCase
       
   229 			| EAknEditorCharactersLowerCase, EAknEditorAlignLeft,
       
   230 			ETrue, ETrue, EFalse);
       
   231 			
       
   232 			iControl->SetAknEditorCase(EAknEditorTextCase);
       
   233 		
       
   234 			// Place cursor to the end of the line
       
   235 			iControl->AddFlagToUserFlags(CEikEdwin::EJustAutoCurEnd);
       
   236 			
       
   237 			HBufC* previousdata = aField.FieldData().AllocLC();
       
   238 			iControl->SetTextL( previousdata );
       
   239 			CleanupStack::PopAndDestroy();// previousdata
       
   240 			aField.ResetFieldData();
       
   241 		
       
   242 			
       
   243 			// CreateTextViewL() is flagged as deprecated but if it is not 
       
   244 			// called here the ActivateL() below crashes sometimes.
       
   245 			iControl->CreateTextViewL();
       
   246 			iCaptionedCtrl = iUiBuilder->LineControl( aField.ControlId() );
       
   247 			iCaptionedCtrl->SetTakesEnterKey(ETrue);
       
   248 			aField.SetControl( iControl, iCaptionedCtrl ); // onerhip transferd here to field
       
   249 		
       
   250 			aField.ActivateL();
       
   251 			break;	
       
   252 			}
       
   253 		}
       
   254 	}
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CVIMPSTUiSearchFieldArray::SetFocusL
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CVIMPSTUiSearchFieldArray::SetFocusL(TInt aFieldIndex )
       
   261     {
       
   262 	TRACER_AUTO;
       
   263     if (aFieldIndex >= 0 && aFieldIndex < iFieldArray.Count() && iUiBuilder )
       
   264         {
       
   265         MVIMPSTUiSearchField& field = At( aFieldIndex);
       
   266         
       
   267         iUiBuilder->TryChangeFocusL( field.ControlId() );
       
   268         }
       
   269         
       
   270     }   
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CVIMPSTUiSearchFieldArray::GetFirstEnteredFieldDataL
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 TPtrC CVIMPSTUiSearchFieldArray::GetFirstEnteredFieldDataL()
       
   277     {
       
   278 	TRACER_AUTO;
       
   279     const TInt count = iFieldArray.Count();
       
   280     
       
   281     for(TInt i = 0; i < count; ++i)
       
   282         {        
       
   283         TPtrC text = iFieldArray[i]->FieldData() ;
       
   284         if ( text.Length() > 0)
       
   285             {
       
   286             return iFieldArray[i]->FieldData();
       
   287             }
       
   288         
       
   289         }
       
   290     return KNullDesC();
       
   291     }   
       
   292 
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CVIMPSTUiSearchFieldArray::GetSearchKeyDataL
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 void CVIMPSTUiSearchFieldArray::GetSearchKeyDataL(RArray<TVIMPSTSearchKeyData>& aKeyDataArray )
       
   299     {
       
   300 	TRACER_AUTO;
       
   301     const TInt count = iFieldArray.Count();
       
   302     TPtrC dataPtr(KNullDesC );
       
   303     for(TInt i = 0; i < count; ++i)
       
   304         {    
       
   305         MVIMPSTUiSearchField*  field = iFieldArray[i] ;
       
   306         TPtrC text = field->FieldData() ;
       
   307         if ( text.Length() > 0)
       
   308             {
       
   309 			if(field->GetSearchKey() != TVIMPSTEnums::EVIMPSTSearchKeyUknown )
       
   310 				{
       
   311 				 TVIMPSTSearchKeyData data = 	{
       
   312 								field->GetSearchKey(),
       
   313 								KNullDesC(),
       
   314 								text	
       
   315 								};
       
   316 				 
       
   317 				aKeyDataArray.Append(data);	
       
   318 				}
       
   319 			else
       
   320 				{
       
   321 				TPtrC label = field->FieldLabel() ;
       
   322 				TVIMPSTSearchKeyData data =	{
       
   323 								field->GetSearchKey(),
       
   324 								label,
       
   325 								text	
       
   326 								};
       
   327 			 	 aKeyDataArray.Append(data );
       
   328 			 				
       
   329 				}
       
   330             }
       
   331         
       
   332         }
       
   333     
       
   334     }   
       
   335  
       
   336   // -----------------------------------------------------------------------------
       
   337 // CVIMPSTUiSearchFieldArray::RemoveField
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 void CVIMPSTUiSearchFieldArray::RemoveField(TInt aIndex )
       
   341     {
       
   342    	iFieldArray.Remove(aIndex);
       
   343    	iFieldArray.Compress();
       
   344     }     
       
   345  
       
   346  // -----------------------------------------------------------------------------
       
   347 // CVIMPSTUiSearchFieldArray::InsertField
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CVIMPSTUiSearchFieldArray::InsertField(MVIMPSTUiSearchField*  aField , TInt aIndex )
       
   351     {
       
   352    	iFieldArray.Insert(aField ,aIndex);
       
   353     }     
       
   354   
       
   355 // -----------------------------------------------------------------------------
       
   356 // CVIMPSTUiSearchFieldArray::GetSearchType
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 TIMPSTSearchFieldTypes CVIMPSTUiSearchFieldArray::GetSearchType()
       
   360 	{
       
   361 	return iSelectedSearchType;
       
   362 	}
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CVIMPSTUiSearchFieldArray::SetSearchType
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 void CVIMPSTUiSearchFieldArray::SetSearchType(TIMPSTSearchFieldTypes aType)
       
   369 	{
       
   370 	iSelectedSearchType = aType;
       
   371 	}
       
   372   
       
   373 //  End of File