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 gstreamer.ChildProxyT;
26 
27 public  import glib.Str;
28 public  import gobject.ObjectG;
29 public  import gobject.ParamSpec;
30 public  import gobject.Signals;
31 public  import gobject.Value;
32 public  import gstreamerc.gstreamer;
33 public  import gstreamerc.gstreamertypes;
34 public  import std.algorithm;
35 
36 
37 /**
38  * This interface abstracts handling of property sets for elements with
39  * children. Imagine elements such as mixers or polyphonic generators. They all
40  * have multiple #GstPad or some kind of voice objects. Another use case are
41  * container elements like #GstBin.
42  * The element implementing the interface acts as a parent for those child
43  * objects.
44  * 
45  * By implementing this interface the child properties can be accessed from the
46  * parent element by using gst_child_proxy_get() and gst_child_proxy_set().
47  * 
48  * Property names are written as "child-name::property-name". The whole naming
49  * scheme is recursive. Thus "child1::child2::property" is valid too, if
50  * "child1" and "child2" implement the #GstChildProxy interface.
51  */
52 public template ChildProxyT(TStruct)
53 {
54 	/** Get the main Gtk struct */
55 	public GstChildProxy* getChildProxyStruct()
56 	{
57 		return cast(GstChildProxy*)getStruct();
58 	}
59 
60 
61 	/**
62 	 * Emits the "child-added" signal.
63 	 *
64 	 * Params:
65 	 *     child = the newly added child
66 	 *     name = the name of the new child
67 	 */
68 	public void childAdded(ObjectG child, string name)
69 	{
70 		gst_child_proxy_child_added(getChildProxyStruct(), (child is null) ? null : child.getObjectGStruct(), Str.toStringz(name));
71 	}
72 
73 	/**
74 	 * Emits the "child-removed" signal.
75 	 *
76 	 * Params:
77 	 *     child = the removed child
78 	 *     name = the name of the old child
79 	 */
80 	public void childRemoved(ObjectG child, string name)
81 	{
82 		gst_child_proxy_child_removed(getChildProxyStruct(), (child is null) ? null : child.getObjectGStruct(), Str.toStringz(name));
83 	}
84 
85 	/**
86 	 * Fetches a child by its number.
87 	 *
88 	 * Params:
89 	 *     index = the child's position in the child list
90 	 *
91 	 * Returns: the child object or %NULL if
92 	 *     not found (index too high). Unref after usage.
93 	 *
94 	 *     MT safe.
95 	 */
96 	public ObjectG getChildByIndex(uint index)
97 	{
98 		auto p = gst_child_proxy_get_child_by_index(getChildProxyStruct(), index);
99 		
100 		if(p is null)
101 		{
102 			return null;
103 		}
104 		
105 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
106 	}
107 
108 	/**
109 	 * Looks up a child element by the given name.
110 	 *
111 	 * This virtual method has a default implementation that uses #GstObject
112 	 * together with gst_object_get_name(). If the interface is to be used with
113 	 * #GObjects, this methods needs to be overridden.
114 	 *
115 	 * Params:
116 	 *     name = the child's name
117 	 *
118 	 * Returns: the child object or %NULL if
119 	 *     not found. Unref after usage.
120 	 *
121 	 *     MT safe.
122 	 */
123 	public ObjectG getChildByName(string name)
124 	{
125 		auto p = gst_child_proxy_get_child_by_name(getChildProxyStruct(), Str.toStringz(name));
126 		
127 		if(p is null)
128 		{
129 			return null;
130 		}
131 		
132 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
133 	}
134 
135 	/**
136 	 * Gets the number of child objects this parent contains.
137 	 *
138 	 * Returns: the number of child objects
139 	 *
140 	 *     MT safe.
141 	 */
142 	public uint getChildrenCount()
143 	{
144 		return gst_child_proxy_get_children_count(getChildProxyStruct());
145 	}
146 
147 	/**
148 	 * Gets a single property using the GstChildProxy mechanism.
149 	 * You are responsible for freeing it by calling g_value_unset()
150 	 *
151 	 * Params:
152 	 *     name = name of the property
153 	 *     value = a #GValue that should take the result.
154 	 */
155 	public void childGetProperty(string name, out Value value)
156 	{
157 		GValue* outvalue = gMalloc!GValue();
158 		
159 		gst_child_proxy_get_property(getChildProxyStruct(), Str.toStringz(name), outvalue);
160 		
161 		value = ObjectG.getDObject!(Value)(outvalue, true);
162 	}
163 
164 	/**
165 	 * Gets properties of the parent object and its children.
166 	 *
167 	 * Params:
168 	 *     firstPropertyName = name of the first property to get
169 	 *     varArgs = return location for the first property, followed optionally by more name/return location pairs, followed by %NULL
170 	 */
171 	public void childGetValist(string firstPropertyName, void* varArgs)
172 	{
173 		gst_child_proxy_get_valist(getChildProxyStruct(), Str.toStringz(firstPropertyName), varArgs);
174 	}
175 
176 	/**
177 	 * Looks up which object and #GParamSpec would be effected by the given @name.
178 	 *
179 	 * MT safe.
180 	 *
181 	 * Params:
182 	 *     name = name of the property to look up
183 	 *     target = pointer to a #GObject that
184 	 *         takes the real object to set property on
185 	 *     pspec = pointer to take the #GParamSpec
186 	 *         describing the property
187 	 *
188 	 * Returns: %TRUE if @target and @pspec could be found. %FALSE otherwise. In that
189 	 *     case the values for @pspec and @target are not modified. Unref @target after
190 	 *     usage. For plain GObjects @target is the same as @object.
191 	 */
192 	public bool lookup(string name, out ObjectG target, out ParamSpec pspec)
193 	{
194 		GObject* outtarget = null;
195 		GParamSpec* outpspec = null;
196 		
197 		auto p = gst_child_proxy_lookup(getChildProxyStruct(), Str.toStringz(name), &outtarget, &outpspec) != 0;
198 		
199 		target = ObjectG.getDObject!(ObjectG)(outtarget);
200 		pspec = ObjectG.getDObject!(ParamSpec)(outpspec);
201 		
202 		return p;
203 	}
204 
205 	/**
206 	 * Sets a single property using the GstChildProxy mechanism.
207 	 *
208 	 * Params:
209 	 *     name = name of the property to set
210 	 *     value = new #GValue for the property
211 	 */
212 	public void childSetProperty(string name, Value value)
213 	{
214 		gst_child_proxy_set_property(getChildProxyStruct(), Str.toStringz(name), (value is null) ? null : value.getValueStruct());
215 	}
216 
217 	/**
218 	 * Sets properties of the parent object and its children.
219 	 *
220 	 * Params:
221 	 *     firstPropertyName = name of the first property to set
222 	 *     varArgs = value for the first property, followed optionally by more name/value pairs, followed by %NULL
223 	 */
224 	public void childSetValist(string firstPropertyName, void* varArgs)
225 	{
226 		gst_child_proxy_set_valist(getChildProxyStruct(), Str.toStringz(firstPropertyName), varArgs);
227 	}
228 
229 	protected class OnChildAddedDelegateWrapper
230 	{
231 		static OnChildAddedDelegateWrapper[] listeners;
232 		void delegate(ObjectG, string, ChildProxyIF) dlg;
233 		gulong handlerId;
234 		
235 		this(void delegate(ObjectG, string, ChildProxyIF) dlg)
236 		{
237 			this.dlg = dlg;
238 			this.listeners ~= this;
239 		}
240 		
241 		void remove(OnChildAddedDelegateWrapper source)
242 		{
243 			foreach(index, wrapper; listeners)
244 			{
245 				if (wrapper.handlerId == source.handlerId)
246 				{
247 					listeners[index] = null;
248 					listeners = std.algorithm.remove(listeners, index);
249 					break;
250 				}
251 			}
252 		}
253 	}
254 
255 	/**
256 	 * Will be emitted after the @object was added to the @child_proxy.
257 	 *
258 	 * Params:
259 	 *     object = the #GObject that was added
260 	 *     name = the name of the new child
261 	 */
262 	gulong addOnChildAdded(void delegate(ObjectG, string, ChildProxyIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
263 	{
264 		auto wrapper = new OnChildAddedDelegateWrapper(dlg);
265 		wrapper.handlerId = Signals.connectData(
266 			this,
267 			"child-added",
268 			cast(GCallback)&callBackChildAdded,
269 			cast(void*)wrapper,
270 			cast(GClosureNotify)&callBackChildAddedDestroy,
271 			connectFlags);
272 		return wrapper.handlerId;
273 	}
274 	
275 	extern(C) static void callBackChildAdded(GstChildProxy* childproxyStruct, GObject* object, char* name, OnChildAddedDelegateWrapper wrapper)
276 	{
277 		wrapper.dlg(ObjectG.getDObject!(ObjectG)(object), Str.toString(name), wrapper.outer);
278 	}
279 	
280 	extern(C) static void callBackChildAddedDestroy(OnChildAddedDelegateWrapper wrapper, GClosure* closure)
281 	{
282 		wrapper.remove(wrapper);
283 	}
284 
285 	protected class OnChildRemovedDelegateWrapper
286 	{
287 		static OnChildRemovedDelegateWrapper[] listeners;
288 		void delegate(ObjectG, string, ChildProxyIF) dlg;
289 		gulong handlerId;
290 		
291 		this(void delegate(ObjectG, string, ChildProxyIF) dlg)
292 		{
293 			this.dlg = dlg;
294 			this.listeners ~= this;
295 		}
296 		
297 		void remove(OnChildRemovedDelegateWrapper source)
298 		{
299 			foreach(index, wrapper; listeners)
300 			{
301 				if (wrapper.handlerId == source.handlerId)
302 				{
303 					listeners[index] = null;
304 					listeners = std.algorithm.remove(listeners, index);
305 					break;
306 				}
307 			}
308 		}
309 	}
310 
311 	/**
312 	 * Will be emitted after the @object was removed from the @child_proxy.
313 	 *
314 	 * Params:
315 	 *     object = the #GObject that was removed
316 	 *     name = the name of the old child
317 	 */
318 	gulong addOnChildRemoved(void delegate(ObjectG, string, ChildProxyIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
319 	{
320 		auto wrapper = new OnChildRemovedDelegateWrapper(dlg);
321 		wrapper.handlerId = Signals.connectData(
322 			this,
323 			"child-removed",
324 			cast(GCallback)&callBackChildRemoved,
325 			cast(void*)wrapper,
326 			cast(GClosureNotify)&callBackChildRemovedDestroy,
327 			connectFlags);
328 		return wrapper.handlerId;
329 	}
330 	
331 	extern(C) static void callBackChildRemoved(GstChildProxy* childproxyStruct, GObject* object, char* name, OnChildRemovedDelegateWrapper wrapper)
332 	{
333 		wrapper.dlg(ObjectG.getDObject!(ObjectG)(object), Str.toString(name), wrapper.outer);
334 	}
335 	
336 	extern(C) static void callBackChildRemovedDestroy(OnChildRemovedDelegateWrapper wrapper, GClosure* closure)
337 	{
338 		wrapper.remove(wrapper);
339 	}
340 }