emailcontacts/contactactionservice/src/CFscPresentationContactField.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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:  Implementation of presentation level contact field
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "emailtrace.h"
       
    21 #include "CFscPresentationContactField.h"
       
    22 #include "CFscPresentationContactFieldTextData.h"
       
    23 
       
    24 #include <MVPbkContactStore.h>
       
    25 #include <MVPbkContactStoreProperties.h>
       
    26 #include <MVPbkContactFieldTextData.h>
       
    27 #include <MVPbkContactFieldBinaryData.h>
       
    28 #include <MPbk2FieldProperty.h>
       
    29 
       
    30 namespace
       
    31     {
       
    32 
       
    33     const TInt KStaticLength = 35;
       
    34 
       
    35     } // namespace
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ============================
       
    38 
       
    39 // --------------------------------------------------------------------------
       
    40 // CFscPresentationContactField::CFscPresentationContactField
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // --------------------------------------------------------------------------
       
    44 //
       
    45 CFscPresentationContactField::CFscPresentationContactField(
       
    46         const MPbk2FieldProperty& aFieldProperty,
       
    47         MVPbkStoreContact& aParentContact) :
       
    48     iFieldProperty(aFieldProperty), iParentContact(aParentContact)
       
    49     {
       
    50     FUNC_LOG;
       
    51     }
       
    52 
       
    53 // --------------------------------------------------------------------------
       
    54 // CFscPresentationContactField::~CFscPresentationContactField
       
    55 // --------------------------------------------------------------------------
       
    56 //
       
    57 CFscPresentationContactField::~CFscPresentationContactField()
       
    58     {
       
    59     FUNC_LOG;
       
    60     delete iData;
       
    61     delete iStoreField;
       
    62     }
       
    63 
       
    64 // --------------------------------------------------------------------------
       
    65 // CFscPresentationContactField::NewL
       
    66 // Two-phased constructor.
       
    67 // --------------------------------------------------------------------------
       
    68 //
       
    69  CFscPresentationContactField* CFscPresentationContactField::NewL
       
    70 (const MPbk2FieldProperty& aFieldProperty,
       
    71         const MVPbkStoreContactField& aStoreField,
       
    72         MVPbkStoreContact& aParentContact)
       
    73     {
       
    74     FUNC_LOG;
       
    75     CFscPresentationContactField* self =
       
    76     NewLC(aFieldProperty, aStoreField, aParentContact);
       
    77     CleanupStack::Pop(self);
       
    78     return self;
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CFscPresentationContactField::NewLC
       
    83 // Two-phased constructor.
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86  CFscPresentationContactField* CFscPresentationContactField::NewLC
       
    87 (const MPbk2FieldProperty& aFieldProperty,
       
    88         const MVPbkStoreContactField& aStoreField,
       
    89         MVPbkStoreContact& aParentContact)
       
    90     {
       
    91     FUNC_LOG;
       
    92     CFscPresentationContactField* self =
       
    93     new(ELeave) CFscPresentationContactField(aFieldProperty,
       
    94             aParentContact);
       
    95     CleanupStack::PushL(self);
       
    96     self->ConstructL(aStoreField);
       
    97     return self;
       
    98     }
       
    99 
       
   100 // --------------------------------------------------------------------------
       
   101 // CFscPresentationContactField::ConstructL
       
   102 // --------------------------------------------------------------------------
       
   103 //
       
   104 void CFscPresentationContactField::ConstructL(
       
   105         const MVPbkStoreContactField& aStoreField)
       
   106     {
       
   107     FUNC_LOG;
       
   108     // Make a permanent copy from the field reference
       
   109     iStoreField = aStoreField.CloneLC();
       
   110     CleanupStack::Pop(); // iStoreField
       
   111 
       
   112     if (FieldData().DataType() == EVPbkFieldStorageTypeText)
       
   113         {
       
   114         MVPbkContactFieldTextData& textData =
       
   115                 MVPbkContactFieldTextData::Cast(iStoreField->FieldData() );
       
   116         iData = CFscPresentationContactFieldTextData::NewL(textData,
       
   117                 iFieldProperty, MaxDataLength() );
       
   118         }
       
   119     }
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CFscPresentationContactField::MaxDataLength
       
   123 // --------------------------------------------------------------------------
       
   124 //  
       
   125  TInt CFscPresentationContactField::MaxDataLength() const
       
   126     {
       
   127     FUNC_LOG;
       
   128     TInt maxLength = KVPbkUnlimitedFieldLength;
       
   129     TVPbkFieldStorageType dataType = iStoreField->FieldData().DataType();
       
   130     switch (dataType)
       
   131         {
       
   132         case EVPbkFieldStorageTypeText:
       
   133             {
       
   134             const MVPbkContactFieldTextData& textData =
       
   135             MVPbkContactFieldTextData::Cast(iStoreField->FieldData());
       
   136             maxLength = textData.MaxLength();
       
   137             break;
       
   138             }
       
   139         case EVPbkFieldStorageTypeBinary:
       
   140             {
       
   141             const MVPbkContactFieldBinaryData& binaryData =
       
   142             MVPbkContactFieldBinaryData::Cast(iStoreField->FieldData());
       
   143             maxLength = binaryData.MaxLength();
       
   144             break;
       
   145             }
       
   146         case EVPbkFieldStorageTypeDateTime: // FALLTHROUGH
       
   147         default:
       
   148             {
       
   149             // Do nothing
       
   150             break;
       
   151             }
       
   152         }
       
   153 
       
   154     TInt staticMaxLength = iFieldProperty.MaxLength();
       
   155     if (maxLength == KVPbkUnlimitedFieldLength)
       
   156         {
       
   157         maxLength = staticMaxLength;
       
   158         }
       
   159     else
       
   160         {
       
   161         maxLength = Min(staticMaxLength, maxLength);
       
   162         }
       
   163     return maxLength;
       
   164     }
       
   165 
       
   166 // --------------------------------------------------------------------------
       
   167 // CFscPresentationContactField::IsEmpty
       
   168 // --------------------------------------------------------------------------
       
   169 //    
       
   170  TBool CFscPresentationContactField::IsEmpty() const
       
   171     {
       
   172     FUNC_LOG;
       
   173     return iStoreField->FieldData().IsEmpty();
       
   174     }
       
   175 
       
   176 // --------------------------------------------------------------------------
       
   177 // CFscPresentationContactField::IsEditable
       
   178 // --------------------------------------------------------------------------
       
   179 //
       
   180  TBool CFscPresentationContactField::IsEditable() const
       
   181     {
       
   182     FUNC_LOG;
       
   183     return !(iFieldProperty.Flags() & KPbk2FieldFlagDisableEdit);
       
   184     }
       
   185 
       
   186 // --------------------------------------------------------------------------
       
   187 // CFscPresentationContactField::IsRemovable
       
   188 // --------------------------------------------------------------------------
       
   189 //    
       
   190  TBool CFscPresentationContactField::IsRemovable() const
       
   191     {
       
   192     FUNC_LOG;
       
   193     return !(iFieldProperty.Flags() & KPbk2FieldFlagCanNotBeRemoved);
       
   194     }
       
   195 // --------------------------------------------------------------------------
       
   196 // CFscPresentationContactField::ParentObject
       
   197 // --------------------------------------------------------------------------
       
   198 //
       
   199 MVPbkObjectHierarchy& CFscPresentationContactField::ParentObject() const
       
   200     {
       
   201     FUNC_LOG;
       
   202     return iStoreField->ParentObject();
       
   203     }
       
   204 
       
   205 // --------------------------------------------------------------------------
       
   206 // CFscPresentationContactField::ParentContact
       
   207 // --------------------------------------------------------------------------
       
   208 //
       
   209 MVPbkBaseContact& CFscPresentationContactField::ParentContact() const
       
   210     {
       
   211     FUNC_LOG;
       
   212     return iStoreField->ParentContact();
       
   213     }
       
   214 
       
   215 // --------------------------------------------------------------------------
       
   216 // CFscPresentationContactField::ParentContact
       
   217 // --------------------------------------------------------------------------
       
   218 //
       
   219 const MVPbkFieldType* CFscPresentationContactField::MatchFieldType(
       
   220         TInt aMatchPriority) const
       
   221     {
       
   222     FUNC_LOG;
       
   223     return iStoreField->MatchFieldType(aMatchPriority);
       
   224     }
       
   225 
       
   226 // --------------------------------------------------------------------------
       
   227 // CFscPresentationContactField::BestMatchingFieldType
       
   228 // --------------------------------------------------------------------------
       
   229 //
       
   230 const MVPbkFieldType* CFscPresentationContactField::BestMatchingFieldType() const
       
   231     {
       
   232     FUNC_LOG;
       
   233     return iStoreField->BestMatchingFieldType();
       
   234     }
       
   235 
       
   236 // --------------------------------------------------------------------------
       
   237 // CFscPresentationContactField::FieldData
       
   238 // --------------------------------------------------------------------------
       
   239 //
       
   240 const MVPbkContactFieldData& CFscPresentationContactField::FieldData() const
       
   241     {
       
   242     FUNC_LOG;
       
   243 
       
   244     TVPbkFieldStorageType dataType = iStoreField->FieldData().DataType();
       
   245     switch (dataType)
       
   246         {
       
   247         case EVPbkFieldStorageTypeText:
       
   248             {
       
   249             if (iData)
       
   250                 {
       
   251                 return *iData;
       
   252                 }
       
   253             else
       
   254                 {
       
   255                 return iStoreField->FieldData();
       
   256                 }
       
   257             }
       
   258         case EVPbkFieldStorageTypeBinary: // FALLTHROUGH
       
   259         case EVPbkFieldStorageTypeDateTime: // FALLTHROUGH
       
   260         default:
       
   261             {
       
   262             return iStoreField->FieldData();
       
   263             }
       
   264         }
       
   265     }
       
   266 
       
   267 // --------------------------------------------------------------------------
       
   268 // CFscPresentationContactField::IsSame
       
   269 // --------------------------------------------------------------------------
       
   270 //
       
   271 TBool CFscPresentationContactField::IsSame(
       
   272         const MVPbkBaseContactField& aOther) const
       
   273     {
       
   274     FUNC_LOG;
       
   275     const CFscPresentationContactField* field =
       
   276             dynamic_cast<const CFscPresentationContactField*>(&aOther);
       
   277     if (field)
       
   278         {
       
   279         return iStoreField->IsSame(*field->iStoreField);
       
   280         }
       
   281     return iStoreField->IsSame(aOther);
       
   282     }
       
   283 
       
   284 // --------------------------------------------------------------------------
       
   285 // CFscPresentationContactField::SupportsLabel
       
   286 // --------------------------------------------------------------------------
       
   287 //
       
   288 TBool CFscPresentationContactField::SupportsLabel() const
       
   289     {
       
   290     FUNC_LOG;
       
   291     return iStoreField->SupportsLabel();
       
   292     }
       
   293 
       
   294 // --------------------------------------------------------------------------
       
   295 // CFscPresentationContactField::FieldLabel
       
   296 // --------------------------------------------------------------------------
       
   297 //
       
   298 TPtrC CFscPresentationContactField::FieldLabel() const
       
   299     {
       
   300     FUNC_LOG;
       
   301     if (iStoreField->ContactStore().StoreProperties().SupportsFieldLabels())
       
   302         {
       
   303         return iStoreField->FieldLabel();
       
   304         }
       
   305     else
       
   306         {
       
   307         return iFieldProperty.DefaultLabel();
       
   308         }
       
   309     }
       
   310 
       
   311 // --------------------------------------------------------------------------
       
   312 // CFscPresentationContactField::SetFieldLabelL
       
   313 // --------------------------------------------------------------------------
       
   314 //
       
   315 void CFscPresentationContactField::SetFieldLabelL(const TDesC& aText)
       
   316     {
       
   317     FUNC_LOG;
       
   318     iStoreField->SetFieldLabelL(aText);
       
   319     }
       
   320 
       
   321 // --------------------------------------------------------------------------
       
   322 // CFscPresentationContactField::MaxLabelLength
       
   323 // --------------------------------------------------------------------------
       
   324 //
       
   325 TInt CFscPresentationContactField::MaxLabelLength() const
       
   326     {
       
   327     FUNC_LOG;
       
   328     TInt storeLength = iStoreField->MaxLabelLength();
       
   329     if (storeLength == KVPbkUnlimitedLabelLength)
       
   330         {
       
   331         return KStaticLength;
       
   332         }
       
   333     else
       
   334         {
       
   335         return Min(KStaticLength, storeLength);
       
   336         }
       
   337     }
       
   338 
       
   339 // --------------------------------------------------------------------------
       
   340 // CFscPresentationContactField::FieldData
       
   341 // --------------------------------------------------------------------------
       
   342 //
       
   343 MVPbkContactFieldData& CFscPresentationContactField::FieldData()
       
   344     {
       
   345     FUNC_LOG;
       
   346     TVPbkFieldStorageType dataType = iStoreField->FieldData().DataType();
       
   347     switch (dataType)
       
   348         {
       
   349         case EVPbkFieldStorageTypeText:
       
   350             {
       
   351             if (iData)
       
   352                 {
       
   353                 return *iData;
       
   354                 }
       
   355             else
       
   356                 {
       
   357                 return iStoreField->FieldData();
       
   358                 }
       
   359             }
       
   360         case EVPbkFieldStorageTypeBinary: // FALLTHROUGH
       
   361         case EVPbkFieldStorageTypeDateTime: // FALLTHROUGH
       
   362         default:
       
   363             {
       
   364             return iStoreField->FieldData();
       
   365             }
       
   366         }
       
   367     }
       
   368 
       
   369 // --------------------------------------------------------------------------
       
   370 // CFscPresentationContactField::CloneLC
       
   371 // --------------------------------------------------------------------------
       
   372 //
       
   373 MVPbkStoreContactField* CFscPresentationContactField::CloneLC() const
       
   374     {
       
   375     FUNC_LOG;
       
   376     CFscPresentationContactField* copy =
       
   377             CFscPresentationContactField::NewLC(iFieldProperty,
       
   378                     *iStoreField, iParentContact);
       
   379     return copy;
       
   380     }
       
   381 
       
   382 // --------------------------------------------------------------------------
       
   383 // CFscPresentationContactField::CreateLinkLC
       
   384 // --------------------------------------------------------------------------
       
   385 //  
       
   386 MVPbkContactLink* CFscPresentationContactField::CreateLinkLC() const
       
   387     {
       
   388     FUNC_LOG;
       
   389     return iStoreField->CreateLinkLC();
       
   390     }
       
   391 
       
   392 //  End of File  
       
   393