on xenial help sign in
make UnityInputInfo a singleton

We don't need many instances of this so saves resources and makes easier to mock

commita54da50544ab8b0bc38944f0b8d73d0c41e0f265 authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 23 Jun 2015, 18:36 (11 years ago) parent7b3f46e
6 files changed+50−25
qml/Components/UnityInputInfo.qml → qml/Components/UnityInputInfo/UnityInputInfo.qml+3−1 qml/Components/UnityInputInfo/qmldir+1 qml/OrientedShell.qml+18−22 tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo_p.h+3 tests/mocks/Unity/InputInfo/mockqinputinfo.cpp+16−2 tests/mocks/Unity/InputInfo/mockqinputinfo.h+9
qml/Components/UnityInputInfo.qml → qml/Components/UnityInputInfo/UnityInputInfo.qmlrenamed+3−1
@@ -1,5 +1,7 @@
1+pragma Singleton
2+
13import QtQuick 2.3
2−import QtSystemInfo 5.0
4+import Unity.InputInfo 0.1
35
46Item {
57 id: root
qml/Components/UnityInputInfo/qmldirnew file+1
@@ -0,0 +1 @@
1+singleton UnityInputInfo 1.0 UnityInputInfo.qml
qml/OrientedShell.qml+18−22
@@ -19,6 +19,7 @@ import QtQuick.Window 2.0
1919import Unity.Session 0.1
2020import GSettings 1.0
2121import "Components"
22+import "Components/UnityInputInfo"
2223import "Rotation"
2324
2425Rectangle {
@@ -40,32 +41,11 @@ Rectangle {
4041 name: applicationArguments.deviceName
4142 }
4243
43− UnityInputInfo {
44− id: inputInfo
45− Component.onCompleted: {
46− // We need to manually update this on startup as the binding
47− // below doesn't seem to have any effect at that stage
48− oskSettings.stayHidden = keyboards > 0
49− oskSettings.disableHeight = shell.usageScenario == "desktop"
50− }
51− }
52−
5344 GSettings {
5445 id: oskSettings
5546 schema.id: "com.canonical.keyboard.maliit"
5647 }
5748
58− Binding {
59− target: oskSettings
60− property: "stayHidden"
61− value: inputInfo.keyboards > 0
62− }
63−
64− Binding {
65− target: oskSettings
66− property: "disableHeight"
67− value: shell.usageScenario == "desktop"
68− }
6949
7050 // to be overwritten by tests
7151 property var usageModeSettings: GSettings { schema.id: "com.canonical.Unity8" }
@@ -90,6 +70,22 @@ Rectangle {
9070 if (orientationLocked) {
9171 orientation = orientationLock.savedOrientation;
9272 }
73+ // We need to manually update this on startup as the binding
74+ // below doesn't seem to have any effect at that stage
75+ oskSettings.stayHidden = UnityInputInfo.keyboards > 0
76+ oskSettings.disableHeight = shell.usageScenario == "desktop"
77+ }
78+
79+ Binding {
80+ target: oskSettings
81+ property: "stayHidden"
82+ value: UnityInputInfo.keyboards > 0
83+ }
84+
85+ Binding {
86+ target: oskSettings
87+ property: "disableHeight"
88+ value: shell.usageScenario == "desktop"
9389 }
9490
9591 readonly property int supportedOrientations: shell.supportedOrientations
@@ -175,7 +171,7 @@ Rectangle {
175171 return "tablet";
176172 }
177173 } else { // automatic
178− if (inputInfo.mice > 0) {
174+ if (UnityInputInfo.mice > 0) {
179175 return "desktop";
180176 } else {
181177 return deviceConfiguration.category;
tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo_p.h+3
@@ -74,6 +74,9 @@ Q_SIGNALS:
7474
7575public Q_SLOTS:
7676 void updateDeviceList();
77+
78+
79+
7780private:
7881 QInputDeviceInfo *deviceInfo;
7982 QVector<QInputDevice *> inputDevices;
tests/mocks/Unity/InputInfo/mockqinputinfo.cpp+16−2
@@ -92,7 +92,6 @@ void QInputDevice::setTypes(QInputDeviceInfo::InputTypes types)
9292 m_types = types;
9393}
9494
95−
9695QInputDeviceInfo::QInputDeviceInfo(QObject *parent) :
9796 QObject(parent)
9897{
@@ -100,5 +99,20 @@ QInputDeviceInfo::QInputDeviceInfo(QObject *parent) :
10099
101100QVector <QInputDevice *> QInputDeviceInfo::deviceList()
102101{
103− return {};
102+ return m_list;
103+}
104+
105+void QInputDeviceInfo::removeMockDevice(int index)
106+{
107+ QInputDevice *device = m_list.takeAt(index);
108+ Q_EMIT deviceRemoved(device->devicePath());
109+ device->deleteLater();
110+}
111+
112+void QInputDeviceInfo::addMockDevice(QInputDeviceInfo::InputType inputType)
113+{
114+ QInputDevice *device = new QInputDevice(this);
115+ device->setTypes({inputType});
116+ m_list.append(device);
117+ Q_EMIT deviceAdded(device->devicePath());
104118}
tests/mocks/Unity/InputInfo/mockqinputinfo.h+9
@@ -76,11 +76,17 @@ public:
7676 Q_INVOKABLE QVector <QInputDevice *> deviceList();
7777
7878 int deviceCount() { return deviceList().count(); }
79+
80+ Q_INVOKABLE void addMockDevice(InputType inputType);
81+ Q_INVOKABLE void removeMockDevice(int index);
82+
7983Q_SIGNALS:
8084
8185 void deviceAdded(const QString & devicePath);
8286 void deviceRemoved(const QString & devicePath);
8387
88+private:
89+ QVector<QInputDevice*> m_list;
8490};
8591
8692class QInputDevice : public QObject
@@ -122,6 +128,9 @@ private:
122128
123129 QString m_name;
124130 QInputDeviceInfo::InputTypes m_types;
131+ QString m_devicePath;
132+
133+ friend class QInputDeviceInfo;
125134};
126135
127136#endif // MOCKQINPUTINFO_H