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