gi-notify-0.7.17: GI/Notify/Functions.hs
{- |
Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)
-}
#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
&& !defined(__HADDOCK_VERSION__))
module GI.Notify.Functions
(
-- * Methods
-- ** getAppName #method:getAppName#
getAppName ,
-- ** getServerCaps #method:getServerCaps#
getServerCaps ,
-- ** getServerInfo #method:getServerInfo#
getServerInfo ,
-- ** init #method:init#
init ,
-- ** isInitted #method:isInitted#
isInitted ,
-- ** setAppName #method:setAppName#
setAppName ,
-- ** uninit #method:uninit#
uninit ,
) where
import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P
import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
-- function notify_uninit
-- Args : []
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "notify_uninit" notify_uninit ::
IO ()
{- |
Uninitialized libnotify.
This should be called when the program no longer needs libnotify for
the rest of its lifecycle, typically just before exitting.
-}
uninit ::
(B.CallStack.HasCallStack, MonadIO m) =>
m ()
uninit = liftIO $ do
notify_uninit
return ()
-- function notify_set_app_name
-- Args : [Arg {argCName = "app_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The name of the application", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "notify_set_app_name" notify_set_app_name ::
CString -> -- app_name : TBasicType TUTF8
IO ()
{- |
Sets the application name.
-}
setAppName ::
(B.CallStack.HasCallStack, MonadIO m) =>
T.Text
{- ^ /@appName@/: The name of the application -}
-> m ()
setAppName appName = liftIO $ do
appName' <- textToCString appName
notify_set_app_name appName'
freeMem appName'
return ()
-- function notify_is_initted
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False
foreign import ccall "notify_is_initted" notify_is_initted ::
IO CInt
{- |
Gets whether or not libnotify is initialized.
-}
isInitted ::
(B.CallStack.HasCallStack, MonadIO m) =>
m Bool
{- ^ __Returns:__ 'True' if libnotify is initialized, or 'False' otherwise. -}
isInitted = liftIO $ do
result <- notify_is_initted
let result' = (/= 0) result
return result'
-- function notify_init
-- Args : [Arg {argCName = "app_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The name of the application initializing libnotify.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False
foreign import ccall "notify_init" notify_init ::
CString -> -- app_name : TBasicType TUTF8
IO CInt
{- |
Initialized libnotify. This must be called before any other functions.
-}
init ::
(B.CallStack.HasCallStack, MonadIO m) =>
T.Text
{- ^ /@appName@/: The name of the application initializing libnotify. -}
-> m Bool
{- ^ __Returns:__ 'True' if successful, or 'False' on error. -}
init appName = liftIO $ do
appName' <- textToCString appName
result <- notify_init appName'
let result' = (/= 0) result
freeMem appName'
return result'
-- function notify_get_server_info
-- Args : [Arg {argCName = "ret_name", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a location to store the server name, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "ret_vendor", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a location to store the server vendor, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "ret_version", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a location to store the server version, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "ret_spec_version", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a location to store the version the service is compliant with, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False
foreign import ccall "notify_get_server_info" notify_get_server_info ::
Ptr CString -> -- ret_name : TBasicType TUTF8
Ptr CString -> -- ret_vendor : TBasicType TUTF8
Ptr CString -> -- ret_version : TBasicType TUTF8
Ptr CString -> -- ret_spec_version : TBasicType TUTF8
IO CInt
{- |
Synchronously queries the server for its information, specifically, the name, vendor,
server version, and the version of the notifications specification that it
is compliant with.
-}
getServerInfo ::
(B.CallStack.HasCallStack, MonadIO m) =>
m ((Bool, T.Text, T.Text, T.Text, T.Text))
{- ^ __Returns:__ 'True' if successful, and the variables passed will be set, 'False'
on error. The returned strings must be freed with g_free -}
getServerInfo = liftIO $ do
retName <- allocMem :: IO (Ptr CString)
retVendor <- allocMem :: IO (Ptr CString)
retVersion <- allocMem :: IO (Ptr CString)
retSpecVersion <- allocMem :: IO (Ptr CString)
result <- notify_get_server_info retName retVendor retVersion retSpecVersion
let result' = (/= 0) result
retName' <- peek retName
retName'' <- cstringToText retName'
freeMem retName'
retVendor' <- peek retVendor
retVendor'' <- cstringToText retVendor'
freeMem retVendor'
retVersion' <- peek retVersion
retVersion'' <- cstringToText retVersion'
freeMem retVersion'
retSpecVersion' <- peek retSpecVersion
retSpecVersion'' <- cstringToText retSpecVersion'
freeMem retSpecVersion'
freeMem retName
freeMem retVendor
freeMem retVersion
freeMem retSpecVersion
return (result', retName'', retVendor'', retVersion'', retSpecVersion'')
-- function notify_get_server_caps
-- Args : []
-- Lengths : []
-- returnType : Just (TGList (TBasicType TUTF8))
-- throws : False
-- Skip return : False
foreign import ccall "notify_get_server_caps" notify_get_server_caps ::
IO (Ptr (GList CString))
{- |
Synchronously queries the server for its capabilities and returns them in a 'GI.GLib.Structs.List.List'.
-}
getServerCaps ::
(B.CallStack.HasCallStack, MonadIO m) =>
m [T.Text]
{- ^ __Returns:__ a 'GI.GLib.Structs.List.List' of server capability strings. Free
the list elements with 'GI.GLib.Functions.free' and the list itself with @/g_list_free()/@. -}
getServerCaps = liftIO $ do
result <- notify_get_server_caps
result' <- unpackGList result
result'' <- mapM cstringToText result'
mapGList freeMem result
g_list_free result
return result''
-- function notify_get_app_name
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False
foreign import ccall "notify_get_app_name" notify_get_app_name ::
IO CString
{- |
Gets the application name registered.
-}
getAppName ::
(B.CallStack.HasCallStack, MonadIO m) =>
m T.Text
{- ^ __Returns:__ The registered application name, passed to 'GI.Notify.Functions.init'. -}
getAppName = liftIO $ do
result <- notify_get_app_name
checkUnexpectedReturnNULL "getAppName" result
result' <- cstringToText result
return result'