messagingapp/msgutils/s60qconversions/src/s60qconversions.cpp
branchGCC_SURGE
changeset 47 5b14749788d7
parent 35 a32b19fb291e
parent 44 36f374c67aa8
equal deleted inserted replaced
35:a32b19fb291e 47:5b14749788d7
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "s60qconversions.h"
       
    19 #include "utf.h"
       
    20 
       
    21 /*!
       
    22     \class S60QConversions
       
    23     \brief S60QConversions class offers functions for converting Symbian/Series60 data types to Qt data types and vice versa.
       
    24  */    
       
    25 
       
    26 
       
    27 /*!
       
    28     Converts Symbian/Series60 descriptor (string) to QString
       
    29 
       
    30     \param desc descriptor to be converted
       
    31     \return QString containing converted string
       
    32  */
       
    33 QString S60QConversions::s60DescToQString(const TDesC& desc)
       
    34     {
       
    35     return QString::fromUtf16(desc.Ptr(),desc.Length());
       
    36     }
       
    37 
       
    38 /*!
       
    39     Converts QString to Symbian/Series60 descriptor (string).
       
    40     Note: Ownership of returned descriptor (string) is transferred to caller
       
    41 
       
    42     \param string QString to be converted
       
    43     \return pointer to Symbian/Series60 descriptor on success;
       
    44             otherwise returns NULL pointer
       
    45  */
       
    46 HBufC* S60QConversions::qStringToS60Desc(const QString& string)
       
    47     {
       
    48     TPtrC16 str(reinterpret_cast<const TUint16*>(string.utf16()));
       
    49     return str.Alloc();
       
    50     }
       
    51 
       
    52 /*!
       
    53     Converts Symbian/Series60 8 bit descriptor (UTF8 string) to QString
       
    54 
       
    55     \param desc 8 bit descriptor to be converted
       
    56     \return QString on success; otherwise returns null QString
       
    57  */
       
    58 QString S60QConversions::s60Desc8ToQString(const TDesC8& desc)
       
    59     {
       
    60     QString qtString;
       
    61     HBufC* s60str = NULL;
       
    62     TRAPD(error, s60str = CnvUtfConverter::ConvertToUnicodeFromUtf8L(desc));
       
    63     if (error == KErrNone) {
       
    64     qtString = QString::fromUtf16(s60str->Ptr(),s60str->Length());
       
    65     delete s60str;
       
    66     }
       
    67     return qtString;
       
    68     }
       
    69 
       
    70 /*!
       
    71     Converts QString to Symbian/Series60 8 bit descriptor (UTF8 string).
       
    72     Note: Ownership of returned descriptor (string) is transferred to caller
       
    73 
       
    74     \param string QString to be converted
       
    75     \return pointer to UTF8 string in Symbian/Series60 descriptor on success;
       
    76             otherwise returns NULL pointer
       
    77  */
       
    78 HBufC8* S60QConversions::qStringToS60Desc8(const QString& string)
       
    79     {
       
    80     TPtrC16 str(reinterpret_cast<const TUint16*>(string.utf16()));
       
    81     HBufC8* s60str = NULL;
       
    82     TRAPD(error, s60str = CnvUtfConverter::ConvertFromUnicodeToUtf8L(str));
       
    83     if (error != KErrNone) {
       
    84     return NULL;
       
    85     }
       
    86     return s60str;
       
    87     }
       
    88 
       
    89 // End of file
       
    90 
       
    91