[gnome-clocks] Factor out a get_contry_name utility



commit f9ed4944ae7a1300d28e829b691504b0bab7ae8c
Author: Paolo Borelli <pborelli gnome org>
Date:   Fri Aug 15 11:44:53 2014 +0200

    Factor out a get_contry_name utility

 src/utils.vala |   10 ++++++++++
 src/world.vala |   16 +++++-----------
 2 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/src/utils.vala b/src/utils.vala
index e14700a..d37f67d 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -51,6 +51,16 @@ public void time_to_hms (double t, out int h, out int m, out int s, out double r
     remainder = t - s;
 }
 
+public string? get_country_name (GWeather.Location location) {
+    var country = location;
+
+    while (country != null && country.get_level () != GWeather.LocationLevel.COUNTRY) {
+        country = country.get_parent ();
+    }
+
+    return country != null ? country.get_name () : null;
+}
+
 // TODO: For now we are wrapping Gnome's clock, but we should probably
 // implement our own class, maybe using gnome-datetime-source
 // Especially if we want to try to use CLOCK_REALTIME_ALARM
diff --git a/src/world.vala b/src/world.vala
index c229120..5e2a806 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -35,8 +35,8 @@ public class Item : Object, ContentItem {
         get {
             // We store it in a _name member even if we overwrite it every time
             // since the abstract name property does not return an owned string
-            if (nation_name != null) {
-                _name = "%s, %s".printf (city_name, nation_name);
+            if (contry_name != null) {
+                _name = "%s, %s".printf (city_name, contry_name);
             } else {
                 _name = city_name;
             }
@@ -54,15 +54,9 @@ public class Item : Object, ContentItem {
         }
     }
 
-    public string? nation_name {
+    public string? contry_name {
         owned get {
-            var nation = location;
-
-            while (nation != null && nation.get_level () != GWeather.LocationLevel.COUNTRY) {
-                nation = nation.get_parent ();
-            }
-
-            return nation != null ? nation.get_name () : null;
+            return Utils.get_country_name (location);
         }
     }
 
@@ -440,7 +434,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
             break;
         case HeaderBar.Mode.STANDALONE:
             header_bar.title = GLib.Markup.escape_text (standalone.location.city_name);
-            header_bar.subtitle = GLib.Markup.escape_text (standalone.location.nation_name);
+            header_bar.subtitle = GLib.Markup.escape_text (standalone.location.contry_name);
             back_button.show ();
             break;
         default:


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