keyboard: Use g_auto for variables

This commit is contained in:
Robert Ancell 2018-01-23 16:03:19 +13:00
parent 690f15b69d
commit a90e13f12c
5 changed files with 28 additions and 58 deletions

View file

@ -228,7 +228,8 @@ add_shortcuts (CcKeyboardManager *self)
{
BindingGroupType group;
GPtrArray *keys;
gchar *id, *title;
g_autofree gchar *id = NULL;
g_autofree gchar *title = NULL;
gint i;
gtk_tree_model_get (sections_model,
@ -272,9 +273,6 @@ add_shortcuts (CcKeyboardManager *self)
}
can_continue = gtk_tree_model_iter_next (sections_model, &sections_iter);
g_free (title);
g_free (id);
}
}
@ -431,11 +429,10 @@ append_sections_from_file (CcKeyboardManager *self,
keys = (KeyListEntry *) g_array_free (keylist->entries, FALSE);
if (keylist->package)
{
char *localedir;
g_autofree gchar *localedir = NULL;
localedir = g_build_filename (datadir, "locale", NULL);
bindtextdomain (keylist->package, localedir);
g_free (localedir);
title = dgettext (keylist->package, keylist->name);
} else {
@ -471,7 +468,7 @@ append_sections_from_file (CcKeyboardManager *self,
static void
append_sections_from_gsettings (CcKeyboardManager *self)
{
char **custom_paths;
g_auto(GStrv) custom_paths = NULL;
GArray *entries;
KeyListEntry key = { 0, 0, 0, 0, 0, 0, 0 };
int i;
@ -491,7 +488,6 @@ append_sections_from_gsettings (CcKeyboardManager *self)
else
g_free (key.name);
}
g_strfreev (custom_paths);
if (entries->len > 0)
{
@ -565,21 +561,18 @@ reload_sections (CcKeyboardManager *self)
data_dirs = g_get_system_data_dirs ();
for (i = 0; data_dirs[i] != NULL; i++)
{
char *dir_path;
g_autofree gchar *dir_path = NULL;
const gchar *name;
dir_path = g_build_filename (data_dirs[i], "gnome-control-center", "keybindings", NULL);
dir = g_dir_open (dir_path, 0, NULL);
if (!dir)
{
g_free (dir_path);
continue;
}
continue;
for (name = g_dir_read_name (dir) ; name ; name = g_dir_read_name (dir))
{
gchar *path;
g_autofree gchar *path = NULL;
if (g_str_has_suffix (name, ".xml") == FALSE)
continue;
@ -593,10 +586,8 @@ reload_sections (CcKeyboardManager *self)
g_hash_table_insert (loaded_files, g_strdup (name), GINT_TO_POINTER (1));
path = g_build_filename (dir_path, name, NULL);
append_sections_from_file (self, path, data_dirs[i], wm_keybindings);
g_free (path);
}
g_free (dir_path);
g_dir_close (dir);
}
@ -753,7 +744,7 @@ CcKeyboardItem*
cc_keyboard_manager_create_custom_shortcut (CcKeyboardManager *self)
{
CcKeyboardItem *item;
gchar *settings_path;
g_autofree gchar *settings_path = NULL;
g_return_val_if_fail (CC_IS_KEYBOARD_MANAGER (self), NULL);
@ -761,7 +752,6 @@ cc_keyboard_manager_create_custom_shortcut (CcKeyboardManager *self)
settings_path = find_free_settings_path (self->binding_settings);
cc_keyboard_item_load_from_gsettings_path (item, settings_path, TRUE);
g_free (settings_path);
item->model = GTK_TREE_MODEL (self->shortcuts_model);
item->group = BINDING_GROUP_USER;

View file

@ -442,7 +442,7 @@ void
cc_keyboard_option_set_selection (CcKeyboardOption *self,
GtkTreeIter *iter)
{
gchar *new_value = NULL;
g_autofree gchar *new_value = NULL;
g_return_if_fail (CC_IS_KEYBOARD_OPTION (self));
@ -465,8 +465,6 @@ cc_keyboard_option_set_selection (CcKeyboardOption *self,
g_settings_set_strv (input_sources_settings, XKB_OPTIONS_KEY,
(const gchar * const *) current_xkb_options);
g_free (new_value);
}
void

View file

@ -118,13 +118,11 @@ transform_binding_to_accel (GBinding *binding,
/* Embolden the label when the shortcut is modified */
if (!cc_keyboard_item_is_value_default (item))
{
gchar *tmp;
g_autofree gchar *tmp = NULL;
tmp = convert_keysym_state_to_string (combo);
accelerator = g_strdup_printf ("<b>%s</b>", tmp);
g_free (tmp);
}
else
{
@ -507,7 +505,7 @@ header_function (GtkListBoxRow *row,
if (add_header)
{
GtkWidget *box, *label;
gchar *markup;
g_autofree gchar *markup = NULL;
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_widget_set_margin_top (box, before ? 18 : 6);
@ -528,8 +526,6 @@ header_function (GtkListBoxRow *row,
gtk_list_box_row_set_header (row, box);
gtk_widget_show_all (box);
g_free (markup);
}
else
{
@ -545,8 +541,9 @@ filter_function (GtkListBoxRow *row,
CcKeyboardItem *item;
RowData *data;
gboolean retval;
gchar *search, *name;
gchar **terms;
g_autofree gchar *search = NULL;
g_autofree gchar *name = NULL;
g_auto(GStrv) terms = NULL;
guint i;
if (gtk_entry_get_text_length (GTK_ENTRY (self->search_entry)) == 0)
@ -569,10 +566,6 @@ filter_function (GtkListBoxRow *row,
break;
}
g_free (search);
g_free (name);
g_strfreev (terms);
return retval;
}

View file

@ -153,7 +153,7 @@ apply_custom_item_fields (CcKeyboardShortcutEditor *self,
if (self->edited)
{
CcKeyCombo *combo = item->primary_combo;
gchar *binding;
g_autofree gchar *binding = NULL;
combo->keycode = self->custom_combo->keycode;
combo->keyval = self->custom_combo->keyval;
@ -168,8 +168,6 @@ apply_custom_item_fields (CcKeyboardShortcutEditor *self,
combo->mask);
g_object_set (G_OBJECT (item), "binding", binding, NULL);
g_free (binding);
}
/* Set the keyboard shortcut name and command for custom entries */

View file

@ -32,10 +32,10 @@
static char *
replace_pictures_folder (const char *description)
{
GRegex *pictures_regex;
g_autoptr(GRegex) pictures_regex = NULL;
const char *path;
char *dirname;
char *ret;
g_autofree gchar *dirname = NULL;
g_autofree gchar *ret = NULL;
if (description == NULL)
return NULL;
@ -49,13 +49,10 @@ replace_pictures_folder (const char *description)
ret = g_regex_replace (pictures_regex, description, -1,
0, dirname, 0, NULL);
g_regex_unref (pictures_regex);
g_free (dirname);
if (ret == NULL)
return g_strdup (description);
return ret;
return g_steal_pointer (&ret);
}
static void
@ -312,8 +309,8 @@ is_valid_accel (CcKeyCombo *combo)
gchar*
find_free_settings_path (GSettings *settings)
{
char **used_names;
char *dir = NULL;
g_auto(GStrv) used_names = NULL;
g_autofree gchar *dir = NULL;
int i, num, n_names;
used_names = g_settings_get_strv (settings, "custom-keybindings");
@ -321,7 +318,7 @@ find_free_settings_path (GSettings *settings)
for (num = 0; dir == NULL; num++)
{
char *tmp;
g_autofree gchar *tmp = NULL;
gboolean found = FALSE;
tmp = g_strdup_printf ("%s/custom%d/", CUSTOM_KEYS_BASENAME, num);
@ -329,13 +326,10 @@ find_free_settings_path (GSettings *settings)
found = strcmp (used_names[i], tmp) == 0;
if (!found)
dir = tmp;
else
g_free (tmp);
dir = g_steal_pointer (&tmp);
}
g_strfreev (used_names);
return dir;
return g_steal_pointer (&dir);
}
static gboolean
@ -380,12 +374,12 @@ KeyList*
parse_keylist_from_file (const gchar *path)
{
KeyList *keylist;
GError *err = NULL;
char *buf;
g_autoptr(GError) err = NULL;
g_autofree gchar *buf = NULL;
gsize buf_len;
guint i;
GMarkupParseContext *ctx;
g_autoptr(GMarkupParseContext) ctx = NULL;
GMarkupParser parser = { parse_start_tag, NULL, NULL, NULL, NULL };
/* Parse file */
@ -399,7 +393,6 @@ parse_keylist_from_file (const gchar *path)
if (!g_markup_parse_context_parse (ctx, buf, buf_len, &err))
{
g_warning ("Failed to parse '%s': '%s'", path, err->message);
g_error_free (err);
g_free (keylist->name);
g_free (keylist->package);
g_free (keylist->wm_name);
@ -409,10 +402,8 @@ parse_keylist_from_file (const gchar *path)
g_array_free (keylist->entries, TRUE);
g_free (keylist);
keylist = NULL;
return NULL;
}
g_markup_parse_context_free (ctx);
g_free (buf);
return keylist;
}