author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Fri, 16 Apr 2010 11:39:52 +0300 | |
branch | RCL_3 |
changeset 9 | 740e5562c97f |
parent 8 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <exception> |
|
43 |
#include <e32base.h> |
|
44 |
#include <e32uid.h> |
|
45 |
#include "qcore_symbian_p.h" |
|
46 |
#include <string> |
|
47 |
||
48 |
QT_BEGIN_NAMESPACE |
|
49 |
||
50 |
/* |
|
51 |
Helper function for calling into Symbian classes that expect a TDes&. |
|
52 |
This function converts a QString to a TDes by allocating memory that |
|
53 |
must be deleted by the caller. |
|
54 |
*/ |
|
55 |
||
56 |
Q_CORE_EXPORT HBufC* qt_QString2HBufC(const QString& aString) |
|
57 |
{ |
|
58 |
HBufC *buffer; |
|
59 |
#ifdef QT_NO_UNICODE |
|
60 |
TPtrC8 ptr(reinterpret_cast<const TUint8*>(aString.toLocal8Bit().constData())); |
|
61 |
#else |
|
62 |
TPtrC16 ptr(qt_QString2TPtrC(aString)); |
|
63 |
#endif |
|
64 |
buffer = q_check_ptr(HBufC::New(ptr.Length())); |
|
65 |
buffer->Des().Copy(ptr); |
|
66 |
return buffer; |
|
67 |
} |
|
68 |
||
69 |
Q_CORE_EXPORT QString qt_TDesC2QString(const TDesC& aDescriptor) |
|
70 |
{ |
|
71 |
#ifdef QT_NO_UNICODE |
|
72 |
return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length()); |
|
73 |
#else |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
74 |
return QString(reinterpret_cast<const QChar *>(aDescriptor.Ptr()), aDescriptor.Length()); |
0 | 75 |
#endif |
76 |
} |
|
77 |
||
78 |
QHBufC::QHBufC() |
|
79 |
: m_hBufC(0) |
|
80 |
{ |
|
81 |
} |
|
82 |
||
83 |
QHBufC::QHBufC(const QHBufC &src) |
|
84 |
: m_hBufC(q_check_ptr(src.m_hBufC->Alloc())) |
|
85 |
{ |
|
86 |
} |
|
87 |
||
88 |
/*! |
|
89 |
\internal |
|
90 |
Constructs a QHBufC from an HBufC. Note that the QHBufC instance takes |
|
91 |
ownership of the HBufC. |
|
92 |
*/ |
|
93 |
QHBufC::QHBufC(HBufC *src) |
|
94 |
: m_hBufC(src) |
|
95 |
{ |
|
96 |
} |
|
97 |
||
98 |
QHBufC::QHBufC(const QString &src) |
|
99 |
{ |
|
100 |
m_hBufC = qt_QString2HBufC(src); |
|
101 |
} |
|
102 |
||
103 |
QHBufC::~QHBufC() |
|
104 |
{ |
|
105 |
if (m_hBufC) |
|
106 |
delete m_hBufC; |
|
107 |
} |
|
108 |
||
109 |
class QS60PluginResolver |
|
110 |
{ |
|
111 |
public: |
|
112 |
QS60PluginResolver() |
|
113 |
: initTried(false) {} |
|
114 |
||
115 |
~QS60PluginResolver() { |
|
116 |
lib.Close(); |
|
117 |
} |
|
118 |
||
119 |
TLibraryFunction resolve(int ordinal) { |
|
120 |
if (!initTried) { |
|
121 |
init(); |
|
122 |
initTried = true; |
|
123 |
} |
|
124 |
||
125 |
if (lib.Handle()) |
|
126 |
return lib.Lookup(ordinal); |
|
127 |
else |
|
128 |
return reinterpret_cast<TLibraryFunction>(NULL); |
|
129 |
} |
|
130 |
||
131 |
private: |
|
132 |
void init() |
|
133 |
{ |
|
134 |
#ifdef Q_WS_S60 |
|
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
135 |
_LIT(KLibName_3_1, "qts60plugin_3_1" QT_LIBINFIX_UNICODE L".dll"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
136 |
_LIT(KLibName_3_2, "qts60plugin_3_2" QT_LIBINFIX_UNICODE L".dll"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
137 |
_LIT(KLibName_5_0, "qts60plugin_5_0" QT_LIBINFIX_UNICODE L".dll"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
138 |
|
0 | 139 |
TPtrC libName; |
140 |
TInt uidValue; |
|
141 |
switch (QSysInfo::s60Version()) { |
|
142 |
case QSysInfo::SV_S60_3_1: |
|
143 |
libName.Set(KLibName_3_1); |
|
144 |
uidValue = 0x2001E620; |
|
145 |
break; |
|
146 |
case QSysInfo::SV_S60_3_2: |
|
147 |
libName.Set(KLibName_3_2); |
|
148 |
uidValue = 0x2001E621; |
|
149 |
break; |
|
150 |
case QSysInfo::SV_S60_5_0: // Fall through to default |
|
151 |
default: |
|
152 |
// Default to 5.0 version, as any unknown platform is likely to be newer than that |
|
153 |
libName.Set(KLibName_5_0); |
|
154 |
uidValue = 0x2001E622; |
|
155 |
break; |
|
156 |
} |
|
157 |
||
158 |
TUidType libUid(KDynamicLibraryUid, KSharedLibraryUid, TUid::Uid(uidValue)); |
|
159 |
lib.Load(libName, libUid); |
|
160 |
#endif |
|
161 |
} |
|
162 |
||
163 |
RLibrary lib; |
|
164 |
bool initTried; |
|
165 |
}; |
|
166 |
||
167 |
Q_GLOBAL_STATIC(QS60PluginResolver, qt_s60_plugin_resolver); |
|
168 |
||
169 |
/*! |
|
170 |
\internal |
|
171 |
Resolves a platform version specific function from S60 plugin. |
|
172 |
If plugin is missing or resolving fails for another reason, NULL is returned. |
|
173 |
*/ |
|
174 |
Q_CORE_EXPORT TLibraryFunction qt_resolveS60PluginFunc(int ordinal) |
|
175 |
{ |
|
176 |
return qt_s60_plugin_resolver()->resolve(ordinal); |
|
177 |
} |
|
178 |
||
179 |
class QS60RFsSession |
|
180 |
{ |
|
181 |
public: |
|
182 |
QS60RFsSession() { |
|
183 |
qt_symbian_throwIfError(iFs.Connect()); |
|
184 |
qt_symbian_throwIfError(iFs.ShareProtected()); |
|
185 |
} |
|
186 |
||
187 |
~QS60RFsSession() { |
|
188 |
iFs.Close(); |
|
189 |
} |
|
190 |
||
191 |
RFs& GetRFs() { |
|
192 |
return iFs; |
|
193 |
} |
|
194 |
||
195 |
private: |
|
196 |
||
197 |
RFs iFs; |
|
198 |
}; |
|
199 |
||
200 |
Q_GLOBAL_STATIC(QS60RFsSession, qt_s60_RFsSession); |
|
201 |
||
202 |
Q_CORE_EXPORT RFs& qt_s60GetRFs() |
|
203 |
{ |
|
204 |
return qt_s60_RFsSession()->GetRFs(); |
|
205 |
} |
|
206 |
||
207 |
QT_END_NAMESPACE |