[evolution-patches] weather calendar units



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.

-David
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.2
diff -u -r1.2 e-cal-backend-weather.c
--- calendar/backends/weather/e-cal-backend-weather.c	8 Jan 2005 09:36:33 -0000	1.2
+++ calendar/backends/weather/e-cal-backend-weather.c	10 Jan 2005 00:58:03 -0000
@@ -276,22 +276,22 @@
 	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);
 
 	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);
@@ -317,15 +317,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"), ctof (report->high));
-		else
+		if (metric)
 			comp_summary.value = g_strdup_printf (_("%.1f°C"), report->high);
-	} else {
-		if (fahrenheit)
-			comp_summary.value = g_strdup_printf (_("%.1f/%.1f°F"), ctof (report->high), ctof (report->low));
 		else
+			comp_summary.value = g_strdup_printf (_("%.1f°F"), ctof (report->high));
+	} else {
+		if (metric)
 			comp_summary.value = g_strdup_printf (_("%.1f/%.1f°C"), report->high, report->low);
+		else
+			comp_summary.value = g_strdup_printf (_("%.1f/%.1f°F"), ctof (report->high), ctof (report->low));
 	}
 	comp_summary.altrep = NULL;
 	e_cal_component_set_summary (cal_comp, &comp_summary);
@@ -337,15 +337,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.3
diff -u -r1.3 ChangeLog
--- plugins/calendar-weather/ChangeLog	7 Jan 2005 16:28:15 -0000	1.3
+++ plugins/calendar-weather/ChangeLog	10 Jan 2005 00:52:19 -0000
@@ -1,3 +1,9 @@
+2005-01-09  David Trowbridge <trowbrds cs colorado edu>
+
+	* calendar-weather.c, org-gnome-calendar-weather.eplug.in: convert
+	the two units dropdowns into a single that switches between
+	metric/imperial units
+
 2005-01-07  Rodrigo Moya <rodrigo novell com>
 
 	* Makefile.am: define EDS's datadir, needed to get to the
Index: plugins/calendar-weather/calendar-weather.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/calendar-weather/calendar-weather.c,v
retrieving revision 1.2
diff -u -r1.2 calendar-weather.c
--- plugins/calendar-weather/calendar-weather.c	7 Jan 2005 16:28:15 -0000	1.2
+++ plugins/calendar-weather/calendar-weather.c	10 Jan 2005 00:52:19 -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);
@@ -108,7 +107,6 @@
 		g_object_unref (weather);
 
 	e_source_list_sync (source_list, NULL);
-	return 0;
 }
 
 static void
@@ -587,107 +585,42 @@
 }
 
 static void
-set_temperature_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)
+set_units (ESource *source, GtkWidget *option)
 {
-	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 to new */
+			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 +651,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 +667,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	10 Jan 2005 00:52:19 -0000
@@ -18,15 +18,11 @@
 		 factory="e_calendar_weather_location"/>
 		<item
 		 type="item_table"
-		 path="00.general/00.source/50.tempFormat"
-		 factory="e_calendar_weather_temperature"/>
+		 path="00.general/00.source/50.units"
+		 factory="e_calendar_weather_units"/>
 		<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]