Commit d43c2690 authored by Andrey Butirsky's avatar Andrey Butirsky

impr: Keyboard Layout plugin: drop excessive DBus API method arguments

Considerations:
* In any point of time, the only layout info client might need is about:
    - a single layout (the current one)
    - list of all layouts configured (e.g to fill context menu entries)
  There is no chance it might need to asqure some random layout info
  which is not current.
* To get current layout Display Name, client shouldn't have to asqure
  the current layout itself first - such dependecy makes code based on
  async DBus API unnecessary complicated.
* Shall the layouts context menu be ever desired, it would be easy to
  implement by adding both Name lists (Short/Long) and Index getters to
  the API.

KWin/P-D parts:
impr: Keyboard Layout DBus API: drop excessive method arguments
parent 7d539f6a
......@@ -11,16 +11,12 @@
#include <QDBusInterface>
template<>
void KeyboardLayout::requestDBusData<KeyboardLayout::CurrentLayout>()
{ if (mIface) requestDBusData(mIface->getCurrentLayout(), mCurrentLayout, &KeyboardLayout::currentLayoutChanged); }
void KeyboardLayout::requestDBusData<KeyboardLayout::LayoutDisplayName>()
{ if (mIface) requestDBusData(mIface->getLayoutDisplayName(), mLayoutDisplayName, &KeyboardLayout::layoutDisplayNameChanged); }
template<>
void KeyboardLayout::requestDBusData<KeyboardLayout::CurrentLayoutDisplayName>()
{ if (mIface) requestDBusData(mIface->getLayoutDisplayName(mCurrentLayout), mCurrentLayoutDisplayName, &KeyboardLayout::currentLayoutDisplayNameChanged); }
template<>
void KeyboardLayout::requestDBusData<KeyboardLayout::CurrentLayoutLongName>()
{ if (mIface) requestDBusData(mIface->getCurrentLayoutLongName(), mCurrentLayoutLongName, &KeyboardLayout::currentLayoutLongNameChanged); }
void KeyboardLayout::requestDBusData<KeyboardLayout::LayoutLongName>()
{ if (mIface) requestDBusData(mIface->getLayoutLongName(), mLayoutLongName, &KeyboardLayout::layoutLongNameChanged); }
template<>
void KeyboardLayout::requestDBusData<KeyboardLayout::Layouts>()
......@@ -41,23 +37,19 @@ KeyboardLayout::KeyboardLayout(QObject* parent)
return;
}
connect(mIface, &OrgKdeKeyboardLayoutsInterface::currentLayoutChanged,
this, [this](const QString &newLayout)
connect(mIface, &OrgKdeKeyboardLayoutsInterface::layoutChanged,
this, [this]()
{
mCurrentLayout = newLayout;
requestDBusData<CurrentLayoutDisplayName>();
requestDBusData<CurrentLayoutLongName>();
requestDBusData<LayoutDisplayName>();
requestDBusData<LayoutLongName>();
});
connect(mIface, &OrgKdeKeyboardLayoutsInterface::layoutListChanged,
this, [this]()
{
requestDBusData<CurrentLayout>();
requestDBusData<CurrentLayoutLongName>();
requestDBusData<LayoutDisplayName>();
requestDBusData<LayoutLongName>();
requestDBusData<Layouts>();
});
connect(this, &KeyboardLayout::currentLayoutChanged,
this, &KeyboardLayout::requestDBusData<CurrentLayoutDisplayName>);
emit mIface->OrgKdeKeyboardLayoutsInterface::layoutListChanged();
}
......@@ -71,11 +63,6 @@ void KeyboardLayout::switchToNextLayout()
if (mIface) mIface->switchToNextLayout();
}
void KeyboardLayout::setCurrentLayout(const QString &layout)
{
if (mIface) mIface->setLayout(layout);
}
template<class T>
void KeyboardLayout::requestDBusData(QDBusPendingReply<T> pendingReply, T &out, void (KeyboardLayout::*notify)())
{
......
......@@ -18,18 +18,13 @@ class KeyboardLayout : public QObject
{
Q_OBJECT
Q_PROPERTY(QString currentLayout
MEMBER mCurrentLayout
WRITE setCurrentLayout
NOTIFY currentLayoutChanged)
Q_PROPERTY(QString layoutDisplayName
MEMBER mLayoutDisplayName
NOTIFY layoutDisplayNameChanged)
Q_PROPERTY(QString currentLayoutDisplayName
MEMBER mCurrentLayoutDisplayName
NOTIFY currentLayoutDisplayNameChanged)
Q_PROPERTY(QString currentLayoutLongName
MEMBER mCurrentLayoutLongName
NOTIFY currentLayoutLongNameChanged)
Q_PROPERTY(QString layoutLongName
MEMBER mLayoutLongName
NOTIFY layoutLongNameChanged)
Q_PROPERTY(QStringList layouts
MEMBER mLayouts
......@@ -40,27 +35,23 @@ public:
~KeyboardLayout() override;
Q_SIGNALS:
void currentLayoutChanged();
void currentLayoutDisplayNameChanged();
void currentLayoutLongNameChanged();
void layoutDisplayNameChanged();
void layoutLongNameChanged();
void layoutsChanged();
protected Q_SLOTS:
void switchToNextLayout();
private:
void setCurrentLayout(const QString &layout);
enum DBusData {CurrentLayout, CurrentLayoutDisplayName, CurrentLayoutLongName, Layouts};
enum DBusData {LayoutDisplayName, LayoutLongName, Layouts};
template<class T>
void requestDBusData(QDBusPendingReply<T> pendingReply, T &out, void (KeyboardLayout::*notify)());
template<DBusData>
inline void requestDBusData();
QString mCurrentLayout;
QString mCurrentLayoutDisplayName;
QString mCurrentLayoutLongName;
QString mLayoutDisplayName;
QString mLayoutLongName;
QStringList mLayouts;
OrgKdeKeyboardLayoutsInterface *mIface;
};
......
......@@ -2,7 +2,7 @@
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.KeyboardLayouts">
<signal name="currentLayoutChanged">
<signal name="layoutChanged">
<arg name="layout" type="s" direction="out"/>
</signal>
<signal name="layoutListChanged">
......@@ -13,19 +13,18 @@
<arg type="b" direction="out"/>
<arg name="layout" type="s" direction="in"/>
</method>
<method name="getCurrentLayout">
<method name="getLayout">
<arg type="s" direction="out"/>
</method>
<method name="getCurrentLayoutLongName">
<method name="getLayoutDisplayName">
<arg type="s" direction="out"/>
</method>
<method name="getLayoutLongName">
<arg type="s" direction="out"/>
</method>
<method name="getLayoutsList">
<arg type="as" direction="out"/>
</method>
<method name="getLayoutDisplayName">
<arg type="s" direction="out"/>
<arg name="layout" type="s" direction="in"/>
</method>
</interface>
</node>
......@@ -11,8 +11,8 @@ import org.kde.plasma.workspace.keyboardlayout 1.0
PlasmaComponents3.ToolButton {
id: kbLayoutButton
property alias layoutShortName: layout.currentLayoutDisplayName
property alias layoutLongName: layout.currentLayoutLongName
property alias layoutShortName: layout.layoutDisplayName
property alias layoutLongName: layout.layoutLongName
readonly property bool hasMultipleKeyboardLayouts: layout.layouts.length > 1
text: layoutLongName
......
Markdown is supported
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