summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2023-12-21 19:35:28 +0200
committerMavridis Philippe <mavridisf@gmail.com>2023-12-25 16:38:10 +0200
commit7c724a49212a9ffdf42381d99648f15457867787 (patch)
treedcd3a0f16c58858979650c6d9dc7a5ec42849e1a
parent9647d4c7ff182c1fadffb9c6218bc00132fe682e (diff)
downloadtdebase-7c724a49212a9ffdf42381d99648f15457867787.tar.gz
tdebase-7c724a49212a9ffdf42381d99648f15457867787.zip
KXkb: add keyboard layout notification
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r--kxkb/CMakeL10n.txt6
-rw-r--r--kxkb/CMakeLists.txt6
-rw-r--r--kxkb/eventsrc8
-rw-r--r--kxkb/kcmlayout.cpp9
-rw-r--r--kxkb/kcmlayoutwidget.ui41
-rw-r--r--kxkb/kxkb.cpp44
-rw-r--r--kxkb/kxkb.h1
-rw-r--r--kxkb/kxkbconfig.cpp8
-rw-r--r--kxkb/kxkbconfig.h2
-rw-r--r--kxkb/kxkbtraywindow.h2
-rw-r--r--translations/desktop_files/kxkb-eventsrc/kxkb-eventsrc.pot32
11 files changed, 158 insertions, 1 deletions
diff --git a/kxkb/CMakeL10n.txt b/kxkb/CMakeL10n.txt
index 0238bd7e3..66ed038d9 100644
--- a/kxkb/CMakeL10n.txt
+++ b/kxkb/CMakeL10n.txt
@@ -27,3 +27,9 @@ tde_l10n_create_template(
SOURCES *.desktop
DESTINATION "${CMAKE_SOURCE_DIR}/translations"
)
+
+tde_l10n_create_template(
+ CATALOG "desktop_files/kxkb-eventsrc/"
+ SOURCES eventsrc
+ DESTINATION "${CMAKE_SOURCE_DIR}/translations"
+) \ No newline at end of file
diff --git a/kxkb/CMakeLists.txt b/kxkb/CMakeLists.txt
index b8bb14912..cb0d4b9db 100644
--- a/kxkb/CMakeLists.txt
+++ b/kxkb/CMakeLists.txt
@@ -33,6 +33,12 @@ tde_create_translated_desktop(
PO_DIR kxkb-desktops
)
+tde_create_translated_desktop(
+ SOURCE eventsrc
+ DESTINATION ${DATA_INSTALL_DIR}/kxkb
+ PO_DIR kxkb-eventsrc
+)
+
install( FILES kxkb_groups DESTINATION ${CONFIG_INSTALL_DIR} )
tde_create_translated_desktop(
diff --git a/kxkb/eventsrc b/kxkb/eventsrc
new file mode 100644
index 000000000..ce25f3979
--- /dev/null
+++ b/kxkb/eventsrc
@@ -0,0 +1,8 @@
+[!Global!]
+IconName=kxkb
+Comment=TDE Keyboard Tool
+
+[LayoutChange]
+Name=Keyboard layout switch
+Comment=The keyboard layout was switched
+default_presentation=16 \ No newline at end of file
diff --git a/kxkb/kcmlayout.cpp b/kxkb/kcmlayout.cpp
index 3744f5a1c..7b59e888b 100644
--- a/kxkb/kcmlayout.cpp
+++ b/kxkb/kcmlayout.cpp
@@ -150,6 +150,9 @@ LayoutConfig::LayoutConfig(TQWidget *parent, const char *name)
connect( widget->chkEnableSticky, TQT_SIGNAL(toggled(bool)), TQT_TQOBJECT(this), TQT_SLOT(changed()));
connect( widget->spinStickyDepth, TQT_SIGNAL(valueChanged(int)), TQT_TQOBJECT(this), TQT_SLOT(changed()));
+ connect(widget->chkEnableNotify, SIGNAL(toggled(bool)), SLOT(changed()));
+ connect(widget->chkNotifyUseKMilo, SIGNAL(toggled(bool)), SLOT(changed()));
+
widget->listLayoutsSrc->setColumnText(LAYOUT_COLUMN_FLAG, "");
widget->listLayoutsDst->setColumnText(LAYOUT_COLUMN_FLAG, "");
// widget->listLayoutsDst->setColumnText(LAYOUT_COLUMN_DISPLAY_NAME, "");
@@ -288,6 +291,9 @@ void LayoutConfig::initUI() {
widget->spinStickyDepth->setEnabled(m_kxkbConfig.m_stickySwitching);
widget->spinStickyDepth->setValue( m_kxkbConfig.m_stickySwitchingDepth);
+ widget->chkEnableNotify->setChecked(m_kxkbConfig.m_enableNotify);
+ widget->chkNotifyUseKMilo->setChecked(m_kxkbConfig.m_notifyUseKMilo);
+
updateStickyLimit();
widget->chkEnable->setChecked( m_kxkbConfig.m_useKxkb );
@@ -397,6 +403,9 @@ void LayoutConfig::save()
m_kxkbConfig.m_stickySwitching = widget->chkEnableSticky->isChecked();
m_kxkbConfig.m_stickySwitchingDepth = widget->spinStickyDepth->value();
+ m_kxkbConfig.m_enableNotify = widget->chkEnableNotify->isChecked();
+ m_kxkbConfig.m_notifyUseKMilo = widget->chkNotifyUseKMilo->isChecked();
+
m_kxkbConfig.save();
// We might need to unset previous hotkey options
diff --git a/kxkb/kcmlayoutwidget.ui b/kxkb/kcmlayoutwidget.ui
index c35df0921..11d147211 100644
--- a/kxkb/kcmlayoutwidget.ui
+++ b/kxkb/kcmlayoutwidget.ui
@@ -611,6 +611,41 @@
</widget>
</grid>
</widget>
+ <widget class="TQGroupBox">
+ <property name="name">
+ <cstring>grpBoxNotifications</cstring>
+ </property>
+ <property name="title">
+ <string>Notifications</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQCheckBox">
+ <property name="name">
+ <cstring>chkEnableNotify</cstring>
+ </property>
+ <property name="text">
+ <string>Enable keyboard layout notification</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>If this option is enabled, a little notification will pop up on the screen displaying the name of the currently selected layout whenever it changes.</string>
+ </property>
+ </widget>
+ <widget class="TQCheckBox">
+ <property name="name">
+ <cstring>chkNotifyUseKMilo</cstring>
+ </property>
+ <property name="text">
+ <string>Use KMilo for notifications, if available</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>If this option is enabled and KMilo is available, it will be used to display the notifications instead of the standard notification system. If KMilo is not available, notifications will be showed via the standard TDE notification system.</string>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
</vbox>
</widget>
<spacer>
@@ -1193,6 +1228,12 @@
<receiver>labelBgColor</receiver>
<slot>setDisabled(bool)</slot>
</connection>
+ <connection>
+ <sender>chkEnableNotify</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>chkNotifyUseKMilo</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">kiconloader.h</include>
diff --git a/kxkb/kxkb.cpp b/kxkb/kxkb.cpp
index 1ecbd2470..f38263645 100644
--- a/kxkb/kxkb.cpp
+++ b/kxkb/kxkb.cpp
@@ -47,6 +47,9 @@ DESCRIPTION
#include <tdepopupmenu.h>
#include <kdebug.h>
#include <tdeconfig.h>
+#include <knotifyclient.h>
+#include <dcopclient.h>
+#include <dcopref.h>
#include "x11helper.h"
#include "kxkb.h"
@@ -205,9 +208,10 @@ bool KXKBApp::setLayout(const LayoutUnit& layoutUnit)
bool res = m_extension->setGroup(group);
if (res) {
m_currentLayout = layoutUnit;
+ maybeShowLayoutNotification();
}
- if (m_tray) {
+ if (m_tray) {
if (res) {
m_tray->setCurrentLayout(layoutUnit);
} else {
@@ -281,6 +285,44 @@ void KXKBApp::slotGroupChanged(uint group)
}
m_currentLayout = kxkbConfig.m_layouts[group];
m_tray->setCurrentLayout(m_currentLayout);
+ maybeShowLayoutNotification();
+}
+
+void KXKBApp::maybeShowLayoutNotification() {
+ if (!kxkbConfig.m_enableNotify) return;
+
+ TQString layoutName(m_rules->getLayoutName(m_currentLayout));
+ bool useKMilo = kxkbConfig.m_notifyUseKMilo;
+ bool notificationSent = false;
+
+ // Query KDED whether KMiloD is loaded
+ if (useKMilo) {
+ QCStringList modules;
+ TQCString replyType;
+ TQByteArray replyData;
+ if (kapp->dcopClient()->call("kded", "kded", "loadedModules()",
+ TQByteArray(), replyType, replyData))
+ {
+ if (replyType == "QCStringList") {
+ TQDataStream reply(replyData, IO_ReadOnly);
+ reply >> modules;
+
+ if (!modules.contains("kmilod")) {
+ useKMilo = false;
+ }
+ }
+ }
+ }
+
+ if (useKMilo) {
+ DCOPRef kmilo("kded", "kmilod");
+ if (kmilo.send("displayText(TQString,TQPixmap)", layoutName, kapp->miniIcon()))
+ notificationSent = true;
+ }
+
+ if (!notificationSent) {
+ KNotifyClient::event(m_tray->winId(), "LayoutChange", layoutName);
+ }
}
// TODO: we also have to handle deleted windows
diff --git a/kxkb/kxkb.h b/kxkb/kxkb.h
index 67e61ab56..ddde9a6c4 100644
--- a/kxkb/kxkb.h
+++ b/kxkb/kxkb.h
@@ -76,6 +76,7 @@ protected slots:
void slotGroupChanged(uint group);
void slotSettingsChanged(int category);
+ void maybeShowLayoutNotification();
protected:
// Read settings, and apply them.
diff --git a/kxkb/kxkbconfig.cpp b/kxkb/kxkbconfig.cpp
index 52ba6941b..0c3dc9e0a 100644
--- a/kxkb/kxkbconfig.cpp
+++ b/kxkb/kxkbconfig.cpp
@@ -129,6 +129,10 @@ bool KxkbConfig::load(int loadMode)
}
}
+ config->setGroup("Notifications");
+ m_enableNotify = config->readBoolEntry("Enable", false);
+ m_notifyUseKMilo = config->readBoolEntry("UseKMilo", true);
+
delete config;
return true;
@@ -196,6 +200,10 @@ void KxkbConfig::save()
config->deleteEntry("Additional");
config->deleteEntry("Layout");
+ config->setGroup("Notifications");
+ config->writeEntry("Enable", m_enableNotify);
+ config->writeEntry("UseKMilo", m_notifyUseKMilo);
+
config->sync();
delete config;
diff --git a/kxkb/kxkbconfig.h b/kxkb/kxkbconfig.h
index 4ec3634be..4e424102a 100644
--- a/kxkb/kxkbconfig.h
+++ b/kxkb/kxkbconfig.h
@@ -56,6 +56,8 @@ public:
SwitchingPolicy m_switchingPolicy;
bool m_stickySwitching;
int m_stickySwitchingDepth;
+ bool m_enableNotify;
+ bool m_notifyUseKMilo;
bool m_useThemeColors;
TQColor m_colorBackground;
diff --git a/kxkb/kxkbtraywindow.h b/kxkb/kxkbtraywindow.h
index 01529f0f3..46d66c44b 100644
--- a/kxkb/kxkbtraywindow.h
+++ b/kxkb/kxkbtraywindow.h
@@ -43,6 +43,8 @@ public:
void setError(const TQString& layoutInfo="");
void setShowFlag(bool showFlag) { m_showFlag = showFlag; }
void show() { label->show(); }
+
+ WId winId() { return label->winId(); }
// signals:
//
diff --git a/translations/desktop_files/kxkb-eventsrc/kxkb-eventsrc.pot b/translations/desktop_files/kxkb-eventsrc/kxkb-eventsrc.pot
new file mode 100644
index 000000000..c4fefe679
--- /dev/null
+++ b/translations/desktop_files/kxkb-eventsrc/kxkb-eventsrc.pot
@@ -0,0 +1,32 @@
+# SOME DESCRIPTIVE TITLE.
+# This file is put in the public domain.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2023-12-25 17:45+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Comment
+#: eventsrc:3
+msgid "TDE Keyboard Tool"
+msgstr ""
+
+#. Name
+#: eventsrc:6
+msgid "Keyboard layout switch"
+msgstr ""
+
+#. Comment
+#: eventsrc:7
+msgid "The keyboard layout was switched"
+msgstr ""