[gnome-photos] Extend the SharePoint API to enable notifications on success



commit f2adeadd642e78d8911ae62ef810f1978735a932
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Oct 22 10:36:09 2017 +0200

    Extend the SharePoint API to enable notifications on success
    
    Not every share-point needs to show a notification on success, but some
    do. eg., when sharing via email it is quite obvious from using the mail
    client when the email gets sent, but not so much when sharing to
    Google. Therefore, a needs_notification pure virtual method was added
    to let each SharePoint sub-class indicate if they require a
    notification to be shown on success.
    
    Note that notifications are always meant to be shown on failure.
    
    Notifications can benefit from showing the URI at which the shared
    BaseItem can be accessed. Therefore, photos_share_point_share_finish,
    and the underlying share_finish pure virtual method, now has an output
    parameter to optionally return the URI.
    
    Some changes by Debarshi Ray.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777505

 src/photos-application.c        |    4 +++-
 src/photos-share-point-email.c  |   10 +++++++++-
 src/photos-share-point-google.c |   25 +++++++++++++++++++++++--
 src/photos-share-point.c        |   13 +++++++++++--
 src/photos-share-point.h        |    6 +++++-
 5 files changed, 51 insertions(+), 7 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 4fe57c6..f7700d0 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -1503,8 +1503,9 @@ photos_application_share_share (GObject *source_object, GAsyncResult *res, gpoin
   PhotosApplication *self = PHOTOS_APPLICATION (user_data);
   PhotosSharePoint *share_point = PHOTOS_SHARE_POINT (source_object);
   GError *error = NULL;
+  gchar *uri = NULL;
 
-  photos_share_point_share_finish (share_point, res, &error);
+  photos_share_point_share_finish (share_point, res, &uri, &error);
   if (error != NULL)
     {
       g_warning ("Unable to share the image: %s", error->message);
@@ -1516,6 +1517,7 @@ photos_application_share_share (GObject *source_object, GAsyncResult *res, gpoin
  out:
   g_application_unmark_busy (G_APPLICATION (self));
   g_application_release (G_APPLICATION (self));
+  g_free (uri);
 }
 
 
diff --git a/src/photos-share-point-email.c b/src/photos-share-point-email.c
index 66e8538..a5ac56b 100644
--- a/src/photos-share-point-email.c
+++ b/src/photos-share-point-email.c
@@ -81,6 +81,13 @@ photos_share_point_email_get_name (PhotosSharePoint *share_point)
 }
 
 
+static gboolean
+photos_share_point_email_needs_notification (PhotosSharePoint *share_point)
+{
+  return FALSE;
+}
+
+
 static void
 photos_share_point_email_share_save_to_dir (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
@@ -163,7 +170,7 @@ photos_share_point_email_share_async (PhotosSharePoint *share_point,
 
 
 static gboolean
-photos_share_point_email_share_finish (PhotosSharePoint *share_point, GAsyncResult *res, GError **error)
+photos_share_point_email_share_finish (PhotosSharePoint *share_point, GAsyncResult *res, gchar **out_uri, 
GError **error)
 {
   PhotosSharePointEmail *self = PHOTOS_SHARE_POINT_EMAIL (share_point);
   GTask *task;
@@ -216,6 +223,7 @@ photos_share_point_email_class_init (PhotosSharePointEmailClass *class)
   object_class->finalize = photos_share_point_email_finalize;
   share_point_class->get_icon = photos_share_point_email_get_icon;
   share_point_class->get_name = photos_share_point_email_get_name;
+  share_point_class->needs_notification = photos_share_point_email_needs_notification;
   share_point_class->share_async = photos_share_point_email_share_async;
   share_point_class->share_finish = photos_share_point_email_share_finish;
 }
diff --git a/src/photos-share-point-google.c b/src/photos-share-point-google.c
index 4fba463..98384e5 100644
--- a/src/photos-share-point-google.c
+++ b/src/photos-share-point-google.c
@@ -89,6 +89,13 @@ photos_share_point_google_share_data_free (PhotosSharePointGoogleShareData *data
 }
 
 
+static gboolean
+photos_share_point_google_needs_notification (PhotosSharePoint *share_point)
+{
+  return TRUE;
+}
+
+
 static gchar *
 photos_share_point_google_parse_error (PhotosSharePoint *self, GError *error)
 {
@@ -427,10 +434,14 @@ photos_share_point_google_share_async (PhotosSharePoint *share_point,
 
 
 static gboolean
-photos_share_point_google_share_finish (PhotosSharePoint *share_point, GAsyncResult *res, GError **error)
+photos_share_point_google_share_finish (PhotosSharePoint *share_point,
+                                        GAsyncResult *res,
+                                        gchar **out_uri,
+                                        GError **error)
 {
   PhotosSharePointGoogle *self = PHOTOS_SHARE_POINT_GOOGLE (share_point);
   GTask *task;
+  gboolean ret_val = FALSE;
 
   g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
   task = G_TASK (res);
@@ -438,7 +449,16 @@ photos_share_point_google_share_finish (PhotosSharePoint *share_point, GAsyncRes
   g_return_val_if_fail (g_task_get_source_tag (task) == photos_share_point_google_share_async, FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  return g_task_propagate_boolean (task, error);
+  if (!g_task_propagate_boolean (task, error))
+    goto out;
+
+  ret_val = TRUE;
+
+  if (out_uri != NULL)
+    *out_uri = g_strdup ("https://photos.google.com/";);
+
+ out:
+  return ret_val;
 }
 
 
@@ -505,6 +525,7 @@ photos_share_point_google_class_init (PhotosSharePointGoogleClass *class)
   object_class->constructed = photos_share_point_google_constructed;
   object_class->dispose = photos_share_point_google_dispose;
   object_class->finalize = photos_share_point_google_finalize;
+  share_point_class->needs_notification = photos_share_point_google_needs_notification;
   share_point_class->parse_error = photos_share_point_google_parse_error;
   share_point_class->share_async = photos_share_point_google_share_async;
   share_point_class->share_finish = photos_share_point_google_share_finish;
diff --git a/src/photos-share-point.c b/src/photos-share-point.c
index 0edae12..de06b91 100644
--- a/src/photos-share-point.c
+++ b/src/photos-share-point.c
@@ -62,6 +62,14 @@ photos_share_point_get_name (PhotosSharePoint *self)
 }
 
 
+gboolean
+photos_share_point_needs_notification (PhotosSharePoint *self)
+{
+  g_return_val_if_fail (PHOTOS_IS_SHARE_POINT (self), FALSE);
+  return PHOTOS_SHARE_POINT_GET_CLASS (self)->needs_notification (self);
+}
+
+
 gchar *
 photos_share_point_parse_error (PhotosSharePoint *self, GError *error)
 {
@@ -87,11 +95,12 @@ photos_share_point_share_async (PhotosSharePoint *self,
 
 
 gboolean
-photos_share_point_share_finish (PhotosSharePoint *self, GAsyncResult *res, GError **error)
+photos_share_point_share_finish (PhotosSharePoint *self, GAsyncResult *res, gchar **out_uri, GError **error)
 {
   g_return_val_if_fail (PHOTOS_IS_SHARE_POINT (self), FALSE);
   g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
+  g_return_val_if_fail (out_uri == NULL || *out_uri == NULL, FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  return PHOTOS_SHARE_POINT_GET_CLASS (self)->share_finish (self, res, error);
+  return PHOTOS_SHARE_POINT_GET_CLASS (self)->share_finish (self, res, out_uri, error);
 }
diff --git a/src/photos-share-point.h b/src/photos-share-point.h
index 8a4f3be..f253f3c 100644
--- a/src/photos-share-point.h
+++ b/src/photos-share-point.h
@@ -44,19 +44,22 @@ struct _PhotosSharePointClass
   /* virtual methods */
   GIcon          *(*get_icon)            (PhotosSharePoint *self);
   const gchar    *(*get_name)            (PhotosSharePoint *self);
+  gboolean        (*needs_notification)  (PhotosSharePoint *self);
   gchar          *(*parse_error)         (PhotosSharePoint *self, GError *error);
   void            (*share_async)         (PhotosSharePoint *self,
                                           PhotosBaseItem *item,
                                           GCancellable *cancellable,
                                           GAsyncReadyCallback callback,
                                           gpointer user_data);
-  gboolean        (*share_finish)        (PhotosSharePoint *self, GAsyncResult *res, GError **error);
+  gboolean        (*share_finish)        (PhotosSharePoint *self, GAsyncResult *res, gchar **out_uri, GError 
**error);
 };
 
 GIcon                  *photos_share_point_get_icon               (PhotosSharePoint *self);
 
 const gchar            *photos_share_point_get_name               (PhotosSharePoint *self);
 
+gboolean                photos_share_point_needs_notification     (PhotosSharePoint *self);
+
 gchar                  *photos_share_point_parse_error            (PhotosSharePoint *self, GError *error);
 
 void                    photos_share_point_share_async            (PhotosSharePoint *self,
@@ -67,6 +70,7 @@ void                    photos_share_point_share_async            (PhotosSharePo
 
 gboolean                photos_share_point_share_finish           (PhotosSharePoint *self,
                                                                    GAsyncResult *res,
+                                                                   gchar **out_uri,
                                                                    GError **error);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]