Commits

Anonymous committed c60ac6f

Depend on dbus instead of deprecated dbus-client

Comments (0)

Files changed (3)

     , replace
     , Notification
     , mkSessionClient
+    , connectSession
     , Client
     -- * Constructing notifications
     , blankNote
     , 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
 --import DBus.Notify
 --
 --main = do
---         client <- mkSessionClient
+--         client <- sessionConnect
 --         let startNote = appNote { summary=\"Starting\"
 --                                 , body=(Just $ Text \"Calculating fib(33).\") }
 --         notification <- notify client startNote
 --         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'.
                    , 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
 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
 
 -- |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
 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))
 import DBus.Notify
 
 main = do
-         client <- mkSessionClient
+         client <- connectSession
          let startNote = appNote { summary="Starting"
                                  , body=(Just $ Text "Calculating fib(33).") }
          notification <- notify client startNote
 name:               fdo-notify
-version:            0.2
+version:            0.3
 synopsis:           Desktop Notifications client
 description:
     A library for issuing notifications using FreeDesktop.org's Desktop
 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