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.MemorySlice;
28 public  import glib.Str;
29 public  import gobject.ObjectG;
30 public  import gobject.ParamSpec;
31 public  import gobject.Signals;
32 public  import gobject.Value;
33 public  import gstreamer.c.functions;
34 public  import gstreamer.c.types;
35 public  import gstreamerc.gstreamertypes;
36 public  import std.algorithm;
37 
38 
39 /**
40  * This interface abstracts handling of property sets for elements with
41  * children. Imagine elements such as mixers or polyphonic generators. They all
42  * have multiple #GstPad or some kind of voice objects. Another use case are
43  * container elements like #GstBin.
44  * The element implementing the interface acts as a parent for those child
45  * objects.
46  * 
47  * By implementing this interface the child properties can be accessed from the
48  * parent element by using gst_child_proxy_get() and gst_child_proxy_set().
49  * 
50  * Property names are written as "child-name::property-name". The whole naming
51  * scheme is recursive. Thus "child1::child2::property" is valid too, if
52  * "child1" and "child2" implement the #GstChildProxy interface.
53  */
54 public template ChildProxyT(TStruct)
55 {
56 	/** Get the main Gtk struct */
57 	public GstChildProxy* getChildProxyStruct(bool transferOwnership = false)
58 	{
59 		if (transferOwnership)
60 			ownedRef = false;
61 		return cast(GstChildProxy*)getStruct();
62 	}
63 
64 
65 	/**
66 	 * Emits the "child-added" signal.
67 	 *
68 	 * Params:
69 	 *     child = the newly added child
70 	 *     name = the name of the new child
71 	 */
72 	public void childAdded(ObjectG child, string name)
73 	{
74 		gst_child_proxy_child_added(getChildProxyStruct(), (child is null) ? null : child.getObjectGStruct(), Str.toStringz(name));
75 	}
76 
77 	/**
78 	 * Emits the "child-removed" signal.
79 	 *
80 	 * Params:
81 	 *     child = the removed child
82 	 *     name = the name of the old child
83 	 */
84 	public void childRemoved(ObjectG child, string name)
85 	{
86 		gst_child_proxy_child_removed(getChildProxyStruct(), (child is null) ? null : child.getObjectGStruct(), Str.toStringz(name));
87 	}
88 
89 	/**
90 	 * Fetches a child by its number.
91 	 *
92 	 * Params:
93 	 *     index = the child's position in the child list
94 	 *
95 	 * Returns: the child object or %NULL if
96 	 *     not found (index too high). Unref after usage.
97 	 *
98 	 *     MT safe.
99 	 */
100 	public ObjectG getChildByIndex(uint index)
101 	{
102 		auto p = gst_child_proxy_get_child_by_index(getChildProxyStruct(), index);
103 
104 		if(p is null)
105 		{
106 			return null;
107 		}
108 
109 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
110 	}
111 
112 	/**
113 	 * Looks up a child element by the given name.
114 	 *
115 	 * This virtual method has a default implementation that uses #GstObject
116 	 * together with gst_object_get_name(). If the interface is to be used with
117 	 * #GObjects, this methods needs to be overridden.
118 	 *
119 	 * Params:
120 	 *     name = the child's name
121 	 *
122 	 * Returns: the child object or %NULL if
123 	 *     not found. Unref after usage.
124 	 *
125 	 *     MT safe.
126 	 */
127 	public ObjectG getChildByName(string name)
128 	{
129 		auto p = gst_child_proxy_get_child_by_name(getChildProxyStruct(), Str.toStringz(name));
130 
131 		if(p is null)
132 		{
133 			return null;
134 		}
135 
136 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
137 	}
138 
139 	/**
140 	 * Gets the number of child objects this parent contains.
141 	 *
142 	 * Returns: the number of child objects
143 	 *
144 	 *     MT safe.
145 	 */
146 	public uint getChildrenCount()
147 	{
148 		return gst_child_proxy_get_children_count(getChildProxyStruct());
149 	}
150 
151 	/**
152 	 * Gets a single property using the GstChildProxy mechanism.
153 	 * You are responsible for freeing it by calling g_value_unset()
154 	 *
155 	 * Params:
156 	 *     name = name of the property
157 	 *     value = a #GValue that should take the result.
158 	 */
159 	public void childGetProperty(string name, out Value value)
160 	{
161 		GValue* outvalue = sliceNew!GValue();
162 
163 		gst_child_proxy_get_property(getChildProxyStruct(), Str.toStringz(name), outvalue);
164 
165 		value = ObjectG.getDObject!(Value)(outvalue, true);
166 	}
167 
168 	/**
169 	 * Gets properties of the parent object and its children.
170 	 *
171 	 * Params:
172 	 *     firstPropertyName = name of the first property to get
173 	 *     varArgs = return location for the first property, followed optionally by more name/return location pairs, followed by %NULL
174 	 */
175 	public void childGetValist(string firstPropertyName, void* varArgs)
176 	{
177 		gst_child_proxy_get_valist(getChildProxyStruct(), Str.toStringz(firstPropertyName), varArgs);
178 	}
179 
180 	/**
181 	 * Looks up which object and #GParamSpec would be effected by the given @name.
182 	 *
183 	 * MT safe.
184 	 *
185 	 * Params:
186 	 *     name = name of the property to look up
187 	 *     target = pointer to a #GObject that
188 	 *         takes the real object to set property on
189 	 *     pspec = pointer to take the #GParamSpec
190 	 *         describing the property
191 	 *
192 	 * Returns: %TRUE if @target and @pspec could be found. %FALSE otherwise. In that
193 	 *     case the values for @pspec and @target are not modified. Unref @target after
194 	 *     usage. For plain GObjects @target is the same as @object.
195 	 */
196 	public bool lookup(string name, out ObjectG target, out ParamSpec pspec)
197 	{
198 		GObject* outtarget = null;
199 		GParamSpec* outpspec = null;
200 
201 		auto p = gst_child_proxy_lookup(getChildProxyStruct(), Str.toStringz(name), &outtarget, &outpspec) != 0;
202 
203 		target = ObjectG.getDObject!(ObjectG)(outtarget);
204 		pspec = ObjectG.getDObject!(ParamSpec)(outpspec);
205 
206 		return p;
207 	}
208 
209 	/**
210 	 * Sets a single property using the GstChildProxy mechanism.
211 	 *
212 	 * Params:
213 	 *     name = name of the property to set
214 	 *     value = new #GValue for the property
215 	 */
216 	public void childSetProperty(string name, Value value)
217 	{
218 		gst_child_proxy_set_property(getChildProxyStruct(), Str.toStringz(name), (value is null) ? null : value.getValueStruct());
219 	}
220 
221 	/**
222 	 * Sets properties of the parent object and its children.
223 	 *
224 	 * Params:
225 	 *     firstPropertyName = name of the first property to set
226 	 *     varArgs = value for the first property, followed optionally by more name/value pairs, followed by %NULL
227 	 */
228 	public void childSetValist(string firstPropertyName, void* varArgs)
229 	{
230 		gst_child_proxy_set_valist(getChildProxyStruct(), Str.toStringz(firstPropertyName), varArgs);
231 	}
232 
233 	/**
234 	 * Will be emitted after the @object was added to the @child_proxy.
235 	 *
236 	 * Params:
237 	 *     object = the #GObject that was added
238 	 *     name = the name of the new child
239 	 */
240 	gulong addOnChildAdded(void delegate(ObjectG, string, ChildProxyIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
241 	{
242 		return Signals.connect(this, "child-added", dlg, connectFlags ^ ConnectFlags.SWAPPED);
243 	}
244 
245 	/**
246 	 * Will be emitted after the @object was removed from the @child_proxy.
247 	 *
248 	 * Params:
249 	 *     object = the #GObject that was removed
250 	 *     name = the name of the old child
251 	 */
252 	gulong addOnChildRemoved(void delegate(ObjectG, string, ChildProxyIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
253 	{
254 		return Signals.connect(this, "child-removed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
255 	}
256 }