2 * e-user-prompter-server-extension.c
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.
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 General Public License
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/>.
19 * SECTION: e-user-prompter-server-extension
20 * @short_description: Extension for a server-side user prompter
22 * The #EUserPrompterServerExtension is a base struct for extension
23 * of EUserPrompterServer, to provide customized or specialized dialog
26 * A descendant defines two virtual functions,
27 * the EUserPrompterServerExtensionClass::register_dialogs which is used as
28 * a convenient function, where the descendant registers all the dialogs it
29 * provides on the server with e_user_prompter_server_register().
31 * The next function is EUserPrompterServerExtensionClass::prompt, which is
32 * used to initiate user prompt. The implementor should not block main thread
33 * with this function, because this is treated fully asynchronously.
34 * User's response is passed to the server with
35 * e_user_prompter_server_extension_response() call.
40 #endif /* HAVE_CONFIG_H */
44 #include "e-user-prompter-server-extension.h"
46 #define E_USER_PROMPTER_SERVER_EXTENSION_GET_PRIVATE(obj) \
47 (G_TYPE_INSTANCE_GET_PRIVATE \
48 ((obj), E_TYPE_USER_PROMPTER_SERVER_EXTENSION, EUserPrompterServerExtensionPrivate))
50 struct _EUserPrompterServerExtensionPrivate {
51 gint dummy; /* not used */
54 G_DEFINE_ABSTRACT_TYPE (EUserPrompterServerExtension, e_user_prompter_server_extension, E_TYPE_EXTENSION)
57 user_prompter_server_extension_constructed (GObject *object)
59 EExtensible *extensible;
60 EUserPrompterServer *server;
61 EExtension *extension;
62 EUserPrompterServerExtensionClass *klass;
64 /* Chain up to parent's constructed() method. */
65 G_OBJECT_CLASS (e_user_prompter_server_extension_parent_class)->constructed (object);
67 g_return_if_fail (E_IS_USER_PROMPTER_SERVER_EXTENSION (object));
69 extension = E_EXTENSION (object);
70 g_return_if_fail (extension != NULL);
72 extensible = e_extension_get_extensible (extension);
73 g_return_if_fail (E_IS_USER_PROMPTER_SERVER (extensible));
75 server = E_USER_PROMPTER_SERVER (extensible);
77 klass = E_USER_PROMPTER_SERVER_EXTENSION_GET_CLASS (extension);
78 g_return_if_fail (klass->register_dialogs);
80 klass->register_dialogs (extension, server);
84 e_user_prompter_server_extension_class_init (EUserPrompterServerExtensionClass *class)
86 GObjectClass *object_class;
87 EExtensionClass *extension_class;
89 g_type_class_add_private (class, sizeof (EUserPrompterServerExtensionPrivate));
91 class->register_dialogs = NULL;
94 object_class = G_OBJECT_CLASS (class);
95 object_class->constructed = user_prompter_server_extension_constructed;
97 extension_class = E_EXTENSION_CLASS (class);
98 extension_class->extensible_type = E_TYPE_USER_PROMPTER_SERVER;
102 e_user_prompter_server_extension_init (EUserPrompterServerExtension *extension)
104 extension->priv = E_USER_PROMPTER_SERVER_EXTENSION_GET_PRIVATE (extension);
108 * e_user_prompter_server_extension_prompt:
109 * @extension: an #EUserPrompterServerExtension
110 * @prompt_id: Prompt identificator, which is used in call to e_user_prompter_server_extension_response()
111 * @dialog_name: Name of a dialog to run
112 * @parameters: (allow-none): Optional extension parameters for the dialog, as passed by a caller
114 * Instructs extension to show dialog @dialog_name. If it cannot be found,
115 * or any error, then return %FALSE. The caller can pass optional @parameters,
116 * if @extension uses any. Meaning of @parameters is known only to the caller
117 * and to the dialog implementor, it's not interpretted nor checked for correctness
118 * in any way in #EUserPrompterServer. The only limitation of @parameters is that
119 * the array elements are strings.
121 * The @prompt_id is used as an identificator of the prompt itself,
122 * and is used in e_user_prompter_server_extension_response() call,
123 * which finishes the prompt.
125 * Note: The function call should not block main loop, it should
126 * just show dialog and return.
128 * Returns: Whether dialog was found and shown.
133 e_user_prompter_server_extension_prompt (EUserPrompterServerExtension *extension,
135 const gchar *dialog_name,
136 const ENamedParameters *parameters)
138 EUserPrompterServerExtensionClass *klass;
140 g_return_val_if_fail (E_IS_USER_PROMPTER_SERVER_EXTENSION (extension), FALSE);
142 klass = E_USER_PROMPTER_SERVER_EXTENSION_GET_CLASS (extension);
143 g_return_val_if_fail (klass->prompt != NULL, FALSE);
145 return klass->prompt (extension, prompt_id, dialog_name, parameters);
149 * e_user_prompter_server_extension_response:
150 * @extension: an #EUserPrompterServerExtension
151 * @prompt_id: Prompt identificator
152 * @response: Response of the prompt
153 * @values: (allow-none): Additional response values, if extension defines any
155 * A conveniente wrapper function around e_user_prompter_server_response(),
156 * which ends previous call of e_user_prompter_server_extension_prompt().
157 * The @response and @values is known only to the caller and to the dialog implementor,
158 * it's not interpretted nor checked for correctness in any way in #EUserPrompterServer.
159 * The only limitation of @values is that the array elements are strings.
164 e_user_prompter_server_extension_response (EUserPrompterServerExtension *extension,
167 const ENamedParameters *values)
169 EExtensible *extensible;
170 EUserPrompterServer *server;
172 g_return_if_fail (E_IS_USER_PROMPTER_SERVER_EXTENSION (extension));
174 extensible = e_extension_get_extensible (E_EXTENSION (extension));
175 g_return_if_fail (E_IS_USER_PROMPTER_SERVER (extensible));
177 server = E_USER_PROMPTER_SERVER (extensible);
179 e_user_prompter_server_response (server, prompt_id, response, values);