1 /*
2  * Copyright (C) 2015 Red Hat, Inc. (www.redhat.com)
3  *
4  * This library is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library. If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 
18 #if !defined (__LIBEDATASERVERUI_H_INSIDE__) && !defined (LIBEDATASERVERUI_COMPILATION)
19 #error "Only <libedataserverui/libedataserverui.h> should be included directly."
20 #endif
21 
22 #ifndef E_CREDENTIALS_PROMPTER_H
23 #define E_CREDENTIALS_PROMPTER_H
24 
25 #include <glib.h>
26 #include <glib-object.h>
27 #include <gio/gio.h>
28 
29 #include <gtk/gtk.h>
30 
31 #include <libedataserver/libedataserver.h>
32 
33 #include <libedataserverui/e-credentials-prompter-impl.h>
34 
35 /* Standard GObject macros */
36 #define E_TYPE_CREDENTIALS_PROMPTER \
37 	(e_credentials_prompter_get_type ())
38 #define E_CREDENTIALS_PROMPTER(obj) \
39 	(G_TYPE_CHECK_INSTANCE_CAST \
40 	((obj), E_TYPE_CREDENTIALS_PROMPTER, ECredentialsPrompter))
41 #define E_CREDENTIALS_PROMPTER_CLASS(cls) \
42 	(G_TYPE_CHECK_CLASS_CAST \
43 	((cls), E_TYPE_CREDENTIALS_PROMPTER, ECredentialsPrompterClass))
44 #define E_IS_CREDENTIALS_PROMPTER(obj) \
45 	(G_TYPE_CHECK_INSTANCE_TYPE \
46 	((obj), E_TYPE_CREDENTIALS_PROMPTER))
47 #define E_IS_CREDENTIALS_PROMPTER_CLASS(cls) \
48 	(G_TYPE_CHECK_CLASS_TYPE \
49 	((cls), E_TYPE_CREDENTIALS_PROMPTER))
50 #define E_CREDENTIALS_PROMPTER_GET_CLASS(obj) \
51 	(G_TYPE_INSTANCE_GET_CLASS \
52 	((obj), E_TYPE_CREDENTIALS_PROMPTER, ECredentialsPrompterClass))
53 
54 G_BEGIN_DECLS
55 
56 typedef struct _ECredentialsPrompter ECredentialsPrompter;
57 typedef struct _ECredentialsPrompterClass ECredentialsPrompterClass;
58 typedef struct _ECredentialsPrompterPrivate ECredentialsPrompterPrivate;
59 
60 /**
61  * ECredentialsPrompterPromptFlags:
62  * @E_CREDENTIALS_PROMPTER_PROMPT_FLAG_NONE:
63  *   No flag is set.
64  * @E_CREDENTIALS_PROMPTER_PROMPT_FLAG_ALLOW_SOURCE_SAVE:
65  *   If set, any source changes during the credentials prompts, like
66  *   the "remember-password" or user name changes, will be automatically
67  *   stored in the source (written on the disk).
68  * @E_CREDENTIALS_PROMPTER_PROMPT_FLAG_ALLOW_STORED_CREDENTIALS:
69  *   If set, the stored credentials will be returned first. If there are no
70  *   credentials saved, then the user will be asked. Any credentials
71  *   reprompt should not have set this flag.
72  *
73  * An #ECredentialsPrompter prompt flags, influencing behaviour
74  * of the e_credentials_prompter_prompt().
75  *
76  * Since: 3.16
77  **/
78 typedef enum {
79 	E_CREDENTIALS_PROMPTER_PROMPT_FLAG_NONE				= 0,
80 	E_CREDENTIALS_PROMPTER_PROMPT_FLAG_ALLOW_SOURCE_SAVE		= 1 << 0,
81 	E_CREDENTIALS_PROMPTER_PROMPT_FLAG_ALLOW_STORED_CREDENTIALS	= 1 << 1
82 } ECredentialsPrompterPromptFlags;
83 
84 /**
85  * ECredentialsPrompterLoopPromptFunc:
86  * @prompter: an #ECredentialsPrompter
87  * @source: an #ESource, as passed to e_credentials_prompter_loop_prompt_sync()
88  * @credentials: an #ENamedParameters with provided credentials
89  * @out_authenticated: (out): set to %TRUE, when the authentication was successful
90  * @user_data: user data, as passed to e_credentials_prompter_loop_prompt_sync()
91  * @cancellable: a #GCancellable, as passed to e_credentials_prompter_loop_prompt_sync()
92  * @error: a #GError, to get an error, or %NULL
93  *
94  * Returns: %TRUE to continue the loop (reprompt credentials), unless @authenticated is
95  *   also set to %TRUE, or %FALSE on error, as an indication that the loop should
96  *   be terminated.
97  **/
98 typedef gboolean (*ECredentialsPrompterLoopPromptFunc) (ECredentialsPrompter *prompter,
99 							ESource *source,
100 							const ENamedParameters *credentials,
101 							gboolean *out_authenticated,
102 							gpointer user_data,
103 							GCancellable *cancellable,
104 							GError **error);
105 /**
106  * ECredentialsPrompter:
107  *
108  * Contains only private data that should be read and manipulated using the
109  * functions below.
110  *
111  * Since: 3.16
112  **/
113 struct _ECredentialsPrompter {
114 	GObject parent;
115 	ECredentialsPrompterPrivate *priv;
116 };
117 
118 struct _ECredentialsPrompterClass {
119 	GObjectClass parent_class;
120 
121 	/* Signals */
122 	GtkWindow *	(*get_dialog_parent)	(ECredentialsPrompter *prompter);
123 	/*GtkWindow *	(*get_dialog_parent_full)(ECredentialsPrompter *prompter,
124 						 ESource *auth_source); */
125 };
126 
127 GType		e_credentials_prompter_get_type	(void) G_GNUC_CONST;
128 ECredentialsPrompter *
129 		e_credentials_prompter_new	(ESourceRegistry *registry);
130 ESourceRegistry *
131 		e_credentials_prompter_get_registry
132 						(ECredentialsPrompter *prompter);
133 ESourceCredentialsProvider *
134 		e_credentials_prompter_get_provider
135 						(ECredentialsPrompter *prompter);
136 gboolean	e_credentials_prompter_get_auto_prompt
137 						(ECredentialsPrompter *prompter);
138 void		e_credentials_prompter_set_auto_prompt
139 						(ECredentialsPrompter *prompter,
140 						 gboolean auto_prompt);
141 void		e_credentials_prompter_set_auto_prompt_disabled_for
142 						(ECredentialsPrompter *prompter,
143 						 ESource *source,
144 						 gboolean is_disabled);
145 gboolean	e_credentials_prompter_get_auto_prompt_disabled_for
146 						(ECredentialsPrompter *prompter,
147 						 ESource *source);
148 GtkWindow *	e_credentials_prompter_get_dialog_parent
149 						(ECredentialsPrompter *prompter);
150 GtkWindow *	e_credentials_prompter_get_dialog_parent_full
151 						(ECredentialsPrompter *prompter,
152 						 ESource *auth_source);
153 gboolean	e_credentials_prompter_register_impl
154 						(ECredentialsPrompter *prompter,
155 						 const gchar *authentication_method,
156 						 ECredentialsPrompterImpl *prompter_impl);
157 void		e_credentials_prompter_unregister_impl
158 						(ECredentialsPrompter *prompter,
159 						 const gchar *authentication_method,
160 						 ECredentialsPrompterImpl *prompter_impl);
161 void		e_credentials_prompter_process_awaiting_credentials
162 						(ECredentialsPrompter *prompter);
163 gboolean	e_credentials_prompter_process_source
164 						(ECredentialsPrompter *prompter,
165 						 ESource *source);
166 void		e_credentials_prompter_prompt	(ECredentialsPrompter *prompter,
167 						 ESource *source,
168 						 const gchar *error_text,
169 						 ECredentialsPrompterPromptFlags flags,
170 						 GAsyncReadyCallback callback,
171 						 gpointer user_data);
172 gboolean	e_credentials_prompter_prompt_finish
173 						(ECredentialsPrompter *prompter,
174 						 GAsyncResult *result,
175 						 ESource **out_source,
176 						 ENamedParameters **out_credentials,
177 						 GError **error);
178 void		e_credentials_prompter_complete_prompt_call
179 						(ECredentialsPrompter *prompter,
180 						 GSimpleAsyncResult *async_result,
181 						 ESource *source,
182 						 const ENamedParameters *credentials,
183 						 const GError *error);
184 gboolean	e_credentials_prompter_loop_prompt_sync
185 						(ECredentialsPrompter *prompter,
186 						 ESource *source,
187 						 ECredentialsPrompterPromptFlags flags,
188 						 ECredentialsPrompterLoopPromptFunc func,
189 						 gpointer user_data,
190 						 GCancellable *cancellable,
191 						 GError **error);
192 G_END_DECLS
193 
194 #endif /* E_CREDENTIALS_PROMPTER_H */
195