summaryrefslogtreecommitdiffstats
path: root/meta-xfce/recipes-panel-plugins/weather/files/0001-Make-plugin-ready-for-met.no-locationforecast-1.2-AP.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-xfce/recipes-panel-plugins/weather/files/0001-Make-plugin-ready-for-met.no-locationforecast-1.2-AP.patch')
-rw-r--r--meta-xfce/recipes-panel-plugins/weather/files/0001-Make-plugin-ready-for-met.no-locationforecast-1.2-AP.patch162
1 files changed, 162 insertions, 0 deletions
diff --git a/meta-xfce/recipes-panel-plugins/weather/files/0001-Make-plugin-ready-for-met.no-locationforecast-1.2-AP.patch b/meta-xfce/recipes-panel-plugins/weather/files/0001-Make-plugin-ready-for-met.no-locationforecast-1.2-AP.patch
new file mode 100644
index 000000000..d4ad24054
--- /dev/null
+++ b/meta-xfce/recipes-panel-plugins/weather/files/0001-Make-plugin-ready-for-met.no-locationforecast-1.2-AP.patch
@@ -0,0 +1,162 @@
1From 1ff71669644a0b824a8a5ba9b40771ee4fb8a76b Mon Sep 17 00:00:00 2001
2From: Harald Judt <h.judt@gmx.at>
3Date: Wed, 28 May 2014 20:08:02 +0200
4Subject: [PATCH 1/2] Make plugin ready for met.no locationforecast-1.2 API
5 (bug #10916).
6
7http://api.yr.no/weatherapi/locationforecastlts/1.1/documentation#version_1_2___2014_05_20
8
9The updated API version uses CamelCase symbol names instead of UPPERCASE
10ones and has added some new names (like 'Drizzle'), which unfortunately
11have not been documented (yet?).
12
13What's more, the typo 'celcius' has been replaced by the fixed 'celsius',
14but luckily the plugin will not be affected by that change.
15
16What's a bit more unfortunate is that the existing icon themes do not
17cover the new symbol names, so one would have to create quite a lot of
18new icons. Also, new translations would have to be added for the symbols,
19and maybe existing ones would have to be altered. To prevent this, we're
20simply going to map the new symbols to existing ones as good as possible.
21This should be good enough for the time being.
22
23Upstream-Status: Applied
24---
25 panel-plugin/weather-parsers.c | 3 +-
26 panel-plugin/weather-translate.c | 70 +++++++++++++++++++++++++++++++++++++++-
27 panel-plugin/weather-translate.h | 2 ++
28 3 files changed, 73 insertions(+), 2 deletions(-)
29
30diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
31index 0f321ba..5a9b30a 100644
32--- a/panel-plugin/weather-parsers.c
33+++ b/panel-plugin/weather-parsers.c
34@@ -28,6 +28,7 @@
35 #define _XOPEN_SOURCE
36 #define _XOPEN_SOURCE_EXTENDED 1
37 #include "weather-parsers.h"
38+#include "weather-translate.h"
39 #include "weather-debug.h"
40
41 #include <time.h>
42@@ -220,8 +221,8 @@ parse_location(xmlNode *cur_node,
43 }
44 if (NODE_IS_TYPE(child_node, "symbol")) {
45 g_free(loc->symbol);
46- loc->symbol = PROP(child_node, "id");
47 loc->symbol_id = strtol(PROP(child_node, "number"), NULL, 10);
48+ loc->symbol = g_strdup(get_symbol_for_id(loc->symbol_id));
49 }
50 }
51
52diff --git a/panel-plugin/weather-translate.c b/panel-plugin/weather-translate.c
53index 0c1606d..c38919a 100644
54--- a/panel-plugin/weather-translate.c
55+++ b/panel-plugin/weather-translate.c
56@@ -29,6 +29,7 @@
57 #include "weather-translate.h"
58
59 #define DAY_LOC_N (sizeof(gchar) * 100)
60+#define NODATA "NODATA"
61
62
63 static const gchar *moon_phases[] = {
64@@ -117,7 +118,7 @@ static const symbol_desc symbol_to_desc[] = {
65
66 { 15, "FOG", N_("Fog"), N_("Fog") },
67
68- /* Symbols 16-19 are used for polar days */
69+ /* Symbols 16-19 are used for polar days (unused beginning with API version 1.2) */
70 { 16, "SUN", N_("Sunny"), N_("Clear") },
71 { 17, "LIGHTCLOUD", N_("Lightly cloudy"), N_("Lightly cloudy") },
72 { 18, "LIGHTRAINSUN", N_("Rain showers"), N_("Rain showers") },
73@@ -133,6 +134,73 @@ static const symbol_desc symbol_to_desc[] = {
74 #define NUM_SYMBOLS (sizeof(symbol_to_desc) / sizeof(symbol_to_desc[0]))
75
76
77+/*
78+ * API version 1.2, published in May 2014, introduced new symbols. We
79+ * try to match these with existing symbols, in order to be compatible
80+ * with existing icon themes and to maintain translation completeness.
81+ *
82+ * See http://api.met.no/weatherapi/weathericon/1.1/documentation
83+ * for a list of symbols. For a list of symbols with descriptions,
84+ * see http://om.yr.no/forklaring/symbol.
85+ */
86+gint
87+replace_symbol_id(gint id)
88+{
89+ /* Symbol ids greater than 100 are used for indicating polar
90+ * night. These ids are over the ordinary id + 100. Since we
91+ * don't support polar icons, we can simply subtract 100 to
92+ * get the non-polar symbol ids.
93+ */
94+ if (id > 100)
95+ id -= 100;
96+
97+ switch (id) {
98+ case 24: return 22; /* Light rain showers and thunder */
99+ case 25: return 6; /* Heavy rain showers and thunder */
100+ case 26: return 20; /* Light sleet showers and thunder */
101+ case 27: return 20; /* Heavy sleet showers and thunder */
102+ case 28: return 21; /* Light snow showers and thunder */
103+ case 29: return 21; /* Heavy snow showers and thunder */
104+ case 30: return 22; /* Light rain and thunder */
105+ case 31: return 23; /* Light sleet and thunder */
106+ case 32: return 23; /* Heavy sleet and thunder */
107+ case 33: return 14; /* Light snow and thunder */
108+ case 34: return 14; /* Heavy snow and thunder */
109+
110+ /* symbols 35-39 are unused */
111+
112+ case 40: return 5; /* Light rain showers */
113+ case 41: return 5; /* Heavy rain showers */
114+ case 42: return 7; /* Light sleet showers */
115+ case 43: return 7; /* Heavy sleet showers */
116+ case 44: return 8; /* Light snow showers */
117+ case 45: return 8; /* Heavy snow showers */
118+ case 46: return 9; /* Light rain */
119+ case 47: return 12; /* Light sleet */
120+ case 48: return 12; /* Heavy sleet */
121+ case 49: return 13; /* Light snow */
122+ case 50: return 13; /* Heavy snow */
123+ default: return id;
124+ }
125+}
126+
127+
128+const gchar *
129+get_symbol_for_id(gint id)
130+{
131+ if (G_UNLIKELY(id < 1))
132+ return NODATA;
133+
134+ if (id >= NUM_SYMBOLS)
135+ id = replace_symbol_id(id);
136+
137+ if (id < NUM_SYMBOLS)
138+ return symbol_to_desc[id-1].symbol;
139+
140+ return NODATA;
141+}
142+
143+
144 const gchar *
145 translate_desc(const gchar *desc,
146 const gboolean nighttime)
147diff --git a/panel-plugin/weather-translate.h b/panel-plugin/weather-translate.h
148index 2116795..854e24f 100644
149--- a/panel-plugin/weather-translate.h
150+++ b/panel-plugin/weather-translate.h
151@@ -24,6 +24,8 @@
152
153 G_BEGIN_DECLS
154
155+const gchar *get_symbol_for_id(gint id);
156+
157 const gchar *translate_desc(const gchar *desc,
158 gboolean nighttime);
159
160--
1611.8.3.1
162