source: appstream-generator/build/girepo/gio/ActionGroupT.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 20.9 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.ActionGroupT;
22
23public  import gi.gio;
24public  import gi.giotypes;
25public  import glib.Str;
26public  import glib.Variant;
27public  import glib.VariantType;
28public  import gobject.Signals;
29public  import std.algorithm;
30
31
32/**
33 * #GActionGroup represents a group of actions. Actions can be used to
34 * expose functionality in a structured way, either from one part of a
35 * program to another, or to the outside world. Action groups are often
36 * used together with a #GMenuModel that provides additional
37 * representation data for displaying the actions to the user, e.g. in
38 * a menu.
39 *
40 * The main way to interact with the actions in a GActionGroup is to
41 * activate them with g_action_group_activate_action(). Activating an
42 * action may require a #GVariant parameter. The required type of the
43 * parameter can be inquired with g_action_group_get_action_parameter_type().
44 * Actions may be disabled, see g_action_group_get_action_enabled().
45 * Activating a disabled action has no effect.
46 *
47 * Actions may optionally have a state in the form of a #GVariant. The
48 * current state of an action can be inquired with
49 * g_action_group_get_action_state(). Activating a stateful action may
50 * change its state, but it is also possible to set the state by calling
51 * g_action_group_change_action_state().
52 *
53 * As typical example, consider a text editing application which has an
54 * option to change the current font to 'bold'. A good way to represent
55 * this would be a stateful action, with a boolean state. Activating the
56 * action would toggle the state.
57 *
58 * Each action in the group has a unique name (which is a string).  All
59 * method calls, except g_action_group_list_actions() take the name of
60 * an action as an argument.
61 *
62 * The #GActionGroup API is meant to be the 'public' API to the action
63 * group.  The calls here are exactly the interaction that 'external
64 * forces' (eg: UI, incoming D-Bus messages, etc.) are supposed to have
65 * with actions.  'Internal' APIs (ie: ones meant only to be accessed by
66 * the action group implementation) are found on subclasses.  This is
67 * why you will find - for example - g_action_group_get_action_enabled()
68 * but not an equivalent set() call.
69 *
70 * Signals are emitted on the action group in response to state changes
71 * on individual actions.
72 *
73 * Implementations of #GActionGroup should provide implementations for
74 * the virtual functions g_action_group_list_actions() and
75 * g_action_group_query_action().  The other virtual functions should
76 * not be implemented - their "wrappers" are actually implemented with
77 * calls to g_action_group_query_action().
78 */
79public template ActionGroupT(TStruct)
80{
81        /** Get the main Gtk struct */
82        public GActionGroup* getActionGroupStruct()
83        {
84                return cast(GActionGroup*)getStruct();
85        }
86
87
88        /**
89         * Emits the #GActionGroup::action-added signal on @action_group.
90         *
91         * This function should only be called by #GActionGroup implementations.
92         *
93         * Params:
94         *     actionName = the name of an action in the group
95         *
96         * Since: 2.28
97         */
98        public void actionAdded(string actionName)
99        {
100                g_action_group_action_added(getActionGroupStruct(), Str.toStringz(actionName));
101        }
102
103        /**
104         * Emits the #GActionGroup::action-enabled-changed signal on @action_group.
105         *
106         * This function should only be called by #GActionGroup implementations.
107         *
108         * Params:
109         *     actionName = the name of an action in the group
110         *     enabled = whether or not the action is now enabled
111         *
112         * Since: 2.28
113         */
114        public void actionEnabledChanged(string actionName, bool enabled)
115        {
116                g_action_group_action_enabled_changed(getActionGroupStruct(), Str.toStringz(actionName), enabled);
117        }
118
119        /**
120         * Emits the #GActionGroup::action-removed signal on @action_group.
121         *
122         * This function should only be called by #GActionGroup implementations.
123         *
124         * Params:
125         *     actionName = the name of an action in the group
126         *
127         * Since: 2.28
128         */
129        public void actionRemoved(string actionName)
130        {
131                g_action_group_action_removed(getActionGroupStruct(), Str.toStringz(actionName));
132        }
133
134        /**
135         * Emits the #GActionGroup::action-state-changed signal on @action_group.
136         *
137         * This function should only be called by #GActionGroup implementations.
138         *
139         * Params:
140         *     actionName = the name of an action in the group
141         *     state = the new state of the named action
142         *
143         * Since: 2.28
144         */
145        public void actionStateChanged(string actionName, Variant state)
146        {
147                g_action_group_action_state_changed(getActionGroupStruct(), Str.toStringz(actionName), (state is null) ? null : state.getVariantStruct());
148        }
149
150        /**
151         * Activate the named action within @action_group.
152         *
153         * If the action is expecting a parameter, then the correct type of
154         * parameter must be given as @parameter.  If the action is expecting no
155         * parameters then @parameter must be %NULL.  See
156         * g_action_group_get_action_parameter_type().
157         *
158         * Params:
159         *     actionName = the name of the action to activate
160         *     parameter = parameters to the activation
161         *
162         * Since: 2.28
163         */
164        public void activateAction(string actionName, Variant parameter)
165        {
166                g_action_group_activate_action(getActionGroupStruct(), Str.toStringz(actionName), (parameter is null) ? null : parameter.getVariantStruct());
167        }
168
169        /**
170         * Request for the state of the named action within @action_group to be
171         * changed to @value.
172         *
173         * The action must be stateful and @value must be of the correct type.
174         * See g_action_group_get_action_state_type().
175         *
176         * This call merely requests a change.  The action may refuse to change
177         * its state or may change its state to something other than @value.
178         * See g_action_group_get_action_state_hint().
179         *
180         * If the @value GVariant is floating, it is consumed.
181         *
182         * Params:
183         *     actionName = the name of the action to request the change on
184         *     value = the new state
185         *
186         * Since: 2.28
187         */
188        public void changeActionState(string actionName, Variant value)
189        {
190                g_action_group_change_action_state(getActionGroupStruct(), Str.toStringz(actionName), (value is null) ? null : value.getVariantStruct());
191        }
192
193        /**
194         * Checks if the named action within @action_group is currently enabled.
195         *
196         * An action must be enabled in order to be activated or in order to
197         * have its state changed from outside callers.
198         *
199         * Params:
200         *     actionName = the name of the action to query
201         *
202         * Returns: whether or not the action is currently enabled
203         *
204         * Since: 2.28
205         */
206        public bool getActionEnabled(string actionName)
207        {
208                return g_action_group_get_action_enabled(getActionGroupStruct(), Str.toStringz(actionName)) != 0;
209        }
210
211        /**
212         * Queries the type of the parameter that must be given when activating
213         * the named action within @action_group.
214         *
215         * When activating the action using g_action_group_activate_action(),
216         * the #GVariant given to that function must be of the type returned
217         * by this function.
218         *
219         * In the case that this function returns %NULL, you must not give any
220         * #GVariant, but %NULL instead.
221         *
222         * The parameter type of a particular action will never change but it is
223         * possible for an action to be removed and for a new action to be added
224         * with the same name but a different parameter type.
225         *
226         * Params:
227         *     actionName = the name of the action to query
228         *
229         * Returns: the parameter type
230         *
231         * Since: 2.28
232         */
233        public VariantType getActionParameterType(string actionName)
234        {
235                auto p = g_action_group_get_action_parameter_type(getActionGroupStruct(), Str.toStringz(actionName));
236               
237                if(p is null)
238                {
239                        return null;
240                }
241               
242                return new VariantType(cast(GVariantType*) p);
243        }
244
245        /**
246         * Queries the current state of the named action within @action_group.
247         *
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_group_get_action_state_type().
251         *
252         * The return value (if non-%NULL) should be freed with
253         * g_variant_unref() when it is no longer required.
254         *
255         * Params:
256         *     actionName = the name of the action to query
257         *
258         * Returns: the current state of the action
259         *
260         * Since: 2.28
261         */
262        public Variant getActionState(string actionName)
263        {
264                auto p = g_action_group_get_action_state(getActionGroupStruct(), Str.toStringz(actionName));
265               
266                if(p is null)
267                {
268                        return null;
269                }
270               
271                return new Variant(cast(GVariant*) p, true);
272        }
273
274        /**
275         * Requests a hint about the valid range of values for the state of the
276         * named action within @action_group.
277         *
278         * If %NULL is returned it either means that the action is not stateful
279         * or that there is no hint about the valid range of values for the
280         * state of the action.
281         *
282         * If a #GVariant array is returned then each item in the array is a
283         * possible value for the state.  If a #GVariant pair (ie: two-tuple) is
284         * returned then the tuple specifies the inclusive lower and upper bound
285         * of valid values for the state.
286         *
287         * In any case, the information is merely a hint.  It may be possible to
288         * have a state value outside of the hinted range and setting a value
289         * within the range may fail.
290         *
291         * The return value (if non-%NULL) should be freed with
292         * g_variant_unref() when it is no longer required.
293         *
294         * Params:
295         *     actionName = the name of the action to query
296         *
297         * Returns: the state range hint
298         *
299         * Since: 2.28
300         */
301        public Variant getActionStateHint(string actionName)
302        {
303                auto p = g_action_group_get_action_state_hint(getActionGroupStruct(), Str.toStringz(actionName));
304               
305                if(p is null)
306                {
307                        return null;
308                }
309               
310                return new Variant(cast(GVariant*) p, true);
311        }
312
313        /**
314         * Queries the type of the state of the named action within
315         * @action_group.
316         *
317         * If the action is stateful then this function returns the
318         * #GVariantType of the state.  All calls to
319         * g_action_group_change_action_state() must give a #GVariant of this
320         * type and g_action_group_get_action_state() will return a #GVariant
321         * of the same type.
322         *
323         * If the action is not stateful then this function will return %NULL.
324         * In that case, g_action_group_get_action_state() will return %NULL
325         * and you must not call g_action_group_change_action_state().
326         *
327         * The state type of a particular action will never change but it is
328         * possible for an action to be removed and for a new action to be added
329         * with the same name but a different state type.
330         *
331         * Params:
332         *     actionName = the name of the action to query
333         *
334         * Returns: the state type, if the action is stateful
335         *
336         * Since: 2.28
337         */
338        public VariantType getActionStateType(string actionName)
339        {
340                auto p = g_action_group_get_action_state_type(getActionGroupStruct(), Str.toStringz(actionName));
341               
342                if(p is null)
343                {
344                        return null;
345                }
346               
347                return new VariantType(cast(GVariantType*) p);
348        }
349
350        /**
351         * Checks if the named action exists within @action_group.
352         *
353         * Params:
354         *     actionName = the name of the action to check for
355         *
356         * Returns: whether the named action exists
357         *
358         * Since: 2.28
359         */
360        public bool hasAction(string actionName)
361        {
362                return g_action_group_has_action(getActionGroupStruct(), Str.toStringz(actionName)) != 0;
363        }
364
365        /**
366         * Lists the actions contained within @action_group.
367         *
368         * The caller is responsible for freeing the list with g_strfreev() when
369         * it is no longer required.
370         *
371         * Returns: a %NULL-terminated array of the names of the
372         *     actions in the groupb
373         *
374         * Since: 2.28
375         */
376        public string[] listActions()
377        {
378                auto retStr = g_action_group_list_actions(getActionGroupStruct());
379               
380                scope(exit) Str.freeStringArray(retStr);
381                return Str.toStringArray(retStr);
382        }
383
384        /**
385         * Queries all aspects of the named action within an @action_group.
386         *
387         * This function acquires the information available from
388         * g_action_group_has_action(), g_action_group_get_action_enabled(),
389         * g_action_group_get_action_parameter_type(),
390         * g_action_group_get_action_state_type(),
391         * g_action_group_get_action_state_hint() and
392         * g_action_group_get_action_state() with a single function call.
393         *
394         * This provides two main benefits.
395         *
396         * The first is the improvement in efficiency that comes with not having
397         * to perform repeated lookups of the action in order to discover
398         * different things about it.  The second is that implementing
399         * #GActionGroup can now be done by only overriding this one virtual
400         * function.
401         *
402         * The interface provides a default implementation of this function that
403         * calls the individual functions, as required, to fetch the
404         * information.  The interface also provides default implementations of
405         * those functions that call this function.  All implementations,
406         * therefore, must override either this function or all of the others.
407         *
408         * If the action exists, %TRUE is returned and any of the requested
409         * fields (as indicated by having a non-%NULL reference passed in) are
410         * filled.  If the action doesn't exist, %FALSE is returned and the
411         * fields may or may not have been modified.
412         *
413         * Params:
414         *     actionName = the name of an action in the group
415         *     enabled = if the action is presently enabled
416         *     parameterType = the parameter type, or %NULL if none needed
417         *     stateType = the state type, or %NULL if stateless
418         *     stateHint = the state hint, or %NULL if none
419         *     state = the current state, or %NULL if stateless
420         *
421         * Returns: %TRUE if the action exists, else %FALSE
422         *
423         * Since: 2.32
424         */
425        public bool queryAction(string actionName, out bool enabled, out VariantType parameterType, out VariantType stateType, out Variant stateHint, out Variant state)
426        {
427                int outenabled;
428                GVariantType* outparameterType = null;
429                GVariantType* outstateType = null;
430                GVariant* outstateHint = null;
431                GVariant* outstate = null;
432               
433                auto p = g_action_group_query_action(getActionGroupStruct(), Str.toStringz(actionName), &outenabled, &outparameterType, &outstateType, &outstateHint, &outstate) != 0;
434               
435                enabled = (outenabled == 1);
436                parameterType = new VariantType(outparameterType);
437                stateType = new VariantType(outstateType);
438                stateHint = new Variant(outstateHint);
439                state = new Variant(outstate);
440               
441                return p;
442        }
443
444        protected class OnActionAddedDelegateWrapper
445        {
446                static OnActionAddedDelegateWrapper[] listeners;
447                void delegate(string, ActionGroupIF) dlg;
448                gulong handlerId;
449               
450                this(void delegate(string, ActionGroupIF) dlg)
451                {
452                        this.dlg = dlg;
453                        this.listeners ~= this;
454                }
455               
456                void remove(OnActionAddedDelegateWrapper source)
457                {
458                        foreach(index, wrapper; listeners)
459                        {
460                                if (wrapper.handlerId == source.handlerId)
461                                {
462                                        listeners[index] = null;
463                                        listeners = std.algorithm.remove(listeners, index);
464                                        break;
465                                }
466                        }
467                }
468        }
469
470        /**
471         * Signals that a new action was just added to the group.
472         * This signal is emitted after the action has been added
473         * and is now visible.
474         *
475         * Params:
476         *     actionName = the name of the action in @action_group
477         *
478         * Since: 2.28
479         */
480        gulong addOnActionAdded(void delegate(string, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
481        {
482                auto wrapper = new OnActionAddedDelegateWrapper(dlg);
483                wrapper.handlerId = Signals.connectData(
484                        this,
485                        "action-added",
486                        cast(GCallback)&callBackActionAdded,
487                        cast(void*)wrapper,
488                        cast(GClosureNotify)&callBackActionAddedDestroy,
489                        connectFlags);
490                return wrapper.handlerId;
491        }
492       
493        extern(C) static void callBackActionAdded(GActionGroup* actiongroupStruct, char* actionName, OnActionAddedDelegateWrapper wrapper)
494        {
495                wrapper.dlg(Str.toString(actionName), wrapper.outer);
496        }
497       
498        extern(C) static void callBackActionAddedDestroy(OnActionAddedDelegateWrapper wrapper, GClosure* closure)
499        {
500                wrapper.remove(wrapper);
501        }
502
503        protected class OnActionEnabledChangedDelegateWrapper
504        {
505                static OnActionEnabledChangedDelegateWrapper[] listeners;
506                void delegate(string, bool, ActionGroupIF) dlg;
507                gulong handlerId;
508               
509                this(void delegate(string, bool, ActionGroupIF) dlg)
510                {
511                        this.dlg = dlg;
512                        this.listeners ~= this;
513                }
514               
515                void remove(OnActionEnabledChangedDelegateWrapper source)
516                {
517                        foreach(index, wrapper; listeners)
518                        {
519                                if (wrapper.handlerId == source.handlerId)
520                                {
521                                        listeners[index] = null;
522                                        listeners = std.algorithm.remove(listeners, index);
523                                        break;
524                                }
525                        }
526                }
527        }
528
529        /**
530         * Signals that the enabled status of the named action has changed.
531         *
532         * Params:
533         *     actionName = the name of the action in @action_group
534         *     enabled = whether the action is enabled or not
535         *
536         * Since: 2.28
537         */
538        gulong addOnActionEnabledChanged(void delegate(string, bool, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
539        {
540                auto wrapper = new OnActionEnabledChangedDelegateWrapper(dlg);
541                wrapper.handlerId = Signals.connectData(
542                        this,
543                        "action-enabled-changed",
544                        cast(GCallback)&callBackActionEnabledChanged,
545                        cast(void*)wrapper,
546                        cast(GClosureNotify)&callBackActionEnabledChangedDestroy,
547                        connectFlags);
548                return wrapper.handlerId;
549        }
550       
551        extern(C) static void callBackActionEnabledChanged(GActionGroup* actiongroupStruct, char* actionName, bool enabled, OnActionEnabledChangedDelegateWrapper wrapper)
552        {
553                wrapper.dlg(Str.toString(actionName), enabled, wrapper.outer);
554        }
555       
556        extern(C) static void callBackActionEnabledChangedDestroy(OnActionEnabledChangedDelegateWrapper wrapper, GClosure* closure)
557        {
558                wrapper.remove(wrapper);
559        }
560
561        protected class OnActionRemovedDelegateWrapper
562        {
563                static OnActionRemovedDelegateWrapper[] listeners;
564                void delegate(string, ActionGroupIF) dlg;
565                gulong handlerId;
566               
567                this(void delegate(string, ActionGroupIF) dlg)
568                {
569                        this.dlg = dlg;
570                        this.listeners ~= this;
571                }
572               
573                void remove(OnActionRemovedDelegateWrapper source)
574                {
575                        foreach(index, wrapper; listeners)
576                        {
577                                if (wrapper.handlerId == source.handlerId)
578                                {
579                                        listeners[index] = null;
580                                        listeners = std.algorithm.remove(listeners, index);
581                                        break;
582                                }
583                        }
584                }
585        }
586
587        /**
588         * Signals that an action is just about to be removed from the group.
589         * This signal is emitted before the action is removed, so the action
590         * is still visible and can be queried from the signal handler.
591         *
592         * Params:
593         *     actionName = the name of the action in @action_group
594         *
595         * Since: 2.28
596         */
597        gulong addOnActionRemoved(void delegate(string, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
598        {
599                auto wrapper = new OnActionRemovedDelegateWrapper(dlg);
600                wrapper.handlerId = Signals.connectData(
601                        this,
602                        "action-removed",
603                        cast(GCallback)&callBackActionRemoved,
604                        cast(void*)wrapper,
605                        cast(GClosureNotify)&callBackActionRemovedDestroy,
606                        connectFlags);
607                return wrapper.handlerId;
608        }
609       
610        extern(C) static void callBackActionRemoved(GActionGroup* actiongroupStruct, char* actionName, OnActionRemovedDelegateWrapper wrapper)
611        {
612                wrapper.dlg(Str.toString(actionName), wrapper.outer);
613        }
614       
615        extern(C) static void callBackActionRemovedDestroy(OnActionRemovedDelegateWrapper wrapper, GClosure* closure)
616        {
617                wrapper.remove(wrapper);
618        }
619
620        protected class OnActionStateChangedDelegateWrapper
621        {
622                static OnActionStateChangedDelegateWrapper[] listeners;
623                void delegate(string, Variant, ActionGroupIF) dlg;
624                gulong handlerId;
625               
626                this(void delegate(string, Variant, ActionGroupIF) dlg)
627                {
628                        this.dlg = dlg;
629                        this.listeners ~= this;
630                }
631               
632                void remove(OnActionStateChangedDelegateWrapper source)
633                {
634                        foreach(index, wrapper; listeners)
635                        {
636                                if (wrapper.handlerId == source.handlerId)
637                                {
638                                        listeners[index] = null;
639                                        listeners = std.algorithm.remove(listeners, index);
640                                        break;
641                                }
642                        }
643                }
644        }
645
646        /**
647         * Signals that the state of the named action has changed.
648         *
649         * Params:
650         *     actionName = the name of the action in @action_group
651         *     value = the new value of the state
652         *
653         * Since: 2.28
654         */
655        gulong addOnActionStateChanged(void delegate(string, Variant, ActionGroupIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
656        {
657                auto wrapper = new OnActionStateChangedDelegateWrapper(dlg);
658                wrapper.handlerId = Signals.connectData(
659                        this,
660                        "action-state-changed",
661                        cast(GCallback)&callBackActionStateChanged,
662                        cast(void*)wrapper,
663                        cast(GClosureNotify)&callBackActionStateChangedDestroy,
664                        connectFlags);
665                return wrapper.handlerId;
666        }
667       
668        extern(C) static void callBackActionStateChanged(GActionGroup* actiongroupStruct, char* actionName, GVariant* value, OnActionStateChangedDelegateWrapper wrapper)
669        {
670                wrapper.dlg(Str.toString(actionName), new Variant(value), wrapper.outer);
671        }
672       
673        extern(C) static void callBackActionStateChangedDestroy(OnActionStateChangedDelegateWrapper wrapper, GClosure* closure)
674        {
675                wrapper.remove(wrapper);
676        }
677}
Note: See TracBrowser for help on using the repository browser.