From fa3052a3efbddc770c10db6763db5c0f77173967 Mon Sep 17 00:00:00 2001 From: Iakovos Gurulian Date: Fri, 3 Nov 2017 17:58:35 +0200 Subject: [PATCH] Fixed issue where if the name of the city is too long, the weather popup stretches over the length of the screen (the user can set the number of max characters to be displayed) --- ...e.shell.extensions.openweather.gschema.xml | 4 +++ data/weather-settings.ui | 35 +++++++++++++++++++ src/darksky_net.js | 5 ++- src/extension.js | 8 +++++ src/openweathermap_org.js | 5 ++- src/prefs.js | 29 +++++++++++++++ 6 files changed, 84 insertions(+), 2 deletions(-) diff --git a/data/org.gnome.shell.extensions.openweather.gschema.xml b/data/org.gnome.shell.extensions.openweather.gschema.xml index c4cc15f..1c5c564 100644 --- a/data/org.gnome.shell.extensions.openweather.gschema.xml +++ b/data/org.gnome.shell.extensions.openweather.gschema.xml @@ -120,6 +120,10 @@ 600 Refresh interval (actual weather) + + 0 + Maximal length of the location text + 3600 Refresh interval (forecast) diff --git a/data/weather-settings.ui b/data/weather-settings.ui index 2dfad90..0a92492 100644 --- a/data/weather-settings.ui +++ b/data/weather-settings.ui @@ -175,6 +175,13 @@ 0.10000000000000001 2 + + 0 + 500 + 50 + 1 + 10 + True False @@ -1138,6 +1145,34 @@ 11 + + + True + False + start + True + Maximal number of characters in location label + + + 0 + 12 + + + + + True + True + number + max-loc-chars-adj + 5 + True + 0 + + + 1 + 12 + + 4 diff --git a/src/darksky_net.js b/src/darksky_net.js index f343acc..49495d7 100644 --- a/src/darksky_net.js +++ b/src/darksky_net.js @@ -174,7 +174,10 @@ function parseWeatherCurrent() { this._weatherInfo.text = weatherInfoC + ((weatherInfoC && weatherInfoT) ? _(", ") : "") + weatherInfoT; this._currentWeatherSummary.text = comment + _(", ") + temperature; - this._currentWeatherLocation.text = location; + if (this._loc_len_current != 0 && location.length > this._loc_len_current) + this._currentWeatherLocation.text = location.substring(0, (this._loc_len_current - 3)) + "..."; + else + this._currentWeatherLocation.text = location; this._currentWeatherCloudiness.text = parseInt(json.cloudCover * 100) + ' %'; this._currentWeatherHumidity.text = parseInt(json.humidity * 100) + ' %'; this._currentWeatherPressure.text = this.formatPressure(json.pressure); diff --git a/src/extension.js b/src/extension.js index 5b7c871..fc37c1f 100644 --- a/src/extension.js +++ b/src/extension.js @@ -86,6 +86,7 @@ const OPENWEATHER_USE_DEFAULT_OWM_API_KEY = 'use-default-owm-key'; const OPENWEATHER_OWM_API_KEY = 'appid'; const OPENWEATHER_OWM_DEFAULT_API_KEY = 'c93b4a667c8c9d1d1eb941621f899bb8'; const OPENWEATHER_FC_API_KEY = 'appid-fc'; +const OPENWEATHER_LOC_TEXT_LEN = 'location-text-length' // Keep enums in sync with GSettings schemas const WeatherProvider = { @@ -813,6 +814,13 @@ const OpenweatherMenuButton = new Lang.Class({ return ((v >= 600) ? v : 600); }, + get _loc_len_current() { + if (!this._settings) + this.loadConfig(); + let v = this._settings.get_int(OPENWEATHER_LOC_TEXT_LEN); + return ((v > 0) ? v : 0); + }, + get _center_forecast() { if (!this._settings) this.loadConfig(); diff --git a/src/openweathermap_org.js b/src/openweathermap_org.js index 0fc844f..d36414c 100644 --- a/src/openweathermap_org.js +++ b/src/openweathermap_org.js @@ -366,7 +366,10 @@ function parseWeatherCurrent() { this._weatherInfo.text = weatherInfoC + ((weatherInfoC && weatherInfoT) ? _(", ") : "") + weatherInfoT; this._currentWeatherSummary.text = comment + _(", ") + temperature; - this._currentWeatherLocation.text = location; + if (this._loc_len_current != 0 && location.length > this._loc_len_current) + this._currentWeatherLocation.text = location.substring(0, (this._loc_len_current - 3)) + "..."; + else + this._currentWeatherLocation.text = location; this._currentWeatherCloudiness.text = json.clouds.all + ' %'; this._currentWeatherHumidity.text = json.main.humidity + ' %'; this._currentWeatherPressure.text = this.formatPressure(json.main.pressure); diff --git a/src/prefs.js b/src/prefs.js index 096f487..e1e7f05 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -71,6 +71,7 @@ const OPENWEATHER_USE_DEFAULT_OWM_API_KEY = 'use-default-owm-key'; const OPENWEATHER_OWM_API_KEY = 'appid'; const OPENWEATHER_FC_API_KEY = 'appid-fc'; const OPENWEATHER_GC_APP_KEY = 'geolocation-appid-mapquest'; +const OPENWEATHER_LOC_TEXT_LEN = 'location-text-length' //URL const OPENWEATHER_URL_MAPQUEST_BASE = 'https://open.mapquestapi.com/nominatim/v1/'; @@ -396,6 +397,21 @@ const WeatherPrefsWidget = new GObject.Class({ arguments[1].markup = arguments[2].get_value(arguments[3], 1); }); + this.location_length_spin = this.Window.get_object("max_loc_chars"); + this.location_length_spin.set_value(this.loc_len_current); + // prevent from continously updating the value + this.locLenSpinTimeout = undefined; + this.location_length_spin.connect("value-changed", Lang.bind(this, function(button) { + + if (this.locLenSpinTimeout !== undefined) + Mainloop.source_remove(this.locLenSpinTimeout); + this.locLenSpinTimeout = Mainloop.timeout_add(250, Lang.bind(this, function() { + this.loc_len_current = button.get_value(); + return false; + })); + + })); + let theObjects = this.Window.get_objects(); for (let i in theObjects) { @@ -927,6 +943,19 @@ const WeatherPrefsWidget = new GObject.Class({ this.Settings.set_int(OPENWEATHER_REFRESH_INTERVAL_CURRENT, ((v >= 600) ? v : 600)); }, + get loc_len_current() { + if (!this.Settings) + this.loadConfig(); + let v = this.Settings.get_int(OPENWEATHER_LOC_TEXT_LEN); + return ((v > 0) ? v : 0); + }, + + set loc_len_current(v) { + if (!this.Settings) + this.loadConfig(); + this.Settings.set_int(OPENWEATHER_LOC_TEXT_LEN, ((v > 0) ? v : 0)); + }, + get refresh_interval_forecast() { if (!this.Settings) this.loadConfig();