|
|
@ -27,6 +27,7 @@ |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const Gtk = imports.gi.Gtk; |
|
|
|
const Gtk = imports.gi.Gtk; |
|
|
|
|
|
|
|
const Gdk = imports.gi.Gdk; |
|
|
|
const GObject = imports.gi.GObject; |
|
|
|
const GObject = imports.gi.GObject; |
|
|
|
const GtkBuilder = Gtk.Builder; |
|
|
|
const GtkBuilder = Gtk.Builder; |
|
|
|
const Gio = imports.gi.Gio; |
|
|
|
const Gio = imports.gi.Gio; |
|
|
@ -57,6 +58,7 @@ const WEATHER_REFRESH_INTERVAL_CURRENT = 'refresh-interval-current'; |
|
|
|
const WEATHER_REFRESH_INTERVAL_FORECAST = 'refresh-interval-forecast'; |
|
|
|
const WEATHER_REFRESH_INTERVAL_FORECAST = 'refresh-interval-forecast'; |
|
|
|
const WEATHER_CENTER_FORECAST_KEY = 'center-forecast'; |
|
|
|
const WEATHER_CENTER_FORECAST_KEY = 'center-forecast'; |
|
|
|
const WEATHER_DAYS_FORECAST = 'days-forecast'; |
|
|
|
const WEATHER_DAYS_FORECAST = 'days-forecast'; |
|
|
|
|
|
|
|
const WEATHER_OWM_API_KEY = 'appid'; |
|
|
|
|
|
|
|
|
|
|
|
//URL
|
|
|
|
//URL
|
|
|
|
const WEATHER_URL_BASE = 'http://api.openweathermap.org/data/2.5/'; |
|
|
|
const WEATHER_URL_BASE = 'http://api.openweathermap.org/data/2.5/'; |
|
|
@ -144,6 +146,8 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
this.addSwitch("center_forecast"); |
|
|
|
this.addSwitch("center_forecast"); |
|
|
|
this.addLabel(_("Number of days in forecast")); |
|
|
|
this.addLabel(_("Number of days in forecast")); |
|
|
|
this.addComboBox(["2", "3", "4", "5", "6", "7", "8", "9", "10"], "days_forecast"); |
|
|
|
this.addComboBox(["2", "3", "4", "5", "6", "7", "8", "9", "10"], "days_forecast"); |
|
|
|
|
|
|
|
this.addLabel(_("Enter your personal Api key from openweather.org")); |
|
|
|
|
|
|
|
this.addAppidEntry(("appid")); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
refreshUI: function() { |
|
|
|
refreshUI: function() { |
|
|
@ -261,6 +265,30 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
this.inc(); |
|
|
|
this.inc(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addAppidEntry: function(a) { |
|
|
|
|
|
|
|
let that = this; |
|
|
|
|
|
|
|
let en = new Gtk.Entry(); |
|
|
|
|
|
|
|
this.configWidgets.push([en, a]); |
|
|
|
|
|
|
|
en.visible = 1; |
|
|
|
|
|
|
|
en.can_focus = 1; |
|
|
|
|
|
|
|
en.set_width_chars(32); |
|
|
|
|
|
|
|
en.text = this[a]; |
|
|
|
|
|
|
|
if (this[a].length != 32) |
|
|
|
|
|
|
|
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
en.connect("notify::text", function() { |
|
|
|
|
|
|
|
let key = arguments[0].text; |
|
|
|
|
|
|
|
let rgba = new Gdk.Color(); |
|
|
|
|
|
|
|
that[a] = key; |
|
|
|
|
|
|
|
if (key.length == 32) |
|
|
|
|
|
|
|
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, ''); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
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.inc(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
selectionChanged: function(select) { |
|
|
|
selectionChanged: function(select) { |
|
|
|
let a = select.get_selected_rows(this.liststore)[0][0]; |
|
|
|
let a = select.get_selected_rows(this.liststore)[0][0]; |
|
|
|
|
|
|
|
|
|
|
@ -350,6 +378,8 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
units: 'metric', |
|
|
|
units: 'metric', |
|
|
|
q: location |
|
|
|
q: location |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
if(this._appid) |
|
|
|
|
|
|
|
params['APPID'] = this._appid; |
|
|
|
if (testLocation(location) == 0) |
|
|
|
if (testLocation(location) == 0) |
|
|
|
that.loadJsonAsync(WEATHER_URL_FIND, params, function() { |
|
|
|
that.loadJsonAsync(WEATHER_URL_FIND, params, function() { |
|
|
|
if (!arguments[0]) |
|
|
|
if (!arguments[0]) |
|
|
@ -414,6 +444,8 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
q: name, |
|
|
|
q: name, |
|
|
|
type: 'accurate' |
|
|
|
type: 'accurate' |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
if(this._appid) |
|
|
|
|
|
|
|
params['APPID'] = this._appid; |
|
|
|
that.loadJsonAsync(WEATHER_URL_CURRENT, params, function() { |
|
|
|
that.loadJsonAsync(WEATHER_URL_CURRENT, params, function() { |
|
|
|
if (!arguments[0]) |
|
|
|
if (!arguments[0]) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -766,6 +798,18 @@ const WeatherPrefsWidget = new GObject.Class({ |
|
|
|
this.Settings.set_int(WEATHER_DAYS_FORECAST, v + 2); |
|
|
|
this.Settings.set_int(WEATHER_DAYS_FORECAST, v + 2); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get appid() { |
|
|
|
|
|
|
|
if (!this.Settings) |
|
|
|
|
|
|
|
this.loadConfig(); |
|
|
|
|
|
|
|
return this.Settings.get_string(WEATHER_OWM_API_KEY); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set appid(v) { |
|
|
|
|
|
|
|
if (!this.Settings) |
|
|
|
|
|
|
|
this.loadConfig(); |
|
|
|
|
|
|
|
this.Settings.set_string(WEATHER_OWM_API_KEY, v); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
extractLocation: function(a) { |
|
|
|
extractLocation: function(a) { |
|
|
|
if (a.search(">") == -1) |
|
|
|
if (a.search(">") == -1) |
|
|
|
return _("Invalid city"); |
|
|
|
return _("Invalid city"); |
|
|
|