[gnome-weather/ewlsh/weather-icons: 2/2] Bundle colorful weather icons as resources. - Moves icon lookup logic to Weather for more finegraine
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-weather/ewlsh/weather-icons: 2/2] Bundle colorful weather icons as resources. - Moves icon lookup logic to Weather for more finegraine
- Date: Tue, 11 Aug 2020 16:41:57 +0000 (UTC)
commit ac4e51efc8902e47c2e4128db0a67052d1e136da
Author: Evan Welsh <contact evanwelsh com>
Date: Tue Aug 11 11:41:34 2020 -0500
Bundle colorful weather icons as resources.
- Moves icon lookup logic to Weather for more finegrained options.
data/org.gnome.Weather.data.gresource.xml | 14 ++++
src/app/city.js | 109 +++++++++++++++++++++++++++++-
2 files changed, 122 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.Weather.data.gresource.xml b/data/org.gnome.Weather.data.gresource.xml
index eb357d3..b58e0b0 100644
--- a/data/org.gnome.Weather.data.gresource.xml
+++ b/data/org.gnome.Weather.data.gresource.xml
@@ -9,6 +9,20 @@
<file preprocess="xml-stripblanks">hour-entry.ui</file>
<file preprocess="xml-stripblanks">day-entry.ui</file>
<file>application.css</file>
+ <!-- Status Icons -->
+ <file>status/weather-clear.svg</file>
+ <file>status/weather-clear-night.svg</file>
+ <file>status/weather-few-clouds.svg</file>
+ <file>status/weather-few-clouds-night.svg</file>
+ <file>status/weather-fog.svg</file>
+ <file>status/weather-overcast.svg</file>
+ <file>status/weather-severe-alert.svg</file>
+ <file>status/weather-showers.svg</file>
+ <file>status/weather-showers-scattered.svg</file>
+ <file>status/weather-snow.svg</file>
+ <file>status/weather-storm.svg</file>
+ <file>status/weather-tornado.svg</file>
+ <file>status/weather-windy.svg</file>
</gresource>
<gresource prefix="/org/gnome/shell">
<file>ShellWeatherIntegration.xml</file>
diff --git a/src/app/city.js b/src/app/city.js
index dce7850..ba3535c 100644
--- a/src/app/city.js
+++ b/src/app/city.js
@@ -34,6 +34,105 @@ const SCROLLING_ANIMATION_TIME = 400000; //us
const UPDATED_TIME_TIMEOUT = 60; //s
+/**
+ * Ported from 'gweather_info_get_icon_name' in libgweather.
+ * Converts the current weather conditions into the appropriate
+ * resource name.
+ *
+ * @param {GWeather.Info} info a GWeather.Info object
+ * @returns {string} the resource name associated with the current weather conditions
+ */
+function get_icon_name(info) {
+ const [significant, phenomenon, qualifier] = info.get_value_conditions();
+ const [valid, sky] = info.get_value_sky();
+
+ if (significant) {
+ if (phenomenon != GWeather.ConditionPhenomenon.NONE &&
+ qualifier == GWeather.ConditionQualifier.THUNDERSTORM)
+ return "weather-storm";
+
+ switch (phenomenon) {
+ case GWeather.ConditionPhenomenon.INVALID:
+ case GWeather.ConditionPhenomenon.LAST:
+ case GWeather.ConditionPhenomenon.NONE:
+ break;
+
+ case GWeather.ConditionPhenomenon.DRIZZLE:
+ case GWeather.ConditionPhenomenon.RAIN:
+ case GWeather.ConditionPhenomenon.UNKNOWN_PRECIPITATION:
+ case GWeather.ConditionPhenomenon.HAIL:
+ case GWeather.ConditionPhenomenon.SMALL_HAIL:
+ return "weather-showers";
+
+ case GWeather.ConditionPhenomenon.SNOW:
+ case GWeather.ConditionPhenomenon.SNOW_GRAINS:
+ case GWeather.ConditionPhenomenon.ICE_PELLETS:
+ case GWeather.ConditionPhenomenon.ICE_CRYSTALS:
+ return "weather-snow";
+
+ case GWeather.ConditionPhenomenon.TORNADO:
+ return "weather-tornado";
+
+ case GWeather.ConditionPhenomenon.SQUALL:
+ return "weather-storm";
+
+ case GWeather.ConditionPhenomenon.MIST:
+ case GWeather.ConditionPhenomenon.FOG:
+ case GWeather.ConditionPhenomenon.SMOKE:
+ case GWeather.ConditionPhenomenon.VOLCANIC_ASH:
+ case GWeather.ConditionPhenomenon.SAND:
+ case GWeather.ConditionPhenomenon.HAZE:
+ case GWeather.ConditionPhenomenon.SPRAY:
+ case GWeather.ConditionPhenomenon.DUST:
+ case GWeather.ConditionPhenomenon.SANDSTORM:
+ case GWeather.ConditionPhenomenon.DUSTSTORM:
+ case GWeather.ConditionPhenomenon.FUNNEL_CLOUD:
+ case GWeather.ConditionPhenomenon.DUST_WHIRLS:
+ return "weather-fog";
+ }
+ }
+
+ const daytime = info.is_daytime();
+
+ if (valid) {
+ switch (sky) {
+ case GWeather.Sky.INVALID:
+ case GWeather.Sky.LAST:
+ case GWeather.Sky.CLEAR:
+ if (daytime)
+ return "weather-clear";
+ else
+ return "weather-clear-night";
+
+ case GWeather.Sky.BROKEN:
+ case GWeather.Sky.SCATTERED:
+ case GWeather.Sky.FEW:
+ if (daytime)
+ return "weather-few-clouds";
+ else
+ return "weather-few-clouds-night";
+
+ case GWeather.Sky.OVERCAST:
+ return "weather-overcast";
+
+ default: /* unrecognized */
+ return null;
+ }
+ }
+
+ return null;
+}
+
+function get_icon_resource(info) {
+ const name = get_icon_name(info);
+
+ if (!name) {
+ return null;
+ }
+
+ return `/org/gnome/Weather/status/${name}.svg`;
+}
+
var WeatherWidget = GObject.registerClass({
Template: 'resource:///org/gnome/Weather/weather-widget.ui',
InternalChildren: ['contentFrame', 'outerGrid', 'conditionsImage',
@@ -202,7 +301,15 @@ var WeatherWidget = GObject.registerClass({
this._worldView.refilter();
- this._conditionsImage.icon_name = info.get_icon_name();
+ this._conditionsImage.clear();
+
+ const resource = get_icon_resource(info);
+
+ try {
+ this._conditionsImage.set_from_resource(resource);
+ } catch (err) {
+ log(`Failed to set weather icon from resource: ${resource}`);
+ }
const [, tempValue] = info.get_value_temp(GWeather.TemperatureUnit.DEFAULT);
this._temperatureLabel.label = '%.0f°'.format(tempValue);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]