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