[gnome-photos/wip/rishi/share-point: 5/10] Add Google share point
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/share-point: 5/10] Add Google share point
- Date: Sat, 23 Jul 2016 14:49:03 +0000 (UTC)
commit c5c0f58599a3dc1777221284b687026ac7b8ce1b
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 | 279 +++++++++++++++++++++++++++++++++++++++
src/photos-google-share-point.h | 45 +++++++
src/photos-utils.c | 3 +
4 files changed, 329 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ced64c9..5f06b5d 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..36e0c35
--- /dev/null
+++ b/src/photos-google-share-point.c
@@ -0,0 +1,279 @@
+/*
+ * 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 "photos-base-item.h"
+#include "photos-google-share-point.h"
+#include "photos-share-point.h"
+#include "photos-source.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));
+
+
+typedef struct _PhotosGoogleSharePointShareData PhotosGoogleSharePointShareData;
+
+struct _PhotosGoogleSharePointShareData
+{
+ GDataUploadStream *stream;
+ PhotosBaseItem *item;
+};
+
+
+static PhotosGoogleSharePointShareData *
+photos_google_share_point_share_data_new (PhotosBaseItem *item)
+{
+ PhotosGoogleSharePointShareData *data;
+
+ data = g_slice_new0 (PhotosGoogleSharePointShareData);
+ data->item = g_object_ref (item);
+
+ return data;
+}
+
+
+static void
+photos_google_share_point_share_data_free (PhotosGoogleSharePointShareData *data)
+{
+ g_clear_object (&data->stream);
+ g_clear_object (&data->item);
+ g_slice_free (PhotosGoogleSharePointShareData, data);
+}
+
+
+static void
+photos_google_share_point_share_save_to_stream (GObject *source_object, GAsyncResult *res, gpointer
user_data)
+{
+ PhotosGoogleSharePoint *self;
+ GError *error;
+ GTask *task = G_TASK (user_data);
+ GDataPicasaWebFile *file_entry = NULL;
+ PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+ PhotosGoogleSharePointShareData *data;
+
+ self = PHOTOS_GOOGLE_SHARE_POINT (g_task_get_source_object (task));
+ data = (PhotosGoogleSharePointShareData *) g_task_get_task_data (task);
+
+ error = NULL;
+ if (!photos_base_item_save_to_stream_finish (item, res, &error))
+ {
+ g_message ("save to stream: %s (%s)", error->message, g_quark_to_string (error->domain));
+ g_task_return_error (task, error);
+ goto out;
+ }
+
+ error = NULL;
+ file_entry = gdata_picasaweb_service_finish_file_upload (GDATA_PICASAWEB_SERVICE (self->service),
+ data->stream,
+ &error);
+ if (error != NULL)
+ {
+ g_message ("finish file upload: %s", error->message);
+ g_task_return_error (task, error);
+ goto out;
+ }
+
+ g_task_return_boolean (task, TRUE);
+
+ out:
+ g_clear_object (&file_entry);
+ g_object_unref (task);
+}
+
+
+static void
+photos_google_share_point_share_refresh_authorization (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ PhotosGoogleSharePoint *self;
+ GCancellable *cancellable;
+ GError *error;
+ GTask *task = G_TASK (user_data);
+ GDataAuthorizer *authorizer = GDATA_AUTHORIZER (source_object);
+ GDataPicasaWebFile *file_entry = NULL;
+ GDataUploadStream *stream = NULL;
+ PhotosGoogleSharePointShareData *data;
+ const gchar *filename;
+ const gchar *mime_type;
+ const gchar *name;
+
+ self = PHOTOS_GOOGLE_SHARE_POINT (g_task_get_source_object (task));
+ cancellable = g_task_get_cancellable (task);
+ data = (PhotosGoogleSharePointShareData *) g_task_get_task_data (task);
+
+ error = NULL;
+ if (!gdata_authorizer_refresh_authorization_finish (authorizer, res, &error))
+ {
+ g_message ("refresh authorization: %s", error->message);
+ g_task_return_error (task, error);
+ goto out;
+ }
+
+ file_entry = gdata_picasaweb_file_new (NULL);
+ name = photos_base_item_get_name_with_fallback (data->item);
+ gdata_entry_set_title (GDATA_ENTRY (file_entry), name);
+
+ filename = photos_base_item_get_filename (data->item);
+ mime_type = photos_base_item_get_mime_type (data->item);
+
+ error = NULL;
+ stream = gdata_picasaweb_service_upload_file (self->service,
+ NULL,
+ file_entry,
+ filename,
+ mime_type,
+ cancellable,
+ &error);
+ if (error != NULL)
+ {
+ g_message ("upload file: %s", error->message);
+ g_task_return_error (task, error);
+ goto out;
+ }
+
+ g_assert_null (data->stream);
+ data->stream = g_object_ref (stream);
+
+ photos_base_item_save_to_stream_async (data->item,
+ G_OUTPUT_STREAM (stream),
+ 1.0,
+ cancellable,
+ photos_google_share_point_share_save_to_stream,
+ g_object_ref (task));
+
+ out:
+ g_clear_object (&file_entry);
+ g_clear_object (&stream);
+ g_object_unref (task);
+}
+
+
+static void
+photos_google_share_point_share_async (PhotosSharePoint *share_point,
+ PhotosBaseItem *item,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ PhotosGoogleSharePoint *self = PHOTOS_GOOGLE_SHARE_POINT (share_point);
+ GTask *task;
+ PhotosGoogleSharePointShareData *data;
+
+ data = photos_google_share_point_share_data_new (item);
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_google_share_point_share_async);
+ g_task_set_task_data (task, data, (GDestroyNotify) photos_google_share_point_share_data_free);
+
+ gdata_authorizer_refresh_authorization_async (GDATA_AUTHORIZER (self->authorizer),
+ cancellable,
+ photos_google_share_point_share_refresh_authorization,
+ g_object_ref (task));
+
+ g_object_unref (task);
+}
+
+
+static gboolean
+photos_google_share_point_share_finish (PhotosSharePoint *share_point, GAsyncResult *res, GError **error)
+{
+ PhotosGoogleSharePoint *self = PHOTOS_GOOGLE_SHARE_POINT (share_point);
+ GTask *task;
+
+ g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+ task = G_TASK (res);
+
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_google_share_point_share_async, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return g_task_propagate_boolean (task, error);
+}
+
+
+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_init (PhotosGoogleSharePoint *self)
+{
+}
+
+
+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;
+ share_point_class->share_async = photos_google_share_point_share_async;
+ share_point_class->share_finish = photos_google_share_point_share_finish;
+}
diff --git a/src/photos-google-share-point.h b/src/photos-google-share-point.h
new file mode 100644
index 0000000..97b352c
--- /dev/null
+++ b/src/photos-google-share-point.h
@@ -0,0 +1,45 @@
+/*
+ * 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>
+
+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))
+
+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 ab4dfba..2d2e56e 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"
@@ -840,6 +841,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]