|
|
@ -43,7 +43,6 @@ const Soup = imports.gi.Soup; |
|
|
|
const Shell = imports.gi.Shell; |
|
|
|
const Shell = imports.gi.Shell; |
|
|
|
const St = imports.gi.St; |
|
|
|
const St = imports.gi.St; |
|
|
|
const Util = imports.misc.util; |
|
|
|
const Util = imports.misc.util; |
|
|
|
const NMClient = imports.gi.NMClient; |
|
|
|
|
|
|
|
const _ = Gettext.gettext; |
|
|
|
const _ = Gettext.gettext; |
|
|
|
|
|
|
|
|
|
|
|
const Main = imports.ui.main; |
|
|
|
const Main = imports.ui.main; |
|
|
@ -111,19 +110,14 @@ const WEATHER_CONV_FPS_IN_MPS = 3.2808399; |
|
|
|
const _httpSession = new Soup.SessionAsync(); |
|
|
|
const _httpSession = new Soup.SessionAsync(); |
|
|
|
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault()); |
|
|
|
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault()); |
|
|
|
|
|
|
|
|
|
|
|
function WeatherMenuButton() { |
|
|
|
const WeatherMenuButton = new Lang.Class({ |
|
|
|
this._init(); |
|
|
|
Name: 'WeatherMenuButton', |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WeatherMenuButton.prototype = { |
|
|
|
Extends: PanelMenu.Button, |
|
|
|
__proto__: PanelMenu.Button.prototype, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_init: function() { |
|
|
|
_init: function() { |
|
|
|
// Load settings
|
|
|
|
// Load settings
|
|
|
|
this.loadConfig(); |
|
|
|
this.loadConfig(); |
|
|
|
|
|
|
|
|
|
|
|
//Load Network status
|
|
|
|
|
|
|
|
this._nmClient = NMClient.Client.new(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Label
|
|
|
|
// Label
|
|
|
|
this._weatherInfo = new St.Label({ text: _('...') }); |
|
|
|
this._weatherInfo = new St.Label({ text: _('...') }); |
|
|
@ -132,8 +126,7 @@ WeatherMenuButton.prototype = { |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Panel icon
|
|
|
|
// Panel icon
|
|
|
|
this._weatherIcon = new St.Icon({ |
|
|
|
this._weatherIcon = new St.Icon({ |
|
|
|
icon_type: this._icon_type, |
|
|
|
icon_name: 'view-refresh'+this.icon_type(), |
|
|
|
icon_name: 'view-refresh-symbolic', |
|
|
|
|
|
|
|
style_class: 'system-status-icon weather-icon' + (Main.panel.actor.get_text_direction() == Clutter.TextDirection.RTL ? '-rtl' : '') |
|
|
|
style_class: 'system-status-icon weather-icon' + (Main.panel.actor.get_text_direction() == Clutter.TextDirection.RTL ? '-rtl' : '') |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -141,14 +134,13 @@ WeatherMenuButton.prototype = { |
|
|
|
let menuAlignment = 0.25; |
|
|
|
let menuAlignment = 0.25; |
|
|
|
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL) |
|
|
|
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL) |
|
|
|
menuAlignment = 1.0 - menuAlignment; |
|
|
|
menuAlignment = 1.0 - menuAlignment; |
|
|
|
PanelMenu.Button.prototype._init.call(this, menuAlignment); |
|
|
|
this.parent(menuAlignment); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Panel icon
|
|
|
|
// Panel icon
|
|
|
|
this._weatherIcon = new St.Icon({ |
|
|
|
this._weatherIcon = new St.Icon({ |
|
|
|
icon_type: this._icon_type, |
|
|
|
icon_name: 'view-refresh'+this.icon_type(), |
|
|
|
icon_name: 'view-refresh-symbolic', |
|
|
|
|
|
|
|
style_class: 'system-status-icon weather-icon' + (Main.panel.actor.get_direction() == St.TextDirection.RTL ? '-rtl' : '') |
|
|
|
style_class: 'system-status-icon weather-icon' + (Main.panel.actor.get_direction() == St.TextDirection.RTL ? '-rtl' : '') |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -165,22 +157,32 @@ WeatherMenuButton.prototype = { |
|
|
|
topBox.add_actor(this._weatherInfo); |
|
|
|
topBox.add_actor(this._weatherInfo); |
|
|
|
this.actor.add_actor(topBox); |
|
|
|
this.actor.add_actor(topBox); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let dummyBox = new St.BoxLayout(); |
|
|
|
|
|
|
|
this.actor.reparent(dummyBox); |
|
|
|
|
|
|
|
dummyBox.remove_actor(this.actor); |
|
|
|
|
|
|
|
dummyBox.destroy(); |
|
|
|
|
|
|
|
|
|
|
|
let children = null; |
|
|
|
let children = null; |
|
|
|
switch (this._position_in_panel) { |
|
|
|
switch (this._position_in_panel) { |
|
|
|
case WeatherPosition.LEFT: |
|
|
|
case WeatherPosition.LEFT: |
|
|
|
children = Main.panel._leftBox.get_children(); |
|
|
|
children = Main.panel._leftBox.get_children(); |
|
|
|
Main.panel._leftBox.add(this.actor, children.length-1); |
|
|
|
Main.panel._leftBox.insert_child_at_index(this.actor, children.length); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case WeatherPosition.CENTER: |
|
|
|
case WeatherPosition.CENTER: |
|
|
|
Main.panel._centerBox.add(this.actor, { y_fill: true }); |
|
|
|
children = Main.panel._centerBox.get_children(); |
|
|
|
|
|
|
|
Main.panel._centerBox.insert_child_at_index(this.actor, children.length); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case WeatherPosition.RIGHT: |
|
|
|
case WeatherPosition.RIGHT: |
|
|
|
children = Main.panel._rightBox.get_children(); |
|
|
|
children = Main.panel._rightBox.get_children(); |
|
|
|
Main.panel._rightBox.insert_child_at_index(this.actor, 0); |
|
|
|
Main.panel._rightBox.insert_child_at_index(this.actor, 0); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(typeof Main.panel._menus == "undefined") |
|
|
|
|
|
|
|
Main.panel.menuManager.addMenu(this.menu); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Main.panel._menus.addMenu(this.menu); |
|
|
|
|
|
|
|
|
|
|
|
Main.panel._menus.addMenu(this.menu); |
|
|
|
this._old_position_in_panel = this._position_in_panel; |
|
|
|
|
|
|
|
|
|
|
|
// Current weather
|
|
|
|
// Current weather
|
|
|
|
this._currentWeather = new St.Bin({ style_class: 'current' }); |
|
|
|
this._currentWeather = new St.Bin({ style_class: 'current' }); |
|
|
@ -407,14 +409,14 @@ WeatherMenuButton.prototype = { |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!this._settings) |
|
|
|
if(!this._settings) |
|
|
|
this.loadConfig(); |
|
|
|
this.loadConfig(); |
|
|
|
return this._settings.get_boolean(WEATHER_USE_SYMBOLIC_ICONS_KEY) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR; |
|
|
|
return this._settings.get_boolean(WEATHER_USE_SYMBOLIC_ICONS_KEY) ? 1 : 0; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
set _icon_type(v) |
|
|
|
set _icon_type(v) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!this._settings) |
|
|
|
if(!this._settings) |
|
|
|
this.loadConfig(); |
|
|
|
this.loadConfig(); |
|
|
|
this._settings.set_boolean(WEATHER_USE_SYMBOLIC_ICONS_KEY,v == St.IconType.SYMBOLIC ? 1 : 0); |
|
|
|
this._settings.set_boolean(WEATHER_USE_SYMBOLIC_ICONS_KEY,v); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get _text_in_panel() |
|
|
|
get _text_in_panel() |
|
|
@ -668,14 +670,13 @@ WeatherMenuButton.prototype = { |
|
|
|
let iconname = this.get_weather_icon(code); |
|
|
|
let iconname = this.get_weather_icon(code); |
|
|
|
for (let i = 0; i < iconname.length; i++) { |
|
|
|
for (let i = 0; i < iconname.length; i++) { |
|
|
|
if (this.has_icon(iconname[i])) |
|
|
|
if (this.has_icon(iconname[i])) |
|
|
|
return iconname[i]; |
|
|
|
return iconname[i]+this.icon_type(); |
|
|
|
} |
|
|
|
} |
|
|
|
return 'weather-severe-alert'; |
|
|
|
return 'weather-severe-alert'+this.icon_type(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
has_icon: function(icon) { |
|
|
|
has_icon: function(icon) { |
|
|
|
//TODO correct symbolic name? (cf. symbolic_names_for_icon)
|
|
|
|
return Gtk.IconTheme.get_default().has_icon(icon+this.icon_type()); |
|
|
|
return Gtk.IconTheme.get_default().has_icon(icon + (this._icon_type == St.IconType.SYMBOLIC ? '-symbolic' : '')); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get_weather_condition: function(code) { |
|
|
|
get_weather_condition: function(code) { |
|
|
@ -850,6 +851,26 @@ WeatherMenuButton.prototype = { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
icon_type : function(icon_name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(!icon_name) |
|
|
|
|
|
|
|
if(this._icon_type) |
|
|
|
|
|
|
|
return "-symbolic"; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this._icon_type) |
|
|
|
|
|
|
|
if(String(icon_name).search("-symbolic") != -1) |
|
|
|
|
|
|
|
return icon_name; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return icon_name+"-symbolic"; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
if(String(icon_name).search("-symbolic") != -1) |
|
|
|
|
|
|
|
return String(icon_name).replace("-symbolic",""); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return icon_name; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
load_json_async: function(url, fun) { |
|
|
|
load_json_async: function(url, fun) { |
|
|
|
let here = this; |
|
|
|
let here = this; |
|
|
|
|
|
|
|
|
|
|
@ -875,40 +896,76 @@ WeatherMenuButton.prototype = { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
refreshWeather: function(recurse) { |
|
|
|
refreshWeather: function(recurse) |
|
|
|
|
|
|
|
{
|
|
|
|
if (this._nmClient.get_active_connections() == null){ |
|
|
|
if(!this.extractWoeid(this._city)) |
|
|
|
this.actor.hide();
|
|
|
|
{ |
|
|
|
} |
|
|
|
this.updateCities(); |
|
|
|
else{ |
|
|
|
return 0; |
|
|
|
this.actor.show(); |
|
|
|
} |
|
|
|
} |
|
|
|
this.load_json_async(this.get_weather_url(), function(json) |
|
|
|
|
|
|
|
{ |
|
|
|
if(!this.extractWoeid(this._city)) |
|
|
|
if(!json) |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
this.updateCities(); |
|
|
|
let weather = json.query.results.channel; |
|
|
|
return 0; |
|
|
|
let many = 0; |
|
|
|
} |
|
|
|
if(typeof weather[0] != "undefined") |
|
|
|
this.load_json_async(this.get_weather_url(), function(json) { |
|
|
|
{ |
|
|
|
if(!json) |
|
|
|
weather = weather[0]; |
|
|
|
return 0; |
|
|
|
many = 1; |
|
|
|
let weather = json.query.results.channel; |
|
|
|
} |
|
|
|
let many = 0; |
|
|
|
let weather_c = weather.item.condition; |
|
|
|
if(typeof weather[0] != "undefined") |
|
|
|
|
|
|
|
{ |
|
|
|
this._weatherIcon.icon_name = this.icon_type(this._weatherIcon.icon_name); |
|
|
|
weather = weather[0]; |
|
|
|
this._currentWeatherIcon.icon_name = this.icon_type(this._currentWeatherIcon.icon_name); |
|
|
|
many = 1; |
|
|
|
this._forecast[0].Icon.icon_name = this.icon_type(this._forecast[0].Icon.icon_name); |
|
|
|
} |
|
|
|
this._forecast[1].Icon.icon_name = this.icon_type(this._forecast[1].Icon.icon_name); |
|
|
|
let weather_c = weather.item.condition; |
|
|
|
this._sunriseIcon.icon_name = this.icon_type(this._sunriseIcon.icon_name); |
|
|
|
|
|
|
|
this._sunsetIcon.icon_name = this.icon_type(this._sunsetIcon.icon_name); |
|
|
|
this._weatherIcon.icon_type = this._icon_type; |
|
|
|
this._buildIcon.icon_name = this.icon_type(this._buildIcon.icon_name); |
|
|
|
this._currentWeatherIcon.icon_type = this._icon_type; |
|
|
|
|
|
|
|
this._forecast[0].Icon.icon_type = this._icon_type; |
|
|
|
|
|
|
|
this._forecast[1].Icon.icon_type = this._icon_type; |
|
|
|
|
|
|
|
this._sunriseIcon.icon_type = this._icon_type; |
|
|
|
|
|
|
|
this._sunsetIcon.icon_type = this._icon_type; |
|
|
|
|
|
|
|
this._buildIcon.icon_type = this._icon_type; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(typeof St.IconType != "undefined") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this._weatherIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR; |
|
|
|
|
|
|
|
this._currentWeatherIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR; |
|
|
|
|
|
|
|
this._forecast[0].Icon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR; |
|
|
|
|
|
|
|
this._forecast[1].Icon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR; |
|
|
|
|
|
|
|
this._sunriseIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR; |
|
|
|
|
|
|
|
this._sunsetIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR; |
|
|
|
|
|
|
|
this._buildIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this._old_position_in_panel != this._position_in_panel) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (this._old_position_in_panel) { |
|
|
|
|
|
|
|
case WeatherPosition.LEFT: |
|
|
|
|
|
|
|
Main.panel._leftBox.remove_actor(this.actor); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case WeatherPosition.CENTER: |
|
|
|
|
|
|
|
Main.panel._centerBox.remove_actor(this.actor); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case WeatherPosition.RIGHT: |
|
|
|
|
|
|
|
Main.panel._rightBox.remove_actor(this.actor); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let children = null; |
|
|
|
|
|
|
|
switch (this._position_in_panel) { |
|
|
|
|
|
|
|
case WeatherPosition.LEFT: |
|
|
|
|
|
|
|
children = Main.panel._leftBox.get_children(); |
|
|
|
|
|
|
|
Main.panel._leftBox.insert_child_at_index(this.actor, children.length); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case WeatherPosition.CENTER: |
|
|
|
|
|
|
|
children = Main.panel._centerBox.get_children(); |
|
|
|
|
|
|
|
Main.panel._centerBox.insert_child_at_index(this.actor, children.length); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case WeatherPosition.RIGHT: |
|
|
|
|
|
|
|
children = Main.panel._rightBox.get_children(); |
|
|
|
|
|
|
|
Main.panel._rightBox.insert_child_at_index(this.actor, 0); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this._old_position_in_panel = this._position_in_panel; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let forecast = weather.item.forecast; |
|
|
|
let forecast = weather.item.forecast; |
|
|
|
let location = this.extractLocation(this._city); |
|
|
|
let location = this.extractLocation(this._city); |
|
|
@ -1209,30 +1266,26 @@ WeatherMenuButton.prototype = { |
|
|
|
|
|
|
|
|
|
|
|
// This will hold the icon for the current weather
|
|
|
|
// This will hold the icon for the current weather
|
|
|
|
this._currentWeatherIcon = new St.Icon({ |
|
|
|
this._currentWeatherIcon = new St.Icon({ |
|
|
|
icon_type: this._icon_type, |
|
|
|
|
|
|
|
icon_size: 72, |
|
|
|
icon_size: 72, |
|
|
|
icon_name: 'view-refresh-symbolic', |
|
|
|
icon_name: 'view-refresh'+this.icon_type(), |
|
|
|
style_class: 'weather-current-icon' |
|
|
|
style_class: 'weather-current-icon' |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this._sunriseIcon = new St.Icon({ |
|
|
|
this._sunriseIcon = new St.Icon({ |
|
|
|
icon_type: this._icon_type, |
|
|
|
|
|
|
|
icon_size: 15, |
|
|
|
icon_size: 15, |
|
|
|
icon_name: 'weather-clear', |
|
|
|
icon_name: 'weather-clear'+this.icon_type(), |
|
|
|
style_class: 'weather-sunrise-icon' |
|
|
|
style_class: 'weather-sunrise-icon' |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this._sunsetIcon = new St.Icon({ |
|
|
|
this._sunsetIcon = new St.Icon({ |
|
|
|
icon_type: this._icon_type, |
|
|
|
|
|
|
|
icon_size: 15, |
|
|
|
icon_size: 15, |
|
|
|
icon_name: 'weather-clear-night', |
|
|
|
icon_name: 'weather-clear-night'+this.icon_type(), |
|
|
|
style_class: 'weather-sunset-icon' |
|
|
|
style_class: 'weather-sunset-icon' |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this._buildIcon = new St.Icon({ |
|
|
|
this._buildIcon = new St.Icon({ |
|
|
|
icon_type: this._icon_type, |
|
|
|
|
|
|
|
icon_size: 15, |
|
|
|
icon_size: 15, |
|
|
|
icon_name: 'view-refresh', |
|
|
|
icon_name: 'view-refresh'+this.icon_type(), |
|
|
|
style_class: 'weather-build-icon' |
|
|
|
style_class: 'weather-build-icon' |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -1319,9 +1372,8 @@ WeatherMenuButton.prototype = { |
|
|
|
let forecastWeather = {}; |
|
|
|
let forecastWeather = {}; |
|
|
|
|
|
|
|
|
|
|
|
forecastWeather.Icon = new St.Icon({ |
|
|
|
forecastWeather.Icon = new St.Icon({ |
|
|
|
icon_type: this._icon_type, |
|
|
|
|
|
|
|
icon_size: 48, |
|
|
|
icon_size: 48, |
|
|
|
icon_name: 'view-refresh-symbolic', |
|
|
|
icon_name: 'view-refresh'+this.icon_type(), |
|
|
|
style_class: 'weather-forecast-icon' |
|
|
|
style_class: 'weather-forecast-icon' |
|
|
|
}); |
|
|
|
}); |
|
|
|
forecastWeather.Day = new St.Label({ |
|
|
|
forecastWeather.Day = new St.Label({ |
|
|
@ -1354,7 +1406,7 @@ WeatherMenuButton.prototype = { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let weatherMenu; |
|
|
|
let weatherMenu; |
|
|
|
|
|
|
|
|
|
|
|