prefs.js (adapted from canek-pelaez version) #21 #59 #69, many update

yahoo_weather
Neroth 12 years ago
parent 8f34b876a0
commit d46b13d7b0
  1. 8
      AUTHORS
  2. 39
      Makefile.am
  3. 0
      NEWS
  4. 0
      README
  5. 2
      autogen.sh
  6. 45
      configure.ac
  7. 42
      data/Makefile.am
  8. 0
      data/metadata.json.in
  9. 0
      data/org.gnome.shell.extensions.weather.gschema.xml.in
  10. 0
      data/stylesheet.css
  11. 2
      data/weather-settings.desktop.in
  12. 22
      data/weather-settings.ui
  13. 2
      po/POTFILES.in
  14. 41
      src/Makefile.am
  15. 92
      src/convenience.js
  16. 604
      src/prefs.js

@ -0,0 +1,8 @@
Elad Alfassa <elad@fedoraproject.org>,
Mark Benjamin <weather.gnome.Markie1@dfgh.net>,
Simon Claessens <gagalago@gmail.com>,
Ecyrbe <ecyrbe+spam@gmail.com>,
Timur Kristóf <venemo@msn.com>,
Simon Legner <Simon.Legner@gmail.com>,
Mattia Meneguzzo <odysseus@fedoraproject.org>,
Christian Metzler <neroth@xeked.com>

@ -1,3 +1,40 @@
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
SUBDIRS = src po
SUBDIRS = src data po
zip-file: all
if LOCAL_INSTALL
-rm -fR $(builddir)/_build
$(MKDIR_P) $(builddir)/_build; \
$(MAKE) install DESTDIR="$(abs_builddir)/_build"; \
$(GLIB_COMPILE_SCHEMAS) "$(abs_builddir)/_build/$(prefix)/share/gnome-shell/extensions/weather@gnome-shell-extensions.gnome.org/schemas"; \
(cd "$(abs_builddir)/_build/$(prefix)/share/gnome-shell/extensions/weather@gnome-shell-extensions.gnome.org" ; \
zip -qr "$(abs_builddir)/gnome-shell-extension-weather.zip" .; \
); \
rm -fR $(builddir)/_build ; \
echo "===================================================================" ; \
echo "zip-file ready for distribution:" ; \
echo "gnome-shell-extension-weather.zip" ; \
echo "==================================================================="
else
@echo "*"
@echo "* You need to configure the package --with-local-install=yes to create a zip-file."
@echo "*"
endif
clean-local:
rm -f "$(abs_builddir)/gnome-shell-extension-weather.zip"
dist-hook: dist-changelog
.PHONY: dist-changelog
dist-changelog:
$(AM_V_at)if git --git-dir=$(top_srcdir)/.git --work-tree=$(top_srcdir) \
log --no-merges --pretty='tformat:%cd %an <%ae>%n%n%s%n%n%b' --date=short 2b58327bf183c94c788a13d746373efc22a3f3c1.. | \
$(SED) -e '/^[12]...-[01].-[0123]. [^<>]* <[^<>]*>$$/,/^$$/ b' \
-e '/[^ ]/,/^[ ]*$$/ !d' \
-e 's/^[ ]*/ /' \
-e 's/^[ ]*$$//' >.ChangeLog.tmp; \
then mv -f .ChangeLog.tmp "$(top_distdir)/ChangeLog"; \
else rm -f .ChangeLog.tmp; exit 1; fi

@ -6,6 +6,8 @@ test -z "$srcdir" && srcdir=.
PKG_NAME="gnome-shell-extension-weather"
touch ChangeLog
test -f $srcdir/configure.ac || {
echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
echo " top-level gnome-shell-extensions directory"

@ -1,18 +1,25 @@
AC_PREREQ(2.63)
dnl be carefull, the version needs to be in sync with your gnome shell version
AC_INIT([gnome-shell-extension-weather],[1.0],[https://github.com/Neroth/gnome-shell-extension-weather/issues])
AC_INIT([gnome-shell-extension-weather],[1.1],[https://github.com/Neroth/gnome-shell-extension-weather/issues])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([config])
AM_INIT_AUTOMAKE([1.10 dist-bzip2 no-dist-gzip foreign tar-ustar])
AM_INIT_AUTOMAKE([1.10 dist-xz])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
AC_PROG_SED
GETTEXT_PACKAGE=gnome-shell-extension-weather
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE",
[The prefix for our gettext translation domains.])
IT_PROG_INTLTOOL(0.26)
PKG_PROG_PKG_CONFIG([0.22])
GLIB_GSETTINGS
AC_ARG_WITH(desktop-dir, [ --with-desktop-dir=PATH where to install desktop files (default=PREFIX/share)])
@ -25,16 +32,42 @@ fi
AM_CONDITIONAL(DESKTOP_DATADIR, test "x$with_desktop_dir" != xno)
AC_SUBST(DESKTOP_DATADIR)
IT_PROG_INTLTOOL(0.26)
AC_ARG_WITH([local-install],
[AS_HELP_STRING([--with-local-install],
[install schemas and translations in a subdir of the extension (default is no)])],
[use_local_install=$withval],
[use_local_install=no])
PKG_PROG_PKG_CONFIG([0.22])
AC_SUBST(use_local_install)
AM_CONDITIONAL(LOCAL_INSTALL, test "x${use_local_install}" == "xyes")
GLIB_GSETTINGS
extensiontopdir=${datadir}/gnome-shell/extensions/weather@gnome-shell-extensions.gnome.org
dnl This is beyond ugly. Suggestions accepted.
if test "x${use_local_install}" == "xyes"; then
AC_SUBST(gsettingsschemadir, [${extensiontopdir}/schemas])
AC_SUBST(LOCALEDIR, [${extensiontopdir}/locale])
else
AC_SUBST(LOCALEDIR, [${datadir}/locale])
fi
dnl Please keep this sorted alphabetically
dnl Please keep this sorted alphabetically.
AC_CONFIG_FILES([
Makefile
data/Makefile
po/Makefile.in
src/Makefile
])
AC_OUTPUT
dnl 'Fugly hack' doesn't get close to describe this. I don't know how else
dnl to change the directory for translations.
if test "x${use_local_install}" == "xyes"; then
${SED} -i -e "s%itlocaledir = .*%itlocaledir = ${extensiontopdir}/locale%g" po/Makefile
fi
if test "x$use_local_install" == "xyes"; then
echo
echo "The schemas and translations will be installed in subdirectories of the extension."
echo
fi

@ -0,0 +1,42 @@
extensionurl = https://github.com/Neroth/gnome-shell-extension-weather
# Change these to modify how installation is performed
topextensiondir = $(datadir)/gnome-shell/extensions
uuid = weather@gnome-shell-extensions.gnome.org
extensiondir = $(topextensiondir)/$(uuid)
if DESKTOP_DATADIR
applicationsdir = $(DESKTOP_DATADIR)/applications
applications_DATA = weather-settings.desktop
endif
dist_extension_DATA = stylesheet.css weather-settings.ui
nodist_extension_DATA = metadata.json $(EXTRA_EXTENSION)
EXTRA_DIST = metadata.json.in weather-settings.desktop.in
metadata.json: metadata.json.in $(top_builddir)/config.status
$(AM_V_GEN) sed -e "s|[@]LOCALEDIR@|$(datadir)/locale|" \
-e "s|[@]uuid@|$(uuid)|" \
-e "s|[@]url@|$(extensionurl)|" $< > $@
weather-settings.desktop: weather-settings.desktop.in $(top_builddir)/config.status
$(AM_V_GEN) sed -e "s|[@]EXTENSIONDIR@|$(extensiondir)|" $< > $@
CLEANFILES = metadata.json weather-settings.desktop
gschemas_in = org.gnome.shell.extensions.weather.gschema.xml.in
@INTLTOOL_XML_NOMERGE_RULE@
gsettings_SCHEMAS = $(gschemas_in:.xml.in=.xml)
@GSETTINGS_RULES@
EXTRA_DIST += $(gschemas_in)
CLEANFILES += $(gschemas_in:.xml.in=.valid) $(gsettings_SCHEMAS)

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

@ -1,10 +1,17 @@
<?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="GtkListStore" id="liststore">
<columns>
<!-- column-name text -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0"></col>
</row>
</data>
</object>
<object class="GtkBox" id="main-widget">
<property name="border-width">14</property>
<child>
@ -30,7 +37,8 @@
<property name="level_indentation">12</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection">
<signal name="changed" handler="selection_changed"/>
</object>
<object class="GtkTreeViewColumn" id="tree-treeviewcolumn">
</object>
</child>
</object>
@ -55,7 +63,6 @@
<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>
@ -68,7 +75,6 @@
<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>
@ -108,6 +114,4 @@
</packing>
</child>
</object>
</child>
</object>
</interface>

@ -1,2 +1,2 @@
../src/extension.js
../src/weather-settings.js.in
../src/prefs.js

@ -1,5 +1,3 @@
url = https://github.com/Neroth/gnome-shell-extension-weather
# Change these to modify how installation is performed
topextensiondir = $(datadir)/gnome-shell/extensions
@ -7,41 +5,6 @@ uuid = weather@gnome-shell-extensions.gnome.org
extensiondir = $(topextensiondir)/$(uuid)
if DESKTOP_DATADIR
applicationsdir = $(DESKTOP_DATADIR)/applications
applications_DATA = weather-settings.desktop
endif
dist_extension_DATA = extension.js stylesheet.css weather-settings.ui
nodist_extension_DATA = metadata.json $(EXTRA_EXTENSION)
nodist_extension_SCRIPTS = weather-settings
EXTRA_DIST = metadata.json.in weather-settings.js.in weather-settings.desktop.in
metadata.json: metadata.json.in $(top_builddir)/config.status
$(AM_V_GEN) sed -e "s|[@]LOCALEDIR@|$(datadir)/locale|" \
-e "s|[@]uuid@|$(uuid)|" \
-e "s|[@]url@|$(url)|" $< > $@
weather-settings: weather-settings.js.in $(top_builddir)/config.status
$(AM_V_GEN) sed -e "s|[@]EXTENSIONDIR@|$(extensiondir)|" $< > $@
weather-settings.desktop: weather-settings.desktop.in $(top_builddir)/config.status
$(AM_V_GEN) sed -e "s|[@]EXTENSIONDIR@|$(extensiondir)|" $< > $@
CLEANFILES = metadata.json weather-settings weather-settings.desktop
gschemas_in = org.gnome.shell.extensions.weather.gschema.xml.in
@INTLTOOL_XML_NOMERGE_RULE@
gsettings_SCHEMAS = $(gschemas_in:.xml.in=.xml)
@GSETTINGS_RULES@
dist_extension_DATA = extension.js convenience.js prefs.js
CLEANFILES += $(gschemas_in:.xml.in=.valid) $(gsettings_SCHEMAS)
EXTRA_DIST += $(gschemas_in)
nodist_extension_DATA = $(EXTRA_EXTENSION)

@ -0,0 +1,92 @@
/* -*- mode: js -*- */
/*
Copyright (c) 2011-2012, Giovanni Campagna <scampa.giovanni@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the GNOME nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
const Gettext = imports.gettext;
const Gio = imports.gi.Gio;
const Config = imports.misc.config;
const ExtensionUtils = imports.misc.extensionUtils;
/**
* initTranslations:
* @domain: (optional): the gettext domain to use
*
* Initialize Gettext to load translations from extensionsdir/locale.
* If @domain is not provided, it will be taken from metadata['gettext-domain']
*/
function initTranslations(domain) {
let extension = ExtensionUtils.getCurrentExtension();
domain = domain || extension.metadata['gettext-domain'];
// check if this extension was built with "make zip-file", and thus
// has the locale files in a subfolder
// otherwise assume that extension has been installed in the
// same prefix as gnome-shell
let localeDir = extension.dir.get_child('locale');
if (localeDir.query_exists(null))
Gettext.bindtextdomain(domain, localeDir.get_path());
else
Gettext.bindtextdomain(domain, Config.LOCALEDIR);
}
/**
* getSettings:
* @schema: (optional): the GSettings schema id
*
* Builds and return a GSettings schema for @schema, using schema files
* in extensionsdir/schemas. If @schema is not provided, it is taken from
* metadata['settings-schema'].
*/
function getSettings(schema) {
let extension = ExtensionUtils.getCurrentExtension();
schema = schema || extension.metadata['settings-schema'];
const GioSSS = Gio.SettingsSchemaSource;
// check if this extension was built with "make zip-file", and thus
// has the schema files in a subfolder
// otherwise assume that extension has been installed in the
// same prefix as gnome-shell (and therefore schemas are available
// in the standard folders)
let schemaDir = extension.dir.get_child('schemas');
let schemaSource;
if (schemaDir.query_exists(null))
schemaSource = GioSSS.new_from_directory(schemaDir.get_path(),
GioSSS.get_default(),
false);
else
schemaSource = GioSSS.get_default();
let schemaObj = schemaSource.lookup(schema, true);
if (!schemaObj)
throw new Error('Schema ' + schema + ' could not be found for extension '
+ extension.metadata.uuid + '. Please check your installation.');
return new Gio.Settings({ settings_schema: schemaObj });
}

@ -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.gtkbuilder;
const GtkBuilder = Gtk.Builder;
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.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],
WeatherSetting.prototype =
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());
},
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;
});
};
entry.connect("changed",searchLocation);
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) {
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.getSettings(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]));
}
return a.split(">")[0];
}
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);
}
});
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()
function init()
{
this.Window.get_object("main-window").signal.hide.connect(Gtk.main_quit);
this.Window.get_object("main-window").show_all();
},
Convenience.initTranslations('gnome-shell-extension-weather');
}
selectionChanged : function(select)
function buildPrefsWidget()
{
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);
}
let prefs = new PrefsWidget();
prefs.show_all();
return prefs;
}
};
new WeatherSetting();
Loading…
Cancel
Save