Commit 395e3105 authored by Bastien Nocera's avatar Bastien Nocera
Browse files

region: Populate the language list

Using the new common/ helper functions.
parent 226aa064
......@@ -128,15 +128,16 @@ cc_region_panel_init (CcRegionPanel * self)
return;
}
setup_images (priv->builder);
setup_xkb_tabs (priv->builder);
setup_language (priv->builder);
prefs_widget = (GtkWidget *) gtk_builder_get_object (priv->builder,
"region_notebook");
gtk_widget_set_size_request (GTK_WIDGET (prefs_widget), -1, 400);
gtk_widget_reparent (prefs_widget, GTK_WIDGET (self));
setup_images (priv->builder);
setup_xkb_tabs (priv->builder);
setup_language (priv->builder);
}
void
......
......@@ -28,9 +28,96 @@
#include "gnome-region-panel-lang.h"
#include "cc-common-language.h"
#include "gdm-languages.h"
static GHashTable *
new_ht_for_user_languages (void)
{
GHashTable *ht;
char *name;
char *language;
ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
/* FIXME: As in um-language-dialog.c, we should add the
* languages used by other users on the system */
/* Add current locale */
name = cc_common_language_get_current_language ();
language = gdm_get_language_from_name (name, NULL);
g_hash_table_insert (ht, name, language);
return ht;
}
static void
remove_timeout (gpointer data,
GObject *where_the_object_was)
{
guint timeout = GPOINTER_TO_UINT (data);
g_source_remove (timeout);
}
static gboolean
finish_language_setup (gpointer user_data)
{
GtkWidget *list = (GtkWidget *) user_data;
GtkTreeModel *model;
GtkWidget *parent;
GHashTable *user_langs;
guint timeout;
/* Did we get called after the widget was destroyed? */
if (list == NULL)
return FALSE;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
user_langs = g_object_get_data (G_OBJECT (list), "user-langs");
cc_common_language_add_available_languages (GTK_LIST_STORE (model), user_langs);
parent = gtk_widget_get_toplevel (list);
gdk_window_set_cursor (gtk_widget_get_window (parent), NULL);
g_object_set_data (G_OBJECT (list), "user-langs", NULL);
timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (list), "timeout"));
g_object_weak_unref (G_OBJECT (list), (GWeakNotify) remove_timeout, GUINT_TO_POINTER (timeout));
return FALSE;
}
void
setup_language (GtkBuilder *builder)
{
g_message ("TODO");
GtkWidget *treeview;
GHashTable *user_langs;
GtkWidget *parent;
GtkTreeModel *model;
GdkWindow *window;
guint timeout;
treeview = GTK_WIDGET (gtk_builder_get_object (builder, "display_language_treeview"));
parent = gtk_widget_get_toplevel (treeview);
g_message ("parent %p", parent);
/* Add user languages */
user_langs = new_ht_for_user_languages ();
cc_common_language_setup_list (treeview, user_langs);
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
/* Setup so that the list is populated after the list appears */
window = gtk_widget_get_window (parent);
if (window) {
GdkCursor *cursor;
cursor = gdk_cursor_new (GDK_WATCH);
gdk_window_set_cursor (gtk_widget_get_window (parent), cursor);
g_object_unref (cursor);
}
g_object_set_data_full (G_OBJECT (treeview), "user-langs",
user_langs, (GDestroyNotify) g_hash_table_destroy);
timeout = g_idle_add ((GSourceFunc) finish_language_setup, treeview);
g_object_set_data (G_OBJECT (treeview), "timeout", GUINT_TO_POINTER (timeout));
g_object_weak_ref (G_OBJECT (treeview), (GWeakNotify) remove_timeout, GUINT_TO_POINTER (timeout));
}
......@@ -119,11 +119,20 @@
<property name="can_focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkTreeView" id="display_language_treeview">
<object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection"/>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="display_language_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection"/>
</child>
</object>
</child>
</object>
<packing>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment