[gnome-photos/wip/uajain/de_dup: 4/11] Add Google share point
- From: Umang Jain <uajain src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/uajain/de_dup: 4/11] Add Google share point
- Date: Wed, 27 Jul 2016 05:37:46 +0000 (UTC)
commit cc6eacc5c46b97055c05de5426c1d7d5a5ba71e3
Author: Umang Jain <mailumangjain gmail com>
Date: Fri Jul 15 18:42:40 2016 +0530
Add Google share point
https://bugzilla.gnome.org/show_bug.cgi?id=751181
src/Makefile.am | 2 +
src/photos-google-share-point.c | 222 +++++++++++++++++++++++++++++++++++++++
src/photos-google-share-point.h | 59 ++++++++++
src/photos-utils.c | 3 +
4 files changed, 286 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 212e1b1..48305f8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -96,6 +96,8 @@ gnome_photos_SOURCES = \
photos-flickr-item.h \
photos-google-item.c \
photos-google-item.h \
+ photos-google-share-point.c \
+ photos-google-share-point.h \
photos-header-bar.c \
photos-header-bar.h \
photos-icons.h \
diff --git a/src/photos-google-share-point.c b/src/photos-google-share-point.c
new file mode 100644
index 0000000..bf89f90
--- /dev/null
+++ b/src/photos-google-share-point.c
@@ -0,0 +1,222 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 Umang Jain
+ *
+ * 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.
+ */
+
+
+#include "config.h"
+
+#include <gio/gio.h>
+#include <gdata/gdata.h>
+#include <gdata/gdata-goa-authorizer.h>
+
+#include "photos-base-item.h"
+#include "photos-filterable.h"
+#include "photos-google-share-point.h"
+#include "photos-share-point.h"
+#include "photos-utils.h"
+
+struct _PhotosGoogleSharePoint
+{
+ PhotosSharePoint parent_instance;
+ GDataGoaAuthorizer *authorizer;
+ GDataPicasaWebService *service;
+};
+
+struct _PhotosGoogleSharePointClass
+{
+ PhotosSharePointClass parent_class;
+};
+
+
+G_DEFINE_TYPE_WITH_CODE (PhotosGoogleSharePoint, photos_google_share_point, PHOTOS_TYPE_SHARE_POINT,
+ photos_utils_ensure_extension_points ();
+ g_io_extension_point_implement (PHOTOS_SHARE_POINT_EXTENSION_POINT_NAME,
+ g_define_type_id,
+ "google",
+ 0));
+
+static void
+photos_google_share_point_init (PhotosGoogleSharePoint *self)
+{
+}
+
+
+static void
+photos_google_share_point_constructed (GObject *object)
+{
+ PhotosGoogleSharePoint *self = PHOTOS_GOOGLE_SHARE_POINT (object);
+ PhotosSource *source;
+ GoaObject *goa_object;
+
+ G_OBJECT_CLASS (photos_google_share_point_parent_class)->constructed (object);
+
+ source = photos_share_point_get_source (PHOTOS_SHARE_POINT (object));
+ goa_object = photos_source_get_goa_object (source);
+ self->authorizer = gdata_goa_authorizer_new (goa_object);
+ self->service = gdata_picasaweb_service_new (GDATA_AUTHORIZER (self->authorizer));
+}
+
+
+static void
+photos_google_share_point_dispose (GObject *object)
+{
+ PhotosGoogleSharePoint *self = PHOTOS_GOOGLE_SHARE_POINT (object);
+
+ g_clear_object (&self->authorizer);
+ g_clear_object (&self->service);
+
+ G_OBJECT_CLASS (photos_google_share_point_parent_class)->dispose (object);
+}
+
+
+static void
+photos_google_share_point_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (photos_google_share_point_parent_class)->finalize (object);
+}
+
+
+static void
+photos_google_share_point_share_image (PhotosGoogleSharePoint *self, GCancellable *cancellable,
PhotosBaseItem *item, GError **error)
+{
+ GDataPicasaWebFile *uploaded_file_entry;
+ GDataPicasaWebFile *file_entry;
+ GDataUploadStream *upload_stream;
+ GFileInputStream *file_stream;
+ GFileInfo *file_info;
+ GFile *file_data;
+ GError *local_error;
+ const gchar *file_name;
+ const gchar *mime_type;
+ const gchar *name;
+
+ file_data = g_file_new_for_uri (photos_base_item_get_uri (item));
+ file_info = g_file_query_info (file_data, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+
+ file_entry = gdata_picasaweb_file_new (NULL);
+ name = photos_base_item_get_name_with_fallback (item);
+ gdata_entry_set_title (GDATA_ENTRY (file_entry), name);
+
+ file_name = photos_base_item_get_filename (item);
+ mime_type = photos_base_item_get_mime_type (item);
+
+ local_error = NULL;
+ upload_stream = gdata_picasaweb_service_upload_file (self->service,
+ NULL,
+ file_entry,
+ file_name,
+ mime_type,
+ cancellable,
+ &local_error);
+ if (local_error != NULL)
+ {
+ g_propagate_error (error, local_error);
+ goto out;
+ }
+
+ local_error = NULL;
+ file_stream = g_file_read (file_data, cancellable, &local_error);
+ if (local_error != NULL)
+ {
+ g_propagate_error (error, local_error);
+ goto out;
+ }
+
+ local_error = NULL;
+ g_output_stream_splice (G_OUTPUT_STREAM (upload_stream),
+ G_INPUT_STREAM (file_stream),
+ G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+ cancellable,
+ &local_error);
+
+ if (local_error != NULL)
+ {
+ g_propagate_error (error, local_error);
+ goto out;
+ }
+
+ local_error = NULL;
+ uploaded_file_entry = gdata_picasaweb_service_finish_file_upload (GDATA_PICASAWEB_SERVICE (self->service),
+ upload_stream,
+ &local_error);
+ if (local_error != NULL)
+ {
+ g_propagate_error (error, local_error);
+ goto out;
+ }
+
+out:
+ g_clear_object (&file_data);
+ g_clear_object (&file_info);
+ g_clear_object (&file_entry);
+ g_clear_object (&file_stream);
+ g_clear_object (&uploaded_file_entry);
+ g_clear_object (&upload_stream);
+}
+
+
+static gboolean
+photos_google_share_point_share (PhotosSharePoint *share_point, PhotosBaseItem *item, GCancellable
*cancellable, GError **error)
+{
+ PhotosGoogleSharePoint *self = PHOTOS_GOOGLE_SHARE_POINT (share_point);
+ GError *local_error;
+ gboolean result = FALSE;
+
+ g_return_val_if_fail (PHOTOS_IS_GOOGLE_SHARE_POINT (self), FALSE);
+
+ if (!gdata_service_is_authorized (GDATA_SERVICE (self->service)))
+ goto out;
+
+ local_error = NULL;
+ gdata_authorizer_refresh_authorization (GDATA_AUTHORIZER (self->authorizer), cancellable, &local_error);
+ if (local_error != NULL)
+ {
+ g_propagate_error (error, local_error);
+ goto out;
+ }
+
+ local_error = NULL;
+ photos_google_share_point_share_image (self, cancellable, item, &local_error);
+ if (local_error != NULL)
+ {
+ g_propagate_error (error, local_error);
+ goto out;
+ }
+
+ result = TRUE;
+
+out:
+ return result;
+}
+
+
+static void
+photos_google_share_point_class_init (PhotosGoogleSharePointClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ PhotosSharePointClass *share_point_class = PHOTOS_SHARE_POINT_CLASS (class);
+
+ object_class->constructed = photos_google_share_point_constructed;
+ object_class->dispose = photos_google_share_point_dispose;
+ object_class->finalize = photos_google_share_point_finalize;
+ share_point_class->share = photos_google_share_point_share;
+}
diff --git a/src/photos-google-share-point.h b/src/photos-google-share-point.h
new file mode 100644
index 0000000..a235349
--- /dev/null
+++ b/src/photos-google-share-point.h
@@ -0,0 +1,59 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 Umang Jain
+ *
+ * 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.
+ */
+
+#ifndef PHOTOS_GOOGLE_SHARE_POINT_H
+#define PHOTOS_GOOGLE_SHARE_POINT_H
+
+#include <glib-object.h>
+
+#include "photos-source.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_GOOGLE_SHARE_POINT (photos_google_share_point_get_type ())
+
+#define PHOTOS_GOOGLE_SHARE_POINT(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_GOOGLE_SHARE_POINT, PhotosGoogleSharePoint))
+
+#define PHOTOS_IS_GOOGLE_SHARE_POINT(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_GOOGLE_SHARE_POINT))
+
+#define PHOTOS_IS_GOOGLE_SHARE_POINT_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_GOOGLE_SHARE_POINT))
+
+#define PHOTOS_GOOGLE_SHARE_POINT_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_GOOGLE_SHARE_POINT, PhotosGoogleSharePointClass))
+
+#define PHOTOS_GOOGLE_SHARE_POINT_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_GOOGLE_SHARE_POINT, PhotosGoogleSharePointClass))
+
+typedef struct _PhotosGoogleSharePoint PhotosGoogleSharePoint;
+typedef struct _PhotosGoogleSharePointClass PhotosGoogleSharePointClass;
+
+GType photos_google_share_point_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_GOOGLE_SHARE_POINT_H */
diff --git a/src/photos-utils.c b/src/photos-utils.c
index cb21e92..c139977 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -40,6 +40,7 @@
#include "photos-facebook-item.h"
#include "photos-flickr-item.h"
#include "photos-google-item.h"
+#include "photos-google-share-point.h"
#include "photos-local-item.h"
#include "photos-media-server-item.h"
#include "photos-operation-insta-curve.h"
@@ -839,6 +840,8 @@ photos_utils_ensure_builtins (void)
g_type_ensure (PHOTOS_TYPE_TRACKER_OVERVIEW_CONTROLLER);
g_type_ensure (PHOTOS_TYPE_TRACKER_SEARCH_CONTROLLER);
+ g_type_ensure (PHOTOS_TYPE_GOOGLE_SHARE_POINT);
+
g_once_init_leave (&once_init_value, 1);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]