[gnome-weather] Displaying local-time for locations in city-view



commit 8596e5393934257683fe4f0fbb7c72277774fb98
Author: Saurabh_P <srp201201051 gmail com>
Date:   Wed Feb 19 21:24:22 2014 +0530

    Displaying local-time for locations in city-view
    
    Set one time-label. Set its value using timezone information and
    GLib.DateTime. Update its value using GnomeWallClock whenever it
    needs to get updated. Diconnect the notify::clock during world-view.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705050

 data/city.ui  |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 src/city.js   |   29 ++++++++++++++++++++++++++++-
 src/window.js |    2 ++
 3 files changed, 74 insertions(+), 2 deletions(-)
---
diff --git a/data/city.ui b/data/city.ui
index b930b6a..6710d7b 100644
--- a/data/city.ui
+++ b/data/city.ui
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.1 -->
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
+  <requires lib="gtk+" version="3.0"/>
   <object class="GtkOverlay" id="outer-box">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -91,6 +92,48 @@
               </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="GtkGrid" id="time-grid">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <child>
+                  <object class="GtkImage" id="clock-image">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">1</property>
+                    <property name="xpad">10</property>
+                    <property name="ypad">15</property>
+                    <property name="icon_name">document-open-recent-symbolic</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="time-label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="ypad">15</property>
+                    <property name="label" translatable="yes">label</property>
+                  </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>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
                 <property name="top_attach">0</property>
                 <property name="width">1</property>
                 <property name="height">1</property>
diff --git a/src/city.js b/src/city.js
index 243a3f1..fc19348 100644
--- a/src/city.js
+++ b/src/city.js
@@ -19,6 +19,8 @@
 const Atk = imports.gi.Atk;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
+const GLib = imports.gi.GLib;
+const Gnome = imports.gi.GnomeDesktop;
 const Lang = imports.lang;
 
 const Forecast = imports.forecast;
@@ -49,9 +51,10 @@ const WeatherWidget = new Lang.Class({
         this._conditions = builder.get_object('conditions-label');
         this._revealButton = builder.get_object('reveal-button');
         this._revealer = builder.get_object('revealer');
+        this._time = builder.get_object('time-label');
 
         this._forecasts = new Forecast.ForecastBox({ hexpand: true });
-        outerGrid.attach(this._forecasts, 0, 1, 1, 1);
+        outerGrid.attach(this._forecasts, 0, 2, 1, 1);
 
         this._today = new Forecast.TodaySidebar({ vexpand: true,
                                                   name: 'today-sidebar' });
@@ -184,7 +187,31 @@ const WeatherView = new Lang.Class({
     _onUpdate: function(info) {
         this._infoPage.clear();
         this._infoPage.update(info);
+        this._updateTime();
         this._spinner.stop();
         this.visible_child_name = 'info';
+    },
+
+    _connectClock: function() {
+        this._wallClock = new Gnome.WallClock();
+        this._clockHandlerId = this._wallClock.connect('notify::clock', Lang.bind(this, this._updateTime));
+    },
+
+    _updateTime: function() {
+        this._infoPage._time.label = this._getTime();
+    },
+
+    _getTime: function() {
+        if (this._info != null) {
+            let location = this._info.location;
+            let tz = GLib.TimeZone.new(location.get_timezone().get_tzid());
+            let dt = GLib.DateTime.new_now(tz);
+            return dt.format("%H:%M");
+        }
+        return null;
+    },
+
+    _disconnectClock: function() {
+        this._wallClock.disconnect(this._clockHandlerId);
     }
 });
diff --git a/src/window.js b/src/window.js
index 0c971a1..9c9c49c 100644
--- a/src/window.js
+++ b/src/window.js
@@ -273,6 +273,7 @@ const MainWindow = new Lang.Class({
 
     showInfo: function(info) {
         this._cityView.info = info;
+        this._cityView._connectClock();
         this._stack.set_visible_child(this._cityView);
         this._goToPage(Page.CITY);
     },
@@ -280,6 +281,7 @@ const MainWindow = new Lang.Class({
     _goWorld: function() {
         this._stack.set_visible_child(this._worldView);
         this._goToPage(Page.WORLD);
+        this._cityView._disconnectClock();
     },
 
     _newLocation: function() {


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