[gnome-clocks] Use the new GtkBuilder support in GWeather



commit c75f6e25ccdeafd52b2dfe972e11f5f8ab2bc090
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun May 19 17:13:02 2013 +0200

    Use the new GtkBuilder support in GWeather
    
    With that, we can move the location entry to Glade and simplify
    our code.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=700642

 configure.ac     |    2 +-
 data/ui/world.ui |   15 +++++++++++++++
 src/world.vala   |   36 ++++++++++++------------------------
 3 files changed, 28 insertions(+), 25 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a033bad..28f055c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,7 +51,7 @@ PKG_CHECK_MODULES(CLOCKS, [
     gio-2.0 >= 2.30.0
     gtk+-3.0 >= 3.7.12
     libcanberra >= 0.30
-    gweather-3.0 >= 3.7.90
+    gweather-3.0 >= 3.9.2
     gnome-desktop-3.0 >= 3.7.90
     libnotify >= 0.7.0
 ])
diff --git a/data/ui/world.ui b/data/ui/world.ui
index d14e4db..679404e 100644
--- a/data/ui/world.ui
+++ b/data/ui/world.ui
@@ -61,6 +61,21 @@
         <property name="height">1</property>
       </packing>
     </child>
+    <child>
+      <object class="GWeatherLocationEntry" id="location_entry">
+        <property name="width_request">400</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="secondary_icon_name">edit-find-symbolic</property>
+        <property name="activates-default">True</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>
   </object>
   <object class="GtkGrid" id="standalone_content">
     <property name="visible">True</property>
diff --git a/src/world.vala b/src/world.vala
index 2d18879..3249e41 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -19,15 +19,6 @@
 namespace Clocks {
 namespace World {
 
-static GWeather.Location? gweather_world = null;
-
-private GWeather.Location get_world_location () {
-    if (gweather_world == null) {
-        gweather_world = new GWeather.Location.world (true);
-    }
-    return gweather_world;
-}
-
 private class Item : Object, ContentItem {
     private static Gdk.Pixbuf? day_pixbuf = Utils.load_image ("day.png");
     private static Gdk.Pixbuf? night_pixbuf = Utils.load_image ("night.png");
@@ -130,7 +121,7 @@ private class Item : Object, ContentItem {
         date_time = local_time.to_timezone (time_zone);
 
         // We don't need to call update(), we're using only astronomical data
-        weather_info = new GWeather.Info.for_world (get_world_location (), location, 
GWeather.ForecastType.LIST);
+        weather_info = new GWeather.Info (location, GWeather.ForecastType.LIST);
     }
 
     public void get_thumb_properties (out string text, out string subtext, out Gdk.Pixbuf? pixbuf, out 
string css_class) {
@@ -153,10 +144,15 @@ private class Item : Object, ContentItem {
 
     public static Item deserialize (GLib.Variant location_variant) {
         GWeather.Location? location = null;
+
+        // This looks like a constructor for historic reasons
+        // it returns the same instance after the first call
+        var world = new GWeather.Location.world (true);
+
         foreach (var v in location_variant) {
             var key = v.get_child_value (0).get_string ();
             if (key == "location") {
-                location = get_world_location ().deserialize (v.get_child_value (1).get_child_value (0));
+                location = world.deserialize (v.get_child_value (1).get_child_value (0));
             }
         }
         return location != null ? new Item (location) : null;
@@ -165,8 +161,6 @@ private class Item : Object, ContentItem {
 
 private class LocationDialog : Gtk.Dialog {
     private GWeather.LocationEntry entry;
-    private GLib.ThemedIcon find_icon;
-    private GLib.ThemedIcon clear_icon;
 
     public LocationDialog (Gtk.Window parent) {
         Object (transient_for: parent, modal: true, title: _("Add a New World Clock"));
@@ -180,14 +174,7 @@ private class LocationDialog : Gtk.Dialog {
         var grid = builder.get_object ("location_dialog_content") as Gtk.Grid;
         get_content_area ().add (grid);
 
-        entry = new GWeather.LocationEntry (get_world_location ());
-        entry.set_size_request (400, -1);
-        find_icon = new GLib.ThemedIcon.with_default_fallbacks ("edit-find-symbolic");
-        clear_icon = new GLib.ThemedIcon.with_default_fallbacks ("edit-clear-symbolic");
-        entry.set_icon_from_gicon (Gtk.EntryIconPosition.SECONDARY, find_icon);
-        entry.set_activates_default (true);
-        entry.show ();
-        grid.attach (entry, 0, 1, 1, 1);
+        entry = builder.get_object ("location_entry") as GWeather.LocationEntry;
 
         entry.changed.connect (() => {
             location_changed ();
@@ -196,7 +183,7 @@ private class LocationDialog : Gtk.Dialog {
             location_changed ();
         });
         entry.icon_release.connect (() => {
-            if (entry.get_icon_gicon (Gtk.EntryIconPosition.SECONDARY) == clear_icon) {
+            if (entry.secondary_icon_name == "edit-clear-symbolic") {
                 entry.set_text ("");
             }
         });
@@ -206,9 +193,10 @@ private class LocationDialog : Gtk.Dialog {
         GWeather.Location? l = null;
         GWeather.Timezone? t = null;
         if (entry.get_text () == "") {
-            entry.set_icon_from_gicon (Gtk.EntryIconPosition.SECONDARY, find_icon);
+            entry.secondary_icon_name = "edit-find-symbolic";
         } else {
-            entry.set_icon_from_gicon (Gtk.EntryIconPosition.SECONDARY, clear_icon);
+            entry.secondary_icon_name = "edit-clear-symbolic";
+
             l = entry.get_location ();
             if (l != null) {
                 t = l.get_timezone ();


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