Safe Haskell | None |
---|
A library for issuing notifications using FreeDesktop.org Desktop Notifications protocol. This protocol is used to communicate with services such as Ubuntu's NotifyOSD.
This library does not yet support receiving events relating to notifications, or images in notifications: if you need that functionality please contact the maintainer.
- notify :: Client -> Note -> IO Notification
- replace :: Client -> Notification -> Note -> IO Notification
- data Notification
- mkSessionClient :: IO Client
- connectSession :: IO Client
- data Client
- blankNote :: Note
- data Note = Note {}
- data Body
- type URL = String
- data Timeout
- = Never
- | Dependent
- | Milliseconds Int32
- newtype Action = Action {
- actionName :: String
- data Image
- data Category
- = Device
- | DeviceAdded
- | DeviceError
- | DeviceRemoved
- | EmailArrived
- | EmailBounced
- | Im
- | ImError
- | ImReceived
- | Network
- | NetworkConnected
- | NetworkDisconnected
- | NetworkError
- | Presence
- | PresenceOffline
- | PresenceOnline
- | Transfer
- | TransferComplete
- | TransferError
- data UrgencyLevel
- data Hint
- getCapabilities :: Client -> IO [Capability]
- data Capability
Usage
A DBUS Client
is needed to display notifications, so the first step is to
create one. The notification service will usually run on the session bus (the DBUS
instance responsible for messages within a desktop session) so you can use
sessionConnect
to create the client.
To display a notification, first construct a Note
. This can be done in pure
code. Notifications can have actions, categories, etc. associated to them but
we will just show a simple example (these features are not supported by all
notification services anyway).
Use the function notify
to display a Note
. This returns a handle which
can be passed to replace
to replace a notification.
import DBus.Notify main = do client <- sessionConnect let startNote = appNote { summary="Starting" , body=(Just $ Text "Calculating fib(33).") } notification <- notify client startNote let endNote = appNote { summary="Finished" , body=(Just . Text . show $ fib33) } fib33 `seq` replace client notification endNote where appNote = blankNote { appName="Fibonacci Demonstration" } fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) fib33 = fib 33
Displaying notifications
notify :: Client -> Note -> IO NotificationSource
Display a notification. Return a handle which can be used to replace the notification.
replace :: Client -> Notification -> Note -> IO NotificationSource
Replace an existing notification. If the notification has already been closed, a new one will be created.
data Notification Source
A handle on a displayed notification The notification may not have reached the screen yet, and may already have been closed.
mkSessionClient :: IO ClientSource
Deprecated: Use DBus.Client.connectSession
Connect to the bus specified in the environment variable
DBUS_SESSION_BUS_ADDRESS
, which must be set.
Throws a ClientError
if DBUS_SESSION_BUS_ADDRESS
is unset, contains an
invalid address, or if connecting to the bus failed.
data Client
An active client session to a message bus. Clients may send or receive method calls, and listen for or emit signals.
Constructing notifications
Contents of a notification
Message bodies may contain simple markup. NotifyOSD doesn't support any markup.
Length of time to display notifications. NotifyOSD seems to ignore these.
Never | Wait to be dismissed by user |
Dependent | Let the notification service decide |
Milliseconds Int32 | Show notification for a fixed duration (must be positive) |
Categorisation of (some) notifications
data UrgencyLevel Source
Urgency of the notification. Notifications may be prioritised by urgency.
Various hints about how the notification should be displayed
Capabilities
getCapabilities :: Client -> IO [Capability]Source
Determine the server's capabilities