Changeset View
Changeset View
Standalone View
Standalone View
components/keyboardlayout/keyboardlayout.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2014 Daniel Vratil <dvratil@redhat.com> | 2 | * Copyright (C) 2014 Daniel Vratil <dvratil@redhat.com> | ||
3 | * Copyright (C) 2019 David Edmundson <davidedmundson@kde.org> | ||||
3 | * | 4 | * | ||
4 | * This library is free software; you can redistribute it and/or | 5 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | 6 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | 7 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | 8 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | 9 | * | ||
9 | * This library is distributed in the hope that it will be useful, | 10 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
Show All 9 Lines | |||||
20 | #include "keyboardlayout.h" | 21 | #include "keyboardlayout.h" | ||
21 | 22 | | |||
22 | #include <QDBusInterface> | 23 | #include <QDBusInterface> | ||
23 | #include <QDBusReply> | 24 | #include <QDBusReply> | ||
24 | 25 | | |||
25 | #include <QDebug> | 26 | #include <QDebug> | ||
26 | #include "debug.h" | 27 | #include "debug.h" | ||
27 | 28 | | |||
29 | #include "keyboard_layout_interface.h" | ||||
30 | | ||||
28 | KeyboardLayout::KeyboardLayout(QObject* parent) | 31 | KeyboardLayout::KeyboardLayout(QObject* parent) | ||
29 | : QObject(parent) | 32 | : QObject(parent) | ||
30 | , mIface(nullptr) | 33 | , mIface(nullptr) | ||
31 | { | 34 | { | ||
32 | mIface = new QDBusInterface(QStringLiteral("org.kde.keyboard"), | 35 | mIface = new OrgKdeKeyboardLayoutsInterface(QStringLiteral("org.kde.keyboard"), | ||
33 | QStringLiteral("/Layouts"), | 36 | QStringLiteral("/Layouts"), | ||
34 | QStringLiteral("org.kde.KeyboardLayouts"), | | |||
35 | QDBusConnection::sessionBus(), | 37 | QDBusConnection::sessionBus(), | ||
36 | this); | 38 | this); | ||
37 | if (!mIface->isValid()) { | 39 | if (!mIface->isValid()) { | ||
38 | delete mIface; | 40 | delete mIface; | ||
39 | mIface = nullptr; | 41 | mIface = nullptr; | ||
40 | return; | 42 | return; | ||
41 | } | 43 | } | ||
42 | 44 | | |||
43 | connect(mIface, SIGNAL(currentLayoutChanged(QString)), | 45 | connect(mIface, &OrgKdeKeyboardLayoutsInterface::currentLayoutChanged, | ||
44 | this, SLOT(setCurrentLayout(QString))); | 46 | this, &KeyboardLayout::setCurrentLayout); | ||
45 | connect(mIface, SIGNAL(layoutListChanged()), | 47 | connect(mIface, &OrgKdeKeyboardLayoutsInterface::layoutListChanged, | ||
46 | this, SLOT(requestLayoutsList())); | 48 | this, &KeyboardLayout::requestLayoutsList); | ||
47 | 49 | | |||
48 | requestCurrentLayout(); | 50 | requestCurrentLayout(); | ||
49 | requestLayoutsList(); | 51 | requestLayoutsList(); | ||
50 | 52 | | |||
51 | } | 53 | } | ||
52 | 54 | | |||
53 | KeyboardLayout::~KeyboardLayout() | 55 | KeyboardLayout::~KeyboardLayout() | ||
54 | { | 56 | { | ||
55 | } | 57 | } | ||
56 | 58 | | |||
57 | void KeyboardLayout::requestCurrentLayout() | 59 | void KeyboardLayout::requestCurrentLayout() | ||
58 | { | 60 | { | ||
59 | if (!mIface) { | 61 | if (!mIface) { | ||
60 | return; | 62 | return; | ||
61 | } | 63 | } | ||
62 | 64 | | |||
63 | QDBusPendingCall pendingLayout = mIface->asyncCall(QStringLiteral("getCurrentLayout")); | 65 | QDBusPendingReply<QString> pendingLayout = mIface->getCurrentLayout(); | ||
64 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingLayout, this); | 66 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingLayout, this); | ||
65 | connect(watcher, &QDBusPendingCallWatcher::finished, | 67 | connect(watcher, &QDBusPendingCallWatcher::finished, | ||
66 | this, &KeyboardLayout::onCurrentLayoutReceived); | 68 | this, &KeyboardLayout::onCurrentLayoutReceived); | ||
67 | } | 69 | } | ||
68 | 70 | | |||
69 | void KeyboardLayout::onCurrentLayoutReceived(QDBusPendingCallWatcher *watcher) | 71 | void KeyboardLayout::onCurrentLayoutReceived(QDBusPendingCallWatcher *watcher) | ||
70 | { | 72 | { | ||
71 | QDBusPendingReply<QString> reply = *watcher; | 73 | QDBusPendingReply<QString> reply = *watcher; | ||
72 | if (reply.isError()) { | 74 | if (reply.isError()) { | ||
73 | qCWarning(KEYBOARD_LAYOUT) << reply.error().message(); | 75 | qCWarning(KEYBOARD_LAYOUT) << reply.error().message(); | ||
74 | } else { | 76 | } else { | ||
75 | mCurrentLayout = reply.value(); | 77 | mCurrentLayout = reply.value(); | ||
76 | requestCurrentLayoutDisplayName(); | 78 | requestCurrentLayoutDisplayName(); | ||
77 | Q_EMIT currentLayoutChanged(mCurrentLayout); | 79 | Q_EMIT currentLayoutChanged(mCurrentLayout); | ||
78 | } | 80 | } | ||
79 | watcher->deleteLater(); | 81 | watcher->deleteLater(); | ||
80 | } | 82 | } | ||
81 | 83 | | |||
82 | void KeyboardLayout::requestCurrentLayoutDisplayName() | 84 | void KeyboardLayout::requestCurrentLayoutDisplayName() | ||
83 | { | 85 | { | ||
84 | QDBusPendingCall pendingDisplayName = mIface->asyncCallWithArgumentList(QStringLiteral("getLayoutDisplayName"), {mCurrentLayout}); | 86 | QDBusPendingReply<QString> pendingDisplayName = mIface->getLayoutDisplayName(mCurrentLayout); | ||
85 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingDisplayName, this); | 87 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingDisplayName, this); | ||
86 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &KeyboardLayout::onCurrentLayoutDisplayNameReceived); | 88 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &KeyboardLayout::onCurrentLayoutDisplayNameReceived); | ||
87 | } | 89 | } | ||
88 | 90 | | |||
89 | void KeyboardLayout::onCurrentLayoutDisplayNameReceived(QDBusPendingCallWatcher *watcher) | 91 | void KeyboardLayout::onCurrentLayoutDisplayNameReceived(QDBusPendingCallWatcher *watcher) | ||
90 | { | 92 | { | ||
91 | QDBusPendingReply<QString> reply = *watcher; | 93 | QDBusPendingReply<QString> reply = *watcher; | ||
92 | if (reply.isError()) { | 94 | if (reply.isError()) { | ||
Show All 11 Lines | |||||
104 | } | 106 | } | ||
105 | 107 | | |||
106 | void KeyboardLayout::requestLayoutsList() | 108 | void KeyboardLayout::requestLayoutsList() | ||
107 | { | 109 | { | ||
108 | if (!mIface) { | 110 | if (!mIface) { | ||
109 | return; | 111 | return; | ||
110 | } | 112 | } | ||
111 | 113 | | |||
112 | QDBusPendingCall pendingLayout = mIface->asyncCall(QStringLiteral("getLayoutsList")); | 114 | QDBusPendingReply<QStringList> pendingLayout = mIface->getLayoutsList(); | ||
113 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingLayout, this); | 115 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingLayout, this); | ||
114 | connect(watcher, &QDBusPendingCallWatcher::finished, | 116 | connect(watcher, &QDBusPendingCallWatcher::finished, | ||
115 | this, &KeyboardLayout::onLayoutsListReceived); | 117 | this, &KeyboardLayout::onLayoutsListReceived); | ||
116 | } | 118 | } | ||
117 | 119 | | |||
118 | 120 | | |||
119 | void KeyboardLayout::onLayoutsListReceived(QDBusPendingCallWatcher *watcher) | 121 | void KeyboardLayout::onLayoutsListReceived(QDBusPendingCallWatcher *watcher) | ||
120 | { | 122 | { | ||
Show All 24 Lines | 140 | { | |||
145 | 147 | | |||
146 | if (!mLayouts.contains(layout)) { | 148 | if (!mLayouts.contains(layout)) { | ||
147 | qCWarning(KEYBOARD_LAYOUT) << "No such layout" << layout; | 149 | qCWarning(KEYBOARD_LAYOUT) << "No such layout" << layout; | ||
148 | return; | 150 | return; | ||
149 | } | 151 | } | ||
150 | 152 | | |||
151 | mCurrentLayout = layout; | 153 | mCurrentLayout = layout; | ||
152 | requestCurrentLayoutDisplayName(); | 154 | requestCurrentLayoutDisplayName(); | ||
153 | mIface->asyncCall(QStringLiteral("setLayout"), layout); | 155 | mIface->setLayout(layout); | ||
154 | Q_EMIT currentLayoutChanged(layout); | 156 | Q_EMIT currentLayoutChanged(layout); | ||
155 | } | 157 | } | ||
156 | 158 | | |||
157 | 159 | | |||
158 | QStringList KeyboardLayout::layouts() const | 160 | QStringList KeyboardLayout::layouts() const | ||
159 | { | 161 | { | ||
160 | return mLayouts; | 162 | return mLayouts; | ||
161 | } | 163 | } | ||
162 | 164 | |