    {-# LINE 1 "Data/GI/Base/GVariant.hsc" #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE LambdaCase #-}
    {-# LANGUAGE EmptyDataDecls #-}
    {-|
    This module contains some helper functions for dealing with GVariant
    values. The simplest way of dealing with them is by using the
    'IsGVariant' typeclass:

    > str <- fromGVariant variant :: IO (Maybe Text)

    assuming that the variant is expected to contain a
    string in UTF8 encoding. The code becomes even shorter if the type
    checker can determine the return type for you:

    > readStringVariant :: GVariant -> IO Text
    > readStringVariant variant =
    >   fromGVariant variant >>= \case
    >      Nothing  -> error "Variant was not a string"
    >      Just str -> return str

    Alternatively, you can use manually the gvariantFrom* and
    gvariantTo* family of functions.
    -}
    module Data.GI.Base.GVariant
        ( IsGVariant(..)
        , IsGVariantBasicType

        , noGVariant

        , gvariantGetTypeString

        -- * Type wrappers
        -- | Some 'GVariant' types are isomorphic to Haskell types, but they
        -- carry some extra information. For example, there is a tuple
        -- singlet type, which is isomorphic to a single Haskell value
        -- with the added bit of information that it is wrapped in a tuple
        -- container. In order to use these values you can use the
        -- following wrappers, which allow the 'IsGVariant' instance to
        -- disambiguate the requested type properly.

        , GVariantSinglet(GVariantSinglet)
        , GVariantDictEntry(GVariantDictEntry)
        , GVariantHandle(GVariantHandle)
        , GVariantObjectPath
        , newGVariantObjectPath
        , gvariantObjectPathToText
        , GVariantSignature
        , newGVariantSignature
        , gvariantSignatureToText

        -- * Manual memory management

        , wrapGVariantPtr
        , newGVariantFromPtr
        , unrefGVariant
        , disownGVariant

        -- * Manual conversions

        -- ** Basic types
        --
        -- | The use of these should be fairly self-explanatory. If you
        -- want to convert a Haskell type into a 'GVariant', use
        -- gvariantTo*. If you want to convert a 'GVariant' into a Haskell
        -- type, use gvariantFrom*. The conversion can fail if the
        -- 'GVariant' is not of the expected type (if you want to convert
        -- a 'GVariant' containing a 'Int16' into a 'Text' value, say), in
        -- which case 'Nothing' will be returned.
        , gvariantToBool
        , gvariantFromBool

        , gvariantToWord8
        , gvariantFromWord8

        , gvariantToInt16
        , gvariantFromInt16

        , gvariantToWord16
        , gvariantFromWord16

        , gvariantToInt32
        , gvariantFromInt32

        , gvariantToWord32
        , gvariantFromWord32

        , gvariantToInt64
        , gvariantFromInt64

        , gvariantToWord64
        , gvariantFromWord64

        , gvariantToHandle
        , gvariantFromHandle

        , gvariantToDouble
        , gvariantFromDouble

        , gvariantToText
        , gvariantFromText

        , gvariantToObjectPath
        , gvariantFromObjectPath

        , gvariantToSignature
        , gvariantFromSignature

        -- ** Container type conversions
        , gvariantToGVariant
        , gvariantFromGVariant

        , gvariantToBytestring
        , gvariantFromBytestring

        , gvariantFromMaybe
        , gvariantToMaybe

        , gvariantFromDictEntry
        , gvariantToDictEntry

        , gvariantFromMap
        , gvariantToMap

        , gvariantFromList
        , gvariantToList

        , gvariantFromTuple
        , gvariantToTuple
        ) where

    import Control.Monad (when, void, (>=>))
    import Control.Exception.Base (bracket)

    import Data.Text (Text)
    import Data.ByteString (ByteString)
    import qualified Data.ByteString as B
    import Data.Word
    import Data.Int

    {-# LINE 147 "Data/GI/Base/GVariant.hsc" #-}
    import Data.Maybe (isJust, fromJust)
    import qualified Data.Map as M

    import System.IO.Unsafe (unsafePerformIO)
    import Foreign.C
    import Foreign.Ptr

    import Data.GI.Base.BasicTypes (GVariant(..))
    import Data.GI.Base.BasicConversions
    import Data.GI.Base.ManagedPtr (withManagedPtr, withManagedPtrList,
                                    newManagedPtr', disownManagedPtr)
    import Data.GI.Base.Utils (freeMem)

    -- | An alias for @Nothing :: Maybe GVariant@ to save some typing.
    noGVariant :: Maybe GVariant
    noGVariant :: Maybe GVariant
    noGVariant = Maybe GVariant
    forall a. Maybe a
    Nothing

    -- | The typeclass for types that can be automatically marshalled into
    -- 'GVariant' using 'toGVariant' and 'fromGVariant'.
    class IsGVariant a where
        -- | Convert a value of the given type into a GVariant.
        toGVariant   :: a -> IO GVariant
        -- | Try to decode a 'GVariant' into a target type. If the
        -- conversion fails we return 'Nothing'. The type that was
        -- expected can be obtained by calling 'toGVariantFormatString',
        -- and the actual type as understood by the 'GVariant' code can be
        -- obtained by calling 'gvariantToTypeString'.
        fromGVariant :: GVariant -> IO (Maybe a)
        -- | The expected format string for this type (the argument is
        -- ignored).
        toGVariantFormatString :: a -> Text

    -- Same as fromGVariant, for cases where we have checked that things
    -- have the right type in advance.
    unsafeFromGVariant :: IsGVariant a => GVariant -> IO a
    unsafeFromGVariant :: forall a. IsGVariant a => GVariant -> IO a
    unsafeFromGVariant GVariant
    gv =
        GVariant -> IO (Maybe a)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    gv IO (Maybe a) -> (Maybe a -> IO a) -> IO a
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \case
                     Maybe a
    Nothing -> [Char] -> IO a
    forall a. HasCallStack => [Char] -> a
    error [Char]
    "Error decoding GVariant. This is a bug in haskell-gi, please report it."
                     Just a
    value -> a -> IO a
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    value

    -- | The typeclass for basic type 'GVariant' types, i.e. those that
    -- are not containers.
    class Ord a => IsGVariantBasicType a

    -- | Haskell has no notion of one element tuples, but GVariants do, so
    -- the following allows for marshalling one element tuples properly
    -- using 'fromGVariant' and 'toGVariant'. For instance, to construct a
    -- single element tuple containing a string, you could do
    --
    -- > toGVariant (GVariantSinglet "Test")
    newtype GVariantSinglet a = GVariantSinglet a
        deriving (GVariantSinglet a -> GVariantSinglet a -> Bool
    (GVariantSinglet a -> GVariantSinglet a -> Bool)
    -> (GVariantSinglet a -> GVariantSinglet a -> Bool)
    -> Eq (GVariantSinglet a)
    forall a. Eq a => GVariantSinglet a -> GVariantSinglet a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall a. Eq a => GVariantSinglet a -> GVariantSinglet a -> Bool
    == :: GVariantSinglet a -> GVariantSinglet a -> Bool
    $c/= :: forall a. Eq a => GVariantSinglet a -> GVariantSinglet a -> Bool
    /= :: GVariantSinglet a -> GVariantSinglet a -> Bool
    Eq, Int -> GVariantSinglet a -> ShowS
    [GVariantSinglet a] -> ShowS
    GVariantSinglet a -> [Char]
    (Int -> GVariantSinglet a -> ShowS)
    -> (GVariantSinglet a -> [Char])
    -> ([GVariantSinglet a] -> ShowS)
    -> Show (GVariantSinglet a)
    forall a. Show a => Int -> GVariantSinglet a -> ShowS
    forall a. Show a => [GVariantSinglet a] -> ShowS
    forall a. Show a => GVariantSinglet a -> [Char]
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> GVariantSinglet a -> ShowS
    showsPrec :: Int -> GVariantSinglet a -> ShowS
    $cshow :: forall a. Show a => GVariantSinglet a -> [Char]
    show :: GVariantSinglet a -> [Char]
    $cshowList :: forall a. Show a => [GVariantSinglet a] -> ShowS
    showList :: [GVariantSinglet a] -> ShowS
    Show)

    data GVariantType

    foreign import ccall "g_variant_type_new" g_variant_type_new ::
        CString -> IO (Ptr GVariantType)

    foreign import ccall "g_variant_type_free" g_variant_type_free ::
        Ptr GVariantType -> IO ()

    foreign import ccall "g_variant_is_of_type" g_variant_is_of_type ::
        Ptr GVariant -> Ptr GVariantType -> IO Int32
    {-# LINE 210 "Data/GI/Base/GVariant.hsc" #-}

    withGVariantType :: Text -> (Ptr GVariantType -> IO a) -> IO a
    withGVariantType :: forall a. Text -> (Ptr GVariantType -> IO a) -> IO a
    withGVariantType Text
    text Ptr GVariantType -> IO a
    action = Text -> (CString -> IO a) -> IO a
    forall a. Text -> (CString -> IO a) -> IO a
    withTextCString Text
    text ((CString -> IO a) -> IO a) -> (CString -> IO a) -> IO a
    forall a b. (a -> b) -> a -> b
    $ \CString
    textPtr ->
                                   IO (Ptr GVariantType)
    -> (Ptr GVariantType -> IO ())
    -> (Ptr GVariantType -> IO a)
    -> IO a
    forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
    bracket (CString -> IO (Ptr GVariantType)
    g_variant_type_new CString
    textPtr)
                                           Ptr GVariantType -> IO ()
    g_variant_type_free
                                           Ptr GVariantType -> IO a
    action

    gvariantIsOfType :: Text -> GVariant -> IO Bool
    gvariantIsOfType :: Text -> GVariant -> IO Bool
    gvariantIsOfType Text
    typeString GVariant
    variant =
        Text -> (Ptr GVariantType -> IO Bool) -> IO Bool
    forall a. Text -> (Ptr GVariantType -> IO a) -> IO a
    withGVariantType Text
    typeString ((Ptr GVariantType -> IO Bool) -> IO Bool)
    -> (Ptr GVariantType -> IO Bool) -> IO Bool
    forall a b. (a -> b) -> a -> b
    $
            \Ptr GVariantType
    typePtr ->
                (Int -> Bool
    forall a. Enum a => Int -> a
    toEnum (Int -> Bool) -> (Int32 -> Int) -> Int32 -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int32 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) (Int32 -> Bool) -> IO Int32 -> IO Bool
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> GVariant -> (Ptr GVariant -> IO Int32) -> IO Int32
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr GVariant
    variant
                                            (\Ptr GVariant
    vptr -> Ptr GVariant -> Ptr GVariantType -> IO Int32
    g_variant_is_of_type
                                                      Ptr GVariant
    vptr Ptr GVariantType
    typePtr)

    withExplicitType :: Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType :: forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType Text
    format Ptr GVariant -> IO a
    action GVariant
    variant = do
      check <- Text -> GVariant -> IO Bool
    gvariantIsOfType Text
    format GVariant
    variant
      if check
      then Just <$> withManagedPtr variant action
      else return Nothing

    withTypeCheck :: forall a. (IsGVariant a) =>
                     (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck :: forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck = Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType (Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a))
    -> Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    forall a b. (a -> b) -> a -> b
    $ a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)

    foreign import ccall "g_variant_get_type_string" g_variant_get_type_string
        :: Ptr GVariant -> IO CString

    -- | Get the expected type of a 'GVariant', in 'GVariant'
    -- notation. See
    -- <https://docs.gtk.org/glib/struct.VariantType.html>
    -- for the meaning of the resulting format string.
    gvariantGetTypeString :: GVariant -> IO Text
    gvariantGetTypeString :: GVariant -> IO Text
    gvariantGetTypeString GVariant
    variant =
        GVariant -> (Ptr GVariant -> IO Text) -> IO Text
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr GVariant
    variant (Ptr GVariant -> IO CString
    g_variant_get_type_string (Ptr GVariant -> IO CString)
    -> (CString -> IO Text) -> Ptr GVariant -> IO Text
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> HasCallStack => CString -> IO Text
    CString -> IO Text
    cstringToText)

    foreign import ccall "g_variant_is_floating" g_variant_is_floating ::
        Ptr GVariant -> IO CInt
    foreign import ccall "g_variant_ref_sink" g_variant_ref_sink ::
        Ptr GVariant -> IO (Ptr GVariant)
    foreign import ccall "g_variant_ref" g_variant_ref ::
        Ptr GVariant -> IO (Ptr GVariant)
    foreign import ccall "g_variant_unref" g_variant_unref ::
        Ptr GVariant -> IO ()
    foreign import ccall "&g_variant_unref" ptr_to_g_variant_unref ::
        FunPtr (Ptr GVariant -> IO ())

    -- | Take ownership of a passed in 'Ptr' (typically created just for
    -- us, so if it is floating we sink it).
    wrapGVariantPtr :: Ptr GVariant -> IO GVariant
    wrapGVariantPtr :: Ptr GVariant -> IO GVariant
    wrapGVariantPtr Ptr GVariant
    ptr = do
      floating <- Ptr GVariant -> IO CInt
    g_variant_is_floating Ptr GVariant
    ptr
      when (floating /= 0) $ void $ g_variant_ref_sink ptr
      fPtr <- newManagedPtr' ptr_to_g_variant_unref ptr
      return $! GVariant fPtr

    -- | Construct a Haskell wrapper for the given 'GVariant', without
    -- assuming ownership.
    newGVariantFromPtr :: Ptr GVariant -> IO GVariant
    newGVariantFromPtr :: Ptr GVariant -> IO GVariant
    newGVariantFromPtr Ptr GVariant
    ptr = do
      fPtr <- Ptr GVariant -> IO (Ptr GVariant)
    g_variant_ref Ptr GVariant
    ptr IO (Ptr GVariant)
    -> (Ptr GVariant -> IO (ManagedPtr GVariant))
    -> IO (ManagedPtr GVariant)
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= FinalizerPtr GVariant -> Ptr GVariant -> IO (ManagedPtr GVariant)
    forall a.
    HasCallStack =>
    FinalizerPtr a -> Ptr a -> IO (ManagedPtr a)
    newManagedPtr' FinalizerPtr GVariant
    ptr_to_g_variant_unref
      return $! GVariant fPtr

    -- | Remove a reference to the given 'GVariant'.
    unrefGVariant :: GVariant -> IO ()
    unrefGVariant :: GVariant -> IO ()
    unrefGVariant GVariant
    gv = GVariant -> (Ptr GVariant -> IO ()) -> IO ()
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr GVariant
    gv Ptr GVariant -> IO ()
    g_variant_unref

    -- | Disown a `GVariant`, i.e. do not unref the underlying object when
    -- the Haskell object is garbage collected.
    disownGVariant :: GVariant -> IO (Ptr GVariant)
    disownGVariant :: GVariant -> IO (Ptr GVariant)
    disownGVariant = GVariant -> IO (Ptr GVariant)
    forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
    disownManagedPtr

    instance IsGVariant Bool where
        toGVariant :: Bool -> IO GVariant
    toGVariant = Bool -> IO GVariant
    gvariantFromBool
        fromGVariant :: GVariant -> IO (Maybe Bool)
    fromGVariant = GVariant -> IO (Maybe Bool)
    gvariantToBool
        toGVariantFormatString :: Bool -> Text
    toGVariantFormatString Bool
    _ = Text
    "b"
    instance IsGVariantBasicType Bool

    foreign import ccall "g_variant_new_boolean" new_bool
        :: Int32 -> IO (Ptr GVariant)
    {-# LINE 291 "Data/GI/Base/GVariant.hsc" #-}

    gvariantFromBool :: Bool -> IO GVariant
    gvariantFromBool :: Bool -> IO GVariant
    gvariantFromBool = (Int32 -> IO (Ptr GVariant)
    new_bool (Int32 -> IO (Ptr GVariant))
    -> (Bool -> Int32) -> Bool -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> Int32
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int -> Int32) -> (Bool -> Int) -> Bool -> Int32
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool -> Int
    forall a. Enum a => a -> Int
    fromEnum) (Bool -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Bool -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_boolean" get_bool
        :: Ptr GVariant -> IO Int32
    {-# LINE 297 "Data/GI/Base/GVariant.hsc" #-}

    gvariantToBool :: GVariant -> IO (Maybe Bool)
    gvariantToBool :: GVariant -> IO (Maybe Bool)
    gvariantToBool = (Ptr GVariant -> IO Bool) -> GVariant -> IO (Maybe Bool)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Bool) -> GVariant -> IO (Maybe Bool))
    -> (Ptr GVariant -> IO Bool) -> GVariant -> IO (Maybe Bool)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO Int32
    get_bool (Ptr GVariant -> IO Int32)
    -> (Int32 -> IO Bool) -> Ptr GVariant -> IO Bool
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Bool -> IO Bool
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Bool -> IO Bool) -> (Int32 -> Bool) -> Int32 -> IO Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> Bool
    forall a. Enum a => Int -> a
    toEnum (Int -> Bool) -> (Int32 -> Int) -> Int32 -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int32 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral)

    instance IsGVariant Word8 where
        toGVariant :: Word8 -> IO GVariant
    toGVariant = Word8 -> IO GVariant
    gvariantFromWord8
        fromGVariant :: GVariant -> IO (Maybe Word8)
    fromGVariant = GVariant -> IO (Maybe Word8)
    gvariantToWord8
        toGVariantFormatString :: Word8 -> Text
    toGVariantFormatString Word8
    _ = Text
    "y"
    instance IsGVariantBasicType Word8

    foreign import ccall "g_variant_new_byte" new_byte
        :: Word8 -> IO (Ptr GVariant)
    {-# LINE 309 "Data/GI/Base/GVariant.hsc" #-}

    gvariantFromWord8 :: Word8 -> IO GVariant
    gvariantFromWord8 :: Word8 -> IO GVariant
    gvariantFromWord8 = (Word8 -> IO (Ptr GVariant)
    new_byte (Word8 -> IO (Ptr GVariant))
    -> (Word8 -> Word8) -> Word8 -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Word8 -> Word8
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) (Word8 -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Word8 -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_byte" get_byte
        :: Ptr GVariant -> IO Word8
    {-# LINE 315 "Data/GI/Base/GVariant.hsc" #-}

    gvariantToWord8 :: GVariant -> IO (Maybe Word8)
    gvariantToWord8 :: GVariant -> IO (Maybe Word8)
    gvariantToWord8 = (Ptr GVariant -> IO Word8) -> GVariant -> IO (Maybe Word8)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Word8) -> GVariant -> IO (Maybe Word8))
    -> (Ptr GVariant -> IO Word8) -> GVariant -> IO (Maybe Word8)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO Word8
    get_byte (Ptr GVariant -> IO Word8)
    -> (Word8 -> IO Word8) -> Ptr GVariant -> IO Word8
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Word8 -> IO Word8
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Word8 -> IO Word8) -> (Word8 -> Word8) -> Word8 -> IO Word8
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Word8 -> Word8
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral)

    instance IsGVariant Int16 where
        toGVariant :: Int16 -> IO GVariant
    toGVariant = Int16 -> IO GVariant
    gvariantFromInt16
        fromGVariant :: GVariant -> IO (Maybe Int16)
    fromGVariant = GVariant -> IO (Maybe Int16)
    gvariantToInt16
        toGVariantFormatString :: Int16 -> Text
    toGVariantFormatString Int16
    _ = Text
    "n"
    instance IsGVariantBasicType Int16

    foreign import ccall "g_variant_new_int16" new_int16
        :: Int16 -> IO (Ptr GVariant)
    {-# LINE 327 "Data/GI/Base/GVariant.hsc" #-}

    gvariantFromInt16 :: Int16 -> IO GVariant
    gvariantFromInt16 :: Int16 -> IO GVariant
    gvariantFromInt16 = (Int16 -> IO (Ptr GVariant)
    new_int16 (Int16 -> IO (Ptr GVariant))
    -> (Int16 -> Int16) -> Int16 -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int16 -> Int16
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) (Int16 -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Int16 -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_int16" get_int16
        :: Ptr GVariant -> IO Int16
    {-# LINE 333 "Data/GI/Base/GVariant.hsc" #-}

    gvariantToInt16 :: GVariant -> IO (Maybe Int16)
    gvariantToInt16 :: GVariant -> IO (Maybe Int16)
    gvariantToInt16 = (Ptr GVariant -> IO Int16) -> GVariant -> IO (Maybe Int16)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Int16) -> GVariant -> IO (Maybe Int16))
    -> (Ptr GVariant -> IO Int16) -> GVariant -> IO (Maybe Int16)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO Int16
    get_int16 (Ptr GVariant -> IO Int16)
    -> (Int16 -> IO Int16) -> Ptr GVariant -> IO Int16
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Int16 -> IO Int16
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Int16 -> IO Int16) -> (Int16 -> Int16) -> Int16 -> IO Int16
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int16 -> Int16
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral)

    instance IsGVariant Word16 where
        toGVariant :: Word16 -> IO GVariant
    toGVariant = Word16 -> IO GVariant
    gvariantFromWord16
        fromGVariant :: GVariant -> IO (Maybe Word16)
    fromGVariant = GVariant -> IO (Maybe Word16)
    gvariantToWord16
        toGVariantFormatString :: Word16 -> Text
    toGVariantFormatString Word16
    _ = Text
    "q"
    instance IsGVariantBasicType Word16

    foreign import ccall "g_variant_new_uint16" new_uint16
        :: Word16 -> IO (Ptr GVariant)
    {-# LINE 345 "Data/GI/Base/GVariant.hsc" #-}

    gvariantFromWord16 :: Word16 -> IO GVariant
    gvariantFromWord16 :: Word16 -> IO GVariant
    gvariantFromWord16 = Word16 -> IO (Ptr GVariant)
    new_uint16 (Word16 -> IO (Ptr GVariant))
    -> (Word16 -> Word16) -> Word16 -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Word16 -> Word16
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Word16 -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Word16 -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_uint16" get_uint16
        :: Ptr GVariant -> IO Word16
    {-# LINE 351 "Data/GI/Base/GVariant.hsc" #-}

    gvariantToWord16 :: GVariant -> IO (Maybe Word16)
    gvariantToWord16 :: GVariant -> IO (Maybe Word16)
    gvariantToWord16 = (Ptr GVariant -> IO Word16) -> GVariant -> IO (Maybe Word16)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Word16) -> GVariant -> IO (Maybe Word16))
    -> (Ptr GVariant -> IO Word16) -> GVariant -> IO (Maybe Word16)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO Word16
    get_uint16 (Ptr GVariant -> IO Word16)
    -> (Word16 -> IO Word16) -> Ptr GVariant -> IO Word16
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Word16 -> IO Word16
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Word16 -> IO Word16) -> (Word16 -> Word16) -> Word16 -> IO Word16
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Word16 -> Word16
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral)

    instance IsGVariant Int32 where
        toGVariant :: Int32 -> IO GVariant
    toGVariant = Int32 -> IO GVariant
    gvariantFromInt32
        fromGVariant :: GVariant -> IO (Maybe Int32)
    fromGVariant = GVariant -> IO (Maybe Int32)
    gvariantToInt32
        toGVariantFormatString :: Int32 -> Text
    toGVariantFormatString Int32
    _ = Text
    "i"
    instance IsGVariantBasicType Int32

    foreign import ccall "g_variant_new_int32" new_int32
        :: Int16 -> IO (Ptr GVariant)
    {-# LINE 363 "Data/GI/Base/GVariant.hsc" #-}

    gvariantFromInt32 :: Int32 -> IO GVariant
    gvariantFromInt32 :: Int32 -> IO GVariant
    gvariantFromInt32 = (Int16 -> IO (Ptr GVariant)
    new_int32 (Int16 -> IO (Ptr GVariant))
    -> (Int32 -> Int16) -> Int32 -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int32 -> Int16
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) (Int32 -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Int32 -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_int32" get_int32
        :: Ptr GVariant -> IO Int32
    {-# LINE 369 "Data/GI/Base/GVariant.hsc" #-}

    gvariantToInt32 :: GVariant -> IO (Maybe Int32)
    gvariantToInt32 :: GVariant -> IO (Maybe Int32)
    gvariantToInt32 = (Ptr GVariant -> IO Int32) -> GVariant -> IO (Maybe Int32)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Int32) -> GVariant -> IO (Maybe Int32))
    -> (Ptr GVariant -> IO Int32) -> GVariant -> IO (Maybe Int32)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO Int32
    get_int32 (Ptr GVariant -> IO Int32)
    -> (Int32 -> IO Int32) -> Ptr GVariant -> IO Int32
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Int32 -> IO Int32
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Int32 -> IO Int32) -> (Int32 -> Int32) -> Int32 -> IO Int32
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int32 -> Int32
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral)

    instance IsGVariant Word32 where
        toGVariant :: Word32 -> IO GVariant
    toGVariant = Word32 -> IO GVariant
    gvariantFromWord32
        fromGVariant :: GVariant -> IO (Maybe Word32)
    fromGVariant = GVariant -> IO (Maybe Word32)
    gvariantToWord32
        toGVariantFormatString :: Word32 -> Text
    toGVariantFormatString Word32
    _ = Text
    "u"
    instance IsGVariantBasicType Word32

    foreign import ccall "g_variant_new_uint32" new_uint32
        :: Word32 -> IO (Ptr GVariant)
    {-# LINE 381 "Data/GI/Base/GVariant.hsc" #-}

    gvariantFromWord32 :: Word32 -> IO GVariant
    gvariantFromWord32 :: Word32 -> IO GVariant
    gvariantFromWord32 = (Word32 -> IO (Ptr GVariant)
    new_uint32 (Word32 -> IO (Ptr GVariant))
    -> (Word32 -> Word32) -> Word32 -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Word32 -> Word32
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) (Word32 -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Word32 -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_uint32" get_uint32
        :: Ptr GVariant -> IO Word32
    {-# LINE 387 "Data/GI/Base/GVariant.hsc" #-}

    gvariantToWord32 :: GVariant -> IO (Maybe Word32)
    gvariantToWord32 :: GVariant -> IO (Maybe Word32)
    gvariantToWord32 = (Ptr GVariant -> IO Word32) -> GVariant -> IO (Maybe Word32)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Word32) -> GVariant -> IO (Maybe Word32))
    -> (Ptr GVariant -> IO Word32) -> GVariant -> IO (Maybe Word32)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO Word32
    get_uint32 (Ptr GVariant -> IO Word32)
    -> (Word32 -> IO Word32) -> Ptr GVariant -> IO Word32
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Word32 -> IO Word32
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Word32 -> IO Word32) -> (Word32 -> Word32) -> Word32 -> IO Word32
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Word32 -> Word32
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral)

    instance IsGVariant Int64 where
        toGVariant :: Int64 -> IO GVariant
    toGVariant = Int64 -> IO GVariant
    gvariantFromInt64
        fromGVariant :: GVariant -> IO (Maybe Int64)
    fromGVariant = GVariant -> IO (Maybe Int64)
    gvariantToInt64
        toGVariantFormatString :: Int64 -> Text
    toGVariantFormatString Int64
    _ = Text
    "x"
    instance IsGVariantBasicType Int64

    foreign import ccall "g_variant_new_int64" new_int64
        :: Int64 -> IO (Ptr GVariant)
    {-# LINE 399 "Data/GI/Base/GVariant.hsc" #-}

    gvariantFromInt64 :: Int64 -> IO GVariant
    gvariantFromInt64 :: Int64 -> IO GVariant
    gvariantFromInt64 = (Int64 -> IO (Ptr GVariant)
    new_int64 (Int64 -> IO (Ptr GVariant))
    -> (Int64 -> Int64) -> Int64 -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int64 -> Int64
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) (Int64 -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Int64 -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_int64" get_int64
        :: Ptr GVariant -> IO Int64
    {-# LINE 405 "Data/GI/Base/GVariant.hsc" #-}

    gvariantToInt64 :: GVariant -> IO (Maybe Int64)
    gvariantToInt64 :: GVariant -> IO (Maybe Int64)
    gvariantToInt64 = (Ptr GVariant -> IO Int64) -> GVariant -> IO (Maybe Int64)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Int64) -> GVariant -> IO (Maybe Int64))
    -> (Ptr GVariant -> IO Int64) -> GVariant -> IO (Maybe Int64)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO Int64
    get_int64 (Ptr GVariant -> IO Int64)
    -> (Int64 -> IO Int64) -> Ptr GVariant -> IO Int64
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Int64 -> IO Int64
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Int64 -> IO Int64) -> (Int64 -> Int64) -> Int64 -> IO Int64
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int64 -> Int64
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral)

    instance IsGVariant Word64 where
        toGVariant :: Word64 -> IO GVariant
    toGVariant = Word64 -> IO GVariant
    gvariantFromWord64
        fromGVariant :: GVariant -> IO (Maybe Word64)
    fromGVariant = GVariant -> IO (Maybe Word64)
    gvariantToWord64
        toGVariantFormatString :: Word64 -> Text
    toGVariantFormatString Word64
    _ = Text
    "t"
    instance IsGVariantBasicType Word64

    foreign import ccall "g_variant_new_uint64" new_uint64
        :: Word64 -> IO (Ptr GVariant)
    {-# LINE 417 "Data/GI/Base/GVariant.hsc" #-}

    gvariantFromWord64 :: Word64 -> IO GVariant
    gvariantFromWord64 :: Word64 -> IO GVariant
    gvariantFromWord64 = (Word64 -> IO (Ptr GVariant)
    new_uint64 (Word64 -> IO (Ptr GVariant))
    -> (Word64 -> Word64) -> Word64 -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Word64 -> Word64
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) (Word64 -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Word64 -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_uint64" get_uint64
        :: Ptr GVariant -> IO Word64
    {-# LINE 423 "Data/GI/Base/GVariant.hsc" #-}

    gvariantToWord64 :: GVariant -> IO (Maybe Word64)
    gvariantToWord64 :: GVariant -> IO (Maybe Word64)
    gvariantToWord64 = (Ptr GVariant -> IO Word64) -> GVariant -> IO (Maybe Word64)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Word64) -> GVariant -> IO (Maybe Word64))
    -> (Ptr GVariant -> IO Word64) -> GVariant -> IO (Maybe Word64)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO Word64
    get_uint64 (Ptr GVariant -> IO Word64)
    -> (Word64 -> IO Word64) -> Ptr GVariant -> IO Word64
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Word64 -> IO Word64
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Word64 -> IO Word64) -> (Word64 -> Word64) -> Word64 -> IO Word64
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Word64 -> Word64
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral)

    newtype GVariantHandle = GVariantHandle Int32
        deriving (GVariantHandle -> GVariantHandle -> Bool
    (GVariantHandle -> GVariantHandle -> Bool)
    -> (GVariantHandle -> GVariantHandle -> Bool) -> Eq GVariantHandle
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: GVariantHandle -> GVariantHandle -> Bool
    == :: GVariantHandle -> GVariantHandle -> Bool
    $c/= :: GVariantHandle -> GVariantHandle -> Bool
    /= :: GVariantHandle -> GVariantHandle -> Bool
    Eq, Eq GVariantHandle
    Eq GVariantHandle =>
    (GVariantHandle -> GVariantHandle -> Ordering)
    -> (GVariantHandle -> GVariantHandle -> Bool)
    -> (GVariantHandle -> GVariantHandle -> Bool)
    -> (GVariantHandle -> GVariantHandle -> Bool)
    -> (GVariantHandle -> GVariantHandle -> Bool)
    -> (GVariantHandle -> GVariantHandle -> GVariantHandle)
    -> (GVariantHandle -> GVariantHandle -> GVariantHandle)
    -> Ord GVariantHandle
    GVariantHandle -> GVariantHandle -> Bool
    GVariantHandle -> GVariantHandle -> Ordering
    GVariantHandle -> GVariantHandle -> GVariantHandle
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: GVariantHandle -> GVariantHandle -> Ordering
    compare :: GVariantHandle -> GVariantHandle -> Ordering
    $c< :: GVariantHandle -> GVariantHandle -> Bool
    < :: GVariantHandle -> GVariantHandle -> Bool
    $c<= :: GVariantHandle -> GVariantHandle -> Bool
    <= :: GVariantHandle -> GVariantHandle -> Bool
    $c> :: GVariantHandle -> GVariantHandle -> Bool
    > :: GVariantHandle -> GVariantHandle -> Bool
    $c>= :: GVariantHandle -> GVariantHandle -> Bool
    >= :: GVariantHandle -> GVariantHandle -> Bool
    $cmax :: GVariantHandle -> GVariantHandle -> GVariantHandle
    max :: GVariantHandle -> GVariantHandle -> GVariantHandle
    $cmin :: GVariantHandle -> GVariantHandle -> GVariantHandle
    min :: GVariantHandle -> GVariantHandle -> GVariantHandle
    Ord, Int -> GVariantHandle -> ShowS
    [GVariantHandle] -> ShowS
    GVariantHandle -> [Char]
    (Int -> GVariantHandle -> ShowS)
    -> (GVariantHandle -> [Char])
    -> ([GVariantHandle] -> ShowS)
    -> Show GVariantHandle
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> GVariantHandle -> ShowS
    showsPrec :: Int -> GVariantHandle -> ShowS
    $cshow :: GVariantHandle -> [Char]
    show :: GVariantHandle -> [Char]
    $cshowList :: [GVariantHandle] -> ShowS
    showList :: [GVariantHandle] -> ShowS
    Show)

    instance IsGVariant GVariantHandle where
        toGVariant :: GVariantHandle -> IO GVariant
    toGVariant (GVariantHandle Int32
    h) = Int32 -> IO GVariant
    gvariantFromHandle Int32
    h
        fromGVariant :: GVariant -> IO (Maybe GVariantHandle)
    fromGVariant = GVariant -> IO (Maybe Int32)
    gvariantToHandle (GVariant -> IO (Maybe Int32))
    -> (Maybe Int32 -> IO (Maybe GVariantHandle))
    -> GVariant
    -> IO (Maybe GVariantHandle)
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Maybe GVariantHandle -> IO (Maybe GVariantHandle)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe GVariantHandle -> IO (Maybe GVariantHandle))
    -> (Maybe Int32 -> Maybe GVariantHandle)
    -> Maybe Int32
    -> IO (Maybe GVariantHandle)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Int32 -> GVariantHandle
    GVariantHandle (Int32 -> GVariantHandle) -> Maybe Int32 -> Maybe GVariantHandle
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>))
        toGVariantFormatString :: GVariantHandle -> Text
    toGVariantFormatString GVariantHandle
    _ = Text
    "h"
    instance IsGVariantBasicType GVariantHandle

    foreign import ccall "g_variant_new_handle" new_handle
        :: Int32 -> IO (Ptr GVariant)
    {-# LINE 438 "Data/GI/Base/GVariant.hsc" #-}

    -- | Convert a DBus handle (an 'Int32') into a 'GVariant'.
    gvariantFromHandle :: Int32 -> IO GVariant
    gvariantFromHandle :: Int32 -> IO GVariant
    gvariantFromHandle Int32
    h = (Int32 -> IO (Ptr GVariant)
    new_handle (Int32 -> IO (Ptr GVariant))
    -> (Int32 -> Int32) -> Int32 -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int32 -> Int32
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) Int32
    h IO (Ptr GVariant) -> (Ptr GVariant -> IO GVariant) -> IO GVariant
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_handle" get_handle
        :: Ptr GVariant -> IO Int32
    {-# LINE 445 "Data/GI/Base/GVariant.hsc" #-}

    -- | Extract the DBus handle (an 'Int32') inside a 'GVariant'.
    gvariantToHandle :: GVariant -> IO (Maybe Int32)
    gvariantToHandle :: GVariant -> IO (Maybe Int32)
    gvariantToHandle =
      Text -> (Ptr GVariant -> IO Int32) -> GVariant -> IO (Maybe Int32)
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType (GVariantHandle -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (GVariantHandle
    forall a. HasCallStack => a
    undefined :: GVariantHandle)) ((Ptr GVariant -> IO Int32) -> GVariant -> IO (Maybe Int32))
    -> (Ptr GVariant -> IO Int32) -> GVariant -> IO (Maybe Int32)
    forall a b. (a -> b) -> a -> b
    $
                       Ptr GVariant -> IO Int32
    get_handle (Ptr GVariant -> IO Int32)
    -> (Int32 -> IO Int32) -> Ptr GVariant -> IO Int32
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Int32 -> IO Int32
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Int32 -> IO Int32) -> (Int32 -> Int32) -> Int32 -> IO Int32
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int32 -> Int32
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral)

    instance IsGVariant Double where
        toGVariant :: Double -> IO GVariant
    toGVariant = Double -> IO GVariant
    gvariantFromDouble
        fromGVariant :: GVariant -> IO (Maybe Double)
    fromGVariant = GVariant -> IO (Maybe Double)
    gvariantToDouble
        toGVariantFormatString :: Double -> Text
    toGVariantFormatString Double
    _ = Text
    "d"
    instance IsGVariantBasicType Double

    foreign import ccall "g_variant_new_double" new_double
        :: Double -> IO (Ptr GVariant)
    {-# LINE 460 "Data/GI/Base/GVariant.hsc" #-}

    gvariantFromDouble :: Double -> IO GVariant
    gvariantFromDouble :: Double -> IO GVariant
    gvariantFromDouble = (Double -> IO (Ptr GVariant)
    new_double (Double -> IO (Ptr GVariant))
    -> (Double -> Double) -> Double -> IO (Ptr GVariant)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Double -> Double
    forall a b. (Real a, Fractional b) => a -> b
    realToFrac) (Double -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Double -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_double" get_double
        :: Ptr GVariant -> IO Double
    {-# LINE 466 "Data/GI/Base/GVariant.hsc" #-}

    gvariantToDouble :: GVariant -> IO (Maybe Double)
    gvariantToDouble :: GVariant -> IO (Maybe Double)
    gvariantToDouble = (Ptr GVariant -> IO Double) -> GVariant -> IO (Maybe Double)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Double) -> GVariant -> IO (Maybe Double))
    -> (Ptr GVariant -> IO Double) -> GVariant -> IO (Maybe Double)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO Double
    get_double (Ptr GVariant -> IO Double)
    -> (Double -> IO Double) -> Ptr GVariant -> IO Double
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Double -> IO Double
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Double -> IO Double) -> (Double -> Double) -> Double -> IO Double
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Double -> Double
    forall a b. (Real a, Fractional b) => a -> b
    realToFrac)

    instance IsGVariant Text where
        toGVariant :: Text -> IO GVariant
    toGVariant = Text -> IO GVariant
    gvariantFromText
        fromGVariant :: GVariant -> IO (Maybe Text)
    fromGVariant = GVariant -> IO (Maybe Text)
    gvariantToText
        toGVariantFormatString :: Text -> Text
    toGVariantFormatString Text
    _ = Text
    "s"
    instance IsGVariantBasicType Text

    foreign import ccall "g_variant_get_string" _get_string
        :: Ptr GVariant -> Ptr Word64 -> IO CString
    {-# LINE 478 "Data/GI/Base/GVariant.hsc" #-}

    get_string :: Ptr GVariant -> IO CString
    get_string :: Ptr GVariant -> IO CString
    get_string Ptr GVariant
    v = Ptr GVariant -> Ptr Word64 -> IO CString
    _get_string Ptr GVariant
    v Ptr Word64
    forall a. Ptr a
    nullPtr

    -- | Decode an UTF-8 encoded string 'GVariant' into 'Text'.
    gvariantToText :: GVariant -> IO (Maybe Text)
    gvariantToText :: GVariant -> IO (Maybe Text)
    gvariantToText = (Ptr GVariant -> IO Text) -> GVariant -> IO (Maybe Text)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO Text) -> GVariant -> IO (Maybe Text))
    -> (Ptr GVariant -> IO Text) -> GVariant -> IO (Maybe Text)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO CString
    get_string (Ptr GVariant -> IO CString)
    -> (CString -> IO Text) -> Ptr GVariant -> IO Text
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> HasCallStack => CString -> IO Text
    CString -> IO Text
    cstringToText

    foreign import ccall "g_variant_new_take_string" take_string
        :: CString -> IO (Ptr GVariant)

    -- | Encode a 'Text' into an UTF-8 encoded string 'GVariant'.
    gvariantFromText :: Text -> IO GVariant
    gvariantFromText :: Text -> IO GVariant
    gvariantFromText = Text -> IO CString
    textToCString (Text -> IO CString)
    -> (CString -> IO GVariant) -> Text -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> CString -> IO (Ptr GVariant)
    take_string (CString -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> CString -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_is_object_path" g_variant_is_object_path ::
        CString -> IO Int32
    {-# LINE 495 "Data/GI/Base/GVariant.hsc" #-}

    -- | An object representing a DBus object path, which is a particular
    -- type of 'GVariant' too. (Just a string with some specific
    -- requirements.) In order to construct/deconstruct a
    -- 'GVariantObjectPath' one can use 'newGVariantObjectPath'
    -- and 'gvariantObjectPathToText'.
    newtype GVariantObjectPath = GVariantObjectPath Text
        deriving (Eq GVariantObjectPath
    Eq GVariantObjectPath =>
    (GVariantObjectPath -> GVariantObjectPath -> Ordering)
    -> (GVariantObjectPath -> GVariantObjectPath -> Bool)
    -> (GVariantObjectPath -> GVariantObjectPath -> Bool)
    -> (GVariantObjectPath -> GVariantObjectPath -> Bool)
    -> (GVariantObjectPath -> GVariantObjectPath -> Bool)
    -> (GVariantObjectPath -> GVariantObjectPath -> GVariantObjectPath)
    -> (GVariantObjectPath -> GVariantObjectPath -> GVariantObjectPath)
    -> Ord GVariantObjectPath
    GVariantObjectPath -> GVariantObjectPath -> Bool
    GVariantObjectPath -> GVariantObjectPath -> Ordering
    GVariantObjectPath -> GVariantObjectPath -> GVariantObjectPath
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: GVariantObjectPath -> GVariantObjectPath -> Ordering
    compare :: GVariantObjectPath -> GVariantObjectPath -> Ordering
    $c< :: GVariantObjectPath -> GVariantObjectPath -> Bool
    < :: GVariantObjectPath -> GVariantObjectPath -> Bool
    $c<= :: GVariantObjectPath -> GVariantObjectPath -> Bool
    <= :: GVariantObjectPath -> GVariantObjectPath -> Bool
    $c> :: GVariantObjectPath -> GVariantObjectPath -> Bool
    > :: GVariantObjectPath -> GVariantObjectPath -> Bool
    $c>= :: GVariantObjectPath -> GVariantObjectPath -> Bool
    >= :: GVariantObjectPath -> GVariantObjectPath -> Bool
    $cmax :: GVariantObjectPath -> GVariantObjectPath -> GVariantObjectPath
    max :: GVariantObjectPath -> GVariantObjectPath -> GVariantObjectPath
    $cmin :: GVariantObjectPath -> GVariantObjectPath -> GVariantObjectPath
    min :: GVariantObjectPath -> GVariantObjectPath -> GVariantObjectPath
    Ord, GVariantObjectPath -> GVariantObjectPath -> Bool
    (GVariantObjectPath -> GVariantObjectPath -> Bool)
    -> (GVariantObjectPath -> GVariantObjectPath -> Bool)
    -> Eq GVariantObjectPath
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: GVariantObjectPath -> GVariantObjectPath -> Bool
    == :: GVariantObjectPath -> GVariantObjectPath -> Bool
    $c/= :: GVariantObjectPath -> GVariantObjectPath -> Bool
    /= :: GVariantObjectPath -> GVariantObjectPath -> Bool
    Eq, Int -> GVariantObjectPath -> ShowS
    [GVariantObjectPath] -> ShowS
    GVariantObjectPath -> [Char]
    (Int -> GVariantObjectPath -> ShowS)
    -> (GVariantObjectPath -> [Char])
    -> ([GVariantObjectPath] -> ShowS)
    -> Show GVariantObjectPath
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> GVariantObjectPath -> ShowS
    showsPrec :: Int -> GVariantObjectPath -> ShowS
    $cshow :: GVariantObjectPath -> [Char]
    show :: GVariantObjectPath -> [Char]
    $cshowList :: [GVariantObjectPath] -> ShowS
    showList :: [GVariantObjectPath] -> ShowS
    Show)

    -- | Try to construct a DBus object path. If the passed string is not
    -- a valid object path 'Nothing' will be returned.
    newGVariantObjectPath :: Text -> Maybe GVariantObjectPath
    newGVariantObjectPath :: Text -> Maybe GVariantObjectPath
    newGVariantObjectPath Text
    p = IO (Maybe GVariantObjectPath) -> Maybe GVariantObjectPath
    forall a. IO a -> a
    unsafePerformIO (IO (Maybe GVariantObjectPath) -> Maybe GVariantObjectPath)
    -> IO (Maybe GVariantObjectPath) -> Maybe GVariantObjectPath
    forall a b. (a -> b) -> a -> b
    $
       Text
    -> (CString -> IO (Maybe GVariantObjectPath))
    -> IO (Maybe GVariantObjectPath)
    forall a. Text -> (CString -> IO a) -> IO a
    withTextCString Text
    p ((CString -> IO (Maybe GVariantObjectPath))
     -> IO (Maybe GVariantObjectPath))
    -> (CString -> IO (Maybe GVariantObjectPath))
    -> IO (Maybe GVariantObjectPath)
    forall a b. (a -> b) -> a -> b
    $ \CString
    cstr -> do
         isObjectPath <- Int -> Bool
    forall a. Enum a => Int -> a
    toEnum (Int -> Bool) -> (Int32 -> Int) -> Int32 -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int32 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int32 -> Bool) -> IO Int32 -> IO Bool
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> CString -> IO Int32
    g_variant_is_object_path CString
    cstr
         if isObjectPath
         then return $ Just (GVariantObjectPath p)
         else return Nothing

    -- | Return the 'Text' representation of a 'GVariantObjectPath'.
    gvariantObjectPathToText :: GVariantObjectPath -> Text
    gvariantObjectPathToText :: GVariantObjectPath -> Text
    gvariantObjectPathToText (GVariantObjectPath Text
    p) = Text
    p

    instance IsGVariant GVariantObjectPath where
        toGVariant :: GVariantObjectPath -> IO GVariant
    toGVariant = GVariantObjectPath -> IO GVariant
    gvariantFromObjectPath
        fromGVariant :: GVariant -> IO (Maybe GVariantObjectPath)
    fromGVariant = GVariant -> IO (Maybe Text)
    gvariantToObjectPath (GVariant -> IO (Maybe Text))
    -> (Maybe Text -> IO (Maybe GVariantObjectPath))
    -> GVariant
    -> IO (Maybe GVariantObjectPath)
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Maybe GVariantObjectPath -> IO (Maybe GVariantObjectPath)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe GVariantObjectPath -> IO (Maybe GVariantObjectPath))
    -> (Maybe Text -> Maybe GVariantObjectPath)
    -> Maybe Text
    -> IO (Maybe GVariantObjectPath)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> GVariantObjectPath
    GVariantObjectPath (Text -> GVariantObjectPath)
    -> Maybe Text -> Maybe GVariantObjectPath
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>)
        toGVariantFormatString :: GVariantObjectPath -> Text
    toGVariantFormatString GVariantObjectPath
    _ = Text
    "o"
    instance IsGVariantBasicType GVariantObjectPath

    foreign import ccall "g_variant_new_object_path" new_object_path
        :: CString -> IO (Ptr GVariant)

    -- | Construct a 'GVariant' containing an object path. In order to
    -- build a 'GVariantObjectPath' value see 'newGVariantObjectPath'.
    gvariantFromObjectPath :: GVariantObjectPath -> IO GVariant
    gvariantFromObjectPath :: GVariantObjectPath -> IO GVariant
    gvariantFromObjectPath (GVariantObjectPath Text
    p) =
        Text -> (CString -> IO GVariant) -> IO GVariant
    forall a. Text -> (CString -> IO a) -> IO a
    withTextCString Text
    p ((CString -> IO GVariant) -> IO GVariant)
    -> (CString -> IO GVariant) -> IO GVariant
    forall a b. (a -> b) -> a -> b
    $ CString -> IO (Ptr GVariant)
    new_object_path (CString -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> CString -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    -- | Extract a 'GVariantObjectPath' from a 'GVariant', represented as
    -- its underlying 'Text' representation.
    gvariantToObjectPath :: GVariant -> IO (Maybe Text)
    gvariantToObjectPath :: GVariant -> IO (Maybe Text)
    gvariantToObjectPath =
        Text -> (Ptr GVariant -> IO Text) -> GVariant -> IO (Maybe Text)
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType (GVariantObjectPath -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (GVariantObjectPath
    forall a. HasCallStack => a
    undefined :: GVariantObjectPath))
                             (Ptr GVariant -> IO CString
    get_string (Ptr GVariant -> IO CString)
    -> (CString -> IO Text) -> Ptr GVariant -> IO Text
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> HasCallStack => CString -> IO Text
    CString -> IO Text
    cstringToText)

    foreign import ccall "g_variant_is_signature" g_variant_is_signature ::
        CString -> IO Int32
    {-# LINE 542 "Data/GI/Base/GVariant.hsc" #-}

    -- | An object representing a DBus signature, which is a particular
    -- type of 'GVariant' too. (Just a string with some specific
    -- requirements.) In order to construct/deconstruct a
    -- 'GVariantSignature' one can use 'newGVariantSignature' and
    -- 'gvariantSignatureToText'.
    newtype GVariantSignature = GVariantSignature Text
        deriving (Eq GVariantSignature
    Eq GVariantSignature =>
    (GVariantSignature -> GVariantSignature -> Ordering)
    -> (GVariantSignature -> GVariantSignature -> Bool)
    -> (GVariantSignature -> GVariantSignature -> Bool)
    -> (GVariantSignature -> GVariantSignature -> Bool)
    -> (GVariantSignature -> GVariantSignature -> Bool)
    -> (GVariantSignature -> GVariantSignature -> GVariantSignature)
    -> (GVariantSignature -> GVariantSignature -> GVariantSignature)
    -> Ord GVariantSignature
    GVariantSignature -> GVariantSignature -> Bool
    GVariantSignature -> GVariantSignature -> Ordering
    GVariantSignature -> GVariantSignature -> GVariantSignature
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: GVariantSignature -> GVariantSignature -> Ordering
    compare :: GVariantSignature -> GVariantSignature -> Ordering
    $c< :: GVariantSignature -> GVariantSignature -> Bool
    < :: GVariantSignature -> GVariantSignature -> Bool
    $c<= :: GVariantSignature -> GVariantSignature -> Bool
    <= :: GVariantSignature -> GVariantSignature -> Bool
    $c> :: GVariantSignature -> GVariantSignature -> Bool
    > :: GVariantSignature -> GVariantSignature -> Bool
    $c>= :: GVariantSignature -> GVariantSignature -> Bool
    >= :: GVariantSignature -> GVariantSignature -> Bool
    $cmax :: GVariantSignature -> GVariantSignature -> GVariantSignature
    max :: GVariantSignature -> GVariantSignature -> GVariantSignature
    $cmin :: GVariantSignature -> GVariantSignature -> GVariantSignature
    min :: GVariantSignature -> GVariantSignature -> GVariantSignature
    Ord, GVariantSignature -> GVariantSignature -> Bool
    (GVariantSignature -> GVariantSignature -> Bool)
    -> (GVariantSignature -> GVariantSignature -> Bool)
    -> Eq GVariantSignature
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: GVariantSignature -> GVariantSignature -> Bool
    == :: GVariantSignature -> GVariantSignature -> Bool
    $c/= :: GVariantSignature -> GVariantSignature -> Bool
    /= :: GVariantSignature -> GVariantSignature -> Bool
    Eq, Int -> GVariantSignature -> ShowS
    [GVariantSignature] -> ShowS
    GVariantSignature -> [Char]
    (Int -> GVariantSignature -> ShowS)
    -> (GVariantSignature -> [Char])
    -> ([GVariantSignature] -> ShowS)
    -> Show GVariantSignature
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> GVariantSignature -> ShowS
    showsPrec :: Int -> GVariantSignature -> ShowS
    $cshow :: GVariantSignature -> [Char]
    show :: GVariantSignature -> [Char]
    $cshowList :: [GVariantSignature] -> ShowS
    showList :: [GVariantSignature] -> ShowS
    Show)

    -- | Try to construct a DBus object path. If the passed string is not
    -- a valid DBus signature 'Nothing' will be returned.
    newGVariantSignature :: Text -> Maybe GVariantSignature
    newGVariantSignature :: Text -> Maybe GVariantSignature
    newGVariantSignature Text
    p = IO (Maybe GVariantSignature) -> Maybe GVariantSignature
    forall a. IO a -> a
    unsafePerformIO (IO (Maybe GVariantSignature) -> Maybe GVariantSignature)
    -> IO (Maybe GVariantSignature) -> Maybe GVariantSignature
    forall a b. (a -> b) -> a -> b
    $
       Text
    -> (CString -> IO (Maybe GVariantSignature))
    -> IO (Maybe GVariantSignature)
    forall a. Text -> (CString -> IO a) -> IO a
    withTextCString Text
    p ((CString -> IO (Maybe GVariantSignature))
     -> IO (Maybe GVariantSignature))
    -> (CString -> IO (Maybe GVariantSignature))
    -> IO (Maybe GVariantSignature)
    forall a b. (a -> b) -> a -> b
    $ \CString
    cstr -> do
         isSignature <- Int -> Bool
    forall a. Enum a => Int -> a
    toEnum (Int -> Bool) -> (Int32 -> Int) -> Int32 -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int32 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int32 -> Bool) -> IO Int32 -> IO Bool
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> CString -> IO Int32
    g_variant_is_signature CString
    cstr
         if isSignature
         then return $ Just (GVariantSignature p)
         else return Nothing

    -- | Return the 'Text' representation of a 'GVariantSignature'.
    gvariantSignatureToText :: GVariantSignature -> Text
    gvariantSignatureToText :: GVariantSignature -> Text
    gvariantSignatureToText (GVariantSignature Text
    p) = Text
    p

    instance IsGVariant GVariantSignature where
        toGVariant :: GVariantSignature -> IO GVariant
    toGVariant = GVariantSignature -> IO GVariant
    gvariantFromSignature
        fromGVariant :: GVariant -> IO (Maybe GVariantSignature)
    fromGVariant = GVariant -> IO (Maybe Text)
    gvariantToSignature (GVariant -> IO (Maybe Text))
    -> (Maybe Text -> IO (Maybe GVariantSignature))
    -> GVariant
    -> IO (Maybe GVariantSignature)
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Maybe GVariantSignature -> IO (Maybe GVariantSignature)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe GVariantSignature -> IO (Maybe GVariantSignature))
    -> (Maybe Text -> Maybe GVariantSignature)
    -> Maybe Text
    -> IO (Maybe GVariantSignature)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> GVariantSignature
    GVariantSignature (Text -> GVariantSignature)
    -> Maybe Text -> Maybe GVariantSignature
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>)
        toGVariantFormatString :: GVariantSignature -> Text
    toGVariantFormatString GVariantSignature
    _ = Text
    "g"
    instance IsGVariantBasicType GVariantSignature

    foreign import ccall "g_variant_new_signature" new_signature
        :: CString -> IO (Ptr GVariant)

    -- | Construct a 'GVariant' containing an DBus signature. In order to
    -- build a 'GVariantSignature' value see 'newGVariantSignature'.
    gvariantFromSignature :: GVariantSignature -> IO GVariant
    gvariantFromSignature :: GVariantSignature -> IO GVariant
    gvariantFromSignature (GVariantSignature Text
    p) =
        Text -> (CString -> IO GVariant) -> IO GVariant
    forall a. Text -> (CString -> IO a) -> IO a
    withTextCString Text
    p ((CString -> IO GVariant) -> IO GVariant)
    -> (CString -> IO GVariant) -> IO GVariant
    forall a b. (a -> b) -> a -> b
    $ CString -> IO (Ptr GVariant)
    new_signature (CString -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> CString -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    -- | Extract a 'GVariantSignature' from a 'GVariant', represented as
    -- 'Text'.
    gvariantToSignature :: GVariant -> IO (Maybe Text)
    gvariantToSignature :: GVariant -> IO (Maybe Text)
    gvariantToSignature =
        Text -> (Ptr GVariant -> IO Text) -> GVariant -> IO (Maybe Text)
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType (GVariantSignature -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (GVariantSignature
    forall a. HasCallStack => a
    undefined :: GVariantSignature))
                             ((Ptr GVariant -> IO Text) -> GVariant -> IO (Maybe Text))
    -> (Ptr GVariant -> IO Text) -> GVariant -> IO (Maybe Text)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO CString
    get_string (Ptr GVariant -> IO CString)
    -> (CString -> IO Text) -> Ptr GVariant -> IO Text
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> HasCallStack => CString -> IO Text
    CString -> IO Text
    cstringToText

    instance IsGVariant GVariant where
        toGVariant :: GVariant -> IO GVariant
    toGVariant = GVariant -> IO GVariant
    gvariantFromGVariant
        fromGVariant :: GVariant -> IO (Maybe GVariant)
    fromGVariant = GVariant -> IO (Maybe GVariant)
    gvariantToGVariant
        toGVariantFormatString :: GVariant -> Text
    toGVariantFormatString GVariant
    _ = Text
    "v"

    foreign import ccall "g_variant_new_variant" new_variant
        :: Ptr GVariant -> IO (Ptr GVariant)

    -- | Box a 'GVariant' inside another 'GVariant'.
    gvariantFromGVariant :: GVariant -> IO GVariant
    gvariantFromGVariant :: GVariant -> IO GVariant
    gvariantFromGVariant GVariant
    v = GVariant -> (Ptr GVariant -> IO GVariant) -> IO GVariant
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr GVariant
    v ((Ptr GVariant -> IO GVariant) -> IO GVariant)
    -> (Ptr GVariant -> IO GVariant) -> IO GVariant
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO (Ptr GVariant)
    new_variant (Ptr GVariant -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Ptr GVariant -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    foreign import ccall "g_variant_get_variant" get_variant
        :: Ptr GVariant -> IO (Ptr GVariant)

    -- | Unbox a 'GVariant' contained inside another 'GVariant'.
    gvariantToGVariant :: GVariant -> IO (Maybe GVariant)
    gvariantToGVariant :: GVariant -> IO (Maybe GVariant)
    gvariantToGVariant = (Ptr GVariant -> IO GVariant) -> GVariant -> IO (Maybe GVariant)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck ((Ptr GVariant -> IO GVariant) -> GVariant -> IO (Maybe GVariant))
    -> (Ptr GVariant -> IO GVariant) -> GVariant -> IO (Maybe GVariant)
    forall a b. (a -> b) -> a -> b
    $ Ptr GVariant -> IO (Ptr GVariant)
    get_variant (Ptr GVariant -> IO (Ptr GVariant))
    -> (Ptr GVariant -> IO GVariant) -> Ptr GVariant -> IO GVariant
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    instance IsGVariant ByteString where
        toGVariant :: ByteString -> IO GVariant
    toGVariant = ByteString -> IO GVariant
    gvariantFromBytestring
        fromGVariant :: GVariant -> IO (Maybe ByteString)
    fromGVariant = GVariant -> IO (Maybe ByteString)
    gvariantToBytestring
        toGVariantFormatString :: ByteString -> Text
    toGVariantFormatString ByteString
    _ = Text
    "ay"

    foreign import ccall "g_variant_get_bytestring" get_bytestring
        :: Ptr GVariant -> IO CString

    -- | Extract a zero terminated list of bytes into a 'ByteString'.
    gvariantToBytestring :: GVariant -> IO (Maybe ByteString)
    gvariantToBytestring :: GVariant -> IO (Maybe ByteString)
    gvariantToBytestring = (Ptr GVariant -> IO ByteString)
    -> GVariant -> IO (Maybe ByteString)
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck (Ptr GVariant -> IO CString
    get_bytestring (Ptr GVariant -> IO CString)
    -> (CString -> IO ByteString) -> Ptr GVariant -> IO ByteString
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> HasCallStack => CString -> IO ByteString
    CString -> IO ByteString
    cstringToByteString)

    foreign import ccall "g_variant_new_bytestring" new_bytestring
        :: CString -> IO (Ptr GVariant)

    -- | Encode a 'ByteString' into a list of bytes 'GVariant'.
    gvariantFromBytestring :: ByteString -> IO GVariant
    gvariantFromBytestring :: ByteString -> IO GVariant
    gvariantFromBytestring ByteString
    bs = Ptr GVariant -> IO GVariant
    wrapGVariantPtr (Ptr GVariant -> IO GVariant) -> IO (Ptr GVariant) -> IO GVariant
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<<
                                  ByteString -> (CString -> IO (Ptr GVariant)) -> IO (Ptr GVariant)
    forall a. ByteString -> (CString -> IO a) -> IO a
    B.useAsCString ByteString
    bs CString -> IO (Ptr GVariant)
    new_bytestring

    foreign import ccall "g_variant_n_children" g_variant_n_children
        :: Ptr GVariant -> IO Word64
    {-# LINE 629 "Data/GI/Base/GVariant.hsc" #-}

    foreign import ccall "g_variant_get_child_value" g_variant_get_child_value
        :: Ptr GVariant -> Word64 -> IO (Ptr GVariant)
    {-# LINE 632 "Data/GI/Base/GVariant.hsc" #-}

    -- No type checking is done here, it is assumed that the caller knows
    -- that the passed variant is indeed of a container type.
    gvariant_get_children :: (Ptr GVariant) -> IO [GVariant]
    gvariant_get_children :: Ptr GVariant -> IO [GVariant]
    gvariant_get_children Ptr GVariant
    vptr = do
          n_children <- Ptr GVariant -> IO Word64
    g_variant_n_children Ptr GVariant
    vptr
          -- n_children is an unsigned type (Word64 in 64 bit
          -- architectures), so if it is 0 and we substract one we would
          -- wrap around to 2^64-1.
          if n_children /= 0
            then mapM ((g_variant_get_child_value vptr) >=> wrapGVariantPtr)
                 [0..(n_children-1)]
            else return []

    -- No type checking is done here, it is assumed that the caller knows
    -- that the passed variant is indeed of a container type with at least
    -- one child.
    gvariant_get_child :: (Ptr GVariant) -> IO GVariant
    gvariant_get_child :: Ptr GVariant -> IO GVariant
    gvariant_get_child Ptr GVariant
    vptr = Ptr GVariant -> Word64 -> IO (Ptr GVariant)
    g_variant_get_child_value Ptr GVariant
    vptr Word64
    0 IO (Ptr GVariant) -> (Ptr GVariant -> IO GVariant) -> IO GVariant
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    instance IsGVariant a => IsGVariant (Maybe a) where
        toGVariant :: Maybe a -> IO GVariant
    toGVariant   = Maybe a -> IO GVariant
    forall a. IsGVariant a => Maybe a -> IO GVariant
    gvariantFromMaybe
        fromGVariant :: GVariant -> IO (Maybe (Maybe a))
    fromGVariant = GVariant -> IO (Maybe (Maybe a))
    forall a. IsGVariant a => GVariant -> IO (Maybe (Maybe a))
    gvariantToMaybe
        toGVariantFormatString :: Maybe a -> Text
    toGVariantFormatString Maybe a
    _ = Text
    "m" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)

    foreign import ccall "g_variant_new_maybe" g_variant_new_maybe ::
        Ptr GVariantType -> Ptr GVariant -> IO (Ptr GVariant)

    -- | Convert a 'Maybe' value into a corresponding 'GVariant' of maybe
    -- type.
    gvariantFromMaybe :: forall a. IsGVariant a => Maybe a -> IO GVariant
    gvariantFromMaybe :: forall a. IsGVariant a => Maybe a -> IO GVariant
    gvariantFromMaybe Maybe a
    m = do
      let fmt :: Text
    fmt = a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)
      Text -> (Ptr GVariantType -> IO GVariant) -> IO GVariant
    forall a. Text -> (Ptr GVariantType -> IO a) -> IO a
    withGVariantType Text
    fmt ((Ptr GVariantType -> IO GVariant) -> IO GVariant)
    -> (Ptr GVariantType -> IO GVariant) -> IO GVariant
    forall a b. (a -> b) -> a -> b
    $ \Ptr GVariantType
    tPtr ->
          case Maybe a
    m of
            Just a
    child -> do
                   childVariant <- a -> IO GVariant
    forall a. IsGVariant a => a -> IO GVariant
    toGVariant a
    child
                   withManagedPtr childVariant
                          (g_variant_new_maybe tPtr >=> wrapGVariantPtr)
            Maybe a
    Nothing -> Ptr GVariantType -> Ptr GVariant -> IO (Ptr GVariant)
    g_variant_new_maybe Ptr GVariantType
    tPtr Ptr GVariant
    forall a. Ptr a
    nullPtr IO (Ptr GVariant) -> (Ptr GVariant -> IO GVariant) -> IO GVariant
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    -- | Try to decode a maybe 'GVariant' into the corresponding 'Maybe'
    -- type. If the conversion is successful this returns @Just x@, where
    -- @x@ itself is of 'Maybe' type. So, in particular, @Just Nothing@
    -- indicates a successful call, and means that the GVariant of maybe
    -- type was empty.
    gvariantToMaybe :: forall a. IsGVariant a => GVariant -> IO (Maybe (Maybe a))
    gvariantToMaybe :: forall a. IsGVariant a => GVariant -> IO (Maybe (Maybe a))
    gvariantToMaybe GVariant
    v = do
      let fmt :: Text
    fmt = Maybe a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (Maybe a
    forall a. HasCallStack => a
    undefined :: Maybe a)
      Text
    -> (Ptr GVariant -> IO [GVariant])
    -> GVariant
    -> IO (Maybe [GVariant])
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType Text
    fmt Ptr GVariant -> IO [GVariant]
    gvariant_get_children GVariant
    v IO (Maybe [GVariant])
    -> (Maybe [GVariant] -> IO (Maybe (Maybe a)))
    -> IO (Maybe (Maybe a))
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>=
       \case
         Just [] -> Maybe (Maybe a) -> IO (Maybe (Maybe a))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe a -> Maybe (Maybe a)
    forall a. a -> Maybe a
    Just Maybe a
    forall a. Maybe a
    Nothing)
         Just [GVariant
    child] -> GVariant -> IO (Maybe a)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    child IO (Maybe a)
    -> (Maybe a -> IO (Maybe (Maybe a))) -> IO (Maybe (Maybe a))
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>=
                         \case
                           Maybe a
    Nothing -> Maybe (Maybe a) -> IO (Maybe (Maybe a))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (Maybe a)
    forall a. Maybe a
    Nothing
                           Just a
    result -> Maybe (Maybe a) -> IO (Maybe (Maybe a))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe a -> Maybe (Maybe a)
    forall a. a -> Maybe a
    Just (a -> Maybe a
    forall a. a -> Maybe a
    Just a
    result))
         Just [GVariant]
    _ -> [Char] -> IO (Maybe (Maybe a))
    forall a. HasCallStack => [Char] -> a
    error [Char]
    "gvariantToMaybe :: the impossible happened, this is a bug."
         Maybe [GVariant]
    Nothing -> Maybe (Maybe a) -> IO (Maybe (Maybe a))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (Maybe a)
    forall a. Maybe a
    Nothing

    -- | A DictEntry 'GVariant' is isomorphic to a two-tuple. Wrapping the
    -- values into a 'GVariantDictentry' allows the 'IsGVariant' instance
    -- to do the right thing.
    data GVariantDictEntry key value = GVariantDictEntry key value
                                       deriving (GVariantDictEntry key value -> GVariantDictEntry key value -> Bool
    (GVariantDictEntry key value
     -> GVariantDictEntry key value -> Bool)
    -> (GVariantDictEntry key value
        -> GVariantDictEntry key value -> Bool)
    -> Eq (GVariantDictEntry key value)
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    forall key value.
    (Eq key, Eq value) =>
    GVariantDictEntry key value -> GVariantDictEntry key value -> Bool
    $c== :: forall key value.
    (Eq key, Eq value) =>
    GVariantDictEntry key value -> GVariantDictEntry key value -> Bool
    == :: GVariantDictEntry key value -> GVariantDictEntry key value -> Bool
    $c/= :: forall key value.
    (Eq key, Eq value) =>
    GVariantDictEntry key value -> GVariantDictEntry key value -> Bool
    /= :: GVariantDictEntry key value -> GVariantDictEntry key value -> Bool
    Eq, Int -> GVariantDictEntry key value -> ShowS
    [GVariantDictEntry key value] -> ShowS
    GVariantDictEntry key value -> [Char]
    (Int -> GVariantDictEntry key value -> ShowS)
    -> (GVariantDictEntry key value -> [Char])
    -> ([GVariantDictEntry key value] -> ShowS)
    -> Show (GVariantDictEntry key value)
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    forall key value.
    (Show key, Show value) =>
    Int -> GVariantDictEntry key value -> ShowS
    forall key value.
    (Show key, Show value) =>
    [GVariantDictEntry key value] -> ShowS
    forall key value.
    (Show key, Show value) =>
    GVariantDictEntry key value -> [Char]
    $cshowsPrec :: forall key value.
    (Show key, Show value) =>
    Int -> GVariantDictEntry key value -> ShowS
    showsPrec :: Int -> GVariantDictEntry key value -> ShowS
    $cshow :: forall key value.
    (Show key, Show value) =>
    GVariantDictEntry key value -> [Char]
    show :: GVariantDictEntry key value -> [Char]
    $cshowList :: forall key value.
    (Show key, Show value) =>
    [GVariantDictEntry key value] -> ShowS
    showList :: [GVariantDictEntry key value] -> ShowS
    Show)

    instance (IsGVariant a, IsGVariantBasicType a, IsGVariant b) =>
        IsGVariant (GVariantDictEntry a b) where
            toGVariant :: GVariantDictEntry a b -> IO GVariant
    toGVariant (GVariantDictEntry a
    key b
    value) =
                a -> b -> IO GVariant
    forall key value.
    (IsGVariant key, IsGVariantBasicType key, IsGVariant value) =>
    key -> value -> IO GVariant
    gvariantFromDictEntry a
    key b
    value
            fromGVariant :: GVariant -> IO (Maybe (GVariantDictEntry a b))
    fromGVariant GVariant
    gv =
                (((a -> b -> GVariantDictEntry a b)
    -> (a, b) -> GVariantDictEntry a b
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry a -> b -> GVariantDictEntry a b
    forall key value. key -> value -> GVariantDictEntry key value
    GVariantDictEntry) ((a, b) -> GVariantDictEntry a b)
    -> Maybe (a, b) -> Maybe (GVariantDictEntry a b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>) (Maybe (a, b) -> Maybe (GVariantDictEntry a b))
    -> IO (Maybe (a, b)) -> IO (Maybe (GVariantDictEntry a b))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> GVariant -> IO (Maybe (a, b))
    forall key value.
    (IsGVariant key, IsGVariantBasicType key, IsGVariant value) =>
    GVariant -> IO (Maybe (key, value))
    gvariantToDictEntry GVariant
    gv
            toGVariantFormatString :: GVariantDictEntry a b -> Text
    toGVariantFormatString GVariantDictEntry a b
    _ = Text
    "{"
                                       Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)
                                       Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> b -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (b
    forall a. HasCallStack => a
    undefined :: b)
                                       Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "}"

    foreign import ccall "g_variant_new_dict_entry" g_variant_new_dict_entry ::
        Ptr GVariant -> Ptr GVariant -> IO (Ptr GVariant)

    -- | Construct a 'GVariant' of type DictEntry from the given 'key' and
    -- 'value'. The key must be a basic 'GVariant' type, i.e. not a
    -- container. This is determined by whether it belongs to the
    -- 'IsGVariantBasicType' typeclass. On the other hand 'value' is an
    -- arbitrary 'GVariant', and in particular it can be a container type.
    gvariantFromDictEntry :: (IsGVariant key, IsGVariantBasicType key,
                              IsGVariant value) =>
                             key -> value -> IO GVariant
    gvariantFromDictEntry :: forall key value.
    (IsGVariant key, IsGVariantBasicType key, IsGVariant value) =>
    key -> value -> IO GVariant
    gvariantFromDictEntry key
    key value
    value = do
      keyVar <- key -> IO GVariant
    forall a. IsGVariant a => a -> IO GVariant
    toGVariant key
    key
      valueVar <- toGVariant value
      withManagedPtr keyVar $ \Ptr GVariant
    keyPtr ->
          GVariant -> (Ptr GVariant -> IO GVariant) -> IO GVariant
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr GVariant
    valueVar ((Ptr GVariant -> IO GVariant) -> IO GVariant)
    -> (Ptr GVariant -> IO GVariant) -> IO GVariant
    forall a b. (a -> b) -> a -> b
    $ \Ptr GVariant
    valuePtr ->
              Ptr GVariant -> Ptr GVariant -> IO (Ptr GVariant)
    g_variant_new_dict_entry Ptr GVariant
    keyPtr Ptr GVariant
    valuePtr IO (Ptr GVariant) -> (Ptr GVariant -> IO GVariant) -> IO GVariant
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Ptr GVariant -> IO GVariant
    wrapGVariantPtr

    -- | Unpack a DictEntry variant into 'key' and 'value', which are
    -- returned as a two element tuple in case of success.
    gvariantToDictEntry :: forall key value.
                           (IsGVariant key, IsGVariantBasicType key,
                            IsGVariant value) =>
                           GVariant -> IO (Maybe (key, value))
    gvariantToDictEntry :: forall key value.
    (IsGVariant key, IsGVariantBasicType key, IsGVariant value) =>
    GVariant -> IO (Maybe (key, value))
    gvariantToDictEntry =
        Text
    -> (Ptr GVariant -> IO (key, value))
    -> GVariant
    -> IO (Maybe (key, value))
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType Text
    fmt ((Ptr GVariant -> IO (key, value))
     -> GVariant -> IO (Maybe (key, value)))
    -> (Ptr GVariant -> IO (key, value))
    -> GVariant
    -> IO (Maybe (key, value))
    forall a b. (a -> b) -> a -> b
    $ \Ptr GVariant
    varPtr -> do
          [key, value] <- Ptr GVariant -> IO [GVariant]
    gvariant_get_children Ptr GVariant
    varPtr
          (,) <$> unsafeFromGVariant key <*> unsafeFromGVariant value
        where
          fmt :: Text
    fmt = GVariantDictEntry key value -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (GVariantDictEntry key value
    forall a. HasCallStack => a
    undefined :: GVariantDictEntry key value)

    instance (IsGVariant a, IsGVariantBasicType a, IsGVariant b) =>
        IsGVariant (M.Map a b) where
            toGVariant :: Map a b -> IO GVariant
    toGVariant = Map a b -> IO GVariant
    forall a b.
    (IsGVariant a, IsGVariantBasicType a, IsGVariant b) =>
    Map a b -> IO GVariant
    gvariantFromMap
            fromGVariant :: GVariant -> IO (Maybe (Map a b))
    fromGVariant = GVariant -> IO (Maybe (Map a b))
    forall a b.
    (IsGVariant a, IsGVariantBasicType a, IsGVariant b) =>
    GVariant -> IO (Maybe (Map a b))
    gvariantToMap
            toGVariantFormatString :: Map a b -> Text
    toGVariantFormatString Map a b
    _ = Text
    "a{"
                                       Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)
                                       Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> b -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (b
    forall a. HasCallStack => a
    undefined :: b)
                                       Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "}"

    -- | Pack a 'Map' into a 'GVariant' for dictionary type, which is just
    -- an array of 'GVariantDictEntry'.
    gvariantFromMap :: (IsGVariant key, IsGVariantBasicType key,
                        IsGVariant value) =>
                       M.Map key value -> IO GVariant
    gvariantFromMap :: forall a b.
    (IsGVariant a, IsGVariantBasicType a, IsGVariant b) =>
    Map a b -> IO GVariant
    gvariantFromMap Map key value
    m = [GVariantDictEntry key value] -> IO GVariant
    forall a. IsGVariant a => [a] -> IO GVariant
    gvariantFromList ([GVariantDictEntry key value] -> IO GVariant)
    -> [GVariantDictEntry key value] -> IO GVariant
    forall a b. (a -> b) -> a -> b
    $
                           ((key, value) -> GVariantDictEntry key value)
    -> [(key, value)] -> [GVariantDictEntry key value]
    forall a b. (a -> b) -> [a] -> [b]
    map ((key -> value -> GVariantDictEntry key value)
    -> (key, value) -> GVariantDictEntry key value
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry key -> value -> GVariantDictEntry key value
    forall key value. key -> value -> GVariantDictEntry key value
    GVariantDictEntry) (Map key value -> [(key, value)]
    forall k a. Map k a -> [(k, a)]
    M.toList Map key value
    m)

    -- | Unpack a 'GVariant' into a 'M.Map'. Notice that this assumes that
    -- all the elements in the 'GVariant' array of 'GVariantDictEntry' are
    -- of the same type, which is not necessary for a generic 'GVariant',
    -- so this is somewhat restrictive. For the general case it is
    -- necessary to use 'gvariantToList' plus 'gvariantToDictEntry'
    -- directly.
    gvariantToMap :: forall key value.
                     (IsGVariant key, IsGVariantBasicType key,
                      IsGVariant value) =>
                     GVariant -> IO (Maybe (M.Map key value))
    gvariantToMap :: forall a b.
    (IsGVariant a, IsGVariantBasicType a, IsGVariant b) =>
    GVariant -> IO (Maybe (Map a b))
    gvariantToMap = GVariant -> IO (Maybe [GVariantDictEntry key value])
    forall a. IsGVariant a => GVariant -> IO (Maybe [a])
    gvariantToList (GVariant -> IO (Maybe [GVariantDictEntry key value]))
    -> (Maybe [GVariantDictEntry key value]
        -> IO (Maybe (Map key value)))
    -> GVariant
    -> IO (Maybe (Map key value))
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (Maybe (Map key value) -> IO (Maybe (Map key value))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe (Map key value) -> IO (Maybe (Map key value)))
    -> (Maybe [GVariantDictEntry key value] -> Maybe (Map key value))
    -> Maybe [GVariantDictEntry key value]
    -> IO (Maybe (Map key value))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([GVariantDictEntry key value] -> Map key value
    fromDictEntryList ([GVariantDictEntry key value] -> Map key value)
    -> Maybe [GVariantDictEntry key value] -> Maybe (Map key value)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>))
        where fromDictEntryList :: [GVariantDictEntry key value] ->
                                   M.Map key value
              fromDictEntryList :: [GVariantDictEntry key value] -> Map key value
    fromDictEntryList = [(key, value)] -> Map key value
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList ([(key, value)] -> Map key value)
    -> ([GVariantDictEntry key value] -> [(key, value)])
    -> [GVariantDictEntry key value]
    -> Map key value
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((GVariantDictEntry key value -> (key, value))
    -> [GVariantDictEntry key value] -> [(key, value)]
    forall a b. (a -> b) -> [a] -> [b]
    map GVariantDictEntry key value -> (key, value)
    tuplefy)
              tuplefy :: GVariantDictEntry key value -> (key, value)
              tuplefy :: GVariantDictEntry key value -> (key, value)
    tuplefy (GVariantDictEntry key
    key value
    value) = (key
    key, value
    value)

    instance IsGVariant a => IsGVariant [a] where
        toGVariant :: [a] -> IO GVariant
    toGVariant   = [a] -> IO GVariant
    forall a. IsGVariant a => [a] -> IO GVariant
    gvariantFromList
        fromGVariant :: GVariant -> IO (Maybe [a])
    fromGVariant = GVariant -> IO (Maybe [a])
    forall a. IsGVariant a => GVariant -> IO (Maybe [a])
    gvariantToList
        toGVariantFormatString :: [a] -> Text
    toGVariantFormatString [a]
    _ = Text
    "a" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)

    foreign import ccall "g_variant_new_array" g_variant_new_array ::
        Ptr GVariantType -> Ptr (Ptr GVariant) -> Word64 -> IO (Ptr GVariant)
    {-# LINE 780 "Data/GI/Base/GVariant.hsc" #-}

    -- | Given a list of elements construct a 'GVariant' array containing
    -- them.
    gvariantFromList :: forall a. IsGVariant a => [a] -> IO GVariant
    gvariantFromList :: forall a. IsGVariant a => [a] -> IO GVariant
    gvariantFromList [a]
    children = do
      let fmt :: Text
    fmt = a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)
      (a -> IO GVariant) -> [a] -> IO [GVariant]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM a -> IO GVariant
    forall a. IsGVariant a => a -> IO GVariant
    toGVariant [a]
    children IO [GVariant] -> ([GVariant] -> IO GVariant) -> IO GVariant
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \[GVariant]
    childVariants ->
          [GVariant] -> ([Ptr GVariant] -> IO GVariant) -> IO GVariant
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    [a] -> ([Ptr a] -> IO c) -> IO c
    withManagedPtrList [GVariant]
    childVariants (([Ptr GVariant] -> IO GVariant) -> IO GVariant)
    -> ([Ptr GVariant] -> IO GVariant) -> IO GVariant
    forall a b. (a -> b) -> a -> b
    $ \[Ptr GVariant]
    childrenPtrs -> do
              Text -> (Ptr GVariantType -> IO GVariant) -> IO GVariant
    forall a. Text -> (Ptr GVariantType -> IO a) -> IO a
    withGVariantType Text
    fmt ((Ptr GVariantType -> IO GVariant) -> IO GVariant)
    -> (Ptr GVariantType -> IO GVariant) -> IO GVariant
    forall a b. (a -> b) -> a -> b
    $ \Ptr GVariantType
    childType -> do
                 packed <- [Ptr GVariant] -> IO (Ptr (Ptr GVariant))
    forall a. [Ptr a] -> IO (Ptr (Ptr a))
    packPtrArray [Ptr GVariant]
    childrenPtrs
                 result <- g_variant_new_array childType packed
                                (fromIntegral $ length children)
                 freeMem packed
                 wrapGVariantPtr result

    -- | Unpack a 'GVariant' array into its elements.
    gvariantToList :: forall a. IsGVariant a => GVariant -> IO (Maybe [a])
    gvariantToList :: forall a. IsGVariant a => GVariant -> IO (Maybe [a])
    gvariantToList = Text -> (Ptr GVariant -> IO [a]) -> GVariant -> IO (Maybe [a])
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType ([a] -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString ([a]
    forall a. HasCallStack => a
    undefined :: [a]))
                     (Ptr GVariant -> IO [GVariant]
    gvariant_get_children (Ptr GVariant -> IO [GVariant])
    -> ([GVariant] -> IO [a]) -> Ptr GVariant -> IO [a]
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (GVariant -> IO a) -> [GVariant] -> IO [a]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM GVariant -> IO a
    forall a. IsGVariant a => GVariant -> IO a
    unsafeFromGVariant)

    foreign import ccall "g_variant_new_tuple" g_variant_new_tuple
            :: Ptr (Ptr GVariant) -> Word64 -> IO (Ptr GVariant)
    {-# LINE 802 "Data/GI/Base/GVariant.hsc" #-}

    -- | Given a list of 'GVariant', construct a 'GVariant' tuple
    -- containing the elements in the list.
    gvariantFromTuple :: [GVariant] -> IO GVariant
    gvariantFromTuple :: [GVariant] -> IO GVariant
    gvariantFromTuple [GVariant]
    children =
        [GVariant] -> ([Ptr GVariant] -> IO GVariant) -> IO GVariant
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    [a] -> ([Ptr a] -> IO c) -> IO c
    withManagedPtrList [GVariant]
    children (([Ptr GVariant] -> IO GVariant) -> IO GVariant)
    -> ([Ptr GVariant] -> IO GVariant) -> IO GVariant
    forall a b. (a -> b) -> a -> b
    $ \[Ptr GVariant]
    childrenPtrs -> do
          packed <- [Ptr GVariant] -> IO (Ptr (Ptr GVariant))
    forall a. [Ptr a] -> IO (Ptr (Ptr a))
    packPtrArray [Ptr GVariant]
    childrenPtrs
          result <- g_variant_new_tuple packed (fromIntegral $ length children)
          freeMem packed
          wrapGVariantPtr result

    -- | Extract the children of a 'GVariant' tuple into a list.
    gvariantToTuple :: GVariant -> IO (Maybe [GVariant])
    gvariantToTuple :: GVariant -> IO (Maybe [GVariant])
    gvariantToTuple = Text
    -> (Ptr GVariant -> IO [GVariant])
    -> GVariant
    -> IO (Maybe [GVariant])
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType Text
    "r" Ptr GVariant -> IO [GVariant]
    gvariant_get_children

    -- | The empty tuple GVariant, mostly useful for type checking.
    instance IsGVariant () where
        toGVariant :: () -> IO GVariant
    toGVariant ()
    _ = [GVariant] -> IO GVariant
    gvariantFromTuple []
        fromGVariant :: GVariant -> IO (Maybe ())
    fromGVariant = (Ptr GVariant -> IO ()) -> GVariant -> IO (Maybe ())
    forall a.
    IsGVariant a =>
    (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withTypeCheck (IO () -> Ptr GVariant -> IO ()
    forall a b. a -> b -> a
    const (IO () -> Ptr GVariant -> IO ()) -> IO () -> Ptr GVariant -> IO ()
    forall a b. (a -> b) -> a -> b
    $ () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ())
        toGVariantFormatString :: () -> Text
    toGVariantFormatString ()
    _ = Text
    "()"

    -- | One element tuples.
    instance IsGVariant a => IsGVariant (GVariantSinglet a) where
        toGVariant :: GVariantSinglet a -> IO GVariant
    toGVariant (GVariantSinglet a
    s) = a -> IO GVariant
    forall a. IsGVariant a => a -> IO GVariant
    gvariantFromSinglet a
    s
        fromGVariant :: GVariant -> IO (Maybe (GVariantSinglet a))
    fromGVariant = GVariant -> IO (Maybe a)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    gvariantToSinglet (GVariant -> IO (Maybe a))
    -> (Maybe a -> IO (Maybe (GVariantSinglet a)))
    -> GVariant
    -> IO (Maybe (GVariantSinglet a))
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> Maybe (GVariantSinglet a) -> IO (Maybe (GVariantSinglet a))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe (GVariantSinglet a) -> IO (Maybe (GVariantSinglet a)))
    -> (Maybe a -> Maybe (GVariantSinglet a))
    -> Maybe a
    -> IO (Maybe (GVariantSinglet a))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a -> GVariantSinglet a
    forall a. a -> GVariantSinglet a
    GVariantSinglet (a -> GVariantSinglet a) -> Maybe a -> Maybe (GVariantSinglet a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>)
        toGVariantFormatString :: GVariantSinglet a -> Text
    toGVariantFormatString GVariantSinglet a
    _ = Text
    "("
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    ")"

    gvariantFromSinglet :: IsGVariant a => a -> IO GVariant
    gvariantFromSinglet :: forall a. IsGVariant a => a -> IO GVariant
    gvariantFromSinglet a
    s = do
      sv <- a -> IO GVariant
    forall a. IsGVariant a => a -> IO GVariant
    toGVariant a
    s
      gvariantFromTuple [sv]

    gvariantToSinglet :: forall a. IsGVariant a => GVariant -> IO (Maybe a)
    gvariantToSinglet :: forall a. IsGVariant a => GVariant -> IO (Maybe a)
    gvariantToSinglet = Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType Text
    fmt
                        (Ptr GVariant -> IO GVariant
    gvariant_get_child (Ptr GVariant -> IO GVariant)
    -> (GVariant -> IO a) -> Ptr GVariant -> IO a
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> GVariant -> IO a
    forall a. IsGVariant a => GVariant -> IO a
    unsafeFromGVariant)
        where fmt :: Text
    fmt = GVariantSinglet a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (GVariantSinglet a
    forall a. HasCallStack => a
    undefined :: GVariantSinglet a)

    instance (IsGVariant a, IsGVariant b) => IsGVariant (a,b) where
        toGVariant :: (a, b) -> IO GVariant
    toGVariant = (a, b) -> IO GVariant
    forall a b. (IsGVariant a, IsGVariant b) => (a, b) -> IO GVariant
    gvariantFromTwoTuple
        fromGVariant :: GVariant -> IO (Maybe (a, b))
    fromGVariant = GVariant -> IO (Maybe (a, b))
    forall a b.
    (IsGVariant a, IsGVariant b) =>
    GVariant -> IO (Maybe (a, b))
    gvariantToTwoTuple
        toGVariantFormatString :: (a, b) -> Text
    toGVariantFormatString (a, b)
    _ = Text
    "("
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> b -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (b
    forall a. HasCallStack => a
    undefined :: b)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    ")"

    gvariantFromTwoTuple :: (IsGVariant a, IsGVariant b) =>
                            (a,b) -> IO GVariant
    gvariantFromTwoTuple :: forall a b. (IsGVariant a, IsGVariant b) => (a, b) -> IO GVariant
    gvariantFromTwoTuple (a
    a, b
    b) = do
      va <- a -> IO GVariant
    forall a. IsGVariant a => a -> IO GVariant
    toGVariant a
    a
      vb <- toGVariant b
      gvariantFromTuple [va, vb]

    gvariantToTwoTuple :: forall a b. (IsGVariant a, IsGVariant b) =>
                          GVariant -> IO (Maybe (a,b))
    gvariantToTwoTuple :: forall a b.
    (IsGVariant a, IsGVariant b) =>
    GVariant -> IO (Maybe (a, b))
    gvariantToTwoTuple GVariant
    variant = do
      let expectedType :: Text
    expectedType = (a, b) -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString ((a, b)
    forall a. HasCallStack => a
    undefined :: (a,b))
      maybeChildren <- Text
    -> (Ptr GVariant -> IO [GVariant])
    -> GVariant
    -> IO (Maybe [GVariant])
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType Text
    expectedType Ptr GVariant -> IO [GVariant]
    gvariant_get_children GVariant
    variant
      case maybeChildren of
        Just [GVariant
    a1,GVariant
    a2] -> do
          (ma1, ma2) <- (,) (Maybe a -> Maybe b -> (Maybe a, Maybe b))
    -> IO (Maybe a) -> IO (Maybe b -> (Maybe a, Maybe b))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> GVariant -> IO (Maybe a)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a1 IO (Maybe b -> (Maybe a, Maybe b))
    -> IO (Maybe b) -> IO (Maybe a, Maybe b)
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe b)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a2
          return $ if isJust ma1 && isJust ma2
                   then Just (fromJust ma1, fromJust ma2)
                   else Nothing
        Just [GVariant]
    _ -> [Char] -> IO (Maybe (a, b))
    forall a. HasCallStack => [Char] -> a
    error [Char]
    "gvariantToTwoTuple :: the impossible happened, this is a bug."
        Maybe [GVariant]
    Nothing -> Maybe (a, b) -> IO (Maybe (a, b))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (a, b)
    forall a. Maybe a
    Nothing

    instance (IsGVariant a, IsGVariant b, IsGVariant c) => IsGVariant (a,b,c) where
        toGVariant :: (a, b, c) -> IO GVariant
    toGVariant = (a, b, c) -> IO GVariant
    forall a b c.
    (IsGVariant a, IsGVariant b, IsGVariant c) =>
    (a, b, c) -> IO GVariant
    gvariantFromThreeTuple
        fromGVariant :: GVariant -> IO (Maybe (a, b, c))
    fromGVariant = GVariant -> IO (Maybe (a, b, c))
    forall a b c.
    (IsGVariant a, IsGVariant b, IsGVariant c) =>
    GVariant -> IO (Maybe (a, b, c))
    gvariantToThreeTuple
        toGVariantFormatString :: (a, b, c) -> Text
    toGVariantFormatString (a, b, c)
    _ = Text
    "("
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> b -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (b
    forall a. HasCallStack => a
    undefined :: b)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> c -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (c
    forall a. HasCallStack => a
    undefined :: c)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    ")"

    gvariantFromThreeTuple :: (IsGVariant a, IsGVariant b, IsGVariant c) =>
                            (a,b,c) -> IO GVariant
    gvariantFromThreeTuple :: forall a b c.
    (IsGVariant a, IsGVariant b, IsGVariant c) =>
    (a, b, c) -> IO GVariant
    gvariantFromThreeTuple (a
    a, b
    b, c
    c) = do
      va <- a -> IO GVariant
    forall a. IsGVariant a => a -> IO GVariant
    toGVariant a
    a
      vb <- toGVariant b
      vc <- toGVariant c
      gvariantFromTuple [va, vb, vc]

    gvariantToThreeTuple :: forall a b c. (IsGVariant a, IsGVariant b,
                                                      IsGVariant c) =>
                          GVariant -> IO (Maybe (a,b,c))
    gvariantToThreeTuple :: forall a b c.
    (IsGVariant a, IsGVariant b, IsGVariant c) =>
    GVariant -> IO (Maybe (a, b, c))
    gvariantToThreeTuple GVariant
    variant = do
      let expectedType :: Text
    expectedType = (a, b, c) -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString ((a, b, c)
    forall a. HasCallStack => a
    undefined :: (a,b,c))
      maybeChildren <- Text
    -> (Ptr GVariant -> IO [GVariant])
    -> GVariant
    -> IO (Maybe [GVariant])
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType Text
    expectedType Ptr GVariant -> IO [GVariant]
    gvariant_get_children GVariant
    variant
      case maybeChildren of
        Just [GVariant
    a1,GVariant
    a2,GVariant
    a3] -> do
          (ma1, ma2, ma3) <- (,,) (Maybe a -> Maybe b -> Maybe c -> (Maybe a, Maybe b, Maybe c))
    -> IO (Maybe a)
    -> IO (Maybe b -> Maybe c -> (Maybe a, Maybe b, Maybe c))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> GVariant -> IO (Maybe a)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a1
                             IO (Maybe b -> Maybe c -> (Maybe a, Maybe b, Maybe c))
    -> IO (Maybe b) -> IO (Maybe c -> (Maybe a, Maybe b, Maybe c))
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe b)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a2
                             IO (Maybe c -> (Maybe a, Maybe b, Maybe c))
    -> IO (Maybe c) -> IO (Maybe a, Maybe b, Maybe c)
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe c)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a3
          return $ if isJust ma1 && isJust ma2 && isJust ma3
                   then Just (fromJust ma1, fromJust ma2, fromJust ma3)
                   else Nothing
        Just [GVariant]
    _ -> [Char] -> IO (Maybe (a, b, c))
    forall a. HasCallStack => [Char] -> a
    error [Char]
    "gvariantToThreeTuple :: the impossible happened, this is a bug."
        Maybe [GVariant]
    Nothing -> Maybe (a, b, c) -> IO (Maybe (a, b, c))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (a, b, c)
    forall a. Maybe a
    Nothing

    instance (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d) =>
        IsGVariant (a,b,c,d) where
        toGVariant :: (a, b, c, d) -> IO GVariant
    toGVariant = (a, b, c, d) -> IO GVariant
    forall a b c d.
    (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d) =>
    (a, b, c, d) -> IO GVariant
    gvariantFromFourTuple
        fromGVariant :: GVariant -> IO (Maybe (a, b, c, d))
    fromGVariant = GVariant -> IO (Maybe (a, b, c, d))
    forall a b c d.
    (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d) =>
    GVariant -> IO (Maybe (a, b, c, d))
    gvariantToFourTuple
        toGVariantFormatString :: (a, b, c, d) -> Text
    toGVariantFormatString (a, b, c, d)
    _ = Text
    "("
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> b -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (b
    forall a. HasCallStack => a
    undefined :: b)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> c -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (c
    forall a. HasCallStack => a
    undefined :: c)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> d -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (d
    forall a. HasCallStack => a
    undefined :: d)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    ")"

    gvariantFromFourTuple :: (IsGVariant a, IsGVariant b, IsGVariant c,
                              IsGVariant d) => (a,b,c,d) -> IO GVariant
    gvariantFromFourTuple :: forall a b c d.
    (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d) =>
    (a, b, c, d) -> IO GVariant
    gvariantFromFourTuple (a
    a, b
    b, c
    c, d
    d) = do
      va <- a -> IO GVariant
    forall a. IsGVariant a => a -> IO GVariant
    toGVariant a
    a
      vb <- toGVariant b
      vc <- toGVariant c
      vd <- toGVariant d
      gvariantFromTuple [va, vb, vc, vd]

    gvariantToFourTuple :: forall a b c d. (IsGVariant a, IsGVariant b,
                                            IsGVariant c, IsGVariant d) =>
                          GVariant -> IO (Maybe (a,b,c,d))
    gvariantToFourTuple :: forall a b c d.
    (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d) =>
    GVariant -> IO (Maybe (a, b, c, d))
    gvariantToFourTuple GVariant
    variant = do
      let expectedType :: Text
    expectedType = (a, b, c, d) -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString ((a, b, c, d)
    forall a. HasCallStack => a
    undefined :: (a,b,c,d))
      maybeChildren <- Text
    -> (Ptr GVariant -> IO [GVariant])
    -> GVariant
    -> IO (Maybe [GVariant])
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType Text
    expectedType Ptr GVariant -> IO [GVariant]
    gvariant_get_children GVariant
    variant
      case maybeChildren of
        Just [GVariant
    a1,GVariant
    a2,GVariant
    a3,GVariant
    a4] -> do
          (ma1, ma2, ma3,ma4) <- (,,,) (Maybe a
     -> Maybe b
     -> Maybe c
     -> Maybe d
     -> (Maybe a, Maybe b, Maybe c, Maybe d))
    -> IO (Maybe a)
    -> IO
         (Maybe b
          -> Maybe c -> Maybe d -> (Maybe a, Maybe b, Maybe c, Maybe d))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> GVariant -> IO (Maybe a)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a1
                                 IO
      (Maybe b
       -> Maybe c -> Maybe d -> (Maybe a, Maybe b, Maybe c, Maybe d))
    -> IO (Maybe b)
    -> IO (Maybe c -> Maybe d -> (Maybe a, Maybe b, Maybe c, Maybe d))
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe b)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a2
                                 IO (Maybe c -> Maybe d -> (Maybe a, Maybe b, Maybe c, Maybe d))
    -> IO (Maybe c)
    -> IO (Maybe d -> (Maybe a, Maybe b, Maybe c, Maybe d))
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe c)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a3
                                 IO (Maybe d -> (Maybe a, Maybe b, Maybe c, Maybe d))
    -> IO (Maybe d) -> IO (Maybe a, Maybe b, Maybe c, Maybe d)
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe d)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a4
          return $ if isJust ma1 && isJust ma2 && isJust ma3 && isJust ma4
                   then Just (fromJust ma1, fromJust ma2, fromJust ma3, fromJust ma4)
                   else Nothing
        Just [GVariant]
    _ -> [Char] -> IO (Maybe (a, b, c, d))
    forall a. HasCallStack => [Char] -> a
    error [Char]
    "gvariantToFourTuple :: the impossible happened, this is a bug."
        Maybe [GVariant]
    Nothing -> Maybe (a, b, c, d) -> IO (Maybe (a, b, c, d))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (a, b, c, d)
    forall a. Maybe a
    Nothing

    instance (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d, IsGVariant e)
        => IsGVariant (a,b,c,d,e) where
        toGVariant :: (a, b, c, d, e) -> IO GVariant
    toGVariant = (a, b, c, d, e) -> IO GVariant
    forall a b c d e.
    (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d,
     IsGVariant e) =>
    (a, b, c, d, e) -> IO GVariant
    gvariantFromFiveTuple
        fromGVariant :: GVariant -> IO (Maybe (a, b, c, d, e))
    fromGVariant = GVariant -> IO (Maybe (a, b, c, d, e))
    forall a b c d e.
    (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d,
     IsGVariant e) =>
    GVariant -> IO (Maybe (a, b, c, d, e))
    gvariantToFiveTuple
        toGVariantFormatString :: (a, b, c, d, e) -> Text
    toGVariantFormatString (a, b, c, d, e)
    _ = Text
    "("
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> a -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (a
    forall a. HasCallStack => a
    undefined :: a)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> b -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (b
    forall a. HasCallStack => a
    undefined :: b)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> c -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (c
    forall a. HasCallStack => a
    undefined :: c)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> d -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (d
    forall a. HasCallStack => a
    undefined :: d)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> e -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString (e
    forall a. HasCallStack => a
    undefined :: e)
                                   Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    ")"

    gvariantFromFiveTuple :: (IsGVariant a, IsGVariant b, IsGVariant c,
                              IsGVariant d, IsGVariant e) =>
                             (a,b,c,d,e) -> IO GVariant
    gvariantFromFiveTuple :: forall a b c d e.
    (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d,
     IsGVariant e) =>
    (a, b, c, d, e) -> IO GVariant
    gvariantFromFiveTuple (a
    a, b
    b, c
    c, d
    d, e
    e) = do
      va <- a -> IO GVariant
    forall a. IsGVariant a => a -> IO GVariant
    toGVariant a
    a
      vb <- toGVariant b
      vc <- toGVariant c
      vd <- toGVariant d
      ve <- toGVariant e
      gvariantFromTuple [va, vb, vc, vd, ve]

    gvariantToFiveTuple :: forall a b c d e.
                           (IsGVariant a, IsGVariant b, IsGVariant c,
                            IsGVariant d, IsGVariant e) =>
                          GVariant -> IO (Maybe (a,b,c,d,e))
    gvariantToFiveTuple :: forall a b c d e.
    (IsGVariant a, IsGVariant b, IsGVariant c, IsGVariant d,
     IsGVariant e) =>
    GVariant -> IO (Maybe (a, b, c, d, e))
    gvariantToFiveTuple GVariant
    variant = do
      let expectedType :: Text
    expectedType = (a, b, c, d, e) -> Text
    forall a. IsGVariant a => a -> Text
    toGVariantFormatString ((a, b, c, d, e)
    forall a. HasCallStack => a
    undefined :: (a,b,c,d,e))
      maybeChildren <- Text
    -> (Ptr GVariant -> IO [GVariant])
    -> GVariant
    -> IO (Maybe [GVariant])
    forall a.
    Text -> (Ptr GVariant -> IO a) -> GVariant -> IO (Maybe a)
    withExplicitType Text
    expectedType Ptr GVariant -> IO [GVariant]
    gvariant_get_children GVariant
    variant
      case maybeChildren of
        Just [GVariant
    a1,GVariant
    a2,GVariant
    a3,GVariant
    a4,GVariant
    a5] -> do
          (ma1, ma2, ma3, ma4, ma5) <- (,,,,) (Maybe a
     -> Maybe b
     -> Maybe c
     -> Maybe d
     -> Maybe e
     -> (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e))
    -> IO (Maybe a)
    -> IO
         (Maybe b
          -> Maybe c
          -> Maybe d
          -> Maybe e
          -> (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> GVariant -> IO (Maybe a)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a1
                                       IO
      (Maybe b
       -> Maybe c
       -> Maybe d
       -> Maybe e
       -> (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e))
    -> IO (Maybe b)
    -> IO
         (Maybe c
          -> Maybe d
          -> Maybe e
          -> (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e))
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe b)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a2
                                       IO
      (Maybe c
       -> Maybe d
       -> Maybe e
       -> (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e))
    -> IO (Maybe c)
    -> IO
         (Maybe d
          -> Maybe e -> (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e))
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe c)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a3
                                       IO
      (Maybe d
       -> Maybe e -> (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e))
    -> IO (Maybe d)
    -> IO (Maybe e -> (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e))
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe d)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a4
                                       IO (Maybe e -> (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e))
    -> IO (Maybe e) -> IO (Maybe a, Maybe b, Maybe c, Maybe d, Maybe e)
    forall a b. IO (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> GVariant -> IO (Maybe e)
    forall a. IsGVariant a => GVariant -> IO (Maybe a)
    fromGVariant GVariant
    a5
          return $ if isJust ma1 && isJust ma2 && isJust ma3 &&
                      isJust ma4 && isJust ma5
                   then Just (fromJust ma1, fromJust ma2, fromJust ma3,
                              fromJust ma4, fromJust ma5)
                   else Nothing
        Just [GVariant]
    _ -> [Char] -> IO (Maybe (a, b, c, d, e))
    forall a. HasCallStack => [Char] -> a
    error [Char]
    "gvariantToFiveTuple :: the impossible happened, this is a bug."
        Maybe [GVariant]
    Nothing -> Maybe (a, b, c, d, e) -> IO (Maybe (a, b, c, d, e))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (a, b, c, d, e)
    forall a. Maybe a
    Nothing