[gnome-photos/wip/flickr: 1/7] base-item: Refactor loading for downloading remote items



commit 0b9d3066959d3f2ef579b7fceafc07416655e595
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Jun 28 18:06:45 2013 +0200

    base-item: Refactor loading for downloading remote items
    
    Rename the virtual method "load" as "download". Remote items should
    implement it to download a local copy of the image and return the
    path.
    
    The implementation in PhotosLocalItem is practically a no-op. It
    converts the file://... URI to a local path.
    
    Fixes: https://bugzilla.gnome.org/697675

 src/photos-base-item.c  |   66 ++++++++++++++++++++++-------------------------
 src/photos-base-item.h  |    2 +-
 src/photos-local-item.c |   20 +++++++++++++-
 3 files changed, 51 insertions(+), 37 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 14f478b..50e7b12 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -200,39 +200,6 @@ photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
 }
 
 
-static GeglNode *
-photos_base_item_default_load (PhotosBaseItem *self, GCancellable *cancellable, GError **error)
-{
-  PhotosBaseItemPrivate *priv = self->priv;
-  GeglNode *ret_val = NULL;
-  GFile *file = NULL;
-  gchar *path = NULL;
-
-  if (priv->graph == NULL)
-    {
-      file = g_file_new_for_uri (priv->uri);
-      path = g_file_get_path (file);
-      if (path == NULL)
-        goto out;
-
-      priv->graph = gegl_node_new ();
-      priv->node = gegl_node_new_child (priv->graph,
-                                        "operation", "gegl:load",
-                                        "path", path,
-                                        NULL);
-    }
-
-  gegl_node_process (priv->node);
-  priv->bbox = gegl_node_get_bounding_box (priv->node);
-  ret_val = g_object_ref (priv->node);
-
- out:
-  g_free (path);
-  g_clear_object (&file);
-  return ret_val;
-}
-
-
 static void
 photos_base_item_default_set_favorite (PhotosBaseItem *self, gboolean favorite)
 {
@@ -450,6 +417,36 @@ photos_base_item_file_query_info (GObject *source_object, GAsyncResult *res, gpo
 }
 
 
+static GeglNode *
+photos_base_item_load (PhotosBaseItem *self, GCancellable *cancellable, GError **error)
+{
+  PhotosBaseItemPrivate *priv = self->priv;
+  GeglNode *ret_val = NULL;
+  gchar *path = NULL;
+
+  if (priv->graph == NULL)
+    {
+      path = PHOTOS_BASE_ITEM_GET_CLASS (self)->download(self, cancellable, error);
+      if (path == NULL)
+        goto out;
+
+      priv->graph = gegl_node_new ();
+      priv->node = gegl_node_new_child (priv->graph,
+                                        "operation", "gegl:load",
+                                        "path", path,
+                                        NULL);
+    }
+
+  gegl_node_process (priv->node);
+  priv->bbox = gegl_node_get_bounding_box (priv->node);
+  ret_val = g_object_ref (priv->node);
+
+ out:
+  g_free (path);
+  return ret_val;
+}
+
+
 static void
 photos_base_item_load_in_thread_func (GSimpleAsyncResult *simple, GObject *object, GCancellable *cancellable)
 {
@@ -460,7 +457,7 @@ photos_base_item_load_in_thread_func (GSimpleAsyncResult *simple, GObject *objec
 
   g_mutex_lock (&priv->mutex);
 
-  node = PHOTOS_BASE_ITEM_GET_CLASS (self)->load (self, cancellable, &error);
+  node = photos_base_item_load (self, cancellable, &error);
   if (error != NULL)
     g_simple_async_result_take_error (simple, error);
 
@@ -753,7 +750,6 @@ photos_base_item_class_init (PhotosBaseItemClass *class)
   object_class->finalize = photos_base_item_finalize;
   object_class->get_property = photos_base_item_get_property;
   object_class->set_property = photos_base_item_set_property;
-  class->load = photos_base_item_default_load;
   class->set_favorite = photos_base_item_default_set_favorite;
   class->update_type_description = photos_base_item_update_type_description;
 
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 6f6b2ba..1cda085 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -68,7 +68,7 @@ struct _PhotosBaseItemClass
 {
   GObjectClass parent_class;
 
-  GeglNode *(*load) (PhotosBaseItem *self, GCancellable *cancellable, GError **error);
+  gchar *(*download) (PhotosBaseItem *self, GCancellable *cancellable, GError **error);
   void (*set_favorite) (PhotosBaseItem *self, gboolean favorite);
   void (*update_type_description) (PhotosBaseItem *self);
 
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index 3158e52..668fde8 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 Red Hat, Inc.
+ * Copyright © 2012, 2013 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -34,6 +34,22 @@
 G_DEFINE_TYPE (PhotosLocalItem, photos_local_item, PHOTOS_TYPE_BASE_ITEM);
 
 
+static gchar *
+photos_local_item_download (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
+{
+  GFile *file = NULL;
+  const gchar *uri;
+  gchar *path = NULL;
+
+  uri = photos_base_item_get_uri (item);
+  file = g_file_new_for_uri (uri);
+  path = g_file_get_path (file);
+
+  g_object_unref (file);
+  return path;
+}
+
+
 static void
 photos_local_item_constructed (GObject *object)
 {
@@ -70,8 +86,10 @@ static void
 photos_local_item_class_init (PhotosLocalItemClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
+  PhotosBaseItemClass *base_item_class = PHOTOS_BASE_ITEM_CLASS (class);
 
   object_class->constructed= photos_local_item_constructed;
+  base_item_class->download = photos_local_item_download;
 }
 
 


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