[gnome-control-center] user: Add a filter entry to the language dialog
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] user: Add a filter entry to the language dialog
- Date: Mon, 22 Aug 2011 18:30:37 +0000 (UTC)
commit eaec9ce36274d99ad4c6bf4244e1b38a734c29a1
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 20 01:34:28 2011 -0400
user: Add a filter entry to the language dialog
This makes the dialog more similar to the layout add dialog
in the region panel, where we want to use it eventually as
well.
panels/user-accounts/data/language-chooser.ui | 57 ++++++++++-----
panels/user-accounts/um-language-dialog.c | 95 ++++++++++++++++++++++++-
panels/user-accounts/um-language-dialog.h | 1 +
panels/user-accounts/um-user-panel.c | 1 +
4 files changed, 134 insertions(+), 20 deletions(-)
---
diff --git a/panels/user-accounts/data/language-chooser.ui b/panels/user-accounts/data/language-chooser.ui
index 56ed8be..5e635c3 100644
--- a/panels/user-accounts/data/language-chooser.ui
+++ b/panels/user-accounts/data/language-chooser.ui
@@ -12,38 +12,57 @@
<object class="GtkBox" id="content-area">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="spacing">2</property>
+ <property name="spacing">6</property>
+ <property name="margin_left">10</property>
+ <property name="margin_right">10</property>
<child>
- <object class="GtkAlignment" id="alignment1">
+ <object class="GtkLabel" id="title">
<property name="visible">True</property>
- <property name="top_padding">10</property>
- <property name="bottom_padding">10</property>
- <property name="left_padding">10</property>
- <property name="right_padding">10</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Select a language</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">never</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <property name="shadow_type">in</property>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <object class="GtkTreeView" id="language-list">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="hscrollbar_policy">never</property>
- <property name="vscrollbar_policy">automatic</property>
- <property name="shadow_type">in</property>
- <child>
- <object class="GtkTreeView" id="language-list">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="headers_visible">False</property>
- <property name="headers_clickable">False</property>
- </object>
- </child>
+ <property name="headers_visible">False</property>
+ <property name="headers_clickable">False</property>
</object>
</child>
</object>
<packing>
- <property name="position">1</property>
+ <property name="position">2</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
+ <child>
+ <object class="GtkEntry" id="filter-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="secondary_icon_name">edit-find-symbolic</property>
+ <property name="secondary_icon_activatable">False</property>
+ <property name="secondary_icon_sensitive">False</property>
+ </object>
+ <packing>
+ <property name="position">3</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
<child internal-child="action_area">
<object class="GtkButtonBox" id="action-area">
<property name="visible">True</property>
diff --git a/panels/user-accounts/um-language-dialog.c b/panels/user-accounts/um-language-dialog.c
index fb87ab8..72217a0 100644
--- a/panels/user-accounts/um-language-dialog.c
+++ b/panels/user-accounts/um-language-dialog.c
@@ -55,6 +55,15 @@ um_language_chooser_get_language (GtkWidget *chooser)
return lang;
}
+void
+um_language_chooser_clear_filter (GtkWidget *chooser)
+{
+ GtkEntry *entry;
+
+ entry = (GtkEntry *) g_object_get_data (G_OBJECT (chooser), "filter-entry");
+ gtk_entry_set_text (entry, "");
+}
+
static void
row_activated (GtkTreeView *tree_view,
GtkTreePath *path,
@@ -198,6 +207,7 @@ finish_um_language_chooser (gpointer user_data)
list = g_object_get_data (G_OBJECT (chooser), "list");
model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
user_langs = g_object_get_data (G_OBJECT (chooser), "user-langs");
async_id = cc_common_language_add_available_languages (GTK_LIST_STORE (model), user_langs);
@@ -216,6 +226,74 @@ finish_um_language_chooser (gpointer user_data)
return FALSE;
}
+static void
+filter_clear (GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, gpointer user_data)
+{
+ gtk_entry_set_text (entry, "");
+}
+
+static void
+filter_changed (GtkWidget *entry, GParamSpec *pspec, GtkWidget *list)
+{
+ const gchar *pattern;
+ GtkTreeModel *filter_model;
+ GtkTreeModel *model;
+
+ pattern = gtk_entry_get_text (GTK_ENTRY (entry));
+
+ filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
+
+ if (g_strcmp0 (pattern, "") == 0) {
+ g_object_set (G_OBJECT (entry),
+ "secondary-icon-name", "edit-find-symbolic",
+ "secondary-icon-activatable", FALSE,
+ "secondary-icon-sensitive", FALSE,
+ NULL);
+
+ g_object_set_data_full (G_OBJECT (model), "filter-string",
+ g_strdup (""), g_free);
+
+ } else {
+ g_object_set (G_OBJECT (entry),
+ "secondary-icon-name", "edit-clear-symbolic",
+ "secondary-icon-activatable", TRUE,
+ "secondary-icon-sensitive", TRUE,
+ NULL);
+
+ g_object_set_data_full (G_OBJECT (model), "filter-string",
+ g_utf8_casefold (pattern, -1), g_free);
+ }
+
+ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
+}
+
+static gboolean
+filter_languages (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ const gchar *filter_string;
+ gchar *locale, *l;
+ gboolean visible;
+
+ filter_string = g_object_get_data (G_OBJECT (model), "filter-string");
+
+ if (filter_string == NULL) {
+ return TRUE;
+ }
+
+ gtk_tree_model_get (model, iter, DISPLAY_LOCALE_COL, &locale, -1);
+ l = g_utf8_casefold (locale, -1);
+
+ visible = strstr (l, filter_string) != NULL;
+
+ g_free (locale);
+ g_free (l);
+
+ return visible;
+}
+
GtkWidget *
um_language_chooser_new (GtkWidget *parent)
{
@@ -225,9 +303,12 @@ um_language_chooser_new (GtkWidget *parent)
GtkWidget *chooser;
GtkWidget *list;
GtkWidget *button;
+ GtkWidget *entry;
GHashTable *user_langs;
GdkCursor *cursor;
guint timeout;
+ GtkTreeModel *model;
+ GtkTreeModel *filter_model;
builder = gtk_builder_new ();
filename = UIDIR "/language-chooser.ui";
@@ -249,10 +330,23 @@ um_language_chooser_new (GtkWidget *parent)
button = (GtkWidget *) gtk_builder_get_object (builder, "ok-button");
gtk_widget_grab_default (button);
+ entry = (GtkWidget *) gtk_builder_get_object (builder, "filter-entry");
+ g_object_set_data (G_OBJECT (chooser), "filter-entry", entry);
+ g_signal_connect (entry, "notify::text",
+ G_CALLBACK (filter_changed), list);
+ g_signal_connect (entry, "icon-release",
+ G_CALLBACK (filter_clear), NULL);
+
/* Add user languages */
user_langs = new_ht_for_user_languages ();
cc_common_language_setup_list (list, user_langs);
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
+ filter_model = gtk_tree_model_filter_new (model, NULL);
+ gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model), filter_languages,
+ NULL, NULL);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (list), filter_model);
+
/* Setup so that the list is added after the dialogue is shown */
cursor = gdk_cursor_new (GDK_WATCH);
gdk_window_set_cursor (gtk_widget_get_window (parent), cursor);
@@ -268,4 +362,3 @@ um_language_chooser_new (GtkWidget *parent)
return chooser;
}
-
diff --git a/panels/user-accounts/um-language-dialog.h b/panels/user-accounts/um-language-dialog.h
index 740cbfc..9b476e3 100644
--- a/panels/user-accounts/um-language-dialog.h
+++ b/panels/user-accounts/um-language-dialog.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
void um_add_user_languages (GtkTreeModel *model);
GtkWidget *um_language_chooser_new (GtkWidget *parent);
+void um_language_chooser_clear_filter (GtkWidget *chooser);
gchar *um_language_chooser_get_language (GtkWidget *chooser);
G_END_DECLS
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index d16d58d..4510924 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -714,6 +714,7 @@ language_changed (UmEditableCombo *combo,
}
if (d->language_chooser) {
+ um_language_chooser_clear_filter (d->language_chooser);
gtk_window_present (GTK_WINDOW (d->language_chooser));
gtk_widget_set_sensitive (GTK_WIDGET (combo), FALSE);
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]