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