Debian Codegraph @

System/GIO/Volumes/VolumeMonitor.chs

raw
1 {-# LANGUAGE CPP #-}
2 -- GIMP Toolkit (GTK) Binding for Haskell: binding to gio -*-haskell-*-
3 --
4 -- Author : Andy Stewart
5 -- Created: 30-Apirl-2010
6 --
7 -- Copyright (c) 2010 Andy Stewart
8 --
9 -- This library is free software: you can redistribute it and/or
10 -- modify it under the terms of the GNU Lesser General Public License
11 -- as published by the Free Software Foundation, either version 3 of
12 -- the License, or (at your option) any later version.
13 --
14 -- This library is distributed in the hope that it will be useful,
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 -- Lesser General Public License for more details.
18 --
19 -- You should have received a copy of the GNU Lesser General Public
20 -- License along with this program. If not, see
21 -- <http://www.gnu.org/licenses/>.
22 --
23 -- GIO, the C library which this Haskell library depends on, is
24 -- available under LGPL Version 2. The documentation included with
25 -- this library is based on the original GIO documentation.
26 --
27 -- | Maintainer : [email protected]
28 -- Stability : alpha
29 -- Portability : portable (depends on GHC)
30 module System.GIO.Volumes.VolumeMonitor (
31 -- * Details
32 --
33 -- | 'VolumeMonitor' is for listing the user interesting devices and volumes on the computer. In other
34 -- words, what a file selector or file manager would show in a sidebar.
35 --
36 -- 'VolumeMonitor' is not thread-default-context aware, and so should not be used other than from the
37 -- main thread, with no thread-default-context active.
38
39 -- * Types
40 VolumeMonitor(..),
41 VolumeMonitorClass,
42
43 -- * Methods
44 volumeMonitorGet,
45 volumeMonitorGetConnectedDrives,
46 volumeMonitorGetVolumes,
47 volumeMonitorGetMounts,
48 volumeMonitorGetMountForUUID,
49 volumeMonitorGetVolumeForUUID,
50
51 -- * Signals
52 vmDriveChanged,
53 vmDriveConnected,
54 vmDriveDisconnected,
55 #if GLIB_CHECK_VERSION(2,18,0)
56 vmDriveEjectButton,
57 #endif
58 #if GLIB_CHECK_VERSION(2,22,0)
59 vmDriveStopButton,
60 #endif
61 vmMountAdded,
62 vmMountChanged,
63 vmMountPreUnmount,
64 vmMountRemoved,
65 vmVolumeAdded,
66 vmVolumeChanged,
67 vmVolumeRemoved,
68 ) where
69
70 import Control.Monad
71 import System.GIO.Enums
72 import System.Glib.Attributes
73 import System.Glib.FFI
74 import System.Glib.Flags
75 import System.Glib.GError
76 import System.Glib.GList
77 import System.Glib.GObject
78 import System.Glib.Properties
79 import System.Glib.Signals
80 import System.Glib.UTFString
81 {#import System.GIO.Signals#}
82 {#import System.GIO.Types#}
83
84 {# context lib = "gio" prefix = "g" #}
85
86 --------------------
87 -- Methods
88 -- | Gets the volume monitor used by gio.
89 volumeMonitorGet :: IO VolumeMonitor
90 volumeMonitorGet =
91 wrapNewGObject mkVolumeMonitor $
92 {#call g_volume_monitor_get #}
93
94 -- | Gets a list of drives connected to the system.
95 volumeMonitorGetConnectedDrives :: VolumeMonitorClass monitor => monitor
96 -> IO [Drive]
97 volumeMonitorGetConnectedDrives monitor = do
98 glistPtr <- {#call g_volume_monitor_get_connected_drives #} (toVolumeMonitor monitor)
99 drivePtrs <- fromGList glistPtr
100 mapM (wrapNewGObject mkDrive . return) drivePtrs
101
102 -- | Gets a list of the volumes on the system.
103 volumeMonitorGetVolumes :: VolumeMonitorClass monitor => monitor
104 -> IO [Drive]
105 volumeMonitorGetVolumes monitor = do
106 glistPtr <- {#call g_volume_monitor_get_volumes #} (toVolumeMonitor monitor)
107 volumePtrs <- fromGList glistPtr
108 mapM (wrapNewGObject mkDrive . return) volumePtrs
109
110 -- | Gets a list of the mounts on the system.
111 volumeMonitorGetMounts :: VolumeMonitorClass monitor => monitor
112 -> IO [Drive]
113 volumeMonitorGetMounts monitor = do
114 glistPtr <- {#call g_volume_monitor_get_mounts #} (toVolumeMonitor monitor)
115 mountPtrs <- fromGList glistPtr
116 mapM (wrapNewGObject mkDrive . return) mountPtrs
117
118 -- | Finds a 'Mount' object by its UUID (see 'mountGetUuid'
119 volumeMonitorGetMountForUUID :: (VolumeMonitorClass monitor, GlibString string) => monitor
120 -> string -- ^ @uuid@ the UUID to look for
121 -> IO (Maybe Mount) -- ^ returns a 'Mount' or 'Nothing' if no such mount is available.
122 volumeMonitorGetMountForUUID monitor uuid =
123 maybeNull (wrapNewGObject mkMount) $
124 withUTFString uuid $ \ uuidPtr ->
125 {#call g_volume_monitor_get_mount_for_uuid#} (toVolumeMonitor monitor) uuidPtr
126
127 -- | Finds a 'Volume' object by its UUID (see 'volumeGetUuid')
128 volumeMonitorGetVolumeForUUID :: (VolumeMonitorClass monitor, GlibString string) => monitor
129 -> string -- ^ @uuid@ the UUID to look for
130 -> IO (Maybe Volume) -- ^ returns a 'Volume' or 'Nothing' if no such volume is available.
131 volumeMonitorGetVolumeForUUID monitor uuid =
132 maybeNull (wrapNewGObject mkVolume) $
133 withUTFString uuid $ \ uuidPtr ->
134 {#call g_volume_monitor_get_volume_for_uuid#} (toVolumeMonitor monitor) uuidPtr
135
136 --------------------
137 -- Signals
138 -- | Emitted when a drive changes.
139 vmDriveChanged :: VolumeMonitorClass monitor => Signal monitor (Drive -> IO ())
140 vmDriveChanged = Signal (connect_OBJECT__NONE "drive-changed")
141
142 -- | Emitted when a drive changes.
143 vmDriveConnected :: VolumeMonitorClass monitor => Signal monitor (Drive -> IO ())
144 vmDriveConnected = Signal (connect_OBJECT__NONE "drive-connected")
145
146 -- | Emitted when a drive changes.
147 vmDriveDisconnected :: VolumeMonitorClass monitor => Signal monitor (Drive -> IO ())
148 vmDriveDisconnected = Signal (connect_OBJECT__NONE "drive-disconnected")
149
150 #if GLIB_CHECK_VERSION(2,18,0)
151 -- | Emitted when the eject button is pressed on drive.
152 vmDriveEjectButton :: VolumeMonitorClass monitor => Signal monitor (Drive -> IO ())
153 vmDriveEjectButton = Signal (connect_OBJECT__NONE "drive-eject-button")
154 #endif
155
156 #if GLIB_CHECK_VERSION(2,22,0)
157 -- | Emitted when the stop button is pressed on drive.
158 vmDriveStopButton :: VolumeMonitorClass monitor => Signal monitor (Drive -> IO ())
159 vmDriveStopButton = Signal (connect_OBJECT__NONE "drive-stop-button")
160 #endif
161
162 -- | Emitted when a mount is added.
163 vmMountAdded :: VolumeMonitorClass monitor => Signal monitor (Mount -> IO ())
164 vmMountAdded = Signal (connect_OBJECT__NONE "mount-added")
165
166 -- | Emitted when a mount is changed.
167 vmMountChanged :: VolumeMonitorClass monitor => Signal monitor (Mount -> IO ())
168 vmMountChanged = Signal (connect_OBJECT__NONE "mount-changed")
169
170 -- | Emitted when a mount is about to be removed.
171 vmMountPreUnmount :: VolumeMonitorClass monitor => Signal monitor (Mount -> IO ())
172 vmMountPreUnmount = Signal (connect_OBJECT__NONE "mount-pre-unmount")
173
174 -- | Emitted when a mount is removed.
175 vmMountRemoved :: VolumeMonitorClass monitor => Signal monitor (Mount -> IO ())
176 vmMountRemoved = Signal (connect_OBJECT__NONE "mount-removed")
177
178 -- | Emitted when a volume is added.
179 vmVolumeAdded :: VolumeMonitorClass monitor => Signal monitor (Volume -> IO ())
180 vmVolumeAdded = Signal (connect_OBJECT__NONE "volume-added")
181
182 -- | Emitted when a volume is changed.
183 vmVolumeChanged :: VolumeMonitorClass monitor => Signal monitor (Volume -> IO ())
184 vmVolumeChanged = Signal (connect_OBJECT__NONE "volume-changed")
185
186 -- | Emitted when a volume is removed.
187 vmVolumeRemoved :: VolumeMonitorClass monitor => Signal monitor (Volume -> IO ())
188 vmVolumeRemoved = Signal (connect_OBJECT__NONE "volume-removed")
189