|
|
@ -88,7 +88,6 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
Window: new Gtk.Builder(), |
|
|
|
Window: new Gtk.Builder(), |
|
|
|
|
|
|
|
|
|
|
|
initWindow: function() { |
|
|
|
initWindow: function() { |
|
|
|
let that = this; |
|
|
|
|
|
|
|
mCities = null; |
|
|
|
mCities = null; |
|
|
|
|
|
|
|
|
|
|
|
this.Window.add_from_file(EXTENSIONDIR + "/weather-settings.ui"); |
|
|
|
this.Window.add_from_file(EXTENSIONDIR + "/weather-settings.ui"); |
|
|
@ -98,17 +97,17 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
this.liststore = this.Window.get_object("liststore"); |
|
|
|
this.liststore = this.Window.get_object("liststore"); |
|
|
|
this.Iter = this.liststore.get_iter_first(); |
|
|
|
this.Iter = this.liststore.get_iter_first(); |
|
|
|
|
|
|
|
|
|
|
|
this.Window.get_object("tree-toolbutton-add").connect("clicked", function() { |
|
|
|
this.Window.get_object("tree-toolbutton-add").connect("clicked", Lang.bind(this, function() { |
|
|
|
that.addCity(); |
|
|
|
this.addCity(); |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
this.Window.get_object("tree-toolbutton-remove").connect("clicked", function() { |
|
|
|
this.Window.get_object("tree-toolbutton-remove").connect("clicked", Lang.bind(this, function() { |
|
|
|
that.removeCity(); |
|
|
|
this.removeCity(); |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
this.Window.get_object("treeview-selection").connect("changed", function(selection) { |
|
|
|
this.Window.get_object("treeview-selection").connect("changed", Lang.bind(this, function(selection) { |
|
|
|
that.selectionChanged(selection); |
|
|
|
this.selectionChanged(selection); |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
this.treeview.set_model(this.liststore); |
|
|
|
this.treeview.set_model(this.liststore); |
|
|
|
|
|
|
|
|
|
|
@ -234,7 +233,6 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
addComboBox: function(a, b) { |
|
|
|
addComboBox: function(a, b) { |
|
|
|
let that = this; |
|
|
|
|
|
|
|
let cf = new Gtk.ComboBoxText(); |
|
|
|
let cf = new Gtk.ComboBoxText(); |
|
|
|
this.configWidgets.push([cf, b]); |
|
|
|
this.configWidgets.push([cf, b]); |
|
|
|
cf.visible = 1; |
|
|
|
cf.visible = 1; |
|
|
@ -243,29 +241,27 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
for (let i in a) |
|
|
|
for (let i in a) |
|
|
|
cf.append_text(a[i]); |
|
|
|
cf.append_text(a[i]); |
|
|
|
cf.active = this[b]; |
|
|
|
cf.active = this[b]; |
|
|
|
cf.connect("changed", function() { |
|
|
|
cf.connect("changed", Lang.bind(this, function() { |
|
|
|
that[b] = arguments[0].active; |
|
|
|
this[b] = arguments[0].active; |
|
|
|
}); |
|
|
|
})); |
|
|
|
this.right_widget.attach(cf, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0); |
|
|
|
this.right_widget.attach(cf, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0); |
|
|
|
this.inc(); |
|
|
|
this.inc(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
addSwitch: function(a) { |
|
|
|
addSwitch: function(a) { |
|
|
|
let that = this; |
|
|
|
|
|
|
|
let sw = new Gtk.Switch(); |
|
|
|
let sw = new Gtk.Switch(); |
|
|
|
this.configWidgets.push([sw, a]); |
|
|
|
this.configWidgets.push([sw, a]); |
|
|
|
sw.visible = 1; |
|
|
|
sw.visible = 1; |
|
|
|
sw.can_focus = 0; |
|
|
|
sw.can_focus = 0; |
|
|
|
sw.active = this[a]; |
|
|
|
sw.active = this[a]; |
|
|
|
sw.connect("notify::active", function() { |
|
|
|
sw.connect("notify::active", Lang.bind(this, function() { |
|
|
|
that[a] = arguments[0].active; |
|
|
|
this[a] = arguments[0].active; |
|
|
|
}); |
|
|
|
})); |
|
|
|
this.right_widget.attach(sw, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0); |
|
|
|
this.right_widget.attach(sw, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0); |
|
|
|
this.inc(); |
|
|
|
this.inc(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
addAppidEntry: function(a) { |
|
|
|
addAppidEntry: function(a) { |
|
|
|
let that = this; |
|
|
|
|
|
|
|
let en = new Gtk.Entry(); |
|
|
|
let en = new Gtk.Entry(); |
|
|
|
this.configWidgets.push([en, a]); |
|
|
|
this.configWidgets.push([en, a]); |
|
|
|
en.visible = 1; |
|
|
|
en.visible = 1; |
|
|
@ -275,15 +271,15 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
if (this[a].length != 32) |
|
|
|
if (this[a].length != 32) |
|
|
|
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning'); |
|
|
|
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning'); |
|
|
|
|
|
|
|
|
|
|
|
en.connect("notify::text", function() { |
|
|
|
en.connect("notify::text", Lang.bind(this, function() { |
|
|
|
let key = arguments[0].text; |
|
|
|
let key = arguments[0].text; |
|
|
|
let rgba = new Gdk.Color(); |
|
|
|
let rgba = new Gdk.Color(); |
|
|
|
that[a] = key; |
|
|
|
this[a] = key; |
|
|
|
if (key.length == 32) |
|
|
|
if (key.length == 32) |
|
|
|
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, ''); |
|
|
|
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, ''); |
|
|
|
else |
|
|
|
else |
|
|
|
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning'); |
|
|
|
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning'); |
|
|
|
}); |
|
|
|
})); |
|
|
|
this.right_widget.attach(en, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0); |
|
|
|
this.right_widget.attach(en, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0); |
|
|
|
this.inc(); |
|
|
|
this.inc(); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -297,7 +293,6 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
addCity: function() { |
|
|
|
addCity: function() { |
|
|
|
let that = this; |
|
|
|
|
|
|
|
let textDialog = _("Name of the city"); |
|
|
|
let textDialog = _("Name of the city"); |
|
|
|
|
|
|
|
|
|
|
|
let dialog = new Gtk.Dialog({ |
|
|
|
let dialog = new Gtk.Dialog({ |
|
|
@ -339,7 +334,7 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
dialog.set_default(d); |
|
|
|
dialog.set_default(d); |
|
|
|
entry.activates_default = true; |
|
|
|
entry.activates_default = true; |
|
|
|
|
|
|
|
|
|
|
|
let testLocation = function(location) { |
|
|
|
let testLocation = Lang.bind(this, function(location) { |
|
|
|
if (location.search(/\[/) == -1 || location.search(/\]/) == -1) |
|
|
|
if (location.search(/\[/) == -1 || location.search(/\]/) == -1) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
@ -347,7 +342,7 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
if (!id) |
|
|
|
if (!id) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
that.loadJsonAsync(WEATHER_URL_CURRENT, { |
|
|
|
this.loadJsonAsync(WEATHER_URL_CURRENT, { |
|
|
|
id: id |
|
|
|
id: id |
|
|
|
}, function() { |
|
|
|
}, function() { |
|
|
|
d.sensitive = 0; |
|
|
|
d.sensitive = 0; |
|
|
@ -366,9 +361,9 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}, "testLocation"); |
|
|
|
}, "testLocation"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let searchLocation = function() { |
|
|
|
let searchLocation = Lang.bind(this, function() { |
|
|
|
let location = entry.get_text(); |
|
|
|
let location = entry.get_text(); |
|
|
|
let params = { |
|
|
|
let params = { |
|
|
|
cnt: '30', |
|
|
|
cnt: '30', |
|
|
@ -380,7 +375,7 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
if (this._appid) |
|
|
|
if (this._appid) |
|
|
|
params['APPID'] = this._appid; |
|
|
|
params['APPID'] = this._appid; |
|
|
|
if (testLocation(location) == 0) |
|
|
|
if (testLocation(location) == 0) |
|
|
|
that.loadJsonAsync(WEATHER_URL_FIND, params, function() { |
|
|
|
this.loadJsonAsync(WEATHER_URL_FIND, params, function() { |
|
|
|
if (!arguments[0]) |
|
|
|
if (!arguments[0]) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
let city = arguments[0]; |
|
|
|
let city = arguments[0]; |
|
|
@ -423,14 +418,14 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}, "getInfo"); |
|
|
|
}, "getInfo"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
entry.connect("changed", searchLocation); |
|
|
|
entry.connect("changed", searchLocation); |
|
|
|
|
|
|
|
|
|
|
|
let dialog_area = dialog.get_content_area(); |
|
|
|
let dialog_area = dialog.get_content_area(); |
|
|
|
dialog_area.pack_start(label, 0, 0, 0); |
|
|
|
dialog_area.pack_start(label, 0, 0, 0); |
|
|
|
dialog_area.pack_start(entry, 0, 0, 0); |
|
|
|
dialog_area.pack_start(entry, 0, 0, 0); |
|
|
|
dialog.connect("response", function(w, response_id) { |
|
|
|
dialog.connect("response", Lang.bind(this, function(w, response_id) { |
|
|
|
if (response_id) { |
|
|
|
if (response_id) { |
|
|
|
if (entry.get_text().search(/\[/) == -1 || entry.get_text().search(/\]/) == -1) |
|
|
|
if (entry.get_text().search(/\[/) == -1 || entry.get_text().search(/\]/) == -1) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -445,7 +440,7 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
}; |
|
|
|
}; |
|
|
|
if (this._appid) |
|
|
|
if (this._appid) |
|
|
|
params['APPID'] = this._appid; |
|
|
|
params['APPID'] = this._appid; |
|
|
|
that.loadJsonAsync(WEATHER_URL_CURRENT, params, function() { |
|
|
|
this.loadJsonAsync(WEATHER_URL_CURRENT, params, Lang.bind(this, function() { |
|
|
|
if (!arguments[0]) |
|
|
|
if (!arguments[0]) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
let city = arguments[0]; |
|
|
|
let city = arguments[0]; |
|
|
@ -465,23 +460,22 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
if (city.sys) |
|
|
|
if (city.sys) |
|
|
|
cityText += " (" + city.sys.country + ")"; |
|
|
|
cityText += " (" + city.sys.country + ")"; |
|
|
|
|
|
|
|
|
|
|
|
if (that.city) |
|
|
|
if (this.city) |
|
|
|
that.city = that.city + " && " + city.id + ">" + cityText; |
|
|
|
this.city = this.city + " && " + city.id + ">" + cityText; |
|
|
|
else |
|
|
|
else |
|
|
|
that.city = city.id + ">" + cityText; |
|
|
|
this.city = city.id + ">" + cityText; |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}, "lastTest"); |
|
|
|
}), "lastTest"); |
|
|
|
} |
|
|
|
} |
|
|
|
dialog.hide(); |
|
|
|
dialog.hide(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
dialog.show_all(); |
|
|
|
dialog.show_all(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
removeCity: function() { |
|
|
|
removeCity: function() { |
|
|
|
let that = this; |
|
|
|
|
|
|
|
let city = this.city.split(" && "); |
|
|
|
let city = this.city.split(" && "); |
|
|
|
if (!city.length) |
|
|
|
if (!city.length) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -508,7 +502,7 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
|
|
|
|
|
|
|
|
let dialog_area = dialog.get_content_area(); |
|
|
|
let dialog_area = dialog.get_content_area(); |
|
|
|
dialog_area.pack_start(label, 0, 0, 0); |
|
|
|
dialog_area.pack_start(label, 0, 0, 0); |
|
|
|
dialog.connect("response", function(w, response_id) { |
|
|
|
dialog.connect("response", Lang.bind(this, function(w, response_id) { |
|
|
|
if (response_id) { |
|
|
|
if (response_id) { |
|
|
|
if (city.length == 0) |
|
|
|
if (city.length == 0) |
|
|
|
city = []; |
|
|
|
city = []; |
|
|
@ -520,15 +514,15 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
city.splice(ac, 1); |
|
|
|
city.splice(ac, 1); |
|
|
|
|
|
|
|
|
|
|
|
if (city.length > 1) |
|
|
|
if (city.length > 1) |
|
|
|
that.city = city.join(" && "); |
|
|
|
this.city = city.join(" && "); |
|
|
|
else if (city[0]) |
|
|
|
else if (city[0]) |
|
|
|
that.city = city[0]; |
|
|
|
this.city = city[0]; |
|
|
|
else |
|
|
|
else |
|
|
|
that.city = ""; |
|
|
|
this.city = ""; |
|
|
|
} |
|
|
|
} |
|
|
|
dialog.hide(); |
|
|
|
dialog.hide(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
dialog.show_all(); |
|
|
|
dialog.show_all(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -584,11 +578,10 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
loadConfig: function() { |
|
|
|
loadConfig: function() { |
|
|
|
let that = this; |
|
|
|
|
|
|
|
this.Settings = Convenience.getSettings(WEATHER_SETTINGS_SCHEMA); |
|
|
|
this.Settings = Convenience.getSettings(WEATHER_SETTINGS_SCHEMA); |
|
|
|
this.Settings.connect("changed", function() { |
|
|
|
this.Settings.connect("changed", Lang.bind(this, function() { |
|
|
|
that.refreshUI(); |
|
|
|
this.refreshUI(); |
|
|
|
}); |
|
|
|
})); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get units() { |
|
|
|
get units() { |
|
|
@ -760,26 +753,26 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
if (!this.Settings) |
|
|
|
if (!this.Settings) |
|
|
|
this.loadConfig(); |
|
|
|
this.loadConfig(); |
|
|
|
let v = this.Settings.get_int(WEATHER_REFRESH_INTERVAL_CURRENT); |
|
|
|
let v = this.Settings.get_int(WEATHER_REFRESH_INTERVAL_CURRENT); |
|
|
|
return ((v >= 600) ? v : 600); |
|
|
|
return ((v >= 60) ? v : 60); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
set refresh_interval_current(v) { |
|
|
|
set refresh_interval_current(v) { |
|
|
|
if (!this.Settings) |
|
|
|
if (!this.Settings) |
|
|
|
this.loadConfig(); |
|
|
|
this.loadConfig(); |
|
|
|
this.Settings.set_int(WEATHER_REFRESH_INTERVAL_CURRENT, ((v >= 600) ? v : 600)); |
|
|
|
this.Settings.set_int(WEATHER_REFRESH_INTERVAL_CURRENT, ((v >= 60) ? v : 60)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get refresh_interval_forecast() { |
|
|
|
get refresh_interval_forecast() { |
|
|
|
if (!this.Settings) |
|
|
|
if (!this.Settings) |
|
|
|
this.loadConfig(); |
|
|
|
this.loadConfig(); |
|
|
|
let v = this.Settings.get_int(WEATHER_REFRESH_INTERVAL_FORECAST); |
|
|
|
let v = this.Settings.get_int(WEATHER_REFRESH_INTERVAL_FORECAST); |
|
|
|
return ((v >= 600) ? v : 600); |
|
|
|
return ((v >= 60) ? v : 60); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
set refresh_interval_forecast(v) { |
|
|
|
set refresh_interval_forecast(v) { |
|
|
|
if (!this.Settings) |
|
|
|
if (!this.Settings) |
|
|
|
this.loadConfig(); |
|
|
|
this.loadConfig(); |
|
|
|
this.Settings.set_int(WEATHER_REFRESH_INTERVAL_FORECAST, ((v >= 600) ? v : 600)); |
|
|
|
this.Settings.set_int(WEATHER_REFRESH_INTERVAL_FORECAST, ((v >= 60) ? v : 60)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get center_forecast() { |
|
|
|
get center_forecast() { |
|
|
|