on xenial help sign in
Proxy more input settings to USC
commit85388522828d78f67a3856700b901c15e96a652d authorMichael Terry <michael.terry@canonical.com> dateThu 25 Feb 2016, 11:57 (11 years ago) parent9cc9cef
7 files changed+136−5
plugins/AccountsService/AccountsService.cpp+54−2 plugins/AccountsService/AccountsService.h+4−1 tests/plugins/AccountsService/CMakeLists.txt+3 tests/plugins/AccountsService/PropertiesServer.cpp+1−2 tests/plugins/AccountsService/client.cpp+54 tests/plugins/AccountsService/interfaces.xml+10 tests/plugins/AccountsService/server.cpp+10
plugins/AccountsService/AccountsService.cpp+54−2
@@ -40,9 +40,32 @@
4040#define PROP_LICENSE_ACCEPTED QStringLiteral("LicenseAccepted")
4141#define PROP_LICENSE_BASE_PATH QStringLiteral("LicenseBasePath")
4242#define PROP_MOUSE_CURSOR_SPEED QStringLiteral("MouseCursorSpeed")
43+#define PROP_MOUSE_DOUBLE_CLICK_SPEED QStringLiteral("MouseDoubleClickSpeed")
44+#define PROP_MOUSE_PRIMARY_BUTTON QStringLiteral("MousePrimaryButton")
45+#define PROP_MOUSE_SCROLL_SPEED QStringLiteral("MouseScrollSpeed")
4346#define PROP_PASSWORD_DISPLAY_HINT QStringLiteral("PasswordDisplayHint")
4447#define PROP_STATS_WELCOME_SCREEN QStringLiteral("StatsWelcomeScreen")
4548#define PROP_TOUCHPAD_CURSOR_SPEED QStringLiteral("TouchpadCursorSpeed")
49+#define PROP_TOUCHPAD_DISABLE_WHILE_TYPING QStringLiteral("TouchpadDisableWhileTyping")
50+#define PROP_TOUCHPAD_DISABLE_WITH_MOUSE QStringLiteral("TouchpadDisableWithMouse")
51+#define PROP_TOUCHPAD_DOUBLE_CLICK_SPEED QStringLiteral("TouchpadDoubleClickSpeed")
52+#define PROP_TOUCHPAD_PRIMARY_BUTTON QStringLiteral("TouchpadPrimaryButton")
53+#define PROP_TOUCHPAD_SCROLL_SPEED QStringLiteral("TouchpadScrollSpeed")
54+#define PROP_TOUCHPAD_TAP_TO_CLICK QStringLiteral("TouchpadTapToClick")
55+#define PROP_TOUCHPAD_TWO_FINGER_SCROLL QStringLiteral("TouchpadTwoFingerScroll")
56+
57+
58+QVariant primaryButtonConverter(const QVariant &value)
59+{
60+ QString stringValue = value.toString();
61+ if (stringValue == "left") {
62+ return QVariant::fromValue(0);
63+ } else if (stringValue == "right") {
64+ return QVariant::fromValue(1); // Mir is less clear on this -- any non-zero value is the same
65+ } else {
66+ return QVariant::fromValue(0); // default to left
67+ }
68+}
4669
4770AccountsService::AccountsService(QObject* parent, const QString &user)
4871 : QObject(parent)
@@ -68,8 +91,30 @@ AccountsService::AccountsService(QObject* parent, const QString &user)
6891
6992 registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_CURSOR_SPEED,
7093 m_unityInput, QStringLiteral("setMouseCursorSpeed"));
94+ registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_DOUBLE_CLICK_SPEED,
95+ m_unityInput, QStringLiteral("setMouseDoubleClickSpeed"));
96+ registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_PRIMARY_BUTTON,
97+ m_unityInput, QStringLiteral("setMousePrimaryButton"),
98+ primaryButtonConverter);
99+ registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_SCROLL_SPEED,
100+ m_unityInput, QStringLiteral("setMouseScrollSpeed"));
71101 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_CURSOR_SPEED,
72102 m_unityInput, QStringLiteral("setTouchpadCursorSpeed"));
103+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_SCROLL_SPEED,
104+ m_unityInput, QStringLiteral("setTouchpadScrollSpeed"));
105+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DISABLE_WHILE_TYPING,
106+ m_unityInput, QStringLiteral("setTouchpadDisableWhileTyping"));
107+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DISABLE_WITH_MOUSE,
108+ m_unityInput, QStringLiteral("setTouchpadDisableWithMouse"));
109+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DOUBLE_CLICK_SPEED,
110+ m_unityInput, QStringLiteral("setTouchpadDoubleClickSpeed"));
111+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_PRIMARY_BUTTON,
112+ m_unityInput, QStringLiteral("setTouchpadPrimaryButton"),
113+ primaryButtonConverter);
114+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TAP_TO_CLICK,
115+ m_unityInput, QStringLiteral("setTouchpadTapToClick"));
116+ registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
117+ m_unityInput, QStringLiteral("setTouchpadTwoFingerScroll"));
73118
74119 setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
75120}
@@ -200,7 +245,13 @@ void AccountsService::updateCache(const QString &interface, const QString &prope
200245 PropertyInfo &info = m_properties[interface][property];
201246
202247 if (info.proxyInterface) {
203− info.proxyInterface->asyncCall(info.proxyMethod, value);
248+ QVariant finalValue;
249+ if (info.proxyConverter) {
250+ finalValue = info.proxyConverter(value);
251+ } else {
252+ finalValue = value;
253+ }
254+ info.proxyInterface->asyncCall(info.proxyMethod, finalValue);
204255 return; // don't bother saving a copy
205256 }
206257
@@ -259,12 +310,13 @@ void AccountsService::updateAllProperties(const QString &interface, bool async)
259310 }
260311}
261312
262−void AccountsService::registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method)
313+void AccountsService::registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter)
263314{
264315 registerProperty(interface, property, nullptr);
265316
266317 m_properties[interface][property].proxyInterface = iface;
267318 m_properties[interface][property].proxyMethod = method;
319+ m_properties[interface][property].proxyConverter = converter;
268320}
269321
270322void AccountsService::registerProperty(const QString &interface, const QString &property, const QString &signal)
plugins/AccountsService/AccountsService.h+4−1
@@ -111,9 +111,11 @@ private Q_SLOTS:
111111 void onMaybeChanged(const QString &user);
112112
113113private:
114+ typedef QVariant (*ProxyConverter)(const QVariant &);
115+
114116 void refresh(bool async);
115117 void registerProperty(const QString &interface, const QString &property, const QString &signal);
116− void registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method);
118+ void registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter = nullptr);
117119
118120 void updateAllProperties(const QString &interface, bool async);
119121 void updateProperty(const QString &interface, const QString &property);
@@ -129,6 +131,7 @@ private:
129131 QString signal{};
130132 QDBusInterface *proxyInterface{};
131133 QString proxyMethod{};
134+ ProxyConverter proxyConverter{};
132135 };
133136 typedef QHash< QString, QHash<QString, PropertyInfo> > PropertyHash;
134137 PropertyHash m_properties;
tests/plugins/AccountsService/CMakeLists.txt+3
@@ -16,6 +16,7 @@ make_dbus_class(SecurityPrivacy com.ubuntu.touch.AccountsService.SecurityPrivacy
1616make_dbus_class(Location com.ubuntu.location.providers.here.AccountsService)
1717make_dbus_class(AccountsUser org.freedesktop.Accounts.User)
1818make_dbus_class(AccountsPrivate com.canonical.unity.AccountsService.Private)
19+make_dbus_class(UscInput com.canonical.Unity.Input)
1920
2021include_directories(
2122 ${CMAKE_CURRENT_BINARY_DIR}
@@ -32,9 +33,11 @@ add_executable(mock-server
3233 ${CMAKE_CURRENT_BINARY_DIR}/PropertiesAdaptor.cpp
3334 ${CMAKE_CURRENT_BINARY_DIR}/LocationAdaptor.cpp
3435 ${CMAKE_CURRENT_BINARY_DIR}/SecurityPrivacyAdaptor.cpp
36+ ${CMAKE_CURRENT_BINARY_DIR}/UscInputAdaptor.cpp
3537 server.cpp
3638 AccountsServer.cpp
3739 PropertiesServer.cpp
40+ UscServer.cpp
3841 )
3942qt5_use_modules(mock-server Core DBus)
4043
tests/plugins/AccountsService/PropertiesServer.cpp+1−2
@@ -92,8 +92,7 @@ void PropertiesServer::Reset()
9292 m_properties["com.canonical.unity.AccountsService"]["LauncherItems"] = QVariant::fromValue(QList<QVariantMap>());
9393 m_properties["com.canonical.unity.AccountsService.Private"]["FailedLogins"] = 0;
9494 m_properties["com.ubuntu.touch.AccountsService.SecurityPrivacy"]["StatsWelcomeScreen"] = true;
95− m_properties["com.ubuntu.AccountsService.Input"]["MouseCursorSpeed"] = 0.5;
96− m_properties["com.ubuntu.AccountsService.Input"]["TouchpadCursorSpeed"] = 0.5;
95+ m_properties["com.ubuntu.AccountsService.Input"]["MousePrimaryButton"] = "right";
9796 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableLauncherWhileLocked"] = true;
9897 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableIndicatorsWhileLocked"] = true;
9998 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["PasswordDisplayHint"] = AccountsService::Keyboard;
tests/plugins/AccountsService/client.cpp+54
@@ -42,7 +42,16 @@ public:
4242 : QObject(parent)
4343 , m_userInterface(nullptr)
4444 , m_spy(this, &AccountsServiceTest::propertiesChanged)
45+ , m_mousePrimaryButtonSpy(this, &AccountsServiceTest::setMousePrimaryButtonCalled)
4546 {
47+ m_uscInputInterface = new QDBusInterface("com.canonical.Unity.Input",
48+ "/com/canonical/Unity/Input",
49+ "com.canonical.Unity.Input",
50+ QDBusConnection::sessionBus(),
51+ this);
52+
53+ QObject::connect(m_uscInputInterface, SIGNAL(setMousePrimaryButtonCalled(int)),
54+ this, SIGNAL(setMousePrimaryButtonCalled(int)));
4655 }
4756
4857private Q_SLOTS:
@@ -71,6 +80,7 @@ private Q_SLOTS:
7180
7281 delete m_userInterface;
7382 m_spy.clear();
83+ m_mousePrimaryButtonSpy.clear();
7484 }
7585
7686 void testInvalids()
@@ -215,12 +225,56 @@ private Q_SLOTS:
215225 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
216226 }
217227
228+ void testProxyOnStartup()
229+ {
230+ AccountsService session(this, QTest::currentTestFunction());
231+
232+ QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
233+ QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
234+ QCOMPARE(arguments.at(0).toInt(), 1);
235+ }
236+
237+ void testProxyOnChange()
238+ {
239+ AccountsService session(this, QTest::currentTestFunction());
240+ QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
241+ m_mousePrimaryButtonSpy.clear();
242+
243+ ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
244+ "com.ubuntu.AccountsService.Input",
245+ "MousePrimaryButton",
246+ dbusVariant("left")));
247+
248+ QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
249+ QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
250+ QCOMPARE(arguments.at(0).toInt(), 0);
251+ }
252+
253+ void testInvalidPrimaryButton()
254+ {
255+ AccountsService session(this, QTest::currentTestFunction());
256+ QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
257+ m_mousePrimaryButtonSpy.clear();
258+
259+ ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
260+ "com.ubuntu.AccountsService.Input",
261+ "MousePrimaryButton",
262+ dbusVariant("NOPE")));
263+
264+ QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
265+ QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
266+ QCOMPARE(arguments.at(0).toInt(), 0);
267+ }
268+
218269Q_SIGNALS:
219270 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
271+ void setMousePrimaryButtonCalled(int button);
220272
221273private:
274+ QDBusInterface* m_uscInputInterface;
222275 QDBusInterface* m_userInterface;
223276 QSignalSpy m_spy;
277+ QSignalSpy m_mousePrimaryButtonSpy;
224278};
225279
226280QTEST_MAIN(AccountsServiceTest)
tests/plugins/AccountsService/interfaces.xml+10
@@ -44,4 +44,14 @@
4444 <signal name="Changed" />
4545 </interface>
4646 <interface name="com.canonical.unity.AccountsService.Private" />
47+
48+ <interface name="com.canonical.Unity.Input">
49+ <method name="setMousePrimaryButton">
50+ <arg name="button" type="i" direction="in" />
51+ </method>
52+ <!-- Just for testing -->
53+ <signal name="setMousePrimaryButtonCalled">
54+ <arg name="button" type="i" direction="out" />
55+ </signal>
56+ </interface>
4757</node>
tests/plugins/AccountsService/server.cpp+10
@@ -24,6 +24,8 @@
2424#include "SecurityPrivacyAdaptor.h"
2525#include "LocationAdaptor.h"
2626#include "AccountsPrivateAdaptor.h"
27+#include "UscInputAdaptor.h"
28+#include "UscServer.h"
2729#include <QCoreApplication>
2830
2931int main(int argc, char *argv[])
@@ -36,8 +38,16 @@ int main(int argc, char *argv[])
3638 new SecurityPrivacyAdaptor(accounts);
3739 new LocationAdaptor(accounts);
3840 new AccountsPrivateAdaptor(accounts);
41+
42+ auto usc = new UscServer(&a);
43+ new UscInputAdaptor(usc);
44+
3945 // We use the session bus for testing. The real plugin uses the system bus
4046 auto connection = QDBusConnection::sessionBus();
47+ if (!connection.registerObject("/com/canonical/Unity/Input", usc))
48+ return 1;
49+ if (!connection.registerService("com.canonical.Unity.Input"))
50+ return 1;
4151 if (!connection.registerObject("/org/freedesktop/Accounts", accounts))
4252 return 1;
4353 if (!connection.registerService("org.freedesktop.Accounts"))