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