yahoo_weather
Neroth 12 years ago
parent 315555cdde
commit 2621a3e632
  1. 2
      data/weather-settings.desktop.in
  2. 81
      src/prefs.js

@ -3,7 +3,7 @@ Version=1.0
Type=Application Type=Application
Name=Weather Settings Name=Weather Settings
Comment=Weather preferences panel Comment=Weather preferences panel
Exec=gnome-shell-extension-prefs Exec=gnome-shell-extension-prefs weather@gnome-shell-extensions.gnome.org
Icon=preferences-system Icon=preferences-system
Terminal=false Terminal=false
Categories=Settings;System;DesktopSettings; Categories=Settings;System;DesktopSettings;

@ -59,15 +59,9 @@ const WEATHER_REFRESH_INTERVAL = 'refresh-interval';
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());
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; let mCities = null;
const PrefsWidget = new GObject.Class( const WeatherPrefsWidget = new GObject.Class(
{ {
Name: 'WeatherExtension.Prefs.Widget', Name: 'WeatherExtension.Prefs.Widget',
GTypeName: 'WeatherExtensionPrefsWidget', GTypeName: 'WeatherExtensionPrefsWidget',
@ -81,32 +75,42 @@ Extends: Gtk.Box,
this.refreshUI(); this.refreshUI();
this.add(MainWidget); this.add(this.MainWidget);
}, },
Window : new Gtk.Builder(),
initWindow : function() initWindow : function()
{ {
let that = this; let that = this;
mCities = null;
this.Window.add_from_file(EXTENSIONDIR+"/weather-settings.ui");
Window.get_object("tree-toolbutton-add").connect("clicked",function() this.MainWidget = this.Window.get_object("main-widget");
this.treeview = this.Window.get_object("tree-treeview");
this.liststore = this.Window.get_object("liststore");
this.Iter = this.liststore.get_iter_first();
this.Window.get_object("tree-toolbutton-add").connect("clicked",function()
{ {
that.addCity(); that.addCity();
}); });
Window.get_object("tree-toolbutton-remove").connect("clicked",function() this.Window.get_object("tree-toolbutton-remove").connect("clicked",function()
{ {
that.removeCity(); that.removeCity();
}); });
Window.get_object("treeview-selection").connect("changed",function(selection) this.Window.get_object("treeview-selection").connect("changed",function(selection)
{ {
that.selectionChanged(selection); that.selectionChanged(selection);
}); });
treeview.set_model(liststore); this.treeview.set_model(this.liststore);
let column = new Gtk.TreeViewColumn() let column = new Gtk.TreeViewColumn()
treeview.append_column(column); this.treeview.append_column(column);
let renderer = new Gtk.CellRendererText(); let renderer = new Gtk.CellRendererText();
column.pack_start(renderer,null); column.pack_start(renderer,null);
@ -139,12 +143,17 @@ Extends: Gtk.Box,
refreshUI : function() refreshUI : function()
{ {
Window.get_object("tree-toolbutton-remove").sensitive = Boolean(this.city.length); this.MainWidget = this.Window.get_object("main-widget");
this.treeview = this.Window.get_object("tree-treeview");
this.liststore = this.Window.get_object("liststore");
this.Iter = this.liststore.get_iter_first();
this.Window.get_object("tree-toolbutton-remove").sensitive = Boolean(this.city.length);
if(mCities != this.city) if(mCities != this.city)
{ {
if(typeof liststore != "undefined") if(typeof this.liststore != "undefined")
liststore.clear(); this.liststore.clear();
if(this.city.length > 0) if(this.city.length > 0)
{ {
@ -153,12 +162,12 @@ Extends: Gtk.Box,
if(city && typeof city == "string") if(city && typeof city == "string")
city = [city]; city = [city];
let current = liststore.get_iter_first(); let current = this.liststore.get_iter_first();
for(let i in city) for(let i in city)
{ {
current = liststore.append(); current = this.liststore.append();
liststore.set_value(current, 0, this.extractLocation(city[i])); this.liststore.set_value(current, 0, this.extractLocation(city[i]));
} }
} }
@ -175,10 +184,11 @@ Extends: Gtk.Box,
initConfigWidget : function() initConfigWidget : function()
{ {
let a = Window.get_object("right-widget-table"); this.inc(1);
let a = this.Window.get_object("right-widget-table");
a.visible = 1; a.visible = 1;
a.can_focus = 0; a.can_focus = 0;
this.widget = a; this.right_widget = a;
}, },
x : [0,1], x : [0,1],
@ -189,17 +199,28 @@ Extends: Gtk.Box,
inc : function() inc : function()
{ {
if(arguments[0])
{
this.x[0] = 0;
this.x[1] = 1;
this.y[0] = 0;
this.y[1] = 1;
return 0;
}
if(this.x[0] == 1) if(this.x[0] == 1)
{ {
this.x[0] = 0; this.x[0] = 0;
this.x[1] = 1; this.x[1] = 1;
this.y[0] += 1; this.y[0] += 1;
this.y[1] += 1; this.y[1] += 1;
return 0;
} }
else else
{ {
this.x[0] += 1; this.x[0] += 1;
this.x[1] += 1; this.x[1] += 1;
return 0;
} }
}, },
@ -208,7 +229,7 @@ Extends: Gtk.Box,
let l = new Gtk.Label({label:text,xalign:0}); let l = new Gtk.Label({label:text,xalign:0});
l.visible = 1; l.visible = 1;
l.can_focus = 0; 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.right_widget.attach(l, this.x[0],this.x[1], this.y[0],this.y[1],0,0,0,0);
this.inc(); this.inc();
}, },
@ -224,7 +245,7 @@ Extends: Gtk.Box,
cf.append_text(a[i]); cf.append_text(a[i]);
cf.active = this[b]; cf.active = this[b];
cf.connect("changed",function(){that[b] = arguments[0].active;}); 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.right_widget.attach(cf, this.x[0],this.x[1], this.y[0],this.y[1],0,0,0,0);
this.inc(); this.inc();
}, },
@ -237,13 +258,13 @@ Extends: Gtk.Box,
sw.can_focus = 0; sw.can_focus = 0;
sw.active = this[a]; sw.active = this[a];
sw.connect("notify::active",function(){that[a] = arguments[0].active;}); 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.right_widget.attach(sw, this.x[0],this.x[1], this.y[0],this.y[1],0,0,0,0);
this.inc(); this.inc();
}, },
selectionChanged : function(select) selectionChanged : function(select)
{ {
let a = select.get_selected_rows(liststore)[0][0]; let a = select.get_selected_rows(this.liststore)[0][0];
if(typeof a != "undefined") if(typeof a != "undefined")
if(this.actual_city != parseInt(a.to_string())) if(this.actual_city != parseInt(a.to_string()))
@ -331,7 +352,7 @@ Extends: Gtk.Box,
return 0; return 0;
completionModel.clear(); completionModel.clear();
let current = liststore.get_iter_first(); let current = this.liststore.get_iter_first();
if(n > 1) if(n > 1)
{ {
@ -480,7 +501,7 @@ Extends: Gtk.Box,
if(arguments[0]) if(arguments[0])
path = arguments[0]; path = arguments[0];
path = new Gtk.TreePath.new_from_string(String(path)); path = new Gtk.TreePath.new_from_string(String(path));
treeview.get_selection().select_path(path); this.treeview.get_selection().select_path(path);
}, },
loadJsonAsync : function(url, fun, id) loadJsonAsync : function(url, fun, id)
@ -754,7 +775,7 @@ Convenience.initTranslations('gnome-shell-extension-weather');
function buildPrefsWidget() function buildPrefsWidget()
{ {
let prefs = new PrefsWidget(); let widget = new WeatherPrefsWidget();
prefs.show_all(); widget.show_all();
return prefs; return widget;
} }

Loading…
Cancel
Save