Re: [evolution-patches] weather calendar units



Here they are.

I've actually got an account now, so there's no need to feel obligated
to commit my stuff once it's gone through review :)

-David

On Tue, 2005-01-11 at 00:07 +0100, Rodrigo Moya wrote:
> On Sun, 2005-01-09 at 18:11 -0700, David Trowbridge wrote:
> > This converts the two separate units dropdowns into a single that lets
> > the user choose between metric and imperial units. I've got some simple
> > code in there to migrate to the new format if people already had the
> > older units set up, but I'm not sure if it's necessary or desirable.
> > 
> e-d-s patch does not apply cleanly on HEAD, could you please resend it?
> I guess evo patch depends on that one, so please resend both.
Index: calendar/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.376
diff -u -r1.376 ChangeLog
--- calendar/ChangeLog	10 Jan 2005 21:43:30 -0000	1.376
+++ calendar/ChangeLog	11 Jan 2005 11:07:36 -0000
@@ -1,3 +1,9 @@
+2005-01-11  David Trowbridge  <trowbrds cs colorado edu>
+
+	* backends/weather/e-cal-backend-weather.c: Use a single
+	metric/imperial setting rather than separate temperature and
+	snowfall settings
+
 2005-01-10  Harish Krishnaswamy  <kharish novell com>
 
 	* backends/groupwise/e-cal-backend-groupwise.c:
Index: calendar/backends/weather/e-cal-backend-weather.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/backends/weather/e-cal-backend-weather.c,v
retrieving revision 1.3
diff -u -r1.3 e-cal-backend-weather.c
--- calendar/backends/weather/e-cal-backend-weather.c	10 Jan 2005 12:35:37 -0000	1.3
+++ calendar/backends/weather/e-cal-backend-weather.c	11 Jan 2005 11:07:37 -0000
@@ -280,7 +280,7 @@
 	ECalComponentText         *description;
 	char                      *pop, *snow;
 	ESource                   *source;
-	gboolean                   fahrenheit, inches;
+	gboolean                   metric;
 	const char                *format;
 
 	g_return_val_if_fail (E_IS_CAL_BACKEND_WEATHER (cbw), NULL);
@@ -288,16 +288,16 @@
 	priv = cbw->priv;
 
 	source = e_cal_backend_get_source (E_CAL_BACKEND (cbw));
-	format = e_source_get_property (source, "temperature");
-	if (format == NULL)
-		fahrenheit = FALSE;
-	else
-		fahrenheit = (strcmp (format, "fahrenheit") == 0);
-	format = e_source_get_property (source, "snowfall");
-	if (format == NULL)
-		inches = FALSE;
-	else
-		inches = (strcmp (format, "inches") == 0);
+	format = e_source_get_property (source, "units");
+	if (format == NULL) {
+		format = e_source_get_property (source, "temperature");
+		if (format == NULL)
+			metric = FALSE;
+		else
+			metric = (strcmp (format, "fahrenheit") != 0);
+	} else {
+		metric = (strcmp (format, "metric") == 0);
+	}
 
 	/* create the component and event object */
 	ical_comp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
@@ -323,15 +323,15 @@
 
 	/* The summary is the high or high/low temperatures */
 	if (report->high == report->low) {
-		if (fahrenheit)
-			comp_summary.value = g_strdup_printf (_("%.1f°F - %s"), ctof (report->high), priv->city);
-		else
+		if (metric)
 			comp_summary.value = g_strdup_printf (_("%.1f°C - %s"), report->high, priv->city);
-	} else {
-		if (fahrenheit)
-			comp_summary.value = g_strdup_printf (_("%.1f/%.1f°F - %s"), ctof (report->high), ctof (report->low), priv->city);
 		else
+			comp_summary.value = g_strdup_printf (_("%.1f°F - %s"), ctof (report->high), priv->city);
+	} else {
+		if (metric)
 			comp_summary.value = g_strdup_printf (_("%.1f/%.1f°C - %s"), report->high, report->low, priv->city);
+		else
+			comp_summary.value = g_strdup_printf (_("%.1f/%.1f°F - %s"), ctof (report->high), ctof (report->low), priv->city);
 	}
 	comp_summary.altrep = NULL;
 	e_cal_component_set_summary (cal_comp, &comp_summary);
@@ -343,15 +343,15 @@
 	if (report->snowhigh == 0)
 		snow = g_strdup ("");
 	else if (report->snowhigh == report->snowlow) {
-		if (inches)
-			snow = g_strdup_printf (_("%.1fin snow\n"), cmtoin(report->snowhigh));
-		else
+		if (metric)
 			snow = g_strdup_printf (_("%.1fcm snow\n"), report->snowhigh);
-	} else {
-		if (inches)
-			snow = g_strdup_printf (_("%.1f-%.1fin snow\n"), cmtoin(report->snowlow), cmtoin(report->snowhigh));
 		else
+			snow = g_strdup_printf (_("%.1fin snow\n"), cmtoin(report->snowhigh));
+	} else {
+		if (metric)
 			snow = g_strdup_printf (_("%.1f-%.1fcm snow\n"), report->snowlow, report->snowhigh);
+		else
+			snow = g_strdup_printf (_("%.1f-%.1fin snow\n"), cmtoin(report->snowlow), cmtoin(report->snowhigh));
 	}
 	description = g_new0 (ECalComponentText, 1);
 	description->value = g_strdup_printf ("%s\n%s%s", getConditions (report), pop, snow);
Index: plugins/calendar-weather/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/calendar-weather/ChangeLog,v
retrieving revision 1.4
diff -u -r1.4 ChangeLog
--- plugins/calendar-weather/ChangeLog	10 Jan 2005 23:04:53 -0000	1.4
+++ plugins/calendar-weather/ChangeLog	11 Jan 2005 11:14:02 -0000
@@ -1,3 +1,9 @@
+2005-01-11  David Trowbridge <trowbrds cs colorado edu>
+
+	* calendar-weather.c, org-gnome-calendar-weather.eplug.in: use
+	a single setting for metric/imperial rather than separate
+	temperature and snowfall settings
+
 2005-01-10  Rodrigo Moya <rodrigo novell com>
 
 	* calendar-weather.c (create_source_selected): use HIG-compliant
Index: plugins/calendar-weather/calendar-weather.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/calendar-weather/calendar-weather.c,v
retrieving revision 1.3
diff -u -r1.3 calendar-weather.c
--- plugins/calendar-weather/calendar-weather.c	10 Jan 2005 23:04:53 -0000	1.3
+++ plugins/calendar-weather/calendar-weather.c	11 Jan 2005 11:14:03 -0000
@@ -34,8 +34,7 @@
 
 GtkWidget *e_calendar_weather_location (EPlugin *epl, EConfigHookItemFactoryData *data);
 GtkWidget *e_calendar_weather_refresh (EPlugin *epl, EConfigHookItemFactoryData *data);
-GtkWidget *e_calendar_weather_temperature (EPlugin *epl, EConfigHookItemFactoryData *data);
-GtkWidget *e_calendar_weather_snowfall (EPlugin *epl, EConfigHookItemFactoryData *data);
+GtkWidget *e_calendar_weather_units (EPlugin *epl, EConfigHookItemFactoryData *data);
 gboolean   e_calendar_weather_check (EPlugin *epl, EConfigHookPageCheckData *data);
 void       e_calendar_weather_migrate (EPlugin *epl, ECalEventTargetComponent *data);
 int        e_plugin_lib_enable (EPluginLib *epl, int enable);
@@ -587,107 +586,42 @@
 }
 
 static void
-set_temperature_units (ESource *source, GtkWidget *option)
+set_units (ESource *source, GtkWidget *option)
 {
-	const char *format = e_source_get_property (source, "temperature");
-	if (format == NULL)
-		gtk_option_menu_set_history (GTK_OPTION_MENU (option), 0);
-	else if (strcmp (format, "fahrenheit") == 0)
-		gtk_option_menu_set_history (GTK_OPTION_MENU (option), 1);
-	else
-		gtk_option_menu_set_history (GTK_OPTION_MENU (option), 0);
-}
-
-static void
-temperature_units_changed (GtkOptionMenu *option, ECalConfigTargetSource *t)
-{
-	int choice = gtk_option_menu_get_history (GTK_OPTION_MENU (option));
-	if (choice == 0)
-		e_source_set_property (t->source, "temperature", "celcius");
-	else
-		e_source_set_property (t->source, "temperature", "fahrenheit");
-}
-
-GtkWidget *
-e_calendar_weather_temperature (EPlugin *epl, EConfigHookItemFactoryData *data)
-{
-	static GtkWidget *label;
-	GtkWidget *option, *menu, *parent;
-	GtkWidget *formats[2];
-	int row, i;
-	ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target;
-	ESource *source = t->source;
-	EUri *uri;
-	char *uri_text;
-	static GtkWidget *hidden = NULL;
-
-	if (!hidden)
-		hidden = gtk_label_new ("");
-
-	if (data->old)
-		gtk_widget_destroy (label);
-
-	uri_text = e_source_get_uri (t->source);
-	uri = e_uri_new (uri_text);
-	g_free (uri_text);
-	if (strcmp (uri->protocol, "weather")) {
-		e_uri_free (uri);
-		return hidden;
-	}
-	e_uri_free (uri);
-
-	parent = data->parent;
-
-	row = ((GtkTable*)parent)->nrows;
-
-	label = gtk_label_new_with_mnemonic (_("_Temperature Units:"));
-	gtk_widget_show (label);
-	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-	gtk_table_attach (GTK_TABLE (parent), label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0);
-
-	option = gtk_option_menu_new ();
-	gtk_widget_show (option);
-	formats[0] = gtk_menu_item_new_with_label (_("Celcius"));
-	formats[1] = gtk_menu_item_new_with_label (_("Fahrenheit"));
-	menu = gtk_menu_new ();
-	gtk_widget_show (menu);
-	for (i = 0; i < 2; i++) {
-		gtk_widget_show (formats[i]);
-		gtk_menu_shell_append (GTK_MENU_SHELL (menu), formats[i]);
+	const char *format = e_source_get_property (source, "units");
+	if (format == NULL) {
+		format = e_source_get_property (source, "temperature");
+		if (format == NULL) {
+			e_source_set_property (source, "units", "metric");
+			gtk_option_menu_set_history (GTK_OPTION_MENU (option), 0);
+		} else if (strcmp (format, "fahrenheit") == 0) {
+			/* old format, convert */
+			e_source_set_property (source, "units", "imperial");
+			gtk_option_menu_set_history (GTK_OPTION_MENU (option), 1);
+		} else {
+			e_source_set_property (source, "units", "metric");
+			gtk_option_menu_set_history (GTK_OPTION_MENU (option), 0);
+		}
+	} else {
+		if (strcmp (format, "metric") == 0)
+			gtk_option_menu_set_history (GTK_OPTION_MENU (option), 0);
+		else
+			gtk_option_menu_set_history (GTK_OPTION_MENU (option), 1);
 	}
-	gtk_option_menu_set_menu (GTK_OPTION_MENU (option), menu);
-	set_temperature_units (source, option);
-	gtk_label_set_mnemonic_widget (GTK_LABEL (label), option);
-	g_signal_connect (G_OBJECT (option), "changed", G_CALLBACK (temperature_units_changed), t);
-	gtk_table_attach (GTK_TABLE (parent), option, 1, 2, row, row+1, GTK_FILL, 0, 0, 0);
-
-	return option;
-}
-
-static void
-set_snowfall_units (ESource *source, GtkWidget *option)
-{
-	const char *format = e_source_get_property (source, "snowfall");
-	if (format == NULL)
-		gtk_option_menu_set_history (GTK_OPTION_MENU (option), 0);
-	else if (strcmp (format, "inches") == 0)
-		gtk_option_menu_set_history (GTK_OPTION_MENU (option), 1);
-	else
-		gtk_option_menu_set_history (GTK_OPTION_MENU (option), 0);
 }
 
 static void
-snowfall_units_changed (GtkOptionMenu *option, ECalConfigTargetSource *t)
+units_changed (GtkOptionMenu *option, ECalConfigTargetSource *t)
 {
 	int choice = gtk_option_menu_get_history (GTK_OPTION_MENU (option));
 	if (choice == 0)
-		e_source_set_property (t->source, "snowfall", "centimeters");
+		e_source_set_property (t->source, "units", "metric");
 	else
-		e_source_set_property (t->source, "snowfall", "inches");
+		e_source_set_property (t->source, "units", "imperial");
 }
 
 GtkWidget *
-e_calendar_weather_snowfall (EPlugin *epl, EConfigHookItemFactoryData *data)
+e_calendar_weather_units (EPlugin *epl, EConfigHookItemFactoryData *data)
 {
 	static GtkWidget *label;
 	GtkWidget *option, *menu, *parent;
@@ -718,15 +652,15 @@
 
 	row = ((GtkTable*)parent)->nrows;
 
-	label = gtk_label_new_with_mnemonic (_("_Snowfall Units:"));
+	label = gtk_label_new_with_mnemonic (_("_Units:"));
 	gtk_widget_show (label);
 	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 	gtk_table_attach (GTK_TABLE (parent), label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0);
 
 	option = gtk_option_menu_new ();
 	gtk_widget_show (option);
-	formats[0] = gtk_menu_item_new_with_label (_("Centimeters"));
-	formats[1] = gtk_menu_item_new_with_label (_("Inches"));
+	formats[0] = gtk_menu_item_new_with_label (_("Metric (celcius, cm, etc)"));
+	formats[1] = gtk_menu_item_new_with_label (_("Imperial (fahrenheit, inches, etc)"));
 	menu = gtk_menu_new ();
 	gtk_widget_show (menu);
 	for (i = 0; i < 2; i++) {
@@ -734,9 +668,9 @@
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), formats[i]);
 	}
 	gtk_option_menu_set_menu (GTK_OPTION_MENU (option), menu);
-	set_snowfall_units (source, option);
+	set_units (source, option);
 	gtk_label_set_mnemonic_widget (GTK_LABEL (label), option);
-	g_signal_connect (G_OBJECT (option), "changed", G_CALLBACK (snowfall_units_changed), t);
+	g_signal_connect (G_OBJECT (option), "changed", G_CALLBACK (units_changed), t);
 	gtk_table_attach (GTK_TABLE (parent), option, 1, 2, row, row+1, GTK_FILL, 0, 0, 0);
 
 	return option;
Index: plugins/calendar-weather/org-gnome-calendar-weather.eplug.in
===================================================================
RCS file: /cvs/gnome/evolution/plugins/calendar-weather/org-gnome-calendar-weather.eplug.in,v
retrieving revision 1.1
diff -u -r1.1 org-gnome-calendar-weather.eplug.in
--- plugins/calendar-weather/org-gnome-calendar-weather.eplug.in	7 Jan 2005 11:35:33 -0000	1.1
+++ plugins/calendar-weather/org-gnome-calendar-weather.eplug.in	11 Jan 2005 11:14:03 -0000
@@ -18,15 +18,11 @@
 		 factory="e_calendar_weather_location"/>
 		<item
 		 type="item_table"
-		 path="00.general/00.source/50.tempFormat"
+		 path="00.general/00.source/50.units"
 		 factory="e_calendar_weather_temperature"/>
 		<item
 		 type="item_table"
-		 path="00.general/00.source/60.snowfallFormat"
-		 factory="e_calendar_weather_snowfall"/>
-		<item
-		 type="item_table"
-		 path="00.general/00.source/70.refresh"
+		 path="00.general/00.source/60.refresh"
 		 factory="e_calendar_weather_refresh"/>
 	    </group>
 	</hook>


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