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

module GI.Gio.Objects.MenuModel
    ( 

-- * Exported types
    MenuModel(..)                           ,
    MenuModelK                              ,
    toMenuModel                             ,
    noMenuModel                             ,


 -- * Methods
-- ** menuModelGetItemAttributeValue
    menuModelGetItemAttributeValue          ,


-- ** menuModelGetItemLink
    menuModelGetItemLink                    ,


-- ** menuModelGetNItems
    menuModelGetNItems                      ,


-- ** menuModelIsMutable
    menuModelIsMutable                      ,


-- ** menuModelItemsChanged
    menuModelItemsChanged                   ,


-- ** menuModelIterateItemAttributes
    menuModelIterateItemAttributes          ,


-- ** menuModelIterateItemLinks
    menuModelIterateItemLinks               ,




 -- * Signals
-- ** ItemsChanged
    MenuModelItemsChangedCallback           ,
    MenuModelItemsChangedCallbackC          ,
    MenuModelItemsChangedSignalInfo         ,
    afterMenuModelItemsChanged              ,
    menuModelItemsChangedCallbackWrapper    ,
    menuModelItemsChangedClosure            ,
    mkMenuModelItemsChangedCallback         ,
    noMenuModelItemsChangedCallback         ,
    onMenuModelItemsChanged                 ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Gio.Types
import GI.Gio.Callbacks
import qualified GI.GLib as GLib
import qualified GI.GObject as GObject

newtype MenuModel = MenuModel (ForeignPtr MenuModel)
foreign import ccall "g_menu_model_get_type"
    c_g_menu_model_get_type :: IO GType

type instance ParentTypes MenuModel = MenuModelParentTypes
type MenuModelParentTypes = '[GObject.Object]

instance GObject MenuModel where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_menu_model_get_type
    

class GObject o => MenuModelK o
instance (GObject o, IsDescendantOf MenuModel o) => MenuModelK o

toMenuModel :: MenuModelK o => o -> IO MenuModel
toMenuModel = unsafeCastTo MenuModel

noMenuModel :: Maybe MenuModel
noMenuModel = Nothing

-- signal MenuModel::items-changed
type MenuModelItemsChangedCallback =
    Int32 ->
    Int32 ->
    Int32 ->
    IO ()

noMenuModelItemsChangedCallback :: Maybe MenuModelItemsChangedCallback
noMenuModelItemsChangedCallback = Nothing

type MenuModelItemsChangedCallbackC =
    Ptr () ->                               -- object
    Int32 ->
    Int32 ->
    Int32 ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkMenuModelItemsChangedCallback :: MenuModelItemsChangedCallbackC -> IO (FunPtr MenuModelItemsChangedCallbackC)

menuModelItemsChangedClosure :: MenuModelItemsChangedCallback -> IO Closure
menuModelItemsChangedClosure cb = newCClosure =<< mkMenuModelItemsChangedCallback wrapped
    where wrapped = menuModelItemsChangedCallbackWrapper cb

menuModelItemsChangedCallbackWrapper ::
    MenuModelItemsChangedCallback ->
    Ptr () ->
    Int32 ->
    Int32 ->
    Int32 ->
    Ptr () ->
    IO ()
menuModelItemsChangedCallbackWrapper _cb _ position removed added _ = do
    _cb  position removed added

onMenuModelItemsChanged :: (GObject a, MonadIO m) => a -> MenuModelItemsChangedCallback -> m SignalHandlerId
onMenuModelItemsChanged obj cb = liftIO $ connectMenuModelItemsChanged obj cb SignalConnectBefore
afterMenuModelItemsChanged :: (GObject a, MonadIO m) => a -> MenuModelItemsChangedCallback -> m SignalHandlerId
afterMenuModelItemsChanged obj cb = connectMenuModelItemsChanged obj cb SignalConnectAfter

connectMenuModelItemsChanged :: (GObject a, MonadIO m) =>
                                a -> MenuModelItemsChangedCallback -> SignalConnectMode -> m SignalHandlerId
connectMenuModelItemsChanged obj cb after = liftIO $ do
    cb' <- mkMenuModelItemsChangedCallback (menuModelItemsChangedCallbackWrapper cb)
    connectSignalFunPtr obj "items-changed" cb' after

type instance AttributeList MenuModel = MenuModelAttributeList
type MenuModelAttributeList = ('[ ] :: [(Symbol, *)])

data MenuModelItemsChangedSignalInfo
instance SignalInfo MenuModelItemsChangedSignalInfo where
    type HaskellCallbackType MenuModelItemsChangedSignalInfo = MenuModelItemsChangedCallback
    connectSignal _ = connectMenuModelItemsChanged

type instance SignalList MenuModel = MenuModelSignalList
type MenuModelSignalList = ('[ '("items-changed", MenuModelItemsChangedSignalInfo), '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method MenuModel::get_item_attribute_value
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "item_index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "attribute", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "expected_type", argType = TInterface "GLib" "VariantType", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "item_index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "attribute", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "expected_type", argType = TInterface "GLib" "VariantType", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TVariant
-- throws : False
-- Skip return : False

foreign import ccall "g_menu_model_get_item_attribute_value" g_menu_model_get_item_attribute_value :: 
    Ptr MenuModel ->                        -- _obj : TInterface "Gio" "MenuModel"
    Int32 ->                                -- item_index : TBasicType TInt32
    CString ->                              -- attribute : TBasicType TUTF8
    Ptr GLib.VariantType ->                 -- expected_type : TInterface "GLib" "VariantType"
    IO (Ptr GVariant)


menuModelGetItemAttributeValue ::
    (MonadIO m, MenuModelK a) =>
    a ->                                    -- _obj
    Int32 ->                                -- item_index
    T.Text ->                               -- attribute
    Maybe (GLib.VariantType) ->             -- expected_type
    m GVariant
menuModelGetItemAttributeValue _obj item_index attribute expected_type = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    attribute' <- textToCString attribute
    maybeExpected_type <- case expected_type of
        Nothing -> return nullPtr
        Just jExpected_type -> do
            let jExpected_type' = unsafeManagedPtrGetPtr jExpected_type
            return jExpected_type'
    result <- g_menu_model_get_item_attribute_value _obj' item_index attribute' maybeExpected_type
    checkUnexpectedReturnNULL "g_menu_model_get_item_attribute_value" result
    result' <- wrapGVariantPtr result
    touchManagedPtr _obj
    whenJust expected_type touchManagedPtr
    freeMem attribute'
    return result'

-- method MenuModel::get_item_link
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "item_index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "link", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "item_index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "link", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "MenuModel"
-- throws : False
-- Skip return : False

foreign import ccall "g_menu_model_get_item_link" g_menu_model_get_item_link :: 
    Ptr MenuModel ->                        -- _obj : TInterface "Gio" "MenuModel"
    Int32 ->                                -- item_index : TBasicType TInt32
    CString ->                              -- link : TBasicType TUTF8
    IO (Ptr MenuModel)


menuModelGetItemLink ::
    (MonadIO m, MenuModelK a) =>
    a ->                                    -- _obj
    Int32 ->                                -- item_index
    T.Text ->                               -- link
    m MenuModel
menuModelGetItemLink _obj item_index link = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    link' <- textToCString link
    result <- g_menu_model_get_item_link _obj' item_index link'
    checkUnexpectedReturnNULL "g_menu_model_get_item_link" result
    result' <- (wrapObject MenuModel) result
    touchManagedPtr _obj
    freeMem link'
    return result'

-- method MenuModel::get_n_items
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TInt32
-- throws : False
-- Skip return : False

foreign import ccall "g_menu_model_get_n_items" g_menu_model_get_n_items :: 
    Ptr MenuModel ->                        -- _obj : TInterface "Gio" "MenuModel"
    IO Int32


menuModelGetNItems ::
    (MonadIO m, MenuModelK a) =>
    a ->                                    -- _obj
    m Int32
menuModelGetNItems _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_menu_model_get_n_items _obj'
    touchManagedPtr _obj
    return result

-- method MenuModel::is_mutable
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "g_menu_model_is_mutable" g_menu_model_is_mutable :: 
    Ptr MenuModel ->                        -- _obj : TInterface "Gio" "MenuModel"
    IO CInt


menuModelIsMutable ::
    (MonadIO m, MenuModelK a) =>
    a ->                                    -- _obj
    m Bool
menuModelIsMutable _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_menu_model_is_mutable _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

-- method MenuModel::items_changed
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "position", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "removed", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "added", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "position", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "removed", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "added", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_menu_model_items_changed" g_menu_model_items_changed :: 
    Ptr MenuModel ->                        -- _obj : TInterface "Gio" "MenuModel"
    Int32 ->                                -- position : TBasicType TInt32
    Int32 ->                                -- removed : TBasicType TInt32
    Int32 ->                                -- added : TBasicType TInt32
    IO ()


menuModelItemsChanged ::
    (MonadIO m, MenuModelK a) =>
    a ->                                    -- _obj
    Int32 ->                                -- position
    Int32 ->                                -- removed
    Int32 ->                                -- added
    m ()
menuModelItemsChanged _obj position removed added = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    g_menu_model_items_changed _obj' position removed added
    touchManagedPtr _obj
    return ()

-- method MenuModel::iterate_item_attributes
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "item_index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "item_index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "MenuAttributeIter"
-- throws : False
-- Skip return : False

foreign import ccall "g_menu_model_iterate_item_attributes" g_menu_model_iterate_item_attributes :: 
    Ptr MenuModel ->                        -- _obj : TInterface "Gio" "MenuModel"
    Int32 ->                                -- item_index : TBasicType TInt32
    IO (Ptr MenuAttributeIter)


menuModelIterateItemAttributes ::
    (MonadIO m, MenuModelK a) =>
    a ->                                    -- _obj
    Int32 ->                                -- item_index
    m MenuAttributeIter
menuModelIterateItemAttributes _obj item_index = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_menu_model_iterate_item_attributes _obj' item_index
    checkUnexpectedReturnNULL "g_menu_model_iterate_item_attributes" result
    result' <- (wrapObject MenuAttributeIter) result
    touchManagedPtr _obj
    return result'

-- method MenuModel::iterate_item_links
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "item_index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "MenuModel", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "item_index", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "MenuLinkIter"
-- throws : False
-- Skip return : False

foreign import ccall "g_menu_model_iterate_item_links" g_menu_model_iterate_item_links :: 
    Ptr MenuModel ->                        -- _obj : TInterface "Gio" "MenuModel"
    Int32 ->                                -- item_index : TBasicType TInt32
    IO (Ptr MenuLinkIter)


menuModelIterateItemLinks ::
    (MonadIO m, MenuModelK a) =>
    a ->                                    -- _obj
    Int32 ->                                -- item_index
    m MenuLinkIter
menuModelIterateItemLinks _obj item_index = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_menu_model_iterate_item_links _obj' item_index
    checkUnexpectedReturnNULL "g_menu_model_iterate_item_links" result
    result' <- (wrapObject MenuLinkIter) result
    touchManagedPtr _obj
    return result'