inputmethod sni: return early for readability

This commit is contained in:
Aleix Pol 2021-07-19 18:23:34 +02:00
parent d2ceea83b7
commit 0169bca6e0

View file

@ -501,42 +501,41 @@ void InputMethod::adoptInputMethodContext()
void InputMethod::updateSni()
{
if (!m_inputMethodCommand.isEmpty()) {
if (!m_sni) {
qCDebug(KWIN_VIRTUALKEYBOARD) << "Registering the SNI";
m_sni.reset(new KStatusNotifierItem(QStringLiteral("kwin-virtual-keyboard"), this));
connect(m_sni.get(), &KStatusNotifierItem::activateRequested, this,
[this] {
setEnabled(!m_enabled);
}
);
}
m_sni->setStandardActionsEnabled(false);
m_sni->setCategory(KStatusNotifierItem::Hardware);
m_sni->setStatus(KStatusNotifierItem::Passive);
m_sni->setTitle(i18n("Virtual Keyboard"));
m_sni->setToolTipTitle(i18n("Whether to show the virtual keyboard on demand."));
m_sni->setStandardActionsEnabled(false);
QMenu *sniMenu = new QMenu;
sniMenu->addAction(i18n("Configure virtual keyboards..."), this, [] {
QProcess::startDetached("systemsettings5", {"kcm_virtualkeyboard"});
});
m_sni->setContextMenu(sniMenu);
if (m_enabled) {
m_sni->setIconByName(QStringLiteral("input-keyboard-virtual-on"));
m_sni->setTitle(i18n("Virtual Keyboard: enabled"));
m_sni->setOverlayIconByName({});
} else {
m_sni->setIconByName(QStringLiteral("input-keyboard-virtual-off"));
m_sni->setTitle(i18n("Virtual Keyboard: disabled"));
m_sni->setOverlayIconByName({});
}
} else {
if (m_inputMethodCommand.isEmpty()) {
m_sni.reset();
return;
}
if (!m_sni) {
qCDebug(KWIN_VIRTUALKEYBOARD) << "Registering the SNI";
m_sni.reset(new KStatusNotifierItem(QStringLiteral("kwin-virtual-keyboard"), this));
connect(m_sni.get(), &KStatusNotifierItem::activateRequested, this,
[this] {
setEnabled(!m_enabled);
}
);
}
m_sni->setStandardActionsEnabled(false);
m_sni->setCategory(KStatusNotifierItem::Hardware);
m_sni->setStatus(KStatusNotifierItem::Passive);
m_sni->setTitle(i18n("Virtual Keyboard"));
m_sni->setToolTipTitle(i18n("Whether to show the virtual keyboard on demand."));
QMenu *sniMenu = new QMenu;
sniMenu->addAction(i18n("Configure virtual keyboards..."), this, [] {
QProcess::startDetached("systemsettings5", {"kcm_virtualkeyboard"});
});
m_sni->setContextMenu(sniMenu);
if (m_enabled) {
m_sni->setIconByName(QStringLiteral("input-keyboard-virtual-on"));
m_sni->setTitle(i18n("Virtual Keyboard: enabled"));
m_sni->setOverlayIconByName({});
} else {
m_sni->setIconByName(QStringLiteral("input-keyboard-virtual-off"));
m_sni->setTitle(i18n("Virtual Keyboard: disabled"));
m_sni->setOverlayIconByName({});
}
}