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 gtkc.gdktypes;
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 
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 	 * Return: 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 	 * Return: 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 	 * Return: 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 = new GValue;
160 		
161 		gst_child_proxy_get_property(getChildProxyStruct(), Str.toStringz(name), outvalue);
162 		
163 		value = ObjectG.getDObject!(Value)(outvalue);
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 	 * Return: %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 	int[string] connectedSignals;
232 
233 	void delegate(ObjectG, string, ChildProxyIF)[] _onChildAddedListeners;
234 	@property void delegate(ObjectG, string, ChildProxyIF)[] onChildAddedListeners()
235 	{
236 		return _onChildAddedListeners;
237 	}
238 	/**
239 	 * Will be emitted after the @object was added to the @child_proxy.
240 	 *
241 	 * Params:
242 	 *     object = the #GObject that was added
243 	 *     name = the name of the new child
244 	 */
245 	void addOnChildAdded(void delegate(ObjectG, string, ChildProxyIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
246 	{
247 		if ( "child-added" !in connectedSignals )
248 		{
249 			Signals.connectData(
250 				this,
251 				"child-added",
252 				cast(GCallback)&callBackChildAdded,
253 				cast(void*)cast(ChildProxyIF)this,
254 				null,
255 				connectFlags);
256 			connectedSignals["child-added"] = 1;
257 		}
258 		_onChildAddedListeners ~= dlg;
259 	}
260 	extern(C) static void callBackChildAdded(GstChildProxy* childproxyStruct, GObject* object, char* name, ChildProxyIF _childproxy)
261 	{
262 		foreach ( void delegate(ObjectG, string, ChildProxyIF) dlg; _childproxy.onChildAddedListeners )
263 		{
264 			dlg(ObjectG.getDObject!(ObjectG)(object), Str.toString(name), _childproxy);
265 		}
266 	}
267 
268 	void delegate(ObjectG, string, ChildProxyIF)[] _onChildRemovedListeners;
269 	@property void delegate(ObjectG, string, ChildProxyIF)[] onChildRemovedListeners()
270 	{
271 		return _onChildRemovedListeners;
272 	}
273 	/**
274 	 * Will be emitted after the @object was removed from the @child_proxy.
275 	 *
276 	 * Params:
277 	 *     object = the #GObject that was removed
278 	 *     name = the name of the old child
279 	 */
280 	void addOnChildRemoved(void delegate(ObjectG, string, ChildProxyIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
281 	{
282 		if ( "child-removed" !in connectedSignals )
283 		{
284 			Signals.connectData(
285 				this,
286 				"child-removed",
287 				cast(GCallback)&callBackChildRemoved,
288 				cast(void*)cast(ChildProxyIF)this,
289 				null,
290 				connectFlags);
291 			connectedSignals["child-removed"] = 1;
292 		}
293 		_onChildRemovedListeners ~= dlg;
294 	}
295 	extern(C) static void callBackChildRemoved(GstChildProxy* childproxyStruct, GObject* object, char* name, ChildProxyIF _childproxy)
296 	{
297 		foreach ( void delegate(ObjectG, string, ChildProxyIF) dlg; _childproxy.onChildRemovedListeners )
298 		{
299 			dlg(ObjectG.getDObject!(ObjectG)(object), Str.toString(name), _childproxy);
300 		}
301 	}
302 }