on xenial help sign in
make UnityInputInfo a singleton
a54da50Michael Zanetti
qml/Components/UnityInputInfo.qml → qml/Components/UnityInputInfo/UnityInputInfo.qmlrenamed+3−1
@@ -1,5 +1,7 @@
1+pragma Singleton
2+
1import QtQuick 2.3
3import QtQuick 2.3
2−import QtSystemInfo 5.0
4+import Unity.InputInfo 0.1
3
5
4Item {
6Item {
5 id: root
7 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
19import Unity.Session 0.1
19import Unity.Session 0.1
20import GSettings 1.0
20import GSettings 1.0
21import "Components"
21import "Components"
22+import "Components/UnityInputInfo"
22import "Rotation"
23import "Rotation"
23
24
24Rectangle {
25Rectangle {
@@ -40,32 +41,11 @@ Rectangle {
40 name: applicationArguments.deviceName
41 name: applicationArguments.deviceName
41 }
42 }
42
43
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−
53 GSettings {
44 GSettings {
54 id: oskSettings
45 id: oskSettings
55 schema.id: "com.canonical.keyboard.maliit"
46 schema.id: "com.canonical.keyboard.maliit"
56 }
47 }
57
48
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− }
69
49
70 // to be overwritten by tests
50 // to be overwritten by tests
71 property var usageModeSettings: GSettings { schema.id: "com.canonical.Unity8" }
51 property var usageModeSettings: GSettings { schema.id: "com.canonical.Unity8" }
@@ -90,6 +70,22 @@ Rectangle {
90 if (orientationLocked) {
70 if (orientationLocked) {
91 orientation = orientationLock.savedOrientation;
71 orientation = orientationLock.savedOrientation;
92 }
72 }
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"
93 }
89 }
94
90
95 readonly property int supportedOrientations: shell.supportedOrientations
91 readonly property int supportedOrientations: shell.supportedOrientations
@@ -175,7 +171,7 @@ Rectangle {
175 return "tablet";
171 return "tablet";
176 }
172 }
177 } else { // automatic
173 } else { // automatic
178− if (inputInfo.mice > 0) {
174+ if (UnityInputInfo.mice > 0) {
179 return "desktop";
175 return "desktop";
180 } else {
176 } else {
181 return deviceConfiguration.category;
177 return deviceConfiguration.category;
tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo_p.h+3
@@ -74,6 +74,9 @@ Q_SIGNALS:
74
74
75public Q_SLOTS:
75public Q_SLOTS:
76 void updateDeviceList();
76 void updateDeviceList();
77+
78+
79+
77private:
80private:
78 QInputDeviceInfo *deviceInfo;
81 QInputDeviceInfo *deviceInfo;
79 QVector<QInputDevice *> inputDevices;
82 QVector<QInputDevice *> inputDevices;
tests/mocks/Unity/InputInfo/mockqinputinfo.cpp+16−2
@@ -92,7 +92,6 @@ void QInputDevice::setTypes(QInputDeviceInfo::InputTypes types)
92 m_types = types;
92 m_types = types;
93}
93}
94
94
95−
96QInputDeviceInfo::QInputDeviceInfo(QObject *parent) :
95QInputDeviceInfo::QInputDeviceInfo(QObject *parent) :
97 QObject(parent)
96 QObject(parent)
98{
97{
@@ -100,5 +99,20 @@ QInputDeviceInfo::QInputDeviceInfo(QObject *parent) :
100
99
101QVector <QInputDevice *> QInputDeviceInfo::deviceList()
100QVector <QInputDevice *> QInputDeviceInfo::deviceList()
102{
101{
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());
104}
118}
tests/mocks/Unity/InputInfo/mockqinputinfo.h+9
@@ -76,11 +76,17 @@ public:
76 Q_INVOKABLE QVector <QInputDevice *> deviceList();
76 Q_INVOKABLE QVector <QInputDevice *> deviceList();
77
77
78 int deviceCount() { return deviceList().count(); }
78 int deviceCount() { return deviceList().count(); }
79+
80+ Q_INVOKABLE void addMockDevice(InputType inputType);
81+ Q_INVOKABLE void removeMockDevice(int index);
82+
79Q_SIGNALS:
83Q_SIGNALS:
80
84
81 void deviceAdded(const QString & devicePath);
85 void deviceAdded(const QString & devicePath);
82 void deviceRemoved(const QString & devicePath);
86 void deviceRemoved(const QString & devicePath);
83
87
88+private:
89+ QVector<QInputDevice*> m_list;
84};
90};
85
91
86class QInputDevice : public QObject
92class QInputDevice : public QObject
@@ -122,6 +128,9 @@ private:
122
128
123 QString m_name;
129 QString m_name;
124 QInputDeviceInfo::InputTypes m_types;
130 QInputDeviceInfo::InputTypes m_types;
131+ QString m_devicePath;
132+
133+ friend class QInputDeviceInfo;
125};
134};
126
135
127#endif // MOCKQINPUTINFO_H
136#endif // MOCKQINPUTINFO_H