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.Drive;
28 private import gio.DriveIF;
29 private import gio.Mount;
30 private import gio.MountIF;
31 private import gio.Volume;
32 private import gio.VolumeIF;
33 private import glib.ConstructionException;
34 private import glib.ListG;
35 private import glib.Str;
36 private import gobject.ObjectG;
37 private import gobject.Signals;
38 public  import gtkc.gdktypes;
39 private import gtkc.gio;
40 public  import gtkc.giotypes;
41 
42 
43 /**
44  * #GVolumeMonitor is for listing the user interesting devices and volumes
45  * on the computer. In other words, what a file selector or file manager
46  * would show in a sidebar.
47  * 
48  * #GVolumeMonitor is not
49  * [thread-default-context aware][g-main-context-push-thread-default],
50  * and so should not be used other than from the main thread, with no
51  * thread-default-context active.
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()
60 	{
61 		return gVolumeMonitor;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gVolumeMonitor;
68 	}
69 
70 	protected override void setStruct(GObject* obj)
71 	{
72 		gVolumeMonitor = cast(GVolumeMonitor*)obj;
73 		super.setStruct(obj);
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GVolumeMonitor* gVolumeMonitor, bool ownedRef = false)
80 	{
81 		this.gVolumeMonitor = gVolumeMonitor;
82 		super(cast(GObject*)gVolumeMonitor, ownedRef);
83 	}
84 
85 	/**
86 	 * Gets the volume monitor used by gio.
87 	 *
88 	 * Return: a reference to the #GVolumeMonitor used by gio. Call
89 	 *     g_object_unref() when done with it.
90 	 */
91 	public this()
92 	{
93 		auto p = g_volume_monitor_get();
94 		
95 		if(p is null)
96 		{
97 			throw new ConstructionException("g_volume_monitor_get()");
98 		}
99 		
100 		this(cast(GVolumeMonitor*) p, true);
101 	}
102 
103 	/**
104 	 */
105 
106 	public static GType getType()
107 	{
108 		return g_volume_monitor_get_type();
109 	}
110 
111 	/**
112 	 * This function should be called by any #GVolumeMonitor
113 	 * implementation when a new #GMount object is created that is not
114 	 * associated with a #GVolume object. It must be called just before
115 	 * emitting the @mount_added signal.
116 	 *
117 	 * If the return value is not %NULL, the caller must associate the
118 	 * returned #GVolume object with the #GMount. This involves returning
119 	 * it in its g_mount_get_volume() implementation. The caller must
120 	 * also listen for the "removed" signal on the returned object
121 	 * and give up its reference when handling that signal
122 	 *
123 	 * Similary, if implementing g_volume_monitor_adopt_orphan_mount(),
124 	 * the implementor must take a reference to @mount and return it in
125 	 * its g_volume_get_mount() implemented. Also, the implementor must
126 	 * listen for the "unmounted" signal on @mount and give up its
127 	 * reference upon handling that signal.
128 	 *
129 	 * There are two main use cases for this function.
130 	 *
131 	 * One is when implementing a user space file system driver that reads
132 	 * blocks of a block device that is already represented by the native
133 	 * volume monitor (for example a CD Audio file system driver). Such
134 	 * a driver will generate its own #GMount object that needs to be
135 	 * associated with the #GVolume object that represents the volume.
136 	 *
137 	 * The other is for implementing a #GVolumeMonitor whose sole purpose
138 	 * is to return #GVolume objects representing entries in the users
139 	 * "favorite servers" list or similar.
140 	 *
141 	 * Deprecated: Instead of using this function, #GVolumeMonitor
142 	 * implementations should instead create shadow mounts with the URI of
143 	 * the mount they intend to adopt. See the proxy volume monitor in
144 	 * gvfs for an example of this. Also see g_mount_is_shadowed(),
145 	 * g_mount_shadow() and g_mount_unshadow() functions.
146 	 *
147 	 * Params:
148 	 *     mount = a #GMount object to find a parent for
149 	 *
150 	 * Return: the #GVolume object that is the parent for @mount or %NULL
151 	 *     if no wants to adopt the #GMount.
152 	 */
153 	public static VolumeIF adoptOrphanMount(MountIF mount)
154 	{
155 		auto p = g_volume_monitor_adopt_orphan_mount((mount is null) ? null : mount.getMountStruct());
156 		
157 		if(p is null)
158 		{
159 			return null;
160 		}
161 		
162 		return ObjectG.getDObject!(Volume, VolumeIF)(cast(GVolume*) p);
163 	}
164 
165 	/**
166 	 * Gets a list of drives connected to the system.
167 	 *
168 	 * The returned list should be freed with g_list_free(), after
169 	 * its elements have been unreffed with g_object_unref().
170 	 *
171 	 * Return: a #GList of connected #GDrive objects.
172 	 */
173 	public ListG getConnectedDrives()
174 	{
175 		auto p = g_volume_monitor_get_connected_drives(gVolumeMonitor);
176 		
177 		if(p is null)
178 		{
179 			return null;
180 		}
181 		
182 		return new ListG(cast(GList*) p);
183 	}
184 
185 	/**
186 	 * Finds a #GMount object by its UUID (see g_mount_get_uuid())
187 	 *
188 	 * Params:
189 	 *     uuid = the UUID to look for
190 	 *
191 	 * Return: a #GMount or %NULL if no such mount is available.
192 	 *     Free the returned object with g_object_unref().
193 	 */
194 	public MountIF getMountForUuid(string uuid)
195 	{
196 		auto p = g_volume_monitor_get_mount_for_uuid(gVolumeMonitor, Str.toStringz(uuid));
197 		
198 		if(p is null)
199 		{
200 			return null;
201 		}
202 		
203 		return ObjectG.getDObject!(Mount, MountIF)(cast(GMount*) p);
204 	}
205 
206 	/**
207 	 * Gets a list of the mounts on the system.
208 	 *
209 	 * The returned list should be freed with g_list_free(), after
210 	 * its elements have been unreffed with g_object_unref().
211 	 *
212 	 * Return: a #GList of #GMount objects.
213 	 */
214 	public ListG getMounts()
215 	{
216 		auto p = g_volume_monitor_get_mounts(gVolumeMonitor);
217 		
218 		if(p is null)
219 		{
220 			return null;
221 		}
222 		
223 		return new ListG(cast(GList*) p);
224 	}
225 
226 	/**
227 	 * Finds a #GVolume object by its UUID (see g_volume_get_uuid())
228 	 *
229 	 * Params:
230 	 *     uuid = the UUID to look for
231 	 *
232 	 * Return: a #GVolume or %NULL if no such volume is available.
233 	 *     Free the returned object with g_object_unref().
234 	 */
235 	public VolumeIF getVolumeForUuid(string uuid)
236 	{
237 		auto p = g_volume_monitor_get_volume_for_uuid(gVolumeMonitor, Str.toStringz(uuid));
238 		
239 		if(p is null)
240 		{
241 			return null;
242 		}
243 		
244 		return ObjectG.getDObject!(Volume, VolumeIF)(cast(GVolume*) p);
245 	}
246 
247 	/**
248 	 * Gets a list of the volumes on the system.
249 	 *
250 	 * The returned list should be freed with g_list_free(), after
251 	 * its elements have been unreffed with g_object_unref().
252 	 *
253 	 * Return: a #GList of #GVolume objects.
254 	 */
255 	public ListG getVolumes()
256 	{
257 		auto p = g_volume_monitor_get_volumes(gVolumeMonitor);
258 		
259 		if(p is null)
260 		{
261 			return null;
262 		}
263 		
264 		return new ListG(cast(GList*) p);
265 	}
266 
267 	int[string] connectedSignals;
268 
269 	void delegate(DriveIF, VolumeMonitor)[] onDriveChangedListeners;
270 	/**
271 	 * Emitted when a drive changes.
272 	 *
273 	 * Params:
274 	 *     drive = the drive that changed
275 	 */
276 	void addOnDriveChanged(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
277 	{
278 		if ( "drive-changed" !in connectedSignals )
279 		{
280 			Signals.connectData(
281 				this,
282 				"drive-changed",
283 				cast(GCallback)&callBackDriveChanged,
284 				cast(void*)this,
285 				null,
286 				connectFlags);
287 			connectedSignals["drive-changed"] = 1;
288 		}
289 		onDriveChangedListeners ~= dlg;
290 	}
291 	extern(C) static void callBackDriveChanged(GVolumeMonitor* volumemonitorStruct, GDrive* drive, VolumeMonitor _volumemonitor)
292 	{
293 		foreach ( void delegate(DriveIF, VolumeMonitor) dlg; _volumemonitor.onDriveChangedListeners )
294 		{
295 			dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumemonitor);
296 		}
297 	}
298 
299 	void delegate(DriveIF, VolumeMonitor)[] onDriveConnectedListeners;
300 	/**
301 	 * Emitted when a drive is connected to the system.
302 	 *
303 	 * Params:
304 	 *     drive = a #GDrive that was connected.
305 	 */
306 	void addOnDriveConnected(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
307 	{
308 		if ( "drive-connected" !in connectedSignals )
309 		{
310 			Signals.connectData(
311 				this,
312 				"drive-connected",
313 				cast(GCallback)&callBackDriveConnected,
314 				cast(void*)this,
315 				null,
316 				connectFlags);
317 			connectedSignals["drive-connected"] = 1;
318 		}
319 		onDriveConnectedListeners ~= dlg;
320 	}
321 	extern(C) static void callBackDriveConnected(GVolumeMonitor* volumemonitorStruct, GDrive* drive, VolumeMonitor _volumemonitor)
322 	{
323 		foreach ( void delegate(DriveIF, VolumeMonitor) dlg; _volumemonitor.onDriveConnectedListeners )
324 		{
325 			dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumemonitor);
326 		}
327 	}
328 
329 	void delegate(DriveIF, VolumeMonitor)[] onDriveDisconnectedListeners;
330 	/**
331 	 * Emitted when a drive is disconnected from the system.
332 	 *
333 	 * Params:
334 	 *     drive = a #GDrive that was disconnected.
335 	 */
336 	void addOnDriveDisconnected(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
337 	{
338 		if ( "drive-disconnected" !in connectedSignals )
339 		{
340 			Signals.connectData(
341 				this,
342 				"drive-disconnected",
343 				cast(GCallback)&callBackDriveDisconnected,
344 				cast(void*)this,
345 				null,
346 				connectFlags);
347 			connectedSignals["drive-disconnected"] = 1;
348 		}
349 		onDriveDisconnectedListeners ~= dlg;
350 	}
351 	extern(C) static void callBackDriveDisconnected(GVolumeMonitor* volumemonitorStruct, GDrive* drive, VolumeMonitor _volumemonitor)
352 	{
353 		foreach ( void delegate(DriveIF, VolumeMonitor) dlg; _volumemonitor.onDriveDisconnectedListeners )
354 		{
355 			dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumemonitor);
356 		}
357 	}
358 
359 	void delegate(DriveIF, VolumeMonitor)[] onDriveEjectButtonListeners;
360 	/**
361 	 * Emitted when the eject button is pressed on @drive.
362 	 *
363 	 * Params:
364 	 *     drive = the drive where the eject button was pressed
365 	 *
366 	 * Since: 2.18
367 	 */
368 	void addOnDriveEjectButton(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
369 	{
370 		if ( "drive-eject-button" !in connectedSignals )
371 		{
372 			Signals.connectData(
373 				this,
374 				"drive-eject-button",
375 				cast(GCallback)&callBackDriveEjectButton,
376 				cast(void*)this,
377 				null,
378 				connectFlags);
379 			connectedSignals["drive-eject-button"] = 1;
380 		}
381 		onDriveEjectButtonListeners ~= dlg;
382 	}
383 	extern(C) static void callBackDriveEjectButton(GVolumeMonitor* volumemonitorStruct, GDrive* drive, VolumeMonitor _volumemonitor)
384 	{
385 		foreach ( void delegate(DriveIF, VolumeMonitor) dlg; _volumemonitor.onDriveEjectButtonListeners )
386 		{
387 			dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumemonitor);
388 		}
389 	}
390 
391 	void delegate(DriveIF, VolumeMonitor)[] onDriveStopButtonListeners;
392 	/**
393 	 * Emitted when the stop button is pressed on @drive.
394 	 *
395 	 * Params:
396 	 *     drive = the drive where the stop button was pressed
397 	 *
398 	 * Since: 2.22
399 	 */
400 	void addOnDriveStopButton(void delegate(DriveIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
401 	{
402 		if ( "drive-stop-button" !in connectedSignals )
403 		{
404 			Signals.connectData(
405 				this,
406 				"drive-stop-button",
407 				cast(GCallback)&callBackDriveStopButton,
408 				cast(void*)this,
409 				null,
410 				connectFlags);
411 			connectedSignals["drive-stop-button"] = 1;
412 		}
413 		onDriveStopButtonListeners ~= dlg;
414 	}
415 	extern(C) static void callBackDriveStopButton(GVolumeMonitor* volumemonitorStruct, GDrive* drive, VolumeMonitor _volumemonitor)
416 	{
417 		foreach ( void delegate(DriveIF, VolumeMonitor) dlg; _volumemonitor.onDriveStopButtonListeners )
418 		{
419 			dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumemonitor);
420 		}
421 	}
422 
423 	void delegate(MountIF, VolumeMonitor)[] onMountAddedListeners;
424 	/**
425 	 * Emitted when a mount is added.
426 	 *
427 	 * Params:
428 	 *     mount = a #GMount that was added.
429 	 */
430 	void addOnMountAdded(void delegate(MountIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
431 	{
432 		if ( "mount-added" !in connectedSignals )
433 		{
434 			Signals.connectData(
435 				this,
436 				"mount-added",
437 				cast(GCallback)&callBackMountAdded,
438 				cast(void*)this,
439 				null,
440 				connectFlags);
441 			connectedSignals["mount-added"] = 1;
442 		}
443 		onMountAddedListeners ~= dlg;
444 	}
445 	extern(C) static void callBackMountAdded(GVolumeMonitor* volumemonitorStruct, GMount* mount, VolumeMonitor _volumemonitor)
446 	{
447 		foreach ( void delegate(MountIF, VolumeMonitor) dlg; _volumemonitor.onMountAddedListeners )
448 		{
449 			dlg(ObjectG.getDObject!(Mount, MountIF)(mount), _volumemonitor);
450 		}
451 	}
452 
453 	void delegate(MountIF, VolumeMonitor)[] onMountChangedListeners;
454 	/**
455 	 * Emitted when a mount changes.
456 	 *
457 	 * Params:
458 	 *     mount = a #GMount that changed.
459 	 */
460 	void addOnMountChanged(void delegate(MountIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
461 	{
462 		if ( "mount-changed" !in connectedSignals )
463 		{
464 			Signals.connectData(
465 				this,
466 				"mount-changed",
467 				cast(GCallback)&callBackMountChanged,
468 				cast(void*)this,
469 				null,
470 				connectFlags);
471 			connectedSignals["mount-changed"] = 1;
472 		}
473 		onMountChangedListeners ~= dlg;
474 	}
475 	extern(C) static void callBackMountChanged(GVolumeMonitor* volumemonitorStruct, GMount* mount, VolumeMonitor _volumemonitor)
476 	{
477 		foreach ( void delegate(MountIF, VolumeMonitor) dlg; _volumemonitor.onMountChangedListeners )
478 		{
479 			dlg(ObjectG.getDObject!(Mount, MountIF)(mount), _volumemonitor);
480 		}
481 	}
482 
483 	void delegate(MountIF, VolumeMonitor)[] onMountPreUnmountListeners;
484 	/**
485 	 * Emitted when a mount is about to be removed.
486 	 *
487 	 * Params:
488 	 *     mount = a #GMount that is being unmounted.
489 	 */
490 	void addOnMountPreUnmount(void delegate(MountIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
491 	{
492 		if ( "mount-pre-unmount" !in connectedSignals )
493 		{
494 			Signals.connectData(
495 				this,
496 				"mount-pre-unmount",
497 				cast(GCallback)&callBackMountPreUnmount,
498 				cast(void*)this,
499 				null,
500 				connectFlags);
501 			connectedSignals["mount-pre-unmount"] = 1;
502 		}
503 		onMountPreUnmountListeners ~= dlg;
504 	}
505 	extern(C) static void callBackMountPreUnmount(GVolumeMonitor* volumemonitorStruct, GMount* mount, VolumeMonitor _volumemonitor)
506 	{
507 		foreach ( void delegate(MountIF, VolumeMonitor) dlg; _volumemonitor.onMountPreUnmountListeners )
508 		{
509 			dlg(ObjectG.getDObject!(Mount, MountIF)(mount), _volumemonitor);
510 		}
511 	}
512 
513 	void delegate(MountIF, VolumeMonitor)[] onMountRemovedListeners;
514 	/**
515 	 * Emitted when a mount is removed.
516 	 *
517 	 * Params:
518 	 *     mount = a #GMount that was removed.
519 	 */
520 	void addOnMountRemoved(void delegate(MountIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
521 	{
522 		if ( "mount-removed" !in connectedSignals )
523 		{
524 			Signals.connectData(
525 				this,
526 				"mount-removed",
527 				cast(GCallback)&callBackMountRemoved,
528 				cast(void*)this,
529 				null,
530 				connectFlags);
531 			connectedSignals["mount-removed"] = 1;
532 		}
533 		onMountRemovedListeners ~= dlg;
534 	}
535 	extern(C) static void callBackMountRemoved(GVolumeMonitor* volumemonitorStruct, GMount* mount, VolumeMonitor _volumemonitor)
536 	{
537 		foreach ( void delegate(MountIF, VolumeMonitor) dlg; _volumemonitor.onMountRemovedListeners )
538 		{
539 			dlg(ObjectG.getDObject!(Mount, MountIF)(mount), _volumemonitor);
540 		}
541 	}
542 
543 	void delegate(VolumeIF, VolumeMonitor)[] onVolumeAddedListeners;
544 	/**
545 	 * Emitted when a mountable volume is added to the system.
546 	 *
547 	 * Params:
548 	 *     volume = a #GVolume that was added.
549 	 */
550 	void addOnVolumeAdded(void delegate(VolumeIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
551 	{
552 		if ( "volume-added" !in connectedSignals )
553 		{
554 			Signals.connectData(
555 				this,
556 				"volume-added",
557 				cast(GCallback)&callBackVolumeAdded,
558 				cast(void*)this,
559 				null,
560 				connectFlags);
561 			connectedSignals["volume-added"] = 1;
562 		}
563 		onVolumeAddedListeners ~= dlg;
564 	}
565 	extern(C) static void callBackVolumeAdded(GVolumeMonitor* volumemonitorStruct, GVolume* volume, VolumeMonitor _volumemonitor)
566 	{
567 		foreach ( void delegate(VolumeIF, VolumeMonitor) dlg; _volumemonitor.onVolumeAddedListeners )
568 		{
569 			dlg(ObjectG.getDObject!(Volume, VolumeIF)(volume), _volumemonitor);
570 		}
571 	}
572 
573 	void delegate(VolumeIF, VolumeMonitor)[] onVolumeChangedListeners;
574 	/**
575 	 * Emitted when mountable volume is changed.
576 	 *
577 	 * Params:
578 	 *     volume = a #GVolume that changed.
579 	 */
580 	void addOnVolumeChanged(void delegate(VolumeIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
581 	{
582 		if ( "volume-changed" !in connectedSignals )
583 		{
584 			Signals.connectData(
585 				this,
586 				"volume-changed",
587 				cast(GCallback)&callBackVolumeChanged,
588 				cast(void*)this,
589 				null,
590 				connectFlags);
591 			connectedSignals["volume-changed"] = 1;
592 		}
593 		onVolumeChangedListeners ~= dlg;
594 	}
595 	extern(C) static void callBackVolumeChanged(GVolumeMonitor* volumemonitorStruct, GVolume* volume, VolumeMonitor _volumemonitor)
596 	{
597 		foreach ( void delegate(VolumeIF, VolumeMonitor) dlg; _volumemonitor.onVolumeChangedListeners )
598 		{
599 			dlg(ObjectG.getDObject!(Volume, VolumeIF)(volume), _volumemonitor);
600 		}
601 	}
602 
603 	void delegate(VolumeIF, VolumeMonitor)[] onVolumeRemovedListeners;
604 	/**
605 	 * Emitted when a mountable volume is removed from the system.
606 	 *
607 	 * Params:
608 	 *     volume = a #GVolume that was removed.
609 	 */
610 	void addOnVolumeRemoved(void delegate(VolumeIF, VolumeMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
611 	{
612 		if ( "volume-removed" !in connectedSignals )
613 		{
614 			Signals.connectData(
615 				this,
616 				"volume-removed",
617 				cast(GCallback)&callBackVolumeRemoved,
618 				cast(void*)this,
619 				null,
620 				connectFlags);
621 			connectedSignals["volume-removed"] = 1;
622 		}
623 		onVolumeRemovedListeners ~= dlg;
624 	}
625 	extern(C) static void callBackVolumeRemoved(GVolumeMonitor* volumemonitorStruct, GVolume* volume, VolumeMonitor _volumemonitor)
626 	{
627 		foreach ( void delegate(VolumeIF, VolumeMonitor) dlg; _volumemonitor.onVolumeRemovedListeners )
628 		{
629 			dlg(ObjectG.getDObject!(Volume, VolumeIF)(volume), _volumemonitor);
630 		}
631 	}
632 }