emailcontacts/contactactionservice/src/CFscContactNameFormatter.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 the class CFscContactNameFormatter.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include "CFscContactNameFormatter.h"
       
    21 #include <CVPbkContactFieldIterator.h>
       
    22 #include <MVPbkFieldType.h>
       
    23 #include <CVPbkFieldTypeRefsList.h>
       
    24 
       
    25 namespace
       
    26     {
       
    27 
       
    28     enum TNameOrder
       
    29         {
       
    30         ENameFirstPart = 0,
       
    31         ENameSecondPart
       
    32         };
       
    33     } // namespace
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CFscContactNameFormatter::CFscContactNameFormatter
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CFscContactNameFormatter::CFscContactNameFormatter(
       
    40         const MVPbkFieldTypeList& aMasterFieldTypeList,
       
    41         const CPbk2SortOrderManager& aSortOrderManager) :
       
    42     CFscContactNameFormatterBase(aMasterFieldTypeList, aSortOrderManager)
       
    43     {
       
    44     FUNC_LOG;
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CFscContactNameFormatter::NewL
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CFscContactNameFormatter* CFscContactNameFormatter::NewL(
       
    52         const TDesC& aUnnamedText,
       
    53         const MVPbkFieldTypeList& aMasterFieldTypeList,
       
    54         const CPbk2SortOrderManager& aSortOrderManager,
       
    55         CVPbkFieldTypeSelector* aTitleFieldSelector)
       
    56     {
       
    57     FUNC_LOG;
       
    58     CFscContactNameFormatter* self = new(ELeave) CFscContactNameFormatter
       
    59     (aMasterFieldTypeList, aSortOrderManager);
       
    60     CleanupStack::PushL(self);
       
    61     self->ConstructL(aUnnamedText, aTitleFieldSelector);
       
    62     CleanupStack::Pop(self);
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CFscContactNameFormatter::ConstructL
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CFscContactNameFormatter::ConstructL(const TDesC& aUnnamedText,
       
    71         CVPbkFieldTypeSelector* aTitleFieldSelector)
       
    72     {
       
    73     FUNC_LOG;
       
    74     // Base class takes ownership of aTitleFieldSelector.
       
    75     // Must not leave after BaseConstructL
       
    76     BaseConstructL(aUnnamedText, aTitleFieldSelector);
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CFscContactNameFormatter::~CFscContactNameFormatter
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CFscContactNameFormatter::~CFscContactNameFormatter()
       
    84     {
       
    85     FUNC_LOG;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CFscContactNameFormatter::GetContactTitle
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CFscContactNameFormatter::GetContactTitle(
       
    93         const MVPbkBaseContactFieldCollection& aContactFields, TDes& aTitle,
       
    94         TUint32 aFormattingFlags)
       
    95     {
       
    96     FUNC_LOG;
       
    97     aTitle.Zero();
       
    98     SetFieldMapper(aContactFields);
       
    99 
       
   100     // Try to create title using first two fields of the sort order
       
   101     // If the field type in the sort order is not defined as a title field
       
   102     // then it's not used for title creation.
       
   103     DoGetContactTitle(aTitle, aFormattingFlags, ENameFirstPart,
       
   104             ENameSecondPart);
       
   105 
       
   106     // If there was no data in the first two fields then
       
   107     // use the third and the rest of the fields in the sort order
       
   108     // for title creation.
       
   109     if (aTitle.Length() == 0 && AreTitleFieldsEmpty(ENameFirstPart,
       
   110             ENameSecondPart) )
       
   111         {
       
   112         // Find the next field in the sort order that has
       
   113         // data to build the title
       
   114         const TInt count = iFieldMapper.FieldCount();
       
   115         DoGetContactTitle(aTitle, aFormattingFlags, ENameSecondPart+1, count
       
   116                 -1); // zero-based
       
   117         }
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CFscContactNameFormatter::GetContactTitleForFind
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CFscContactNameFormatter::GetContactTitleForFind(
       
   125         const MVPbkBaseContactFieldCollection& aContactFields, TDes& aTitle,
       
   126         TUint32 aFormattingFlags)
       
   127     {
       
   128     FUNC_LOG;
       
   129     aTitle.Zero();
       
   130     SetFieldMapper(aContactFields);
       
   131 
       
   132     const TInt count = iFieldMapper.FieldCount();
       
   133     DoGetContactTitle(aTitle, aFormattingFlags, ENameFirstPart, count-1); // zero-based
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CFscContactNameFormatter::ActualTitleFieldsLC
       
   138 // See function CFscContactNameFormatter::GetContactTitle.
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 CVPbkBaseContactFieldTypeListIterator* CFscContactNameFormatter::ActualTitleFieldsLC(
       
   142         CVPbkFieldTypeRefsList& aFieldTypeList,
       
   143         const MVPbkBaseContactFieldCollection& aContactFields)
       
   144     {
       
   145     FUNC_LOG;
       
   146     aFieldTypeList.Reset();
       
   147 
       
   148     SetFieldMapper(aContactFields);
       
   149 
       
   150     DoAppendNonEmptyTitleFieldTypesL(aFieldTypeList, ENameFirstPart,
       
   151             ENameSecondPart);
       
   152 
       
   153     if (aFieldTypeList.FieldTypeCount() == 0)
       
   154         {
       
   155         const TInt count = iFieldMapper.FieldCount();
       
   156         DoAppendNonEmptyTitleFieldTypesL(aFieldTypeList, ENameSecondPart+1,
       
   157                 count-1);
       
   158         }
       
   159 
       
   160     return CVPbkBaseContactFieldTypeListIterator::NewLC(aFieldTypeList,
       
   161             aContactFields);
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CFscContactNameFormatter::MaxTitleLength
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 TInt CFscContactNameFormatter::MaxTitleLength(
       
   169         const MVPbkBaseContactFieldCollection& aContactFields,
       
   170         const TUint32 aFormattingFlags)
       
   171     {
       
   172     FUNC_LOG;
       
   173     TInt result = 0;
       
   174     SetFieldMapper(aContactFields);
       
   175 
       
   176     result = DoCalculateMaxTitleLength(aFormattingFlags, ENameFirstPart,
       
   177             ENameSecondPart);
       
   178 
       
   179     if (result == 0)
       
   180         {
       
   181         // Use the rest of the fields in sort order to
       
   182         // build the title (ie. the company name)
       
   183         const TInt count = iFieldMapper.FieldCount();
       
   184         result = DoCalculateMaxTitleLength(aFormattingFlags, ENameSecondPart
       
   185                 +1, count-1); // zero-based
       
   186         }
       
   187 
       
   188     return result;
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CFscContactNameFormatter::MaxTitleLengthForFind
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 TInt CFscContactNameFormatter::MaxTitleLengthForFind(
       
   196         const MVPbkBaseContactFieldCollection& aContactFields,
       
   197         const TUint32 aFormattingFlags)
       
   198     {
       
   199     FUNC_LOG;
       
   200     TInt result = 0;
       
   201     SetFieldMapper(aContactFields);
       
   202 
       
   203     const TInt count = iFieldMapper.FieldCount();
       
   204     result = DoCalculateMaxTitleLength(aFormattingFlags, ENameFirstPart,
       
   205             count-1); // zero-based
       
   206 
       
   207     return result;
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CFscContactNameFormatter::IsFindSeparatorChar
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TBool CFscContactNameFormatter::IsFindSeparatorChar(TChar aCh)
       
   215     {
       
   216     FUNC_LOG;
       
   217     return aCh.IsSpace();
       
   218     }
       
   219 
       
   220 // End of File
       
   221