Commit 24812f8b authored by Volker Krause's avatar Volker Krause
Browse files

Port keystate data engine to KLazyLocalizedString

The I18N_NOOP use here looks questionable, as we hand out untranslated
strings to somebody else who might use a different domain for translating
them, but probably not worth reworking with data engines on the way out
anyway. This change doesn't make this any better or worse.
parent 0bf22263
Pipeline #147499 passed with stage
in 11 minutes and 19 seconds
......@@ -12,22 +12,22 @@
KeyStatesEngine::KeyStatesEngine(QObject *parent, const QVariantList &args)
: Plasma::DataEngine(parent, args)
{
m_mods.insert(Qt::Key_Shift, I18N_NOOP("Shift"));
m_mods.insert(Qt::Key_Control, I18N_NOOP("Ctrl"));
m_mods.insert(Qt::Key_Alt, I18N_NOOP("Alt"));
m_mods.insert(Qt::Key_Meta, I18N_NOOP("Meta"));
m_mods.insert(Qt::Key_Super_L, I18N_NOOP("Super"));
m_mods.insert(Qt::Key_Hyper_L, I18N_NOOP("Hyper"));
m_mods.insert(Qt::Key_AltGr, I18N_NOOP("AltGr"));
m_mods.insert(Qt::Key_NumLock, I18N_NOOP("Num Lock"));
m_mods.insert(Qt::Key_CapsLock, I18N_NOOP("Caps Lock"));
m_mods.insert(Qt::Key_ScrollLock, I18N_NOOP("Scroll Lock"));
m_buttons.insert(Qt::LeftButton, I18N_NOOP("Left Button"));
m_buttons.insert(Qt::RightButton, I18N_NOOP("Right Button"));
m_buttons.insert(Qt::MiddleButton, I18N_NOOP("Middle Button"));
m_buttons.insert(Qt::XButton1, I18N_NOOP("First X Button"));
m_buttons.insert(Qt::XButton2, I18N_NOOP("Second X Button"));
m_mods.insert(Qt::Key_Shift, kli18n("Shift"));
m_mods.insert(Qt::Key_Control, kli18n("Ctrl"));
m_mods.insert(Qt::Key_Alt, kli18n("Alt"));
m_mods.insert(Qt::Key_Meta, kli18n("Meta"));
m_mods.insert(Qt::Key_Super_L, kli18n("Super"));
m_mods.insert(Qt::Key_Hyper_L, kli18n("Hyper"));
m_mods.insert(Qt::Key_AltGr, kli18n("AltGr"));
m_mods.insert(Qt::Key_NumLock, kli18n("Num Lock"));
m_mods.insert(Qt::Key_CapsLock, kli18n("Caps Lock"));
m_mods.insert(Qt::Key_ScrollLock, kli18n("Scroll Lock"));
m_buttons.insert(Qt::LeftButton, kli18n("Left Button"));
m_buttons.insert(Qt::RightButton, kli18n("Right Button"));
m_buttons.insert(Qt::MiddleButton, kli18n("Middle Button"));
m_buttons.insert(Qt::XButton1, kli18n("First X Button"));
m_buttons.insert(Qt::XButton2, kli18n("Second X Button"));
init();
}
......@@ -37,24 +37,22 @@ KeyStatesEngine::~KeyStatesEngine()
void KeyStatesEngine::init()
{
QMap<Qt::Key, QString>::const_iterator it;
QMap<Qt::Key, QString>::const_iterator end = m_mods.constEnd();
for (it = m_mods.constBegin(); it != end; ++it) {
const auto end = m_mods.constEnd();
for (auto it = m_mods.constBegin(); it != end; ++it) {
if (m_keyInfo.knowsKey(it.key())) {
Data data;
data.insert(I18N_NOOP("Pressed"), m_keyInfo.isKeyPressed(it.key()));
data.insert(I18N_NOOP("Latched"), m_keyInfo.isKeyLatched(it.key()));
data.insert(I18N_NOOP("Locked"), m_keyInfo.isKeyLocked(it.key()));
setData(it.value(), data);
data.insert(kli18n("Pressed").untranslatedText(), m_keyInfo.isKeyPressed(it.key()));
data.insert(kli18n("Latched").untranslatedText(), m_keyInfo.isKeyLatched(it.key()));
data.insert(kli18n("Locked").untranslatedText(), m_keyInfo.isKeyLocked(it.key()));
setData(it.value().untranslatedText(), data);
}
}
QMap<Qt::MouseButton, QString>::const_iterator it2;
QMap<Qt::MouseButton, QString>::const_iterator end2 = m_buttons.constEnd();
for (it2 = m_buttons.constBegin(); it2 != end2; ++it2) {
const auto end2 = m_buttons.constEnd();
for (auto it2 = m_buttons.constBegin(); it2 != end2; ++it2) {
Data data;
data.insert(I18N_NOOP("Pressed"), m_keyInfo.isButtonPressed(it2.key()));
setData(it2.value(), data);
data.insert(kli18n("Pressed").untranslatedText(), m_keyInfo.isButtonPressed(it2.key()));
setData(it2.value().untranslatedText(), data);
}
connect(&m_keyInfo, &KModifierKeyInfo::keyPressed, this, &KeyStatesEngine::keyPressed);
......@@ -67,10 +65,9 @@ void KeyStatesEngine::init()
Plasma::Service *KeyStatesEngine::serviceForSource(const QString &source)
{
QMap<Qt::Key, QString>::const_iterator it;
QMap<Qt::Key, QString>::const_iterator end = m_mods.constEnd();
for (it = m_mods.constBegin(); it != end; ++it) {
if (it.value() == source) {
const auto end = m_mods.constEnd();
for (auto it = m_mods.constBegin(); it != end; ++it) {
if (it.value().untranslatedText() == source) {
return new KeyService(this, &m_keyInfo, it.key());
}
}
......@@ -81,28 +78,28 @@ Plasma::Service *KeyStatesEngine::serviceForSource(const QString &source)
void KeyStatesEngine::keyPressed(Qt::Key key, bool state)
{
if (m_mods.contains(key)) {
setData(m_mods.value(key), I18N_NOOP("Pressed"), state);
setData(m_mods.value(key).untranslatedText(), kli18n("Pressed").untranslatedText(), state);
}
}
void KeyStatesEngine::keyLatched(Qt::Key key, bool state)
{
if (m_mods.contains(key)) {
setData(m_mods.value(key), I18N_NOOP("Latched"), state);
setData(m_mods.value(key).untranslatedText(), kli18n("Latched").untranslatedText(), state);
}
}
void KeyStatesEngine::keyLocked(Qt::Key key, bool state)
{
if (m_mods.contains(key)) {
setData(m_mods.value(key), I18N_NOOP("Locked"), state);
setData(m_mods.value(key).untranslatedText(), kli18n("Locked").untranslatedText(), state);
}
}
void KeyStatesEngine::mouseButtonPressed(Qt::MouseButton button, bool state)
{
if (m_buttons.contains(button)) {
setData(m_buttons.value(button), I18N_NOOP("Pressed"), state);
setData(m_buttons.value(button).untranslatedText(), kli18n("Pressed").untranslatedText(), state);
}
}
......@@ -110,17 +107,17 @@ void KeyStatesEngine::keyAdded(Qt::Key key)
{
if (m_mods.contains(key)) {
Data data;
data.insert(I18N_NOOP("Pressed"), m_keyInfo.isKeyPressed(key));
data.insert(I18N_NOOP("Latched"), m_keyInfo.isKeyLatched(key));
data.insert(I18N_NOOP("Locked"), m_keyInfo.isKeyLocked(key));
setData(m_mods.value(key), data);
data.insert(kli18n("Pressed").untranslatedText(), m_keyInfo.isKeyPressed(key));
data.insert(kli18n("Latched").untranslatedText(), m_keyInfo.isKeyLatched(key));
data.insert(kli18n("Locked").untranslatedText(), m_keyInfo.isKeyLocked(key));
setData(m_mods.value(key).untranslatedText(), data);
}
}
void KeyStatesEngine::keyRemoved(Qt::Key key)
{
if (m_mods.contains(key)) {
removeSource(m_mods.value(key));
removeSource(m_mods.value(key).untranslatedText());
}
}
......
......@@ -8,6 +8,7 @@
#include <Plasma/DataEngine>
#include <KLazyLocalizedString>
#include <kmodifierkeyinfo.h>
/**
......@@ -39,6 +40,6 @@ protected Q_SLOTS:
private:
KModifierKeyInfo m_keyInfo;
QMap<Qt::Key, QString> m_mods;
QMap<Qt::MouseButton, QString> m_buttons;
QMap<Qt::Key, KLazyLocalizedString> m_mods;
QMap<Qt::MouseButton, KLazyLocalizedString> m_buttons;
};
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