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