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