[gnome-photos/wip/rishi/share-point] Add notification for sharing failure



commit eb167d397e79b9df815236c7dc4615d846f28abc
Author: Umang Jain <mailumangjain gmail com>
Date:   Fri Aug 5 18:56:15 2016 +0530

    Add notification for sharing failure
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751181

 src/Makefile.am                 |    2 +
 src/photos-application.c        |    2 +
 src/photos-share-notification.c |  285 +++++++++++++++++++++++++++++++++++++++
 src/photos-share-notification.h |   51 +++++++
 4 files changed, 340 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2fd11b1..11e536c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -204,6 +204,8 @@ gnome_photos_SOURCES = \
        photos-settings.h \
        photos-share-dialog.c \
        photos-share-dialog.h \
+       photos-share-notification.c \
+       photos-share-notification.h \
        photos-share-point.c \
        photos-share-point.h \
        photos-share-point-email.c \
diff --git a/src/photos-application.c b/src/photos-application.c
index 82ac5d2..be08ead 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -55,6 +55,7 @@
 #include "photos-search-type.h"
 #include "photos-search-provider.h"
 #include "photos-selection-controller.h"
+#include "photos-share-notification.h"
 #include "photos-single-item-job.h"
 #include "photos-source.h"
 #include "photos-source-manager.h"
@@ -1290,6 +1291,7 @@ photos_application_share_share (GObject *source_object, GAsyncResult *res, gpoin
   if (error != NULL)
     {
       g_warning ("Unable to share the image: %s", error->message);
+      photos_share_notification_new_with_error (error);
       g_error_free (error);
       goto out;
     }
diff --git a/src/photos-share-notification.c b/src/photos-share-notification.c
new file mode 100644
index 0000000..ff73d02
--- /dev/null
+++ b/src/photos-share-notification.c
@@ -0,0 +1,285 @@
+/*
+ * 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/gdesktopappinfo.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <gdata/gdata.h>
+#include <gdata/gdata-goa-authorizer.h>
+
+#include "photos-base-item.h"
+#include "photos-base-manager.h"
+#include "photos-share-point-manager.h"
+#include "photos-share-notification.h"
+#include "photos-icons.h"
+#include "photos-notification-manager.h"
+
+struct _PhotosShareNotification
+{
+  GtkGrid parent_instance;
+  GtkWidget *ntfctn_mngr;
+  GError *error;
+  GFile *file; // Why ?
+  GList *items;
+  guint timeout_id;
+};
+
+struct _PhotosShareNotificationClass
+{
+  GtkGridClass parent_class;
+};
+
+enum
+{
+  PROP_0,
+  PROP_ERROR,
+  PROP_FILE,
+  PROP_ITEMS
+};
+
+
+G_DEFINE_TYPE (PhotosShareNotification, photos_share_notification, GTK_TYPE_GRID);
+
+
+enum
+{
+    SHARE_TIMEOUT = 10 /* s */
+};
+
+static void
+photos_share_notification_remove_timeout (PhotosShareNotification *self)
+{
+  if (self->timeout_id != 0)
+    {
+      g_source_remove (self->timeout_id);
+      self->timeout_id = 0;
+    }
+}
+
+
+static void
+photos_share_notification_destroy (PhotosShareNotification *self)
+{
+  photos_share_notification_remove_timeout (self);
+  gtk_widget_destroy (GTK_WIDGET (self));
+}
+
+
+static void
+photos_share_notification_close (PhotosShareNotification *self)
+{
+  photos_share_notification_destroy (self);
+}
+
+
+static gboolean
+photos_share_notification_timeout (gpointer user_data)
+{
+  PhotosShareNotification *self = PHOTOS_SHARE_NOTIFICATION (user_data);
+
+  self->timeout_id = 0;
+  photos_share_notification_destroy (self);
+  return G_SOURCE_REMOVE;
+}
+
+static void
+photos_share_notification_constructed (GObject *object)
+{
+  PhotosShareNotification *self = PHOTOS_SHARE_NOTIFICATION (object);
+  GtkWidget *close;
+  GtkWidget *image;
+  GtkWidget *label;
+  gchar *msg;
+  guint length;
+
+  G_OBJECT_CLASS (photos_share_notification_parent_class)->constructed (object);
+
+  gtk_grid_set_column_spacing (GTK_GRID (self), 12);
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
+
+  length = g_list_length (self->items);
+  if (length == 0)
+    {
+      g_assert_nonnull (self->error);
+
+      if (g_error_matches (self->error, GDATA_SERVICE_ERROR,  GDATA_SERVICE_ERROR_ENTRY_ALREADY_INSERTED))
+        msg = g_strdup (_("Failed to upload photo: Image already inserted "));
+
+      else if (g_error_matches (self->error, GDATA_SERVICE_ERROR, 
GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED))
+        msg = g_strdup (_("Failed to upload photo: Service not authorized"));
+
+      else
+        msg = g_strdup (_("Failed to upload photo"));
+    }
+  else
+    {
+      /* Share success logic here.*/
+      return;
+    }
+
+  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);
+  g_free (msg);
+
+  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);
+  gtk_image_set_pixel_size (GTK_IMAGE (image), 16);
+
+  close = gtk_button_new ();
+  gtk_widget_set_valign (close, GTK_ALIGN_CENTER);
+  gtk_button_set_focus_on_click (GTK_BUTTON (close), FALSE);
+  gtk_button_set_relief (GTK_BUTTON (close), GTK_RELIEF_NONE);
+  gtk_button_set_image (GTK_BUTTON (close), image);
+  gtk_container_add (GTK_CONTAINER (self), close);
+  g_signal_connect_swapped (close, "clicked", G_CALLBACK (photos_share_notification_close), self);
+
+  photos_notification_manager_add_notification (PHOTOS_NOTIFICATION_MANAGER (self->ntfctn_mngr),
+                                                GTK_WIDGET (self));
+
+  self->timeout_id = g_timeout_add_seconds (SHARE_TIMEOUT, photos_share_notification_timeout, self);
+}
+
+
+static void
+photos_share_notification_dispose (GObject *object)
+{
+  PhotosShareNotification *self = PHOTOS_SHARE_NOTIFICATION (object);
+
+  photos_share_notification_remove_timeout (self);
+
+  if (self->items != NULL)
+    {
+      g_list_free_full (self->items, g_object_unref);
+      self->items = NULL;
+    }
+
+  g_clear_object (&self->file);
+  g_clear_object (&self->ntfctn_mngr);
+
+  G_OBJECT_CLASS (photos_share_notification_parent_class)->dispose (object);
+}
+
+
+static void
+photos_share_notification_finalize (GObject *object)
+{
+  PhotosShareNotification *self = PHOTOS_SHARE_NOTIFICATION (object);
+
+  g_clear_error (&self->error);
+
+  G_OBJECT_CLASS (photos_share_notification_parent_class)->finalize (object);
+}
+
+
+static void
+photos_share_notification_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec 
*pspec)
+{
+  PhotosShareNotification *self = PHOTOS_SHARE_NOTIFICATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_ERROR:
+      self->error = g_value_dup_boxed (value);
+      break;
+
+    case PROP_FILE:
+      self->file = g_value_dup_object (value);
+      break;
+
+    case PROP_ITEMS:
+      {
+        GList *items;
+
+        items = (GList *) g_value_get_pointer (value);
+        self->items = g_list_copy_deep (items, (GCopyFunc) g_object_ref, NULL);
+        break;
+      }
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_share_notification_init (PhotosShareNotification *self)
+{
+  self->ntfctn_mngr = photos_notification_manager_dup_singleton ();
+}
+
+
+static void
+photos_share_notification_class_init (PhotosShareNotificationClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->constructed = photos_share_notification_constructed;
+  object_class->dispose = photos_share_notification_dispose;
+  object_class->finalize = photos_share_notification_finalize;
+  object_class->set_property = photos_share_notification_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_ERROR,
+                                   g_param_spec_boxed ("error",
+                                                       "Error",
+                                                       "Error thrown during share",
+                                                       G_TYPE_ERROR,
+                                                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_FILE,
+                                   g_param_spec_object ("file",
+                                                        "File",
+                                                        "A GFile representing the exported file or 
directory",
+                                                        G_TYPE_FILE,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_ITEMS,
+                                   g_param_spec_pointer ("items",
+                                                         "List of PhotosBaseItems",
+                                                         "List of items that were shared",
+                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+}
+
+
+void
+photos_share_notification_new (GList *items, GFile *file)
+{
+  g_return_if_fail (G_IS_FILE (file));
+  g_return_if_fail (items != NULL);
+
+  g_object_new (PHOTOS_TYPE_SHARE_NOTIFICATION, "file", file, "items", items, NULL);
+}
+
+
+void
+photos_share_notification_new_with_error (GError *error)
+{
+  g_return_if_fail (error != NULL);
+  g_object_new (PHOTOS_TYPE_SHARE_NOTIFICATION, "error", error, NULL);
+}
diff --git a/src/photos-share-notification.h b/src/photos-share-notification.h
new file mode 100644
index 0000000..c55f0c2
--- /dev/null
+++ b/src/photos-share-notification.h
@@ -0,0 +1,51 @@
+/*
+ * 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_SHARE_NOTIFICATION_H
+#define PHOTOS_SHARE_NOTIFICATION_H
+
+#include <gio/gio.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SHARE_NOTIFICATION (photos_share_notification_get_type ())
+
+#define PHOTOS_SHARE_NOTIFICATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SHARE_NOTIFICATION, PhotosShareNotification))
+
+#define PHOTOS_IS_SHARE_NOTIFICATION(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SHARE_NOTIFICATION))
+
+typedef struct _PhotosShareNotification      PhotosShareNotification;
+typedef struct _PhotosShareNotificationClass PhotosShareNotificationClass;
+
+GType               photos_share_notification_get_type        (void) G_GNUC_CONST;
+
+void                photos_share_notification_new             (GList *items, GFile *file);
+
+void                photos_share_notification_new_with_error  (GError *error);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SHARE_NOTIFICATION_H */


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