[gnome-clocks/wip/cityimages] Do not monitor the flickr folder, pass name of changed file to signal



commit e1986dcdbfc0b8f69c3c172ac7d9bf1c69611d52
Author: Evgeny Bobkin <evgen ibqn gmail com>
Date:   Mon Sep 16 22:49:33 2013 +0200

    Do not monitor the flickr folder, pass name of changed file to signal

 src/providers.vala |   51 +++++++++++++++++++++------------------------------
 src/world.vala     |   15 +++++++++------
 2 files changed, 30 insertions(+), 36 deletions(-)
---
diff --git a/src/providers.vala b/src/providers.vala
index 7275c84..302e8be 100644
--- a/src/providers.vala
+++ b/src/providers.vala
@@ -24,7 +24,7 @@ public interface ImageProvider : GLib.Object {
         return null;
     }
 
-    public signal void image_updated ();
+    public signal void image_updated (string name);
 }
 
 // This is the default fallback provider
@@ -59,7 +59,7 @@ public class LocalImageProvider : GLib.Object, ImageProvider {
         File folder = File.new_for_path (folder_path);
 
         if (!folder.query_exists ()) {
-            stdout.printf( "creating a flickr directory\n");
+            stdout.printf( "creating a city-images directory\n");
             try {
                 folder.make_directory_with_parents ();
             } catch (Error e) {
@@ -79,7 +79,7 @@ public class LocalImageProvider : GLib.Object, ImageProvider {
                     stdout.printf ("%s: %s\n", event.to_string (), src.get_path ());
                 }
 
-                image_updated ();
+                image_updated (src.get_path ());
             });
         } catch (Error err) {
             warning ("Monitoring image files: %s\n", err.message);
@@ -199,7 +199,7 @@ private class FlickrClient : GLib.Object {
         return null;
     }
 
-    public async string? get_image_uri (string image_id) {
+    public async string? seek_image_uri (string image_id) {
         string msg = @"&method=flickr.photos.getSizes&photo_id=$image_id";
 
         var object = yield get_root_object (msg);
@@ -228,8 +228,8 @@ private class FlickrClient : GLib.Object {
 
 public class FlickrImageProvider : GLib.Object, ImageProvider {
     private string folder_path;
-    private FileMonitor monitor;
     private FlickrClient flickr_client;
+    private int downloading;
 
     public FlickrImageProvider () {
         folder_path = GLib.Path.build_path (GLib.Path.DIR_SEPARATOR_S,
@@ -247,24 +247,6 @@ public class FlickrImageProvider : GLib.Object, ImageProvider {
             }
         }
 
-        try {
-            monitor = folder.monitor_directory (FileMonitorFlags.NONE, null);
-            stdout.printf ("Monitoring: %s\n", folder.get_path ());
-
-            monitor.changed.connect ((src, dest, event) => {
-                if (dest != null) {
-                    stdout.printf ("%s: %s, %s\n", event.to_string (),
-                                   src.get_path (), dest.get_path ());
-                } else {
-                    stdout.printf ("%s: %s\n", event.to_string (), src.get_path ());
-                }
-
-                image_updated ();
-            });
-        } catch (Error err) {
-            warning ("Monitoring flickr image files: %s\n", err.message);
-        }
-
         flickr_client = new FlickrClient ();
     }
 
@@ -286,12 +268,16 @@ public class FlickrImageProvider : GLib.Object, ImageProvider {
 
     private void fetch_image (string name) {
         if (flickr_client.group_id != null) {
-            receive_image.begin ((obj, res) = > {
-                    receive_image.end (res);
+            receive_image.begin (name, (obj, res) => {
+                receive_image.end (res);
             });
         } else {
-            flickr_client.notify["group-id"].connect (receve_image, name);
-            flickr_client.get_group_id.begin ();
+            flickr_client.notify["group-id"].connect ((sender, property) => {
+                receive_image.begin (name, (obj, res) => {
+                    receive_image.end (res);
+                });
+            });
+            flickr_client.seek_group_id.begin ();
         }
     }
 
@@ -310,7 +296,7 @@ public class FlickrImageProvider : GLib.Object, ImageProvider {
             return;
         }
 
-        yield download_image (image_uri, string name);
+        yield download_image (image_uri, name);
     }
 
     private async void download_image (string uri, string name) {
@@ -320,12 +306,17 @@ public class FlickrImageProvider : GLib.Object, ImageProvider {
         var source = File.new_for_uri (uri);
         var target = File.new_for_path (target_path);
 
+        GLib.AtomicInt.inc (ref downloading);
         try {
             yield source.copy_async (target, FileCopyFlags.OVERWRITE);
         } catch (Error e) {
             warning ("Copying an image has failed: %s", e.message);
             return;
+        } finally {
+            GLib.AtomicInt.dec_and_test (ref downloading);
         }
+
+        image_updated (name);
     }
 }
 
@@ -340,8 +331,8 @@ public class AutomaticImageProvider : GLib.Object, ImageProvider {
         providers.prepend (new LocalImageProvider ());
 
         foreach (var provider in providers) {
-            provider.image_updated.connect (() => {
-                image_updated ();
+            provider.image_updated.connect ((name) => {
+                image_updated (name);
             });
         }
     }
diff --git a/src/world.vala b/src/world.vala
index 8dc8ee8..99840e2 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -149,17 +149,20 @@ private class Item : Object, ContentItem {
 
         image_provider.image_updated.connect (update_images);
 
-        update_images ();
+        update_images (file_name);
 
         tick ();
     }
 
-    public void update_images () {
-        day_pixbuf = image_provider.get_image (file_name + "-day");
-        scaled_day_pixbuf = day_pixbuf.scale_simple (256, 256, Gdk.InterpType.BILINEAR);
+    public void update_images (string name) {
+        if (file_name in name) {
+            stdout.printf ("YES");
+            day_pixbuf = image_provider.get_image (file_name + "-day");
+            scaled_day_pixbuf = day_pixbuf.scale_simple (256, 256, Gdk.InterpType.BILINEAR);
 
-        night_pixbuf = image_provider.get_image (file_name + "-night");
-        scaled_night_pixbuf = night_pixbuf.scale_simple (256, 256, Gdk.InterpType.BILINEAR);
+            night_pixbuf = image_provider.get_image (file_name + "-night");
+            scaled_night_pixbuf = night_pixbuf.scale_simple (256, 256, Gdk.InterpType.BILINEAR);
+        }
     }
 
     public void tick () {


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