6.6. User Notifications

KNotifyClient is the class for notifying the user when something special happened.

For example, if you are writing a KDE version of wget, the popular GNU utility to grab files off the Web, you would do this:

   2 #include <knotifyclient.h>
   3 […]
   4 KNotifyClient::event("done getting",i18n("The file is downloaded!"));
   5 […]

And with your program, you would install a file named eventsrc to $KDEDATADIR/APP/eventsrc ($KDEDIR/share/apps/APPNAME/eventsrc). Continuing with our example, you would use the following eventsrc:

   2 [!Global!]
   3 Name=kwget
   4 Comment=KDE Web-Get
   6 [done getting]
   7 Name=Download Completion
   8 Name[fr]=Completion de Telechargement
   9 Comment=Download of File is Complete
  10 Comment=Telechargement de Lime est Complete
  11 default_sound=downloaddone.wav
  12 default_presentation=1
  13 nopresentation=0
  14 level=1

The presentation and nopresentation fields are produced by adding:

   2 None=0, Sound=1, Messagebox=2, Logfile=4, Stderr=8

nopresentation was originally created to prevent an infinite recursion situation with KWin calling KNotify, which opens a window, for which KWin calls KNotify. You should have very little need for it.

And the level field is produced by adding:

   2 None=0, Notification=1, Warning=2, Error=4, Catastrophe=8

Logfile uses the key default_file, in the same format as default_sound.

Several systemwide handlers also exist, all defined in your own $KDEDIR/share/config directory: cannotopenfile, notification, warning, fatalerror, and catastrophe. A more complete list is availible in: KDEDIR/share/config/eventsrc

These can be called with

   2 KNotifyClient::event("fatalerror", i18n("An internal error occurred,
   3 opened files have been backed up, and this program will now quit");