module Libnotify
(
Notification
, display
, display_
, close
, Mod
, summary
, body
, icon
, timeout
, Timeout(..)
, category
, urgency
, Urgency(..)
, image
, Hint(..)
, nohints
, action
, noactions
, reuse
, Monoid(..), (<>)
) where
import Control.Applicative ((<$))
import Data.ByteString (ByteString)
import Data.Int (Int32)
import Data.Monoid (Monoid(..), (<>), Last(..))
import Data.Word (Word8)
import Graphics.UI.Gtk.Gdk.Pixbuf (Pixbuf)
import System.Glib.Properties (objectSetPropertyString)
import Libnotify.C.Notify
import Libnotify.C.NotifyNotification
newtype Notification = Notification
{ unNotification :: NotifyNotification
} deriving (Show, Eq)
display :: Mod Notification -> IO Notification
display (Mod m a) = do
notify_init "haskell-libnotify"
n <- maybe (notify_notification_new "" "" "") (return . unNotification) (getLast m)
let y = Notification n
a y
notify_notification_show n
return y
display_ :: Mod Notification -> IO ()
display_ m = () <$ display m
close :: Notification -> IO ()
close n = () <$ do
notify_init "haskell-libnotify"
notify_notification_close (unNotification n)
data Mod a = Mod (Last a) (a -> IO ())
instance Monoid (Mod a) where
mempty = Mod mempty (\_ -> return ())
mappend = (<>)
summary :: String -> Mod Notification
summary t = act (\n -> objectSetPropertyString "summary" n t)
body :: String -> Mod Notification
body t = act (\n -> objectSetPropertyString "body" n t)
icon :: String -> Mod Notification
icon t = act (\n -> objectSetPropertyString "icon-name" n t)
timeout :: Timeout -> Mod Notification
timeout t = act (\n -> notify_notification_set_timeout n t)
category :: String -> Mod Notification
category t = act (\n -> notify_notification_set_category n t)
urgency :: Urgency -> Mod Notification
urgency t = act (\n -> notify_notification_set_urgency n t)
image :: Pixbuf -> Mod Notification
image t = act (\n -> notify_notification_set_image_from_pixbuf n t)
class Hint v where
hint :: String -> v -> Mod Notification
instance Hint Int32 where
hint k v = act (\n -> notify_notification_set_hint_int32 n k v)
instance Hint Double where
hint k v = act (\n -> notify_notification_set_hint_double n k v)
instance Hint String where
hint k v = act (\n -> notify_notification_set_hint_string n k v)
instance Hint Word8 where
hint k v = act (\n -> notify_notification_set_hint_byte n k v)
instance Hint ByteString where
hint k v = act (\n -> notify_notification_set_hint_byte_array n k v)
nohints :: Mod Notification
nohints = act notify_notification_clear_hints
action
:: String
-> String
-> (Notification -> String -> IO a)
-> Mod Notification
action a l f =
Mod mempty (\n -> notify_notification_add_action (unNotification n) a l
(\p s' -> () <$ f (Notification p) s'))
noactions :: Mod Notification
noactions = act notify_notification_clear_actions
reuse :: Notification -> Mod Notification
reuse n = Mod (Last (Just n)) (\_ -> return ())
act :: (NotifyNotification -> IO ()) -> Mod Notification
act f = Mod mempty (f . unNotification)