Back to index

im-sdk  12.3.91
Enumerations | Functions | Variables
language.c File Reference
#include <config.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkdrawingarea.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtksignal.h>
#include <panel-applet.h>
#include <panel-applet-gconf.h>
#include <gnome.h>
#include "gnome-im-switcher.h"
#include "language.h"
#include "utils.h"
#include <gconf/gconf-client.h>
#include <gtk/gtktreeview.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtktreestore.h>
#include <string.h>
#include "gimlet-lang-data.h"

Go to the source code of this file.

Enumerations

enum  { COLUMN_NAME, COLUMN_DESCRIPTION, N_COLUMNS }

Functions

void gconf_set_conversion_keys (GtkWidget *, GSList *)
char * gconf_get_conversion_keys (GimletWindow *)
static void update_single_tree_model (GtkListStore *store)
static void unregister_store (void *data, GObject *where_object_was)
static void update_active_language_tree_models (void)
static void register_active_language_tree_model (GtkListStore *store)
static void update_active_languages_from_string_list (GSList *strings)
static void languages_change_notify (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data)
static GimletLanguage * find_language_by_description (const char *description)
static const GimletLanguage * find_language_by_iiim_lang_name (const char *iiim_lang_name)
gchar * gimlet_language_find_name (char *iiim_lang_name)
gchar * gimlet_language_find_description (char *iiim_lang_name)
gchar * gimlet_language_find_short (char *ilname)
static GimletLanguage * gimlet_language_copy (const GimletLanguage *src)
static void response_callback (GtkWidget *window, int id, void *data)
static void count_selected_items_func (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
static void available_selection_changed_callback (GtkTreeSelection *selection, void *data)
static void displayed_selection_changed_callback (GtkTreeSelection *selection, void *data)
static void get_selected_languages_func (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
static gboolean description_in_language_list (GSList *list, const char *str)
static GSList * remove_iiim_lang_from_list (GSList *list, const char *str)
static GSList * language_list_to_iiim_lang_list (GSList *src)
static void gconf_set_active_languages (GtkWidget *gimlet_applet, GSList *strings)
static GSList * gconf_get_active_languages (GimletWindow *gimlet)
static void add_button_clicked_callback (GtkWidget *button, void *data)
static void remove_button_clicked_callback (GtkWidget *button, void *data)
GtkWidget * gimlet_langmenu_dialog_new (GtkWindow *transient_parent, GimletWindow *gimlet)
void gimlet_language_init (GimletWindow *gimlet)
char * gimlet_language_get_name (GimletLanguage *data)
char * gimlet_language_get_iiim_lang_name (GimletLanguage *data)
char * gimlet_language_get_conversion_mode (char *iiim_lang_name)
GSList * gimlet_language_get_active_languages (void)
void gimlet_language_add_active_language (GimletWindow *gimlet, char *iiim_lang_name)
void gimlet_language_free (GimletLanguage *language)
static void hotkey_cancel_callback (GtkWidget *button, GimletWindow *gimlet)
static char * get_hotkey_with_type (char *string, char *type)
static void hotkey_changed_callback (GtkWidget *button, GimletWindow *gimlet)
GtkWidget * gimlet_hotkey_dialog_new (GtkWidget *transient_parent, GimletWindow *gimlet)

Variables

static GConfClient * default_client = NULL
static GSList * active_languages = NULL
static GSList * stores = NULL

Enumeration Type Documentation

anonymous enum
Enumerator:
COLUMN_NAME 
COLUMN_DESCRIPTION 
N_COLUMNS 

Definition at line 49 of file language.c.


Function Documentation

static void add_button_clicked_callback ( GtkWidget *  button,
void *  data 
) [static]

Definition at line 543 of file language.c.

{
  GtkWidget *dialog;
  GtkWidget *treeview;
  GtkWidget *gimlet_applet;
  GtkTreeSelection *selection;
  GSList *languages;
  GSList *tmp;
  GSList *active_iiim_lang_list;

  dialog = data;

  treeview = g_object_get_data (G_OBJECT (dialog),
                                "language-dialog-available-treeview");
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));

  languages = NULL;
  gtk_tree_selection_selected_foreach (selection,
                                       get_selected_languages_func,
                                       &languages);

  active_iiim_lang_list = language_list_to_iiim_lang_list (active_languages);

  tmp = languages;
  while (tmp != NULL)
    {
      /* appending is less efficient but produces user-expected
       * result
       */
      if (!description_in_language_list (active_languages, tmp->data))
       {
         GimletLanguage *l;

         l = find_language_by_description ((const char*)tmp->data);
#if 0
         if (l == NULL)
           continue;        /* this should not happen */
#endif
         active_iiim_lang_list = g_slist_append (active_iiim_lang_list,
                                            g_strdup (l->iiim_lang_name));
       }
      tmp = tmp->next;
    }

  /* this is reentrant, but only after it's done using the list
   * values, so should be safe
   */
  gimlet_applet = g_object_get_data (G_OBJECT (dialog),
                                 "gimlet-applet");

  gconf_set_active_languages (gimlet_applet, active_iiim_lang_list);

  g_slist_foreach (active_iiim_lang_list, (GFunc) g_free, NULL);
  g_slist_free (active_iiim_lang_list);
  
  g_slist_foreach (languages, (GFunc) g_free, NULL);
  g_slist_free (languages);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void available_selection_changed_callback ( GtkTreeSelection *  selection,
void *  data 
) [static]

Definition at line 336 of file language.c.

{
  int count;
  GtkWidget *add_button;
  GtkWidget *dialog;

  dialog = data;
  
  count = 0;
  gtk_tree_selection_selected_foreach (selection,
                                       count_selected_items_func,
                                       &count);

  add_button = g_object_get_data (G_OBJECT (dialog), "language-dialog-add");
  
  gtk_widget_set_sensitive (add_button, count > 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void count_selected_items_func ( GtkTreeModel *  model,
GtkTreePath *  path,
GtkTreeIter *  iter,
gpointer  data 
) [static]

Definition at line 325 of file language.c.

{
  int *count = data;

  *count += 1;
}

Here is the caller graph for this function:

static gboolean description_in_language_list ( GSList *  list,
const char *  str 
) [static]

Definition at line 395 of file language.c.

{
  GSList *tmp;

  tmp = list;
  while (tmp != NULL)
    {
      const GimletLanguage *lang = tmp->data;
      
      if (strcmp (lang->description, str) == 0)
        return TRUE;

      tmp = tmp->next;
    }

  return FALSE;
}

Here is the caller graph for this function:

static void displayed_selection_changed_callback ( GtkTreeSelection *  selection,
void *  data 
) [static]

Definition at line 356 of file language.c.

{
  int count;
  GtkWidget *remove_button;
  GtkWidget *dialog;

  dialog = data;
  
  count = 0;
  gtk_tree_selection_selected_foreach (selection,
                                       count_selected_items_func,
                                       &count);

  remove_button = g_object_get_data (G_OBJECT (dialog), "language-dialog-remove");
  
  gtk_widget_set_sensitive (remove_button, count > 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static GimletLanguage* find_language_by_description ( const char *  description) [static]

Definition at line 167 of file language.c.

{
  int i = 0;
  int n_elements = G_N_ELEMENTS (g_languages);

  while (i < n_elements)
    {
      if (strcmp (description, g_languages[i].description) == 0)
        return &g_languages[i];

      ++i;
    }

  return NULL;
}

Here is the caller graph for this function:

static const GimletLanguage* find_language_by_iiim_lang_name ( const char *  iiim_lang_name) [static]

Definition at line 184 of file language.c.

{
  int i = 0;
  int n_elements = G_N_ELEMENTS (g_languages);

  while (i < n_elements)
    {
      if (strcmp (iiim_lang_name, g_languages[i].iiim_lang_name) == 0)
        return &g_languages[i];

      ++i;
    }

  return NULL;
}

Here is the caller graph for this function:

static GSList* gconf_get_active_languages ( GimletWindow *  gimlet) [static]

Definition at line 515 of file language.c.

{
  gchar *key;
  GSList *strings = NULL;

  key = panel_applet_gconf_get_full_key (PANEL_APPLET (gimlet->applet),
                                    "active_languages");
  if (default_client == NULL)
    {
      GError *err;

      default_client = gconf_client_get_default ();
      g_object_ref (G_OBJECT (default_client));

      err = NULL;
      gconf_client_notify_add (default_client, key, 
                            languages_change_notify,
                            NULL, /* user_data */
                            NULL, &err);
    }
  strings = gconf_client_get_list (default_client,
                               key,
                               GCONF_VALUE_STRING, NULL);
  g_free (key);
  return strings;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * gconf_get_conversion_keys ( GimletWindow *  gimlet)

Definition at line 969 of file language.c.

{
  gchar *key;
  GSList *strings = NULL;
  int i, n;
  gchar *conversion_keys = NULL;
  char s[512], *p = s;

  key = panel_applet_gconf_get_full_key (PANEL_APPLET (gimlet->applet),
                                    "conversion_keys");
  if (default_client == NULL)
    {
      GError *err = NULL;

      default_client = gconf_client_get_default ();
      g_object_ref (G_OBJECT (default_client));
    }

  strings = gconf_client_get_list (default_client,
                               key,
                               GCONF_VALUE_STRING, NULL);

  
  n = g_list_length (strings);

  memset (s, 0, 512);

  for (i=0; i < n; ++i)
    {
      char *k = g_list_nth_data (strings, i);
      char key_delimiter = ',';

      strcpy (p, k);
      p += strlen (k);

      if (i < n -1)
       *p++ = key_delimiter;

      g_free (k);
    }

  g_free (key);
  g_list_free (strings);

  if (*s) conversion_keys = g_strdup (s);

  return conversion_keys;
}

Here is the caller graph for this function:

static void gconf_set_active_languages ( GtkWidget *  gimlet_applet,
GSList *  strings 
) [static]

Definition at line 501 of file language.c.

{
  gchar *key;

  key = panel_applet_gconf_get_full_key (PANEL_APPLET (gimlet_applet),
                                    (const gchar*)"active_languages");
  gconf_client_set_list (default_client, key, 
                         GCONF_VALUE_STRING,
                         strings,
                         NULL);
  g_free (key);
}

Here is the caller graph for this function:

static void gconf_set_conversion_keys ( GtkWidget *  gimlet_applet,
GSList *  strings 
)

Definition at line 954 of file language.c.

{
  gchar *key;

  key = panel_applet_gconf_get_full_key (PANEL_APPLET (gimlet_applet),
                                    (const gchar*)"conversion_keys");
  gconf_client_set_list (default_client, key,
                      GCONF_VALUE_STRING,
                      strings,
                      NULL);
  g_free (key);
}

Here is the caller graph for this function:

static char* get_hotkey_with_type ( char *  string,
char *  type 
) [static]

Definition at line 1026 of file language.c.

{
  char *label_delimiter = ":";
  char **hotkeys = g_strsplit (string, label_delimiter, -1);
  int num_hotkeys = 0, i;
  char *keys = NULL;

  // num_hotkeys = g_strv_length (hotkeys) / 2;
  while (hotkeys [num_hotkeys]) ++num_hotkeys;
  num_hotkeys /= 2;

  for (i = 0; i < num_hotkeys; ++i)
    {
      if (!strcmp (hotkeys[i * 2], type))
       {        
         keys = strdup (hotkeys[i * 2 + 1]);
         break;
       }
    }

  g_strfreev (hotkeys);

  return keys;
}

Here is the caller graph for this function:

static void get_selected_languages_func ( GtkTreeModel *  model,
GtkTreePath *  path,
GtkTreeIter *  iter,
gpointer  data 
) [static]

Definition at line 376 of file language.c.

{
  GSList **list = data;
  char *description;

  description = NULL;
  gtk_tree_model_get (model,
                      iter,
                      COLUMN_DESCRIPTION,
                      &description,
                      -1);

  *list = g_slist_prepend (*list, description);
}

Here is the caller graph for this function:

GtkWidget* gimlet_hotkey_dialog_new ( GtkWidget *  transient_parent,
GimletWindow *  gimlet 
)

Definition at line 1101 of file language.c.

{
  GladeXML *xml;
  GtkWidget *dialog = NULL;
  GtkWidget *vbox, *table;
  GtkWidget *trigger_entry, *w;
  int num_hotkeys = 0;
  gchar *label_delimiter = ":";
  gchar **hotkeys;
  int i;

  if (!gimlet->hotkey) return NULL;

  hotkeys = g_strsplit (gimlet->hotkey, label_delimiter, -1);

  //num_hotkeys = g_strv_length (hotkeys)/2;
  while (hotkeys[num_hotkeys]) ++num_hotkeys;
  num_hotkeys /= 2;

  xml = gimlet_util_load_glade_file (GIMLET_GLADE_FILE,
                                 "hotkey-dialog",
                                 transient_parent);

  if (xml == NULL) goto END_HOTKEY_DIALOG;

  dialog = glade_xml_get_widget (xml, "hotkey-dialog");

  gimlet_util_set_unique_role (GTK_WINDOW (dialog), "gimlet-hotkeys");

  /* dynamically create the table */
  vbox = glade_xml_get_widget (xml, "hotkey-vbox");
  table = gtk_table_new (num_hotkeys, 2, FALSE);
  gtk_table_set_row_spacings (GTK_TABLE (table), 4);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);

  for (i = 0; i < num_hotkeys; ++i)
    {
      w = gtk_label_new (hotkeys [i * 2]);
      gtk_table_attach_defaults (GTK_TABLE (table),
                             w,
                             0, 1, i, i + 1);

      w = gtk_entry_new ();
      gtk_entry_set_text (w, hotkeys[i * 2 + 1]);
      gtk_table_attach_defaults (GTK_TABLE (table),
                             w,
                             1, 2, i, i + 1);
      if (!strcasecmp (hotkeys[i * 2], TRIGGER_KEY_LABEL))
       trigger_entry = w;
      else
       gtk_widget_set_sensitive (w, FALSE);
    }

  w = glade_xml_get_widget (xml, "hotkey-okbutton");
  g_object_set_data (G_OBJECT (w), "iiim-hotkey-trigger",
                   trigger_entry);
  g_object_set_data (G_OBJECT (w), "iiim-hotkey-dialog",
                   dialog);

  g_signal_connect (G_OBJECT (w), "clicked",
                  G_CALLBACK (hotkey_changed_callback),
                  gimlet);

  w = glade_xml_get_widget (xml, "hotkey-cancelbutton");
  g_signal_connect (G_OBJECT (w), "clicked",
                  G_CALLBACK (hotkey_cancel_callback),
                  gimlet);

  /* FIXME one 'reset' button should be added here in order 
   * to reset the trigger key
   */

  g_object_unref (G_OBJECT (xml));

 END_HOTKEY_DIALOG:
  g_strfreev (hotkeys);
  return dialog;
}

Here is the call graph for this function:

Here is the caller graph for this function:

GtkWidget* gimlet_langmenu_dialog_new ( GtkWindow *  transient_parent,
GimletWindow *  gimlet 
)

Definition at line 663 of file language.c.

{
  GladeXML *xml;
  GtkWidget *w;
  GtkCellRenderer *cell_renderer;
  int i;
  GtkTreeModel *sort_model;
  GtkListStore *tree;
  GtkTreeViewColumn *column;
  GtkTreeIter parent_iter;
  GtkTreeSelection *selection;
  GtkWidget *dialog;

  xml = gimlet_util_load_glade_file (GIMLET_GLADE_FILE,
                                 "languages-dialog",
                                 transient_parent);
  if (xml == NULL)
    return NULL;

  /* The dialog itself */
  dialog = glade_xml_get_widget (xml, "languages-dialog");

  gimlet_util_set_unique_role (GTK_WINDOW (dialog), "gimlet-languages");

  g_signal_connect (G_OBJECT (dialog), "response",
                    G_CALLBACK (response_callback),
                    NULL);

  /* buttons */
  w = glade_xml_get_widget (xml, "add-button");
  g_object_set_data (G_OBJECT (dialog),
                     "language-dialog-add",
                     w);

  g_object_set_data (G_OBJECT (dialog),
                     "gimlet-applet",
                     gimlet->applet);
  g_signal_connect (G_OBJECT (w), "clicked",
                    G_CALLBACK (add_button_clicked_callback),
                    dialog);

  w = glade_xml_get_widget (xml, "remove-button");
  g_object_set_data (G_OBJECT (dialog),
                     "language-dialog-remove",
                     w);

  g_signal_connect (G_OBJECT (w), "clicked",
                    G_CALLBACK (remove_button_clicked_callback),
                    dialog);
  
  /* Tree view of available languages */
  
  w = glade_xml_get_widget (xml, "available-treeview");
  g_object_set_data (G_OBJECT (dialog),
                     "language-dialog-available-treeview",
                     w);
  
  tree = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);

  /* Column 1 */
  cell_renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes (_("_Language"),
                                               cell_renderer,
                                               "text", COLUMN_NAME,
                                               NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (w), column);
  gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);
  
  /* Column 2 */
  cell_renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes (_("_Description"),
                                               cell_renderer,
                                               "text", COLUMN_DESCRIPTION,
                                               NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (w), column);
  gtk_tree_view_column_set_sort_column_id (column, COLUMN_DESCRIPTION);  

  /* Add the data */

  i = 0;
  while (i < (int) G_N_ELEMENTS (g_languages))
    {
      if (g_languages[i].valid && (strcmp (g_languages[i].iiim_lang_name,
                                      "ASCII") != 0))
        {
          gtk_list_store_append (tree, &parent_iter);
          gtk_list_store_set (tree, &parent_iter,
                              COLUMN_DESCRIPTION,
                              g_languages[i].description,
                              COLUMN_NAME,
                              g_languages[i].name,
                              -1);
        }
      ++i;
    }

  /* Sort model */
  sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree));
  
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model),
                                        COLUMN_NAME,
                                        GTK_SORT_ASCENDING);
  
  gtk_tree_view_set_model (GTK_TREE_VIEW (w), sort_model);
  g_object_unref (G_OBJECT (tree));

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (w));    
  gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection),
                            GTK_SELECTION_MULTIPLE);

  available_selection_changed_callback (selection, dialog);
  g_signal_connect (G_OBJECT (selection), "changed",                    
                    G_CALLBACK (available_selection_changed_callback),
                    dialog);

  /* Tree view of selected languages */
  
  w = glade_xml_get_widget (xml, "displayed-treeview");
  g_object_set_data (G_OBJECT (dialog),
                     "language-dialog-displayed-treeview",
                     w);
  
  tree = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);

  /* Column 1 */
  cell_renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes (_("_Language"),
                                               cell_renderer,
                                               "text", COLUMN_NAME,
                                               NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (w), column);
  gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);
  
  /* Column 2 */
  cell_renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes (_("_Description"),
                                               cell_renderer,
                                               "text", COLUMN_DESCRIPTION,
                                               NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (w), column);
  gtk_tree_view_column_set_sort_column_id (column, COLUMN_DESCRIPTION);  

  /* Add the data */
  register_active_language_tree_model (tree);

  /* Sort model */
  sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree));
  
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model),
                                        COLUMN_NAME,
                                        GTK_SORT_ASCENDING);
  
  gtk_tree_view_set_model (GTK_TREE_VIEW (w), sort_model);
  g_object_unref (G_OBJECT (tree));  

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (w));    
  gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection),
                            GTK_SELECTION_MULTIPLE);

  displayed_selection_changed_callback (selection, dialog);
  g_signal_connect (G_OBJECT (selection), "changed",
                    G_CALLBACK (displayed_selection_changed_callback),
                    dialog);

  g_object_unref (G_OBJECT (xml));
  
  return dialog;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gimlet_language_add_active_language ( GimletWindow *  gimlet,
char *  iiim_lang_name 
)

Definition at line 920 of file language.c.

{
  GtkWidget *gimlet_applet = GTK_WIDGET (gimlet->applet);
  GSList *active_iiim_lang_list;
  GSList *tmp;

  active_iiim_lang_list = language_list_to_iiim_lang_list (active_languages);

  tmp = active_iiim_lang_list;
  while (tmp != NULL)
    {
      if (strcmp (tmp->data, iiim_lang_name) == 0)
       return;
      tmp = tmp->next;
    }
  active_iiim_lang_list = g_slist_prepend (active_iiim_lang_list,
                                      g_strdup (iiim_lang_name));
  gconf_set_active_languages (gimlet_applet, active_iiim_lang_list);

  g_slist_foreach (active_iiim_lang_list, (GFunc) g_free, NULL);
  g_slist_free (active_iiim_lang_list);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static GimletLanguage* gimlet_language_copy ( const GimletLanguage *  src) [static]

Definition at line 247 of file language.c.

{
  GimletLanguage *c;

  c = g_new (GimletLanguage, 1);
  c->idx = src->idx;
  c->valid = src->valid;
  c->conversion_on = src->conversion_on;
  c->name = g_strdup (src->name);
  c->description = g_strdup (src->description);
  c->iiim_lang_name = g_strdup (src->iiim_lang_name);
  
  return c;
}

Here is the caller graph for this function:

gchar* gimlet_language_find_description ( char *  iiim_lang_name)

Definition at line 211 of file language.c.

{
  const GimletLanguage *ilname = find_language_by_iiim_lang_name (iiim_lang_name);
  if (ilname)
    return ilname->description;
  else
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gchar* gimlet_language_find_name ( char *  iiim_lang_name)

Definition at line 201 of file language.c.

{
  const GimletLanguage *ilname = find_language_by_iiim_lang_name (iiim_lang_name);
  if (ilname)
    return ilname->name;
  else
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gchar* gimlet_language_find_short ( char *  ilname)

Definition at line 221 of file language.c.

{
  if (find_language_by_iiim_lang_name (ilname))
    {
      /* treat Chinese specially */
      if (strlen (ilname) == 5 &&
         ilname[0] == 'z' &&
         ilname[1] == 'h')
       {
         if (strcmp (ilname, "zh_CN") == 0)
           return (g_strdup ("SC"));
         else
           return (g_strdup ("TC"));
       }    
      else
       {
         gchar *ll = g_strndup (ilname, 2);
         ll[0] = g_ascii_toupper (ll[0]);
         return ll;
       }
    }
  else
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gimlet_language_free ( GimletLanguage *  language)

Definition at line 945 of file language.c.

{
  g_free (language->name);
  g_free (language->description);
  g_free (language->iiim_lang_name);
  g_free (language);
}

Here is the caller graph for this function:

Definition at line 897 of file language.c.

{
  GSList *copy;
  GSList *tmp;

  copy = NULL;
  tmp = active_languages;
  while (tmp != NULL)
    {
      copy = g_slist_append (copy,
                              gimlet_language_copy (tmp->data));
      
      tmp = tmp->next;
    }

  return copy;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* gimlet_language_get_conversion_mode ( char *  iiim_lang_name)

Definition at line 882 of file language.c.

{
  GSList *tmp = active_languages;

  while (tmp != NULL)
    {
      GimletLanguage *lang = tmp->data;
      if (strcmp (lang->iiim_lang_name, iiim_lang_name) == 0)
         return (lang->conversion_on ? "on" : "off");
      tmp = tmp->next;
    }
  return "off";
}

Here is the caller graph for this function:

char* gimlet_language_get_iiim_lang_name ( GimletLanguage *  data)

Definition at line 875 of file language.c.

{
  /* avoid returning NULL */
  return data->iiim_lang_name ? data->iiim_lang_name : DEFAULT_LANG;
}

Here is the caller graph for this function:

char* gimlet_language_get_name ( GimletLanguage *  data)

Definition at line 869 of file language.c.

{
  return data->name;
}

Here is the caller graph for this function:

void gimlet_language_init ( GimletWindow *  gimlet)

Definition at line 834 of file language.c.

{
  int i;
  int n_elements;
  gchar **p;
  GSList *strings = NULL;

  n_elements = G_N_ELEMENTS (g_languages);

  if (gimlet->client_lang_list != NULL)
    {
      for (p = gimlet->client_lang_list; *p; p++)
       for (i = 0; i < n_elements; i++)
         {
           /* Translate the description */
           g_languages[i].description = _(g_languages[i].description);

           if (g_languages[i].iiim_lang_name != NULL)
             {
              guint len = strlen (g_languages[i].iiim_lang_name);
              if (strncmp (g_languages[i].iiim_lang_name, *p, len) == 0)
                g_languages[i].valid = TRUE;
             }
         }
    }

  strings = gconf_get_active_languages (gimlet);

  update_active_languages_from_string_list (strings);

  g_slist_foreach (strings, (GFunc) g_free, NULL);
  g_slist_free (strings);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hotkey_cancel_callback ( GtkWidget *  button,
GimletWindow *  gimlet 
) [static]

Definition at line 1019 of file language.c.

{
  gtk_widget_destroy (GTK_WINDOW (gimlet->edit_hotkey_dialog));
}

Here is the caller graph for this function:

static void hotkey_changed_callback ( GtkWidget *  button,
GimletWindow *  gimlet 
) [static]

Definition at line 1053 of file language.c.

{
  GSList *strings = NULL;
  GtkEntry *trigger_entry = (GtkEntry *)g_object_get_data (G_OBJECT (button),
                                      "iiim-hotkey-trigger");
  char *trigger; 
  char **keys;
  char *key_delimiter = ",";
  char *old_trigger;
  int num_keys, i;
  
  trigger = strdup (gtk_entry_get_text (trigger_entry));

  /* return if no change is made */
  
  old_trigger = get_hotkey_with_type (gimlet->hotkey, TRIGGER_KEY_LABEL);
  if (!strcasecmp (trigger, old_trigger))
    goto END_HOTKEY_CHANGED_CALLBACK;

  /*
   * FIXME one warning dialog should be popuped if the trigger input is corrupted.
   */

  gimlet_iiim_hotkey_set (gimlet, trigger);

  keys = g_strsplit (trigger, key_delimiter, -1);

  //  num_keys = g_strv_length (keys);
  num_keys = 0;
  while (keys[num_keys]) ++num_keys;

  for (i = 0; i < num_keys; ++i)
    strings = g_list_insert (strings, keys[i], -1);

  gconf_set_conversion_keys (gimlet->applet, strings);

  g_list_free (strings);
  g_strfreev (keys);

 END_HOTKEY_CHANGED_CALLBACK:
  gtk_widget_destroy (GTK_WINDOW (gimlet->edit_hotkey_dialog));

  g_free (old_trigger);
  g_free (trigger);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static GSList* language_list_to_iiim_lang_list ( GSList *  src) [static]

Definition at line 482 of file language.c.

{
  GSList *list;
  GSList *tmp;
  
  list = NULL;
  tmp = src;
  while (tmp != NULL)
    {
      const GimletLanguage *lang = tmp->data;
      
      list = g_slist_append (list, g_strdup (lang->iiim_lang_name));
      tmp = tmp->next;
    }

  return list;
}

Here is the caller graph for this function:

static void languages_change_notify ( GConfClient *  client,
guint  cnxn_id,
GConfEntry *  entry,
gpointer  user_data 
) [static]

Definition at line 124 of file language.c.

{
  GConfValue *val;
  GSList *strings;
  
  /* FIXME handle whether the entry is writable
   */

  val = gconf_entry_get_value (entry);
  if (val == NULL || val->type != GCONF_VALUE_LIST ||
      gconf_value_get_list_type (val) != GCONF_VALUE_STRING)
    strings = NULL;
  else
    {
      GSList *tmp;

      strings = NULL;
      tmp = gconf_value_get_list (val);
      while (tmp != NULL)
        {
          GConfValue *v = tmp->data;
          g_assert (v->type == GCONF_VALUE_STRING);

          if (gconf_value_get_string (v))
            {
              strings = g_slist_prepend (strings,
                                    (gchar*) gconf_value_get_string (v));
            }
          
          tmp = tmp->next;
        }
    }

  update_active_languages_from_string_list (strings);

  /* note we didn't copy the strings themselves, so don't free them */
  g_slist_free (strings);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void register_active_language_tree_model ( GtkListStore *  store) [static]

Definition at line 114 of file language.c.

{
  update_single_tree_model (store);
  stores = g_slist_prepend (stores, store);
  g_object_weak_ref (G_OBJECT (store), unregister_store, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void remove_button_clicked_callback ( GtkWidget *  button,
void *  data 
) [static]

Definition at line 604 of file language.c.

{
  GtkWidget *dialog;
  GtkWidget *treeview;
  GtkWidget *gimlet_applet;
  GtkTreeSelection *selection;
  GSList *languages;
  GSList *tmp;
  GSList *active_iiim_lang_list;

  dialog = data;

  treeview = g_object_get_data (G_OBJECT (dialog),
                                "language-dialog-displayed-treeview");
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));

  languages = NULL;
  gtk_tree_selection_selected_foreach (selection,
                                       get_selected_languages_func,
                                       &languages);

  active_iiim_lang_list = language_list_to_iiim_lang_list (active_languages);

  tmp = languages;
  while (tmp != NULL)
    {
      GimletLanguage *l;

      /* appending is less efficient but produces user-expected
       * result
       */
      l = find_language_by_description (tmp->data);
#if 0
      if (l == NULL)
       continue;            /* this should not happen */
#endif
      active_iiim_lang_list =
       remove_iiim_lang_from_list (active_iiim_lang_list, l->iiim_lang_name);

      tmp = tmp->next;
    }

  /* this is reentrant, but only after it's done using the list
   * values, so should be safe
   */
  gimlet_applet = g_object_get_data (G_OBJECT (dialog),
                                 "gimlet-applet");

  gconf_set_active_languages (gimlet_applet, active_iiim_lang_list);

  g_slist_foreach (active_iiim_lang_list, (GFunc) g_free, NULL);
  g_slist_free (active_iiim_lang_list);

  g_slist_foreach (languages, (GFunc) g_free, NULL);
  g_slist_free (languages);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static GSList* remove_iiim_lang_from_list ( GSList *  list,
const char *  str 
) [static]

Definition at line 415 of file language.c.

{
  GSList *tmp;

  tmp = list;
  while (tmp != NULL)
    {
      if (strcmp (tmp->data, str) == 0)
        break;

      tmp = tmp->next;
    }

  if (tmp != NULL)
    {
      list = g_slist_remove (list, tmp->data);
      g_free (tmp->data);
    }
  return list;
}

Here is the caller graph for this function:

static void response_callback ( GtkWidget *  window,
int  id,
void *  data 
) [static]

Definition at line 314 of file language.c.

{
  if (id == GTK_RESPONSE_HELP)
    gimlet_util_show_help ("imswitcher-usage-add", GTK_WINDOW (window));
  else
    gtk_widget_destroy (GTK_WIDGET (window));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void unregister_store ( void *  data,
GObject *  where_object_was 
) [static]

Definition at line 95 of file language.c.

{
  stores = g_slist_remove (stores, where_object_was);
}

Here is the caller graph for this function:

static void update_active_language_tree_models ( void  ) [static]

Definition at line 102 of file language.c.

{
  GSList *tmp;
  tmp = stores;
  while (tmp != NULL)
    {
      update_single_tree_model (tmp->data);
      tmp = tmp->next;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void update_active_languages_from_string_list ( GSList *  strings) [static]

Definition at line 263 of file language.c.

{
  GSList *tmp;
  GHashTable *table;
  const char *description;

  table = g_hash_table_new (g_direct_hash, g_direct_equal);
  
  g_slist_foreach (active_languages, (GFunc) gimlet_language_free,
                 NULL);
  g_slist_free (active_languages);
  active_languages = NULL;

  /* First add the ASCII . */
  description = g_languages[ASCII].description;
  if (g_hash_table_lookup (table, GINT_TO_POINTER (g_quark_from_string (description))) == NULL)
    {
      active_languages = g_slist_prepend (active_languages,
                                     gimlet_language_copy (&g_languages[ASCII]));
      g_hash_table_insert (table,
                        GINT_TO_POINTER (g_quark_from_string (description)),
                        GINT_TO_POINTER (g_quark_from_string (description)));
    }

  for (tmp = strings; tmp != NULL; tmp = tmp->next)
    {
      const GimletLanguage *l;
      GimletLanguage *language;
      const char *iiim_lang_name = tmp->data;
      
      l = find_language_by_iiim_lang_name (iiim_lang_name);
      if (l == NULL)
       continue;            /* this can happen e.g client locale is "C" */

      if (g_hash_table_lookup (table, GINT_TO_POINTER (g_quark_from_string (l->description))) != NULL)
       continue;
      g_hash_table_insert (table,
                        GINT_TO_POINTER (g_quark_from_string (l->description)),
                        GINT_TO_POINTER (g_quark_from_string (l->description)));
      language = l->valid ? gimlet_language_copy (l) : NULL;

      if (language != NULL)
       active_languages = g_slist_append (active_languages, language);
    }

  g_hash_table_destroy (table);
  
  update_active_language_tree_models ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void update_single_tree_model ( GtkListStore *  store) [static]

Definition at line 66 of file language.c.

{
  GSList *tmp;
  GtkTreeIter parent_iter;

  gtk_list_store_clear (store);
  
  tmp = active_languages;
  while (tmp != NULL)
    {
      GimletLanguage *e = tmp->data;
      
      if (strcmp (e->iiim_lang_name, "ASCII") != 0)
       {
         gtk_list_store_append (store, &parent_iter);
         gtk_list_store_set (store, &parent_iter,
                           COLUMN_DESCRIPTION,
                           e->description,
                           COLUMN_NAME,
                           e->name,
                           -1);
       }
      tmp = tmp->next;
    }
}

Here is the caller graph for this function:


Variable Documentation

GSList* active_languages = NULL [static]

Definition at line 62 of file language.c.

GConfClient* default_client = NULL [static]

Definition at line 47 of file language.c.

GSList* stores = NULL [static]

Definition at line 92 of file language.c.