[gnome-photos/wip/rishi/share-point: 4/9] Add Google share point
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/share-point: 4/9] Add Google share point
- Date: Wed, 20 Jul 2016 09:29:44 +0000 (UTC)
commit c0e1ca71b476bcda34318d507748bfe64e57692a
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 | 195 +++++++++++++++++++++++++++++++++++++++
src/photos-google-share-point.h | 45 +++++++++
src/photos-utils.c | 3 +
4 files changed, 245 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..e080059
--- /dev/null
+++ b/src/photos-google-share-point.c
@@ -0,0 +1,195 @@
+/*
+ * 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-filterable.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));
+
+
+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 gboolean
+photos_google_share_point_share_image (PhotosGoogleSharePoint *self,
+ PhotosBaseItem *item,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GDataPicasaWebFile *uploaded_file_entry = NULL;
+ GDataPicasaWebFile *file_entry = NULL;
+ GDataUploadStream *upload_stream = NULL;
+ GFileInputStream *file_stream = NULL;
+ GFile *file_data = NULL;
+ gboolean ret_val = FALSE;
+ const gchar *file_name;
+ const gchar *mime_type;
+ const gchar *name;
+
+ 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);
+
+ upload_stream = gdata_picasaweb_service_upload_file (self->service,
+ NULL,
+ file_entry,
+ file_name,
+ mime_type,
+ cancellable,
+ error);
+ if (upload_stream == NULL)
+ goto out;
+
+ file_data = g_file_new_for_uri (photos_base_item_get_uri (item));
+
+ file_stream = g_file_read (file_data, cancellable, error);
+ if (file_stream == NULL)
+ goto out;
+
+ if (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,
+ error) == -1)
+ goto out;
+
+ uploaded_file_entry = gdata_picasaweb_service_finish_file_upload (GDATA_PICASAWEB_SERVICE (self->service),
+ upload_stream,
+ error);
+ if (uploaded_file_entry == NULL)
+ goto out;
+
+ ret_val = TRUE;
+
+ out:
+ g_clear_object (&file_data);
+ g_clear_object (&file_entry);
+ g_clear_object (&file_stream);
+ g_clear_object (&uploaded_file_entry);
+ g_clear_object (&upload_stream);
+ return ret_val;
+}
+
+
+static gboolean
+photos_google_share_point_share (PhotosSharePoint *share_point,
+ PhotosBaseItem *item,
+ GCancellable *cancellable,
+ GError **error)
+{
+ PhotosGoogleSharePoint *self = PHOTOS_GOOGLE_SHARE_POINT (share_point);
+ gboolean ret_val = FALSE;
+
+ g_return_val_if_fail (PHOTOS_IS_GOOGLE_SHARE_POINT (self), FALSE);
+
+ if (!gdata_authorizer_refresh_authorization (GDATA_AUTHORIZER (self->authorizer), cancellable, error))
+ goto out;
+
+ if (!photos_google_share_point_share_image (self, item, cancellable, error))
+ goto out;
+
+ ret_val = TRUE;
+
+ out:
+ return ret_val;
+}
+
+
+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;
+ 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..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]