[gnome-clocks/wip/cityimages] Add non working yet Flickr provider



commit 912ca32d4894635e20ef5cb5d7dee0a9d84b8a20
Author: Evgeny Bobkin <evgen ibqn gmail com>
Date:   Mon Sep 16 11:34:50 2013 +0200

    Add non working yet Flickr provider

 src/providers.vala |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/src/providers.vala b/src/providers.vala
index c71e4cc..508a5ad 100644
--- a/src/providers.vala
+++ b/src/providers.vala
@@ -93,6 +93,51 @@ public class LocalImageProvider : GLib.Object, ImageProvider {
     }
 }
 
+public class FlickrImageProvider : GLib.Object, ImageProvider {
+    private string folder_path;
+    private FileMonitor monitor;
+
+    public FlickrImageProvider () {
+        folder_path = GLib.Path.build_path (GLib.Path.DIR_SEPARATOR_S,
+                                            GLib.Environment.get_user_data_dir (),
+                                            "gnome-clocks", "city-images", "flickr");
+
+        File folder = File.new_for_path (folder_path);
+
+        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);
+        }
+    }
+
+    public Gdk.Pixbuf? get_image (string name) {
+        Gdk.Pixbuf? image = null;
+
+        try {
+            var path = GLib.Path.build_path (GLib.Path.DIR_SEPARATOR_S, folder_path, name + ".jpg");
+
+            image = new Gdk.Pixbuf.from_file (path);
+        } catch (Error e) {
+            image = null;
+        }
+
+        return image;
+    }
+}
+
 public class AutomaticImageProvider : GLib.Object, ImageProvider {
     private List<ImageProvider> providers;
 
@@ -100,6 +145,7 @@ public class AutomaticImageProvider : GLib.Object, ImageProvider {
         providers = new List<ImageProvider> ();
 
         providers.prepend (new DefaultProvider ());
+        providers.prepend (new FlickrImageProvider ());
         providers.prepend (new LocalImageProvider ());
 
         foreach (var provider in providers) {


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