@ -43,7 +43,6 @@ const Soup = imports.gi.Soup;
const Shell = imports . gi . Shell ;
const St = imports . gi . St ;
const Util = imports . misc . util ;
const NMClient = imports . gi . NMClient ;
const _ = Gettext . gettext ;
const Main = imports . ui . main ;
@ -119,9 +118,6 @@ const WeatherMenuButton = new Lang.Class({
_init : function ( ) {
// Load settings
this . loadConfig ( ) ;
//Load Network status
this . _nmClient = NMClient . Client . new ( ) ;
// Label
this . _weatherInfo = new St . Label ( { text : _ ( '...' ) } ) ;
@ -130,8 +126,7 @@ const WeatherMenuButton = new Lang.Class({
{
// Panel icon
this . _weatherIcon = new St . Icon ( {
icon _type : this . _icon _type ,
icon _name : 'view-refresh' ,
icon _name : 'view-refresh' + this . icon _type ( ) ,
style _class : 'system-status-icon weather-icon' + ( Main . panel . actor . get _text _direction ( ) == Clutter . TextDirection . RTL ? '-rtl' : '' )
} ) ;
@ -145,8 +140,7 @@ const WeatherMenuButton = new Lang.Class({
{
// Panel icon
this . _weatherIcon = new St . Icon ( {
icon _type : this . _icon _type ,
icon _name : 'view-refresh' ,
icon _name : 'view-refresh' + this . icon _type ( ) ,
style _class : 'system-status-icon weather-icon' + ( Main . panel . actor . get _direction ( ) == St . TextDirection . RTL ? '-rtl' : '' )
} ) ;
@ -163,6 +157,11 @@ const WeatherMenuButton = new Lang.Class({
topBox . add _actor ( this . _weatherInfo ) ;
this . actor . add _actor ( topBox ) ;
let dummyBox = new St . BoxLayout ( ) ;
this . actor . reparent ( dummyBox ) ;
dummyBox . remove _actor ( this . actor ) ;
dummyBox . destroy ( ) ;
let children = null ;
switch ( this . _position _in _panel ) {
case WeatherPosition . LEFT :
@ -178,8 +177,12 @@ const WeatherMenuButton = new Lang.Class({
Main . panel . _rightBox . insert _child _at _index ( this . actor , 0 ) ;
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
this . _currentWeather = new St . Bin ( { style _class : 'current' } ) ;
@ -406,14 +409,14 @@ const WeatherMenuButton = new Lang.Class({
{
if ( ! this . _settings )
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 )
{
if ( ! this . _settings )
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 ( )
@ -667,14 +670,13 @@ const WeatherMenuButton = new Lang.Class({
let iconname = this . get _weather _icon ( code ) ;
for ( let i = 0 ; i < iconname . length ; 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 ) {
//TODO correct symbolic name? (cf. symbolic_names_for_icon)
return Gtk . IconTheme . get _default ( ) . has _icon ( icon + ( this . _icon _type == 1 ? '-symbolic' : '' ) ) ;
return Gtk . IconTheme . get _default ( ) . has _icon ( icon + this . icon _type ( ) ) ;
} ,
get _weather _condition : function ( code ) {
@ -849,6 +851,26 @@ const WeatherMenuButton = new Lang.Class({
}
} ,
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 ) {
let here = this ;
@ -874,40 +896,76 @@ const WeatherMenuButton = new Lang.Class({
} ) ;
} ,
refreshWeather : function ( recurse ) {
if ( this . _nmClient . get _active _connections ( ) == null ) {
this . actor . hide ( ) ;
}
else {
this . actor . show ( ) ;
}
if ( ! this . extractWoeid ( this . _city ) )
{
this . updateCities ( ) ;
return 0 ;
}
this . load _json _async ( this . get _weather _url ( ) , function ( json ) {
if ( ! json )
return 0 ;
let weather = json . query . results . channel ;
let many = 0 ;
if ( typeof weather [ 0 ] != "undefined" )
{
weather = weather [ 0 ] ;
many = 1 ;
}
let weather _c = weather . item . condition ;
this . _weatherIcon . icon _type = this . _icon _type ;
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 ;
refreshWeather : function ( recurse )
{
if ( ! this . extractWoeid ( this . _city ) )
{
this . updateCities ( ) ;
return 0 ;
}
this . load _json _async ( this . get _weather _url ( ) , function ( json )
{
if ( ! json )
return 0 ;
let weather = json . query . results . channel ;
let many = 0 ;
if ( typeof weather [ 0 ] != "undefined" )
{
weather = weather [ 0 ] ;
many = 1 ;
}
let weather _c = weather . item . condition ;
this . _weatherIcon . icon _name = this . icon _type ( this . _weatherIcon . icon _name ) ;
this . _currentWeatherIcon . icon _name = this . icon _type ( this . _currentWeatherIcon . icon _name ) ;
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 ) ;
this . _sunriseIcon . icon _name = this . icon _type ( this . _sunriseIcon . icon _name ) ;
this . _sunsetIcon . icon _name = this . icon _type ( this . _sunsetIcon . icon _name ) ;
this . _buildIcon . icon _name = this . icon _type ( this . _buildIcon . icon _name ) ;
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 location = this . extractLocation ( this . _city ) ;
@ -1208,30 +1266,26 @@ const WeatherMenuButton = new Lang.Class({
// This will hold the icon for the current weather
this . _currentWeatherIcon = new St . Icon ( {
icon _type : this . _icon _type ,
icon _size : 72 ,
icon _name : 'view-refresh' ,
icon _name : 'view-refresh' + this . icon _type ( ) ,
style _class : 'weather-current-icon'
} ) ;
this . _sunriseIcon = new St . Icon ( {
icon _type : this . _icon _type ,
icon _size : 15 ,
icon _name : 'weather-clear' ,
icon _name : 'weather-clear' + this . icon _type ( ) ,
style _class : 'weather-sunrise-icon'
} ) ;
this . _sunsetIcon = new St . Icon ( {
icon _type : this . _icon _type ,
icon _size : 15 ,
icon _name : 'weather-clear-night' ,
icon _name : 'weather-clear-night' + this . icon _type ( ) ,
style _class : 'weather-sunset-icon'
} ) ;
this . _buildIcon = new St . Icon ( {
icon _type : this . _icon _type ,
icon _size : 15 ,
icon _name : 'view-refresh' ,
icon _name : 'view-refresh' + this . icon _type ( ) ,
style _class : 'weather-build-icon'
} ) ;
@ -1318,9 +1372,8 @@ const WeatherMenuButton = new Lang.Class({
let forecastWeather = { } ;
forecastWeather . Icon = new St . Icon ( {
icon _type : this . _icon _type ,
icon _size : 48 ,
icon _name : 'view-refresh-symbolic' ,
icon _name : 'view-refresh' + this . icon _type ( ) ,
style _class : 'weather-forecast-icon'
} ) ;
forecastWeather . Day = new St . Label ( {