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 737983 - gtkplacessidebar: Open $HOME after unmounting or ejecting
gtkplacessidebar: Open $HOME after unmounting or ejecting
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
Federico Mena Quintero
: 737987 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-10-06 09:43 UTC by Carlos Soriano
Modified: 2014-10-26 10:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtkplacessidebar: Open $HOME after unmounting or ejecting (2.06 KB, patch)
2014-10-06 09:43 UTC, Carlos Soriano
reviewed Details | Review
gtkplacessidebar: Don't change location if clicked on eject button (1.21 KB, patch)
2014-10-09 18:40 UTC, Carlos Soriano
committed Details | Review
gtkplacessidebar: Open $HOME after unmounting or ejecting (6.76 KB, patch)
2014-10-09 18:40 UTC, Carlos Soriano
reviewed Details | Review
gtkplacessidebar: Open $HOME after unmounting or ejecting (6.96 KB, patch)
2014-10-10 12:01 UTC, Carlos Soriano
reviewed Details | Review
gtkplacessidebar: Open $HOME after unmounting or ejecting (6.93 KB, patch)
2014-10-10 13:44 UTC, Carlos Soriano
committed Details | Review
gtkplacessidebar: Fix commit f6870e5b79fd9ab (2.39 KB, patch)
2014-10-12 01:59 UTC, Carlos Soriano
none Details | Review
gtkplacessidebar: Fix commit f6870e5b79fd9ab (2.49 KB, patch)
2014-10-12 02:20 UTC, Carlos Soriano
committed Details | Review

Description Carlos Soriano 2014-10-06 09:43:41 UTC
See patch
Comment 1 Carlos Soriano 2014-10-06 09:43:43 UTC
Created attachment 287823 [details] [review]
gtkplacessidebar: Open $HOME after unmounting or ejecting

When a drive is ejected or a volume unmounted the current directory
doesn't change most of the times being empty or being a directory that
user shouldn't take care about, like /run/media

Seems more useful to change to $HOME directory in that case so the user
can see something useful and familiar just after unmounting.
Comment 2 Matthias Clasen 2014-10-06 19:32:45 UTC
Review of attachment 287823 [details] [review]:

But we only want to switch to home if the unmounted/ejected volume contains the 'current' folder, right ?

Is that always the case ?
Comment 3 Carlos Soriano 2014-10-09 18:40:16 UTC
Created attachment 288163 [details] [review]
gtkplacessidebar: Don't change location if clicked on eject button

Currently we change the current location if we click the eject button of
a mount.

Check whether the user actually clicked the eject button and don't
change location in that case.
Comment 4 Carlos Soriano 2014-10-09 18:40:21 UTC
Created attachment 288164 [details] [review]
gtkplacessidebar: Open $HOME after unmounting or ejecting

When a drive is ejected or a volume unmounted the current directory
doesn't change most of the times being empty or being a directory that
user shouldn't take care about, like /run/media

Seems more useful to change to $HOME directory in that case so the user
can see something useful and familiar just after unmounting.
Comment 5 Matthias Clasen 2014-10-09 21:54:42 UTC
Review of attachment 288163 [details] [review]:

looks good
Comment 6 Matthias Clasen 2014-10-09 22:00:11 UTC
Review of attachment 288164 [details] [review]:

::: gtk/gtkplacessidebar.c
@@ +2721,3 @@
+                      GMount           *mount,
+                      GVolume          *volume,
+                      GDrive           *drive)

I think this could have a better name, like current_location_on_volume(), or so

@@ +2737,3 @@
+          mount_default_location = g_mount_get_default_location (mount);
+          needed_to_open_home = g_file_has_prefix (sidebar->current_location, mount_default_location) ||
+                                file_same_path (sidebar->current_location, mount_default_location);

Are you sure the same_path check is necessary ? My understanding of prefix would be <=, so I think the same path case should already be covered by the prefix test. If it isn't, I'd consider that a gio bug.

@@ +2742,3 @@
+      // this code path is probably never reached since mount always exists,
+      // and if it doesn't exists we don't offer a way to eject a volume or
+      // drive in the ui. do it for defensive programming

We don't use C99-style comments in GTK+ (mostly for historical reasons at this point), so please use
/* */. And follow the convention we use for comment formatting:

/* first line
 * more text
 */
Comment 7 Carlos Soriano 2014-10-10 12:01:54 UTC
Created attachment 288214 [details] [review]
gtkplacessidebar: Open $HOME after unmounting or ejecting

When a drive is ejected or a volume unmounted the current directory
doesn't change most of the times being empty or being a directory that
user shouldn't take care about, like /run/media

Seems more useful to change to $HOME directory in that case so the user
can see something useful and familiar just after unmounting.
Comment 8 Matthias Clasen 2014-10-10 12:54:23 UTC
Review of attachment 288214 [details] [review]:

::: gtk/gtkplacessidebar.c
@@ +2737,3 @@
+          mount_default_location = g_mount_get_default_location (mount);
+          current_location_on_volume = g_file_has_prefix (sidebar->current_location, mount_default_location) ||
+                                                          file_same_path (sidebar->current_location, mount_default_location);

sorry to come back to this one more time - maybe it would be nicer to avoid open-coding the || in 2 or 3 places, and just have a helper function that does the '<= prefix' check ? like

file_prefix_or_same (...)

@@ +2971,3 @@
+   *and if it doesn't exists we don't offer a way to eject a volume or
+   *drive in the UI. Do it for defensive programming
+   */

Almost :-) Now capitalize it and add a space between the * and the text. Sorry for being a pain
Comment 9 Carlos Soriano 2014-10-10 13:44:23 UTC
Created attachment 288223 [details] [review]
gtkplacessidebar: Open $HOME after unmounting or ejecting

When a drive is ejected or a volume unmounted the current directory
doesn't change most of the times being empty or being a directory that
user shouldn't take care about, like /run/media

Seems more useful to change to $HOME directory in that case so the user
can see something useful and familiar just after unmounting.
Comment 10 Carlos Soriano 2014-10-10 13:49:01 UTC
(In reply to comment #8)
> Review of attachment 288214 [details] [review]:
> 
> ::: gtk/gtkplacessidebar.c
> @@ +2737,3 @@
> +          mount_default_location = g_mount_get_default_location (mount);
> +          current_location_on_volume = g_file_has_prefix
> (sidebar->current_location, mount_default_location) ||
> +                                                          file_same_path
> (sidebar->current_location, mount_default_location);
> 
> sorry to come back to this one more time - maybe it would be nicer to avoid
> open-coding the || in 2 or 3 places, and just have a helper function that does
> the '<= prefix' check ? like
> 
> file_prefix_or_same (...)
> 
Indeed, much better
> @@ +2971,3 @@
> +   *and if it doesn't exists we don't offer a way to eject a volume or
> +   *drive in the UI. Do it for defensive programming
> +   */
> 
> Almost :-) Now capitalize it and add a space between the * and the text. Sorry
> for being a pain
actually sorry on my side for not double-check with existing gtk+ multiline comment formatting.
Comment 11 Matthias Clasen 2014-10-10 14:48:03 UTC
Review of attachment 288223 [details] [review]:

Looks good to commit, with that change

::: gtk/gtkplacessidebar.c
@@ +2721,3 @@
+
+  return strcmp (file1path, file2path) == 0;
+}

g_file_get_path can return NULL, so g_strcmp0() is advisable here.
Comment 12 Carlos Soriano 2014-10-10 16:27:43 UTC
Thanks for the tip, didn't know we have such kind of functions.

Attachment 288163 [details] pushed as 3c29212 - gtkplacessidebar: Don't change location if clicked on eject button
Attachment 288223 [details] pushed as f6870e5 - gtkplacessidebar: Open $HOME after unmounting or ejecting
Comment 13 Cosimo Cecchi 2014-10-10 19:44:31 UTC
Review of attachment 288223 [details] [review]:

I happened to see this going by and I saw some bugs with the code as committed  - please see below.

::: gtk/gtkplacessidebar.c
@@ +133,3 @@
   GtkTrashMonitor   *trash_monitor;
   GtkSettings       *gtk_settings;
+  GFile             *current_location;

You don't seem to unref this in dispose()

@@ +2720,3 @@
+  file2path = g_file_get_path (file2);
+
+  const gchar *file1path;

This doesn't look right...
- g_file_get_path() returns a newly allocated string that should be freed afterwards
- you can just use g_file_equal() instead

@@ +2787,3 @@
+                }
+            }
+          g_object_unref (mount_default_location);

Hmm, shouldn't this use g_list_free/g_list_free_full() instead?

@@ +4716,3 @@
+  if (sidebar->current_location != NULL)
+    g_object_unref (sidebar->current_location);
+  sidebar->current_location = g_file_dup (location);

Can't you g_object_ref(location) instead of calling g_file_dup()?
Comment 14 Carlos Soriano 2014-10-12 01:59:20 UTC
Created attachment 288297 [details] [review]
gtkplacessidebar: Fix commit f6870e5b79fd9ab

Commit f6870e5b79fd9ab introduced a some memory leaks and could be
improved in some areas.

Fix the memory leaks and apply the improvements.
Comment 15 Carlos Soriano 2014-10-12 02:00:37 UTC
(In reply to comment #13)
> Review of attachment 288223 [details] [review]:
> 
> I happened to see this going by and I saw some bugs with the code as committed 
> - please see below.
> 
> ::: gtk/gtkplacessidebar.c
> @@ +133,3 @@
>    GtkTrashMonitor   *trash_monitor;
>    GtkSettings       *gtk_settings;
> +  GFile             *current_location;
> 
> You don't seem to unref this in dispose()
> 
> @@ +2720,3 @@
> +  file2path = g_file_get_path (file2);
> +
> +  const gchar *file1path;
> 
> This doesn't look right...
> - g_file_get_path() returns a newly allocated string that should be freed
> afterwards
> - you can just use g_file_equal() instead
> 
> @@ +2787,3 @@
> +                }
> +            }
> +          g_object_unref (mount_default_location);
> 
> Hmm, shouldn't this use g_list_free/g_list_free_full() instead?
> 
> @@ +4716,3 @@
> +  if (sidebar->current_location != NULL)
> +    g_object_unref (sidebar->current_location);
> +  sidebar->current_location = g_file_dup (location);
> 
> Can't you g_object_ref(location) instead of calling g_file_dup()?

Thanks for the comments, and sorry for the bad code
Comment 16 Carlos Soriano 2014-10-12 02:20:55 UTC
Created attachment 288298 [details] [review]
gtkplacessidebar: Fix commit f6870e5b79fd9ab

Commit f6870e5b79fd9ab introduced a some memory leaks and could be
improved in some areas.

Fix the memory leaks and apply the improvements.
Comment 17 Ilja Sekler 2014-10-26 10:41:14 UTC
*** Bug 737987 has been marked as a duplicate of this bug. ***