GHashTable *
terminal_encodings_get_builtins (void)
{
  GHashTable *encodings_hashtable;
  guint i;
  TerminalEncoding *encoding;

  encodings_hashtable = g_hash_table_new_full (g_str_hash, g_str_equal,
                                               NULL,
                                               (GDestroyNotify) terminal_encoding_unref);


  /* Placeholder entry for the current locale's charset */
  encoding = terminal_encoding_new ("current",
                                    _("Current Locale"),
                                    FALSE,
                                    TRUE);
  g_hash_table_insert (encodings_hashtable,
                       (gpointer) terminal_encoding_get_id (encoding),
                       encoding);

  for (i = 0; i < G_N_ELEMENTS (encodings); ++i)
    {
      encoding = terminal_encoding_new (encodings[i].charset,
                                        _(encodings[i].name),
                                        FALSE,
                                        FALSE);
      g_hash_table_insert (encodings_hashtable,
                           (gpointer) terminal_encoding_get_id (encoding),
                           encoding);
    }

  return encodings_hashtable;
}
示例#2
0
/**
 * terminal_app_ensure_encoding:
 * @app:
 * @charset: (allow-none): a charset, or %NULL
 *
 * Ensures there's a #TerminalEncoding for @charset available. If @charset
 * is %NULL, returns the #TerminalEncoding for the locale's charset. If
 * @charset is not a known charset, returns a #TerminalEncoding for a
 * custom charset.
 *
 * Returns: (transfer none): a #TerminalEncoding, or %NULL
 */
TerminalEncoding *
terminal_app_ensure_encoding (TerminalApp *app,
                              const char *charset)
{
  TerminalEncoding *encoding;

  encoding = g_hash_table_lookup (app->encodings, charset_validated (charset));
  if (encoding == NULL)
    {
      encoding = terminal_encoding_new (charset,
                                        _("User Defined"),
                                        TRUE,
                                        TRUE /* scary! */);
      g_hash_table_insert (app->encodings,
                          (gpointer) terminal_encoding_get_charset (encoding),
                          encoding);
    }

  return encoding;
}