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:
Richard Hughes 2011-05-30 22:06:36 +01:00
parent 63c7019e95
commit e51b037b76

View file

@ -351,6 +351,17 @@ gcm_prefs_add_profiles_suitable_for_devices (CcColorPanel *prefs,
if (profile != NULL && cd_profile_equal (profile, profile_tmp))
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 */
ret = gcm_prefs_is_profile_suitable_for_device (profile_tmp,
priv->current_device);
@ -599,7 +610,7 @@ gcm_prefs_delete_cb (GtkWidget *widget, CcColorPanel *prefs)
/* try to delete device */
ret = cd_client_delete_device_sync (priv->client,
cd_device_get_id (priv->current_device),
priv->current_device,
priv->cancellable,
&error);
if (!ret)
@ -821,7 +832,7 @@ gcm_prefs_profile_clicked (CcColorPanel *prefs, CdProfile *profile, CdDevice *de
/* find the profile relationship */
relation = cd_device_get_profile_relation (device,
relation = cd_device_get_profile_relation_sync (device,
profile,
NULL, NULL);
@ -1046,8 +1057,6 @@ out:
g_object_unref (profile);
}
static void
gcm_prefs_sensor_coldplug (CcColorPanel *prefs)
{
@ -1200,14 +1209,28 @@ out:
}
static gchar *
gcm_prefs_get_profile_title (CdProfile *profile)
gcm_prefs_get_profile_title (CcColorPanel *prefs, CdProfile *profile)
{
CdColorspace colorspace;
const gchar *title;
gchar *string;
gboolean ret;
GError *error = NULL;
CcColorPanelPrivate *priv = prefs->priv;
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 */
title = cd_profile_get_title (profile);
if (title != NULL)
@ -1323,12 +1346,12 @@ out:
static void
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 *tooltip = NULL;
CdProfile *profile = NULL;
gint age;
GPtrArray *profiles;
GPtrArray *profiles = NULL;
CdProfile *profile_tmp;
guint i;
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_p;
guint threshold = 0;
gboolean ret;
GError *error = NULL;
CcColorPanelPrivate *priv = prefs->priv;
/* set status */
@ -1350,6 +1375,17 @@ gcm_prefs_device_set_model_by_iter (CcColorPanel *prefs, CdDevice *device, GtkTr
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 */
if (cd_device_get_kind (device) == CD_DEVICE_KIND_PRINTER &&
cd_profile_get_filename (profile) == NULL)
@ -1415,7 +1451,7 @@ skip:
for (i = 0; i < profiles->len; 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 */
if (gcm_prefs_profile_is_based_from_edid (profile_tmp))
@ -1457,6 +1493,7 @@ skip:
/* remove old profiles that no longer exist */
gcm_prefs_device_remove_profiles_phase2 (prefs, iter);
out:
if (status != NULL)
g_string_free (status, TRUE);
if (profiles != NULL)
g_ptr_array_unref (profiles);
@ -1496,6 +1533,8 @@ gcm_prefs_device_changed_cb (CdDevice *device, CcColorPanel *prefs)
static void
gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
{
gboolean ret;
GError *error = NULL;
CdDeviceKind kind;
const gchar *icon_name;
const gchar *id;
@ -1504,6 +1543,15 @@ gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
GtkTreeIter parent;
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 */
kind = cd_device_get_kind (device);
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,
-1);
gcm_prefs_device_set_model_by_iter (prefs, device, &parent);
out:
g_free (sort);
g_free (title);
}
@ -1541,11 +1590,21 @@ gcm_prefs_remove_device (CcColorPanel *prefs, CdDevice *cd_device)
{
GtkTreeIter iter;
GtkTreeModel *model;
GError *error = NULL;
const gchar *id;
gchar *id_tmp;
gboolean ret;
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 */
id = cd_device_get_id (cd_device);
@ -1857,6 +1916,36 @@ gcm_prefs_setup_drag_and_drop (GtkWidget *widget)
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
cc_color_panel_get_property (GObject *object,
guint property_id,
@ -1951,8 +2040,6 @@ static void
cc_color_panel_init (CcColorPanel *prefs)
{
CcColorPanelPrivate *priv;
gboolean ret;
gchar *text = NULL;
GError *error = NULL;
GtkStyleContext *context;
GtkTreeSelection *selection;
@ -2118,20 +2205,9 @@ cc_color_panel_init (CcColorPanel *prefs)
G_CALLBACK (gcm_prefs_changed_cb), prefs);
/* connect to colord */
ret = cd_client_connect_sync (priv->client,
cd_client_connect (priv->client,
priv->cancellable,
&error);
if (!ret)
{
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,
gcm_prefs_connect_cb,
prefs);
/* use the color sensor */
@ -2142,11 +2218,7 @@ cc_color_panel_init (CcColorPanel *prefs)
G_CALLBACK (gcm_prefs_client_sensor_changed_cb),
prefs);
out:
g_free (text);
/* set calibrate button sensitivity */
gcm_prefs_sensor_coldplug (prefs);
gcm_prefs_set_calibrate_button_sensitivity (prefs);
widget = WID (priv->builder, "dialog-vbox1");