gnome-panel r11047 - trunk/applets/clock



Author: vuntz
Date: Thu Apr 10 17:25:30 2008
New Revision: 11047
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=11047&view=rev

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

	Do not create lots of new ClockLocation everytime we load the locations
	from gconf, and try to re-use the old ones.
	As a side-effect, it fixes a bug where you need to click twice on Set
	to set the current location from a different timezone.

	* clock-location.[ch]: (clock_location_find_and_ref): new, find a
	ClockLocation if it already exists, and ref it
	(clock_location_make_current): do not do anything if the location is
	already the current one
	* clock.c: (location_start_element): try to find the location among
	existing ones first, and then fallback on creating a new one
	(run_prefs_edit_save): do not explicitly call locations_changed(), it
	will be done later via gconf notification
	(remove_tree_row): ditto


Modified:
   trunk/applets/clock/ChangeLog
   trunk/applets/clock/clock-location.c
   trunk/applets/clock/clock-location.h
   trunk/applets/clock/clock.c

Modified: trunk/applets/clock/clock-location.c
==============================================================================
--- trunk/applets/clock/clock-location.c	(original)
+++ trunk/applets/clock/clock-location.c	Thu Apr 10 17:25:30 2008
@@ -67,6 +67,34 @@
 #define PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CLOCK_LOCATION_TYPE, ClockLocationPrivate))
 
 ClockLocation *
+clock_location_find_and_ref (GList       *locations,
+                             const gchar *name,
+                             const gchar *timezone,
+                             gfloat       latitude,
+                             gfloat       longitude,
+                             const gchar *code)
+{
+        GList *l;
+        ClockLocationPrivate *priv;
+
+        for (l = locations; l != NULL; l = l->next) {
+                priv = PRIVATE (l->data);
+
+                if (priv->latitude == latitude &&
+                    priv->longitude == longitude &&
+                    g_strcmp0 (priv->weather_code, code) == 0 &&
+                    g_strcmp0 (priv->timezone, timezone) == 0 &&
+                    g_strcmp0 (priv->name, name) == 0)
+                        break;
+        }
+
+        if (l != NULL)
+                return g_object_ref (CLOCK_LOCATION (l->data));
+        else
+                return NULL;
+}
+
+ClockLocation *
 clock_location_new (const gchar *name, const gchar *timezone,
 		    gfloat latitude, gfloat longitude,
 		    const gchar *code, WeatherPrefs *prefs)
@@ -467,6 +495,12 @@
         gchar *filename;
 	MakeCurrentData *mcdata;
 
+        if (loc == current_location) {
+                if (destroy)
+                        destroy (data);
+                return;
+        }
+
 	if (clock_location_is_current_timezone (loc)) {
 		if (current_location)
 			g_object_remove_weak_pointer (G_OBJECT (current_location), 

Modified: trunk/applets/clock/clock-location.h
==============================================================================
--- trunk/applets/clock/clock-location.h	(original)
+++ trunk/applets/clock/clock-location.h	Thu Apr 10 17:25:30 2008
@@ -38,6 +38,13 @@
 				   const gchar *code,
 				   WeatherPrefs *prefs);
 
+ClockLocation *clock_location_find_and_ref (GList       *locations,
+                                            const gchar *name,
+                                            const gchar *timezone,
+                                            gfloat       latitude,
+                                            gfloat       longitude,
+                                            const gchar *code);
+
 gchar *clock_location_get_tzname (ClockLocation *loc);
 
 const gchar *clock_location_get_name (ClockLocation *loc);

Modified: trunk/applets/clock/clock.c
==============================================================================
--- trunk/applets/clock/clock.c	(original)
+++ trunk/applets/clock/clock.c	Thu Apr 10 17:25:30 2008
@@ -2208,7 +2208,11 @@
                 return;
         }
 
-        loc = clock_location_new (name, timezone, latitude, longitude, code, &prefs);
+	loc = clock_location_find_and_ref (cd->locations, name, timezone,
+					   latitude, longitude, code);
+	if (!loc)
+		loc = clock_location_new (name, timezone,
+					  latitude, longitude, code, &prefs);
 
 	if (current && clock_location_is_current_timezone (loc))
 		clock_location_make_current (loc, NULL, NULL, NULL);
@@ -3087,9 +3091,10 @@
 		clock_location_is_current (loc);
 
                 cd->locations = g_list_append (cd->locations, loc);
-                locations_changed (cd);
         }
 
+	/* This will update everything related to locations to take into
+	 * account the new location (via the gconf notification) */
         save_cities_store (cd);
 
         edit_hide (edit_window, cd);
@@ -3828,12 +3833,11 @@
         ClockLocation *loc = NULL;
 
         gtk_tree_model_get (model, iter, COL_CITY_LOC, &loc, -1);
-
-        gtk_list_store_remove (cd->cities_store, iter);
 	cd->locations = g_list_remove (cd->locations, loc);
-	locations_changed (cd);
 	g_object_unref (loc);
 
+	/* This will update everything related to locations to take into
+	 * account the removed location (via the gconf notification) */
         save_cities_store (cd);
 }
 



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