/usr/share/gnome-shell/extensions/weather-extension@jenslody.de/extension.js is in gnome-shell-extension-weather 0~20131021.git1bf555c-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 | /*
*
* 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 - 2013
* ecyrbe <ecyrbe+spam@gmail.com>,
* Timur Kristof <venemo@msn.com>,
* Elad Alfassa <elad@fedoraproject.org>,
* Simon Legner <Simon.Legner@gmail.com>,
* Christian METZLER <neroth@xeked.com>,
* Mark Benjamin weather.gnome.Markie1@dfgh.net,
* Mattia Meneguzzo odysseus@fedoraproject.org,
* Meng Zhuo <mengzhuo1203+spam@gmail.com>,
* Jens Lody <jens@jenslody.de>
*
*
* 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 ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Config = imports.misc.config;
const Convenience = Me.imports.convenience;
const Cairo = imports.cairo;
const Clutter = imports.gi.Clutter;
const Gettext = imports.gettext.domain('gnome-shell-extension-weather');
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Soup = imports.gi.Soup;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const Util = imports.misc.util;
const _ = Gettext.gettext;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
// Settings
const WEATHER_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.weather';
const WEATHER_UNIT_KEY = 'unit';
const WEATHER_WIND_SPEED_UNIT_KEY = 'wind-speed-unit';
const WEATHER_WIND_DIRECTION_KEY = 'wind-direction';
const WEATHER_PRESSURE_UNIT_KEY = 'pressure-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';
const WEATHER_CENTER_FORECAST_KEY = 'center-forecast';
const WEATHER_DAYS_FORECAST = 'days-forecast';
// Keep enums in sync with GSettings schemas
const WeatherUnits = {
CELSIUS: 0,
FAHRENHEIT: 1,
KELVIN: 2,
RANKINE: 3,
REAUMUR: 4,
ROEMER: 5,
DELISLE: 6,
NEWTON: 7
}
const WeatherWindSpeedUnits = {
KPH: 0,
MPH: 1,
MPS: 2,
KNOTS: 3,
FPS: 4,
BEAUFORT: 5
}
const WeatherPressureUnits = {
hPa: 0,
inHg: 1,
bar: 2,
Pa: 3,
kPa: 4,
atm: 5,
at: 6,
Torr: 7,
psi: 8
}
const WeatherPosition = {
CENTER: 0,
RIGHT: 1,
LEFT: 2
}
const WEATHER_CONV_MPH_IN_MPS = 2.23693629;
const WEATHER_CONV_KPH_IN_MPS = 3.6;
const WEATHER_CONV_KNOTS_IN_MPS = 1.94384449;
const WEATHER_CONV_FPS_IN_MPS = 3.2808399;
// Soup session (see https://bugzilla.gnome.org/show_bug.cgi?id=661323#c64) (Simon Legner)
const _httpSession = new Soup.SessionAsync();
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault());
const WeatherMenuButton = new Lang.Class({
Name: 'WeatherMenuButton',
Extends: PanelMenu.Button,
_init: function() {
// Load settings
this.loadConfig();
// Label
this._weatherInfo = new St.Label({
y_align: Clutter.ActorAlign.CENTER,
text: _('...')
});
if (typeof St.TextDirection == "undefined") {
// Panel icon
this._weatherIcon = new St.Icon({
icon_name: 'view-refresh' + this.icon_type(),
style_class: 'system-status-icon weather-icon' + (Main.panel.actor.get_text_direction() == Clutter.TextDirection.RTL ? '-rtl' : '')
});
// Panel menu item - the current class
let menuAlignment = 0.25;
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
menuAlignment = 1.0 - menuAlignment;
this.parent(menuAlignment);
} else {
// Panel icon
this._weatherIcon = new St.Icon({
icon_name: 'view-refresh' + this.icon_type(),
style_class: 'system-status-icon weather-icon' + (Main.panel.actor.get_direction() == St.TextDirection.RTL ? '-rtl' : '')
});
// 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.add_actor(topBox);
let dummyBox = new St.BoxLayout();
this.actor.reparent(dummyBox);
dummyBox.remove_actor(this.actor);
dummyBox.destroy();
let children = null;
switch (this._position_in_panel) {
case WeatherPosition.LEFT:
children = Main.panel._leftBox.get_children();
Main.panel._leftBox.insert_child_at_index(this.actor, children.length);
break;
case WeatherPosition.CENTER:
children = Main.panel._centerBox.get_children();
Main.panel._centerBox.insert_child_at_index(this.actor, children.length);
break;
case WeatherPosition.RIGHT:
children = Main.panel._rightBox.get_children();
Main.panel._rightBox.insert_child_at_index(this.actor, 0);
break;
}
if (typeof Main.panel._menus == "undefined")
Main.panel.menuManager.addMenu(this.menu);
else
Main.panel._menus.addMenu(this.menu);
this._old_position_in_panel = this._position_in_panel;
// Current weather
this._currentWeather = new St.Bin({
style_class: 'current'
});
// Future weather
this._futureWeather = new St.Bin({
style_class: 'forecast'
});
// Putting the popup item together
let _itemCurrent = new PopupMenu.PopupBaseMenuItem({
reactive: false
});
let _itemFuture = new PopupMenu.PopupBaseMenuItem({
reactive: false
});
if (ExtensionUtils.versionCheck(['3.9', '3.10'], Config.PACKAGE_VERSION)) {
_itemCurrent.actor.add_actor(this._currentWeather);
_itemFuture.actor.add_actor(this._futureWeather);
} else {
_itemCurrent.addActor(this._currentWeather);
_itemFuture.addActor(this._futureWeather);
}
this.menu.addMenuItem(_itemCurrent);
let item = new PopupMenu.PopupSeparatorMenuItem();
this.menu.addMenuItem(item);
this.menu.addMenuItem(_itemFuture);
let item = new PopupMenu.PopupSeparatorMenuItem();
this.menu.addMenuItem(item);
this._selectCity = new PopupMenu.PopupSubMenuMenuItem(_("Locations"));
this.menu.addMenuItem(this._selectCity);
this.rebuildSelectCityItem();
let item = new PopupMenu.PopupMenuItem(_("Reload Weather Information"));
item.connect('activate', Lang.bind(this, function() {
this.refreshWeather(false);
}));
this.menu.addMenuItem(item);
let item = new PopupMenu.PopupMenuItem(_("Weather Settings"));
item.connect('activate', Lang.bind(this, this._onPreferencesActivate));
this.menu.addMenuItem(item);
// Items
this.showLoadingUi();
this.rebuildCurrentWeatherUi();
this.rebuildFutureWeatherUi();
// Show weather
this.refreshWeather(true);
this.menu.connect('open-state-changed', Lang.bind(this, this._onOpenStateChanged));
},
stop: function() {
if (this._timeoutS)
Mainloop.source_remove(this._timeoutS);
if (this._settingsC) {
this._settings.disconnect(this._settingsC);
this._settingsC = 0;
}
if (this._settingsInterfaceC) {
this._settingsInterface.disconnect(this._settingsInterfaceC);
this._settingsInterfaceC = 0;
}
},
loadConfig: function() {
let that = this;
this._settings = Convenience.getSettings(WEATHER_SETTINGS_SCHEMA);
this._settingsC = this._settings.connect("changed", function() {
that.rebuildFutureWeatherUi();
that.refreshWeather(false);
});
},
loadConfigInterface: function() {
let that = this;
let schemaInterface = "org.gnome.desktop.interface";
if (Gio.Settings.list_schemas().indexOf(schemaInterface) == -1)
throw _("Schema \"%s\" not found.").replace("%s", schemaInterface);
this._settingsInterface = new Gio.Settings({
schema: schemaInterface
});
this._settingsInterfaceC = this._settingsInterface.connect("changed", function() {
that.refreshWeather(false);
});
},
get _clockFormat() {
if (!this._settingsInterface)
this.loadConfigInterface();
return this._settingsInterface.get_string("clock-format");
},
get _units() {
if (!this._settings)
this.loadConfig();
return this._settings.get_enum(WEATHER_UNIT_KEY);
},
set _units(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_enum(WEATHER_UNIT_KEY, v);
},
get _wind_speed_units() {
if (!this._settings)
this.loadConfig();
return this._settings.get_enum(WEATHER_WIND_SPEED_UNIT_KEY);
},
set _wind_speed_units(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_enum(WEATHER_WIND_SPEED_UNIT_KEY, v);
},
get _wind_direction() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(WEATHER_WIND_DIRECTION_KEY);
},
set _wind_direction(v) {
if (!this._settings)
this.loadConfig();
return this._settings.set_boolean(WEATHER_WIND_DIRECTION_KEY, v);
},
get _pressure_units() {
if (!this._settings)
this.loadConfig();
return this._settings.get_enum(WEATHER_PRESSURE_UNIT_KEY);
},
set _pressure_units(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_enum(WEATHER_PRESSURE_UNIT_KEY, v);
},
get _cities() {
if (!this._settings)
this.loadConfig();
return this._settings.get_string(WEATHER_CITY_KEY);
},
set _cities(v) {
if (!this._settings)
this.loadConfig();
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 b = a;
var cities = this._cities.split(" && ");
if (typeof cities != "object")
cities = [cities];
var l = cities.length - 1;
if (a < 0)
a = 0;
if (l < 0)
l = 0;
if (a > l)
a = l;
return a;
},
set _actual_city(a) {
if (!this._settings)
this.loadConfig();
var cities = this._cities.split(" && ");
if (typeof cities != "object")
cities = [cities];
var l = cities.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 _city() {
let cities = this._cities;
let cities = cities.split(" && ");
if (cities && typeof cities == "string")
cities = [cities];
if (!cities[0])
return "";
cities = cities[this._actual_city];
return cities;
},
set _city(v) {
let cities = this._cities;
cities = cities.split(" && ");
if (cities && typeof cities == "string")
cities = [cities];
if (!cities[0])
cities = [];
cities.splice(this.actual_city, 1, v);
cities = cities.join(" && ");
if (typeof cities != "string")
cities = cities[0];
this._cities = cities;
},
get _translate_condition() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(WEATHER_TRANSLATE_CONDITION_KEY);
},
set _translate_condition(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(WEATHER_TRANSLATE_CONDITION_KEY, v);
},
get _icon_type() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(WEATHER_USE_SYMBOLIC_ICONS_KEY) ? 1 : 0;
},
set _icon_type(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(WEATHER_USE_SYMBOLIC_ICONS_KEY, v);
},
get _text_in_panel() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(WEATHER_SHOW_TEXT_IN_PANEL_KEY);
},
set _text_in_panel(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(WEATHER_SHOW_TEXT_IN_PANEL_KEY, v);
},
get _position_in_panel() {
if (!this._settings)
this.loadConfig();
return this._settings.get_enum(WEATHER_POSITION_IN_PANEL_KEY);
},
set _position_in_panel(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_enum(WEATHER_POSITION_IN_PANEL_KEY, v);
},
get _comment_in_panel() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(WEATHER_SHOW_COMMENT_IN_PANEL_KEY);
},
set _comment_in_panel(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(WEATHER_SHOW_COMMENT_IN_PANEL_KEY, v);
},
get _refresh_interval() {
if (!this._settings)
this.loadConfig();
return this._settings.get_int(WEATHER_REFRESH_INTERVAL);
},
set _refresh_interval(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_int(WEATHER_REFRESH_INTERVAL, v);
},
get _center_forecast() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(WEATHER_CENTER_FORECAST_KEY);
},
set _center_forecast(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(WEATHER_CENTER_FORECAST_KEY, v);
},
get _days_forecast() {
if (!this._settings)
this.loadConfig();
return this._settings.get_int(WEATHER_DAYS_FORECAST);
},
set _days_forecast(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_int(WEATHER_DAYS_FORECAST, v);
},
rebuildSelectCityItem: function() {
let that = this;
this._selectCity.menu.removeAll();
let item = null;
let cities = this._cities;
cities = cities.split(" && ");
if (cities && typeof cities == "string")
cities = [cities];
if (!cities[0])
return 0;
for (let i = 0; cities.length > i; i++) {
item = new PopupMenu.PopupMenuItem(this.extractLocation(cities[i]));
item.location = i;
if (i == this._actual_city) {
if (ExtensionUtils.versionCheck(['3.9', '3.10'], Config.PACKAGE_VERSION))
item.setOrnament(PopupMenu.Ornament.DOT);
else
item.setShowDot(true);
}
this._selectCity.menu.addMenuItem(item);
item.connect('activate', function(actor, event) {
that._actual_city = actor.location;
});
}
if (cities.length == 1)
this._selectCity.actor.hide();
else
this._selectCity.actor.show();
return 0;
},
extractLocation: function() {
if (!arguments[0])
return "";
if (arguments[0].search(">") == -1)
return _("Invalid city");
return arguments[0].split(">")[1];
},
extractWoeid: function() {
if (!arguments[0])
return 0;
if (arguments[0].search(">") == -1)
return 0;
return arguments[0].split(">")[0];
},
updateCities: function() {
let that = this;
let cities = this._cities;
cities = cities.split(" && ");
if (cities && typeof cities == "string")
cities = [cities];
if (!cities[0])
cities = [];
if (cities.length == 0) {
this._cities = "12478500>Ibiza, Balearic Islands (ES)";
this.updateCities();
return 0;
}
for (let a in cities) {
if (!this.extractWoeid(cities[a])) {
this.load_json_async(encodeURI("http://query.yahooapis.com/v1/public/yql?format=json&q=select woeid,name,admin1,country from geo.places where text = '" + cities[a] + "' limit 1"), function() {
let city = arguments[0].query;
if (typeof city == "object" && typeof city.results == "object")
city = city.results.place;
else
return;
let cityText = city.woeid + ">" + city.name;
if (city.admin1)
cityText += ", " + city.admin1.content;
if (city.country)
cityText += " (" + city.country.code + ")";
cities.splice(a, 1, cityText);
cities = cities.join(" && ");
if (typeof cities != "string")
cities = cities[0];
that._cities = cities;
that.updateCities();
});
return 0;
} else
continue;
}
this.refreshWeather();
return 0;
},
_onPreferencesActivate: function() {
Util.spawn(["gnome-shell-extension-prefs", "weather-extension@jenslody.de"]);
return 0;
},
_onOpenStateChanged: function(menu, open) {
if (open && typeof this._forecastScrollBox != "undefined" && typeof this._forecastBox != "undefined" && typeof this._currentWeather != "undefined") {
this._forecastScrollBox.set_width(this._currentWeather.get_width());
if (this._forecastBox.get_width() > this._currentWeather.get_width()) {
this._forecastScrollBox.hscroll.margin_top = 10;
this._forecastScrollBox.hscroll.show();
} else {
this._forecastScrollBox.hscroll.margin_top = 0;
this._forecastScrollBox.hscroll.hide();
}
}
},
unit_to_unicode: function() {
if (this._units == WeatherUnits.FAHRENHEIT)
return '\u00B0\F';
else if (this._units == WeatherUnits.KELVIN)
return 'K';
else if (this._units == WeatherUnits.RANKINE)
return '\u00B0\Ra';
else if (this._units == WeatherUnits.REAUMUR)
return '\u00B0\R\u00E9';
else if (this._units == WeatherUnits.ROEMER)
return '\u00B0\R\u00F8';
else if (this._units == WeatherUnits.DELISLE)
return '\u00B0\De';
else if (this._units == WeatherUnits.NEWTON)
return '\u00B0\N';
else
return '\u00B0\C';
},
get_weather_url: function() {
return encodeURI('http://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.forecast where woeid = ' + this.extractWoeid(this._city) + ' and u="f"');
},
get_weather_icon: function(code) {
// see http://developer.yahoo.com/weather/#codetable
// fallback icons are: weather-clear-night weather-clear weather-few-clouds-night weather-few-clouds weather-fog weather-overcast weather-severe-alert weather-showers weather-showers-scattered weather-snow weather-storm
switch (parseInt(code, 10)) {
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', 'weather-snow'];
case 6:
// mixed rain and sleet
return ['weather-snow-rain', 'weather-snow'];
case 7:
// mixed snow and sleet
return ['weather-snow'];
case 8:
// freezing drizzle
return ['weather-freezing-rain', 'weather-showers'];
case 9:
// drizzle
return ['weather-showers'];
case 10:
// freezing rain
return ['weather-freezing-rain', 'weather-showers'];
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', 'weather-few-clouds-night'];
case 28:
// mostly cloudy (day)
return ['weather-clouds', 'weather-overcast'];
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', 'weather-showers'];
case 36:
// hot
return ['weather-clear'];
case 37:
// isolated thunderstorms
return ['weather-storm'];
case 38:
// scattered thunderstorms
return ['weather-storm'];
case 39:
// The API-description differs from the use by !Yahoo, see:
// http://developer.yahoo.com/forum/YDN-Documentation/Yahoo-Weather-API-Wrong-Condition-Code/1290534174000-1122fc3d-da6d-34a2-9fb9-d0863e6c5bc6
// guessed as isolated showers
return ['weather-showers-isolated', 'weather-showers'];
case 40:
// scattered showers
return ['weather-showers-scattered', 'weather-showers'];
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_icon_safely: function(code) {
let iconname = this.get_weather_icon(code);
for (let i = 0; i < iconname.length; i++) {
if (this.has_icon(iconname[i]))
return iconname[i] + this.icon_type();
}
return 'weather-severe-alert' + this.icon_type();
},
has_icon: function(icon) {
return Gtk.IconTheme.get_default().has_icon(icon + this.icon_type());
},
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
return _('Scattered thunderstorms');
case 39:
// The API-description differs from the use by !Yahoo, see:
// http://developer.yahoo.com/forum/YDN-Documentation/Yahoo-Weather-API-Wrong-Condition-Code/1290534174000-1122fc3d-da6d-34a2-9fb9-d0863e6c5bc6
// guessed as isolated showers
return _('Isolated showers');
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');
}
},
toCelsius: function(t) {
return String(Math.round((Number(t) - 32) / 1.8));
},
toKelvin: function(t) {
return String(Math.round(((Number(t) + 459.67) / 1.8) * 100) / 100);
},
toRankine: function(t) {
return String(Math.round((Number(t) + 459.67) * 100) / 100);
},
toReaumur: function(t) {
return String(Math.round((Number(t) - 32) / 2.25));
},
toRoemer: function(t) {
return String(Math.round((((Number(t) - 32) * 7) / 24) + 7.5));
},
toDelisle: function(t) {
return String(Math.round(((212 - Number(t)) * 5) / 6));
},
toNewton: function(t) {
return String(Math.round((((Number(t) - 32) * 11) / 60) * 10) / 10);
},
toPascal: function(p, t) {
return Math.round((p * (3386.39 - ((t - 32) * 0.003407143))));
},
toBeaufort: function(w, t) {
if (w < 1)
return (!t) ? "0" : "(" + _("Calm") + ")";
else if (w >= 1 && w <= 3)
return (!t) ? "1" : "(" + _("Light air") + ")";
else if (w >= 4 && w <= 7)
return (!t) ? "2" : "(" + _("Light breeze") + ")";
else if (w >= 8 && w <= 12)
return (!t) ? "3" : "(" + _("Gentle breeze") + ")";
else if (w >= 13 && w <= 17)
return (!t) ? "4" : "(" + _("Moderate breeze") + ")";
else if (w >= 18 && w <= 24)
return (!t) ? "5" : "(" + _("Fresh breeze") + ")";
else if (w >= 25 && w <= 30)
return (!t) ? "6" : "(" + _("Strong breeze") + ")";
else if (w >= 31 && w <= 38)
return (!t) ? "7" : "(" + _("Moderate gale") + ")";
else if (w >= 39 && w <= 46)
return (!t) ? "8" : "(" + _("Fresh gale") + ")";
else if (w >= 47 && w <= 54)
return (!t) ? "9" : "(" + _("Strong gale") + ")";
else if (w >= 55 && w <= 63)
return (!t) ? "10" : "(" + _("Storm") + ")";
else if (w >= 64 && w <= 73)
return (!t) ? "11" : "(" + _("Violent storm") + ")";
else
return (!t) ? "12" : "(" + _("Hurricane") + ")";
},
get_locale_day: function(abr) {
let days = [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')];
return days[abr];
},
get_wind_direction: function(deg) {
let arrows = ["\u2193", "\u2199", "\u2190", "\u2196", "\u2191", "\u2197", "\u2192", "\u2198"];
let letters = [_('N'), _('NE'), _('E'), _('SE'), _('S'), _('SW'), _('W'), _('NW')];
let idx = Math.round(deg / 45) % arrows.length;
return (this._wind_direction) ? arrows[idx] : letters[idx];
},
get_pressure_state: function(state) {
switch (parseInt(state, 3)) {
case 0:
return '';
break;
case 1:
return '\u2934';
break;
case 2:
return '\u2935';
break;
}
return 0;
},
icon_type: function(icon_name) {
if (!icon_name)
if (this._icon_type)
return "-symbolic";
else
return "";
if (this._icon_type)
if (String(icon_name).search("-symbolic") != -1)
return icon_name;
else
return icon_name + "-symbolic";
else
if (String(icon_name).search("-symbolic") != -1)
return String(icon_name).replace("-symbolic", "");
else
return icon_name;
},
load_json_async: function(url, fun) {
let here = this;
let message = Soup.Message.new('GET', url);
_httpSession.queue_message(message, function(_httpSession, message) {
if (!message.response_body.data) {
fun.call(here, 0);
return;
}
try {
let jp = JSON.parse(message.response_body.data);
fun.call(here, jp);
} catch (e) {
fun.call(here, 0);
return;
}
});
return 0;
},
refreshWeather: function(recurse) {
if (!this.extractWoeid(this._city)) {
this.updateCities();
return 0;
}
this.load_json_async(this.get_weather_url(), function(json) {
if (!json)
return 0;
let weather = json.query.results.channel;
let many = 0;
if (typeof weather[0] != "undefined") {
weather = weather[0];
many = 1;
}
let weather_c = weather.item.condition;
this.rebuildSelectCityItem();
this._weatherIcon.icon_name = this.icon_type(this._weatherIcon.icon_name);
this._currentWeatherIcon.icon_name = this.icon_type(this._currentWeatherIcon.icon_name);
this._forecast[0].Icon.icon_name = this.icon_type(this._forecast[0].Icon.icon_name);
this._forecast[1].Icon.icon_name = this.icon_type(this._forecast[1].Icon.icon_name);
this._sunriseIcon.icon_name = this.icon_type(this._sunriseIcon.icon_name);
this._sunsetIcon.icon_name = this.icon_type(this._sunsetIcon.icon_name);
this._buildIcon.icon_name = this.icon_type(this._buildIcon.icon_name);
if (typeof St.IconType != "undefined") {
this._weatherIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR;
this._currentWeatherIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR;
this._forecast[0].Icon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR;
this._forecast[1].Icon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR;
this._sunriseIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR;
this._sunsetIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR;
this._buildIcon.icon_type = (this._icon_type) ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR;
}
if (this._old_position_in_panel != this._position_in_panel) {
switch (this._old_position_in_panel) {
case WeatherPosition.LEFT:
Main.panel._leftBox.remove_actor(this.actor);
break;
case WeatherPosition.CENTER:
Main.panel._centerBox.remove_actor(this.actor);
break;
case WeatherPosition.RIGHT:
Main.panel._rightBox.remove_actor(this.actor);
break;
}
let children = null;
switch (this._position_in_panel) {
case WeatherPosition.LEFT:
children = Main.panel._leftBox.get_children();
Main.panel._leftBox.insert_child_at_index(this.actor, children.length);
break;
case WeatherPosition.CENTER:
children = Main.panel._centerBox.get_children();
Main.panel._centerBox.insert_child_at_index(this.actor, children.length);
break;
case WeatherPosition.RIGHT:
children = Main.panel._rightBox.get_children();
Main.panel._rightBox.insert_child_at_index(this.actor, 0);
break;
}
this._old_position_in_panel = this._position_in_panel;
}
let forecast = weather.item.forecast;
let location = this.extractLocation(this._city);
// Refresh current weather
let comment = weather_c.text;
if (this._translate_condition)
comment = this.get_weather_condition(weather_c.code);
let temperature = weather_c.temp;
let chill = weather.wind.chill;
let humidity = weather.atmosphere.humidity + ' %';
let pressure = weather.atmosphere.pressure;
let pressure_unit = weather.units.pressure;
let pressure_state = weather.atmosphere.rising;
let wind_direction = this.get_wind_direction(weather.wind.direction);
let wind = weather.wind.speed;
let wind_unit = weather.units.speed;
let iconname = this.get_weather_icon_safely(weather_c.code);
let sunrise = weather.astronomy.sunrise;
let sunset = weather.astronomy.sunset;
if (typeof this.lastBuildId == "undefined")
this.lastBuildId = 0;
if (typeof this.lastBuildDate == "undefined")
this.lastBuildDate = 0;
if (this.lastBuildId != weather_c.date || !this.lastBuildDate) {
this.lastBuildId = weather_c.date;
this.lastBuildDate = new Date();
}
let actualDate = new Date();
let d = Math.floor((actualDate.getTime() - this.lastBuildDate.getTime()) / 86400000);
switch (this._pressure_units) {
case WeatherPressureUnits.inHg:
pressure_unit = "inHg";
break;
case WeatherPressureUnits.hPa:
pressure = Math.round(this.toPascal(pressure, temperature) / 100);
pressure_unit = "hPa";
break;
case WeatherPressureUnits.bar:
pressure = this.toPascal(pressure, temperature) / 100000;
pressure_unit = "bar";
break;
case WeatherPressureUnits.Pa:
pressure = this.toPascal(pressure, temperature);
pressure_unit = "Pa";
break;
case WeatherPressureUnits.kPa:
pressure = Math.round(this.toPascal(pressure, temperature) / 100) / 10;
pressure_unit = "kPa";
break;
case WeatherPressureUnits.atm:
pressure = Math.round((this.toPascal(pressure, temperature) * 0.00000986923267) * 100000) / 100000;
pressure_unit = "atm";
break;
case WeatherPressureUnits.at:
pressure = Math.round((this.toPascal(pressure, temperature) * 0.0000101971621298) * 100000) / 100000;
pressure_unit = "at";
break;
case WeatherPressureUnits.Torr:
pressure = Math.round((this.toPascal(pressure, temperature) * 0.00750061683) * 100) / 100;
pressure_unit = "Torr";
break;
case WeatherPressureUnits.psi:
pressure = Math.round((this.toPascal(pressure, temperature) * 0.000145037738) * 100) / 100;
pressure_unit = "psi";
break;
}
switch (this._units) {
case WeatherUnits.FAHRENHEIT:
break;
case WeatherUnits.CELSIUS:
temperature = this.toCelsius(temperature);
chill = this.toCelsius(chill);
break;
case WeatherUnits.KELVIN:
temperature = this.toKelvin(temperature);
chill = this.toKelvin(chill);
break;
case WeatherUnits.RANKINE:
temperature = this.toRankine(temperature);
chill = this.toRankine(chill);
break;
case WeatherUnits.REAUMUR:
temperature = this.toReaumur(temperature);
chill = this.toReaumur(chill);
break;
case WeatherUnits.ROEMER:
temperature = this.toRoemer(temperature);
chill = this.toRoemer(chill);
break;
case WeatherUnits.DELISLE:
temperature = this.toDelisle(temperature);
chill = this.toDelisle(chill);
break;
case WeatherUnits.NEWTON:
temperature = this.toNewton(temperature);
chill = this.toNewton(chill);
break;
}
let lastBuild = (this.lastBuildDate.getHours() % 12) + ":" + ((this.lastBuildDate.getMinutes() < 10) ? "0" : "") + this.lastBuildDate.getMinutes() + " " + ((this.lastBuildDate.getHours() >= 12) ? "pm" : "am");
if (this._clockFormat == "24h") {
sunrise = new Date("3 Mar 1999 " + sunrise);
sunrise = sunrise.getHours() + ":" + ((sunrise.getMinutes() < 10) ? "0" : "") + sunrise.getMinutes();
sunset = new Date("3 Mar 1999 " + sunset);
sunset = sunset.getHours() + ":" + ((sunset.getMinutes() < 10) ? "0" : "") + sunset.getMinutes();
lastBuild = this.lastBuildDate.getHours() + ":" + ((this.lastBuildDate.getMinutes() < 10) ? "0" : "") + this.lastBuildDate.getMinutes();
}
if (d >= 1) {
lastBuild = _("Yesterday");
if (d > 1)
lastBuild = _("%s days ago").replace("%s", d);
}
this._currentWeatherIcon.icon_name = this._weatherIcon.icon_name = iconname;
let weatherInfoC = "";
let weatherInfoT = "";
if (this._comment_in_panel)
weatherInfoC = comment;
if (this._text_in_panel)
weatherInfoT = parseFloat(temperature).toLocaleString() + ' ' + this.unit_to_unicode();
this._weatherInfo.text = weatherInfoC + ((weatherInfoC && weatherInfoT) ? ", " : "") + weatherInfoT;
this._currentWeatherSummary.text = comment + ", " + parseFloat(temperature).toLocaleString() + ' ' + this.unit_to_unicode();
this._currentWeatherLocation.text = location;
this._currentWeatherTemperature.text = parseFloat(chill).toLocaleString() + ' ' + this.unit_to_unicode();
this._currentWeatherHumidity.text = parseFloat(humidity).toLocaleString() + ' %';
this._currentWeatherPressure.text = parseFloat(pressure).toLocaleString() + ' ' + pressure_unit + ((pressure_state) ? " " : "") + this.get_pressure_state(pressure_state);
this._currentWeatherSunrise.text = sunrise;
this._currentWeatherSunset.text = sunset;
this._currentWeatherBuild.text = lastBuild;
// Override wind units with our preference
// Need to consider what units the Yahoo API has returned it in
switch (this._wind_speed_units) {
case WeatherWindSpeedUnits.MPH:
break;
case WeatherWindSpeedUnits.KPH:
wind = Math.round(wind / WEATHER_CONV_MPH_IN_MPS * WEATHER_CONV_KPH_IN_MPS);
wind_unit = 'km/h';
break;
case WeatherWindSpeedUnits.MPS:
wind = Math.round((wind / WEATHER_CONV_MPH_IN_MPS) * 10) / 10;
wind_unit = 'm/s';
break;
case WeatherWindSpeedUnits.KNOTS:
wind = Math.round(wind / WEATHER_CONV_MPH_IN_MPS * WEATHER_CONV_KNOTS_IN_MPS);
wind_unit = 'kn';
break;
case WeatherWindSpeedUnits.FPS:
wind = Math.round(wind / WEATHER_CONV_MPH_IN_MPS * WEATHER_CONV_FPS_IN_MPS);
wind_unit = 'ft/s';
break;
case WeatherWindSpeedUnits.BEAUFORT:
wind_unit = this.toBeaufort(wind, true);
wind = this.toBeaufort(wind);
}
if (!wind)
this._currentWeatherWind.text = '\u2013';
else if (wind == 0 || !wind_direction)
this._currentWeatherWind.text = parseFloat(wind).toLocaleString() + ' ' + wind_unit;
else // i.e. wind > 0 && wind_direction
this._currentWeatherWind.text = wind_direction + ' ' + parseFloat(wind).toLocaleString() + ' ' + wind_unit;
// Refresh forecast
for (let i = 0; i < this._days_forecast; i++) {
let forecastUi = this._forecast[i];
let forecastData = forecast[i];
let code = forecastData.code;
let t_low = forecastData.low;
let t_high = forecastData.high;
switch (this._units) {
case WeatherUnits.FAHRENHEIT:
break;
case WeatherUnits.CELSIUS:
t_low = this.toCelsius(t_low);
t_high = this.toCelsius(t_high);
break;
case WeatherUnits.KELVIN:
t_low = this.toKelvin(t_low);
t_high = this.toKelvin(t_high);
break;
case WeatherUnits.RANKINE:
t_low = this.toRankine(t_low);
t_high = this.toRankine(t_high);
break;
case WeatherUnits.REAUMUR:
t_low = this.toReaumur(t_low);
t_high = this.toReaumur(t_high);
break;
case WeatherUnits.ROEMER:
t_low = this.toRoemer(t_low);
t_high = this.toRoemer(t_high);
break;
case WeatherUnits.DELISLE:
t_low = this.toDelisle(t_low);
t_high = this.toDelisle(t_high);
break;
case WeatherUnits.NEWTON:
t_low = this.toNewton(t_low);
t_high = this.toNewton(t_high);
break;
}
let comment = forecastData.text;
if (this._translate_condition)
comment = this.get_weather_condition(code);
let forecastDate = new Date(forecastData.date);
let dayLeft = Math.floor((actualDate.getTime() - forecastDate.getTime()) / 1000 / 60 / 60 / 24);
let date_string = _("Today");
if (dayLeft == -1)
date_string = _("Tomorrow");
else if (dayLeft < -1)
date_string = _("In %s days").replace("%s", -1 * dayLeft);
else if (dayLeft == 1)
date_string = _("Yesterday");
else if (dayLeft > 1)
date_string = _("%s days ago").replace("%s", dayLeft);
forecastUi.Day.text = date_string + ' (' + this.get_locale_day(forecastDate.getDay()) + ')';
forecastUi.Temperature.text = '\u2193 ' + parseFloat(t_low).toLocaleString() + ' ' + this.unit_to_unicode() + ' \u2191 ' + parseFloat(t_high).toLocaleString() + ' ' + this.unit_to_unicode();
forecastUi.Summary.text = comment;
forecastUi.Icon.icon_name = this.get_weather_icon_safely(code);
}
return 0;
});
// Repeatedly refresh weather if recurse is set
if (recurse) {
this._timeoutS = Mainloop.timeout_add_seconds(this._refresh_interval, Lang.bind(this, function() {
this.refreshWeather(true);
}));
}
return 0;
},
destroyCurrentWeather: function() {
if (this._currentWeather.get_child() != null)
this._currentWeather.get_child().destroy();
},
destroyFutureWeather: function() {
if (this._futureWeather.get_child() != null)
this._futureWeather.get_child().destroy();
},
showLoadingUi: function() {
this.destroyCurrentWeather();
this.destroyFutureWeather();
this._currentWeather.set_child(new St.Label({
text: _('Loading current weather ...')
}));
this._futureWeather.set_child(new St.Label({
text: _('Loading future weather ...')
}));
},
rebuildCurrentWeatherUi: function() {
this.destroyCurrentWeather();
// This will hold the icon for the current weather
this._currentWeatherIcon = new St.Icon({
icon_size: 72,
icon_name: 'view-refresh' + this.icon_type(),
style_class: 'weather-current-icon'
});
this._sunriseIcon = new St.Icon({
icon_size: 15,
icon_name: 'weather-clear' + this.icon_type(),
style_class: 'weather-sunrise-icon'
});
this._sunsetIcon = new St.Icon({
icon_size: 15,
icon_name: 'weather-clear-night' + this.icon_type(),
style_class: 'weather-sunset-icon'
});
this._buildIcon = new St.Icon({
icon_size: 15,
icon_name: 'view-refresh' + this.icon_type(),
style_class: 'weather-build-icon'
});
// The summary of the current weather
this._currentWeatherSummary = new St.Label({
text: _('Loading ...'),
style_class: 'weather-current-summary'
});
this._currentWeatherLocation = new St.Label({
text: _('Please wait')
});
let bb = new St.BoxLayout({
vertical: true,
style_class: 'weather-current-summarybox'
});
bb.add_actor(this._currentWeatherLocation);
bb.add_actor(this._currentWeatherSummary);
this._currentWeatherSunrise = new St.Label({
text: '-'
});
this._currentWeatherSunset = new St.Label({
text: '-'
});
this._currentWeatherBuild = new St.Label({
text: '-'
});
let ab = new St.BoxLayout({
style_class: 'weather-current-infobox'
});
ab.add_actor(this._sunriseIcon);
ab.add_actor(this._currentWeatherSunrise);
ab.add_actor(this._sunsetIcon);
ab.add_actor(this._currentWeatherSunset);
ab.add_actor(this._buildIcon);
ab.add_actor(this._currentWeatherBuild);
bb.add_actor(ab);
// Other labels
this._currentWeatherTemperature = new St.Label({
text: '...'
});
this._currentWeatherHumidity = new St.Label({
text: '...'
});
this._currentWeatherPressure = new St.Label({
text: '...'
});
this._currentWeatherWind = new St.Label({
text: '...'
});
let rb = new St.BoxLayout({
style_class: 'weather-current-databox'
});
let rb_captions = new St.BoxLayout({
vertical: true,
style_class: 'weather-current-databox-captions'
});
let rb_values = new St.BoxLayout({
vertical: true,
style_class: 'weather-current-databox-values'
});
rb.add_actor(rb_captions);
rb.add_actor(rb_values);
rb_captions.add_actor(new St.Label({
text: _('Feels like:')
}));
rb_values.add_actor(this._currentWeatherTemperature);
rb_captions.add_actor(new St.Label({
text: _('Humidity:')
}));
rb_values.add_actor(this._currentWeatherHumidity);
rb_captions.add_actor(new St.Label({
text: _('Pressure:')
}));
rb_values.add_actor(this._currentWeatherPressure);
rb_captions.add_actor(new St.Label({
text: _('Wind:')
}));
rb_values.add_actor(this._currentWeatherWind);
let xb = new St.BoxLayout();
xb.add_actor(bb);
xb.add_actor(rb);
let box = new St.BoxLayout({
style_class: 'weather-current-iconbox'
});
box.add_actor(this._currentWeatherIcon);
box.add_actor(xb);
this._currentWeather.set_child(box);
},
rebuildFutureWeatherUi: function() {
this.destroyFutureWeather();
this._forecast = [];
this._forecastBox = new St.BoxLayout({
x_align: this._center_forecast ? St.Align.END : St.Align.START,
style_class: 'weather-forecast-box'
});
this._forecastScrollBox = new St.ScrollView({
style_class: 'weather-forecasts'
});
this._forecastScrollBox.hscroll.margin_right = 25;
this._forecastScrollBox.hscroll.margin_left = 25;
this._forecastScrollBox.hscroll.hide();
this._forecastScrollBox.vscrollbar_policy = Gtk.PolicyType.NEVER;
this._forecastScrollBox.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
this._futureWeather.set_child(this._forecastScrollBox);
for (let i = 0; i < this._days_forecast; i++) {
let forecastWeather = {};
forecastWeather.Icon = new St.Icon({
icon_size: 48,
icon_name: 'view-refresh' + this.icon_type(),
style_class: 'weather-forecast-icon'
});
forecastWeather.Day = new St.Label({
style_class: 'weather-forecast-day'
});
forecastWeather.Summary = new St.Label({
style_class: 'weather-forecast-summary'
});
forecastWeather.Temperature = new St.Label({
style_class: 'weather-forecast-temperature'
});
let by = new St.BoxLayout({
vertical: true,
style_class: 'weather-forecast-databox'
});
by.add_actor(forecastWeather.Day);
by.add_actor(forecastWeather.Summary);
by.add_actor(forecastWeather.Temperature);
let bb = new St.BoxLayout({
style_class: 'weather-forecast-iconbox'
});
bb.add_actor(forecastWeather.Icon);
bb.add_actor(by);
this._forecast[i] = forecastWeather;
this._forecastBox.add_actor(bb);
}
this._forecastScrollBox.add_actor(this._forecastBox);
}
});
let weatherMenu;
function init() {
Convenience.initTranslations('gnome-shell-extension-weather');
}
function enable() {
weatherMenu = new WeatherMenuButton();
Main.panel.addToStatusArea('weatherMenu', weatherMenu);
}
function disable() {
weatherMenu.stop();
weatherMenu.destroy();
}
|