KNotify Plugins (Or, “What I’ve been working on, now with details”)

I didn’t say much in my last post because I was still working things out.  Now I’m pleased to say that support for notification plugins has hit KNotify in KDE trunk as of last week.  The whole thing started when I was talking with some friends about an idea I’d been tossing around to forward notifications from my laptop/desktop to my N900 over the LAN, so that I wouldn’t miss important events when away frm the keyboard.  Aaron Seigo pointed out that the behaviour I wanted could be done nicely with KNotify, but that it currently required notification actions to be compiled in.  With a lot of help from him and others, I got going, and managed to get it done before the freeze.  I still have done no work towards my original idea, but I had some realizations while working on the code.  For one thing, notifications on the G15 keyboard’s auxiliary LCD are darn cool. :)  For another, it occurred to me that as KDE technologies move to the mobile world, and other non-traditional form-factors, there will be devices with blinky lights (OHAI, N900) , vibration motors, and who knows what other hardware that someone might want to utilize for notifications.  Now a vendor or developer can write a simple plugin and ship it for a specific device or use-case.

However… there is a caveat, and that is that there is currently no UI support for the extra plugins.  This means that for now you will have to enable plugins for each event individually by mucking around in configuration files.  I’ll be working on resolving this for 4.7.

If anyone wants to try writing plugins, it’s quite straightforward.  Start by taking a look at the example code here.

The important bits:

  • Derive from KNotifyPlugin, and link to libknotifyplugin
  • Implement the pure virtual KNotifyPlugin::optionName() method, and set it to return an identifying name for your plugin.  This is what will go in the “Action=” field in the config files
  • Implement KNotifyPlugin::notify(), and do whatever the heck you want to – it’s that simple.  If you want to make a robotic bunny jump up and down every time you receive an e-mail, do so – and send me a picture.
  • Make sure to include the macro at the bottom: e.g. K_EXPORT_KNOTIFY_METHOD(g15message, NotifyByG15Message), where “g15message” is the library name, and “NotifyByG15Message” is your plugin class name.
  • Once your plugin is installed, edit any fooapprc.notifyrc file in $kdeprefix/share/config, and add the name (as mentioned above) to the “Action=” field, optionally using |’s to separate multiple actions.

Comments appreciated, especially if you write any plugins.  Code is also appreciated at the Gitorious link above; the G15 plugin is rather rudimentary right now, for example, and could use some love.


P.S. If you like this, there’s a very lonely Flattr button sitting in the sidebar. *wink*


  1. #1 by Markus on November 15, 2010 - 12:55 pm

    I’m not entirely sure what this means. Does this mean that by 4.7 we’ll have an KCM to select (for example) plain KNotify, Plasma’s default notifications, Colibri, some networked notification system, etc.?

    • #2 by Jeffery MacEachern on November 15, 2010 - 9:58 pm

      Hmm… maybe I was unclear. KNotify itself delegates to various actions already, such as popups (which could be Plasma notifications /or/ Colibri), sounds, and several other actions. What this does is just add the possibility of more actions. So an application will fire off a notification to KNotify, and KNotify can have more options of what to do with it. So if you wanted to forward it over a network link, or SMS, or whatever, you could do that, but it wouldn’t replace anything; rather, it would just be another checkbox in the existing KCM.

  2. #3 by Shafqat Bhuiyan on November 15, 2010 - 10:31 pm

    Nice work. Opens up a lot of possibilities. Someone can set it up so that notifications are uploaded to a website so that anyone can check from anywhere what’s going on.

    I was wondering that maybe you could use this to set up a triggering system. Like if a file finishes downloading then halt the computer. I’m not sure if something like this doesn’t already exists though.

  3. #4 by Alex on November 16, 2010 - 12:11 am

    Would love having notifications for my G15!

    • #5 by Jeffery MacEachern on November 16, 2010 - 5:00 am

      Well, the code in the Gitorious repo[0] already works, more or less. The main issues right now are just timing and modality, so that, for example, transient notifications don’t get missed because of one waiting for dismissal by an OK button. Also, I’d ideally like to add proper button support so that apps like Kopete (“Chat” button) can work better. To use this code, you’ll need a recent trunk build of kdebase/runtime, a functioning G15Daemon setup, and the program “g15message”, which is somewhere out there on the Internets.

  4. #6 by Pedro Alves on November 16, 2010 - 10:31 am

    It’d be super if one could write the notification plugin as a script, rather than compiled code. Is that already possible?

    • #7 by Jeffery MacEachern on November 16, 2010 - 11:25 am

      I can certainly see the appeal, especially since it would enable the usage of GHNS, however, I’m frankly not sure that there are enough use-cases to warrant the added complexity. It may turn out to be less complex than I think, though, so I’ll keep it in mind.
      Oh, and keep in mind that you can already execute scripts with the “Run a command” action.

  5. #8 by Govi on November 18, 2010 - 1:00 am

    Thanks for great feature. I’ve got a question. Is possible with KNotify and KNotify plugins to detect the end of notified event? I mean e.g. flashing diode on new IM message until is read.

    • #9 by Jeffery MacEachern on November 18, 2010 - 2:36 am

      Yep. The slot you’d be looking for is KNotification::close(). The program showing the notification would need to call that when some condition is met, such as the user focussing an IM window containing the new message. In fact, I believe Kopete already does this.

  6. #10 by BajK on January 20, 2011 - 8:54 pm

    I had a look at your G15 example and I do not know much about coding but there is a script called by the plugin that then eventually sends your data to your g15? Is it possible to send notifications using USB/Serial to an Arduino ( if you don‘t know what it is) so that I can display notifications there in a similar way? An answer or suggestions would really be appreciated. Thanks :)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: