1
From 76c53350cf86cb15400c00c9ca0b84931cb5f040 Mon Sep 17 00:00:00 2001
2
From: Ted M Lin <tedmlin@gmail.com>
3
Date: Tue, 1 Sep 2009 22:00:36 -0400
4
Subject: [PATCH] Fix sunrise and sunset times in tooltip to respect 12/24 hour format setting.
6
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=520226
7
Bug-Ubuntu: https://launchpad.net/bugs/197657
9
diff --git a/applets/clock/clock-location-tile.c b/applets/clock/clock-location-tile.c
10
index e1b254c..22c1e9f 100644
11
--- a/applets/clock/clock-location-tile.c
12
+++ b/applets/clock/clock-location-tile.c
13
@@ -501,6 +501,36 @@ format_time (struct tm *now,
18
+convert_time_to_str (time_t now, ClockFormat clock_format)
24
+ if (clock_format == CLOCK_FORMAT_12) {
25
+/* translators: This is a strftime format string that is used for formatting
26
+ * the time that is displayed in the sunrise/sunset popup. This string is used
27
+ * for 12-hour format (the %p expands to am/pm).
28
+ * There should be little need to translate this string.
30
+ format = _("%l:%M %p");
33
+/* translators: This is a strftime format string that is used for formatting
34
+ * the time that is displayed in the sunrise/sunset popup. This string is used
35
+ * for a 24-hour format.
36
+ * There should be little need to translate this string.
38
+ format = _("%H:%M");
41
+ tm = localtime (&now);
42
+ strftime (buf, sizeof (buf) - 1, format, tm);
44
+ return g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
48
clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
50
@@ -556,7 +586,8 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
54
-weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkTooltip *tooltip)
55
+weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkTooltip *tooltip,
56
+ ClockFormat clock_format)
58
GdkPixbuf *pixbuf = NULL;
59
GtkIconTheme *theme = NULL;
60
@@ -565,6 +596,8 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
61
gchar *line1, *line2, *line3, *line4, *tip;
62
const gchar *icon_name;
63
const gchar *sys_timezone;
64
+ time_t sunrise_time, sunset_time;
65
+ gchar *sunrise_str, *sunset_str;
67
icon_name = weather_info_get_icon_name (info);
68
theme = gtk_icon_theme_get_default ();
69
@@ -600,15 +633,21 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
71
line3 = g_strdup ("");
73
- /* FIXME: we need libgweather to give us the time,
74
- * not just a formatted string
76
sys_timezone = getenv ("TZ");
77
setenv ("TZ", clock_location_get_timezone (location), 1);
79
+ if (weather_info_get_value_sunrise (info, &sunrise_time))
80
+ sunrise_str = convert_time_to_str (sunrise_time, clock_format);
82
+ sunrise_str = g_strdup ("???");
83
+ if (weather_info_get_value_sunset (info, &sunset_time))
84
+ sunset_str = convert_time_to_str (sunset_time, clock_format);
86
+ sunset_str = g_strdup ("???");
87
line4 = g_strdup_printf (_("Sunrise: %s / Sunset: %s"),
88
- weather_info_get_sunrise (info),
89
- weather_info_get_sunset (info));
90
+ sunrise_str, sunset_str);
91
+ g_free (sunrise_str);
92
+ g_free (sunset_str);
94
setenv ("TZ", sys_timezone, 1);
96
@@ -635,13 +674,16 @@ weather_tooltip (GtkWidget *widget,
97
ClockLocationTile *tile = data;
98
ClockLocationTilePrivate *priv = PRIVATE (tile);
102
info = clock_location_get_weather_info (priv->location);
104
if (!info || !weather_info_is_valid (info))
107
- weather_info_setup_tooltip (info, priv->location, tooltip);
108
+ g_signal_emit (tile, signals[NEED_CLOCK_FORMAT], 0, &clock_format);
110
+ weather_info_setup_tooltip (info, priv->location, tooltip, clock_format);
114
diff --git a/applets/clock/clock-location-tile.h b/applets/clock/clock-location-tile.h
115
index b480e3f..628a8b5 100644
116
--- a/applets/clock/clock-location-tile.h
117
+++ b/applets/clock/clock-location-tile.h
120
#include "clock-face.h"
121
#include "clock-location.h"
122
+#include "clock-utils.h"
126
@@ -36,7 +37,8 @@ ClockLocationTile *clock_location_tile_new (ClockLocation *loc,
128
ClockLocation *clock_location_tile_get_location (ClockLocationTile *this);
130
-void weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkTooltip *tip);
131
+void weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkTooltip *tip,
132
+ ClockFormat clock_format);
134
void clock_location_tile_refresh (ClockLocationTile *this,
135
gboolean force_refresh);
136
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
137
index 7ee7273..ec4100f 100644
138
--- a/applets/clock/clock.c
139
+++ b/applets/clock/clock.c
140
@@ -1389,7 +1389,7 @@ weather_tooltip (GtkWidget *widget,
141
if (!info || !weather_info_is_valid (info))
144
- weather_info_setup_tooltip (info, location, tooltip);
145
+ weather_info_setup_tooltip (info, location, tooltip, cd->format);