color: Adapt to new async colord API
The libcolord async API used to use a thread to get the properties for the device and profiles in the background. This was racy as hell, and was not good API design. Connect to each device and profiles explicitly before we access the properties.
This commit is contained in:
parent
63c7019e95
commit
e51b037b76
1 changed files with 111 additions and 39 deletions
|
@ -246,7 +246,7 @@ gcm_prefs_device_add_cb (GtkWidget *widget, CcColorPanel *prefs)
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gcm_prefs_is_profile_suitable_for_device (CdProfile *profile,
|
gcm_prefs_is_profile_suitable_for_device (CdProfile *profile,
|
||||||
CdDevice *device)
|
CdDevice *device)
|
||||||
{
|
{
|
||||||
CdProfileKind profile_kind_tmp;
|
CdProfileKind profile_kind_tmp;
|
||||||
CdProfileKind profile_kind;
|
CdProfileKind profile_kind;
|
||||||
|
@ -351,6 +351,17 @@ gcm_prefs_add_profiles_suitable_for_devices (CcColorPanel *prefs,
|
||||||
if (profile != NULL && cd_profile_equal (profile, profile_tmp))
|
if (profile != NULL && cd_profile_equal (profile, profile_tmp))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* get properties */
|
||||||
|
ret = cd_profile_connect_sync (profile_tmp,
|
||||||
|
priv->cancellable,
|
||||||
|
&error);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
g_warning ("failed to get profile: %s", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* only add correct types */
|
/* only add correct types */
|
||||||
ret = gcm_prefs_is_profile_suitable_for_device (profile_tmp,
|
ret = gcm_prefs_is_profile_suitable_for_device (profile_tmp,
|
||||||
priv->current_device);
|
priv->current_device);
|
||||||
|
@ -599,7 +610,7 @@ gcm_prefs_delete_cb (GtkWidget *widget, CcColorPanel *prefs)
|
||||||
|
|
||||||
/* try to delete device */
|
/* try to delete device */
|
||||||
ret = cd_client_delete_device_sync (priv->client,
|
ret = cd_client_delete_device_sync (priv->client,
|
||||||
cd_device_get_id (priv->current_device),
|
priv->current_device,
|
||||||
priv->cancellable,
|
priv->cancellable,
|
||||||
&error);
|
&error);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
|
@ -627,7 +638,7 @@ gcm_prefs_treeview_renderer_toggled (GtkCellRendererToggle *cell,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcm_prefs_add_devices_columns (CcColorPanel *prefs,
|
gcm_prefs_add_devices_columns (CcColorPanel *prefs,
|
||||||
GtkTreeView *treeview)
|
GtkTreeView *treeview)
|
||||||
{
|
{
|
||||||
GtkCellRenderer *renderer;
|
GtkCellRenderer *renderer;
|
||||||
GtkTreeViewColumn *column;
|
GtkTreeViewColumn *column;
|
||||||
|
@ -821,9 +832,9 @@ gcm_prefs_profile_clicked (CcColorPanel *prefs, CdProfile *profile, CdDevice *de
|
||||||
|
|
||||||
|
|
||||||
/* find the profile relationship */
|
/* find the profile relationship */
|
||||||
relation = cd_device_get_profile_relation (device,
|
relation = cd_device_get_profile_relation_sync (device,
|
||||||
profile,
|
profile,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
/* we can only remove hard relationships */
|
/* we can only remove hard relationships */
|
||||||
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
|
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
|
||||||
|
@ -1046,8 +1057,6 @@ out:
|
||||||
g_object_unref (profile);
|
g_object_unref (profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcm_prefs_sensor_coldplug (CcColorPanel *prefs)
|
gcm_prefs_sensor_coldplug (CcColorPanel *prefs)
|
||||||
{
|
{
|
||||||
|
@ -1082,8 +1091,8 @@ out:
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcm_prefs_client_sensor_changed_cb (CdClient *client,
|
gcm_prefs_client_sensor_changed_cb (CdClient *client,
|
||||||
CdSensor *sensor,
|
CdSensor *sensor,
|
||||||
CcColorPanel *prefs)
|
CcColorPanel *prefs)
|
||||||
{
|
{
|
||||||
gcm_prefs_sensor_coldplug (prefs);
|
gcm_prefs_sensor_coldplug (prefs);
|
||||||
gcm_prefs_set_calibrate_button_sensitivity (prefs);
|
gcm_prefs_set_calibrate_button_sensitivity (prefs);
|
||||||
|
@ -1200,14 +1209,28 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
gcm_prefs_get_profile_title (CdProfile *profile)
|
gcm_prefs_get_profile_title (CcColorPanel *prefs, CdProfile *profile)
|
||||||
{
|
{
|
||||||
CdColorspace colorspace;
|
CdColorspace colorspace;
|
||||||
const gchar *title;
|
const gchar *title;
|
||||||
gchar *string;
|
gchar *string;
|
||||||
|
gboolean ret;
|
||||||
|
GError *error = NULL;
|
||||||
|
CcColorPanelPrivate *priv = prefs->priv;
|
||||||
|
|
||||||
g_return_val_if_fail (profile != NULL, NULL);
|
g_return_val_if_fail (profile != NULL, NULL);
|
||||||
|
|
||||||
|
/* get properties */
|
||||||
|
ret = cd_profile_connect_sync (profile,
|
||||||
|
priv->cancellable,
|
||||||
|
&error);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
g_warning ("failed to get profile: %s", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* add profile description */
|
/* add profile description */
|
||||||
title = cd_profile_get_title (profile);
|
title = cd_profile_get_title (profile);
|
||||||
if (title != NULL)
|
if (title != NULL)
|
||||||
|
@ -1323,12 +1346,12 @@ out:
|
||||||
static void
|
static void
|
||||||
gcm_prefs_device_set_model_by_iter (CcColorPanel *prefs, CdDevice *device, GtkTreeIter *iter)
|
gcm_prefs_device_set_model_by_iter (CcColorPanel *prefs, CdDevice *device, GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GString *status;
|
GString *status = NULL;
|
||||||
const gchar *status_image = NULL;
|
const gchar *status_image = NULL;
|
||||||
const gchar *tooltip = NULL;
|
const gchar *tooltip = NULL;
|
||||||
CdProfile *profile = NULL;
|
CdProfile *profile = NULL;
|
||||||
gint age;
|
gint age;
|
||||||
GPtrArray *profiles;
|
GPtrArray *profiles = NULL;
|
||||||
CdProfile *profile_tmp;
|
CdProfile *profile_tmp;
|
||||||
guint i;
|
guint i;
|
||||||
gchar *title_tmp;
|
gchar *title_tmp;
|
||||||
|
@ -1337,6 +1360,8 @@ gcm_prefs_device_set_model_by_iter (CcColorPanel *prefs, CdDevice *device, GtkTr
|
||||||
GtkTreeIter iter_tmp;
|
GtkTreeIter iter_tmp;
|
||||||
GtkTreeIter *iter_tmp_p;
|
GtkTreeIter *iter_tmp_p;
|
||||||
guint threshold = 0;
|
guint threshold = 0;
|
||||||
|
gboolean ret;
|
||||||
|
GError *error = NULL;
|
||||||
CcColorPanelPrivate *priv = prefs->priv;
|
CcColorPanelPrivate *priv = prefs->priv;
|
||||||
|
|
||||||
/* set status */
|
/* set status */
|
||||||
|
@ -1350,6 +1375,17 @@ gcm_prefs_device_set_model_by_iter (CcColorPanel *prefs, CdDevice *device, GtkTr
|
||||||
goto skip;
|
goto skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get properties */
|
||||||
|
ret = cd_profile_connect_sync (profile,
|
||||||
|
priv->cancellable,
|
||||||
|
&error);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
g_warning ("failed to get profile: %s", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* autogenerated printer defaults */
|
/* autogenerated printer defaults */
|
||||||
if (cd_device_get_kind (device) == CD_DEVICE_KIND_PRINTER &&
|
if (cd_device_get_kind (device) == CD_DEVICE_KIND_PRINTER &&
|
||||||
cd_profile_get_filename (profile) == NULL)
|
cd_profile_get_filename (profile) == NULL)
|
||||||
|
@ -1415,7 +1451,7 @@ skip:
|
||||||
for (i = 0; i < profiles->len; i++)
|
for (i = 0; i < profiles->len; i++)
|
||||||
{
|
{
|
||||||
profile_tmp = g_ptr_array_index (profiles, i);
|
profile_tmp = g_ptr_array_index (profiles, i);
|
||||||
title_tmp = gcm_prefs_get_profile_title (profile_tmp);
|
title_tmp = gcm_prefs_get_profile_title (prefs, profile_tmp);
|
||||||
|
|
||||||
/* don't show details for EDID profiles */
|
/* don't show details for EDID profiles */
|
||||||
if (gcm_prefs_profile_is_based_from_edid (profile_tmp))
|
if (gcm_prefs_profile_is_based_from_edid (profile_tmp))
|
||||||
|
@ -1432,7 +1468,7 @@ skip:
|
||||||
|
|
||||||
/* get an existing profile, or create a new one */
|
/* get an existing profile, or create a new one */
|
||||||
iter_tmp_p = get_iter_for_profile (GTK_TREE_MODEL (priv->list_store_devices),
|
iter_tmp_p = get_iter_for_profile (GTK_TREE_MODEL (priv->list_store_devices),
|
||||||
profile_tmp, iter);
|
profile_tmp, iter);
|
||||||
if (iter_tmp_p == NULL)
|
if (iter_tmp_p == NULL)
|
||||||
{
|
{
|
||||||
gtk_tree_store_append (priv->list_store_devices, &iter_tmp, iter);
|
gtk_tree_store_append (priv->list_store_devices, &iter_tmp, iter);
|
||||||
|
@ -1457,7 +1493,8 @@ skip:
|
||||||
/* remove old profiles that no longer exist */
|
/* remove old profiles that no longer exist */
|
||||||
gcm_prefs_device_remove_profiles_phase2 (prefs, iter);
|
gcm_prefs_device_remove_profiles_phase2 (prefs, iter);
|
||||||
out:
|
out:
|
||||||
g_string_free (status, TRUE);
|
if (status != NULL)
|
||||||
|
g_string_free (status, TRUE);
|
||||||
if (profiles != NULL)
|
if (profiles != NULL)
|
||||||
g_ptr_array_unref (profiles);
|
g_ptr_array_unref (profiles);
|
||||||
if (profile != NULL)
|
if (profile != NULL)
|
||||||
|
@ -1496,6 +1533,8 @@ gcm_prefs_device_changed_cb (CdDevice *device, CcColorPanel *prefs)
|
||||||
static void
|
static void
|
||||||
gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
|
gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
|
||||||
{
|
{
|
||||||
|
gboolean ret;
|
||||||
|
GError *error = NULL;
|
||||||
CdDeviceKind kind;
|
CdDeviceKind kind;
|
||||||
const gchar *icon_name;
|
const gchar *icon_name;
|
||||||
const gchar *id;
|
const gchar *id;
|
||||||
|
@ -1504,6 +1543,15 @@ gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
|
||||||
GtkTreeIter parent;
|
GtkTreeIter parent;
|
||||||
CcColorPanelPrivate *priv = prefs->priv;
|
CcColorPanelPrivate *priv = prefs->priv;
|
||||||
|
|
||||||
|
/* get device properties */
|
||||||
|
ret = cd_device_connect_sync (device, priv->cancellable, &error);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
g_warning ("failed to connect to the device: %s", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* get icon */
|
/* get icon */
|
||||||
kind = cd_device_get_kind (device);
|
kind = cd_device_get_kind (device);
|
||||||
icon_name = gcm_prefs_device_kind_to_icon_name (kind);
|
icon_name = gcm_prefs_device_kind_to_icon_name (kind);
|
||||||
|
@ -1532,6 +1580,7 @@ gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
|
||||||
GCM_PREFS_COLUMN_ICON, icon_name,
|
GCM_PREFS_COLUMN_ICON, icon_name,
|
||||||
-1);
|
-1);
|
||||||
gcm_prefs_device_set_model_by_iter (prefs, device, &parent);
|
gcm_prefs_device_set_model_by_iter (prefs, device, &parent);
|
||||||
|
out:
|
||||||
g_free (sort);
|
g_free (sort);
|
||||||
g_free (title);
|
g_free (title);
|
||||||
}
|
}
|
||||||
|
@ -1541,11 +1590,21 @@ gcm_prefs_remove_device (CcColorPanel *prefs, CdDevice *cd_device)
|
||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
|
GError *error = NULL;
|
||||||
const gchar *id;
|
const gchar *id;
|
||||||
gchar *id_tmp;
|
gchar *id_tmp;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
CcColorPanelPrivate *priv = prefs->priv;
|
CcColorPanelPrivate *priv = prefs->priv;
|
||||||
|
|
||||||
|
/* get device properties */
|
||||||
|
ret = cd_device_connect_sync (cd_device, priv->cancellable, &error);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
g_warning ("failed to connect to the device: %s", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* remove */
|
/* remove */
|
||||||
id = cd_device_get_id (cd_device);
|
id = cd_device_get_id (cd_device);
|
||||||
|
|
||||||
|
@ -1559,8 +1618,8 @@ gcm_prefs_remove_device (CcColorPanel *prefs, CdDevice *cd_device)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
gtk_tree_model_get (model, &iter,
|
gtk_tree_model_get (model, &iter,
|
||||||
GCM_PREFS_COLUMN_DEVICE_ID, &id_tmp,
|
GCM_PREFS_COLUMN_DEVICE_ID, &id_tmp,
|
||||||
-1);
|
-1);
|
||||||
if (g_strcmp0 (id_tmp, id) == 0)
|
if (g_strcmp0 (id_tmp, id) == 0)
|
||||||
{
|
{
|
||||||
gtk_list_store_remove (GTK_LIST_STORE(model), &iter);
|
gtk_list_store_remove (GTK_LIST_STORE(model), &iter);
|
||||||
|
@ -1857,6 +1916,36 @@ gcm_prefs_setup_drag_and_drop (GtkWidget *widget)
|
||||||
g_free (entry.target);
|
g_free (entry.target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gcm_prefs_connect_cb (GObject *object,
|
||||||
|
GAsyncResult *res,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
gboolean ret;
|
||||||
|
GError *error = NULL;
|
||||||
|
CcColorPanel *prefs = CC_COLOR_PANEL (user_data);
|
||||||
|
CcColorPanelPrivate *priv = prefs->priv;
|
||||||
|
|
||||||
|
ret = cd_client_connect_finish (priv->client,
|
||||||
|
res,
|
||||||
|
&error);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
g_warning ("failed to connect to colord: %s", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set calibrate button sensitivity */
|
||||||
|
gcm_prefs_sensor_coldplug (prefs);
|
||||||
|
|
||||||
|
/* get devices */
|
||||||
|
cd_client_get_devices (priv->client,
|
||||||
|
priv->cancellable,
|
||||||
|
gcm_prefs_get_devices_cb,
|
||||||
|
prefs);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cc_color_panel_get_property (GObject *object,
|
cc_color_panel_get_property (GObject *object,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
|
@ -1951,8 +2040,6 @@ static void
|
||||||
cc_color_panel_init (CcColorPanel *prefs)
|
cc_color_panel_init (CcColorPanel *prefs)
|
||||||
{
|
{
|
||||||
CcColorPanelPrivate *priv;
|
CcColorPanelPrivate *priv;
|
||||||
gboolean ret;
|
|
||||||
gchar *text = NULL;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GtkStyleContext *context;
|
GtkStyleContext *context;
|
||||||
GtkTreeSelection *selection;
|
GtkTreeSelection *selection;
|
||||||
|
@ -2118,21 +2205,10 @@ cc_color_panel_init (CcColorPanel *prefs)
|
||||||
G_CALLBACK (gcm_prefs_changed_cb), prefs);
|
G_CALLBACK (gcm_prefs_changed_cb), prefs);
|
||||||
|
|
||||||
/* connect to colord */
|
/* connect to colord */
|
||||||
ret = cd_client_connect_sync (priv->client,
|
cd_client_connect (priv->client,
|
||||||
priv->cancellable,
|
priv->cancellable,
|
||||||
&error);
|
gcm_prefs_connect_cb,
|
||||||
if (!ret)
|
prefs);
|
||||||
{
|
|
||||||
g_warning ("failed to connect to colord: %s", error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get devices async */
|
|
||||||
cd_client_get_devices (priv->client,
|
|
||||||
priv->cancellable,
|
|
||||||
gcm_prefs_get_devices_cb,
|
|
||||||
prefs);
|
|
||||||
|
|
||||||
/* use the color sensor */
|
/* use the color sensor */
|
||||||
g_signal_connect (priv->client, "sensor-added",
|
g_signal_connect (priv->client, "sensor-added",
|
||||||
|
@ -2142,11 +2218,7 @@ cc_color_panel_init (CcColorPanel *prefs)
|
||||||
G_CALLBACK (gcm_prefs_client_sensor_changed_cb),
|
G_CALLBACK (gcm_prefs_client_sensor_changed_cb),
|
||||||
prefs);
|
prefs);
|
||||||
|
|
||||||
out:
|
|
||||||
g_free (text);
|
|
||||||
|
|
||||||
/* set calibrate button sensitivity */
|
/* set calibrate button sensitivity */
|
||||||
gcm_prefs_sensor_coldplug (prefs);
|
|
||||||
gcm_prefs_set_calibrate_button_sensitivity (prefs);
|
gcm_prefs_set_calibrate_button_sensitivity (prefs);
|
||||||
|
|
||||||
widget = WID (priv->builder, "dialog-vbox1");
|
widget = WID (priv->builder, "dialog-vbox1");
|
||||||
|
|
Loading…
Add table
Reference in a new issue