gnome-panel r10993 - trunk/applets/clock



Author: vuntz
Date: Mon Apr  7 19:57:22 2008
New Revision: 10993
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=10993&view=rev

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

	Don't lose weather code when editing a location and changing the
	timezone. Fix bug #522007

	* clock.c: (update_coords_helper): new, from code of update_coords
	(update_coords): updated to use update_coords_helper
	(zone_combo_changed): be a bit more clever and only update fields of
	the window if we have to guess them from the timezone
	(edit_tree_row): set weather-code on the window so that it's saved


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	Mon Apr  7 19:57:22 2008
@@ -3071,13 +3071,28 @@
 }
 
 static void
+update_coords_helper (gfloat value, GtkWidget *entry, GtkWidget *combo)
+{
+        gchar *tmp;
+
+        tmp = g_strdup_printf ("%f", fabsf (value));
+        gtk_entry_set_text (GTK_ENTRY (entry), tmp);
+        g_free (tmp);
+
+        if (value > 0) {
+                gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+        } else {
+                gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
+        }
+}
+
+static void
 update_coords (ClockData *cd, gboolean valid, gfloat lat, gfloat lon)
 {
         GtkWidget *lat_entry = glade_xml_get_widget (cd->glade_xml, "edit-location-latitude-entry");
         GtkWidget *lon_entry = glade_xml_get_widget (cd->glade_xml, "edit-location-longitude-entry");
         GtkWidget *lat_combo = glade_xml_get_widget (cd->glade_xml, "edit-location-latitude-combo");
         GtkWidget *lon_combo = glade_xml_get_widget (cd->glade_xml, "edit-location-longitude-combo");
-        gchar *tmp;
 
 	if (!valid) {
         	gtk_entry_set_text (GTK_ENTRY (lat_entry), "");
@@ -3088,25 +3103,8 @@
 		return;
 	}
 
-        tmp = g_strdup_printf ("%f", fabsf(lat));
-        gtk_entry_set_text (GTK_ENTRY (lat_entry), tmp);
-        g_free (tmp);
-
-        if (lat > 0) {
-                gtk_combo_box_set_active (GTK_COMBO_BOX (lat_combo), 0);
-        } else {
-                gtk_combo_box_set_active (GTK_COMBO_BOX (lat_combo), 1);
-        }
-
-        tmp = g_strdup_printf ("%f", fabsf(lon));
-        gtk_entry_set_text (GTK_ENTRY (lon_entry), tmp);
-        g_free (tmp);
-
-        if (lon > 0) {
-                gtk_combo_box_set_active (GTK_COMBO_BOX (lon_combo), 0);
-        } else {
-                gtk_combo_box_set_active (GTK_COMBO_BOX (lon_combo), 1);
-        }
+	update_coords_helper (lat, lat_entry, lat_combo);
+	update_coords_helper (lon, lon_entry, lon_combo);
 }
 
 static gint
@@ -3652,14 +3650,16 @@
 zone_combo_changed (GtkComboBox *widget, ClockData *cd)
 {
         ClockZoneTable *zones = cd->zones;
-        gchar *timezone = gtk_combo_box_get_active_text (widget);
-        gchar *city = NULL;
+        gchar *timezone;
         gfloat lat = 0;
         gfloat lon = 0;
 	GtkTreeModel *model;
-	const gchar *name;
+	gchar *city;
+	const gchar *buffer;
 
         GtkWidget *name_entry = glade_xml_get_widget (cd->glade_xml, "edit-location-name-entry");
+        GtkWidget *lat_entry = glade_xml_get_widget (cd->glade_xml, "edit-location-latitude-entry");
+        GtkWidget *lon_entry = glade_xml_get_widget (cd->glade_xml, "edit-location-longitude-entry");
         GtkWidget *edit_window = glade_xml_get_widget (cd->glade_xml, "edit-location-window");
 	gchar *weather_code;
 
@@ -3670,14 +3670,7 @@
                 return;
         }
 
-	/* only fill in other field if name is not set yet, to
-         * allow correcting a guessed timezone
-         */
-	name = gtk_entry_get_text (GTK_ENTRY (name_entry));
-	if (name && name[0]) {
-		return;
-	}
-
+	timezone = gtk_combo_box_get_active_text (widget);
         info = clock_zonetable_get_l10n_zone (zones, timezone);
         g_free (timezone);
 
@@ -3685,27 +3678,55 @@
                 return;
         }
 
-        country = clock_zonetable_get_country (zones, clock_zoneinfo_get_country (info));
-        if (country != NULL) {
-                city = g_strdup_printf (_("%s, %s"),
-                                        clock_zoneinfo_get_l10n_city (info),
-                                        clock_country_get_l10n_name (country));
-        } else {
-                city = g_strdup (clock_zoneinfo_get_l10n_city (info));
-        }
+	buffer = gtk_entry_get_text (GTK_ENTRY (name_entry));
+	weather_code = g_object_get_data (G_OBJECT (edit_window),
+					  "weather-code");
+
+	if (!buffer || !buffer[0] || !weather_code) {
+		country = clock_zonetable_get_country (zones,
+						       clock_zoneinfo_get_country (info));
+		if (country != NULL) {
+			city = g_strdup_printf (_("%s, %s"),
+						clock_zoneinfo_get_l10n_city (info),
+						clock_country_get_l10n_name (country));
+		} else {
+			city = g_strdup (clock_zoneinfo_get_l10n_city (info));
+		}
+	} else
+		city = NULL;
 
-        gtk_entry_set_text (GTK_ENTRY (name_entry), city);
+	/* only fill fields in if not set yet, to allow correcting
+	 * a guessed timezone */
+	if (!buffer || !buffer[0]) {
+		gtk_entry_set_text (GTK_ENTRY (name_entry), city);
+	}
+
+	if (!weather_code) {
+		fill_location_tree (cd);
+		model = gtk_tree_view_get_model (GTK_TREE_VIEW (cd->location_tree));
+		weather_code = find_weather_code (model, city,
+						  clock_zoneinfo_get_country (info),
+						  lat * M_PI/180.0,
+						  lon * M_PI/180.0);
+		g_object_set_data_full (G_OBJECT (edit_window),
+					"weather-code", weather_code, g_free);
+	}
 
-        g_free (city);
+	g_free (city);
 
         clock_zoneinfo_get_coords (info, &lat, &lon);
-	update_coords (cd, TRUE, lat, lon);
 
-	fill_location_tree (cd);
-	model = gtk_tree_view_get_model (GTK_TREE_VIEW (cd->location_tree));
-	weather_code = find_weather_code (model, city, clock_zoneinfo_get_country (info),
-                                          lat * M_PI/180.0, lon * M_PI/180.0);
-	g_object_set_data_full (G_OBJECT (edit_window), "weather-code", weather_code, g_free);
+	buffer = gtk_entry_get_text (GTK_ENTRY (lat_entry));
+	if (!buffer || !buffer[0]) {
+		GtkWidget *lat_combo = glade_xml_get_widget (cd->glade_xml, "edit-location-latitude-combo");
+		update_coords_helper (lat, lat_entry, lat_combo);
+	}
+
+	buffer = gtk_entry_get_text (GTK_ENTRY (lon_entry));
+	if (!buffer || !buffer[0]) {
+		GtkWidget *lon_combo = glade_xml_get_widget (cd->glade_xml, "edit-location-longitude-combo");
+		update_coords_helper (lon, lon_entry, lon_combo);
+	}
 }
 
 static void
@@ -3780,12 +3801,18 @@
 
         gtk_tree_model_get (model, iter, COL_CITY_LOC, &loc, -1);
 
-        fill_timezone_combo_from_location (cd, zone_combo, loc);
-
-        gtk_entry_set_text (GTK_ENTRY (name_entry), clock_location_get_name (loc));
+        gtk_entry_set_text (GTK_ENTRY (name_entry),
+			    clock_location_get_name (loc));
+	g_object_set_data_full (G_OBJECT (edit_window), "weather-code",
+				g_strdup (clock_location_get_weather_code (loc)),
+				g_free);
 
         clock_location_get_coords (loc, &lat, &lon);
 
+	/* doing this after setting all the other fields will make it possible
+	 * to do less work in zone_combo_changed */
+        fill_timezone_combo_from_location (cd, zone_combo, loc);
+
         tmp = g_strdup_printf ("%f", fabsf(lat));
         gtk_entry_set_text (GTK_ENTRY (lat_entry), tmp);
         g_free (tmp);



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