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.ActionT;
26 
27 public  import glib.ErrorG;
28 public  import glib.GException;
29 public  import glib.Str;
30 public  import glib.Variant;
31 public  import glib.VariantType;
32 public  import gtkc.gio;
33 public  import gtkc.giotypes;
34 
35 
36 /**
37  * #GAction represents a single named action.
38  * 
39  * The main interface to an action is that it can be activated with
40  * g_action_activate().  This results in the 'activate' signal being
41  * emitted.  An activation has a #GVariant parameter (which may be
42  * %NULL).  The correct type for the parameter is determined by a static
43  * parameter type (which is given at construction time).
44  * 
45  * An action may optionally have a state, in which case the state may be
46  * set with g_action_change_state().  This call takes a #GVariant.  The
47  * correct type for the state is determined by a static state type
48  * (which is given at construction time).
49  * 
50  * The state may have a hint associated with it, specifying its valid
51  * range.
52  * 
53  * #GAction is merely the interface to the concept of an action, as
54  * described above.  Various implementations of actions exist, including
55  * #GSimpleAction.
56  * 
57  * In all cases, the implementing class is responsible for storing the
58  * name of the action, the parameter type, the enabled state, the
59  * optional state type and the state and emitting the appropriate
60  * signals when these change.  The implementor responsible for filtering
61  * calls to g_action_activate() and g_action_change_state() for type
62  * safety and for the state being enabled.
63  * 
64  * Probably the only useful thing to do with a #GAction is to put it
65  * inside of a #GSimpleActionGroup.
66  */
67 public template ActionT(TStruct)
68 {
69 	/** Get the main Gtk struct */
70 	public GAction* getActionStruct()
71 	{
72 		return cast(GAction*)getStruct();
73 	}
74 
75 
76 	/**
77 	 * Checks if @action_name is valid.
78 	 *
79 	 * @action_name is valid if it consists only of alphanumeric characters,
80 	 * plus '-' and '.'.  The empty string is not a valid action name.
81 	 *
82 	 * It is an error to call this function with a non-utf8 @action_name.
83 	 * @action_name must not be %NULL.
84 	 *
85 	 * Params:
86 	 *     actionName = an potential action name
87 	 *
88 	 * Return: %TRUE if @action_name is valid
89 	 *
90 	 * Since: 2.38
91 	 */
92 	public static bool nameIsValid(string actionName)
93 	{
94 		return g_action_name_is_valid(Str.toStringz(actionName)) != 0;
95 	}
96 
97 	/**
98 	 * Parses a detailed action name into its separate name and target
99 	 * components.
100 	 *
101 	 * Detailed action names can have three formats.
102 	 *
103 	 * The first format is used to represent an action name with no target
104 	 * value and consists of just an action name containing no whitespace
105 	 * nor the characters ':', '(' or ')'.  For example: "app.action".
106 	 *
107 	 * The second format is used to represent an action with a target value
108 	 * that is a non-empty string consisting only of alphanumerics, plus '-'
109 	 * and '.'.  In that case, the action name and target value are
110 	 * separated by a double colon ("::").  For example:
111 	 * "app.action::target".
112 	 *
113 	 * The third format is used to represent an action with any type of
114 	 * target value, including strings.  The target value follows the action
115 	 * name, surrounded in parens.  For example: "app.action(42)".  The
116 	 * target value is parsed using g_variant_parse().  If a tuple-typed
117 	 * value is desired, it must be specified in the same way, resulting in
118 	 * two sets of parens, for example: "app.action((1,2,3))".  A string
119 	 * target can be specified this way as well: "app.action('target')".
120 	 * For strings, this third format must be used if * target value is
121 	 * empty or contains characters other than alphanumerics, '-' and '.'.
122 	 *
123 	 * Params:
124 	 *     detailedName = a detailed action name
125 	 *     actionName = the action name
126 	 *     targetValue = the target value, or %NULL for no target
127 	 *
128 	 * Return: %TRUE if successful, else %FALSE with @error set
129 	 *
130 	 * Since: 2.38
131 	 *
132 	 * Throws: GException on failure.
133 	 */
134 	public static bool parseDetailedName(string detailedName, out string actionName, out Variant targetValue)
135 	{
136 		char* outactionName = null;
137 		GVariant* outtargetValue = null;
138 		GError* err = null;
139 		
140 		auto p = g_action_parse_detailed_name(Str.toStringz(detailedName), &outactionName, &outtargetValue, &err) != 0;
141 		
142 		if (err !is null)
143 		{
144 			throw new GException( new ErrorG(err) );
145 		}
146 		
147 		actionName = Str.toString(outactionName);
148 		targetValue = new Variant(outtargetValue);
149 		
150 		return p;
151 	}
152 
153 	/**
154 	 * Formats a detailed action name from @action_name and @target_value.
155 	 *
156 	 * It is an error to call this function with an invalid action name.
157 	 *
158 	 * This function is the opposite of
159 	 * g_action_parse_detailed_action_name().  It will produce a string that
160 	 * can be parsed back to the @action_name and @target_value by that
161 	 * function.
162 	 *
163 	 * See that function for the types of strings that will be printed by
164 	 * this function.
165 	 *
166 	 * Params:
167 	 *     actionName = a valid action name
168 	 *     targetValue = a #GVariant target value, or %NULL
169 	 *
170 	 * Return: a detailed format string
171 	 *
172 	 * Since: 2.38
173 	 */
174 	public static string printDetailedName(string actionName, Variant targetValue)
175 	{
176 		auto retStr = g_action_print_detailed_name(Str.toStringz(actionName), (targetValue is null) ? null : targetValue.getVariantStruct());
177 		
178 		scope(exit) Str.freeString(retStr);
179 		return Str.toString(retStr);
180 	}
181 
182 	/**
183 	 * Activates the action.
184 	 *
185 	 * @parameter must be the correct type of parameter for the action (ie:
186 	 * the parameter type given at construction time).  If the parameter
187 	 * type was %NULL then @parameter must also be %NULL.
188 	 *
189 	 * If the @parameter GVariant is floating, it is consumed.
190 	 *
191 	 * Params:
192 	 *     parameter = the parameter to the activation
193 	 *
194 	 * Since: 2.28
195 	 */
196 	public void activate(Variant parameter)
197 	{
198 		g_action_activate(getActionStruct(), (parameter is null) ? null : parameter.getVariantStruct());
199 	}
200 
201 	/**
202 	 * Request for the state of @action to be changed to @value.
203 	 *
204 	 * The action must be stateful and @value must be of the correct type.
205 	 * See g_action_get_state_type().
206 	 *
207 	 * This call merely requests a change.  The action may refuse to change
208 	 * its state or may change its state to something other than @value.
209 	 * See g_action_get_state_hint().
210 	 *
211 	 * If the @value GVariant is floating, it is consumed.
212 	 *
213 	 * Params:
214 	 *     value = the new state
215 	 *
216 	 * Since: 2.30
217 	 */
218 	public void changeState(Variant value)
219 	{
220 		g_action_change_state(getActionStruct(), (value is null) ? null : value.getVariantStruct());
221 	}
222 
223 	/**
224 	 * Checks if @action is currently enabled.
225 	 *
226 	 * An action must be enabled in order to be activated or in order to
227 	 * have its state changed from outside callers.
228 	 *
229 	 * Return: whether the action is enabled
230 	 *
231 	 * Since: 2.28
232 	 */
233 	public bool getEnabled()
234 	{
235 		return g_action_get_enabled(getActionStruct()) != 0;
236 	}
237 
238 	/**
239 	 * Queries the name of @action.
240 	 *
241 	 * Return: the name of the action
242 	 *
243 	 * Since: 2.28
244 	 */
245 	public string getName()
246 	{
247 		return Str.toString(g_action_get_name(getActionStruct()));
248 	}
249 
250 	/**
251 	 * Queries the type of the parameter that must be given when activating
252 	 * @action.
253 	 *
254 	 * When activating the action using g_action_activate(), the #GVariant
255 	 * given to that function must be of the type returned by this function.
256 	 *
257 	 * In the case that this function returns %NULL, you must not give any
258 	 * #GVariant, but %NULL instead.
259 	 *
260 	 * Return: the parameter type
261 	 *
262 	 * Since: 2.28
263 	 */
264 	public VariantType getParameterType()
265 	{
266 		auto p = g_action_get_parameter_type(getActionStruct());
267 		
268 		if(p is null)
269 		{
270 			return null;
271 		}
272 		
273 		return new VariantType(cast(GVariantType*) p);
274 	}
275 
276 	/**
277 	 * Queries the current state of @action.
278 	 *
279 	 * If the action is not stateful then %NULL will be returned.  If the
280 	 * action is stateful then the type of the return value is the type
281 	 * given by g_action_get_state_type().
282 	 *
283 	 * The return value (if non-%NULL) should be freed with
284 	 * g_variant_unref() when it is no longer required.
285 	 *
286 	 * Return: the current state of the action
287 	 *
288 	 * Since: 2.28
289 	 */
290 	public Variant getState()
291 	{
292 		auto p = g_action_get_state(getActionStruct());
293 		
294 		if(p is null)
295 		{
296 			return null;
297 		}
298 		
299 		return new Variant(cast(GVariant*) p, true);
300 	}
301 
302 	/**
303 	 * Requests a hint about the valid range of values for the state of
304 	 * @action.
305 	 *
306 	 * If %NULL is returned it either means that the action is not stateful
307 	 * or that there is no hint about the valid range of values for the
308 	 * state of the action.
309 	 *
310 	 * If a #GVariant array is returned then each item in the array is a
311 	 * possible value for the state.  If a #GVariant pair (ie: two-tuple) is
312 	 * returned then the tuple specifies the inclusive lower and upper bound
313 	 * of valid values for the state.
314 	 *
315 	 * In any case, the information is merely a hint.  It may be possible to
316 	 * have a state value outside of the hinted range and setting a value
317 	 * within the range may fail.
318 	 *
319 	 * The return value (if non-%NULL) should be freed with
320 	 * g_variant_unref() when it is no longer required.
321 	 *
322 	 * Return: the state range hint
323 	 *
324 	 * Since: 2.28
325 	 */
326 	public Variant getStateHint()
327 	{
328 		auto p = g_action_get_state_hint(getActionStruct());
329 		
330 		if(p is null)
331 		{
332 			return null;
333 		}
334 		
335 		return new Variant(cast(GVariant*) p, true);
336 	}
337 
338 	/**
339 	 * Queries the type of the state of @action.
340 	 *
341 	 * If the action is stateful (e.g. created with
342 	 * g_simple_action_new_stateful()) then this function returns the
343 	 * #GVariantType of the state.  This is the type of the initial value
344 	 * given as the state. All calls to g_action_change_state() must give a
345 	 * #GVariant of this type and g_action_get_state() will return a
346 	 * #GVariant of the same type.
347 	 *
348 	 * If the action is not stateful (e.g. created with g_simple_action_new())
349 	 * then this function will return %NULL. In that case, g_action_get_state()
350 	 * will return %NULL and you must not call g_action_change_state().
351 	 *
352 	 * Return: the state type, if the action is stateful
353 	 *
354 	 * Since: 2.28
355 	 */
356 	public VariantType getStateType()
357 	{
358 		auto p = g_action_get_state_type(getActionStruct());
359 		
360 		if(p is null)
361 		{
362 			return null;
363 		}
364 		
365 		return new VariantType(cast(GVariantType*) p);
366 	}
367 }