{- |
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.DBusMenuModel.DBusMenuModel' is an implementation of 'GI.Gio.Objects.MenuModel.MenuModel' that can be used
as a proxy for a menu model that is exported over D-Bus with
'GI.Gio.Objects.DBusConnection.dBusConnectionExportMenuModel'.
-}

module GI.Gio.Objects.DBusMenuModel
    ( 

-- * Exported types
    DBusMenuModel(..)                       ,
    IsDBusMenuModel                         ,
    toDBusMenuModel                         ,
    noDBusMenuModel                         ,


 -- * Methods
-- ** get #method:get#
    dBusMenuModelGet                        ,




    ) 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
import {-# SOURCE #-} qualified GI.Gio.Objects.DBusConnection as Gio.DBusConnection
import {-# SOURCE #-} qualified GI.Gio.Objects.MenuModel as Gio.MenuModel

newtype DBusMenuModel = DBusMenuModel (ManagedPtr DBusMenuModel)
foreign import ccall "g_dbus_menu_model_get_type"
    c_g_dbus_menu_model_get_type :: IO GType

instance GObject DBusMenuModel where
    gobjectType _ = c_g_dbus_menu_model_get_type
    

class GObject o => IsDBusMenuModel o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError DBusMenuModel a) =>
    IsDBusMenuModel a
#endif
instance IsDBusMenuModel DBusMenuModel
instance Gio.MenuModel.IsMenuModel DBusMenuModel
instance GObject.Object.IsObject DBusMenuModel

toDBusMenuModel :: IsDBusMenuModel o => o -> IO DBusMenuModel
toDBusMenuModel = unsafeCastTo DBusMenuModel

noDBusMenuModel :: Maybe DBusMenuModel
noDBusMenuModel = Nothing

type family ResolveDBusMenuModelMethod (t :: Symbol) (o :: *) :: * where
    ResolveDBusMenuModelMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveDBusMenuModelMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveDBusMenuModelMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveDBusMenuModelMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveDBusMenuModelMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveDBusMenuModelMethod "isMutable" o = Gio.MenuModel.MenuModelIsMutableMethodInfo
    ResolveDBusMenuModelMethod "itemsChanged" o = Gio.MenuModel.MenuModelItemsChangedMethodInfo
    ResolveDBusMenuModelMethod "iterateItemAttributes" o = Gio.MenuModel.MenuModelIterateItemAttributesMethodInfo
    ResolveDBusMenuModelMethod "iterateItemLinks" o = Gio.MenuModel.MenuModelIterateItemLinksMethodInfo
    ResolveDBusMenuModelMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveDBusMenuModelMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveDBusMenuModelMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveDBusMenuModelMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveDBusMenuModelMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveDBusMenuModelMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveDBusMenuModelMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveDBusMenuModelMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveDBusMenuModelMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveDBusMenuModelMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveDBusMenuModelMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveDBusMenuModelMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveDBusMenuModelMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveDBusMenuModelMethod "getItemAttributeValue" o = Gio.MenuModel.MenuModelGetItemAttributeValueMethodInfo
    ResolveDBusMenuModelMethod "getItemLink" o = Gio.MenuModel.MenuModelGetItemLinkMethodInfo
    ResolveDBusMenuModelMethod "getNItems" o = Gio.MenuModel.MenuModelGetNItemsMethodInfo
    ResolveDBusMenuModelMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveDBusMenuModelMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveDBusMenuModelMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveDBusMenuModelMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveDBusMenuModelMethod l o = O.MethodResolutionFailed l o

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

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

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

type instance O.SignalList DBusMenuModel = DBusMenuModelSignalList
type DBusMenuModelSignalList = ('[ '("itemsChanged", Gio.MenuModel.MenuModelItemsChangedSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method DBusMenuModel::get
-- method type : MemberFunction
-- Args : [Arg {argCName = "connection", argType = TInterface (Name {namespace = "Gio", name = "DBusConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GDBusConnection", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "bus_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the bus name which exports the menu model", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "object_path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the object path at which the menu model is exported", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "DBusMenuModel"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_dbus_menu_model_get" g_dbus_menu_model_get :: 
    Ptr Gio.DBusConnection.DBusConnection -> -- connection : TInterface (Name {namespace = "Gio", name = "DBusConnection"})
    CString ->                              -- bus_name : TBasicType TUTF8
    CString ->                              -- object_path : TBasicType TUTF8
    IO (Ptr DBusMenuModel)

{- |
Obtains a 'GI.Gio.Objects.DBusMenuModel.DBusMenuModel' for the menu model which is exported
at the given /@busName@/ and /@objectPath@/.

The thread default main context is taken at the time of this call.
All signals on the menu model (and any linked models) are reported
with respect to this context.  All calls on the returned menu model
(and linked models) must also originate from this same context, with
the thread default main context unchanged.

@since 2.32
-}
dBusMenuModelGet ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.DBusConnection.IsDBusConnection a) =>
    a
    {- ^ /@connection@/: a 'GI.Gio.Objects.DBusConnection.DBusConnection' -}
    -> T.Text
    {- ^ /@busName@/: the bus name which exports the menu model -}
    -> T.Text
    {- ^ /@objectPath@/: the object path at which the menu model is exported -}
    -> m DBusMenuModel
    {- ^ __Returns:__ a 'GI.Gio.Objects.DBusMenuModel.DBusMenuModel' object. Free with
    'GI.GObject.Objects.Object.objectUnref'. -}
dBusMenuModelGet connection busName objectPath = liftIO $ do
    connection' <- unsafeManagedPtrCastPtr connection
    busName' <- textToCString busName
    objectPath' <- textToCString objectPath
    result <- g_dbus_menu_model_get connection' busName' objectPath'
    checkUnexpectedReturnNULL "dBusMenuModelGet" result
    result' <- (wrapObject DBusMenuModel) result
    touchManagedPtr connection
    freeMem busName'
    freeMem objectPath'
    return result'