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