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 "qmousedriverfactory_qws.h"
43
44 #include "qapplication.h"
45 #include "qmousepc_qws.h"
46 #include "qmouselinuxtp_qws.h"
47 #include "qmouselinuxinput_qws.h"
48 #include "qmousevfb_qws.h"
49 #include "qmousetslib_qws.h"
50 #include "qmouseqnx_qws.h"
51 #include "qmouseintegrity_qws.h"
52 #include <stdlib.h>
53 #include "private/qfactoryloader_p.h"
54 #include "qmousedriverplugin_qws.h"
55 #include "qdebug.h"
56
57 QT_BEGIN_NAMESPACE
58
59 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
60 #ifndef QT_NO_LIBRARY
61
62 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
63 (QWSMouseHandlerFactoryInterface_iid,
64 QLatin1String("/mousedrivers"), Qt::CaseInsensitive))
65
66 #endif //QT_NO_LIBRARY
67 #endif //QT_MAKEDLL
68
69 /*!
70 \class QMouseDriverFactory
71 \ingroup qws
72
73 \brief The QMouseDriverFactory class creates mouse drivers in
74 Qt for Embedded Linux.
75
76 Note that this class is only available in \l{Qt for Embedded Linux}.
77
78 QMouseDriverFactory is used to detect and instantiate the
79 available mouse drivers, allowing \l{Qt for Embedded Linux} to load the
80 preferred driver into the server application at runtime. The
81 create() function returns a QWSMouseHandler object representing
82 the mouse driver identified by a given key. The valid keys
83 (i.e. the supported drivers) can be retrieved using the keys()
84 function.
85
86 \l{Qt for Embedded Linux} provides several built-in mouse drivers. In
87 addition, custom mouse drivers can be added using Qt's plugin
88 mechanism, i.e. by subclassing the QWSMouseHandler class and
89 creating a mouse driver plugin (QMouseDriverPlugin). See the
90 \l{Qt for Embedded Linux Pointer Handling}{pointer handling}
91 documentation for details.
92
93 \sa QWSMouseHandler, QMouseDriverPlugin
94 */
95
96 /*!
97 Creates the mouse driver specified by the given \a key, using the
98 display specified by the given \a device.
99
100 Note that the keys are case-insensitive.
101
102 \sa keys()
103 */
create(const QString & key,const QString & device)104 QWSMouseHandler *QMouseDriverFactory::create(const QString& key, const QString &device)
105 {
106 QString driver = key.toLower();
107 #if defined(Q_OS_QNX) && !defined(QT_NO_QWS_MOUSE_QNX)
108 if (driver == QLatin1String("qnx") || driver.isEmpty())
109 return new QQnxMouseHandler(key, device);
110 #endif
111 #if defined(Q_OS_INTEGRITY) && !defined(QT_NO_MOUSE_INTEGRITY)
112 if (driver == QLatin1String("integrity") || driver.isEmpty())
113 return new QIntMouseHandler(key, device);
114 #endif
115 #ifndef QT_NO_QWS_MOUSE_LINUXTP
116 if (driver == QLatin1String("linuxtp") || driver.isEmpty())
117 return new QWSLinuxTPMouseHandler(key, device);
118 #endif
119 #ifndef QT_NO_QWS_MOUSE_PC
120 if (driver == QLatin1String("auto")
121 || driver == QLatin1String("intellimouse")
122 || driver == QLatin1String("microsoft")
123 || driver == QLatin1String("mousesystems")
124 || driver == QLatin1String("mouseman")
125 || driver.isEmpty()) {
126 return new QWSPcMouseHandler(key, device);
127 }
128 #endif
129 #ifndef QT_NO_QWS_MOUSE_TSLIB
130 if (driver == QLatin1String("tslib") || driver.isEmpty())
131 return new QWSTslibMouseHandler(key, device);
132 #endif
133 # ifndef QT_NO_QWS_MOUSE_LINUXINPUT
134 if (driver == QLatin1String("linuxinput") || \
135 driver == QLatin1String("usb") || \
136 driver == QLatin1String("linuxis"))
137 return new QWSLinuxInputMouseHandler(device);
138 # endif
139 #ifndef QT_NO_QWS_MOUSE_QVFB
140 if (driver == QLatin1String("qvfbmouse") || driver == QLatin1String("qvfb"))
141 return new QVFbMouseHandler(key, device);
142 #endif
143
144 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
145 #ifndef QT_NO_LIBRARY
146 if (QWSMouseHandlerFactoryInterface *factory = qobject_cast<QWSMouseHandlerFactoryInterface*>(loader()->instance(driver)))
147 return factory->create(driver, device);
148 #endif
149 #endif
150 return 0;
151 }
152
153 /*!
154 Returns the list of valid keys, i.e. the available mouse drivers.
155
156 \sa create()
157 */
keys()158 QStringList QMouseDriverFactory::keys()
159 {
160 QStringList list;
161
162 #if defined(Q_OS_QNX) && !defined(QT_NO_QWS_MOUSE_QNX)
163 list << QLatin1String("QNX");
164 #endif
165 #if defined(Q_OS_INTEGRITY) && !defined(QT_NO_QWS_MOUSE_INTEGRITY)
166 list << QLatin1String("INTEGRITY");
167 #endif
168 #ifndef QT_NO_QWS_MOUSE_LINUXTP
169 list << QLatin1String("LinuxTP");
170 #endif
171 #ifndef QT_NO_QWS_MOUSE_PC
172 list << QLatin1String("Auto")
173 << QLatin1String("IntelliMouse")
174 << QLatin1String("Microsoft")
175 << QLatin1String("MouseSystems")
176 << QLatin1String("MouseMan");
177 #endif
178 #ifndef QT_NO_QWS_MOUSE_TSLIB
179 list << QLatin1String("Tslib");
180 #endif
181 #ifndef QT_NO_QWS_MOUSE_LINUXINPUT
182 list << QLatin1String("LinuxInput");
183 #endif
184
185 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
186 #ifndef QT_NO_LIBRARY
187 QStringList plugins = loader()->keys();
188 for (int i = 0; i < plugins.size(); ++i) {
189 if (!list.contains(plugins.at(i)))
190 list += plugins.at(i);
191 }
192 #endif //QT_NO_LIBRARY
193 #endif //QT_MAKEDLL
194 return list;
195 }
196
197 QT_END_NAMESPACE
198