1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qkbddriverfactory_qws.h"
43
44 #ifndef QT_NO_QWS_KEYBOARD
45
46 #include "qapplication.h"
47 #include "qkbdtty_qws.h"
48 #include "qkbdlinuxinput_qws.h"
49 #include "qkbdum_qws.h"
50 #include "qkbdvfb_qws.h"
51 #include "qkbdqnx_qws.h"
52 #include "qkbdintegrity_qws.h"
53 #include <stdlib.h>
54 #include "private/qfactoryloader_p.h"
55 #include "qkbddriverplugin_qws.h"
56
57 QT_BEGIN_NAMESPACE
58
59 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
60 #ifndef QT_NO_LIBRARY
61 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
62 (QWSKeyboardHandlerFactoryInterface_iid,
63 QLatin1String("/kbddrivers"), Qt::CaseInsensitive))
64
65 #endif //QT_NO_LIBRARY
66 #endif //QT_MAKEDLL
67
68 /*!
69 \class QKbdDriverFactory
70 \ingroup qws
71
72 \brief The QKbdDriverFactory class creates keyboard drivers in
73 Qt for Embedded Linux.
74
75 Note that this class is only available in \l{Qt for Embedded Linux}.
76
77 QKbdDriverFactory is used to detect and instantiate the available
78 keyboard drivers, allowing \l{Qt for Embedded Linux} to load the preferred
79 driver into the server application at runtime. The create()
80 function returns a QWSKeyboardHandler object representing the
81 keyboard driver identified by a given key. The valid keys
82 (i.e. the supported drivers) can be retrieved using the keys()
83 function.
84
85 \l{Qt for Embedded Linux} provides several built-in keyboard drivers. In
86 addition, custom keyboard drivers can be added using Qt's plugin
87 mechanism, i.e. by subclassing the QWSKeyboardHandler class and
88 creating a keyboard driver plugin (QKbdDriverPlugin). See the
89 \l{Qt for Embedded Linux Character Input}{character input} documentation
90 for details.
91
92 \sa QWSKeyboardHandler, QKbdDriverPlugin
93 */
94
95 /*!
96 Creates the keyboard driver specified by the given \a key, using
97 the display specified by the given \a device.
98
99 Note that the keys are case-insensitive.
100
101 \sa keys()
102 */
create(const QString & key,const QString & device)103 QWSKeyboardHandler *QKbdDriverFactory::create(const QString& key, const QString& device)
104 {
105 QString driver = key.toLower();
106 #if defined(Q_OS_QNX) && !defined(QT_NO_QWS_KBD_QNX)
107 if (driver == QLatin1String("qnx") || driver.isEmpty())
108 return new QWSQnxKeyboardHandler(device);
109 #endif
110 #if defined(Q_OS_INTEGRITY)
111 if (driver == QLatin1String("integrity") || driver.isEmpty())
112 return new QWSIntKeyboardHandler(device);
113 #endif
114 #ifndef QT_NO_QWS_KEYBOARD
115 # ifndef QT_NO_QWS_KBD_TTY
116 if (driver == QLatin1String("tty") || driver.isEmpty())
117 return new QWSTtyKeyboardHandler(device);
118 # endif
119 # ifndef QT_NO_QWS_KBD_LINUXINPUT
120 if (driver == QLatin1String("linuxinput") || \
121 driver == QLatin1String("usb") || \
122 driver == QLatin1String("linuxis"))
123 return new QWSLinuxInputKeyboardHandler(device);
124 # endif
125 # ifndef QT_NO_QWS_KBD_UM
126 if (driver == QLatin1String("um") || driver == QLatin1String("qvfbkeyboard"))
127 return new QWSUmKeyboardHandler(device);
128 # endif
129 # ifndef QT_NO_QWS_KBD_QVFB
130 if (driver == QLatin1String("qvfbkbd")
131 || driver == QLatin1String("qvfbkeyboard")
132 || driver == QLatin1String("qvfb"))
133 return new QVFbKeyboardHandler(device);
134 # endif
135 #endif
136
137 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
138 #ifndef QT_NO_LIBRARY
139 if (QWSKeyboardHandlerFactoryInterface *factory = qobject_cast<QWSKeyboardHandlerFactoryInterface*>(loader()->instance(driver)))
140 return factory->create(driver, device);
141 #endif
142 #endif
143 return 0;
144 }
145
146 /*!
147 Returns the list of valid keys, i.e. the available keyboard
148 drivers.
149
150 \sa create()
151 */
keys()152 QStringList QKbdDriverFactory::keys()
153 {
154 QStringList list;
155
156 #if defined(Q_OS_QNX) && !defined(QT_NO_QWS_KBD_QNX)
157 list << QLatin1String("QNX");
158 #endif
159 #if defined(Q_OS_INTEGRITY) && !defined(QT_NO_QWS_KBD_INTEGRITY)
160 list << QLatin1String("INTEGRITY");
161 #endif
162 #ifndef QT_NO_QWS_KBD_TTY
163 list << QLatin1String("TTY");
164 #endif
165 #ifndef QT_NO_QWS_KBD_LINUXINPUT
166 list << QLatin1String("LinuxInput");
167 #endif
168 #ifndef QT_NO_QWS_KBD_UM
169 list << QLatin1String("UM");
170 #endif
171
172 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
173 #ifndef QT_NO_LIBRARY
174 QStringList plugins = loader()->keys();
175 for (int i = 0; i < plugins.size(); ++i) {
176 if (!list.contains(plugins.at(i)))
177 list += plugins.at(i);
178 }
179 #endif //QT_NO_LIBRARY
180 #endif //QT_MAKEDLL
181
182 return list;
183 }
184
185 QT_END_NAMESPACE
186
187 #endif // QT_NO_QWS_KEYBOARD
188