int main (int argc, char **argv)
{
	char **langs;
	guint i;

	g_type_init ();

	if (argc > 1) {
		guint i;
		for (i = 1; i < argc; i++) {
			char *lang, *norm;
			norm = gdm_normalize_language_name (argv[i]);
			lang = gdm_get_language_from_name (norm, NULL);
			g_print ("%s (norm: %s) == %s\n", argv[i], norm, lang);
			g_free (norm);
			g_free (lang);
		}
		return 0;
	}

	langs = gdm_get_all_language_names ();
	if (langs == NULL) {
		g_warning ("No languages found");
		return 1;
	}

	for (i = 0; langs[i] != NULL; i++)
		g_print ("%s == %s\n", langs[i], gdm_get_language_from_name (langs[i], NULL));

	g_strfreev (langs);

	return 0;
}
static void
add_available_languages (GtkListStore *store)
{
        char **languages;
        int i;
        char *name;
        char *language;
        GtkTreeIter iter;

        gtk_list_store_clear (store);

        languages = gdm_get_all_language_names ();

        for (i = 0; languages[i] != NULL; i++) {
                if (!language_has_font (languages[i]))
                        continue;

                name = gdm_normalize_language_name (languages[i]);
                language = gdm_get_language_from_name (name, NULL);

                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter, LOCALE_COL, name, DISPLAY_LOCALE_COL, language, -1);

                g_free (name);
                g_free (language);
        }

        g_strfreev (languages);
}
Example #3
0
static void
print_languages (void)
{
        char **language_names;
        int    i;

        language_names = gdm_get_all_language_names ();

        for (i = 0; language_names[i] != NULL; i++) {
                char *language;
                char *normalized_name;
                char *readable_language;

                normalized_name = gdm_normalize_language_name (language_names[i]);
                language = gdm_get_language_from_name (normalized_name, normalized_name);
                readable_language = gdm_get_language_from_name (normalized_name, NULL);

                g_print ("%s\t%s\t%s\t%s\n",
                         language_names[i],
                         normalized_name,
                         language,
                         readable_language);

                g_free (language);
                g_free (readable_language);
                g_free (normalized_name);
        }

        g_strfreev (language_names);
}
static void
gdm_language_chooser_widget_add_language (GdmLanguageChooserWidget *widget,
                                          const char               *name)
{
        char *language;
        char *normalized_name;
        char *readable_language;
        char *lang_tag;
        char *tagged;

        normalized_name = gdm_normalize_language_name (name);
        gdm_parse_language_name (name, &lang_tag, NULL, NULL, NULL);
        language = gdm_get_language_from_name (normalized_name, normalized_name);
        readable_language = gdm_get_language_from_name (normalized_name, NULL);

        tagged = g_strdup_printf ("<span lang=\"%s\">%s</span>", lang_tag, language);

        if (language != NULL) {
                gdm_chooser_widget_add_item (GDM_CHOOSER_WIDGET (widget),
                                             normalized_name,
                                             NULL,
                                             tagged,
                                             readable_language,
                                             0,
                                             FALSE,
                                             FALSE,
                                             NULL,
                                             NULL);
                g_free (language);
        }
        g_free (readable_language);
        g_free (tagged);
        g_free (lang_tag);
        g_free (normalized_name);
}
gchar *
cc_common_language_get_current_language (void)
{
        gchar *language;
        const gchar *locale;

        locale = (const gchar *) setlocale (LC_MESSAGES, NULL);
        if (locale)
                language = gdm_normalize_language_name (locale);
        else
                language = NULL;

        return language;
}
void
um_language_dialog_set_user (UmLanguageDialog *um,
                             UmUser           *user)
{
        GdkPixbuf *pixbuf;
        const gchar *name;

        if (um->user) {
                g_object_unref (um->user);
                um->user = NULL;
        }
        if (um->language) {
                g_free (um->language);
                um->language = NULL;
        }
        um->force_setting = FALSE;

        um->user = user;
        if (um->user) {
                const gchar *language;

                g_object_ref (user);

                pixbuf = um_user_render_icon (user, FALSE, 48);
                gtk_image_set_from_pixbuf (GTK_IMAGE (um->user_icon), pixbuf);
                g_object_unref (pixbuf);

                name = um_user_get_real_name (user);
                gtk_label_set_label (GTK_LABEL (um->user_name), name);

                um_add_user_languages (um->dialog_combo);

                language = um_user_get_language (user);
                if (language) {
                        select_language (um, language);
                } else if (um_user_get_uid (user) == getuid ()) {
                        const char *locale;
                        char *lang;

                        locale = (const char *) setlocale(LC_MESSAGES, NULL);
                        lang = gdm_normalize_language_name (locale);

                        select_language (um, lang);
                        g_free (lang);
                        um->force_setting = TRUE;
                }
        }
}
static gboolean
iter_for_language (GtkTreeModel *model,
                   const gchar  *lang,
                   GtkTreeIter  *iter,
                   gboolean      region)
{
        char *l;
        char *name;
        char *language;

        gtk_tree_model_get_iter_first (model, iter);
        do {
                gtk_tree_model_get (model, iter, LOCALE_COL, &l, -1);
                if (g_strcmp0 (l, lang) == 0) {
                        g_free (l);
                        return TRUE;
                }
                g_free (l);
        } while (gtk_tree_model_iter_next (model, iter));

        name = gdm_normalize_language_name (lang);
        if (name != NULL) {
                if (region) {
                        language = gdm_get_region_from_name (name, NULL);
                }
                else {
                        language = gdm_get_language_from_name (name, NULL);
                }

                gtk_list_store_insert_with_values (GTK_LIST_STORE (model),
                                                   iter,
                                                   -1,
                                                   LOCALE_COL, name,
                                                   DISPLAY_LOCALE_COL, language,
                                                   -1);
                g_free (name);
                g_free (language);
                return TRUE;
        }

        return FALSE;
}
void
gdm_language_chooser_widget_set_current_language_name (GdmLanguageChooserWidget *widget,
                                                       const char               *lang_name)
{
        char *name;

        g_return_if_fail (GDM_IS_LANGUAGE_CHOOSER_WIDGET (widget));

        if (lang_name == NULL) {
                gdm_chooser_widget_set_selected_item (GDM_CHOOSER_WIDGET (widget),
                                                      NULL);
                return;
        }

        name = gdm_normalize_language_name (lang_name);
        gdm_chooser_widget_set_selected_item (GDM_CHOOSER_WIDGET (widget),
                                              name);

        g_free (name);
}
int main (int argc, char **argv)
{
	char **langs;
	guint i;

	setlocale (LC_ALL, NULL);
	textdomain (GETTEXT_PACKAGE);
	bindtextdomain (GETTEXT_PACKAGE, "/usr/share/locale");
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

	g_type_init ();

	if (argc > 1) {
		guint i;
		for (i = 1; i < argc; i++) {
			char *lang, *norm;
			norm = gdm_normalize_language_name (argv[i]);
			lang = gdm_get_language_from_name (norm, NULL);
			g_print ("%s (norm: %s) == %s\n", argv[i], norm, lang);
			g_free (norm);
			g_free (lang);
		}
		return 0;
	}

	langs = gdm_get_all_language_names ();
	if (langs == NULL) {
		g_warning ("No languages found");
		return 1;
	}

	for (i = 0; langs[i] != NULL; i++)
		g_print ("%s == %s\n", langs[i], gdm_get_language_from_name (langs[i], NULL));

	g_strfreev (langs);

	return 0;
}
void
um_select_language (GtkWidget   *combo,
                    const gchar *lang)
{
        GtkTreeModel *model;
        GtkTreeIter iter;
        char *l;
        char *name;
        char *language;

        model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));

        gtk_widget_set_sensitive (combo, TRUE);

        gtk_tree_model_get_iter_first (model, &iter);
        do {
                gtk_tree_model_get (model, &iter, LOCALE_COL, &l, -1);
                if (g_strcmp0 (l, lang) == 0) {
                        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
                        g_free (l);
                        return;
                }
                g_free (l);
        } while (gtk_tree_model_iter_next (model, &iter));

        name = gdm_normalize_language_name (lang);
        if (name != NULL) {
                language = gdm_get_language_from_name (name, NULL);

                gtk_list_store_append (GTK_LIST_STORE (model), &iter);
                gtk_list_store_set (GTK_LIST_STORE (model), &iter, LOCALE_COL, name, DISPLAY_LOCALE_COL, language, -1);
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);

                g_free (name);
                g_free (language);
        }
}
void
um_add_user_languages (GtkWidget *combo)
{
        GHashTable *seen;
        GSList *users, *l;
        UmUser *user;
        const char *lang;
        char *name;
        char *language;
        GtkTreeIter iter;
        UmUserManager *manager;
        GtkTreeModel *model;
        GtkListStore *store;

        model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
        store = GTK_LIST_STORE (model);

        gtk_list_store_clear (store);

        seen = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

        manager = um_user_manager_ref_default ();
        users = um_user_manager_list_users (manager);
        g_object_unref (manager);

        for (l = users; l; l = l->next) {
                user = l->data;
                lang = um_user_get_language (user);
                if (!lang || !language_has_font (lang)) {
                        continue;
                }

                name = gdm_normalize_language_name (lang);

                if (g_hash_table_lookup (seen, name)) {
                        g_free (name);
                        continue;
                }

                g_hash_table_insert (seen, name, GINT_TO_POINTER (TRUE));

                language = gdm_get_language_from_name (name, NULL);
                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter, LOCALE_COL, name, DISPLAY_LOCALE_COL, language, -1);

                g_free (language);
        }

        g_slist_free (users);

        /* Make sure the current locale is present */
        lang = (const gchar *) setlocale (LC_MESSAGES, NULL);
        name = gdm_normalize_language_name (lang);

        if (!g_hash_table_lookup (seen, name)) {
                language = gdm_get_language_from_name (name, NULL);
                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter, LOCALE_COL, name, DISPLAY_LOCALE_COL, language, -1);
                g_free (language);
        }

        g_free (name);

        g_hash_table_destroy (seen);

        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter, LOCALE_COL, NULL, DISPLAY_LOCALE_COL, _("Other..."), -1);
}
static void
add_other_users_language (GHashTable *ht)
{
        GVariant *variant;
        GVariantIter *vi;
        GError *error = NULL;
        const char *str;
        GDBusProxy *proxy;

        proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                               G_DBUS_PROXY_FLAGS_NONE,
                                               NULL,
                                               "org.freedesktop.Accounts",
                                               "/org/freedesktop/Accounts",
                                               "org.freedesktop.Accounts",
                                               NULL,
                                               NULL);

        if (proxy == NULL)
                return;

        variant = g_dbus_proxy_call_sync (proxy,
                                          "ListCachedUsers",
                                          NULL,
                                          G_DBUS_CALL_FLAGS_NONE,
                                          -1,
                                          NULL,
                                          &error);
        if (variant == NULL) {
                g_warning ("Failed to list existing users: %s", error->message);
                g_error_free (error);
                g_object_unref (proxy);
                return;
        }
        g_variant_get (variant, "(ao)", &vi);
        while (g_variant_iter_loop (vi, "o", &str)) {
                GDBusProxy *user;
                GVariant *props;
                const char *lang;
                char *name;
                char *language;

                user = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                                      G_DBUS_PROXY_FLAGS_NONE,
                                                      NULL,
                                                      "org.freedesktop.Accounts",
                                                      str,
                                                      "org.freedesktop.Accounts.User",
                                                      NULL,
                                                      &error);
                if (user == NULL) {
                        g_warning ("Failed to get proxy for user '%s': %s",
                                   str, error->message);
                        g_error_free (error);
                        error = NULL;
                        continue;
                }
                props = g_dbus_proxy_get_cached_property (user, "Language");
                lang = g_variant_get_string (props, NULL);
                if (lang != NULL && *lang != '\0' &&
                    cc_common_language_has_font (lang) &&
                    gdm_language_has_translations (lang)) {
                        name = gdm_normalize_language_name (lang);
                        if (!g_hash_table_lookup (ht, name)) {
                                language = gdm_get_language_from_name (name, NULL);
                                g_hash_table_insert (ht, name, language);
                        }
                        else {
                                g_free (name);
                        }
                }
                g_variant_unref (props);
                g_object_unref (user);
        }
        g_variant_iter_free (vi);
        g_variant_unref (variant);

        g_object_unref (proxy);
}
static gboolean
add_one_language (gpointer d)
{
  AsyncLangData *data = d;
  char *name;
  char *language;
  GtkTreeIter iter;

  if (data->languages[data->position] == NULL) {
    /* we are done */
    async_lang_data_free (data);
    return FALSE;
  }

  name = gdm_normalize_language_name (data->languages[data->position]);
  if (g_hash_table_lookup (data->user_langs, name) != NULL) {
    g_free (name);
    goto next;
  }

  if (!cc_common_language_has_font (data->languages[data->position])) {
    g_free (name);
    goto next;
  }

  if (data->regions) {
    language = gdm_get_region_from_name (name, NULL);
  }
  else {
    language = gdm_get_language_from_name (name, NULL);
  }
  if (!language) {
    g_debug ("Ignoring '%s' as a locale, because we couldn't figure the language name", name);
    g_free (name);
    goto next;
  }

  /* Add separator between initial languages and new additions */
  if (g_object_get_data (G_OBJECT (data->store), "needs-separator")) {
    GtkTreeIter iter;

    gtk_list_store_insert_with_values (GTK_LIST_STORE (data->store),
                                       &iter,
                                       -1,
                                       LOCALE_COL, NULL,
                                       DISPLAY_LOCALE_COL, "Don't show",
                                       SEPARATOR_COL, TRUE,
                                       USER_LANGUAGE, FALSE,
                                       -1);
    g_object_set_data (G_OBJECT (data->store), "needs-separator", NULL);
  }

  gtk_list_store_insert_with_values (data->store,
                                     &iter,
                                     -1,
                                     LOCALE_COL, name,
                                     DISPLAY_LOCALE_COL, language,
                                     -1);

  g_free (name);
  g_free (language);

 next:
  data->position++;

  return TRUE;
}