[gnome-photos/wip/facebook] facebook thumbnailing: get the photo image closer to the thumbnail size



commit 75834eaf4cefb728e69ad769c1d9cb253407a5d9
Author: Álvaro Peña <alvaropg gmail com>
Date:   Mon Aug 26 19:37:24 2013 +0200

    facebook thumbnailing: get the photo image closer to the thumbnail size

 src/photos-facebook-item.c |   87 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 65 insertions(+), 22 deletions(-)
---
diff --git a/src/photos-facebook-item.c b/src/photos-facebook-item.c
index 454e548..2e658b4 100644
--- a/src/photos-facebook-item.c
+++ b/src/photos-facebook-item.c
@@ -29,6 +29,8 @@
 
 #include "config.h"
 
+#include <gfbgraph/gfbgraph.h>
+#include <gfbgraph/gfbgraph-goa-authorizer.h>
 #include <gio/gio.h>
 #include <glib.h>
 #include <glib/gi18n.h>
@@ -38,6 +40,7 @@
 #include "photos-facebook-item.h"
 #include "photos-source.h"
 #include "photos-source-manager.h"
+#include "photos-utils.h"
 
 
 struct _PhotosFacebookItemPrivate
@@ -45,39 +48,79 @@ struct _PhotosFacebookItemPrivate
   PhotosBaseManager *src_mngr;
 };
 
+GFBGraphPhoto* photos_facebook_get_gfbgraph_photo (PhotosBaseItem *item, GCancellable *cancellable, GError 
**error);
 
 G_DEFINE_TYPE (PhotosFacebookItem, photos_facebook_item, PHOTOS_TYPE_BASE_ITEM);
 
+GFBGraphPhoto*
+photos_facebook_get_gfbgraph_photo (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
+{
+  PhotosFacebookItemPrivate *priv = PHOTOS_FACEBOOK_ITEM (item)->priv;
+  PhotosSource *source;
+  const gchar *identifier, *resource_urn;
+  GFBGraphGoaAuthorizer *authorizer;
+  GFBGraphPhoto *photo;
+
+  resource_urn = photos_base_item_get_resource_urn (item);
+  source = PHOTOS_SOURCE (photos_base_manager_get_object_by_id (priv->src_mngr, resource_urn));
+  authorizer = gfbgraph_goa_authorizer_new (photos_source_get_goa_object (source));
+  identifier = photos_base_item_get_identifier (item) + strlen("facebook:photos:");
+
+  gfbgraph_authorizer_refresh_authorization (GFBGRAPH_AUTHORIZER (authorizer), cancellable, error);
+
+  photo = gfbgraph_photo_new_from_id (GFBGRAPH_AUTHORIZER (authorizer), identifier, error);
+
+  return photo;
+}
 
 static gboolean
 photos_facebook_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
 {
-  const gchar *uri;
+  GFBGraphPhoto *photo;
+  GFBGraphPhotoImage *thumbnail_image;
   gchar *local_path, *local_dir;
   GFile *local_file, *remote_file;
   gboolean ret_val = FALSE;
 
-  uri = photos_base_item_get_uri (item);
-  remote_file = g_file_new_for_uri (uri);
-  local_path = gnome_desktop_thumbnail_path_for_uri (uri, GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
-  local_file = g_file_new_for_path (local_path);
-  local_dir = g_path_get_dirname (local_path);
-  g_mkdir_with_parents (local_dir, 0700);
-
-  g_debug ("Downloading %s from Facebook to %s", uri, local_path);
-  if (g_file_copy (remote_file,
-                   local_file,
-                   G_FILE_COPY_ALL_METADATA | G_FILE_COPY_OVERWRITE,
-                   cancellable,
-                   NULL,
-                   NULL,
-                   error))
-    ret_val = TRUE;
-
-  g_free (local_path);
-  g_free (local_dir);
-  g_clear_object (&local_file);
-  g_clear_object (&remote_file);
+  photo = photos_facebook_get_gfbgraph_photo (item, cancellable, error);
+  if (photo == NULL)
+    {
+      g_error ("Can't get the photo from the Facebook Graph\n");
+    }
+  else
+    {
+    thumbnail_image = gfbgraph_photo_get_image_near_width (photo, photos_utils_get_icon_size ());
+    if (thumbnail_image == NULL)
+      {
+        g_error ("Can't get a photo size to create the thumbnail.\n");
+      }
+    else
+      {
+        remote_file = g_file_new_for_uri (thumbnail_image->source);
+
+        local_path = gnome_desktop_thumbnail_path_for_uri (photos_base_item_get_uri (item),
+                                                           GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
+        local_file = g_file_new_for_path (local_path);
+        local_dir = g_path_get_dirname (local_path);
+        g_mkdir_with_parents (local_dir, 0700);
+
+        g_debug ("Downloading %s from Facebook to %s",
+                 thumbnail_image->source, local_path);
+        if (g_file_copy (remote_file,
+                         local_file,
+                         G_FILE_COPY_ALL_METADATA | G_FILE_COPY_OVERWRITE,
+                         cancellable,
+                         NULL,
+                         NULL,
+                         error))
+          ret_val = TRUE;
+
+        g_free (local_path);
+        g_free (local_dir);
+        g_clear_object (&local_file);
+        g_clear_object (&remote_file);
+      }
+    }
 
   return ret_val;
 }


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