[gcr/wip/gcr4: 2/2] gcr: Use GLib macros for the GcrPrompt Interface
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcr/wip/gcr4: 2/2] gcr: Use GLib macros for the GcrPrompt Interface
- Date: Mon, 4 Oct 2021 18:14:57 +0000 (UTC)
commit b20c250c37ce7f55eae2c979bca4484845b9b5fe
Author: Corentin Noël <corentin noel collabora com>
Date: Mon Oct 4 20:13:56 2021 +0200
gcr: Use GLib macros for the GcrPrompt Interface
Use the right structure and macros names.
gcr/gcr-mock-prompter.c | 4 +-
gcr/gcr-prompt.c | 333 ++++++++++++++++++++++------------------------
gcr/gcr-prompt.h | 15 +--
gcr/gcr-system-prompt.c | 4 +-
gcr/gcr-system-prompter.c | 2 +-
ui/gcr-prompt-dialog.c | 4 +-
6 files changed, 173 insertions(+), 189 deletions(-)
---
diff --git a/gcr/gcr-mock-prompter.c b/gcr/gcr-mock-prompter.c
index 60c5dc0..8a1a159 100644
--- a/gcr/gcr-mock-prompter.c
+++ b/gcr/gcr-mock-prompter.c
@@ -103,7 +103,7 @@ typedef struct {
static gint prompts_a_prompting = 0;
static ThreadData *running = NULL;
-static void gcr_mock_prompt_iface (GcrPromptIface *iface);
+static void gcr_mock_prompt_iface (GcrPromptInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GcrMockPrompt, _gcr_mock_prompt, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GCR_TYPE_PROMPT, gcr_mock_prompt_iface);
@@ -560,7 +560,7 @@ gcr_mock_prompt_password_finish (GcrPrompt *prompt,
}
static void
-gcr_mock_prompt_iface (GcrPromptIface *iface)
+gcr_mock_prompt_iface (GcrPromptInterface *iface)
{
iface->prompt_confirm_async = gcr_mock_prompt_confirm_async;
iface->prompt_confirm_finish = gcr_mock_prompt_confirm_finish;
diff --git a/gcr/gcr-prompt.c b/gcr/gcr-prompt.c
index 403f796..d62f258 100644
--- a/gcr/gcr-prompt.c
+++ b/gcr/gcr-prompt.c
@@ -56,7 +56,7 @@
*/
/**
- * GcrPromptIface:
+ * GcrPromptInterface:
* @parent_iface: parent interface
* @prompt_password_async: begin a password prompt
* @prompt_password_finish: complete a password prompt
@@ -88,171 +88,162 @@ typedef struct {
GMainContext *context;
} RunClosure;
-typedef GcrPromptIface GcrPromptInterface;
-
-static void gcr_prompt_default_init (GcrPromptIface *iface);
+static void gcr_prompt_default_init (GcrPromptInterface *iface);
G_DEFINE_INTERFACE (GcrPrompt, gcr_prompt, G_TYPE_OBJECT);
static void
-gcr_prompt_default_init (GcrPromptIface *iface)
+gcr_prompt_default_init (GcrPromptInterface *iface)
{
- static gsize initialized = 0;
-
- if (g_once_init_enter (&initialized)) {
-
- /**
- * GcrPrompt:title:
- *
- * The title of the prompt.
- *
- * A prompt implementation may choose not to display the prompt title. The
- * #GcrPrompt:message should contain relevant information.
- */
- g_object_interface_install_property (iface,
- g_param_spec_string ("title", "Title", "Prompt title",
- NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:message:
- *
- * The prompt message for the user.
- *
- * A prompt implementation should always display this message.
- */
- g_object_interface_install_property (iface,
- g_param_spec_string ("message", "Message", "Prompt message",
- NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:description:
- *
- * The detailed description of the prompt.
- *
- * A prompt implementation may choose not to display this detailed description.
- * The prompt message should contain relevant information.
- */
- g_object_interface_install_property (iface,
- g_param_spec_string ("description", "Description", "Prompt description",
- NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:warning:
- *
- * A prompt warning displayed on the prompt, or %NULL for no warning.
- *
- * This is a warning like "The password is incorrect." usually displayed to the
- * user about a previous 'unsuccessful' prompt.
- */
- g_object_interface_install_property (iface,
- g_param_spec_string ("warning", "Warning", "Prompt warning",
- NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:password-new:
- *
- * Whether the prompt will prompt for a new password.
- *
- * This will cause the prompt implementation to ask the user to confirm the
- * password and/or display other relevant user interface for creating a new
- * password.
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("password-new", "Password new", "Whether prompting for a
new password",
- FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:password-strength:
- *
- * Indication of the password strength.
- *
- * Prompts will return a zero value if the password is empty, and a value
- * greater than zero if the password has any characters.
- *
- * This is only valid after a successful prompt for a password.
- */
- g_object_interface_install_property (iface,
- g_param_spec_int ("password-strength", "Password strength", "String of new
password",
- 0, G_MAXINT, 0, G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:choice-label:
- *
- * The label for the additional choice.
- *
- * If this is a non-%NULL value then an additional boolean choice will be
- * displayed by the prompt allowing the user to select or deselect it.
- *
- * If %NULL, then no additional choice is displayed.
- *
- * The initial value of the choice can be set with #GcrPrompt:choice-chosen.
- */
- g_object_interface_install_property (iface,
- g_param_spec_string ("choice-label", "Choice label", "Label for prompt
choice",
- NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:choice-chosen:
- *
- * Whether the additional choice is chosen or not.
- *
- * The additional choice would have been setup using #GcrPrompt:choice-label.
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("choice-chosen", "Choice chosen", "Whether prompt choice
is chosen",
- FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:caller-window:
- *
- * The string handle of the caller's window.
- *
- * The caller window indicates to the prompt which window is prompting the
- * user. The prompt may choose to ignore this information or use it in whatever
- * way it sees fit.
- *
- * In X11, this will be a stringified version of the XWindow handle; in
- * Wayland this is the result of an export using the XDG foreign
- * protocol.
- */
- g_object_interface_install_property (iface,
- g_param_spec_string ("caller-window", "Caller window", "Window ID of
application window requesting prompt",
- NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:continue-label:
- *
- * The label for the continue button in the prompt.
- */
- g_object_interface_install_property (iface,
- g_param_spec_string ("continue-label", "Continue label", "Continue button
label",
- _("Continue"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt:cancel-label:
- *
- * The label for the cancel button in the prompt.
- */
- g_object_interface_install_property (iface,
- g_param_spec_string ("cancel-label", "Cancel label", "Cancel button label",
- _("Cancel"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-
- /**
- * GcrPrompt::prompt-close:
- *
- * Action signal fired when the prompt is to be closed. After the default
- * handler has run, the prompt is closed. The various prompting methods
- * will return results as if the user dismissed the prompt.
- *
- * You can use the gcr_prompt_close() method to emit this signal.
- */
- signals[PROMPT_CLOSE] = g_signal_new ("prompt-close", GCR_TYPE_PROMPT, G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GcrPromptIface, prompt_close),
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- g_once_init_leave (&initialized, 1);
- }
+ /**
+ * GcrPrompt:title:
+ *
+ * The title of the prompt.
+ *
+ * A prompt implementation may choose not to display the prompt title. The
+ * #GcrPrompt:message should contain relevant information.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("title", "Title", "Prompt title",
+ NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:message:
+ *
+ * The prompt message for the user.
+ *
+ * A prompt implementation should always display this message.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("message", "Message", "Prompt message",
+ NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:description:
+ *
+ * The detailed description of the prompt.
+ *
+ * A prompt implementation may choose not to display this detailed description.
+ * The prompt message should contain relevant information.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("description", "Description", "Prompt description",
+ NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:warning:
+ *
+ * A prompt warning displayed on the prompt, or %NULL for no warning.
+ *
+ * This is a warning like "The password is incorrect." usually displayed to the
+ * user about a previous 'unsuccessful' prompt.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("warning", "Warning", "Prompt warning",
+ NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:password-new:
+ *
+ * Whether the prompt will prompt for a new password.
+ *
+ * This will cause the prompt implementation to ask the user to confirm the
+ * password and/or display other relevant user interface for creating a new
+ * password.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_boolean ("password-new", "Password new", "Whether prompting for a new
password",
+ FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:password-strength:
+ *
+ * Indication of the password strength.
+ *
+ * Prompts will return a zero value if the password is empty, and a value
+ * greater than zero if the password has any characters.
+ *
+ * This is only valid after a successful prompt for a password.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_int ("password-strength", "Password strength", "String of new
password",
+ 0, G_MAXINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:choice-label:
+ *
+ * The label for the additional choice.
+ *
+ * If this is a non-%NULL value then an additional boolean choice will be
+ * displayed by the prompt allowing the user to select or deselect it.
+ *
+ * If %NULL, then no additional choice is displayed.
+ *
+ * The initial value of the choice can be set with #GcrPrompt:choice-chosen.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("choice-label", "Choice label", "Label for prompt choice",
+ NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:choice-chosen:
+ *
+ * Whether the additional choice is chosen or not.
+ *
+ * The additional choice would have been setup using #GcrPrompt:choice-label.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_boolean ("choice-chosen", "Choice chosen", "Whether prompt choice is
chosen",
+ FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:caller-window:
+ *
+ * The string handle of the caller's window.
+ *
+ * The caller window indicates to the prompt which window is prompting the
+ * user. The prompt may choose to ignore this information or use it in whatever
+ * way it sees fit.
+ *
+ * In X11, this will be a stringified version of the XWindow handle; in
+ * Wayland this is the result of an export using the XDG foreign
+ * protocol.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("caller-window", "Caller window", "Window ID of application
window requesting prompt",
+ NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:continue-label:
+ *
+ * The label for the continue button in the prompt.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("continue-label", "Continue label", "Continue button label",
+ _("Continue"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt:cancel-label:
+ *
+ * The label for the cancel button in the prompt.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("cancel-label", "Cancel label", "Cancel button label",
+ _("Cancel"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GcrPrompt::prompt-close:
+ *
+ * Action signal fired when the prompt is to be closed. After the default
+ * handler has run, the prompt is closed. The various prompting methods
+ * will return results as if the user dismissed the prompt.
+ *
+ * You can use the gcr_prompt_close() method to emit this signal.
+ */
+ signals[PROMPT_CLOSE] = g_signal_new ("prompt-close", GCR_TYPE_PROMPT, G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GcrPromptInterface, prompt_close),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
}
static void
@@ -304,12 +295,12 @@ void
gcr_prompt_reset (GcrPrompt *prompt)
{
GParamSpec **params;
- GcrPromptIface *iface;
+ GcrPromptInterface *iface;
guint i, n_params;
g_return_if_fail (GCR_IS_PROMPT (prompt));
- iface = GCR_PROMPT_GET_INTERFACE (prompt);
+ iface = GCR_PROMPT_GET_IFACE (prompt);
params = g_object_interface_list_properties (iface, &n_params);
g_object_freeze_notify (G_OBJECT (prompt));
@@ -777,12 +768,12 @@ gcr_prompt_password_async (GcrPrompt *prompt,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GcrPromptIface *iface;
+ GcrPromptInterface *iface;
g_return_if_fail (GCR_IS_PROMPT (prompt));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- iface = GCR_PROMPT_GET_INTERFACE (prompt);
+ iface = GCR_PROMPT_GET_IFACE (prompt);
g_return_if_fail (iface->prompt_password_async);
(iface->prompt_password_async) (prompt, cancellable, callback, user_data);
@@ -810,13 +801,13 @@ gcr_prompt_password_finish (GcrPrompt *prompt,
GAsyncResult *result,
GError **error)
{
- GcrPromptIface *iface;
+ GcrPromptInterface *iface;
g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- iface = GCR_PROMPT_GET_INTERFACE (prompt);
+ iface = GCR_PROMPT_GET_IFACE (prompt);
g_return_val_if_fail (iface->prompt_password_async, NULL);
return (iface->prompt_password_finish) (prompt, result, error);
@@ -931,12 +922,12 @@ gcr_prompt_confirm_async (GcrPrompt *prompt,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GcrPromptIface *iface;
+ GcrPromptInterface *iface;
g_return_if_fail (GCR_IS_PROMPT (prompt));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- iface = GCR_PROMPT_GET_INTERFACE (prompt);
+ iface = GCR_PROMPT_GET_IFACE (prompt);
g_return_if_fail (iface->prompt_confirm_async);
(iface->prompt_confirm_async) (prompt, cancellable, callback, user_data);
@@ -961,13 +952,13 @@ gcr_prompt_confirm_finish (GcrPrompt *prompt,
GAsyncResult *result,
GError **error)
{
- GcrPromptIface *iface;
+ GcrPromptInterface *iface;
g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), GCR_PROMPT_REPLY_CANCEL);
g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
- iface = GCR_PROMPT_GET_INTERFACE (prompt);
+ iface = GCR_PROMPT_GET_IFACE (prompt);
g_return_val_if_fail (iface->prompt_confirm_async, GCR_PROMPT_REPLY_CANCEL);
return (iface->prompt_confirm_finish) (prompt, result, error);
diff --git a/gcr/gcr-prompt.h b/gcr/gcr-prompt.h
index 56b9339..ed850ec 100644
--- a/gcr/gcr-prompt.h
+++ b/gcr/gcr-prompt.h
@@ -37,16 +37,11 @@ typedef enum {
GCR_PROMPT_REPLY_CONTINUE = 1,
} GcrPromptReply;
-#define GCR_TYPE_PROMPT (gcr_prompt_get_type ())
-#define GCR_PROMPT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCR_TYPE_PROMPT, GcrPrompt))
-#define GCR_IS_PROMPT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCR_TYPE_PROMPT))
-#define GCR_PROMPT_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GCR_TYPE_PROMPT,
GcrPromptIface))
+#define GCR_TYPE_PROMPT gcr_prompt_get_type ()
+G_DECLARE_INTERFACE(GcrPrompt, gcr_prompt, GCR, PROMPT, GObject)
-typedef struct _GcrPrompt GcrPrompt;
-typedef struct _GcrPromptIface GcrPromptIface;
-
-struct _GcrPromptIface {
- GTypeInterface parent_iface;
+struct _GcrPromptInterface {
+ GTypeInterface g_iface;
void (* prompt_password_async) (GcrPrompt *prompt,
GCancellable *cancellable,
@@ -69,8 +64,6 @@ struct _GcrPromptIface {
void (* prompt_close) (GcrPrompt *prompt);
};
-GType gcr_prompt_get_type (void);
-
void gcr_prompt_reset (GcrPrompt *prompt);
gchar * gcr_prompt_get_title (GcrPrompt *prompt);
diff --git a/gcr/gcr-system-prompt.c b/gcr/gcr-system-prompt.c
index 530faf6..f444931 100644
--- a/gcr/gcr-system-prompt.c
+++ b/gcr/gcr-system-prompt.c
@@ -122,7 +122,7 @@ struct _GcrSystemPromptPrivate {
gchar *last_response;
};
-static void gcr_system_prompt_prompt_iface (GcrPromptIface *iface);
+static void gcr_system_prompt_prompt_iface (GcrPromptInterface *iface);
static void gcr_system_prompt_initable_iface (GInitableIface *iface);
@@ -1338,7 +1338,7 @@ gcr_system_prompt_real_close (GcrPrompt *prompt)
}
static void
-gcr_system_prompt_prompt_iface (GcrPromptIface *iface)
+gcr_system_prompt_prompt_iface (GcrPromptInterface *iface)
{
iface->prompt_password_async = gcr_system_prompt_password_async;
iface->prompt_password_finish = gcr_system_prompt_password_finish;
diff --git a/gcr/gcr-system-prompter.c b/gcr/gcr-system-prompter.c
index 10948cf..bb5c933 100644
--- a/gcr/gcr-system-prompter.c
+++ b/gcr/gcr-system-prompter.c
@@ -444,7 +444,7 @@ prompt_build_properties (GcrPrompt *prompt,
while (g_hash_table_iter_next (&iter, (gpointer *)&property_name, NULL)) {
/* Make sure this property is on the prompt interface */
- pspec = g_object_interface_find_property (GCR_PROMPT_GET_INTERFACE (obj),
+ pspec = g_object_interface_find_property (GCR_PROMPT_GET_IFACE (obj),
property_name);
if (pspec == NULL)
continue;
diff --git a/ui/gcr-prompt-dialog.c b/ui/gcr-prompt-dialog.c
index 5331b6e..bc6643c 100644
--- a/ui/gcr-prompt-dialog.c
+++ b/ui/gcr-prompt-dialog.c
@@ -122,7 +122,7 @@ struct _GcrPromptDialogPrivate {
gboolean was_closed;
};
-static void gcr_prompt_dialog_prompt_iface (GcrPromptIface *iface);
+static void gcr_prompt_dialog_prompt_iface (GcrPromptInterface *iface);
static gboolean ungrab_keyboard (GtkWidget *win,
GdkEvent *event,
@@ -1065,7 +1065,7 @@ gcr_prompt_dialog_close (GcrPrompt *prompt)
}
static void
-gcr_prompt_dialog_prompt_iface (GcrPromptIface *iface)
+gcr_prompt_dialog_prompt_iface (GcrPromptInterface *iface)
{
iface->prompt_password_async = gcr_prompt_dialog_password_async;
iface->prompt_password_finish = gcr_prompt_dialog_password_finish;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]