Qt 4.8
qinputcontextfactory.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 ** immodule-qt@freedesktop.org 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 
83 
84 #ifndef QT_NO_LIBRARY
87 #endif
88 
137 {
138  QInputContext *result = 0;
139 #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
140  if (key == QLatin1String("xim")) {
141  result = new QXIMInputContext;
142  }
143 #endif
144 #if defined(Q_WS_WIN)
145  if (key == QLatin1String("win")) {
146  result = new QWinInputContext;
147  }
148 #endif
149 #if defined(Q_WS_MAC)
150  if (key == QLatin1String("mac")) {
151  result = new QMacInputContext;
152  }
153 #endif
154 #if defined(Q_WS_S60)
155  if (key == QLatin1String("coefep")) {
156  result = new QCoeFepInputContext;
157  }
158 #endif
159 #ifdef QT_NO_LIBRARY
160  Q_UNUSED(key);
161 #else
162  if (QInputContextFactoryInterface *factory =
163  qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key))) {
164  result = factory->create(key);
165  }
166 #endif
167  if (result)
168  result->setParent(parent);
169  return result;
170 }
171 
172 
185 {
186  QStringList result;
187 #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
188  result << QLatin1String("xim");
189 #endif
190 #if defined(Q_WS_WIN) && !defined(QT_NO_XIM)
191  result << QLatin1String("win");
192 #endif
193 #if defined(Q_WS_MAC)
194  result << QLatin1String("mac");
195 #endif
196 #if defined(Q_WS_S60)
197  result << QLatin1String("coefep");
198 #endif
199 #ifndef QT_NO_LIBRARY
200  result += loader()->keys();
201 #endif // QT_NO_LIBRARY
202  return result;
203 }
204 
205 #if defined(Q_WS_S60)
206 
216 static CAknInputLanguageList* s60LangListL()
217 {
218  CAknInputLanguageInfo *langInfo = AknInputLanguageInfoFactory::CreateInputLanguageInfoL();
219  CleanupStack::PushL(langInfo);
220  // In rare phone there is more than 7 languages installed -> use 7 as an array granularity
221  CAknInputLanguageList *langList = new (ELeave) CAknInputLanguageList(7);
222  CleanupStack::PushL(langList);
223  langInfo->AppendAvailableLanguagesL(langList);
224  CleanupStack::Pop(langList);
225  CleanupStack::PopAndDestroy(langInfo);
226  return langList;
227 }
228 
238 static CAknInputLanguageList* s60LangList()
239 {
240  CAknInputLanguageList *langList = NULL;
241  TRAP_IGNORE(langList = s60LangListL());
242  q_check_ptr(langList);
243  return langList;
244 }
245 #endif
246 
262 {
263  QStringList result;
264 #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
265  if (key == QLatin1String("xim"))
266  return QStringList(QString());
267 #endif
268 #if defined(Q_WS_WIN)
269  if (key == QLatin1String("win"))
270  return QStringList(QString());
271 #endif
272 #if defined(Q_WS_MAC)
273  if (key == QLatin1String("mac"))
274  return QStringList(QString());
275 #endif
276 #if defined(Q_WS_S60)
277  if (key == QLatin1String("coefep"))
278  {
279  CAknInputLanguageList *langList = s60LangList();
280  int count = langList->Count();
281  for (int i = 0; i < count; ++i)
282  {
283  result.append(QString(qt_symbianLocaleName(langList->At(i)->LanguageCode())));
284  }
285  delete langList;
286  }
287 #endif
288 #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
289  Q_UNUSED(key);
290 #else
291  if (QInputContextFactoryInterface *factory =
292  qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
293  result = factory->languages(key);
294 #endif // QT_NO_LIBRARY
295  return result;
296 }
297 
306 {
307  QString result;
308 #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
309  if (key == QLatin1String("xim"))
310  return QInputContext::tr( "XIM" );
311 #endif
312 #ifdef Q_WS_S60
313  if (key == QLatin1String("coefep"))
314  return QInputContext::tr( "FEP" );
315 #endif
316 #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
317  Q_UNUSED(key);
318 #else
319  if (QInputContextFactoryInterface *factory =
320  qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
321  return factory->displayName(key);
322 #endif // QT_NO_LIBRARY
323  return QString();
324 }
325 
334 {
335 #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
336  if (key == QLatin1String("xim"))
337  return QInputContext::tr( "XIM input method" );
338 #endif
339 #if defined(Q_WS_WIN) && !defined(QT_NO_XIM)
340  if (key == QLatin1String("win"))
341  return QInputContext::tr( "Windows input method" );
342 #endif
343 #if defined(Q_WS_MAC)
344  if (key == QLatin1String("mac"))
345  return QInputContext::tr( "Mac OS X input method" );
346 #endif
347 #if defined(Q_WS_S60)
348  if (key == QLatin1String("coefep"))
349  return QInputContext::tr( "S60 FEP input method" );
350 #endif
351 #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
352  Q_UNUSED(key);
353 #else
354  if (QInputContextFactoryInterface *factory =
355  qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
356  return factory->description(key);
357 #endif // QT_NO_LIBRARY
358  return QString();
359 }
360 
362 
363 #endif // QT_NO_IM
T * q_check_ptr(T *p)
Definition: qglobal.h:1857
static QInputContext * create(const QString &key, QObject *parent)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QString displayName(const QString &key)
Returns a user friendly internationalized name of the QInputContext object specified by key...
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QStringList keys()
Returns the list of keys this factory can create input contexts for.
#define QInputContextFactoryInterface_iid
static QStringList languages(const QString &key)
Returns the languages supported by the QInputContext object specified by key.
int key
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
static QString description(const QString &key)
Returns an internationalized brief description of the QInputContext object specified by key...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
Declares a global static variable with the specified type and name.
Definition: qglobal.h:1982