@ -1,37 +1,46 @@
#! /usr/bin/env seed
/ *
*
* Weather Settings for GNOME Shell Extension Weather
* Weather extension for GNOME Shell preferences
* - Creates a widget to set the preferences of the weather extension
*
* Copyright ( C ) 2012
* Christian METZLER < neroth @ xeked . com >
*
* Canek Peláez < canek @ ciencias . unam . mx > ,
* Christian METZLER < neroth @ xeked . com > ,
*
* This file is part of gnome - shell - extension - weather .
*
* gnome - shell - extension - weather is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
* gnome - shell - extension - weather is free software : you can
* redistribute it and / or modify it under the terms of the GNU
* General Public License as published by the Free Software
* Foundation , either version 3 of the License , or ( at your option )
* any later version .
*
* gnome - shell - extension - weather is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
* gnome - shell - extension - weather is distributed in the hope that it
* will be useful , but WITHOUT ANY WARRANTY ; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE . See the GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with gnome - shell - extension - weather . If not , see < http : //www.gnu.org/licenses/>.
* along with gnome - shell - extension - weather . If not , see
* < http : //www.gnu.org/licenses/>.
*
* /
const Gtk = imports . gi . Gtk ;
const GObject = imports . gi . GObject ;
const GtkBuilder = imports . gtkb uilder;
const GtkBuilder = Gtk . B uilder;
const Gio = imports . gi . Gio ;
const Gettext = imports . gettext ;
const Gettext = imports . gettext . domain ( 'gnome-shell-extension-weather' ) ;
const _ = Gettext . gettext ;
const Soup = imports . gi . Soup ;
const Lang = imports . lang ;
const ExtensionUtils = imports . misc . extensionUtils ;
const Me = ExtensionUtils . getCurrentExtension ( ) ;
const Convenience = Me . imports . convenience ;
const EXTENSIONDIR = Me . dir . get _path ( ) ;
const WEATHER _SETTINGS _SCHEMA = 'org.gnome.shell.extensions.weather' ;
const WEATHER _UNIT _KEY = 'unit' ;
const WEATHER _PRESSURE _UNIT _KEY = 'pressure-unit' ;
@ -50,32 +59,206 @@ const WEATHER_REFRESH_INTERVAL = 'refresh-interval';
const _httpSession = new Soup . SessionAsync ( ) ;
Soup . Session . prototype . add _feature . call ( _httpSession , new Soup . ProxyResolverDefault ( ) ) ;
var WeatherSetting = function ( )
const Window = new Gtk . Builder ( ) ;
Window . add _from _file ( EXTENSIONDIR + "/weather-settings.ui" ) ;
const MainWidget = Window . get _object ( "main-widget" ) ;
const treeview = Window . get _object ( "tree-treeview" ) ;
const liststore = Window . get _object ( "liststore" ) ;
const Iter = liststore . get _iter _first ( ) ;
let mCities = null ;
const PrefsWidget = new GObject . Class (
{
Gettext . textdomain ( "gnome-shell-extension-weather" ) ;
Name : 'WeatherExtension.Prefs.Widget' ,
GTypeName : 'WeatherExtensionPrefsWidget' ,
Extends : Gtk . Box ,
Gtk . init ( Seed . argv ) ;
_init : function ( params )
{
this . parent ( params ) ;
this . initWindow ( ) ;
this . initWindow ( ) ;
this . refreshUI ( ) ;
this . refreshUI ( ) ;
this . showWindow ( ) ;
this . add ( MainWidget ) ;
} ,
Gtk . main ( ) ;
} ;
initWindow : function ( )
{
let that = this ;
Window . get _object ( "tree-toolbutton-add" ) . connect ( "clicked" , function ( )
{
that . addCity ( ) ;
} ) ;
Window . get _object ( "tree-toolbutton-remove" ) . connect ( "clicked" , function ( )
{
that . removeCity ( ) ;
} ) ;
Window . get _object ( "treeview-selection" ) . connect ( "changed" , function ( selection )
{
that . selectionChanged ( selection ) ;
} ) ;
treeview . set _model ( liststore ) ;
let column = new Gtk . TreeViewColumn ( )
treeview . append _column ( column ) ;
let renderer = new Gtk . CellRendererText ( ) ;
column . pack _start ( renderer , null ) ;
column . set _cell _data _func ( renderer , function ( )
{
arguments [ 1 ] . markup = arguments [ 2 ] . get _value ( arguments [ 3 ] , 0 ) ;
} ) ;
this . initConfigWidget ( ) ;
this . addLabel ( _ ( "Temperature Unit" ) ) ;
this . addComboBox ( [ "\u00b0C" , "\u00b0F" , "K" , "\u00b0Ra" , "\u00b0R\u00E9" , "\u00b0R\u00F8" , "\u00b0De" , "\u00b0N" ] , "units" ) ;
this . addLabel ( _ ( "Wind Speed Unit" ) ) ;
this . addComboBox ( [ "km/h" , "mph" , "m/s" , "kn" , "ft/s" , "Beaufort" ] , "wind_speed_unit" ) ;
this . addLabel ( _ ( "Pressure Unit" ) ) ;
this . addComboBox ( [ "hPa" , "inHg" , "bar" , "Pa" , "kPa" , "atm" , "at" , "Torr" , "psi" ] , "pressure_unit" ) ;
this . addLabel ( _ ( "Position in Panel" ) ) ;
this . addComboBox ( [ _ ( "Center" ) , _ ( "Right" ) , _ ( "Left" ) ] , "position_in_panel" ) ;
this . addLabel ( _ ( "Wind Direction by Arrows" ) ) ;
this . addSwitch ( "wind_direction" ) ;
this . addLabel ( _ ( "Translate Conditions" ) ) ;
this . addSwitch ( "translate_condition" ) ;
this . addLabel ( _ ( "Symbolic Icons" ) ) ;
this . addSwitch ( "icon_type" ) ;
this . addLabel ( _ ( "Temperature in Panel" ) ) ;
this . addSwitch ( "text_in_panel" ) ;
this . addLabel ( _ ( "Conditions in Panel" ) ) ;
this . addSwitch ( "comment_in_panel" ) ;
} ,
refreshUI : function ( )
{
Window . get _object ( "tree-toolbutton-remove" ) . sensitive = Boolean ( this . city . length ) ;
if ( mCities != this . city )
{
if ( typeof liststore != "undefined" )
liststore . clear ( ) ;
if ( this . city . length > 0 )
{
let city = String ( this . city ) . split ( " && " ) ;
if ( city && typeof city == "string" )
city = [ city ] ;
let current = liststore . get _iter _first ( ) ;
for ( let i in city )
{
current = liststore . append ( ) ;
liststore . set _value ( current , 0 , this . extractLocation ( city [ i ] ) ) ;
}
}
mCities = this . city ;
}
this . changeSelection ( ) ;
let config = this . configWidgets ;
for ( let i in config )
if ( config [ i ] [ 0 ] . active != this [ config [ i ] [ 1 ] ] )
config [ i ] [ 0 ] . active = this [ config [ i ] [ 1 ] ] ;
} ,
initConfigWidget : function ( )
{
let a = Window . get _object ( "right-widget-table" ) ;
a . visible = 1 ;
a . can _focus = 0 ;
this . widget = a ;
} ,
x : [ 0 , 1 ] ,
y : [ 0 , 1 ] ,
configWidgets : [ ] ,
inc : function ( )
{
if ( this . x [ 0 ] == 1 )
{
this . x [ 0 ] = 0 ;
this . x [ 1 ] = 1 ;
this . y [ 0 ] += 1 ;
this . y [ 1 ] += 1 ;
}
else
{
this . x [ 0 ] += 1 ;
this . x [ 1 ] += 1 ;
}
} ,
addLabel : function ( text )
{
let l = new Gtk . Label ( { label : text , xalign : 0 } ) ;
l . visible = 1 ;
l . can _focus = 0 ;
this . widget . attach ( l , this . x [ 0 ] , this . x [ 1 ] , this . y [ 0 ] , this . y [ 1 ] , 0 , 0 , 0 , 0 ) ;
this . inc ( ) ;
} ,
addComboBox : function ( a , b )
{
let that = this ;
let cf = new Gtk . ComboBoxText ( ) ;
this . configWidgets . push ( [ cf , b ] ) ;
cf . visible = 1 ;
cf . can _focus = 0 ;
cf . width _request = 100 ;
for ( let i in a )
cf . append _text ( a [ i ] ) ;
cf . active = this [ b ] ;
cf . connect ( "changed" , function ( ) { that [ b ] = arguments [ 0 ] . active ; } ) ;
this . widget . attach ( cf , this . x [ 0 ] , this . x [ 1 ] , this . y [ 0 ] , this . y [ 1 ] , 0 , 0 , 0 , 0 ) ;
this . inc ( ) ;
} ,
addSwitch : function ( a )
{
let that = this ;
let sw = new Gtk . Switch ( ) ;
this . configWidgets . push ( [ sw , a ] ) ;
sw . visible = 1 ;
sw . can _focus = 0 ;
sw . active = this [ a ] ;
sw . connect ( "notify::active" , function ( ) { that [ a ] = arguments [ 0 ] . active ; } ) ;
this . widget . attach ( sw , this . x [ 0 ] , this . x [ 1 ] , this . y [ 0 ] , this . y [ 1 ] , 0 , 0 , 0 , 0 ) ;
this . inc ( ) ;
} ,
selectionChanged : function ( select )
{
let a = select . get _selected _rows ( liststore ) [ 0 ] [ 0 ] ;
if ( typeof a != "undefined" )
if ( this . actual _city != parseInt ( a . to _string ( ) ) )
this . actual _city = parseInt ( a . to _string ( ) ) ;
} ,
WeatherSetting . prototype =
{
addCity : function ( )
{
var that = this ;
var textDialog = _ ( "Name of the city" ) ;
var dialog = new Gtk . Dialog ( { title : "" } ) ;
var entry = new Gtk . Entry ( ) ;
var completion = new Gtk . EntryCompletion ( ) ;
let that = this ;
let textDialog = _ ( "Name of the city" ) ;
let dialog = new Gtk . Dialog ( { title : "" } ) ;
let entry = new Gtk . Entry ( ) ;
let completion = new Gtk . EntryCompletion ( ) ;
entry . set _completion ( completion ) ;
var completionModel = new Gtk . ListStore . c _new ( 1 , [ GObject . TYPE _STRING ] ) ;
let completionModel = new Gtk . ListStore . new ( [ GObject . TYPE _STRING ] ) ;
completion . set _model ( completionModel ) ;
completion . set _text _column ( 0 ) ;
completion . set _popup _single _match ( true ) ;
@ -83,21 +266,23 @@ WeatherSetting.prototype =
completion . set _match _func ( function ( completion , key , iter )
{
if ( iter )
if ( completionModel . get _value ( iter , 0 ) . value . get _string ( ) )
{
if ( completionModel . get _value ( iter , 0 ) )
return true ;
}
return false ;
} ) ;
entry . margin _top = 12 ;
entry . margin _bottom = 12 ;
var label = new Gtk . Label ( { label : textDialog } ) ;
let label = new Gtk . Label ( { label : textDialog } ) ;
dialog . set _border _width ( 12 ) ;
dialog . set _modal ( 1 ) ;
dialog . set _resizable ( 0 ) ;
dialog . set _transient _for ( this . Window . get _object ( "main-window" ) ) ;
//dialog.set_transient_for(***** Need parent Window *****);
dialog . add _button ( Gtk . STOCK _CANCEL , 0 ) ;
var d = dialog . add _button ( Gtk . STOCK _OK , 1 ) ;
let d = dialog . add _button ( Gtk . STOCK _OK , 1 ) ;
d . set _can _default ( true ) ;
d . sensitive = 0 ;
@ -105,54 +290,58 @@ WeatherSetting.prototype =
dialog . set _default ( d ) ;
entry . activates _default = true ;
var testLocation = function ( location )
let testLocation = function ( location )
{
if ( location . search ( /\[/ ) == - 1 || location . search ( /\]/ ) == - 1 )
return 0 ;
var woeid = location . split ( /\[/ ) [ 1 ] . split ( /\]/ ) [ 0 ] ;
let woeid = location . split ( /\[/ ) [ 1 ] . split ( /\]/ ) [ 0 ] ;
if ( ! woeid )
return 0 ;
that . loadJsonAsync ( encodeURI ( 'http://query.yahooapis.com/v1/public/yql?format=json& q=select woeid from geo.places where woeid = "' + woeid + '" limit 1' ) , function ( )
that . loadJsonAsync ( encodeURI ( 'http://query.yahooapis.com/v1/public/yql?q=select woeid from geo.places where woeid = "' + woeid + '" limit 1&format=json ' ) , function ( )
{
d . sensitive = 0 ;
if ( typeof arguments [ 0 ] . query == "undefined" )
return 0 ;
var city = arguments [ 0 ] . query ;
let city = arguments [ 0 ] . query ;
if ( Number ( city . count ) == 0 )
return 0 ;
d . sensitive = 1 ;
} , "test" ) ;
return 0 ;
} , "testLocation" ) ;
return 0 ;
} ;
entry . signal . changed . connect ( function ( )
let searchLocation = function ( )
{
var location = entry . get _text ( ) ;
let location = entry . get _text ( ) ;
if ( testLocation ( location ) == 0 )
that . loadJsonAsync ( encodeURI ( 'http://query.yahooapis.com/v1/public/yql?q=select woeid,name,admin1,country from geo.places where text = "*' + location + '*" or text = "' + location + '"&format=json' ) , function ( )
{
if ( ! arguments [ 0 ] )
return 0 ;
var city = arguments [ 0 ] . query ;
var n = Number ( city . count ) ;
let city = arguments [ 0 ] . query ;
let n = Number ( city . count ) ;
if ( n > 0 )
city = city . results . place ;
else
return 0 ;
var iter = new Gtk . TreeIter ( ) ;
completionModel . clear ( ) ;
let current = liststore . get _iter _first ( ) ;
if ( n > 1 )
{
for ( var i in city )
{
if ( typeof m == "undefined" )
var m = { } ;
var current = completionModel . append ( iter ) . iter ;
var cityText = city [ i ] . name ;
current = completionModel . append ( ) ;
let cityText = city [ i ] . name ;
if ( city [ i ] . admin1 )
cityText += ", " + city [ i ] . admin1 . content ;
@ -165,13 +354,14 @@ WeatherSetting.prototype =
continue ;
else
m [ cityText ] = 1 ;
completionModel . set _value ( current , 0 , cityText ) ;
}
}
else
{
var current = completionModel . append ( iter ) . iter ;
var cityText = city . name ;
current = completionModel . append ( ) ;
let cityText = city . name ;
if ( city . admin1 )
cityText += ", " + city . admin1 . content ;
@ -181,32 +371,36 @@ WeatherSetting.prototype =
cityText += " [" + city . woeid + "]" ;
completionModel . set _value ( current , 0 , cityText ) ;
}
completion . complete ( ) ;
return 0 ;
} , "getInfo" ) ;
return 0 ;
} ) ;
} ;
var dialog _area = dialog . get _content _area ( ) ;
dialog _area . pack _start ( label ) ;
dialog _area . pack _start ( entry ) ;
dialog . signal . response . connect ( function ( w , response _id ) {
entry . connect ( "changed" , searchLocation ) ;
let dialog _area = dialog . get _content _area ( ) ;
dialog _area . pack _start ( label , 0 , 0 , 0 ) ;
dialog _area . pack _start ( entry , 0 , 0 , 0 ) ;
dialog . connect ( "response" , function ( w , response _id ) {
if ( response _id )
{
if ( entry . get _text ( ) . search ( /\[/ ) == - 1 || entry . get _text ( ) . search ( /\]/ ) == - 1 )
return 0 ;
var woeid = entry . get _text ( ) . split ( /\[/ ) [ 1 ] . split ( /\]/ ) [ 0 ] ;
let woeid = entry . get _text ( ) . split ( /\[/ ) [ 1 ] . split ( /\]/ ) [ 0 ] ;
if ( ! woeid )
return 0 ;
that . loadJsonAsync ( encodeURI ( 'http://query.yahooapis.com/v1/public/yql?format=json&q=select woeid,name,admin1,country from geo.places where woeid = "' + woeid + '" limit 1' ) , function ( )
{
var city = arguments [ 0 ] . query ;
let city = arguments [ 0 ] . query ;
if ( Number ( city . count ) > 0 )
city = city . results . place ;
else
return 0 ;
var cityText = city . name ;
let cityText = city . name ;
if ( city . admin1 )
cityText += ", " + city . admin1 . content ;
@ -217,9 +411,11 @@ WeatherSetting.prototype =
that . city = that . city + " && " + city . woeid + ">" + cityText ;
else
that . city = city . woeid + ">" + cityText ;
return 0 ;
} , "lastTest" ) ;
}
dialog . hide ( ) ;
return 0 ;
} ) ;
dialog . show _all ( ) ;
@ -227,30 +423,30 @@ WeatherSetting.prototype =
removeCity : function ( )
{
var that = this ;
var city = this . city . split ( " && " ) ;
let that = this ;
let city = this . city . split ( " && " ) ;
if ( ! city . length )
return 0 ;
var ac = this . actual _city ;
var textDialog = _ ( "Remove %s ?" ) . replace ( "%s" , this . extractLocation ( city [ ac ] ) ) ;
var dialog = new Gtk . Dialog ( { title : "" } ) ;
var label = new Gtk . Label ( { label : textDialog } ) ;
let ac = this . actual _city ;
let textDialog = _ ( "Remove %s ?" ) . replace ( "%s" , this . extractLocation ( city [ ac ] ) ) ;
let dialog = new Gtk . Dialog ( { title : "" } ) ;
let label = new Gtk . Label ( { label : textDialog } ) ;
label . margin _bottom = 12 ;
dialog . set _border _width ( 12 ) ;
dialog . set _modal ( 1 ) ;
dialog . set _resizable ( 0 ) ;
dialog . set _transient _for ( this . Window . get _object ( "main-window" ) ) ;
//dialog.set_transient_for(***** Need parent Window *****);
dialog . add _button ( Gtk . STOCK _NO , 0 ) ;
var d = dialog . add _button ( Gtk . STOCK _YES , 1 ) ;
let d = dialog . add _button ( Gtk . STOCK _YES , 1 ) ;
d . set _can _default ( true ) ;
dialog . set _default ( d ) ;
var dialog _area = dialog . get _content _area ( ) ;
dialog _area . pack _start ( label ) ;
dialog . signal . response . connect ( function ( w , response _id )
let dialog _area = dialog . get _content _area ( ) ;
dialog _area . pack _start ( label , 0 , 0 , 0 ) ;
dialog . connect ( "response" , function ( w , response _id )
{
if ( response _id )
{
@ -271,29 +467,31 @@ WeatherSetting.prototype =
that . city = "" ;
}
dialog . hide ( ) ;
return 0 ;
} ) ;
dialog . show _all ( ) ;
return 0 ;
} ,
changeSelection : function ( )
{
var path = this . actual _city ;
let path = this . actual _city ;
if ( arguments [ 0 ] )
path = arguments [ 0 ] ;
path = new Gtk . TreePath . from _string ( path ) ;
this . treeview . get _selection ( ) . select _path ( path ) ;
path = new Gtk . TreePath . new _ from_string ( String ( path ) ) ;
treeview . get _selection ( ) . select _path ( path ) ;
} ,
loadJsonAsync : function ( url , fun , id )
{
var here = this ;
var message = new Soup . Message . c _ new( 'GET' , url ) ;
let here = this ;
let message = new Soup . Message . new ( 'GET' , url ) ;
if ( typeof this . asyncSession == "undefined" )
this . asyncSession = { } ;
if ( typeof this . asyncSession [ id ] && this . asyncSession [ id ] )
if ( typeof this . asyncSession [ id ] != "undefined" && this . asyncSession [ id ] )
{
_httpSession . abort ( ) ;
this . asyncSession [ id ] = 0 ;
@ -302,6 +500,7 @@ WeatherSetting.prototype =
this . asyncSession [ id ] = 1 ;
_httpSession . queue _message ( message , function ( _httpSession , message )
{
here . asyncSession [ id ] = 0 ;
if ( ! message . response _body . data )
{
fun . call ( here , 0 ) ;
@ -310,7 +509,7 @@ WeatherSetting.prototype =
try
{
var jp = JSON . parse ( message . response _body . data ) ;
let jp = JSON . parse ( message . response _body . data ) ;
fun . call ( here , jp ) ;
}
catch ( e )
@ -318,17 +517,18 @@ WeatherSetting.prototype =
fun . call ( here , 0 ) ;
return 0 ;
}
return 0 ;
} ) ;
} ,
loadConfig : function ( )
{
var that = this ;
var schema = WEATHER _SETTINGS _SCHEMA ;
let that = this ;
let schema = WEATHER _SETTINGS _SCHEMA ;
if ( Gio . Settings . list _schemas ( ) . indexOf ( schema ) == - 1 )
throw _ ( "Schema \"%s\" not found." ) . format ( schema ) ;
this . Settings = new Gio . Settings ( { schema : schema } ) ;
this . Settings . signal . connect ( "changed" , function ( ) { that . refreshUI ( ) ; } ) ;
this . Settings = Convenience . get Settings( schema ) ;
this . Settings . connect ( "changed" , function ( ) { that . refreshUI ( ) ; } ) ;
} ,
get units ( )
@ -338,11 +538,11 @@ WeatherSetting.prototype =
return this . Settings . get _enum ( WEATHER _UNIT _KEY ) ;
} ,
set units ( )
set units ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _enum ( WEATHER _UNIT _KEY , arguments [ 0 ] ) ;
this . Settings . set _enum ( WEATHER _UNIT _KEY , v ) ;
} ,
get pressure _unit ( )
@ -352,11 +552,11 @@ WeatherSetting.prototype =
return this . Settings . get _enum ( WEATHER _PRESSURE _UNIT _KEY ) ;
} ,
set pressure _unit ( )
set pressure _unit ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _enum ( WEATHER _PRESSURE _UNIT _KEY , arguments [ 0 ] ) ;
this . Settings . set _enum ( WEATHER _PRESSURE _UNIT _KEY , v ) ;
} ,
get wind _speed _unit ( )
@ -366,11 +566,11 @@ WeatherSetting.prototype =
return this . Settings . get _enum ( WEATHER _WIND _SPEED _UNIT _KEY ) ;
} ,
set wind _speed _unit ( )
set wind _speed _unit ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _enum ( WEATHER _WIND _SPEED _UNIT _KEY , arguments [ 0 ] ) ;
this . Settings . set _enum ( WEATHER _WIND _SPEED _UNIT _KEY , v ) ;
} ,
get wind _direction ( )
@ -380,11 +580,11 @@ WeatherSetting.prototype =
return this . Settings . get _boolean ( WEATHER _WIND _DIRECTION _KEY ) ;
} ,
set wind _direction ( )
set wind _direction ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
return this . Settings . set _boolean ( WEATHER _WIND _DIRECTION _KEY , arguments [ 0 ] ) ;
return this . Settings . set _boolean ( WEATHER _WIND _DIRECTION _KEY , v ) ;
} ,
get city ( )
@ -394,24 +594,24 @@ WeatherSetting.prototype =
return this . Settings . get _string ( WEATHER _CITY _KEY ) ;
} ,
set city ( )
set city ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _string ( WEATHER _CITY _KEY , arguments [ 0 ] ) ;
this . Settings . set _string ( WEATHER _CITY _KEY , v ) ;
} ,
get actual _city ( )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
var a = this . Settings . get _int ( WEATHER _ACTUAL _CITY _KEY ) ;
var citys = this . city . split ( " && " ) ;
let a = this . Settings . get _int ( WEATHER _ACTUAL _CITY _KEY ) ;
let citys = this . city . split ( " && " ) ;
if ( citys && typeof citys == "string" )
citys = [ citys ] ;
var l = citys . length - 1 ;
let l = citys . length - 1 ;
if ( a < 0 )
a = 0 ;
@ -425,17 +625,16 @@ WeatherSetting.prototype =
return a ;
} ,
set actual _city ( )
set actual _city ( a )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
var a = arguments [ 0 ] ;
var citys = this . city . split ( " && " ) ;
let citys = this . city . split ( " && " ) ;
if ( citys && typeof citys == "string" )
citys = [ citys ] ;
var l = citys . length - 1 ;
let l = citys . length - 1 ;
if ( a < 0 )
a = 0 ;
@ -456,11 +655,11 @@ WeatherSetting.prototype =
return this . Settings . get _boolean ( WEATHER _TRANSLATE _CONDITION _KEY ) ;
} ,
set translate _condition ( )
set translate _condition ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _boolean ( WEATHER _TRANSLATE _CONDITION _KEY , arguments [ 0 ] ) ;
this . Settings . set _boolean ( WEATHER _TRANSLATE _CONDITION _KEY , v ) ;
} ,
get icon _type ( )
@ -470,11 +669,11 @@ WeatherSetting.prototype =
return this . Settings . get _boolean ( WEATHER _USE _SYMBOLIC _ICONS _KEY ) ;
} ,
set icon _type ( )
set icon _type ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _boolean ( WEATHER _USE _SYMBOLIC _ICONS _KEY , arguments [ 0 ] ) ;
this . Settings . set _boolean ( WEATHER _USE _SYMBOLIC _ICONS _KEY , v ) ;
} ,
get text _in _panel ( )
@ -484,11 +683,11 @@ WeatherSetting.prototype =
return this . Settings . get _boolean ( WEATHER _SHOW _TEXT _IN _PANEL _KEY ) ;
} ,
set text _in _panel ( )
set text _in _panel ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _boolean ( WEATHER _SHOW _TEXT _IN _PANEL _KEY , arguments [ 0 ] ) ;
this . Settings . set _boolean ( WEATHER _SHOW _TEXT _IN _PANEL _KEY , v ) ;
} ,
get position _in _panel ( )
@ -498,11 +697,11 @@ WeatherSetting.prototype =
return this . Settings . get _enum ( WEATHER _POSITION _IN _PANEL _KEY ) ;
} ,
set position _in _panel ( )
set position _in _panel ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _enum ( WEATHER _POSITION _IN _PANEL _KEY , arguments [ 0 ] ) ;
this . Settings . set _enum ( WEATHER _POSITION _IN _PANEL _KEY , v ) ;
} ,
get comment _in _panel ( )
@ -512,11 +711,11 @@ WeatherSetting.prototype =
return this . Settings . get _boolean ( WEATHER _SHOW _COMMENT _IN _PANEL _KEY ) ;
} ,
set comment _in _panel ( )
set comment _in _panel ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _boolean ( WEATHER _SHOW _COMMENT _IN _PANEL _KEY , arguments [ 0 ] ) ;
this . Settings . set _boolean ( WEATHER _SHOW _COMMENT _IN _PANEL _KEY , v ) ;
} ,
get refresh _interval ( )
@ -526,205 +725,36 @@ WeatherSetting.prototype =
return this . Settings . get _int ( WEATHER _REFRESH _INTERVAL ) ;
} ,
set refresh _interval ( )
set refresh _interval ( v )
{
if ( ! this . Settings )
this . loadConfig ( ) ;
this . Settings . set _int ( WEATHER _REFRESH _INTERVAL , arguments [ 0 ] ) ;
this . Settings . set _int ( WEATHER _REFRESH _INTERVAL , v ) ;
} ,
extractLocation : function ( )
extractLocation : function ( a )
{
if ( arguments [ 0 ] . search ( ">" ) == - 1 )
if ( a . search ( ">" ) == - 1 )
return _ ( "Invalid city" ) ;
return arguments [ 0 ] . split ( ">" ) [ 1 ] ;
return a . split ( ">" ) [ 1 ] ;
} ,
extractWoeid : function ( )
extractWoeid : function ( a )
{
if ( arguments [ 0 ] . search ( ">" ) == - 1 )
if ( a . search ( ">" ) == - 1 )
return 0 ;
return arguments [ 0 ] . split ( ">" ) [ 0 ] ;
} ,
refreshUI : function ( )
{
this . Window . get _object ( "tree-toolbutton-remove" ) . sensitive = Boolean ( this . city . length ) ;
if ( this . mCities != this . city )
{
if ( typeof this . liststore != "undefined" )
this . liststore . clear ( ) ;
if ( this . city . length > 0 )
{
var city = String ( this . city ) . split ( " && " ) ;
if ( city && typeof city == "string" )
city = [ city ] ;
var iter = this . iter ;
for ( var i in city )
{
var a = this . liststore . append ( iter ) ;
var current = a . iter ;
this . liststore . set _value ( current , 0 , this . extractLocation ( city [ i ] ) ) ;
}
}
this . mCities = this . city ;
}
this . changeSelection ( ) ;
var config = this . configWidgets ;
for ( var i in config )
if ( config [ i ] [ 0 ] . active != this [ config [ i ] [ 1 ] ] )
config [ i ] [ 0 ] . active = this [ config [ i ] [ 1 ] ] ;
} ,
initConfigWidget : function ( )
{
var a = this . Window . get _object ( "right-widget-table" ) ;
a . visible = 1 ;
a . can _focus = 0 ;
this . widget = a ;
} ,
x : [ 0 , 1 ] ,
y : [ 0 , 1 ] ,
configWidgets : [ ] ,
inc : function ( )
{
if ( this . x [ 0 ] == 1 )
{
this . x [ 0 ] = 0 ;
this . x [ 1 ] = 1 ;
this . y [ 0 ] += 1 ;
this . y [ 1 ] += 1 ;
}
else
{
this . x [ 0 ] += 1 ;
this . x [ 1 ] += 1 ;
}
} ,
addLabel : function ( text )
{
var l = new Gtk . Label ( { label : text , xalign : 0 } ) ;
l . visible = 1 ;
l . can _focus = 0 ;
this . widget . attach ( l , this . x [ 0 ] , this . x [ 1 ] , this . y [ 0 ] , this . y [ 1 ] ) ;
this . inc ( ) ;
} ,
addComboBox : function ( a , b )
{
var that = this ;
var cf = new Gtk . ComboBoxText ( ) ;
this . configWidgets . push ( [ cf , b ] ) ;
cf . visible = 1 ;
cf . can _focus = 0 ;
cf . width _request = 100 ;
for ( var i in a )
cf . append _text ( a [ i ] ) ;
cf . active = this [ b ] ;
cf . signal . changed . connect ( function ( ) { that [ b ] = arguments [ 0 ] . active ; } ) ;
this . widget . attach ( cf , this . x [ 0 ] , this . x [ 1 ] , this . y [ 0 ] , this . y [ 1 ] ) ;
this . inc ( ) ;
} ,
addSwitch : function ( a )
{
var that = this ;
var sw = new Gtk . Switch ( ) ;
this . configWidgets . push ( [ sw , a ] ) ;
sw . visible = 1 ;
sw . can _focus = 0 ;
sw . active = this [ a ] ;
sw . signal . connect ( "notify::active" , function ( ) { that [ a ] = arguments [ 0 ] . active ; } ) ;
this . widget . attach ( sw , this . x [ 0 ] , this . x [ 1 ] , this . y [ 0 ] , this . y [ 1 ] ) ;
this . inc ( ) ;
} ,
initWindow : function ( )
{
var that = this ;
this . Window = new Gtk . Builder ( ) ;
this . Window . add _from _file ( "@EXTENSIONDIR@/weather-settings.ui" ) ;
this . Window . get _object ( "main-window" ) . title = _ ( "Weather Settings" ) ;
this . Window . connect _signals (
{
add _button _clicked : function ( button )
{
that . addCity ( ) ;
} ,
remove _button _clicked : function ( button )
{
that . removeCity ( ) ;
} ,
selection _changed : function ( selection )
{
that . selectionChanged ( selection ) ;
return a . split ( ">" ) [ 0 ] ;
}
} ) ;
this . treeview = this . Window . get _object ( "tree-treeview" ) ;
this . iter = new Gtk . TreeIter ( ) ;
this . liststore = new Gtk . ListStore . c _new ( 1 , [ GObject . TYPE _STRING ] ) ;
this . treeview . set _model ( this . liststore ) ;
var column = new Gtk . TreeViewColumn ( )
this . treeview . append _column ( column ) ;
} ) ;
renderer = new Gtk . CellRendererText ( ) ;
column . pack _start ( renderer ) ;
column . set _cell _data _func ( renderer , function ( )
{
arguments [ 1 ] . markup = arguments [ 2 ] . get _value ( arguments [ 3 ] , 0 ) . value . get _string ( ) ;
} ) ;
this . initConfigWidget ( ) ;
this . addLabel ( _ ( "Temperature Unit" ) ) ;
this . addComboBox ( [ "°C" , "°F" , "K" , "°Ra" , "°Ré" , "°Rø" , "°De" , "°N" ] , "units" ) ;
this . addLabel ( _ ( "Wind Speed Unit" ) ) ;
this . addComboBox ( [ "km/h" , "mph" , "m/s" , "kn" , "ft/s" , "Beaufort" ] , "wind_speed_unit" ) ;
this . addLabel ( _ ( "Pressure Unit" ) ) ;
this . addComboBox ( [ "hPa" , "inHg" , "bar" , "Pa" , "kPa" , "atm" , "at" , "Torr" , "psi" ] , "pressure_unit" ) ;
this . addLabel ( _ ( "Position in Panel" ) ) ;
this . addComboBox ( [ _ ( "Center" ) , _ ( "Right" ) , _ ( "Left" ) ] , "position_in_panel" ) ;
this . addLabel ( _ ( "Wind Direction by Arrows" ) ) ;
this . addSwitch ( "wind_direction" ) ;
this . addLabel ( _ ( "Translate Conditions" ) ) ;
this . addSwitch ( "translate_condition" ) ;
this . addLabel ( _ ( "Symbolic Icons" ) ) ;
this . addSwitch ( "icon_type" ) ;
this . addLabel ( _ ( "Temperature in Panel" ) ) ;
this . addSwitch ( "text_in_panel" ) ;
this . addLabel ( _ ( "Conditions in Panel" ) ) ;
this . addSwitch ( "comment_in_panel" ) ;
} ,
showWindow : function ( )
{
this . Window . get _object ( "main-window" ) . signal . hide . connect ( Gtk . main _quit ) ;
this . Window . get _object ( "main-window" ) . show _all ( ) ;
} ,
selectionChanged : function ( select )
{
if ( typeof select . get _selected _rows ( this . treestore ) [ 0 ] == "object" )
{
var a = select . get _selected _rows ( this . treestore ) [ 0 ] . to _string ( ) ;
if ( this . actual _city != parseInt ( a ) )
this . actual _city = parseInt ( a ) ;
}
}
} ;
function init ( )
{
Convenience . initTranslations ( 'gnome-shell-extension-weather' ) ;
}
new WeatherSetting ( ) ;
function buildPrefsWidget ( )
{
let prefs = new PrefsWidget ( ) ;
prefs . show _all ( ) ;
return prefs ;
}