|
From: Andy S. <And...@co...> - 2010-08-20 07:05:34
|
diffing dir...
Sun Aug 15 14:20:50 EDT 2010 Andy Stewart <laz...@gm...>
* Add new module System.GIO.File.ContentType
Ignore-this: bde0c7cca0295d4312be28d3d8c031f4
{
hunk ./gio/System/GIO.hs 33
- module System.GIO.File.File,
hunk ./gio/System/GIO.hs 34
+ module System.GIO.File.ContentType,
+ module System.GIO.File.File,
hunk ./gio/System/GIO.hs 41
-import System.GIO.File.File
hunk ./gio/System/GIO.hs 42
+import System.GIO.File.ContentType
+import System.GIO.File.File
addfile ./gio/System/GIO/File/ContentType.chs
hunk ./gio/System/GIO/File/ContentType.chs 1
+{-# LANGUAGE CPP #-}
+-- GIMP Toolkit (GTK) Binding for Haskell: binding to gio -*-haskell-*-
+--
+-- Author : Andy Stewart
+-- Created: 30-Apirl-2010
+--
+-- Copyright (c) 2010 Andy Stewart
+--
+-- This library is free software: you can redistribute it and/or
+-- modify it under the terms of the GNU Lesser General Public License
+-- as published by the Free Software Foundation, either version 3 of
+-- the License, or (at your option) any later version.
+-- [_$_]
+-- This library is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+-- Lesser General Public License for more details.
+-- [_$_]
+-- You should have received a copy of the GNU Lesser General Public
+-- License along with this program. If not, see
+-- <http://www.gnu.org/licenses/>.
+-- [_$_]
+-- GIO, the C library which this Haskell library depends on, is
+-- available under LGPL Version 2. The documentation included with
+-- this library is based on the original GIO documentation.
+-- [_$_]
+-- | Maintainer : gtk...@li...
+-- Stability : alpha
+-- Portability : portable (depends on GHC)
+module System.GIO.File.ContentType (
+-- * Details
+--
+-- | A content type is a platform specific string that defines the type of a file. On unix it is a mime
+-- type, on win32 it is an extension string like ".doc", ".txt" or a percieved string like
+-- "audio". Such strings can be looked up in the registry at HkeyClassesRoot.
+
+-- * Methods
+ contentTypeEquals,
+ contentTypeIsA,
+ contentTypeIsUnknown,
+ contentTypeGetDescription,
+ contentTypeGetMimeType,
+ contentTypeGetIcon,
+ contentTypeCanBeExecutable,
+#if GLIB_CHECK_VERSION(2,18,0)
+ contentTypeFromMimeType,
+#endif
+ contentTypeGuess,
+#if GLIB_CHECK_VERSION(2,18,0)
+ contentTypeGuessForTree,
+#endif
+ contentTypesGetRegistered,
+ ) where
+
+import Control.Monad
+import System.GIO.Enums
+import System.Glib.FFI
+import System.Glib.Flags
+import System.Glib.GError
+import System.Glib.GList
+import System.Glib.GObject
+import System.Glib.UTFString
+{#import System.GIO.Types#}
+
+{# context lib = "gio" prefix = "g" #}
+
+-- | Compares two content types for equality.
+contentTypeEquals :: [_$_]
+ String [_$_]
+ -> String [_$_]
+ -> Bool -- ^ returns 'True' if the two strings are identical or equivalent, 'False' otherwise.
+contentTypeEquals type1 type2 = [_$_]
+ toBool $ unsafePerformIO $
+ withUTFString type1 $ \ type1Ptr -> [_$_]
+ withUTFString type2 $ \ type2Ptr -> [_$_]
+ {#call g_content_type_equals#} type1Ptr type2Ptr
+
+-- | Determines if type is a subset of supertype.
+contentTypeIsA :: [_$_]
+ String [_$_]
+ -> String [_$_]
+ -> Bool -- ^ returns 'True' if type is a kind of supertype, 'False' otherwise. [_$_]
+contentTypeIsA type1 supertype = [_$_]
+ toBool $ unsafePerformIO $
+ withUTFString type1 $ \ type1Ptr -> [_$_]
+ withUTFString supertype $ \ supertypePtr -> [_$_]
+ {#call g_content_type_equals#} type1Ptr supertypePtr
+
+-- | Checks if the content type is the generic "unknown" type. On unix this is the
+-- "application/octet-stream" mimetype, while on win32 it is \"*\".
+contentTypeIsUnknown :: String
+ -> Bool -- ^ returns 'True' if the type is the unknown type. [_$_]
+contentTypeIsUnknown typ =
+ toBool $ unsafePerformIO $
+ withUTFString typ $ \ typPtr -> [_$_]
+ {#call g_content_type_is_unknown#} typPtr
+
+-- | Gets the human readable description of the content type.
+contentTypeGetDescription :: [_$_]
+ String [_$_]
+ -> String -- ^ returns a short description of the content type type. [_$_]
+contentTypeGetDescription typ = [_$_]
+ unsafePerformIO $
+ withUTFString typ $ \ typPtr -> [_$_]
+ {#call g_content_type_get_description#} typPtr
+ >>= readUTFString
+
+-- | Gets the mime-type for the content type. If one is registered
+contentTypeGetMimeType :: [_$_]
+ String [_$_]
+ -> String -- ^ returns the registered mime-type for the given type, or 'Nothing' if unknown. [_$_]
+contentTypeGetMimeType typ = [_$_]
+ unsafePerformIO $
+ withUTFString typ $ \ typPtr -> [_$_]
+ {#call g_content_type_get_mime_type#} typPtr
+ >>= readUTFString
+
+-- | Gets the icon for a content type.
+contentTypeGetIcon :: String [_$_]
+ -> Icon -- ^ returns 'Icon' corresponding to the content type. [_$_]
+contentTypeGetIcon typ = [_$_]
+ unsafePerformIO $ makeNewGObject mkIcon $
+ withUTFString typ $ \ typPtr -> [_$_]
+ {#call g_content_type_get_icon#} typPtr
+
+-- | Checks if a content type can be executable. Note that for instance things like text files can be
+-- executables (i.e. scripts and batch files).
+contentTypeCanBeExecutable :: String [_$_]
+ -> Bool -- ^ returns 'True' if the file type corresponds to a type that can be executable, 'False' otherwise.
+contentTypeCanBeExecutable typ =
+ toBool $ unsafePerformIO $
+ withUTFString typ $ \ typPtr -> [_$_]
+ {#call g_content_type_can_be_executable#} typPtr
+
+#if GLIB_CHECK_VERSION(2,18,0)
+-- | Tries to find a content type based on the mime type name.
+contentTypeFromMimeType :: [_$_]
+ String -- ^ @mimeType@ a mime type string. [_$_]
+ -> IO String [_$_]
+contentTypeFromMimeType mimeType =
+ withUTFString mimeType $ \ mimeTypePtr -> [_$_]
+ {#call g_content_type_from_mime_type#} mimeTypePtr
+ >>= readUTFString
+#endif
+
+-- | Guesses the content type based on example data. If the function is uncertain, @resultUncertain@ will
+-- be set to 'True'. Either filename or data may be 'Nothing', in which case the guess will be based solely on
+-- the other argument.
+contentTypeGuess :: String
+ -> String -- ^ @data@ a stream of data,
+ -> Int -- ^ @dataSize@ the size of data [_$_]
+ -> IO (Bool, String) -- ^ returns a string indicating a guessed content type for the given data.
+contentTypeGuess filename dat dataSize =
+ withUTFString filename $ \ filenamePtr -> [_$_]
+ withUTFString dat $ \ datPtr -> [_$_]
+ alloca $ \ resultUncertainPtr -> do
+ strPtr <- {#call g_content_type_guess#} [_$_]
+ filenamePtr [_$_]
+ (castPtr datPtr)
+ (fromIntegral dataSize)
+ (castPtr resultUncertainPtr)
+ resultUncertain <- peek resultUncertainPtr
+ str <- readUTFString strPtr
+ return (resultUncertain, str)
+
+#if GLIB_CHECK_VERSION(2,18,0)
+-- | Tries to guess the type of the tree with root root, by looking at the files it contains. The result
+-- is an array of content types, with the best guess coming first.
+-- [_$_]
+-- The types returned all have the form x-content/foo, e.g. x-content/audio-cdda (for audio CDs) or
+-- x-content/image-dcf (for a camera memory card). See the shared-mime-info specification for more on
+-- x-content types.
+-- [_$_]
+-- This function is useful in the implementation of 'mountGuessContentType'.
+contentTypeGuessForTree :: FileClass file
+ => file -- ^ @root@ the root of the tree to guess a type for [_$_]
+ -> IO [String] -- ^ returns an 'Nothing'-terminated array of zero or more content types
+contentTypeGuessForTree root =
+ {#call g_content_type_guess_for_tree#} (toFile root)
+ >>= readUTFStringArray0
+#endif
+
+-- | Gets a list of strings containing all the registered content types known to the system. [_$_]
+contentTypesGetRegistered :: [_$_]
+ IO [String] -- ^ returns GList of the registered content types. [_$_]
+contentTypesGetRegistered = do
+ glistPtr <- {#call g_content_types_get_registered#} [_$_]
+ strPtrs <- fromGList glistPtr
+ {# call unsafe g_list_free #} glistPtr
+ mapM readUTFString strPtrs
+
+ [_$_]
hunk ./gio/gio.cabal 57
+ System.GIO.File.ContentType
}
|