email/imum/Utils/Src/ImumInSettingsDataAttribute.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  ImumInSettingsDataAttribute.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 
       
    22 #include "ImumInSettingsDataAttribute.h"
       
    23 #include "ImumInSettingsDataCtrl.h"
       
    24 #include "ImumUtilsLogging.h"
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // CImumInSettingsDataAttribute::NewL()
       
    30 // ----------------------------------------------------------------------------
       
    31 //
       
    32 CImumInSettingsDataAttribute* CImumInSettingsDataAttribute::NewL(
       
    33     const TUint aAttributeId,
       
    34     const TInt aAttributeType,
       
    35     const TUint aAttributeSize,
       
    36     const TAny* aAttributeValue,
       
    37     const TAny* aAttributeDefault )
       
    38     {
       
    39     CImumInSettingsDataAttribute* self = NewLC(
       
    40         aAttributeId,
       
    41         aAttributeType,
       
    42         aAttributeSize,
       
    43         aAttributeValue,
       
    44         aAttributeDefault );
       
    45     CleanupStack::Pop( self );
       
    46 
       
    47     return self;
       
    48     }
       
    49 
       
    50 // ----------------------------------------------------------------------------
       
    51 // CImumInSetting::NewLC()
       
    52 // ----------------------------------------------------------------------------
       
    53 //
       
    54 CImumInSettingsDataAttribute* CImumInSettingsDataAttribute::NewLC(
       
    55     const TUint aAttributeId,
       
    56     const TInt aAttributeType,
       
    57     const TUint aAttributeSize,
       
    58     const TAny* aAttributeValue,
       
    59     const TAny* aAttributeDefault )
       
    60     {
       
    61     CImumInSettingsDataAttribute* self =
       
    62         new ( ELeave ) CImumInSettingsDataAttribute();
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL(
       
    65         aAttributeId,
       
    66         aAttributeType,
       
    67         aAttributeSize,
       
    68         aAttributeValue,
       
    69         aAttributeDefault );
       
    70 
       
    71     return self;
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // CImumInSettingsDataAttribute::CImumInSettingsDataAttribute()
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 CImumInSettingsDataAttribute::CImumInSettingsDataAttribute()
       
    79     :
       
    80     iType( 0 ),
       
    81     iSize( 0 ),
       
    82     iValue( NULL ),
       
    83     iDefault( NULL )
       
    84     {
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // CImumInSettingsDataAttribute::~CImumInSettingsDataAttribute()
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 CImumInSettingsDataAttribute::~CImumInSettingsDataAttribute()
       
    92     {
       
    93     Cleanup();
       
    94     iValue = NULL;
       
    95     iDefault = NULL;
       
    96     }
       
    97 
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // CImumInSettingsDataAttribute::ConstructL()
       
   101 // ----------------------------------------------------------------------------
       
   102 //
       
   103 void CImumInSettingsDataAttribute::ConstructL(
       
   104     const TUint aAttributeId,
       
   105     const TInt aAttributeType,
       
   106     const TUint aAttributeSize,
       
   107     const TAny* aAttributeValue,
       
   108     const TAny* aAttributeDefault )
       
   109     {
       
   110     SetAttributeL(
       
   111         aAttributeId,
       
   112         aAttributeType,
       
   113         aAttributeSize,
       
   114         aAttributeValue,
       
   115         aAttributeDefault );
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CImumInSettingsDataAttribute::Cleanup()
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CImumInSettingsDataAttribute::Cleanup()
       
   123     {
       
   124     // Delete attribute data accoding to its type
       
   125     if ( ImumInSettingsDataCtrl::IsText( iType ) )
       
   126         {
       
   127         DeleteText();
       
   128         }
       
   129     else if ( iType == ECmpTInt64 )
       
   130         {
       
   131         DeleteNumber<TInt64>();
       
   132         }
       
   133     else
       
   134         {
       
   135         DeleteNumber<TInt>();
       
   136         }
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CImumInSettingsDataAttribute::DeleteText()
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CImumInSettingsDataAttribute::DeleteText()
       
   144     {
       
   145     // Doing the deletion. Both value and default must be deleted from
       
   146     // the memory as both of the items are objects.
       
   147     if ( iType == ECmpNormal )
       
   148         {
       
   149         delete reinterpret_cast<HBufC*>( iValue );
       
   150         delete reinterpret_cast<HBufC*>( iDefault );
       
   151         }
       
   152     else if ( iType == ECmpNormal8 )
       
   153         {
       
   154         delete reinterpret_cast<HBufC8*>( iValue );
       
   155         delete reinterpret_cast<HBufC8*>( iDefault );
       
   156         }
       
   157     else
       
   158         {
       
   159         // This just can't simply happen, since it would be a number
       
   160         }
       
   161 
       
   162     iValue = NULL;
       
   163     iDefault = NULL;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CImumInSettingsDataAttribute::SetAttributeL()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CImumInSettingsDataAttribute::SetAttributeL(
       
   171     const TUint aAttributeId,
       
   172     const TInt aAttributeType,
       
   173     const TUint aAttributeSize,
       
   174     const TAny* aAttributeValue,
       
   175     const TAny* aAttributeDefault )
       
   176     {
       
   177     // Make sure that previous item is cleaned up
       
   178     Cleanup();
       
   179 
       
   180     iId     = aAttributeId;
       
   181     iType   = aAttributeType;
       
   182     iSize   = aAttributeSize;
       
   183 
       
   184     AllocL( aAttributeValue, aAttributeDefault );
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CImumInSettingsDataAttribute::AllocL()
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CImumInSettingsDataAttribute::AllocL(
       
   192     const TAny* aValue,
       
   193     const TAny* aDefault )
       
   194     {
       
   195     // Allocate data only if the values contains valid information
       
   196     if ( aValue && aDefault )
       
   197         {
       
   198         // Create copy of the text
       
   199         if ( ImumInSettingsDataCtrl::IsText( iType ) )
       
   200             {
       
   201             iValue = reinterpret_cast<const TDes*>( aValue )->AllocL();
       
   202             iDefault = reinterpret_cast<const TDes*>( aDefault )->AllocL();
       
   203             }
       
   204         else if ( iType == ECmpTInt64 )
       
   205             {
       
   206             DoAllocL<TInt64>( aValue, aDefault );
       
   207             }
       
   208         else
       
   209             {
       
   210             DoAllocL<TInt>( aValue, aDefault );
       
   211             }
       
   212         }
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // CImumInSettingsDataAttribute::CloneL()
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 CImumInSettingsDataAttribute* CImumInSettingsDataAttribute::CloneL()
       
   220     {
       
   221     return NewL( iId, iType, iSize, iValue, iDefault );
       
   222     }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // CImumInSettingsDataAttribute::Copy()
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void CImumInSettingsDataAttribute::Copy(
       
   229     const CImumInSettingsDataAttribute& aAttribute )
       
   230     {
       
   231     TRAP_IGNORE( SetAttributeL(
       
   232         aAttribute.iId,
       
   233         aAttribute.iType,
       
   234         aAttribute.iSize,
       
   235         aAttribute.iValue,
       
   236         aAttribute.iDefault ) );
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CImumInSettingsDataAttribute::Reset()
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CImumInSettingsDataAttribute::Reset()
       
   244     {
       
   245     // Copy the value in the
       
   246     if ( iType == ECmpNormal )
       
   247         {
       
   248         // Only copy if the descriptor contents differ
       
   249         if( reinterpret_cast<TDes*>( iValue )->Compare(
       
   250         		*reinterpret_cast<TDesC*>( iDefault ) ) )
       
   251         	reinterpret_cast<TDes*>( iValue )->Copy(
       
   252         			*reinterpret_cast<TDesC*>( iDefault ) );
       
   253         }
       
   254     else if ( iType == ECmpNormal8 )
       
   255         {
       
   256         // Only copy if the descriptor contents differ
       
   257         if( reinterpret_cast<TDes8*>( iValue )->Compare(
       
   258         		*reinterpret_cast<TDesC8*>( iDefault ) ) )
       
   259         	reinterpret_cast<TDes8*>( iValue )->Copy(
       
   260         			*reinterpret_cast<TDesC8*>( iDefault ) );
       
   261         }
       
   262     else
       
   263         {
       
   264         memmove( iValue, iDefault, iSize );
       
   265         }
       
   266     }
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // CImumInSettingsDataAttribute::operator==()
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 TBool CImumInSettingsDataAttribute::operator==(
       
   273     const CImumInSettingsDataAttribute& aAttribute )
       
   274     {
       
   275     return ( iValue == aAttribute.iValue );
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CImumInSettingsDataAttribute::operator!=()
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 TBool CImumInSettingsDataAttribute::operator!=(
       
   283     const CImumInSettingsDataAttribute& aAttribute )
       
   284     {
       
   285     return ( iValue != aAttribute.iValue );
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CImumInSettingsDataAttribute::SetId()
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 void CImumInSettingsDataAttribute::SetId( const TUint aId )
       
   293     {
       
   294     iId = aId;
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // CImumInSettingsDataAttribute::IdCompare()
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 TBool CImumInSettingsDataAttribute::IdCompare(
       
   302     const CImumInSettingsDataAttribute& aLeft,
       
   303     const CImumInSettingsDataAttribute& aRight )
       
   304     {
       
   305     return ( aLeft.Id() == aRight.Id() );
       
   306     }
       
   307 
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // CImumInSettingsDataAttribute::Id()
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 TUint CImumInSettingsDataAttribute::Id() const
       
   314     {
       
   315     return iId;
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // CImumInSettingsDataAttribute::Type()
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 TInt CImumInSettingsDataAttribute::Type() const
       
   323     {
       
   324     return iType;
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CImumInSettingsDataAttribute::Log()
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 void CImumInSettingsDataAttribute::Log() const
       
   332     {
       
   333     IMUM_CONTEXT( CImumInSettingsDataAttribute::Log, 0, KLogDataAttr );
       
   334     IMUM_IN();
       
   335 
       
   336     IMUM0( 0, "------------------------------------------------------" );
       
   337     IMUM1( 0, "Attribute: 0x%x", this );
       
   338     IMUM1( 0, "Attribute ID: 0x%x", iId );
       
   339     IMUM1( 0, "Attribute type: 0x%x", iType );
       
   340     IMUM1( 0, "Attribute size: 0x%x", iSize );
       
   341     IMUM1( 0, "Attribute iValue; addr: 0x%x", iValue );
       
   342     IMUM1( 0, "Attribute iDefault; addr: 0x%x", iDefault );
       
   343     IMUM0( 0, "------------------------------------------------------" );
       
   344 
       
   345     IMUM_OUT();
       
   346     }
       
   347 
       
   348 
       
   349 // End of File