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