1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
|
{-# 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 : gtk2hs-devel@lists.sourceforge.net
-- Stability : alpha
-- Portability : portable (depends on GHC)
module System.GIO.File.FileInfo (
-- * Details
--
-- | Functionality for manipulating basic metadata for files. 'FileInfo' implements methods for getting
-- information that all files should contain, and allows for manipulation of extended attributes.
--
-- See 'FileAttribute' for more information on how GIO handles file attributes.
--
-- To obtain a 'FileInfo' for a 'File', use 'fileQueryInfo'. To obtain a
-- 'FileInfo' for a file input or output stream, use 'fileInputStreamQueryInfo' or
-- 'fileOutputStreamQueryInfo'.
--
-- To change the actual attributes of a file, you should then set the attribute in the 'FileInfo' and
-- call 'fileSetAttributesFromInfo' on a 'File'.
--
-- However, not all attributes can be changed in the file. For instance, the actual size of a file
-- cannot be changed via 'fileInfoSetSize' and
-- 'fileQueryWritableNamespaces' to discover the settable attributes of a particular file at
-- runtime.
--
-- 'FileAttributeMatcher' allows for searching through a 'FileInfo' for attributes.
-- * Types
FileInfo(..),
FileInfoClass,
-- * Enums,
FileAttributeStatus (..),
-- * Methods
fileInfoNew,
fileInfoDup,
fileInfoCopyInto,
fileInfoHasAttribute,
#if GLIB_CHECK_VERSION(2,22,0)
fileInfoHasNamespace,
#endif
fileInfoListAttributes,
fileInfoGetAttributeType,
fileInfoRemoveAttribute,
fileInfoGetAttributeAsString,
fileInfoGetAttributeStatus,
fileInfoGetAttributeString,
#if GLIB_CHECK_VERSION(2,22,0)
fileInfoGetAttributeStringList,
#endif
fileInfoGetAttributeByteString,
fileInfoGetAttributeBool,
fileInfoGetAttributeWord32,
fileInfoGetAttributeInt32,
fileInfoGetAttributeWord64,
fileInfoGetAttributeInt64,
fileInfoGetAttributeObject,
#if GLIB_CHECK_VERSION(2,22,0)
fileInfoSetAttributeStatus,
#endif
fileInfoSetAttributeString,
#if GLIB_CHECK_VERSION(2,22,0)
fileInfoSetAttributeStringList,
#endif
fileInfoSetAttributeByteString,
fileInfoSetAttributeBool,
fileInfoSetAttributeWord32,
fileInfoSetAttributeInt32,
fileInfoSetAttributeWord64,
fileInfoSetAttributeInt64,
fileInfoSetAttributeObject,
fileInfoClearStatus,
fileInfoGetFileType,
fileInfoGetIsHidden,
fileInfoGetIsBackup,
fileInfoGetIsSymlink,
fileInfoGetName,
fileInfoGetDisplayName,
fileInfoGetEditName,
fileInfoGetIcon,
fileInfoGetContentType,
fileInfoGetModificationTime,
fileInfoGetSize,
fileInfoGetSymlinkTarget,
fileInfoGetEtag,
fileInfoGetSortOrder,
fileInfoUnsetAttributeMask,
fileInfoSetFileType,
fileInfoSetIsHidden,
fileInfoSetIsSymlink,
fileInfoSetName,
fileInfoSetDisplayName,
fileInfoSetEditName,
fileInfoSetIcon,
fileInfoSetContentType,
fileInfoSetModificationTime,
fileInfoSetSize,
-- 'fileInfoSetSymlinkTarget' use *static string* that we don't understand the purpose of this function.
-- If someone know how to use it, uncomment it and fix documentation.
-- fileInfoSetSymlinkTarget,
fileInfoSetSortOrder,
) where
import Control.Monad
import Data.ByteString (ByteString)
import Data.ByteString (useAsCString)
import Data.ByteString.Unsafe (unsafePackCStringFinalizer)
import System.Glib.FFI
import System.Glib.Flags
import System.Glib.GError
import System.Glib.UTFString
import System.Glib.GObject
import System.Glib.GDateTime
import System.GIO.Enums
import System.GIO.File.FileAttribute
{#import System.GIO.Types#}
{# context lib = "gio" prefix = "g" #}
-- | Creates a new file info structure.
fileInfoNew :: IO FileInfo
fileInfoNew =
wrapNewGObject mkFileInfo $
{#call g_file_info_new#}
-- | Duplicates a file info structure.
fileInfoDup :: FileInfoClass info => info -> IO FileInfo
fileInfoDup info =
wrapNewGObject mkFileInfo $
{#call g_file_info_dup#} (toFileInfo info)
-- | Copies all of the 'FileAttributes' from @srcInfo@ to @destInfo@.
fileInfoCopyInto :: (FileInfoClass srcInfo, FileInfoClass destInfo)
=> srcInfo -- ^ @srcInfo@ source to copy attributes from.
-> destInfo -- ^ @destInfo@ destination to copy attributes to.
-> IO ()
fileInfoCopyInto srcInfo destInfo =
{#call g_file_info_copy_into#} (toFileInfo srcInfo) (toFileInfo destInfo)
-- | Checks if a file info structure has an attribute named attribute.
fileInfoHasAttribute :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> Bool -- ^ returns 'True' if Ginfo has an attribute named attribute, 'False' otherwise.
fileInfoHasAttribute info attribute =
toBool $ unsafePerformIO $
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_has_attribute#} (toFileInfo info) attributePtr
#if GLIB_CHECK_VERSION(2,22,0)
-- | Checks if a file info structure has an attribute in the specified @nameSpace@.
fileInfoHasNamespace :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @namespace@ a file namespace key.
-> Bool -- ^ returns 'True' if Ginfo has an namespace named namespace, 'False' otherwise.
fileInfoHasNamespace info namespace =
toBool $ unsafePerformIO $
withUTFString namespace $ \ namespacePtr ->
{#call g_file_info_has_namespace#} (toFileInfo info) namespacePtr
#endif
-- | Lists the file info structure's attributes.
fileInfoListAttributes :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @nameSpace@ a file attribute key's namespace.
-> IO [string]-- ^ returns a array of strings of all of the possible attribute types for the given @nameSpace@
fileInfoListAttributes info nameSpace =
withUTFString nameSpace $ \ nameSpacePtr ->
{#call g_file_info_list_attributes#} (toFileInfo info) nameSpacePtr
>>= readUTFStringArray0
-- | Gets the attribute type for an attribute key.
fileInfoGetAttributeType :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO FileAttributeType -- ^ returns a 'FileAttributeType' for the given attribute, or 'FileAttributeTypeInvalid' if the key is not set.
fileInfoGetAttributeType info attribute =
liftM (toEnum . fromIntegral) $
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_get_attribute_type#} (toFileInfo info) attributePtr
-- | Removes all cases of attribute from info if it exists.
fileInfoRemoveAttribute :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO ()
fileInfoRemoveAttribute info attribute =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_remove_attribute#} (toFileInfo info) attributePtr
-- | Gets the value of a attribute, formatted as a string. This escapes things as needed to make the
-- string valid utf8.
fileInfoGetAttributeAsString :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO string -- ^ returns a UTF-8 string associated with the given attribute.
fileInfoGetAttributeAsString info attribute =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_get_attribute_as_string#} (toFileInfo info) attributePtr
>>= readUTFString
-- | Gets the attribute status for an attribute key.
fileInfoGetAttributeStatus :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO FileAttributeStatus -- ^ returns a 'FileAttributeStatus' for the given attribute, or 'FileAttributeStatusUnset' if the key is invalid.
fileInfoGetAttributeStatus info attribute =
liftM (toEnum . fromIntegral) $
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_get_attribute_status#} (toFileInfo info) attributePtr
-- | Gets the value of a string attribute.
fileInfoGetAttributeString :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO string -- ^ returns the contents of the attribute value as a string
fileInfoGetAttributeString info attribute =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_get_attribute_string#} (toFileInfo info) attributePtr
>>= readUTFString
#if GLIB_CHECK_VERSION(2,22,0)
-- | Gets the value of a stringv attribute. If the attribute does not contain a stringv
fileInfoGetAttributeStringList :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO [string] -- ^ returns the contents of the attribute value as a string list
fileInfoGetAttributeStringList info attribute =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_get_attribute_stringv#} (toFileInfo info) attributePtr
>>= readUTFStringArray0
#endif
-- | Gets the value of a byte string attribute.
fileInfoGetAttributeByteString :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO ByteString -- ^ returns the contents of the attribute value as a ByteString
fileInfoGetAttributeByteString info attribute =
withUTFString attribute $ \ attributePtr -> do
sPtr <- {#call g_file_info_get_attribute_byte_string#} (toFileInfo info) attributePtr
sLen <- lengthArray0 0 sPtr
unsafePackCStringFinalizer (castPtr sPtr) (fromIntegral sLen)
({#call unsafe g_free#} (castPtr sPtr))
-- | Gets the value of a boolean attribute.
fileInfoGetAttributeBool :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO Bool -- ^ returns the contents of the attribute value as a bool
fileInfoGetAttributeBool info attribute =
liftM toBool $
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_get_attribute_boolean#} (toFileInfo info) attributePtr
-- | Gets an Word32 contained within the attribute.
fileInfoGetAttributeWord32 :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO Word32 -- ^ returns the contents of the attribute value as a bool
fileInfoGetAttributeWord32 info attribute =
liftM fromIntegral $
withUTFString attribute $ \ attributePtr -> do
{#call g_file_info_get_attribute_uint32#} (toFileInfo info) attributePtr
-- | Gets an Int32 contained within the attribute.
fileInfoGetAttributeInt32 :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO Int32 -- ^ returns the contents of the attribute value as a bool
fileInfoGetAttributeInt32 info attribute =
liftM fromIntegral $
withUTFString attribute $ \ attributePtr -> do
{#call g_file_info_get_attribute_int32#} (toFileInfo info) attributePtr
-- | Gets an Word64 contained within the attribute.
fileInfoGetAttributeWord64 :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO Word64 -- ^ returns the contents of the attribute value as a bool
fileInfoGetAttributeWord64 info attribute =
liftM fromIntegral $
withUTFString attribute $ \ attributePtr -> do
{#call g_file_info_get_attribute_uint64#} (toFileInfo info) attributePtr
-- | Gets an Int64 contained within the attribute.
fileInfoGetAttributeInt64 :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO Int64 -- ^ returns the contents of the attribute value as a bool
fileInfoGetAttributeInt64 info attribute =
liftM fromIntegral $
withUTFString attribute $ \ attributePtr -> do
{#call g_file_info_get_attribute_int64#} (toFileInfo info) attributePtr
-- | Gets the value of a GObject attribute.
fileInfoGetAttributeObject :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> IO (Maybe GObject) -- ^ returns the contents of the attribute value as a object
fileInfoGetAttributeObject info attribute =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_get_attribute_object#} (toFileInfo info) attributePtr
>>= \x -> maybeNull (makeNewGObject mkGObject) (return $ castPtr x)
#if GLIB_CHECK_VERSION(2,22,0)
-- | Sets the attribute status for an attribute key. This is only needed by external code that implement
-- 'fileSetAttributesFromInfo' or similar functions.
--
-- The attribute must exist in info for this to work. Otherwise 'False' is returned and info is
-- unchanged.
fileInfoSetAttributeStatus :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key
-> FileAttributeStatus -- ^ @status@ a 'FileAttributeStatus'
-> IO Bool -- ^ returns 'True' if the status was changed, 'False' if the key was not set.
fileInfoSetAttributeStatus info attribute status =
liftM toBool $
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_set_attribute_status#}
(toFileInfo info)
attributePtr
((fromIntegral . fromEnum) status)
#endif
-- | Sets the attribute to contain the given @attrValue@, if possible.
fileInfoSetAttributeString :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> string -- ^ @attrValue@ a string.
-> IO ()
fileInfoSetAttributeString info attribute attrValue =
withUTFString attribute $ \ attributePtr ->
withUTFString attrValue $ \ attrValuePtr ->
{#call g_file_info_set_attribute_string#} (toFileInfo info) attributePtr attrValuePtr
#if GLIB_CHECK_VERSION(2,22,0)
-- | Sets the attribute to contain the given @attrValue@, if possible.
fileInfoSetAttributeStringList :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> [string] -- ^ @attrValue@ a string.
-> IO ()
fileInfoSetAttributeStringList info attribute attrValue =
withUTFString attribute $ \ attributePtr ->
withUTFStringArray0 attrValue $ \ attrValuePtr ->
{#call g_file_info_set_attribute_stringv#} (toFileInfo info) attributePtr attrValuePtr
#endif
-- | Sets the attribute to contain the given @attrValue@, if possible.
fileInfoSetAttributeByteString :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> ByteString -- ^ @attrValue@ a string.
-> IO ()
fileInfoSetAttributeByteString info attribute attrValue =
withUTFString attribute $ \ attributePtr ->
useAsCString attrValue $ \ attrValuePtr ->
{#call g_file_info_set_attribute_byte_string#} (toFileInfo info) attributePtr attrValuePtr
-- | Sets the attribute to contain the given @attrValue@, if possible.
fileInfoSetAttributeBool :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> Bool -- ^ @attrValue@ a string.
-> IO ()
fileInfoSetAttributeBool info attribute attrValue =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_set_attribute_boolean#} (toFileInfo info) attributePtr (fromBool attrValue)
-- | Sets the attribute to contain the given @attrValue@, if possible.
fileInfoSetAttributeWord32 :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> Word32 -- ^ @attrValue@ an Word32
-> IO ()
fileInfoSetAttributeWord32 info attribute attrValue =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_set_attribute_uint32#} (toFileInfo info) attributePtr (fromIntegral attrValue)
-- | Sets the attribute to contain the given @attrValue@, if possible.
fileInfoSetAttributeInt32 :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> Int32 -- ^ @attrValue@ an Int32
-> IO ()
fileInfoSetAttributeInt32 info attribute attrValue =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_set_attribute_int32#} (toFileInfo info) attributePtr (fromIntegral attrValue)
-- | Sets the attribute to contain the given @attrValue@, if possible.
fileInfoSetAttributeWord64 :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> Word64 -- ^ @attrValue@ an Word64
-> IO ()
fileInfoSetAttributeWord64 info attribute attrValue =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_set_attribute_uint64#} (toFileInfo info) attributePtr (fromIntegral attrValue)
-- | Sets the attribute to contain the given @attrValue@, if possible.
fileInfoSetAttributeInt64 :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @attribute@ a file attribute key.
-> Int64 -- ^ @attrValue@ an Int64
-> IO ()
fileInfoSetAttributeInt64 info attribute attrValue =
withUTFString attribute $ \ attributePtr ->
{#call g_file_info_set_attribute_int64#} (toFileInfo info) attributePtr (fromIntegral attrValue)
-- | Sets the attribute to contain the given @attrValue@, if possible.
fileInfoSetAttributeObject :: (FileInfoClass info, GlibString string) => info
-> string
-> GObject
-> IO ()
fileInfoSetAttributeObject info attribute (GObject attrValue) =
withUTFString attribute $ \ attributePtr ->
withForeignPtr attrValue $ \attrValuePtr ->
{#call g_file_info_set_attribute_object#} (toFileInfo info) attributePtr (castPtr attrValuePtr)
-- | Clears the status information from info.
--
fileInfoClearStatus :: FileInfoClass info => info -> IO ()
fileInfoClearStatus info =
{#call g_file_info_clear_status #} (toFileInfo info)
-- | Gets a file's type (whether it is a regular file, symlink, etc). This is different from the file's
-- content type, see 'fileInfoGetContentType'.
--
fileInfoGetFileType :: FileInfoClass info => info
-> FileType -- ^ returns a 'FileType' for the given file.
fileInfoGetFileType info =
(toEnum . fromIntegral) $ unsafePerformIO $
{#call g_file_info_get_file_type#} (toFileInfo info)
-- | Checks if a file is hidden.
fileInfoGetIsHidden :: FileInfoClass info => info
-> Bool -- ^ returns 'True' if the file is a hidden file, 'False' otherwise.
fileInfoGetIsHidden info =
toBool $ unsafePerformIO $
{#call g_file_info_get_is_hidden#} (toFileInfo info)
-- | Checks if a file is a backup file.
fileInfoGetIsBackup :: FileInfoClass info => info
-> Bool -- ^ returns 'True' if the file is a backup file, 'False' otherwise.
fileInfoGetIsBackup info =
toBool $ unsafePerformIO $
{#call g_file_info_get_is_backup#} (toFileInfo info)
-- | Checks if a file is a symlink file.
fileInfoGetIsSymlink :: FileInfoClass info => info
-> Bool -- ^ returns 'True' if the file is a symlink file, 'False' otherwise.
fileInfoGetIsSymlink info =
toBool $ unsafePerformIO $
{#call g_file_info_get_is_symlink#} (toFileInfo info)
-- | Gets the name for a file.
fileInfoGetName :: FileInfoClass info => info
-> Maybe ByteString -- ^ returns a string containing the file name.
fileInfoGetName info =
unsafePerformIO $ do
sPtr <- {#call g_file_info_get_name#} (toFileInfo info)
if sPtr == nullPtr
then return Nothing
else do
sLen <- lengthArray0 0 sPtr
liftM Just $ unsafePackCStringFinalizer (castPtr sPtr) (fromIntegral sLen)
({#call unsafe g_free#} (castPtr sPtr))
-- | Gets the display name for a file.
fileInfoGetDisplayName :: (FileInfoClass info, GlibString string) => info
-> Maybe string -- ^ returns a string containing the display name.
fileInfoGetDisplayName info =
unsafePerformIO $
{#call g_file_info_get_display_name#} (toFileInfo info)
>>= maybePeek readUTFString
-- | Gets the edit name for a file.
fileInfoGetEditName :: (FileInfoClass info, GlibString string) => info
-> Maybe string -- ^ returns a string containing the edit name.
fileInfoGetEditName info =
unsafePerformIO $
{#call g_file_info_get_edit_name#} (toFileInfo info)
>>= maybePeek readUTFString
-- | Gets the icon for a file.
fileInfoGetIcon :: FileInfoClass info => info
-> IO Icon -- ^ returns 'Icon' for the given info.
fileInfoGetIcon info =
makeNewGObject mkIcon $
{#call g_file_info_get_icon#} (toFileInfo info)
-- | Gets the file's content type.
fileInfoGetContentType :: (FileInfoClass info, GlibString string) => info
-> Maybe string -- ^ returns a string containing the file's content type.
fileInfoGetContentType info =
unsafePerformIO $
{#call g_file_info_get_content_type#} (toFileInfo info)
>>= maybePeek peekUTFString
-- | Gets the modification time of the current info and sets it in result.
fileInfoGetModificationTime :: FileInfoClass info => info
-> GTimeVal
fileInfoGetModificationTime info =
unsafePerformIO $
alloca $ \ timeValPtr -> do
{#call g_file_info_get_modification_time#} (toFileInfo info) (castPtr timeValPtr)
peek timeValPtr
-- | Gets the file's size.
fileInfoGetSize :: FileInfoClass info => info
-> Int64 -- ^ returns a 'Offset' containing the file's size.
fileInfoGetSize info =
fromIntegral $ unsafePerformIO $
{#call g_file_info_get_size#} (toFileInfo info)
-- | Gets the symlink target for a given 'FileInfo'.
fileInfoGetSymlinkTarget :: (FileInfoClass info, GlibString string) => info
-> Maybe string -- ^ returns a string containing the symlink target.
fileInfoGetSymlinkTarget info =
unsafePerformIO $
{#call g_file_info_get_symlink_target#} (toFileInfo info)
>>= maybePeek readUTFString
-- | Gets the entity tag for a given 'FileInfo'. See 'FileAttributeEtagValue'.
fileInfoGetEtag :: (FileInfoClass info, GlibString string) => info
-> Maybe string -- ^ returns a string containing the value of the "etag:value" attribute.
fileInfoGetEtag info =
unsafePerformIO $
{#call g_file_info_get_etag#} (toFileInfo info)
>>= maybePeek readUTFString
-- | Gets the value of the @sortOrder@ attribute from the 'FileInfo'. See
-- 'FileAttributeStandardSortOrder'.
fileInfoGetSortOrder :: FileInfoClass info => info
-> Int -- ^ returns the value of the \"standard::sort_order\" attribute.
fileInfoGetSortOrder info =
fromIntegral $ unsafePerformIO $
{#call g_file_info_get_sort_order#} (toFileInfo info)
-- | Unsets a mask set by 'fileInfoSetAttributeMask', if one is set.
fileInfoUnsetAttributeMask :: FileInfoClass info => info -> IO ()
fileInfoUnsetAttributeMask info =
{#call g_file_info_unset_attribute_mask#} (toFileInfo info)
-- | Sets the file type in a 'FileInfo' to type. See 'FileAttributeStandardType'.
fileInfoSetFileType :: FileInfoClass info => info -> FileType -> IO ()
fileInfoSetFileType info fType =
{#call g_file_info_set_file_type#}
(toFileInfo info)
((fromIntegral . fromEnum) fType)
-- | Sets the @isHidden@ attribute in a 'FileInfo' according to @isSymlink@. See
-- 'FileAttributeStandardIsHidden'.
fileInfoSetIsHidden :: FileInfoClass info => info -> Bool -> IO ()
fileInfoSetIsHidden info isHidden =
{#call g_file_info_set_is_hidden#} (toFileInfo info) (fromBool isHidden)
-- | Sets the @isSymlink@ attribute in a 'FileInfo' according to @isSymlink@. See
-- 'FileAttributeStandardIsSymlink'.
fileInfoSetIsSymlink :: FileInfoClass info => info -> Bool -> IO ()
fileInfoSetIsSymlink info isSymlink =
{#call g_file_info_set_is_symlink#} (toFileInfo info) (fromBool isSymlink)
-- | Sets the name attribute for the current 'FileInfo'. See 'FileAttributeStandardName'.
fileInfoSetName :: FileInfoClass info => info -> ByteString -> IO ()
fileInfoSetName info name =
useAsCString name $ \ namePtr ->
{#call g_file_info_set_name#} (toFileInfo info) namePtr
-- | Sets the display name for the current 'FileInfo'. See 'FileAttributeStandardDisplayName'.
fileInfoSetDisplayName :: (FileInfoClass info, GlibString string) => info -> string -> IO ()
fileInfoSetDisplayName info displayName =
withUTFString displayName $ \ displayNamePtr ->
{#call g_file_info_set_display_name#} (toFileInfo info) displayNamePtr
-- | Sets the edit name for the current 'FileInfo'. See 'FileAttributeStandardEditName'.
fileInfoSetEditName :: (FileInfoClass info, GlibString string) => info -> string -> IO ()
fileInfoSetEditName info editName =
withUTFString editName $ \ editNamePtr ->
{#call g_file_info_set_edit_name#} (toFileInfo info) editNamePtr
-- | Sets the icon for a given 'FileInfo'. See 'FileAttributeStandardIcon'.
fileInfoSetIcon :: FileInfoClass info => info -> Icon -> IO ()
fileInfoSetIcon info icon =
{#call g_file_info_set_icon#} (toFileInfo info) (toIcon icon)
-- | Sets the content type attribute for a given 'FileInfo'. See 'FileAttributeStandardContentType'.
fileInfoSetContentType :: (FileInfoClass info, GlibString string) => info
-> string -- ^ @contentType@ a content type. See GContentType.
-> IO ()
fileInfoSetContentType info contentType =
withUTFString contentType $ \ contentTypePtr ->
{#call g_file_info_set_content_type#} (toFileInfo info) contentTypePtr
-- | Sets the 'FileAttributeTimeModified' attribute in the file info to the given time value.
fileInfoSetModificationTime :: FileInfoClass info => info
-> GTimeVal
-> IO ()
fileInfoSetModificationTime info mtime =
with mtime $ \ mtimePtr ->
{#call g_file_info_set_modification_time#} (toFileInfo info) (castPtr mtimePtr)
-- | Sets the 'FileAttributeStandardSize' attribute in the file info to the given size.
fileInfoSetSize :: FileInfoClass info => info
-> Int64 -- ^ @size@ a goffset containing the file's size.
-> IO ()
fileInfoSetSize info size =
{#call g_file_info_set_size#} (toFileInfo info) (fromIntegral size)
-- | Sets the 'FileAttributeStandardSymlinkTarget' attribute in the file info to the given symlink
-- target.
-- fileInfoSetSymlinkTarget :: FileInfoClass info => info
-- -> String -- ^ @symlinkTarget@ a static string containing a path to a symlink target.
-- -> IO ()
-- fileInfoSetSymlinkTarget info symlinkTarget =
-- withUTFString symlinkTarget $ \ symlinkTargetPtr ->
-- {#call g_file_info_set_symlink_target#} (toFileInfo info) symlinkTargetPtr
-- | Sets the sort order attribute in the file info structure. See 'FileAttributeStandardSortOrder'.
fileInfoSetSortOrder :: FileInfoClass info => info
-> Int -- ^ @sortOrder@ a sort order integer.
-> IO ()
fileInfoSetSortOrder info sortOrder =
{#call g_file_info_set_sort_order#} (toFileInfo info) (fromIntegral sortOrder)
|