metadataengine/client/src/mdetextpropertycondition.cpp
changeset 0 c53acadfccc6
child 40 910a23996aa0
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2009 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 #include "mdetextpropertycondition.h"
       
    19 #include "mdcserializationbuffer.h"
       
    20 #include "mdepropertydef.h"
       
    21 #include "mdcquery.h"
       
    22 
       
    23 CMdETextPropertyCondition* 
       
    24 CMdETextPropertyCondition::NewL(const CMdEPropertyDef& aPropertyDef,
       
    25                                 TTextPropertyConditionCompareMethod aCompareMethod,
       
    26                                 const TDesC& aText)
       
    27     {
       
    28     CMdETextPropertyCondition* self = NewLC(aPropertyDef, aCompareMethod, aText);
       
    29     CleanupStack::Pop(self);
       
    30     return self;
       
    31     }
       
    32 
       
    33 
       
    34 CMdETextPropertyCondition* 
       
    35 CMdETextPropertyCondition::NewLC(const CMdEPropertyDef& aPropertyDef,
       
    36                                  TTextPropertyConditionCompareMethod aCompareMethod,
       
    37                                  const TDesC& aText)
       
    38     {
       
    39     CMdETextPropertyCondition* self 
       
    40         = new(ELeave) CMdETextPropertyCondition(aPropertyDef, aCompareMethod);
       
    41     CleanupStack::PushL(self);
       
    42     self->ConstructL(aText);
       
    43     return self;
       
    44     }
       
    45 
       
    46 
       
    47 CMdETextPropertyCondition::CMdETextPropertyCondition(const CMdEPropertyDef& aPropertyDef, 
       
    48                                                      TTextPropertyConditionCompareMethod aCompareMethod)
       
    49         : CMdEPropertyCondition(EConditionTypePropertyText, aPropertyDef), 
       
    50           iCompareMethod(aCompareMethod)
       
    51     {
       
    52     }
       
    53 
       
    54 
       
    55 void CMdETextPropertyCondition::ConstructL(const TDesC& aText)
       
    56     {
       
    57     // Make a copy of the string.
       
    58     iText = aText.AllocL();
       
    59     }
       
    60 
       
    61 
       
    62 CMdETextPropertyCondition::~CMdETextPropertyCondition()
       
    63 	{
       
    64     delete iText;
       
    65 	}
       
    66 
       
    67 TUint32 CMdETextPropertyCondition::InternalQueryOptimizationFlags(TUint32& aFlags)
       
    68 	{
       
    69 	return CMdEPropertyCondition::InternalQueryOptimizationFlags(aFlags);
       
    70 	}
       
    71 
       
    72 TUint32 CMdETextPropertyCondition::RequiredBufferSize() const
       
    73 	{
       
    74 	// Required size for property condition
       
    75 	TUint32 bufferSize = sizeof( TMdCPropertyCondition );
       
    76 
       
    77 	// Required size for compare method (TUint32) and text
       
    78 	bufferSize += CMdCSerializationBuffer::KRequiredSizeForTUint32;
       
    79 	bufferSize += CMdCSerializationBuffer::RequiredSize( *iText );
       
    80 
       
    81 	return bufferSize;
       
    82 	}
       
    83 
       
    84 void CMdETextPropertyCondition::SerializeL(CMdCSerializationBuffer& aBuffer,
       
    85 		TMdCOffset& aFreespaceOffset) const
       
    86 	{
       
    87 	TMdCPropertyCondition property;
       
    88 
       
    89 	property.iConditionType = iType;
       
    90 	property.iNegated = iNegated;
       
    91 	property.iObjectDefId = iPropertyDef.ObjectDefId();
       
    92 	property.iPropertyDefId = iPropertyDef.Id();
       
    93 	property.iCondition = aBuffer.Position() + sizeof( TMdCPropertyCondition );
       
    94 
       
    95 	property.SerializeL( aBuffer );
       
    96 
       
    97 	aBuffer.InsertL( (TUint32)iCompareMethod );
       
    98 	aBuffer.InsertL( *iText );
       
    99 
       
   100 	aFreespaceOffset = aBuffer.Position();
       
   101 	}
       
   102 
       
   103 const TDesC& CMdETextPropertyCondition::Text() const
       
   104 	{
       
   105 	return *iText;
       
   106 	}
       
   107 
       
   108 TTextPropertyConditionCompareMethod CMdETextPropertyCondition::CompareMethod() const
       
   109 	{
       
   110 	return iCompareMethod;
       
   111 	}