fdo-notify 0.2 → 0.3
raw patch · 3 files changed
+29/−28 lines, 3 filesdep +containersdep +dbusdep −dbus-clientdep −dbus-core
Dependencies added: containers, dbus
Dependencies removed: dbus-client, dbus-core
Files
- DBus/Notify.hs +25/−24
- examples/fib.hs +1/−1
- fdo-notify.cabal +3/−3
DBus/Notify.hs view
@@ -15,6 +15,7 @@ , replace , Notification , mkSessionClient+ , connectSession , Client -- * Constructing notifications , blankNote@@ -32,22 +33,21 @@ , Capability (..) ) where -import DBus.Message+import DBus import DBus.Client-import DBus.Bus-import DBus.Types import Control.Applicative import Data.Maybe (fromMaybe, fromJust) import Data.Int import Data.Word import Data.Char (isLower, toLower) import Control.Arrow (first, second, (***))+import qualified Data.Map as M -- $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--- 'mkSessionClient' to create the client.+-- '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@@ -61,7 +61,7 @@ --import DBus.Notify -- --main = do--- client <- mkSessionClient+-- client <- sessionConnect -- let startNote = appNote { summary=\"Starting\" -- , body=(Just $ Text \"Calculating fib(33).\") } -- notification <- notify client startNote@@ -76,11 +76,9 @@ -- fib33 = fib 33 -- @ --- |Create a 'Client' connected to the session bus.--- Note that this opens a socket and spawns a thread,--- so it's best to reuse a single client.+{-# DEPRECATED mkSessionClient "Use DBus.Client.connectSession" #-} mkSessionClient :: IO Client-mkSessionClient = mkClient =<< getSessionBus+mkSessionClient = connectSession -- |A 'Note' with default values. -- All fields are blank except for 'expiry', which is 'Dependent'.@@ -94,12 +92,6 @@ , expiry=Dependent } -proxy = Proxy (RemoteObject busname path) iface- where- busname = "org.freedesktop.Notifications"- path = "/org/freedesktop/Notifications"- iface = "org.freedesktop.Notifications"- -- |Contents of a notification data Note = Note { appName :: String , appImage :: Maybe Image@@ -177,12 +169,22 @@ notify :: Client -> Note -> IO Notification notify cl = replace cl (Notification { notificationId=0 }) +callNotificationMethod client methodName args =+ call_ client $ (methodCall path iface methodName)+ { methodCallDestination=Just busname+ , methodCallBody=args+ }+ where+ busname = "org.freedesktop.Notifications"+ path = "/org/freedesktop/Notifications"+ iface = "org.freedesktop.Notifications"+ -- |Replace an existing notification. -- If the notification has already been closed, a new one will be created. replace :: Client -> Notification -> Note -> IO Notification replace cl (Notification { notificationId=replaceId }) note = Notification . fromJust . fromVariant . head . methodReturnBody <$>- callProxyBlocking_ cl proxy "Notify" [] args+ callNotificationMethod cl "Notify" args where args = map ($ note) [ toVariant . appName@@ -202,9 +204,9 @@ -- |Determine the server's capabilities getCapabilities :: Client -> IO [Capability]-getCapabilities cl = map readCapability . fromJust . fromArray . fromJust+getCapabilities cl = map readCapability . fromJust . fromVariant . head . methodReturnBody- <$> callProxyBlocking_ cl proxy "GetCapabilities" [] []+ <$> callNotificationMethod cl "GetCapabilities" [] readCapability :: String -> Capability readCapability s = case s of@@ -239,14 +241,13 @@ flattenBody (Img h alt) = "<img src=\"" ++ h ++ "\" alt=\"" ++ alt ++ "\"/>" flattenBody (Concat b1 b2) = flattenBody b1 ++ flattenBody b2 -actionsArray :: [(Action, String)] -> Array-actionsArray = fromJust . arrayFromItems DBusString . concatMap pairList+--actionsArray :: [(Action, String)] -> [[String]]+actionsArray = concatMap pairList where- pairList (a, b) = [toVariant $ actionName a, toVariant $ b]+ pairList (a, b) = [actionName a, b] -hintsDict :: [Hint] -> Dictionary-hintsDict = fromJust . dictionaryFromItems DBusString DBusVariant- . map ((toVariant *** toVariant) . hint)+hintsDict :: [Hint] -> M.Map String Variant+hintsDict = M.fromList . map hint where hint :: Hint -> (String, Variant) hint (Urgency u) = ("urgency", toVariant (fromIntegral $ fromEnum u :: Word8))
examples/fib.hs view
@@ -1,7 +1,7 @@ import DBus.Notify main = do- client <- mkSessionClient+ client <- connectSession let startNote = appNote { summary="Starting" , body=(Just $ Text "Calculating fib(33).") } notification <- notify client startNote
fdo-notify.cabal view
@@ -1,5 +1,5 @@ name: fdo-notify-version: 0.2+version: 0.3 synopsis: Desktop Notifications client description: A library for issuing notifications using FreeDesktop.org's Desktop@@ -20,7 +20,7 @@ library build-depends: base >= 3 && < 5- , dbus-client >= 0.3 && < 0.4- , dbus-core >= 0.8 && < 0.9+ , containers >= 0.1+ , dbus >= 0.10.7 exposed-modules: DBus.Notify