parent
104361c51e
commit
8d6d51dccb
@ -0,0 +1,13 @@ |
||||
[Desktop Entry] |
||||
Version=1.0 |
||||
Encoding=UTF-8 |
||||
Type=Application |
||||
Name=Weather Settings |
||||
Comment=Weather preferences panel |
||||
Exec=@EXTENSIONDIR@/weather-settings |
||||
Icon=preferences-system |
||||
Terminal=false |
||||
Categories=GNOME;Settings; |
||||
StartupNotify=true |
||||
Name[fr]=Paramètres de la météo |
||||
Comment[fr]=Panel de préférences météo |
@ -0,0 +1,485 @@ |
||||
#! /usr/bin/env seed
|
||||
/* |
||||
* |
||||
* Weather Settings for GNOME Shell Extension Weather |
||||
* |
||||
* Copyright (C) 2012 |
||||
* 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 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/>.
|
||||
* |
||||
*/ |
||||
|
||||
const Gtk = imports.gi.Gtk; |
||||
const GObject = imports.gi.GObject; |
||||
const GtkBuilder = imports.gtkbuilder; |
||||
const Gio = imports.gi.Gio; |
||||
const Gettext = imports.gettext; |
||||
const _ = Gettext.gettext; |
||||
|
||||
const WEATHER_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.weather'; |
||||
const WEATHER_UNIT_KEY = 'unit'; |
||||
const WEATHER_CITY_KEY = 'city'; |
||||
const WEATHER_ACTUAL_CITY_KEY = 'actual-city'; |
||||
const WEATHER_TRANSLATE_CONDITION_KEY = 'translate-condition'; |
||||
const WEATHER_USE_SYMBOLIC_ICONS_KEY = 'use-symbolic-icons'; |
||||
const WEATHER_SHOW_TEXT_IN_PANEL_KEY = 'show-text-in-panel'; |
||||
const WEATHER_POSITION_IN_PANEL_KEY = 'position-in-panel'; |
||||
const WEATHER_SHOW_COMMENT_IN_PANEL_KEY = 'show-comment-in-panel'; |
||||
const WEATHER_REFRESH_INTERVAL = 'refresh-interval'; |
||||
|
||||
var WeatherSetting = function() |
||||
{ |
||||
Gettext.textdomain("gnome-shell-extension-weather"); |
||||
|
||||
Gtk.init(Seed.argv); |
||||
|
||||
this.initWindow(); |
||||
|
||||
this.refreshUI(); |
||||
|
||||
this.showWindow(); |
||||
|
||||
Gtk.main(); |
||||
}; |
||||
|
||||
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 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.add_button(Gtk.STOCK_CANCEL, 0); |
||||
dialog.add_button(_("Add..."), 1); |
||||
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) { |
||||
if(response_id) |
||||
if(that.city) |
||||
that.city = that.city+" && "+entry.get_text(); |
||||
else |
||||
that.city = entry.get_text(); |
||||
dialog.hide(); |
||||
}); |
||||
|
||||
dialog.show_all(); |
||||
}, |
||||
|
||||
removeCity : function() |
||||
{ |
||||
var that = this; |
||||
var city = this.city.split(" && "); |
||||
var ac = this.actual_city; |
||||
var textDialog = _("Remove "+city[ac]+" ?"); |
||||
var dialog = new Gtk.Dialog({title : ""}); |
||||
var 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.add_button(Gtk.STOCK_NO, 0); |
||||
dialog.add_button(Gtk.STOCK_YES, 1); |
||||
var dialog_area = dialog.get_content_area(); |
||||
dialog_area.pack_start(label); |
||||
dialog.signal.response.connect(function(w, response_id) |
||||
{ |
||||
if(response_id) |
||||
{ |
||||
if(city.length == 0) |
||||
city = []; |
||||
|
||||
if(city.length > 0 && typeof city != "object") |
||||
city = [city]; |
||||
|
||||
if(city.length > 0) |
||||
city.splice(ac,1); |
||||
|
||||
if(city.length > 1) |
||||
that.city = city.join(" && "); |
||||
else if(city[0]) |
||||
that.city = city[0]; |
||||
else |
||||
that.city = ""; |
||||
} |
||||
dialog.hide(); |
||||
}); |
||||
|
||||
dialog.show_all(); |
||||
}, |
||||
|
||||
changeSelection : function() |
||||
{ |
||||
var path = this.actual_city; |
||||
if(arguments[0]) |
||||
path = arguments[0]; |
||||
path = new Gtk.TreePath.from_string(path); |
||||
this.treeview.get_selection().select_path(path); |
||||
}, |
||||
|
||||
loadConfig : function() |
||||
{ |
||||
var that = this; |
||||
var 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();}); |
||||
}, |
||||
|
||||
get units() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
return this.Settings.get_enum(WEATHER_UNIT_KEY); |
||||
}, |
||||
|
||||
set units() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
this.Settings.set_enum(WEATHER_UNIT_KEY,arguments[0]); |
||||
}, |
||||
|
||||
get city() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
return this.Settings.get_string(WEATHER_CITY_KEY); |
||||
}, |
||||
|
||||
set city() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
this.Settings.set_string(WEATHER_CITY_KEY,arguments[0]); |
||||
}, |
||||
|
||||
get actual_city() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
var a = this.Settings.get_int(WEATHER_ACTUAL_CITY_KEY); |
||||
var b = a; |
||||
var citys = this.city.split(" && "); |
||||
|
||||
if(citys && typeof citys == "string") |
||||
citys = [citys]; |
||||
|
||||
var l = citys.length-1; |
||||
|
||||
if(a < 0) |
||||
a = 0; |
||||
|
||||
if(l < 0) |
||||
l = 0; |
||||
|
||||
if(a > l) |
||||
a = l; |
||||
|
||||
if(a != b) |
||||
this.actual_city = a; |
||||
return a; |
||||
}, |
||||
|
||||
set actual_city() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
var a = arguments[0]; |
||||
var citys = this.city.split(" && "); |
||||
|
||||
if(citys && typeof citys == "string") |
||||
citys = [citys]; |
||||
|
||||
var l = citys.length-1; |
||||
|
||||
if(a < 0) |
||||
a = 0; |
||||
|
||||
if(l < 0) |
||||
l = 0; |
||||
|
||||
if(a > l) |
||||
a = l; |
||||
|
||||
this.Settings.set_int(WEATHER_ACTUAL_CITY_KEY,a); |
||||
}, |
||||
|
||||
get translate_condition() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
return this.Settings.get_boolean(WEATHER_TRANSLATE_CONDITION_KEY); |
||||
}, |
||||
|
||||
set translate_condition() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
this.Settings.set_boolean(WEATHER_TRANSLATE_CONDITION_KEY,arguments[0]); |
||||
}, |
||||
|
||||
get icon_type() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
return this.Settings.get_boolean(WEATHER_USE_SYMBOLIC_ICONS_KEY); |
||||
}, |
||||
|
||||
set icon_type() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
this.Settings.set_boolean(WEATHER_USE_SYMBOLIC_ICONS_KEY,arguments[0]); |
||||
}, |
||||
|
||||
get text_in_panel() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
return this.Settings.get_boolean(WEATHER_SHOW_TEXT_IN_PANEL_KEY); |
||||
}, |
||||
|
||||
set text_in_panel() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
this.Settings.set_boolean(WEATHER_SHOW_TEXT_IN_PANEL_KEY,arguments[0]); |
||||
}, |
||||
|
||||
get position_in_panel() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
return this.Settings.get_enum(WEATHER_POSITION_IN_PANEL_KEY); |
||||
}, |
||||
|
||||
set position_in_panel() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
this.Settings.set_enum(WEATHER_POSITION_IN_PANEL_KEY,arguments[0]); |
||||
}, |
||||
|
||||
get comment_in_panel() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
return this.Settings.get_boolean(WEATHER_SHOW_COMMENT_IN_PANEL_KEY); |
||||
}, |
||||
|
||||
set comment_in_panel() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
this.Settings.set_boolean(WEATHER_SHOW_COMMENT_IN_PANEL_KEY,arguments[0]); |
||||
}, |
||||
|
||||
get refresh_interval() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
return this.Settings.get_int(WEATHER_REFRESH_INTERVAL); |
||||
}, |
||||
|
||||
set refresh_interval() |
||||
{ |
||||
if(!this.Settings) |
||||
this.loadConfig(); |
||||
this.Settings.set_int(WEATHER_REFRESH_INTERVAL,arguments[0]); |
||||
}, |
||||
|
||||
refreshUI : function() |
||||
{ |
||||
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,city[i]); |
||||
} |
||||
|
||||
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 = 75; |
||||
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); |
||||
} |
||||
}); |
||||
|
||||
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"],"units"); |
||||
this.addLabel(_("Position in Panel")); |
||||
this.addComboBox([_("Center"),_("Left"),_("Right")],"position_in_panel"); |
||||
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(_("Condition 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); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
new WeatherSetting(); |
@ -0,0 +1,113 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<interface> |
||||
<!-- interface-requires gtk+ 3.0 --> |
||||
<object class="GtkWindow" id="main-window"> |
||||
<property name="can_focus">False</property> |
||||
<property name="resizable">False</property> |
||||
<child> |
||||
<object class="GtkBox" id="main-widget"> |
||||
<property name="border-width">14</property> |
||||
<child> |
||||
<object class="GtkTable" id="left-widget"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="n_rows">2</property> |
||||
<property name="n_columns">1</property> |
||||
<property name="column_spacing">6</property> |
||||
<child> |
||||
<object class="GtkScrolledWindow" id="tree-scrolledwindow"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
<property name="shadow_type">in</property> |
||||
<property name="min_content_width">200</property> |
||||
<property name="min_content_height">250</property> |
||||
<child> |
||||
<object class="GtkTreeView" id="tree-treeview"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
<property name="headers_visible">False</property> |
||||
<property name="show_expanders">False</property> |
||||
<property name="level_indentation">12</property> |
||||
<child internal-child="selection"> |
||||
<object class="GtkTreeSelection" id="treeview-selection"> |
||||
<signal name="changed" handler="selection_changed"/> |
||||
</object> |
||||
</child> |
||||
</object> |
||||
</child> |
||||
</object> |
||||
<packing> |
||||
<property name="x_options">GTK_FILL</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<object class="GtkToolbar" id="tree-toolbar"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="toolbar_style">icons</property> |
||||
<property name="icon_size">1</property> |
||||
<style> |
||||
<class name="inline-toolbar"/> |
||||
</style> |
||||
<child> |
||||
<object class="GtkToolButton" id="tree-toolbutton-add"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="use_action_appearance">False</property> |
||||
<property name="icon_name">list-add-symbolic</property> |
||||
<signal name="clicked" handler="add_button_clicked"/> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="homogeneous">True</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<object class="GtkToolButton" id="tree-toolbutton-remove"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="use_action_appearance">False</property> |
||||
<property name="icon_name">list-remove-symbolic</property> |
||||
<signal name="clicked" handler="remove_button_clicked"/> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="homogeneous">True</property> |
||||
</packing> |
||||
</child> |
||||
</object> |
||||
<packing> |
||||
<property name="top_attach">1</property> |
||||
<property name="bottom_attach">2</property> |
||||
<property name="x_options">GTK_FILL</property> |
||||
<property name="y_options">GTK_SHRINK</property> |
||||
</packing> |
||||
</child> |
||||
</object> |
||||
</child> |
||||
<child> |
||||
<object class="GtkBox" id="right-widget"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="homogeneous">True</property> |
||||
<child> |
||||
<object class="GtkTable" id="right-widget-table"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">False</property> |
||||
<property name="n_rows">6</property> |
||||
<property name="n_columns">2</property> |
||||
<property name="column_spacing">36</property> |
||||
<property name="row_spacing">20</property> |
||||
<property name="margin_left">36</property> |
||||
</object> |
||||
</child> |
||||
</object> |
||||
<packing> |
||||
<property name="expand">True</property> |
||||
<property name="fill">True</property> |
||||
</packing> |
||||
</child> |
||||
</object> |
||||
</child> |
||||
</object> |
||||
</interface> |
Loading…
Reference in new issue