uiservicetab/vimpstdetailsviewplugin/src/cvimpstfieldproperty.cpp
changeset 0 5e5d6b214f4f
child 9 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:  a single field with type
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cvimpstfieldproperty.h"
       
    20 
       
    21 #include "cvimpstfieldpropertyarray.h"
       
    22 // From Virtual Phonebook
       
    23 #include <MVPbkFieldType.h>
       
    24 #include <MVPbkStoreContactField.h>
       
    25 #include "vimpstdetailsview.hrh"
       
    26 #include <MVPbkBaseContactField.h>
       
    27 #include <MVPbkContactFieldData.h>
       
    28 #include <MVPbkContactFieldTextData.h>
       
    29 #include <MVPbkContactFieldUriData.h>
       
    30 #include <MVPbkContactFieldDateTimeData.h>
       
    31 // System includes
       
    32 #include <barsread.h>
       
    33 
       
    34 _LIT(KColon,":");
       
    35 // --------------------------------------------------------------------------
       
    36 // CVIMPSTFieldProperty::CVIMPSTFieldProperty
       
    37 // --------------------------------------------------------------------------
       
    38 //    
       
    39 CVIMPSTFieldProperty::CVIMPSTFieldProperty( TInt aFieldId, TInt aIconId, TInt aMaxLength )
       
    40      :iFieldId( aFieldId ),
       
    41      iIconId( aIconId ),
       
    42      iMaxLength( aMaxLength)
       
    43      {
       
    44      }
       
    45 
       
    46 // --------------------------------------------------------------------------
       
    47 // CVIMPSTFieldProperty::~CVIMPSTFieldProperty
       
    48 // --------------------------------------------------------------------------
       
    49 //    
       
    50 CVIMPSTFieldProperty::~CVIMPSTFieldProperty()
       
    51     {
       
    52     delete iDefaultLabel;
       
    53     delete iFieldData;
       
    54     delete iField;
       
    55     }
       
    56 
       
    57 // --------------------------------------------------------------------------
       
    58 // CVIMPSTFieldProperty::ConstructL
       
    59 // --------------------------------------------------------------------------
       
    60 //    
       
    61 inline void CVIMPSTFieldProperty::ConstructL(const TDesC&  aDefaultLabel)
       
    62     {
       
    63     if( aDefaultLabel.Length() )
       
    64         {
       
    65         iDefaultLabel = aDefaultLabel.AllocL();
       
    66         }
       
    67     }
       
    68 // --------------------------------------------------------------------------
       
    69 // CVIMPSTFieldProperty::NewLC
       
    70 // --------------------------------------------------------------------------
       
    71 //    
       
    72 CVIMPSTFieldProperty* CVIMPSTFieldProperty::NewLC
       
    73         ( TInt aFieldId, TInt aIconId, TInt aMaxLength,  const TDesC&  aDefaultLabel )
       
    74     {
       
    75     CVIMPSTFieldProperty* self = new( ELeave ) CVIMPSTFieldProperty( aFieldId, aIconId, aMaxLength);
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL(aDefaultLabel);
       
    78     return self;
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CVIMPSTFieldProperty::IconId
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 TInt CVIMPSTFieldProperty::IconId() 
       
    86     {
       
    87     return iIconId;
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 // CVIMPSTFieldProperty::FieldId
       
    92 // --------------------------------------------------------------------------
       
    93 //
       
    94 TInt CVIMPSTFieldProperty::FieldId() 
       
    95     {
       
    96     if( iFieldId == EVIMPSTFieldIdImpp || 
       
    97     	iFieldId ==  EVIMPSTFieldIdEmailAddress|| 
       
    98     	iFieldId == EVIMPSTFieldIdEmailGen )
       
    99 	    {
       
   100 	    // these fields are map to one field
       
   101 	    return EVIMPSTFieldIdImpp;
       
   102 	    }
       
   103     return iFieldId;
       
   104     }
       
   105 // --------------------------------------------------------------------------
       
   106 // CVIMPSTFieldProperty::DefaultLabelL
       
   107 // --------------------------------------------------------------------------
       
   108 //
       
   109 const TDesC& CVIMPSTFieldProperty::DefaultLabelL() 
       
   110     {
       
   111    	if( iField && !iDefaultLabel )
       
   112 		{
       
   113 		iDefaultLabel = iField->FieldLabel().Left( iMaxLength ).AllocL();	
       
   114 		}
       
   115 		
       
   116     if( iDefaultLabel )
       
   117 	    {
       
   118 	    return 	*iDefaultLabel;
       
   119 	    }
       
   120 
       
   121     return  KNullDesC();
       
   122     }
       
   123 
       
   124 // --------------------------------------------------------------------------
       
   125 // CVIMPSTFieldProperty::SetFieldTextL
       
   126 // --------------------------------------------------------------------------
       
   127 //
       
   128 void CVIMPSTFieldProperty::SetFieldTextL(const TDesC& aText ) 
       
   129     {
       
   130     if( iFieldData )
       
   131 	    {
       
   132 	    delete iFieldData;
       
   133 	    iFieldData = NULL;	
       
   134 	    }
       
   135 	iFieldData = aText.AllocL();
       
   136     }
       
   137 // --------------------------------------------------------------------------
       
   138 // CVIMPSTFieldProperty::SetStoredFieldL
       
   139 // --------------------------------------------------------------------------
       
   140 //
       
   141 void CVIMPSTFieldProperty::SetStoredFieldL(MVPbkStoreContactField& aField ) 
       
   142     {
       
   143     iField = aField.CloneLC();
       
   144     CleanupStack::Pop();
       
   145 	}
       
   146 
       
   147 // --------------------------------------------------------------------------
       
   148 // CVIMPSTFieldProperty::FieldDataL
       
   149 // --------------------------------------------------------------------------
       
   150 //
       
   151 const TDesC& CVIMPSTFieldProperty::FieldDataL() 
       
   152     {
       
   153     if( iField && !iFieldData )
       
   154         {
       
   155         const MVPbkContactFieldData& fieldData = iField->FieldData();
       
   156         switch( fieldData.DataType() )
       
   157             {
       
   158             case EVPbkFieldStorageTypeText:
       
   159                 {
       
   160                 TPtrC text = MVPbkContactFieldTextData::Cast( fieldData ).Text();
       
   161                 iFieldData = text.AllocL();
       
   162                 break;
       
   163                 }
       
   164              case EVPbkFieldStorageTypeUri:
       
   165                 {
       
   166                 const MVPbkContactFieldUriData& uri = MVPbkContactFieldUriData::Cast(fieldData);
       
   167 
       
   168                 HBufC* user = uri.Uri().AllocLC();
       
   169                 TPtr userPtr( user->Des() );
       
   170                 TInt index = userPtr.Find( KColon );
       
   171                 if( index != KErrNotFound )
       
   172                     {
       
   173                     TInt length = userPtr.Length();
       
   174                     iFieldData = userPtr.Right( length - index - 1 ).AllocL();
       
   175                     CleanupStack::PopAndDestroy(); //user   
       
   176                     }
       
   177                 else
       
   178                     {
       
   179                     CleanupStack::Pop();// user
       
   180                     iFieldData = user;      
       
   181                     }
       
   182             
       
   183                 break;
       
   184                 }
       
   185              case EVPbkFieldStorageTypeDateTime:
       
   186                  {
       
   187                  const MVPbkContactFieldDateTimeData& dateData =
       
   188                  MVPbkContactFieldDateTimeData::Cast( fieldData );
       
   189                  TTime date = dateData.DateTime();
       
   190                  _LIT( KDateFormat, "%D%M%Y%/0%1%/1%2%/2%3%/3" );
       
   191                  const TInt KDateLength( 12 );
       
   192                  HBufC* dateStr = HBufC::NewLC( KDateLength );
       
   193                  TPtr datePtr( dateStr->Des() );
       
   194                  date.FormatL( datePtr, KDateFormat, TLocale() );
       
   195                  CleanupStack::Pop( dateStr );
       
   196                  iFieldData = dateStr;
       
   197                  break;
       
   198                  }
       
   199              default :
       
   200                 {
       
   201                 break;  
       
   202                 }  
       
   203             }
       
   204         }
       
   205     return iFieldData ? *iFieldData : KNullDesC();
       
   206     }
       
   207 
       
   208 	 
       
   209 // End of file