@ -93,6 +93,15 @@ const GeolocationProvider = {
MAPQUEST : 2
} ;
let provider = new Gtk . CssProvider ( ) ;
provider . load _from _path ( Me . dir . get _path ( ) + '/prefs.css' ) ;
Gtk . StyleContext . add _provider _for _display (
Gdk . Display . get _default ( ) ,
provider ,
Gtk . STYLE _PROVIDER _PRIORITY _APPLICATION ) ;
let _httpSession ;
let mCities = null ;
@ -138,7 +147,10 @@ const WeatherPrefsWidget = new GObject.Class({
this . editCoord = this . Window . get _object ( "edit-coord" ) ;
this . editCombo = this . Window . get _object ( "edit-combo" ) ;
this . searchWidget = this . Window . get _object ( "search-widget" ) ;
this . searchMenu = this . Window . get _object ( "search-menu" ) ;
this . searchMenuWidget = this . Window . get _object ( "search-menu-widget" ) ;
this . searchScrolledWindow = this . Window . get _object ( "search-scrolledwindow" ) ;
this . searchTreeview = this . Window . get _object ( "search-treeview" ) ;
this . searchListstore = this . Window . get _object ( "search-liststore" ) ;
this . searchName = this . Window . get _object ( "search-name" ) ;
this . searchCombo = this . Window . get _object ( "search-combo" ) ;
@ -147,7 +159,9 @@ const WeatherPrefsWidget = new GObject.Class({
this . editCoord . connect ( "icon-release" , Lang . bind ( this , this . clearEntry ) ) ;
this . Window . get _object ( "tree-toolbutton-add" ) . connect ( "clicked" , Lang . bind ( this , function ( ) {
this . searchWidget . show _all ( ) ;
this . searchName . set _text ( "" ) ;
this . clearSearchMenu ( ) ;
this . searchWidget . show ( ) ;
} ) ) ;
this . Window . get _object ( "tree-toolbutton-remove" ) . connect ( "clicked" , Lang . bind ( this , this . removeCity ) ) ;
@ -158,6 +172,11 @@ const WeatherPrefsWidget = new GObject.Class({
this . selectionChanged ( selection ) ;
} ) ) ;
this . searchSelection = this . Window . get _object ( "search-selection" ) ;
this . searchSelection . connect ( "changed" , Lang . bind ( this , function ( selection ) {
this . searchSelectionChanged ( selection ) ;
} ) ) ;
this . Window . get _object ( "button-edit-cancel" ) . connect ( "clicked" , Lang . bind ( this , this . editCancel ) ) ;
this . Window . get _object ( "button-edit-save" ) . connect ( "clicked" , Lang . bind ( this , this . editSave ) ) ;
@ -175,13 +194,7 @@ const WeatherPrefsWidget = new GObject.Class({
if ( location === "" )
return 0 ;
let item = new Gtk . MenuItem ( ) ;
let spinner = new Gtk . Spinner ( ) ;
spinner . start ( ) ;
item . add ( spinner ) ;
this . searchMenu . append ( item ) ;
this . showSearchMenu ( ) ;
this . appendToSearchList ( _ ( "Searching ..." ) ) ;
if ( this . geolocation _provider == GeolocationProvider . OPENSTREETMAPS ) {
let params = {
@ -193,18 +206,12 @@ const WeatherPrefsWidget = new GObject.Class({
this . loadJsonAsync ( OPENWEATHER _URL _OSM _FIND , params , Lang . bind ( this , function ( ) {
this . clearSearchMenu ( ) ;
if ( ! arguments [ 0 ] ) {
let item = new Gtk . MenuItem ( {
label : _ ( "Invalid data when searching for \"%s\"" ) . format ( location )
} ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( _ ( "Invalid data when searching for \"%s\"" ) . format ( location ) ) ;
} else {
let newCity = arguments [ 0 ] ;
if ( Number ( newCity . length ) < 1 ) {
let item = new Gtk . MenuItem ( {
label : _ ( "\"%s\" not found" ) . format ( location )
} ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( _ ( "\"%s\" not found" ) . format ( location ) ) ;
} else {
var m = { } ;
for ( var i in newCity ) {
@ -212,11 +219,7 @@ const WeatherPrefsWidget = new GObject.Class({
let cityText = newCity [ i ] . display _name ;
let cityCoord = "[" + newCity [ i ] . lat + "," + newCity [ i ] . lon + "]" ;
let item = new Gtk . MenuItem ( {
label : cityText + " " + cityCoord
} ) ;
item . connect ( "activate" , Lang . bind ( this , this . onActivateItem ) ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( cityText + " " + cityCoord ) ;
}
}
}
@ -226,14 +229,8 @@ const WeatherPrefsWidget = new GObject.Class({
} else if ( this . geolocation _provider == GeolocationProvider . MAPQUEST ) {
if ( this . geolocation _appid _mapquest === '' ) {
this . clearSearchMenu ( ) ;
let item = new Gtk . MenuItem ( {
label : "You need an AppKey to search on openmapquest."
} ) ;
this . searchMenu . append ( item ) ;
item = new Gtk . MenuItem ( {
label : "Please visit https://developer.mapquest.com/ ."
} ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( _ ( "You need an AppKey to search on openmapquest." ) ) ;
this . appendToSearchList ( _ ( "Please visit https://developer.mapquest.com/ ." ) ) ;
this . showSearchMenu ( ) ;
return 0 ;
}
@ -247,26 +244,14 @@ const WeatherPrefsWidget = new GObject.Class({
this . loadJsonAsync ( OPENWEATHER _URL _MAPQUEST _FIND , params , Lang . bind ( this , function ( ) {
this . clearSearchMenu ( ) ;
if ( ! arguments [ 0 ] ) {
let item = new Gtk . MenuItem ( {
label : _ ( "Invalid data when searching for \"%s\"" ) . format ( location )
} ) ;
this . searchMenu . append ( item ) ;
item = new Gtk . MenuItem ( {
label : "Do you use a valid AppKey to search on openmapquest ?"
} ) ;
this . searchMenu . append ( item ) ;
item = new Gtk . MenuItem ( {
label : "If not, please visit https://developer.mapquest.com/ ."
} ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( _ ( "Invalid data when searching for \"%s\"" ) . format ( location ) ) ;
this . appendToSearchList ( _ ( "Do you use a valid AppKey to search on openmapquest ?" ) ) ;
this . appendToSearchList ( _ ( "If not, please visit https://developer.mapquest.com/ ." ) ) ;
} else {
let newCity = arguments [ 0 ] ;
if ( Number ( newCity . length ) < 1 ) {
let item = new Gtk . MenuItem ( {
label : _ ( "\"%s\" not found" ) . format ( location )
} ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( _ ( "\"%s\" not found" ) . format ( location ) ) ;
} else {
var m = { } ;
for ( var i in newCity ) {
@ -274,11 +259,7 @@ const WeatherPrefsWidget = new GObject.Class({
let cityText = newCity [ i ] . display _name ;
let cityCoord = "[" + newCity [ i ] . lat + "," + newCity [ i ] . lon + "]" ;
let item = new Gtk . MenuItem ( {
label : cityText + " " + cityCoord
} ) ;
item . connect ( "activate" , Lang . bind ( this , this . onActivateItem ) ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( cityText + " " + cityCoord ) ;
}
}
}
@ -294,23 +275,14 @@ const WeatherPrefsWidget = new GObject.Class({
this . clearSearchMenu ( ) ;
if ( ! arguments [ 0 ] ) {
let item = new Gtk . MenuItem ( {
label : _ ( "Invalid data when searching for \"%s\"" ) . format ( location )
} ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( _ ( "Invalid data when searching for \"%s\"" ) . format ( location ) ) ;
} else {
let newCity = arguments [ 0 ] . geocoding _results ;
if ( Number ( newCity . length ) < 1 ) {
let item = new Gtk . MenuItem ( {
label : _ ( "Invalid data when searching for \"%s\"" ) . format ( location )
} ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( _ ( "Invalid data when searching for \"%s\"" ) . format ( location ) ) ;
} else {
if ( Number ( newCity . STATUS . result _count ) < 1 ) {
let item = new Gtk . MenuItem ( {
label : _ ( "\"%s\" not found" ) . format ( location )
} ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( _ ( "\"%s\" not found" ) . format ( location ) ) ;
} else {
var m = { } ;
newCity = newCity . RESULTS ;
@ -319,11 +291,7 @@ const WeatherPrefsWidget = new GObject.Class({
let cityText = newCity [ i ] . formatted _address ;
let cityCoord = "[" + newCity [ i ] . COORDINATES . latitude + "," + newCity [ i ] . COORDINATES . longitude + "]" ;
let item = new Gtk . MenuItem ( {
label : cityText + " " + cityCoord
} ) ;
item . connect ( "activate" , Lang . bind ( this , this . onActivateItem ) ) ;
this . searchMenu . append ( item ) ;
this . appendToSearchList ( cityText + " " + cityCoord ) ;
}
}
@ -372,7 +340,7 @@ const WeatherPrefsWidget = new GObject.Class({
this . treeview . append _column ( column ) ;
let renderer = new Gtk . CellRendererText ( ) ;
column . pack _start ( renderer , null ) ;
column . pack _start ( renderer , false ) ;
column . add _attribute ( renderer , "text" , 0 ) ;
column . set _cell _data _func ( renderer , function ( ) {
@ -382,12 +350,22 @@ const WeatherPrefsWidget = new GObject.Class({
column . set _title ( _ ( "Provider" ) ) ;
this . treeview . append _column ( column ) ;
column . pack _start ( renderer , null ) ;
column . pack _start ( renderer , false ) ;
column . add _attribute ( renderer , "text" , 1 ) ;
column . set _cell _data _func ( renderer , function ( ) {
arguments [ 1 ] . markup = arguments [ 2 ] . get _value ( arguments [ 3 ] , 1 ) ;
} ) ;
column = new Gtk . TreeViewColumn ( ) ;
column . set _title ( _ ( "Result" ) ) ;
this . searchTreeview . append _column ( column ) ;
column . pack _start ( renderer , false ) ;
column . add _attribute ( renderer , "text" , 0 ) ;
column . set _cell _data _func ( renderer , function ( ) {
arguments [ 1 ] . markup = arguments [ 2 ] . get _value ( arguments [ 3 ] , 0 ) ;
} ) ;
this . location _length _spin = this . Window . get _object ( "max_loc_chars" ) ;
this . location _length _spin . set _value ( this . loc _len _current ) ;
@ -407,15 +385,15 @@ const WeatherPrefsWidget = new GObject.Class({
let theObjects = this . Window . get _objects ( ) ;
for ( let i in theObjects ) {
let name = theObjects [ i ] . get _name ? theObjects [ i ] . get _name ( ) : 'dummy' ;
let name = theObjects [ i ] . get _buildable _id ? theObjects [ i ] . get _buildable _id ( ) : 'dummy' ;
if ( this [ name ] !== undefined ) {
if ( theObjects [ i ] . class _path ( ) [ 1 ] . indexOf ( 'GtkEntry' ) != - 1 )
if ( theObjects [ i ] . get _name ( ) . indexOf ( 'GtkEntry' ) != - 1 )
this . initEntry ( theObjects [ i ] ) ;
else if ( theObjects [ i ] . class _path ( ) [ 1 ] . indexOf ( 'GtkComboBoxText' ) != - 1 )
else if ( theObjects [ i ] . get _name ( ) . indexOf ( 'GtkComboBoxText' ) != - 1 )
this . initComboBox ( theObjects [ i ] ) ;
else if ( theObjects [ i ] . class _path ( ) [ 1 ] . indexOf ( 'GtkSwitch' ) != - 1 )
else if ( theObjects [ i ] . get _name ( ) . indexOf ( 'GtkSwitch' ) != - 1 )
this . initSwitch ( theObjects [ i ] ) ;
else if ( theObjects [ i ] . class _path ( ) [ 1 ] . indexOf ( 'GtkScale' ) != - 1 )
else if ( theObjects [ i ] . get _name ( ) . indexOf ( 'GtkScale' ) != - 1 )
this . initScale ( theObjects [ i ] ) ;
this . configWidgets . push ( [ theObjects [ i ] , name ] ) ;
}
@ -424,6 +402,13 @@ const WeatherPrefsWidget = new GObject.Class({
this . Window . get _object ( 'version' ) . set _label ( Me . metadata . version . toString ( ) ) ;
} ,
appendToSearchList : function ( text ) {
let current = this . searchListstore . get _iter _first ( ) ;
current = this . searchListstore . append ( ) ;
this . searchListstore . set _value ( current , 0 , text ) ;
} ,
clearEntry : function ( ) {
arguments [ 0 ] . set _text ( "" ) ;
} ,
@ -433,14 +418,9 @@ const WeatherPrefsWidget = new GObject.Class({
} ,
showSearchMenu : function ( ) {
this . searchMenu . show _all ( ) ;
if ( typeof this . searchMenu . popup _at _widget === "function" ) {
this . searchMenu . popup _at _widget ( this . searchName , Gdk . Gravity . SOUTH _WEST , Gdk . Gravity . NORTH _WEST , null ) ;
}
else
{
this . searchMenu . popup ( null , null , Lang . bind ( this , this . placeSearchMenu ) , 0 , this . searchName ) ;
}
this . searchSelection . unselect _all ( ) ;
this . searchMenuWidget . show ( ) ;
this . searchSelection . set _mode ( Gtk . SelectionMode . SINGLE ) ;
} ,
placeSearchMenu : function ( ) {
@ -450,14 +430,15 @@ const WeatherPrefsWidget = new GObject.Class({
} ,
clearSearchMenu : function ( ) {
let children = this . searchMenu . get _children ( ) ;
for ( let i in children ) {
this . searchMenu . remove ( children [ i ] ) ;
}
this . searchSelection . unselect _all ( ) ;
this . searchSelection . set _mode ( Gtk . SelectionMode . NONE ) ;
if ( this . searchListstore !== undefined )
this . searchListstore . clear ( ) ;
this . searchMenuWidget . hide ( ) ;
} ,
initEntry : function ( theEntry ) {
let name = theEntry . get _name ( ) ;
let name = theEntry . get _buildable _id ( ) ;
theEntry . text = this [ name ] ;
if ( this [ name ] . length != 32 )
theEntry . set _icon _from _icon _name ( Gtk . PositionType . LEFT , 'dialog-warning' ) ;
@ -473,21 +454,21 @@ const WeatherPrefsWidget = new GObject.Class({
} ,
initComboBox : function ( theComboBox ) {
let name = theComboBox . get _name ( ) ;
let name = theComboBox . get _buildable _id ( ) ;
theComboBox . connect ( "changed" , Lang . bind ( this , function ( ) {
this [ name ] = arguments [ 0 ] . active ;
} ) ) ;
} ,
initSwitch : function ( theSwitch ) {
let name = theSwitch . get _name ( ) ;
let name = theSwitch . get _buildable _id ( ) ;
theSwitch . connect ( "notify::active" , Lang . bind ( this , function ( ) {
this [ name ] = arguments [ 0 ] . active ;
} ) ) ;
} ,
initScale : function ( theScale ) {
let name = theScale . get _name ( ) ;
let name = theScale . get _buildable _id ( ) ;
theScale . set _value ( this [ name ] ) ;
this [ name + 'Timeout' ] = undefined ;
theScale . connect ( "value-changed" , Lang . bind ( this , function ( slider ) {
@ -552,6 +533,15 @@ const WeatherPrefsWidget = new GObject.Class({
this . actual _city = parseInt ( a . to _string ( ) ) ;
} ,
searchSelectionChanged : function ( select ) {
let a = select . get _selected _rows ( ) [ 0 ] [ 0 ] ;
if ( a !== undefined ) {
let b = this . searchListstore . get _iter ( a ) ;
this . searchName . set _text ( this . searchListstore . get _value ( b [ 1 ] , 0 ) . toString ( ) ) ;
}
this . clearSearchMenu ( ) ;
} ,
removeCity : function ( ) {
let city = this . city . split ( " && " ) ;
if ( ! city . length )
@ -559,28 +549,26 @@ const WeatherPrefsWidget = new GObject.Class({
let ac = this . actual _city ;
let textDialog = _ ( "Remove %s ?" ) . format ( this . extractLocation ( city [ ac ] ) ) ;
let dialog = new Gtk . Dialog ( {
title : ""
title : "" ,
css _classes : [ 'openweather-dialog' ]
} ) ;
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 _modal ( true ) ;
dialog . set _resizable ( false ) ;
//dialog.set_transient_for(***** Need parent Window *****);
dialog . add _button ( _ ( "No" ) , 0 ) ;
let d = dialog . add _button ( _ ( "Yes" ) , 1 ) ;
dialog . add _button ( Gtk . STOCK _NO , 0 ) ;
let d = dialog . add _button ( Gtk . STOCK _YES , 1 ) ;
d . set _can _default ( true ) ;
dialog . set _default ( d ) ;
dialog . set _default _response ( 0 ) ;
let dialog _area = dialog . get _content _area ( ) ;
dialog _area . pack _start ( label , 0 , 0 , 0 ) ;
dialog _area . append ( label ) ;
dialog . connect ( "response" , Lang . bind ( this , function ( w , response _id ) {
if ( response _id ) {
if ( response _id == 1 ) {
if ( city . length === 0 )
city = [ ] ;
@ -601,7 +589,7 @@ const WeatherPrefsWidget = new GObject.Class({
return 0 ;
} ) ) ;
dialog . show _all ( ) ;
dialog . show ( ) ;
return 0 ;
} ,
@ -613,7 +601,7 @@ const WeatherPrefsWidget = new GObject.Class({
this . editName . set _text ( this . extractLocation ( city [ ac ] ) ) ;
this . editCoord . set _text ( this . extractCoord ( city [ ac ] ) ) ;
this . editCombo . set _active ( this . extractProvider ( city [ ac ] ) + 1 ) ;
this . editWidget . show _all ( ) ;
this . editWidget . show ( ) ;
return 0 ;
} ,
@ -1115,6 +1103,6 @@ function init() {
function buildPrefsWidget ( ) {
let prefs = new WeatherPrefsWidget ( ) ;
let widget = prefs . mainWidget ;
widget . show _all ( ) ;
widget . show ( ) ;
return widget ;
}