[gnome-photos] Add PhotosGoogleItem
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Add PhotosGoogleItem
- Date: Tue, 5 Aug 2014 15:42:15 +0000 (UTC)
commit a581f73b17edf4522d70db6d99cb47ae22751a0f
Author: Saurav Agarwalla <saurav agarwalla92 gmail com>
Date: Thu Jul 24 20:55:24 2014 +0530
Add PhotosGoogleItem
https://bugzilla.gnome.org/show_bug.cgi?id=711563
configure.ac | 2 +
src/Makefile.am | 4 +
src/photos-application.c | 12 ++
src/photos-google-item.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++
src/photos-google-item.h | 73 +++++++++++
src/photos-utils.c | 6 +-
6 files changed, 407 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b7582e8..8d62e1d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,7 @@ AC_SUBST(LIBM)
GLIB_GSETTINGS
EXEMPI_MIN_VERSION=1.99.5
+GDATA_MIN_VERSION=0.15.2
GFBGRAPH_MIN_VERSION=0.2.1
GLIB_MIN_VERSION=2.39.3
GOA_MIN_VERSION=3.8.0
@@ -86,6 +87,7 @@ AC_DEFINE([HAVE_CAIRO_GOBJECT], [], [We want gegl-gtk to use the cairo-gobject c
PKG_CHECK_MODULES(EXEMPI, [exempi-2.0 >= $EXEMPI_MIN_VERSION])
PKG_CHECK_MODULES(GFBGRAPH, [libgfbgraph-0.2 >= $GFBGRAPH_MIN_VERSION])
+PKG_CHECK_MODULES(GDATA, [libgdata >= $GDATA_MIN_VERSION])
PKG_CHECK_MODULES(GEGL, [gegl-0.2])
PKG_CHECK_MODULES(GDK_PIXBUF, [gdk-pixbuf-2.0])
PKG_CHECK_MODULES(GLIB, [glib-2.0 >= $GLIB_MIN_VERSION])
diff --git a/src/Makefile.am b/src/Makefile.am
index 8a04c55..30f6eaf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -118,6 +118,8 @@ gnome_photos_SOURCES = \
photos-filterable.h \
photos-flickr-item.c \
photos-flickr-item.h \
+ photos-google-item.c \
+ photos-google-item.h \
photos-header-bar.c \
photos-header-bar.h \
photos-icons.h \
@@ -266,6 +268,7 @@ AM_CPPFLAGS = \
$(BABL_CFLAGS) \
$(CAIRO_CFLAGS) \
$(EXEMPI_CFLAGS) \
+ $(GDATA_CFLAGS) \
$(GDK_PIXBUF_CFLAGS) \
$(GFBGRAPH_CFLAGS) \
$(GEGL_CFLAGS) \
@@ -293,6 +296,7 @@ gnome_photos_LDADD = \
$(BABL_LIBS) \
$(CAIRO_LIBS) \
$(EXEMPI_LIBS) \
+ $(GDATA_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(GFBGRAPH_LIBS) \
$(GEGL_LIBS) \
diff --git a/src/photos-application.c b/src/photos-application.c
index 57e465b..993d543 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -72,6 +72,7 @@ struct _PhotosApplicationPrivate
GSimpleAction *remote_display_action;
GomMiner *facebook_miner;
GomMiner *flickr_miner;
+ GomMiner *google_miner;
GtkWidget *main_window;
PhotosBaseManager *item_mngr;
PhotosCameraCache *camera_cache;
@@ -455,6 +456,9 @@ photos_application_refresh_miners (PhotosApplication *self)
if (photos_source_manager_has_provider_type (PHOTOS_SOURCE_MANAGER (priv->state->src_mngr), "flickr"))
photos_application_refresh_miner_now (self, priv->flickr_miner);
+
+ if (photos_source_manager_has_provider_type (PHOTOS_SOURCE_MANAGER (priv->state->src_mngr), "google"))
+ photos_application_refresh_miner_now (self, priv->google_miner);
}
@@ -821,6 +825,13 @@ photos_application_startup (GApplication *application)
NULL,
NULL);
+ priv->google_miner = gom_miner_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.gnome.OnlineMiners.GData",
+ "/org/gnome/OnlineMiners/GData",
+ NULL,
+ NULL);
+
tracker_extract_priority_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.Tracker1.Miner.Extract",
@@ -958,6 +969,7 @@ photos_application_dispose (GObject *object)
g_clear_object (&priv->set_bg_action);
g_clear_object (&priv->facebook_miner);
g_clear_object (&priv->flickr_miner);
+ g_clear_object (&priv->google_miner);
g_clear_object (&priv->item_mngr);
g_clear_object (&priv->camera_cache);
g_clear_object (&priv->mode_cntrlr);
diff --git a/src/photos-google-item.c b/src/photos-google-item.c
new file mode 100644
index 0000000..d585a7e
--- /dev/null
+++ b/src/photos-google-item.c
@@ -0,0 +1,311 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Saurav Agarwalla
+ *
+ * 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 <gdata/gdata.h>
+#include <gio/gio.h>
+#include <glib.h>
+#include <libgnome-desktop/gnome-desktop-thumbnail.h>
+
+#include "photos-base-manager.h"
+#include "photos-google-item.h"
+#include "photos-search-context.h"
+#include "photos-source.h"
+#include "photos-utils.h"
+
+
+struct _PhotosGoogleItemPrivate
+{
+ PhotosBaseManager *src_mngr;
+};
+
+
+G_DEFINE_TYPE_WITH_CODE (PhotosGoogleItem, photos_google_item, PHOTOS_TYPE_BASE_ITEM,
+ G_ADD_PRIVATE (PhotosGoogleItem)
+ photos_utils_ensure_extension_points ();
+ g_io_extension_point_implement (PHOTOS_BASE_ITEM_EXTENSION_POINT_NAME,
+ g_define_type_id,
+ "google",
+ 0));
+
+
+static GDataEntry *
+photos_google_get_picasaweb_file (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
+{
+ PhotosGoogleItemPrivate *priv = PHOTOS_GOOGLE_ITEM (item)->priv;
+ PhotosSource *source;
+ GDataAuthorizationDomain *authorization_domain;
+ GDataEntry *entry;
+ GDataGoaAuthorizer *authorizer;
+ GDataPicasaWebQuery *query;
+ GDataPicasaWebService *service;
+ const gchar *identifier;
+ const gchar *resource_urn;
+
+ 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 = gdata_goa_authorizer_new (photos_source_get_goa_object (source));
+ identifier = photos_base_item_get_identifier (item) + strlen ("google:picasaweb:");
+ service = gdata_picasaweb_service_new (GDATA_AUTHORIZER (authorizer));
+ authorization_domain = gdata_picasaweb_service_get_primary_authorization_domain ();
+
+ query = gdata_picasaweb_query_new (NULL);
+ gdata_picasaweb_query_set_image_size (query, "d");
+
+ entry = gdata_service_query_single_entry (GDATA_SERVICE (service),
+ authorization_domain,
+ identifier,
+ GDATA_QUERY (query),
+ GDATA_TYPE_PICASAWEB_FILE,
+ cancellable,
+ error);
+
+ g_object_unref (service);
+ g_object_unref (authorizer);
+ g_object_unref (query);
+
+ return entry;
+}
+
+
+static gboolean
+photos_google_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
+{
+ GDataEntry *entry = NULL;
+ GList *l;
+ GList *thumbnails;
+ GDataMediaThumbnail *thumbnail = NULL;
+ gchar *local_path = NULL;
+ gchar *local_dir = NULL;
+ GFile *local_file = NULL;
+ GFile *remote_file = NULL;
+ gboolean ret_val = FALSE;
+ const gchar *thumbnail_uri;
+ const gchar *uri;
+ guint max_width = 0;
+ guint current_width;
+
+ entry = photos_google_get_picasaweb_file (item, cancellable, error);
+ if (entry == NULL)
+ goto out;
+
+ thumbnails = gdata_picasaweb_file_get_thumbnails (GDATA_PICASAWEB_FILE (entry));
+ if (thumbnails == NULL)
+ {
+ g_set_error (error, PHOTOS_ERROR, 0, "Failed to find an image for the thumbnail");
+ goto out;
+ }
+
+ for (l = thumbnails; l != NULL; l = l->next)
+ {
+ current_width = gdata_media_thumbnail_get_width (GDATA_MEDIA_THUMBNAIL (l->data));
+ if (current_width > max_width)
+ {
+ max_width = current_width;
+ thumbnail = GDATA_MEDIA_THUMBNAIL (l->data);
+ }
+ }
+
+ thumbnail_uri = gdata_media_thumbnail_get_uri (thumbnail);
+ remote_file = g_file_new_for_uri (thumbnail_uri);
+
+ uri = photos_base_item_get_uri (item);
+ local_path = gnome_desktop_thumbnail_path_for_uri (uri, GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
+ 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 Google to %s", thumbnail_uri, local_path);
+ if (!g_file_copy (remote_file,
+ local_file,
+ G_FILE_COPY_ALL_METADATA | G_FILE_COPY_OVERWRITE,
+ cancellable,
+ NULL,
+ NULL,
+ error))
+ goto out;
+
+ ret_val = TRUE;
+
+ out:
+ g_free (local_path);
+ g_free (local_dir);
+ g_clear_object (&local_file);
+ g_clear_object (&remote_file);
+ g_clear_object (&entry);
+ return ret_val;
+}
+
+
+static gchar *
+photos_google_item_download (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
+{
+ GDataEntry *entry = NULL;
+ GFile *local_file = NULL;
+ GFile *remote_file = NULL;
+ const gchar *cache_dir;
+ const gchar *uri;
+ gchar *local_dir = NULL;
+ gchar *local_filename = NULL;
+ gchar *local_path = NULL;
+ gchar *ret_val = NULL;
+
+ entry = photos_google_get_picasaweb_file (item, cancellable, error);
+ if (entry == NULL)
+ goto out;
+
+ uri = gdata_entry_get_content_uri (entry);
+ remote_file = g_file_new_for_uri (uri);
+ cache_dir = g_get_user_cache_dir ();
+
+ local_dir = g_build_filename (cache_dir, PACKAGE_TARNAME, "google", NULL);
+ g_mkdir_with_parents (local_dir, 0700);
+
+ local_filename = g_file_get_basename (remote_file);
+ local_path = g_build_filename (local_dir, local_filename, NULL);
+ local_file = g_file_new_for_path (local_path);
+
+ if (!g_file_test (local_path, G_FILE_TEST_EXISTS))
+ {
+ g_debug ("Downloading %s from Google 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))
+ {
+ g_file_delete (local_file, NULL, NULL);
+ goto out;
+ }
+ }
+
+ ret_val = local_path;
+ local_path = NULL;
+
+ out:
+ g_free (local_path);
+ g_free (local_filename);
+ g_free (local_dir);
+ g_clear_object (&local_file);
+ g_clear_object (&remote_file);
+ g_clear_object (&entry);
+ return ret_val;
+}
+
+
+static GtkWidget *
+photos_google_item_get_source_widget (PhotosBaseItem *item)
+{
+ PhotosGoogleItem *self = PHOTOS_GOOGLE_ITEM (item);
+ GtkWidget *source_widget;
+ const gchar *name;
+
+ name = photos_utils_get_provider_name (self->priv->src_mngr, item);
+ source_widget = gtk_link_button_new_with_label ("https://picasaweb.google.com/", name);
+ gtk_widget_set_halign (source_widget, GTK_ALIGN_START);
+
+ return source_widget;
+}
+
+
+/* NOTE: For private photos, opening the URI in a browser results in a
+ * 'Sorry, that page was not found.' if the user is not logged in with the respective account
+ */
+static void
+photos_google_item_open (PhotosBaseItem *item, GdkScreen *screen, guint32 timestamp)
+{
+ GError *error;
+ const gchar *google_uri;
+
+ google_uri = photos_base_item_get_uri (item);
+
+ error = NULL;
+ gtk_show_uri (screen, google_uri, timestamp, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to show URI %s: %s", google_uri, error->message);
+ g_error_free (error);
+ }
+}
+
+
+static void
+photos_google_item_constructed (GObject *object)
+{
+ PhotosGoogleItem *self = PHOTOS_GOOGLE_ITEM (object);
+ const gchar *name;
+
+ G_OBJECT_CLASS (photos_google_item_parent_class)->constructed (object);
+
+ name = photos_utils_get_provider_name (self->priv->src_mngr, PHOTOS_BASE_ITEM (self));
+ photos_base_item_set_default_app_name (PHOTOS_BASE_ITEM (self), name);
+}
+
+
+static void
+photos_google_item_dispose (GObject *object)
+{
+ PhotosGoogleItem *self = PHOTOS_GOOGLE_ITEM (object);
+
+ g_clear_object (&self->priv->src_mngr);
+
+ G_OBJECT_CLASS (photos_google_item_parent_class)->dispose (object);
+}
+
+
+static void
+photos_google_item_init (PhotosGoogleItem *self)
+{
+ PhotosGoogleItemPrivate *priv;
+ GApplication *app;
+ PhotosSearchContextState *state;
+
+ self->priv = photos_google_item_get_instance_private (self);
+ priv = self->priv;
+
+ app = g_application_get_default ();
+ state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+ priv->src_mngr = g_object_ref (state->src_mngr);
+}
+
+
+static void
+photos_google_item_class_init (PhotosGoogleItemClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ PhotosBaseItemClass *base_item_class = PHOTOS_BASE_ITEM_CLASS (class);
+
+ object_class->constructed = photos_google_item_constructed;
+ object_class->dispose = photos_google_item_dispose;
+ base_item_class->create_thumbnail = photos_google_item_create_thumbnail;
+ base_item_class->download = photos_google_item_download;
+ base_item_class->get_source_widget = photos_google_item_get_source_widget;
+ base_item_class->open = photos_google_item_open;
+}
diff --git a/src/photos-google-item.h b/src/photos-google-item.h
new file mode 100644
index 0000000..90f71d2
--- /dev/null
+++ b/src/photos-google-item.h
@@ -0,0 +1,73 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Saurav Agarwalla
+ *
+ * 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_GOOGLE_ITEM_H
+#define PHOTOS_GOOGLE_ITEM_H
+
+#include "photos-base-item.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_GOOGLE_ITEM (photos_google_item_get_type ())
+
+#define PHOTOS_GOOGLE_ITEM(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_GOOGLE_ITEM, PhotosGoogleItem))
+
+#define PHOTOS_GOOGLE_ITEM_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_GOOGLE_ITEM, PhotosGoogleItemClass))
+
+#define PHOTOS_IS_GOOGLE_ITEM(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_GOOGLE_ITEM))
+
+#define PHOTOS_IS_GOOGLE_ITEM_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_GOOGLE_ITEM))
+
+#define PHOTOS_GOOGLE_ITEM_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_GOOGLE_ITEM, PhotosGoogleItemClass))
+
+typedef struct _PhotosGoogleItem PhotosGoogleItem;
+typedef struct _PhotosGoogleItemClass PhotosGoogleItemClass;
+typedef struct _PhotosGoogleItemPrivate PhotosGoogleItemPrivate;
+
+struct _PhotosGoogleItem
+{
+ PhotosBaseItem parent_instance;
+ PhotosGoogleItemPrivate *priv;
+};
+
+struct _PhotosGoogleItemClass
+{
+ PhotosBaseItemClass parent_class;
+};
+
+GType photos_google_item_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_GOOGLE_ITEM_H */
diff --git a/src/photos-utils.c b/src/photos-utils.c
index e82556a..5e61c98 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -37,6 +37,7 @@
#include "photos-application.h"
#include "photos-facebook-item.h"
#include "photos-flickr-item.h"
+#include "photos-google-item.h"
#include "photos-local-item.h"
#include "photos-query.h"
#include "photos-source.h"
@@ -310,7 +311,9 @@ photos_utils_get_icon_from_cursor (TrackerSparqlCursor *cursor)
identifier = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL);
if (identifier != NULL)
{
- if (g_str_has_prefix (identifier, "facebook:") || g_str_has_prefix (identifier, "flickr:"))
+ if (g_str_has_prefix (identifier, "facebook:") ||
+ g_str_has_prefix (identifier, "flickr:") ||
+ g_str_has_prefix (identifier, "google:"))
is_remote = TRUE;
}
@@ -379,6 +382,7 @@ photos_utils_ensure_builtins (void)
{
g_type_ensure (PHOTOS_TYPE_FACEBOOK_ITEM);
g_type_ensure (PHOTOS_TYPE_FLICKR_ITEM);
+ g_type_ensure (PHOTOS_TYPE_GOOGLE_ITEM);
g_type_ensure (PHOTOS_TYPE_LOCAL_ITEM);
g_once_init_leave (&once_init_value, 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]