diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2018-06-03 10:22:08 +0400 |
---|---|---|
committer | Robert Ancell <robert.ancell@gmail.com> | 2019-09-09 22:08:26 +0000 |
commit | dab5f5301fe1ae19b0701343e5ee5be8c90ce54c (patch) | |
tree | 4c2270fe5b582257356b5526d8e6bbb510aa0fac /panels/wacom | |
parent | af1ffd76e11721a36ef8d5345a76eafedfe99432 (diff) | |
download | gnome-control-center-dab5f5301fe1ae19b0701343e5ee5be8c90ce54c.tar.gz |
wacom: Use g_auto for variables
Diffstat (limited to 'panels/wacom')
-rw-r--r-- | panels/wacom/cc-tablet-tool-map.c | 77 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-button-row.c | 12 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-device.c | 48 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-mapping-panel.c | 19 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-nav-button.c | 5 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-page.c | 84 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-panel.c | 84 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-stylus-page.c | 13 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-tool.c | 3 | ||||
-rw-r--r-- | panels/wacom/gsd-wacom-key-shortcut-button.c | 3 |
10 files changed, 107 insertions, 241 deletions
diff --git a/panels/wacom/cc-tablet-tool-map.c b/panels/wacom/cc-tablet-tool-map.c index 8b681e3f4..bdc51b971 100644 --- a/panels/wacom/cc-tablet-tool-map.c +++ b/panels/wacom/cc-tablet-tool-map.c @@ -44,54 +44,49 @@ G_DEFINE_TYPE (CcTabletToolMap, cc_tablet_tool_map, G_TYPE_OBJECT) static void load_keyfiles (CcTabletToolMap *map) { - GError *error = NULL; - gchar *dir; + g_autoptr(GError) devices_error = NULL; + g_autoptr(GError) tools_error = NULL; + g_autofree gchar *dir = NULL; dir = g_build_filename (g_get_user_cache_dir (), "gnome-control-center", "wacom", NULL); if (g_mkdir_with_parents (dir, 0700) < 0) { g_warning ("Could not create directory '%s', expect stylus mapping oddities: %m", dir); - g_free (dir); return; } map->tablet_path = g_build_filename (dir, "devices", NULL); g_key_file_load_from_file (map->tablets, map->tablet_path, - G_KEY_FILE_NONE, &error); + G_KEY_FILE_NONE, &devices_error); - if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { + if (devices_error && !g_error_matches (devices_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { g_warning ("Could not load tablets keyfile '%s': %s", - map->tablet_path, error->message); + map->tablet_path, devices_error->message); } - g_clear_error (&error); - map->tool_path = g_build_filename (dir, "tools", NULL); g_key_file_load_from_file (map->tools, map->tool_path, - G_KEY_FILE_NONE, &error); + G_KEY_FILE_NONE, &tools_error); - if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { + if (tools_error && !g_error_matches (tools_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { g_warning ("Could not load tools keyfile '%s': %s", - map->tool_path, error->message); + map->tool_path, tools_error->message); } - - g_clear_error (&error); - - g_free (dir); } static void cache_tools (CcTabletToolMap *map) { - gchar **serials; + g_auto(GStrv) serials = NULL; gsize n_serials, i; serials = g_key_file_get_groups (map->tools, &n_serials); for (i = 0; i < n_serials; i++) { - gchar *str, *end; + g_autofree gchar *str = NULL; + gchar *end; guint64 serial, id; - GError *error = NULL; + g_autoptr(GError) error = NULL; CcWacomTool *tool; serial = g_ascii_strtoull (serials[i], &end, 16); @@ -102,26 +97,21 @@ cache_tools (CcTabletToolMap *map) } str = g_key_file_get_string (map->tools, serials[i], KEY_TOOL_ID, &error); - if (error) { + if (str == NULL) { g_warning ("Could not get cached ID for tool with serial %s: %s", serials[i], error->message); - g_clear_error (&error); continue; } id = g_ascii_strtoull (str, &end, 16); if (*end != '\0') { g_warning ("Invalid tool ID %s", str); - g_free (str); continue; } tool = cc_wacom_tool_new (serial, id, NULL); g_hash_table_insert (map->tool_map, g_strdup (serials[i]), tool); - g_free (str); } - - g_strfreev (serials); } static void @@ -135,14 +125,13 @@ cache_devices (CcTabletToolMap *map) for (i = 0; i < n_ids; i++) { gchar **styli; gsize n_styli, j; - GError *error = NULL; + g_autoptr(GError) error = NULL; GList *tools = NULL; styli = g_key_file_get_string_list (map->tablets, ids[i], KEY_DEVICE_STYLI, &n_styli, &error); - if (error) { + if (styli == NULL) { g_warning ("Could not get cached styli for with ID %s: %s", ids[i], error->message); - g_clear_error (&error); continue; } @@ -254,7 +243,7 @@ cc_tablet_tool_map_list_tools (CcTabletToolMap *map, { CcWacomTool *no_serial_tool; GList *styli; - gchar *key; + g_autofree gchar *key = NULL; g_return_val_if_fail (CC_IS_TABLET_TOOL_MAP (map), NULL); g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), NULL); @@ -274,8 +263,6 @@ cc_tablet_tool_map_list_tools (CcTabletToolMap *map, styli = g_list_prepend (styli, no_serial_tool); } - g_free (key); - return styli; } @@ -285,7 +272,7 @@ cc_tablet_tool_map_lookup_tool (CcTabletToolMap *map, guint64 serial) { CcWacomTool *tool = NULL; - gchar *key = NULL; + g_autofree gchar *key = NULL; g_return_val_if_fail (CC_IS_TABLET_TOOL_MAP (map), FALSE); g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), FALSE); @@ -298,8 +285,6 @@ cc_tablet_tool_map_lookup_tool (CcTabletToolMap *map, tool = g_hash_table_lookup (map->tool_map, key); } - g_free (key); - return tool; } @@ -308,8 +293,8 @@ keyfile_add_device_stylus (CcTabletToolMap *map, const gchar *device_key, const gchar *tool_key) { - GArray *array; - gchar **styli; + g_autoptr(GArray) array = NULL; + g_auto(GStrv) styli = NULL; gsize n_styli; array = g_array_new (FALSE, FALSE, sizeof (gchar *)); @@ -324,8 +309,6 @@ keyfile_add_device_stylus (CcTabletToolMap *map, g_array_append_val (array, tool_key); g_key_file_set_string_list (map->tablets, device_key, KEY_DEVICE_STYLI, (const gchar **) array->data, array->len); - g_array_free (array, TRUE); - g_strfreev (styli); } static void @@ -333,12 +316,11 @@ keyfile_add_stylus (CcTabletToolMap *map, const gchar *tool_key, guint64 id) { - gchar *str; + g_autofree gchar *str = NULL; /* Also works for IDs */ str = get_tool_key (id); g_key_file_set_string (map->tools, tool_key, KEY_TOOL_ID, str); - g_free (str); } void @@ -348,8 +330,8 @@ cc_tablet_tool_map_add_relation (CcTabletToolMap *map, { gboolean tablets_changed = FALSE, tools_changed = FALSE; gboolean new_tool_without_serial = FALSE; - gchar *tool_key, *device_key; - GError *error = NULL; + g_autofree gchar *tool_key = NULL; + g_autofree gchar *device_key = NULL; guint64 serial, id; GList *styli; @@ -396,26 +378,21 @@ cc_tablet_tool_map_add_relation (CcTabletToolMap *map, } } - g_free (device_key); - g_free (tool_key); - if (tools_changed) { - g_key_file_save_to_file (map->tools, map->tool_path, &error); + g_autoptr(GError) error = NULL; - if (error) { + if (!g_key_file_save_to_file (map->tools, map->tool_path, &error)) { g_warning ("Error saving tools keyfile: %s", error->message); - g_clear_error (&error); } } if (tablets_changed) { - g_key_file_save_to_file (map->tablets, map->tablet_path, &error); + g_autoptr(GError) error = NULL; - if (error) { + if (!g_key_file_save_to_file (map->tablets, map->tablet_path, &error)) { g_warning ("Error saving tablets keyfile: %s", error->message); - g_clear_error (&error); } } } diff --git a/panels/wacom/cc-wacom-button-row.c b/panels/wacom/cc-wacom-button-row.c index c897d7d6c..d7df80a22 100644 --- a/panels/wacom/cc-wacom-button-row.c +++ b/panels/wacom/cc-wacom-button-row.c @@ -81,7 +81,7 @@ cc_wacom_button_row_update_shortcut (CcWacomButtonRow *row, { guint keyval; GdkModifierType mask; - char *shortcut; + g_autofree gchar *shortcut = NULL; if (action_type != G_DESKTOP_PAD_BUTTON_ACTION_KEYBINDING) return; @@ -96,8 +96,6 @@ cc_wacom_button_row_update_shortcut (CcWacomButtonRow *row, "key-value", keyval, "key-mods", mask, NULL); - - g_free (shortcut); } } @@ -156,7 +154,7 @@ static void on_key_shortcut_edited (GsdWacomKeyShortcutButton *shortcut_button, CcWacomButtonRow *row) { - char *custom_key; + g_autofree gchar *custom_key = NULL; guint keyval; GdkModifierType mask; @@ -172,8 +170,6 @@ on_key_shortcut_edited (GsdWacomKeyShortcutButton *shortcut_button, custom_key = gtk_accelerator_name (keyval, mask); g_settings_set_string (row->settings, KEYBINDING_KEY, custom_key); - - g_free (custom_key); } static void @@ -238,7 +234,7 @@ cc_wacom_button_row_new (guint button, { CcWacomButtonRow *row; GtkWidget *grid, *combo, *label, *shortcut_button; - char *name = NULL; + g_autofree gchar *name = NULL; row = CC_WACOM_BUTTON_ROW (g_object_new (CC_WACOM_TYPE_BUTTON_ROW, NULL)); @@ -282,7 +278,5 @@ cc_wacom_button_row_new (guint button, cc_wacom_button_row_update (CC_WACOM_BUTTON_ROW (row)); - g_free (name); - return GTK_WIDGET (row); } diff --git a/panels/wacom/cc-wacom-device.c b/panels/wacom/cc-wacom-device.c index e0915d5b5..4a3f98068 100644 --- a/panels/wacom/cc-wacom-device.c +++ b/panels/wacom/cc-wacom-device.c @@ -266,7 +266,9 @@ find_output_by_edid (GnomeRRScreen *rr_screen, rr_outputs = gnome_rr_screen_list_outputs (rr_screen); for (i = 0; rr_outputs[i] != NULL; i++) { - gchar *o_vendor, *o_product, *o_serial; + g_autofree gchar *o_vendor = NULL; + g_autofree gchar *o_product = NULL; + g_autofree gchar *o_serial = NULL; gboolean match; gnome_rr_output_get_ids_from_edid (rr_outputs[i], @@ -281,10 +283,6 @@ find_output_by_edid (GnomeRRScreen *rr_screen, (g_strcmp0 (product, o_product) == 0) && \ (g_strcmp0 (serial, o_serial) == 0); - g_free (o_vendor); - g_free (o_product); - g_free (o_serial); - if (match) { retval = rr_outputs[i]; break; @@ -302,10 +300,9 @@ static GnomeRROutput * find_output (GnomeRRScreen *rr_screen, CcWacomDevice *device) { - GSettings *settings; - GVariant *variant; - const gchar **edid; - GnomeRROutput *ret = NULL; + g_autoptr(GSettings) settings = NULL; + g_autoptr(GVariant) variant = NULL; + g_autofree const gchar **edid = NULL; gsize n; settings = cc_wacom_device_get_settings (device); @@ -314,20 +311,13 @@ find_output (GnomeRRScreen *rr_screen, if (n != 3) { g_critical ("Expected 'output' key to store %d values; got %"G_GSIZE_FORMAT".", 3, n); - goto out; + return NULL; } if (strlen (edid[0]) == 0 || strlen (edid[1]) == 0 || strlen (edid[2]) == 0) - goto out; - - ret = find_output_by_edid (rr_screen, edid[0], edid[1], edid[2]); - -out: - g_free (edid); - g_variant_unref (variant); - g_object_unref (settings); + return NULL; - return ret; + return find_output_by_edid (rr_screen, edid[0], edid[1], edid[2]); } GnomeRROutput * @@ -359,8 +349,10 @@ void cc_wacom_device_set_output (CcWacomDevice *device, GnomeRROutput *output) { - GSettings *settings; - gchar *vendor, *product, *serial; + g_autoptr(GSettings) settings = NULL; + g_autofree gchar *vendor = NULL; + g_autofree gchar *product = NULL; + g_autofree gchar *serial = NULL; const gchar *values[] = { "", "", "", NULL }; g_return_if_fail (CC_IS_WACOM_DEVICE (device)); @@ -379,11 +371,6 @@ cc_wacom_device_set_output (CcWacomDevice *device, } g_settings_set_strv (settings, "output", values); - - g_free (vendor); - g_free (product); - g_free (serial); - g_object_unref (settings); } guint @@ -398,8 +385,10 @@ GSettings * cc_wacom_device_get_button_settings (CcWacomDevice *device, guint button) { - GSettings *tablet_settings, *settings; - gchar *path, *button_path; + g_autoptr(GSettings) tablet_settings = NULL; + GSettings *settings; + g_autofree gchar *path = NULL; + g_autofree gchar *button_path = NULL; g_return_val_if_fail (CC_IS_WACOM_DEVICE (device), NULL); @@ -412,9 +401,6 @@ cc_wacom_device_get_button_settings (CcWacomDevice *device, button_path = g_strdup_printf ("%sbutton%c/", path, 'A' + button); settings = g_settings_new_with_path ("org.gnome.desktop.peripherals.tablet.pad-button", button_path); - g_free (path); - g_free (button_path); - g_object_unref (tablet_settings); return settings; } diff --git a/panels/wacom/cc-wacom-mapping-panel.c b/panels/wacom/cc-wacom-mapping-panel.c index 60664d331..46d913d1e 100644 --- a/panels/wacom/cc-wacom-mapping-panel.c +++ b/panels/wacom/cc-wacom-mapping-panel.c @@ -77,7 +77,7 @@ set_combobox_sensitive (CcWacomMappingPanel *self, static void update_monitor_chooser (CcWacomMappingPanel *self) { - GtkListStore *store; + g_autoptr(GtkListStore) store = NULL; GnomeRROutput **outputs; GSettings *settings; GnomeRROutput *cur_output; @@ -88,7 +88,6 @@ update_monitor_chooser (CcWacomMappingPanel *self) if (self->device == NULL) { set_combobox_sensitive (self, FALSE); - g_object_unref (store); return; } @@ -105,8 +104,8 @@ update_monitor_chooser (CcWacomMappingPanel *self) g_signal_handlers_unblock_by_func (G_OBJECT (self->aspectswitch), aspectswitch_toggled_cb, self); if (!self->rr_screen) { - cur_output = NULL; - goto bail; + set_combobox_sensitive (self, FALSE); + return; } outputs = gnome_rr_screen_list_outputs (self->rr_screen); @@ -119,7 +118,7 @@ update_monitor_chooser (CcWacomMappingPanel *self) if (crtc && gnome_rr_crtc_get_current_mode (crtc) != NULL) { GtkTreeIter iter; const gchar *name, *disp_name; - gchar *text; + g_autofree gchar *text = NULL; name = gnome_rr_output_get_name (output); disp_name = gnome_rr_output_get_display_name (output); @@ -133,14 +132,10 @@ update_monitor_chooser (CcWacomMappingPanel *self) gtk_combo_box_set_active_iter (GTK_COMBO_BOX(self->combobox), &iter); g_signal_handlers_unblock_by_func (G_OBJECT (self->combobox), combobox_changed_cb, self); } - - g_free (text); } } -bail: set_combobox_sensitive (self, cur_output != NULL); - g_object_unref (store); } static void @@ -231,14 +226,12 @@ cc_wacom_mapping_panel_init (CcWacomMappingPanel *self) { GtkWidget *vbox, *grid; GtkCellRenderer *renderer; - GError *error = NULL; + g_autoptr(GError) error = NULL; self->rr_screen = gnome_rr_screen_new (gdk_screen_get_default (), &error); - if (error) { + if (error) g_warning ("Could not get RR screen: %s", error->message); - g_error_free (error); - } g_signal_connect_swapped (self->rr_screen, "changed", G_CALLBACK (update_monitor_chooser), self); diff --git a/panels/wacom/cc-wacom-nav-button.c b/panels/wacom/cc-wacom-nav-button.c index 938f79f6a..67a614e44 100644 --- a/panels/wacom/cc-wacom-nav-button.c +++ b/panels/wacom/cc-wacom-nav-button.c @@ -140,8 +140,8 @@ cc_wacom_nav_button_set_property (GObject *object, g_signal_handler_disconnect (nav->notebook, nav->page_added_id); g_signal_handler_disconnect (nav->notebook, nav->page_removed_id); g_signal_handler_disconnect (nav->notebook, nav->page_switched_id); - g_object_unref (nav->notebook); } + g_clear_object (&nav->notebook); nav->notebook = g_value_dup_object (value); nav->page_added_id = g_signal_connect (G_OBJECT (nav->notebook), "page-added", G_CALLBACK (pages_changed), nav); @@ -172,8 +172,7 @@ cc_wacom_nav_button_dispose (GObject *object) self->page_removed_id = 0; g_signal_handler_disconnect (self->notebook, self->page_switched_id); self->page_switched_id = 0; - g_object_unref (self->notebook); - self->notebook = NULL; + g_clear_object (&self->notebook); } G_OBJECT_CLASS (cc_wacom_nav_button_parent_class)->dispose (object); diff --git a/panels/wacom/cc-wacom-page.c b/panels/wacom/cc-wacom-page.c index 47fb59579..81e682f4f 100644 --- a/panels/wacom/cc-wacom-page.c +++ b/panels/wacom/cc-wacom-page.c @@ -148,7 +148,7 @@ set_calibration (CcWacomDevice *device, { GVariant *current; /* current calibration */ GVariant *array; /* new calibration */ - GVariant **tmp; + g_autofree GVariant **tmp = NULL; gsize nvalues; gint i; @@ -166,8 +166,6 @@ set_calibration (CcWacomDevice *device, array = g_variant_new_array (G_VARIANT_TYPE_DOUBLE, tmp, nvalues); g_settings_set_value (settings, "area", array); - g_free (tmp); - g_debug ("Setting area to %f, %f, %f, %f (left/right/top/bottom) (last used resolution: %d x %d)", cal[0], cal[1], cal[2], cal[3], display_width, display_height); @@ -216,7 +214,8 @@ cc_wacom_page_get_gdk_device (CcWacomPage *page) GdkDevice *gdk_device = NULL; GdkDisplay *display; GdkSeat *seat; - GList *slaves, *l; + g_autoptr(GList) slaves = NULL; + GList *l; gsd_device = cc_wacom_device_get_device (page->stylus); g_return_val_if_fail (GSD_IS_DEVICE (gsd_device), NULL); @@ -226,7 +225,7 @@ cc_wacom_page_get_gdk_device (CcWacomPage *page) slaves = gdk_seat_get_slaves (seat, GDK_SEAT_CAPABILITY_TABLET_STYLUS); for (l = slaves; l && !gdk_device; l = l->next) { - gchar *device_node = NULL; + g_autofree gchar *device_node = NULL; if (gdk_device_get_source (l->data) != GDK_SOURCE_PEN) continue; @@ -242,12 +241,8 @@ cc_wacom_page_get_gdk_device (CcWacomPage *page) if (g_strcmp0 (device_node, gsd_device_get_device_file (gsd_device)) == 0) gdk_device = l->data; - - g_free (device_node); } - g_list_free (slaves); - return gdk_device; } @@ -289,21 +284,21 @@ static void calibrate (CcWacomPage *page) { int i; - GVariant *old_calibration, **tmp, *array; - gdouble *calibration; + GVariant *old_calibration, *array; + g_autofree GVariant **tmp = NULL; + g_autofree gdouble *calibration = NULL; gsize ncal; GdkMonitor *monitor; GdkScreen *screen; - GnomeRRScreen *rr_screen; + g_autoptr(GnomeRRScreen) rr_screen = NULL; GnomeRROutput *output; - GError *error = NULL; + g_autoptr(GError) error = NULL; gint x, y; screen = gdk_screen_get_default (); rr_screen = gnome_rr_screen_new (screen, &error); if (error) { g_warning ("Could not connect to display manager: %s", error->message); - g_error_free (error); return; } @@ -339,13 +334,9 @@ calibrate (CcWacomPage *page) array = g_variant_new_array (G_VARIANT_TYPE_DOUBLE, tmp, ncal); g_settings_set_value (page->wacom_settings, "area", array); - g_free (tmp); run_calibration (page, old_calibration, calibration, monitor); - g_free (calibration); gtk_widget_set_sensitive (WID ("button-calibrate"), FALSE); - - g_object_unref (rr_screen); } static void @@ -408,15 +399,14 @@ button_mapping_dialog_closed (GtkDialog *dialog, CcWacomPage *page) { gtk_widget_destroy (MWID ("button-mapping-dialog")); - g_object_unref (page->mapping_builder); - page->mapping_builder = NULL; + g_clear_object (&page->mapping_builder); } static void show_button_mapping_dialog (CcWacomPage *page) { GtkWidget *toplevel; - GError *error = NULL; + g_autoptr(GError) error = NULL; GtkWidget *dialog; g_assert (page->mapping_builder == NULL); @@ -427,9 +417,7 @@ show_button_mapping_dialog (CcWacomPage *page) if (error != NULL) { g_warning ("Error loading UI file: %s", error->message); - g_object_unref (page->mapping_builder); - page->mapping_builder = NULL; - g_error_free (error); + g_clear_object (&page->mapping_builder); return; } @@ -453,7 +441,7 @@ set_osd_visibility_cb (GObject *source_object, GAsyncResult *res, gpointer data) { - GError *error = NULL; + g_autoptr(GError) error = NULL; GVariant *result; CcWacomPage *page; @@ -464,10 +452,8 @@ set_osd_visibility_cb (GObject *source_object, if (result == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_printerr ("Error setting OSD's visibility: %s\n", error->message); - g_error_free (error); show_button_mapping_dialog (page); } else { - g_error_free (error); return; } } @@ -655,36 +641,13 @@ cc_wacom_page_dispose (GObject *object) { CcWacomPage *self = CC_WACOM_PAGE (object); - if (self->cancellable) { - g_cancellable_cancel (self->cancellable); - g_clear_object (&self->cancellable); - } - - if (self->area) { - calib_area_free (self->area); - self->area = NULL; - } - - if (self->button_map) { - gtk_widget_destroy (self->button_map); - self->button_map = NULL; - } - - if (self->dialog) { - gtk_widget_destroy (self->dialog); - self->dialog = NULL; - } - - if (self->builder) { - g_object_unref (self->builder); - self->builder = NULL; - } - - if (self->header_group) { - g_object_unref (self->header_group); - self->header_group = NULL; - } - + g_cancellable_cancel (self->cancellable); + g_clear_object (&self->cancellable); + g_clear_pointer (&self->area, calib_area_free); + g_clear_pointer (&self->button_map, gtk_widget_destroy); + g_clear_pointer (&self->dialog, gtk_widget_destroy); + g_clear_object (&self->builder); + g_clear_object (&self->header_group); self->panel = NULL; @@ -717,7 +680,7 @@ remove_link_padding (GtkWidget *widget) static void cc_wacom_page_init (CcWacomPage *page) { - GError *error = NULL; + g_autoptr(GError) error = NULL; GtkComboBox *combo; GtkWidget *box; GtkSwitch *sw; @@ -738,8 +701,6 @@ cc_wacom_page_init (CcWacomPage *page) &error); if (error != NULL) { g_warning ("Error loading UI file: %s", error->message); - g_object_unref (page->builder); - g_error_free (error); return; } @@ -786,11 +747,10 @@ set_icon_name (CcWacomPage *page, const char *widget_name, const char *icon_name) { - char *resource; + g_autofree gchar *resource = NULL; resource = g_strdup_printf ("/org/gnome/control-center/wacom/%s.svg", icon_name); gtk_image_set_from_resource (GTK_IMAGE (WID (widget_name)), resource); - g_free (resource); } static void diff --git a/panels/wacom/cc-wacom-panel.c b/panels/wacom/cc-wacom-panel.c index 4e123a5ae..c0c15b3aa 100644 --- a/panels/wacom/cc-wacom-panel.c +++ b/panels/wacom/cc-wacom-panel.c @@ -146,7 +146,8 @@ set_device_page (CcWacomPanel *self, const gchar *device_name) static void run_operation_from_params (CcWacomPanel *self, GVariant *parameters) { - GVariant *v; + g_autoptr(GVariant) v = NULL; + g_autoptr(GVariant) v2 = NULL; CcWacomPage *page; const gchar *operation = NULL; const gchar *device_name = NULL; @@ -160,28 +161,23 @@ run_operation_from_params (CcWacomPanel *self, GVariant *parameters) if (!g_variant_is_of_type (v, G_VARIANT_TYPE_STRING)) { g_warning ("Wrong type for the second argument GVariant, expected 's' but got '%s'", g_variant_get_type_string (v)); - g_variant_unref (v); - return; } - g_variant_unref (v); - switch (n_params) { case 3: page = set_device_page (self, device_name); if (page == NULL) return; - g_variant_get_child (parameters, 1, "v", &v); + g_variant_get_child (parameters, 1, "v", &v2); - if (!g_variant_is_of_type (v, G_VARIANT_TYPE_STRING)) { + if (!g_variant_is_of_type (v2, G_VARIANT_TYPE_STRING)) { g_warning ("Wrong type for the operation name argument. A string is expected."); - g_variant_unref (v); break; } - operation = g_variant_get_string (v, NULL); + operation = g_variant_get_string (v2, NULL); if (g_strcmp0 (operation, "run-calibration") == 0) { if (cc_wacom_page_can_calibrate (page)) cc_wacom_page_calibrate (page); @@ -190,7 +186,6 @@ run_operation_from_params (CcWacomPanel *self, GVariant *parameters) } else { g_warning ("Ignoring unrecognized operation '%s'", operation); } - g_variant_unref (v); case 2: set_device_page (self, device_name); break; @@ -248,11 +243,7 @@ cc_wacom_panel_dispose (GObject *object) { CcWacomPanel *self = CC_WACOM_PANEL (object); - if (self->builder) - { - g_object_unref (self->builder); - self->builder = NULL; - } + g_clear_object (&self->builder); if (self->manager) { @@ -261,26 +252,11 @@ cc_wacom_panel_dispose (GObject *object) self->manager = NULL; } - if (self->devices) - { - g_hash_table_destroy (self->devices); - self->devices = NULL; - } - + g_clear_pointer (&self->devices, g_hash_table_unref); g_clear_object (&self->cancellable); g_clear_object (&self->proxy); - - if (self->pages) - { - g_hash_table_destroy (self->pages); - self->pages = NULL; - } - - if (self->stylus_pages) - { - g_hash_table_destroy (self->stylus_pages); - self->stylus_pages = NULL; - } + g_clear_pointer (&self->pages, g_hash_table_unref); + g_clear_pointer (&self->stylus_pages, g_hash_table_unref); G_OBJECT_CLASS (cc_wacom_panel_parent_class)->dispose (object); } @@ -292,7 +268,8 @@ check_remove_stylus_pages (CcWacomPanel *self) CcWacomDevice *device; CcWacomTool *tool; GtkWidget *page; - GList *tools, *total = NULL; + GList *tools; + g_autoptr(GList) total = NULL; /* First. Iterate known devices and get the tools */ g_hash_table_iter_init (&iter, self->devices); @@ -311,8 +288,6 @@ check_remove_stylus_pages (CcWacomPanel *self) gtk_widget_destroy (page); g_hash_table_iter_remove (&iter); } - - g_list_free (total); } static gboolean @@ -540,7 +515,8 @@ update_current_page (CcWacomPanel *self, CcWacomDevice *removed_device) { GHashTable *ht; - GList *tablets, *l; + g_autoptr(GList) tablets = NULL; + GList *l; gboolean changed; GHashTableIter iter; GsdDevice *gsd_device; @@ -610,7 +586,6 @@ update_current_page (CcWacomPanel *self, cc_wacom_page_update_tools (CC_WACOM_PAGE (page), tablet->stylus, tablet->pad); } } - g_list_free (tablets); g_hash_table_destroy (ht); @@ -631,7 +606,6 @@ add_known_device (CcWacomPanel *self, { CcWacomDevice *device; GsdDeviceType device_type; - GList *tools, *l; device_type = gsd_device_get_device_type (gsd_device); @@ -651,13 +625,14 @@ add_known_device (CcWacomPanel *self, /* Only trigger tool lookup on pen devices */ if ((device_type & GSD_DEVICE_TYPE_TABLET) != 0) { + g_autoptr(GList) tools = NULL; + GList *l; + tools = cc_tablet_tool_map_list_tools (self->tablet_tool_map, device); for (l = tools; l != NULL; l = l->next) { add_stylus (self, l->data); } - - g_list_free (tools); } } @@ -666,7 +641,7 @@ device_removed_cb (GsdDeviceManager *manager, GsdDevice *gsd_device, CcWacomPanel *self) { - CcWacomDevice *device; + g_autoptr(CcWacomDevice) device = NULL; device = g_hash_table_lookup (self->devices, gsd_device); if (!device) @@ -675,7 +650,6 @@ device_removed_cb (GsdDeviceManager *manager, g_hash_table_steal (self->devices, gsd_device); update_current_page (self, device); check_remove_stylus_pages (self); - g_object_unref (device); } static void @@ -700,16 +674,13 @@ cc_wacom_panel_switch_to_panel (CcWacomPanel *self, const char *panel) { CcShell *shell; - GError *error = NULL; + g_autoptr(GError) error = NULL; g_return_if_fail (self); shell = cc_panel_get_shell (CC_PANEL (self)); - if (cc_shell_set_active_panel_from_id (shell, panel, NULL, &error) == FALSE) - { + if (!cc_shell_set_active_panel_from_id (shell, panel, NULL, &error)) g_warning ("Failed to activate '%s' panel: %s", panel, error->message); - g_error_free (error); - } } static void @@ -717,7 +688,7 @@ got_osd_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer data) { - GError *error = NULL; + g_autoptr(GError) error = NULL; CcWacomPanel *self; self = CC_WACOM_PANEL (data); @@ -727,7 +698,6 @@ got_osd_proxy_cb (GObject *source_object, if (self->proxy == NULL) { g_printerr ("Error creating proxy: %s\n", error->message); - g_error_free (error); return; } } @@ -736,12 +706,11 @@ static void enbiggen_label (GtkLabel *label) { const char *str; - char *new_str; + g_autofree char *new_str = NULL; str = gtk_label_get_text (label); new_str = g_strdup_printf ("<big>%s</big>", str); gtk_label_set_markup (label, new_str); - g_free (new_str); } static void @@ -765,8 +734,9 @@ static void cc_wacom_panel_init (CcWacomPanel *self) { GtkWidget *widget; - GList *devices, *l; - GError *error = NULL; + g_autoptr(GList) devices = NULL; + GList *l; + g_autoptr(GError) error = NULL; char *objects[] = { "main-box", "no-stylus-page", @@ -785,11 +755,8 @@ cc_wacom_panel_init (CcWacomPanel *self) "/org/gnome/control-center/wacom/wacom-stylus-page.ui", objects, &error); - if (error != NULL) - { + if (error != NULL) { g_warning ("Error loading UI file: %s", error->message); - g_object_unref (self->builder); - g_error_free (error); return; } @@ -874,7 +841,6 @@ cc_wacom_panel_init (CcWacomPanel *self) GSD_DEVICE_TYPE_TABLET); for (l = devices; l ; l = l->next) add_known_device (self, l->data); - g_list_free (devices); update_current_page (self, NULL); } diff --git a/panels/wacom/cc-wacom-stylus-page.c b/panels/wacom/cc-wacom-stylus-page.c index 6eb57b14d..5bbbfa601 100644 --- a/panels/wacom/cc-wacom-stylus-page.c +++ b/panels/wacom/cc-wacom-stylus-page.c @@ -243,11 +243,7 @@ cc_wacom_stylus_page_dispose (GObject *object) { CcWacomStylusPage *page = CC_WACOM_STYLUS_PAGE (object); - if (page->builder) { - g_object_unref (page->builder); - page->builder = NULL; - } - + g_clear_object (&page->builder); G_OBJECT_CLASS (cc_wacom_stylus_page_parent_class)->dispose (object); } @@ -265,7 +261,7 @@ cc_wacom_stylus_page_class_init (CcWacomStylusPageClass *klass) static void cc_wacom_stylus_page_init (CcWacomStylusPage *page) { - GError *error = NULL; + g_autoptr(GError) error = NULL; GtkComboBox *combo; GtkWidget *box; char *objects[] = { @@ -284,8 +280,6 @@ cc_wacom_stylus_page_init (CcWacomStylusPage *page) &error); if (error != NULL) { g_warning ("Error loading UI file: %s", error->message); - g_object_unref (page->builder); - g_error_free (error); return; } @@ -325,11 +319,10 @@ set_icon_name (CcWacomStylusPage *page, const char *widget_name, const char *icon_name) { - char *resource; + g_autofree gchar *resource = NULL; resource = g_strdup_printf ("/org/gnome/control-center/wacom/%s.svg", icon_name); gtk_image_set_from_resource (GTK_IMAGE (WID (widget_name)), resource); - g_free (resource); } /* Different types of layout for the stylus config */ diff --git a/panels/wacom/cc-wacom-tool.c b/panels/wacom/cc-wacom-tool.c index fa1169fbd..1316fa5d6 100644 --- a/panels/wacom/cc-wacom-tool.c +++ b/panels/wacom/cc-wacom-tool.c @@ -109,8 +109,7 @@ cc_wacom_tool_finalize (GObject *object) { CcWacomTool *tool = CC_WACOM_TOOL (object); - if (tool->settings) - g_object_unref (tool->settings); + g_clear_object (&tool->settings); G_OBJECT_CLASS (cc_wacom_tool_parent_class)->finalize (object); } diff --git a/panels/wacom/gsd-wacom-key-shortcut-button.c b/panels/wacom/gsd-wacom-key-shortcut-button.c index 2e7464116..fcc531372 100644 --- a/panels/wacom/gsd-wacom-key-shortcut-button.c +++ b/panels/wacom/gsd-wacom-key-shortcut-button.c @@ -210,7 +210,7 @@ gsd_wacom_key_shortcut_remove_editing_mode (GsdWacomKeyShortcutButton *self) static void gsd_wacom_key_shortcut_button_changed (GsdWacomKeyShortcutButton *self) { - gchar *text; + g_autofree gchar *text = NULL; if (self->editing_mode) { @@ -231,7 +231,6 @@ gsd_wacom_key_shortcut_button_changed (GsdWacomKeyShortcutButton *self) text = gtk_accelerator_get_label (self->keyval, self->mods); gtk_button_set_label (GTK_BUTTON (self), text); - g_free (text); } static void |