From 192402b7b26832617f9a437858c989a05de9a832 Mon Sep 17 00:00:00 2001 From: None Date: Sun, 5 Apr 2015 10:13:31 +0200 Subject: [PATCH] Add edit-dialog and make it workable; change search-dialog; code formatting. --- data/weather-settings.ui | 343 ++++++++++++++++++++++++++++----------- src/extension.js | 31 ++-- src/prefs.js | 79 ++++----- 3 files changed, 299 insertions(+), 154 deletions(-) diff --git a/data/weather-settings.ui b/data/weather-settings.ui index de6b7fc..aa59956 100644 --- a/data/weather-settings.ui +++ b/data/weather-settings.ui @@ -2,105 +2,169 @@ - - True + False - 10 - 10 - vertical - - - True - False - start - True - Search by (or edit) name - - - False - False - 0 - - - - - 350 - True - True - True - edit-find-symbolic - edit-clear-symbolic - Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/ - Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/ - Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/ - Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/ - e.g. Te Auala o Tuvalu, Funafuti, Tuvalu - - - False - True - 1 - - - - - True - False - start - True - Search by (or edit) coordinates - - - False - True - 2 - - + True + center-on-parent + True + True + dialog - - True - True - True - edit-find-symbolic - edit-clear-symbolic - False - False - e.g. -8.5202006,179.1976286 - - - False - True - 3 - - - - + True False + 10 + 10 10 10 + vertical + + + True + False + start + True + Edit name + + + False + False + 0 + + + + + 350 + True + True + True + edit-clear-symbolic + False + False + Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/ + Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/ + Clear the entry + + + False + True + 1 + + + + + True + False + start + True + Edit coordinates + + + False + True + 2 + + + + + True + True + True + edit-clear-symbolic + False + False + Clear entry + + + False + True + 3 + + + + + True + False + 10 + 10 + + + False + False + 4 + + + + + True + False + baseline + False + + + gtk-cancel + True + True + True + start + True + 0.46000000834465027 + + + False + False + 0 + + + + + + + + gtk-save + True + True + True + True + + + False + True + end + 2 + + + + + False + True + end + 6 + + - - False - False - 4 - + + + False + center-on-parent + True + True + dialog - + True False - baseline - False + 10 + 10 + vertical - - gtk-cancel + True - True - True + False start - True - 0.46000000834465027 + True + Search by location or coordinates False @@ -109,30 +173,113 @@ - + + True + False + 5 + + + 350 + True + True + True + edit-find-symbolic + edit-clear-symbolic + Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/ + Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/ + Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/ + Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/ + e.g. Vaiaku, Tuvalu or -8.5211767,179.1976747 + + + False + True + 0 + + + + + gtk-find + True + True + True + True + + + False + True + 1 + + + + + False + True + 1 + + + + + True + False + 10 + 10 + + + False + False + 5 + - - gtk-save + True - True - True - True + False + baseline + False + + + gtk-cancel + True + True + True + start + True + 0.46000000834465027 + + + False + False + 0 + + + + + + + + gtk-save + True + True + True + True + + + False + True + end + 2 + + False True end - 2 + 6 - - False - True - end - 6 - diff --git a/src/extension.js b/src/extension.js index 9eeeb73..714ceb3 100644 --- a/src/extension.js +++ b/src/extension.js @@ -326,7 +326,7 @@ const OpenweatherMenuButton = new Lang.Class({ this.weatherProvider = "https://forecast.io/"; this.fc_locale = 'en'; - let fc_locales = ['bs','de','en','es','fr','it','nl','pl','pt','ru','tet','x-pig-latin']; + let fc_locales = ['bs', 'de', 'en', 'es', 'fr', 'it', 'nl', 'pl', 'pt', 'ru', 'tet', 'x-pig-latin']; let locale = GLib.get_language_names()[0]; if (locale.indexOf('_') != -1) @@ -337,14 +337,11 @@ const OpenweatherMenuButton = new Lang.Class({ }, getWeatherProviderURL: function() { - let url=""; - if (this._weather_provider == WeatherProvider.FORECAST_IO) - { + let url = ""; + if (this._weather_provider == WeatherProvider.FORECAST_IO) { url = "https://forecast.io/#/f/"; url += this.extractCoord(this._city); - } - else - { + } else { url = "https://openweathermap.org"; url += "/city/" + this.owmCityId; if (this._appid) @@ -1087,16 +1084,16 @@ weather-storm.png = weather-storm-symbolic.svg }, fcGet_weather_icon: function(icon) { -// clear-day weather-clear-day -// clear-night weather-clear-night -// rain weather-showers -// snow weather-snow -// sleet weather-snow -// wind weather-storm -// fog weather-fog -// cloudy weather-overcast -// partly-cloudy-day weather-few-clouds -// partly-cloudy-night weather-few-clouds-night + // clear-day weather-clear-day + // clear-night weather-clear-night + // rain weather-showers + // snow weather-snow + // sleet weather-snow + // wind weather-storm + // fog weather-fog + // cloudy weather-overcast + // partly-cloudy-day weather-few-clouds + // partly-cloudy-night weather-few-clouds-night switch (icon) { case 'wind': diff --git a/src/prefs.js b/src/prefs.js index 78988ea..7d554fa 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -102,6 +102,10 @@ const WeatherPrefsWidget = new GObject.Class({ this.MainWidget = this.Window.get_object("main-widget"); this.treeview = this.Window.get_object("tree-treeview"); this.liststore = this.Window.get_object("tree-liststore"); + 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.Window.get_object("tree-toolbutton-add").connect("clicked", Lang.bind(this, function() { this.addCity(); @@ -119,6 +123,14 @@ const WeatherPrefsWidget = new GObject.Class({ this.selectionChanged(selection); })); + this.Window.get_object("button-edit-cancel").connect("clicked", Lang.bind(this, function() { + this.editCancel(); + })); + + this.Window.get_object("button-edit-save").connect("clicked", Lang.bind(this, function() { + this.editSave(); + })); + let column = new Gtk.TreeViewColumn(); this.treeview.append_column(column); @@ -420,54 +432,43 @@ const WeatherPrefsWidget = new GObject.Class({ if (!city.length) return 0; let ac = this.actual_city; - let textDialog = _("Remove %s ?").format(this.extractLocation(city[ac])); - let dialog = new Gtk.Dialog({ - title: "" - }); - let label = new Gtk.Label({ - label: textDialog - }); - label.margin_bottom = 12; - - dialog.set_border_width(12); - dialog.set_modal(1); - dialog.set_resizable(0); - //dialog.set_transient_for(***** Need parent Window *****); + this.editName.set_text(this.extractLocation(city[ac])); + this.editCoord.set_text(this.extractCoord(city[ac])); + this.editWidget.show_all(); + return 0; + }, - dialog.add_button(Gtk.STOCK_NO, 0); - let d = dialog.add_button(Gtk.STOCK_YES, 1); + editSave: function() { + let theCity = this.city.split(" && "); - d.set_can_default(true); - dialog.set_default(d); + if (theCity.length === 0) + return 0; + if (theCity.length > 0 && typeof theCity != "object") + theCity = [theCity]; - let dialog_area = dialog.get_content_area(); - dialog_area.pack_start(label, 0, 0, 0); - dialog.connect("response", Lang.bind(this, function(w, response_id) { - if (response_id) { - if (city.length === 0) - city = []; + let ac = this.actual_city; + let location = this.editName.get_text(); + let coord = this.editCoord.get_text(); + theCity[ac] = coord + ">" + location; - if (city.length > 0 && typeof city != "object") - city = [city]; + if (theCity.length > 1) + this.city = theCity.join(" && "); + else if (theCity[0]) + this.city = theCity[0]; - if (city.length > 0) - city.splice(ac, 1); + this.editWidget.hide(); - if (city.length > 1) - this.city = city.join(" && "); - else if (city[0]) - this.city = city[0]; - else - this.city = ""; - } - dialog.hide(); - return 0; - })); + this.actual_city = ac; - dialog.show_all(); return 0; }, + editCancel: function() { + this.editName.set_text(""); + this.editCoord.set_text(""); + this.editWidget.hide(); + }, + changeSelection: function() { let path = this.actual_city; if (arguments[0]) @@ -817,7 +818,7 @@ const WeatherPrefsWidget = new GObject.Class({ return a.split(">")[1]; }, - extractId: function(a) { + extractCoord: function(a) { if (a.search(">") == -1) return 0; return a.split(">")[0];