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  * Conversion parameters:
26  * inFile  = 
27  * outPack = glib
28  * outFile = OptionGroup
29  * strct   = GOptionGroup
30  * realStrct=
31  * ctorStrct=
32  * clss    = OptionGroup
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_option_group_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gtkc.Loader
48  * 	- gtkc.paths
49  * structWrap:
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module glib.OptionGroup;
56 
57 public  import gtkc.glibtypes;
58 
59 private import gtkc.glib;
60 private import glib.ConstructionException;
61 
62 
63 private import glib.Str;
64 private import gtkc.Loader;
65 private import gtkc.paths;
66 
67 
68 
69 
70 /**
71  * The GOption commandline parser is intended to be a simpler replacement
72  * for the popt library. It supports short and long commandline options,
73  * as shown in the following example:
74  *
75  * testtreemodel -r 1 --max-size 20 --rand --display=:1.0 -vb -- file1 file2
76  *
77  * The example demonstrates a number of features of the GOption
78  * commandline parser
79  *
80  *  Options can be single letters, prefixed by a single dash. Multiple
81  *  short options can be grouped behind a single dash.
82  *
83  *  Long options are prefixed by two consecutive dashes.
84  *
85  *  Options can have an extra argument, which can be a number, a string or
86  *  a filename. For long options, the extra argument can be appended with
87  *  an equals sign after the option name, which is useful if the extra
88  *  argument starts with a dash, which would otherwise cause it to be
89  *  interpreted as another option.
90  *
91  *  Non-option arguments are returned to the application as rest arguments.
92  *
93  *  An argument consisting solely of two dashes turns off further parsing,
94  *  any remaining arguments (even those starting with a dash) are returned
95  *  to the application as rest arguments.
96  *
97  * Another important feature of GOption is that it can automatically
98  * generate nicely formatted help output. Unless it is explicitly turned
99  * off with g_option_context_set_help_enabled(), GOption will recognize
100  * the --help, -?,
101  * --help-all and
102  * --help-groupname options
103  * (where groupname is the name of a
104  * GOptionGroup) and write a text similar to the one shown in the
105  * following example to stdout.
106  *
107  * $(DDOC_COMMENT example)
108  *
109  * GOption groups options in GOptionGroups, which makes it easy to
110  * incorporate options from multiple sources. The intended use for this is
111  * to let applications collect option groups from the libraries it uses,
112  * add them to their GOptionContext, and parse all options by a single call
113  * to g_option_context_parse(). See gtk_get_option_group() for an example.
114  *
115  * If an option is declared to be of type string or filename, GOption takes
116  * care of converting it to the right encoding; strings are returned in
117  * UTF-8, filenames are returned in the GLib filename encoding. Note that
118  * this only works if setlocale() has been called before
119  * g_option_context_parse().
120  *
121  * Here is a complete example of setting up GOption to parse the example
122  * commandline above and produce the example help output.
123  *
124  * $(DDOC_COMMENT example)
125  */
126 public class OptionGroup
127 {
128 	
129 	/** the main Gtk struct */
130 	protected GOptionGroup* gOptionGroup;
131 	
132 	
133 	public GOptionGroup* getOptionGroupStruct()
134 	{
135 		return gOptionGroup;
136 	}
137 	
138 	
139 	/** the main Gtk struct as a void* */
140 	protected void* getStruct()
141 	{
142 		return cast(void*)gOptionGroup;
143 	}
144 	
145 	/**
146 	 * Sets our main struct and passes it to the parent class
147 	 */
148 	public this (GOptionGroup* gOptionGroup)
149 	{
150 		this.gOptionGroup = gOptionGroup;
151 	}
152 	
153 	~this ()
154 	{
155 		if ( Linker.isLoaded(LIBRARY.GLIB) && gOptionGroup !is null )
156 		{
157 			g_option_group_free(gOptionGroup);
158 		}
159 	}
160 	
161 	/**
162 	 */
163 	
164 	/**
165 	 * Creates a new GOptionGroup.
166 	 * Since 2.6
167 	 * Params:
168 	 * name = the name for the option group, this is used to provide
169 	 * help for the options in this group with --help-name
170 	 * description = a description for this group to be shown in
171 	 * --help. This string is translated using the translation
172 	 * domain or translation function of the group
173 	 * helpDescription = a description for the --help-name option.
174 	 * This string is translated using the translation domain or translation function
175 	 * of the group
176 	 * userData = user data that will be passed to the pre- and post-parse hooks,
177 	 * the error hook and to callbacks of G_OPTION_ARG_CALLBACK options, or NULL. [allow-none]
178 	 * destroy = a function that will be called to free user_data, or NULL. [allow-none]
179 	 * Throws: ConstructionException GTK+ fails to create the object.
180 	 */
181 	public this (string name, string description, string helpDescription, void* userData, GDestroyNotify destroy)
182 	{
183 		// GOptionGroup * g_option_group_new (const gchar *name,  const gchar *description,  const gchar *help_description,  gpointer user_data,  GDestroyNotify destroy);
184 		auto p = g_option_group_new(Str.toStringz(name), Str.toStringz(description), Str.toStringz(helpDescription), userData, destroy);
185 		if(p is null)
186 		{
187 			throw new ConstructionException("null returned by g_option_group_new(Str.toStringz(name), Str.toStringz(description), Str.toStringz(helpDescription), userData, destroy)");
188 		}
189 		this(cast(GOptionGroup*) p);
190 	}
191 	
192 	/**
193 	 * Frees a GOptionGroup. Note that you must not
194 	 * free groups which have been added to a GOptionContext.
195 	 * Since 2.6
196 	 */
197 	public void free()
198 	{
199 		// void g_option_group_free (GOptionGroup *group);
200 		g_option_group_free(gOptionGroup);
201 	}
202 	
203 	/**
204 	 * Adds the options specified in entries to group.
205 	 * Since 2.6
206 	 * Params:
207 	 * entries = a NULL-terminated array of GOptionEntrys
208 	 */
209 	public void addEntries(GOptionEntry* entries)
210 	{
211 		// void g_option_group_add_entries (GOptionGroup *group,  const GOptionEntry *entries);
212 		g_option_group_add_entries(gOptionGroup, entries);
213 	}
214 	
215 	/**
216 	 * Associates two functions with group which will be called
217 	 * from g_option_context_parse() before the first option is parsed
218 	 * and after the last option has been parsed, respectively.
219 	 * Note that the user data to be passed to pre_parse_func and
220 	 * post_parse_func can be specified when constructing the group
221 	 * with g_option_group_new().
222 	 * Since 2.6
223 	 * Params:
224 	 * preParseFunc = a function to call before parsing, or NULL. [allow-none]
225 	 * postParseFunc = a function to call after parsing, or NULL. [allow-none]
226 	 */
227 	public void setParseHooks(GOptionParseFunc preParseFunc, GOptionParseFunc postParseFunc)
228 	{
229 		// void g_option_group_set_parse_hooks (GOptionGroup *group,  GOptionParseFunc pre_parse_func,  GOptionParseFunc post_parse_func);
230 		g_option_group_set_parse_hooks(gOptionGroup, preParseFunc, postParseFunc);
231 	}
232 	
233 	/**
234 	 * Associates a function with group which will be called
235 	 * from g_option_context_parse() when an error occurs.
236 	 * Note that the user data to be passed to error_func can be
237 	 * specified when constructing the group with g_option_group_new().
238 	 * Since 2.6
239 	 * Params:
240 	 * errorFunc = a function to call when an error occurs
241 	 */
242 	public void setErrorHook(GOptionErrorFunc errorFunc)
243 	{
244 		// void g_option_group_set_error_hook (GOptionGroup *group,  GOptionErrorFunc error_func);
245 		g_option_group_set_error_hook(gOptionGroup, errorFunc);
246 	}
247 	
248 	/**
249 	 * Sets the function which is used to translate user-visible
250 	 * strings, for --help output. Different
251 	 * groups can use different GTranslateFuncs. If func
252 	 * is NULL, strings are not translated.
253 	 * If you are using gettext(), you only need to set the translation
254 	 * domain, see g_option_group_set_translation_domain().
255 	 * Since 2.6
256 	 * Params:
257 	 * func = the GTranslateFunc, or NULL. [allow-none]
258 	 * data = user data to pass to func, or NULL. [allow-none]
259 	 * destroyNotify = a function which gets called to free data, or NULL. [allow-none]
260 	 */
261 	public void setTranslateFunc(GTranslateFunc func, void* data, GDestroyNotify destroyNotify)
262 	{
263 		// void g_option_group_set_translate_func (GOptionGroup *group,  GTranslateFunc func,  gpointer data,  GDestroyNotify destroy_notify);
264 		g_option_group_set_translate_func(gOptionGroup, func, data, destroyNotify);
265 	}
266 	
267 	/**
268 	 * A convenience function to use gettext() for translating
269 	 * user-visible strings.
270 	 * Since 2.6
271 	 * Params:
272 	 * domain = the domain to use
273 	 */
274 	public void setTranslationDomain(string domain)
275 	{
276 		// void g_option_group_set_translation_domain  (GOptionGroup *group,  const gchar *domain);
277 		g_option_group_set_translation_domain(gOptionGroup, Str.toStringz(domain));
278 	}
279 }