gnome-panel r11022 - trunk/applets/clock



Author: vuntz
Date: Thu Apr 10 02:27:38 2008
New Revision: 11022
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=11022&view=rev

Log:
2008-04-10  Vincent Untz  <vuntz gnome org>

	Huge performance improvement when clicking "Add" for adding a location.
	Before this, the first click took around 0.2s and the following clicks
	took more than 0.8s (!!!). Now the first click takes less than 0.15s
	and the following clicks take around 0.007s. (put some James Bond music
	here)

	* clock.c: (revert_sort_zoneinfo_by_l10n_name): renamed from
	sort_zoneinfo_by_l10n_name() because it revert sorts.
	(fill_timezone_combo_from_location): be a bit more serious. First,
	let's not clear the combo box to add items again since the list of
	timezones never changes. Then don't append to the combo box, but
	prepend. There's no need to append.


Modified:
   trunk/applets/clock/ChangeLog
   trunk/applets/clock/clock.c

Modified: trunk/applets/clock/clock.c
==============================================================================
--- trunk/applets/clock/clock.c	(original)
+++ trunk/applets/clock/clock.c	Thu Apr 10 02:27:38 2008
@@ -3152,7 +3152,7 @@
 }
 
 static gint
-sort_zoneinfo_by_l10n_name (gconstpointer a, gconstpointer b)
+revert_sort_zoneinfo_by_l10n_name (gconstpointer a, gconstpointer b)
 {
         ClockZoneInfo *info_a = CLOCK_ZONEINFO (a);
         ClockZoneInfo *info_b = CLOCK_ZONEINFO (b);
@@ -3160,7 +3160,7 @@
         const char *name_a = clock_zoneinfo_get_l10n_name (info_a);
         const char *name_b = clock_zoneinfo_get_l10n_name (info_b);
 
-        return strcmp (name_a, name_b); /* FIXME: should this be g_utf8_collate() ? */
+        return strcmp (name_b, name_a); /* FIXME: should this be g_utf8_collate() ? */
 }
 
 static void
@@ -3170,7 +3170,6 @@
         GtkTreeModel *model;
         GtkTreeIter iter;
 
-        GList *list, *cur;
         int timezone_idx = -1;
         int i = 0;
 
@@ -3188,28 +3187,56 @@
         }
 
         model = gtk_combo_box_get_model (GTK_COMBO_BOX (zone_combo));
-        while (gtk_tree_model_get_iter_first (model, &iter)) {
-                gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
-        }
-
-        list = g_list_copy (clock_zonetable_get_zones (zones));
-        list = g_list_sort (list, &sort_zoneinfo_by_l10n_name);
-
-        cur = list;
-        while (cur) {
-                const gchar *timezone = clock_zoneinfo_get_l10n_name (CLOCK_ZONEINFO (cur->data));
 
-                gtk_combo_box_append_text (GTK_COMBO_BOX (zone_combo), timezone);
+	/* FIXME: not clearing the combo means if the list of timezones
+	 * changes, we won't have the right list. But right now, our list
+	 * will never change so it doesn't matter. */
+
+	/* Fill the combo if it's empty, and also remember the item that should
+	 * be selected if we have a location */
+	if (!gtk_tree_model_get_iter_first (model, &iter)) {
+		GList *list, *cur;
+		const gchar *timezone;
+
+		list = g_list_copy (clock_zonetable_get_zones (zones));
+		/* this is a revert sort because we prepend to the combo box */
+		list = g_list_sort (list, &revert_sort_zoneinfo_by_l10n_name);
+
+		cur = list;
+		while (cur) {
+			timezone = clock_zoneinfo_get_l10n_name (CLOCK_ZONEINFO (cur->data));
+
+			gtk_combo_box_prepend_text (GTK_COMBO_BOX (zone_combo),
+						    timezone);
+
+			if (loc_timezone && timezone_idx == -1
+			    && (strcmp (timezone, loc_timezone) == 0)) {
+				timezone_idx = i;
+			}
 
-                if (loc_timezone && (strcmp (timezone, loc_timezone) == 0)) {
-                        timezone_idx = i;
-                }
+			i++;
+			cur = g_list_next (cur);
+		}
 
-                i++;
-                cur = g_list_next (cur);
-        }
+		g_list_free (list);
+	} else if (loc_timezone) {
+		/* Find the item to select */
+		gchar *timezone;
+		int count = 0;
+
+		do {
+			gtk_tree_model_get (model, &iter, 0, &timezone, -1);
+
+			if (strcmp (timezone, loc_timezone) == 0) {
+				timezone_idx = count;
+				g_free (timezone);
+				break;
+			}
+			count++;
 
-        g_list_free (list);
+			g_free (timezone);
+		} while (gtk_tree_model_iter_next (model, &iter));
+	}
 
         if (timezone_idx >= 0) {
                 gtk_combo_box_set_active (GTK_COMBO_BOX (zone_combo), timezone_idx);



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