source: trunk/src/gui/inputmethod/qinputcontextfactory.cpp@ 100

Last change on this file since 100 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department 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
75#include "private/qfactoryloader_p.h"
76#include "qmutex.h"
77
78QT_BEGIN_NAMESPACE
79
80#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
81Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
82 (QInputContextFactoryInterface_iid, QLatin1String("/inputmethods")))
83#endif
84
85/*!
86 \class QInputContextFactory
87 \brief The QInputContextFactory class creates QInputContext objects.
88
89 \ingroup appearance
90
91 The input context factory creates a QInputContext object for a
92 given key with QInputContextFactory::create().
93
94 The input contexts are either built-in or dynamically loaded from
95 an input context plugin (see QInputContextPlugin).
96
97 keys() returns a list of valid keys. The
98 keys are the names used, for example, to identify and specify
99 input methods for the input method switching mechanism. The names
100 have to be consistent with QInputContext::identifierName(), and
101 may only contain ASCII characters.
102
103 A key can be used to retrieve the associated input context's
104 supported languages using languages(). You
105 can retrieve the input context's description using
106 description() and finally you can get a user
107 friendly internationalized name of the QInputContext object
108 specified by the key using displayName().
109
110 \legalese
111 Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved.
112
113 This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own
114 license. You may use this file under your Qt license. Following
115 description is copied from their original file headers. Contact
116 [email protected] if any conditions of this licensing are
117 not clear to you.
118 \endlegalese
119
120 \sa QInputContext, QInputContextPlugin
121*/
122
123/*!
124 Creates and returns a QInputContext object for the input context
125 specified by \a key with the given \a parent. Keys are case
126 sensitive.
127
128 \sa keys()
129*/
130QInputContext *QInputContextFactory::create( const QString& key, QObject *parent )
131{
132 QInputContext *result = 0;
133#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
134 if (key == QLatin1String("xim")) {
135 result = new QXIMInputContext;
136 }
137#endif
138#if defined(Q_WS_WIN)
139 if (key == QLatin1String("win")) {
140 result = new QWinInputContext;
141 }
142#endif
143#if defined(Q_WS_MAC)
144 if (key == QLatin1String("mac")) {
145 result = new QMacInputContext;
146 }
147#endif
148#if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
149 Q_UNUSED(key);
150#else
151 if (QInputContextFactoryInterface *factory =
152 qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key))) {
153 result = factory->create(key);
154 }
155#endif
156 if (result)
157 result->setParent(parent);
158 return result;
159}
160
161
162/*!
163 Returns the list of keys this factory can create input contexts
164 for.
165
166 The keys are the names used, for example, to identify and specify
167 input methods for the input method switching mechanism. The names
168 have to be consistent with QInputContext::identifierName(), and
169 may only contain ASCII characters.
170
171 \sa create(), displayName(), QInputContext::identifierName()
172*/
173QStringList QInputContextFactory::keys()
174{
175 QStringList result;
176#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
177 result << QLatin1String("xim");
178#endif
179#if defined(Q_WS_WIN) && !defined(QT_NO_XIM)
180 result << QLatin1String("win");
181#endif
182#if defined(Q_WS_MAC)
183 result << QLatin1String("mac");
184#endif
185#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
186 result += loader()->keys();
187#endif // QT_NO_LIBRARY
188 return result;
189}
190
191/*!
192 Returns the languages supported by the QInputContext object
193 specified by \a key.
194
195 The languages are expressed as language code (e.g. "zh_CN",
196 "zh_TW", "zh_HK", "ja", "ko", ...). An input context that supports
197 multiple languages can return all supported languages as a
198 QStringList. The name has to be consistent with
199 QInputContext::language().
200
201 This information may be used to optimize a user interface.
202
203 \sa keys(), QInputContext::language(), QLocale
204*/
205QStringList QInputContextFactory::languages( const QString &key )
206{
207 QStringList result;
208#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
209 if (key == QLatin1String("xim"))
210 return QStringList(QString());
211#endif
212#if defined(Q_WS_WIN)
213 if (key == QLatin1String("win"))
214 return QStringList(QString());
215#endif
216#if defined(Q_WS_MAC)
217 if (key == QLatin1String("mac"))
218 return QStringList(QString());
219#endif
220#if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
221 Q_UNUSED(key);
222#else
223 if (QInputContextFactoryInterface *factory =
224 qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
225 result = factory->languages(key);
226#endif // QT_NO_LIBRARY
227 return result;
228}
229
230/*!
231 Returns a user friendly internationalized name of the
232 QInputContext object specified by \a key. You can, for example,
233 use this name in a menu.
234
235 \sa keys(), QInputContext::identifierName()
236*/
237QString QInputContextFactory::displayName( const QString &key )
238{
239 QString result;
240#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
241 if (key == QLatin1String("xim"))
242 return QInputContext::tr( "XIM" );
243#endif
244#if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
245 Q_UNUSED(key);
246#else
247 if (QInputContextFactoryInterface *factory =
248 qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
249 return factory->displayName(key);
250#endif // QT_NO_LIBRARY
251 return QString();
252}
253
254/*!
255 Returns an internationalized brief description of the QInputContext
256 object specified by \a key. You can, for example, use this
257 description in a user interface.
258
259 \sa keys(), displayName()
260*/
261QString QInputContextFactory::description( const QString &key )
262{
263#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
264 if (key == QLatin1String("xim"))
265 return QInputContext::tr( "XIM input method" );
266#endif
267#if defined(Q_WS_WIN) && !defined(QT_NO_XIM)
268 if (key == QLatin1String("win"))
269 return QInputContext::tr( "Windows input method" );
270#endif
271#if defined(Q_WS_MAC)
272 if (key == QLatin1String("mac"))
273 return QInputContext::tr( "Mac OS X input method" );
274#endif
275#if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
276 Q_UNUSED(key);
277#else
278 if (QInputContextFactoryInterface *factory =
279 qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key)))
280 return factory->description(key);
281#endif // QT_NO_LIBRARY
282 return QString();
283}
284
285QT_END_NAMESPACE
286
287#endif // QT_NO_IM
Note: See TracBrowser for help on using the repository browser.