module System.Gnome.VFS.Util (
formatFileSizeForDisplay,
formatURIForDisplay,
urlShow,
urlShowWithEnv,
isExecutableCommandString,
escapeString,
escapePathString,
escapeHostAndPathString,
escapeSlashes,
escapeSet,
unescapeString,
unescapeStringForDisplay,
makeURICanonical,
makeURICanonicalStripFragment,
makePathNameCanonical,
makeURIFromInput,
makeURIFromInputWithDirs,
makeURIFromShellArg,
expandInitialTilde,
getLocalPathFromURI,
getURIFromLocalPath,
iconPathFromFilename,
getVolumeFreeSpace,
urisMatch,
getURIScheme,
isPrimaryThread,
openFD,
) where
import Control.Exception (assert)
import Control.Monad (liftM)
import System.Posix.Types (Fd)
import System.Glib.FFI
import System.Glib.UTFString
import System.Gnome.VFS.BasicTypes
import System.Gnome.VFS.Marshal
formatFileSizeForDisplay :: FileSize
-> String
formatFileSizeForDisplay size =
unsafePerformIO $ gnome_vfs_format_file_size_for_display (fromIntegral size) >>= readUTFString
formatURIForDisplay :: TextURI
-> Maybe String
formatURIForDisplay textURI =
unsafePerformIO $ withUTFString textURI gnome_vfs_format_uri_for_display >>= maybePeek readUTFString
urlShow :: String
-> IO ()
urlShow url =
voidResultMarshal $ withUTFString url gnome_vfs_url_show
urlShowWithEnv :: String
-> [String]
-> IO ()
urlShowWithEnv url env =
voidResultMarshal $ withUTFStringArray env $ \cEnv ->
withUTFString url $ \cURL ->
gnome_vfs_url_show_with_env cURL cEnv
marshalPureString :: IO CString
-> String
marshalPureString cAction =
unsafePerformIO $ cAction >>= readUTFString
marshalPureMaybeString :: IO CString
-> Maybe String
marshalPureMaybeString cAction =
unsafePerformIO $ cAction >>= maybePeek readUTFString
escapeString :: String
-> String
escapeString string =
marshalPureString $ withUTFString string gnome_vfs_escape_string
escapePathString :: FilePath
-> String
escapePathString path =
marshalPureString $ withUTFString path gnome_vfs_escape_path_string
escapeHostAndPathString :: FilePath
-> String
escapeHostAndPathString path =
marshalPureString $ withUTFString path gnome_vfs_escape_host_and_path_string
escapeSlashes :: String
-> String
escapeSlashes string =
marshalPureString $ withUTFString string gnome_vfs_escape_slashes
escapeSet :: String
-> String
-> String
escapeSet string matchSet =
marshalPureString $ withUTFString matchSet $ \cMatchSet ->
withUTFString string $ \cString ->
gnome_vfs_escape_set cString cMatchSet
unescapeString :: String
-> String
-> String
unescapeString escapedString illegalCharacters =
marshalPureString $ withUTFString illegalCharacters $ \cIllegalCharacters ->
withUTFString escapedString $ \cEscapedString ->
gnome_vfs_unescape_string cEscapedString cIllegalCharacters
makeURICanonical :: TextURI
-> Maybe TextURI
makeURICanonical textURI =
unsafePerformIO $ withUTFString textURI gnome_vfs_make_uri_canonical >>= maybePeek readUTFString
makeURICanonicalStripFragment :: TextURI
-> Maybe TextURI
makeURICanonicalStripFragment textURI =
unsafePerformIO $ withUTFString textURI gnome_vfs_make_uri_canonical_strip_fragment >>= maybePeek readUTFString
makePathNameCanonical :: FilePath
-> Maybe TextURI
makePathNameCanonical pathName =
unsafePerformIO $ withUTFString pathName gnome_vfs_make_path_name_canonical >>= maybePeek readUTFString
makeURIFromInput :: String
-> Maybe TextURI
makeURIFromInput location =
unsafePerformIO $ withUTFString location gnome_vfs_make_uri_from_input >>= maybePeek readUTFString
makeURIFromInputWithDirs :: FilePath
-> [MakeURIDirs]
-> IO TextURI
makeURIFromInputWithDirs location dirs =
(withUTFString location $ flip gnome_vfs_make_uri_from_input_with_dirs $ cFromFlags dirs) >>= readUTFString
makeURIFromShellArg :: String
-> String
makeURIFromShellArg uri =
unsafePerformIO $ withUTFString uri gnome_vfs_make_uri_from_shell_arg >>= readUTFString
expandInitialTilde :: String
-> IO String
expandInitialTilde path =
withUTFString path gnome_vfs_expand_initial_tilde >>= readUTFString
unescapeStringForDisplay :: String
-> String
unescapeStringForDisplay escaped =
marshalPureString $ withUTFString escaped gnome_vfs_unescape_string_for_display
getLocalPathFromURI :: TextURI
-> Maybe FilePath
getLocalPathFromURI uri =
marshalPureMaybeString $ withUTFString uri gnome_vfs_get_local_path_from_uri
getURIFromLocalPath :: FilePath
-> TextURI
getURIFromLocalPath localFullPath =
marshalPureString $ withUTFString localFullPath gnome_vfs_get_uri_from_local_path
isExecutableCommandString :: String
-> IO Bool
isExecutableCommandString commandString =
liftM toBool $ withUTFString commandString gnome_vfs_is_executable_command_string
getVolumeFreeSpace :: URI
-> IO FileSize
getVolumeFreeSpace uri =
alloca $ \cFileSizePtr ->
genericResultMarshal ((\(URI arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gnome_vfs_get_volume_free_space argPtr1 arg2) uri cFileSizePtr)
(liftM fromIntegral $ peek cFileSizePtr)
(do cFileSize <- peek cFileSizePtr
assert (cFileSize == 0) $ return ())
iconPathFromFilename :: String
-> IO String
iconPathFromFilename filename =
withUTFString filename gnome_vfs_icon_path_from_filename >>= readUTFString
isPrimaryThread :: IO Bool
isPrimaryThread =
liftM toBool gnome_vfs_is_primary_thread
getURIScheme :: TextURI
-> Maybe String
getURIScheme uri =
marshalPureMaybeString $ withUTFString uri gnome_vfs_get_uri_scheme
urisMatch :: TextURI
-> TextURI
-> Bool
urisMatch uri1 uri2 =
unsafePerformIO $ liftM toBool $ withUTFString uri1 $ \cURI1 ->
withUTFString uri2 $ gnome_vfs_uris_match cURI1
openFD :: Fd
-> IO Handle
openFD filedes =
newObjectResultMarshal Handle $ \cHandlePtr ->
gnome_vfs_open_fd (castPtr cHandlePtr) $ fromIntegral filedes
foreign import ccall safe "gnome_vfs_format_file_size_for_display"
gnome_vfs_format_file_size_for_display :: (CULLong -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_format_uri_for_display"
gnome_vfs_format_uri_for_display :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_url_show"
gnome_vfs_url_show :: ((Ptr CChar) -> (IO CInt))
foreign import ccall safe "gnome_vfs_url_show_with_env"
gnome_vfs_url_show_with_env :: ((Ptr CChar) -> ((Ptr (Ptr CChar)) -> (IO CInt)))
foreign import ccall safe "gnome_vfs_escape_string"
gnome_vfs_escape_string :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_escape_path_string"
gnome_vfs_escape_path_string :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_escape_host_and_path_string"
gnome_vfs_escape_host_and_path_string :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_escape_slashes"
gnome_vfs_escape_slashes :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_escape_set"
gnome_vfs_escape_set :: ((Ptr CChar) -> ((Ptr CChar) -> (IO (Ptr CChar))))
foreign import ccall safe "gnome_vfs_unescape_string"
gnome_vfs_unescape_string :: ((Ptr CChar) -> ((Ptr CChar) -> (IO (Ptr CChar))))
foreign import ccall safe "gnome_vfs_make_uri_canonical"
gnome_vfs_make_uri_canonical :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_make_uri_canonical_strip_fragment"
gnome_vfs_make_uri_canonical_strip_fragment :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_make_path_name_canonical"
gnome_vfs_make_path_name_canonical :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_make_uri_from_input"
gnome_vfs_make_uri_from_input :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_make_uri_from_input_with_dirs"
gnome_vfs_make_uri_from_input_with_dirs :: ((Ptr CChar) -> (CInt -> (IO (Ptr CChar))))
foreign import ccall safe "gnome_vfs_make_uri_from_shell_arg"
gnome_vfs_make_uri_from_shell_arg :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_expand_initial_tilde"
gnome_vfs_expand_initial_tilde :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_unescape_string_for_display"
gnome_vfs_unescape_string_for_display :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_get_local_path_from_uri"
gnome_vfs_get_local_path_from_uri :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_get_uri_from_local_path"
gnome_vfs_get_uri_from_local_path :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_is_executable_command_string"
gnome_vfs_is_executable_command_string :: ((Ptr CChar) -> (IO CInt))
foreign import ccall safe "gnome_vfs_get_volume_free_space"
gnome_vfs_get_volume_free_space :: ((Ptr URI) -> ((Ptr CULLong) -> (IO CInt)))
foreign import ccall safe "gnome_vfs_icon_path_from_filename"
gnome_vfs_icon_path_from_filename :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_is_primary_thread"
gnome_vfs_is_primary_thread :: (IO CInt)
foreign import ccall safe "gnome_vfs_get_uri_scheme"
gnome_vfs_get_uri_scheme :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall safe "gnome_vfs_uris_match"
gnome_vfs_uris_match :: ((Ptr CChar) -> ((Ptr CChar) -> (IO CInt)))
foreign import ccall safe "gnome_vfs_open_fd"
gnome_vfs_open_fd :: ((Ptr Handle) -> (CInt -> (IO CInt)))