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