bluetoothengine/btnotif/src/btnotifnameutils.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 0 f63038272f30
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
       
     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:  Declares Bluetooth notifiers base class.
       
    15  *
       
    16  */
       
    17 
       
    18 #include <AknUtils.h>
       
    19 #include <StringLoader.h>
       
    20 #include <utf.h>
       
    21 
       
    22 #include <BTNotif.rsg>
       
    23 
       
    24 #include "btNotifDebug.h"
       
    25 #include "btnotifnameutils.h"
       
    26 
       
    27 /**
       
    28  * A function for strip dangerous chars out of BT name 
       
    29  * @param  a device name. After return, it contains the stripped name.
       
    30  * @return void
       
    31  */
       
    32 void BtNotifNameUtils::StripDeviceName(TBTDeviceName& aDeviceNameForStrip)
       
    33     {	   
       
    34     aDeviceNameForStrip.Trim();
       
    35     // Filter out listbox non-friendly control chars.
       
    36     //
       
    37     AknTextUtils::StripCharacters(aDeviceNameForStrip, KAknStripListControlChars);  	             
       
    38 
       
    39     // Filter out sub-string-separator to pretend unexpected text layout.
       
    40     //
       
    41     TChar subStringSeparator = TChar(0x0001);
       
    42     TBuf<1> tempCharBuf;
       
    43     tempCharBuf.Append(subStringSeparator);
       
    44     AknTextUtils::StripCharacters(aDeviceNameForStrip, tempCharBuf); 
       
    45     }
       
    46 
       
    47 /**
       
    48  * Gets the device name to be displayed in note or dialog.
       
    49  * @param aName contains the name to be displayed
       
    50  * @param aDev the device that may have a friendly or device name, or no name at all.
       
    51  */
       
    52 void BtNotifNameUtils::GetDeviceDisplayName(TBTDeviceName& aName, const CBTDevice* aDev)
       
    53     {
       
    54     if(aDev && aDev->IsValidFriendlyName() )
       
    55         {
       
    56         aName.Copy( aDev->FriendlyName() );
       
    57         }
       
    58     else
       
    59         {
       
    60         GetDeviceName(aName, aDev);
       
    61         }
       
    62     }
       
    63 
       
    64 /**
       
    65  * Gets the device name from aDev if its friendly name or device name is valid; otherwise 
       
    66  * the predefined default BT name.
       
    67  * @param aName contains the device name as the result 
       
    68  * @param aDev the device that may have a device name, or no name at all.
       
    69  */
       
    70 void BtNotifNameUtils::GetDeviceName(TBTDeviceName& aName, const CBTDevice* aDev)
       
    71     {
       
    72     aName.Zero();
       
    73     TInt err (CnvUtfConverter::EErrorIllFormedInput);
       
    74     if(aDev && aDev->IsValidDeviceName())
       
    75         {
       
    76         err = CnvUtfConverter::ConvertToUnicodeFromUtf8(aName, aDev->DeviceName());
       
    77         }
       
    78     // if there are illformated chars in the device name, default name should be used for display.
       
    79     if (err == CnvUtfConverter::EErrorIllFormedInput || aName.Length() == 0)
       
    80         {
       
    81         StringLoader::Load(aName, R_BT_DIALOG_DEF_NAME);
       
    82         }
       
    83     StripDeviceName(aName);
       
    84     }
       
    85 
       
    86 /**
       
    87  * Sets the device name.  This handles the conversion from unicode
       
    88  * to UTF8.
       
    89  * @param aDev the device that the name should be set for
       
    90  * @param aName the name to set
       
    91  */
       
    92 void BtNotifNameUtils::SetDeviceNameL(const TBTDeviceName& aName, CBTDevice& aDev)
       
    93     {
       
    94     FTRACE(FPrint(_L("[BTNOTIF]\t CBTNotifierBase::SetDeviceNameL - Name: '%S' length: %d"), &aName, aName.Length() ));
       
    95 
       
    96     // Rationalise the name to remove whitespace and control characters
       
    97     // then set the name if there's anything left
       
    98     TBTDeviceName devName(aName);
       
    99     StripDeviceName(devName);
       
   100     if (aName.Length())
       
   101         {
       
   102         aDev.SetDeviceNameL(BTDeviceNameConverter::ToUTF8L(devName)); 
       
   103         }	
       
   104     }
       
   105 
       
   106