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.ActionGroupT;
26 
27 public  import gio.c.functions;
28 public  import gio.c.types;
29 public  import glib.Str;
30 public  import glib.Variant;
31 public  import glib.VariantType;
32 public  import glib.c.functions;
33 public  import gobject.Signals;
34 public  import std.algorithm;
35 
36 
37 /**
38  * #GActionGroup represents a group of actions. Actions can be used to
39  * expose functionality in a structured way, either from one part of a
40  * program to another, or to the outside world. Action groups are often
41  * used together with a #GMenuModel that provides additional
42  * representation data for displaying the actions to the user, e.g. in
43  * a menu.
44  * 
45  * The main way to interact with the actions in a GActionGroup is to
46  * activate them with g_action_group_activate_action(). Activating an
47  * action may require a #GVariant parameter. The required type of the
48  * parameter can be inquired with g_action_group_get_action_parameter_type().
49  * Actions may be disabled, see g_action_group_get_action_enabled().
50  * Activating a disabled action has no effect.
51  * 
52  * Actions may optionally have a state in the form of a #GVariant. The
53  * current state of an action can be inquired with
54  * g_action_group_get_action_state(). Activating a stateful action may
55  * change its state, but it is also possible to set the state by calling
56  * g_action_group_change_action_state().
57  * 
58  * As typical example, consider a text editing application which has an
59  * option to change the current font to 'bold'. A good way to represent
60  * this would be a stateful action, with a boolean state. Activating the
61  * action would toggle the state.
62  * 
63  * Each action in the group has a unique name (which is a string).  All
64  * method calls, except g_action_group_list_actions() take the name of
65  * an action as an argument.
66  * 
67  * The #GActionGroup API is meant to be the 'public' API to the action
68  * group.  The calls here are exactly the interaction that 'external
69  * forces' (eg: UI, incoming D-Bus messages, etc.) are supposed to have
70  * with actions.  'Internal' APIs (ie: ones meant only to be accessed by
71  * the action group implementation) are found on subclasses.  This is
72  * why you will find - for example - g_action_group_get_action_enabled()
73  * but not an equivalent set() call.
74  * 
75  * Signals are emitted on the action group in response to state changes
76  * on individual actions.
77  * 
78  * Implementations of #GActionGroup should provide implementations for
79  * the virtual functions g_action_group_list_actions() and
80  * g_action_group_query_action().  The other virtual functions should
81  * not be implemented - their "wrappers" are actually implemented with
82  * calls to g_action_group_query_action().
83  */
84 public template ActionGroupT(TStruct)
85 {
86 	/** Get the main Gtk struct */
87 	public GActionGroup* getActionGroupStruct(bool transferOwnership = false)
88 	{
89 		if (transferOwnership)
90 			ownedRef = false;
91 		return cast(GActionGroup*)getStruct();
92 	}
93 
94 
95 	/**
96 	 * Emits the #GActionGroup::action-added signal on @action_group.
97 	 *
98 	 * This function should only be called by #GActionGroup implementations.
99 	 *
100 	 * Params:
101 	 *     actionName = the name of an action in the group
102 	 *
103 	 * Since: 2.28
104 	 */
105 	public void actionAdded(string actionName)
106 	{
107 		g_action_group_action_added(getActionGroupStruct(), Str.toStringz(actionName));
108 	}
109 
110 	/**
111 	 * Emits the #GActionGroup::action-enabled-changed signal on @action_group.
112 	 *
113 	 * This function should only be called by #GActionGroup implementations.
114 	 *
115 	 * Params:
116 	 *     actionName = the name of an action in the group
117 	 *     enabled = whether or not the action is now enabled
118 	 *
119 	 * Since: 2.28
120 	 */
121 	public void actionEnabledChanged(string actionName, bool enabled)
122 	{
123 		g_action_group_action_enabled_changed(getActionGroupStruct(), Str.toStringz(actionName), enabled);
124 	}
125 
126 	/**
127 	 * Emits the #GActionGroup::action-removed signal on @action_group.
128 	 *
129 	 * This function should only be called by #GActionGroup implementations.
130 	 *
131 	 * Params:
132 	 *     actionName = the name of an action in the group
133 	 *
134 	 * Since: 2.28
135 	 */
136 	public void actionRemoved(string actionName)
137 	{
138 		g_action_group_action_removed(getActionGroupStruct(), Str.toStringz(actionName));
139 	}
140 
141 	/**
142 	 * Emits the #GActionGroup::action-state-changed signal on @action_group.
143 	 *
144 	 * This function should only be called by #GActionGroup implementations.
145 	 *
146 	 * Params:
147 	 *     actionName = the name of an action in the group
148 	 *     state = the new state of the named action
149 	 *
150 	 * Since: 2.28
151 	 */
152 	public void actionStateChanged(string actionName, Variant state)
153 	{
154 		g_action_group_action_state_changed(getActionGroupStruct(), Str.toStringz(actionName), (state is null) ? null : state.getVariantStruct());
155 	}
156 
157 	/**
158 	 * Activate the named action within @action_group.
159 	 *
160 	 * If the action is expecting a parameter, then the correct type of
161 	 * parameter must be given as @parameter.  If the action is expecting no
162 	 * parameters then @parameter must be %NULL.  See
163 	 * g_action_group_get_action_parameter_type().
164 	 *
165 	 * If the #GActionGroup implementation supports asynchronous remote
166 	 * activation over D-Bus, this call may return before the relevant
167 	 * D-Bus traffic has been sent, or any replies have been received. In
168 	 * order to block on such asynchronous activation calls,
169 	 * g_dbus_connection_flush() should be called prior to the code, which
170 	 * depends on the result of the action activation. Without flushing
171 	 * the D-Bus connection, there is no guarantee that the action would
172 	 * have been activated.
173 	 *
174 	 * The following code which runs in a remote app instance, shows an
175 	 * example of a "quit" action being activated on the primary app
176 	 * instance over D-Bus. Here g_dbus_connection_flush() is called
177 	 * before `exit()`. Without g_dbus_connection_flush(), the "quit" action
178 	 * may fail to be activated on the primary instance.
179 	 *
180 	 * |[<!-- language="C" -->
181 	 * // call "quit" action on primary instance
182 	 * g_action_group_activate_action (G_ACTION_GROUP (app), "quit", NULL);
183 	 *
184 	 * // make sure the action is activated now
185 	 * g_dbus_connection_flush (...);
186 	 *
187 	 * g_debug ("application has been terminated. exiting.");
188 	 *
189 	 * exit (0);
190 	 * ]|
191 	 *
192 	 * Params:
193 	 *     actionName = the name of the action to activate
194 	 *     parameter = parameters to the activation
195 	 *
196 	 * Since: 2.28
197 	 */
198 	public void activateAction(string actionName, Variant parameter)
199 	{
200 		g_action_group_activate_action(getActionGroupStruct(), Str.toStringz(actionName), (parameter is null) ? null : parameter.getVariantStruct());
201 	}
202 
203 	/**
204 	 * Request for the state of the named action within @action_group to be
205 	 * changed to @value.
206 	 *
207 	 * The action must be stateful and @value must be of the correct type.
208 	 * See g_action_group_get_action_state_type().
209 	 *
210 	 * This call merely requests a change.  The action may refuse to change
211 	 * its state or may change its state to something other than @value.
212 	 * See g_action_group_get_action_state_hint().
213 	 *
214 	 * If the @value GVariant is floating, it is consumed.
215 	 *
216 	 * Params:
217 	 *     actionName = the name of the action to request the change on
218 	 *     value = the new state
219 	 *
220 	 * Since: 2.28
221 	 */
222 	public void changeActionState(string actionName, Variant value)
223 	{
224 		g_action_group_change_action_state(getActionGroupStruct(), Str.toStringz(actionName), (value is null) ? null : value.getVariantStruct());
225 	}
226 
227 	/**
228 	 * Checks if the named action within @action_group is currently enabled.
229 	 *
230 	 * An action must be enabled in order to be activated or in order to
231 	 * have its state changed from outside callers.
232 	 *
233 	 * Params:
234 	 *     actionName = the name of the action to query
235 	 *
236 	 * Returns: whether or not the action is currently enabled
237 	 *
238 	 * Since: 2.28
239 	 */
240 	public bool getActionEnabled(string actionName)
241 	{
242 		return g_action_group_get_action_enabled(getActionGroupStruct(), Str.toStringz(actionName)) != 0;
243 	}
244 
245 	/**
246 	 * Queries the type of the parameter that must be given when activating
247 	 * the named action within @action_group.
248 	 *
249 	 * When activating the action using g_action_group_activate_action(),
250 	 * the #GVariant given to that function must be of the type returned
251 	 * by this function.
252 	 *
253 	 * In the case that this function returns %NULL, you must not give any
254 	 * #GVariant, but %NULL instead.
255 	 *
256 	 * The parameter type of a particular action will never change but it is
257 	 * possible for an action to be removed and for a new action to be added
258 	 * with the same name but a different parameter type.
259 	 *
260 	 * Params:
261 	 *     actionName = the name of the action to query
262 	 *
263 	 * Returns: the parameter type
264 	 *
265 	 * Since: 2.28
266 	 */
267 	public VariantType getActionParameterType(string actionName)
268 	{
269 		auto __p = g_action_group_get_action_parameter_type(getActionGroupStruct(), Str.toStringz(actionName));
270 
271 		if(__p is null)
272 		{
273 			return null;
274 		}
275 
276 		return new VariantType(cast(GVariantType*) __p);
277 	}
278 
279 	/**
280 	 * Queries the current state of the named action within @action_group.
281 	 *
282 	 * If the action is not stateful then %NULL will be returned.  If the
283 	 * action is stateful then the type of the return value is the type
284 	 * given by g_action_group_get_action_state_type().
285 	 *
286 	 * The return value (if non-%NULL) should be freed with
287 	 * g_variant_unref() when it is no longer required.
288 	 *
289 	 * Params:
290 	 *     actionName = the name of the action to query
291 	 *
292 	 * Returns: the current state of the action
293 	 *
294 	 * Since: 2.28
295 	 */
296 	public Variant getActionState(string actionName)
297 	{
298 		auto __p = g_action_group_get_action_state(getActionGroupStruct(), Str.toStringz(actionName));
299 
300 		if(__p is null)
301 		{
302 			return null;
303 		}
304 
305 		return new Variant(cast(GVariant*) __p, true);
306 	}
307 
308 	/**
309 	 * Requests a hint about the valid range of values for the state of the
310 	 * named action within @action_group.
311 	 *
312 	 * If %NULL is returned it either means that the action is not stateful
313 	 * or that there is no hint about the valid range of values for the
314 	 * state of the action.
315 	 *
316 	 * If a #GVariant array is returned then each item in the array is a
317 	 * possible value for the state.  If a #GVariant pair (ie: two-tuple) is
318 	 * returned then the tuple specifies the inclusive lower and upper bound
319 	 * of valid values for the state.
320 	 *
321 	 * In any case, the information is merely a hint.  It may be possible to
322 	 * have a state value outside of the hinted range and setting a value
323 	 * within the range may fail.
324 	 *
325 	 * The return value (if non-%NULL) should be freed with
326 	 * g_variant_unref() when it is no longer required.
327 	 *
328 	 * Params:
329 	 *     actionName = the name of the action to query
330 	 *
331 	 * Returns: the state range hint
332 	 *
333 	 * Since: 2.28
334 	 */
335 	public Variant getActionStateHint(string actionName)
336 	{
337 		auto __p = g_action_group_get_action_state_hint(getActionGroupStruct(), Str.toStringz(actionName));
338 
339 		if(__p is null)
340 		{
341 			return null;
342 		}
343 
344 		return new Variant(cast(GVariant*) __p, true);
345 	}
346 
347 	/**
348 	 * Queries the type of the state of the named action within
349 	 * @action_group.
350 	 *
351 	 * If the action is stateful then this function returns the
352 	 * #GVariantType of the state.  All calls to
353 	 * g_action_group_change_action_state() must give a #GVariant of this
354 	 * type and g_action_group_get_action_state() will return a #GVariant
355 	 * of the same type.
356 	 *
357 	 * If the action is not stateful then this function will return %NULL.
358 	 * In that case, g_action_group_get_action_state() will return %NULL
359 	 * and you must not call g_action_group_change_action_state().
360 	 *
361 	 * The state type of a particular action will never change but it is
362 	 * possible for an action to be removed and for a new action to be added
363 	 * with the same name but a different state type.
364 	 *
365 	 * Params:
366 	 *     actionName = the name of the action to query
367 	 *
368 	 * Returns: the state type, if the action is stateful
369 	 *
370 	 * Since: 2.28
371 	 */
372 	public VariantType getActionStateType(string actionName)
373 	{
374 		auto __p = g_action_group_get_action_state_type(getActionGroupStruct(), Str.toStringz(actionName));
375 
376 		if(__p is null)
377 		{
378 			return null;
379 		}
380 
381 		return new VariantType(cast(GVariantType*) __p);
382 	}
383 
384 	/**
385 	 * Checks if the named action exists within @action_group.
386 	 *
387 	 * Params:
388 	 *     actionName = the name of the action to check for
389 	 *
390 	 * Returns: whether the named action exists
391 	 *
392 	 * Since: 2.28
393 	 */
394 	public bool hasAction(string actionName)
395 	{
396 		return g_action_group_has_action(getActionGroupStruct(), Str.toStringz(actionName)) != 0;
397 	}
398 
399 	/**
400 	 * Lists the actions contained within @action_group.
401 	 *
402 	 * The caller is responsible for freeing the list with g_strfreev() when
403 	 * it is no longer required.
404 	 *
405 	 * Returns: a %NULL-terminated array of the names of the
406 	 *     actions in the group
407 	 *
408 	 * Since: 2.28
409 	 */
410 	public string[] listActions()
411 	{
412 		auto retStr = g_action_group_list_actions(getActionGroupStruct());
413 
414 		scope(exit) Str.freeStringArray(retStr);
415 		return Str.toStringArray(retStr);
416 	}
417 
418 	/**
419 	 * Queries all aspects of the named action within an @action_group.
420 	 *
421 	 * This function acquires the information available from
422 	 * g_action_group_has_action(), g_action_group_get_action_enabled(),
423 	 * g_action_group_get_action_parameter_type(),
424 	 * g_action_group_get_action_state_type(),
425 	 * g_action_group_get_action_state_hint() and
426 	 * g_action_group_get_action_state() with a single function call.
427 	 *
428 	 * This provides two main benefits.
429 	 *
430 	 * The first is the improvement in efficiency that comes with not having
431 	 * to perform repeated lookups of the action in order to discover
432 	 * different things about it.  The second is that implementing
433 	 * #GActionGroup can now be done by only overriding this one virtual
434 	 * function.
435 	 *
436 	 * The interface provides a default implementation of this function that
437 	 * calls the individual functions, as required, to fetch the
438 	 * information.  The interface also provides default implementations of
439 	 * those functions that call this function.  All implementations,
440 	 * therefore, must override either this function or all of the others.
441 	 *
442 	 * If the action exists, %TRUE is returned and any of the requested
443 	 * fields (as indicated by having a non-%NULL reference passed in) are
444 	 * filled.  If the action doesn't exist, %FALSE is returned and the
445 	 * fields may or may not have been modified.
446 	 *
447 	 * Params:
448 	 *     actionName = the name of an action in the group
449 	 *     enabled = if the action is presently enabled
450 	 *     parameterType = the parameter type, or %NULL if none needed
451 	 *     stateType = the state type, or %NULL if stateless
452 	 *     stateHint = the state hint, or %NULL if none
453 	 *     state = the current state, or %NULL if stateless
454 	 *
455 	 * Returns: %TRUE if the action exists, else %FALSE
456 	 *
457 	 * Since: 2.32
458 	 */
459 	public bool queryAction(string actionName, out bool enabled, out VariantType parameterType, out VariantType stateType, out Variant stateHint, out Variant state)
460 	{
461 		int outenabled;
462 		GVariantType* outparameterType = null;
463 		GVariantType* outstateType = null;
464 		GVariant* outstateHint = null;
465 		GVariant* outstate = null;
466 
467 		auto __p = g_action_group_query_action(getActionGroupStruct(), Str.toStringz(actionName), &outenabled, &outparameterType, &outstateType, &outstateHint, &outstate) != 0;
468 
469 		enabled = (outenabled == 1);
470 		parameterType = new VariantType(outparameterType);
471 		stateType = new VariantType(outstateType);
472 		stateHint = new Variant(outstateHint);
473 		state = new Variant(outstate);
474 
475 		return __p;
476 	}
477 
478 	/**
479 	 * Signals that a new action was just added to the group.
480 	 * This signal is emitted after the action has been added
481 	 * and is now visible.
482 	 *
483 	 * Params:
484 	 *     actionName = the name of the action in @action_group
485 	 *
486 	 * Since: 2.28
487 	 */
488 	gulong addOnActionAdded(void delegate(string, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
489 	{
490 		return Signals.connect(this, "action-added", dlg, connectFlags ^ ConnectFlags.SWAPPED);
491 	}
492 
493 	/**
494 	 * Signals that the enabled status of the named action has changed.
495 	 *
496 	 * Params:
497 	 *     actionName = the name of the action in @action_group
498 	 *     enabled = whether the action is enabled or not
499 	 *
500 	 * Since: 2.28
501 	 */
502 	gulong addOnActionEnabledChanged(void delegate(string, bool, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
503 	{
504 		return Signals.connect(this, "action-enabled-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
505 	}
506 
507 	/**
508 	 * Signals that an action is just about to be removed from the group.
509 	 * This signal is emitted before the action is removed, so the action
510 	 * is still visible and can be queried from the signal handler.
511 	 *
512 	 * Params:
513 	 *     actionName = the name of the action in @action_group
514 	 *
515 	 * Since: 2.28
516 	 */
517 	gulong addOnActionRemoved(void delegate(string, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
518 	{
519 		return Signals.connect(this, "action-removed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
520 	}
521 
522 	/**
523 	 * Signals that the state of the named action has changed.
524 	 *
525 	 * Params:
526 	 *     actionName = the name of the action in @action_group
527 	 *     value = the new value of the state
528 	 *
529 	 * Since: 2.28
530 	 */
531 	gulong addOnActionStateChanged(void delegate(string, Variant, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
532 	{
533 		return Signals.connect(this, "action-state-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
534 	}
535 }