Changeset View
Changeset View
Standalone View
Standalone View
keyboard_layout.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 55 | { | |||
---|---|---|---|---|---|
65 | QDBusConnection::sessionBus().connect(QString(), | 65 | QDBusConnection::sessionBus().connect(QString(), | ||
66 | QStringLiteral("/Layouts"), | 66 | QStringLiteral("/Layouts"), | ||
67 | QStringLiteral("org.kde.keyboard"), | 67 | QStringLiteral("org.kde.keyboard"), | ||
68 | QStringLiteral("reloadConfig"), | 68 | QStringLiteral("reloadConfig"), | ||
69 | this, | 69 | this, | ||
70 | SLOT(reconfigure())); | 70 | SLOT(reconfigure())); | ||
71 | 71 | | |||
72 | reconfigure(); | 72 | reconfigure(); | ||
73 | | ||||
74 | initDBusInterface(); | ||||
75 | } | ||||
76 | | ||||
77 | void KeyboardLayout::initDBusInterface() | ||||
78 | { | ||||
79 | auto dbusInterface = new KeyboardLayoutDBusInterface(m_xkb, this); | ||||
80 | connect(this, &KeyboardLayout::layoutChanged, dbusInterface, | ||||
81 | [this, dbusInterface] { | ||||
82 | emit dbusInterface->currentLayoutChanged(m_xkb->layoutName()); | ||||
83 | } | ||||
84 | ); | ||||
85 | // TODO: the signal might be emitted even if the list didn't change | ||||
86 | connect(this, &KeyboardLayout::layoutsReconfigured, dbusInterface, &KeyboardLayoutDBusInterface::layoutListChanged); | ||||
73 | } | 87 | } | ||
74 | 88 | | |||
75 | void KeyboardLayout::initNotifierItem() | 89 | void KeyboardLayout::initNotifierItem() | ||
76 | { | 90 | { | ||
77 | bool showNotifier = true; | 91 | bool showNotifier = true; | ||
78 | bool showSingle = false; | 92 | bool showSingle = false; | ||
79 | if (m_config) { | 93 | if (m_config) { | ||
80 | const auto config = m_config->group(QStringLiteral("Layout")); | 94 | const auto config = m_config->group(QStringLiteral("Layout")); | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | |||||
149 | 163 | | |||
150 | void KeyboardLayout::resetLayout() | 164 | void KeyboardLayout::resetLayout() | ||
151 | { | 165 | { | ||
152 | m_layout = m_xkb->currentLayout(); | 166 | m_layout = m_xkb->currentLayout(); | ||
153 | initNotifierItem(); | 167 | initNotifierItem(); | ||
154 | updateNotifier(); | 168 | updateNotifier(); | ||
155 | reinitNotifierMenu(); | 169 | reinitNotifierMenu(); | ||
156 | loadShortcuts(); | 170 | loadShortcuts(); | ||
171 | emit layoutsReconfigured(); | ||||
157 | } | 172 | } | ||
158 | 173 | | |||
159 | void KeyboardLayout::loadShortcuts() | 174 | void KeyboardLayout::loadShortcuts() | ||
160 | { | 175 | { | ||
161 | qDeleteAll(m_layoutShortcuts); | 176 | qDeleteAll(m_layoutShortcuts); | ||
162 | m_layoutShortcuts.clear(); | 177 | m_layoutShortcuts.clear(); | ||
163 | const auto layouts = m_xkb->layoutNames(); | 178 | const auto layouts = m_xkb->layoutNames(); | ||
164 | const QString componentName = QStringLiteral("KDE Keyboard Layout Switcher"); | 179 | const QString componentName = QStringLiteral("KDE Keyboard Layout Switcher"); | ||
Show All 25 Lines | |||||
190 | { | 205 | { | ||
191 | const auto layout = m_xkb->currentLayout(); | 206 | const auto layout = m_xkb->currentLayout(); | ||
192 | if (m_layout == layout) { | 207 | if (m_layout == layout) { | ||
193 | return; | 208 | return; | ||
194 | } | 209 | } | ||
195 | m_layout = layout; | 210 | m_layout = layout; | ||
196 | notifyLayoutChange(); | 211 | notifyLayoutChange(); | ||
197 | updateNotifier(); | 212 | updateNotifier(); | ||
213 | emit layoutChanged(); | ||||
198 | } | 214 | } | ||
199 | 215 | | |||
200 | void KeyboardLayout::notifyLayoutChange() | 216 | void KeyboardLayout::notifyLayoutChange() | ||
201 | { | 217 | { | ||
202 | // notify OSD service about the new layout | 218 | // notify OSD service about the new layout | ||
203 | QDBusMessage msg = QDBusMessage::createMethodCall( | 219 | QDBusMessage msg = QDBusMessage::createMethodCall( | ||
204 | QStringLiteral("org.kde.plasmashell"), | 220 | QStringLiteral("org.kde.plasmashell"), | ||
205 | QStringLiteral("/org/kde/osdService"), | 221 | QStringLiteral("/org/kde/osdService"), | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 253 | [this] { | |||
250 | ); | 266 | ); | ||
251 | p->start(); | 267 | p->start(); | ||
252 | } | 268 | } | ||
253 | ); | 269 | ); | ||
254 | 270 | | |||
255 | m_notifierItem->setContextMenu(menu); | 271 | m_notifierItem->setContextMenu(menu); | ||
256 | } | 272 | } | ||
257 | 273 | | |||
274 | static const QString s_keyboardService = QStringLiteral("org.kde.keyboard"); | ||||
275 | static const QString s_keyboardObject = QStringLiteral("/Layouts"); | ||||
276 | | ||||
277 | KeyboardLayoutDBusInterface::KeyboardLayoutDBusInterface(Xkb *xkb, QObject *parent) | ||||
278 | : QObject(parent) | ||||
279 | , m_xkb(xkb) | ||||
280 | { | ||||
281 | QDBusConnection::sessionBus().registerService(s_keyboardService); | ||||
282 | QDBusConnection::sessionBus().registerObject(s_keyboardObject, this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals); | ||||
283 | } | ||||
284 | | ||||
285 | KeyboardLayoutDBusInterface::~KeyboardLayoutDBusInterface() | ||||
286 | { | ||||
287 | QDBusConnection::sessionBus().unregisterService(s_keyboardService); | ||||
288 | } | ||||
289 | | ||||
290 | bool KeyboardLayoutDBusInterface::setLayout(const QString &layout) | ||||
291 | { | ||||
292 | const auto layouts = m_xkb->layoutNames(); | ||||
293 | auto it = layouts.begin(); | ||||
294 | for (; it !=layouts.end(); it++) { | ||||
295 | if (it.value() == layout) { | ||||
296 | break; | ||||
297 | } | ||||
298 | } | ||||
299 | if (it == layouts.end()) { | ||||
300 | return false; | ||||
301 | } | ||||
302 | m_xkb->switchToLayout(it.key()); | ||||
303 | return true; | ||||
304 | } | ||||
305 | | ||||
306 | QString KeyboardLayoutDBusInterface::getCurrentLayout() | ||||
307 | { | ||||
308 | return m_xkb->layoutName(); | ||||
309 | } | ||||
310 | | ||||
311 | QStringList KeyboardLayoutDBusInterface::getLayoutsList() | ||||
312 | { | ||||
313 | const auto layouts = m_xkb->layoutNames(); | ||||
314 | QStringList ret; | ||||
315 | for (auto it = layouts.begin(); it != layouts.end(); it++) { | ||||
316 | ret << it.value(); | ||||
317 | } | ||||
318 | return ret; | ||||
319 | } | ||||
320 | | ||||
321 | QString KeyboardLayoutDBusInterface::getLayoutDisplayName(const QString &layout) | ||||
322 | { | ||||
323 | return translatedLayout(layout); | ||||
324 | } | ||||
325 | | ||||
258 | } | 326 | } |