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 gtkc.glib;
30 public  import gtkc.glibtypes;
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);
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 	/**
142 	 * Increments the reference count of @group by one.
143 	 *
144 	 * Returns: a #GoptionGroup
145 	 *
146 	 * Since: 2.44
147 	 */
148 	public OptionGroup doref()
149 	{
150 		auto p = g_option_group_ref(gOptionGroup);
151 		
152 		if(p is null)
153 		{
154 			return null;
155 		}
156 		
157 		return new OptionGroup(cast(GOptionGroup*) p, true);
158 	}
159 
160 	/**
161 	 * Associates a function with @group which will be called
162 	 * from g_option_context_parse() when an error occurs.
163 	 *
164 	 * Note that the user data to be passed to @error_func can be
165 	 * specified when constructing the group with g_option_group_new().
166 	 *
167 	 * Params:
168 	 *     errorFunc = a function to call when an error occurs
169 	 *
170 	 * Since: 2.6
171 	 */
172 	public void setErrorHook(GOptionErrorFunc errorFunc)
173 	{
174 		g_option_group_set_error_hook(gOptionGroup, errorFunc);
175 	}
176 
177 	/**
178 	 * Associates two functions with @group which will be called
179 	 * from g_option_context_parse() before the first option is parsed
180 	 * and after the last option has been parsed, respectively.
181 	 *
182 	 * Note that the user data to be passed to @pre_parse_func and
183 	 * @post_parse_func can be specified when constructing the group
184 	 * with g_option_group_new().
185 	 *
186 	 * Params:
187 	 *     preParseFunc = a function to call before parsing, or %NULL
188 	 *     postParseFunc = a function to call after parsing, or %NULL
189 	 *
190 	 * Since: 2.6
191 	 */
192 	public void setParseHooks(GOptionParseFunc preParseFunc, GOptionParseFunc postParseFunc)
193 	{
194 		g_option_group_set_parse_hooks(gOptionGroup, preParseFunc, postParseFunc);
195 	}
196 
197 	/**
198 	 * Sets the function which is used to translate user-visible strings,
199 	 * for `--help` output. Different groups can use different
200 	 * #GTranslateFuncs. If @func is %NULL, strings are not translated.
201 	 *
202 	 * If you are using gettext(), you only need to set the translation
203 	 * domain, see g_option_group_set_translation_domain().
204 	 *
205 	 * Params:
206 	 *     func = the #GTranslateFunc, or %NULL
207 	 *     data = user data to pass to @func, or %NULL
208 	 *     destroyNotify = a function which gets called to free @data, or %NULL
209 	 *
210 	 * Since: 2.6
211 	 */
212 	public void setTranslateFunc(GTranslateFunc func, void* data, GDestroyNotify destroyNotify)
213 	{
214 		g_option_group_set_translate_func(gOptionGroup, func, data, destroyNotify);
215 	}
216 
217 	/**
218 	 * A convenience function to use gettext() for translating
219 	 * user-visible strings.
220 	 *
221 	 * Params:
222 	 *     domain = the domain to use
223 	 *
224 	 * Since: 2.6
225 	 */
226 	public void setTranslationDomain(string domain)
227 	{
228 		g_option_group_set_translation_domain(gOptionGroup, Str.toStringz(domain));
229 	}
230 
231 	/**
232 	 * Decrements the reference count of @group by one.
233 	 * If the reference count drops to 0, the @group will be freed.
234 	 * and all memory allocated by the @group is released.
235 	 *
236 	 * Since: 2.44
237 	 */
238 	public void unref()
239 	{
240 		g_option_group_unref(gOptionGroup);
241 	}
242 }