on xenial help sign in
update tests
2e9b248Michael Zanetti
plugins/Unity/InputInfo/qinputinfo.cpp+3−1
@@ -41,7 +41,9 @@
41
41
42#include "qinputinfo.h"
42#include "qinputinfo.h"
43
43
44+#if defined(UNITY_MOCKS)
45+#include "qinputdeviceinfo_mock.h"
44−#if defined(Q_OS_LINUX)
46+#elif defined(Q_OS_LINUX)
45#include "linux/qinputdeviceinfo_linux_p.h"
47#include "linux/qinputdeviceinfo_linux_p.h"
46#endif
48#endif
47
49
qml/OrientedShell.qml+17−7
@@ -16,13 +16,12 @@
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18import QtQuick.Window 2.0
18import QtQuick.Window 2.0
19+import Unity.InputInfo 0.1
19import Unity.Session 0.1
20import Unity.Session 0.1
20import GSettings 1.0
21import GSettings 1.0
21import "Components"
22import "Components"
22−import "Components/UnityInputInfo"
23import "Rotation"
23import "Rotation"
24−// Backup Workaround https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1473471
24+// Workaround https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1473471
25−// in case we remove the UnityInputInfo import
26import Ubuntu.Components 1.2
25import Ubuntu.Components 1.2
27
26
28Rectangle {
27Rectangle {
@@ -53,6 +52,17 @@ Rectangle {
53 property bool orientationLocked: OrientationLock.enabled
52 property bool orientationLocked: OrientationLock.enabled
54 property var orientationLock: OrientationLock
53 property var orientationLock: OrientationLock
55
54
55+ InputDeviceModel {
56+ id: miceModel
57+ deviceFilter: InputInfo.Mouse
58+ onCountChanged: print("*****************", count)
59+ }
60+
61+ InputDeviceModel {
62+ id: keyboardsModel
63+ deviceFilter: InputInfo.Keyboard
64+ }
65+
56 property int orientation
66 property int orientation
57 onPhysicalOrientationChanged: {
67 onPhysicalOrientationChanged: {
58 if (!orientationLocked) {
68 if (!orientationLocked) {
@@ -72,14 +82,14 @@ Rectangle {
72 }
82 }
73 // We need to manually update this on startup as the binding
83 // We need to manually update this on startup as the binding
74 // below doesn't seem to have any effect at that stage
84 // below doesn't seem to have any effect at that stage
75− oskSettings.stayHidden = UnityInputInfo.keyboards > 0
85+ oskSettings.stayHidden = keyboardsModel.count > 0
76 oskSettings.disableHeight = shell.usageScenario == "desktop"
86 oskSettings.disableHeight = shell.usageScenario == "desktop"
77 }
87 }
78
88
79 Binding {
89 Binding {
80 target: oskSettings
90 target: oskSettings
81 property: "stayHidden"
91 property: "stayHidden"
82− value: UnityInputInfo.keyboards > 0
92+ value: keyboardsModel.count > 0
83 }
93 }
84
94
85 Binding {
95 Binding {
@@ -155,7 +165,7 @@ Rectangle {
155 nativeWidth: root.width
165 nativeWidth: root.width
156 nativeHeight: root.height
166 nativeHeight: root.height
157 mode: applicationArguments.mode
167 mode: applicationArguments.mode
158− hasMouse: UnityInputInfo.mice > deviceConfiguration.ignoredMice
168+ hasMouse: miceModel.count > deviceConfiguration.ignoredMice
159
169
160 // TODO: Factor in the connected input devices (eg: physical keyboard, mouse, touchscreen),
170 // TODO: Factor in the connected input devices (eg: physical keyboard, mouse, touchscreen),
161 // what's the output device (eg: big TV, desktop monitor, phone display), etc.
171 // what's the output device (eg: big TV, desktop monitor, phone display), etc.
@@ -169,7 +179,7 @@ Rectangle {
169 return "tablet";
179 return "tablet";
170 }
180 }
171 } else { // automatic
181 } else { // automatic
172− if (UnityInputInfo.mice > deviceConfiguration.ignoredMice) {
182+ if (miceModel.count > deviceConfiguration.ignoredMice) {
173 return "desktop";
183 return "desktop";
174 } else {
184 } else {
175 return deviceConfiguration.category;
185 return deviceConfiguration.category;
tests/mocks/Unity/InputInfo/CMakeLists.txt+6−2
@@ -9,12 +9,16 @@ find_package(Qt5Quick REQUIRED)
9include_directories(
9include_directories(
10 ${CMAKE_CURRENT_SOURCE_DIR}
10 ${CMAKE_CURRENT_SOURCE_DIR}
11 ${CMAKE_CURRENT_BINARY_DIR}
11 ${CMAKE_CURRENT_BINARY_DIR}
12+ ${CMAKE_SOURCE_DIR}/plugins/Unity/InputInfo/
12)
13)
13
14
15+add_definitions(-DUNITY_MOCKS)
16+
14set(MockInputInfo_SOURCES
17set(MockInputInfo_SOURCES
15 plugin.cpp
18 plugin.cpp
16− mockqinputinfo.cpp
19+ qinputdeviceinfo_mock.cpp
17− mockqdeclarativeinputdeviceinfo.cpp
20+ ${CMAKE_SOURCE_DIR}/plugins/Unity/InputInfo/qinputinfo.cpp
21+ ${CMAKE_SOURCE_DIR}/plugins/Unity/InputInfo/qdeclarativeinputdevicemodel.cpp
18)
22)
19
23
20add_library(MockInputInfo SHARED
24add_library(MockInputInfo SHARED
tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo.cppdeleted−173
@@ -1,173 +0,0 @@
1−/****************************************************************************
2−**
3−** Copyright (C) 2015 Jolla.
4−** Copyright (C) 2015 Canonical Ltd.
5−** Contact: http://www.qt-project.org/legal
6−**
7−** This file is part of the QtSystems module of the Qt Toolkit.
8−**
9−** $QT_BEGIN_LICENSE:LGPL$
10−** Commercial License Usage
11−** Licensees holding valid commercial Qt licenses may use this file in
12−** accordance with the commercial license agreement provided with the
13−** Software or, alternatively, in accordance with the terms contained in
14−** a written agreement between you and Digia. For licensing terms and
15−** conditions see http://qt.digia.com/licensing. For further information
16−** use the contact form at http://qt.digia.com/contact-us.
17−**
18−** GNU Lesser General Public License Usage
19−** Alternatively, this file may be used under the terms of the GNU Lesser
20−** General Public License version 2.1 as published by the Free Software
21−** Foundation and appearing in the file LICENSE.LGPL included in the
22−** packaging of this file. Please review the following information to
23−** ensure the GNU Lesser General Public License version 2.1 requirements
24−** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25−**
26−** In addition, as a special exception, Digia gives you certain additional
27−** rights. These rights are described in the Digia Qt 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−**
39−** $QT_END_LICENSE$
40−**
41−****************************************************************************/
42−#include "mockqdeclarativeinputdeviceinfo_p.h"
43−
44−QDeclarativeInputDeviceInfo::QDeclarativeInputDeviceInfo(QObject *parent) :
45− QAbstractListModel(parent),
46− deviceInfo(new QInputDeviceInfo)
47−{
48− connect(deviceInfo, &QInputDeviceInfo::deviceAdded,this,&QDeclarativeInputDeviceInfo::addedDevice);
49− connect(deviceInfo, &QInputDeviceInfo::deviceRemoved,this,&QDeclarativeInputDeviceInfo::removedDevice);
50−}
51−
52−QDeclarativeInputDeviceInfo::~QDeclarativeInputDeviceInfo()
53−{
54− delete deviceInfo;
55−}
56−
57−QVariant QDeclarativeInputDeviceInfo::data(const QModelIndex &index, int role) const
58−{
59− switch (role) {
60− case ServiceRole:
61− return QVariant::fromValue(static_cast<QObject *>(inputDevices.value(index.row())));
62− }
63−
64− return QVariant();
65−}
66−
67−int QDeclarativeInputDeviceInfo::rowCount(const QModelIndex &parent) const
68−{
69− Q_UNUSED(parent);
70−
71− return inputDevices.count();
72−}
73−
74−int QDeclarativeInputDeviceInfo::indexOf(const QString &devicePath) const
75−{
76− int idx(-1);
77− Q_FOREACH (QInputDevice *device, inputDevices) {
78− idx++;
79− if (device->devicePath() == devicePath) return idx;
80− }
81−
82− return -1;
83−}
84−
85−QInputDevice *QDeclarativeInputDeviceInfo::get(int index) const
86−{
87− if (index < 0 || index > inputDevices.count())
88− return 0;
89− return inputDevices.value(index);
90−}
91−
92−void QDeclarativeInputDeviceInfo::addMockMouse()
93−{
94− deviceInfo->addMockDevice(QInputDeviceInfo::Mouse);
95−}
96−
97−void QDeclarativeInputDeviceInfo::addMockKeyboard()
98−{
99− deviceInfo->addMockDevice(QInputDeviceInfo::Keyboard);
100−}
101−
102−void QDeclarativeInputDeviceInfo::removeMockMouse()
103−{
104− for (int i = 0; i < inputDevices.count(); i++) {
105− if (inputDevices.at(i)->types().testFlag(QInputDeviceInfo::Mouse)) {
106− deviceInfo->removeMockDevice(i);
107− return;
108− }
109− }
110−}
111−
112−void QDeclarativeInputDeviceInfo::removeMockKeyboard()
113−{
114− for (int i = 0; i < inputDevices.count(); i++) {
115− if (inputDevices.at(i)->types().testFlag(QInputDeviceInfo::Keyboard)) {
116− deviceInfo->removeMockDevice(i);
117− return;
118− }
119− }
120−}
121−
122−void QDeclarativeInputDeviceInfo::updateDeviceList()
123−{
124− QVector <QInputDevice *> newDevices = deviceInfo->deviceList();
125−
126− int numNew = newDevices.count();
127−
128− for (int i = 0; i < numNew; i++) {
129− int j = inputDevices.indexOf(newDevices.value(i));
130− if (j == -1) {
131− // not found -> remove from list
132− beginInsertRows(QModelIndex(), i, i);
133− inputDevices.insert(i, newDevices.value(i));
134− endInsertRows();
135− } else if (i != j) {
136− // changed its position -> move it
137− QInputDevice* device = inputDevices.value(j);
138− beginMoveRows(QModelIndex(), j, j, QModelIndex(), i);
139− inputDevices.remove(j);
140− inputDevices.insert(i, device);
141− endMoveRows();
142− } else {
143− QModelIndex changedIndex(this->index(j, 0, QModelIndex()));
144− Q_EMIT dataChanged(changedIndex, changedIndex);
145− }
146− }
147−
148− int numOld = inputDevices.count();
149− if (numOld > numNew) {
150− beginRemoveRows(QModelIndex(), numNew, numOld - 1);
151− inputDevices.remove(numNew, numOld - numNew);
152− endRemoveRows();
153− }
154−}
155−
156−void QDeclarativeInputDeviceInfo::addedDevice(const QString &devicePath)
157−{
158− updateDeviceList();
159− Q_EMIT newDevice(devicePath);
160−}
161−
162−void QDeclarativeInputDeviceInfo::removedDevice(const QString &devicePath)
163−{
164− updateDeviceList();
165− Q_EMIT deviceRemoved(devicePath);
166−}
167−
168−QHash<int, QByteArray> QDeclarativeInputDeviceInfo::roleNames() const
169−{
170− QHash<int, QByteArray> roles;
171− roles.insert(ServiceRole, "service");
172− return roles;
173−}
tests/mocks/Unity/InputInfo/mockqinputinfo.hdeleted−139
@@ -1,139 +0,0 @@
1−/****************************************************************************
2−**
3−** Copyright (C) 2015 Canonical, Ltd. and/or its subsidiary(-ies).
4−** Contact: http://www.qt-project.org/legal
5−**
6−** This file is part of the QtSystems 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−#ifndef MOCKQINPUTINFO_H
43−#define MOCKQINPUTINFO_H
44−
45−#include <QObject>
46−#include <QVector>
47−#include <QMap>
48−#include <QSocketNotifier>
49−#include <QDebug>
50−
51−class QInputDevicePrivate;
52−class QInputDevice;
53−
54−class QInputDeviceInfoPrivate;
55−class QInputDeviceInfo : public QObject
56−{
57− Q_OBJECT
58− Q_PROPERTY(int deviceCount READ deviceCount)
59−public:
60−
61− enum InputType {
62− Unknown = 0,
63− Button = 1,
64− Mouse = 2,
65− TouchPad = 4,
66− TouchScreen = 8,
67− Keyboard = 16,
68− Switch = 32
69− };
70− Q_ENUMS(InputType)
71− Q_FLAGS(InputTypes)
72− Q_DECLARE_FLAGS(InputTypes, InputType)
73−
74− explicit QInputDeviceInfo(QObject *parent = 0);
75−
76− Q_INVOKABLE QVector <QInputDevice *> deviceList();
77−
78− int deviceCount() { return deviceList().count(); }
79−
80− Q_INVOKABLE void addMockDevice(InputType inputType);
81− Q_INVOKABLE void removeMockDevice(int index);
82−
83−Q_SIGNALS:
84−
85− void deviceAdded(const QString & devicePath);
86− void deviceRemoved(const QString & devicePath);
87−
88−private:
89− QVector<QInputDevice*> m_list;
90−
91− int m_counter = 0;
92−};
93−
94−class QInputDevice : public QObject
95−{
96− friend class QInputDeviceInfoPrivate;
97− Q_OBJECT
98− Q_ENUMS(InputType)
99− Q_FLAGS(InputTypes)
100− Q_PROPERTY(QString name READ name NOTIFY nameChanged)
101− Q_PROPERTY(QString devicePath READ devicePath NOTIFY devicePathChanged)
102− Q_PROPERTY(QList <int> buttons READ buttons NOTIFY buttonsChanged)
103− Q_PROPERTY(QList <int> switches READ switches NOTIFY switchesChanged)
104− Q_PROPERTY(QList <int> relativeAxis READ relativeAxis NOTIFY relativeAxisChanged)
105− Q_PROPERTY(QList <int> absoluteAxis READ absoluteAxis NOTIFY absoluteAxisChanged)
106− Q_PROPERTY(QInputDeviceInfo::InputTypes types READ types NOTIFY typesChanged)
107−
108−public:
109− explicit QInputDevice(QObject *parent = 0);
110−
111− QString name() const;
112− QString devicePath() const;
113− QList <int> buttons() const; //keys event code
114− QList <int> switches() const;
115− QList <int> relativeAxis() const;
116− QList <int> absoluteAxis() const;
117−
118− QInputDeviceInfo::InputTypes types();
119−Q_SIGNALS:
120− void nameChanged();
121− void devicePathChanged();
122− void buttonsChanged();
123− void switchesChanged();
124− void relativeAxisChanged();
125− void absoluteAxisChanged();
126− void typesChanged();
127−private:
128− void setName(const QString &name);
129− void setTypes(QInputDeviceInfo::InputTypes types);
130− void setDevicePath(const QString &path);
131−
132− QString m_name;
133− QInputDeviceInfo::InputTypes m_types;
134− QString m_devicePath;
135−
136− friend class QInputDeviceInfo;
137−};
138−
139−#endif // MOCKQINPUTINFO_H
tests/mocks/Unity/InputInfo/plugin.cpp+12−2
@@ -21,12 +21,22 @@
21#include "plugin.h"
21#include "plugin.h"
22
22
23// local
23// local
24−#include "mockqdeclarativeinputdeviceinfo_p.h"
24+#include "qdeclarativeinputdevicemodel_p.h"
25+#include "qinputdeviceinfo_mock_p.h"
26+
27+static QObject *backendProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
28+{
29+ Q_UNUSED(engine)
30+ Q_UNUSED(scriptEngine)
31+ return QInputDeviceManagerPrivate::instance();
32+}
25
33
26void InputInfoPlugin::registerTypes(const char *uri)
34void InputInfoPlugin::registerTypes(const char *uri)
27{
35{
28 int major = 0;
36 int major = 0;
29 int minor = 1;
37 int minor = 1;
30− qmlRegisterType<QDeclarativeInputDeviceInfo>(uri, major, minor, "InputDeviceInfo");
38+ qmlRegisterType<QDeclarativeInputDeviceModel>(uri, major, minor, "InputDeviceModel");
31 qmlRegisterType<QInputDevice>(uri, major, minor, "InputInfo");
39 qmlRegisterType<QInputDevice>(uri, major, minor, "InputInfo");
40+
41+ qmlRegisterSingletonType<QInputDeviceManagerPrivate>(uri, major, minor, "MockInputDeviceBackend", backendProvider);
32}
42}
tests/mocks/Unity/InputInfo/mockqinputinfo.cpp → tests/mocks/Unity/InputInfo/qinputdeviceinfo_mock.cpprenamed+27−71
@@ -1,6 +1,6 @@
1/****************************************************************************
1/****************************************************************************
2**
2**
3−** Copyright (C) 2015 Canonical, Ltd. and/or its subsidiary(-ies).
3+** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
4** Contact: http://www.qt-project.org/legal
5**
5**
6** This file is part of the QtSystems module of the Qt Toolkit.
6** This file is part of the QtSystems module of the Qt Toolkit.
@@ -39,86 +39,42 @@
39**
39**
40****************************************************************************/
40****************************************************************************/
41
41
42−#include "mockqinputinfo.h"
42+#include "qinputdeviceinfo_mock_p.h"
43
43
44+#include <QTimer>
45+#include <QDebug>
44
46
45−QInputDevice::QInputDevice(QObject *parent) :
47+QInputDeviceManagerPrivate::QInputDeviceManagerPrivate(QObject *parent) :
46− QObject(parent)
48+ QObject(parent),
49+ currentFilter(QInputDevice::Unknown)
47{
50{
51+ QTimer::singleShot(1, SIGNAL(ready()));
48}
52}
49
53
50−QString QInputDevice::name() const
54+QInputDeviceManagerPrivate::~QInputDeviceManagerPrivate()
51{
55{
52− return m_name;
53}
56}
54
57
55−void QInputDevice::setName(const QString &name)
58+QInputDevice *QInputDeviceManagerPrivate::addMockDevice(const QString &devicePath, QInputDevice::InputType type)
56{
59{
57− m_name = name;
60+ QInputDevice *inputDevice = new QInputDevice(this);
61+ inputDevice->setDevicePath(devicePath);
62+ inputDevice->setName("Mock Device " + devicePath);
63+ inputDevice->setType(type);
64+ deviceMap.insert(devicePath, inputDevice);
65+ qDebug() << "Adding mock input device" << devicePath << type;
66+ Q_EMIT deviceAdded(devicePath);
67+ return inputDevice;
58}
68}
59
69
60−QString QInputDevice::devicePath() const
70+void QInputDeviceManagerPrivate::removeDevice(const QString &path)
61{
71{
62− return m_devicePath;
72+ qDebug() << "should remove" << path;
63−}
73+ Q_FOREACH (const QString devicePath, deviceMap.keys()) {
64−
74+ qDebug() << "comparing" << devicePath << path;
65−void QInputDevice::setDevicePath(const QString &path)
75+ if (devicePath.contains(path)) {
66−{
76+ deviceMap.remove(devicePath);
67− m_devicePath = path;
68−}
69−
70−QList <int> QInputDevice::buttons() const
71−{
72− return {1, 2 ,3};
73−}
74−
75−QList <int> QInputDevice::switches() const
76−{
77− return {};
78−}
79−
80−QList <int> QInputDevice::relativeAxis() const
81−{
82− return {};
83−}
84−
85−QList <int> QInputDevice::absoluteAxis() const
86−{
87− return {};
88−}
89−
90−QInputDeviceInfo::InputTypes QInputDevice::types()
91−{
92− return m_types;
93−}
94−
95−void QInputDevice::setTypes(QInputDeviceInfo::InputTypes types)
96−{
97− m_types = types;
98−}
99−
100−QInputDeviceInfo::QInputDeviceInfo(QObject *parent) :
101− QObject(parent)
102−{
103−}
104−
105−QVector <QInputDevice *> QInputDeviceInfo::deviceList()
106−{
107− return m_list;
108−}
109−
110−void QInputDeviceInfo::removeMockDevice(int index)
111−{
112− QInputDevice *device = m_list.takeAt(index);
113− Q_EMIT deviceRemoved(device->devicePath());
77+ Q_EMIT deviceRemoved(devicePath);
114− device->deleteLater();
115−}
78+ }
116−
79+ }
117−void QInputDeviceInfo::addMockDevice(QInputDeviceInfo::InputType inputType)
118−{
119− QInputDevice *device = new QInputDevice(this);
120− device->setDevicePath("/mock/device/" + QString::number(m_counter++));
121− device->setTypes({inputType});
122− m_list.append(device);
123− Q_EMIT deviceAdded(device->devicePath());
124}
80}
tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo_p.h → tests/mocks/Unity/InputInfo/qinputdeviceinfo_mock_p.hrenamed+30−41
@@ -1,7 +1,6 @@
1/****************************************************************************
1/****************************************************************************
2**
2**
3−** Copyright (C) 2015 Jolla.
3+** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
4−** Copyright (C) 2015 Canoncal Ltd.
5** Contact: http://www.qt-project.org/legal
4** Contact: http://www.qt-project.org/legal
6**
5**
7** This file is part of the QtSystems module of the Qt Toolkit.
6** This file is part of the QtSystems module of the Qt Toolkit.
@@ -40,55 +39,45 @@
40**
39**
41****************************************************************************/
40****************************************************************************/
42
41
43−#ifndef QDECLARATIVEINPUTDEVICEINFO_H
42+#ifndef QINPUTDEVICEINFO_MOCK_H
44−#define QDECLARATIVEINPUTDEVICEINFO_H
43+#define QINPUTDEVICEINFO_MOCK_H
45
44
46#include <QObject>
45#include <QObject>
47−#include <QAbstractListModel>
46+#include "qinputinfo.h"
48−#include "mockqinputinfo.h"
49
47
50−class QDeclarativeInputDeviceInfo : public QAbstractListModel
48+class QInputDevicePrivate : public QObject
51{
49{
52 Q_OBJECT
50 Q_OBJECT
53− Q_DISABLE_COPY(QDeclarativeInputDeviceInfo)
54−
55public:
51public:
56− enum ItemRoles {
57− ServiceRole = Qt::UserRole + 1
58− };
59−
60− explicit QDeclarativeInputDeviceInfo(QObject *parent = 0);
52+ explicit QInputDevicePrivate(QObject *parent = 0);
61− virtual ~QDeclarativeInputDeviceInfo();
62−
63− QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
64− int rowCount(const QModelIndex &parent = QModelIndex()) const;
65
53
66− QHash<int, QByteArray> roleNames() const;
54+ QString name;
67−
68− Q_INVOKABLE int indexOf(const QString &devicePath) const;
55+ QString devicePath;
56+ QList <int> buttons; //keys
57+ QList <int> switches;
58+ QList <int> relativeAxis;
59+ QList <int> absoluteAxis;
60+ QInputDevice::InputTypeFlags type;
61+};
69
62
70− Q_INVOKABLE QInputDevice *get(int index) const;
63+class QInputDeviceManagerPrivate : public QObject
64+{
65+ Q_OBJECT
66+public:
67+ explicit QInputDeviceManagerPrivate(QObject *parent = 0);
68+ ~QInputDeviceManagerPrivate();
69+ QVector <QInputDevice *> deviceList;
70+ QMap <QString, QInputDevice *> deviceMap;
71+ static QInputDeviceManagerPrivate * instance();
72+ QInputDevice::InputType currentFilter;
71
73
72− // For testing
74+ Q_INVOKABLE QInputDevice* addMockDevice(const QString &devicePath, QInputDevice::InputType type);
73− Q_INVOKABLE void addMockMouse();
75+ Q_INVOKABLE void removeDevice(const QString &devicePath);
74− Q_INVOKABLE void addMockKeyboard();
75− Q_INVOKABLE void removeMockMouse();
76− Q_INVOKABLE void removeMockKeyboard();
77
76
78Q_SIGNALS:
77Q_SIGNALS:
79− void newDevice(const QString &devicePath);
78+ void deviceAdded(const QString &);
80− void deviceRemoved(const QString &devicePath);
79+ void deviceRemoved(const QString &);
81−
80+ void ready();
82−public Q_SLOTS:
83− void updateDeviceList();
84−
85−private:
86− QInputDeviceInfo *deviceInfo;
87− QVector<QInputDevice *> inputDevices;
88−private Q_SLOTS:
89− void addedDevice(const QString &);
90− void removedDevice(const QString &path);
91−
92};
81};
93
82
94−#endif // QDECLARATIVEINPUTDEVICEINFO_H
83+#endif // QINPUTDEVICEINFO_MOCK_H
tests/qmltests/Notifications/tst_Notifications.qml+5−6
@@ -19,7 +19,6 @@ import QtQuick.Layouts 1.1
19import QtTest 1.0
19import QtTest 1.0
20import ".."
20import ".."
21import "../../../qml/Notifications"
21import "../../../qml/Notifications"
22−import "../../../qml/Components/UnityInputInfo"
23import Ubuntu.Components 1.2
22import Ubuntu.Components 1.2
24import Unity.Test 0.1
23import Unity.Test 0.1
25import Unity.Notifications 1.0
24import Unity.Notifications 1.0
@@ -188,7 +187,7 @@ Item {
188
187
189 anchors.fill: parent
188 anchors.fill: parent
190 model: mockModel
189 model: mockModel
191− hasMouse: UnityInputInfo.mice > 0 // for testing, we add/remove only a mock mouse
190+ hasMouse: false
192 }
191 }
193 }
192 }
194
193
@@ -264,9 +263,9 @@ Item {
264 id: fakeMouseCB
263 id: fakeMouseCB
265 onClicked: {
264 onClicked: {
266 if (checked) {
265 if (checked) {
267− UnityInputInfo.inputInfo.addMockMouse();
266+ notifications.hasMouse = true;
268 } else {
267 } else {
269− UnityInputInfo.inputInfo.removeMockMouse();
268+ notifications.hasMouse = false;
270 }
269 }
271 }
270 }
272 }
271 }
@@ -695,7 +694,7 @@ Item {
695 }
694 }
696
695
697 function test_clickToClose_data() { // reuse the data
696 function test_clickToClose_data() { // reuse the data
698− UnityInputInfo.inputInfo.addMockMouse();
697+ notifications.hasMouse = true;
699 return test_NotificationRenderer_data();
698 return test_NotificationRenderer_data();
700 }
699 }
701
700
@@ -726,7 +725,7 @@ Item {
726 }
725 }
727
726
728 function cleanupTestCase() {
727 function cleanupTestCase() {
729− UnityInputInfo.inputInfo.removeMockMouse();
728+ notifications.hasMouse = false;
730 }
729 }
731 }
730 }
732 }
731 }
tests/qmltests/Notifications/tst_SwipeToAct.qml+5−6
@@ -19,7 +19,6 @@ import QtQuick.Layouts 1.1
19import QtTest 1.0
19import QtTest 1.0
20import ".."
20import ".."
21import "../../../qml/Notifications"
21import "../../../qml/Notifications"
22−import "../../../qml/Components/UnityInputInfo"
23import Ubuntu.Components 0.1
22import Ubuntu.Components 0.1
24import Unity.Test 0.1
23import Unity.Test 0.1
25import Unity.Notifications 1.0
24import Unity.Notifications 1.0
@@ -112,7 +111,7 @@ Item {
112
111
113 anchors.fill: parent
112 anchors.fill: parent
114 model: mockModel
113 model: mockModel
115− hasMouse: UnityInputInfo.mice > 0 // for testing, we add/remove only a mock mouse
114+ hasMouse: false
116 }
115 }
117 }
116 }
118
117
@@ -152,9 +151,9 @@ Item {
152 id: fakeMouseCB
151 id: fakeMouseCB
153 onClicked: {
152 onClicked: {
154 if (checked) {
153 if (checked) {
155− UnityInputInfo.inputInfo.addMockMouse();
154+ notifications.hasMouse = true;
156 } else {
155 } else {
157− UnityInputInfo.inputInfo.removeMockMouse();
156+ notifications.hasMouse = false;
158 }
157 }
159 }
158 }
160 }
159 }
@@ -301,7 +300,7 @@ Item {
301 }
300 }
302
301
303 // add a mock mouse, test clicking the left/right buttons
302 // add a mock mouse, test clicking the left/right buttons
304− UnityInputInfo.inputInfo.addMockMouse();
303+ notifications.hasMouse = true;
305 var leftButton = findChild(swipeButton, "leftButton");
304 var leftButton = findChild(swipeButton, "leftButton");
306 var rightButton = findChild(swipeButton, "rightButton");
305 var rightButton = findChild(swipeButton, "rightButton");
307
306
@@ -316,7 +315,7 @@ Item {
316 compare(actionSpy.signalArguments[0][0], data.actions.data(1, ActionModel.RoleActionId), "got wrong id for negative action");
315 compare(actionSpy.signalArguments[0][0], data.actions.data(1, ActionModel.RoleActionId), "got wrong id for negative action");
317 actionSpy.clear();
316 actionSpy.clear();
318 }
317 }
319− UnityInputInfo.inputInfo.removeMockMouse();
318+ notifications.hasMouse = false;
320 }
319 }
321 }
320 }
322 }
321 }
tests/qmltests/tst_OrientedShell.qml+17−9
@@ -26,7 +26,6 @@ import Powerd 0.1
26import Unity.InputInfo 0.1
26import Unity.InputInfo 0.1
27
27
28import "../../qml"
28import "../../qml"
29−import "../../qml/Components/UnityInputInfo"
30
29
31Rectangle {
30Rectangle {
32 id: root
31 id: root
@@ -55,6 +54,15 @@ Rectangle {
55 property bool stayHidden: false;
54 property bool stayHidden: false;
56 }
55 }
57
56
57+ InputDeviceModel {
58+ id: miceModel
59+ deviceFilter: InputInfo.Mouse
60+ }
61+ InputDeviceModel {
62+ id: keyboardsModel
63+ deviceFilter: InputInfo.Keyboard
64+ }
65+
58 property int physicalOrientation0
66 property int physicalOrientation0
59 property int physicalOrientation90
67 property int physicalOrientation90
60 property int physicalOrientation180
68 property int physicalOrientation180
@@ -307,13 +315,13 @@ Rectangle {
307 Button {
315 Button {
308 text: "Add mouse"
316 text: "Add mouse"
309 onClicked: {
317 onClicked: {
310− UnityInputInfo.inputInfo.addMockMouse()
318+ MockInputDeviceBackend.addMockDevice("/mouse" + miceModel.count, InputInfo.Mouse)
311 }
319 }
312 }
320 }
313 Button {
321 Button {
314 text: "Remove mouse"
322 text: "Remove mouse"
315 onClicked: {
323 onClicked: {
316− UnityInputInfo.inputInfo.removeMockMouse()
324+ MockInputDeviceBackend.removeDevice("/mouse" + (miceModel.count - 1))
317 }
325 }
318 }
326 }
319 }
327 }
@@ -321,13 +329,13 @@ Rectangle {
321 Button {
329 Button {
322 text: "Add kbd"
330 text: "Add kbd"
323 onClicked: {
331 onClicked: {
324− UnityInputInfo.inputInfo.addMockKeyboard()
332+ MockInputDeviceBackend.addMockDevice("/kbd" + keyboardsModel.count, InputInfo.Keyboard)
325 }
333 }
326 }
334 }
327 Button {
335 Button {
328 text: "Remove kbd"
336 text: "Remove kbd"
329 onClicked: {
337 onClicked: {
330− UnityInputInfo.inputInfo.removeMockKeyboard()
338+ MockInputDeviceBackend.removeDevice("/kbd" + (keyboardsModel.count - 1))
331 }
339 }
332 }
340 }
333 }
341 }
@@ -934,19 +942,19 @@ Rectangle {
934 tryCompare(shell, "usageScenario", "phone");
942 tryCompare(shell, "usageScenario", "phone");
935 tryCompare(mockOskSettings, "stayHidden", false);
943 tryCompare(mockOskSettings, "stayHidden", false);
936
944
937− UnityInputInfo.inputInfo.addMockKeyboard();
945+ MockInputDeviceBackend.addMockDevice("/kbd0", InputInfo.Keyboard);
938 tryCompare(shell, "usageScenario", "phone");
946 tryCompare(shell, "usageScenario", "phone");
939 tryCompare(mockOskSettings, "stayHidden", true);
947 tryCompare(mockOskSettings, "stayHidden", true);
940
948
941− UnityInputInfo.inputInfo.addMockMouse();
949+ MockInputDeviceBackend.addMockDevice("/mouse0", InputInfo.Mouse);
942 tryCompare(shell, "usageScenario", "desktop");
950 tryCompare(shell, "usageScenario", "desktop");
943 tryCompare(mockOskSettings, "stayHidden", true);
951 tryCompare(mockOskSettings, "stayHidden", true);
944
952
945− UnityInputInfo.inputInfo.removeMockKeyboard();
953+ MockInputDeviceBackend.removeDevice("/kbd0");
946 tryCompare(shell, "usageScenario", "desktop");
954 tryCompare(shell, "usageScenario", "desktop");
947 tryCompare(mockOskSettings, "stayHidden", false);
955 tryCompare(mockOskSettings, "stayHidden", false);
948
956
949− UnityInputInfo.inputInfo.removeMockMouse();
957+ MockInputDeviceBackend.removeDevice("/mouse0");
950 tryCompare(shell, "usageScenario", "phone");
958 tryCompare(shell, "usageScenario", "phone");
951 tryCompare(mockOskSettings, "stayHidden", false);
959 tryCompare(mockOskSettings, "stayHidden", false);
952 }
960 }