color: Use g_auto for variables

This commit is contained in:
Robert Ancell 2018-05-30 15:44:04 +12:00
parent 04e36953ff
commit 490bee5a23
5 changed files with 176 additions and 358 deletions

View file

@ -226,23 +226,21 @@ cc_color_calibrate_calib_set_output_gamma (CcColorCalibrate *calibrate,
CdColorRGB *p1; CdColorRGB *p1;
CdColorRGB *p2; CdColorRGB *p2;
CdColorRGB result; CdColorRGB result;
gboolean ret = TRUE;
gdouble mix; gdouble mix;
GnomeRRCrtc *crtc; GnomeRRCrtc *crtc;
guint16 *blue = NULL; g_autofree guint16 *blue = NULL;
guint16 *green = NULL; g_autofree guint16 *green = NULL;
guint16 *red = NULL; g_autofree guint16 *red = NULL;
guint i; guint i;
/* no length? */ /* no length? */
if (array->len == 0) if (array->len == 0)
{ {
ret = FALSE;
g_set_error_literal (error, g_set_error_literal (error,
CD_SESSION_ERROR, CD_SESSION_ERROR,
CD_SESSION_ERROR_INTERNAL, CD_SESSION_ERROR_INTERNAL,
"no data in the CLUT array"); "no data in the CLUT array");
goto out; return FALSE;
} }
/* convert to a type X understands of the right size */ /* convert to a type X understands of the right size */
@ -270,21 +268,16 @@ cc_color_calibrate_calib_set_output_gamma (CcColorCalibrate *calibrate,
crtc = gnome_rr_output_get_crtc (calibrate->output); crtc = gnome_rr_output_get_crtc (calibrate->output);
if (crtc == NULL) if (crtc == NULL)
{ {
ret = FALSE;
g_set_error (error, g_set_error (error,
CD_SESSION_ERROR, CD_SESSION_ERROR,
CD_SESSION_ERROR_INTERNAL, CD_SESSION_ERROR_INTERNAL,
"failed to get ctrc for %s", "failed to get ctrc for %s",
gnome_rr_output_get_name (calibrate->output)); gnome_rr_output_get_name (calibrate->output));
goto out; return FALSE;
} }
gnome_rr_crtc_set_gamma (crtc, calibrate->gamma_size, gnome_rr_crtc_set_gamma (crtc, calibrate->gamma_size,
red, green, blue); red, green, blue);
out: return TRUE;
g_free (red);
g_free (green);
g_free (blue);
return ret;
} }
static void static void
@ -317,7 +310,6 @@ cc_color_calibrate_interaction_required (CcColorCalibrate *calibrate,
{ {
const gchar *message_transl; const gchar *message_transl;
gboolean show_button_start = FALSE; gboolean show_button_start = FALSE;
GdkPixbuf *pixbuf;
GtkImage *img; GtkImage *img;
GtkLabel *label; GtkLabel *label;
GtkWidget *widget; GtkWidget *widget;
@ -331,15 +323,14 @@ cc_color_calibrate_interaction_required (CcColorCalibrate *calibrate,
"image_status")); "image_status"));
if (image_path != NULL && image_path[0] != '\0') if (image_path != NULL && image_path[0] != '\0')
{ {
g_autoptr(GdkPixbuf) pixbuf = NULL;
g_debug ("showing image %s", image_path); g_debug ("showing image %s", image_path);
pixbuf = gdk_pixbuf_new_from_file_at_size (image_path, pixbuf = gdk_pixbuf_new_from_file_at_size (image_path,
400, 400, 400, 400,
NULL); NULL);
if (pixbuf != NULL) if (pixbuf != NULL)
{
gtk_image_set_from_pixbuf (img, pixbuf); gtk_image_set_from_pixbuf (img, pixbuf);
g_object_unref (pixbuf);
}
gtk_widget_set_visible (GTK_WIDGET (img), TRUE); gtk_widget_set_visible (GTK_WIDGET (img), TRUE);
gtk_widget_set_visible (GTK_WIDGET (calibrate->sample_widget), FALSE); gtk_widget_set_visible (GTK_WIDGET (calibrate->sample_widget), FALSE);
} }
@ -436,7 +427,7 @@ cc_color_calibrate_finished (CcColorCalibrate *calibrate,
const gchar *error_fallback) const gchar *error_fallback)
{ {
GtkWidget *widget; GtkWidget *widget;
GString *str; g_autoptr(GString) str = NULL;
const gchar *tmp; const gchar *tmp;
/* save failure so we can get this after we've quit the loop */ /* save failure so we can get this after we've quit the loop */
@ -481,7 +472,6 @@ cc_color_calibrate_finished (CcColorCalibrate *calibrate,
widget = GTK_WIDGET (gtk_builder_get_object (calibrate->builder, widget = GTK_WIDGET (gtk_builder_get_object (calibrate->builder,
"label_status")); "label_status"));
gtk_label_set_label (GTK_LABEL (widget), str->str); gtk_label_set_label (GTK_LABEL (widget), str->str);
g_string_free (str, TRUE);
} }
static void static void
@ -498,12 +488,11 @@ cc_color_calibrate_signal_cb (GDBusProxy *proxy,
const gchar *profile_path = NULL; const gchar *profile_path = NULL;
const gchar *str = NULL; const gchar *str = NULL;
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
GPtrArray *array = NULL; GPtrArray *array = NULL;
GtkImage *img; GtkImage *img;
GtkLabel *label; GtkLabel *label;
GVariantIter *iter; g_autoptr(GVariant) dict = NULL;
GVariant *dict = NULL;
if (g_strcmp0 (signal_name, "Finished") == 0) if (g_strcmp0 (signal_name, "Finished") == 0)
{ {
@ -517,7 +506,7 @@ cc_color_calibrate_signal_cb (GDBusProxy *proxy,
if (ret) if (ret)
calibrate->profile = cd_profile_new_with_object_path (profile_path); calibrate->profile = cd_profile_new_with_object_path (profile_path);
cc_color_calibrate_finished (calibrate, error_code, str); cc_color_calibrate_finished (calibrate, error_code, str);
goto out; return;
} }
if (g_strcmp0 (signal_name, "UpdateSample") == 0) if (g_strcmp0 (signal_name, "UpdateSample") == 0)
{ {
@ -548,7 +537,7 @@ cc_color_calibrate_signal_cb (GDBusProxy *proxy,
* display off the screen (although we do cope if this is * display off the screen (although we do cope if this is
* detected early enough) */ * detected early enough) */
gtk_label_set_label (label, _("Do not disturb the calibration device while in progress")); gtk_label_set_label (label, _("Do not disturb the calibration device while in progress"));
goto out; return;
} }
if (g_strcmp0 (signal_name, "InteractionRequired") == 0) if (g_strcmp0 (signal_name, "InteractionRequired") == 0)
{ {
@ -564,10 +553,12 @@ cc_color_calibrate_signal_cb (GDBusProxy *proxy,
code, code,
message, message,
image); image);
goto out; return;
} }
if (g_strcmp0 (signal_name, "UpdateGamma") == 0) if (g_strcmp0 (signal_name, "UpdateGamma") == 0)
{ {
g_autoptr(GVariantIter) iter = NULL;
g_variant_get (parameters, g_variant_get (parameters,
"(a(ddd))", "(a(ddd))",
&iter); &iter);
@ -581,7 +572,6 @@ cc_color_calibrate_signal_cb (GDBusProxy *proxy,
cd_color_rgb_copy (&color, color_tmp); cd_color_rgb_copy (&color, color_tmp);
g_ptr_array_add (array, color_tmp); g_ptr_array_add (array, color_tmp);
} }
g_variant_iter_free (iter);
ret = cc_color_calibrate_calib_set_output_gamma (calibrate, ret = cc_color_calibrate_calib_set_output_gamma (calibrate,
array, array,
&error); &error);
@ -589,22 +579,18 @@ cc_color_calibrate_signal_cb (GDBusProxy *proxy,
{ {
g_warning ("failed to update gamma: %s", g_warning ("failed to update gamma: %s",
error->message); error->message);
g_error_free (error); return;
goto out;
} }
goto out; return;
} }
g_warning ("got unknown signal %s", signal_name); g_warning ("got unknown signal %s", signal_name);
out:
if (dict != NULL)
g_variant_unref (dict);
} }
static void static void
cc_color_calibrate_cancel (CcColorCalibrate *calibrate) cc_color_calibrate_cancel (CcColorCalibrate *calibrate)
{ {
GVariant *retval; g_autoptr(GVariant) retval = NULL;
GError *error = NULL; g_autoptr(GError) error = NULL;
/* cancel the calibration to ensure the helper quits */ /* cancel the calibration to ensure the helper quits */
retval = g_dbus_proxy_call_sync (calibrate->proxy_helper, retval = g_dbus_proxy_call_sync (calibrate->proxy_helper,
@ -615,15 +601,10 @@ cc_color_calibrate_cancel (CcColorCalibrate *calibrate)
NULL, NULL,
&error); &error);
if (retval == NULL) if (retval == NULL)
{
g_warning ("Failed to send Cancel: %s", error->message); g_warning ("Failed to send Cancel: %s", error->message);
g_error_free (error);
}
/* return */ /* return */
g_main_loop_quit (calibrate->loop); g_main_loop_quit (calibrate->loop);
if (retval != NULL)
g_variant_unref (retval);
} }
static gboolean static gboolean
@ -690,7 +671,7 @@ cc_color_calibrate_window_state_cb (GtkWidget *widget,
CcColorCalibrate *calibrate) CcColorCalibrate *calibrate)
{ {
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
GdkEventWindowState *event_state = (GdkEventWindowState *) event; GdkEventWindowState *event_state = (GdkEventWindowState *) event;
GtkWindow *window = GTK_WINDOW (widget); GtkWindow *window = GTK_WINDOW (widget);
@ -705,10 +686,7 @@ cc_color_calibrate_window_state_cb (GtkWidget *widget,
calibrate->device, calibrate->device,
&error); &error);
if (!ret) if (!ret)
{
g_warning ("Failed to resize window: %s", error->message); g_warning ("Failed to resize window: %s", error->message);
g_error_free (error);
}
return TRUE; return TRUE;
} }
@ -723,8 +701,8 @@ static void
cc_color_calibrate_button_start_cb (GtkWidget *widget, cc_color_calibrate_button_start_cb (GtkWidget *widget,
CcColorCalibrate *calibrate) CcColorCalibrate *calibrate)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
GVariant *retval; g_autoptr(GVariant) retval = NULL;
/* set correct buttons */ /* set correct buttons */
widget = GTK_WIDGET (gtk_builder_get_object (calibrate->builder, widget = GTK_WIDGET (gtk_builder_get_object (calibrate->builder,
@ -743,12 +721,7 @@ cc_color_calibrate_button_start_cb (GtkWidget *widget,
NULL, NULL,
&error); &error);
if (retval == NULL) if (retval == NULL)
{
g_warning ("Failed to send Resume: %s", error->message); g_warning ("Failed to send Resume: %s", error->message);
g_error_free (error);
}
if (retval != NULL)
g_variant_unref (retval);
} }
static void static void
@ -811,10 +784,10 @@ cc_color_calibrate_uninhibit (CcColorCalibrate *calibrate)
static void static void
cc_color_calibrate_inhibit (CcColorCalibrate *calibrate, GtkWindow *window) cc_color_calibrate_inhibit (CcColorCalibrate *calibrate, GtkWindow *window)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
gint idx; gint idx;
GUnixFDList *fd_list = NULL; g_autoptr(GUnixFDList) fd_list = NULL;
GVariant *retval; g_autoptr(GVariant) retval = NULL;
GtkApplication *application; GtkApplication *application;
/* inhibit basically everything we can */ /* inhibit basically everything we can */
@ -847,23 +820,16 @@ cc_color_calibrate_inhibit (CcColorCalibrate *calibrate, GtkWindow *window)
if (retval == NULL) if (retval == NULL)
{ {
g_warning ("Failed to send Inhibit: %s", error->message); g_warning ("Failed to send Inhibit: %s", error->message);
g_error_free (error); return;
goto out;
} }
g_variant_get (retval, "(h)", &idx); g_variant_get (retval, "(h)", &idx);
calibrate->inhibit_fd = g_unix_fd_list_get (fd_list, idx, &error); calibrate->inhibit_fd = g_unix_fd_list_get (fd_list, idx, &error);
if (calibrate->inhibit_fd == -1) if (calibrate->inhibit_fd == -1)
{ {
g_warning ("Failed to receive system inhibitor fd: %s", error->message); g_warning ("Failed to receive system inhibitor fd: %s", error->message);
g_error_free (error); return;
goto out;
} }
g_debug ("System inhibitor fd is %d", calibrate->inhibit_fd); g_debug ("System inhibitor fd is %d", calibrate->inhibit_fd);
out:
if (fd_list != NULL)
g_object_unref (fd_list);
if (retval != NULL)
g_variant_unref (retval);
} }
gboolean gboolean
@ -920,20 +886,18 @@ cc_color_calibrate_start (CcColorCalibrate *calibrate,
GError **error) GError **error)
{ {
const gchar *name; const gchar *name;
gboolean ret;
GtkWidget *widget; GtkWidget *widget;
GtkWindow *window; GtkWindow *window;
GVariantBuilder builder; GVariantBuilder builder;
GVariant *retval = NULL; g_autoptr(GVariant) retval = NULL;
g_return_val_if_fail (CC_IS_COLOR_CALIBRATE (calibrate), FALSE); g_return_val_if_fail (CC_IS_COLOR_CALIBRATE (calibrate), FALSE);
/* get screen */ /* get screen */
name = cd_device_get_metadata_item (calibrate->device, name = cd_device_get_metadata_item (calibrate->device,
CD_DEVICE_METADATA_XRANDR_NAME); CD_DEVICE_METADATA_XRANDR_NAME);
ret = cc_color_calibrate_calib_setup_screen (calibrate, name, error); if (!cc_color_calibrate_calib_setup_screen (calibrate, name, error))
if (!ret) return FALSE;
goto out;
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
g_variant_builder_add (&builder, g_variant_builder_add (&builder,
@ -967,10 +931,7 @@ cc_color_calibrate_start (CcColorCalibrate *calibrate,
NULL, NULL,
error); error);
if (retval == NULL) if (retval == NULL)
{ return FALSE;
ret = FALSE;
goto out;
}
/* set this above our parent */ /* set this above our parent */
window = GTK_WINDOW (gtk_builder_get_object (calibrate->builder, window = GTK_WINDOW (gtk_builder_get_object (calibrate->builder,
@ -1004,16 +965,14 @@ cc_color_calibrate_start (CcColorCalibrate *calibrate,
/* see if we failed */ /* see if we failed */
if (calibrate->session_error_code != CD_SESSION_ERROR_NONE) if (calibrate->session_error_code != CD_SESSION_ERROR_NONE)
{ {
ret = FALSE;
g_set_error_literal (error, g_set_error_literal (error,
CD_SESSION_ERROR, CD_SESSION_ERROR,
CD_SESSION_ERROR_INTERNAL, CD_SESSION_ERROR_INTERNAL,
"failed to calibrate"); "failed to calibrate");
return FALSE;
} }
out:
if (retval != NULL) return TRUE;
g_variant_unref (retval);
return ret;
} }
static gboolean static gboolean
@ -1054,9 +1013,9 @@ cc_color_calibrate_class_init (CcColorCalibrateClass *klass)
static void static void
cc_color_calibrate_init (CcColorCalibrate *calibrate) cc_color_calibrate_init (CcColorCalibrate *calibrate)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
gint retval; gint retval;
GSettings *settings; g_autoptr(GSettings) settings = NULL;
GtkBox *box; GtkBox *box;
GtkWidget *widget; GtkWidget *widget;
GtkWindow *window; GtkWindow *window;
@ -1070,10 +1029,7 @@ cc_color_calibrate_init (CcColorCalibrate *calibrate)
"/org/gnome/control-center/color/color-calibrate.ui", "/org/gnome/control-center/color/color-calibrate.ui",
&error); &error);
if (retval == 0) if (retval == 0)
{
g_warning ("Could not load interface: %s", error->message); g_warning ("Could not load interface: %s", error->message);
g_error_free (error);
}
/* add sample widget */ /* add sample widget */
box = GTK_BOX (gtk_builder_get_object (calibrate->builder, box = GTK_BOX (gtk_builder_get_object (calibrate->builder,
@ -1089,7 +1045,6 @@ cc_color_calibrate_init (CcColorCalibrate *calibrate)
settings = g_settings_new (COLORD_SETTINGS_SCHEMA); settings = g_settings_new (COLORD_SETTINGS_SCHEMA);
calibrate->target_whitepoint = g_settings_get_int (settings, "display-whitepoint"); calibrate->target_whitepoint = g_settings_get_int (settings, "display-whitepoint");
calibrate->target_gamma = g_settings_get_double (settings, "display-gamma"); calibrate->target_gamma = g_settings_get_double (settings, "display-gamma");
g_object_unref (settings);
/* connect to buttons */ /* connect to buttons */
widget = GTK_WIDGET (gtk_builder_get_object (calibrate->builder, widget = GTK_WIDGET (gtk_builder_get_object (calibrate->builder,

View file

@ -108,13 +108,9 @@ cc_color_device_kind_to_sort (CdDevice *device)
gchar * gchar *
cc_color_device_get_sortable_base (CdDevice *device) cc_color_device_get_sortable_base (CdDevice *device)
{ {
gchar *sortable; g_autofree gchar *title = cc_color_device_get_title (device);
gchar *title; return g_strdup_printf ("%s-%s-%s",
title = cc_color_device_get_title (device);
sortable = g_strdup_printf ("%s-%s-%s",
cc_color_device_kind_to_sort (device), cc_color_device_kind_to_sort (device),
cd_device_get_id (device), cd_device_get_id (device),
title); title);
g_free (title);
return sortable;
} }

View file

@ -62,15 +62,16 @@ static guint signals [SIGNAL_LAST] = { 0 };
static void static void
cc_color_device_refresh (CcColorDevice *color_device) cc_color_device_refresh (CcColorDevice *color_device)
{ {
gchar *title = NULL; g_autofree gchar *title = NULL;
GPtrArray *profiles = NULL; g_autoptr(GPtrArray) profiles = NULL;
AtkObject *accessible; AtkObject *accessible;
gchar *name = NULL; g_autofree gchar *name1 = NULL;
g_autofree gchar *name2 = NULL;
/* add switch and expander if there are profiles, otherwise use a label */ /* add switch and expander if there are profiles, otherwise use a label */
profiles = cd_device_get_profiles (color_device->device); profiles = cd_device_get_profiles (color_device->device);
if (profiles == NULL) if (profiles == NULL)
goto out; return;
title = cc_color_device_get_title (color_device->device); title = cc_color_device_get_title (color_device->device);
gtk_label_set_label (GTK_LABEL (color_device->widget_description), title); gtk_label_set_label (GTK_LABEL (color_device->widget_description), title);
@ -87,19 +88,12 @@ cc_color_device_refresh (CcColorDevice *color_device)
cd_device_get_enabled (color_device->device)); cd_device_get_enabled (color_device->device));
accessible = gtk_widget_get_accessible (color_device->widget_switch); accessible = gtk_widget_get_accessible (color_device->widget_switch);
name = g_strdup_printf (_("Enable color management for %s"), title); name1 = g_strdup_printf (_("Enable color management for %s"), title);
atk_object_set_name (accessible, name); atk_object_set_name (accessible, name1);
g_free (name);
name = g_strdup_printf (_("Show color profiles for %s"), title); name2 = g_strdup_printf (_("Show color profiles for %s"), title);
accessible = gtk_widget_get_accessible (color_device->widget_button); accessible = gtk_widget_get_accessible (color_device->widget_button);
atk_object_set_name (accessible, name); atk_object_set_name (accessible, name2);
g_free (name);
out:
if (profiles != NULL)
g_ptr_array_unref (profiles);
g_free (title);
} }
CdDevice * CdDevice *
@ -187,18 +181,15 @@ cc_color_device_notify_enable_device_cb (GtkSwitch *sw,
CcColorDevice *color_device = CC_COLOR_DEVICE (user_data); CcColorDevice *color_device = CC_COLOR_DEVICE (user_data);
gboolean enable; gboolean enable;
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
enable = gtk_switch_get_active (sw); enable = gtk_switch_get_active (sw);
g_debug ("Set %s to %i", cd_device_get_id (color_device->device), enable); g_debug ("Set %s to %i", cd_device_get_id (color_device->device), enable);
ret = cd_device_set_enabled_sync (color_device->device, ret = cd_device_set_enabled_sync (color_device->device,
enable, NULL, &error); enable, NULL, &error);
if (!ret) if (!ret)
{
g_warning ("failed to %s to the device: %s", g_warning ("failed to %s to the device: %s",
enable ? "enable" : "disable", error->message); enable ? "enable" : "disable", error->message);
g_error_free (error);
}
/* if expanded, close */ /* if expanded, close */
cc_color_device_set_expanded (color_device, FALSE); cc_color_device_set_expanded (color_device, FALSE);
@ -215,7 +206,7 @@ static void
cc_color_device_constructed (GObject *object) cc_color_device_constructed (GObject *object)
{ {
CcColorDevice *color_device = CC_COLOR_DEVICE (object); CcColorDevice *color_device = CC_COLOR_DEVICE (object);
gchar *sortable_tmp; g_autofree gchar *sortable_tmp = NULL;
/* watch the device for changes */ /* watch the device for changes */
color_device->device_changed_id = color_device->device_changed_id =
@ -227,7 +218,6 @@ cc_color_device_constructed (GObject *object)
* https://bugzilla.gnome.org/show_bug.cgi?id=691341 */ * https://bugzilla.gnome.org/show_bug.cgi?id=691341 */
sortable_tmp = cc_color_device_get_sortable_base (color_device->device); sortable_tmp = cc_color_device_get_sortable_base (color_device->device);
color_device->sortable = g_strdup_printf ("%sXX", sortable_tmp); color_device->sortable = g_strdup_printf ("%sXX", sortable_tmp);
g_free (sortable_tmp);
cc_color_device_refresh (color_device); cc_color_device_refresh (color_device);

View file

@ -113,7 +113,7 @@ gcm_prefs_combobox_add_profile (CcColorPanel *prefs,
{ {
const gchar *id; const gchar *id;
GtkTreeIter iter_tmp; GtkTreeIter iter_tmp;
GString *string; g_autoptr(GString) string = NULL;
GtkListStore *list_store; GtkListStore *list_store;
gchar *escaped = NULL; gchar *escaped = NULL;
guint kind = 0; guint kind = 0;
@ -173,36 +173,27 @@ gcm_prefs_combobox_add_profile (CcColorPanel *prefs,
GCM_PREFS_COMBO_COLUMN_TYPE, kind, GCM_PREFS_COMBO_COLUMN_TYPE, kind,
GCM_PREFS_COMBO_COLUMN_WARNING_FILENAME, warning, GCM_PREFS_COMBO_COLUMN_WARNING_FILENAME, warning,
-1); -1);
g_string_free (string, TRUE);
} }
static void static void
gcm_prefs_default_cb (GtkWidget *widget, CcColorPanel *prefs) gcm_prefs_default_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
CdProfile *profile; g_autoptr(CdProfile) profile = NULL;
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
/* TODO: check if the profile is already systemwide */ /* TODO: check if the profile is already systemwide */
profile = cd_device_get_default_profile (prefs->current_device); profile = cd_device_get_default_profile (prefs->current_device);
if (profile == NULL) if (profile == NULL)
goto out; return;
/* install somewhere out of $HOME */ /* install somewhere out of $HOME */
ret = cd_profile_install_system_wide_sync (profile, ret = cd_profile_install_system_wide_sync (profile,
prefs->cancellable, prefs->cancellable,
&error); &error);
if (!ret) if (!ret)
{
g_warning ("failed to set profile system-wide: %s", g_warning ("failed to set profile system-wide: %s",
error->message); error->message);
g_error_free (error);
goto out;
}
out:
if (profile != NULL)
g_object_unref (profile);
} }
static GFile * static GFile *
@ -298,7 +289,7 @@ static void
gcm_prefs_calib_apply_cb (GtkWidget *widget, CcColorPanel *prefs) gcm_prefs_calib_apply_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
GtkWindow *window = NULL; GtkWindow *window = NULL;
/* setup the calibration object with items that can fail */ /* setup the calibration object with items that can fail */
@ -310,8 +301,7 @@ gcm_prefs_calib_apply_cb (GtkWidget *widget, CcColorPanel *prefs)
if (!ret) if (!ret)
{ {
g_warning ("failed to setup calibrate: %s", error->message); g_warning ("failed to setup calibrate: %s", error->message);
g_error_free (error); return;
goto out;
} }
/* actually start the calibration */ /* actually start the calibration */
@ -323,16 +313,13 @@ gcm_prefs_calib_apply_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
g_warning ("failed to start calibrate: %s", error->message); g_warning ("failed to start calibrate: %s", error->message);
gtk_widget_hide (GTK_WIDGET (window)); gtk_widget_hide (GTK_WIDGET (window));
g_error_free (error); return;
goto out;
} }
/* if we are a LiveCD then don't close the window as there is another /* if we are a LiveCD then don't close the window as there is another
* summary pane with the export button */ * summary pane with the export button */
if (!prefs->is_live_cd) if (!prefs->is_live_cd)
gtk_widget_hide (GTK_WIDGET (window)); gtk_widget_hide (GTK_WIDGET (window));
out:
return;
} }
static gboolean static gboolean
@ -506,7 +493,7 @@ gcm_prefs_calib_sensor_treeview_clicked_cb (GtkTreeSelection *selection,
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel *model; GtkTreeModel *model;
GtkWidget *widget; GtkWidget *widget;
CdSensor *sensor; g_autoptr(CdSensor) sensor = NULL;
GtkAssistant *assistant; GtkAssistant *assistant;
/* check to see if anything is selected */ /* check to see if anything is selected */
@ -523,7 +510,6 @@ gcm_prefs_calib_sensor_treeview_clicked_cb (GtkTreeSelection *selection,
COLUMN_CALIB_SENSOR_OBJECT, &sensor, COLUMN_CALIB_SENSOR_OBJECT, &sensor,
-1); -1);
gcm_prefs_calib_set_sensor (prefs, sensor); gcm_prefs_calib_set_sensor (prefs, sensor);
g_object_unref (sensor);
} }
static void static void
@ -608,9 +594,9 @@ static void
gcm_prefs_calibrate_cb (GtkWidget *widget, CcColorPanel *prefs) gcm_prefs_calibrate_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
guint xid; guint xid;
GPtrArray *argv; g_autoptr(GPtrArray) argv = NULL;
/* use the new-style calibration helper */ /* use the new-style calibration helper */
if (cd_device_get_kind (prefs->current_device) == CD_DEVICE_KIND_DISPLAY) if (cd_device_get_kind (prefs->current_device) == CD_DEVICE_KIND_DISPLAY)
@ -633,11 +619,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, CcColorPanel *prefs)
ret = g_spawn_async (NULL, (gchar**) argv->pdata, NULL, 0, ret = g_spawn_async (NULL, (gchar**) argv->pdata, NULL, 0,
NULL, NULL, NULL, &error); NULL, NULL, NULL, &error);
if (!ret) if (!ret)
{
g_warning ("failed to run calibrate: %s", error->message); g_warning ("failed to run calibrate: %s", error->message);
g_error_free (error);
}
g_ptr_array_unref (argv);
} }
static gboolean static gboolean
@ -701,9 +683,8 @@ gcm_prefs_combo_sort_func_cb (GtkTreeModel *model,
gpointer user_data) gpointer user_data)
{ {
gint type_a, type_b; gint type_a, type_b;
gchar *text_a; g_autofree gchar *text_a = NULL;
gchar *text_b; g_autofree gchar *text_b = NULL;
gint retval;
/* get data from model */ /* get data from model */
gtk_tree_model_get (model, a, gtk_tree_model_get (model, a,
@ -717,15 +698,11 @@ gcm_prefs_combo_sort_func_cb (GtkTreeModel *model,
/* prefer normal type profiles over the 'Other Profile...' entry */ /* prefer normal type profiles over the 'Other Profile...' entry */
if (type_a < type_b) if (type_a < type_b)
retval = -1; return -1;
else if (type_a > type_b) else if (type_a > type_b)
retval = 1; return 1;
else else
retval = g_strcmp0 (text_a, text_b); return g_strcmp0 (text_a, text_b);
g_free (text_a);
g_free (text_b);
return retval;
} }
static gboolean static gboolean
@ -749,8 +726,8 @@ gcm_prefs_add_profiles_suitable_for_devices (CcColorPanel *prefs,
{ {
CdProfile *profile_tmp; CdProfile *profile_tmp;
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
GPtrArray *profile_array = NULL; g_autoptr(GPtrArray) profile_array = NULL;
GtkTreeIter iter; GtkTreeIter iter;
GtkListStore *list_store; GtkListStore *list_store;
GtkWidget *widget; GtkWidget *widget;
@ -779,8 +756,7 @@ gcm_prefs_add_profiles_suitable_for_devices (CcColorPanel *prefs,
{ {
g_warning ("failed to get profiles: %s", g_warning ("failed to get profiles: %s",
error->message); error->message);
g_error_free (error); return;
goto out;
} }
/* add profiles of the right kind */ /* add profiles of the right kind */
@ -795,8 +771,7 @@ gcm_prefs_add_profiles_suitable_for_devices (CcColorPanel *prefs,
if (!ret) if (!ret)
{ {
g_warning ("failed to get profile: %s", error->message); g_warning ("failed to get profile: %s", error->message);
g_error_free (error); return;
goto out;
} }
/* don't add any of the already added profiles */ /* don't add any of the already added profiles */
@ -823,9 +798,6 @@ gcm_prefs_add_profiles_suitable_for_devices (CcColorPanel *prefs,
profile_tmp, profile_tmp,
&iter); &iter);
} }
out:
if (profile_array != NULL)
g_ptr_array_unref (profile_array);
} }
static void static void
@ -834,24 +806,23 @@ gcm_prefs_calib_upload_cb (GtkWidget *widget, CcColorPanel *prefs)
CdProfile *profile; CdProfile *profile;
const gchar *uri; const gchar *uri;
gboolean ret; gboolean ret;
gchar *upload_uri = NULL; g_autofree gchar *upload_uri = NULL;
gchar *msg_result = NULL; g_autofree gchar *msg_result = NULL;
gchar *data = NULL; g_autofree gchar *data = NULL;
GError *error = NULL; g_autoptr(GError) error = NULL;
gsize length; gsize length;
guint status_code; guint status_code;
SoupBuffer *buffer = NULL; g_autoptr(SoupBuffer) buffer = NULL;
SoupMessage *msg = NULL; g_autoptr(SoupMessage) msg = NULL;
SoupMultipart *multipart = NULL; g_autoptr(SoupMultipart) multipart = NULL;
SoupSession *session = NULL; g_autoptr(SoupSession) session = NULL;
profile = cc_color_calibrate_get_profile (prefs->calibrate); profile = cc_color_calibrate_get_profile (prefs->calibrate);
ret = cd_profile_connect_sync (profile, NULL, &error); ret = cd_profile_connect_sync (profile, NULL, &error);
if (!ret) if (!ret)
{ {
g_warning ("Failed to get imported profile: %s", error->message); g_warning ("Failed to get imported profile: %s", error->message);
g_error_free (error); return;
goto out;
} }
/* read file */ /* read file */
@ -862,8 +833,7 @@ gcm_prefs_calib_upload_cb (GtkWidget *widget, CcColorPanel *prefs)
if (!ret) if (!ret)
{ {
g_warning ("Failed to read file: %s", error->message); g_warning ("Failed to read file: %s", error->message);
g_error_free (error); return;
goto out;
} }
/* setup the session */ /* setup the session */
@ -873,7 +843,7 @@ gcm_prefs_calib_upload_cb (GtkWidget *widget, CcColorPanel *prefs)
if (session == NULL) if (session == NULL)
{ {
g_warning ("Failed to setup networking"); g_warning ("Failed to setup networking");
goto out; return;
} }
soup_session_add_feature_by_type (session, SOUP_TYPE_PROXY_RESOLVER_DEFAULT); soup_session_add_feature_by_type (session, SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
@ -896,7 +866,7 @@ gcm_prefs_calib_upload_cb (GtkWidget *widget, CcColorPanel *prefs)
msg_result = g_strdup_printf (_("Failed to upload file: %s"), msg->reason_phrase), msg_result = g_strdup_printf (_("Failed to upload file: %s"), msg->reason_phrase),
gtk_label_set_label (GTK_LABEL (widget), msg_result); gtk_label_set_label (GTK_LABEL (widget), msg_result);
gtk_widget_show (widget); gtk_widget_show (widget);
goto out; return;
} }
/* show instructions to the user */ /* show instructions to the user */
@ -919,18 +889,6 @@ gcm_prefs_calib_upload_cb (GtkWidget *widget, CcColorPanel *prefs)
widget = GTK_WIDGET (gtk_builder_get_object (prefs->builder, widget = GTK_WIDGET (gtk_builder_get_object (prefs->builder,
"button_calib_upload")); "button_calib_upload"));
gtk_widget_hide (widget); gtk_widget_hide (widget);
out:
if (session != NULL)
g_object_unref (session);
if (buffer != NULL)
soup_buffer_free (buffer);
if (msg != NULL)
g_object_unref (msg);
if (multipart != NULL)
soup_multipart_free (multipart);
g_free (data);
g_free (upload_uri);
g_free (msg_result);
} }
static void static void
@ -938,12 +896,20 @@ gcm_prefs_calib_export_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
CdProfile *profile; CdProfile *profile;
gboolean ret; gboolean ret;
gchar *default_name = NULL; g_autofree gchar *default_name = NULL;
GError *error = NULL; g_autoptr(GError) error = NULL;
GFile *destination = NULL; g_autoptr(GFile) destination = NULL;
GFile *source = NULL; g_autoptr(GFile) source = NULL;
GtkWidget *dialog; GtkWidget *dialog;
profile = cc_color_calibrate_get_profile (prefs->calibrate);
ret = cd_profile_connect_sync (profile, NULL, &error);
if (!ret)
{
g_warning ("Failed to get imported profile: %s", error->message);
return;
}
/* TRANSLATORS: this is the dialog to save the ICC profile */ /* TRANSLATORS: this is the dialog to save the ICC profile */
dialog = gtk_file_chooser_dialog_new (_("Save Profile"), dialog = gtk_file_chooser_dialog_new (_("Save Profile"),
GTK_WINDOW (prefs->main_window), GTK_WINDOW (prefs->main_window),
@ -953,14 +919,6 @@ gcm_prefs_calib_export_cb (GtkWidget *widget, CcColorPanel *prefs)
NULL); NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
profile = cc_color_calibrate_get_profile (prefs->calibrate);
ret = cd_profile_connect_sync (profile, NULL, &error);
if (!ret)
{
g_warning ("Failed to get imported profile: %s", error->message);
g_error_free (error);
goto out;
}
default_name = g_strdup_printf ("%s.icc", cd_profile_get_title (profile)); default_name = g_strdup_printf ("%s.icc", cd_profile_get_title (profile));
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), default_name); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), default_name);
@ -976,19 +934,10 @@ gcm_prefs_calib_export_cb (GtkWidget *widget, CcColorPanel *prefs)
NULL, NULL,
&error); &error);
if (!ret) if (!ret)
{
g_warning ("Failed to copy profile: %s", error->message); g_warning ("Failed to copy profile: %s", error->message);
g_error_free (error);
goto out;
} }
}
out:
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
g_free (default_name);
if (source != NULL)
g_object_unref (source);
if (destination != NULL)
g_object_unref (destination);
} }
static void static void
@ -1005,7 +954,7 @@ gcm_prefs_calib_export_link_cb (GtkLabel *widget,
static void static void
gcm_prefs_profile_add_cb (GtkWidget *widget, CcColorPanel *prefs) gcm_prefs_profile_add_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
GPtrArray *profiles; g_autoptr(GPtrArray) profiles = NULL;
/* add profiles of the right kind */ /* add profiles of the right kind */
profiles = cd_device_get_profiles (prefs->current_device); profiles = cd_device_get_profiles (prefs->current_device);
@ -1020,8 +969,6 @@ gcm_prefs_profile_add_cb (GtkWidget *widget, CcColorPanel *prefs)
widget = GTK_WIDGET (prefs->dialog_assign); widget = GTK_WIDGET (prefs->dialog_assign);
gtk_widget_show (widget); gtk_widget_show (widget);
gtk_window_set_transient_for (GTK_WINDOW (widget), GTK_WINDOW (prefs->main_window)); gtk_window_set_transient_for (GTK_WINDOW (widget), GTK_WINDOW (prefs->main_window));
if (profiles != NULL)
g_ptr_array_unref (profiles);
} }
static void static void
@ -1029,7 +976,7 @@ gcm_prefs_profile_remove_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
CdProfile *profile; CdProfile *profile;
gboolean ret = FALSE; gboolean ret = FALSE;
GError *error = NULL; g_autoptr(GError) error = NULL;
GtkListBoxRow *row; GtkListBoxRow *row;
/* get the selected profile */ /* get the selected profile */
@ -1049,10 +996,7 @@ gcm_prefs_profile_remove_cb (GtkWidget *widget, CcColorPanel *prefs)
prefs->cancellable, prefs->cancellable,
&error); &error);
if (!ret) if (!ret)
{
g_warning ("failed to remove profile: %s", error->message); g_warning ("failed to remove profile: %s", error->message);
g_error_free (error);
}
} }
static void static void
@ -1062,7 +1006,7 @@ gcm_prefs_make_profile_default_cb (GObject *object,
{ {
CdDevice *device = CD_DEVICE (object); CdDevice *device = CD_DEVICE (object);
gboolean ret = FALSE; gboolean ret = FALSE;
GError *error = NULL; g_autoptr(GError) error = NULL;
ret = cd_device_make_profile_default_finish (device, ret = cd_device_make_profile_default_finish (device,
res, res,
@ -1072,7 +1016,6 @@ gcm_prefs_make_profile_default_cb (GObject *object,
g_warning ("failed to set default profile on %s: %s", g_warning ("failed to set default profile on %s: %s",
cd_device_get_id (device), cd_device_get_id (device),
error->message); error->message);
g_error_free (error);
} }
else else
{ {
@ -1111,10 +1054,10 @@ gcm_prefs_device_profile_enable_cb (GtkWidget *widget, CcColorPanel *prefs)
static void static void
gcm_prefs_profile_view (CcColorPanel *prefs, CdProfile *profile) gcm_prefs_profile_view (CcColorPanel *prefs, CdProfile *profile)
{ {
GPtrArray *argv = NULL; g_autoptr(GPtrArray) argv = NULL;
guint xid; guint xid;
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
/* get xid */ /* get xid */
xid = gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET (prefs->main_window))); xid = gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET (prefs->main_window)));
@ -1130,12 +1073,7 @@ gcm_prefs_profile_view (CcColorPanel *prefs, CdProfile *profile)
ret = g_spawn_async (NULL, (gchar**) argv->pdata, NULL, 0, ret = g_spawn_async (NULL, (gchar**) argv->pdata, NULL, 0,
NULL, NULL, NULL, &error); NULL, NULL, NULL, &error);
if (!ret) if (!ret)
{
g_warning ("failed to run calibrate: %s", error->message); g_warning ("failed to run calibrate: %s", error->message);
g_error_free (error);
}
g_ptr_array_unref (argv);
} }
static void static void
@ -1193,9 +1131,9 @@ gcm_prefs_button_assign_ok_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel *model; GtkTreeModel *model;
CdProfile *profile = NULL; g_autoptr(CdProfile) profile = NULL;
gboolean ret = FALSE; gboolean ret = FALSE;
GError *error = NULL; g_autoptr(GError) error = NULL;
GtkTreeSelection *selection; GtkTreeSelection *selection;
/* hide window */ /* hide window */
@ -1207,14 +1145,14 @@ gcm_prefs_button_assign_ok_cb (GtkWidget *widget, CcColorPanel *prefs)
"treeview_assign")); "treeview_assign"));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
if (!gtk_tree_selection_get_selected (selection, &model, &iter)) if (!gtk_tree_selection_get_selected (selection, &model, &iter))
goto out; return;
gtk_tree_model_get (model, &iter, gtk_tree_model_get (model, &iter,
GCM_PREFS_COMBO_COLUMN_PROFILE, &profile, GCM_PREFS_COMBO_COLUMN_PROFILE, &profile,
-1); -1);
if (profile == NULL) if (profile == NULL)
{ {
g_warning ("failed to get the active profile"); g_warning ("failed to get the active profile");
goto out; return;
} }
/* if the device is disabled, enable the device so that we can /* if the device is disabled, enable the device so that we can
@ -1228,8 +1166,7 @@ gcm_prefs_button_assign_ok_cb (GtkWidget *widget, CcColorPanel *prefs)
if (!ret) if (!ret)
{ {
g_warning ("failed to enabled device: %s", error->message); g_warning ("failed to enabled device: %s", error->message);
g_error_free (error); return;
goto out;
} }
} }
@ -1242,8 +1179,7 @@ gcm_prefs_button_assign_ok_cb (GtkWidget *widget, CcColorPanel *prefs)
if (!ret) if (!ret)
{ {
g_warning ("failed to add: %s", error->message); g_warning ("failed to add: %s", error->message);
g_error_free (error); return;
goto out;
} }
/* make it default */ /* make it default */
@ -1252,9 +1188,6 @@ gcm_prefs_button_assign_ok_cb (GtkWidget *widget, CcColorPanel *prefs)
prefs->cancellable, prefs->cancellable,
(GAsyncReadyCallback) gcm_prefs_make_profile_default_cb, (GAsyncReadyCallback) gcm_prefs_make_profile_default_cb,
prefs); prefs);
out:
if (profile != NULL)
g_object_unref (profile);
} }
static gboolean static gboolean
@ -1387,7 +1320,7 @@ static void
gcm_prefs_profile_clicked (CcColorPanel *prefs, CdProfile *profile, CdDevice *device) gcm_prefs_profile_clicked (CcColorPanel *prefs, CdProfile *profile, CdDevice *device)
{ {
GtkWidget *widget; GtkWidget *widget;
gchar *s; g_autofree gchar *s = NULL;
/* get profile */ /* get profile */
g_debug ("selected profile = %s", g_debug ("selected profile = %s",
@ -1398,10 +1331,7 @@ gcm_prefs_profile_clicked (CcColorPanel *prefs, CdProfile *profile, CdDevice *de
"toolbutton_profile_view")); "toolbutton_profile_view"));
if (cd_profile_get_filename (profile) != NULL && if (cd_profile_get_filename (profile) != NULL &&
(s = g_find_program_in_path ("gcm-viewer")) != NULL) (s = g_find_program_in_path ("gcm-viewer")) != NULL)
{
gtk_widget_set_sensitive (widget, TRUE); gtk_widget_set_sensitive (widget, TRUE);
g_free (s);
}
else else
gtk_widget_set_sensitive (widget, FALSE); gtk_widget_set_sensitive (widget, FALSE);
} }
@ -1413,7 +1343,7 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection,
GtkWidget *widget; GtkWidget *widget;
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
CdProfile *profile = NULL; g_autoptr(CdProfile) profile = NULL;
#if CD_CHECK_VERSION(0,1,25) #if CD_CHECK_VERSION(0,1,25)
gchar **warnings; gchar **warnings;
#endif #endif
@ -1440,7 +1370,6 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection,
#else #else
gtk_widget_set_visible (widget, FALSE); gtk_widget_set_visible (widget, FALSE);
#endif #endif
g_object_unref (profile);
} }
static void static void
@ -1463,9 +1392,9 @@ static void
gcm_prefs_button_assign_import_cb (GtkWidget *widget, gcm_prefs_button_assign_import_cb (GtkWidget *widget,
CcColorPanel *prefs) CcColorPanel *prefs)
{ {
GFile *file = NULL; g_autoptr(GFile) file = NULL;
GError *error = NULL; g_autoptr(GError) error = NULL;
CdProfile *profile = NULL; g_autoptr(CdProfile) profile = NULL;
file = gcm_prefs_file_chooser_get_icc_profile (prefs); file = gcm_prefs_file_chooser_get_icc_profile (prefs);
if (file == NULL) if (file == NULL)
@ -1473,7 +1402,7 @@ gcm_prefs_button_assign_import_cb (GtkWidget *widget,
g_warning ("failed to get ICC file"); g_warning ("failed to get ICC file");
widget = GTK_WIDGET (prefs->dialog_assign); widget = GTK_WIDGET (prefs->dialog_assign);
gtk_widget_hide (widget); gtk_widget_hide (widget);
goto out; return;
} }
#if CD_CHECK_VERSION(0,1,12) #if CD_CHECK_VERSION(0,1,12)
@ -1484,18 +1413,12 @@ gcm_prefs_button_assign_import_cb (GtkWidget *widget,
if (profile == NULL) if (profile == NULL)
{ {
g_warning ("failed to get imported profile: %s", error->message); g_warning ("failed to get imported profile: %s", error->message);
g_error_free (error); return;
goto out;
} }
#endif #endif
/* add to list view */ /* add to list view */
gcm_prefs_profile_add_cb (NULL, prefs); gcm_prefs_profile_add_cb (NULL, prefs);
out:
if (file != NULL)
g_object_unref (file);
if (profile != NULL)
g_object_unref (profile);
} }
static void static void
@ -1503,8 +1426,8 @@ gcm_prefs_sensor_coldplug (CcColorPanel *prefs)
{ {
CdSensor *sensor_tmp; CdSensor *sensor_tmp;
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
GPtrArray *sensors; g_autoptr(GPtrArray) sensors = NULL;
guint i; guint i;
/* unref old */ /* unref old */
@ -1515,11 +1438,10 @@ gcm_prefs_sensor_coldplug (CcColorPanel *prefs)
if (sensors == NULL) if (sensors == NULL)
{ {
g_warning ("%s", error->message); g_warning ("%s", error->message);
g_error_free (error); return;
goto out;
} }
if (sensors->len == 0) if (sensors->len == 0)
goto out; return;
/* save a copy of the sensor list */ /* save a copy of the sensor list */
prefs->sensors = g_ptr_array_ref (sensors); prefs->sensors = g_ptr_array_ref (sensors);
@ -1532,13 +1454,9 @@ gcm_prefs_sensor_coldplug (CcColorPanel *prefs)
if (!ret) if (!ret)
{ {
g_warning ("%s", error->message); g_warning ("%s", error->message);
g_error_free (error); return;
goto out;
} }
} }
out:
if (sensors != NULL)
g_ptr_array_unref (sensors);
} }
static void static void
@ -1557,7 +1475,7 @@ gcm_prefs_add_device_profile (CcColorPanel *prefs,
gboolean is_default) gboolean is_default)
{ {
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
GtkWidget *widget; GtkWidget *widget;
/* get properties */ /* get properties */
@ -1567,8 +1485,7 @@ gcm_prefs_add_device_profile (CcColorPanel *prefs,
if (!ret) if (!ret)
{ {
g_warning ("failed to get profile: %s", error->message); g_warning ("failed to get profile: %s", error->message);
g_error_free (error); return;
goto out;
} }
/* ignore profiles from other user accounts */ /* ignore profiles from other user accounts */
@ -1585,7 +1502,7 @@ gcm_prefs_add_device_profile (CcColorPanel *prefs,
g_warning ("%s is not usable by this user", g_warning ("%s is not usable by this user",
cd_profile_get_id (profile)); cd_profile_get_id (profile));
} }
goto out; return;
} }
/* add to listbox */ /* add to listbox */
@ -1593,29 +1510,24 @@ gcm_prefs_add_device_profile (CcColorPanel *prefs,
gtk_widget_show (widget); gtk_widget_show (widget);
gtk_container_add (GTK_CONTAINER (prefs->list_box), widget); gtk_container_add (GTK_CONTAINER (prefs->list_box), widget);
gtk_size_group_add_widget (prefs->list_box_size, widget); gtk_size_group_add_widget (prefs->list_box_size, widget);
out:
return;
} }
static void static void
gcm_prefs_add_device_profiles (CcColorPanel *prefs, CdDevice *device) gcm_prefs_add_device_profiles (CcColorPanel *prefs, CdDevice *device)
{ {
CdProfile *profile_tmp; CdProfile *profile_tmp;
GPtrArray *profiles = NULL; g_autoptr(GPtrArray) profiles = NULL;
guint i; guint i;
/* add profiles */ /* add profiles */
profiles = cd_device_get_profiles (device); profiles = cd_device_get_profiles (device);
if (profiles == NULL) if (profiles == NULL)
goto out; return;
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);
gcm_prefs_add_device_profile (prefs, device, profile_tmp, i == 0); gcm_prefs_add_device_profile (prefs, device, profile_tmp, i == 0);
} }
out:
if (profiles != NULL)
g_ptr_array_unref (profiles);
} }
/* find the profile in the array -- for flicker-free changes */ /* find the profile in the array -- for flicker-free changes */
@ -1676,7 +1588,7 @@ gcm_prefs_device_changed_cb (CdDevice *device, CcColorPanel *prefs)
CdProfile *profile_tmp; CdProfile *profile_tmp;
gboolean ret; gboolean ret;
GList *l; GList *l;
GList *list; g_autoptr(GList) list = NULL;
GPtrArray *profiles; GPtrArray *profiles;
guint i; guint i;
@ -1715,7 +1627,6 @@ gcm_prefs_device_changed_cb (CdDevice *device, CcColorPanel *prefs)
if (!ret) if (!ret)
gcm_prefs_add_device_profile (prefs, device, profile_tmp, i == 0); gcm_prefs_add_device_profile (prefs, device, profile_tmp, i == 0);
} }
g_list_free (list);
/* resort */ /* resort */
gtk_list_box_invalidate_sort (prefs->list_box); gtk_list_box_invalidate_sort (prefs->list_box);
@ -1726,9 +1637,6 @@ gcm_prefs_device_expanded_changed_cb (CcColorDevice *widget,
gboolean is_expanded, gboolean is_expanded,
CcColorPanel *prefs) CcColorPanel *prefs)
{ {
GList *l;
GList *list;
/* ignore internal changes */ /* ignore internal changes */
if (prefs->model_is_changing) if (prefs->model_is_changing)
return; return;
@ -1736,6 +1644,9 @@ gcm_prefs_device_expanded_changed_cb (CcColorDevice *widget,
g_free (prefs->list_box_filter); g_free (prefs->list_box_filter);
if (is_expanded) if (is_expanded)
{ {
g_autoptr(GList) list = NULL;
GList *l;
prefs->list_box_filter = g_strdup (cd_device_get_id (cc_color_device_get_device (widget))); prefs->list_box_filter = g_strdup (cd_device_get_id (cc_color_device_get_device (widget)));
/* unexpand other device widgets */ /* unexpand other device widgets */
@ -1749,7 +1660,6 @@ gcm_prefs_device_expanded_changed_cb (CcColorDevice *widget,
cc_color_device_set_expanded (CC_COLOR_DEVICE (l->data), FALSE); cc_color_device_set_expanded (CC_COLOR_DEVICE (l->data), FALSE);
} }
prefs->model_is_changing = FALSE; prefs->model_is_changing = FALSE;
g_list_free (list);
} }
else else
{ {
@ -1762,7 +1672,7 @@ static void
gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device) gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
{ {
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
GtkWidget *widget; GtkWidget *widget;
/* get device properties */ /* get device properties */
@ -1770,8 +1680,7 @@ gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
if (!ret) if (!ret)
{ {
g_warning ("failed to connect to the device: %s", error->message); g_warning ("failed to connect to the device: %s", error->message);
g_error_free (error); return;
goto out;
} }
/* add device */ /* add device */
@ -1790,8 +1699,6 @@ gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
g_signal_connect (device, "changed", g_signal_connect (device, "changed",
G_CALLBACK (gcm_prefs_device_changed_cb), prefs); G_CALLBACK (gcm_prefs_device_changed_cb), prefs);
gtk_list_box_invalidate_sort (prefs->list_box); gtk_list_box_invalidate_sort (prefs->list_box);
out:
return;
} }
static void static void
@ -1799,7 +1706,7 @@ gcm_prefs_remove_device (CcColorPanel *prefs, CdDevice *device)
{ {
CdDevice *device_tmp; CdDevice *device_tmp;
GList *l; GList *l;
GList *list; g_autoptr(GList) list = NULL;
list = gtk_container_get_children (GTK_CONTAINER (prefs->list_box)); list = gtk_container_get_children (GTK_CONTAINER (prefs->list_box));
for (l = list; l != NULL; l = l->next) for (l = list; l != NULL; l = l->next)
@ -1814,7 +1721,6 @@ gcm_prefs_remove_device (CcColorPanel *prefs, CdDevice *device)
gtk_widget_destroy (GTK_WIDGET (l->data)); gtk_widget_destroy (GTK_WIDGET (l->data));
} }
} }
g_list_free (list);
g_signal_handlers_disconnect_by_func (device, g_signal_handlers_disconnect_by_func (device,
G_CALLBACK (gcm_prefs_device_changed_cb), G_CALLBACK (gcm_prefs_device_changed_cb),
prefs); prefs);
@ -1824,7 +1730,7 @@ gcm_prefs_remove_device (CcColorPanel *prefs, CdDevice *device)
static void static void
gcm_prefs_update_device_list_extra_entry (CcColorPanel *prefs) gcm_prefs_update_device_list_extra_entry (CcColorPanel *prefs)
{ {
GList *device_widgets; g_autoptr(GList) device_widgets = NULL;
GtkWidget *widget; GtkWidget *widget;
guint number_of_devices; guint number_of_devices;
@ -1841,7 +1747,6 @@ gcm_prefs_update_device_list_extra_entry (CcColorPanel *prefs)
/* if we have only one device expand it by default */ /* if we have only one device expand it by default */
if (number_of_devices == 1) if (number_of_devices == 1)
cc_color_device_set_expanded (CC_COLOR_DEVICE (device_widgets->data), TRUE); cc_color_device_set_expanded (CC_COLOR_DEVICE (device_widgets->data), TRUE);
g_list_free (device_widgets);
} }
static void static void
@ -1876,8 +1781,8 @@ gcm_prefs_get_devices_cb (GObject *object,
CcColorPanel *prefs = (CcColorPanel *) user_data; CcColorPanel *prefs = (CcColorPanel *) user_data;
CdClient *client = CD_CLIENT (object); CdClient *client = CD_CLIENT (object);
CdDevice *device; CdDevice *device;
GError *error = NULL; g_autoptr(GError) error = NULL;
GPtrArray *devices; g_autoptr(GPtrArray) devices = NULL;
guint i; guint i;
/* get devices and add them */ /* get devices and add them */
@ -1886,8 +1791,7 @@ gcm_prefs_get_devices_cb (GObject *object,
{ {
g_warning ("failed to add connected devices: %s", g_warning ("failed to add connected devices: %s",
error->message); error->message);
g_error_free (error); return;
goto out;
} }
for (i = 0; i < devices->len; i++) for (i = 0; i < devices->len; i++)
{ {
@ -1897,9 +1801,6 @@ gcm_prefs_get_devices_cb (GObject *object,
/* ensure we show the 'No devices detected' entry if empty */ /* ensure we show the 'No devices detected' entry if empty */
gcm_prefs_update_device_list_extra_entry (prefs); gcm_prefs_update_device_list_extra_entry (prefs);
out:
if (devices != NULL)
g_ptr_array_unref (devices);
} }
static void static void
@ -1931,8 +1832,7 @@ gcm_prefs_refresh_toolbar_buttons (CcColorPanel *panel)
return; return;
/* save current device */ /* save current device */
if (panel->current_device != NULL) g_clear_object (&panel->current_device);
g_object_unref (panel->current_device);
g_object_get (row, "device", &panel->current_device, NULL); g_object_get (row, "device", &panel->current_device, NULL);
/* device actions */ /* device actions */
@ -1992,7 +1892,7 @@ gcm_prefs_connect_cb (GObject *object,
{ {
CcColorPanel *prefs; CcColorPanel *prefs;
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
ret = cd_client_connect_finish (CD_CLIENT (object), ret = cd_client_connect_finish (CD_CLIENT (object),
res, res,
@ -2001,8 +1901,6 @@ gcm_prefs_connect_cb (GObject *object,
{ {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("failed to connect to colord: %s", error->message); g_warning ("failed to connect to colord: %s", error->message);
g_error_free (error);
return; return;
} }
@ -2014,7 +1912,6 @@ gcm_prefs_connect_cb (GObject *object,
/* set calibrate button sensitivity */ /* set calibrate button sensitivity */
gcm_prefs_sensor_coldplug (prefs); gcm_prefs_sensor_coldplug (prefs);
/* get devices */ /* get devices */
cd_client_get_devices (prefs->client, cd_client_get_devices (prefs->client,
prefs->cancellable, prefs->cancellable,
@ -2027,12 +1924,12 @@ gcm_prefs_is_livecd (void)
{ {
#ifdef __linux__ #ifdef __linux__
gboolean ret = TRUE; gboolean ret = TRUE;
gchar *data = NULL; g_autofree gchar *data = NULL;
GError *error = NULL; g_autoptr(GError) error = NULL;
/* allow testing */ /* allow testing */
if (g_getenv ("CC_COLOR_PANEL_IS_LIVECD") != NULL) if (g_getenv ("CC_COLOR_PANEL_IS_LIVECD") != NULL)
goto out; return TRUE;
/* get the kernel commandline */ /* get the kernel commandline */
ret = g_file_get_contents ("/proc/cmdline", &data, NULL, &error); ret = g_file_get_contents ("/proc/cmdline", &data, NULL, &error);
@ -2040,14 +1937,10 @@ gcm_prefs_is_livecd (void)
{ {
g_warning ("failed to get kernel command line: %s", g_warning ("failed to get kernel command line: %s",
error->message); error->message);
g_error_free (error); return TRUE;
goto out;
} }
ret = (g_strstr_len (data, -1, "liveimg") != NULL || return (g_strstr_len (data, -1, "liveimg") != NULL ||
g_strstr_len (data, -1, "casper") != NULL); g_strstr_len (data, -1, "casper") != NULL);
out:
g_free (data);
return ret;
#else #else
return FALSE; return FALSE;
#endif #endif
@ -2121,8 +2014,7 @@ cc_color_panel_dispose (GObject *object)
G_CALLBACK (gcm_prefs_device_changed_cb), G_CALLBACK (gcm_prefs_device_changed_cb),
CC_COLOR_PANEL (object)); CC_COLOR_PANEL (object));
} }
g_ptr_array_unref (prefs->devices); g_clear_pointer (&prefs->devices, g_ptr_array_unref);
prefs->devices = NULL;
} }
if (prefs->cancellable != NULL) if (prefs->cancellable != NULL)
@ -2188,17 +2080,14 @@ static gboolean
cc_color_panel_filter_func (GtkListBoxRow *row, void *user_data) cc_color_panel_filter_func (GtkListBoxRow *row, void *user_data)
{ {
CcColorPanel *prefs = CC_COLOR_PANEL (user_data); CcColorPanel *prefs = CC_COLOR_PANEL (user_data);
CdDevice *device; g_autoptr(CdDevice) device = NULL;
gboolean ret;
/* always show all devices */ /* always show all devices */
if (CC_IS_COLOR_DEVICE (row)) if (CC_IS_COLOR_DEVICE (row))
return TRUE; return TRUE;
g_object_get (row, "device", &device, NULL); g_object_get (row, "device", &device, NULL);
ret = g_strcmp0 (cd_device_get_id (device), prefs->list_box_filter) == 0; return g_strcmp0 (cd_device_get_id (device), prefs->list_box_filter) == 0;
g_object_unref (device);
return ret;
} }
static gboolean static gboolean
@ -2221,7 +2110,7 @@ cc_color_panel_treeview_quality_default_cb (GtkTreeModel *model,
static void static void
cc_color_panel_init (CcColorPanel *prefs) cc_color_panel_init (CcColorPanel *prefs)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
GtkStyleContext *context; GtkStyleContext *context;
GtkTreeModel *model; GtkTreeModel *model;
@ -2240,7 +2129,6 @@ cc_color_panel_init (CcColorPanel *prefs)
if (error != NULL) if (error != NULL)
{ {
g_warning ("Could not load interface file: %s", error->message); g_warning ("Could not load interface file: %s", error->message);
g_error_free (error);
return; return;
} }

View file

@ -65,19 +65,14 @@ static gchar *
cc_color_profile_get_profile_date (CdProfile *profile) cc_color_profile_get_profile_date (CdProfile *profile)
{ {
gint64 created; gint64 created;
gchar *string = NULL; g_autoptr(GDateTime) dt = NULL;
GDateTime *dt = NULL;
/* get profile age */ /* get profile age */
created = cd_profile_get_created (profile); created = cd_profile_get_created (profile);
if (created == 0) if (created == 0)
goto out; return NULL;
dt = g_date_time_new_from_unix_utc (created); dt = g_date_time_new_from_unix_utc (created);
string = g_date_time_format (dt, "%x"); return g_date_time_format (dt, "%x");
out:
if (dt != NULL)
g_date_time_unref (dt);
return string;
} }
static gchar * static gchar *
@ -234,7 +229,7 @@ static void
cc_color_profile_refresh (CcColorProfile *color_profile) cc_color_profile_refresh (CcColorProfile *color_profile)
{ {
const gchar *warnings; const gchar *warnings;
gchar *title = NULL; g_autofree gchar *title = NULL;
/* show the image if the profile is default */ /* show the image if the profile is default */
gtk_widget_set_visible (color_profile->widget_image, color_profile->is_default); gtk_widget_set_visible (color_profile->widget_image, color_profile->is_default);
@ -244,7 +239,6 @@ cc_color_profile_refresh (CcColorProfile *color_profile)
/* set the title */ /* set the title */
title = gcm_prefs_get_profile_title (color_profile->profile); title = gcm_prefs_get_profile_title (color_profile->profile);
gtk_label_set_markup (GTK_LABEL (color_profile->widget_description), title); gtk_label_set_markup (GTK_LABEL (color_profile->widget_description), title);
g_free (title);
/* show any information */ /* show any information */
warnings = cc_color_profile_get_warnings (color_profile); warnings = cc_color_profile_get_warnings (color_profile);
@ -355,16 +349,13 @@ static void
cc_color_profile_changed_cb (CdDevice *device, cc_color_profile_changed_cb (CdDevice *device,
CcColorProfile *color_profile) CcColorProfile *color_profile)
{ {
CdProfile *profile; g_autoptr(CdProfile) profile = NULL;
/* check to see if the default has changed */ /* check to see if the default has changed */
profile = cd_device_get_default_profile (device); profile = cd_device_get_default_profile (device);
if (profile != NULL) if (profile != NULL)
{
color_profile->is_default = g_strcmp0 (cd_profile_get_object_path (profile), color_profile->is_default = g_strcmp0 (cd_profile_get_object_path (profile),
cd_profile_get_object_path (color_profile->profile)) == 0; cd_profile_get_object_path (color_profile->profile)) == 0;
g_object_unref (profile);
}
cc_color_profile_refresh (color_profile); cc_color_profile_refresh (color_profile);
} }
@ -389,8 +380,8 @@ cc_color_profile_constructed (GObject *object)
{ {
CcColorProfile *color_profile = CC_COLOR_PROFILE (object); CcColorProfile *color_profile = CC_COLOR_PROFILE (object);
const gchar *sortable_data_source; const gchar *sortable_data_source;
gchar *sortable_device; g_autofree gchar *sortable_device = NULL;
gchar *title; g_autofree gchar *title = NULL;
/* watch to see if the default changes */ /* watch to see if the default changes */
color_profile->device_changed_id = color_profile->device_changed_id =
@ -414,8 +405,6 @@ cc_color_profile_constructed (GObject *object)
sortable_data_source, sortable_data_source,
cd_profile_get_created (color_profile->profile), cd_profile_get_created (color_profile->profile),
title); title);
g_free (title);
g_free (sortable_device);
cc_color_profile_refresh (color_profile); cc_color_profile_refresh (color_profile);
} }