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 709771 - Background chooser lists 'null' pictures_dir directory
Background chooser lists 'null' pictures_dir directory
Status: RESOLVED FIXED
Product: gnome-control-center
Classification: Core
Component: Background
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Debarshi Ray
Control-Center Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-10-09 20:20 UTC by Jason Gerecke
Modified: 2014-02-13 11:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
background: Guard against XDG_PICTURES_DIR not being defined (5.60 KB, patch)
2014-02-11 15:41 UTC, Debarshi Ray
needs-work Details | Review
background: Guard against XDG_PICTURES_DIR not being defined (2.80 KB, patch)
2014-02-12 15:41 UTC, Debarshi Ray
reviewed Details | Review
background: Guard against XDG_PICTURES_DIR not being defined (2.80 KB, patch)
2014-02-13 08:30 UTC, Debarshi Ray
committed Details | Review
background: Use GLib API to convert absolute filename to URI (1.52 KB, patch)
2014-02-13 08:58 UTC, Debarshi Ray
committed Details | Review

Description Jason Gerecke 2013-10-09 20:20:58 UTC
If G_USER_DIRECTORY_PICTURES is not defined (e.g. because the necessary XDG variables have not been set), the background chooser shows the following message on the "Pictures" tab:

"You can add images to your (null) folder and they will show up here"

If G_USER_DIRECTORY_PICTURES is not defined, the background chooser should either display pictures from a fallback location (e.g. '~/') or allow the user to select their Pictures directory and set the appropriate XDG variable in '~/.config/user-dirs.dirs'.
Comment 1 Debarshi Ray 2014-02-11 15:41:03 UTC
(In reply to comment #0)
> If G_USER_DIRECTORY_PICTURES is not defined, the background chooser should
> either display pictures from a fallback location (e.g. '~/') or allow the user
> to select their Pictures directory and set the appropriate XDG variable in
> '~/.config/user-dirs.dirs'.

I think XDG_PICTURES_DIR not being defined is indicative of a broken system. Not sure we need to have any elaborate fallback mechanism. Distributions should just define the variable.
Comment 2 Debarshi Ray 2014-02-11 15:41:35 UTC
Created attachment 268803 [details] [review]
background: Guard against XDG_PICTURES_DIR not being defined
Comment 3 Jason Gerecke 2014-02-11 18:56:01 UTC
(In reply to comment #1)
> I think XDG_PICTURES_DIR not being defined is indicative of a broken system.
> Not sure we need to have any elaborate fallback mechanism. Distributions should
> just define the variable.
For shrinkwrapped distros, certianly. If XDG_PICTURES_DIR isn't defined, then the user has clearly broken something and there's little reason to bother holding their hand. For the more cobbled-together distros such as Gentoo and Arch, its debatable whether not this is really a "broken" condition (perhaps xdg-user-dirs should be a dependency of GNOME; perhaps `g_get_user_special_dir` should define a fallback for more than just G_USER_DIRECTORY_DESKTOP if XDG special user directories have not been set up...)

(In reply to comment #2)
> Created an attachment (id=268803) [details] [review]
> background: Guard against XDG_PICTURES_DIR not being defined
This could use some improvement. You really should display a message explaining how the user can resolve an error if at all possible. A flat "No Pictures Found" is entirely un-helpful: I'd used my Arch system for nearly a year before bug 630892 added the "you can add images..." message that wound up cluing me in to the fact that GNOME had no idea /where/ my Pictures directory was.

Perhaps changing the message to "You must define a Pictures folder to use this feature." would be sufficient for this particular case. Its no elaborate fallback, but it does at least provide a clue about what is going wrong.
Comment 4 Bastien Nocera 2014-02-12 14:43:58 UTC
Review of attachment 268803 [details] [review]:

::: panels/background/bg-pictures-source.c
@@ -720,2 @@
   pictures_path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
-  g_mkdir_with_parents (pictures_path, USER_DIR_MODE);

if (pictures_path == NULL)
  pictures_path = g_get_home_dir();

That's how fallback is defined in the users dirs "spec".

::: panels/background/cc-background-chooser-dialog.c
@@ +389,1 @@
   pictures_dir = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);

Ditto.
Comment 5 Debarshi Ray 2014-02-12 15:41:40 UTC
Created attachment 268923 [details] [review]
background: Guard against XDG_PICTURES_DIR not being defined
Comment 6 Bastien Nocera 2014-02-12 17:04:28 UTC
Review of attachment 268923 [details] [review]:

::: panels/background/cc-background-chooser-dialog.c
@@ +392,3 @@
   gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+

Whitespace change here.

@@ +400,3 @@
+       * directory in the string below when XDG_PICTURES_DIR is
+       * undefined */
+      pictures_dir_basename = g_strdup (_("home"));

"Home" better? That's the string nautilus/GTK+ use.

@@ +405,3 @@
+    pictures_dir_basename = g_path_get_basename (pictures_dir);
+
+  href = g_markup_printf_escaped ("<a href=\"file://%s\">%s</a>", pictures_dir, pictures_dir_basename);

That's definitely not how you construct a URL.
Use g_filename_to_uri()

(I realise it was broken before, please fix it in a subsequent patch).
Comment 7 Debarshi Ray 2014-02-12 17:07:11 UTC
(In reply to comment #6)
> Review of attachment 268923 [details] [review]:
> 
> ::: panels/background/cc-background-chooser-dialog.c
> @@ +392,3 @@
>    gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
>    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
> +
> 
> Whitespace change here.

That was deliberate for the sake of readability.

> @@ +400,3 @@
> +       * directory in the string below when XDG_PICTURES_DIR is
> +       * undefined */
> +      pictures_dir_basename = g_strdup (_("home"));
> 
> "Home" better? That's the string nautilus/GTK+ use.

Ok.

> @@ +405,3 @@
> +    pictures_dir_basename = g_path_get_basename (pictures_dir);
> +
> +  href = g_markup_printf_escaped ("<a href=\"file://%s\">%s</a>",
> pictures_dir, pictures_dir_basename);
> 
> That's definitely not how you construct a URL.
> Use g_filename_to_uri()
> 
> (I realise it was broken before, please fix it in a subsequent patch).

Ok.
Comment 8 Debarshi Ray 2014-02-13 08:30:14 UTC
Created attachment 268990 [details] [review]
background: Guard against XDG_PICTURES_DIR not being defined

s/home/Home/
Comment 9 Debarshi Ray 2014-02-13 08:58:37 UTC
Created attachment 268991 [details] [review]
background: Use GLib API to convert absolute filename to URI
Comment 10 Bastien Nocera 2014-02-13 10:57:01 UTC
Review of attachment 268990 [details] [review]:

Looks good.
Comment 11 Bastien Nocera 2014-02-13 10:57:27 UTC
Review of attachment 268991 [details] [review]:

Looks good.
Comment 12 Debarshi Ray 2014-02-13 11:38:49 UTC
Thanks for the reviews!