-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

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.BasicTypes as B.Types
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
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 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 :: m ()
uninit  = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    IO ()
notify_uninit
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- function 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 :: Text -> m ()
setAppName Text
appName = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    CString
appName' <- Text -> IO CString
textToCString Text
appName
    CString -> IO ()
notify_set_app_name CString
appName'
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
appName'
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- function 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:__ 'P.True' if libnotify is initialized, or 'P.False' otherwise.
isInitted :: m Bool
isInitted  = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    CInt
result <- IO CInt
notify_is_initted
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'


-- function 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:__ 'P.True' if successful, or 'P.False' on error.
init :: Text -> m Bool
init Text
appName = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    CString
appName' <- Text -> IO CString
textToCString Text
appName
    CInt
result <- CString -> IO CInt
notify_init CString
appName'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
appName'
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'


-- function 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:__ 'P.True' if successful, and the variables passed will be set, 'P.False'
    --          on error. The returned strings must be freed with g_free
getServerInfo :: m (Bool, Text, Text, Text, Text)
getServerInfo  = IO (Bool, Text, Text, Text, Text)
-> m (Bool, Text, Text, Text, Text)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Bool, Text, Text, Text, Text)
 -> m (Bool, Text, Text, Text, Text))
-> IO (Bool, Text, Text, Text, Text)
-> m (Bool, Text, Text, Text, Text)
forall a b. (a -> b) -> a -> b
$ do
    Ptr CString
retName <- IO (Ptr CString)
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr CString)
    Ptr CString
retVendor <- IO (Ptr CString)
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr CString)
    Ptr CString
retVersion <- IO (Ptr CString)
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr CString)
    Ptr CString
retSpecVersion <- IO (Ptr CString)
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr CString)
    CInt
result <- Ptr CString -> Ptr CString -> Ptr CString -> Ptr CString -> IO CInt
notify_get_server_info Ptr CString
retName Ptr CString
retVendor Ptr CString
retVersion Ptr CString
retSpecVersion
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    CString
retName' <- Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek Ptr CString
retName
    Text
retName'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
retName'
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
retName'
    CString
retVendor' <- Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek Ptr CString
retVendor
    Text
retVendor'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
retVendor'
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
retVendor'
    CString
retVersion' <- Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek Ptr CString
retVersion
    Text
retVersion'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
retVersion'
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
retVersion'
    CString
retSpecVersion' <- Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek Ptr CString
retSpecVersion
    Text
retSpecVersion'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
retSpecVersion'
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
retSpecVersion'
    Ptr CString -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CString
retName
    Ptr CString -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CString
retVendor
    Ptr CString -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CString
retVersion
    Ptr CString -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CString
retSpecVersion
    (Bool, Text, Text, Text, Text) -> IO (Bool, Text, Text, Text, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
result', Text
retName'', Text
retVendor'', Text
retVersion'', Text
retSpecVersion'')


-- function 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 t'GI.GLib.Structs.List.List'.
getServerCaps ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m [T.Text]
    -- ^ __Returns:__ a t'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 :: m [Text]
getServerCaps  = IO [Text] -> m [Text]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Text] -> m [Text]) -> IO [Text] -> m [Text]
forall a b. (a -> b) -> a -> b
$ do
    Ptr (GList CString)
result <- IO (Ptr (GList CString))
notify_get_server_caps
    [CString]
result' <- Ptr (GList CString) -> IO [CString]
forall a. Ptr (GList (Ptr a)) -> IO [Ptr a]
unpackGList Ptr (GList CString)
result
    [Text]
result'' <- (CString -> IO Text) -> [CString] -> IO [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText [CString]
result'
    (CString -> IO ()) -> Ptr (GList CString) -> IO ()
forall a b. (Ptr a -> IO b) -> Ptr (GList (Ptr a)) -> IO ()
mapGList CString -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr (GList CString)
result
    Ptr (GList CString) -> IO ()
forall a. Ptr (GList a) -> IO ()
g_list_free Ptr (GList CString)
result
    [Text] -> IO [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return [Text]
result''


-- function 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 :: m Text
getAppName  = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    CString
result <- IO CString
notify_get_app_name
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"getAppName" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'