{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

'GI.Gio.Objects.MenuAttributeIter.MenuAttributeIter' is an opaque structure type.  You must access it
using the functions below.
-}

module GI.Gio.Objects.MenuAttributeIter
    ( 

-- * Exported types
    MenuAttributeIter(..)                   ,
    IsMenuAttributeIter                     ,
    toMenuAttributeIter                     ,
    noMenuAttributeIter                     ,


 -- * Methods
-- ** getName #method:getName#
    MenuAttributeIterGetNameMethodInfo      ,
    menuAttributeIterGetName                ,


-- ** getNext #method:getNext#
    MenuAttributeIterGetNextMethodInfo      ,
    menuAttributeIterGetNext                ,


-- ** getValue #method:getValue#
    MenuAttributeIterGetValueMethodInfo     ,
    menuAttributeIterGetValue               ,


-- ** next #method:next#
    MenuAttributeIterNextMethodInfo         ,
    menuAttributeIterNext                   ,




    ) 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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 GI.GObject.Objects.Object as GObject.Object

newtype MenuAttributeIter = MenuAttributeIter (ManagedPtr MenuAttributeIter)
foreign import ccall "g_menu_attribute_iter_get_type"
    c_g_menu_attribute_iter_get_type :: IO GType

instance GObject MenuAttributeIter where
    gobjectType _ = c_g_menu_attribute_iter_get_type
    

class GObject o => IsMenuAttributeIter o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError MenuAttributeIter a) =>
    IsMenuAttributeIter a
#endif
instance IsMenuAttributeIter MenuAttributeIter
instance GObject.Object.IsObject MenuAttributeIter

toMenuAttributeIter :: IsMenuAttributeIter o => o -> IO MenuAttributeIter
toMenuAttributeIter = unsafeCastTo MenuAttributeIter

noMenuAttributeIter :: Maybe MenuAttributeIter
noMenuAttributeIter = Nothing

type family ResolveMenuAttributeIterMethod (t :: Symbol) (o :: *) :: * where
    ResolveMenuAttributeIterMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveMenuAttributeIterMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveMenuAttributeIterMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveMenuAttributeIterMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveMenuAttributeIterMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveMenuAttributeIterMethod "next" o = MenuAttributeIterNextMethodInfo
    ResolveMenuAttributeIterMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveMenuAttributeIterMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveMenuAttributeIterMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveMenuAttributeIterMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveMenuAttributeIterMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveMenuAttributeIterMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveMenuAttributeIterMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveMenuAttributeIterMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveMenuAttributeIterMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveMenuAttributeIterMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveMenuAttributeIterMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveMenuAttributeIterMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveMenuAttributeIterMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveMenuAttributeIterMethod "getName" o = MenuAttributeIterGetNameMethodInfo
    ResolveMenuAttributeIterMethod "getNext" o = MenuAttributeIterGetNextMethodInfo
    ResolveMenuAttributeIterMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveMenuAttributeIterMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveMenuAttributeIterMethod "getValue" o = MenuAttributeIterGetValueMethodInfo
    ResolveMenuAttributeIterMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveMenuAttributeIterMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveMenuAttributeIterMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveMenuAttributeIterMethod t MenuAttributeIter, O.MethodInfo info MenuAttributeIter p) => O.IsLabelProxy t (MenuAttributeIter -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveMenuAttributeIterMethod t MenuAttributeIter, O.MethodInfo info MenuAttributeIter p) => O.IsLabel t (MenuAttributeIter -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

instance O.HasAttributeList MenuAttributeIter
type instance O.AttributeList MenuAttributeIter = MenuAttributeIterAttributeList
type MenuAttributeIterAttributeList = ('[ ] :: [(Symbol, *)])

type instance O.SignalList MenuAttributeIter = MenuAttributeIterSignalList
type MenuAttributeIterSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method MenuAttributeIter::get_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "Gio", name = "MenuAttributeIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GMenuAttributeIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "g_menu_attribute_iter_get_name" g_menu_attribute_iter_get_name :: 
    Ptr MenuAttributeIter ->                -- iter : TInterface (Name {namespace = "Gio", name = "MenuAttributeIter"})
    IO CString

{- |
Gets the name of the attribute at the current iterator position, as
a string.

The iterator is not advanced.

@since 2.32
-}
menuAttributeIterGetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsMenuAttributeIter a) =>
    a
    {- ^ /@iter@/: a 'GI.Gio.Objects.MenuAttributeIter.MenuAttributeIter' -}
    -> m T.Text
    {- ^ __Returns:__ the name of the attribute -}
menuAttributeIterGetName iter = liftIO $ do
    iter' <- unsafeManagedPtrCastPtr iter
    result <- g_menu_attribute_iter_get_name iter'
    checkUnexpectedReturnNULL "menuAttributeIterGetName" result
    result' <- cstringToText result
    touchManagedPtr iter
    return result'

data MenuAttributeIterGetNameMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsMenuAttributeIter a) => O.MethodInfo MenuAttributeIterGetNameMethodInfo a signature where
    overloadedMethod _ = menuAttributeIterGetName

-- method MenuAttributeIter::get_next
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "Gio", name = "MenuAttributeIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GMenuAttributeIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "out_name", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the type of the attribute", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TVariant, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the attribute value", 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 "g_menu_attribute_iter_get_next" g_menu_attribute_iter_get_next :: 
    Ptr MenuAttributeIter ->                -- iter : TInterface (Name {namespace = "Gio", name = "MenuAttributeIter"})
    Ptr CString ->                          -- out_name : TBasicType TUTF8
    Ptr (Ptr GVariant) ->                   -- value : TVariant
    IO CInt

{- |
This function combines 'GI.Gio.Objects.MenuAttributeIter.menuAttributeIterNext' with
'GI.Gio.Objects.MenuAttributeIter.menuAttributeIterGetName' and 'GI.Gio.Objects.MenuAttributeIter.menuAttributeIterGetValue'.

First the iterator is advanced to the next (possibly first) attribute.
If that fails, then 'False' is returned and there are no other
effects.

If successful, /@name@/ and /@value@/ are set to the name and value of the
attribute that has just been advanced to.  At this point,
'GI.Gio.Objects.MenuAttributeIter.menuAttributeIterGetName' and 'GI.Gio.Objects.MenuAttributeIter.menuAttributeIterGetValue' will
return the same values again.

The value returned in /@name@/ remains valid for as long as the iterator
remains at the current position.  The value returned in /@value@/ must
be unreffed using 'GI.GLib.Structs.Variant.variantUnref' when it is no longer in use.

@since 2.32
-}
menuAttributeIterGetNext ::
    (B.CallStack.HasCallStack, MonadIO m, IsMenuAttributeIter a) =>
    a
    {- ^ /@iter@/: a 'GI.Gio.Objects.MenuAttributeIter.MenuAttributeIter' -}
    -> m (Bool,T.Text,GVariant)
    {- ^ __Returns:__ 'True' on success, or 'False' if there is no additional
    attribute -}
menuAttributeIterGetNext iter = liftIO $ do
    iter' <- unsafeManagedPtrCastPtr iter
    outName <- allocMem :: IO (Ptr CString)
    value <- allocMem :: IO (Ptr (Ptr GVariant))
    result <- g_menu_attribute_iter_get_next iter' outName value
    let result' = (/= 0) result
    outName' <- peek outName
    outName'' <- cstringToText outName'
    value' <- peek value
    value'' <- wrapGVariantPtr value'
    touchManagedPtr iter
    freeMem outName
    freeMem value
    return (result', outName'', value'')

data MenuAttributeIterGetNextMethodInfo
instance (signature ~ (m (Bool,T.Text,GVariant)), MonadIO m, IsMenuAttributeIter a) => O.MethodInfo MenuAttributeIterGetNextMethodInfo a signature where
    overloadedMethod _ = menuAttributeIterGetNext

-- method MenuAttributeIter::get_value
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "Gio", name = "MenuAttributeIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GMenuAttributeIter", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just TVariant
-- throws : False
-- Skip return : False

foreign import ccall "g_menu_attribute_iter_get_value" g_menu_attribute_iter_get_value :: 
    Ptr MenuAttributeIter ->                -- iter : TInterface (Name {namespace = "Gio", name = "MenuAttributeIter"})
    IO (Ptr GVariant)

{- |
Gets the value of the attribute at the current iterator position.

The iterator is not advanced.

@since 2.32
-}
menuAttributeIterGetValue ::
    (B.CallStack.HasCallStack, MonadIO m, IsMenuAttributeIter a) =>
    a
    {- ^ /@iter@/: a 'GI.Gio.Objects.MenuAttributeIter.MenuAttributeIter' -}
    -> m GVariant
    {- ^ __Returns:__ the value of the current attribute -}
menuAttributeIterGetValue iter = liftIO $ do
    iter' <- unsafeManagedPtrCastPtr iter
    result <- g_menu_attribute_iter_get_value iter'
    checkUnexpectedReturnNULL "menuAttributeIterGetValue" result
    result' <- wrapGVariantPtr result
    touchManagedPtr iter
    return result'

data MenuAttributeIterGetValueMethodInfo
instance (signature ~ (m GVariant), MonadIO m, IsMenuAttributeIter a) => O.MethodInfo MenuAttributeIterGetValueMethodInfo a signature where
    overloadedMethod _ = menuAttributeIterGetValue

-- method MenuAttributeIter::next
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "Gio", name = "MenuAttributeIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GMenuAttributeIter", 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 "g_menu_attribute_iter_next" g_menu_attribute_iter_next :: 
    Ptr MenuAttributeIter ->                -- iter : TInterface (Name {namespace = "Gio", name = "MenuAttributeIter"})
    IO CInt

{- |
Attempts to advance the iterator to the next (possibly first)
attribute.

'True' is returned on success, or 'False' if there are no more
attributes.

You must call this function when you first acquire the iterator
to advance it to the first attribute (and determine if the first
attribute exists at all).

@since 2.32
-}
menuAttributeIterNext ::
    (B.CallStack.HasCallStack, MonadIO m, IsMenuAttributeIter a) =>
    a
    {- ^ /@iter@/: a 'GI.Gio.Objects.MenuAttributeIter.MenuAttributeIter' -}
    -> m Bool
    {- ^ __Returns:__ 'True' on success, or 'False' when there are no more attributes -}
menuAttributeIterNext iter = liftIO $ do
    iter' <- unsafeManagedPtrCastPtr iter
    result <- g_menu_attribute_iter_next iter'
    let result' = (/= 0) result
    touchManagedPtr iter
    return result'

data MenuAttributeIterNextMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsMenuAttributeIter a) => O.MethodInfo MenuAttributeIterNextMethodInfo a signature where
    overloadedMethod _ = menuAttributeIterNext