[gnome-photos] Show a notification when an item has been successfully shared



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

    Show a notification when an item has been successfully shared
    
    Some changes by Debarshi Ray.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777505

 po/POTFILES.in                  |    1 +
 src/photos-application.c        |   11 +++-
 src/photos-share-notification.c |  108 ++++++++++++++++++++++++++++++++++++++-
 src/photos-share-notification.h |    5 ++
 4 files changed, 121 insertions(+), 4 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 f7700d0..e32704a 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -1500,11 +1500,14 @@ 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);
+  PhotosApplication *self;
   PhotosSharePoint *share_point = PHOTOS_SHARE_POINT (source_object);
   GError *error = NULL;
+  PhotosBaseItem *item = PHOTOS_BASE_ITEM (user_data);
   gchar *uri = NULL;
 
+  self = PHOTOS_APPLICATION (g_application_get_default ());
+
   photos_share_point_share_finish (share_point, res, &uri, &error);
   if (error != NULL)
     {
@@ -1514,10 +1517,14 @@ 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, uri);
+
  out:
   g_application_unmark_busy (G_APPLICATION (self));
   g_application_release (G_APPLICATION (self));
   g_free (uri);
+  g_object_unref (item);
 }
 
 
@@ -1543,7 +1550,7 @@ photos_application_share_response (GtkDialog *dialog, gint response_id, gpointer
 
   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);
+  photos_share_point_share_async (share_point, item, NULL, photos_application_share_share, g_object_ref 
(item));
 
  out:
   gtk_widget_destroy (GTK_WIDGET (dialog));
diff --git a/src/photos-share-notification.c b/src/photos-share-notification.c
index a5ecfa7..8c6f4bf 100644
--- a/src/photos-share-notification.c
+++ b/src/photos-share-notification.c
@@ -1,5 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2017 Red Hat, Inc.
  * Copyright © 2016 Umang Jain
  *
  * This program is free software; you can redistribute it and/or
@@ -21,8 +22,11 @@
 
 #include "config.h"
 
+#include <gio/gio.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,7 +37,9 @@ struct _PhotosShareNotification
   GtkGrid parent_instance;
   GError *error;
   GtkWidget *ntfctn_mngr;
+  PhotosBaseItem *item;
   PhotosSharePoint *share_point;
+  gchar *uri;
   guint timeout_id;
 };
 
@@ -41,7 +47,9 @@ enum
 {
   PROP_0,
   PROP_ERROR,
-  PROP_SHARE_POINT
+  PROP_ITEM,
+  PROP_SHARE_POINT,
+  PROP_URI
 };
 
 
@@ -80,6 +88,34 @@ photos_share_notification_close (PhotosShareNotification *self)
 }
 
 
+static void
+photos_share_notification_open (PhotosShareNotification *self)
+{
+  GApplication *app;
+  GError *error;
+  GtkWindow *parent;
+  guint32 time;
+
+  g_return_if_fail (PHOTOS_IS_SHARE_NOTIFICATION (self));
+  g_return_if_fail (photos_share_point_needs_notification (self->share_point));
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (self->item));
+  g_return_if_fail (self->uri != NULL && self->uri[0] != '\0');
+
+  app = g_application_get_default ();
+  parent = gtk_application_get_active_window (GTK_APPLICATION (app));
+  time = gtk_get_current_event_time ();
+
+  error = NULL;
+  if (!gtk_show_uri_on_window (parent, self->uri, time, &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 +140,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"), 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 && self->uri != NULL && self->uri[0] != '\0')
+    {
+      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 +205,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);
@@ -150,6 +219,7 @@ photos_share_notification_finalize (GObject *object)
   PhotosShareNotification *self = PHOTOS_SHARE_NOTIFICATION (object);
 
   g_clear_error (&self->error);
+  g_free (self->uri);
 
   G_OBJECT_CLASS (photos_share_notification_parent_class)->finalize (object);
 }
@@ -166,10 +236,18 @@ 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;
 
+    case PROP_URI:
+      self->uri = g_value_dup_string (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -201,6 +279,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 original 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",
@@ -209,7 +296,24 @@ photos_share_notification_class_init (PhotosShareNotificationClass *class)
                                                         PHOTOS_TYPE_SHARE_POINT,
                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
 
+  g_object_class_install_property (object_class,
+                                   PROP_URI,
+                                   g_param_spec_string ("uri",
+                                                        "URI",
+                                                        "The URI at which the shared item can be accessed",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+}
+
+
+void
+photos_share_notification_new (PhotosSharePoint *share_point, PhotosBaseItem *item, const gchar *uri)
+{
+  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, "uri", uri, NULL);
 }
 
 
diff --git a/src/photos-share-notification.h b/src/photos-share-notification.h
index 62b3a1a..729c72e 100644
--- a/src/photos-share-notification.h
+++ b/src/photos-share-notification.h
@@ -1,5 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2017 Red Hat, Inc.
  * Copyright © 2016 Umang Jain
  *
  * This program is free software; you can redistribute it and/or
@@ -31,6 +32,10 @@ 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,
+                                                               const gchar *uri);
+
 void                photos_share_notification_new_with_error  (PhotosSharePoint *share_point, GError *error);
 
 G_END_DECLS


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