phonebookui/Phonebook2/remotecontactlookup/contactactionservice/src/CFscNumberGroupingFormatter.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 number grouping phone number formatter.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include "CFscNumberGroupingFormatter.h"
       
    21 
       
    22 // System includes
       
    23 #include <NumberGrouping.h>
       
    24 #include <AknUtils.h>
       
    25 
       
    26 /// Unnamed namespace for local definitions
       
    27 namespace
       
    28     {
       
    29 
       
    30     const TInt KGroupingFactor = 2;
       
    31 
       
    32     } /// namespace
       
    33 
       
    34 
       
    35 // --------------------------------------------------------------------------
       
    36 // CFscNumberGroupingFormatter::CFscNumberGroupingFormatter
       
    37 // --------------------------------------------------------------------------
       
    38 //
       
    39 CFscNumberGroupingFormatter::CFscNumberGroupingFormatter()
       
    40     {
       
    41     FUNC_LOG;
       
    42     }
       
    43 
       
    44 // --------------------------------------------------------------------------
       
    45 // CFscNumberGroupingFormatter::~CFscNumberGroupingFormatter
       
    46 // --------------------------------------------------------------------------
       
    47 //
       
    48 CFscNumberGroupingFormatter::~CFscNumberGroupingFormatter()
       
    49     {
       
    50     FUNC_LOG;
       
    51     delete iNumberGrouping;
       
    52     delete iFormatterNumberBuffer;
       
    53     }
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CFscNumberGroupingFormatter::ConstructL
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 void CFscNumberGroupingFormatter::ConstructL(TInt aMaxDisplayLength)
       
    60     {
       
    61     FUNC_LOG;
       
    62     // The grouping object takes care of calculating the size of the
       
    63     // grouped number, just pass the length of the non-grouped number
       
    64     iNumberGrouping = CPNGNumberGrouping::NewL(aMaxDisplayLength);
       
    65 
       
    66     iFormatterNumberBuffer = HBufC::NewL(KGroupingFactor * aMaxDisplayLength);
       
    67 
       
    68     }
       
    69 
       
    70 // --------------------------------------------------------------------------
       
    71 // CFscNumberGroupingFormatter::NewL
       
    72 // --------------------------------------------------------------------------
       
    73 //
       
    74 CFscNumberGroupingFormatter* CFscNumberGroupingFormatter::NewL(
       
    75         TInt aMaxDisplayLength)
       
    76     {
       
    77     FUNC_LOG;
       
    78     CFscNumberGroupingFormatter* self = new( ELeave ) CFscNumberGroupingFormatter;
       
    79     CleanupStack::PushL(self);
       
    80     self->ConstructL(aMaxDisplayLength);
       
    81     CleanupStack::Pop(self);
       
    82     return self;
       
    83     }
       
    84 
       
    85 // --------------------------------------------------------------------------
       
    86 // CFscNumberGroupingFormatter::SetMaxBufferLengthL
       
    87 // --------------------------------------------------------------------------
       
    88 //
       
    89 void CFscNumberGroupingFormatter::SetMaxBufferLengthL(TInt aMaxLength)
       
    90     {
       
    91     FUNC_LOG;
       
    92     if (aMaxLength > iNumberGrouping->MaxDisplayLength() )
       
    93         {
       
    94         CPNGNumberGrouping* newNumberGrouping =
       
    95                 CPNGNumberGrouping::NewL(aMaxLength);
       
    96         delete iNumberGrouping;
       
    97         iNumberGrouping = newNumberGrouping;
       
    98         iFormatterNumberBuffer
       
    99                 = iFormatterNumberBuffer->ReAllocL(KGroupingFactor
       
   100                         * aMaxLength);
       
   101         }
       
   102     }
       
   103 
       
   104 // --------------------------------------------------------------------------
       
   105 // CPbkNumberGroupingFormatter::FormatPhoneNumberForDisplay
       
   106 // --------------------------------------------------------------------------
       
   107 //
       
   108 TPtrC CFscNumberGroupingFormatter::FormatPhoneNumberForDisplay(
       
   109         const TDesC& aOriginalPhoneNumber)
       
   110     {
       
   111     FUNC_LOG;
       
   112     if (aOriginalPhoneNumber.Length() <= iNumberGrouping->MaxDisplayLength() )
       
   113         {
       
   114         iNumberGrouping->Set(aOriginalPhoneNumber);
       
   115         TPtr formatterNumber = iFormatterNumberBuffer->Des();
       
   116         formatterNumber.Copy(iNumberGrouping->FormattedNumber() );
       
   117 
       
   118         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formatterNumber);
       
   119         return formatterNumber;
       
   120         }
       
   121     else
       
   122         {
       
   123         // Too long number to format, just return the original. This is
       
   124         // in line with MPbkPhoneNumberFormatter interface's
       
   125         // best-effort promise.
       
   126         return aOriginalPhoneNumber;
       
   127         }
       
   128     }
       
   129 
       
   130 // End of File
       
   131