region: Use g_auto for variables
This commit is contained in:
parent
389bb1b87c
commit
79e00c37b0
4 changed files with 195 additions and 317 deletions
|
@ -59,24 +59,25 @@ typedef struct {
|
||||||
static void
|
static void
|
||||||
display_date (GtkWidget *label, GDateTime *dt, const gchar *format)
|
display_date (GtkWidget *label, GDateTime *dt, const gchar *format)
|
||||||
{
|
{
|
||||||
gchar *s;
|
g_autofree gchar *s = g_date_time_format (dt, format);
|
||||||
s = g_date_time_format (dt, format);
|
gtk_label_set_text (GTK_LABEL (label), g_strstrip (s));
|
||||||
s = g_strstrip (s);
|
|
||||||
gtk_label_set_text (GTK_LABEL (label), s);
|
|
||||||
g_free (s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_format_examples (GtkDialog *chooser)
|
update_format_examples (GtkDialog *chooser)
|
||||||
{
|
{
|
||||||
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
||||||
gchar *locale;
|
g_autofree gchar *time_locale = NULL;
|
||||||
GDateTime *dt;
|
g_autofree gchar *numeric_locale = NULL;
|
||||||
gchar *s;
|
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;
|
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);
|
setlocale (LC_TIME, priv->region);
|
||||||
|
|
||||||
dt = g_date_time_new_now_local ();
|
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->time, dt, "%X");
|
||||||
display_date (priv->date_time, dt, "%c");
|
display_date (priv->date_time, dt, "%c");
|
||||||
|
|
||||||
setlocale (LC_TIME, locale);
|
setlocale (LC_TIME, time_locale);
|
||||||
g_free (locale);
|
|
||||||
|
|
||||||
locale = g_strdup (setlocale (LC_NUMERIC, NULL));
|
numeric_locale = g_strdup (setlocale (LC_NUMERIC, NULL));
|
||||||
setlocale (LC_NUMERIC, priv->region);
|
setlocale (LC_NUMERIC, priv->region);
|
||||||
|
|
||||||
s = g_strdup_printf ("%'.2f", 123456789.00);
|
s = g_strdup_printf ("%'.2f", 123456789.00);
|
||||||
gtk_label_set_text (GTK_LABEL (priv->number), s);
|
gtk_label_set_text (GTK_LABEL (priv->number), s);
|
||||||
g_free (s);
|
|
||||||
|
|
||||||
setlocale (LC_NUMERIC, locale);
|
setlocale (LC_NUMERIC, numeric_locale);
|
||||||
g_free (locale);
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
locale = g_strdup (setlocale (LC_MONETARY, NULL));
|
monetary_locale = g_strdup (setlocale (LC_MONETARY, NULL));
|
||||||
setlocale (LC_MONETARY, priv->region);
|
setlocale (LC_MONETARY, priv->region);
|
||||||
|
|
||||||
num_info = localeconv ();
|
num_info = localeconv ();
|
||||||
if (num_info != NULL)
|
if (num_info != NULL)
|
||||||
gtk_label_set_text (GTK_LABEL (priv->currency), num_info->currency_symbol);
|
gtk_label_set_text (GTK_LABEL (priv->currency), num_info->currency_symbol);
|
||||||
|
|
||||||
setlocale (LC_MONETARY, locale);
|
setlocale (LC_MONETARY, monetary_locale);
|
||||||
g_free (locale);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LC_MEASUREMENT
|
#ifdef LC_MEASUREMENT
|
||||||
locale = g_strdup (setlocale (LC_MEASUREMENT, NULL));
|
measurement_locale = g_strdup (setlocale (LC_MEASUREMENT, NULL));
|
||||||
setlocale (LC_MEASUREMENT, priv->region);
|
setlocale (LC_MEASUREMENT, priv->region);
|
||||||
|
|
||||||
fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
|
fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
|
||||||
|
@ -119,20 +116,17 @@ update_format_examples (GtkDialog *chooser)
|
||||||
else
|
else
|
||||||
gtk_label_set_text (GTK_LABEL (priv->measurement), C_("measurement format", "Metric"));
|
gtk_label_set_text (GTK_LABEL (priv->measurement), C_("measurement format", "Metric"));
|
||||||
|
|
||||||
setlocale (LC_MEASUREMENT, locale);
|
setlocale (LC_MEASUREMENT, measurement_locale);
|
||||||
g_free (locale);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LC_PAPER
|
#ifdef LC_PAPER
|
||||||
locale = g_strdup (setlocale (LC_PAPER, NULL));
|
paper_locale = g_strdup (setlocale (LC_PAPER, NULL));
|
||||||
setlocale (LC_PAPER, priv->region);
|
setlocale (LC_PAPER, priv->region);
|
||||||
|
|
||||||
paper = gtk_paper_size_new (gtk_paper_size_get_default ());
|
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_label_set_text (GTK_LABEL (priv->paper), gtk_paper_size_get_display_name (paper));
|
||||||
gtk_paper_size_free (paper);
|
|
||||||
|
|
||||||
setlocale (LC_PAPER, locale);
|
setlocale (LC_PAPER, paper_locale);
|
||||||
g_free (locale);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +135,8 @@ set_locale_id (GtkDialog *chooser,
|
||||||
const gchar *locale_id)
|
const gchar *locale_id)
|
||||||
{
|
{
|
||||||
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (priv->list));
|
children = gtk_container_get_children (GTK_CONTAINER (priv->list));
|
||||||
for (l = children; l; l = l->next) {
|
for (l = children; l; l = l->next) {
|
||||||
|
@ -169,7 +164,6 @@ set_locale_id (GtkDialog *chooser,
|
||||||
gtk_widget_set_opacity (check, 0.0);
|
gtk_widget_set_opacity (check, 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
|
||||||
|
|
||||||
g_free (priv->region);
|
g_free (priv->region);
|
||||||
priv->region = g_strdup (locale_id);
|
priv->region = g_strdup (locale_id);
|
||||||
|
@ -325,14 +319,12 @@ add_regions (GtkDialog *chooser,
|
||||||
static void
|
static void
|
||||||
add_all_regions (GtkDialog *chooser)
|
add_all_regions (GtkDialog *chooser)
|
||||||
{
|
{
|
||||||
gchar **locale_ids;
|
g_auto(GStrv) locale_ids = NULL;
|
||||||
GHashTable *initial;
|
g_autoptr(GHashTable) initial = NULL;
|
||||||
|
|
||||||
locale_ids = gnome_get_all_locales ();
|
locale_ids = gnome_get_all_locales ();
|
||||||
initial = cc_common_language_get_initial_languages ();
|
initial = cc_common_language_get_initial_languages ();
|
||||||
add_regions (chooser, locale_ids, initial);
|
add_regions (chooser, locale_ids, initial);
|
||||||
g_hash_table_destroy (initial);
|
|
||||||
g_strfreev (locale_ids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -354,11 +346,10 @@ region_visible (GtkListBoxRow *row,
|
||||||
{
|
{
|
||||||
GtkDialog *chooser = user_data;
|
GtkDialog *chooser = user_data;
|
||||||
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
||||||
gchar *locale_name = NULL;
|
g_autofree gchar *locale_name = NULL;
|
||||||
gchar *locale_current_name = NULL;
|
g_autofree gchar *locale_current_name = NULL;
|
||||||
gchar *locale_untranslated_name = NULL;
|
g_autofree gchar *locale_untranslated_name = NULL;
|
||||||
gboolean is_extra;
|
gboolean is_extra;
|
||||||
gboolean visible;
|
|
||||||
|
|
||||||
if (row == priv->more_item)
|
if (row == priv->more_item)
|
||||||
return !priv->showing_extra;
|
return !priv->showing_extra;
|
||||||
|
@ -371,36 +362,26 @@ region_visible (GtkListBoxRow *row,
|
||||||
if (!priv->filter_words)
|
if (!priv->filter_words)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
visible = FALSE;
|
|
||||||
|
|
||||||
locale_name =
|
locale_name =
|
||||||
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (row), "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 (match_all (priv->filter_words, locale_name))
|
||||||
if (visible)
|
return TRUE;
|
||||||
goto out;
|
|
||||||
|
|
||||||
locale_current_name =
|
locale_current_name =
|
||||||
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (row), "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 (match_all (priv->filter_words, locale_current_name))
|
||||||
if (visible)
|
return TRUE;
|
||||||
goto out;
|
|
||||||
|
|
||||||
locale_untranslated_name =
|
locale_untranslated_name =
|
||||||
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (row), "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);
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
filter_changed (GtkDialog *chooser)
|
filter_changed (GtkDialog *chooser)
|
||||||
{
|
{
|
||||||
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
||||||
gchar *filter_contents = NULL;
|
g_autofree gchar *filter_contents = NULL;
|
||||||
|
|
||||||
g_clear_pointer (&priv->filter_words, g_strfreev);
|
g_clear_pointer (&priv->filter_words, g_strfreev);
|
||||||
|
|
||||||
|
@ -412,7 +393,6 @@ filter_changed (GtkDialog *chooser)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
priv->filter_words = g_strsplit_set (g_strstrip (filter_contents), " ", 0);
|
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_set_placeholder (GTK_LIST_BOX (priv->list), GTK_WIDGET (priv->no_results));
|
||||||
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
|
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
|
||||||
}
|
}
|
||||||
|
@ -447,7 +427,7 @@ row_activated (GtkListBox *box,
|
||||||
GtkDialog *chooser)
|
GtkDialog *chooser)
|
||||||
{
|
{
|
||||||
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
||||||
gchar *new_locale_id;
|
const gchar *new_locale_id;
|
||||||
|
|
||||||
if (priv->adding)
|
if (priv->adding)
|
||||||
return;
|
return;
|
||||||
|
@ -475,7 +455,7 @@ activate_default (GtkWindow *window,
|
||||||
{
|
{
|
||||||
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
|
||||||
GtkWidget *focus;
|
GtkWidget *focus;
|
||||||
gchar *locale_id;
|
const gchar *locale_id;
|
||||||
|
|
||||||
focus = gtk_window_get_focus (window);
|
focus = gtk_window_get_focus (window);
|
||||||
if (!focus)
|
if (!focus)
|
||||||
|
@ -505,23 +485,21 @@ cc_format_chooser_private_free (gpointer data)
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
cc_format_chooser_new (GtkWidget *parent)
|
cc_format_chooser_new (GtkWidget *parent)
|
||||||
{
|
{
|
||||||
GtkBuilder *builder;
|
g_autoptr(GtkBuilder) builder = NULL;
|
||||||
GtkWidget *chooser;
|
GtkWidget *chooser;
|
||||||
CcFormatChooserPrivate *priv;
|
CcFormatChooserPrivate *priv;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
builder = gtk_builder_new ();
|
builder = gtk_builder_new ();
|
||||||
if (gtk_builder_add_from_resource (builder, "/org/gnome/control-center/region/format-chooser.ui", &error) == 0) {
|
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_warning ("failed to load format chooser: %s", error->message);
|
||||||
g_error_free (error);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
chooser = WID ("dialog");
|
chooser = WID ("dialog");
|
||||||
priv = g_new0 (CcFormatChooserPrivate, 1);
|
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), "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->done_button = WID ("ok-button");
|
||||||
priv->filter_entry = WID ("region-filter-entry");
|
priv->filter_entry = WID ("region-filter-entry");
|
||||||
|
|
|
@ -274,12 +274,12 @@ input_source_row_new (GtkWidget *chooser,
|
||||||
static void
|
static void
|
||||||
remove_all_children (GtkContainer *container)
|
remove_all_children (GtkContainer *container)
|
||||||
{
|
{
|
||||||
GList *list, *l;
|
g_autoptr(GList) list = NULL;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
list = gtk_container_get_children (container);
|
list = gtk_container_get_children (container);
|
||||||
for (l = list; l; l = l->next)
|
for (l = list; l; l = l->next)
|
||||||
gtk_container_remove (container, (GtkWidget *) l->data);
|
gtk_container_remove (container, (GtkWidget *) l->data);
|
||||||
g_list_free (list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -371,7 +371,7 @@ static void
|
||||||
show_locale_rows (GtkWidget *chooser)
|
show_locale_rows (GtkWidget *chooser)
|
||||||
{
|
{
|
||||||
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
|
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
|
||||||
GHashTable *initial = NULL;
|
g_autoptr(GHashTable) initial = NULL;
|
||||||
LocaleInfo *info;
|
LocaleInfo *info;
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
|
|
||||||
|
@ -415,9 +415,6 @@ show_locale_rows (GtkWidget *chooser)
|
||||||
if (gtk_widget_is_visible (priv->filter_entry) &&
|
if (gtk_widget_is_visible (priv->filter_entry) &&
|
||||||
!gtk_widget_is_focus (priv->filter_entry))
|
!gtk_widget_is_focus (priv->filter_entry))
|
||||||
gtk_widget_grab_focus (priv->filter_entry);
|
gtk_widget_grab_focus (priv->filter_entry);
|
||||||
|
|
||||||
if (!priv->showing_extra)
|
|
||||||
g_hash_table_destroy (initial);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
@ -573,38 +570,33 @@ static gboolean
|
||||||
do_filter (GtkWidget *chooser)
|
do_filter (GtkWidget *chooser)
|
||||||
{
|
{
|
||||||
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
|
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
|
||||||
gchar **previous_words;
|
g_autofree gchar *filter_contents = NULL;
|
||||||
gchar *filter_contents = NULL;
|
gboolean words_changed;
|
||||||
|
|
||||||
priv->filter_timeout_id = 0;
|
priv->filter_timeout_id = 0;
|
||||||
|
|
||||||
previous_words = priv->filter_words;
|
|
||||||
|
|
||||||
filter_contents =
|
filter_contents =
|
||||||
cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (priv->filter_entry)));
|
cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (priv->filter_entry)));
|
||||||
|
|
||||||
|
words_changed = !priv->filter_words;
|
||||||
if (filter_contents)
|
if (filter_contents)
|
||||||
{
|
{
|
||||||
|
g_auto(GStrv) previous_words = priv->filter_words;
|
||||||
priv->filter_words = g_strsplit_set (g_strstrip (filter_contents), " ", 0);
|
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])
|
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_invalidate_filter (GTK_LIST_BOX (priv->list));
|
||||||
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->list), NULL);
|
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_invalidate_filter (GTK_LIST_BOX (priv->list));
|
||||||
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->list), priv->no_results);
|
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->list), priv->no_results);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
g_strfreev (previous_words);
|
|
||||||
|
|
||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
@ -818,15 +810,15 @@ get_ibus_locale_infos (GtkWidget *chooser)
|
||||||
g_hash_table_iter_init (&iter, priv->ibus_engines);
|
g_hash_table_iter_init (&iter, priv->ibus_engines);
|
||||||
while (g_hash_table_iter_next (&iter, (gpointer *) &engine_id, (gpointer *) &engine))
|
while (g_hash_table_iter_next (&iter, (gpointer *) &engine_id, (gpointer *) &engine))
|
||||||
{
|
{
|
||||||
gchar *lang_code = NULL;
|
g_autofree gchar *lang_code = NULL;
|
||||||
gchar *country_code = NULL;
|
g_autofree gchar *country_code = NULL;
|
||||||
const gchar *ibus_locale = ibus_engine_desc_get_language (engine);
|
const gchar *ibus_locale = ibus_engine_desc_get_language (engine);
|
||||||
|
|
||||||
if (gnome_parse_locale (ibus_locale, &lang_code, &country_code, NULL, NULL) &&
|
if (gnome_parse_locale (ibus_locale, &lang_code, &country_code, NULL, NULL) &&
|
||||||
lang_code != NULL &&
|
lang_code != NULL &&
|
||||||
country_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);
|
info = g_hash_table_lookup (priv->locales, locale);
|
||||||
if (info)
|
if (info)
|
||||||
|
@ -848,14 +840,12 @@ get_ibus_locale_infos (GtkWidget *chooser)
|
||||||
{
|
{
|
||||||
add_row_other (chooser, INPUT_SOURCE_TYPE_IBUS, engine_id);
|
add_row_other (chooser, INPUT_SOURCE_TYPE_IBUS, engine_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (locale);
|
|
||||||
}
|
}
|
||||||
else if (lang_code != NULL)
|
else if (lang_code != NULL)
|
||||||
{
|
{
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
GHashTable *locales_for_language;
|
GHashTable *locales_for_language;
|
||||||
gchar *language;
|
g_autofree gchar *language = NULL;
|
||||||
|
|
||||||
/* Most IBus engines only specify the language so we try to
|
/* Most IBus engines only specify the language so we try to
|
||||||
add them to all locales for that language. */
|
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);
|
locales_for_language = g_hash_table_lookup (priv->locales_by_language, language);
|
||||||
else
|
else
|
||||||
locales_for_language = NULL;
|
locales_for_language = NULL;
|
||||||
g_free (language);
|
|
||||||
|
|
||||||
if (locales_for_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);
|
add_row_other (chooser, INPUT_SOURCE_TYPE_IBUS, engine_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (country_code);
|
|
||||||
g_free (lang_code);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* HAVE_IBUS */
|
#endif /* HAVE_IBUS */
|
||||||
|
@ -896,7 +882,7 @@ add_locale_to_table (GHashTable *table,
|
||||||
LocaleInfo *info)
|
LocaleInfo *info)
|
||||||
{
|
{
|
||||||
GHashTable *set;
|
GHashTable *set;
|
||||||
gchar *language;
|
g_autofree gchar *language = NULL;
|
||||||
|
|
||||||
language = gnome_get_language_from_code (lang_code, 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_replace (table, g_strdup (language), set);
|
||||||
}
|
}
|
||||||
g_hash_table_add (set, info);
|
g_hash_table_add (set, info);
|
||||||
|
|
||||||
g_free (language);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -926,11 +910,12 @@ static void
|
||||||
get_locale_infos (GtkWidget *chooser)
|
get_locale_infos (GtkWidget *chooser)
|
||||||
{
|
{
|
||||||
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
|
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
|
||||||
GHashTable *layouts_with_locale;
|
g_autoptr(GHashTable) layouts_with_locale = NULL;
|
||||||
LocaleInfo *info;
|
LocaleInfo *info;
|
||||||
gchar **locale_ids;
|
g_auto(GStrv) locale_ids = NULL;
|
||||||
gchar **locale;
|
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,
|
priv->locales = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
NULL, locale_info_free);
|
NULL, locale_info_free);
|
||||||
|
@ -942,11 +927,13 @@ get_locale_infos (GtkWidget *chooser)
|
||||||
locale_ids = gnome_get_all_locales ();
|
locale_ids = gnome_get_all_locales ();
|
||||||
for (locale = locale_ids; *locale; ++locale)
|
for (locale = locale_ids; *locale; ++locale)
|
||||||
{
|
{
|
||||||
gchar *lang_code, *country_code;
|
g_autofree gchar *lang_code = NULL;
|
||||||
gchar *simple_locale;
|
g_autofree gchar *country_code = NULL;
|
||||||
gchar *tmp;
|
g_autofree gchar *simple_locale = NULL;
|
||||||
|
g_autofree gchar *tmp = NULL;
|
||||||
const gchar *type = NULL;
|
const gchar *type = NULL;
|
||||||
const gchar *id = NULL;
|
const gchar *id = NULL;
|
||||||
|
g_autoptr(GList) language_layouts = NULL;
|
||||||
|
|
||||||
if (!gnome_parse_locale (*locale, &lang_code, &country_code, NULL, NULL))
|
if (!gnome_parse_locale (*locale, &lang_code, &country_code, NULL, NULL))
|
||||||
continue;
|
continue;
|
||||||
|
@ -957,20 +944,14 @@ get_locale_infos (GtkWidget *chooser)
|
||||||
simple_locale = g_strdup_printf ("%s.UTF-8", lang_code);
|
simple_locale = g_strdup_printf ("%s.UTF-8", lang_code);
|
||||||
|
|
||||||
if (g_hash_table_contains (priv->locales, simple_locale))
|
if (g_hash_table_contains (priv->locales, simple_locale))
|
||||||
{
|
|
||||||
g_free (simple_locale);
|
|
||||||
g_free (country_code);
|
|
||||||
g_free (lang_code);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
info = g_new0 (LocaleInfo, 1);
|
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->name = gnome_get_language_from_locale (simple_locale, NULL);
|
||||||
info->unaccented_name = cc_util_normalize_casefold_and_unaccent (info->name);
|
info->unaccented_name = cc_util_normalize_casefold_and_unaccent (info->name);
|
||||||
tmp = gnome_get_language_from_locale (simple_locale, "C");
|
tmp = gnome_get_language_from_locale (simple_locale, "C");
|
||||||
info->untranslated_name = cc_util_normalize_casefold_and_unaccent (tmp);
|
info->untranslated_name = cc_util_normalize_casefold_and_unaccent (tmp);
|
||||||
g_free (tmp);
|
|
||||||
|
|
||||||
g_hash_table_replace (priv->locales, simple_locale, info);
|
g_hash_table_replace (priv->locales, simple_locale, info);
|
||||||
add_locale_to_table (priv->locales_by_language, lang_code, 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,
|
info->engine_rows_by_id = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
NULL, g_object_unref);
|
NULL, g_object_unref);
|
||||||
|
|
||||||
list = gnome_xkb_info_get_layouts_for_language (priv->xkb_info, lang_code);
|
language_layouts = 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_rows_to_table (chooser, info, language_layouts, INPUT_SOURCE_TYPE_XKB, id);
|
||||||
add_ids_to_set (layouts_with_locale, list);
|
add_ids_to_set (layouts_with_locale, language_layouts);
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
if (country_code != NULL)
|
if (country_code != NULL)
|
||||||
{
|
{
|
||||||
list = gnome_xkb_info_get_layouts_for_country (priv->xkb_info, country_code);
|
g_autoptr(GList) country_layouts = 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_rows_to_table (chooser, info, country_layouts, INPUT_SOURCE_TYPE_XKB, id);
|
||||||
add_ids_to_set (layouts_with_locale, list);
|
add_ids_to_set (layouts_with_locale, country_layouts);
|
||||||
g_list_free (list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (lang_code);
|
|
||||||
g_free (country_code);
|
|
||||||
}
|
}
|
||||||
g_strfreev (locale_ids);
|
|
||||||
|
|
||||||
/* Add a "Other" locale to hold the remaining input sources */
|
/* Add a "Other" locale to hold the remaining input sources */
|
||||||
info = g_new0 (LocaleInfo, 1);
|
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,
|
info->engine_rows_by_id = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
NULL, g_object_unref);
|
NULL, g_object_unref);
|
||||||
|
|
||||||
list = gnome_xkb_info_get_all_layouts (priv->xkb_info);
|
all_layouts = gnome_xkb_info_get_all_layouts (priv->xkb_info);
|
||||||
for (l = list; l; l = l->next)
|
for (l = all_layouts; l; l = l->next)
|
||||||
if (!g_hash_table_contains (layouts_with_locale, l->data))
|
if (!g_hash_table_contains (layouts_with_locale, l->data))
|
||||||
add_row_other (chooser, INPUT_SOURCE_TYPE_XKB, 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
|
static void
|
||||||
|
@ -1061,18 +1032,16 @@ cc_input_chooser_new (GtkWindow *main_window,
|
||||||
GnomeXkbInfo *xkb_info,
|
GnomeXkbInfo *xkb_info,
|
||||||
GHashTable *ibus_engines)
|
GHashTable *ibus_engines)
|
||||||
{
|
{
|
||||||
GtkBuilder *builder;
|
g_autoptr(GtkBuilder) builder = NULL;
|
||||||
GtkWidget *chooser;
|
GtkWidget *chooser;
|
||||||
CcInputChooserPrivate *priv;
|
CcInputChooserPrivate *priv;
|
||||||
gint width, height;
|
gint width, height;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
builder = gtk_builder_new ();
|
builder = gtk_builder_new ();
|
||||||
if (gtk_builder_add_from_resource (builder, "/org/gnome/control-center/region/input-chooser.ui", &error) == 0)
|
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_warning ("failed to load input chooser: %s", error->message);
|
||||||
g_error_free (error);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
chooser = WID ("input-dialog");
|
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);
|
gtk_window_set_transient_for (GTK_WINDOW (chooser), main_window);
|
||||||
|
|
||||||
g_object_unref (builder);
|
|
||||||
|
|
||||||
return chooser;
|
return chooser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,9 @@ static void
|
||||||
update_shortcut_label (GtkWidget *widget,
|
update_shortcut_label (GtkWidget *widget,
|
||||||
const gchar *value)
|
const gchar *value)
|
||||||
{
|
{
|
||||||
gchar *text;
|
g_autofree gchar *text = NULL;
|
||||||
guint accel_key, *keycode;
|
guint accel_key;
|
||||||
|
g_autofree guint *keycode = NULL;
|
||||||
GdkModifierType mods;
|
GdkModifierType mods;
|
||||||
|
|
||||||
if (value == NULL || *value == '\0') {
|
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);
|
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);
|
gtk_label_set_text (GTK_LABEL (widget), text);
|
||||||
g_free (text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_shortcuts (CcInputOptions *self)
|
update_shortcuts (CcInputOptions *self)
|
||||||
{
|
{
|
||||||
gchar **previous;
|
g_auto(GStrv) previous = NULL;
|
||||||
gchar **next;
|
g_auto(GStrv) next = NULL;
|
||||||
gchar *previous_shortcut;
|
g_autofree gchar *previous_shortcut = NULL;
|
||||||
GSettings *settings;
|
g_autoptr(GSettings) settings = NULL;
|
||||||
|
|
||||||
settings = g_settings_new ("org.gnome.desktop.wm.keybindings");
|
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->previous_source, previous_shortcut);
|
||||||
update_shortcut_label (self->next_source, next[0]);
|
update_shortcut_label (self->next_source, next[0]);
|
||||||
|
|
||||||
g_free (previous_shortcut);
|
|
||||||
|
|
||||||
g_strfreev (previous);
|
|
||||||
g_strfreev (next);
|
|
||||||
|
|
||||||
g_object_unref (settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_modifiers_shortcut (CcInputOptions *self)
|
update_modifiers_shortcut (CcInputOptions *self)
|
||||||
{
|
{
|
||||||
gchar **options, **p;
|
g_auto(GStrv) options = NULL;
|
||||||
GSettings *settings;
|
gchar **p;
|
||||||
GnomeXkbInfo *xkb_info;
|
g_autoptr(GSettings) settings = NULL;
|
||||||
|
g_autoptr(GnomeXkbInfo) xkb_info = NULL;
|
||||||
const gchar *text;
|
const gchar *text;
|
||||||
|
|
||||||
xkb_info = gnome_xkb_info_new ();
|
xkb_info = gnome_xkb_info_new ();
|
||||||
|
@ -115,10 +108,6 @@ update_modifiers_shortcut (CcInputOptions *self)
|
||||||
} else {
|
} else {
|
||||||
gtk_widget_hide (self->alt_next_source);
|
gtk_widget_hide (self->alt_next_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (options);
|
|
||||||
g_object_unref (settings);
|
|
||||||
g_object_unref (xkb_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -226,7 +226,7 @@ set_restart_notification_visible (CcRegionPanel *self,
|
||||||
gboolean visible)
|
gboolean visible)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
gchar *current_locale = NULL;
|
g_autofree gchar *current_locale = NULL;
|
||||||
|
|
||||||
if (locale) {
|
if (locale) {
|
||||||
current_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
|
current_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
|
||||||
|
@ -235,10 +235,8 @@ set_restart_notification_visible (CcRegionPanel *self,
|
||||||
|
|
||||||
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->restart_notification), visible);
|
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->restart_notification), visible);
|
||||||
|
|
||||||
if (locale) {
|
if (locale)
|
||||||
setlocale (LC_MESSAGES, current_locale);
|
setlocale (LC_MESSAGES, current_locale);
|
||||||
g_free (current_locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
g_file_delete (g_file_new_for_path (priv->needs_restart_file_path),
|
g_file_delete (g_file_new_for_path (priv->needs_restart_file_path),
|
||||||
|
@ -257,26 +255,35 @@ typedef struct {
|
||||||
gchar *target_locale;
|
gchar *target_locale;
|
||||||
} MaybeNotifyData;
|
} MaybeNotifyData;
|
||||||
|
|
||||||
|
static void
|
||||||
|
maybe_notify_data_free (MaybeNotifyData *data)
|
||||||
|
{
|
||||||
|
g_free (data->target_locale);
|
||||||
|
g_free (data);
|
||||||
|
}
|
||||||
|
|
||||||
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MaybeNotifyData, maybe_notify_data_free)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
maybe_notify_finish (GObject *source,
|
maybe_notify_finish (GObject *source,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
MaybeNotifyData *mnd = data;
|
g_autoptr(MaybeNotifyData) mnd = data;
|
||||||
CcRegionPanel *self = mnd->self;
|
CcRegionPanel *self = mnd->self;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
GVariant *retval = NULL;
|
g_autoptr(GVariant) retval = NULL;
|
||||||
gchar *current_lang_code = NULL;
|
g_autofree gchar *current_lang_code = NULL;
|
||||||
gchar *current_country_code = NULL;
|
g_autofree gchar *current_country_code = NULL;
|
||||||
gchar *target_lang_code = NULL;
|
g_autofree gchar *target_lang_code = NULL;
|
||||||
gchar *target_country_code = NULL;
|
g_autofree gchar *target_country_code = NULL;
|
||||||
const gchar *current_locale = NULL;
|
const gchar *current_locale = NULL;
|
||||||
|
|
||||||
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, &error);
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, &error);
|
||||||
if (!retval) {
|
if (!retval) {
|
||||||
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 get locale: %s\n", error->message);
|
g_warning ("Failed to get locale: %s\n", error->message);
|
||||||
goto out;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_variant_get (retval, "(&s)", ¤t_locale);
|
g_variant_get (retval, "(&s)", ¤t_locale);
|
||||||
|
@ -286,14 +293,14 @@ maybe_notify_finish (GObject *source,
|
||||||
¤t_country_code,
|
¤t_country_code,
|
||||||
NULL,
|
NULL,
|
||||||
NULL))
|
NULL))
|
||||||
goto out;
|
return;
|
||||||
|
|
||||||
if (!gnome_parse_locale (mnd->target_locale,
|
if (!gnome_parse_locale (mnd->target_locale,
|
||||||
&target_lang_code,
|
&target_lang_code,
|
||||||
&target_country_code,
|
&target_country_code,
|
||||||
NULL,
|
NULL,
|
||||||
NULL))
|
NULL))
|
||||||
goto out;
|
return;
|
||||||
|
|
||||||
if (g_str_equal (current_lang_code, target_lang_code) == FALSE ||
|
if (g_str_equal (current_lang_code, target_lang_code) == FALSE ||
|
||||||
g_str_equal (current_country_code, target_country_code) == FALSE)
|
g_str_equal (current_country_code, target_country_code) == FALSE)
|
||||||
|
@ -304,15 +311,6 @@ maybe_notify_finish (GObject *source,
|
||||||
set_restart_notification_visible (self,
|
set_restart_notification_visible (self,
|
||||||
mnd->category == LC_MESSAGES ? mnd->target_locale : NULL,
|
mnd->category == LC_MESSAGES ? mnd->target_locale : NULL,
|
||||||
FALSE);
|
FALSE);
|
||||||
out:
|
|
||||||
g_free (target_country_code);
|
|
||||||
g_free (target_lang_code);
|
|
||||||
g_free (current_country_code);
|
|
||||||
g_free (current_lang_code);
|
|
||||||
g_clear_pointer (&retval, g_variant_unref);
|
|
||||||
g_clear_error (&error);
|
|
||||||
g_free (mnd->target_locale);
|
|
||||||
g_free (mnd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -506,14 +504,13 @@ permission_acquired (GObject *source,
|
||||||
{
|
{
|
||||||
CcRegionPanel *self = data;
|
CcRegionPanel *self = data;
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
gboolean allowed;
|
gboolean allowed;
|
||||||
|
|
||||||
allowed = g_permission_acquire_finish (priv->permission, res, &error);
|
allowed = g_permission_acquire_finish (priv->permission, res, &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
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 acquire permission: %s\n", error->message);
|
g_warning ("Failed to acquire permission: %s\n", error->message);
|
||||||
g_error_free (error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -576,7 +573,7 @@ update_region_label (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
const gchar *region = get_effective_region (self);
|
const gchar *region = get_effective_region (self);
|
||||||
gchar *name = NULL;
|
g_autofree gchar *name = NULL;
|
||||||
|
|
||||||
if (region)
|
if (region)
|
||||||
name = gnome_get_country_from_locale (region, region);
|
name = gnome_get_country_from_locale (region, region);
|
||||||
|
@ -585,7 +582,6 @@ update_region_label (CcRegionPanel *self)
|
||||||
name = gnome_get_country_from_locale (DEFAULT_LOCALE, DEFAULT_LOCALE);
|
name = gnome_get_country_from_locale (DEFAULT_LOCALE, DEFAULT_LOCALE);
|
||||||
|
|
||||||
gtk_label_set_label (GTK_LABEL (priv->formats_label), name);
|
gtk_label_set_label (GTK_LABEL (priv->formats_label), name);
|
||||||
g_free (name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -603,7 +599,7 @@ update_language_label (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
const gchar *language = get_effective_language (self);
|
const gchar *language = get_effective_language (self);
|
||||||
gchar *name = NULL;
|
g_autofree gchar *name = NULL;
|
||||||
|
|
||||||
if (language)
|
if (language)
|
||||||
name = gnome_get_language_from_locale (language, language);
|
name = gnome_get_language_from_locale (language, language);
|
||||||
|
@ -612,7 +608,6 @@ update_language_label (CcRegionPanel *self)
|
||||||
name = gnome_get_language_from_locale (DEFAULT_LOCALE, DEFAULT_LOCALE);
|
name = gnome_get_language_from_locale (DEFAULT_LOCALE, DEFAULT_LOCALE);
|
||||||
|
|
||||||
gtk_label_set_label (GTK_LABEL (priv->language_label), name);
|
gtk_label_set_label (GTK_LABEL (priv->language_label), name);
|
||||||
g_free (name);
|
|
||||||
|
|
||||||
/* Formats will change too if not explicitly set. */
|
/* Formats will change too if not explicitly set. */
|
||||||
update_region_label (self);
|
update_region_label (self);
|
||||||
|
@ -679,12 +674,12 @@ static void
|
||||||
update_ibus_active_sources (CcRegionPanel *self)
|
update_ibus_active_sources (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GList *rows, *l;
|
g_autoptr(GList) rows = NULL;
|
||||||
|
GList *l;
|
||||||
GtkWidget *row;
|
GtkWidget *row;
|
||||||
const gchar *type;
|
const gchar *type;
|
||||||
const gchar *id;
|
const gchar *id;
|
||||||
IBusEngineDesc *engine_desc;
|
IBusEngineDesc *engine_desc;
|
||||||
gchar *display_name;
|
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
|
|
||||||
rows = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
rows = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
||||||
|
@ -697,13 +692,11 @@ update_ibus_active_sources (CcRegionPanel *self)
|
||||||
|
|
||||||
engine_desc = g_hash_table_lookup (priv->ibus_engines, id);
|
engine_desc = g_hash_table_lookup (priv->ibus_engines, id);
|
||||||
if (engine_desc) {
|
if (engine_desc) {
|
||||||
display_name = engine_get_display_name (engine_desc);
|
g_autofree gchar *display_name = engine_get_display_name (engine_desc);
|
||||||
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "label"));
|
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "label"));
|
||||||
gtk_label_set_text (GTK_LABEL (label), display_name);
|
gtk_label_set_text (GTK_LABEL (label), display_name);
|
||||||
g_free (display_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_list_free (rows);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -725,15 +718,14 @@ fetch_ibus_engines_result (GObject *object,
|
||||||
CcRegionPanel *self)
|
CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv;
|
CcRegionPanelPrivate *priv;
|
||||||
GList *list, *l;
|
g_autoptr(GList) list = NULL;
|
||||||
GError *error;
|
GList *l;
|
||||||
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
error = NULL;
|
|
||||||
list = ibus_bus_list_engines_async_finish (IBUS_BUS (object), result, &error);
|
list = ibus_bus_list_engines_async_finish (IBUS_BUS (object), result, &error);
|
||||||
if (!list && error) {
|
if (!list && error) {
|
||||||
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 ("Couldn't finish IBus request: %s", error->message);
|
g_warning ("Couldn't finish IBus request: %s", error->message);
|
||||||
g_error_free (error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -752,7 +744,6 @@ fetch_ibus_engines_result (GObject *object,
|
||||||
else
|
else
|
||||||
g_hash_table_replace (priv->ibus_engines, (gpointer)engine_id, engine);
|
g_hash_table_replace (priv->ibus_engines, (gpointer)engine_id, engine);
|
||||||
}
|
}
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
update_ibus_active_sources (self);
|
update_ibus_active_sources (self);
|
||||||
update_input_chooser (self);
|
update_input_chooser (self);
|
||||||
|
@ -794,35 +785,28 @@ maybe_start_ibus (void)
|
||||||
static GDesktopAppInfo *
|
static GDesktopAppInfo *
|
||||||
setup_app_info_for_id (const gchar *id)
|
setup_app_info_for_id (const gchar *id)
|
||||||
{
|
{
|
||||||
GDesktopAppInfo *app_info;
|
g_autofree gchar *desktop_file_name = NULL;
|
||||||
gchar *desktop_file_name;
|
g_auto(GStrv) strv = NULL;
|
||||||
gchar **strv;
|
|
||||||
|
|
||||||
strv = g_strsplit (id, ":", 2);
|
strv = g_strsplit (id, ":", 2);
|
||||||
desktop_file_name = g_strdup_printf ("ibus-setup-%s.desktop", strv[0]);
|
desktop_file_name = g_strdup_printf ("ibus-setup-%s.desktop", strv[0]);
|
||||||
g_strfreev (strv);
|
|
||||||
|
|
||||||
app_info = g_desktop_app_info_new (desktop_file_name);
|
return g_desktop_app_info_new (desktop_file_name);
|
||||||
g_free (desktop_file_name);
|
|
||||||
|
|
||||||
return app_info;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
remove_no_input_row (GtkContainer *list)
|
remove_no_input_row (GtkContainer *list)
|
||||||
{
|
{
|
||||||
GList *l;
|
g_autoptr(GList) l = NULL;
|
||||||
|
|
||||||
l = gtk_container_get_children (list);
|
l = gtk_container_get_children (list);
|
||||||
if (!l)
|
if (!l)
|
||||||
return;
|
return;
|
||||||
if (l->next != NULL)
|
if (l->next != NULL)
|
||||||
goto out;
|
return;
|
||||||
if (g_strcmp0 (g_object_get_data (G_OBJECT (l->data), "type"), "none") == 0)
|
if (g_strcmp0 (g_object_get_data (G_OBJECT (l->data), "type"), "none") == 0)
|
||||||
gtk_container_remove (list, GTK_WIDGET (l->data));
|
gtk_container_remove (list, GTK_WIDGET (l->data));
|
||||||
out:
|
|
||||||
g_list_free (l);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
|
@ -891,8 +875,8 @@ add_input_sources (CcRegionPanel *self,
|
||||||
const gchar *type;
|
const gchar *type;
|
||||||
const gchar *id;
|
const gchar *id;
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
gchar *display_name;
|
g_autofree gchar *display_name = NULL;
|
||||||
GDesktopAppInfo *app_info;
|
g_autoptr(GDesktopAppInfo) app_info = NULL;
|
||||||
|
|
||||||
if (g_variant_n_children (sources) < 1) {
|
if (g_variant_n_children (sources) < 1) {
|
||||||
add_no_input_row (self);
|
add_no_input_row (self);
|
||||||
|
@ -930,8 +914,6 @@ add_input_sources (CcRegionPanel *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
add_input_row (self, type, id, display_name ? display_name : id, app_info);
|
add_input_row (self, type, id, display_name ? display_name : id, app_info);
|
||||||
g_free (display_name);
|
|
||||||
g_clear_object (&app_info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -939,22 +921,22 @@ static void
|
||||||
add_input_sources_from_settings (CcRegionPanel *self)
|
add_input_sources_from_settings (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GVariant *sources;
|
g_autoptr(GVariant) sources = NULL;
|
||||||
sources = g_settings_get_value (priv->input_settings, "sources");
|
sources = g_settings_get_value (priv->input_settings, "sources");
|
||||||
add_input_sources (self, sources);
|
add_input_sources (self, sources);
|
||||||
g_variant_unref (sources);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clear_input_sources (CcRegionPanel *self)
|
clear_input_sources (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GList *list, *l;
|
g_autoptr(GList) list = NULL;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
list = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
list = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
||||||
for (l = list; l; l = l->next) {
|
for (l = list; l; l = l->next) {
|
||||||
gtk_container_remove (GTK_CONTAINER (priv->input_list), GTK_WIDGET (l->data));
|
gtk_container_remove (GTK_CONTAINER (priv->input_list), GTK_WIDGET (l->data));
|
||||||
}
|
}
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (priv->input_list));
|
cc_list_box_adjust_scrolling (GTK_LIST_BOX (priv->input_list));
|
||||||
}
|
}
|
||||||
|
@ -986,17 +968,15 @@ input_sources_changed (GSettings *settings,
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GtkListBoxRow *selected;
|
GtkListBoxRow *selected;
|
||||||
gchar *id = NULL;
|
g_autofree gchar *id = NULL;
|
||||||
|
|
||||||
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
|
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
|
||||||
if (selected)
|
if (selected)
|
||||||
id = g_strdup (g_object_get_data (G_OBJECT (selected), "id"));
|
id = g_strdup (g_object_get_data (G_OBJECT (selected), "id"));
|
||||||
clear_input_sources (self);
|
clear_input_sources (self);
|
||||||
add_input_sources_from_settings (self);
|
add_input_sources_from_settings (self);
|
||||||
if (id) {
|
if (id)
|
||||||
select_input (self, id);
|
select_input (self, id);
|
||||||
g_free (id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1005,12 +985,11 @@ update_buttons (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GtkListBoxRow *selected;
|
GtkListBoxRow *selected;
|
||||||
GList *children;
|
g_autoptr(GList) children = NULL;
|
||||||
guint n_rows;
|
guint n_rows;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
children = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
||||||
n_rows = g_list_length (children);
|
n_rows = g_list_length (children);
|
||||||
g_list_free (children);
|
|
||||||
|
|
||||||
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
|
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
|
||||||
if (selected == NULL) {
|
if (selected == NULL) {
|
||||||
|
@ -1042,7 +1021,8 @@ set_input_settings (CcRegionPanel *self)
|
||||||
const gchar *type;
|
const gchar *type;
|
||||||
const gchar *id;
|
const gchar *id;
|
||||||
GVariantBuilder builder;
|
GVariantBuilder builder;
|
||||||
GList *list, *l;
|
g_autoptr(GList) list = NULL;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss)"));
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss)"));
|
||||||
list = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
list = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
||||||
|
@ -1051,7 +1031,6 @@ set_input_settings (CcRegionPanel *self)
|
||||||
id = (const gchar *)g_object_get_data (G_OBJECT (l->data), "id");
|
id = (const gchar *)g_object_get_data (G_OBJECT (l->data), "id");
|
||||||
g_variant_builder_add (&builder, "(ss)", type, id);
|
g_variant_builder_add (&builder, "(ss)", type, id);
|
||||||
}
|
}
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
g_settings_set_value (priv->input_settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder));
|
g_settings_set_value (priv->input_settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder));
|
||||||
g_settings_apply (priv->input_settings);
|
g_settings_apply (priv->input_settings);
|
||||||
|
@ -1078,49 +1057,42 @@ input_source_already_added (CcRegionPanel *self,
|
||||||
const gchar *id)
|
const gchar *id)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GList *list, *l;
|
g_autoptr(GList) list = NULL;
|
||||||
gboolean retval = FALSE;
|
GList *l;
|
||||||
|
|
||||||
list = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
list = gtk_container_get_children (GTK_CONTAINER (priv->input_list));
|
||||||
for (l = list; l; l = l->next)
|
for (l = list; l; l = l->next)
|
||||||
if (g_str_equal (id, (const gchar *) g_object_get_data (G_OBJECT (l->data), "id"))) {
|
if (g_str_equal (id, (const gchar *) g_object_get_data (G_OBJECT (l->data), "id"))) {
|
||||||
retval = TRUE;
|
return TRUE;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
return retval;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
run_input_chooser (CcRegionPanel *self, GtkWidget *chooser)
|
run_input_chooser (CcRegionPanel *self, GtkWidget *chooser)
|
||||||
{
|
{
|
||||||
gchar *type;
|
|
||||||
gchar *id;
|
|
||||||
gchar *name;
|
|
||||||
GDesktopAppInfo *app_info = NULL;
|
|
||||||
|
|
||||||
if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) {
|
if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) {
|
||||||
|
g_autofree gchar *type = NULL;
|
||||||
|
g_autofree gchar *id = NULL;
|
||||||
|
g_autofree gchar *name = NULL;
|
||||||
|
|
||||||
if (cc_input_chooser_get_selected (chooser, &type, &id, &name) &&
|
if (cc_input_chooser_get_selected (chooser, &type, &id, &name) &&
|
||||||
!input_source_already_added (self, id)) {
|
!input_source_already_added (self, id)) {
|
||||||
|
g_autoptr(GDesktopAppInfo) app_info = NULL;
|
||||||
|
|
||||||
if (g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) {
|
if (g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) {
|
||||||
g_free (type);
|
|
||||||
type = INPUT_SOURCE_TYPE_IBUS;
|
|
||||||
#ifdef HAVE_IBUS
|
#ifdef HAVE_IBUS
|
||||||
app_info = setup_app_info_for_id (id);
|
app_info = setup_app_info_for_id (id);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
g_free (type);
|
g_free (type);
|
||||||
type = INPUT_SOURCE_TYPE_XKB;
|
type = g_strdup (INPUT_SOURCE_TYPE_XKB);
|
||||||
}
|
}
|
||||||
|
|
||||||
add_input_row (self, type, id, name, app_info);
|
add_input_row (self, type, id, name, app_info);
|
||||||
update_buttons (self);
|
update_buttons (self);
|
||||||
update_input (self);
|
update_input (self);
|
||||||
|
|
||||||
g_free (id);
|
|
||||||
g_free (name);
|
|
||||||
g_clear_object (&app_info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gtk_widget_hide(chooser);
|
gtk_widget_hide(chooser);
|
||||||
|
@ -1177,8 +1149,8 @@ add_input (CcRegionPanel *self)
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
find_sibling (GtkContainer *container, GtkWidget *child)
|
find_sibling (GtkContainer *container, GtkWidget *child)
|
||||||
{
|
{
|
||||||
GList *list, *c;
|
g_autoptr(GList) list = NULL;
|
||||||
GList *l;
|
GList *c, *l;
|
||||||
GtkWidget *sibling;
|
GtkWidget *sibling;
|
||||||
|
|
||||||
list = gtk_container_get_children (container);
|
list = gtk_container_get_children (container);
|
||||||
|
@ -1187,21 +1159,16 @@ find_sibling (GtkContainer *container, GtkWidget *child)
|
||||||
for (l = c->next; l; l = l->next) {
|
for (l = c->next; l; l = l->next) {
|
||||||
sibling = l->data;
|
sibling = l->data;
|
||||||
if (gtk_widget_get_visible (sibling) && gtk_widget_get_child_visible (sibling))
|
if (gtk_widget_get_visible (sibling) && gtk_widget_get_child_visible (sibling))
|
||||||
goto out;
|
return sibling;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (l = c->prev; l; l = l->prev) {
|
for (l = c->prev; l; l = l->prev) {
|
||||||
sibling = l->data;
|
sibling = l->data;
|
||||||
if (gtk_widget_get_visible (sibling) && gtk_widget_get_child_visible (sibling))
|
if (gtk_widget_get_visible (sibling) && gtk_widget_get_child_visible (sibling))
|
||||||
goto out;
|
return sibling;
|
||||||
}
|
}
|
||||||
|
|
||||||
sibling = NULL;
|
return NULL;
|
||||||
|
|
||||||
out:
|
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
return sibling;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1313,10 +1280,10 @@ show_selected_settings (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GtkListBoxRow *selected;
|
GtkListBoxRow *selected;
|
||||||
GdkAppLaunchContext *ctx;
|
g_autoptr(GdkAppLaunchContext) ctx = NULL;
|
||||||
GDesktopAppInfo *app_info;
|
GDesktopAppInfo *app_info;
|
||||||
const gchar *id;
|
const gchar *id;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
|
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
|
||||||
if (selected == NULL)
|
if (selected == NULL)
|
||||||
|
@ -1333,12 +1300,8 @@ show_selected_settings (CcRegionPanel *self)
|
||||||
g_app_launch_context_setenv (G_APP_LAUNCH_CONTEXT (ctx),
|
g_app_launch_context_setenv (G_APP_LAUNCH_CONTEXT (ctx),
|
||||||
"IBUS_ENGINE_NAME", id);
|
"IBUS_ENGINE_NAME", id);
|
||||||
|
|
||||||
if (!g_app_info_launch (G_APP_INFO (app_info), NULL, G_APP_LAUNCH_CONTEXT (ctx), &error)) {
|
if (!g_app_info_launch (G_APP_INFO (app_info), NULL, G_APP_LAUNCH_CONTEXT (ctx), &error))
|
||||||
g_warning ("Failed to launch input source setup: %s", error->message);
|
g_warning ("Failed to launch input source setup: %s", error->message);
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_unref (ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1350,7 +1313,7 @@ show_selected_layout (CcRegionPanel *self)
|
||||||
const gchar *id;
|
const gchar *id;
|
||||||
const gchar *layout;
|
const gchar *layout;
|
||||||
const gchar *variant;
|
const gchar *variant;
|
||||||
gchar *commandline;
|
g_autofree gchar *commandline = NULL;
|
||||||
|
|
||||||
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
|
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
|
||||||
if (selected == NULL)
|
if (selected == NULL)
|
||||||
|
@ -1396,7 +1359,6 @@ show_selected_layout (CcRegionPanel *self)
|
||||||
layout);
|
layout);
|
||||||
|
|
||||||
g_spawn_command_line_async (commandline, NULL);
|
g_spawn_command_line_async (commandline, NULL);
|
||||||
g_free (commandline);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1493,11 +1455,11 @@ on_localed_properties_changed (GDBusProxy *proxy,
|
||||||
CcRegionPanel *self)
|
CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GVariant *v;
|
g_autoptr(GVariant) v = NULL;
|
||||||
|
|
||||||
v = g_dbus_proxy_get_cached_property (proxy, "Locale");
|
v = g_dbus_proxy_get_cached_property (proxy, "Locale");
|
||||||
if (v) {
|
if (v) {
|
||||||
const gchar **strv;
|
g_autofree const gchar **strv = NULL;
|
||||||
gsize len;
|
gsize len;
|
||||||
gint i;
|
gint i;
|
||||||
const gchar *lang, *messages, *time;
|
const gchar *lang, *messages, *time;
|
||||||
|
@ -1524,8 +1486,6 @@ on_localed_properties_changed (GDBusProxy *proxy,
|
||||||
priv->system_language = g_strdup (messages);
|
priv->system_language = g_strdup (messages);
|
||||||
g_free (priv->system_region);
|
g_free (priv->system_region);
|
||||||
priv->system_region = g_strdup (time);
|
priv->system_region = g_strdup (time);
|
||||||
g_variant_unref (v);
|
|
||||||
g_free (strv);
|
|
||||||
|
|
||||||
update_language_label (self);
|
update_language_label (self);
|
||||||
}
|
}
|
||||||
|
@ -1535,28 +1495,27 @@ static void
|
||||||
add_input_sources_from_localed (CcRegionPanel *self)
|
add_input_sources_from_localed (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GVariant *v;
|
g_autoptr(GVariant) layout_property = NULL;
|
||||||
|
g_autoptr(GVariant) variant_property = NULL;
|
||||||
const gchar *s;
|
const gchar *s;
|
||||||
gchar **layouts = NULL;
|
g_auto(GStrv) layouts = NULL;
|
||||||
gchar **variants = NULL;
|
g_auto(GStrv) variants = NULL;
|
||||||
gint i, n;
|
gint i, n;
|
||||||
|
|
||||||
if (!priv->localed)
|
if (!priv->localed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
v = g_dbus_proxy_get_cached_property (priv->localed, "X11Layout");
|
layout_property = g_dbus_proxy_get_cached_property (priv->localed, "X11Layout");
|
||||||
if (v) {
|
if (layout_property) {
|
||||||
s = g_variant_get_string (v, NULL);
|
s = g_variant_get_string (layout_property, NULL);
|
||||||
layouts = g_strsplit (s, ",", -1);
|
layouts = g_strsplit (s, ",", -1);
|
||||||
g_variant_unref (v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v = g_dbus_proxy_get_cached_property (priv->localed, "X11Variant");
|
variant_property = g_dbus_proxy_get_cached_property (priv->localed, "X11Variant");
|
||||||
if (v) {
|
if (variant_property) {
|
||||||
s = g_variant_get_string (v, NULL);
|
s = g_variant_get_string (variant_property, NULL);
|
||||||
if (s && *s)
|
if (s && *s)
|
||||||
variants = g_strsplit (s, ",", -1);
|
variants = g_strsplit (s, ",", -1);
|
||||||
g_variant_unref (v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (variants && variants[0])
|
if (variants && variants[0])
|
||||||
|
@ -1568,7 +1527,7 @@ add_input_sources_from_localed (CcRegionPanel *self)
|
||||||
|
|
||||||
for (i = 0; i < n && layouts[i][0]; i++) {
|
for (i = 0; i < n && layouts[i][0]; i++) {
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
gchar *id;
|
g_autofree gchar *id = NULL;
|
||||||
|
|
||||||
if (variants && variants[i] && variants[i][0])
|
if (variants && variants[i] && variants[i][0])
|
||||||
id = g_strdup_printf ("%s+%s", layouts[i], variants[i]);
|
id = g_strdup_printf ("%s+%s", layouts[i], variants[i]);
|
||||||
|
@ -1578,63 +1537,57 @@ add_input_sources_from_localed (CcRegionPanel *self)
|
||||||
gnome_xkb_info_get_layout_info (priv->xkb_info, id, &name, NULL, NULL, NULL);
|
gnome_xkb_info_get_layout_info (priv->xkb_info, id, &name, NULL, NULL, NULL);
|
||||||
|
|
||||||
add_input_row (self, INPUT_SOURCE_TYPE_XKB, id, name ? name : id, NULL);
|
add_input_row (self, INPUT_SOURCE_TYPE_XKB, id, name ? name : id, NULL);
|
||||||
|
|
||||||
g_free (id);
|
|
||||||
}
|
}
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
add_no_input_row (self);
|
add_no_input_row (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (variants);
|
|
||||||
g_strfreev (layouts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_localed_locale (CcRegionPanel *self)
|
set_localed_locale (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GVariantBuilder *b;
|
g_autoptr(GVariantBuilder) b = NULL;
|
||||||
gchar *s;
|
g_autofree gchar *lang_value = NULL;
|
||||||
|
|
||||||
b = g_variant_builder_new (G_VARIANT_TYPE ("as"));
|
b = g_variant_builder_new (G_VARIANT_TYPE ("as"));
|
||||||
s = g_strconcat ("LANG=", priv->system_language, NULL);
|
lang_value = g_strconcat ("LANG=", priv->system_language, NULL);
|
||||||
g_variant_builder_add (b, "s", s);
|
g_variant_builder_add (b, "s", lang_value);
|
||||||
g_free (s);
|
|
||||||
|
|
||||||
if (priv->system_region != NULL &&
|
if (priv->system_region != NULL &&
|
||||||
g_strcmp0 (priv->system_language, priv->system_region) != 0) {
|
g_strcmp0 (priv->system_language, priv->system_region) != 0) {
|
||||||
s = g_strconcat ("LC_TIME=", priv->system_region, NULL);
|
g_autofree gchar *time_value = NULL;
|
||||||
g_variant_builder_add (b, "s", s);
|
g_autofree gchar *numeric_value = NULL;
|
||||||
g_free (s);
|
g_autofree gchar *monetary_value = NULL;
|
||||||
s = g_strconcat ("LC_NUMERIC=", priv->system_region, NULL);
|
g_autofree gchar *measurement_value = NULL;
|
||||||
g_variant_builder_add (b, "s", s);
|
g_autofree gchar *paper_value = NULL;
|
||||||
g_free (s);
|
time_value = g_strconcat ("LC_TIME=", priv->system_region, NULL);
|
||||||
s = g_strconcat ("LC_MONETARY=", priv->system_region, NULL);
|
g_variant_builder_add (b, "s", time_value);
|
||||||
g_variant_builder_add (b, "s", s);
|
numeric_value = g_strconcat ("LC_NUMERIC=", priv->system_region, NULL);
|
||||||
g_free (s);
|
g_variant_builder_add (b, "s", numeric_value);
|
||||||
s = g_strconcat ("LC_MEASUREMENT=", priv->system_region, NULL);
|
monetary_value = g_strconcat ("LC_MONETARY=", priv->system_region, NULL);
|
||||||
g_variant_builder_add (b, "s", s);
|
g_variant_builder_add (b, "s", monetary_value);
|
||||||
g_free (s);
|
measurement_value = g_strconcat ("LC_MEASUREMENT=", priv->system_region, NULL);
|
||||||
s = g_strconcat ("LC_PAPER=", priv->system_region, NULL);
|
g_variant_builder_add (b, "s", measurement_value);
|
||||||
g_variant_builder_add (b, "s", s);
|
paper_value = g_strconcat ("LC_PAPER=", priv->system_region, NULL);
|
||||||
g_free (s);
|
g_variant_builder_add (b, "s", paper_value);
|
||||||
}
|
}
|
||||||
g_dbus_proxy_call (priv->localed,
|
g_dbus_proxy_call (priv->localed,
|
||||||
"SetLocale",
|
"SetLocale",
|
||||||
g_variant_new ("(asb)", b, TRUE),
|
g_variant_new ("(asb)", b, TRUE),
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
-1, NULL, NULL, NULL);
|
-1, NULL, NULL, NULL);
|
||||||
g_variant_builder_unref (b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_localed_input (CcRegionPanel *self)
|
set_localed_input (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GString *layouts;
|
g_autoptr(GString) layouts = NULL;
|
||||||
GString *variants;
|
g_autoptr(GString) variants = NULL;
|
||||||
const gchar *type, *id;
|
const gchar *type, *id;
|
||||||
GList *list, *li;
|
g_autoptr(GList) list = NULL;
|
||||||
|
GList *li;
|
||||||
const gchar *l, *v;
|
const gchar *l, *v;
|
||||||
|
|
||||||
layouts = g_string_new ("");
|
layouts = g_string_new ("");
|
||||||
|
@ -1656,16 +1609,12 @@ set_localed_input (CcRegionPanel *self)
|
||||||
g_string_append (variants, v);
|
g_string_append (variants, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_list_free (list);
|
|
||||||
|
|
||||||
g_dbus_proxy_call (priv->localed,
|
g_dbus_proxy_call (priv->localed,
|
||||||
"SetX11Keyboard",
|
"SetX11Keyboard",
|
||||||
g_variant_new ("(ssssbb)", layouts->str, "", variants->str, "", TRUE, TRUE),
|
g_variant_new ("(ssssbb)", layouts->str, "", variants->str, "", TRUE, TRUE),
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
-1, NULL, NULL, NULL);
|
-1, NULL, NULL, NULL);
|
||||||
|
|
||||||
g_string_free (layouts, TRUE);
|
|
||||||
g_string_free (variants, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1676,14 +1625,13 @@ localed_proxy_ready (GObject *source,
|
||||||
CcRegionPanel *self = data;
|
CcRegionPanel *self = data;
|
||||||
CcRegionPanelPrivate *priv;
|
CcRegionPanelPrivate *priv;
|
||||||
GDBusProxy *proxy;
|
GDBusProxy *proxy;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
proxy = g_dbus_proxy_new_finish (res, &error);
|
proxy = g_dbus_proxy_new_finish (res, &error);
|
||||||
|
|
||||||
if (!proxy) {
|
if (!proxy) {
|
||||||
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 contact localed: %s\n", error->message);
|
g_warning ("Failed to contact localed: %s\n", error->message);
|
||||||
g_error_free (error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1746,15 +1694,14 @@ static void
|
||||||
setup_login_button (CcRegionPanel *self)
|
setup_login_button (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv = self->priv;
|
CcRegionPanelPrivate *priv = self->priv;
|
||||||
GDBusConnection *bus;
|
g_autoptr(GDBusConnection) bus = NULL;
|
||||||
gboolean loaded;
|
gboolean loaded;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
priv->permission = polkit_permission_new_sync ("org.freedesktop.locale1.set-locale", NULL, NULL, &error);
|
priv->permission = polkit_permission_new_sync ("org.freedesktop.locale1.set-locale", NULL, NULL, &error);
|
||||||
if (priv->permission == NULL) {
|
if (priv->permission == NULL) {
|
||||||
g_warning ("Could not get 'org.freedesktop.locale1.set-locale' permission: %s",
|
g_warning ("Could not get 'org.freedesktop.locale1.set-locale' permission: %s",
|
||||||
error->message);
|
error->message);
|
||||||
g_error_free (error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1768,7 +1715,6 @@ setup_login_button (CcRegionPanel *self)
|
||||||
priv->cancellable,
|
priv->cancellable,
|
||||||
(GAsyncReadyCallback) localed_proxy_ready,
|
(GAsyncReadyCallback) localed_proxy_ready,
|
||||||
self);
|
self);
|
||||||
g_object_unref (bus);
|
|
||||||
|
|
||||||
priv->login_label = WID ("login-label");
|
priv->login_label = WID ("login-label");
|
||||||
priv->login_button = gtk_toggle_button_new_with_mnemonic (_("Login _Screen"));
|
priv->login_button = gtk_toggle_button_new_with_mnemonic (_("Login _Screen"));
|
||||||
|
@ -1795,14 +1741,13 @@ session_proxy_ready (GObject *source,
|
||||||
{
|
{
|
||||||
CcRegionPanel *self = data;
|
CcRegionPanel *self = data;
|
||||||
GDBusProxy *proxy;
|
GDBusProxy *proxy;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
proxy = cc_object_storage_create_dbus_proxy_finish (res, &error);
|
proxy = cc_object_storage_create_dbus_proxy_finish (res, &error);
|
||||||
|
|
||||||
if (!proxy) {
|
if (!proxy) {
|
||||||
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 contact gnome-session: %s\n", error->message);
|
g_warning ("Failed to contact gnome-session: %s\n", error->message);
|
||||||
g_error_free (error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1813,7 +1758,7 @@ static void
|
||||||
cc_region_panel_init (CcRegionPanel *self)
|
cc_region_panel_init (CcRegionPanel *self)
|
||||||
{
|
{
|
||||||
CcRegionPanelPrivate *priv;
|
CcRegionPanelPrivate *priv;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
priv = self->priv = REGION_PANEL_PRIVATE (self);
|
priv = self->priv = REGION_PANEL_PRIVATE (self);
|
||||||
g_resources_register (cc_region_get_resource ());
|
g_resources_register (cc_region_get_resource ());
|
||||||
|
@ -1825,7 +1770,6 @@ cc_region_panel_init (CcRegionPanel *self)
|
||||||
&error);
|
&error);
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
g_warning ("Error loading UI file: %s", error->message);
|
g_warning ("Error loading UI file: %s", error->message);
|
||||||
g_error_free (error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue