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