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