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