[gnome-control-center] region: Redo the formats tab



commit 7720b989ea8d98a8feaa5bd55f028510668d3d3a
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 20 21:59:42 2011 -0400

    region: Redo the formats tab
    
    The big combo box is not very usable, so as a first improvement,
    move things around so that we can use a list on the left, and
    put the examples on the right.
    
    Also add a 'need logout' hint in the same style as on the
    language tab.

 panels/region/gnome-region-panel-formats.c |  168 ++++++++++++++++------
 panels/region/gnome-region-panel.ui        |  211 +++++++++++++++++----------
 2 files changed, 258 insertions(+), 121 deletions(-)
---
diff --git a/panels/region/gnome-region-panel-formats.c b/panels/region/gnome-region-panel-formats.c
index e2cbb4d..ebf56ff 100644
--- a/panels/region/gnome-region-panel-formats.c
+++ b/panels/region/gnome-region-panel-formats.c
@@ -31,8 +31,6 @@
 #include "gdm-languages.h"
 #include "gnome-region-panel-formats.h"
 
-static GSettings *locale_settings = NULL;
-
 static void
 display_date (GtkLabel *label, GDateTime *dt, const gchar *format)
 {
@@ -44,19 +42,56 @@ display_date (GtkLabel *label, GDateTime *dt, const gchar *format)
 }
 
 static void
-selection_changed_cb (GtkComboBox *combo, gpointer user_data)
+select_region (GtkTreeView *treeview, const gchar *lang)
+{
+        GtkTreeModel *model;
+        GtkTreeSelection *selection;
+        GtkTreeIter iter;
+        GtkTreePath *path;
+        gboolean cont;
+
+        model = gtk_tree_view_get_model (treeview);
+        selection = gtk_tree_view_get_selection (treeview);
+        cont = gtk_tree_model_get_iter_first (model, &iter);
+        while (cont) {
+                gchar *locale;
+
+                gtk_tree_model_get (model, &iter, 0, &locale, -1);
+                if (g_strcmp0 (locale, lang) == 0) {
+                        gtk_tree_selection_select_iter (selection, &iter);
+                        path = gtk_tree_model_get_path (model, &iter);
+                        gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.0, 0.0);
+                        gtk_tree_path_free (path);
+                        g_free (locale);
+                        break;
+                }
+                g_free (locale);
+
+                cont = gtk_tree_model_iter_next (model, &iter);
+        }
+}
+
+static void
+selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
 {
-	const gchar *active_id;
+	GtkBuilder *builder = GTK_BUILDER (user_data);
+        GtkTreeModel *model;
+        GtkTreeIter iter;
+        gchar *active_id;
 	gchar *locale;
 	GDateTime *dt;
 	gchar *s;
 	struct lconv *num_info;
-	GtkBuilder *builder = GTK_BUILDER (user_data);
 	const char *fmt;
+        GtkWidget *treeview;
+        GSettings *locale_settings;
+        gchar *current_setting;
+
+        if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
+                return;
+        }
 
-	active_id = gtk_combo_box_get_active_id (combo);
-	if (!active_id || !active_id[0])
-		return;
+        gtk_tree_model_get (model, &iter, 0, &active_id, -1);
 
 	locale = g_strdup (setlocale (LC_TIME, NULL));
 	setlocale (LC_TIME, active_id);
@@ -111,67 +146,114 @@ selection_changed_cb (GtkComboBox *combo, gpointer user_data)
 
 	setlocale (LC_MEASUREMENT, locale);
 	g_free (locale);
+
+	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");
+
+        if (g_strcmp0 (active_id, current_setting) != 0) {
+                g_settings_set_string (locale_settings, "region", active_id);
+        }
+
+        g_free (current_setting);
+        g_free (active_id);
+}
+
+static void
+setting_changed_cb (GSettings *locale_settings, gchar *key, GtkTreeView *treeview)
+{
+        gchar *current_setting;
+
+        current_setting = g_settings_get_string (locale_settings, "region");
+        select_region (treeview, current_setting);
+        g_free (current_setting);
+}
+
+static gint
+sort_regions (GtkTreeModel *model,
+              GtkTreeIter  *a,
+              GtkTreeIter  *b,
+              gpointer      data)
+{
+        gchar *la, *lb;
+        gint result;
+
+        gtk_tree_model_get (model, a, 1, &la, -1);
+        gtk_tree_model_get (model, b, 1, &lb, -1);
+
+        result = strcmp (la, lb);
+
+        g_free (la);
+        g_free (lb);
+
+        return result;
 }
 
 void
 setup_formats (GtkBuilder *builder)
 {
-	GtkWidget *combo;
+	GtkWidget *treeview;
 	gchar **langs, *language, *current_lang;
 	gint i;
+	GtkTreeModel *model;
+        GtkTreeIter iter;
+        GtkCellRenderer *cell;
+        GtkTreeViewColumn *column;
+        GtkWidget *widget;
+        GtkStyleContext *context;
+        GSettings *locale_settings;
 
 	locale_settings = g_settings_new ("org.gnome.system.locale");
 
+        /* Setup junction between toolbar and treeview */
+        widget = (GtkWidget *)gtk_builder_get_object (builder, "region-swindow");
+        context = gtk_widget_get_style_context (widget);
+        gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
+        widget = (GtkWidget *)gtk_builder_get_object (builder, "region-toolbar");
+        context = gtk_widget_get_style_context (widget);
+        gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
+
 	/* Setup formats selector */
-	combo = GTK_WIDGET (gtk_builder_get_object (builder, "region_selector"));
-	gtk_combo_box_set_id_column (GTK_COMBO_BOX (combo), 1);
+	treeview = GTK_WIDGET (gtk_builder_get_object (builder, "region_selector"));
+        cell = gtk_cell_renderer_text_new ();
+        g_object_set (cell,
+                      "width-chars", 40,
+                      "ellipsize", PANGO_ELLIPSIZE_END,
+                      NULL);
+        column = gtk_tree_view_column_new_with_attributes (NULL, cell, "text", 1, NULL);
+        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+        model = (GtkTreeModel*)gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
+        gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (model),
+                                                 sort_regions, NULL, NULL);
+        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
+                                              GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
+                                              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++) {
-		GtkTreeModel *model;
-		GtkTreeIter iter;
-		gint row = 0;
 
 		language = gdm_get_language_from_name (langs[i], NULL);
-
-		/* Sort while adding */
-		model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-		if (gtk_tree_model_get_iter_first (model, &iter)) {
-			gboolean added = FALSE;
-
-			do {
-				gchar *iter_s;
-
-				gtk_tree_model_get (model, &iter, 0, &iter_s, -1);
-				if (g_strcmp0 (language, iter_s) < 0) {
-					gtk_combo_box_text_insert (GTK_COMBO_BOX_TEXT (combo), row,
-								   langs[i], language);
-					added = TRUE;
-					break;
-				}
-
-				row++;
-			} while (gtk_tree_model_iter_next (model, &iter));
-
-			if (!added)
-				gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), langs[i], language);
-		} else
-			gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), langs[i], language);
+                
+                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_signal_connect (G_OBJECT (combo), "changed",
+        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);
 
 	current_lang = g_settings_get_string (locale_settings, "region");
 	if (!current_lang || !current_lang[0])
 		current_lang = cc_common_language_get_current_language ();
 
-	gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo), current_lang);
+	select_region (GTK_TREE_VIEW (treeview), current_lang);
 	g_free (current_lang);
 
-	g_object_weak_ref (G_OBJECT (combo), (GWeakNotify) g_object_unref, locale_settings);
-	g_settings_bind (locale_settings, "region", combo, "active-id", G_SETTINGS_BIND_DEFAULT);
+        g_signal_connect (locale_settings, "changed::region",
+                          G_CALLBACK (setting_changed_cb), treeview);
 }
diff --git a/panels/region/gnome-region-panel.ui b/panels/region/gnome-region-panel.ui
index 5a20b21..bfea7cd 100644
--- a/panels/region/gnome-region-panel.ui
+++ b/panels/region/gnome-region-panel.ui
@@ -109,7 +109,7 @@
                   <object class="GtkVBox" id="vbox2">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="border_width">10</property>
+                    <property name="border_width">12</property>
                     <property name="spacing">12</property>
                     <child>
                       <object class="GtkLabel" id="label4">
@@ -141,7 +141,7 @@
                                 <property name="can_focus">True</property>
                                 <property name="headers_visible">False</property>
                                 <child internal-child="selection">
-                                  <object class="GtkTreeSelection" id="treeview-selection"/>
+                                  <object class="GtkTreeSelection" id="language-treeview-selection"/>
                                 </child>
                               </object>
                             </child>
@@ -153,76 +153,78 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkToolbar" id="language-toolbar">
-                            <property name="visible">True</property>
+                          <object class="GtkVBox" id="vbox3">
                             <property name="can_focus">False</property>
-                            <property name="show_arrow">False</property>
-                            <property name="icon_size">1</property>
-                            <property name="toolbar-style">icons</property>
-                            <style>
-                              <class name="inline-toolbar"/>
-                            </style>
                             <child>
-                              <object class="GtkToolButton" id="language_add">
+                              <object class="GtkLabel" id="label23">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="use_action_appearance">False</property>
-                                <property name="use_underline">True</property>
-                                <property name="icon_name">list-add-symbolic</property>
                               </object>
                               <packing>
-                                <property name="expand">False</property>
-                                <property name="homogeneous">True</property>
+                                <property name="expand">True</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkToolButton" id="language_remove">
+                              <object class="GtkLinkButton" id="linkbutton1">
+                                <property name="label" translatable="yes">Install languages...</property>
                                 <property name="visible">True</property>
-                                <property name="can_focus">False</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="has_tooltip">True</property>
                                 <property name="use_action_appearance">False</property>
-                                <property name="use_underline">True</property>
-                                <property name="icon_name">list-remove-symbolic</property>
-                                <property name="sensitive">False</property>
+                                <property name="relief">none</property>
+                                <property name="uri">http://glade.gnome.org</property>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
-                                <property name="homogeneous">True</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
                               </packing>
                             </child>
                           </object>
                           <packing>
+                            <property name="expand">False</property>
                             <property name="fill">True</property>
+                            <property name="position">1</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkVBox" id="vbox3">
+                          <object class="GtkToolbar" id="language-toolbar">
+                            <property name="visible">True</property>
                             <property name="can_focus">False</property>
+                            <property name="toolbar_style">icons</property>
+                            <property name="show_arrow">False</property>
+                            <property name="icon_size">1</property>
+                            <style>
+                              <class name="inline-toolbar"/>
+                            </style>
                             <child>
-                              <object class="GtkLabel" id="label23">
+                              <object class="GtkToolButton" id="language_add">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
+                                <property name="use_action_appearance">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="icon_name">list-add-symbolic</property>
                               </object>
                               <packing>
-                                <property name="expand">True</property>
-                                <property name="fill">True</property>
-                                <property name="position">0</property>
+                                <property name="expand">False</property>
+                                <property name="homogeneous">True</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkLinkButton" id="linkbutton1">
-                                <property name="label" translatable="yes">Install languages...</property>
+                              <object class="GtkToolButton" id="language_remove">
                                 <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="receives_default">True</property>
-                                <property name="has_tooltip">True</property>
+                                <property name="sensitive">False</property>
+                                <property name="can_focus">False</property>
                                 <property name="use_action_appearance">False</property>
-                                <property name="relief">none</property>
-                                <property name="uri">http://glade.gnome.org</property>
+                                <property name="use_underline">True</property>
+                                <property name="icon_name">list-remove-symbolic</property>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
-                                <property name="fill">True</property>
-                                <property name="position">1</property>
+                                <property name="homogeneous">True</property>
                               </packing>
                             </child>
                           </object>
@@ -252,24 +254,107 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkTable" id="table1">
+                  <object class="GtkGrid" id="table1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="n_rows">2</property>
-                    <property name="n_columns">2</property>
                     <property name="column_spacing">12</property>
-                    <property name="row_spacing">12</property>
+                    <property name="row_spacing">6</property>
+                    <property name="margin_top">12</property>
+                    <property name="margin_bottom">12</property>
+                    <property name="margin_left">12</property>
+                    <property name="margin_right">12</property>
                     <child>
                       <object class="GtkLabel" id="label5">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Region:</property>
+                        <property name="halign">start</property>
+                        <property name="label" translatable="yes">Select a region (change will be applied the next time you log in)</property>
                       </object>
                       <packing>
-                        <property name="x_options">GTK_SHRINK</property>
-                        <property name="y_options">GTK_FILL</property>
-                        <property name="x_padding">12</property>
-                        <property name="y_padding">12</property>
+                        <property name="left-attach">0</property>
+                        <property name="top-attach">0</property>
+                        <property name="width">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkBox" id="region-box">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
+                        <child>
+                      <object class="GtkScrolledWindow" id="region-swindow">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hscrollbar_policy">never</property>
+                        <property name="shadow_type">in</property>
+                        <property name="halign">fill</property>
+                        <property name="valign">fill</property>
+                        <property name="vexpand">True</property>
+                        <child>
+                          <object class="GtkTreeView" id="region_selector">
+                            <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="region-treeview-selection"/>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                        <packing>
+                          <property name="expand">True</property>
+                          <property name="fill">True</property>
+                          <property name="position">0</property>
+                        </packing>
+                        </child>
+                      <child>
+                        <object class="GtkToolbar" id="region-toolbar">
+                        <property name="visible">False</property>
+                        <property name="can_focus">False</property>
+                        <property name="toolbar_style">icons</property>
+                        <property name="show_arrow">False</property>
+                        <property name="icon_size">1</property>
+                        <style>
+                          <class name="inline-toolbar"/>
+                        </style>
+                        <child>
+                          <object class="GtkToolButton" id="region_add">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="use_action_appearance">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="icon_name">list-add-symbolic</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="homogeneous">True</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkToolButton" id="region_remove">
+                            <property name="visible">True</property>
+                            <property name="sensitive">False</property>
+                            <property name="can_focus">False</property>
+                            <property name="use_action_appearance">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="icon_name">list-remove-symbolic</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="homogeneous">True</property>
+                          </packing>
+                        </child>
+                      </object>
+                        <packing>
+                          <property name="expand">False</property>
+                          <property name="fill">True</property>
+                          <property name="position">1</property>
+                        </packing>
+                    </child>
+
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">1</property>
                       </packing>
                     </child>
                     <child>
@@ -509,18 +594,6 @@
                                     <property name="y_padding">3</property>
                                   </packing>
                                 </child>
-                                <child>
-                                  <placeholder/>
-                                </child>
-                                <child>
-                                  <placeholder/>
-                                </child>
-                                <child>
-                                  <placeholder/>
-                                </child>
-                                <child>
-                                  <placeholder/>
-                                </child>
                               </object>
                             </child>
                           </object>
@@ -529,7 +602,7 @@
                           <object class="GtkLabel" id="label6">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="label" translatable="yes">Example</property>
+                            <property name="label" translatable="yes">Examples</property>
                             <attributes>
                               <attribute name="weight" value="bold"/>
                             </attributes>
@@ -537,26 +610,8 @@
                         </child>
                       </object>
                       <packing>
-                        <property name="right_attach">2</property>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
-                        <property name="x_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
-                        <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
-                        <property name="x_padding">12</property>
-                        <property name="y_padding">3</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkComboBoxText" id="region_selector">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                      <packing>
                         <property name="left_attach">1</property>
-                        <property name="right_attach">2</property>
-                        <property name="y_options">GTK_FILL</property>
-                        <property name="x_padding">12</property>
-                        <property name="y_padding">12</property>
+                        <property name="top_attach">1</property>
                       </packing>
                     </child>
                   </object>
@@ -619,9 +674,9 @@
                               <object class="GtkToolbar" id="layouts-toolbar">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
+                                <property name="toolbar_style">icons</property>
                                 <property name="show_arrow">False</property>
                                 <property name="icon_size">1</property>
-                                <property name="toolbar-style">icons</property>
                                 <style>
                                   <class name="inline-toolbar"/>
                                 </style>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]