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