| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 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 | #endif
|
|---|
| 77 |
|
|---|
| 78 | #include "private/qfactoryloader_p.h"
|
|---|
| 79 | #include "qmutex.h"
|
|---|
| 80 |
|
|---|
| 81 | QT_BEGIN_NAMESPACE
|
|---|
| 82 |
|
|---|
| 83 | #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
|
|---|
| 84 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
|
|---|
| 85 | (QInputContextFactoryInterface_iid, QLatin1String("/inputmethods")))
|
|---|
| 86 | #endif
|
|---|
| 87 |
|
|---|
| 88 | /*!
|
|---|
| 89 | \class QInputContextFactory
|
|---|
| 90 | \brief The QInputContextFactory class creates QInputContext objects.
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | The input context factory creates a QInputContext object for a
|
|---|
| 94 | given key with QInputContextFactory::create().
|
|---|
| 95 |
|
|---|
| 96 | The input contexts are either built-in or dynamically loaded from
|
|---|
| 97 | an input context plugin (see QInputContextPlugin).
|
|---|
| 98 |
|
|---|
| 99 | keys() returns a list of valid keys. The
|
|---|
| 100 | keys are the names used, for example, to identify and specify
|
|---|
| 101 | input methods for the input method switching mechanism. The names
|
|---|
| 102 | have to be consistent with QInputContext::identifierName(), and
|
|---|
| 103 | may only contain ASCII characters.
|
|---|
| 104 |
|
|---|
| 105 | A key can be used to retrieve the associated input context's
|
|---|
| 106 | supported languages using languages(). You
|
|---|
| 107 | can retrieve the input context's description using
|
|---|
| 108 | description() and finally you can get a user
|
|---|
| 109 | friendly internationalized name of the QInputContext object
|
|---|
| 110 | specified by the key using displayName().
|
|---|
| 111 |
|
|---|
| 112 | \legalese
|
|---|
| 113 | Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved.
|
|---|
| 114 |
|
|---|
| 115 | This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own
|
|---|
| 116 | license. You may use this file under your Qt license. Following
|
|---|
| 117 | description is copied from their original file headers. Contact
|
|---|
| 118 | [email protected] if any conditions of this licensing are
|
|---|
| 119 | not clear to you.
|
|---|
| 120 | \endlegalese
|
|---|
| 121 |
|
|---|
| 122 | \sa QInputContext, QInputContextPlugin
|
|---|
| 123 | */
|
|---|
| 124 |
|
|---|
| 125 | /*!
|
|---|
| 126 | Creates and returns a QInputContext object for the input context
|
|---|
| 127 | specified by \a key with the given \a parent. Keys are case
|
|---|
| 128 | sensitive.
|
|---|
| 129 |
|
|---|
| 130 | \sa keys()
|
|---|
| 131 | */
|
|---|
| 132 | QInputContext *QInputContextFactory::create( const QString& key, QObject *parent )
|
|---|
| 133 | {
|
|---|
| 134 | QInputContext *result = 0;
|
|---|
| 135 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
|---|
| 136 | if (key == QLatin1String("xim")) {
|
|---|
| 137 | result = new QXIMInputContext;
|
|---|
| 138 | }
|
|---|
| 139 | #endif
|
|---|
| 140 | #if defined(Q_WS_WIN)
|
|---|
| 141 | if (key == QLatin1String("win")) {
|
|---|
| 142 | result = new QWinInputContext;
|
|---|
| 143 | }
|
|---|
| 144 | #endif
|
|---|
| 145 | #if defined(Q_WS_MAC)
|
|---|
| 146 | if (key == QLatin1String("mac")) {
|
|---|
| 147 | result = new QMacInputContext;
|
|---|
| 148 | }
|
|---|
| 149 | #endif
|
|---|
| 150 | #if defined(Q_WS_S60)
|
|---|
| 151 | if (key == QLatin1String("coefep")) {
|
|---|
| 152 | result = new QCoeFepInputContext;
|
|---|
| 153 | }
|
|---|
| 154 | #endif
|
|---|
| 155 | #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
|
|---|
| 156 | Q_UNUSED(key);
|
|---|
| 157 | #else
|
|---|
| 158 | if (QInputContextFactoryInterface *factory =
|
|---|
| 159 | qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key))) {
|
|---|
| 160 | result = factory->create(key);
|
|---|
| 161 | }
|
|---|
| 162 | #endif
|
|---|
| 163 | if (result)
|
|---|
| 164 | result->setParent(parent);
|
|---|
| 165 | return result;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 | /*!
|
|---|
| 170 | Returns the list of keys this factory can create input contexts
|
|---|
| 171 | for.
|
|---|
| 172 |
|
|---|
| 173 | The keys are the names used, for example, to identify and specify
|
|---|
| 174 | input methods for the input method switching mechanism. The names
|
|---|
| 175 | have to be consistent with QInputContext::identifierName(), and
|
|---|
| 176 | may only contain ASCII characters.
|
|---|
| 177 |
|
|---|
| 178 | \sa create(), displayName(), QInputContext::identifierName()
|
|---|
| 179 | */
|
|---|
| 180 | QStringList QInputContextFactory::keys()
|
|---|
| 181 | {
|
|---|
| 182 | QStringList result;
|
|---|
| 183 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
|---|
| 184 | result << QLatin1String("xim");
|
|---|
| 185 | #endif
|
|---|
| 186 | #if defined(Q_WS_WIN) && !defined(QT_NO_XIM)
|
|---|
| 187 | result << QLatin1String("win");
|
|---|
| 188 | #endif
|
|---|
| 189 | #if defined(Q_WS_MAC)
|
|---|
| 190 | result << QLatin1String("mac");
|
|---|
| 191 | #endif
|
|---|
| 192 | #if defined(Q_WS_S60)
|
|---|
| 193 | result << QLatin1String("coefep");
|
|---|
| 194 | #endif
|
|---|
| 195 | #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
|
|---|
| 196 | result += loader()->keys();
|
|---|
| 197 | #endif // QT_NO_LIBRARY
|
|---|
| 198 | return result;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | /*!
|
|---|
| 202 | Returns the languages supported by the QInputContext object
|
|---|
| 203 | specified by \a key.
|
|---|
| 204 |
|
|---|
| 205 | The languages are expressed as language code (e.g. "zh_CN",
|
|---|
| 206 | "zh_TW", "zh_HK", "ja", "ko", ...). An input context that supports
|
|---|
| 207 | multiple languages can return all supported languages as a
|
|---|
| 208 | QStringList. The name has to be consistent with
|
|---|
| 209 | QInputContext::language().
|
|---|
| 210 |
|
|---|
| 211 | This information may be used to optimize a user interface.
|
|---|
| 212 |
|
|---|
| 213 | \sa keys(), QInputContext::language(), QLocale
|
|---|
| 214 | */
|
|---|
| 215 | QStringList QInputContextFactory::languages( const QString &key )
|
|---|
| 216 | {
|
|---|
| 217 | QStringList result;
|
|---|
| 218 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
|---|
| 219 | if (key == QLatin1String("xim"))
|
|---|
| 220 | return QStringList(QString());
|
|---|
| 221 | #endif
|
|---|
| 222 | #if defined(Q_WS_WIN)
|
|---|
| 223 | if (key == QLatin1String("win"))
|
|---|
| 224 | return QStringList(QString());
|
|---|
| 225 | #endif
|
|---|
| 226 | #if defined(Q_WS_MAC)
|
|---|
| 227 | if (key == QLatin1String("mac"))
|
|---|
| 228 | return QStringList(QString());
|
|---|
| 229 | #endif
|
|---|
| 230 | #if defined(Q_WS_S60)
|
|---|
| 231 | if (key == QLatin1String("coefep"))
|
|---|
| 232 | return QStringList(QString());
|
|---|
| 233 | #endif
|
|---|
| 234 | #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
|
|---|
| 235 | Q_UNUSED(key);
|
|---|
| 236 | #else
|
|---|
| 237 | if (QInputContextFactoryInterface *factory =
|
|---|
| 238 | qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
|
|---|
| 239 | result = factory->languages(key);
|
|---|
| 240 | #endif // QT_NO_LIBRARY
|
|---|
| 241 | return result;
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | /*!
|
|---|
| 245 | Returns a user friendly internationalized name of the
|
|---|
| 246 | QInputContext object specified by \a key. You can, for example,
|
|---|
| 247 | use this name in a menu.
|
|---|
| 248 |
|
|---|
| 249 | \sa keys(), QInputContext::identifierName()
|
|---|
| 250 | */
|
|---|
| 251 | QString QInputContextFactory::displayName( const QString &key )
|
|---|
| 252 | {
|
|---|
| 253 | QString result;
|
|---|
| 254 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
|---|
| 255 | if (key == QLatin1String("xim"))
|
|---|
| 256 | return QInputContext::tr( "XIM" );
|
|---|
| 257 | #endif
|
|---|
| 258 | #ifdef Q_WS_S60
|
|---|
| 259 | if (key == QLatin1String("coefep"))
|
|---|
| 260 | return QInputContext::tr( "FEP" );
|
|---|
| 261 | #endif
|
|---|
| 262 | #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
|
|---|
| 263 | Q_UNUSED(key);
|
|---|
| 264 | #else
|
|---|
| 265 | if (QInputContextFactoryInterface *factory =
|
|---|
| 266 | qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
|
|---|
| 267 | return factory->displayName(key);
|
|---|
| 268 | #endif // QT_NO_LIBRARY
|
|---|
| 269 | return QString();
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | /*!
|
|---|
| 273 | Returns an internationalized brief description of the QInputContext
|
|---|
| 274 | object specified by \a key. You can, for example, use this
|
|---|
| 275 | description in a user interface.
|
|---|
| 276 |
|
|---|
| 277 | \sa keys(), displayName()
|
|---|
| 278 | */
|
|---|
| 279 | QString QInputContextFactory::description( const QString &key )
|
|---|
| 280 | {
|
|---|
| 281 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM)
|
|---|
| 282 | if (key == QLatin1String("xim"))
|
|---|
| 283 | return QInputContext::tr( "XIM input method" );
|
|---|
| 284 | #endif
|
|---|
| 285 | #if defined(Q_WS_WIN) && !defined(QT_NO_XIM)
|
|---|
| 286 | if (key == QLatin1String("win"))
|
|---|
| 287 | return QInputContext::tr( "Windows input method" );
|
|---|
| 288 | #endif
|
|---|
| 289 | #if defined(Q_WS_MAC)
|
|---|
| 290 | if (key == QLatin1String("mac"))
|
|---|
| 291 | return QInputContext::tr( "Mac OS X input method" );
|
|---|
| 292 | #endif
|
|---|
| 293 | #if defined(Q_WS_S60)
|
|---|
| 294 | if (key == QLatin1String("coefep"))
|
|---|
| 295 | return QInputContext::tr( "S60 FEP input method" );
|
|---|
| 296 | #endif
|
|---|
| 297 | #if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
|
|---|
| 298 | Q_UNUSED(key);
|
|---|
| 299 | #else
|
|---|
| 300 | if (QInputContextFactoryInterface *factory =
|
|---|
| 301 | qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
|
|---|
| 302 | return factory->description(key);
|
|---|
| 303 | #endif // QT_NO_LIBRARY
|
|---|
| 304 | return QString();
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | QT_END_NAMESPACE
|
|---|
| 308 |
|
|---|
| 309 | #endif // QT_NO_IM
|
|---|