phonebookui/Phonebook2/Presentation/src/CPbk2JapaneseContactNameFormatter.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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: 
       
    15 *     Japanese contact name formatter.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "CPbk2JapaneseContactNameFormatter.h"
       
    21 #include <CVPbkContactFieldIterator.h>
       
    22 #include <MVPbkFieldType.h>
       
    23 #include <CVPbkFieldTypeRefsList.h>
       
    24 
       
    25 namespace {
       
    26 
       
    27 enum TNameOrder
       
    28     {
       
    29     ETopContactOrderNumber = 0,
       
    30     EReadingFirstPart,
       
    31     EReadingSecondPart,
       
    32     ENameFirstPart,
       
    33     ENameSecondPart
       
    34     };
       
    35 } // namespace
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CPbk2JapaneseContactNameFormatter::CPbk2JapaneseContactNameFormatter
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CPbk2JapaneseContactNameFormatter::CPbk2JapaneseContactNameFormatter(
       
    42     const MVPbkFieldTypeList& aMasterFieldTypeList,
       
    43     const CPbk2SortOrderManager& aSortOrderManager)
       
    44     :   CPbk2ContactNameFormatterBase( aMasterFieldTypeList,
       
    45             aSortOrderManager )
       
    46     {
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CPbk2JapaneseContactNameFormatter::NewL
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CPbk2JapaneseContactNameFormatter* CPbk2JapaneseContactNameFormatter::NewL
       
    54     (
       
    55     const MVPbkFieldTypeList& aMasterFieldTypeList,
       
    56     const CPbk2SortOrderManager& aSortOrderManager,
       
    57     CVPbkFieldTypeSelector* aTitleFieldSelector,
       
    58     const TDesC& aUnnamedText
       
    59     )
       
    60     {
       
    61     CPbk2JapaneseContactNameFormatter* self = 
       
    62         new(ELeave) CPbk2JapaneseContactNameFormatter(
       
    63             aMasterFieldTypeList, aSortOrderManager );
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL( aUnnamedText, aTitleFieldSelector );
       
    66     CleanupStack::Pop(self);
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CPbk2JapaneseContactNameFormatter::ConstructL
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 inline void CPbk2JapaneseContactNameFormatter::ConstructL
       
    75         (const TDesC& aUnnamedText,
       
    76          CVPbkFieldTypeSelector* aTitleFieldSelector )
       
    77     {
       
    78     // Base class takes ownership of aTitleFieldSelector.
       
    79     // Must not leave after BaseConstructL
       
    80     BaseConstructL( aUnnamedText, aTitleFieldSelector );
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CPbk2JapaneseContactNameFormatter::~CPbk2JapaneseContactNameFormatter
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CPbk2JapaneseContactNameFormatter::~CPbk2JapaneseContactNameFormatter()
       
    88     {
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CPbk2JapaneseContactNameFormatter::GetContactTitle
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CPbk2JapaneseContactNameFormatter::GetContactTitle
       
    96         (const MVPbkBaseContactFieldCollection& aContactFields,
       
    97         TDes& aTitle, TUint32 aFormattingFlags)
       
    98     {
       
    99     aTitle.Zero();
       
   100     SetFieldMapper( aContactFields );
       
   101 
       
   102     // Try to create title using last/first name.
       
   103     DoGetContactTitle(aTitle, aFormattingFlags,
       
   104         ENameFirstPart, ENameSecondPart );
       
   105 
       
   106     // If no last/first name, use reading fields
       
   107     if ( aTitle.Length() == 0 && 
       
   108          AreTitleFieldsEmpty( ENameFirstPart, ENameSecondPart ) )
       
   109         {
       
   110         DoGetContactTitle(aTitle, aFormattingFlags,
       
   111             EReadingFirstPart, EReadingSecondPart );
       
   112         }
       
   113 
       
   114     // If there there was no data use rest of the fields
       
   115     if ( aTitle.Length() == 0 &&
       
   116          AreTitleFieldsEmpty( EReadingFirstPart, EReadingSecondPart ) )
       
   117         {
       
   118         // Find the next field in the sort order that has
       
   119         // data to build the title
       
   120         const TInt count = iFieldMapper.FieldCount();
       
   121         DoGetContactTitle( aTitle, aFormattingFlags,
       
   122             ENameSecondPart+1 , count-1 ); // zero-based
       
   123         }
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CPbk2JapaneseContactNameFormatter::GetContactTitleForFind
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CPbk2JapaneseContactNameFormatter::GetContactTitleForFind
       
   131         (const MVPbkBaseContactFieldCollection& aContactFields,
       
   132         TDes& aTitle, TUint32 aFormattingFlags)
       
   133     {
       
   134     aTitle.Zero();
       
   135     SetFieldMapper( aContactFields );
       
   136 
       
   137     // Try to use the name fields "reading first part", "reading second part", 
       
   138     // "first part" and "second part"
       
   139     DoGetContactTitle( aTitle, aFormattingFlags,
       
   140         EReadingFirstPart, ENameSecondPart );
       
   141 
       
   142     // If there there was no data in the name fields then
       
   143     // use the rest of the fields in the sort order for the find
       
   144     if ( aTitle.Length() == 0 &&
       
   145          AreTitleFieldsEmpty( EReadingFirstPart, ENameSecondPart ) )
       
   146         {
       
   147         // Find the next title field in the sort order that has
       
   148         // data to build the title
       
   149         const TInt count = iFieldMapper.FieldCount();
       
   150         DoGetContactTitle( aTitle, aFormattingFlags,
       
   151             ENameSecondPart+1 , count-1 ); // zero-based
       
   152         }
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CPbk2JapaneseContactNameFormatter::ActualTitleFieldsLC
       
   157 // See CPbk2JapaneseContactNameFormatter::GetContactTitle.
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 CVPbkBaseContactFieldTypeListIterator*
       
   161 CPbk2JapaneseContactNameFormatter::ActualTitleFieldsLC(
       
   162         CVPbkFieldTypeRefsList& aFieldTypeList,
       
   163         const MVPbkBaseContactFieldCollection& aContactFields)
       
   164     {
       
   165     aFieldTypeList.Reset();
       
   166 
       
   167     SetFieldMapper( aContactFields );
       
   168 
       
   169     DoAppendNonEmptyTitleFieldTypesL(
       
   170             aFieldTypeList,
       
   171             ENameFirstPart,
       
   172             ENameSecondPart);
       
   173 
       
   174     if( aFieldTypeList.FieldTypeCount() == 0 )
       
   175         {
       
   176         DoAppendNonEmptyTitleFieldTypesL(
       
   177                 aFieldTypeList,
       
   178                 EReadingFirstPart,
       
   179                 EReadingSecondPart);
       
   180         }
       
   181 
       
   182     if( aFieldTypeList.FieldTypeCount() == 0 )
       
   183         {
       
   184         const TInt count = iFieldMapper.FieldCount();
       
   185         DoAppendNonEmptyTitleFieldTypesL(
       
   186                 aFieldTypeList,
       
   187                 ENameSecondPart+1,
       
   188                 count-1);
       
   189         }
       
   190 
       
   191     return CVPbkBaseContactFieldTypeListIterator::NewLC(
       
   192             aFieldTypeList,
       
   193             aContactFields);
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CPbk2JapaneseContactNameFormatter::MaxTitleLength
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TInt CPbk2JapaneseContactNameFormatter::MaxTitleLength
       
   201         (const MVPbkBaseContactFieldCollection& aContactFields,
       
   202         const TUint32 aFormattingFlags)
       
   203     {
       
   204     TInt result = 0;
       
   205     SetFieldMapper( aContactFields );
       
   206 
       
   207     // Last/First name
       
   208     result = DoCalculateMaxTitleLength
       
   209         (aFormattingFlags, ENameFirstPart, ENameSecondPart);
       
   210 
       
   211     // Last/First name reading
       
   212     if (result == 0)
       
   213         {
       
   214         result = DoCalculateMaxTitleLength
       
   215             ( aFormattingFlags, EReadingFirstPart, EReadingSecondPart );
       
   216         }
       
   217 
       
   218     if (result == 0)
       
   219         {
       
   220         // Use the rest of the fields in sort order to
       
   221         // build the title (ie. the company name)
       
   222         const TInt count = iFieldMapper.FieldCount();
       
   223         result = DoCalculateMaxTitleLength
       
   224             (aFormattingFlags, ENameSecondPart+1, count-1); // zero-based
       
   225         }
       
   226 
       
   227     return result;
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CPbk2JapaneseContactNameFormatter::MaxTitleLengthForFind
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TInt CPbk2JapaneseContactNameFormatter::MaxTitleLengthForFind
       
   235         (const MVPbkBaseContactFieldCollection& aContactFields,
       
   236         const TUint32 aFormattingFlags)
       
   237     {
       
   238     TInt result = 0;
       
   239     SetFieldMapper( aContactFields );
       
   240 
       
   241     const TInt count = iFieldMapper.FieldCount();
       
   242     result = DoCalculateMaxTitleLength
       
   243         ( aFormattingFlags, EReadingFirstPart, ENameSecondPart );
       
   244 
       
   245     // Rest of the title fields
       
   246     if( result == 0 )
       
   247         {
       
   248         result = DoCalculateMaxTitleLength
       
   249             ( aFormattingFlags, ENameSecondPart + 1, count - 1 );
       
   250         }
       
   251 
       
   252     return result;
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CPbk2JapaneseContactNameFormatter::IsFindSeparatorChar
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 TBool CPbk2JapaneseContactNameFormatter::IsFindSeparatorChar( TChar aCh )
       
   260     {
       
   261     return aCh.IsSpace();
       
   262     }
       
   263 
       
   264 
       
   265 // End of File