diff --git a/data/org.gnome.shell.extensions.openweather.gschema.xml.in b/data/org.gnome.shell.extensions.openweather.gschema.xml.in index 8b6158a..be51e90 100644 --- a/data/org.gnome.shell.extensions.openweather.gschema.xml.in +++ b/data/org.gnome.shell.extensions.openweather.gschema.xml.in @@ -65,7 +65,7 @@ <_description>Choose whether to display wind direction through arrows or letters. - '2516479>Eivissa (CA)' + '-8.5211767,179.1976747>Vaiaku, Tuvalu>-1' <_summary>City to be displayed diff --git a/data/weather-settings.ui b/data/weather-settings.ui index 817e51d..5e48ef7 100644 --- a/data/weather-settings.ui +++ b/data/weather-settings.ui @@ -77,6 +77,23 @@ 3 + + + True + False + 5 + + Extensions default weather provider + http://openweathermap.org + http://forecast.io + + + + False + True + 4 + + True @@ -87,7 +104,7 @@ False False - 4 + 5 @@ -215,6 +232,24 @@ 1 + + + True + False + 5 + 0 + + Extensions default weather provider + http://openweathermap.org + http://forecast.io + + + + False + True + 2 + + True @@ -225,7 +260,7 @@ False False - 5 + 3 @@ -271,7 +306,7 @@ False True end - 6 + 4 @@ -286,18 +321,21 @@ - + + + dummy + dummy - 910 - 730 + 720 + 480 True True 20 @@ -309,12 +347,13 @@ natural none - + True - False - 5 + True + True + True - + True False True @@ -325,17 +364,18 @@ True True in - 200 + 300 250 True True tree-liststore - False + True 0 False 12 + 1 @@ -398,26 +438,31 @@ + + + + True + False + Locations + - True - True - 0 + False - + True False True True + 10 5 5 - True True False - Chose weather provider + Chose default weather provider 0 @@ -425,10 +470,10 @@ - + True False - Temperature Unit + Personal Api key from openweathermap.org 0 @@ -436,241 +481,315 @@ - + True False - Wind Speed Unit + + http://openweathermap.org + http://forecast.io + - 0 + 1 + 0 + + + + + True + True + 32 + 32 + + + 1 + 1 + + + + + True + True + True + 32 + + + 1 2 - + True False - Pressure Unit + Personal Api key from forecast.io 0 - 3 + 2 + + + 1 + + + + + True + False + Weather provider + + + 1 + False + + + + + True + False + True + True + 10 + 5 + 5 - + True False - Position in Panel + Temperature Unit 0 - 4 + 0 - + True False - Wind Direction by Arrows + Wind Speed Unit 0 - 5 + 1 - + True False - Translate Conditions + Pressure Unit 0 - 6 + 2 - + True False - Symbolic Icons + + °C + °F + K + °Ra + °Ré + °Rø + °De + °N + - 0 - 7 + 1 + 0 - + True False - Text on buttons + + km/h + mph + m/s + kn + ft/s + Beaufort + - 0 - 8 + 1 + 1 - + True False - Temperature in Panel + + hPa + inHg + bar + Pa + kPa + atm + at + Torr + psi + - 0 - 9 + 1 + 2 + + + 2 + + + + + True + False + Units + + + 2 + False + + + + + True + False + True + True + 10 + 5 + 5 - + True False - Conditions in Panel + Position in Panel 0 - 10 + 0 - + True False - Conditions in Forecast + Wind Direction by Arrows 0 - 11 + 1 - + True False - Center forecast + Translate Conditions 0 - 12 + 2 - + True False - Number of days in forecast + Symbolic Icons 0 - 13 + 3 - + True False - Maximal number of digits after the decimal point + Text on buttons 0 - 14 + 4 - + True False - Personal Api key from openweathermap.org + Temperature in Panel 0 - 15 + 5 - + True False - Personal Api key from forecast.io + Conditions in Panel 0 - 16 + 6 - + True False - - http://openweathermap.org - http://forecast.io - + Conditions in Forecast - 1 - 0 + 0 + 7 - + True False - - °C - °F - K - °Ra - °Ré - °Rø - °De - °N - + Center forecast - 1 - 1 + 0 + 8 - + True False - - km/h - mph - m/s - kn - ft/s - Beaufort - + Number of days in forecast - 1 - 2 + 0 + 9 - + True False - - hPa - inHg - bar - Pa - kPa - atm - at - Torr - psi - + Maximal number of digits after the decimal point - 1 - 3 + 0 + 10 @@ -685,7 +804,7 @@ 1 - 4 + 0 @@ -696,7 +815,7 @@ 1 - 5 + 1 @@ -707,7 +826,7 @@ 1 - 6 + 2 @@ -718,7 +837,7 @@ 1 - 7 + 3 @@ -729,7 +848,7 @@ 1 - 8 + 4 @@ -740,7 +859,7 @@ 1 - 9 + 5 @@ -751,7 +870,7 @@ 1 - 10 + 6 @@ -762,7 +881,7 @@ 1 - 11 + 7 @@ -773,7 +892,7 @@ 1 - 12 + 8 @@ -794,7 +913,7 @@ 1 - 13 + 9 @@ -810,38 +929,23 @@ 1 - 14 - - - - - True - True - 32 - 32 - - - 1 - 15 - - - - - True - True - True - 32 - - - 1 - 16 + 10 - True - True - 1 + 3 + + + + + True + False + Layout + + + 3 + False diff --git a/src/extension.js b/src/extension.js index 77dff4b..8a80544 100644 --- a/src/extension.js +++ b/src/extension.js @@ -83,6 +83,7 @@ const OPENWEATHER_FC_API_KEY = 'appid-fc'; // Keep enums in sync with GSettings schemas const WeatherProvider = { + DEFAULT: -1, OPENWEATHERMAP: 0, FORECAST_IO: 1 }; @@ -351,11 +352,11 @@ const OpenweatherMenuButton = new Lang.Class({ this._settings = Convenience.getSettings(OPENWEATHER_SETTINGS_SCHEMA); if (this._cities.length === 0) - this._cities = "-8.5211767,179.1976747>Vaiaku, Tuvalu"; + this._cities = "-8.5211767,179.1976747>Vaiaku, Tuvalu>-1"; this._settingsC = this._settings.connect("changed", Lang.bind(this, function() { if (this._cities.length === 0) - this._cities = "-8.5211767,179.1976747>Vaiaku, Tuvalu"; + this._cities = "-8.5211767,179.1976747>Vaiaku, Tuvalu>-1"; this.rebuildCurrentWeatherUi(); this.rebuildFutureWeatherUi(); if (this.providerChanged()) { @@ -433,13 +434,13 @@ const OpenweatherMenuButton = new Lang.Class({ get _weather_provider() { if (!this._settings) this.loadConfig(); - return this._settings.get_enum(OPENWEATHER_PROVIDER_KEY); - }, - set _weather_provider(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_enum(OPENWEATHER_PROVIDER_KEY, v); + let provider = this.extractProvider(this._city); + + if (provider == WeatherProvider.DEFAULT) + provider = this._settings.get_enum(OPENWEATHER_PROVIDER_KEY); + + return provider; }, get _units() { @@ -448,60 +449,30 @@ const OpenweatherMenuButton = new Lang.Class({ return this._settings.get_enum(OPENWEATHER_UNIT_KEY); }, - set _units(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_enum(OPENWEATHER_UNIT_KEY, v); - }, - get _wind_speed_units() { if (!this._settings) this.loadConfig(); return this._settings.get_enum(OPENWEATHER_WIND_SPEED_UNIT_KEY); }, - set _wind_speed_units(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_enum(OPENWEATHER_WIND_SPEED_UNIT_KEY, v); - }, - get _wind_direction() { if (!this._settings) this.loadConfig(); return this._settings.get_boolean(OPENWEATHER_WIND_DIRECTION_KEY); }, - set _wind_direction(v) { - if (!this._settings) - this.loadConfig(); - return this._settings.set_boolean(OPENWEATHER_WIND_DIRECTION_KEY, v); - }, - get _pressure_units() { if (!this._settings) this.loadConfig(); return this._settings.get_enum(OPENWEATHER_PRESSURE_UNIT_KEY); }, - set _pressure_units(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_enum(OPENWEATHER_PRESSURE_UNIT_KEY, v); - }, - get _cities() { if (!this._settings) this.loadConfig(); return this._settings.get_string(OPENWEATHER_CITY_KEY); }, - set _cities(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_string(OPENWEATHER_CITY_KEY, v); - }, - get _actual_city() { if (!this._settings) this.loadConfig(); @@ -559,104 +530,48 @@ const OpenweatherMenuButton = new Lang.Class({ return cities; }, - set _city(v) { - let cities = this._cities; - cities = cities.split(" && "); - if (cities && typeof cities == "string") - cities = [cities]; - if (!cities[0]) - cities = []; - cities.splice(this.actual_city, 1, v); - cities = cities.join(" && "); - if (typeof cities != "string") - cities = cities[0]; - this._cities = cities; - }, - get _translate_condition() { if (!this._settings) this.loadConfig(); return this._settings.get_boolean(OPENWEATHER_TRANSLATE_CONDITION_KEY); }, - set _translate_condition(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_boolean(OPENWEATHER_TRANSLATE_CONDITION_KEY, v); - }, - get _getIconType() { if (!this._settings) this.loadConfig(); return this._settings.get_boolean(OPENWEATHER_USE_SYMBOLIC_ICONS_KEY) ? 1 : 0; }, - set _getIconType(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_boolean(OPENWEATHER_USE_SYMBOLIC_ICONS_KEY, v); - }, - get _use_text_on_buttons() { if (!this._settings) this.loadConfig(); return this._settings.get_boolean(OPENWEATHER_USE_TEXT_ON_BUTTONS_KEY) ? 1 : 0; }, - set _use_text_on_buttons(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_boolean(OPENWEATHER_USE_TEXT_ON_BUTTONS_KEY, v); - }, - get _text_in_panel() { if (!this._settings) this.loadConfig(); return this._settings.get_boolean(OPENWEATHER_SHOW_TEXT_IN_PANEL_KEY); }, - set _text_in_panel(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_boolean(OPENWEATHER_SHOW_TEXT_IN_PANEL_KEY, v); - }, - get _position_in_panel() { if (!this._settings) this.loadConfig(); return this._settings.get_enum(OPENWEATHER_POSITION_IN_PANEL_KEY); }, - set _position_in_panel(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_enum(OPENWEATHER_POSITION_IN_PANEL_KEY, v); - }, - get _comment_in_panel() { if (!this._settings) this.loadConfig(); return this._settings.get_boolean(OPENWEATHER_SHOW_COMMENT_IN_PANEL_KEY); }, - set _comment_in_panel(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_boolean(OPENWEATHER_SHOW_COMMENT_IN_PANEL_KEY, v); - }, - get _comment_in_forecast() { if (!this._settings) this.loadConfig(); return this._settings.get_boolean(OPENWEATHER_SHOW_COMMENT_IN_FORECAST_KEY); }, - set _comment_in_forecast(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_boolean(OPENWEATHER_SHOW_COMMENT_IN_FORECAST_KEY, v); - }, - get _refresh_interval_current() { if (!this._settings) this.loadConfig(); @@ -664,12 +579,6 @@ const OpenweatherMenuButton = new Lang.Class({ return ((v >= 600) ? v : 600); }, - set _refresh_interval_current(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_int(OPENWEATHER_REFRESH_INTERVAL_CURRENT, ((v >= 600) ? v : 600)); - }, - get _refresh_interval_forecast() { if (!this._settings) this.loadConfig(); @@ -677,48 +586,24 @@ const OpenweatherMenuButton = new Lang.Class({ return ((v >= 600) ? v : 600); }, - set _refresh_interval_forecast(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_int(OPENWEATHER_REFRESH_INTERVAL_FORECAST, ((v >= 600) ? v : 600)); - }, - get _center_forecast() { if (!this._settings) this.loadConfig(); return this._settings.get_boolean(OPENWEATHER_CENTER_FORECAST_KEY); }, - set _center_forecast(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_boolean(OPENWEATHER_CENTER_FORECAST_KEY, v); - }, - get _days_forecast() { if (!this._settings) this.loadConfig(); return this._settings.get_int(OPENWEATHER_DAYS_FORECAST); }, - set _days_forecast(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_int(OPENWEATHER_DAYS_FORECAST, v); - }, - get _decimal_places() { if (!this._settings) this.loadConfig(); return this._settings.get_int(OPENWEATHER_DECIMAL_PLACES); }, - set _decimal_places(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_int(OPENWEATHER_DECIMAL_PLACES, v); - }, - get _appid() { if (!this._settings) this.loadConfig(); @@ -726,12 +611,6 @@ const OpenweatherMenuButton = new Lang.Class({ return (key.length == 32) ? key : ''; }, - set _appid(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_string(OPENWEATHER_OWM_API_KEY, v); - }, - get _appid_fc() { if (!this._settings) this.loadConfig(); @@ -739,12 +618,6 @@ const OpenweatherMenuButton = new Lang.Class({ return (key.length == 32) ? key : ''; }, - set _appid_fc(v) { - if (!this._settings) - this.loadConfig(); - this._settings.set_string(OPENWEATHER_FC_API_KEY, v); - }, - rebuildButtonMenu: function() { if (this._buttonBox) { if (this._buttonBox1) { @@ -870,15 +743,6 @@ const OpenweatherMenuButton = new Lang.Class({ return arguments[0].split(">")[1]; }, - extractCity: function() { - if (!arguments[0]) - return ""; - let city = this.extractLocation(arguments[0]); - if (city.indexOf("(") == -1) - return _("Invalid city"); - return city.split("(")[0].trim(); - }, - extractCoord: function() { let coords = 0; @@ -893,6 +757,16 @@ const OpenweatherMenuButton = new Lang.Class({ return coords; }, + extractProvider: function() { + if (!arguments[0]) + return -1; + if (arguments[0].split(">")[2] === undefined) + return -1; + if (isNaN(parseInt(arguments[0].split(">")[2]))) + return -1; + return parseInt(arguments[0].split(">")[2]); + }, + _onPreferencesActivate: function() { this.menu.actor.hide(); Util.spawn(["gnome-shell-extension-prefs", "openweather-extension@jenslody.de"]); diff --git a/src/prefs.js b/src/prefs.js index d0c4d6a..9e5fdcf 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -69,13 +69,19 @@ const OPENWEATHER_URL_BASE = 'https://open.mapquestapi.com/nominatim/v1/'; const OPENWEATHER_URL_FIND = OPENWEATHER_URL_BASE + 'search.php'; const OPENWEATHER_URL_REVERSE = OPENWEATHER_URL_BASE + 'reverse.php'; +const WeatherProvider = { + DEFAULT: -1, + OPENWEATHERMAP: 0, + FORECAST_IO: 1 +}; + let _httpSession; let mCities = null; let inRealize = false; -let defaultSize = [-1,-1]; +let defaultSize = [-1, -1]; const WeatherPrefsWidget = new GObject.Class({ Name: 'OpenWeatherExtension.Prefs.Widget', @@ -100,7 +106,7 @@ const WeatherPrefsWidget = new GObject.Class({ this.add(this.MainWidget); this.MainWidget.connect('realize', Lang.bind(this, function() { - if ( inRealize ) + if (inRealize) return; inRealize = true; @@ -123,9 +129,11 @@ const WeatherPrefsWidget = new GObject.Class({ this.editWidget = this.Window.get_object("edit-widget"); this.editName = this.Window.get_object("edit-name"); this.editCoord = this.Window.get_object("edit-coord"); + this.editCombo = this.Window.get_object("edit-combo"); this.searchWidget = this.Window.get_object("search-widget"); this.searchMenu = this.Window.get_object("search-menu"); this.searchName = this.Window.get_object("search-name"); + this.searchCombo = this.Window.get_object("search-combo"); this.spinner = this.Window.get_object("spinner"); this.searchName.connect("icon-release", Lang.bind(this, this.clearEntry)); @@ -182,15 +190,12 @@ const WeatherPrefsWidget = new GObject.Class({ let newCity = arguments[0]; - if (Number(newCity.length) < 1) - { + if (Number(newCity.length) < 1) { let item = new Gtk.MenuItem({ label: _("\"%s\" not found").format(location) }); this.searchMenu.append(item); - } - else - { + } else { var m = {}; for (var i in newCity) { @@ -212,6 +217,7 @@ const WeatherPrefsWidget = new GObject.Class({ })); let column = new Gtk.TreeViewColumn(); + column.set_title(_("Location")); this.treeview.append_column(column); let renderer = new Gtk.CellRendererText(); @@ -220,6 +226,15 @@ const WeatherPrefsWidget = new GObject.Class({ column.set_cell_data_func(renderer, function() { arguments[1].markup = arguments[2].get_value(arguments[3], 0); }); + column = new Gtk.TreeViewColumn(); + column.set_title(_("Provider")); + this.treeview.append_column(column); + + column.pack_start(renderer, null); + + column.set_cell_data_func(renderer, function() { + arguments[1].markup = arguments[2].get_value(arguments[3], 1); + }); let theObjects = this.Window.get_objects(); @@ -311,6 +326,7 @@ const WeatherPrefsWidget = new GObject.Class({ for (let i in city) { current = this.liststore.append(); this.liststore.set_value(current, 0, this.extractLocation(city[i])); + this.liststore.set_value(current, 1, this.getProviderShort(this.extractProvider(city[i]))); } } @@ -396,18 +412,20 @@ const WeatherPrefsWidget = new GObject.Class({ let ac = this.actual_city; this.editName.set_text(this.extractLocation(city[ac])); this.editCoord.set_text(this.extractCoord(city[ac])); + this.editCombo.set_active(this.extractProvider(city[ac]) + 1); this.editWidget.show_all(); return 0; }, searchSave: function() { - let cityText = this.searchName.get_text().split(/\[/)[0]; + let location = this.searchName.get_text().split(/\[/)[0]; let coord = this.searchName.get_text().split(/\[/)[1].split(/\]/)[0]; + let provider = this.searchCombo.get_active() - 1; if (this.city) - this.city = this.city + " && " + coord + ">" + cityText; + this.city = this.city + " && " + coord + ">" + location + ">" + provider; else - this.city = coord + ">" + cityText; + this.city = coord + ">" + location + ">" + provider; this.searchWidget.hide(); return 0; @@ -424,7 +442,8 @@ const WeatherPrefsWidget = new GObject.Class({ let ac = this.actual_city; let location = this.editName.get_text(); let coord = this.editCoord.get_text(); - theCity[ac] = coord + ">" + location; + let provider = this.editCombo.get_active() - 1; + theCity[ac] = coord + ">" + location + ">" + provider; if (theCity.length > 1) this.city = theCity.join(" && "); @@ -782,16 +801,48 @@ const WeatherPrefsWidget = new GObject.Class({ this.Settings.set_string(OPENWEATHER_FC_API_KEY, v); }, - extractLocation: function(a) { - if (a.search(">") == -1) + extractLocation: function() { + if (!arguments[0]) + return ""; + + if (arguments[0].search(">") == -1) return _("Invalid city"); - return a.split(">")[1]; + return arguments[0].split(">")[1]; }, - extractCoord: function(a) { - if (a.search(">") == -1) + extractCoord: function() { + if (!arguments[0]) return 0; - return a.split(">")[0]; + + if (arguments[0].search(">") == -1) + return 0; + return arguments[0].split(">")[0]; + }, + + extractProvider: function() { + if (!arguments[0]) + return -1; + if (arguments[0].split(">")[2] === undefined) + return -1; + if (isNaN(parseInt(arguments[0].split(">")[2]))) + return -1; + return parseInt(arguments[0].split(">")[2]); + }, + + getProviderShort: function() { + let provider = arguments[0]; + if ( provider === undefined) + provider = this.extractProvider(this.city[this.actual_city]); + + switch (provider) { + case WeatherProvider.OPENWEATHERMAP: + return "openweathermap.org"; + case WeatherProvider.FORECAST_IO: + return "forecast.io"; + default: + case WeatherProvider.DEFAULT: + return _("default"); + } } });