1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
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 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /****************************************************************************
|
---|
43 | **
|
---|
44 | ** Implementation of QInputContextFactory class
|
---|
45 | **
|
---|
46 | ** Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved.
|
---|
47 | **
|
---|
48 | ** This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own
|
---|
49 | ** license. You may use this file under your Qt license. Following
|
---|
50 | ** description is copied from their original file headers. Contact
|
---|
51 | ** [email protected] if any conditions of this licensing are
|
---|
52 | ** not clear to you.
|
---|
53 | **
|
---|
54 | ****************************************************************************/
|
---|
55 |
|
---|
56 | #include "qinputcontextfactory.h"
|
---|
57 |
|
---|
58 | #ifndef QT_NO_IM
|
---|
59 |
|
---|
60 | #include "qcoreapplication.h"
|
---|
61 | #include "qinputcontext.h"
|
---|
62 | #include "qinputcontextplugin.h"
|
---|
63 |
|
---|
64 | #ifdef Q_WS_X11
|
---|
65 | #include "private/qt_x11_p.h"
|
---|
66 | #include "qximinputcontext_p.h"
|
---|
67 | #endif
|
---|
68 | #ifdef Q_WS_WIN
|
---|
69 | #include "qwininputcontext_p.h"
|
---|
70 | #endif
|
---|
71 | #ifdef Q_WS_MAC
|
---|
72 | #include "qmacinputcontext_p.h"
|
---|
73 | #endif
|
---|
74 | #ifdef Q_WS_S60
|
---|
75 | #include "qcoefepinputcontext_p.h"
|
---|
76 | #include "AknInputLanguageInfo.h"
|
---|
77 | #endif
|
---|
78 |
|
---|
79 | #include "private/qfactoryloader_p.h"
|
---|
80 | #include "qmutex.h"
|
---|
81 |
|
---|
82 | QT_BEGIN_NAMESPACE
|
---|
83 |
|
---|
84 | #ifndef QT_NO_LIBRARY
|
---|
85 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
|
---|
86 | (QInputContextFactoryInterface_iid, QLatin1String("/inputmethods")))
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | /*!
|
---|
90 | \class QInputContextFactory
|
---|
91 | \brief The QInputContextFactory class creates QInputContext objects.
|
---|
92 |
|
---|
93 |
|
---|
94 | The input context factory creates a QInputContext object for a
|
---|
95 | given key with QInputContextFactory::create().
|
---|
96 |
|
---|
97 | The input contexts are either built-in or dynamically loaded from
|
---|
98 | an input context plugin (see QInputContextPlugin).
|
---|
99 |
|
---|
100 | keys() returns a list of valid keys. The
|
---|
101 | keys are the names used, for example, to identify and specify
|
---|
102 | input methods for the input method switching mechanism. The names
|
---|
103 | have to be consistent with QInputContext::identifierName(), and
|
---|
104 | may only contain ASCII characters.
|
---|
105 |
|
---|
106 | A key can be used to retrieve the associated input context's
|
---|
107 | supported languages using languages(). You
|
---|
108 | can retrieve the input context's description using
|
---|
109 | description() and finally you can get a user
|
---|
110 | friendly internationalized name of the QInputContext object
|
---|
111 | specified by the key using displayName().
|
---|
112 |
|
---|
113 | \legalese
|
---|
114 | Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved.
|
---|
115 |
|
---|
116 | This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own
|
---|
117 | license. You may use this file under your Qt license. Following
|
---|
118 | description is copied from their original file headers. Contact
|
---|
119 | [email protected] if any conditions of this licensing are
|
---|
120 | not clear to you.
|
---|
121 | \endlegalese
|
---|
122 |
|
---|
123 | \sa QInputContext, QInputContextPlugin
|
---|
124 | */
|
---|
125 |
|
---|
126 | /*!
|
---|
127 | Creates and returns a QInputContext object for the input context
|
---|
128 | specified by \a key with the given \a parent. Keys are case
|
---|
129 | sensitive.
|
---|
130 |
|
---|
131 | \sa keys()
|
---|
132 | */
|
---|
133 | QInputContext *QInputContextFactory::create( const QString& key, QObject *parent )
|
---|
134 | {
|
---|
135 | QInputContext *result = 0;
|
---|
136 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
---|
137 | if (key == QLatin1String("xim")) {
|
---|
138 | result = new QXIMInputContext;
|
---|
139 | }
|
---|
140 | #endif
|
---|
141 | #if defined(Q_WS_WIN)
|
---|
142 | if (key == QLatin1String("win")) {
|
---|
143 | result = new QWinInputContext;
|
---|
144 | }
|
---|
145 | #endif
|
---|
146 | #if defined(Q_WS_MAC)
|
---|
147 | if (key == QLatin1String("mac")) {
|
---|
148 | result = new QMacInputContext;
|
---|
149 | }
|
---|
150 | #endif
|
---|
151 | #if defined(Q_WS_S60)
|
---|
152 | if (key == QLatin1String("coefep")) {
|
---|
153 | result = new QCoeFepInputContext;
|
---|
154 | }
|
---|
155 | #endif
|
---|
156 | #ifdef QT_NO_LIBRARY
|
---|
157 | Q_UNUSED(key);
|
---|
158 | #else
|
---|
159 | if (QInputContextFactoryInterface *factory =
|
---|
160 | qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key))) {
|
---|
161 | result = factory->create(key);
|
---|
162 | }
|
---|
163 | #endif
|
---|
164 | if (result)
|
---|
165 | result->setParent(parent);
|
---|
166 | return result;
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | /*!
|
---|
171 | Returns the list of keys this factory can create input contexts
|
---|
172 | for.
|
---|
173 |
|
---|
174 | The keys are the names used, for example, to identify and specify
|
---|
175 | input methods for the input method switching mechanism. The names
|
---|
176 | have to be consistent with QInputContext::identifierName(), and
|
---|
177 | may only contain ASCII characters.
|
---|
178 |
|
---|
179 | \sa create(), displayName(), QInputContext::identifierName()
|
---|
180 | */
|
---|
181 | QStringList QInputContextFactory::keys()
|
---|
182 | {
|
---|
183 | QStringList result;
|
---|
184 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
---|
185 | result << QLatin1String("xim");
|
---|
186 | #endif
|
---|
187 | #if defined(Q_WS_WIN) && !defined(QT_NO_XIM)
|
---|
188 | result << QLatin1String("win");
|
---|
189 | #endif
|
---|
190 | #if defined(Q_WS_MAC)
|
---|
191 | result << QLatin1String("mac");
|
---|
192 | #endif
|
---|
193 | #if defined(Q_WS_S60)
|
---|
194 | result << QLatin1String("coefep");
|
---|
195 | #endif
|
---|
196 | #ifndef QT_NO_LIBRARY
|
---|
197 | result += loader()->keys();
|
---|
198 | #endif // QT_NO_LIBRARY
|
---|
199 | return result;
|
---|
200 | }
|
---|
201 |
|
---|
202 | #if defined(Q_WS_S60)
|
---|
203 | /*!
|
---|
204 | \internal
|
---|
205 |
|
---|
206 | This function contains pure Symbian exception handling code for
|
---|
207 | getting S60 language list.
|
---|
208 | Returned object ownership is transferred to caller.
|
---|
209 | */
|
---|
210 | static CAknInputLanguageList* s60LangListL()
|
---|
211 | {
|
---|
212 | CAknInputLanguageInfo *langInfo = AknInputLanguageInfoFactory::CreateInputLanguageInfoL();
|
---|
213 | CleanupStack::PushL(langInfo);
|
---|
214 | // In rare phone there is more than 7 languages installed -> use 7 as an array granularity
|
---|
215 | CAknInputLanguageList *langList = new (ELeave) CAknInputLanguageList(7);
|
---|
216 | CleanupStack::PushL(langList);
|
---|
217 | langInfo->AppendAvailableLanguagesL(langList);
|
---|
218 | CleanupStack::Pop(langList);
|
---|
219 | CleanupStack::PopAndDestroy(langInfo);
|
---|
220 | return langList;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /*!
|
---|
224 | \internal
|
---|
225 |
|
---|
226 | This function utility function return S60 language list.
|
---|
227 | Returned object ownership is transferred to caller.
|
---|
228 | */
|
---|
229 | static CAknInputLanguageList* s60LangList()
|
---|
230 | {
|
---|
231 | CAknInputLanguageList *langList = NULL;
|
---|
232 | TRAP_IGNORE(langList = s60LangListL());
|
---|
233 | q_check_ptr(langList);
|
---|
234 | return langList;
|
---|
235 | }
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | /*!
|
---|
239 | Returns the languages supported by the QInputContext object
|
---|
240 | specified by \a key.
|
---|
241 |
|
---|
242 | The languages are expressed as language code (e.g. "zh_CN",
|
---|
243 | "zh_TW", "zh_HK", "ja", "ko", ...). An input context that supports
|
---|
244 | multiple languages can return all supported languages as a
|
---|
245 | QStringList. The name has to be consistent with
|
---|
246 | QInputContext::language().
|
---|
247 |
|
---|
248 | This information may be used to optimize a user interface.
|
---|
249 |
|
---|
250 | \sa keys(), QInputContext::language(), QLocale
|
---|
251 | */
|
---|
252 | QStringList QInputContextFactory::languages( const QString &key )
|
---|
253 | {
|
---|
254 | QStringList result;
|
---|
255 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
---|
256 | if (key == QLatin1String("xim"))
|
---|
257 | return QStringList(QString());
|
---|
258 | #endif
|
---|
259 | #if defined(Q_WS_WIN)
|
---|
260 | if (key == QLatin1String("win"))
|
---|
261 | return QStringList(QString());
|
---|
262 | #endif
|
---|
263 | #if defined(Q_WS_MAC)
|
---|
264 | if (key == QLatin1String("mac"))
|
---|
265 | return QStringList(QString());
|
---|
266 | #endif
|
---|
267 | #if defined(Q_WS_S60)
|
---|
268 | if (key == QLatin1String("coefep"))
|
---|
269 | {
|
---|
270 | CAknInputLanguageList *langList = s60LangList();
|
---|
271 | int count = langList->Count();
|
---|
272 | for (int i = 0; i < count; ++i)
|
---|
273 | {
|
---|
274 | result.append(QString(qt_symbianLocaleName(langList->At(i)->LanguageCode())));
|
---|
275 | }
|
---|
276 | delete langList;
|
---|
277 | }
|
---|
278 | #endif
|
---|
279 | #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
|
---|
280 | Q_UNUSED(key);
|
---|
281 | #else
|
---|
282 | if (QInputContextFactoryInterface *factory =
|
---|
283 | qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
|
---|
284 | result = factory->languages(key);
|
---|
285 | #endif // QT_NO_LIBRARY
|
---|
286 | return result;
|
---|
287 | }
|
---|
288 |
|
---|
289 | /*!
|
---|
290 | Returns a user friendly internationalized name of the
|
---|
291 | QInputContext object specified by \a key. You can, for example,
|
---|
292 | use this name in a menu.
|
---|
293 |
|
---|
294 | \sa keys(), QInputContext::identifierName()
|
---|
295 | */
|
---|
296 | QString QInputContextFactory::displayName( const QString &key )
|
---|
297 | {
|
---|
298 | QString result;
|
---|
299 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
---|
300 | if (key == QLatin1String("xim"))
|
---|
301 | return QInputContext::tr( "XIM" );
|
---|
302 | #endif
|
---|
303 | #ifdef Q_WS_S60
|
---|
304 | if (key == QLatin1String("coefep"))
|
---|
305 | return QInputContext::tr( "FEP" );
|
---|
306 | #endif
|
---|
307 | #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
|
---|
308 | Q_UNUSED(key);
|
---|
309 | #else
|
---|
310 | if (QInputContextFactoryInterface *factory =
|
---|
311 | qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
|
---|
312 | return factory->displayName(key);
|
---|
313 | #endif // QT_NO_LIBRARY
|
---|
314 | return QString();
|
---|
315 | }
|
---|
316 |
|
---|
317 | /*!
|
---|
318 | Returns an internationalized brief description of the QInputContext
|
---|
319 | object specified by \a key. You can, for example, use this
|
---|
320 | description in a user interface.
|
---|
321 |
|
---|
322 | \sa keys(), displayName()
|
---|
323 | */
|
---|
324 | QString QInputContextFactory::description( const QString &key )
|
---|
325 | {
|
---|
326 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
---|
327 | if (key == QLatin1String("xim"))
|
---|
328 | return QInputContext::tr( "XIM input method" );
|
---|
329 | #endif
|
---|
330 | #if defined(Q_WS_WIN) && !defined(QT_NO_XIM)
|
---|
331 | if (key == QLatin1String("win"))
|
---|
332 | return QInputContext::tr( "Windows input method" );
|
---|
333 | #endif
|
---|
334 | #if defined(Q_WS_MAC)
|
---|
335 | if (key == QLatin1String("mac"))
|
---|
336 | return QInputContext::tr( "Mac OS X input method" );
|
---|
337 | #endif
|
---|
338 | #if defined(Q_WS_S60)
|
---|
339 | if (key == QLatin1String("coefep"))
|
---|
340 | return QInputContext::tr( "S60 FEP input method" );
|
---|
341 | #endif
|
---|
342 | #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
|
---|
343 | Q_UNUSED(key);
|
---|
344 | #else
|
---|
345 | if (QInputContextFactoryInterface *factory =
|
---|
346 | qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
|
---|
347 | return factory->description(key);
|
---|
348 | #endif // QT_NO_LIBRARY
|
---|
349 | return QString();
|
---|
350 | }
|
---|
351 |
|
---|
352 | QT_END_NAMESPACE
|
---|
353 |
|
---|
354 | #endif // QT_NO_IM
|
---|