@ -41,15 +41,15 @@ const Me = ExtensionUtils.getCurrentExtension();
const Config = imports . misc . config ;
const Config = imports . misc . config ;
const DarkskyNet = Me . imports . darksky _net ;
const DarkskyNet = Me . imports . darksky _net ;
const OpenweathermapOrg = Me . imports . openweathermap _org ;
const OpenweathermapOrg = Me . imports . openweathermap _org ;
const Clutter = imports . gi . Clutter ;
const {
Clutter , Gio , Gtk , GLib , GObject , Soup , St
} = imports . gi ;
const Gettext = imports . gettext . domain ( 'gnome-shell-extension-openweather' ) ;
const Gettext = imports . gettext . domain ( 'gnome-shell-extension-openweather' ) ;
const Gio = imports . gi . Gio ;
const Gtk = imports . gi . Gtk ;
const GLib = imports . gi . GLib ;
const Lang = imports . lang ;
const Lang = imports . lang ;
const Mainloop = imports . mainloop ;
const Mainloop = imports . mainloop ;
const Soup = imports . gi . Soup ;
const St = imports . gi . St ;
const GnomeSession = imports . misc . gnomeSession ;
const GnomeSession = imports . misc . gnomeSession ;
const Util = imports . misc . util ;
const Util = imports . misc . util ;
const _ = Gettext . gettext ;
const _ = Gettext . gettext ;
@ -143,12 +143,11 @@ let _httpSession;
let _currentWeatherCache , _forecastWeatherCache ;
let _currentWeatherCache , _forecastWeatherCache ;
let _timeCacheCurrentWeather , _timeCacheForecastWeather ;
let _timeCacheCurrentWeather , _timeCacheForecastWeather ;
const OpenweatherMenuButton = new Lang . Class ( {
let OpenweatherMenuButton = GObject . registerClass (
Name : 'OpenweatherMenuButton' ,
class OpenweatherMenuButton extends PanelMenu . Button {
Extends : PanelMenu . Button ,
_init ( ) {
super . _init ( 0 , 'OpenweatherMenuButton' , false ) ;
_init : function ( ) {
this . owmCityId = 0 ;
this . owmCityId = 0 ;
// Get locale, needed for toLocaleString, workaround for gnome-shell 3.24
// Get locale, needed for toLocaleString, workaround for gnome-shell 3.24
@ -187,11 +186,7 @@ const OpenweatherMenuButton = new Lang.Class({
style _class : 'system-status-icon openweather-icon ' + this . getIconType ( )
style _class : 'system-status-icon openweather-icon ' + this . getIconType ( )
} ) ;
} ) ;
// Panel menu item - the current class
this . checkAlignment ( ) ;
let menuAlignment = 1.0 - ( this . _menu _alignment / 100 ) ;
if ( Clutter . get _default _text _direction ( ) == Clutter . TextDirection . RTL )
menuAlignment = 1.0 - menuAlignment ;
this . parent ( menuAlignment ) ;
// Putting the panel item together
// Putting the panel item together
let topBox = new St . BoxLayout ( ) ;
let topBox = new St . BoxLayout ( ) ;
@ -316,17 +311,18 @@ const OpenweatherMenuButton = new Lang.Class({
this . _needsColorUpdate = true ;
this . _needsColorUpdate = true ;
} ) ) ;
} ) ) ;
}
}
} ,
_onStatusChanged : function ( status ) {
}
_onStatusChanged ( status ) {
this . _idle = false ;
this . _idle = false ;
if ( status == GnomeSession . PresenceStatus . IDLE ) {
if ( status == GnomeSession . PresenceStatus . IDLE ) {
this . _idle = true ;
this . _idle = true ;
}
}
} ,
}
stop : function ( ) {
stop ( ) {
_forecastWeatherCache = this . forecastWeatherCache ;
_forecastWeatherCache = this . forecastWeatherCache ;
_currentWeatherCache = this . currentWeatherCache ;
_currentWeatherCache = this . currentWeatherCache ;
@ -375,16 +371,16 @@ const OpenweatherMenuButton = new Lang.Class({
context . disconnect ( this . _globalThemeChangedId ) ;
context . disconnect ( this . _globalThemeChangedId ) ;
this . _globalThemeChangedId = undefined ;
this . _globalThemeChangedId = undefined ;
}
}
} ,
}
switchProvider : function ( ) {
switchProvider ( ) {
if ( this . _weather _provider == WeatherProvider . DARKSKY )
if ( this . _weather _provider == WeatherProvider . DARKSKY )
this . useDarkskyNet ( ) ;
this . useDarkskyNet ( ) ;
else
else
this . useOpenweathermapOrg ( ) ;
this . useOpenweathermapOrg ( ) ;
} ,
}
useOpenweathermapOrg : function ( ) {
useOpenweathermapOrg ( ) {
this . parseWeatherForecast = OpenweathermapOrg . parseWeatherForecast ;
this . parseWeatherForecast = OpenweathermapOrg . parseWeatherForecast ;
this . parseWeatherCurrent = OpenweathermapOrg . parseWeatherCurrent ;
this . parseWeatherCurrent = OpenweathermapOrg . parseWeatherCurrent ;
this . getWeatherIcon = OpenweathermapOrg . getWeatherIcon ;
this . getWeatherIcon = OpenweathermapOrg . getWeatherIcon ;
@ -396,9 +392,9 @@ const OpenweatherMenuButton = new Lang.Class({
if ( this . _appid . toString ( ) . trim ( ) === '' )
if ( this . _appid . toString ( ) . trim ( ) === '' )
Main . notify ( "Openweather" , _ ( "Openweathermap.org does not work without an api-key.\nEither set the switch to use the extensions default key in the preferences dialog to on or register at https://openweathermap.org/appid and paste your personal key into the preferences dialog." ) ) ;
Main . notify ( "Openweather" , _ ( "Openweathermap.org does not work without an api-key.\nEither set the switch to use the extensions default key in the preferences dialog to on or register at https://openweathermap.org/appid and paste your personal key into the preferences dialog." ) ) ;
} ,
}
useDarkskyNet : function ( ) {
useDarkskyNet ( ) {
this . parseWeatherCurrent = DarkskyNet . parseWeatherCurrent ;
this . parseWeatherCurrent = DarkskyNet . parseWeatherCurrent ;
this . parseWeatherForecast = DarkskyNet . parseWeatherForecast ;
this . parseWeatherForecast = DarkskyNet . parseWeatherForecast ;
this . getWeatherIcon = DarkskyNet . getWeatherIcon ;
this . getWeatherIcon = DarkskyNet . getWeatherIcon ;
@ -449,9 +445,9 @@ const OpenweatherMenuButton = new Lang.Class({
if ( this . _appid _fc . toString ( ) . trim ( ) === '' )
if ( this . _appid _fc . toString ( ) . trim ( ) === '' )
Main . notify ( "Openweather" , _ ( "Dark Sky does not work without an api-key.\nPlease register at https://darksky.net/dev/register and paste your personal key into the preferences dialog." ) ) ;
Main . notify ( "Openweather" , _ ( "Dark Sky does not work without an api-key.\nPlease register at https://darksky.net/dev/register and paste your personal key into the preferences dialog." ) ) ;
} ,
}
getWeatherProviderURL : function ( ) {
getWeatherProviderURL ( ) {
let url = "" ;
let url = "" ;
if ( this . _weather _provider == WeatherProvider . DARKSKY ) {
if ( this . _weather _provider == WeatherProvider . DARKSKY ) {
url = "https://darksky.net/" ;
url = "https://darksky.net/" ;
@ -463,9 +459,9 @@ const OpenweatherMenuButton = new Lang.Class({
url += "?APPID=" + this . _appid ;
url += "?APPID=" + this . _appid ;
}
}
return url ;
return url ;
} ,
}
loadConfig : function ( ) {
loadConfig ( ) {
this . _settings = ExtensionUtils . getSettings ( OPENWEATHER _SETTINGS _SCHEMA ) ;
this . _settings = ExtensionUtils . getSettings ( OPENWEATHER _SETTINGS _SCHEMA ) ;
if ( this . _cities . length === 0 )
if ( this . _cities . length === 0 )
@ -488,9 +484,9 @@ const OpenweatherMenuButton = new Lang.Class({
this . rebuildButtonMenu ( ) ;
this . rebuildButtonMenu ( ) ;
this . parseWeatherCurrent ( ) ;
this . parseWeatherCurrent ( ) ;
} ) ) ;
} ) ) ;
} ,
}
loadConfigInterface : function ( ) {
loadConfigInterface ( ) {
this . _settingsInterface = ExtensionUtils . getSettings ( OPENWEATHER _DESKTOP _INTERFACE ) ;
this . _settingsInterface = ExtensionUtils . getSettings ( OPENWEATHER _DESKTOP _INTERFACE ) ;
this . _settingsInterfaceC = this . _settingsInterface . connect ( "changed" , Lang . bind ( this , function ( ) {
this . _settingsInterfaceC = this . _settingsInterface . connect ( "changed" , Lang . bind ( this , function ( ) {
this . rebuildCurrentWeatherUi ( ) ;
this . rebuildCurrentWeatherUi ( ) ;
@ -506,21 +502,21 @@ const OpenweatherMenuButton = new Lang.Class({
}
}
this . parseWeatherCurrent ( ) ;
this . parseWeatherCurrent ( ) ;
} ) ) ;
} ) ) ;
} ,
}
_onNetworkStateChanged : function ( ) {
_onNetworkStateChanged ( ) {
this . _checkConnectionState ( ) ;
this . _checkConnectionState ( ) ;
} ,
}
_checkConnectionState : function ( ) {
_checkConnectionState ( ) {
this . _checkConnectionStateRetries = 3 ;
this . _checkConnectionStateRetries = 3 ;
this . _oldConnected = this . _connected ;
this . _oldConnected = this . _connected ;
this . _connected = false ;
this . _connected = false ;
this . _checkConnectionStateWithRetries ( 1250 ) ;
this . _checkConnectionStateWithRetries ( 1250 ) ;
} ,
}
_checkConnectionStateRetry : function ( ) {
_checkConnectionStateRetry ( ) {
if ( this . _checkConnectionStateRetries > 0 ) {
if ( this . _checkConnectionStateRetries > 0 ) {
let timeout ;
let timeout ;
if ( this . _checkConnectionStateRetries == 3 )
if ( this . _checkConnectionStateRetries == 3 )
@ -533,9 +529,9 @@ const OpenweatherMenuButton = new Lang.Class({
this . _checkConnectionStateRetries -= 1 ;
this . _checkConnectionStateRetries -= 1 ;
this . _checkConnectionStateWithRetries ( timeout ) ;
this . _checkConnectionStateWithRetries ( timeout ) ;
}
}
} ,
}
_checkConnectionStateWithRetries : function ( interval ) {
_checkConnectionStateWithRetries ( interval ) {
if ( this . _timeoutCheckConnectionState ) {
if ( this . _timeoutCheckConnectionState ) {
Mainloop . source _remove ( this . _timeoutCheckConnectionState ) ;
Mainloop . source _remove ( this . _timeoutCheckConnectionState ) ;
this . _timeoutCheckConnectionState = undefined ;
this . _timeoutCheckConnectionState = undefined ;
@ -559,9 +555,9 @@ const OpenweatherMenuButton = new Lang.Class({
}
}
return false ;
return false ;
} ) ) ;
} ) ) ;
} ,
}
_asyncReadyCallback : function ( nm , res ) {
_asyncReadyCallback ( nm , res ) {
try {
try {
this . _connected = this . _network _monitor . can _reach _finish ( res ) ;
this . _connected = this . _network _monitor . can _reach _finish ( res ) ;
} catch ( err ) {
} catch ( err ) {
@ -580,17 +576,17 @@ const OpenweatherMenuButton = new Lang.Class({
this . forecastWeatherCache = undefined ;
this . forecastWeatherCache = undefined ;
this . parseWeatherCurrent ( ) ;
this . parseWeatherCurrent ( ) ;
}
}
} ,
}
locationChanged : function ( ) {
locationChanged ( ) {
let location = this . extractCoord ( this . _city ) ;
let location = this . extractCoord ( this . _city ) ;
if ( this . oldLocation != location ) {
if ( this . oldLocation != location ) {
return true ;
return true ;
}
}
return false ;
return false ;
} ,
}
providerChanged : function ( ) {
providerChanged ( ) {
let provider = this . _weather _provider ;
let provider = this . _weather _provider ;
if ( this . oldProvider != provider ) {
if ( this . oldProvider != provider ) {
this . oldProvider = provider ;
this . oldProvider = provider ;
@ -611,13 +607,13 @@ const OpenweatherMenuButton = new Lang.Class({
}
}
}
}
return false ;
return false ;
} ,
}
get _clockFormat ( ) {
get _clockFormat ( ) {
if ( ! this . _settingsInterface )
if ( ! this . _settingsInterface )
this . loadConfigInterface ( ) ;
this . loadConfigInterface ( ) ;
return this . _settingsInterface . get _string ( "clock-format" ) ;
return this . _settingsInterface . get _string ( "clock-format" ) ;
} ,
}
get _weather _provider ( ) {
get _weather _provider ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
@ -629,45 +625,45 @@ const OpenweatherMenuButton = new Lang.Class({
provider = this . _settings . get _enum ( OPENWEATHER _PROVIDER _KEY ) ;
provider = this . _settings . get _enum ( OPENWEATHER _PROVIDER _KEY ) ;
return provider ;
return provider ;
} ,
}
get _units ( ) {
get _units ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _enum ( OPENWEATHER _UNIT _KEY ) ;
return this . _settings . get _enum ( OPENWEATHER _UNIT _KEY ) ;
} ,
}
get _wind _speed _units ( ) {
get _wind _speed _units ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _enum ( OPENWEATHER _WIND _SPEED _UNIT _KEY ) ;
return this . _settings . get _enum ( OPENWEATHER _WIND _SPEED _UNIT _KEY ) ;
} ,
}
get _wind _direction ( ) {
get _wind _direction ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _boolean ( OPENWEATHER _WIND _DIRECTION _KEY ) ;
return this . _settings . get _boolean ( OPENWEATHER _WIND _DIRECTION _KEY ) ;
} ,
}
get _pressure _units ( ) {
get _pressure _units ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _enum ( OPENWEATHER _PRESSURE _UNIT _KEY ) ;
return this . _settings . get _enum ( OPENWEATHER _PRESSURE _UNIT _KEY ) ;
} ,
}
get _cities ( ) {
get _cities ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _string ( OPENWEATHER _CITY _KEY ) ;
return this . _settings . get _string ( OPENWEATHER _CITY _KEY ) ;
} ,
}
set _cities ( v ) {
set _cities ( v ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . set _string ( OPENWEATHER _CITY _KEY , v ) ;
return this . _settings . set _string ( OPENWEATHER _CITY _KEY , v ) ;
} ,
}
_onButtonHoverChanged : function ( actor , event ) {
_onButtonHoverChanged ( actor , event ) {
if ( actor . hover ) {
if ( actor . hover ) {
actor . add _style _pseudo _class ( 'hover' ) ;
actor . add _style _pseudo _class ( 'hover' ) ;
actor . set _style ( this . _button _background _style ) ;
actor . set _style ( this . _button _background _style ) ;
@ -677,9 +673,9 @@ const OpenweatherMenuButton = new Lang.Class({
if ( actor != this . _urlButton )
if ( actor != this . _urlButton )
actor . set _style ( this . _button _border _style ) ;
actor . set _style ( this . _button _border _style ) ;
}
}
} ,
}
_updateButtonColors : function ( ) {
_updateButtonColors ( ) {
if ( ! this . _needsColorUpdate )
if ( ! this . _needsColorUpdate )
return ;
return ;
this . _needsColorUpdate = false ;
this . _needsColorUpdate = false ;
@ -700,10 +696,10 @@ const OpenweatherMenuButton = new Lang.Class({
color = this . _buttonMenu . get _theme _node ( ) . get _background _color ( ) ;
color = this . _buttonMenu . get _theme _node ( ) . get _background _color ( ) ;
this . _button _background _style = 'background-color:rgba(' + color . red + ',' + color . green + ',' + color . blue + ',' + ( Math . round ( color . alpha / 2.55 ) / 100 ) + ');' ;
this . _button _background _style = 'background-color:rgba(' + color . red + ',' + color . green + ',' + color . blue + ',' + ( Math . round ( color . alpha / 2.55 ) / 100 ) + ');' ;
this . _buttonMenu . remove _style _pseudo _class ( 'active' ) ;
this . _buttonMenu . remove _style _pseudo _class ( 'active' ) ;
} ,
}
createButton : function ( iconName , accessibleName ) {
createButton ( iconName , accessibleName ) {
let button ;
let button ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
@ -722,7 +718,7 @@ const OpenweatherMenuButton = new Lang.Class({
button = Main . panel . statusArea . aggregateMenu . _system . _createActionButton ( iconName , accessibleName ) ;
button = Main . panel . statusArea . aggregateMenu . _system . _createActionButton ( iconName , accessibleName ) ;
return button ;
return button ;
} ,
}
get _actual _city ( ) {
get _actual _city ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
@ -746,7 +742,7 @@ const OpenweatherMenuButton = new Lang.Class({
a = l ;
a = l ;
return a ;
return a ;
} ,
}
set _actual _city ( a ) {
set _actual _city ( a ) {
if ( ! this . _settings )
if ( ! this . _settings )
@ -768,7 +764,7 @@ const OpenweatherMenuButton = new Lang.Class({
a = l ;
a = l ;
this . _settings . set _int ( OPENWEATHER _ACTUAL _CITY _KEY , a ) ;
this . _settings . set _int ( OPENWEATHER _ACTUAL _CITY _KEY , a ) ;
} ,
}
get _city ( ) {
get _city ( ) {
let cities = this . _cities . split ( " && " ) ;
let cities = this . _cities . split ( " && " ) ;
@ -778,94 +774,94 @@ const OpenweatherMenuButton = new Lang.Class({
return "" ;
return "" ;
cities = cities [ this . _actual _city ] ;
cities = cities [ this . _actual _city ] ;
return cities ;
return cities ;
} ,
}
get _translate _condition ( ) {
get _translate _condition ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _boolean ( OPENWEATHER _TRANSLATE _CONDITION _KEY ) ;
return this . _settings . get _boolean ( OPENWEATHER _TRANSLATE _CONDITION _KEY ) ;
} ,
}
get _getIconType ( ) {
get _getIconType ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _boolean ( OPENWEATHER _USE _SYMBOLIC _ICONS _KEY ) ? 1 : 0 ;
return this . _settings . get _boolean ( OPENWEATHER _USE _SYMBOLIC _ICONS _KEY ) ? 1 : 0 ;
} ,
}
get _use _text _on _buttons ( ) {
get _use _text _on _buttons ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _boolean ( OPENWEATHER _USE _TEXT _ON _BUTTONS _KEY ) ? 1 : 0 ;
return this . _settings . get _boolean ( OPENWEATHER _USE _TEXT _ON _BUTTONS _KEY ) ? 1 : 0 ;
} ,
}
get _text _in _panel ( ) {
get _text _in _panel ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _boolean ( OPENWEATHER _SHOW _TEXT _IN _PANEL _KEY ) ;
return this . _settings . get _boolean ( OPENWEATHER _SHOW _TEXT _IN _PANEL _KEY ) ;
} ,
}
get _position _in _panel ( ) {
get _position _in _panel ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _enum ( OPENWEATHER _POSITION _IN _PANEL _KEY ) ;
return this . _settings . get _enum ( OPENWEATHER _POSITION _IN _PANEL _KEY ) ;
} ,
}
get _menu _alignment ( ) {
get _menu _alignment ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _double ( OPENWEATHER _MENU _ALIGNMENT _KEY ) ;
return this . _settings . get _double ( OPENWEATHER _MENU _ALIGNMENT _KEY ) ;
} ,
}
get _comment _in _panel ( ) {
get _comment _in _panel ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _boolean ( OPENWEATHER _SHOW _COMMENT _IN _PANEL _KEY ) ;
return this . _settings . get _boolean ( OPENWEATHER _SHOW _COMMENT _IN _PANEL _KEY ) ;
} ,
}
get _comment _in _forecast ( ) {
get _comment _in _forecast ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _boolean ( OPENWEATHER _SHOW _COMMENT _IN _FORECAST _KEY ) ;
return this . _settings . get _boolean ( OPENWEATHER _SHOW _COMMENT _IN _FORECAST _KEY ) ;
} ,
}
get _refresh _interval _current ( ) {
get _refresh _interval _current ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
let v = this . _settings . get _int ( OPENWEATHER _REFRESH _INTERVAL _CURRENT ) ;
let v = this . _settings . get _int ( OPENWEATHER _REFRESH _INTERVAL _CURRENT ) ;
return ( ( v >= 600 ) ? v : 600 ) ;
return ( ( v >= 600 ) ? v : 600 ) ;
} ,
}
get _refresh _interval _forecast ( ) {
get _refresh _interval _forecast ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
let v = this . _settings . get _int ( OPENWEATHER _REFRESH _INTERVAL _FORECAST ) ;
let v = this . _settings . get _int ( OPENWEATHER _REFRESH _INTERVAL _FORECAST ) ;
return ( ( v >= 600 ) ? v : 600 ) ;
return ( ( v >= 600 ) ? v : 600 ) ;
} ,
}
get _loc _len _current ( ) {
get _loc _len _current ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
let v = this . _settings . get _int ( OPENWEATHER _LOC _TEXT _LEN ) ;
let v = this . _settings . get _int ( OPENWEATHER _LOC _TEXT _LEN ) ;
return ( ( v > 0 ) ? v : 0 ) ;
return ( ( v > 0 ) ? v : 0 ) ;
} ,
}
get _center _forecast ( ) {
get _center _forecast ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _boolean ( OPENWEATHER _CENTER _FORECAST _KEY ) ;
return this . _settings . get _boolean ( OPENWEATHER _CENTER _FORECAST _KEY ) ;
} ,
}
get _days _forecast ( ) {
get _days _forecast ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _int ( OPENWEATHER _DAYS _FORECAST ) ;
return this . _settings . get _int ( OPENWEATHER _DAYS _FORECAST ) ;
} ,
}
get _decimal _places ( ) {
get _decimal _places ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _int ( OPENWEATHER _DECIMAL _PLACES ) ;
return this . _settings . get _int ( OPENWEATHER _DECIMAL _PLACES ) ;
} ,
}
get _appid ( ) {
get _appid ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
@ -876,22 +872,22 @@ const OpenweatherMenuButton = new Lang.Class({
else
else
key = this . _settings . get _string ( OPENWEATHER _OWM _API _KEY ) ;
key = this . _settings . get _string ( OPENWEATHER _OWM _API _KEY ) ;
return ( key . length == 32 ) ? key : '' ;
return ( key . length == 32 ) ? key : '' ;
} ,
}
get _use _default _owm _key ( ) {
get _use _default _owm _key ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
return this . _settings . get _boolean ( OPENWEATHER _USE _DEFAULT _OWM _API _KEY ) ;
return this . _settings . get _boolean ( OPENWEATHER _USE _DEFAULT _OWM _API _KEY ) ;
} ,
}
get _appid _fc ( ) {
get _appid _fc ( ) {
if ( ! this . _settings )
if ( ! this . _settings )
this . loadConfig ( ) ;
this . loadConfig ( ) ;
let key = this . _settings . get _string ( OPENWEATHER _FC _API _KEY ) ;
let key = this . _settings . get _string ( OPENWEATHER _FC _API _KEY ) ;
return ( key . length == 32 ) ? key : '' ;
return ( key . length == 32 ) ? key : '' ;
} ,
}
rebuildButtonMenu : function ( ) {
rebuildButtonMenu ( ) {
if ( this . _buttonBox ) {
if ( this . _buttonBox ) {
if ( this . _buttonBox1 ) {
if ( this . _buttonBox1 ) {
this . _buttonBox1 . destroy ( ) ;
this . _buttonBox1 . destroy ( ) ;
@ -989,9 +985,9 @@ const OpenweatherMenuButton = new Lang.Class({
this . _buttonMenu . add _actor ( this . _buttonBox2 ) ;
this . _buttonMenu . add _actor ( this . _buttonBox2 ) ;
}
}
this . _buttonBox1MinWidth = undefined ;
this . _buttonBox1MinWidth = undefined ;
} ,
}
rebuildSelectCityItem : function ( ) {
rebuildSelectCityItem ( ) {
this . _selectCity . menu . removeAll ( ) ;
this . _selectCity . menu . removeAll ( ) ;
let item = null ;
let item = null ;
@ -1022,22 +1018,22 @@ const OpenweatherMenuButton = new Lang.Class({
else
else
this . _selectCity . show ( ) ;
this . _selectCity . show ( ) ;
} ,
}
_onActivate : function ( ) {
_onActivate ( ) {
openweatherMenu . _actual _city = this . location ;
openweatherMenu . _actual _city = this . location ;
} ,
}
extractLocation : function ( ) {
extractLocation ( ) {
if ( ! arguments [ 0 ] )
if ( ! arguments [ 0 ] )
return "" ;
return "" ;
if ( arguments [ 0 ] . search ( ">" ) == - 1 )
if ( arguments [ 0 ] . search ( ">" ) == - 1 )
return _ ( "Invalid city" ) ;
return _ ( "Invalid city" ) ;
return arguments [ 0 ] . split ( ">" ) [ 1 ] ;
return arguments [ 0 ] . split ( ">" ) [ 1 ] ;
} ,
}
extractCoord : function ( ) {
extractCoord ( ) {
let coords = 0 ;
let coords = 0 ;
if ( arguments [ 0 ] && ( arguments [ 0 ] . search ( ">" ) != - 1 ) )
if ( arguments [ 0 ] && ( arguments [ 0 ] . search ( ">" ) != - 1 ) )
@ -1049,9 +1045,9 @@ const OpenweatherMenuButton = new Lang.Class({
}
}
return coords ;
return coords ;
} ,
}
extractProvider : function ( ) {
extractProvider ( ) {
if ( ! arguments [ 0 ] )
if ( ! arguments [ 0 ] )
return - 1 ;
return - 1 ;
if ( arguments [ 0 ] . split ( ">" ) [ 2 ] === undefined )
if ( arguments [ 0 ] . split ( ">" ) [ 2 ] === undefined )
@ -1059,15 +1055,15 @@ const OpenweatherMenuButton = new Lang.Class({
if ( isNaN ( parseInt ( arguments [ 0 ] . split ( ">" ) [ 2 ] ) ) )
if ( isNaN ( parseInt ( arguments [ 0 ] . split ( ">" ) [ 2 ] ) ) )
return - 1 ;
return - 1 ;
return parseInt ( arguments [ 0 ] . split ( ">" ) [ 2 ] ) ;
return parseInt ( arguments [ 0 ] . split ( ">" ) [ 2 ] ) ;
} ,
}
_onPreferencesActivate : function ( ) {
_onPreferencesActivate ( ) {
this . menu . actor . hide ( ) ;
this . menu . actor . hide ( ) ;
Util . spawn ( [ "gnome-shell-extension-prefs" , "openweather-extension@jenslody.de" ] ) ;
Util . spawn ( [ "gnome-shell-extension-prefs" , "openweather-extension@jenslody.de" ] ) ;
return 0 ;
return 0 ;
} ,
}
recalcLayout : function ( ) {
recalcLayout ( ) {
if ( ! this . menu . isOpen )
if ( ! this . menu . isOpen )
return ;
return ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
@ -1087,9 +1083,9 @@ const OpenweatherMenuButton = new Lang.Class({
this . _forecastScrollBox . hscroll . hide ( ) ;
this . _forecastScrollBox . hscroll . hide ( ) ;
}
}
}
}
} ,
}
unit _to _unicode : function ( ) {
unit _to _unicode ( ) {
if ( this . _units == WeatherUnits . FAHRENHEIT )
if ( this . _units == WeatherUnits . FAHRENHEIT )
return _ ( '\u00B0F' ) ;
return _ ( '\u00B0F' ) ;
else if ( this . _units == WeatherUnits . KELVIN )
else if ( this . _units == WeatherUnits . KELVIN )
@ -1106,45 +1102,45 @@ const OpenweatherMenuButton = new Lang.Class({
return _ ( '\u00B0N' ) ;
return _ ( '\u00B0N' ) ;
else
else
return _ ( '\u00B0C' ) ;
return _ ( '\u00B0C' ) ;
} ,
}
hasIcon : function ( icon ) {
hasIcon ( icon ) {
return Gtk . IconTheme . get _default ( ) . has _icon ( icon ) ;
return Gtk . IconTheme . get _default ( ) . has _icon ( icon ) ;
} ,
}
toFahrenheit : function ( t ) {
toFahrenheit ( t ) {
return ( ( Number ( t ) * 1.8 ) + 32 ) . toFixed ( this . _decimal _places ) ;
return ( ( Number ( t ) * 1.8 ) + 32 ) . toFixed ( this . _decimal _places ) ;
} ,
}
toKelvin : function ( t ) {
toKelvin ( t ) {
return ( Number ( t ) + 273.15 ) . toFixed ( this . _decimal _places ) ;
return ( Number ( t ) + 273.15 ) . toFixed ( this . _decimal _places ) ;
} ,
}
toRankine : function ( t ) {
toRankine ( t ) {
return ( ( Number ( t ) * 1.8 ) + 491.67 ) . toFixed ( this . _decimal _places ) ;
return ( ( Number ( t ) * 1.8 ) + 491.67 ) . toFixed ( this . _decimal _places ) ;
} ,
}
toReaumur : function ( t ) {
toReaumur ( t ) {
return ( Number ( t ) * 0.8 ) . toFixed ( this . _decimal _places ) ;
return ( Number ( t ) * 0.8 ) . toFixed ( this . _decimal _places ) ;
} ,
}
toRoemer : function ( t ) {
toRoemer ( t ) {
return ( ( Number ( t ) * 21 / 40 ) + 7.5 ) . toFixed ( this . _decimal _places ) ;
return ( ( Number ( t ) * 21 / 40 ) + 7.5 ) . toFixed ( this . _decimal _places ) ;
} ,
}
toDelisle : function ( t ) {
toDelisle ( t ) {
return ( ( 100 - Number ( t ) ) * 1.5 ) . toFixed ( this . _decimal _places ) ;
return ( ( 100 - Number ( t ) ) * 1.5 ) . toFixed ( this . _decimal _places ) ;
} ,
}
toNewton : function ( t ) {
toNewton ( t ) {
return ( Number ( t ) - 0.33 ) . toFixed ( this . _decimal _places ) ;
return ( Number ( t ) - 0.33 ) . toFixed ( this . _decimal _places ) ;
} ,
}
toInHg : function ( p /*, t*/ ) {
toInHg ( p /*, t*/ ) {
return ( p / 33.86530749 ) . toFixed ( this . _decimal _places ) ;
return ( p / 33.86530749 ) . toFixed ( this . _decimal _places ) ;
} ,
}
toBeaufort : function ( w , t ) {
toBeaufort ( w , t ) {
if ( w < 0.3 )
if ( w < 0.3 )
return ( ! t ) ? "0" : "(" + _ ( "Calm" ) + ")" ;
return ( ! t ) ? "0" : "(" + _ ( "Calm" ) + ")" ;
@ -1183,29 +1179,29 @@ const OpenweatherMenuButton = new Lang.Class({
else
else
return ( ! t ) ? "12" : "(" + _ ( "Hurricane" ) + ")" ;
return ( ! t ) ? "12" : "(" + _ ( "Hurricane" ) + ")" ;
} ,
}
getLocaleDay : function ( abr ) {
getLocaleDay ( abr ) {
let days = [ _ ( 'Sunday' ) , _ ( 'Monday' ) , _ ( 'Tuesday' ) , _ ( 'Wednesday' ) , _ ( 'Thursday' ) , _ ( 'Friday' ) , _ ( 'Saturday' ) ] ;
let days = [ _ ( 'Sunday' ) , _ ( 'Monday' ) , _ ( 'Tuesday' ) , _ ( 'Wednesday' ) , _ ( 'Thursday' ) , _ ( 'Friday' ) , _ ( 'Saturday' ) ] ;
return days [ abr ] ;
return days [ abr ] ;
} ,
}
getWindDirection : function ( deg ) {
getWindDirection ( deg ) {
let arrows = [ "\u2193" , "\u2199" , "\u2190" , "\u2196" , "\u2191" , "\u2197" , "\u2192" , "\u2198" ] ;
let arrows = [ "\u2193" , "\u2199" , "\u2190" , "\u2196" , "\u2191" , "\u2197" , "\u2192" , "\u2198" ] ;
let letters = [ _ ( 'N' ) , _ ( 'NE' ) , _ ( 'E' ) , _ ( 'SE' ) , _ ( 'S' ) , _ ( 'SW' ) , _ ( 'W' ) , _ ( 'NW' ) ] ;
let letters = [ _ ( 'N' ) , _ ( 'NE' ) , _ ( 'E' ) , _ ( 'SE' ) , _ ( 'S' ) , _ ( 'SW' ) , _ ( 'W' ) , _ ( 'NW' ) ] ;
let idx = Math . round ( deg / 45 ) % arrows . length ;
let idx = Math . round ( deg / 45 ) % arrows . length ;
return ( this . _wind _direction ) ? arrows [ idx ] : letters [ idx ] ;
return ( this . _wind _direction ) ? arrows [ idx ] : letters [ idx ] ;
} ,
}
getIconType : function ( ) {
getIconType ( ) {
if ( this . _getIconType ) {
if ( this . _getIconType ) {
return "openweather-symbolic" ;
return "openweather-symbolic" ;
} else {
} else {
return "openweather-regular" ;
return "openweather-regular" ;
}
}
} ,
}
load _json _async : function ( url , params , fun ) {
load _json _async ( url , params , fun ) {
if ( _httpSession === undefined ) {
if ( _httpSession === undefined ) {
_httpSession = new Soup . Session ( ) ;
_httpSession = new Soup . Session ( ) ;
_httpSession . user _agent = this . user _agent ;
_httpSession . user _agent = this . user _agent ;
@ -1230,16 +1226,16 @@ const OpenweatherMenuButton = new Lang.Class({
}
}
} ) ) ;
} ) ) ;
return ;
return ;
} ,
}
checkAlignment : function ( ) {
checkAlignment ( ) {
let menuAlignment = 1.0 - ( this . _menu _alignment / 100 ) ;
let menuAlignment = 1.0 - ( this . _menu _alignment / 100 ) ;
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 ;
this . menu . _arrowAlignment = menuAlignment ;
this . menu . _arrowAlignment = menuAlignment ;
} ,
}
checkPositionInPanel : function ( ) {
checkPositionInPanel ( ) {
if ( this . _old _position _in _panel != this . _position _in _panel ) {
if ( this . _old _position _in _panel != this . _position _in _panel ) {
switch ( this . _old _position _in _panel ) {
switch ( this . _old _position _in _panel ) {
case WeatherPosition . LEFT :
case WeatherPosition . LEFT :
@ -1271,9 +1267,9 @@ const OpenweatherMenuButton = new Lang.Class({
this . _old _position _in _panel = this . _position _in _panel ;
this . _old _position _in _panel = this . _position _in _panel ;
}
}
} ,
}
formatPressure : function ( pressure ) {
formatPressure ( pressure ) {
let pressure _unit = _ ( 'hPa' ) ;
let pressure _unit = _ ( 'hPa' ) ;
switch ( this . _pressure _units ) {
switch ( this . _pressure _units ) {
case WeatherPressureUnits . INHG :
case WeatherPressureUnits . INHG :
@ -1332,9 +1328,9 @@ const OpenweatherMenuButton = new Lang.Class({
break ;
break ;
}
}
return parseFloat ( pressure ) . toLocaleString ( this . locale ) + ' ' + pressure _unit ;
return parseFloat ( pressure ) . toLocaleString ( this . locale ) + ' ' + pressure _unit ;
} ,
}
formatTemperature : function ( temperature ) {
formatTemperature ( temperature ) {
switch ( this . _units ) {
switch ( this . _units ) {
case WeatherUnits . FAHRENHEIT :
case WeatherUnits . FAHRENHEIT :
temperature = this . toFahrenheit ( temperature ) ;
temperature = this . toFahrenheit ( temperature ) ;
@ -1369,9 +1365,9 @@ const OpenweatherMenuButton = new Lang.Class({
break ;
break ;
}
}
return parseFloat ( temperature ) . toLocaleString ( this . locale ) . replace ( '-' , '\u2212' ) + ' ' + this . unit _to _unicode ( ) ;
return parseFloat ( temperature ) . toLocaleString ( this . locale ) . replace ( '-' , '\u2212' ) + ' ' + this . unit _to _unicode ( ) ;
} ,
}
formatWind : function ( speed , direction ) {
formatWind ( speed , direction ) {
let unit = _ ( 'm/s' ) ;
let unit = _ ( 'm/s' ) ;
switch ( this . _wind _speed _units ) {
switch ( this . _wind _speed _units ) {
case WeatherWindSpeedUnits . MPH :
case WeatherWindSpeedUnits . MPH :
@ -1411,9 +1407,9 @@ const OpenweatherMenuButton = new Lang.Class({
return parseFloat ( speed ) . toLocaleString ( this . locale ) + ' ' + unit ;
return parseFloat ( speed ) . toLocaleString ( this . locale ) + ' ' + unit ;
else // i.e. speed > 0 && direction
else // i.e. speed > 0 && direction
return direction + ' ' + parseFloat ( speed ) . toLocaleString ( this . locale ) + ' ' + unit ;
return direction + ' ' + parseFloat ( speed ) . toLocaleString ( this . locale ) + ' ' + unit ;
} ,
}
reloadWeatherCurrent : function ( interval ) {
reloadWeatherCurrent ( interval ) {
if ( this . _timeoutCurrent ) {
if ( this . _timeoutCurrent ) {
Mainloop . source _remove ( this . _timeoutCurrent ) ;
Mainloop . source _remove ( this . _timeoutCurrent ) ;
this . _timeoutCurrent = undefined ;
this . _timeoutCurrent = undefined ;
@ -1426,9 +1422,9 @@ const OpenweatherMenuButton = new Lang.Class({
this . parseWeatherCurrent ( ) ;
this . parseWeatherCurrent ( ) ;
return true ;
return true ;
} ) ) ;
} ) ) ;
} ,
}
reloadWeatherForecast : function ( interval ) {
reloadWeatherForecast ( interval ) {
if ( this . _timeoutForecast ) {
if ( this . _timeoutForecast ) {
Mainloop . source _remove ( this . _timeoutForecast ) ;
Mainloop . source _remove ( this . _timeoutForecast ) ;
this . _timeoutForecast = undefined ;
this . _timeoutForecast = undefined ;
@ -1441,19 +1437,19 @@ const OpenweatherMenuButton = new Lang.Class({
this . parseWeatherForecast ( ) ;
this . parseWeatherForecast ( ) ;
return true ;
return true ;
} ) ) ;
} ) ) ;
} ,
}
destroyCurrentWeather : function ( ) {
destroyCurrentWeather ( ) {
if ( this . _currentWeather . get _child ( ) !== null )
if ( this . _currentWeather . get _child ( ) !== null )
this . _currentWeather . get _child ( ) . destroy ( ) ;
this . _currentWeather . get _child ( ) . destroy ( ) ;
} ,
}
destroyFutureWeather : function ( ) {
destroyFutureWeather ( ) {
if ( this . _futureWeather . get _child ( ) !== null )
if ( this . _futureWeather . get _child ( ) !== null )
this . _futureWeather . get _child ( ) . destroy ( ) ;
this . _futureWeather . get _child ( ) . destroy ( ) ;
} ,
}
rebuildCurrentWeatherUi : function ( ) {
rebuildCurrentWeatherUi ( ) {
this . _weatherInfo . text = ( ' ' ) ;
this . _weatherInfo . text = ( ' ' ) ;
this . _weatherIcon . icon _name = 'view-refresh' ;
this . _weatherIcon . icon _name = 'view-refresh' ;
this . _weatherIcon . remove _style _class _name ( 'openweather-regular' ) ;
this . _weatherIcon . remove _style _class _name ( 'openweather-regular' ) ;
@ -1580,15 +1576,15 @@ const OpenweatherMenuButton = new Lang.Class({
box . add _actor ( this . _currentWeatherIcon ) ;
box . add _actor ( this . _currentWeatherIcon ) ;
box . add _actor ( xb ) ;
box . add _actor ( xb ) ;
this . _currentWeather . set _child ( box ) ;
this . _currentWeather . set _child ( box ) ;
} ,
}
scrollForecastBy : function ( delta ) {
scrollForecastBy ( delta ) {
if ( this . _forecastScrollBox === undefined )
if ( this . _forecastScrollBox === undefined )
return ;
return ;
this . _forecastScrollBox . hscroll . adjustment . value += delta ;
this . _forecastScrollBox . hscroll . adjustment . value += delta ;
} ,
}
rebuildFutureWeatherUi : function ( cnt ) {
rebuildFutureWeatherUi ( cnt ) {
this . destroyFutureWeather ( ) ;
this . destroyFutureWeather ( ) ;
this . _forecast = [ ] ;
this . _forecast = [ ] ;
@ -1666,9 +1662,9 @@ const OpenweatherMenuButton = new Lang.Class({
this . _forecastBox . add _actor ( bb ) ;
this . _forecastBox . add _actor ( bb ) ;
}
}
this . _forecastScrollBox . add _actor ( this . _forecastBox ) ;
this . _forecastScrollBox . add _actor ( this . _forecastBox ) ;
} ,
}
_onScroll : function ( actor , event ) {
_onScroll ( actor , event ) {
let dx = 0 ;
let dx = 0 ;
let dy = 0 ;
let dy = 0 ;
switch ( event . get _scroll _direction ( ) ) {
switch ( event . get _scroll _direction ( ) ) {