[gnome-control-center] fingerprint-manager: Add completion callback to update state
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] fingerprint-manager: Add completion callback to update state
- Date: Fri, 26 Jun 2020 01:59:23 +0000 (UTC)
commit d8c119db2d6bb82a9fba939817a0f41a1e202ef8
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Tue Apr 7 01:46:47 2020 +0200
fingerprint-manager: Add completion callback to update state
panels/user-accounts/cc-fingerprint-manager.c | 56 +++++++++++++++++++--------
panels/user-accounts/cc-fingerprint-manager.h | 9 ++++-
panels/user-accounts/um-fingerprint-dialog.c | 18 +++++++--
3 files changed, 62 insertions(+), 21 deletions(-)
---
diff --git a/panels/user-accounts/cc-fingerprint-manager.c b/panels/user-accounts/cc-fingerprint-manager.c
index c9cb7f362..3d5f2fe0b 100644
--- a/panels/user-accounts/cc-fingerprint-manager.c
+++ b/panels/user-accounts/cc-fingerprint-manager.c
@@ -121,7 +121,7 @@ cc_fingerprint_manager_set_property (GObject *object,
static void
cc_fingerprint_manager_constructed (GObject *object)
{
- cc_fingerprint_manager_update_state (CC_FINGERPRINT_MANAGER (object));
+ cc_fingerprint_manager_update_state (CC_FINGERPRINT_MANAGER (object), NULL, NULL);
}
static void
@@ -329,6 +329,12 @@ set_state (CcFingerprintManager *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STATE]);
}
+typedef struct
+{
+ guint waiting_devices;
+ CcFingerprintStateUpdated callback;
+ gpointer user_data;
+} UpdateStateData;
static void
update_state_callback (GObject *object,
@@ -339,11 +345,16 @@ update_state_callback (GObject *object,
CcFingerprintManagerPrivate *priv = cc_fingerprint_manager_get_instance_private (self);
g_autoptr(GError) error = NULL;
CcFingerprintState state;
+ UpdateStateData *data;
+ GTask *task;
g_return_if_fail (g_task_is_valid (res, self));
- priv->current_task = NULL;
- state = g_task_propagate_int (G_TASK (res), &error);
+ task = G_TASK (res);
+ g_assert (g_steal_pointer (&priv->current_task) == task);
+
+ state = g_task_propagate_int (task, &error);
+ data = g_task_get_task_data (task);
if (error)
{
@@ -357,6 +368,9 @@ update_state_callback (GObject *object,
}
set_state (self, state);
+
+ if (data->callback)
+ data->callback (self, state, data->user_data, error);
}
static void
@@ -368,27 +382,25 @@ on_device_list_enrolled (GObject *object,
g_autoptr(GTask) task = G_TASK (user_data);
g_autoptr(GError) error = NULL;
g_auto(GStrv) enrolled_fingers = NULL;
- guint waiting_devices;
+ UpdateStateData *data = g_task_get_task_data (task);
guint num_enrolled_fingers;
- waiting_devices = GPOINTER_TO_UINT (g_task_get_task_data (task));
-
cc_fprintd_device_call_list_enrolled_fingers_finish (fprintd_device,
&enrolled_fingers,
res, &error);
- waiting_devices--;
- g_task_set_task_data (task, GUINT_TO_POINTER (waiting_devices), NULL);
- if (g_task_get_completed (task))
+ if (data->waiting_devices == 0)
return;
+ data->waiting_devices--;
+
if (error)
{
g_autofree char *dbus_error = g_dbus_error_get_remote_error (error);
if (!g_str_equal (dbus_error, CC_FPRINTD_NAME ".Error.NoEnrolledPrints"))
{
- if (waiting_devices == 0)
+ if (data->waiting_devices == 0)
g_task_return_error (task, g_steal_pointer (&error));
else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("Impossible to list enrolled fingers: %s", error->message);
@@ -404,9 +416,14 @@ on_device_list_enrolled (GObject *object,
num_enrolled_fingers);
if (num_enrolled_fingers > 0)
- g_task_return_int (task, CC_FINGERPRINT_STATE_ENABLED);
- else if (waiting_devices == 0)
- g_task_return_int (task, CC_FINGERPRINT_STATE_DISABLED);
+ {
+ data->waiting_devices = 0;
+ g_task_return_int (task, CC_FINGERPRINT_STATE_ENABLED);
+ }
+ else if (data->waiting_devices == 0)
+ {
+ g_task_return_int (task, CC_FINGERPRINT_STATE_DISABLED);
+ }
}
static void
@@ -419,6 +436,7 @@ on_manager_devices_list (GObject *object,
g_autolist(CcFprintdDevice) fprintd_devices = NULL;
g_autoptr(GTask) task = G_TASK (user_data);
g_autoptr(GError) error = NULL;
+ UpdateStateData *data = g_task_get_task_data (task);
const char *user_name;
GList *l;
@@ -438,7 +456,6 @@ on_manager_devices_list (GObject *object,
}
user_name = act_user_get_user_name (priv->user);
- g_task_set_task_data (task, GUINT_TO_POINTER (g_list_length (fprintd_devices)), NULL);
for (l = fprintd_devices; l; l = l->next)
{
@@ -447,6 +464,7 @@ on_manager_devices_list (GObject *object,
g_debug ("Connected to device %s, looking for enrolled fingers",
cc_fprintd_device_get_name (device));
+ data->waiting_devices++;
cc_fprintd_device_call_list_enrolled_fingers (device, user_name,
g_task_get_cancellable (task),
on_device_list_enrolled,
@@ -455,10 +473,13 @@ on_manager_devices_list (GObject *object,
}
void
-cc_fingerprint_manager_update_state (CcFingerprintManager *self)
+cc_fingerprint_manager_update_state (CcFingerprintManager *self,
+ CcFingerprintStateUpdated callback,
+ gpointer user_data)
{
CcFingerprintManagerPrivate *priv = cc_fingerprint_manager_get_instance_private (self);
g_autoptr(GCancellable) cancellable = NULL;
+ UpdateStateData *data;
g_return_if_fail (priv->current_task == NULL);
@@ -469,11 +490,14 @@ cc_fingerprint_manager_update_state (CcFingerprintManager *self)
return;
}
-
cancellable = g_cancellable_new ();
+ data = g_new0 (UpdateStateData, 1);
+ data->callback = callback;
+ data->user_data = user_data;
priv->current_task = g_task_new (self, cancellable, update_state_callback, NULL);
g_task_set_source_tag (priv->current_task, cc_fingerprint_manager_update_state);
+ g_task_set_task_data (priv->current_task, data, g_free);
cc_fingerprint_manager_get_devices (self, cancellable, on_manager_devices_list,
priv->current_task);
diff --git a/panels/user-accounts/cc-fingerprint-manager.h b/panels/user-accounts/cc-fingerprint-manager.h
index 89c958929..8ebfca481 100644
--- a/panels/user-accounts/cc-fingerprint-manager.h
+++ b/panels/user-accounts/cc-fingerprint-manager.h
@@ -45,11 +45,18 @@ typedef enum {
CC_FINGERPRINT_STATE_DISABLED,
} CcFingerprintState;
+typedef void (*CcFingerprintStateUpdated) (CcFingerprintManager *fp_manager,
+ CcFingerprintState state,
+ gpointer user_data,
+ GError *error);
+
CcFingerprintManager * cc_fingerprint_manager_new (ActUser *user);
CcFingerprintState cc_fingerprint_manager_get_state (CcFingerprintManager *fp_manager);
-void cc_fingerprint_manager_update_state (CcFingerprintManager *fp_manager);
+void cc_fingerprint_manager_update_state (CcFingerprintManager *fp_manager,
+ CcFingerprintStateUpdated callback,
+ gpointer user_data);
void cc_fingerprint_manager_get_devices (CcFingerprintManager *fp_manager,
GCancellable *cancellable,
diff --git a/panels/user-accounts/um-fingerprint-dialog.c b/panels/user-accounts/um-fingerprint-dialog.c
index 68b645d2a..8f1111583 100644
--- a/panels/user-accounts/um-fingerprint-dialog.c
+++ b/panels/user-accounts/um-fingerprint-dialog.c
@@ -182,6 +182,17 @@ get_error_dialog (const char *title,
return error_dialog;
}
+static void
+on_state_updated (CcFingerprintManager *fp_manager,
+ CcFingerprintState state,
+ gpointer user_data,
+ GError *error)
+{
+ g_autoptr (GtkWidget) fingerprint_row = GTK_WIDGET (user_data);
+
+ gtk_widget_set_sensitive (fingerprint_row, TRUE);
+}
+
static void
set_fingerprint_row_cb (GObject *source_object,
GAsyncResult *res,
@@ -200,9 +211,8 @@ set_fingerprint_row_cb (GObject *source_object,
}
}
- gtk_widget_set_sensitive (fingerprint_row, TRUE);
-
- cc_fingerprint_manager_update_state (fingerprint_manager);
+ cc_fingerprint_manager_update_state (fingerprint_manager, on_state_updated,
+ g_object_ref (fingerprint_row));
}
static void
@@ -412,7 +422,7 @@ static void
assistant_cancelled (GtkAssistant *ass, EnrollData *data)
{
enroll_data_destroy (data);
- cc_fingerprint_manager_update_state (fingerprint_manager);
+ cc_fingerprint_manager_update_state (fingerprint_manager, NULL, NULL);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]