/* * Weather extension for Gnome shell * - Displays a small weather information on the top panel * - On click, gives a popup with details about the weather Copyright (C) 2011 ecyrbe , Timur Kristof , Elad Alfassa , Simon Legner 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 . */ const GLib = imports.gi.GLib; const Gio = imports.gi.Gio; const Lang = imports.lang; const Mainloop = imports.mainloop; const Cairo = imports.cairo; const Clutter = imports.gi.Clutter; const Shell = imports.gi.Shell; const St = imports.gi.St; const Gettext = imports.gettext.domain('gnome-shell-extension-weather'); const _ = Gettext.gettext; const Json = imports.gi.Json; const Main = imports.ui.main; const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; const Soup = imports.gi.Soup; const Util = imports.misc.util; const UNITS = 'c'; // Units for temperature (case sensitive). f: Fahrenheit. c: Celsius const CITY_DISPLAYED = 'your city'; const YAHOO_ID = 'your yahoo woeid'; const WEATHER_URL = 'http://weather.yahooapis.com/forecastjson?u=' + UNITS + '&p=' + YAHOO_ID; const FORECAST_URL = 'http://query.yahooapis.com/v1/public/yql?format=json&q=select%20item.forecast%20from%20weather.forecast%20where%20location%3D%22' + YAHOO_ID + '%22%20%20and%20u="' + UNITS + '"'; function WeatherMenuButton() { this._init(); } WeatherMenuButton.prototype = { __proto__: PanelMenu.Button.prototype, _init: function() { // Panel icon this._weatherIcon = new St.Icon({ icon_type: St.IconType.SYMBOLIC, icon_size: Main.panel.button.get_child().height, icon_name: 'view-refresh-symbolic', style_class: 'weather-icon' + (Main.panel.actor.get_direction() == St.TextDirection.RTL ? '-rtl' : '') }); // Label this._weatherInfo = new St.Label({ text: _('...') }); // Panel menu item - the current class let menuAlignment = 0.25; if (St.Widget.get_default_direction() == St.TextDirection.RTL) menuAlignment = 1.0 - menuAlignment; PanelMenu.Button.prototype._init.call(this, menuAlignment); // Putting the panel item together let topBox = new St.BoxLayout(); topBox.add_actor(this._weatherIcon); topBox.add_actor(this._weatherInfo); this.actor.set_child(topBox); Main.panel._centerBox.add(this.actor, { y_fill: true }); Main.panel._menus.addMenu(this.menu); // Current weather this._currentWeather = new St.Bin({style_class: 'current'}); // Future weather this._futureWeather = new St.Bin({style_class: 'forecast'/*, x_align: St.Align.START*/}); // Separator (copied from Gnome shell's popupMenu.js) this._separatorArea = new St.DrawingArea({ style_class: 'popup-separator-menu-item' }); this._separatorArea.width = 200; this._separatorArea.connect('repaint', Lang.bind(this, this._onSeparatorAreaRepaint)); // Putting the popup item together let mainBox = new St.BoxLayout({vertical: true}); mainBox.add_actor(this._currentWeather); mainBox.add_actor(this._separatorArea); mainBox.add_actor(this._futureWeather); this.menu.addActor(mainBox); // Items this.showLoadingUi(); this.rebuildCurrentWeatherUi(); this.rebuildFutureWeatherUi(); // Show weather here = this; Mainloop.timeout_add(3000, function() { here.refreshWeather(); }); }, get_weather_icon: function(code) { switch (parseInt(code, 10)){ /* see http://developer.yahoo.com/weather/#codetable */ case 0:/* tornado */ return 'weather-severe-alert'; case 1:/* tropical storm */ return 'weather-severe-alert'; case 2:/* hurricane */ return 'weather-severe-alert'; case 3:/* severe thunderstorms */ return 'weather-severe-alert'; case 4:/* thunderstorms */ return 'weather-storm'; case 5:/* mixed rain and snow */ return 'weather-snow-rain'; case 6:/* mixed rain and sleet */ return 'weather-snow-rain'; case 7:/* mixed snow and sleet */ return 'weather-snow'; case 8:/* freezing drizzle */ return 'weather-freezing-rain'; case 9:/* drizzle */ return 'weather-fog'; case 10:/* freezing rain */ return 'weather-freezing-rain'; case 11:/* showers */ return 'weather-showers'; case 12:/* showers */ return 'weather-showers'; case 13:/* snow flurries */ return 'weather-snow'; case 14:/* light snow showers */ return 'weather-snow'; case 15:/* blowing snow */ return 'weather-snow'; case 16:/* snow */ return 'weather-snow'; case 17:/* hail */ return 'weather-snow'; case 18:/* sleet */ return 'weather-snow'; case 19:/* dust */ return 'weather-fog'; case 20:/* foggy */ return 'weather-fog'; case 21:/* haze */ return 'weather-fog'; case 22:/* smoky */ return 'weather-fog'; case 23:/* blustery */ return 'weather-few-clouds'; case 24:/* windy */ return 'weather-few-clouds'; case 25:/* cold */ return 'weather-few-clouds'; case 26:/* cloudy */ return 'weather-overcast'; case 27:/* mostly cloudy (night) */ return 'weather-clouds-night'; case 28:/* mostly cloudy (day) */ return 'weather-clouds'; case 29:/* partly cloudy (night) */ return 'weather-few-clouds-night'; case 30:/* partly cloudy (day) */ return 'weather-few-clouds'; case 31:/* clear (night) */ return 'weather-clear-night'; case 32:/* sunny */ return 'weather-clear'; case 33:/* fair (night) */ return 'weather-clear-night'; case 34:/* fair (day) */ return 'weather-clear'; case 35:/* mixed rain and hail */ return 'weather-snow-rain'; case 36:/* hot */ return 'weather-clear'; case 37:/* isolated thunderstorms */ return 'weather-storm'; case 38:/* scattered thunderstorms */ case 39:/* scattered thunderstorms */ return 'weather-storm'; case 40:/* scattered showers */ return 'weather-showers-scattered'; case 41:/* heavy snow */ return 'weather-snow'; case 42:/* scattered snow showers */ return 'weather-snow'; case 43:/* heavy snow */ return 'weather-snow'; case 44:/* partly cloudy */ return 'weather-few-clouds'; case 45:/* thundershowers */ return 'weather-storm'; case 46:/* snow showers */ return 'weather-snow'; case 47:/* isolated thundershowers */ return 'weather-storm'; case 3200:/* not available */ default: return 'weather-severe-alert'; } }, get_weather_condition: function(code) { switch (parseInt(code, 10)){ case 0:/* tornado */ return _('Tornado'); case 1:/* tropical storm */ return _('Tropical storm'); case 2:/* hurricane */ return _('Hurricane'); case 3:/* severe thunderstorms */ return _('Severe thunderstorms'); case 4:/* thunderstorms */ return _('Thunderstorms'); case 5:/* mixed rain and snow */ return _('Mixed rain and snow'); case 6:/* mixed rain and sleet */ return _('Mixed rain and sleet'); case 7:/* mixed snow and sleet */ return _('Mixed snow and sleet'); case 8:/* freezing drizzle */ return _('Freezing drizzle'); case 9:/* drizzle */ return _('Drizzle'); case 10:/* freezing rain */ return _('Freezing rain'); case 11:/* showers */ return _('Showers'); case 12:/* showers */ return _('Showers'); case 13:/* snow flurries */ return _('Snow flurries'); case 14:/* light snow showers */ return _('Light snow showers'); case 15:/* blowing snow */ return _('Blowing snow'); case 16:/* snow */ return _('Snow'); case 17:/* hail */ return _('Hail'); case 18:/* sleet */ return _('Sleet'); case 19:/* dust */ return _('Dust'); case 20:/* foggy */ return _('Foggy'); case 21:/* haze */ return _('Haze'); case 22:/* smoky */ return _('Smoky'); case 23:/* blustery */ return _('Blustery'); case 24:/* windy */ return _('Windy'); case 25:/* cold */ return _('Cold'); case 26:/* cloudy */ return _('Cloudy'); case 27:/* mostly cloudy (night) */ case 28:/* mostly cloudy (day) */ return _('Mostly cloudy'); case 29:/* partly cloudy (night) */ case 30:/* partly cloudy (day) */ return _('Partly cloudy'); case 31:/* clear (night) */ return _('Clear'); case 32:/* sunny */ return _('Sunny'); case 33:/* fair (night) */ case 34:/* fair (day) */ return _('Fair'); case 35:/* mixed rain and hail */ return _('Mixed rain and hail'); case 36:/* hot */ return _('Hot'); case 37:/* isolated thunderstorms */ return _('Isolated thunderstorms'); case 38:/* scattered thunderstorms */ case 39:/* scattered thunderstorms */ return _('Scattered thunderstorms'); case 40:/* scattered showers */ return _('Scattered showers'); case 41:/* heavy snow */ return _('Heavy snow'); case 42:/* scattered snow showers */ return _('Scattered snow showers'); case 43:/* heavy snow */ return _('Heavy snow'); case 44:/* partly cloudy */ return _('Partly cloudy'); case 45:/* thundershowers */ return _('Thundershowers'); case 46:/* snow showers */ return _('Snow showers'); case 47:/* isolated thundershowers */ return _('Isolated thundershowers'); case 3200:/* not available */ default: return _('Not available'); } }, parse_day: function(abr) { let yahoo_days = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday']; for(var i =0;i