1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "xqconversions.h" |
|
23 #include "utf.h" |
|
24 |
|
25 /*! |
|
26 \class XQConversions |
|
27 \brief The XQConversions class offers functions for converting between Symbian S60 data types and Qt data types. |
|
28 */ |
|
29 |
|
30 /*! |
|
31 Converts a Symbian S60 descriptor (string) to a QString |
|
32 |
|
33 \param desc descriptor to be converted |
|
34 \return QString containing the converted string |
|
35 */ |
|
36 QString XQConversions::s60DescToQString(const TDesC& desc) |
|
37 { |
|
38 return QString::fromUtf16(desc.Ptr(), desc.Length()); |
|
39 } |
|
40 |
|
41 /*! |
|
42 Converts a QString to a Symbian S60 descriptor (string). |
|
43 |
|
44 Note: Ownership of the returned descriptor (string) is transferred to caller. |
|
45 |
|
46 \param string QString to be converted |
|
47 \return Pointer to a Symbian S60 descriptor on success; |
|
48 otherwise returns NULL pointer |
|
49 */ |
|
50 HBufC* XQConversions::qStringToS60Desc(const QString& string) |
|
51 { |
|
52 TPtrC16 str(reinterpret_cast<const TUint16*>(string.utf16())); |
|
53 return str.Alloc(); |
|
54 } |
|
55 |
|
56 /*! |
|
57 Converts a Symbian S60 8 bit descriptor (UTF8 string) to a QString |
|
58 |
|
59 \param desc 8 bit descriptor to be converted |
|
60 \return Converted QString on success; otherwise returns null QString |
|
61 */ |
|
62 QString XQConversions::s60Desc8ToQString(const TDesC8& desc) |
|
63 { |
|
64 QString qtString; |
|
65 HBufC* s60str; |
|
66 TRAPD(error, s60str = CnvUtfConverter::ConvertToUnicodeFromUtf8L(desc)); |
|
67 if (error == KErrNone) |
|
68 { |
|
69 qtString = QString::fromUtf16(s60str->Ptr(), s60str->Length()); |
|
70 delete s60str; |
|
71 } |
|
72 return qtString; |
|
73 } |
|
74 |
|
75 /*! |
|
76 Converts a QString to a Symbian S60 8 bit descriptor (UTF8 string). |
|
77 |
|
78 Note: Ownership of the returned descriptor (string) is transferred to the caller |
|
79 |
|
80 \param string QString to be converted |
|
81 \return Pointer to a Symbian S60 descriptor containing the UTF8 string on success; |
|
82 otherwise returns NULL pointer |
|
83 */ |
|
84 HBufC8* XQConversions::qStringToS60Desc8(const QString& string) |
|
85 { |
|
86 TPtrC16 str(reinterpret_cast<const TUint16*>(string.utf16())); |
|
87 HBufC8* s60str; |
|
88 TRAPD(error, s60str = CnvUtfConverter::ConvertFromUnicodeToUtf8L(str)); |
|
89 if (error != KErrNone) |
|
90 { |
|
91 return NULL; |
|
92 } |
|
93 return s60str; |
|
94 } |
|
95 |
|
96 /*! |
|
97 Converts a Symbian S60 8 bit descriptor to a QByteArray |
|
98 |
|
99 \param desc 8 bit descriptor to be converted |
|
100 \return QByteArray on success; otherwise returns null QByteArray |
|
101 */ |
|
102 QByteArray XQConversions::s60Desc8ToQByteArray(const TDesC8& desc) |
|
103 { |
|
104 return QByteArray((const char*)desc.Ptr(), desc.Length()); |
|
105 } |
|
106 |
|
107 /*! |
|
108 Converts a QByteArray to a Symbian S60 8 bit descriptor. |
|
109 Note: Ownership of the returned descriptor (string) is transferred to the caller |
|
110 |
|
111 \param byteArray QByteArray to be converted |
|
112 \return Pointer to an 8 bit Symbian S60 descriptor string on success; |
|
113 otherwise returns NULL pointer |
|
114 */ |
|
115 HBufC8* XQConversions::qByteArrayToS60Desc8(const QByteArray& byteArray) |
|
116 { |
|
117 TPtrC8 ptr8((TUint8*)(byteArray.constData())); |
|
118 return ptr8.Alloc(); |
|
119 } |
|
120 |
|
121 // End of file |
|