[gnome-photos/wip/rishi/share-notify: 3/3] share-point-notification: Notifying when an item has been shared successfully



commit 3f7ef1245a5f984b70383b09cc1619d8258e1d5c
Author: Ankriti Sachan <ankritisachan gmail com>
Date:   Tue Apr 4 16:48:53 2017 +0000

    share-point-notification: Notifying when an item has been shared successfully
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777505

 po/POTFILES.in                  |    1 +
 src/photos-application.c        |   43 +++++++++++++++++--
 src/photos-share-notification.c |   86 ++++++++++++++++++++++++++++++++++++++-
 src/photos-share-notification.h |    2 +
 src/photos-share-point-email.c  |    8 ++++
 src/photos-share-point-google.c |   16 +++++++
 src/photos-share-point.c        |   16 +++++++
 src/photos-share-point.h        |    6 +++
 8 files changed, 173 insertions(+), 5 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3af387d..8ae5598 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -36,6 +36,7 @@ src/photos-selection-menu.ui
 src/photos-selection-toolbar.c
 src/photos-selection-toolbar.ui
 src/photos-share-dialog.ui
+src/photos-share-notification.c
 src/photos-share-point-email.c
 src/photos-share-point-google.c
 src/photos-source-manager.c
diff --git a/src/photos-application.c b/src/photos-application.c
index 4fe57c6..8d4dce6 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -194,6 +194,7 @@ static const gchar *DESKTOP_KEY_SECONDARY_COLOR = "secondary-color";
 typedef struct _PhotosApplicationCreateData PhotosApplicationCreateData;
 typedef struct _PhotosApplicationRefreshData PhotosApplicationRefreshData;
 typedef struct _PhotosApplicationSetBackgroundData PhotosApplicationSetBackgroundData;
+typedef struct _PhotosApplicationShareData PhotosApplicationShareData;
 
 struct _PhotosApplicationCreateData
 {
@@ -215,6 +216,12 @@ struct _PhotosApplicationSetBackgroundData
   GSettings *settings;
 };
 
+struct _PhotosApplicationShareData
+{
+  PhotosApplication *application;
+  PhotosBaseItem *item;
+};
+
 static void photos_application_refresh_miner_now (PhotosApplication *self, GomMiner *miner);
 static void photos_application_start_miners (PhotosApplication *self);
 static void photos_application_start_miners_second (PhotosApplication *self);
@@ -293,6 +300,28 @@ photos_application_set_background_data_free (PhotosApplicationSetBackgroundData
 }
 
 
+static PhotosApplicationShareData *
+photos_application_share_data_new (PhotosApplication *application, PhotosBaseItem *item)
+{
+  PhotosApplicationShareData *data;
+
+  data = g_slice_new0 (PhotosApplicationShareData);
+  g_application_hold (G_APPLICATION (application));
+  data->application = application;
+  data->item = g_object_ref (item);
+  return data;
+}
+
+
+static void
+photos_application_share_data_free (PhotosApplicationShareData *data)
+{
+  g_application_release (G_APPLICATION (data->application));
+  g_object_unref (data->item);
+  g_slice_free (PhotosApplicationShareData, data);
+}
+
+
 static void
 photos_application_help (PhotosApplication *self)
 {
@@ -1500,9 +1529,11 @@ photos_application_set_screensaver (PhotosApplication *self)
 static void
 photos_application_share_share (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
-  PhotosApplication *self = PHOTOS_APPLICATION (user_data);
+  PhotosApplicationShareData *data = (PhotosApplicationShareData *) user_data;
+  PhotosApplication *self = data->application;
   PhotosSharePoint *share_point = PHOTOS_SHARE_POINT (source_object);
   GError *error = NULL;
+  PhotosBaseItem *item = data->item;
 
   photos_share_point_share_finish (share_point, res, &error);
   if (error != NULL)
@@ -1513,9 +1544,12 @@ photos_application_share_share (GObject *source_object, GAsyncResult *res, gpoin
       goto out;
     }
 
+  if (photos_share_point_needs_notification (share_point))
+    photos_share_notification_new (share_point, item);
+
  out:
   g_application_unmark_busy (G_APPLICATION (self));
-  g_application_release (G_APPLICATION (self));
+  photos_application_share_data_free (data);
 }
 
 
@@ -1524,6 +1558,7 @@ photos_application_share_response (GtkDialog *dialog, gint response_id, gpointer
 {
   PhotosApplication *self = PHOTOS_APPLICATION (user_data);
   GVariant *new_state;
+  PhotosApplicationShareData *data;
   PhotosBaseItem *item;
   PhotosSharePoint *share_point;
 
@@ -1539,9 +1574,9 @@ photos_application_share_response (GtkDialog *dialog, gint response_id, gpointer
   new_state = g_variant_new ("b", FALSE);
   g_action_change_state (G_ACTION (self->selection_mode_action), new_state);
 
-  g_application_hold (G_APPLICATION (self));
   g_application_mark_busy (G_APPLICATION (self));
-  photos_share_point_share_async (share_point, item, NULL, photos_application_share_share, self);
+  data = photos_application_share_data_new (self, item);
+  photos_share_point_share_async (share_point, item, NULL, photos_application_share_share, data);
 
  out:
   gtk_widget_destroy (GTK_WIDGET (dialog));
diff --git a/src/photos-share-notification.c b/src/photos-share-notification.c
index a5ecfa7..94a0d86 100644
--- a/src/photos-share-notification.c
+++ b/src/photos-share-notification.c
@@ -22,7 +22,9 @@
 #include "config.h"
 
 #include <gtk/gtk.h>
+#include <glib/gi18n.h>
 
+#include "photos-base-item.h"
 #include "photos-icons.h"
 #include "photos-notification-manager.h"
 #include "photos-share-notification.h"
@@ -33,6 +35,7 @@ struct _PhotosShareNotification
   GtkGrid parent_instance;
   GError *error;
   GtkWidget *ntfctn_mngr;
+  PhotosBaseItem *item;
   PhotosSharePoint *share_point;
   guint timeout_id;
 };
@@ -41,6 +44,7 @@ enum
 {
   PROP_0,
   PROP_ERROR,
+  PROP_ITEM,
   PROP_SHARE_POINT
 };
 
@@ -80,6 +84,29 @@ photos_share_notification_close (PhotosShareNotification *self)
 }
 
 
+static void
+photos_share_notification_open (PhotosShareNotification *self)
+{
+  GError *error;
+  const gchar *uri;
+
+  g_return_if_fail (PHOTOS_IS_SHARE_NOTIFICATION (self));
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (self->item));
+  g_return_if_fail (photos_share_point_needs_notification (self->share_point));
+
+  uri = photos_share_point_get_base_url (self->share_point);
+
+  error = NULL;
+  if (!g_app_info_launch_default_for_uri (uri, NULL, &error))
+    {
+      g_warning ("Failed to open uri: %s", error->message);
+      g_error_free (error);
+    }
+
+  photos_share_notification_destroy (self);
+}
+
+
 static gboolean
 photos_share_notification_timeout (gpointer user_data)
 {
@@ -104,13 +131,44 @@ photos_share_notification_constructed (GObject *object)
   gtk_grid_set_column_spacing (GTK_GRID (self), 12);
   gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
 
-  msg = photos_share_point_parse_error (self->share_point, self->error);
+  if (self->item == NULL)
+    {
+      g_assert_nonnull (self->error);
+      msg = photos_share_point_parse_error (self->share_point, self->error);
+    }
+  else
+    {
+      const gchar *name;
+
+      g_assert_true (photos_share_point_needs_notification (self->share_point));
+      name = photos_base_item_get_name_with_fallback (PHOTOS_BASE_ITEM (self->item));
+      msg = g_strdup_printf (_("ā€œ%sā€ shared successfully"), name);
+    }
 
   label = gtk_label_new (msg);
   gtk_widget_set_halign (label, GTK_ALIGN_START);
   gtk_widget_set_hexpand (label, TRUE);
   gtk_container_add (GTK_CONTAINER (self), label);
 
+  if (self->item != NULL)
+    {
+      GtkWidget *open;
+      const gchar *name;
+      gchar *app_label;
+
+      g_assert_true (photos_share_point_needs_notification (self->share_point));
+
+      name = photos_share_point_get_name (self->share_point);
+      app_label = g_strdup_printf (_("Open with %s"), name);
+
+      open = gtk_button_new_with_label (app_label);
+      gtk_widget_set_valign (open, GTK_ALIGN_CENTER);
+      gtk_widget_set_halign (open, GTK_ALIGN_CENTER);
+      gtk_container_add (GTK_CONTAINER (self), open);
+      g_signal_connect_swapped (open, "clicked", G_CALLBACK (photos_share_notification_open), self);
+      g_free (app_label);
+    }
+
   image = gtk_image_new_from_icon_name (PHOTOS_ICON_WINDOW_CLOSE_SYMBOLIC, GTK_ICON_SIZE_INVALID);
   gtk_widget_set_margin_bottom (image, 2);
   gtk_widget_set_margin_top (image, 2);
@@ -138,6 +196,8 @@ photos_share_notification_dispose (GObject *object)
   PhotosShareNotification *self = PHOTOS_SHARE_NOTIFICATION (object);
 
   photos_share_notification_remove_timeout (self);
+
+  g_clear_object (&self->item);
   g_clear_object (&self->ntfctn_mngr);
 
   G_OBJECT_CLASS (photos_share_notification_parent_class)->dispose (object);
@@ -166,6 +226,10 @@ photos_share_notification_set_property (GObject *object, guint prop_id, const GV
       self->error = (GError *) g_value_dup_boxed (value);
       break;
 
+    case PROP_ITEM:
+      self->item = PHOTOS_BASE_ITEM (g_value_dup_object (value));
+      break;
+
     case PROP_SHARE_POINT:
       self->share_point = PHOTOS_SHARE_POINT (g_value_dup_object (value));
       break;
@@ -201,6 +265,15 @@ photos_share_notification_class_init (PhotosShareNotificationClass *class)
                                                        "Error thrown during share",
                                                        G_TYPE_ERROR,
                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_ITEM,
+                                   g_param_spec_object ("item",
+                                                        "Item",
+                                                        "The item that was shared",
+                                                        PHOTOS_TYPE_BASE_ITEM,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
   g_object_class_install_property (object_class,
                                    PROP_SHARE_POINT,
                                    g_param_spec_object ("share-point",
@@ -214,6 +287,17 @@ photos_share_notification_class_init (PhotosShareNotificationClass *class)
 
 
 void
+photos_share_notification_new (PhotosSharePoint *share_point, PhotosBaseItem *item)
+{
+  g_return_if_fail (PHOTOS_IS_SHARE_POINT (share_point));
+  g_return_if_fail (photos_share_point_needs_notification (share_point));
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (item));
+
+  g_object_new (PHOTOS_TYPE_SHARE_NOTIFICATION, "share-point", share_point, "item", item, NULL);
+}
+
+
+void
 photos_share_notification_new_with_error (PhotosSharePoint *share_point, GError *error)
 {
   g_return_if_fail (PHOTOS_IS_SHARE_POINT (share_point));
diff --git a/src/photos-share-notification.h b/src/photos-share-notification.h
index 62b3a1a..605760c 100644
--- a/src/photos-share-notification.h
+++ b/src/photos-share-notification.h
@@ -31,6 +31,8 @@ G_BEGIN_DECLS
 #define PHOTOS_TYPE_SHARE_NOTIFICATION (photos_share_notification_get_type ())
 G_DECLARE_FINAL_TYPE (PhotosShareNotification, photos_share_notification, PHOTOS, SHARE_NOTIFICATION, 
GtkGrid);
 
+void                photos_share_notification_new             (PhotosSharePoint *share_point, PhotosBaseItem 
*item);
+
 void                photos_share_notification_new_with_error  (PhotosSharePoint *share_point, GError *error);
 
 G_END_DECLS
diff --git a/src/photos-share-point-email.c b/src/photos-share-point-email.c
index 66e8538..b88a7e8 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)
 {
@@ -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..e64a47d 100644
--- a/src/photos-share-point-google.c
+++ b/src/photos-share-point-google.c
@@ -89,6 +89,20 @@ photos_share_point_google_share_data_free (PhotosSharePointGoogleShareData *data
 }
 
 
+static const gchar *
+photos_share_point_google_get_base_url (PhotosSharePoint *share_point)
+{
+  return "https://photos.google.com";;
+}
+
+
+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)
 {
@@ -505,6 +519,8 @@ 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->get_base_url = photos_share_point_google_get_base_url;
+  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..eb33a44 100644
--- a/src/photos-share-point.c
+++ b/src/photos-share-point.c
@@ -46,6 +46,14 @@ photos_share_point_class_init (PhotosSharePointClass *class)
 }
 
 
+const gchar *
+photos_share_point_get_base_url (PhotosSharePoint *self)
+{
+  g_return_val_if_fail (PHOTOS_IS_SHARE_POINT (self), NULL);
+  return PHOTOS_SHARE_POINT_GET_CLASS (self)->get_base_url (self);
+}
+
+
 GIcon *
 photos_share_point_get_icon (PhotosSharePoint *self)
 {
@@ -62,6 +70,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), NULL);
+  return PHOTOS_SHARE_POINT_GET_CLASS (self)->needs_notification (self);
+}
+
+
 gchar *
 photos_share_point_parse_error (PhotosSharePoint *self, GError *error)
 {
diff --git a/src/photos-share-point.h b/src/photos-share-point.h
index 8a4f3be..614f6b5 100644
--- a/src/photos-share-point.h
+++ b/src/photos-share-point.h
@@ -42,8 +42,10 @@ struct _PhotosSharePointClass
   GObjectClass parent_class;
 
   /* virtual methods */
+  const gchar    *(*get_base_url)        (PhotosSharePoint *self);
   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,
@@ -53,10 +55,14 @@ struct _PhotosSharePointClass
   gboolean        (*share_finish)        (PhotosSharePoint *self, GAsyncResult *res, GError **error);
 };
 
+const gchar            *photos_share_point_get_base_url           (PhotosSharePoint *self);
+
 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,


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