source: appstream-generator/build/girepo/glib/OptionGroup.d @ 4841

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

Initial release

File size: 6.5 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 glib.OptionGroup;
22
23private import gi.glib;
24public  import gi.glibtypes;
25private import glib.ConstructionException;
26private import glib.Str;
27
28
29/**
30 * A `GOptionGroup` struct defines the options in a single
31 * group. The struct has only private fields and should not be directly accessed.
32 *
33 * All options in a group share the same translation function. Libraries which
34 * need to parse commandline options are expected to provide a function for
35 * getting a `GOptionGroup` holding their options, which
36 * the application can then add to its #GOptionContext.
37 */
38public class OptionGroup
39{
40        /** the main Gtk struct */
41        protected GOptionGroup* gOptionGroup;
42        protected bool ownedRef;
43
44        /** Get the main Gtk struct */
45        public GOptionGroup* getOptionGroupStruct()
46        {
47                return gOptionGroup;
48        }
49
50        /** the main Gtk struct as a void* */
51        protected void* getStruct()
52        {
53                return cast(void*)gOptionGroup;
54        }
55
56        /**
57         * Sets our main struct and passes it to the parent class.
58         */
59        public this (GOptionGroup* gOptionGroup, bool ownedRef = false)
60        {
61                this.gOptionGroup = gOptionGroup;
62                this.ownedRef = ownedRef;
63        }
64
65
66        /**
67         * Creates a new #GOptionGroup.
68         *
69         * Params:
70         *     name = the name for the option group, this is used to provide
71         *         help for the options in this group with `--help-`@name
72         *     description = a description for this group to be shown in
73         *         `--help`. This string is translated using the translation
74         *         domain or translation function of the group
75         *     helpDescription = a description for the `--help-`@name option.
76         *         This string is translated using the translation domain or translation function
77         *         of the group
78         *     userData = user data that will be passed to the pre- and post-parse hooks,
79         *         the error hook and to callbacks of %G_OPTION_ARG_CALLBACK options, or %NULL
80         *     destroy = a function that will be called to free @user_data, or %NULL
81         *
82         * Returns: a newly created option group. It should be added
83         *     to a #GOptionContext or freed with g_option_group_unref().
84         *
85         * Since: 2.6
86         *
87         * Throws: ConstructionException GTK+ fails to create the object.
88         */
89        public this(string name, string description, string helpDescription, void* userData, GDestroyNotify destroy)
90        {
91                auto p = g_option_group_new(Str.toStringz(name), Str.toStringz(description), Str.toStringz(helpDescription), userData, destroy);
92               
93                if(p is null)
94                {
95                        throw new ConstructionException("null returned by new");
96                }
97               
98                this(cast(GOptionGroup*) p);
99        }
100
101        /**
102         * Adds the options specified in @entries to @group.
103         *
104         * Params:
105         *     entries = a %NULL-terminated array of #GOptionEntrys
106         *
107         * Since: 2.6
108         */
109        public void addEntries(GOptionEntry* entries)
110        {
111                g_option_group_add_entries(gOptionGroup, entries);
112        }
113
114        /**
115         * Frees a #GOptionGroup. Note that you must not free groups
116         * which have been added to a #GOptionContext.
117         *
118         * Deprecated: Use g_option_group_unref() instead.
119         *
120         * Since: 2.6
121         */
122        public void free()
123        {
124                g_option_group_free(gOptionGroup);
125        }
126
127        /**
128         * Increments the reference count of @group by one.
129         *
130         * Returns: a #GoptionGroup
131         *
132         * Since: 2.44
133         */
134        public OptionGroup doref()
135        {
136                auto p = g_option_group_ref(gOptionGroup);
137               
138                if(p is null)
139                {
140                        return null;
141                }
142               
143                return new OptionGroup(cast(GOptionGroup*) p, true);
144        }
145
146        /**
147         * Associates a function with @group which will be called
148         * from g_option_context_parse() when an error occurs.
149         *
150         * Note that the user data to be passed to @error_func can be
151         * specified when constructing the group with g_option_group_new().
152         *
153         * Params:
154         *     errorFunc = a function to call when an error occurs
155         *
156         * Since: 2.6
157         */
158        public void setErrorHook(GOptionErrorFunc errorFunc)
159        {
160                g_option_group_set_error_hook(gOptionGroup, errorFunc);
161        }
162
163        /**
164         * Associates two functions with @group which will be called
165         * from g_option_context_parse() before the first option is parsed
166         * and after the last option has been parsed, respectively.
167         *
168         * Note that the user data to be passed to @pre_parse_func and
169         * @post_parse_func can be specified when constructing the group
170         * with g_option_group_new().
171         *
172         * Params:
173         *     preParseFunc = a function to call before parsing, or %NULL
174         *     postParseFunc = a function to call after parsing, or %NULL
175         *
176         * Since: 2.6
177         */
178        public void setParseHooks(GOptionParseFunc preParseFunc, GOptionParseFunc postParseFunc)
179        {
180                g_option_group_set_parse_hooks(gOptionGroup, preParseFunc, postParseFunc);
181        }
182
183        /**
184         * Sets the function which is used to translate user-visible strings,
185         * for `--help` output. Different groups can use different
186         * #GTranslateFuncs. If @func is %NULL, strings are not translated.
187         *
188         * If you are using gettext(), you only need to set the translation
189         * domain, see g_option_group_set_translation_domain().
190         *
191         * Params:
192         *     func = the #GTranslateFunc, or %NULL
193         *     data = user data to pass to @func, or %NULL
194         *     destroyNotify = a function which gets called to free @data, or %NULL
195         *
196         * Since: 2.6
197         */
198        public void setTranslateFunc(GTranslateFunc func, void* data, GDestroyNotify destroyNotify)
199        {
200                g_option_group_set_translate_func(gOptionGroup, func, data, destroyNotify);
201        }
202
203        /**
204         * A convenience function to use gettext() for translating
205         * user-visible strings.
206         *
207         * Params:
208         *     domain = the domain to use
209         *
210         * Since: 2.6
211         */
212        public void setTranslationDomain(string domain)
213        {
214                g_option_group_set_translation_domain(gOptionGroup, Str.toStringz(domain));
215        }
216
217        /**
218         * Decrements the reference count of @group by one.
219         * If the reference count drops to 0, the @group will be freed.
220         * and all memory allocated by the @group is released.
221         *
222         * Since: 2.44
223         */
224        public void unref()
225        {
226                g_option_group_unref(gOptionGroup);
227        }
228}
Note: See TracBrowser for help on using the repository browser.