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.ErrorG;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gtkc.glib;
30 public  import gtkc.glibtypes;
31 private import gtkd.Loader;
32 
33 
34 /**
35  * The `GError` structure contains information about
36  * an error that has occurred.
37  */
38 public class ErrorG
39 {
40 	/** the main Gtk struct */
41 	protected GError* gError;
42 	protected bool ownedRef;
43 
44 	/** Get the main Gtk struct */
45 	public GError* getErrorGStruct(bool transferOwnership = false)
46 	{
47 		if (transferOwnership)
48 			ownedRef = false;
49 		return gError;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected void* getStruct()
54 	{
55 		return cast(void*)gError;
56 	}
57 
58 	/**
59 	 * Sets our main struct and passes it to the parent class.
60 	 */
61 	public this (GError* gError, bool ownedRef = false)
62 	{
63 		this.gError = gError;
64 		this.ownedRef = ownedRef;
65 	}
66 
67 	~this ()
68 	{
69 		if (  Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
70 			g_error_free(gError);
71 	}
72 
73 
74 	/**
75 	 * Creates a new #GError; unlike g_error_new(), @message is
76 	 * not a printf()-style format string. Use this function if
77 	 * @message contains text you don't have control over,
78 	 * that could include printf() escape sequences.
79 	 *
80 	 * Params:
81 	 *     domain = error domain
82 	 *     code = error code
83 	 *     message = error message
84 	 *
85 	 * Returns: a new #GError
86 	 *
87 	 * Throws: ConstructionException GTK+ fails to create the object.
88 	 */
89 	public this(GQuark domain, int code, string message)
90 	{
91 		auto p = g_error_new_literal(domain, code, Str.toStringz(message));
92 		
93 		if(p is null)
94 		{
95 			throw new ConstructionException("null returned by new_literal");
96 		}
97 		
98 		this(cast(GError*) p);
99 	}
100 
101 	/**
102 	 * Creates a new #GError with the given @domain and @code,
103 	 * and a message formatted with @format.
104 	 *
105 	 * Params:
106 	 *     domain = error domain
107 	 *     code = error code
108 	 *     format = printf()-style format for error message
109 	 *     args = #va_list of parameters for the message format
110 	 *
111 	 * Returns: a new #GError
112 	 *
113 	 * Since: 2.22
114 	 *
115 	 * Throws: ConstructionException GTK+ fails to create the object.
116 	 */
117 	public this(GQuark domain, int code, string format, void* args)
118 	{
119 		auto p = g_error_new_valist(domain, code, Str.toStringz(format), args);
120 		
121 		if(p is null)
122 		{
123 			throw new ConstructionException("null returned by new_valist");
124 		}
125 		
126 		this(cast(GError*) p);
127 	}
128 
129 	/**
130 	 * Makes a copy of @error.
131 	 *
132 	 * Returns: a new #GError
133 	 */
134 	public ErrorG copy()
135 	{
136 		auto p = g_error_copy(gError);
137 		
138 		if(p is null)
139 		{
140 			return null;
141 		}
142 		
143 		return new ErrorG(cast(GError*) p, true);
144 	}
145 
146 	/**
147 	 * Frees a #GError and associated resources.
148 	 */
149 	public void free()
150 	{
151 		g_error_free(gError);
152 		ownedRef = false;
153 	}
154 
155 	/**
156 	 * Returns %TRUE if @error matches @domain and @code, %FALSE
157 	 * otherwise. In particular, when @error is %NULL, %FALSE will
158 	 * be returned.
159 	 *
160 	 * If @domain contains a `FAILED` (or otherwise generic) error code,
161 	 * you should generally not check for it explicitly, but should
162 	 * instead treat any not-explicitly-recognized error code as being
163 	 * equivalent to the `FAILED` code. This way, if the domain is
164 	 * extended in the future to provide a more specific error code for
165 	 * a certain case, your code will still work.
166 	 *
167 	 * Params:
168 	 *     domain = an error domain
169 	 *     code = an error code
170 	 *
171 	 * Returns: whether @error has @domain and @code
172 	 */
173 	public bool matches(GQuark domain, int code)
174 	{
175 		return g_error_matches(gError, domain, code) != 0;
176 	}
177 
178 	/**
179 	 * If @dest is %NULL, free @src; otherwise, moves @src into *@dest.
180 	 * The error variable @dest points to must be %NULL.
181 	 *
182 	 * @src must be non-%NULL.
183 	 *
184 	 * Note that @src is no longer valid after this call. If you want
185 	 * to keep using the same GError*, you need to set it to %NULL
186 	 * after calling this function on it.
187 	 *
188 	 * Params:
189 	 *     dest = error return location
190 	 *     src = error to move into the return location
191 	 */
192 	public static void propagateError(out ErrorG dest, ErrorG src)
193 	{
194 		GError* outdest = null;
195 		
196 		g_propagate_error(&outdest, (src is null) ? null : src.getErrorGStruct(true));
197 		
198 		dest = new ErrorG(outdest);
199 	}
200 
201 	/**
202 	 * Does nothing if @err is %NULL; if @err is non-%NULL, then *@err
203 	 * must be %NULL. A new #GError is created and assigned to *@err.
204 	 * Unlike g_set_error(), @message is not a printf()-style format string.
205 	 * Use this function if @message contains text you don't have control over,
206 	 * that could include printf() escape sequences.
207 	 *
208 	 * Params:
209 	 *     err = a return location for a #GError
210 	 *     domain = error domain
211 	 *     code = error code
212 	 *     message = error message
213 	 *
214 	 * Since: 2.18
215 	 */
216 	public static void setErrorLiteral(out ErrorG err, GQuark domain, int code, string message)
217 	{
218 		GError* outerr = null;
219 		
220 		g_set_error_literal(&outerr, domain, code, Str.toStringz(message));
221 		
222 		err = new ErrorG(outerr);
223 	}
224 }