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