{- |
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.Interfaces.ListModel
    ( 

-- * Exported types
    ListModel(..)                           ,
    noListModel                             ,
    ListModelK                              ,
    toListModel                             ,


 -- * Methods
-- ** listModelGetItem
    listModelGetItem                        ,


-- ** listModelGetItemType
    listModelGetItemType                    ,


-- ** listModelGetNItems
    listModelGetNItems                      ,


-- ** listModelItemsChanged
    listModelItemsChanged                   ,




 -- * Signals
-- ** ItemsChanged
    ListModelItemsChangedCallback           ,
    ListModelItemsChangedCallbackC          ,
    ListModelItemsChangedSignalInfo         ,
    afterListModelItemsChanged              ,
    listModelItemsChangedCallbackWrapper    ,
    listModelItemsChangedClosure            ,
    mkListModelItemsChangedCallback         ,
    noListModelItemsChangedCallback         ,
    onListModelItemsChanged                 ,




    ) 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.GObject as GObject

-- interface ListModel 

newtype ListModel = ListModel (ForeignPtr ListModel)
noListModel :: Maybe ListModel
noListModel = Nothing

-- signal ListModel::items-changed
type ListModelItemsChangedCallback =
    Word32 ->
    Word32 ->
    Word32 ->
    IO ()

noListModelItemsChangedCallback :: Maybe ListModelItemsChangedCallback
noListModelItemsChangedCallback = Nothing

type ListModelItemsChangedCallbackC =
    Ptr () ->                               -- object
    Word32 ->
    Word32 ->
    Word32 ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkListModelItemsChangedCallback :: ListModelItemsChangedCallbackC -> IO (FunPtr ListModelItemsChangedCallbackC)

listModelItemsChangedClosure :: ListModelItemsChangedCallback -> IO Closure
listModelItemsChangedClosure cb = newCClosure =<< mkListModelItemsChangedCallback wrapped
    where wrapped = listModelItemsChangedCallbackWrapper cb

listModelItemsChangedCallbackWrapper ::
    ListModelItemsChangedCallback ->
    Ptr () ->
    Word32 ->
    Word32 ->
    Word32 ->
    Ptr () ->
    IO ()
listModelItemsChangedCallbackWrapper _cb _ position removed added _ = do
    _cb  position removed added

onListModelItemsChanged :: (GObject a, MonadIO m) => a -> ListModelItemsChangedCallback -> m SignalHandlerId
onListModelItemsChanged obj cb = liftIO $ connectListModelItemsChanged obj cb SignalConnectBefore
afterListModelItemsChanged :: (GObject a, MonadIO m) => a -> ListModelItemsChangedCallback -> m SignalHandlerId
afterListModelItemsChanged obj cb = connectListModelItemsChanged obj cb SignalConnectAfter

connectListModelItemsChanged :: (GObject a, MonadIO m) =>
                                a -> ListModelItemsChangedCallback -> SignalConnectMode -> m SignalHandlerId
connectListModelItemsChanged obj cb after = liftIO $ do
    cb' <- mkListModelItemsChangedCallback (listModelItemsChangedCallbackWrapper cb)
    connectSignalFunPtr obj "items-changed" cb' after

type instance AttributeList ListModel = ListModelAttributeList
type ListModelAttributeList = ('[ ] :: [(Symbol, *)])

data ListModelItemsChangedSignalInfo
instance SignalInfo ListModelItemsChangedSignalInfo where
    type HaskellCallbackType ListModelItemsChangedSignalInfo = ListModelItemsChangedCallback
    connectSignal _ = connectListModelItemsChanged

type instance SignalList ListModel = ListModelSignalList
type ListModelSignalList = ('[ '("items-changed", ListModelItemsChangedSignalInfo), '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

foreign import ccall "g_list_model_get_type"
    c_g_list_model_get_type :: IO GType

type instance ParentTypes ListModel = ListModelParentTypes
type ListModelParentTypes = '[GObject.Object]

instance GObject ListModel where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_list_model_get_type
    

class GObject o => ListModelK o
instance (GObject o, IsDescendantOf ListModel o) => ListModelK o

toListModel :: ListModelK o => o -> IO ListModel
toListModel = unsafeCastTo ListModel

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

foreign import ccall "g_list_model_get_item_type" g_list_model_get_item_type :: 
    Ptr ListModel ->                        -- _obj : TInterface "Gio" "ListModel"
    IO CGType


listModelGetItemType ::
    (MonadIO m, ListModelK a) =>
    a ->                                    -- _obj
    m GType
listModelGetItemType _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_list_model_get_item_type _obj'
    let result' = GType result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "g_list_model_get_n_items" g_list_model_get_n_items :: 
    Ptr ListModel ->                        -- _obj : TInterface "Gio" "ListModel"
    IO Word32


listModelGetNItems ::
    (MonadIO m, ListModelK a) =>
    a ->                                    -- _obj
    m Word32
listModelGetNItems _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_list_model_get_n_items _obj'
    touchManagedPtr _obj
    return result

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

foreign import ccall "g_list_model_get_object" g_list_model_get_object :: 
    Ptr ListModel ->                        -- _obj : TInterface "Gio" "ListModel"
    Word32 ->                               -- position : TBasicType TUInt32
    IO (Ptr GObject.Object)


listModelGetItem ::
    (MonadIO m, ListModelK a) =>
    a ->                                    -- _obj
    Word32 ->                               -- position
    m GObject.Object
listModelGetItem _obj position = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_list_model_get_object _obj' position
    checkUnexpectedReturnNULL "g_list_model_get_object" result
    result' <- (wrapObject GObject.Object) result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "g_list_model_items_changed" g_list_model_items_changed :: 
    Ptr ListModel ->                        -- _obj : TInterface "Gio" "ListModel"
    Word32 ->                               -- position : TBasicType TUInt32
    Word32 ->                               -- removed : TBasicType TUInt32
    Word32 ->                               -- added : TBasicType TUInt32
    IO ()


listModelItemsChanged ::
    (MonadIO m, ListModelK a) =>
    a ->                                    -- _obj
    Word32 ->                               -- position
    Word32 ->                               -- removed
    Word32 ->                               -- added
    m ()
listModelItemsChanged _obj position removed added = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    g_list_model_items_changed _obj' position removed added
    touchManagedPtr _obj
    return ()