[gnome-photos/wip/rishi/share-notify: 3/3] share-point-notification: Notifying when an item has been shared successfully
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/share-notify: 3/3] share-point-notification: Notifying when an item has been shared successfully
- Date: Sun, 22 Oct 2017 08:10:27 +0000 (UTC)
commit 386acbcc306cc119ec27b92fdd72f71812d21d4a
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 | 47 ++++++++++++++++--
src/photos-share-notification.c | 99 ++++++++++++++++++++++++++++++++++++++-
src/photos-share-notification.h | 5 ++
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 ++-
8 files changed, 193 insertions(+), 13 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..331a394 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,11 +1529,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);
+ PhotosApplicationShareData *data = (PhotosApplicationShareData *) user_data;
+ PhotosApplication *self = data->application;
PhotosSharePoint *share_point = PHOTOS_SHARE_POINT (source_object);
GError *error = NULL;
+ PhotosBaseItem *item = data->item;
+ 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);
@@ -1513,9 +1545,13 @@ 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));
+ photos_application_share_data_free (data);
+ g_free (uri);
}
@@ -1524,6 +1560,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 +1576,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..f5ee830 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
@@ -22,7 +23,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,7 +36,9 @@ struct _PhotosShareNotification
GtkGrid parent_instance;
GError *error;
GtkWidget *ntfctn_mngr;
+ PhotosBaseItem *item;
PhotosSharePoint *share_point;
+ gchar *uri;
guint timeout_id;
};
@@ -41,7 +46,9 @@ enum
{
PROP_0,
PROP_ERROR,
- PROP_SHARE_POINT
+ PROP_ITEM,
+ PROP_SHARE_POINT,
+ PROP_URI
};
@@ -80,6 +87,26 @@ photos_share_notification_close (PhotosShareNotification *self)
}
+static void
+photos_share_notification_open (PhotosShareNotification *self)
+{
+ GError *error;
+
+ 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));
+
+ error = NULL;
+ if (!g_app_info_launch_default_for_uri (self->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"), 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);
@@ -150,6 +210,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 +227,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 +270,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 +287,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
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..3c3bd68 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), NULL);
+ 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..a1b1bd0 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]