Filtering Kopete notifications
Submitted by blizzzThe scenario is: you have (on a KDE 4.2 desktop) a panel with fading out enabled. You use Kopete for instant messaging, but don't want sound notifications for incoming messages. Also you don't want popups when the chat window is actually focused.
The solution (at least for me) is: a little python script, some dbus magic and use of kdialog. You set up a notification on incoming messages and type your script in the "run command" text input field. Note that you have to give the path in apostrophe`s, else it will fail. The script does following:
- Check wether the chat window is active
- If so, do nothing; if not, trigger a popup via kdialog
And the code looks like this:
#!/usr/bin/python # -*- coding: utf-8 -*- from dbus.mainloop.qt import DBusQtMainLoop from dbus import SessionBus from os import system if __name__ == "__main__": dbus_loop = DBusQtMainLoop() dbus_session_bus = SessionBus(mainloop=dbus_loop) dbus_kopete = dbus_session_bus.get_object('org.kde.kopete', '/kopete/MainWindow_2') try: isActive = dbus_kopete.Get('com.trolltech.Qt.QWidget', 'isActiveWindow') if (isActive == 0): raise StandardError('Window closed') except: command = 'kdialog --passivepopup "New message in Kopete" 2 ' +\ '--title "IM Message"' system(command)
This works only when you have all chats in a single window (Kopete setting), presumably. It still is not perfect as you don't know who sent you a message and you cannot raise or show the chat window, as an original Kopete popup offers you to do.
The number "2" in the kdialog command defines the time in seconds until the popup vanishes. You can leave it out for a standard value or pass any other value.
You can download the script here.
Add new comment