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

'GI.Gio.Objects.FileIcon.FileIcon' specifies an icon by pointing to an image file
to be used as icon.
-}

#define ENABLE_OVERLOADING \
       (!defined(__HADDOCK_VERSION__))

module GI.Gio.Objects.FileIcon
    ( 

-- * Exported types
    FileIcon(..)                            ,
    IsFileIcon                              ,
    toFileIcon                              ,
    noFileIcon                              ,


 -- * Methods
-- ** getFile #method:getFile#

#if ENABLE_OVERLOADING
    FileIconGetFileMethodInfo               ,
#endif
    fileIconGetFile                         ,


-- ** new #method:new#

    fileIconNew                             ,




 -- * Properties
-- ** file #attr:file#
{- | The file containing the icon.
-}
#if ENABLE_OVERLOADING
    FileIconFilePropertyInfo                ,
#endif
    constructFileIconFile                   ,
#if ENABLE_OVERLOADING
    fileIconFile                            ,
#endif
    getFileIconFile                         ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Interfaces.File as Gio.File
import {-# SOURCE #-} qualified GI.Gio.Interfaces.Icon as Gio.Icon
import {-# SOURCE #-} qualified GI.Gio.Interfaces.LoadableIcon as Gio.LoadableIcon

-- | Memory-managed wrapper type.
newtype FileIcon = FileIcon (ManagedPtr FileIcon)
foreign import ccall "g_file_icon_get_type"
    c_g_file_icon_get_type :: IO GType

instance GObject FileIcon where
    gobjectType :: FileIcon -> IO GType
gobjectType _ = IO GType
c_g_file_icon_get_type
    

-- | Type class for types which can be safely cast to `FileIcon`, for instance with `toFileIcon`.
class GObject o => IsFileIcon o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError FileIcon a) =>
    IsFileIcon a
#endif
instance IsFileIcon FileIcon
instance GObject.Object.IsObject FileIcon
instance Gio.Icon.IsIcon FileIcon
instance Gio.LoadableIcon.IsLoadableIcon FileIcon

-- | Cast to `FileIcon`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toFileIcon :: (MonadIO m, IsFileIcon o) => o -> m FileIcon
toFileIcon :: o -> m FileIcon
toFileIcon = IO FileIcon -> m FileIcon
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileIcon -> m FileIcon)
-> (o -> IO FileIcon) -> o -> m FileIcon
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr FileIcon -> FileIcon) -> o -> IO FileIcon
forall o o'.
(HasCallStack, GObject o, GObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr FileIcon -> FileIcon
FileIcon

-- | A convenience alias for `Nothing` :: `Maybe` `FileIcon`.
noFileIcon :: Maybe FileIcon
noFileIcon :: Maybe FileIcon
noFileIcon = Maybe FileIcon
forall a. Maybe a
Nothing

#if ENABLE_OVERLOADING
type family ResolveFileIconMethod (t :: Symbol) (o :: *) :: * where
    ResolveFileIconMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveFileIconMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveFileIconMethod "equal" o = Gio.Icon.IconEqualMethodInfo
    ResolveFileIconMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveFileIconMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveFileIconMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveFileIconMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveFileIconMethod "load" o = Gio.LoadableIcon.LoadableIconLoadMethodInfo
    ResolveFileIconMethod "loadAsync" o = Gio.LoadableIcon.LoadableIconLoadAsyncMethodInfo
    ResolveFileIconMethod "loadFinish" o = Gio.LoadableIcon.LoadableIconLoadFinishMethodInfo
    ResolveFileIconMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveFileIconMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveFileIconMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveFileIconMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveFileIconMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveFileIconMethod "serialize" o = Gio.Icon.IconSerializeMethodInfo
    ResolveFileIconMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveFileIconMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveFileIconMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveFileIconMethod "toString" o = Gio.Icon.IconToStringMethodInfo
    ResolveFileIconMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveFileIconMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveFileIconMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveFileIconMethod "getFile" o = FileIconGetFileMethodInfo
    ResolveFileIconMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveFileIconMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveFileIconMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveFileIconMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveFileIconMethod l o = O.MethodResolutionFailed l o

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

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

#endif

-- VVV Prop "file"
   -- Type: TInterface (Name {namespace = "Gio", name = "File"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

{- |
Get the value of the “@file@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' fileIcon #file
@
-}
getFileIconFile :: (MonadIO m, IsFileIcon o) => o -> m Gio.File.File
getFileIconFile :: o -> m File
getFileIconFile obj :: o
obj = IO File -> m File
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO File -> m File) -> IO File -> m File
forall a b. (a -> b) -> a -> b
$ Text -> IO (Maybe File) -> IO File
forall a. HasCallStack => Text -> IO (Maybe a) -> IO a
checkUnexpectedNothing "getFileIconFile" (IO (Maybe File) -> IO File) -> IO (Maybe File) -> IO File
forall a b. (a -> b) -> a -> b
$ o -> String -> (ManagedPtr File -> File) -> IO (Maybe File)
forall a b.
(GObject a, GObject b) =>
a -> String -> (ManagedPtr b -> b) -> IO (Maybe b)
getObjectPropertyObject o
obj "file" ManagedPtr File -> File
Gio.File.File

{- |
Construct a `GValueConstruct` with valid value for the “@file@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
-}
constructFileIconFile :: (IsFileIcon o, Gio.File.IsFile a) => a -> IO (GValueConstruct o)
constructFileIconFile :: a -> IO (GValueConstruct o)
constructFileIconFile val :: a
val = String -> Maybe a -> IO (GValueConstruct o)
forall a o.
GObject a =>
String -> Maybe a -> IO (GValueConstruct o)
constructObjectPropertyObject "file" (a -> Maybe a
forall a. a -> Maybe a
Just a
val)

#if ENABLE_OVERLOADING
data FileIconFilePropertyInfo
instance AttrInfo FileIconFilePropertyInfo where
    type AttrAllowedOps FileIconFilePropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint FileIconFilePropertyInfo = Gio.File.IsFile
    type AttrBaseTypeConstraint FileIconFilePropertyInfo = IsFileIcon
    type AttrGetType FileIconFilePropertyInfo = Gio.File.File
    type AttrLabel FileIconFilePropertyInfo = "file"
    type AttrOrigin FileIconFilePropertyInfo = FileIcon
    attrGet _ = getFileIconFile
    attrSet _ = undefined
    attrConstruct _ = constructFileIconFile
    attrClear _ = undefined
#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList FileIcon
type instance O.AttributeList FileIcon = FileIconAttributeList
type FileIconAttributeList = ('[ '("file", FileIconFilePropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
fileIconFile :: AttrLabelProxy "file"
fileIconFile = AttrLabelProxy

#endif

#if ENABLE_OVERLOADING
type instance O.SignalList FileIcon = FileIconSignalList
type FileIconSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method FileIcon::new
-- method type : Constructor
-- Args : [Arg {argCName = "file", argType = TInterface (Name {namespace = "Gio", name = "File"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GFile.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "FileIcon"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_file_icon_new" g_file_icon_new :: 
    Ptr Gio.File.File ->                    -- file : TInterface (Name {namespace = "Gio", name = "File"})
    IO (Ptr FileIcon)

{- |
Creates a new icon for a file.
-}
fileIconNew ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.File.IsFile a) =>
    a
    {- ^ /@file@/: a 'GI.Gio.Interfaces.File.File'. -}
    -> m FileIcon
    {- ^ __Returns:__ a 'GI.Gio.Interfaces.Icon.Icon' for the given
  /@file@/, or 'Nothing' on error. -}
fileIconNew :: a -> m FileIcon
fileIconNew file :: a
file = IO FileIcon -> m FileIcon
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileIcon -> m FileIcon) -> IO FileIcon -> m FileIcon
forall a b. (a -> b) -> a -> b
$ do
    Ptr File
file' <- a -> IO (Ptr File)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
file
    Ptr FileIcon
result <- Ptr File -> IO (Ptr FileIcon)
g_file_icon_new Ptr File
file'
    Text -> Ptr FileIcon -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "fileIconNew" Ptr FileIcon
result
    FileIcon
result' <- ((ManagedPtr FileIcon -> FileIcon) -> Ptr FileIcon -> IO FileIcon
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr FileIcon -> FileIcon
FileIcon) Ptr FileIcon
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
file
    FileIcon -> IO FileIcon
forall (m :: * -> *) a. Monad m => a -> m a
return FileIcon
result'

#if ENABLE_OVERLOADING
#endif

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

foreign import ccall "g_file_icon_get_file" g_file_icon_get_file :: 
    Ptr FileIcon ->                         -- icon : TInterface (Name {namespace = "Gio", name = "FileIcon"})
    IO (Ptr Gio.File.File)

{- |
Gets the 'GI.Gio.Interfaces.File.File' associated with the given /@icon@/.
-}
fileIconGetFile ::
    (B.CallStack.HasCallStack, MonadIO m, IsFileIcon a) =>
    a
    {- ^ /@icon@/: a 'GI.Gio.Interfaces.Icon.Icon'. -}
    -> m Gio.File.File
    {- ^ __Returns:__ a 'GI.Gio.Interfaces.File.File', or 'Nothing'. -}
fileIconGetFile :: a -> m File
fileIconGetFile icon :: a
icon = IO File -> m File
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO File -> m File) -> IO File -> m File
forall a b. (a -> b) -> a -> b
$ do
    Ptr FileIcon
icon' <- a -> IO (Ptr FileIcon)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
icon
    Ptr File
result <- Ptr FileIcon -> IO (Ptr File)
g_file_icon_get_file Ptr FileIcon
icon'
    Text -> Ptr File -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "fileIconGetFile" Ptr File
result
    File
result' <- ((ManagedPtr File -> File) -> Ptr File -> IO File
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr File -> File
Gio.File.File) Ptr File
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
icon
    File -> IO File
forall (m :: * -> *) a. Monad m => a -> m a
return File
result'

#if ENABLE_OVERLOADING
data FileIconGetFileMethodInfo
instance (signature ~ (m Gio.File.File), MonadIO m, IsFileIcon a) => O.MethodInfo FileIconGetFileMethodInfo a signature where
    overloadedMethod _ = fileIconGetFile

#endif