[gnome-photos/wip/facebook] facebook: Initial facebook support.



commit 28d36c625f073fb24d306b8db0d132eb6bbb0f09
Author: Álvaro Peña <alvaropg gmail com>
Date:   Tue Aug 20 21:49:01 2013 +0200

    facebook: Initial facebook support.

 src/Makefile.am            |    2 +
 src/photos-facebook-item.c |  211 ++++++++++++++++++++++++++++++++++++++++++++
 src/photos-facebook-item.h |   81 +++++++++++++++++
 src/photos-item-manager.c  |    3 +
 4 files changed, 297 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0e95e5d..60e69c9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -90,6 +90,8 @@ gnome_photos_SOURCES = \
        photos-empty-results-box.h \
        photos-error-box.c \
        photos-error-box.h \
+       photos-facebook-item.c \
+       photos-facebook-item.h \
        photos-fetch-collection-state-job.c \
        photos-fetch-collection-state-job.h \
        photos-fetch-collections-job.c \
diff --git a/src/photos-facebook-item.c b/src/photos-facebook-item.c
new file mode 100644
index 0000000..454e548
--- /dev/null
+++ b/src/photos-facebook-item.c
@@ -0,0 +1,211 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * Facebook support by Álvaro Peña
+ * Copyright © 2013 Álvaro Peña
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+
+#include "config.h"
+
+#include <gio/gio.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <goa/goa.h>
+#include <libgnome-desktop/gnome-desktop-thumbnail.h>
+
+#include "photos-facebook-item.h"
+#include "photos-source.h"
+#include "photos-source-manager.h"
+
+
+struct _PhotosFacebookItemPrivate
+{
+  PhotosBaseManager *src_mngr;
+};
+
+
+G_DEFINE_TYPE (PhotosFacebookItem, photos_facebook_item, PHOTOS_TYPE_BASE_ITEM);
+
+
+static gboolean
+photos_facebook_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
+{
+  const gchar *uri;
+  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);
+
+  return ret_val;
+}
+
+
+static gchar *
+photos_facebook_item_download (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
+{
+  const gchar *uri, *identifier;
+  gchar *local_dir, *filename, *local_filename;
+  GFile *local_file, *remote_file;
+
+  uri = photos_base_item_get_uri (item);
+  remote_file = g_file_new_for_uri (uri);
+
+  /* Local path */
+  local_dir = g_build_filename (g_get_user_cache_dir (), PACKAGE_TARNAME, "facebook", NULL);
+  g_mkdir_with_parents (local_dir, 0700);
+
+  /* Local filename */
+  identifier = photos_base_item_get_identifier (item) + strlen("facebook:photos:");
+  filename = g_strdup_printf ("%s.jpeg", identifier);
+  local_filename = g_build_filename (local_dir, filename, NULL);
+
+  local_file = g_file_new_for_path (local_filename);
+
+  g_debug ("Downloading %s from Facebook to %s", uri, local_filename);
+  if (!g_file_copy (remote_file,
+                    local_file,
+                    G_FILE_COPY_ALL_METADATA | G_FILE_COPY_OVERWRITE,
+                    cancellable,
+                    NULL,
+                    NULL,
+                    error))
+    g_warning ("Failed downloading %s from Facebook to %s\n", uri, local_filename);
+
+  g_free (filename);
+  g_free (local_dir);
+  g_clear_object (&local_file);
+  g_clear_object (&remote_file);
+
+  return local_filename;
+}
+
+
+static const gchar *
+photos_facebook_item_get_source_name (PhotosBaseItem *item)
+{
+  return _("Facebook");
+}
+
+/* TODO */
+static void
+photos_facebook_item_open (PhotosBaseItem *item, GdkScreen *screen, guint32 timestamp)
+{
+  GError *error;
+  gchar *facebook_uri;
+
+  facebook_uri = g_strdup ("https://www.facebook.com/";);
+
+  error = NULL;
+  gtk_show_uri (screen, facebook_uri, timestamp, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to show URI %s: %s", facebook_uri, error->message);
+      g_error_free (error);
+    }
+
+  g_free (facebook_uri);
+}
+
+
+static void
+photos_facebook_item_constructed (GObject *object)
+{
+  PhotosFacebookItem *self = PHOTOS_FACEBOOK_ITEM (object);
+
+  G_OBJECT_CLASS (photos_facebook_item_parent_class)->constructed (object);
+
+  photos_base_item_set_default_app_name (PHOTOS_BASE_ITEM (self), _("Facebook"));
+}
+
+
+static void
+photos_facebook_item_dispose (GObject *object)
+{
+  PhotosFacebookItem *self = PHOTOS_FACEBOOK_ITEM (object);
+
+  g_clear_object (&self->priv->src_mngr);
+
+  G_OBJECT_CLASS (photos_facebook_item_parent_class)->dispose (object);
+}
+
+
+static void
+photos_facebook_item_init (PhotosFacebookItem *self)
+{
+  PhotosFacebookItemPrivate *priv;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_FACEBOOK_ITEM, PhotosFacebookItemPrivate);
+  priv = self->priv;
+
+  priv->src_mngr = photos_source_manager_new ();
+}
+
+
+static void
+photos_facebook_item_class_init (PhotosFacebookItemClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  PhotosBaseItemClass *base_item_class = PHOTOS_BASE_ITEM_CLASS (class);
+
+  object_class->constructed= photos_facebook_item_constructed;
+  object_class->dispose = photos_facebook_item_dispose;
+  base_item_class->create_thumbnail = photos_facebook_item_create_thumbnail;
+  base_item_class->download = photos_facebook_item_download;
+  base_item_class->get_source_name = photos_facebook_item_get_source_name;
+  base_item_class->open = photos_facebook_item_open;
+
+  g_type_class_add_private (class, sizeof (PhotosFacebookItemPrivate));
+}
+
+
+PhotosBaseItem *
+photos_facebook_item_new (TrackerSparqlCursor *cursor)
+{
+  return g_object_new (PHOTOS_TYPE_FACEBOOK_ITEM,
+                       "cursor", cursor,
+                       "failed-thumbnailing", FALSE,
+                       NULL);
+}
diff --git a/src/photos-facebook-item.h b/src/photos-facebook-item.h
new file mode 100644
index 0000000..a2f5b68
--- /dev/null
+++ b/src/photos-facebook-item.h
@@ -0,0 +1,81 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2012 Red Hat, Inc.
+ *
+ * Facebook support by Álvaro Peña
+ * Copyright © 2013 Álvaro Peña
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+#ifndef PHOTOS_FACEBOOK_ITEM_H
+#define PHOTOS_FACEBOOK_ITEM_H
+
+#include <tracker-sparql.h>
+
+#include "photos-base-item.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_FACEBOOK_ITEM (photos_facebook_item_get_type ())
+
+#define PHOTOS_FACEBOOK_ITEM(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_FACEBOOK_ITEM, PhotosFacebookItem))
+
+#define PHOTOS_FACEBOOK_ITEM_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_FACEBOOK_ITEM, PhotosFacebookItemClass))
+
+#define PHOTOS_IS_FACEBOOK_ITEM(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_FACEBOOK_ITEM))
+
+#define PHOTOS_IS_FACEBOOK_ITEM_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_FACEBOOK_ITEM))
+
+#define PHOTOS_FACEBOOK_ITEM_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_FACEBOOK_ITEM, PhotosFacebookItemClass))
+
+typedef struct _PhotosFacebookItem        PhotosFacebookItem;
+typedef struct _PhotosFacebookItemClass   PhotosFacebookItemClass;
+typedef struct _PhotosFacebookItemPrivate PhotosFacebookItemPrivate;
+
+struct _PhotosFacebookItem
+{
+  PhotosBaseItem parent_instance;
+  PhotosFacebookItemPrivate *priv;
+};
+
+struct _PhotosFacebookItemClass
+{
+  PhotosBaseItemClass parent_class;
+};
+
+GType               photos_facebook_item_get_type           (void) G_GNUC_CONST;
+
+PhotosBaseItem     *photos_facebook_item_new                (TrackerSparqlCursor *cursor);
+
+G_END_DECLS
+
+#endif /* PHOTOS_FACEBOOK_ITEM_H */
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index d649396..a52594d 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -30,6 +30,7 @@
 #include "photos-collection-manager.h"
 #include "photos-item-manager.h"
 #include "photos-local-item.h"
+#include "photos-facebook-item.h"
 #include "photos-flickr-item.h"
 #include "photos-query.h"
 #include "photos-single-item-job.h"
@@ -273,6 +274,8 @@ photos_item_manager_create_item (PhotosItemManager *self, TrackerSparqlCursor *c
     {
       if (g_str_has_prefix (identifier, "flickr:") || g_str_has_prefix (identifier, 
"photos:collection:flickr:"))
         ret_val = photos_flickr_item_new (cursor);
+      else if (g_str_has_prefix (identifier, "facebook:"))
+        ret_val = photos_facebook_item_new (cursor);
     }
 
   if (ret_val == NULL)


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