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  * Conversion parameters:
26  * inFile  = GTlsInteraction.html
27  * outPack = gio
28  * outFile = TlsInteraction
29  * strct   = GTlsInteraction
30  * realStrct=
31  * ctorStrct=
32  * clss    = TlsInteraction
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_tls_interaction_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.ErrorG
47  * 	- glib.GException
48  * 	- gio.AsyncResultIF
49  * 	- gio.Cancellable
50  * 	- gio.TlsPassword
51  * structWrap:
52  * 	- GAsyncResult* -> AsyncResultIF
53  * 	- GCancellable* -> Cancellable
54  * 	- GTlsPassword* -> TlsPassword
55  * module aliases:
56  * local aliases:
57  * overrides:
58  */
59 
60 module gio.TlsInteraction;
61 
62 public  import gtkc.giotypes;
63 
64 private import gtkc.gio;
65 private import glib.ConstructionException;
66 private import gobject.ObjectG;
67 
68 
69 private import glib.ErrorG;
70 private import glib.GException;
71 private import gio.AsyncResultIF;
72 private import gio.Cancellable;
73 private import gio.TlsPassword;
74 
75 
76 
77 private import gobject.ObjectG;
78 
79 /**
80  * GTlsInteraction provides a mechanism for the TLS connection and database
81  * code to interact with the user. It can be used to ask the user for passwords.
82  *
83  * To use a GTlsInteraction with a TLS connection use
84  * g_tls_connection_set_interaction().
85  *
86  * Callers should instantiate a derived class that implements the various
87  * interaction methods to show the required dialogs.
88  *
89  * Callers should use the 'invoke' functions like
90  * g_tls_interaction_invoke_ask_password() to run interaction methods. These
91  * functions make sure that the interaction is invoked in the main loop
92  * and not in the current thread, if the current thread is not running the
93  * main loop.
94  *
95  * Derived classes can choose to implement whichever interactions methods they'd
96  * like to support by overriding those virtual methods in their class
97  * initialization function. Any interactions not implemented will return
98  * G_TLS_INTERACTION_UNHANDLED. If a derived class implements an async method,
99  * it must also implement the corresponding finish method.
100  */
101 public class TlsInteraction : ObjectG
102 {
103 	
104 	/** the main Gtk struct */
105 	protected GTlsInteraction* gTlsInteraction;
106 	
107 	
108 	public GTlsInteraction* getTlsInteractionStruct()
109 	{
110 		return gTlsInteraction;
111 	}
112 	
113 	
114 	/** the main Gtk struct as a void* */
115 	protected override void* getStruct()
116 	{
117 		return cast(void*)gTlsInteraction;
118 	}
119 	
120 	/**
121 	 * Sets our main struct and passes it to the parent class
122 	 */
123 	public this (GTlsInteraction* gTlsInteraction)
124 	{
125 		super(cast(GObject*)gTlsInteraction);
126 		this.gTlsInteraction = gTlsInteraction;
127 	}
128 	
129 	protected override void setStruct(GObject* obj)
130 	{
131 		super.setStruct(obj);
132 		gTlsInteraction = cast(GTlsInteraction*)obj;
133 	}
134 	
135 	/**
136 	 */
137 	
138 	/**
139 	 * Run synchronous interaction to ask the user for a password. In general,
140 	 * g_tls_interaction_invoke_ask_password() should be used instead of this
141 	 * function.
142 	 * Derived subclasses usually implement a password prompt, although they may
143 	 * also choose to provide a password from elsewhere. The password value will
144 	 * be filled in and then callback will be called. Alternatively the user may
145 	 * abort this password request, which will usually abort the TLS connection.
146 	 * If the interaction is cancelled by the cancellation object, or by the
147 	 * user then G_TLS_INTERACTION_FAILED will be returned with an error that
148 	 * contains a G_IO_ERROR_CANCELLED error code. Certain implementations may
149 	 * not support immediate cancellation.
150 	 * Since 2.30
151 	 * Params:
152 	 * password = a GTlsPassword object
153 	 * cancellable = an optional GCancellable cancellation object
154 	 * Returns: The status of the ask password interaction.
155 	 * Throws: GException on failure.
156 	 */
157 	public GTlsInteractionResult askPassword(TlsPassword password, Cancellable cancellable)
158 	{
159 		// GTlsInteractionResult g_tls_interaction_ask_password (GTlsInteraction *interaction,  GTlsPassword *password,  GCancellable *cancellable,  GError **error);
160 		GError* err = null;
161 		
162 		auto p = g_tls_interaction_ask_password(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
163 		
164 		if (err !is null)
165 		{
166 			throw new GException( new ErrorG(err) );
167 		}
168 		
169 		return p;
170 	}
171 	
172 	/**
173 	 * Run asynchronous interaction to ask the user for a password. In general,
174 	 * g_tls_interaction_invoke_ask_password() should be used instead of this
175 	 * function.
176 	 * Derived subclasses usually implement a password prompt, although they may
177 	 * also choose to provide a password from elsewhere. The password value will
178 	 * be filled in and then callback will be called. Alternatively the user may
179 	 * abort this password request, which will usually abort the TLS connection.
180 	 * If the interaction is cancelled by the cancellation object, or by the
181 	 * user then G_TLS_INTERACTION_FAILED will be returned with an error that
182 	 * contains a G_IO_ERROR_CANCELLED error code. Certain implementations may
183 	 * not support immediate cancellation.
184 	 * Certain implementations may not support immediate cancellation.
185 	 * Since 2.30
186 	 * Params:
187 	 * password = a GTlsPassword object
188 	 * cancellable = an optional GCancellable cancellation object
189 	 * callback = will be called when the interaction completes. [allow-none]
190 	 * userData = data to pass to the callback. [allow-none]
191 	 */
192 	public void askPasswordAsync(TlsPassword password, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
193 	{
194 		// void g_tls_interaction_ask_password_async  (GTlsInteraction *interaction,  GTlsPassword *password,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
195 		g_tls_interaction_ask_password_async(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
196 	}
197 	
198 	/**
199 	 * Complete an ask password user interaction request. This should be once
200 	 * the g_tls_interaction_ask_password_async() completion callback is called.
201 	 * If G_TLS_INTERACTION_HANDLED is returned, then the GTlsPassword passed
202 	 * to g_tls_interaction_ask_password() will have its password filled in.
203 	 * If the interaction is cancelled by the cancellation object, or by the
204 	 * user then G_TLS_INTERACTION_FAILED will be returned with an error that
205 	 * contains a G_IO_ERROR_CANCELLED error code.
206 	 * Since 2.30
207 	 * Params:
208 	 * result = the result passed to the callback
209 	 * Returns: The status of the ask password interaction.
210 	 * Throws: GException on failure.
211 	 */
212 	public GTlsInteractionResult askPasswordFinish(AsyncResultIF result)
213 	{
214 		// GTlsInteractionResult g_tls_interaction_ask_password_finish  (GTlsInteraction *interaction,  GAsyncResult *result,  GError **error);
215 		GError* err = null;
216 		
217 		auto p = g_tls_interaction_ask_password_finish(gTlsInteraction, (result is null) ? null : result.getAsyncResultTStruct(), &err);
218 		
219 		if (err !is null)
220 		{
221 			throw new GException( new ErrorG(err) );
222 		}
223 		
224 		return p;
225 	}
226 	
227 	/**
228 	 * Invoke the interaction to ask the user for a password. It invokes this
229 	 * interaction in the main loop, specifically the GMainContext returned by
230 	 * g_main_context_get_thread_default() when the interaction is created. This
231 	 * is called by called by GTlsConnection or GTlsDatabase to ask the user
232 	 * for a password.
233 	 * Derived subclasses usually implement a password prompt, although they may
234 	 * also choose to provide a password from elsewhere. The password value will
235 	 * be filled in and then callback will be called. Alternatively the user may
236 	 * abort this password request, which will usually abort the TLS connection.
237 	 * The implementation can either be a synchronous (eg: modal dialog) or an
238 	 * asynchronous one (eg: modeless dialog). This function will take care of
239 	 * calling which ever one correctly.
240 	 * If the interaction is cancelled by the cancellation object, or by the
241 	 * user then G_TLS_INTERACTION_FAILED will be returned with an error that
242 	 * contains a G_IO_ERROR_CANCELLED error code. Certain implementations may
243 	 * not support immediate cancellation.
244 	 * Since 2.30
245 	 * Params:
246 	 * password = a GTlsPassword object
247 	 * cancellable = an optional GCancellable cancellation object
248 	 * Returns: The status of the ask password interaction.
249 	 * Throws: GException on failure.
250 	 */
251 	public GTlsInteractionResult invokeAskPassword(TlsPassword password, Cancellable cancellable)
252 	{
253 		// GTlsInteractionResult g_tls_interaction_invoke_ask_password  (GTlsInteraction *interaction,  GTlsPassword *password,  GCancellable *cancellable,  GError **error);
254 		GError* err = null;
255 		
256 		auto p = g_tls_interaction_invoke_ask_password(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
257 		
258 		if (err !is null)
259 		{
260 			throw new GException( new ErrorG(err) );
261 		}
262 		
263 		return p;
264 	}
265 }