Add option to force a per location provider, independant from global default provider;

use gtk_noteboook for preferences, to make it possible to provide new column without blowing up the dialog-size.
merge-requests/218/head
None 9 years ago
parent 61b31e9b38
commit f42e966142
  1. 2
      data/org.gnome.shell.extensions.openweather.gschema.xml.in
  2. 406
      data/weather-settings.ui
  3. 164
      src/extension.js
  4. 85
      src/prefs.js

@ -65,7 +65,7 @@
<_description>Choose whether to display wind direction through arrows or letters.</_description>
</key>
<key name="city" type="s">
<default>'2516479>Eivissa (CA)'</default>
<default>'-8.5211767,179.1976747>Vaiaku, Tuvalu>-1'</default>
<_summary>City to be displayed</_summary>
</key>
<key name="actual-city" type="i">

@ -77,6 +77,23 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="edit-combo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">5</property>
<items>
<item translatable="yes">Extensions default weather provider</item>
<item>http://openweathermap.org</item>
<item>http://forecast.io</item>
</items>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkSeparator" id="separator2">
<property name="visible">True</property>
@ -87,7 +104,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
<property name="position">5</property>
</packing>
</child>
<child>
@ -215,6 +232,24 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="search-combo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">5</property>
<property name="active">0</property>
<items>
<item translatable="yes">Extensions default weather provider</item>
<item>http://openweathermap.org</item>
<item>http://forecast.io</item>
</items>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkSeparator" id="separator1">
<property name="visible">True</property>
@ -225,7 +260,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">5</property>
<property name="position">3</property>
</packing>
</child>
<child>
@ -271,7 +306,7 @@
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">6</property>
<property name="position">4</property>
</packing>
</child>
</object>
@ -286,18 +321,21 @@
</object>
<object class="GtkListStore" id="tree-liststore">
<columns>
<!-- column-name text -->
<!-- column-name location -->
<column type="gchararray"/>
<!-- column-name provider -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0">dummy</col>
<col id="1">dummy</col>
</row>
</data>
</object>
<object class="GtkScrolledWindow" id="main-widget">
<property name="width_request">910</property>
<property name="height_request">730</property>
<property name="width_request">720</property>
<property name="height_request">480</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="border_width">20</property>
@ -309,12 +347,13 @@
<property name="vscroll_policy">natural</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkBox" id="main-box">
<object class="GtkNotebook" id="prefs-notebook">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="can_focus">True</property>
<property name="scrollable">True</property>
<property name="enable_popup">True</property>
<child>
<object class="GtkBox" id="box-left">
<object class="GtkBox" id="locations-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
@ -325,17 +364,18 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<property name="min_content_width">200</property>
<property name="min_content_width">300</property>
<property name="min_content_height">250</property>
<child>
<object class="GtkTreeView" id="tree-treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">tree-liststore</property>
<property name="headers_visible">False</property>
<property name="reorderable">True</property>
<property name="search_column">0</property>
<property name="show_expanders">False</property>
<property name="level_indentation">12</property>
<property name="tooltip_column">1</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection"/>
</child>
@ -398,26 +438,31 @@
</packing>
</child>
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="locations-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Locations</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid4">
<object class="GtkGrid" id="provider-grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">10</property>
<property name="row_spacing">5</property>
<property name="column_spacing">5</property>
<property name="row_homogeneous">True</property>
<child>
<object class="GtkLabel" id="label-weather-provider">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Chose weather provider</property>
<property name="label" translatable="yes">Chose default weather provider</property>
</object>
<packing>
<property name="left_attach">0</property>
@ -425,10 +470,10 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="label-units">
<object class="GtkLabel" id="label-appid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Temperature Unit</property>
<property name="label" translatable="yes">Personal Api key from openweathermap.org</property>
</object>
<packing>
<property name="left_attach">0</property>
@ -436,241 +481,315 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="label-wind-speed-unit">
<object class="GtkComboBoxText" id="weather_provider">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Wind Speed Unit</property>
<items>
<item>http://openweathermap.org</item>
<item>http://forecast.io</item>
</items>
</object>
<packing>
<property name="left_attach">0</property>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="appid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">32</property>
<property name="width_chars">32</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="appid_fc">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_tooltip">True</property>
<property name="width_chars">32</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-pressure-unit">
<object class="GtkLabel" id="label-appid-fc">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Pressure Unit</property>
<property name="label" translatable="yes">Personal Api key from forecast.io</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="provider-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Weather provider</property>
</object>
<packing>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="units-grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">10</property>
<property name="row_spacing">5</property>
<property name="column_spacing">5</property>
<child>
<object class="GtkLabel" id="label-position-in-panel">
<object class="GtkLabel" id="label-units">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Position in Panel</property>
<property name="label" translatable="yes">Temperature Unit</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-wind-direction">
<object class="GtkLabel" id="label-wind-speed-unit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Wind Direction by Arrows</property>
<property name="label" translatable="yes">Wind Speed Unit</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-translate-condition">
<object class="GtkLabel" id="label-pressure-unit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Translate Conditions</property>
<property name="label" translatable="yes">Pressure Unit</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-icon-type">
<object class="GtkComboBoxText" id="units">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Symbolic Icons</property>
<items>
<item>°C</item>
<item>°F</item>
<item>K</item>
<item>°Ra</item>
<item>°Ré</item>
<item>°Rø</item>
<item>°De</item>
<item>°N</item>
</items>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">7</property>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-use-text-on-buttons">
<object class="GtkComboBoxText" id="wind_speed_unit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Text on buttons</property>
<items>
<item>km/h</item>
<item>mph</item>
<item>m/s</item>
<item>kn</item>
<item>ft/s</item>
<item>Beaufort</item>
</items>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">8</property>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-text-in-panel">
<object class="GtkComboBoxText" id="pressure_unit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Temperature in Panel</property>
<items>
<item>hPa</item>
<item>inHg</item>
<item>bar</item>
<item>Pa</item>
<item>kPa</item>
<item>atm</item>
<item>at</item>
<item>Torr</item>
<item>psi</item>
</items>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">9</property>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="units-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Units</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="layout-grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">10</property>
<property name="row_spacing">5</property>
<property name="column_spacing">5</property>
<child>
<object class="GtkLabel" id="label-comment-in-panel">
<object class="GtkLabel" id="label-position-in-panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Conditions in Panel</property>
<property name="label" translatable="yes">Position in Panel</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">10</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-comment-in-forecast">
<object class="GtkLabel" id="label-wind-direction">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Conditions in Forecast</property>
<property name="label" translatable="yes">Wind Direction by Arrows</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">11</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-center-in-forecast">
<object class="GtkLabel" id="label-translate-condition">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Center forecast</property>
<property name="label" translatable="yes">Translate Conditions</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">12</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-days-forecast">
<object class="GtkLabel" id="label-icon-type">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Number of days in forecast</property>
<property name="label" translatable="yes">Symbolic Icons</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">13</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-decimal-places">
<object class="GtkLabel" id="label-use-text-on-buttons">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Maximal number of digits after the decimal point</property>
<property name="label" translatable="yes">Text on buttons</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">14</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-appid">
<object class="GtkLabel" id="label-text-in-panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Personal Api key from openweathermap.org</property>
<property name="label" translatable="yes">Temperature in Panel</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">15</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-appid-fc">
<object class="GtkLabel" id="label-comment-in-panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Personal Api key from forecast.io</property>
<property name="label" translatable="yes">Conditions in Panel</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">16</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="weather_provider">
<object class="GtkLabel" id="label-comment-in-forecast">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item>http://openweathermap.org</item>
<item>http://forecast.io</item>
</items>
<property name="label" translatable="yes">Conditions in Forecast</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="left_attach">0</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="units">
<object class="GtkLabel" id="label-center-in-forecast">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item>°C</item>
<item>°F</item>
<item>K</item>
<item>°Ra</item>
<item>°Ré</item>
<item>°Rø</item>
<item>°De</item>
<item>°N</item>
</items>
<property name="label" translatable="yes">Center forecast</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="left_attach">0</property>
<property name="top_attach">8</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="wind_speed_unit">
<object class="GtkLabel" id="label-days-forecast">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item>km/h</item>
<item>mph</item>
<item>m/s</item>
<item>kn</item>
<item>ft/s</item>
<item>Beaufort</item>
</items>
<property name="label" translatable="yes">Number of days in forecast</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="left_attach">0</property>
<property name="top_attach">9</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="pressure_unit">
<object class="GtkLabel" id="label-decimal-places">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item>hPa</item>
<item>inHg</item>
<item>bar</item>
<item>Pa</item>
<item>kPa</item>
<item>atm</item>
<item>at</item>
<item>Torr</item>
<item>psi</item>
</items>
<property name="label" translatable="yes">Maximal number of digits after the decimal point</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="left_attach">0</property>
<property name="top_attach">10</property>
</packing>
</child>
<child>
@ -685,7 +804,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
@ -696,7 +815,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
@ -707,7 +826,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
@ -718,7 +837,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">7</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
@ -729,7 +848,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">8</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
@ -740,7 +859,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">9</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
@ -751,7 +870,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">10</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
@ -762,7 +881,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">11</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
@ -773,7 +892,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">12</property>
<property name="top_attach">8</property>
</packing>
</child>
<child>
@ -794,7 +913,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">13</property>
<property name="top_attach">9</property>
</packing>
</child>
<child>
@ -810,38 +929,23 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">14</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="appid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">32</property>
<property name="width_chars">32</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">15</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="appid_fc">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_tooltip">True</property>
<property name="width_chars">32</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">16</property>
<property name="top_attach">10</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">3</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="layout-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Layout</property>
</object>
<packing>
<property name="position">3</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>

@ -83,6 +83,7 @@ const OPENWEATHER_FC_API_KEY = 'appid-fc';
// Keep enums in sync with GSettings schemas
const WeatherProvider = {
DEFAULT: -1,
OPENWEATHERMAP: 0,
FORECAST_IO: 1
};
@ -351,11 +352,11 @@ const OpenweatherMenuButton = new Lang.Class({
this._settings = Convenience.getSettings(OPENWEATHER_SETTINGS_SCHEMA);
if (this._cities.length === 0)
this._cities = "-8.5211767,179.1976747>Vaiaku, Tuvalu";
this._cities = "-8.5211767,179.1976747>Vaiaku, Tuvalu>-1";
this._settingsC = this._settings.connect("changed", Lang.bind(this, function() {
if (this._cities.length === 0)
this._cities = "-8.5211767,179.1976747>Vaiaku, Tuvalu";
this._cities = "-8.5211767,179.1976747>Vaiaku, Tuvalu>-1";
this.rebuildCurrentWeatherUi();
this.rebuildFutureWeatherUi();
if (this.providerChanged()) {
@ -433,13 +434,13 @@ const OpenweatherMenuButton = new Lang.Class({
get _weather_provider() {
if (!this._settings)
this.loadConfig();
return this._settings.get_enum(OPENWEATHER_PROVIDER_KEY);
},
set _weather_provider(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_enum(OPENWEATHER_PROVIDER_KEY, v);
let provider = this.extractProvider(this._city);
if (provider == WeatherProvider.DEFAULT)
provider = this._settings.get_enum(OPENWEATHER_PROVIDER_KEY);
return provider;
},
get _units() {
@ -448,60 +449,30 @@ const OpenweatherMenuButton = new Lang.Class({
return this._settings.get_enum(OPENWEATHER_UNIT_KEY);
},
set _units(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_enum(OPENWEATHER_UNIT_KEY, v);
},
get _wind_speed_units() {
if (!this._settings)
this.loadConfig();
return this._settings.get_enum(OPENWEATHER_WIND_SPEED_UNIT_KEY);
},
set _wind_speed_units(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_enum(OPENWEATHER_WIND_SPEED_UNIT_KEY, v);
},
get _wind_direction() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(OPENWEATHER_WIND_DIRECTION_KEY);
},
set _wind_direction(v) {
if (!this._settings)
this.loadConfig();
return this._settings.set_boolean(OPENWEATHER_WIND_DIRECTION_KEY, v);
},
get _pressure_units() {
if (!this._settings)
this.loadConfig();
return this._settings.get_enum(OPENWEATHER_PRESSURE_UNIT_KEY);
},
set _pressure_units(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_enum(OPENWEATHER_PRESSURE_UNIT_KEY, v);
},
get _cities() {
if (!this._settings)
this.loadConfig();
return this._settings.get_string(OPENWEATHER_CITY_KEY);
},
set _cities(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_string(OPENWEATHER_CITY_KEY, v);
},
get _actual_city() {
if (!this._settings)
this.loadConfig();
@ -559,104 +530,48 @@ const OpenweatherMenuButton = new Lang.Class({
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(OPENWEATHER_TRANSLATE_CONDITION_KEY);
},
set _translate_condition(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(OPENWEATHER_TRANSLATE_CONDITION_KEY, v);
},
get _getIconType() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(OPENWEATHER_USE_SYMBOLIC_ICONS_KEY) ? 1 : 0;
},
set _getIconType(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(OPENWEATHER_USE_SYMBOLIC_ICONS_KEY, v);
},
get _use_text_on_buttons() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(OPENWEATHER_USE_TEXT_ON_BUTTONS_KEY) ? 1 : 0;
},
set _use_text_on_buttons(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(OPENWEATHER_USE_TEXT_ON_BUTTONS_KEY, v);
},
get _text_in_panel() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(OPENWEATHER_SHOW_TEXT_IN_PANEL_KEY);
},
set _text_in_panel(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(OPENWEATHER_SHOW_TEXT_IN_PANEL_KEY, v);
},
get _position_in_panel() {
if (!this._settings)
this.loadConfig();
return this._settings.get_enum(OPENWEATHER_POSITION_IN_PANEL_KEY);
},
set _position_in_panel(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_enum(OPENWEATHER_POSITION_IN_PANEL_KEY, v);
},
get _comment_in_panel() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(OPENWEATHER_SHOW_COMMENT_IN_PANEL_KEY);
},
set _comment_in_panel(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(OPENWEATHER_SHOW_COMMENT_IN_PANEL_KEY, v);
},
get _comment_in_forecast() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(OPENWEATHER_SHOW_COMMENT_IN_FORECAST_KEY);
},
set _comment_in_forecast(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(OPENWEATHER_SHOW_COMMENT_IN_FORECAST_KEY, v);
},
get _refresh_interval_current() {
if (!this._settings)
this.loadConfig();
@ -664,12 +579,6 @@ const OpenweatherMenuButton = new Lang.Class({
return ((v >= 600) ? v : 600);
},
set _refresh_interval_current(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_int(OPENWEATHER_REFRESH_INTERVAL_CURRENT, ((v >= 600) ? v : 600));
},
get _refresh_interval_forecast() {
if (!this._settings)
this.loadConfig();
@ -677,48 +586,24 @@ const OpenweatherMenuButton = new Lang.Class({
return ((v >= 600) ? v : 600);
},
set _refresh_interval_forecast(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_int(OPENWEATHER_REFRESH_INTERVAL_FORECAST, ((v >= 600) ? v : 600));
},
get _center_forecast() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(OPENWEATHER_CENTER_FORECAST_KEY);
},
set _center_forecast(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_boolean(OPENWEATHER_CENTER_FORECAST_KEY, v);
},
get _days_forecast() {
if (!this._settings)
this.loadConfig();
return this._settings.get_int(OPENWEATHER_DAYS_FORECAST);
},
set _days_forecast(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_int(OPENWEATHER_DAYS_FORECAST, v);
},
get _decimal_places() {
if (!this._settings)
this.loadConfig();
return this._settings.get_int(OPENWEATHER_DECIMAL_PLACES);
},
set _decimal_places(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_int(OPENWEATHER_DECIMAL_PLACES, v);
},
get _appid() {
if (!this._settings)
this.loadConfig();
@ -726,12 +611,6 @@ const OpenweatherMenuButton = new Lang.Class({
return (key.length == 32) ? key : '';
},
set _appid(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_string(OPENWEATHER_OWM_API_KEY, v);
},
get _appid_fc() {
if (!this._settings)
this.loadConfig();
@ -739,12 +618,6 @@ const OpenweatherMenuButton = new Lang.Class({
return (key.length == 32) ? key : '';
},
set _appid_fc(v) {
if (!this._settings)
this.loadConfig();
this._settings.set_string(OPENWEATHER_FC_API_KEY, v);
},
rebuildButtonMenu: function() {
if (this._buttonBox) {
if (this._buttonBox1) {
@ -870,15 +743,6 @@ const OpenweatherMenuButton = new Lang.Class({
return arguments[0].split(">")[1];
},
extractCity: function() {
if (!arguments[0])
return "";
let city = this.extractLocation(arguments[0]);
if (city.indexOf("(") == -1)
return _("Invalid city");
return city.split("(")[0].trim();
},
extractCoord: function() {
let coords = 0;
@ -893,6 +757,16 @@ const OpenweatherMenuButton = new Lang.Class({
return coords;
},
extractProvider: function() {
if (!arguments[0])
return -1;
if (arguments[0].split(">")[2] === undefined)
return -1;
if (isNaN(parseInt(arguments[0].split(">")[2])))
return -1;
return parseInt(arguments[0].split(">")[2]);
},
_onPreferencesActivate: function() {
this.menu.actor.hide();
Util.spawn(["gnome-shell-extension-prefs", "openweather-extension@jenslody.de"]);

@ -69,13 +69,19 @@ const OPENWEATHER_URL_BASE = 'https://open.mapquestapi.com/nominatim/v1/';
const OPENWEATHER_URL_FIND = OPENWEATHER_URL_BASE + 'search.php';
const OPENWEATHER_URL_REVERSE = OPENWEATHER_URL_BASE + 'reverse.php';
const WeatherProvider = {
DEFAULT: -1,
OPENWEATHERMAP: 0,
FORECAST_IO: 1
};
let _httpSession;
let mCities = null;
let inRealize = false;
let defaultSize = [-1,-1];
let defaultSize = [-1, -1];
const WeatherPrefsWidget = new GObject.Class({
Name: 'OpenWeatherExtension.Prefs.Widget',
@ -100,7 +106,7 @@ const WeatherPrefsWidget = new GObject.Class({
this.add(this.MainWidget);
this.MainWidget.connect('realize', Lang.bind(this, function() {
if ( inRealize )
if (inRealize)
return;
inRealize = true;
@ -123,9 +129,11 @@ const WeatherPrefsWidget = new GObject.Class({
this.editWidget = this.Window.get_object("edit-widget");
this.editName = this.Window.get_object("edit-name");
this.editCoord = this.Window.get_object("edit-coord");
this.editCombo = this.Window.get_object("edit-combo");
this.searchWidget = this.Window.get_object("search-widget");
this.searchMenu = this.Window.get_object("search-menu");
this.searchName = this.Window.get_object("search-name");
this.searchCombo = this.Window.get_object("search-combo");
this.spinner = this.Window.get_object("spinner");
this.searchName.connect("icon-release", Lang.bind(this, this.clearEntry));
@ -182,15 +190,12 @@ const WeatherPrefsWidget = new GObject.Class({
let newCity = arguments[0];
if (Number(newCity.length) < 1)
{
if (Number(newCity.length) < 1) {
let item = new Gtk.MenuItem({
label: _("\"%s\" not found").format(location)
});
this.searchMenu.append(item);
}
else
{
} else {
var m = {};
for (var i in newCity) {
@ -212,6 +217,7 @@ const WeatherPrefsWidget = new GObject.Class({
}));
let column = new Gtk.TreeViewColumn();
column.set_title(_("Location"));
this.treeview.append_column(column);
let renderer = new Gtk.CellRendererText();
@ -220,6 +226,15 @@ const WeatherPrefsWidget = new GObject.Class({
column.set_cell_data_func(renderer, function() {
arguments[1].markup = arguments[2].get_value(arguments[3], 0);
});
column = new Gtk.TreeViewColumn();
column.set_title(_("Provider"));
this.treeview.append_column(column);
column.pack_start(renderer, null);
column.set_cell_data_func(renderer, function() {
arguments[1].markup = arguments[2].get_value(arguments[3], 1);
});
let theObjects = this.Window.get_objects();
@ -311,6 +326,7 @@ const WeatherPrefsWidget = new GObject.Class({
for (let i in city) {
current = this.liststore.append();
this.liststore.set_value(current, 0, this.extractLocation(city[i]));
this.liststore.set_value(current, 1, this.getProviderShort(this.extractProvider(city[i])));
}
}
@ -396,18 +412,20 @@ const WeatherPrefsWidget = new GObject.Class({
let ac = this.actual_city;
this.editName.set_text(this.extractLocation(city[ac]));
this.editCoord.set_text(this.extractCoord(city[ac]));
this.editCombo.set_active(this.extractProvider(city[ac]) + 1);
this.editWidget.show_all();
return 0;
},
searchSave: function() {
let cityText = this.searchName.get_text().split(/\[/)[0];
let location = this.searchName.get_text().split(/\[/)[0];
let coord = this.searchName.get_text().split(/\[/)[1].split(/\]/)[0];
let provider = this.searchCombo.get_active() - 1;
if (this.city)
this.city = this.city + " && " + coord + ">" + cityText;
this.city = this.city + " && " + coord + ">" + location + ">" + provider;
else
this.city = coord + ">" + cityText;
this.city = coord + ">" + location + ">" + provider;
this.searchWidget.hide();
return 0;
@ -424,7 +442,8 @@ const WeatherPrefsWidget = new GObject.Class({
let ac = this.actual_city;
let location = this.editName.get_text();
let coord = this.editCoord.get_text();
theCity[ac] = coord + ">" + location;
let provider = this.editCombo.get_active() - 1;
theCity[ac] = coord + ">" + location + ">" + provider;
if (theCity.length > 1)
this.city = theCity.join(" && ");
@ -782,16 +801,48 @@ const WeatherPrefsWidget = new GObject.Class({
this.Settings.set_string(OPENWEATHER_FC_API_KEY, v);
},
extractLocation: function(a) {
if (a.search(">") == -1)
extractLocation: function() {
if (!arguments[0])
return "";
if (arguments[0].search(">") == -1)
return _("Invalid city");
return a.split(">")[1];
return arguments[0].split(">")[1];
},
extractCoord: function(a) {
if (a.search(">") == -1)
extractCoord: function() {
if (!arguments[0])
return 0;
return a.split(">")[0];
if (arguments[0].search(">") == -1)
return 0;
return arguments[0].split(">")[0];
},
extractProvider: function() {
if (!arguments[0])
return -1;
if (arguments[0].split(">")[2] === undefined)
return -1;
if (isNaN(parseInt(arguments[0].split(">")[2])))
return -1;
return parseInt(arguments[0].split(">")[2]);
},
getProviderShort: function() {
let provider = arguments[0];
if ( provider === undefined)
provider = this.extractProvider(this.city[this.actual_city]);
switch (provider) {
case WeatherProvider.OPENWEATHERMAP:
return "openweathermap.org";
case WeatherProvider.FORECAST_IO:
return "forecast.io";
default:
case WeatherProvider.DEFAULT:
return _("default");
}
}
});

Loading…
Cancel
Save