[gnome-documents/wip/facebook: 1/2] wip/facebook branch: initial commit
- From: Álvaro Peña <alvaropg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/facebook: 1/2] wip/facebook branch: initial commit
- Date: Mon, 3 Jun 2013 09:17:09 +0000 (UTC)
commit 4d544e1e37a15fb76f9994fdbad11ece83fb63cf
Author: Álvaro Peña <alvaropg gmail com>
Date: Mon Jun 3 11:04:49 2013 +0200
wip/facebook branch: initial commit
configure.ac | 2 +
src/Makefile-miner.am | 24 +++
src/miner/facebook-miner-main.c | 30 ++++
src/miner/gd-facebook-miner.c | 341 +++++++++++++++++++++++++++++++++++++++
src/miner/gd-facebook-miner.h | 70 ++++++++
5 files changed, 467 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f33cf14..6401e8c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -67,6 +67,7 @@ GOBJECT_INTROSPECTION_MIN_VERSION=1.31.6
GDATA_MIN_VERSION=0.13.3
GOA_MIN_VERSION=3.2.0
GRILO_MIN_VERSION=0.2.6
+GFBGRAPH_MIN_VERSION=0.1
TRACKER_MIN_VERSION=0.13.1
ZAPOJIT_MIN_VERSION=0.0.2
SOUP_MIN_VERSION=2.41.3
@@ -95,6 +96,7 @@ PKG_CHECK_MODULES(MINER,
goa-1.0 >= $GOA_MIN_VERSION
grilo-0.2 >= $GRILO_MIN_VERSION
libgdata >= $GDATA_MIN_VERSION
+ libgfbgraph-0.1 >= $GFBGRAPH_MIN_VERSION
zapojit-0.0 >= $ZAPOJIT_MIN_VERSION)
LIBGD_INIT([
diff --git a/src/Makefile-miner.am b/src/Makefile-miner.am
index eaf52d7..62a0bb3 100644
--- a/src/Makefile-miner.am
+++ b/src/Makefile-miner.am
@@ -101,4 +101,28 @@ gd_tracker_flickr_miner_LDADD = \
$(DOCUMENTS_LIBS) \
$(NULL)
+libexec_PROGRAMS += gd-tracker-facebook-miner
+
+gd_tracker_facebook_miner_SOURCES = \
+ miner/facebook-miner-main.c \
+ miner/gd-miner.c \
+ miner/gd-miner.h \
+ miner/gd-facebook-miner.c \
+ miner/gd-facebook-miner.h \
+ $(NULL)
+
+gd_tracker_facebook_miner_CFLAGS = \
+ -DG_DISABLE_DEPRECATED \
+ -I$(top_srcdir)/src/lib \
+ $(MINER_CFLAGS) \
+ $(DOCUMENTS_CFLAGS) \
+ $(NULL)
+
+gd_tracker_facebook_miner_LDADD = \
+ libgdminer-1.0.la \
+ libgdprivate-1.0.la \
+ $(MINER_LIBS) \
+ $(DOCUMENTS_LIBS) \
+ $(NULL)
+
EXTRA_DIST += miner/miner-main.c
diff --git a/src/miner/facebook-miner-main.c b/src/miner/facebook-miner-main.c
new file mode 100644
index 0000000..f13b58c
--- /dev/null
+++ b/src/miner/facebook-miner-main.c
@@ -0,0 +1,30 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2; -*- */
+/*
+ * Copyright (c) 2013 The GNOME Foundation.
+ *
+ * Gnome Documents 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.
+ *
+ * Gnome Documents 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 Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Álvaro Peña <alvaropg gmail com
+ */
+
+#define INSIDE_MINER
+#define MINER_NAME "FACEBOOK"
+#define MINER_TYPE GD_TYPE_FACEBOOK_MINER
+
+#define MINER_BUS_NAME "org.gnome.Documents.Facebook"
+#define MINER_OBJECT_PATH "/org/gnome/Documents/Facebook"
+
+#include "gd-facebook-miner.h"
+#include "miner-main.c"
diff --git a/src/miner/gd-facebook-miner.c b/src/miner/gd-facebook-miner.c
new file mode 100644
index 0000000..f5ed0ab
--- /dev/null
+++ b/src/miner/gd-facebook-miner.c
@@ -0,0 +1,341 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2; -*- */
+/*
+ * Copyright (c) 2013 The GNOME Foundation.
+ *
+ * Gnome Documents 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.
+ *
+ * Gnome Documents 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 Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Álvaro Peña <alvaropg gmail com>
+ */
+
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+#include <goa/goa.h>
+#include <gfbgraph/gfbgraph.h>
+#include <gfbgraph/gfbgraph-goa-authorizer.h>
+
+#include "gd-facebook-miner.h"
+
+/* FIXME find out how to create this identifier */
+#define MINER_IDENTIFIER "gd:facebook:miner:9c2430466e82e937a386870250044bb9"
+#define MINER_VERSION 1
+
+#define GOA_PROVIDER_TYPE "facebook"
+
+/* object functions */
+static void gd_facebook_miner_class_init (GdFacebookMinerClass *klass);
+static void gd_facebook_miner_init (GdFacebookMiner *miner);
+/* miner functions */
+static GObject *create_service (GdMiner *self, GoaObject *object);
+static void query_facebook (GdAccountMinerJob *job, GError **error);
+/* private functions */
+static gboolean account_miner_job_lookup_album (GdAccountMinerJob *job, GFBGraphAlbum *album, const gchar
*creator, GError **error);
+static gboolean account_miner_job_process_photo (GdAccountMinerJob *job, GFBGraphPhoto *photo, const gchar
*parent_identifier, const gchar *creator,GError **error);
+
+G_DEFINE_TYPE (GdFacebookMiner, gd_facebook_miner, GD_TYPE_MINER)
+
+static void
+gd_facebook_miner_class_init (GdFacebookMinerClass *klass)
+{
+ GdMinerClass *miner_class = GD_MINER_CLASS (klass);
+
+ miner_class->goa_provider_type = GOA_PROVIDER_TYPE;
+ miner_class->miner_identifier = MINER_IDENTIFIER;
+ miner_class->version = MINER_VERSION;
+
+ miner_class->create_service = create_service;
+ miner_class->query = query_facebook;
+}
+
+static void
+gd_facebook_miner_init (GdFacebookMiner *miner)
+{
+}
+
+static GObject *
+create_service (GdMiner *self, GoaObject *object)
+{
+ GFBGraphGoaAuthorizer *authorizer;
+
+ authorizer = gfbgraph_goa_authorizer_new (object);
+
+ if (GFBGRAPH_IS_GOA_AUTHORIZER (authorizer)) {
+ g_debug ("GFBGraph GOA authorizer created");
+ g_object_ref (authorizer);
+ }
+
+ return G_OBJECT (authorizer);
+}
+
+static void
+query_facebook (GdAccountMinerJob *job, GError **error)
+{
+ GFBGraphUser *me;
+ gchar *me_name;
+ GList *albums = NULL;
+
+ me = gfbgraph_user_get_me (GFBGRAPH_AUTHORIZER (job->service), error);
+ if (*error != NULL) {
+ g_warning ("Error getting \"me\" user");
+ goto out;
+ }
+
+ g_object_get (me, "name", &me_name, NULL);
+
+ albums = gfbgraph_user_get_albums (me, GFBGRAPH_AUTHORIZER (job->service), error);
+ if (*error != NULL) {
+ g_warning ("Error getting albums");
+ goto out;
+ }
+
+ while (albums) {
+ GFBGraphAlbum *album;
+
+ album = albums->data;
+ account_miner_job_lookup_album (job, album, (const gchar*) me_name, error);
+
+ albums = g_list_next (albums);
+ }
+
+ out:
+ if (me_name)
+ g_free (me_name);
+ g_clear_object (&me);
+}
+
+/* TODO: Until GFBGraph parse the "from" node section, we require the album creator (generally the logged
user) */
+static gboolean
+account_miner_job_lookup_album (GdAccountMinerJob *job, GFBGraphAlbum *album, const gchar *creator, GError
**error)
+{
+ gchar *album_id;
+ gchar *album_name;
+ gchar *album_description;
+ gchar *album_link;
+ gchar *album_created_time;
+ gchar *identifier;
+ const gchar *class = "nfo:DataContainer";
+ gchar *resource = NULL;
+ gboolean resource_exists;
+ gchar *contact_resource;
+ GList *photos = NULL;
+
+ g_object_get (album,
+ "id", &album_id,
+ "link", &album_link,
+ "name", &album_name,
+ "description", &album_description,
+ "created_time", &album_created_time,
+ NULL);
+
+ identifier = g_strdup_printf ("gd:collection:facebook:%s", album_id);
+
+ /* remove from the list of the previous resources */
+ g_hash_table_remove (job->previous_resources, identifier);
+
+ resource = gd_miner_tracker_sparql_connection_ensure_resource (job->connection,
+ job->cancellable, error,
+ &resource_exists,
+ job->datasource_urn, identifier,
+ "nfo:RemoteDataObject", class,
+ NULL);
+
+ if (*error != NULL)
+ goto out;
+
+ gd_miner_tracker_update_datasource (job->connection, job->datasource_urn,
+ resource_exists, identifier, resource,
+ job->cancellable, error);
+
+ if (*error != NULL)
+ goto out;
+
+ // insert album url
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nie:url", album_link);
+ if (*error != NULL)
+ goto out;
+
+ // insert description
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nie:description", album_description);
+ if (*error != NULL)
+ goto out;
+
+ // insert filename
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nfo:fileName", album_name);
+ if (*error != NULL)
+ goto out;
+
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nie:contentCreated", album_created_time);
+ if (*error != NULL)
+ goto out;
+
+ contact_resource = gd_miner_tracker_utils_ensure_contact_resource (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, creator);
+ if (*error != NULL)
+ goto out;
+
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nco:creator", contact_resource);
+ g_free (contact_resource);
+ if (*error != NULL)
+ goto out;
+
+ /* Album photos */
+ photos = gfbgraph_node_get_connection_nodes (GFBGRAPH_NODE (album), GFBGRAPH_TYPE_PHOTO,
+ GFBGRAPH_AUTHORIZER (job->service),
+ error);
+ if (*error != NULL)
+ goto out;
+
+ while (photos) {
+ GFBGraphPhoto *photo;
+
+ photo = GFBGRAPH_PHOTO (photos->data);
+ account_miner_job_process_photo (job, photo, (const gchar*) identifier, creator, error);
+
+ photos = g_list_next (photos);
+ }
+
+ out:
+ g_free (album_id);
+ g_free (album_name);
+ g_free (album_link);
+ g_free (album_description);
+ g_free (album_created_time);
+ g_free (identifier);
+ g_free (resource);
+
+ if (*error != NULL)
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean
+account_miner_job_process_photo (GdAccountMinerJob *job, GFBGraphPhoto *photo, const gchar
*parent_identifier, const gchar *creator, GError **error)
+{
+ gchar *photo_id;
+ gchar *photo_name;
+ gchar *photo_link;
+ gchar *photo_created_time;
+ gchar *identifier;
+ const gchar *class = "nmm:Photo";
+ gchar *resource = NULL;
+ gboolean resource_exists;
+ gchar *contact_resource;
+ gchar *parent_resource_urn;
+
+ g_object_get (photo,
+ "id", &photo_id,
+ "name", &photo_name,
+ "link", &photo_link,
+ "created_time", &photo_created_time,
+ NULL);
+
+ identifier = g_strdup_printf ("facebook:%s", photo_id);
+
+ /* remove from the list of the previous resources */
+ g_hash_table_remove (job->previous_resources, identifier);
+
+ resource = gd_miner_tracker_sparql_connection_ensure_resource (job->connection,
+ job->cancellable, error,
+ &resource_exists,
+ job->datasource_urn, identifier,
+ "nfo:RemoteDataObject", class, NULL);
+ if (*error != NULL)
+ goto out;
+
+ // insert url
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nie:url", photo_link);
+ if (*error != NULL)
+ goto out;
+
+ /* link with the album */
+ parent_resource_urn = gd_miner_tracker_sparql_connection_ensure_resource (job->connection,
+ job->cancellable, error,
+ NULL,
+ job->datasource_urn,
parent_identifier,
+ "nfo:RemoteDataObject",
"nfo:DataContainer", NULL);
+ if (*error != NULL)
+ goto out;
+
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nie:isPartOf", parent_resource_urn);
+ g_free (parent_resource_urn);
+ if (*error != NULL)
+ goto out;
+
+ /* insert filename */
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nfo:fileName", photo_name);
+ if (*error != NULL)
+ goto out;
+
+ /* created time */
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nie:contentCreated", photo_created_time);
+ if (*error != NULL)
+ goto out;
+
+ /* Creator */
+ contact_resource = gd_miner_tracker_utils_ensure_contact_resource (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, creator);
+ if (*error != NULL)
+ goto out;
+
+ gd_miner_tracker_sparql_connection_insert_or_replace_triple (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nco:creator", contact_resource);
+ g_free (contact_resource);
+ if (*error != NULL)
+ goto out;
+
+ out:
+ g_free (photo_id);
+ g_free (photo_name);
+ g_free (photo_link);
+ g_free (photo_created_time);
+ g_free (identifier);
+ g_free (resource);
+ g_free (contact_resource);
+
+ if (*error != NULL)
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/src/miner/gd-facebook-miner.h b/src/miner/gd-facebook-miner.h
new file mode 100644
index 0000000..4cd6537
--- /dev/null
+++ b/src/miner/gd-facebook-miner.h
@@ -0,0 +1,70 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2; -*- */
+/*
+ * Copyright (c) 2013 The GNOME Foundation.
+ *
+ * Gnome Documents 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.
+ *
+ * Gnome Documents 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 Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Álvaro Peña <alvaropg gmail com>
+ */
+
+#ifndef __GD_FACEBOOK_MINER_H__
+#define __GD_FACEBOOK_MINER_H__
+
+#include <gio/gio.h>
+#include "gd-miner.h"
+
+G_BEGIN_DECLS
+
+#define GD_TYPE_FACEBOOK_MINER gd_facebook_miner_get_type()
+
+#define GD_FACEBOOK_MINER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ GD_TYPE_FACEBOOK_MINER, GdFacebookMiner))
+
+#define GD_FACEBOOK_MINER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ GD_TYPE_FACEBOOK_MINER, GdFacebookMinerClass))
+
+#define GD_IS_FACEBOOK_MINER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ GD_TYPE_FACEBOOK_MINER))
+
+#define GD_IS_FACEBOOK_MINER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ GD_TYPE_FACEBOOK_MINER))
+
+#define GD_FACEBOOK_MINER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ GD_TYPE_FACEBOOK_MINER, GdFacebookMinerClass))
+
+typedef struct _GdFacebookMiner GdFacebookMiner;
+typedef struct _GdFacebookMinerClass GdFacebookMinerClass;
+typedef struct _GdFacebookMinerPrivate GdFacebookMinerPrivate;
+
+struct _GdFacebookMiner {
+ GdMiner parent;
+
+ GdFacebookMinerPrivate *priv;
+};
+
+struct _GdFacebookMinerClass {
+ GdMinerClass parent_class;
+};
+
+GType gd_facebook_miner_get_type(void);
+
+G_END_DECLS
+
+#endif /* __GD_FACEBOOK_MINER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]