1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.VolumeMonitor;
26 
27 private import gio.DriveIF;
28 private import gio.MountIF;
29 private import gio.VolumeIF;
30 private import gio.c.functions;
31 public  import gio.c.types;
32 private import glib.ConstructionException;
33 private import glib.ListG;
34 private import glib.Str;
35 private import gobject.ObjectG;
36 private import gobject.Signals;
37 public  import gtkc.giotypes;
38 private import std.algorithm;
39 
40 
41 /**
42  * #GVolumeMonitor is for listing the user interesting devices and volumes
43  * on the computer. In other words, what a file selector or file manager
44  * would show in a sidebar.
45  * 
46  * #GVolumeMonitor is not
47  * [thread-default-context aware][g-main-context-push-thread-default],
48  * and so should not be used other than from the main thread, with no
49  * thread-default-context active.
50  * 
51  * In order to receive updates about volumes and mounts monitored through GVFS,
52  * a main loop must be running.
53  */
54 public class VolumeMonitor : ObjectG
55 {
56 	/** the main Gtk struct */
57 	protected GVolumeMonitor* gVolumeMonitor;
58 
59 	/** Get the main Gtk struct */
60 	public GVolumeMonitor* getVolumeMonitorStruct(bool transferOwnership = false)
61 	{
62 		if (transferOwnership)
63 			ownedRef = false;
64 		return gVolumeMonitor;
65 	}
66 
67 	/** the main Gtk struct as a void* */
68 	protected override void* getStruct()
69 	{
70 		return cast(void*)gVolumeMonitor;
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GVolumeMonitor* gVolumeMonitor, bool ownedRef = false)
77 	{
78 		this.gVolumeMonitor = gVolumeMonitor;
79 		super(cast(GObject*)gVolumeMonitor, ownedRef);
80 	}
81 
82 	/**
83 	 * Gets the volume monitor used by gio.
84 	 *
85 	 * Return: a reference to the #GVolumeMonitor used by gio. Call
86 	 *     g_object_unref() when done with it.
87 	 */
88 	public this()
89 	{
90 		auto p = g_volume_monitor_get();
91 
92 		if(p is null)
93 		{
94 			throw new ConstructionException("g_volume_monitor_get()");
95 		}
96 
97 		this(cast(GVolumeMonitor*) p, true);
98 	}
99 
100 	/**
101 	 */
102 
103 	/** */
104 	public static GType getType()
105 	{
106 		return g_volume_monitor_get_type();
107 	}
108 
109 	/**
110 	 * This function should be called by any #GVolumeMonitor
111 	 * implementation when a new #GMount object is created that is not
112 	 * associated with a #GVolume object. It must be called just before
113 	 * emitting the @mount_added signal.
114 	 *
115 	 * If the return value is not %NULL, the caller must associate the
116 	 * returned #GVolume object with the #GMount. This involves returning
117 	 * it in its g_mount_get_volume() implementation. The caller must
118 	 * also listen for the "removed" signal on the returned object
119 	 * and give up its reference when handling that signal
120 	 *
121 	 * Similarly, if implementing g_volume_monitor_adopt_orphan_mount(),
122 	 * the implementor must take a reference to @mount and return it in
123 	 * its g_volume_get_mount() implemented. Also, the implementor must
124 	 * listen for the "unmounted" signal on @mount and give up its
125 	 * reference upon handling that signal.
126 	 *
127 	 * There are two main use cases for this function.
128 	 *
129 	 * One is when implementing a user space file system driver that reads
130 	 * blocks of a block device that is already represented by the native
131 	 * volume monitor (for example a CD Audio file system driver). Such
132 	 * a driver will generate its own #GMount object that needs to be
133 	 * associated with the #GVolume object that represents the volume.
134 	 *
135 	 * The other is for implementing a #GVolumeMonitor whose sole purpose
136 	 * is to return #GVolume objects representing entries in the users
137 	 * "favorite servers" list or similar.
138 	 *
139 	 * Deprecated: Instead of using this function, #GVolumeMonitor
140 	 * implementations should instead create shadow mounts with the URI of
141 	 * the mount they intend to adopt. See the proxy volume monitor in
142 	 * gvfs for an example of this. Also see g_mount_is_shadowed(),
143 	 * g_mount_shadow() and g_mount_unshadow() functions.
144 	 *
145 	 * Params:
146 	 *     mount = a #GMount object to find a parent for
147 	 *
148 	 * Returns: the #GVolume object that is the parent for @mount or %NULL
149 	 *     if no wants to adopt the #GMount.
150 	 */
151 	public static VolumeIF adoptOrphanMount(MountIF mount)
152 	{
153 		auto __p = g_volume_monitor_adopt_orphan_mount((mount is null) ? null : mount.getMountStruct());
154 
155 		if(__p is null)
156 		{
157 			return null;
158 		}
159 
160 		return ObjectG.getDObject!(VolumeIF)(cast(GVolume*) __p, true);
161 	}
162 
163 	/**
164 	 * Gets a list of drives connected to the system.
165 	 *
166 	 * The returned list should be freed with g_list_free(), after
167 	 * its elements have been unreffed with g_object_unref().
168 	 *
169 	 * Returns: a #GList of connected #GDrive objects.
170 	 */
171 	public ListG getConnectedDrives()
172 	{
173 		auto __p = g_volume_monitor_get_connected_drives(gVolumeMonitor);
174 
175 		if(__p is null)
176 		{
177 			return null;
178 		}
179 
180 		return new ListG(cast(GList*) __p, true);
181 	}
182 
183 	/**
184 	 * Finds a #GMount object by its UUID (see g_mount_get_uuid())
185 	 *
186 	 * Params:
187 	 *     uuid = the UUID to look for
188 	 *
189 	 * Returns: a #GMount or %NULL if no such mount is available.
190 	 *     Free the returned object with g_object_unref().
191 	 */
192 	public MountIF getMountForUuid(string uuid)
193 	{
194 		auto __p = g_volume_monitor_get_mount_for_uuid(gVolumeMonitor, Str.toStringz(uuid));
195 
196 		if(__p is null)
197 		{
198 			return null;
199 		}
200 
201 		return ObjectG.getDObject!(MountIF)(cast(GMount*) __p, true);
202 	}
203 
204 	/**
205 	 * Gets a list of the mounts on the system.
206 	 *
207 	 * The returned list should be freed with g_list_free(), after
208 	 * its elements have been unreffed with g_object_unref().
209 	 *
210 	 * Returns: a #GList of #GMount objects.
211 	 */
212 	public ListG getMounts()
213 	{
214 		auto __p = g_volume_monitor_get_mounts(gVolumeMonitor);
215 
216 		if(__p is null)
217 		{
218 			return null;
219 		}
220 
221 		return new ListG(cast(GList*) __p, true);
222 	}
223 
224 	/**
225 	 * Finds a #GVolume object by its UUID (see g_volume_get_uuid())
226 	 *
227 	 * Params:
228 	 *     uuid = the UUID to look for
229 	 *
230 	 * Returns: a #GVolume or %NULL if no such volume is available.
231 	 *     Free the returned object with g_object_unref().
232 	 */
233 	public VolumeIF getVolumeForUuid(string uuid)
234 	{
235 		auto __p = g_volume_monitor_get_volume_for_uuid(gVolumeMonitor, Str.toStringz(uuid));
236 
237 		if(__p is null)
238 		{
239 			return null;
240 		}
241 
242 		return ObjectG.getDObject!(VolumeIF)(cast(GVolume*) __p, true);
243 	}
244 
245 	/**
246 	 * Gets a list of the volumes on the system.
247 	 *
248 	 * The returned list should be freed with g_list_free(), after
249 	 * its elements have been unreffed with g_object_unref().
250 	 *
251 	 * Returns: a #GList of #GVolume objects.
252 	 */
253 	public ListG getVolumes()
254 	{
255 		auto __p = g_volume_monitor_get_volumes(gVolumeMonitor);
256 
257 		if(__p is null)
258 		{
259 			return null;
260 		}
261 
262 		return new ListG(cast(GList*) __p, true);
263 	}
264 
265 	/**
266 	 * Emitted when a drive changes.
267 	 *
268 	 * Params:
269 	 *     drive = the drive that changed
270 	 */
271 	gulong addOnDriveChanged(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
272 	{
273 		return Signals.connect(this, "drive-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
274 	}
275 
276 	/**
277 	 * Emitted when a drive is connected to the system.
278 	 *
279 	 * Params:
280 	 *     drive = a #GDrive that was connected.
281 	 */
282 	gulong addOnDriveConnected(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
283 	{
284 		return Signals.connect(this, "drive-connected", dlg, connectFlags ^ ConnectFlags.SWAPPED);
285 	}
286 
287 	/**
288 	 * Emitted when a drive is disconnected from the system.
289 	 *
290 	 * Params:
291 	 *     drive = a #GDrive that was disconnected.
292 	 */
293 	gulong addOnDriveDisconnected(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
294 	{
295 		return Signals.connect(this, "drive-disconnected", dlg, connectFlags ^ ConnectFlags.SWAPPED);
296 	}
297 
298 	/**
299 	 * Emitted when the eject button is pressed on @drive.
300 	 *
301 	 * Params:
302 	 *     drive = the drive where the eject button was pressed
303 	 *
304 	 * Since: 2.18
305 	 */
306 	gulong addOnDriveEjectButton(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
307 	{
308 		return Signals.connect(this, "drive-eject-button", dlg, connectFlags ^ ConnectFlags.SWAPPED);
309 	}
310 
311 	/**
312 	 * Emitted when the stop button is pressed on @drive.
313 	 *
314 	 * Params:
315 	 *     drive = the drive where the stop button was pressed
316 	 *
317 	 * Since: 2.22
318 	 */
319 	gulong addOnDriveStopButton(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
320 	{
321 		return Signals.connect(this, "drive-stop-button", dlg, connectFlags ^ ConnectFlags.SWAPPED);
322 	}
323 
324 	/**
325 	 * Emitted when a mount is added.
326 	 *
327 	 * Params:
328 	 *     mount = a #GMount that was added.
329 	 */
330 	gulong addOnMountAdded(void delegate(MountIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
331 	{
332 		return Signals.connect(this, "mount-added", dlg, connectFlags ^ ConnectFlags.SWAPPED);
333 	}
334 
335 	/**
336 	 * Emitted when a mount changes.
337 	 *
338 	 * Params:
339 	 *     mount = a #GMount that changed.
340 	 */
341 	gulong addOnMountChanged(void delegate(MountIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
342 	{
343 		return Signals.connect(this, "mount-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
344 	}
345 
346 	/**
347 	 * May be emitted when a mount is about to be removed.
348 	 *
349 	 * This signal depends on the backend and is only emitted if
350 	 * GIO was used to unmount.
351 	 *
352 	 * Params:
353 	 *     mount = a #GMount that is being unmounted.
354 	 */
355 	gulong addOnMountPreUnmount(void delegate(MountIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
356 	{
357 		return Signals.connect(this, "mount-pre-unmount", dlg, connectFlags ^ ConnectFlags.SWAPPED);
358 	}
359 
360 	/**
361 	 * Emitted when a mount is removed.
362 	 *
363 	 * Params:
364 	 *     mount = a #GMount that was removed.
365 	 */
366 	gulong addOnMountRemoved(void delegate(MountIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
367 	{
368 		return Signals.connect(this, "mount-removed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
369 	}
370 
371 	/**
372 	 * Emitted when a mountable volume is added to the system.
373 	 *
374 	 * Params:
375 	 *     volume = a #GVolume that was added.
376 	 */
377 	gulong addOnVolumeAdded(void delegate(VolumeIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
378 	{
379 		return Signals.connect(this, "volume-added", dlg, connectFlags ^ ConnectFlags.SWAPPED);
380 	}
381 
382 	/**
383 	 * Emitted when mountable volume is changed.
384 	 *
385 	 * Params:
386 	 *     volume = a #GVolume that changed.
387 	 */
388 	gulong addOnVolumeChanged(void delegate(VolumeIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
389 	{
390 		return Signals.connect(this, "volume-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
391 	}
392 
393 	/**
394 	 * Emitted when a mountable volume is removed from the system.
395 	 *
396 	 * Params:
397 	 *     volume = a #GVolume that was removed.
398 	 */
399 	gulong addOnVolumeRemoved(void delegate(VolumeIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
400 	{
401 		return Signals.connect(this, "volume-removed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
402 	}
403 }