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.UnixMountMonitor;
26 
27 private import gio.c.functions;
28 public  import gio.c.types;
29 private import glib.ConstructionException;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 public  import gtkc.giotypes;
33 private import std.algorithm;
34 
35 
36 /**
37  * Watches #GUnixMounts for changes.
38  */
39 public class UnixMountMonitor : ObjectG
40 {
41 	/** the main Gtk struct */
42 	protected GUnixMountMonitor* gUnixMountMonitor;
43 
44 	/** Get the main Gtk struct */
45 	public GUnixMountMonitor* getUnixMountMonitorStruct(bool transferOwnership = false)
46 	{
47 		if (transferOwnership)
48 			ownedRef = false;
49 		return gUnixMountMonitor;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected override void* getStruct()
54 	{
55 		return cast(void*)gUnixMountMonitor;
56 	}
57 
58 	protected override void setStruct(GObject* obj)
59 	{
60 		gUnixMountMonitor = cast(GUnixMountMonitor*)obj;
61 		super.setStruct(obj);
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GUnixMountMonitor* gUnixMountMonitor, bool ownedRef = false)
68 	{
69 		this.gUnixMountMonitor = gUnixMountMonitor;
70 		super(cast(GObject*)gUnixMountMonitor, ownedRef);
71 	}
72 
73 
74 	/** */
75 	public static GType getType()
76 	{
77 		return g_unix_mount_monitor_get_type();
78 	}
79 
80 	/**
81 	 * Deprecated alias for g_unix_mount_monitor_get().
82 	 *
83 	 * This function was never a true constructor, which is why it was
84 	 * renamed.
85 	 *
86 	 * Deprecated: Use g_unix_mount_monitor_get() instead.
87 	 *
88 	 * Returns: a #GUnixMountMonitor.
89 	 *
90 	 * Throws: ConstructionException GTK+ fails to create the object.
91 	 */
92 	public this()
93 	{
94 		auto p = g_unix_mount_monitor_new();
95 
96 		if(p is null)
97 		{
98 			throw new ConstructionException("null returned by new");
99 		}
100 
101 		this(cast(GUnixMountMonitor*) p, true);
102 	}
103 
104 	/**
105 	 * Gets the #GUnixMountMonitor for the current thread-default main
106 	 * context.
107 	 *
108 	 * The mount monitor can be used to monitor for changes to the list of
109 	 * mounted filesystems as well as the list of mount points (ie: fstab
110 	 * entries).
111 	 *
112 	 * You must only call g_object_unref() on the return value from under
113 	 * the same main context as you called this function.
114 	 *
115 	 * Returns: the #GUnixMountMonitor.
116 	 *
117 	 * Since: 2.44
118 	 */
119 	public static UnixMountMonitor get()
120 	{
121 		auto p = g_unix_mount_monitor_get();
122 
123 		if(p is null)
124 		{
125 			return null;
126 		}
127 
128 		return ObjectG.getDObject!(UnixMountMonitor)(cast(GUnixMountMonitor*) p, true);
129 	}
130 
131 	/**
132 	 * This function does nothing.
133 	 *
134 	 * Before 2.44, this was a partially-effective way of controlling the
135 	 * rate at which events would be reported under some uncommon
136 	 * circumstances.  Since @mount_monitor is a singleton, it also meant
137 	 * that calling this function would have side effects for other users of
138 	 * the monitor.
139 	 *
140 	 * Deprecated: This function does nothing.  Don't call it.
141 	 *
142 	 * Params:
143 	 *     limitMsec = a integer with the limit in milliseconds to
144 	 *         poll for changes.
145 	 *
146 	 * Since: 2.18
147 	 */
148 	public void setRateLimit(int limitMsec)
149 	{
150 		g_unix_mount_monitor_set_rate_limit(gUnixMountMonitor, limitMsec);
151 	}
152 
153 	protected class OnMountpointsChangedDelegateWrapper
154 	{
155 		void delegate(UnixMountMonitor) dlg;
156 		gulong handlerId;
157 
158 		this(void delegate(UnixMountMonitor) dlg)
159 		{
160 			this.dlg = dlg;
161 			onMountpointsChangedListeners ~= this;
162 		}
163 
164 		void remove(OnMountpointsChangedDelegateWrapper source)
165 		{
166 			foreach(index, wrapper; onMountpointsChangedListeners)
167 			{
168 				if (wrapper.handlerId == source.handlerId)
169 				{
170 					onMountpointsChangedListeners[index] = null;
171 					onMountpointsChangedListeners = std.algorithm.remove(onMountpointsChangedListeners, index);
172 					break;
173 				}
174 			}
175 		}
176 	}
177 	OnMountpointsChangedDelegateWrapper[] onMountpointsChangedListeners;
178 
179 	/**
180 	 * Emitted when the unix mount points have changed.
181 	 */
182 	gulong addOnMountpointsChanged(void delegate(UnixMountMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
183 	{
184 		auto wrapper = new OnMountpointsChangedDelegateWrapper(dlg);
185 		wrapper.handlerId = Signals.connectData(
186 			this,
187 			"mountpoints-changed",
188 			cast(GCallback)&callBackMountpointsChanged,
189 			cast(void*)wrapper,
190 			cast(GClosureNotify)&callBackMountpointsChangedDestroy,
191 			connectFlags);
192 		return wrapper.handlerId;
193 	}
194 
195 	extern(C) static void callBackMountpointsChanged(GUnixMountMonitor* unixmountmonitorStruct, OnMountpointsChangedDelegateWrapper wrapper)
196 	{
197 		wrapper.dlg(wrapper.outer);
198 	}
199 
200 	extern(C) static void callBackMountpointsChangedDestroy(OnMountpointsChangedDelegateWrapper wrapper, GClosure* closure)
201 	{
202 		wrapper.remove(wrapper);
203 	}
204 
205 	protected class OnMountsChangedDelegateWrapper
206 	{
207 		void delegate(UnixMountMonitor) dlg;
208 		gulong handlerId;
209 
210 		this(void delegate(UnixMountMonitor) dlg)
211 		{
212 			this.dlg = dlg;
213 			onMountsChangedListeners ~= this;
214 		}
215 
216 		void remove(OnMountsChangedDelegateWrapper source)
217 		{
218 			foreach(index, wrapper; onMountsChangedListeners)
219 			{
220 				if (wrapper.handlerId == source.handlerId)
221 				{
222 					onMountsChangedListeners[index] = null;
223 					onMountsChangedListeners = std.algorithm.remove(onMountsChangedListeners, index);
224 					break;
225 				}
226 			}
227 		}
228 	}
229 	OnMountsChangedDelegateWrapper[] onMountsChangedListeners;
230 
231 	/**
232 	 * Emitted when the unix mounts have changed.
233 	 */
234 	gulong addOnMountsChanged(void delegate(UnixMountMonitor) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
235 	{
236 		auto wrapper = new OnMountsChangedDelegateWrapper(dlg);
237 		wrapper.handlerId = Signals.connectData(
238 			this,
239 			"mounts-changed",
240 			cast(GCallback)&callBackMountsChanged,
241 			cast(void*)wrapper,
242 			cast(GClosureNotify)&callBackMountsChangedDestroy,
243 			connectFlags);
244 		return wrapper.handlerId;
245 	}
246 
247 	extern(C) static void callBackMountsChanged(GUnixMountMonitor* unixmountmonitorStruct, OnMountsChangedDelegateWrapper wrapper)
248 	{
249 		wrapper.dlg(wrapper.outer);
250 	}
251 
252 	extern(C) static void callBackMountsChangedDestroy(OnMountsChangedDelegateWrapper wrapper, GClosure* closure)
253 	{
254 		wrapper.remove(wrapper);
255 	}
256 }