{-# LINE 2 "./System/GIO/Volumes/Volume.chs" #-}
-- 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:
--
-- 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.Volumes.Volume (
-- * Details
--
-- | The 'Volume' interface represents user-visible objects that can be mounted. Note, when porting from
-- GnomeVFS, 'Volume' is the moral equivalent of GnomeVFSDrive.
--
-- Mounting a 'Volume' instance is an asynchronous operation. For more information about asynchronous
-- operations, see 'AsyncReady' and GSimpleAsyncReady. To mount a 'Volume', first call 'volumeMount'
-- with (at least) the 'Volume' instance, optionally a 'MountOperation' object and a 'AsyncReadyCallback'.
--
-- Typically, one will only want to pass 'Nothing' for the 'MountOperation' if automounting all volumes when
-- a desktop session starts since it's not desirable to put up a lot of dialogs asking for credentials.
--
-- The callback will be fired when the operation has resolved (either with success or failure), and a
-- 'AsyncReady' structure will be passed to the callback. That callback should then call
-- 'volumeMountFinish' with the 'Volume' instance and the 'AsyncReady' data to see if the operation
-- was completed successfully. If an error is present when 'volumeMountFinish' is called, then it
-- will be filled with any error information.
--
-- It is sometimes necessary to directly access the underlying operating system object behind a volume
-- (e.g. for passing a volume to an application via the commandline). For this purpose, GIO allows to
-- obtain an 'identifier' for the volume. There can be different kinds of identifiers, such as Hal
-- UDIs, filesystem labels, traditional Unix devices (e.g. /dev/sda2), uuids. GIO uses predefind
-- strings as names for the different kinds of identifiers: 'VolumeIdentifierKindHalUdi',
-- 'VolumeIdentifierKindLabel', etc. Use 'volumeGetIdentifier' to obtain an identifier for a
-- volume.
--
-- Note that 'VolumeIdentifierKindHalUdi' will only be available when the gvfs hal volume monitor
-- is in use. Other volume monitors will generally be able to provide the
-- 'VolumeIdentifierKindUnixDevice' identifier, which can be used to obtain a hal device by means
-- of 'mangerFindDeviceStringMatch'.

-- * Types
    Volume(..),
    VolumeClass,

-- * Methods
    volumeGetName,
    volumeGetUUID,
    volumeGetIcon,
    volumeGetDrive,
    volumeGetMount,
    volumeCanMount,
    volumeShouldAutomount,

    volumeGetActivationRoot,

    volumeMount,
    volumeMountFinish,
    volumeCanEject,

    volumeEjectWithOperation,
    volumeEjectWithOperationFinish,

    volumeEnumerateIdentifiers,
    volumeGetIdentifier,

-- * Signals
    volumeChanged,
    volumeRemoved,
    ) where

import Control.Monad
import Data.Maybe (fromMaybe)
import System.GIO.Enums
import System.Glib.Attributes
import System.Glib.FFI
import System.Glib.Flags
import System.Glib.GError
import System.Glib.GObject
import System.Glib.Properties
import System.Glib.Signals
import System.Glib.UTFString
import System.GIO.Async.AsyncResult
{-# LINE 104 "./System/GIO/Volumes/Volume.chs" #-}
import System.GIO.Signals
{-# LINE 105 "./System/GIO/Volumes/Volume.chs" #-}
import System.GIO.Types
{-# LINE 106 "./System/GIO/Volumes/Volume.chs" #-}


{-# LINE 108 "./System/GIO/Volumes/Volume.chs" #-}

--------------------
-- Methods
-- | Gets the name of volume.
volumeGetName :: (VolumeClass volume, GlibString string) => volume
              -> IO string -- ^ returns the name for the given volume.
volumeGetName :: forall volume string.
(VolumeClass volume, GlibString string) =>
volume -> IO string
volumeGetName volume
volume =
    (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume
-> (Ptr Volume -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO (Ptr CChar)) -> IO (Ptr CChar))
-> (Ptr Volume -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO (Ptr CChar)
g_volume_get_name Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)
    IO (Ptr CChar) -> (Ptr CChar -> IO string) -> IO string
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr CChar -> IO string
forall s. GlibString s => Ptr CChar -> IO s
readUTFString

-- | Gets the UUID for the volume. The reference is typically based on the file system UUID for the
-- volume in question and should be considered an opaque string. Returns 'Nothing' if there is no UUID
-- available.
volumeGetUUID :: (VolumeClass volume, GlibString string) => volume
              -> IO (Maybe string) -- ^ returns the UUID for volume or 'Nothing' if no UUID can be computed.
volumeGetUUID :: forall volume string.
(VolumeClass volume, GlibString string) =>
volume -> IO (Maybe string)
volumeGetUUID volume
volume =
  (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume
-> (Ptr Volume -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO (Ptr CChar)) -> IO (Ptr CChar))
-> (Ptr Volume -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO (Ptr CChar)
g_volume_get_uuid Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)
  IO (Ptr CChar)
-> (Ptr CChar -> IO (Maybe string)) -> IO (Maybe string)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Ptr CChar -> IO string) -> Ptr CChar -> IO (Maybe string)
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek Ptr CChar -> IO string
forall s. GlibString s => Ptr CChar -> IO s
readUTFString

-- | Gets the icon for volume.
volumeGetIcon :: VolumeClass volume => volume
              -> IO Icon
volumeGetIcon :: forall volume. VolumeClass volume => volume -> IO Icon
volumeGetIcon volume
volume =
  (ForeignPtr Icon -> Icon, FinalizerPtr Icon)
-> IO (Ptr Icon) -> IO Icon
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
wrapNewGObject (ForeignPtr Icon -> Icon, FinalizerPtr Icon)
forall {a}. (ForeignPtr Icon -> Icon, FinalizerPtr a)
mkIcon (IO (Ptr Icon) -> IO Icon) -> IO (Ptr Icon) -> IO Icon
forall a b. (a -> b) -> a -> b
$
  (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume -> (Ptr Volume -> IO (Ptr Icon)) -> IO (Ptr Icon)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO (Ptr Icon)) -> IO (Ptr Icon))
-> (Ptr Volume -> IO (Ptr Icon)) -> IO (Ptr Icon)
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO (Ptr Icon)
g_volume_get_icon Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)

-- | Gets the drive for the volume.
volumeGetDrive :: VolumeClass volume => volume
               -> IO (Maybe Drive) -- ^ returns a 'Drive' or 'Nothing' if volume is not associated with a drive.
volumeGetDrive :: forall volume. VolumeClass volume => volume -> IO (Maybe Drive)
volumeGetDrive volume
volume =
  (IO (Ptr Drive) -> IO Drive) -> IO (Ptr Drive) -> IO (Maybe Drive)
forall a. (IO (Ptr a) -> IO a) -> IO (Ptr a) -> IO (Maybe a)
maybeNull ((ForeignPtr Drive -> Drive, FinalizerPtr Drive)
-> IO (Ptr Drive) -> IO Drive
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
wrapNewGObject (ForeignPtr Drive -> Drive, FinalizerPtr Drive)
forall {a}. (ForeignPtr Drive -> Drive, FinalizerPtr a)
mkDrive) (IO (Ptr Drive) -> IO (Maybe Drive))
-> IO (Ptr Drive) -> IO (Maybe Drive)
forall a b. (a -> b) -> a -> b
$
  (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume
-> (Ptr Volume -> IO (Ptr Drive)) -> IO (Ptr Drive)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO (Ptr Drive)) -> IO (Ptr Drive))
-> (Ptr Volume -> IO (Ptr Drive)) -> IO (Ptr Drive)
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO (Ptr Drive)
g_volume_get_drive Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)

-- | Gets the mount for the volume.
volumeGetMount :: VolumeClass volume => volume
               -> IO (Maybe Mount) -- ^ returns a 'Mount' or 'Nothing' if volume is not associated with a mount.
volumeGetMount :: forall volume. VolumeClass volume => volume -> IO (Maybe Mount)
volumeGetMount volume
volume =
  (IO (Ptr Mount) -> IO Mount) -> IO (Ptr Mount) -> IO (Maybe Mount)
forall a. (IO (Ptr a) -> IO a) -> IO (Ptr a) -> IO (Maybe a)
maybeNull ((ForeignPtr Mount -> Mount, FinalizerPtr Mount)
-> IO (Ptr Mount) -> IO Mount
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
wrapNewGObject (ForeignPtr Mount -> Mount, FinalizerPtr Mount)
forall {a}. (ForeignPtr Mount -> Mount, FinalizerPtr a)
mkMount) (IO (Ptr Mount) -> IO (Maybe Mount))
-> IO (Ptr Mount) -> IO (Maybe Mount)
forall a b. (a -> b) -> a -> b
$
  (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume
-> (Ptr Volume -> IO (Ptr Mount)) -> IO (Ptr Mount)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO (Ptr Mount)) -> IO (Ptr Mount))
-> (Ptr Volume -> IO (Ptr Mount)) -> IO (Ptr Mount)
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO (Ptr Mount)
g_volume_get_mount Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)

-- | Checks if a volume can be mounted.
volumeCanMount :: VolumeClass volume => volume
               -> IO Bool -- ^ returns 'True' if the volume can be mounted. 'False' otherwise.
volumeCanMount :: forall volume. VolumeClass volume => volume -> IO Bool
volumeCanMount volume
volume =
  (CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$
  (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume -> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO CInt) -> IO CInt)
-> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO CInt
g_volume_can_mount Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)

-- | Returns whether the volume should be automatically mounted.
volumeShouldAutomount :: VolumeClass volume => volume
                      -> IO Bool -- ^ returns 'True' if the volume should be automatically mounted.
volumeShouldAutomount :: forall volume. VolumeClass volume => volume -> IO Bool
volumeShouldAutomount volume
volume =
  (CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$
  (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume -> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO CInt) -> IO CInt)
-> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO CInt
g_volume_should_automount Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)


-- | Gets the activation root for a 'Volume' if it is known ahead of mount time. Returns 'Nothing'
-- otherwise. If not 'Nothing' and if volume is mounted, then the result of 'mountGetRoot' on the 'Mount'
-- object obtained from 'volumeGetMount' will always either be equal or a prefix of what this
-- function returns.
volumeGetActivationRoot :: VolumeClass volume => volume
                        -> IO (Maybe File) -- ^ returns the activation root of volume or 'Nothing'.
volumeGetActivationRoot :: forall volume. VolumeClass volume => volume -> IO (Maybe File)
volumeGetActivationRoot volume
volume =
  (IO (Ptr File) -> IO File) -> IO (Ptr File) -> IO (Maybe File)
forall a. (IO (Ptr a) -> IO a) -> IO (Ptr a) -> IO (Maybe a)
maybeNull ((ForeignPtr File -> File, FinalizerPtr File)
-> IO (Ptr File) -> IO File
forall obj.
GObjectClass obj =>
(ForeignPtr obj -> obj, FinalizerPtr obj) -> IO (Ptr obj) -> IO obj
wrapNewGObject (ForeignPtr File -> File, FinalizerPtr File)
forall {a}. (ForeignPtr File -> File, FinalizerPtr a)
mkFile) (IO (Ptr File) -> IO (Maybe File))
-> IO (Ptr File) -> IO (Maybe File)
forall a b. (a -> b) -> a -> b
$
  (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume -> (Ptr Volume -> IO (Ptr File)) -> IO (Ptr File)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO (Ptr File)) -> IO (Ptr File))
-> (Ptr Volume -> IO (Ptr File)) -> IO (Ptr File)
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO (Ptr File)
g_volume_get_activation_root Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)


-- | Mounts a volume. This is an asynchronous operation, and is finished by calling
-- 'volumeMountFinish' with the volume and 'AsyncResult' returned in the callback.
volumeMount :: VolumeClass volume => volume
            -> [MountMountFlags] -- ^ @flags@ flags affecting the operation
            -> Maybe MountOperation -- ^ @mountOperation@ a 'MountOperation' or 'Nothing' to avoid user interaction.
            -> Maybe Cancellable -- ^ @cancellable@ optional 'Cancellable' object, 'Nothing' to ignore.
            -> AsyncReadyCallback -- ^ @callback@ a 'AsyncReadyCallback'
            -> IO ()
volumeMount :: forall volume.
VolumeClass volume =>
volume
-> [MountMountFlags]
-> Maybe MountOperation
-> Maybe Cancellable
-> AsyncReadyCallback
-> IO ()
volumeMount volume
volume [MountMountFlags]
flags Maybe MountOperation
mountOperation Maybe Cancellable
cancellable AsyncReadyCallback
callback = do
      GAsyncReadyCallback
cCallback <- AsyncReadyCallback -> IO GAsyncReadyCallback
marshalAsyncReadyCallback AsyncReadyCallback
callback
      (\(Volume ForeignPtr Volume
arg1) CInt
arg2 (MountOperation ForeignPtr MountOperation
arg3) (Cancellable ForeignPtr Cancellable
arg4) GAsyncReadyCallback
arg5 Ptr ()
arg6 -> ForeignPtr Volume -> (Ptr Volume -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO ()) -> IO ()) -> (Ptr Volume -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->ForeignPtr MountOperation -> (Ptr MountOperation -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr MountOperation
arg3 ((Ptr MountOperation -> IO ()) -> IO ())
-> (Ptr MountOperation -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr MountOperation
argPtr3 ->ForeignPtr Cancellable -> (Ptr Cancellable -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Cancellable
arg4 ((Ptr Cancellable -> IO ()) -> IO ())
-> (Ptr Cancellable -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Cancellable
argPtr4 ->Ptr Volume
-> CInt
-> Ptr MountOperation
-> Ptr Cancellable
-> GAsyncReadyCallback
-> Ptr ()
-> IO ()
g_volume_mount Ptr Volume
argPtr1 CInt
arg2 Ptr MountOperation
argPtr3 Ptr Cancellable
argPtr4 GAsyncReadyCallback
arg5 Ptr ()
arg6)
{-# LINE 185 "./System/GIO/Volumes/Volume.chs" #-}
        (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)
        ((Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt)
-> ([MountMountFlags] -> Int) -> [MountMountFlags] -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [MountMountFlags] -> Int
forall a. Flags a => [a] -> Int
fromFlags) [MountMountFlags]
flags)
        (MountOperation -> Maybe MountOperation -> MountOperation
forall a. a -> Maybe a -> a
fromMaybe (ForeignPtr MountOperation -> MountOperation
MountOperation ForeignPtr MountOperation
forall a. ForeignPtr a
nullForeignPtr) Maybe MountOperation
mountOperation)
        (Cancellable -> Maybe Cancellable -> Cancellable
forall a. a -> Maybe a -> a
fromMaybe (ForeignPtr Cancellable -> Cancellable
Cancellable ForeignPtr Cancellable
forall a. ForeignPtr a
nullForeignPtr) Maybe Cancellable
cancellable)
        GAsyncReadyCallback
cCallback
        (GAsyncReadyCallback -> Ptr ()
forall a b. FunPtr a -> Ptr b
castFunPtrToPtr GAsyncReadyCallback
cCallback)

-- | Finishes mounting a volume. If any errors occurred during the operation, error will be set to contain
-- the errors and 'False' will be returned.
--
-- If the mount operation succeeded, 'volumeGetMount' on volume is guaranteed to return the mount
-- right after calling this function; there's no need to listen for the 'mount-added' signal on
-- 'VolumeMonitor'.
--
-- Throws a 'GError' if an error occurs.
volumeMountFinish :: VolumeClass volume => volume
                  -> AsyncResult -- ^ @result@ a 'AsyncResult'
                  -> IO ()
volumeMountFinish :: forall volume. VolumeClass volume => volume -> AsyncResult -> IO ()
volumeMountFinish volume
volume AsyncResult
result =
    (Ptr (Ptr ()) -> IO ()) -> IO ()
forall a. (Ptr (Ptr ()) -> IO a) -> IO a
propagateGError (\Ptr (Ptr ())
gErrorPtr -> do
                        (\(Volume ForeignPtr Volume
arg1) (AsyncResult ForeignPtr AsyncResult
arg2) Ptr (Ptr ())
arg3 -> ForeignPtr Volume -> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO CInt) -> IO CInt)
-> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->ForeignPtr AsyncResult -> (Ptr AsyncResult -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr AsyncResult
arg2 ((Ptr AsyncResult -> IO CInt) -> IO CInt)
-> (Ptr AsyncResult -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr AsyncResult
argPtr2 ->Ptr Volume -> Ptr AsyncResult -> Ptr (Ptr ()) -> IO CInt
g_volume_mount_finish Ptr Volume
argPtr1 Ptr AsyncResult
argPtr2 Ptr (Ptr ())
arg3)
{-# LINE 206 "./System/GIO/Volumes/Volume.chs" #-}
                           (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)
                           AsyncResult
result
                           Ptr (Ptr ())
gErrorPtr
                        () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ())

-- | Checks if a volume can be ejected.
volumeCanEject :: VolumeClass volume => volume
               -> IO Bool -- ^ returns 'True' if the volume can be ejected. 'False' otherwise.
volumeCanEject :: forall volume. VolumeClass volume => volume -> IO Bool
volumeCanEject volume
volume =
  (CInt -> Bool) -> IO CInt -> IO Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM CInt -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (IO CInt -> IO Bool) -> IO CInt -> IO Bool
forall a b. (a -> b) -> a -> b
$
  (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume -> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO CInt) -> IO CInt)
-> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO CInt
g_volume_can_eject Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)


-- | Ejects a volume. This is an asynchronous operation, and is finished by calling
-- 'volumeEjectWithOperationFinish' with the volume and 'AsyncResult' data returned in the
-- callback.
volumeEjectWithOperation :: VolumeClass volume => volume
 -> [MountUnmountFlags] -- ^ @flags@ flags affecting the unmount if required for eject
 -> Maybe MountOperation -- ^ @mountOperation@ a 'MountOperation' or 'Nothing' to avoid user interaction.
 -> Maybe Cancellable -- ^ @cancellable@ optional 'Cancellable' object, 'Nothing' to ignore.
 -> AsyncReadyCallback -- ^ @callback@ a 'AsyncReadyCallback'
 -> IO ()
volumeEjectWithOperation :: forall volume.
VolumeClass volume =>
volume
-> [MountUnmountFlags]
-> Maybe MountOperation
-> Maybe Cancellable
-> AsyncReadyCallback
-> IO ()
volumeEjectWithOperation volume
volume [MountUnmountFlags]
flags Maybe MountOperation
mountOperation Maybe Cancellable
cancellable AsyncReadyCallback
callback = do
      GAsyncReadyCallback
cCallback <- AsyncReadyCallback -> IO GAsyncReadyCallback
marshalAsyncReadyCallback AsyncReadyCallback
callback
      (\(Volume ForeignPtr Volume
arg1) CInt
arg2 (MountOperation ForeignPtr MountOperation
arg3) (Cancellable ForeignPtr Cancellable
arg4) GAsyncReadyCallback
arg5 Ptr ()
arg6 -> ForeignPtr Volume -> (Ptr Volume -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO ()) -> IO ()) -> (Ptr Volume -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->ForeignPtr MountOperation -> (Ptr MountOperation -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr MountOperation
arg3 ((Ptr MountOperation -> IO ()) -> IO ())
-> (Ptr MountOperation -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr MountOperation
argPtr3 ->ForeignPtr Cancellable -> (Ptr Cancellable -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Cancellable
arg4 ((Ptr Cancellable -> IO ()) -> IO ())
-> (Ptr Cancellable -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Cancellable
argPtr4 ->Ptr Volume
-> CInt
-> Ptr MountOperation
-> Ptr Cancellable
-> GAsyncReadyCallback
-> Ptr ()
-> IO ()
g_volume_eject_with_operation Ptr Volume
argPtr1 CInt
arg2 Ptr MountOperation
argPtr3 Ptr Cancellable
argPtr4 GAsyncReadyCallback
arg5 Ptr ()
arg6)
{-# LINE 231 "./System/GIO/Volumes/Volume.chs" #-}
        (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)
        ((Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt)
-> ([MountUnmountFlags] -> Int) -> [MountUnmountFlags] -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [MountUnmountFlags] -> Int
forall a. Flags a => [a] -> Int
fromFlags) [MountUnmountFlags]
flags)
        (MountOperation -> Maybe MountOperation -> MountOperation
forall a. a -> Maybe a -> a
fromMaybe (ForeignPtr MountOperation -> MountOperation
MountOperation ForeignPtr MountOperation
forall a. ForeignPtr a
nullForeignPtr) Maybe MountOperation
mountOperation)
        (Cancellable -> Maybe Cancellable -> Cancellable
forall a. a -> Maybe a -> a
fromMaybe (ForeignPtr Cancellable -> Cancellable
Cancellable ForeignPtr Cancellable
forall a. ForeignPtr a
nullForeignPtr) Maybe Cancellable
cancellable)
        GAsyncReadyCallback
cCallback
        (GAsyncReadyCallback -> Ptr ()
forall a b. FunPtr a -> Ptr b
castFunPtrToPtr GAsyncReadyCallback
cCallback)

-- | Finishes ejecting a volume. If any errors occurred during the operation, error will be set to
-- contain the errors and 'False' will be returned.
--
-- Throws a 'GError' if an error occurs.
volumeEjectWithOperationFinish :: VolumeClass volume => volume
                               -> AsyncResult -- ^ @result@ a 'AsyncResult'.
                               -> IO ()
volumeEjectWithOperationFinish :: forall volume. VolumeClass volume => volume -> AsyncResult -> IO ()
volumeEjectWithOperationFinish volume
volume AsyncResult
result =
    (Ptr (Ptr ()) -> IO ()) -> IO ()
forall a. (Ptr (Ptr ()) -> IO a) -> IO a
propagateGError (\Ptr (Ptr ())
gErrorPtr -> do
                       (\(Volume ForeignPtr Volume
arg1) (AsyncResult ForeignPtr AsyncResult
arg2) Ptr (Ptr ())
arg3 -> ForeignPtr Volume -> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO CInt) -> IO CInt)
-> (Ptr Volume -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->ForeignPtr AsyncResult -> (Ptr AsyncResult -> IO CInt) -> IO CInt
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr AsyncResult
arg2 ((Ptr AsyncResult -> IO CInt) -> IO CInt)
-> (Ptr AsyncResult -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \Ptr AsyncResult
argPtr2 ->Ptr Volume -> Ptr AsyncResult -> Ptr (Ptr ()) -> IO CInt
g_volume_eject_with_operation_finish Ptr Volume
argPtr1 Ptr AsyncResult
argPtr2 Ptr (Ptr ())
arg3)
{-# LINE 248 "./System/GIO/Volumes/Volume.chs" #-}
                          (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)
                          AsyncResult
result
                          Ptr (Ptr ())
gErrorPtr
                       () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ())


-- | Gets the kinds of identifiers that volume has. Use 'volumeGetIdentifier' to obtain the
-- identifiers themselves.
volumeEnumerateIdentifiers :: (VolumeClass volume, GlibString string) => volume
                           -> IO [string]
volumeEnumerateIdentifiers :: forall volume string.
(VolumeClass volume, GlibString string) =>
volume -> IO [string]
volumeEnumerateIdentifiers volume
volume =
  (\(Volume ForeignPtr Volume
arg1) -> ForeignPtr Volume
-> (Ptr Volume -> IO (Ptr (Ptr CChar))) -> IO (Ptr (Ptr CChar))
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO (Ptr (Ptr CChar))) -> IO (Ptr (Ptr CChar)))
-> (Ptr Volume -> IO (Ptr (Ptr CChar))) -> IO (Ptr (Ptr CChar))
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> IO (Ptr (Ptr CChar))
g_volume_enumerate_identifiers Ptr Volume
argPtr1) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume)
  IO (Ptr (Ptr CChar))
-> (Ptr (Ptr CChar) -> IO [string]) -> IO [string]
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr (Ptr CChar) -> IO [string]
forall s. GlibString s => Ptr (Ptr CChar) -> IO [s]
readUTFStringArray0

-- | Gets the identifier of the given kind for volume. See the introduction for more information about
-- volume identifiers.
volumeGetIdentifier :: (VolumeClass volume, GlibString string) => volume
                    -> string -- ^ @kind@ the kind of identifier to return
                    -> IO string
volumeGetIdentifier :: forall volume string.
(VolumeClass volume, GlibString string) =>
volume -> string -> IO string
volumeGetIdentifier volume
volume string
kind =
  string -> (Ptr CChar -> IO string) -> IO string
forall a. string -> (Ptr CChar -> IO a) -> IO a
forall s a. GlibString s => s -> (Ptr CChar -> IO a) -> IO a
withUTFString string
kind ((Ptr CChar -> IO string) -> IO string)
-> (Ptr CChar -> IO string) -> IO string
forall a b. (a -> b) -> a -> b
$ \ Ptr CChar
kindPtr ->
  (\(Volume ForeignPtr Volume
arg1) Ptr CChar
arg2 -> ForeignPtr Volume
-> (Ptr Volume -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Volume
arg1 ((Ptr Volume -> IO (Ptr CChar)) -> IO (Ptr CChar))
-> (Ptr Volume -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ \Ptr Volume
argPtr1 ->Ptr Volume -> Ptr CChar -> IO (Ptr CChar)
g_volume_get_identifier Ptr Volume
argPtr1 Ptr CChar
arg2) (volume -> Volume
forall o. VolumeClass o => o -> Volume
toVolume volume
volume) Ptr CChar
kindPtr
  IO (Ptr CChar) -> (Ptr CChar -> IO string) -> IO string
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr CChar -> IO string
forall s. GlibString s => Ptr CChar -> IO s
readUTFString

--------------------
-- Signals
-- | Emitted when the volume has been changed.
volumeChanged :: VolumeClass volume => Signal volume (IO ())
volumeChanged :: forall volume. VolumeClass volume => Signal volume (IO ())
volumeChanged = (Bool -> volume -> IO () -> IO (ConnectId volume))
-> Signal volume (IO ())
forall object handler.
(Bool -> object -> handler -> IO (ConnectId object))
-> Signal object handler
Signal (SignalName -> Bool -> volume -> IO () -> IO (ConnectId volume)
forall obj.
GObjectClass obj =>
SignalName -> Bool -> obj -> IO () -> IO (ConnectId obj)
connect_NONE__NONE SignalName
"changed")

-- | This signal is emitted when the 'Volume' have been removed. If the recipient is holding references to
-- the object they should release them so the object can be finalized.
volumeRemoved :: VolumeClass volume => Signal volume (IO ())
volumeRemoved :: forall volume. VolumeClass volume => Signal volume (IO ())
volumeRemoved = (Bool -> volume -> IO () -> IO (ConnectId volume))
-> Signal volume (IO ())
forall object handler.
(Bool -> object -> handler -> IO (ConnectId object))
-> Signal object handler
Signal (SignalName -> Bool -> volume -> IO () -> IO (ConnectId volume)
forall obj.
GObjectClass obj =>
SignalName -> Bool -> obj -> IO () -> IO (ConnectId obj)
connect_NONE__NONE SignalName
"removed")

foreign import ccall safe "g_volume_get_name"
  g_volume_get_name :: ((Ptr Volume) -> (IO (Ptr CChar)))

foreign import ccall safe "g_volume_get_uuid"
  g_volume_get_uuid :: ((Ptr Volume) -> (IO (Ptr CChar)))

foreign import ccall safe "g_volume_get_icon"
  g_volume_get_icon :: ((Ptr Volume) -> (IO (Ptr Icon)))

foreign import ccall safe "g_volume_get_drive"
  g_volume_get_drive :: ((Ptr Volume) -> (IO (Ptr Drive)))

foreign import ccall safe "g_volume_get_mount"
  g_volume_get_mount :: ((Ptr Volume) -> (IO (Ptr Mount)))

foreign import ccall safe "g_volume_can_mount"
  g_volume_can_mount :: ((Ptr Volume) -> (IO CInt))

foreign import ccall safe "g_volume_should_automount"
  g_volume_should_automount :: ((Ptr Volume) -> (IO CInt))

foreign import ccall safe "g_volume_get_activation_root"
  g_volume_get_activation_root :: ((Ptr Volume) -> (IO (Ptr File)))

foreign import ccall safe "g_volume_mount"
  g_volume_mount :: ((Ptr Volume) -> (CInt -> ((Ptr MountOperation) -> ((Ptr Cancellable) -> ((FunPtr ((Ptr ()) -> ((Ptr AsyncResult) -> ((Ptr ()) -> (IO ()))))) -> ((Ptr ()) -> (IO ())))))))

foreign import ccall safe "g_volume_mount_finish"
  g_volume_mount_finish :: ((Ptr Volume) -> ((Ptr AsyncResult) -> ((Ptr (Ptr ())) -> (IO CInt))))

foreign import ccall safe "g_volume_can_eject"
  g_volume_can_eject :: ((Ptr Volume) -> (IO CInt))

foreign import ccall safe "g_volume_eject_with_operation"
  g_volume_eject_with_operation :: ((Ptr Volume) -> (CInt -> ((Ptr MountOperation) -> ((Ptr Cancellable) -> ((FunPtr ((Ptr ()) -> ((Ptr AsyncResult) -> ((Ptr ()) -> (IO ()))))) -> ((Ptr ()) -> (IO ())))))))

foreign import ccall safe "g_volume_eject_with_operation_finish"
  g_volume_eject_with_operation_finish :: ((Ptr Volume) -> ((Ptr AsyncResult) -> ((Ptr (Ptr ())) -> (IO CInt))))

foreign import ccall safe "g_volume_enumerate_identifiers"
  g_volume_enumerate_identifiers :: ((Ptr Volume) -> (IO (Ptr (Ptr CChar))))

foreign import ccall safe "g_volume_get_identifier"
  g_volume_get_identifier :: ((Ptr Volume) -> ((Ptr CChar) -> (IO (Ptr CChar))))