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