[gnome-control-center] region: show fewer regions
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] region: show fewer regions
- Date: Mon, 22 Aug 2011 18:31:17 +0000 (UTC)
commit 68c7654dfb37e39e9bfc7997777bebfefb9b711b
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Aug 22 13:51:27 2011 -0400
region: show fewer regions
Rework the region list to only show regions 'matching' the current
language, and add a region chooser dialog that offers the full set.
panels/region/gnome-region-panel-formats.c | 184 +++++++++++++++++++++++-----
panels/region/gnome-region-panel-formats.h | 2 +
panels/region/gnome-region-panel-lang.c | 9 +-
panels/region/gnome-region-panel-system.c | 23 ++--
panels/region/gnome-region-panel.ui | 2 +-
5 files changed, 177 insertions(+), 43 deletions(-)
---
diff --git a/panels/region/gnome-region-panel-formats.c b/panels/region/gnome-region-panel-formats.c
index 1eb6724..ed88624 100644
--- a/panels/region/gnome-region-panel-formats.c
+++ b/panels/region/gnome-region-panel-formats.c
@@ -28,6 +28,7 @@
#include <langinfo.h>
#include <stdlib.h>
#include "cc-common-language.h"
+#include "cc-language-chooser.h"
#include "gdm-languages.h"
#include "gnome-region-panel-formats.h"
@@ -72,7 +73,7 @@ select_region (GtkTreeView *treeview, const gchar *lang)
}
static void
-selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
+update_examples_cb (GtkTreeSelection *selection, gpointer user_data)
{
GtkBuilder *builder = GTK_BUILDER (user_data);
GtkTreeModel *model;
@@ -83,18 +84,14 @@ selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
gchar *s;
struct lconv *num_info;
const char *fmt;
- GtkWidget *treeview;
- GSettings *locale_settings;
- gchar *current_setting;
if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
return;
}
-
gtk_tree_model_get (model, &iter, 0, &active_id, -1);
locale = g_strdup (setlocale (LC_TIME, NULL));
- setlocale (LC_TIME, active_id);
+ setlocale (LC_TIME, active_id);
dt = g_date_time_new_now_local ();
@@ -103,7 +100,7 @@ selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
display_date (GTK_LABEL (gtk_builder_get_object (builder, "full_day_format")), dt, "%e %B %Y");
display_date (GTK_LABEL (gtk_builder_get_object (builder, "short_day_format")), dt, "%e %b %Y");
display_date (GTK_LABEL (gtk_builder_get_object (builder, "shortest_day_format")), dt, "%x");
-
+
/* Display times */
display_date (GTK_LABEL (gtk_builder_get_object (builder, "full_time_format")), dt, "%r %Z");
display_date (GTK_LABEL (gtk_builder_get_object (builder, "short_time_format")), dt, "%X");
@@ -146,10 +143,30 @@ selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
setlocale (LC_MEASUREMENT, locale);
g_free (locale);
+ g_free (active_id);
+}
+
+
+static void
+update_settings_cb (GtkTreeSelection *selection, gpointer user_data)
+{
+ GtkBuilder *builder = GTK_BUILDER (user_data);
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gchar *active_id;
+ GtkWidget *treeview;
+ GSettings *locale_settings;
+ gchar *current_setting;
+
+ if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
+ return;
+ }
+ gtk_tree_model_get (model, &iter, 0, &active_id, -1);
+
+ treeview = GTK_WIDGET (gtk_builder_get_object (builder, "region_selector"));
- treeview = GTK_WIDGET (gtk_builder_get_object (builder, "region_selector"));
locale_settings = g_object_get_data (G_OBJECT (treeview), "settings");
- current_setting = g_settings_get_string (locale_settings, "region");
+ current_setting = g_settings_get_string (locale_settings, "region");
if (g_strcmp0 (active_id, current_setting) != 0) {
g_settings_set_string (locale_settings, "region", active_id);
@@ -189,19 +206,126 @@ sort_regions (GtkTreeModel *model,
return result;
}
+static void
+populate_regions (GtkBuilder *builder, const gchar *current_lang)
+{
+ gchar *current_region;
+ GSettings *locale_settings;
+ GHashTable *ht;
+ GHashTableIter htiter;
+ GtkTreeModel *model;
+ gchar *name, *language;
+ GtkWidget *treeview;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
+
+ treeview = GTK_WIDGET (gtk_builder_get_object (builder, "region_selector"));
+ /* don't update the setting just because the list is repopulated */
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+ g_signal_handlers_block_by_func (selection, update_settings_cb, builder);
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
+ locale_settings = g_object_get_data (G_OBJECT (treeview), "settings");
+
+ ht = cc_common_language_get_initial_regions (current_lang);
+
+ current_region = g_settings_get_string (locale_settings, "region");
+ if (!current_region || !current_region[0]) {
+ current_region = g_strdup (current_lang);
+ }
+ else if (!g_hash_table_lookup (ht, current_region)) {
+ name = gdm_get_region_from_name (current_region, NULL);
+ g_hash_table_insert (ht, g_strdup (current_region), name);
+ }
+
+ gtk_list_store_clear (GTK_LIST_STORE (model));
+
+ g_hash_table_iter_init (&htiter, ht);
+ while (g_hash_table_iter_next (&htiter, (gpointer *)&name, (gpointer *)&language)) {
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, name, 1, language, -1);
+ }
+ g_hash_table_unref (ht);
+
+ select_region (GTK_TREE_VIEW (treeview), current_region);
+
+ g_free (current_region);
+
+ g_signal_handlers_unblock_by_func (selection, update_settings_cb, builder);
+}
+
+static void
+region_response (GtkDialog *dialog,
+ gint response_id,
+ GtkWidget *treeview)
+{
+ gchar *lang;
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+
+ gtk_widget_hide (GTK_WIDGET (dialog));
+
+ if (response_id != GTK_RESPONSE_OK) {
+ return;
+ }
+
+ lang = cc_language_chooser_get_language (GTK_WIDGET (dialog));
+
+ if (lang == NULL) {
+ return;
+ }
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+
+ if (cc_common_language_get_iter_for_region (model, lang, &iter)) {
+ gtk_tree_selection_select_iter (selection, &iter);
+ }
+
+ gtk_widget_grab_focus (treeview);
+
+ g_free (lang);
+}
+
+static void
+add_region (GtkWidget *button, GtkWidget *treeview)
+{
+ GtkWidget *toplevel;
+ GtkWidget *chooser;
+
+ toplevel = gtk_widget_get_toplevel (button);
+ chooser = g_object_get_data (G_OBJECT (button), "chooser");
+ if (chooser == NULL) {
+ chooser = cc_language_chooser_new (toplevel, TRUE);
+
+ g_signal_connect (chooser, "response",
+ G_CALLBACK (region_response), treeview);
+ g_signal_connect (chooser, "delete-event",
+ G_CALLBACK (gtk_widget_hide_on_delete), NULL);
+
+ g_object_set_data_full (G_OBJECT (button), "chooser",
+ chooser, (GDestroyNotify)gtk_widget_destroy);
+ }
+ else {
+ cc_language_chooser_clear_filter (chooser);
+ }
+
+ gdk_window_set_cursor (gtk_widget_get_window (toplevel), NULL);
+ gtk_window_present (GTK_WINDOW (chooser));
+}
+
void
setup_formats (GtkBuilder *builder)
{
GtkWidget *treeview;
- gchar **langs, *language, *current_lang;
- gint i;
+ gchar *current_lang;
GtkTreeModel *model;
- GtkTreeIter iter;
GtkCellRenderer *cell;
GtkTreeViewColumn *column;
GtkWidget *widget;
GtkStyleContext *context;
GSettings *locale_settings;
+ GtkTreeSelection *selection;
locale_settings = g_settings_new ("org.gnome.system.locale");
@@ -231,29 +355,31 @@ setup_formats (GtkBuilder *builder)
GTK_SORT_ASCENDING);
gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), model);
- langs = gdm_get_all_language_names ();
- for (i = 0; langs[i] != NULL; i++) {
-
- language = gdm_get_region_from_name (langs[i], NULL);
-
- gtk_list_store_append (GTK_LIST_STORE (model), &iter);
- gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, langs[i], 1, language, -1);
-
- g_free (language);
- }
-
g_object_set_data_full (G_OBJECT (treeview), "settings", locale_settings, g_object_unref);
- g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview))), "changed",
- G_CALLBACK (selection_changed_cb), builder);
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+ g_signal_connect (selection, "changed",
+ G_CALLBACK (update_settings_cb), builder);
+ g_signal_connect (selection, "changed",
+ G_CALLBACK (update_examples_cb), builder);
- current_lang = g_settings_get_string (locale_settings, "region");
- if (!current_lang || !current_lang[0])
- current_lang = cc_common_language_get_current_language ();
+ /* Connect buttons */
+ widget = (GtkWidget *)gtk_builder_get_object (builder, "region_add");
+ g_signal_connect (widget, "clicked",
+ G_CALLBACK (add_region), treeview);
- select_region (GTK_TREE_VIEW (treeview), current_lang);
+ current_lang = cc_common_language_get_current_language ();
+ populate_regions (builder, current_lang);
g_free (current_lang);
g_signal_connect (locale_settings, "changed::region",
G_CALLBACK (setting_changed_cb), treeview);
}
+
+void
+formats_update_language (GtkBuilder *builder,
+ const gchar *language)
+{
+ populate_regions (builder, language);
+}
+
diff --git a/panels/region/gnome-region-panel-formats.h b/panels/region/gnome-region-panel-formats.h
index 91200da..6ba1176 100644
--- a/panels/region/gnome-region-panel-formats.h
+++ b/panels/region/gnome-region-panel-formats.h
@@ -25,5 +25,7 @@
#include <gtk/gtk.h>
void setup_formats (GtkBuilder *builder);
+void formats_update_language (GtkBuilder *builder,
+ const gchar *language);
#endif
diff --git a/panels/region/gnome-region-panel-lang.c b/panels/region/gnome-region-panel-lang.c
index 8ba0e39..ef31a05 100644
--- a/panels/region/gnome-region-panel-lang.c
+++ b/panels/region/gnome-region-panel-lang.c
@@ -27,6 +27,7 @@
#include <glib/gi18n.h>
#include "gnome-region-panel-lang.h"
+#include "gnome-region-panel-formats.h"
#include "cc-common-language.h"
#include "cc-language-chooser.h"
#include "gdm-languages.h"
@@ -35,7 +36,7 @@ static GDBusProxy *proxy = NULL;
static void
selection_changed (GtkTreeSelection *selection,
- GtkTreeView *list)
+ GtkBuilder *builder)
{
GtkTreeModel *model;
GtkTreeIter iter;
@@ -108,6 +109,10 @@ selection_changed (GtkTreeSelection *selection,
goto bail;
}
+ /* Update the list of regions in the other tab */
+
+ formats_update_language (builder, locale);
+
/* And done */
bail:
@@ -231,7 +236,7 @@ setup_language (GtkBuilder *builder)
/* And now listen for changes */
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
g_signal_connect (G_OBJECT (selection), "changed",
- G_CALLBACK (selection_changed), treeview);
+ G_CALLBACK (selection_changed), builder);
gtk_widget_grab_focus (treeview);
}
diff --git a/panels/region/gnome-region-panel-system.c b/panels/region/gnome-region-panel-system.c
index 197ffb7..8670f68 100644
--- a/panels/region/gnome-region-panel-system.c
+++ b/panels/region/gnome-region-panel-system.c
@@ -36,17 +36,18 @@ locale_settings_changed (GSettings *settings,
const gchar *key,
gpointer user_data)
{
- gchar *language, *display_language;
- GtkBuilder *builder = GTK_BUILDER (user_data);
-
- if (g_str_equal (key, "region")) {
- language = g_settings_get_string (locale_settings, "region");
- display_language = gdm_get_language_from_name (language, NULL);
- gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (builder, "user_format")),
- display_language);
- g_free (language);
- g_free (display_language);
- }
+ GtkBuilder *builder = GTK_BUILDER (user_data);
+ GtkWidget *label;
+ gchar *region, *display_region;
+
+ region = g_settings_get_string (locale_settings, "region");
+ if (!region || !region[0])
+ region = cc_common_language_get_current_language ();
+ display_region = gdm_get_language_from_name (region, NULL);
+ label = GTK_WIDGET (gtk_builder_get_object (builder, "user_format"));
+ gtk_label_set_text (GTK_LABEL (label), display_region);
+ g_free (region);
+ g_free (display_region);
}
static void
@@ -86,7 +87,7 @@ setup_system (GtkBuilder *builder)
gchar *language, *display_language;
locale_settings = g_settings_new ("org.gnome.system.locale");
- g_signal_connect (locale_settings, "changed",
+ g_signal_connect (locale_settings, "changed::region",
G_CALLBACK (locale_settings_changed), builder);
g_object_weak_ref (G_OBJECT (builder), (GWeakNotify) g_object_unref, locale_settings);
diff --git a/panels/region/gnome-region-panel.ui b/panels/region/gnome-region-panel.ui
index bfea7cd..c2080b9 100644
--- a/panels/region/gnome-region-panel.ui
+++ b/panels/region/gnome-region-panel.ui
@@ -308,7 +308,7 @@
</child>
<child>
<object class="GtkToolbar" id="region-toolbar">
- <property name="visible">False</property>
+ <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="toolbar_style">icons</property>
<property name="show_arrow">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]