Ejemplo n.º 1
0
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;
			lang = gdm_get_language_from_name (argv[i], NULL);
			g_print ("%s == %s\n", argv[i], lang);
			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;
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
0
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);
}
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);
}
Ejemplo n.º 5
0
gboolean _fcitx_im_dialog_filter_func(GtkTreeModel *model,
                                      GtkTreeIter  *iter,
                                      gpointer      data)
{
    FcitxImDialog* self = data;
    const gchar* filter_text = gtk_entry_get_text(GTK_ENTRY(self->filterentry));
    FcitxIMItem* item = NULL;
    gtk_tree_model_get(GTK_TREE_MODEL(self->availimstore),
                       iter,
                       IM_LIST_IM, &item,
                       -1);

    gboolean flag = TRUE;
    if (item) {
        if (strcmp(item->unique_name, "fcitx-keyboard-us") != 0) {
            char* language = gdm_get_language_from_name(item->langcode, NULL);
            flag = flag && (
                        strlen(filter_text) == 0
                     || strcasestr(item->name, filter_text)
                     || strcasestr(item->unique_name, filter_text)
                     || strcasestr(item->langcode, filter_text)
                     || (language && strcasestr(language, filter_text)));
            g_free(language);

            gchar temp[3] = {0, 0, 0};
            strncpy(temp, item->langcode, 2);
            flag = flag && (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->onlycurlangcheckbox)) ?
                     strncmp(item->langcode, self->language , 2) == 0 || g_hash_table_contains(self->langset, temp) : TRUE) ;
        }
    }
    return flag;
}
Ejemplo n.º 6
0
void _fcitx_inputmethod_insert_foreach_cb(gpointer data,
        gpointer user_data)
{
    FcitxIMItem* item = data;
    FcitxImDialog* self = user_data;
    GtkTreeIter iter;

    if (!item->enable) {
        gtk_list_store_append(self->availimstore, &iter);
        char* lang = NULL;
        if (strlen(item->langcode) != 0)
            lang = gdm_get_language_from_name(item->langcode, NULL);
        if (!lang) {
            if (strcmp(item->langcode, "*") == 0)
                lang = g_strdup_printf("%s", _("Unknown"));
            else
                lang = g_strdup_printf("%s", _("Unknown"));
        }
        gtk_list_store_set(self->availimstore, &iter, IM_LIST_IM_STRING, item->name, IM_LIST_IM, item, IM_LIST_IM_LANGUAGE, lang, -1);
    } else {
        gchar temp[3] = {0, 0, 0};
        strncpy(temp, item->langcode, 2);
        if (!g_hash_table_contains(self->langset, temp)) {
            g_hash_table_insert(self->langset, g_strdup(temp), NULL);
        }
    }
}
Ejemplo n.º 7
0
void _fcitx_inputmethod_insert_foreach_cb(gpointer data,
        gpointer user_data)
{
    foreach_ct* context = user_data;
    FcitxIMItem* item = data;
    FcitxImWidget* self = context->widget;
    GtkTreeIter iter;

    if (item->enable) {
        context->flag = TRUE;
        gtk_list_store_append(self->imstore, &iter);
        gtk_list_store_set(self->imstore, &iter, IM_LIST_IM_STRING, item->name, -1);
        gtk_list_store_set(self->imstore, &iter, IM_LIST_IM, item, -1);
        char* lang = NULL;
        if (strlen(item->langcode) != 0)
            lang = gdm_get_language_from_name(item->langcode, NULL);
        if (!lang) {
            if (strcmp(item->langcode, "*") == 0)
                lang = g_strdup_printf("%s", _("Unknown"));
            else
                lang = g_strdup_printf("%s", _("Unknown"));
        }
        gtk_list_store_set(self->imstore, &iter, IM_LIST_IM_LANGUAGE, lang, -1);
        if (self->focus == NULL || strcmp(self->focus, item->unique_name) == 0)
            context->iter = iter;
    }
}
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
system_update_language (GtkBuilder *dialog, const gchar *language)
{
        gchar *display_language;
        GtkWidget *label;

        display_language = gdm_get_language_from_name (language, NULL);
        label = WID ("user_display_language");
        gtk_label_set_text (GTK_LABEL (label), display_language);
        g_object_set_data_full (G_OBJECT (label), "language", g_strdup (language), g_free);
        g_free (display_language);

        /* need to update the region display in case the setting is '' */
        locale_settings_changed (locale_settings, "region", dialog);

        update_copy_button (dialog);
}
GHashTable *
cc_common_language_get_initial_languages (void)
{
        GHashTable *ht;
        char *name;
        char *language;

        ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);

        /* Add some common languages first */
        g_hash_table_insert (ht, g_strdup ("en_US.utf8"), g_strdup (_("English")));
        if (gdm_language_has_translations ("en_GB"))
                g_hash_table_insert (ht, g_strdup ("en_GB.utf8"), g_strdup (_("British English")));
        if (gdm_language_has_translations ("de") ||
            gdm_language_has_translations ("de_DE"))
                g_hash_table_insert (ht, g_strdup ("de_DE.utf8"), g_strdup (_("German")));
        if (gdm_language_has_translations ("fr") ||
            gdm_language_has_translations ("fr_FR"))
                g_hash_table_insert (ht, g_strdup ("fr_FR.utf8"), g_strdup (_("French")));
        if (gdm_language_has_translations ("es") ||
            gdm_language_has_translations ("es_ES"))
                g_hash_table_insert (ht, g_strdup ("es_ES.utf8"), g_strdup (_("Spanish")));
        if (gdm_language_has_translations ("zh_CN"))
                g_hash_table_insert (ht, g_strdup ("zh_CN.utf8"), g_strdup (_("Chinese (simplified)")));
        if (gdm_language_has_translations ("ru") ||
            gdm_language_has_translations ("ru_RU"))
                 g_hash_table_insert (ht, g_strdup ("ru_RU.utf8"), g_strdup (_("Russian")));
        if (gdm_language_has_translations ("ar") ||
            gdm_language_has_translations ("ar_EG"))
                g_hash_table_insert (ht, g_strdup ("ar_EG.utf8"), g_strdup (_("Arabic")));

        /* Add the languages used by other users on the system */
        add_other_users_language (ht);

        /* Add current locale */
        name = cc_common_language_get_current_language ();
        if (g_hash_table_lookup (ht, name) == NULL) {
                language = gdm_get_language_from_name (name, NULL);
                g_hash_table_insert (ht, name, language);
        } else {
                g_free (name);
        }

        return ht;
}
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
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);
}
Ejemplo n.º 14
0
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;
}
static void
on_localed_properties_changed (GDBusProxy   *proxy,
                               GVariant     *changed_properties,
                               const gchar **invalidated_properties,
                               GtkBuilder   *dialog)
{
        GVariant *v;
        GtkWidget *label;
        const char *layout;
        char **layouts;
        GString *disp;
        guint i;

        if (invalidated_properties != NULL) {
                guint i;
                for (i = 0; invalidated_properties[i] != NULL; i++) {
                        if (g_str_equal (invalidated_properties[i], "Locale"))
                                update_property (proxy, "Locale");
                        else if (g_str_equal (invalidated_properties[i], "X11Layout"))
                                update_property (proxy, "X11Layout");
                }
        }

        v = g_dbus_proxy_get_cached_property (proxy, "Locale");
        if (v) {
                const gchar **strv;
                gsize len;
                gint i;
                const gchar *lang, *messages, *time;
                gchar *name;
                GtkWidget *label;

                strv = g_variant_get_strv (v, &len);

                lang = messages = time = NULL;
                for (i = 0; strv[i]; i++) {
                        if (g_str_has_prefix (strv[i], "LANG=")) {
                                lang = strv[i] + strlen ("LANG=");
                        }
                        else if (g_str_has_prefix (strv[i], "LC_MESSAGES=")) {
                                messages = strv[i] + strlen ("LC_MESSAGES=");
                        }
                        else if (g_str_has_prefix (strv[i], "LC_TIME=")) {
                                time = strv[i] + strlen ("LC_TIME=");
                        }
                }
                if (!messages) {
                        messages = lang;
                }
                if (!time) {
                        time = lang;
                }

                if (messages) {
                        name = gdm_get_language_from_name (messages, NULL);
                        label = WID ("system_display_language");
                        gtk_label_set_text (GTK_LABEL (label), name);
                        g_free (name);
                        g_object_set_data_full (G_OBJECT (label), "language", g_strdup (lang), g_free);
                }

                if (time) {
                        name = gdm_get_region_from_name (time, NULL);
                        label = WID ("system_format");
                        gtk_label_set_text (GTK_LABEL (label), name);
                        g_free (name);
                        g_object_set_data_full (G_OBJECT (label), "region", g_strdup (time), g_free);
                }
                g_variant_unref (v);
        }

        label = WID ("system_input_source");
        v = g_dbus_proxy_get_cached_property (proxy, "X11Layout");
        if (v) {
                layout = g_variant_get_string (v, NULL);
                g_object_set_data_full (G_OBJECT (label), "input_source", g_strdup (layout), g_free);
	} else {
                g_object_set_data_full (G_OBJECT (label), "input_source", NULL, g_free);
                update_copy_button (dialog);
                return;
        }

	disp = g_string_new ("");
	layouts = g_strsplit (layout, ",", -1);
	for (i = 0; layouts[i]; i++) {
		gchar *utf_visible;

		utf_visible = xkb_layout_description_utf8 (layouts[i]);
		if (disp->str[0] != '\0')
			disp = g_string_append (disp, ", ");
		disp = g_string_append (disp, utf_visible ? utf_visible : layouts[i]);
		g_free (utf_visible);
	}
        gtk_label_set_text (GTK_LABEL (label), disp->str);
        g_string_free (disp, TRUE);

        g_variant_unref (v);

        update_copy_button (dialog);
}