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