Commit 79e00c37 authored by Robert Ancell's avatar Robert Ancell Committed by Georges Basile Stavracas Neto

region: Use g_auto for variables

parent 389bb1b8
Pipeline #13324 passed with stages
in 7 minutes and 58 seconds
......@@ -59,24 +59,25 @@ typedef struct {
static void
display_date (GtkWidget *label, GDateTime *dt, const gchar *format)
{
gchar *s;
s = g_date_time_format (dt, format);
s = g_strstrip (s);
gtk_label_set_text (GTK_LABEL (label), s);
g_free (s);
g_autofree gchar *s = g_date_time_format (dt, format);
gtk_label_set_text (GTK_LABEL (label), g_strstrip (s));
}
static void
update_format_examples (GtkDialog *chooser)
{
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
gchar *locale;
GDateTime *dt;
gchar *s;
g_autofree gchar *time_locale = NULL;
g_autofree gchar *numeric_locale = NULL;
g_autofree gchar *monetary_locale = NULL;
g_autofree gchar *measurement_locale = NULL;
g_autofree gchar *paper_locale = NULL;
g_autoptr(GDateTime) dt = NULL;
g_autofree gchar *s = NULL;
const gchar *fmt;
GtkPaperSize *paper;
g_autoptr(GtkPaperSize) paper = NULL;
locale = g_strdup (setlocale (LC_TIME, NULL));
time_locale = g_strdup (setlocale (LC_TIME, NULL));
setlocale (LC_TIME, priv->region);
dt = g_date_time_new_now_local ();
......@@ -84,33 +85,29 @@ update_format_examples (GtkDialog *chooser)
display_date (priv->time, dt, "%X");
display_date (priv->date_time, dt, "%c");
setlocale (LC_TIME, locale);
g_free (locale);
setlocale (LC_TIME, time_locale);
locale = g_strdup (setlocale (LC_NUMERIC, NULL));
numeric_locale = g_strdup (setlocale (LC_NUMERIC, NULL));
setlocale (LC_NUMERIC, priv->region);
s = g_strdup_printf ("%'.2f", 123456789.00);
gtk_label_set_text (GTK_LABEL (priv->number), s);
g_free (s);
setlocale (LC_NUMERIC, locale);
g_free (locale);
setlocale (LC_NUMERIC, numeric_locale);
#if 0
locale = g_strdup (setlocale (LC_MONETARY, NULL));
monetary_locale = g_strdup (setlocale (LC_MONETARY, NULL));
setlocale (LC_MONETARY, priv->region);
num_info = localeconv ();
if (num_info != NULL)
gtk_label_set_text (GTK_LABEL (priv->currency), num_info->currency_symbol);
setlocale (LC_MONETARY, locale);
g_free (locale);
setlocale (LC_MONETARY, monetary_locale);
#endif
#ifdef LC_MEASUREMENT
locale = g_strdup (setlocale (LC_MEASUREMENT, NULL));
measurement_locale = g_strdup (setlocale (LC_MEASUREMENT, NULL));
setlocale (LC_MEASUREMENT, priv->region);
fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
......@@ -119,20 +116,17 @@ update_format_examples (GtkDialog *chooser)
else
gtk_label_set_text (GTK_LABEL (priv->measurement), C_("measurement format", "Metric"));
setlocale (LC_MEASUREMENT, locale);
g_free (locale);
setlocale (LC_MEASUREMENT, measurement_locale);
#endif
#ifdef LC_PAPER
locale = g_strdup (setlocale (LC_PAPER, NULL));
paper_locale = g_strdup (setlocale (LC_PAPER, NULL));
setlocale (LC_PAPER, priv->region);
paper = gtk_paper_size_new (gtk_paper_size_get_default ());
gtk_label_set_text (GTK_LABEL (priv->paper), gtk_paper_size_get_display_name (paper));
gtk_paper_size_free (paper);
setlocale (LC_PAPER, locale);
g_free (locale);
setlocale (LC_PAPER, paper_locale);
#endif
}
......@@ -141,7 +135,8 @@ set_locale_id (GtkDialog *chooser,
const gchar *locale_id)
{
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
GList *children, *l;
g_autoptr(GList) children = NULL;
GList *l;
children = gtk_container_get_children (GTK_CONTAINER (priv->list));
for (l = children; l; l = l->next) {
......@@ -169,7 +164,6 @@ set_locale_id (GtkDialog *chooser,
gtk_widget_set_opacity (check, 0.0);
}
}
g_list_free (children);
g_free (priv->region);
priv->region = g_strdup (locale_id);
......@@ -325,14 +319,12 @@ add_regions (GtkDialog *chooser,
static void
add_all_regions (GtkDialog *chooser)
{
gchar **locale_ids;
GHashTable *initial;
g_auto(GStrv) locale_ids = NULL;
g_autoptr(GHashTable) initial = NULL;
locale_ids = gnome_get_all_locales ();
initial = cc_common_language_get_initial_languages ();
add_regions (chooser, locale_ids, initial);
g_hash_table_destroy (initial);
g_strfreev (locale_ids);
}
static gboolean
......@@ -354,11 +346,10 @@ region_visible (GtkListBoxRow *row,
{
GtkDialog *chooser = user_data;
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
gchar *locale_name = NULL;
gchar *locale_current_name = NULL;
gchar *locale_untranslated_name = NULL;
g_autofree gchar *locale_name = NULL;
g_autofree gchar *locale_current_name = NULL;
g_autofree gchar *locale_untranslated_name = NULL;
gboolean is_extra;
gboolean visible;
if (row == priv->more_item)
return !priv->showing_extra;
......@@ -371,36 +362,26 @@ region_visible (GtkListBoxRow *row,
if (!priv->filter_words)
return TRUE;
visible = FALSE;
locale_name =
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (row), "locale-name"));
visible = match_all (priv->filter_words, locale_name);
if (visible)
goto out;
if (match_all (priv->filter_words, locale_name))
return TRUE;
locale_current_name =
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (row), "locale-current-name"));
visible = match_all (priv->filter_words, locale_current_name);
if (visible)
goto out;
if (match_all (priv->filter_words, locale_current_name))
return TRUE;
locale_untranslated_name =
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (row), "locale-untranslated-name"));
visible = match_all (priv->filter_words, locale_untranslated_name);
out:
g_free (locale_untranslated_name);
g_free (locale_current_name);
g_free (locale_name);
return visible;
return match_all (priv->filter_words, locale_untranslated_name);
}
static void
filter_changed (GtkDialog *chooser)
{
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
gchar *filter_contents = NULL;
g_autofree gchar *filter_contents = NULL;
g_clear_pointer (&priv->filter_words, g_strfreev);
......@@ -412,7 +393,6 @@ filter_changed (GtkDialog *chooser)
return;
}
priv->filter_words = g_strsplit_set (g_strstrip (filter_contents), " ", 0);
g_free (filter_contents);
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->list), GTK_WIDGET (priv->no_results));
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
}
......@@ -447,7 +427,7 @@ row_activated (GtkListBox *box,
GtkDialog *chooser)
{
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
gchar *new_locale_id;
const gchar *new_locale_id;
if (priv->adding)
return;
......@@ -475,7 +455,7 @@ activate_default (GtkWindow *window,
{
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
GtkWidget *focus;
gchar *locale_id;
const gchar *locale_id;
focus = gtk_window_get_focus (window);
if (!focus)
......@@ -505,23 +485,21 @@ cc_format_chooser_private_free (gpointer data)
GtkWidget *
cc_format_chooser_new (GtkWidget *parent)
{
GtkBuilder *builder;
g_autoptr(GtkBuilder) builder = NULL;
GtkWidget *chooser;
CcFormatChooserPrivate *priv;
GError *error = NULL;
g_autoptr(GError) error = NULL;
builder = gtk_builder_new ();
if (gtk_builder_add_from_resource (builder, "/org/gnome/control-center/region/format-chooser.ui", &error) == 0) {
g_object_unref (builder);
g_warning ("failed to load format chooser: %s", error->message);
g_error_free (error);
return NULL;
}
chooser = WID ("dialog");
priv = g_new0 (CcFormatChooserPrivate, 1);
g_object_set_data_full (G_OBJECT (chooser), "private", priv, cc_format_chooser_private_free);
g_object_set_data_full (G_OBJECT (chooser), "builder", builder, g_object_unref);
g_object_set_data_full (G_OBJECT (chooser), "builder", g_object_ref (builder), g_object_unref);
priv->done_button = WID ("ok-button");
priv->filter_entry = WID ("region-filter-entry");
......
......@@ -274,12 +274,12 @@ input_source_row_new (GtkWidget *chooser,
static void
remove_all_children (GtkContainer *container)
{
GList *list, *l;
g_autoptr(GList) list = NULL;
GList *l;
list = gtk_container_get_children (container);
for (l = list; l; l = l->next)
gtk_container_remove (container, (GtkWidget *) l->data);
g_list_free (list);
}
static void
......@@ -371,7 +371,7 @@ static void
show_locale_rows (GtkWidget *chooser)
{
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
GHashTable *initial = NULL;
g_autoptr(GHashTable) initial = NULL;
LocaleInfo *info;
GHashTableIter iter;
......@@ -415,9 +415,6 @@ show_locale_rows (GtkWidget *chooser)
if (gtk_widget_is_visible (priv->filter_entry) &&
!gtk_widget_is_focus (priv->filter_entry))
gtk_widget_grab_focus (priv->filter_entry);
if (!priv->showing_extra)
g_hash_table_destroy (initial);
}
static gint
......@@ -573,39 +570,34 @@ static gboolean
do_filter (GtkWidget *chooser)
{
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
gchar **previous_words;
gchar *filter_contents = NULL;
g_autofree gchar *filter_contents = NULL;
gboolean words_changed;
priv->filter_timeout_id = 0;
previous_words = priv->filter_words;
filter_contents =
cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (priv->filter_entry)));
words_changed = !priv->filter_words;
if (filter_contents)
{
g_auto(GStrv) previous_words = priv->filter_words;
priv->filter_words = g_strsplit_set (g_strstrip (filter_contents), " ", 0);
g_free (filter_contents);
if (strvs_differ (priv->filter_words, previous_words))
words_changed = TRUE;
}
if (!priv->filter_words || !priv->filter_words[0])
{
g_clear_pointer (&priv->filter_words, g_strfreev);
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->list), NULL);
}
else
else if (words_changed)
{
if (!previous_words || strvs_differ (priv->filter_words, previous_words))
{
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->list), priv->no_results);
}
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->list), priv->no_results);
}
g_strfreev (previous_words);
return G_SOURCE_REMOVE;
}
......@@ -818,15 +810,15 @@ get_ibus_locale_infos (GtkWidget *chooser)
g_hash_table_iter_init (&iter, priv->ibus_engines);
while (g_hash_table_iter_next (&iter, (gpointer *) &engine_id, (gpointer *) &engine))
{
gchar *lang_code = NULL;
gchar *country_code = NULL;
g_autofree gchar *lang_code = NULL;
g_autofree gchar *country_code = NULL;
const gchar *ibus_locale = ibus_engine_desc_get_language (engine);
if (gnome_parse_locale (ibus_locale, &lang_code, &country_code, NULL, NULL) &&
lang_code != NULL &&
country_code != NULL)
{
gchar *locale = g_strdup_printf ("%s_%s.UTF-8", lang_code, country_code);
g_autofree gchar *locale = g_strdup_printf ("%s_%s.UTF-8", lang_code, country_code);
info = g_hash_table_lookup (priv->locales, locale);
if (info)
......@@ -848,14 +840,12 @@ get_ibus_locale_infos (GtkWidget *chooser)
{
add_row_other (chooser, INPUT_SOURCE_TYPE_IBUS, engine_id);
}
g_free (locale);
}
else if (lang_code != NULL)
{
GHashTableIter iter;
GHashTable *locales_for_language;
gchar *language;
g_autofree gchar *language = NULL;
/* Most IBus engines only specify the language so we try to
add them to all locales for that language. */
......@@ -865,7 +855,6 @@ get_ibus_locale_infos (GtkWidget *chooser)
locales_for_language = g_hash_table_lookup (priv->locales_by_language, language);
else
locales_for_language = NULL;
g_free (language);
if (locales_for_language)
{
......@@ -883,9 +872,6 @@ get_ibus_locale_infos (GtkWidget *chooser)
{
add_row_other (chooser, INPUT_SOURCE_TYPE_IBUS, engine_id);
}
g_free (country_code);
g_free (lang_code);
}
}
#endif /* HAVE_IBUS */
......@@ -896,7 +882,7 @@ add_locale_to_table (GHashTable *table,
LocaleInfo *info)
{
GHashTable *set;
gchar *language;
g_autofree gchar *language = NULL;
language = gnome_get_language_from_code (lang_code, NULL);
......@@ -907,8 +893,6 @@ add_locale_to_table (GHashTable *table,
g_hash_table_replace (table, g_strdup (language), set);
}
g_hash_table_add (set, info);
g_free (language);
}
static void
......@@ -926,11 +910,12 @@ static void
get_locale_infos (GtkWidget *chooser)
{
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
GHashTable *layouts_with_locale;
g_autoptr(GHashTable) layouts_with_locale = NULL;
LocaleInfo *info;
gchar **locale_ids;
g_auto(GStrv) locale_ids = NULL;
gchar **locale;
GList *list, *l;
g_autoptr(GList) all_layouts = NULL;
GList *l;
priv->locales = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, locale_info_free);
......@@ -942,11 +927,13 @@ get_locale_infos (GtkWidget *chooser)
locale_ids = gnome_get_all_locales ();
for (locale = locale_ids; *locale; ++locale)
{
gchar *lang_code, *country_code;
gchar *simple_locale;
gchar *tmp;
g_autofree gchar *lang_code = NULL;
g_autofree gchar *country_code = NULL;
g_autofree gchar *simple_locale = NULL;
g_autofree gchar *tmp = NULL;
const gchar *type = NULL;
const gchar *id = NULL;
g_autoptr(GList) language_layouts = NULL;
if (!gnome_parse_locale (*locale, &lang_code, &country_code, NULL, NULL))
continue;
......@@ -957,20 +944,14 @@ get_locale_infos (GtkWidget *chooser)
simple_locale = g_strdup_printf ("%s.UTF-8", lang_code);
if (g_hash_table_contains (priv->locales, simple_locale))
{
g_free (simple_locale);
g_free (country_code);
g_free (lang_code);
continue;
}
info = g_new0 (LocaleInfo, 1);
info->id = simple_locale; /* Take ownership */
info->id = g_steal_pointer (&simple_locale);
info->name = gnome_get_language_from_locale (simple_locale, NULL);
info->unaccented_name = cc_util_normalize_casefold_and_unaccent (info->name);
tmp = gnome_get_language_from_locale (simple_locale, "C");
info->untranslated_name = cc_util_normalize_casefold_and_unaccent (tmp);
g_free (tmp);
g_hash_table_replace (priv->locales, simple_locale, info);
add_locale_to_table (priv->locales_by_language, lang_code, info);
......@@ -988,23 +969,17 @@ get_locale_infos (GtkWidget *chooser)
info->engine_rows_by_id = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, g_object_unref);
list = gnome_xkb_info_get_layouts_for_language (priv->xkb_info, lang_code);
add_rows_to_table (chooser, info, list, INPUT_SOURCE_TYPE_XKB, id);
add_ids_to_set (layouts_with_locale, list);
g_list_free (list);
language_layouts = gnome_xkb_info_get_layouts_for_language (priv->xkb_info, lang_code);
add_rows_to_table (chooser, info, language_layouts, INPUT_SOURCE_TYPE_XKB, id);
add_ids_to_set (layouts_with_locale, language_layouts);
if (country_code != NULL)
{
list = gnome_xkb_info_get_layouts_for_country (priv->xkb_info, country_code);
add_rows_to_table (chooser, info, list, INPUT_SOURCE_TYPE_XKB, id);
add_ids_to_set (layouts_with_locale, list);
g_list_free (list);
g_autoptr(GList) country_layouts = gnome_xkb_info_get_layouts_for_country (priv->xkb_info, country_code);
add_rows_to_table (chooser, info, country_layouts, INPUT_SOURCE_TYPE_XKB, id);
add_ids_to_set (layouts_with_locale, country_layouts);
}
g_free (lang_code);
g_free (country_code);
}
g_strfreev (locale_ids);
/* Add a "Other" locale to hold the remaining input sources */
info = g_new0 (LocaleInfo, 1);
......@@ -1019,14 +994,10 @@ get_locale_infos (GtkWidget *chooser)
info->engine_rows_by_id = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, g_object_unref);
list = gnome_xkb_info_get_all_layouts (priv->xkb_info);
for (l = list; l; l = l->next)
all_layouts = gnome_xkb_info_get_all_layouts (priv->xkb_info);
for (l = all_layouts; l; l = l->next)
if (!g_hash_table_contains (layouts_with_locale, l->data))
add_row_other (chooser, INPUT_SOURCE_TYPE_XKB, l->data);
g_list_free (list);
g_hash_table_destroy (layouts_with_locale);
}
static void
......@@ -1061,18 +1032,16 @@ cc_input_chooser_new (GtkWindow *main_window,
GnomeXkbInfo *xkb_info,
GHashTable *ibus_engines)
{
GtkBuilder *builder;
g_autoptr(GtkBuilder) builder = NULL;
GtkWidget *chooser;
CcInputChooserPrivate *priv;
gint width, height;
GError *error = NULL;
g_autoptr(GError) error = NULL;
builder = gtk_builder_new ();
if (gtk_builder_add_from_resource (builder, "/org/gnome/control-center/region/input-chooser.ui", &error) == 0)
{
g_object_unref (builder);
g_warning ("failed to load input chooser: %s", error->message);
g_error_free (error);
return NULL;
}
chooser = WID ("input-dialog");
......@@ -1119,8 +1088,6 @@ cc_input_chooser_new (GtkWindow *main_window,
gtk_window_set_transient_for (GTK_WINDOW (chooser), main_window);
g_object_unref (builder);
return chooser;
}
......
......@@ -45,8 +45,9 @@ static void
update_shortcut_label (GtkWidget *widget,
const gchar *value)
{
gchar *text;
guint accel_key, *keycode;
g_autofree gchar *text = NULL;
guint accel_key;
g_autofree guint *keycode = NULL;
GdkModifierType mods;
if (value == NULL || *value == '\0') {
......@@ -62,18 +63,16 @@ update_shortcut_label (GtkWidget *widget,
}
text = gtk_accelerator_get_label_with_keycode (gtk_widget_get_display (widget), accel_key, *keycode, mods);
g_free (keycode);
gtk_label_set_text (GTK_LABEL (widget), text);
g_free (text);
}
static void
update_shortcuts (CcInputOptions *self)
{
gchar **previous;
gchar **next;
gchar *previous_shortcut;
GSettings *settings;
g_auto(GStrv) previous = NULL;
g_auto(GStrv) next = NULL;
g_autofree gchar *previous_shortcut = NULL;
g_autoptr(GSettings) settings = NULL;
settings = g_settings_new ("org.gnome.desktop.wm.keybindings");
......@@ -84,21 +83,15 @@ update_shortcuts (CcInputOptions *self)
update_shortcut_label (self->previous_source, previous_shortcut);
update_shortcut_label (self->next_source, next[0]);
g_free (previous_shortcut);
g_strfreev (previous);
g_strfreev (next);
g_object_unref (settings);
}
static void
update_modifiers_shortcut (CcInputOptions *self)
{
gchar **options, **p;
GSettings *settings;
GnomeXkbInfo *xkb_info;
g_auto(GStrv) options = NULL;
gchar **p;
g_autoptr(GSettings) settings = NULL;
g_autoptr(GnomeXkbInfo) xkb_info = NULL;
const gchar *text;
xkb_info = gnome_xkb_info_new ();
......@@ -115,10 +108,6 @@ update_modifiers_shortcut (CcInputOptions *self)
} else {
gtk_widget_hide (self->alt_next_source);
}
g_strfreev (options);
g_object_unref (settings);
g_object_unref (xkb_info);
}
static void
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment