[gnome-weather] Add a preference dialog for configuring units of measure



commit 2a7415ac1306d1390560e3fbcdd1f6376ef0affb
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sat Mar 16 01:47:40 2013 +0100

    Add a preference dialog for configuring units of measure
    
    Mostly for temperature (which is the only one we use in gnome-weather
    right now), but includes all the units libgweather knows about.
    And the dialog was made in Glade!
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695762

 data/app-menu.ui                 |    4 +
 data/gnome-weather.gresource.xml |    1 +
 data/preferences.ui              |  297 ++++++++++++++++++++++++++++++++++++++
 src/window.js                    |   26 ++++
 4 files changed, 328 insertions(+), 0 deletions(-)
---
diff --git a/data/app-menu.ui b/data/app-menu.ui
index 42a16a4..725bf2e 100644
--- a/data/app-menu.ui
+++ b/data/app-menu.ui
@@ -7,6 +7,10 @@
         <attribute name="accel">&lt;Primary&gt;n</attribute>
       </item>
       <item>
+        <attribute name="label" translatable="yes">_Preferences</attribute>
+        <attribute name="action">win.preferences</attribute>
+      </item>
+      <item>
         <attribute name="action">win.about</attribute>
         <attribute name="label" translatable="yes">About Weather</attribute>
       </item>
diff --git a/data/gnome-weather.gresource.xml b/data/gnome-weather.gresource.xml
index 61f405e..d080d36 100644
--- a/data/gnome-weather.gresource.xml
+++ b/data/gnome-weather.gresource.xml
@@ -4,6 +4,7 @@
     <file preprocess="xml-stripblanks">app-menu.ui</file>
     <file preprocess="xml-stripblanks">window.ui</file>
     <file preprocess="xml-stripblanks">new-location-dialog.ui</file>
+    <file preprocess="xml-stripblanks">preferences.ui</file>
     <file>application.css</file>
     <file>weather-clear.jpg</file>
     <file>weather-clear-night.jpg</file>
diff --git a/data/preferences.ui b/data/preferences.ui
new file mode 100644
index 0000000..8ed830c
--- /dev/null
+++ b/data/preferences.ui
@@ -0,0 +1,297 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.6 -->
+  <object class="GtkListStore" id="distance-store">
+    <columns>
+      <!-- column-name value -->
+      <column type="gchararray"/>
+      <!-- column-name description -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0">meters</col>
+        <col id="1" translatable="yes">Meters (m)</col>
+      </row>
+      <row>
+        <col id="0">km</col>
+        <col id="1" translatable="yes">Kilometers (km)</col>
+      </row>
+      <row>
+        <col id="0">miles</col>
+        <col id="1" translatable="yes">Miles (mi)</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkDialog" id="preferences-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Preferences</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">6</property>
+            <property name="margin_right">6</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">12</property>
+            <child>
+              <object class="GtkLabel" id="temp-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Temperature unit:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="speed-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Speed unit:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="distance-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Distance unit:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="pressure-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Pressure unit:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="temp-combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="model">temp-store</property>
+                <property name="id_column">0</property>
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext1"/>
+                  <attributes>
+                    <attribute name="text">1</attribute>
+                  </attributes>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="speed-combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="model">speed-store</property>
+                <property name="id_column">0</property>
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext2"/>
+                  <attributes>
+                    <attribute name="text">1</attribute>
+                  </attributes>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="distance-combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="model">distance-store</property>
+                <property name="id_column">0</property>
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext3"/>
+                  <attributes>
+                    <attribute name="text">1</attribute>
+                  </attributes>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">2</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="pressure-combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="model">pressure-store</property>
+                <property name="id_column">0</property>
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext4"/>
+                  <attributes>
+                    <attribute name="text">1</attribute>
+                  </attributes>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">3</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkListStore" id="pressure-store">
+    <columns>
+      <!-- column-name value -->
+      <column type="gchararray"/>
+      <!-- column-name description -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0">kpa</col>
+        <col id="1" translatable="yes">Kilopascal (kPa)</col>
+      </row>
+      <row>
+        <col id="0">hpa</col>
+        <col id="1" translatable="yes">Hectopascal (hPa)</col>
+      </row>
+      <row>
+        <col id="0">mb</col>
+        <col id="1" translatable="yes">Millibar (mbar)</col>
+      </row>
+      <row>
+        <col id="0">mm-hg</col>
+        <col id="1" translatable="yes">Millimeters of mercury (mmHg)</col>
+      </row>
+      <row>
+        <col id="0">inch-hg</col>
+        <col id="1" translatable="yes">Inches of mercury (inchHg)</col>
+      </row>
+      <row>
+        <col id="0">atm</col>
+        <col id="1" translatable="yes">Atmosphere (atm)</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="speed-store">
+    <columns>
+      <!-- column-name value -->
+      <column type="gchararray"/>
+      <!-- column-name description -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0">ms</col>
+        <col id="1" translatable="yes">Meters per second (m/s)</col>
+      </row>
+      <row>
+        <col id="0">kph</col>
+        <col id="1" translatable="yes">Kilometers per hour (km/h)</col>
+      </row>
+      <row>
+        <col id="0">mph</col>
+        <col id="1" translatable="yes">Miles per hour (mph)</col>
+      </row>
+      <row>
+        <col id="0">knots</col>
+        <col id="1" translatable="yes">Knots</col>
+      </row>
+      <row>
+        <col id="0">bft</col>
+        <col id="1" translatable="yes">Beaufort scale</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="temp-store">
+    <columns>
+      <!-- column-name value -->
+      <column type="gchararray"/>
+      <!-- column-name description -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0">kelvin</col>
+        <col id="1" translatable="yes">Kelvin (K)</col>
+      </row>
+      <row>
+        <col id="0">centigrade</col>
+        <col id="1" translatable="yes">Centigrade (°C)</col>
+      </row>
+      <row>
+        <col id="0">fahrenheit</col>
+        <col id="1" translatable="yes">Fahrenheit (°F)</col>
+      </row>
+    </data>
+  </object>
+</interface>
diff --git a/src/window.js b/src/window.js
index 14eaeaf..25529d1 100644
--- a/src/window.js
+++ b/src/window.js
@@ -103,6 +103,8 @@ const MainWindow = new Lang.Class({
         Util.initActions(this,
                          [{ name: 'new',
                             callback: this._newLocation },
+                          { name: 'preferences',
+                            callback: this._showPreferences },
                           { name: 'about',
                             callback: this._showAbout },
                           { name: 'exit-selection-mode',
@@ -352,5 +354,29 @@ const MainWindow = new Lang.Class({
         aboutDialog.connect('response', function() {
             aboutDialog.destroy();
         });
+    },
+
+    _showPreferences: function() {
+        let builder = new Gtk.Builder();
+        builder.add_from_resource('/org/gnome/weather/preferences.ui');
+
+        let dialog = builder.get_object('preferences-dialog');
+        dialog.transient_for = this;
+
+        let settings = new Gio.Settings({ schema: 'org.gnome.GWeather' });
+        settings.bind('temperature-unit', builder.get_object('temp-combo'), 'active-id',
+                      Gio.SettingsBindFlags.DEFAULT);
+        settings.bind('speed-unit', builder.get_object('speed-combo'), 'active-id',
+                      Gio.SettingsBindFlags.DEFAULT);
+        settings.bind('distance-unit', builder.get_object('distance-combo'), 'active-id',
+                      Gio.SettingsBindFlags.DEFAULT);
+        settings.bind('pressure-unit', builder.get_object('pressure-combo'), 'active-id',
+                      Gio.SettingsBindFlags.DEFAULT);
+
+        dialog.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE);
+        dialog.set_default_response(Gtk.ResponseType.CLOSE);
+        dialog.connect('response', function(d) { d.destroy(); });
+
+        dialog.show();
     }
 });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]