module Graphics.UI.Gtk.Selectors.FileFilter (
FileFilter,
FileFilterClass,
castToFileFilter, gTypeFileFilter,
toFileFilter,
FileFilterFlags(..),
fileFilterNew,
fileFilterSetName,
fileFilterGetName,
fileFilterAddMimeType,
fileFilterAddPattern,
fileFilterAddCustom,
fileFilterAddPixbufFormats,
fileFilterName,
) where
import Control.Monad (liftM)
import System.Glib.FFI
import System.Glib.Flags (Flags, fromFlags)
import System.Glib.UTFString
import System.Glib.Attributes
import Graphics.UI.Gtk.Types
import Graphics.UI.Gtk.Abstract.Object (makeNewObject)
data FileFilterFlags = FileFilterFilename
| FileFilterUri
| FileFilterDisplayName
| FileFilterMimeType
deriving (Bounded,Show,Eq)
instance Enum FileFilterFlags where
fromEnum FileFilterFilename = 1
fromEnum FileFilterUri = 2
fromEnum FileFilterDisplayName = 4
fromEnum FileFilterMimeType = 8
toEnum 1 = FileFilterFilename
toEnum 2 = FileFilterUri
toEnum 4 = FileFilterDisplayName
toEnum 8 = FileFilterMimeType
toEnum unmatched = error ("FileFilterFlags.toEnum: Cannot match " ++ show unmatched)
succ FileFilterFilename = FileFilterUri
succ FileFilterUri = FileFilterDisplayName
succ FileFilterDisplayName = FileFilterMimeType
succ _ = undefined
pred FileFilterUri = FileFilterFilename
pred FileFilterDisplayName = FileFilterUri
pred FileFilterMimeType = FileFilterDisplayName
pred _ = undefined
enumFromTo x y | fromEnum x == fromEnum y = [ y ]
| otherwise = x : enumFromTo (succ x) y
enumFrom x = enumFromTo x FileFilterMimeType
enumFromThen _ _ = error "Enum FileFilterFlags: enumFromThen not implemented"
enumFromThenTo _ _ _ = error "Enum FileFilterFlags: enumFromThenTo not implemented"
instance Flags FileFilterFlags
fileFilterNew :: IO FileFilter
fileFilterNew =
makeNewObject mkFileFilter $
gtk_file_filter_new
fileFilterSetName :: GlibString string
=> FileFilter
-> string
-> IO ()
fileFilterSetName self name =
withUTFString name $ \namePtr ->
(\(FileFilter arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_file_filter_set_name argPtr1 arg2)
self
namePtr
fileFilterGetName :: GlibString string
=> FileFilter
-> IO string
fileFilterGetName self =
(\(FileFilter arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_file_filter_get_name argPtr1)
self
>>= peekUTFString
fileFilterAddMimeType :: GlibString string
=> FileFilter
-> string
-> IO ()
fileFilterAddMimeType self mimeType =
withUTFString mimeType $ \mimeTypePtr ->
(\(FileFilter arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_file_filter_add_mime_type argPtr1 arg2)
self
mimeTypePtr
fileFilterAddPattern :: GlibString string
=> FileFilter
-> string
-> IO ()
fileFilterAddPattern self pattern =
withUTFString pattern $ \patternPtr ->
(\(FileFilter arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gtk_file_filter_add_pattern argPtr1 arg2)
self
patternPtr
fileFilterAddCustom :: GlibString string => FileFilter
-> [FileFilterFlags]
-> ( Maybe string
-> Maybe string
-> Maybe string
-> Maybe string
-> IO Bool)
-> IO ()
fileFilterAddCustom self needed func = do
hPtr <- mkHandler_GtkFileFilterFunc
(\filterInfoPtr _ -> do
filenamePtr <- (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)}) filterInfoPtr
uriPtr <- (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)}) filterInfoPtr
displayNamePtr <- (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr CChar)}) filterInfoPtr
mimeTypePtr <- (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)}) filterInfoPtr
filename <- maybePeek peekUTFString filenamePtr
uri <- maybePeek peekUTFString uriPtr
displayName <- maybePeek peekUTFString displayNamePtr
mimeType <- maybePeek peekUTFString mimeTypePtr
liftM fromBool $ func filename uri displayName mimeType)
(\(FileFilter arg1) arg2 arg3 arg4 arg5 -> withForeignPtr arg1 $ \argPtr1 ->gtk_file_filter_add_custom argPtr1 arg2 arg3 arg4 arg5)
self
((fromIntegral . fromFlags) needed)
hPtr
(castFunPtrToPtr hPtr)
destroyFunPtr
type GtkFileFilterInfoPtr = Ptr (())
type GtkFileFilterFunc =
GtkFileFilterInfoPtr ->
Ptr () ->
IO CInt
foreign import ccall "wrapper" mkHandler_GtkFileFilterFunc ::
GtkFileFilterFunc ->
IO (FunPtr GtkFileFilterFunc)
fileFilterAddPixbufFormats :: FileFilter -> IO ()
fileFilterAddPixbufFormats self =
(\(FileFilter arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_file_filter_add_pixbuf_formats argPtr1)
self
fileFilterName :: GlibString string => Attr FileFilter string
fileFilterName = newAttr
fileFilterGetName
fileFilterSetName
foreign import ccall safe "gtk_file_filter_new"
gtk_file_filter_new :: (IO (Ptr FileFilter))
foreign import ccall safe "gtk_file_filter_set_name"
gtk_file_filter_set_name :: ((Ptr FileFilter) -> ((Ptr CChar) -> (IO ())))
foreign import ccall safe "gtk_file_filter_get_name"
gtk_file_filter_get_name :: ((Ptr FileFilter) -> (IO (Ptr CChar)))
foreign import ccall safe "gtk_file_filter_add_mime_type"
gtk_file_filter_add_mime_type :: ((Ptr FileFilter) -> ((Ptr CChar) -> (IO ())))
foreign import ccall safe "gtk_file_filter_add_pattern"
gtk_file_filter_add_pattern :: ((Ptr FileFilter) -> ((Ptr CChar) -> (IO ())))
foreign import ccall safe "gtk_file_filter_add_custom"
gtk_file_filter_add_custom :: ((Ptr FileFilter) -> (CInt -> ((FunPtr ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))) -> ((Ptr ()) -> ((FunPtr ((Ptr ()) -> (IO ()))) -> (IO ()))))))
foreign import ccall safe "gtk_file_filter_add_pixbuf_formats"
gtk_file_filter_add_pixbuf_formats :: ((Ptr FileFilter) -> (IO ()))