After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 762371 - Export: Add notifications when photos are exported
Export: Add notifications when photos are exported
Status: RESOLVED FIXED
Product: gnome-photos
Classification: Applications
Component: general
3.19.x
Other All
: Normal normal
: ---
Assigned To: GNOME photos maintainer(s)
GNOME photos maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2016-02-20 11:15 UTC by Umang Jain
Modified: 2016-03-02 10:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Export: Add notifications when photos are exported (15.05 KB, patch)
2016-02-21 17:54 UTC, Umang Jain
none Details | Review
Export: Add notifications when photos are exported (14.79 KB, patch)
2016-02-22 12:03 UTC, Umang Jain
none Details | Review
export: add notifications when photos are exported (16.13 KB, patch)
2016-02-23 20:41 UTC, Umang Jain
none Details | Review
export: add notifications when photos are exported (17.12 KB, patch)
2016-02-24 03:58 UTC, Umang Jain
none Details | Review
export: add notifications when photos are exported (17.12 KB, patch)
2016-02-24 14:46 UTC, Umang Jain
none Details | Review
export: add notifications when photos are exported (40.10 KB, patch)
2016-02-24 20:05 UTC, Umang Jain
none Details | Review
export: add notifications when photos are exported (19.64 KB, patch)
2016-02-24 20:08 UTC, Umang Jain
none Details | Review
export: add notifications when photos are exported (19.24 KB, patch)
2016-02-25 10:05 UTC, Debarshi Ray
none Details | Review
export: add notifications when photos are exported (19.43 KB, patch)
2016-02-25 17:27 UTC, Umang Jain
none Details | Review
Make photos_base_item_save_finish return the exported file (4.09 KB, patch)
2016-02-28 23:47 UTC, Debarshi Ray
committed Details | Review
Add notifications when photos are exported (20.03 KB, patch)
2016-02-28 23:48 UTC, Debarshi Ray
committed Details | Review

Comment 1 Umang Jain 2016-02-21 17:54:26 UTC
Created attachment 321788 [details] [review]
Export: Add notifications when photos are exported
Comment 2 Umang Jain 2016-02-22 12:03:32 UTC
Created attachment 321826 [details] [review]
Export: Add notifications when photos are exported
Comment 3 Umang Jain 2016-02-22 12:11:04 UTC
In attachment 321826 [details] [review]:

A workaround has been implemented: If there is an error in exporting, the GList  argument in photos_export_notification_new will be passed as NULL and the location argument will contain the error string.

Also, a bug still remains: When we try to export a another photo while the previous photo's exported notification is still in display; both of the notification overlap each other. 

There is already 
photos_selection_controller_set_selection_mode (self->priv->sel_cntrlr, FALSE); 
in photos_application_save_save but still it allows to select the photo and export it  while the export notification is in display.
Comment 4 Debarshi Ray 2016-02-22 12:28:59 UTC
Review of attachment 321826 [details] [review]:

Thanks for the patch, Umang. A few quick comments:

::: src/photos-application.c
@@ +987,3 @@
     {
       g_warning ("Unable to save: %s", error->message);
+      photos_export_notification_new (NULL, g_strdup ("Failed to Export"));

Should be a small 'e': "Failed to export"

@@ +1052,3 @@
     {
       g_warning ("Unable to create %s: %s", export_path, error->message);
+      photos_export_notification_new (NULL, "Failed to export: Not enough space");

We can't assume that a failure to create the directory is due to lack of space. Also, photos_base_item_save_async can fail due to lack of space. File I/O is racy - multiple processes can access the filesystem at the same time.

So, we need to explicitly check for G_IO_ERROR_NO_SPACE. See g_error_matches. There are some examples in the code.

::: src/photos-export-notification.c
@@ +132,3 @@
+  
+  else if (length > 1)
+    msg = g_strdup_printf (ngettext ("%d item exported", "%d items exported", length), length);

Nice. :)

@@ +152,3 @@
+
+  if(length == 1)
+  {

The brace is misaligned.
Comment 5 Umang Jain 2016-02-23 20:41:23 UTC
Created attachment 322182 [details] [review]
export: add notifications when photos are exported
Comment 6 Debarshi Ray 2016-02-24 01:31:24 UTC
Review of attachment 322182 [details] [review]:

This is not in "git format-patch" format.

::: src/photos-application.c
@@ +996,3 @@
+  photos_export_notification_new (items, g_file_get_uri (export));
+
+  g_list_free_full (items, g_object_unref);

Put it at the end of the function. That way we know we won't leak anything even if the code changes a bit.

::: src/photos-export-notification.c
@@ +18,3 @@
+ * 02110-1301, USA.
+ */
+

Nitpick: needs another new line.

@@ +30,3 @@
+#include "photos-notification-manager.h"
+#include "photos-search-context.h"
+

Ditto.

@@ +127,3 @@
+
+  if ((length == 0) && (self->error != NULL))
+  {

The indentation is off.

@@ +129,3 @@
+  {
+    if (g_error_matches ((self->error), G_IO_ERROR, G_IO_ERROR_NO_SPACE))
+        msg = g_strdup ("Failed to export: not enough space");

Ditto.

@@ +132,3 @@
+
+    else
+        msg = g_strdup ("Failed to export");

These user visible strings need to be enclosed in _(), and this file should be listed in po/POTFILES.in.

@@ +150,3 @@
+    }
+  
+  else

No need for the new line. Enclose the else in braces too.

@@ +158,3 @@
+  g_free (msg);
+
+  if(length == 1)

Missing space between if and (.

@@ +225,3 @@
+  PhotosExportNotification *self = PHOTOS_EXPORT_NOTIFICATION (object);
+
+  g_return_if_fail (self->export_loc != NULL);

We don't usually do this. It is not idiomatic. :)

@@ +287,3 @@
+  self->ntfctn_mngr = g_object_ref_sink (photos_notification_manager_dup_singleton ());
+  self->item_mngr = g_object_ref (state->item_mngr);
+  self->error = NULL;

No need to initialize it to NULL. GObject will zero-initialize the whole structure.
Comment 7 Umang Jain 2016-02-24 03:58:37 UTC
Created attachment 322203 [details] [review]
export: add notifications when photos are exported

https://bugzilla.gnome.org/show_bug.cgi?id=762371
Comment 8 Debarshi Ray 2016-02-24 11:15:07 UTC
Review of attachment 322203 [details] [review]:

Thanks, this looks better.

I don't see the "analyze", "empty trash" buttons, though. Grep for DISK_SPACE_ANALYZER in gnome-settings-daemon's plugins/housekeeping/gsd-disk-space.c file to see an example implementation.

::: src/photos-export-notification.c
@@ +49,3 @@
+};
+
+

Nitpick: extra newline.

@@ +57,3 @@
+  PROP_ERROR
+};
+

Missing a newline.

@@ +59,3 @@
+
+G_DEFINE_TYPE (PhotosExportNotification, photos_export_notification, GTK_TYPE_GRID);
+

Ditto.
Comment 9 Umang Jain 2016-02-24 14:46:48 UTC
Created attachment 322247 [details] [review]
export: add notifications when photos are exported

https://bugzilla.gnome.org/show_bug.cgi?id=762371
Comment 10 Umang Jain 2016-02-24 20:05:35 UTC
Created attachment 322280 [details] [review]
export: add notifications when photos are exported
Comment 11 Umang Jain 2016-02-24 20:08:53 UTC
Created attachment 322281 [details] [review]
export: add notifications when photos are exported
Comment 12 Debarshi Ray 2016-02-25 10:00:25 UTC
Review of attachment 322281 [details] [review]:

Thanks, Umang. This looks better. A few comments:

::: src/photos-export-notification.c
@@ +168,3 @@
+  G_OBJECT_CLASS (photos_export_notification_parent_class)->constructed (object);
+
+  length = g_list_length (self->items);

It would be nice to avoid g_list_length if possible because it is O(n). In this case we can avoid it.

@@ +170,3 @@
+  length = g_list_length (self->items);
+
+  if ((length == 0) && (self->error != NULL))

I would add a g_assert_nonnull to enforce that self->error is non-NULL if self->items is NULL and vice-versa. Otherwise, it would be a programming error.

@@ +281,3 @@
+
+static void
+photos_export_notification_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)

We don't need this. See below.

@@ +316,3 @@
+
+    case PROP_EXPORT_LOCATION:
+      {

Brace not needed.

@@ +317,3 @@
+    case PROP_EXPORT_LOCATION:
+      {
+        self->export_loc = g_value_dup_string (value);

We are not freeing the string anywhere.

@@ +319,3 @@
+        self->export_loc = g_value_dup_string (value);
+        break;
+        return;

Typo alert!

@@ +323,3 @@
+
+    case PROP_ERROR:
+      {

Brace not needed.

@@ +372,3 @@
+                                                        "Location of exported items",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));

Why does this property need to be readable? We are not reading it via g_object_get or a getter method.

@@ +380,3 @@
+                                                       "Error object which contains the error details",
+                                                       G_TYPE_ERROR,
+                                                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));

Ditto.

@@ +391,3 @@
+  g_object_new (PHOTOS_TYPE_EXPORT_NOTIFICATION,
+                "items", items,
+                "export_location", location,

How about just calling it 'location' like the parameter?

@@ +394,3 @@
+                "error", NULL,
+                "column-spacing", 12,
+                "margin-start", 12,

I know where you copied this style from, but it is an anti-pattern. :) I would prefer to pass only those properties to g_object_new that were passed by the client code, because a direct g_object_new call should match the C wrapper as much as possible. The rest should be set "inside" in _init, _constructed, etc..
Comment 13 Debarshi Ray 2016-02-25 10:04:29 UTC
(In reply to Debarshi Ray from comment #12)
> Review of attachment 322281 [details] [review] [review]:
> ::: src/photos-export-notification.c
> @@ +168,3 @@
> +  G_OBJECT_CLASS (photos_export_notification_parent_class)->constructed
> (object);
> +
> +  length = g_list_length (self->items);
> 
> It would be nice to avoid g_list_length if possible because it is O(n). In
> this case we can avoid it.

Ignore this. I was mistaken. I can see why you really need the length.
Comment 14 Debarshi Ray 2016-02-25 10:05:12 UTC
Created attachment 322345 [details] [review]
export: add notifications when photos are exported

Fixed the above issues.
Comment 15 Debarshi Ray 2016-02-25 10:11:03 UTC
Review of attachment 322345 [details] [review]:

Somethings left for you to address:

::: src/photos-export-notification.c
@@ +112,3 @@
+
+  g_free (file_uri);
+}

We should close the notification when the open buttons are clicked.

@@ +121,3 @@
+  const gchar *argv[] = { DISK_SPACE_ANALYZER, "/", NULL };
+
+  g_spawn_async (NULL, (gchar **) argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);

I am inclined to think that g_desktop_app_info_new and g_app_info_launch are better options than g_spawn_async. I am not 100% sure, yet.

@@ +151,3 @@
+photos_export_notification_empty_trash (PhotosExportNotification *self)
+{
+  g_bus_get (G_BUS_TYPE_SESSION, NULL, photos_export_notification_trash_callback, self);

Since we are not using a GCancellable to hold the asynchronous operations together, we should take a reference on self when we pass it as user_data and unref it in the callback.
Comment 16 Debarshi Ray 2016-02-25 15:52:04 UTC
(In reply to Debarshi Ray from comment #15)
> @@ +121,3 @@
> +  const gchar *argv[] = { DISK_SPACE_ANALYZER, "/", NULL };
> +
> +  g_spawn_async (NULL, (gchar **) argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
> NULL, NULL, NULL);
> 
> I am inclined to think that g_desktop_app_info_new and g_app_info_launch are
> better options than g_spawn_async. I am not 100% sure, yet.

I spoke to Bastien in #control-center on GIMPNet, and, indeed, we should use g_desktop_app_info_new and g_app_info_launch.
Comment 17 Umang Jain 2016-02-25 15:53:55 UTC
> 
> I spoke to Bastien in #control-center on GIMPNet, and, indeed, we should use
> g_desktop_app_info_new and g_app_info_launch.

Yes, I have already ported the code for using that.
Comment 18 Umang Jain 2016-02-25 17:27:15 UTC
Created attachment 322397 [details] [review]
export: add notifications when photos are exported
Comment 19 Debarshi Ray 2016-02-28 23:43:51 UTC
Review of attachment 322397 [details] [review]:

Thanks, Umang. This is looking better.

::: src/photos-application.c
@@ +994,3 @@
 
+  items = g_list_prepend (items, g_object_ref (item));
+  export =  G_FILE (g_object_get_data (G_OBJECT (item), "export_dir"));

Trying to reconstruct the location of the exported file won't be possible once we land the patches in bug 762318 We need to change photos_base_item_save_async/finish to return the exported file, and then use it here.

@@ +995,3 @@
+  items = g_list_prepend (items, g_object_ref (item));
+  export =  G_FILE (g_object_get_data (G_OBJECT (item), "export_dir"));
+  photos_export_notification_new (items, g_file_get_uri (export));

We need to free the value returned by g_file_get_uri. Otherwise we are leaking it.

::: src/photos-export-notification.c
@@ +22,3 @@
+#include "config.h"
+
+#include <gio/gdesktopappinfo.h>

We should also add gio-unix-2.0 to configure.ac.

@@ +32,3 @@
+#include "photos-notification-manager.h"
+#include "photos-search-context.h"
+#include "photos-utils.h"

Unused header.

@@ +38,3 @@
+{
+  GtkGrid parent_instance;
+  PhotosBaseManager *item_mngr;

item_mngr is unused.

@@ +100,3 @@
+
+  self->timeout_id = 0;
+  photos_export_notification_close (self);

Why not directly call photos_export_notification_destroy?

@@ +118,3 @@
+    }
+
+  photos_export_notification_close (self);

Ditto.

@@ +163,3 @@
+  GError *error = NULL;
+
+  connection = g_bus_get_finish (result, &error);

We need to unref connection once we are done with it.

@@ +172,3 @@
+    }
+
+    g_dbus_connection_call (connection,

The indentation is off.

@@ +177,3 @@
+                            "org.gnome.SettingsDaemon.Housekeeping",
+                            "EmptyTrash",
+                            NULL, NULL, 0, -1, NULL, NULL, NULL);

One parameter per line, and G_DBUS_CALL_FLAGS_NONE instead of 0.

@@ +236,3 @@
+  g_free (msg);
+
+  if (g_error_matches (self->error, G_IO_ERROR, G_IO_ERROR_NO_SPACE))

It would be more readable if we use the same structure for the if...else as above.

@@ +271,3 @@
+      gtk_widget_set_halign (open, GTK_ALIGN_CENTER);
+      gtk_container_add (GTK_CONTAINER (self), open);
+      g_object_set_data (G_OBJECT (self), "file_loc", file_loc);

Instead of g_object_set_data, we could just use a member variable for self. However, we need to do this differently, anyway. See above.
Comment 20 Debarshi Ray 2016-02-28 23:47:02 UTC
Created attachment 322612 [details] [review]
Make photos_base_item_save_finish return the exported file
Comment 21 Debarshi Ray 2016-02-28 23:48:00 UTC
Created attachment 322613 [details] [review]
Add notifications when photos are exported

Fixed the above issues, but we need to ask for permission before pushing.
Comment 22 Debarshi Ray 2016-02-28 23:51:12 UTC
Since we are in UI Freeze and String Change Announcement Period [1], could you please send the email asking for permission to add the new UI and strings?

[1] https://wiki.gnome.org/ThreePointNineteen
Comment 23 Debarshi Ray 2016-03-02 10:39:48 UTC
(In reply to Debarshi Ray from comment #21)
> Created attachment 322613 [details] [review] [review]
> Add notifications when photos are exported
> 
> Fixed the above issues, but we need to ask for permission before pushing.

Pushed to master.

The freeze break request [1] was sent two days ago, and so far we have only received only one approval (which was unfortunately not CCed to the release-team mailing list). However, given the following reasons, I am not going to wait any further:
  (a) We don't need approval from the documentation team or the translators.
  (b) This is a relatively self-contained follow-up to a feature (editing) that we worked on this cycle. Hence should be safe.
  (c) I am not going to release 3.20 without this patch and it is holding up our 3.19.91 release.

I wish the release team was more active in handling paperwork related to the release, but, at the end of the day, as maintainer, I am on the hook for the well-being of this module and I am confident that this patch is good enough to go in.

[1] https://mail.gnome.org/archives/release-team/2016-February/msg00046.html