From 39327c21b8b51d3b29f7a01f58200dcf8f5d99bd Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 1 Feb 2016 14:57:21 +0100 Subject: [PATCH] LockScreen: Use layout display name in KeyboardLayoutButton Use display name (can be changed by user) instead of full layout name. This matches the behavior of keyboard layout osd and systray. REVIEW: 126944 --- components/keyboardlayout/keyboardlayout.cpp | 32 +++++++++++++++---- components/keyboardlayout/keyboardlayout.h | 11 +++++-- .../components/KeyboardLayoutButton.qml | 5 +-- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/components/keyboardlayout/keyboardlayout.cpp b/components/keyboardlayout/keyboardlayout.cpp index 3e456ca77..15206ba6c 100644 --- a/components/keyboardlayout/keyboardlayout.cpp +++ b/components/keyboardlayout/keyboardlayout.cpp @@ -74,11 +74,36 @@ void KeyboardLayout::onCurrentLayoutReceived(QDBusPendingCallWatcher *watcher) qCWarning(KEYBOARD_LAYOUT) << reply.error().message(); } else { mCurrentLayout = reply.value(); + requestCurrentLayoutDisplayName(); Q_EMIT currentLayoutChanged(mCurrentLayout); } watcher->deleteLater(); } +void KeyboardLayout::requestCurrentLayoutDisplayName() +{ + QDBusPendingCall pendingDisplayName = mIface->asyncCallWithArgumentList(QStringLiteral("getLayoutDisplayName"), {mCurrentLayout}); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingDisplayName, this); + connect(watcher, &QDBusPendingCallWatcher::finished, this, &KeyboardLayout::onCurrentLayoutDisplayNameReceived); +} + +void KeyboardLayout::onCurrentLayoutDisplayNameReceived(QDBusPendingCallWatcher *watcher) +{ + QDBusPendingReply reply = *watcher; + if (reply.isError()) { + qCWarning(KEYBOARD_LAYOUT) << reply.error().message(); + } else { + mCurrentLayoutDisplayName = reply.value(); + Q_EMIT currentLayoutDisplayNameChanged(mCurrentLayoutDisplayName); + } + watcher->deleteLater(); +} + +QString KeyboardLayout::currentLayoutDisplayName() const +{ + return mCurrentLayoutDisplayName; +} + void KeyboardLayout::requestLayoutsList() { if (!mIface) { @@ -125,6 +150,7 @@ void KeyboardLayout::setCurrentLayout(const QString &layout) } mCurrentLayout = layout; + requestCurrentLayoutDisplayName(); mIface->asyncCall(QStringLiteral("setLayout"), layout); Q_EMIT currentLayoutChanged(layout); } @@ -135,9 +161,3 @@ QStringList KeyboardLayout::layouts() const return mLayouts; } -void KeyboardLayout::onCurrentLayoutChanged(const QString &newLayout) -{ - mCurrentLayout = newLayout; - Q_EMIT currentLayoutChanged(newLayout); -} - diff --git a/components/keyboardlayout/keyboardlayout.h b/components/keyboardlayout/keyboardlayout.h index e5a172edb..e4d04abe3 100644 --- a/components/keyboardlayout/keyboardlayout.h +++ b/components/keyboardlayout/keyboardlayout.h @@ -36,6 +36,10 @@ class KeyboardLayout : public QObject WRITE setCurrentLayout NOTIFY currentLayoutChanged) + Q_PROPERTY(QString currentLayoutDisplayName + READ currentLayoutDisplayName + NOTIFY currentLayoutDisplayNameChanged) + Q_PROPERTY(QStringList layouts READ layouts NOTIFY layoutsChanged) @@ -45,6 +49,7 @@ public: ~KeyboardLayout(); QString currentLayout() const; + QString currentLayoutDisplayName() const; QStringList layouts() const; public Q_SLOTS: @@ -52,20 +57,22 @@ public Q_SLOTS: Q_SIGNALS: void currentLayoutChanged(const QString &newLayout); + void currentLayoutDisplayNameChanged(const QString &newLayout); void layoutsChanged(); private Q_SLOTS: void requestCurrentLayout(); + void requestCurrentLayoutDisplayName(); void requestLayoutsList(); void onCurrentLayoutReceived(QDBusPendingCallWatcher *watcher); + void onCurrentLayoutDisplayNameReceived(QDBusPendingCallWatcher *watcher); void onLayoutsListReceived(QDBusPendingCallWatcher *watcher); - void onCurrentLayoutChanged(const QString &newLayout); - private: QStringList mLayouts; QString mCurrentLayout; + QString mCurrentLayoutDisplayName; QDBusInterface *mIface; }; diff --git a/lookandfeel/contents/components/KeyboardLayoutButton.qml b/lookandfeel/contents/components/KeyboardLayoutButton.qml index 0644f15ba..f78198e64 100644 --- a/lookandfeel/contents/components/KeyboardLayoutButton.qml +++ b/lookandfeel/contents/components/KeyboardLayoutButton.qml @@ -25,11 +25,8 @@ import org.kde.plasma.workspace.keyboardlayout 1.0 PlasmaComponents.Button { id: kbLayoutButton -// flat: false -// checkable: false - activeFocusOnTab: true implicitWidth: minimumWidth - text: layout.currentLayout + text: layout.currentLayoutDisplayName Accessible.name: i18ndc("plasma_lookandfeel_org.kde.lookandfeel", "Button to change keyboard layout", "Switch layout")