Use ui-file for prefs-dialog, remove most of the now obsolete-code.

multiprovider
None 10 years ago
parent f05128700d
commit a233741755
  1. 713
      data/weather-settings.ui
  2. 287
      src/prefs.js

@ -1,8 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkListStore" id="liststore">
<requires lib="gtk+" version="3.10"/>
<object class="GtkBox" id="search-widget">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Search by (or edit) name</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="search-name">
<property name="width_request">350</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="secondary_icon_name">edit-clear-symbolic</property>
<property name="primary_icon_tooltip_text" translatable="yes">Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/</property>
<property name="secondary_icon_tooltip_text" translatable="yes">Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/</property>
<property name="primary_icon_tooltip_markup" translatable="yes">Click here to search the coordinates for the entered location on https://open.mapquestapi.com/nominatim/</property>
<property name="secondary_icon_tooltip_markup" translatable="yes">Click here to search the locatopn for the entered coordinates on https://open.mapquestapi.com/nominatim/</property>
<property name="placeholder_text" translatable="yes">e.g. Te Auala o Tuvalu, Funafuti, Tuvalu</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Search by (or edit) coordinates</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="search-coordinate">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="secondary_icon_name">edit-clear-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<property name="placeholder_text" translatable="yes">e.g. -8.5202006,179.1976286</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkSeparator" id="separator1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">baseline</property>
<property name="vexpand">False</property>
<child>
<object class="GtkButton" id="button-cancel">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
<property name="use_stock">True</property>
<property name="xalign">0.46000000834465027</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkButton" id="button-save">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">6</property>
</packing>
</child>
</object>
<object class="GtkListStore" id="tree-liststore">
<columns>
<!-- column-name text -->
<column type="gchararray"/>
@ -15,13 +148,13 @@
</object>
<object class="GtkBox" id="main-widget">
<property name="can_focus">False</property>
<property name="border_width">14</property>
<property name="margin_bottom">10</property>
<property name="border_width">10</property>
<child>
<object class="GtkTable" id="left-widget">
<object class="GtkBox" id="box-left">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">2</property>
<property name="column_spacing">6</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="tree-scrolledwindow">
<property name="visible">True</property>
@ -33,6 +166,7 @@
<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="show_expanders">False</property>
<property name="level_indentation">12</property>
@ -43,7 +177,9 @@
</child>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
@ -57,7 +193,7 @@
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-add-symbolic</property>
<property name="stock_id">gtk-add</property>
</object>
<packing>
<property name="expand">False</property>
@ -69,22 +205,30 @@
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-remove-symbolic</property>
<property name="stock_id">gtk-delete</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="tree-toolbutton-edit">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock_id">gtk-edit</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<style>
<class name="inline-toolbar"/>
</style>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_SHRINK</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
@ -95,131 +239,440 @@
</packing>
</child>
<child>
<object class="GtkBox" id="right-widget">
<object class="GtkGrid" id="grid4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<property name="margin_left">10</property>
<property name="row_spacing">5</property>
<property name="column_spacing">5</property>
<property name="row_homogeneous">True</property>
<child>
<object class="GtkTable" id="right-widget-table">
<object class="GtkLabel" id="label-weather-provider">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">36</property>
<property name="n_rows">17</property>
<property name="n_columns">2</property>
<property name="column_spacing">36</property>
<property name="row_spacing">12</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<property name="label" translatable="yes">Choose weather provider</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-units">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Temperature Unit</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<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 Speed Unit</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-pressure-unit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Pressure Unit</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-position-in-panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Position in Panel</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-wind-direction">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Wind Direction by Arrows</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-translate-condition">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Translate Conditions</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-icon-type">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Symbolic Icons</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
<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">Text on buttons</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">8</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-text-in-panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Temperature in Panel</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">9</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-comment-in-panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Conditions in Panel</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">10</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-comment-in-forecast">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Conditions in Forecast</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">11</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-center-in-forecast">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Center forecast</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">12</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-days-forecast">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Number of days in forecast</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">13</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-decimal-places">
<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>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">14</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-appid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Personal Api key from openweathermap.org</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">15</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-appid-fc">
<property name="visible">True</property>
<property name="can_focus">False</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">16</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="weather_provider">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item>http://openweathermap.org</item>
<item>http://forecast.io</item>
</items>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="units">
<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>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="wind_speed_unit">
<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>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="pressure_unit">
<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>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="position_in_panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item translatable="yes">Center</item>
<item translatable="yes">Right</item>
<item translatable="yes">Left</item>
</items>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="wind_direction">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="translate_conditions">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="icon_type">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="use_text_on_buttons">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">8</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="text_in_panel">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">9</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="comment_in_panel">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">10</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="comment_in_forecast">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">11</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="center_forecast">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">12</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="days_forecast">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
</items>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">13</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="decimal_places">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</items>
</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>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>

@ -101,7 +101,8 @@ const WeatherPrefsWidget = new GObject.Class({
this.MainWidget = this.Window.get_object("main-widget");
this.treeview = this.Window.get_object("tree-treeview");
this.liststore = this.Window.get_object("liststore");
// this.liststore = this.Window.get_object("treestore");
this.liststore = this.Window.get_object("tree-liststore");
this.Iter = this.liststore.get_iter_first();
this.Window.get_object("tree-toolbutton-add").connect("clicked", Lang.bind(this, function() {
@ -112,11 +113,17 @@ const WeatherPrefsWidget = new GObject.Class({
this.removeCity();
}));
this.Window.get_object("tree-toolbutton-edit").connect("clicked", Lang.bind(this, function() {
this.editCity();
}));
this.Window.get_object("treeview-selection").connect("changed", Lang.bind(this, function(selection) {
this.selectionChanged(selection);
}));
this.treeview.set_model(this.liststore);
// this.treeview.set_model(this.liststore);
let column = new Gtk.TreeViewColumn();
this.treeview.append_column(column);
@ -128,49 +135,43 @@ const WeatherPrefsWidget = new GObject.Class({
arguments[1].markup = arguments[2].get_value(arguments[3], 0);
});
this.initConfigWidget();
this.addLabel(_("Choose weather provider"));
this.addComboBox(["http://openweathermap.org", "http://forecast.io"], "weather_provider");
this.addLabel(_("Temperature Unit"));
this.addComboBox(["\u00b0C", "\u00b0F", "K", "\u00b0Ra", "\u00b0R\u00E9", "\u00b0R\u00F8", "\u00b0De", "\u00b0N"], "units");
this.addLabel(_("Wind Speed Unit"));
this.addComboBox(["km/h", "mph", "m/s", "kn", "ft/s", "Beaufort"], "wind_speed_unit");
this.addLabel(_("Pressure Unit"));
this.addComboBox(["hPa", "inHg", "bar", "Pa", "kPa", "atm", "at", "Torr", "psi"], "pressure_unit");
this.addLabel(_("Position in Panel"));
this.addComboBox([_("Center"), _("Right"), _("Left")], "position_in_panel");
this.addLabel(_("Wind Direction by Arrows"));
this.addSwitch("wind_direction");
this.addLabel(_("Translate Conditions"));
this.addSwitch("translate_condition");
this.addLabel(_("Symbolic Icons"));
this.addSwitch("icon_type");
this.addLabel(_("Text on buttons"));
this.addSwitch("use_text_on_buttons");
this.addLabel(_("Temperature in Panel"));
this.addSwitch("text_in_panel");
this.addLabel(_("Conditions in Panel"));
this.addSwitch("comment_in_panel");
this.addLabel(_("Conditions in Forecast"));
this.addSwitch("comment_in_forecast");
this.addLabel(_("Center forecast"));
this.addSwitch("center_forecast");
this.addLabel(_("Number of days in forecast"));
this.addComboBox(["2", "3", "4", "5", "6", "7", "8", "9", "10"], "days_forecast");
this.addLabel(_("Maximal number of digits after the decimal point"));
this.addComboBox(["0", "1", "2", "3"], "decimal_places");
this.addLabel(_("Personal Api key from openweathermap.org"));
this.addAppidEntry(("appid"));
this.addLabel(_("Personal Api key from forecast.io"));
this.addAppidEntry(("appid_fc"));
let theObjects = this.Window.get_objects();
for (let i in theObjects) {
let name = theObjects[i].get_name ? theObjects[i].get_name() : 'dummy';
if (this[name] !== undefined) {
let theObject = theObjects[i];
if (theObject.class_path()[1].indexOf('GtkEntry') != -1) {
theObject.text = this[name];
if (this[name].length != 32)
theObject.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning');
theObject.connect("notify::text", Lang.bind(this, function() {
let key = arguments[0].text;
this[name] = key;
if (key.length == 32)
theObject.set_icon_from_icon_name(Gtk.PositionType.LEFT, '');
else
theObject.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning');
}));
}
if (theObject.class_path()[1].indexOf('GtkComboBoxText') != -1) {
theObject.connect("changed", Lang.bind(this, function() {
this[name] = arguments[0].active;
}));
}
if (theObject.class_path()[1].indexOf('GtkSwitch') != -1) {
theObject.connect("notify::active", Lang.bind(this, function() {
this[name] = arguments[0].active;
}));
}
this.configWidgets.push([theObjects[i], name]);
}
}
},
refreshUI: function() {
this.MainWidget = this.Window.get_object("main-widget");
this.treeview = this.Window.get_object("tree-treeview");
this.liststore = this.Window.get_object("liststore");
this.Iter = this.liststore.get_iter_first();
this.Window.get_object("tree-toolbutton-remove").sensitive = Boolean(this.city.length);
if (mCities != this.city) {
@ -197,109 +198,13 @@ const WeatherPrefsWidget = new GObject.Class({
this.changeSelection();
let config = this.configWidgets;
for (let i in config)
for (let i in config) {
if (config[i][0].active != this[config[i][1]])
config[i][0].active = this[config[i][1]];
},
initConfigWidget: function() {
this.inc(1);
let a = this.Window.get_object("right-widget-table");
a.visible = 1;
a.can_focus = 0;
this.right_widget = a;
},
x: [0, 1],
y: [0, 1],
configWidgets: [],
inc: function() {
if (arguments[0]) {
this.x[0] = 0;
this.x[1] = 1;
this.y[0] = 0;
this.y[1] = 1;
return 0;
}
if (this.x[0] == 1) {
this.x[0] = 0;
this.x[1] = 1;
this.y[0] += 1;
this.y[1] += 1;
return 0;
} else {
this.x[0] += 1;
this.x[1] += 1;
return 0;
}
},
addLabel: function(text) {
let l = new Gtk.Label({
label: text,
xalign: 0
});
l.visible = 1;
l.can_focus = 0;
this.right_widget.attach(l, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0);
this.inc();
},
addComboBox: function(a, b) {
let cf = new Gtk.ComboBoxText();
this.configWidgets.push([cf, b]);
cf.visible = 1;
cf.can_focus = 0;
cf.width_request = 100;
for (let i in a)
cf.append_text(a[i]);
cf.active = this[b];
cf.connect("changed", Lang.bind(this, function() {
this[b] = arguments[0].active;
}));
this.right_widget.attach(cf, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0);
this.inc();
},
addSwitch: function(a) {
let sw = new Gtk.Switch();
this.configWidgets.push([sw, a]);
sw.visible = 1;
sw.can_focus = 0;
sw.active = this[a];
sw.connect("notify::active", Lang.bind(this, function() {
this[a] = arguments[0].active;
}));
this.right_widget.attach(sw, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0);
this.inc();
},
addAppidEntry: function(a) {
let en = new Gtk.Entry();
this.configWidgets.push([en, a]);
en.visible = 1;
en.can_focus = 1;
en.set_width_chars(32);
en.text = this[a];
if (this[a].length != 32)
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning');
en.connect("notify::text", Lang.bind(this, function() {
let key = arguments[0].text;
let rgba = new Gdk.Color();
this[a] = key;
if (key.length == 32)
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, '');
else
en.set_icon_from_icon_name(Gtk.PositionType.LEFT, 'dialog-warning');
}));
this.right_widget.attach(en, this.x[0], this.x[1], this.y[0], this.y[1], 0, 0, 0, 0);
this.inc();
},
configWidgets: [],
selectionChanged: function(select) {
let a = select.get_selected_rows(this.liststore)[0][0];
@ -352,31 +257,13 @@ const WeatherPrefsWidget = new GObject.Class({
entry.activates_default = true;
let testLocation = Lang.bind(this, function(location) {
log(new Error().lineNumber + ' : location = ' + location);
if (location.search(/\[/) == -1 || location.search(/\]/) == -1)
return 0;
let coord = location.split(/\[/)[1].split(/\]/)[0];
if (!coord)
return 0;
log(new Error().lineNumber + ' : coord = ' + coord);
this.loadJsonAsync(WEATHER_URL_REVERSE, {
lat: coord.split(/,/)[0],
lon: coord.split(/,/)[1]
}, function() {
d.sensitive = 0;
if (arguments[0] === undefined)
return 0;
let city = arguments[0];
if (Number(city.length) < 1)
return 0;
d.sensitive = 1;
return 0;
}, "testLocation");
d.sensitive = 1;
return 0;
});
@ -390,7 +277,6 @@ const WeatherPrefsWidget = new GObject.Class({
Lang.bind(
this,
function() {
let location = entry.get_text();
let params = {
format: 'json',
@ -402,9 +288,9 @@ const WeatherPrefsWidget = new GObject.Class({
this.loadJsonAsync(WEATHER_URL_FIND, params, function() {
if (!arguments[0])
return 0;
let city = arguments[0];
let newCity = arguments[0];
if (Number(city.length) < 1)
if (Number(newCity.length) < 1)
return 0;
completionModel.clear();
@ -412,12 +298,11 @@ const WeatherPrefsWidget = new GObject.Class({
let current = this.liststore.get_iter_first();
var m = {};
for (var i in city) {
for (var i in newCity) {
current = completionModel.append();
let cityText = city[i].display_name;
let cityCoord = "[" + city[i].lat + "," + city[i].lon + "]";
let cityText = newCity[i].display_name;
let cityCoord = "[" + newCity[i].lat + "," + newCity[i].lon + "]";
if (m[cityCoord])
continue;
@ -426,7 +311,6 @@ const WeatherPrefsWidget = new GObject.Class({
completionModel.set_value(current, 0, cityText + " " + cityCoord);
}
completion.complete();
return 0;
}, "getInfo");
@ -454,34 +338,75 @@ const WeatherPrefsWidget = new GObject.Class({
lat: coord.split(/,/)[0],
lon: coord.split(/,/)[1]
};
this.loadJsonAsync(WEATHER_URL_REVERSE, params, Lang.bind(this, function() {
if (!arguments[0])
return 0;
let city = arguments[0];
if (Number(city.length) < 1)
return 0;
let cityText = entry.get_text().split(/\[/)[0];
if (this.city)
this.city = this.city + " && " + coord + ">" + cityText;
else
this.city = coord + ">" + cityText;
}
dialog.hide();
return 0;
}));
dialog.show_all();
},
removeCity: function() {
let city = this.city.split(" && ");
if (!city.length)
return 0;
let ac = this.actual_city;
let textDialog = _("Remove %s ?").format(this.extractLocation(city[ac]));
let dialog = new Gtk.Dialog({
title: ""
});
let label = new Gtk.Label({
label: textDialog
});
label.margin_bottom = 12;
dialog.set_border_width(12);
dialog.set_modal(1);
dialog.set_resizable(0);
//dialog.set_transient_for(***** Need parent Window *****);
let cityText = entry.get_text().split(/\[/)[0];
dialog.add_button(Gtk.STOCK_NO, 0);
let d = dialog.add_button(Gtk.STOCK_YES, 1);
d.set_can_default(true);
dialog.set_default(d);
let dialog_area = dialog.get_content_area();
dialog_area.pack_start(label, 0, 0, 0);
dialog.connect("response", Lang.bind(this, function(w, response_id) {
if (response_id) {
if (city.length === 0)
city = [];
if (this.city)
this.city = this.city + " && " + coord + ">" + cityText;
else
this.city = coord + ">" + cityText;
if (city.length > 0 && typeof city != "object")
city = [city];
return 0;
}), "lastTest");
if (city.length > 0)
city.splice(ac, 1);
if (city.length > 1)
this.city = city.join(" && ");
else if (city[0])
this.city = city[0];
else
this.city = "";
}
dialog.hide();
return 0;
}));
dialog.show_all();
return 0;
},
removeCity: function() {
editCity: function() {
let city = this.city.split(" && ");
if (!city.length)
return 0;

Loading…
Cancel
Save