[gnome-clocks] World clocks: use the new serialization capabilities in libgweather



commit 52377a04254b8740a30349fbea1203df54057c0a
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Dec 2 04:15:14 2012 +0100

    World clocks: use the new serialization capabilities in libgweather
    
    libgweather now can transform a GWeatherLocation into a GVariant and
    back, and can compare two GWeatherLocation for equality. Use that
    ability to replace our handling of METAR codes and fix the inability
    to have two cities that happen to share a weather station in libgweather's
    database.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685433

 gnomeclocks/world.py |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/gnomeclocks/world.py b/gnomeclocks/world.py
index b3cdb16..b5517c4 100644
--- a/gnomeclocks/world.py
+++ b/gnomeclocks/world.py
@@ -37,19 +37,20 @@ class WorldClockStorage:
         self.filename = os.path.join(Dirs.get_user_data_dir(), "clocks.json")
 
     def save(self, clocks):
-        location_codes = [c.location.get_code() for c in clocks]
+        locations = [str(c.location.serialize()) for c in clocks]
         f = open(self.filename, "wb")
-        json.dump(location_codes, f)
+        json.dump(locations, f)
         f.close()
 
     def load(self):
         clocks = []
         try:
             f = open(self.filename, "rb")
-            location_codes = json.load(f)
+            locations = json.load(f)
             f.close()
-            for l in location_codes:
-                location = GWeather.Location.find_by_station_code(gweather_world, l)
+            for l in locations:
+                variant = GLib.Variant.parse(None, l, None, None)
+                location = GWeather.Location.deserialize(gweather_world, variant)
                 if location:
                     clock = ClockItem(location)
                     clocks.append(clock)
@@ -390,7 +391,7 @@ class World(Clock):
             self._add_clock_item(clock)
 
     def add_clock(self, location):
-        if location.get_code() in [c.location.get_code() for c in self.clocks]:
+        if any(c.location.equal(location) for c in self.clocks):
             # duplicate
             return
         clock = ClockItem(location)



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