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