Commit d6438a01 authored by Andrey Butirsky's avatar Andrey Butirsky
Browse files

refactor: keyboard layout applet: return to Properties-based QML API

Return "layout" and "layoutsList" Properties where all layouts names are
now stored.
getLayoutLongName() DBus method is not used any more so it was also
deleted from DBus API in KWin and P-D, see corresponding commits there.

The Properties interface allows QML code be more declarative.
There is a trade-off though as now we have to:
- store all layout names on client side, even if it's not needed for
base QML layout component here
- duplicate layouts in layoutsList Property as they are also stored in
Action objects of the plasmoid in P-D.
parent 9c885b97
......@@ -12,20 +12,11 @@
inline void KeyboardLayout::requestDBusData<KeyboardLayout::Layout>()
{ if (mIface) requestDBusData(mIface->getLayout(), &KeyboardLayout::layoutChanged); }
{ if (mIface) requestDBusData(mIface->getLayout(), mLayout, &KeyboardLayout::layoutChanged); }
inline void KeyboardLayout::requestDBusData<KeyboardLayout::Layouts>()
{ if (mIface) requestDBusData(mIface->getLayoutsList(), &KeyboardLayout::layoutsChanged); }
inline void KeyboardLayout::requestDBusData<KeyboardLayout::LayoutLongName>()
{ if (mIface) requestDBusData(mIface->getLayoutLongName(), &KeyboardLayout::layoutLongNameChanged); }
void KeyboardLayout::requestLayoutLongName()
inline void KeyboardLayout::requestDBusData<KeyboardLayout::LayoutsList>()
{ if (mIface) requestDBusData(mIface->getLayoutsList(), mLayoutsList, &KeyboardLayout::layoutsListChanged); }
KeyboardLayout::KeyboardLayout(QObject* parent)
......@@ -45,12 +36,16 @@ KeyboardLayout::KeyboardLayout(QObject* parent)
connect(mIface, &OrgKdeKeyboardLayoutsInterface::layoutChanged,
this, &KeyboardLayout::layoutChanged);
this, [this](uint index)
mLayout = index;
emit layoutChanged();
connect(mIface, &OrgKdeKeyboardLayoutsInterface::layoutListChanged,
this, [this]()
......@@ -77,18 +72,18 @@ void KeyboardLayout::setLayout(uint index)
template<class T>
void KeyboardLayout::requestDBusData(QDBusPendingReply<T> pendingReply, void (KeyboardLayout::*notify)(T))
void KeyboardLayout::requestDBusData(QDBusPendingReply<T> pendingReply, T &out, void (KeyboardLayout::*notify)())
const QDBusPendingCallWatcher * const watcher = new QDBusPendingCallWatcher(pendingReply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this,
[this, notify](QDBusPendingCallWatcher *watcher)
connect(new QDBusPendingCallWatcher(pendingReply, this), &QDBusPendingCallWatcher::finished, this,
[this, &out, notify](QDBusPendingCallWatcher *watcher)
QDBusPendingReply<T> reply = *watcher;
if (reply.isError()) {
qCWarning(KEYBOARD_LAYOUT) << reply.error().message();
} else {
emit (this->*notify)(reply.value());
out = reply.value();
emit (this->*notify)();
......@@ -18,31 +18,40 @@ class KeyboardLayout : public QObject
Q_PROPERTY(uint layout
MEMBER mLayout
WRITE setLayout
NOTIFY layoutChanged)
Q_PROPERTY(const QVector<LayoutNames>& layoutsList
READ getLayoutsList
NOTIFY layoutsListChanged)
explicit KeyboardLayout(QObject *parent = nullptr);
~KeyboardLayout() override;
void layoutChanged(uint index);
void layoutsChanged(QVector<LayoutNames> layouts);
void layoutLongNameChanged(QString longName);
void layoutChanged();
void layoutsListChanged();
Q_INVOKABLE void switchToNextLayout();
Q_INVOKABLE void switchToPreviousLayout();
Q_INVOKABLE void setLayout(uint index);
Q_INVOKABLE void requestLayoutLongName();
enum DBusData {Layout, LayoutLongName, Layouts};
void setLayout(uint index);
const QVector<LayoutNames> &getLayoutsList() const { return mLayoutsList; }
enum DBusData {Layout, LayoutsList};
template<class T>
void requestDBusData(QDBusPendingReply<T> pendingReply, void (KeyboardLayout::*notify)(T));
void requestDBusData(QDBusPendingReply<T> pendingReply, T &out, void (KeyboardLayout::*notify)());
void requestDBusData();
uint mLayout;
QVector<LayoutNames> mLayoutsList;
OrgKdeKeyboardLayoutsInterface *mIface;
......@@ -18,9 +18,6 @@
<method name="getLayout">
<arg type="u" direction="out"/>
<method name="getLayoutLongName">
<arg type="s" direction="out"/>
<method name="getLayoutsList">
<arg type="a(sss)" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVector&lt;LayoutNames&gt;" />
......@@ -10,9 +10,10 @@ import org.kde.plasma.workspace.keyboardlayout 1.0
PlasmaComponents3.ToolButton {
property alias keyboardLayout: keyboardLayout
property alias connections: connections
property bool hasMultipleKeyboardLayouts
readonly property bool hasMultipleKeyboardLayouts: keyboardLayout.layoutsList.length > 1
readonly property var layoutNames: keyboardLayout.layoutsList[keyboardLayout.layout]
text: layoutNames.longName
visible: hasMultipleKeyboardLayouts i18ndc("plasma_lookandfeel_org.kde.lookandfeel", "Button to change keyboard layout", "Switch layout")
......@@ -34,20 +35,5 @@ PlasmaComponents3.ToolButton {
KeyboardLayout {
id: keyboardLayout
onLayoutsChanged: hasMultipleKeyboardLayouts = layouts.length > 1
Connections {
id: connections
target: keyboardLayout
function onLayoutChanged() {
function onLayoutLongNameChanged(longName) {
text = longName
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment