Add edit-dialog and make it workable; change search-dialog; code formatting.

multiprovider
None 10 years ago
parent e1d4f402e9
commit 192402b7b2
  1. 343
      data/weather-settings.ui
  2. 31
      src/extension.js
  3. 79
      src/prefs.js

@ -2,105 +2,169 @@
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkBox" id="search-widget">
<property name="visible">True</property>
<object class="GtkWindow" id="edit-widget">
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Search by (or edit) name</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="search-name">
<property name="width_request">350</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="secondary_icon_name">edit-clear-symbolic</property>
<property name="primary_icon_tooltip_text" translatable="yes">Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/</property>
<property name="secondary_icon_tooltip_text" translatable="yes">Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/</property>
<property name="primary_icon_tooltip_markup" translatable="yes">Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/</property>
<property name="secondary_icon_tooltip_markup" translatable="yes">Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/</property>
<property name="placeholder_text" translatable="yes">e.g. Te Auala o Tuvalu, Funafuti, Tuvalu</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Search by (or edit) coordinates</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="destroy_with_parent">True</property>
<property name="hide_titlebar_when_maximized">True</property>
<property name="type_hint">dialog</property>
<child>
<object class="GtkEntry" id="search-coordinate">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="secondary_icon_name">edit-clear-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<property name="placeholder_text" translatable="yes">e.g. -8.5202006,179.1976286</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkSeparator" id="separator1">
<object class="GtkBox" id="edit-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Edit name</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="edit-name">
<property name="width_request">350</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="secondary_icon_name">edit-clear-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<property name="primary_icon_tooltip_text" translatable="yes">Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/</property>
<property name="secondary_icon_tooltip_text" translatable="yes">Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/</property>
<property name="secondary_icon_tooltip_markup" translatable="yes">Clear the entry</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Edit coordinates</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="edit-coord">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="secondary_icon_name">edit-clear-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<property name="secondary_icon_tooltip_text" translatable="yes">Clear entry</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkSeparator" id="separator2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">baseline</property>
<property name="vexpand">False</property>
<child>
<object class="GtkButton" id="button-edit-cancel">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
<property name="use_stock">True</property>
<property name="xalign">0.46000000834465027</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkButton" id="button-edit-save">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">6</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
</object>
<object class="GtkWindow" id="search-widget">
<property name="can_focus">False</property>
<property name="window_position">center-on-parent</property>
<property name="destroy_with_parent">True</property>
<property name="hide_titlebar_when_maximized">True</property>
<property name="type_hint">dialog</property>
<child>
<object class="GtkBox" id="box1">
<object class="GtkBox" id="search-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">baseline</property>
<property name="vexpand">False</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton" id="button-cancel">
<property name="label">gtk-cancel</property>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="use_stock">True</property>
<property name="xalign">0.46000000834465027</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Search by location or coordinates</property>
</object>
<packing>
<property name="expand">False</property>
@ -109,30 +173,113 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkBox" id="box3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">5</property>
<child>
<object class="GtkEntry" id="search-name">
<property name="width_request">350</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="secondary_icon_name">edit-clear-symbolic</property>
<property name="primary_icon_tooltip_text" translatable="yes">Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/</property>
<property name="secondary_icon_tooltip_text" translatable="yes">Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/</property>
<property name="primary_icon_tooltip_markup" translatable="yes">Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/</property>
<property name="secondary_icon_tooltip_markup" translatable="yes">Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/</property>
<property name="placeholder_text" translatable="yes">e.g. Vaiaku, Tuvalu or -8.5211767,179.1976747</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button-search-find">
<property name="label">gtk-find</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSeparator" id="separator1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button-save">
<property name="label">gtk-save</property>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="can_focus">False</property>
<property name="valign">baseline</property>
<property name="vexpand">False</property>
<child>
<object class="GtkButton" id="button-cancel">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
<property name="use_stock">True</property>
<property name="xalign">0.46000000834465027</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkButton" id="button-save">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
<property name="position">6</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">6</property>
</packing>
</child>
</object>
<object class="GtkListStore" id="tree-liststore">

@ -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':

@ -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];

Loading…
Cancel
Save