View | Details | Raw Unified | Return to bug 236166
Collapse All | Expand All

(-)Makefile (-1 / +2 lines)
Lines 3-8 Link Here
3
3
4
PORTNAME=	xfce4-weather-plugin
4
PORTNAME=	xfce4-weather-plugin
5
PORTVERSION=	0.9.0
5
PORTVERSION=	0.9.0
6
PORTREVISION=	1
6
CATEGORIES=	misc xfce geography
7
CATEGORIES=	misc xfce geography
7
MASTER_SITES=	XFCE/src/panel-plugins/${PORTNAME}/${PORTVERSION:R}
8
MASTER_SITES=	XFCE/src/panel-plugins/${PORTNAME}/${PORTVERSION:R}
8
DIST_SUBDIR=	xfce4
9
DIST_SUBDIR=	xfce4
Lines 18-24 Link Here
18
		libfreetype.so:print/freetype2
19
		libfreetype.so:print/freetype2
19
20
20
USES=		gettext-tools gmake gnome libtool pkgconfig tar:bzip2 xfce:gtk3
21
USES=		gettext-tools gmake gnome libtool pkgconfig tar:bzip2 xfce:gtk3
21
USE_GNOME=	cairo glib20 gtk30 intlhack intltool libxml2
22
USE_GNOME=	cairo glib20 gtk30 intltool libxml2
22
USE_XFCE=	panel
23
USE_XFCE=	panel
23
USE_LDCONFIG=	yes
24
USE_LDCONFIG=	yes
24
25
(-)files/patch-panel-plugin_weather-data.c (+34 lines)
Line 0 Link Here
1
--- panel-plugin/weather-data.c.orig	2018-09-16 22:12:20 UTC
2
+++ panel-plugin/weather-data.c
3
@@ -105,25 +105,25 @@ double_to_string(const gdouble val,
4
 
5
 
6
 gchar *
7
-format_date(const time_t date_t,
8
+format_date(time_t date_t,
9
             gchar *format,
10
             gboolean local)
11
 {
12
     struct tm *tm;
13
-    time_t t = date_t;
14
     gchar buf[40];
15
     size_t size;
16
 
17
+    if (format == NULL)
18
+        format = "%Y-%m-%d %H:%M:%S";
19
+
20
     if (G_LIKELY(local))
21
-        tm = localtime(&t);
22
+        tm = localtime(&date_t);
23
     else
24
-        tm = gmtime(&t);
25
+        tm = gmtime(&date_t);
26
 
27
     /* A year <= 1970 means date has not been set */
28
     if (G_UNLIKELY(tm == NULL) || tm->tm_year <= 70)
29
         return g_strdup("-");
30
-    if (format == NULL)
31
-        format = "%Y-%m-%d %H:%M:%S";
32
     size = strftime(buf, 40, format, tm);
33
     return (size ? g_strdup(buf) : g_strdup("-"));
34
 }
(-)files/patch-panel-plugin_weather-data.h (+11 lines)
Line 0 Link Here
1
--- panel-plugin/weather-data.h.orig	2018-09-16 22:11:17 UTC
2
+++ panel-plugin/weather-data.h
3
@@ -103,7 +103,7 @@ gdouble string_to_double(const gchar *str,
4
 gchar *double_to_string(gdouble val,
5
                         const gchar *format);
6
 
7
-gchar *format_date(const time_t t,
8
+gchar *format_date(time_t t,
9
                    gchar *format,
10
                    gboolean local);
11
 
(-)files/patch-panel-plugin_weather-parsers.c (+249 lines)
Line 0 Link Here
1
--- panel-plugin/weather-parsers.c.orig	2018-09-16 22:12:20 UTC
2
+++ panel-plugin/weather-parsers.c
3
@@ -35,7 +35,10 @@
4
 #include <stdlib.h>
5
 #include <string.h>
6
 
7
+#include <libxml/parser.h>
8
+#include <libxml/tree.h>
9
 
10
+
11
 #define DATA(node)                                                  \
12
     ((gchar *) xmlNodeListGetString(node->doc, node->children, 1))
13
 
14
@@ -71,6 +74,28 @@ my_timegm(struct tm *tm)
15
 }
16
 
17
 
18
+/*
19
+ * Remove offset of timezone, in order to keep previous
20
+ * date format (before the new API, 2.x).
21
+ */
22
+static gchar *
23
+remove_timezone_offset(gchar *date)
24
+{
25
+    GRegex *re = NULL;
26
+    const gchar *pattern = "[+-][0-9]{2}:[0-9]{2}";
27
+    gchar *res;
28
+
29
+    re = g_regex_new(pattern, 0, 0, NULL);
30
+    if (re != NULL && g_regex_match(re, date, 0, NULL)) {
31
+        res = g_regex_replace(re, date, -1, 0, "Z", 0, NULL);
32
+    } else {
33
+        res = date;
34
+    }
35
+    g_regex_unref(re);
36
+    return res;
37
+}
38
+
39
+
40
 xml_time *
41
 get_timeslice(xml_weather *wd,
42
               const time_t start_t,
43
@@ -128,9 +153,10 @@ parse_timestring(const gchar *ts,
44
     time_t t;
45
     struct tm tm;
46
 
47
-    memset(&t, 0, sizeof(time_t));
48
-    if (G_UNLIKELY(ts == NULL))
49
+    if (G_UNLIKELY(ts == NULL)) {
50
+        memset(&t, 0, sizeof(time_t));
51
         return t;
52
+    }
53
 
54
     /* standard format */
55
     if (format == NULL)
56
@@ -141,15 +167,22 @@ parse_timestring(const gchar *ts,
57
     memset(&tm, 0, sizeof(struct tm));
58
     tm.tm_isdst = -1;
59
 
60
-    if (G_UNLIKELY(strptime(ts, format, &tm) == NULL))
61
-        return t;
62
+    if (strptime(ts, format, &tm) != NULL) {
63
+        if (local)
64
+            t = mktime(&tm);
65
+        else
66
+            t = my_timegm(&tm);
67
 
68
-    if (local)
69
-        t = mktime(&tm);
70
-    else
71
-        t = my_timegm(&tm);
72
-
73
-    return t;
74
+        if (t < 0) {
75
+            memset(&t, 0, sizeof(time_t));
76
+            return t;
77
+        } else {
78
+            return t;
79
+        }
80
+    } else {
81
+        memset(&t, 0, sizeof(time_t));
82
+        return t;
83
+    }
84
 }
85
 
86
 
87
@@ -365,83 +398,14 @@ parse_weather(xmlNode *cur_node,
88
 }
89
 
90
 
91
-static void
92
-parse_astro_location(xmlNode *cur_node,
93
-                     xml_astro *astro)
94
-{
95
-    xmlNode *child_node;
96
-    gchar *sunrise, *sunset, *moonrise, *moonset;
97
-    gchar *never_rises, *never_sets;
98
-
99
-    for (child_node = cur_node->children; child_node;
100
-         child_node = child_node->next) {
101
-        if (NODE_IS_TYPE(child_node, "sun")) {
102
-            never_rises = PROP(child_node, "never_rise");
103
-            if (never_rises &&
104
-                (!strcmp(never_rises, "true") ||
105
-                 !strcmp(never_rises, "1")))
106
-                astro->sun_never_rises = TRUE;
107
-            else
108
-                astro->sun_never_rises = FALSE;
109
-            xmlFree(never_rises);
110
-
111
-            never_sets = PROP(child_node, "never_set");
112
-            if (never_sets &&
113
-                (!strcmp(never_sets, "true") ||
114
-                 !strcmp(never_sets, "1")))
115
-                astro->sun_never_sets = TRUE;
116
-            else
117
-                astro->sun_never_sets = FALSE;
118
-            xmlFree(never_sets);
119
-
120
-            sunrise = PROP(child_node, "rise");
121
-            astro->sunrise = parse_timestring(sunrise, NULL, FALSE);
122
-            xmlFree(sunrise);
123
-
124
-            sunset = PROP(child_node, "set");
125
-            astro->sunset = parse_timestring(sunset, NULL, FALSE);
126
-            xmlFree(sunset);
127
-        }
128
-
129
-        if (NODE_IS_TYPE(child_node, "moon")) {
130
-            never_rises = PROP(child_node, "never_rise");
131
-            if (never_rises &&
132
-                (!strcmp(never_rises, "true") ||
133
-                 !strcmp(never_rises, "1")))
134
-                astro->moon_never_rises = TRUE;
135
-            else
136
-                astro->moon_never_rises = FALSE;
137
-            xmlFree(never_rises);
138
-
139
-            never_sets = PROP(child_node, "never_set");
140
-            if (never_sets &&
141
-                (!strcmp(never_sets, "true") ||
142
-                 !strcmp(never_sets, "1")))
143
-                astro->moon_never_sets = TRUE;
144
-            else
145
-                astro->moon_never_sets = FALSE;
146
-            xmlFree(never_sets);
147
-
148
-            moonrise = PROP(child_node, "rise");
149
-            astro->moonrise = parse_timestring(moonrise, NULL, FALSE);
150
-            xmlFree(moonrise);
151
-
152
-            moonset = PROP(child_node, "set");
153
-            astro->moonset = parse_timestring(moonset, NULL, FALSE);
154
-            xmlFree(moonset);
155
-
156
-            astro->moon_phase = PROP(child_node, "phase");
157
-        }
158
-    }
159
-}
160
-
161
-
162
 static xml_astro *
163
 parse_astro_time(xmlNode *cur_node)
164
 {
165
     xmlNode *child_node;
166
     xml_astro *astro;
167
-    gchar *date;
168
+    gchar *date, *sunrise, *sunset, *moonrise, *moonset;
169
+    gboolean sun_rises = FALSE, sun_sets = FALSE;
170
+    gboolean moon_rises = FALSE, moon_sets = FALSE;
171
 
172
     astro = g_slice_new0(xml_astro);
173
     if (G_UNLIKELY(astro == NULL))
174
@@ -452,15 +416,61 @@ parse_astro_time(xmlNode *cur_node)
175
     xmlFree(date);
176
 
177
     for (child_node = cur_node->children; child_node;
178
-         child_node = child_node->next)
179
-        if (NODE_IS_TYPE(child_node, "location"))
180
-            parse_astro_location(child_node, astro);
181
+         child_node = child_node->next) {
182
+        if (child_node->type == XML_ELEMENT_NODE) {
183
+            if (NODE_IS_TYPE(child_node, "sunrise")) {
184
+                sunrise = remove_timezone_offset(PROP(child_node, "time"));
185
+                astro->sunrise = parse_timestring(sunrise, NULL, FALSE);
186
+                xmlFree(sunrise);
187
+                sun_rises = TRUE;
188
+            }
189
+
190
+            if (NODE_IS_TYPE(child_node, "moonset")) {
191
+                moonset = remove_timezone_offset(PROP(child_node, "time"));
192
+                astro->moonset = parse_timestring(moonset, NULL, FALSE);
193
+                xmlFree(moonset);
194
+                moon_sets = TRUE;
195
+            }
196
+
197
+            if (NODE_IS_TYPE(child_node, "sunset")) {
198
+                sunset = remove_timezone_offset(PROP(child_node, "time"));
199
+                astro->sunset = parse_timestring(sunset, NULL, FALSE);
200
+                xmlFree(sunset);
201
+                sun_sets = TRUE;
202
+            }
203
+
204
+            if (NODE_IS_TYPE(child_node, "moonrise")) {
205
+                moonrise = remove_timezone_offset(PROP(child_node, "time"));
206
+                astro->moonrise = parse_timestring(moonrise, NULL, FALSE);
207
+                xmlFree(moonrise);
208
+                moon_rises = TRUE;
209
+            }
210
+        }
211
+    }
212
+
213
+    if (sun_rises)
214
+        astro->sun_never_rises = FALSE;
215
+    else
216
+        astro->sun_never_rises = TRUE;
217
+    if (sun_sets)
218
+        astro->sun_never_sets = FALSE;
219
+    else
220
+        astro->sun_never_sets = TRUE;
221
+
222
+    if (moon_rises)
223
+        astro->moon_never_rises = FALSE;
224
+    else
225
+        astro->moon_never_rises = TRUE;
226
+    if (moon_sets)
227
+        astro->moon_never_sets = FALSE;
228
+    else
229
+        astro->moon_never_sets = TRUE;
230
     return astro;
231
 }
232
 
233
 
234
 /*
235
- * Look at https://api.met.no/weatherapi/sunrise/1.1/schema for information
236
+ * Look at https://api.met.no/weatherapi/sunrise/2.0/schema for information
237
  * of elements and attributes to expect.
238
  */
239
 gboolean
240
@@ -475,7 +485,8 @@ parse_astrodata(xmlNode *cur_node,
241
         return FALSE;
242
 
243
     g_assert(cur_node != NULL);
244
-    if (G_UNLIKELY(cur_node == NULL || !NODE_IS_TYPE(cur_node, "astrodata")))
245
+    if (G_UNLIKELY(cur_node == NULL ||
246
+        !NODE_IS_TYPE(cur_node, "location")))
247
         return FALSE;
248
 
249
     for (child_node = cur_node->children; child_node;
(-)files/patch-panel-plugin_weather-summary.c (+77 lines)
Line 0 Link Here
1
--- panel-plugin/weather-summary.c.orig	2018-09-22 11:00:03 UTC
2
+++ panel-plugin/weather-summary.c
3
@@ -465,12 +465,12 @@ create_summary_tab(plugin_data *data)
4
             value = g_strdup(_("\tSunset:\t\tThe sun never sets today.\n"));
5
             APPEND_TEXT_ITEM_REAL(value);
6
         } else {
7
-            sunrise = format_date(data->current_astro->sunrise, NULL, TRUE);
8
+            sunrise = format_date(data->current_astro->sunrise, NULL, FALSE);
9
             value = g_strdup_printf(_("\tSunrise:\t\t%s\n"), sunrise);
10
             g_free(sunrise);
11
             APPEND_TEXT_ITEM_REAL(value);
12
 
13
-            sunset = format_date(data->current_astro->sunset, NULL, TRUE);
14
+            sunset = format_date(data->current_astro->sunset, NULL, FALSE);
15
             value = g_strdup_printf(_("\tSunset:\t\t%s\n\n"), sunset);
16
             g_free(sunset);
17
             APPEND_TEXT_ITEM_REAL(value);
18
@@ -493,12 +493,12 @@ create_summary_tab(plugin_data *data)
19
                 g_strdup(_("\tMoonset:\tThe moon never sets today.\n"));
20
             APPEND_TEXT_ITEM_REAL(value);
21
         } else {
22
-            moonrise = format_date(data->current_astro->moonrise, NULL, TRUE);
23
+            moonrise = format_date(data->current_astro->moonrise, NULL, FALSE);
24
             value = g_strdup_printf(_("\tMoonrise:\t%s\n"), moonrise);
25
             g_free(moonrise);
26
             APPEND_TEXT_ITEM_REAL(value);
27
 
28
-            moonset = format_date(data->current_astro->moonset, NULL, TRUE);
29
+            moonset = format_date(data->current_astro->moonset, NULL, FALSE);
30
             value = g_strdup_printf(_("\tMoonset:\t%s\n"), moonset);
31
             g_free(moonset);
32
             APPEND_TEXT_ITEM_REAL(value);
33
@@ -749,13 +749,13 @@ forecast_day_header_tooltip_text(xml_astro *astro)
34
                                     "Sunset: The sun never sets this day."
35
                                     "</small></tt>\n"));
36
         else {
37
-            sunrise = format_date(astro->sunrise, NULL, TRUE);
38
+            sunrise = format_date(astro->sunrise, NULL, FALSE);
39
             g_string_append_printf(text, _("<tt><small>"
40
                                            "Sunrise: %s"
41
                                            "</small></tt>\n"), sunrise);
42
             g_free(sunrise);
43
 
44
-            sunset = format_date(astro->sunset, NULL, TRUE);
45
+            sunset = format_date(astro->sunset, NULL, FALSE);
46
             g_string_append_printf(text, _("<tt><small>"
47
                                            "Sunset:  %s"
48
                                            "</small></tt>\n\n"), sunset);
49
@@ -782,13 +782,13 @@ forecast_day_header_tooltip_text(xml_astro *astro)
50
                               "Moonset: The moon never sets this day."
51
                               "</small></tt>\n"));
52
         else {
53
-            moonrise = format_date(astro->moonrise, NULL, TRUE);
54
+            moonrise = format_date(astro->moonrise, NULL, FALSE);
55
             g_string_append_printf(text, _("<tt><small>"
56
                                            "Moonrise: %s"
57
                                            "</small></tt>\n"), moonrise);
58
             g_free(moonrise);
59
 
60
-            moonset = format_date(astro->moonset, NULL, TRUE);
61
+            moonset = format_date(astro->moonset, NULL, FALSE);
62
             g_string_append_printf(text, _("<tt><small>"
63
                                            "Moonset:  %s"
64
                                            "</small></tt>"), moonset);
65
@@ -1134,10 +1134,10 @@ update_summary_subtitle(plugin_data *data)
66
     time(&now_t);
67
 #ifdef HAVE_UPOWER_GLIB
68
     if (data->upower_on_battery)
69
-        date_format = "%Y-%m-%d %H:%M %z (%Z)";
70
+        date_format = "%Y-%m-%d %H:%M:%S (%Z)";
71
     else
72
 #endif
73
-        date_format = "%Y-%m-%d %H:%M:%S %z (%Z)";
74
+        date_format = "%Y-%m-%d %H:%M:%S (%Z)";
75
     date = format_date(now_t, date_format, TRUE);
76
     title = g_strdup_printf("%s\n%s", data->location_name, date);
77
     g_free(date);
(-)files/patch-panel-plugin_weather.c (+255 lines)
Line 0 Link Here
1
--- panel-plugin/weather.c.orig	2018-09-16 22:12:20 UTC
2
+++ panel-plugin/weather.c
3
@@ -26,6 +26,9 @@
4
 #include <libxfce4util/libxfce4util.h>
5
 #include <libxfce4ui/libxfce4ui.h>
6
 
7
+#include <libxml/parser.h>
8
+#include <libxml/tree.h>
9
+
10
 #include "weather-parsers.h"
11
 #include "weather-data.h"
12
 #include "weather.h"
13
@@ -47,12 +50,6 @@
14
 #define CONN_RETRY_INTERVAL_SMALL (10)
15
 #define CONN_RETRY_INTERVAL_LARGE (10 * 60)
16
 
17
-/* met.no sunrise API returns data for up to 30 days in the future and
18
-   will return an error page if too many days are requested. Let's
19
-   play it safe and request fewer than that, since we can only get a
20
-   10 days forecast too. */
21
-#define ASTRODATA_MAX_DAYS 25
22
-
23
 /* power saving update interval in seconds used as a precaution to
24
    deal with suspend/resume events etc., when nothing needs to be
25
    updated earlier: */
26
@@ -81,6 +78,7 @@
27
     g_free(locname);                            \
28
     g_free(lat);                                \
29
     g_free(lon);                                \
30
+    g_free(offset);                             \
31
     if (keyfile)                                \
32
         g_key_file_free(keyfile);
33
 
34
@@ -270,6 +268,19 @@ update_timezone(plugin_data *data)
35
 
36
 
37
 void
38
+update_offset(plugin_data *data)
39
+{
40
+    GDateTime *dt;
41
+
42
+    dt = g_date_time_new_now_local();
43
+    if (G_LIKELY(data->offset))
44
+        g_free(data->offset);
45
+
46
+    data->offset = g_date_time_format(dt, "%:z");
47
+}
48
+
49
+
50
+void
51
 update_icon(plugin_data *data)
52
 {
53
     GdkPixbuf *icon;
54
@@ -481,7 +492,7 @@ cb_astro_update(SoupSession *session,
55
 {
56
     plugin_data *data = user_data;
57
     xmlDoc *doc;
58
-    xmlNode *root_node;
59
+    xmlNode *root_node, *child_node;
60
     time_t now_t;
61
     gboolean parsing_error = TRUE;
62
 
63
@@ -492,13 +503,19 @@ cb_astro_update(SoupSession *session,
64
         doc = get_xml_document(msg);
65
         if (G_LIKELY(doc)) {
66
             root_node = xmlDocGetRootElement(doc);
67
-            if (G_LIKELY(root_node))
68
-                if (parse_astrodata(root_node, data->astrodata)) {
69
-                    /* schedule next update */
70
-                    data->astro_update->attempt = 0;
71
-                    data->astro_update->last = now_t;
72
-                    parsing_error = FALSE;
73
+            if (G_LIKELY(root_node)) {
74
+                for (child_node = root_node->children; child_node;
75
+                     child_node = child_node->next) {
76
+                    if (child_node->type == XML_ELEMENT_NODE) {
77
+                        if (parse_astrodata(child_node, data->astrodata)) {
78
+                            /* schedule next update */
79
+                            data->astro_update->attempt = 0;
80
+                            data->astro_update->last = now_t;
81
+                            parsing_error = FALSE;
82
+                        }
83
+                    }
84
                 }
85
+            }
86
             xmlFreeDoc(doc);
87
         }
88
         if (parsing_error)
89
@@ -580,8 +597,8 @@ update_handler(plugin_data *data)
90
 {
91
     gchar *url;
92
     gboolean night_time;
93
-    time_t now_t, end_t;
94
-    struct tm now_tm, end_tm;
95
+    time_t now_t;
96
+    struct tm now_tm;
97
 
98
     g_assert(data != NULL);
99
     if (G_UNLIKELY(data == NULL))
100
@@ -616,26 +633,22 @@ update_handler(plugin_data *data)
101
         data->astro_update->next = time_calc_hour(now_tm, 1);
102
         data->astro_update->started = TRUE;
103
 
104
-        /* calculate date range for request */
105
-        end_t = time_calc_day(now_tm, ASTRODATA_MAX_DAYS);
106
-        end_tm = *localtime(&end_t);
107
-
108
         /* build url */
109
-        url = g_strdup_printf("https://api.met.no/weatherapi/sunrise/1.1/?"
110
-                              "lat=%s;lon=%s;"
111
-                              "from=%04d-%02d-%02d;"
112
-                              "to=%04d-%02d-%02d",
113
+        url = g_strdup_printf("https://api.met.no/weatherapi"
114
+                              "/sunrise/2.0/?lat=%s&lon=%s&"
115
+                              "date=%04d-%02d-%02d&"
116
+                              "offset=%s&days=%u",
117
                               data->lat, data->lon,
118
                               now_tm.tm_year + 1900,
119
                               now_tm.tm_mon + 1,
120
                               now_tm.tm_mday,
121
-                              end_tm.tm_year + 1900,
122
-                              end_tm.tm_mon + 1,
123
-                              end_tm.tm_mday);
124
+                              data->offset,
125
+                              data->forecast_days);
126
 
127
         /* start receive thread */
128
         g_message(_("getting %s"), url);
129
-        weather_http_queue_request(data->session, url, cb_astro_update, data);
130
+        weather_http_queue_request(data->session, url,
131
+                                   cb_astro_update, data);
132
         g_free(url);
133
     }
134
 
135
@@ -647,10 +660,10 @@ update_handler(plugin_data *data)
136
         data->weather_update->started = TRUE;
137
 
138
         /* build url */
139
-        url =
140
-            g_strdup_printf("https://api.met.no/weatherapi"
141
-                            "/locationforecastlts/1.3/?lat=%s;lon=%s;msl=%d",
142
-                            data->lat, data->lon, data->msl);
143
+        url = g_strdup_printf("https://api.met.no/weatherapi"
144
+                              "/locationforecastlts/1.3/?lat=%s&lon=%s&"
145
+                              "msl=%d",
146
+                              data->lat, data->lon, data->msl);
147
 
148
         /* start receive thread */
149
         g_message(_("getting %s"), url);
150
@@ -707,7 +720,7 @@ schedule_next_wakeup(plugin_data *data)
151
 
152
     next_day_t = day_at_midnight(now_t, 1);
153
     diff = difftime(next_day_t, now_t);
154
-	data->next_wakeup_reason = "current astro data update";
155
+    data->next_wakeup_reason = "current astro data update";
156
     SCHEDULE_WAKEUP_COMPARE(data->astro_update->next,
157
                             "astro data download");
158
     SCHEDULE_WAKEUP_COMPARE(data->weather_update->next,
159
@@ -853,6 +866,12 @@ xfceweather_read_config(XfcePanelPlugin *plugin,
160
         data->timezone = g_strdup(value);
161
     }
162
 
163
+    value = xfce_rc_read_entry(rc, "offset", NULL);
164
+    if (value) {
165
+        g_free(data->offset);
166
+        data->offset = g_strdup(value);
167
+    }
168
+
169
     value = xfce_rc_read_entry(rc, "geonames_username", NULL);
170
     if (value) {
171
         g_free(data->geonames_username);
172
@@ -975,6 +994,8 @@ xfceweather_write_config(XfcePanelPlugin *plugin,
173
 
174
     xfce_rc_write_entry(rc, "timezone", data->timezone);
175
 
176
+    xfce_rc_write_entry(rc, "offset", data->offset);
177
+
178
     if (data->geonames_username)
179
         xfce_rc_write_entry(rc, "geonames_username", data->geonames_username);
180
 
181
@@ -1076,6 +1097,7 @@ write_cache_file(plugin_data *data)
182
     CACHE_APPEND("location_name=%s\n", data->location_name);
183
     CACHE_APPEND("lat=%s\n", data->lat);
184
     CACHE_APPEND("lon=%s\n", data->lon);
185
+    CACHE_APPEND("offset=%s\n", data->offset);
186
     g_string_append_printf(out, "msl=%d\n", data->msl);
187
     g_string_append_printf(out, "timeslices=%d\n", wd->timeslices->len);
188
     if (G_LIKELY(data->weather_update)) {
189
@@ -1190,7 +1212,7 @@ read_cache_file(plugin_data *data)
190
     xml_location *loc = NULL;
191
     xml_astro *astro = NULL;
192
     time_t now_t = time(NULL), cache_date_t;
193
-    gchar *file, *locname = NULL, *lat = NULL, *lon = NULL, *group = NULL;
194
+    gchar *file, *locname = NULL, *lat = NULL, *lon = NULL, *group = NULL, *offset = NULL;
195
     gchar *timestring;
196
     gint msl, num_timeslices = 0, i, j;
197
 
198
@@ -1225,7 +1247,8 @@ read_cache_file(plugin_data *data)
199
     locname = g_key_file_get_string(keyfile, group, "location_name", NULL);
200
     lat = g_key_file_get_string(keyfile, group, "lat", NULL);
201
     lon = g_key_file_get_string(keyfile, group, "lon", NULL);
202
-    if (locname == NULL || lat == NULL || lon == NULL) {
203
+    offset = g_key_file_get_string(keyfile, group, "offset", NULL);
204
+    if (locname == NULL || lat == NULL || lon == NULL || offset == NULL) {
205
         CACHE_FREE_VARS();
206
         weather_debug("Required values are missing in the cache file, "
207
                       "reading cache file aborted.");
208
@@ -1236,7 +1259,8 @@ read_cache_file(plugin_data *data)
209
         num_timeslices = g_key_file_get_integer(keyfile, group,
210
                                                 "timeslices", &err);
211
     if (err || strcmp(lat, data->lat) || strcmp(lon, data->lon) ||
212
-        msl != data->msl || num_timeslices < 1) {
213
+        strcmp(offset, data->offset) || msl != data->msl ||
214
+        num_timeslices < 1) {
215
         CACHE_FREE_VARS();
216
         weather_debug("The required values are not present in the cache file "
217
                       "or do not match the current plugin data. Reading "
218
@@ -1404,6 +1428,9 @@ update_weatherdata_with_reset(plugin_data *data)
219
     /* set location timezone */
220
     update_timezone(data);
221
 
222
+    /* set the offset of timezone */
223
+    update_offset(data);
224
+
225
     /* clear update times */
226
     init_update_infos(data);
227
 
228
@@ -1709,9 +1736,9 @@ weather_get_tooltip_text(const plugin_data *data)
229
             sunval = g_strdup(_("The sun never sets today."));
230
         } else {
231
             sunrise = format_date(data->current_astro->sunrise,
232
-                                  "%H:%M:%S", TRUE);
233
+                                  "%H:%M:%S", FALSE);
234
             sunset = format_date(data->current_astro->sunset,
235
-                                 "%H:%M:%S", TRUE);
236
+                                 "%H:%M:%S", FALSE);
237
             sunval =
238
                 g_strdup_printf(_("The sun rises at %s and sets at %s."),
239
                                 sunrise, sunset);
240
@@ -1999,6 +2026,7 @@ xfceweather_free(XfcePanelPlugin *plugin,
241
     g_free(data->location_name);
242
     g_free(data->scrollbox_font);
243
     g_free(data->timezone);
244
+    g_free(data->offset);
245
     g_free(data->timezone_initial);
246
     g_free(data->geonames_username);
247
 
248
@@ -2170,6 +2198,7 @@ weather_construct(XfcePanelPlugin *plugin)
249
 
250
     xfceweather_read_config(plugin, data);
251
     update_timezone(data);
252
+    update_offset(data);
253
     read_cache_file(data);
254
     update_current_conditions(data, TRUE);
255
     scrollbox_set_visible(data);
(-)files/patch-panel-plugin_weather.h (+19 lines)
Line 0 Link Here
1
--- panel-plugin/weather.h.orig	2018-09-22 10:58:51 UTC
2
+++ panel-plugin/weather.h
3
@@ -114,6 +114,7 @@ typedef struct {
4
     gchar *lon;
5
     gint msl;
6
     gchar *timezone;
7
+    gchar *offset;
8
     gchar *timezone_initial;
9
     gint cache_file_max_age;
10
     gboolean night_time;
11
@@ -143,6 +144,8 @@ void forecast_click(GtkWidget *widget,
12
 gchar *get_cache_directory(void);
13
 
14
 void update_timezone(plugin_data *data);
15
+
16
+void update_offset(plugin_data *data);
17
 
18
 void update_icon(plugin_data *data);
19
 

Return to bug 236166