Bug 19011

Summary: xdg-desktop-icon (v1.0.2) does not use localized desktop folder name under GNOME
Product: Portland Reporter: Florian Höch <florian.hoech>
Component: xdg-utilsAssignee: Rex Dieter <rdieter>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: fabo
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Proposed patch for xdg-desktop-icon, using user-dirs.dirs

Description Florian Höch 2008-12-10 16:47:11 UTC
For example, the "Desktop" folder on a french Ubuntu Intrepid is "Bureau", but if I read the source code correctly "$HOME/Desktop" is hard-coded and used when under GNOME (did not try KDE).
Comment 1 Florian Höch 2008-12-10 19:57:00 UTC
Created attachment 21029 [details] [review]
Proposed patch for xdg-desktop-icon, using user-dirs.dirs
Comment 2 Rex Dieter 2008-12-11 05:49:11 UTC
Don't forget about (global): /etc/xdg/user-dirs.conf
Comment 3 Florian Höch 2008-12-11 13:53:36 UTC
Comment on attachment 21029 [details] [review]
Proposed patch for xdg-desktop-icon, using user-dirs.dirs

--- xdg-desktop-icon.bak	Sun Jun 24 20:57:56 2007
+++ xdg-desktop-icon	Thu Dec 11 22:51:11 2008
@@ -496,6 +496,15 @@
 
 my_umask=077
 desktop_dir="$HOME/Desktop"
+# Is xdg-user-dirs present and enabled ?
+if [ -e /etc/xdg/user-dirs.conf ] && cat /etc/xdg/user-dirs.conf | grep enabled=True > /dev/null; then
+    DESKTOP=Desktop
+    # Try to get global defaults
+    test -f /etc/xdg/user-dirs.defaults && source /etc/xdg/user-dirs.defaults
+    # Try to get user-defined settings
+    test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && source ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
+    desktop_dir=${XDG_DESKTOP_DIR:-$HOME/$DESKTOP}
+fi
 desktop_dir_kde=`kde-config --userpath desktop 2> /dev/null`
 if gconftool-2 -g /apps/nautilus/preferences/desktop_is_home_dir 2> /dev/null | grep true > /dev/null; then
     desktop_dir_gnome="$HOME"
Comment 4 Rex Dieter 2008-12-11 13:56:39 UTC
Come to think of it, why not just use the output from:
xdg-user-dir DESKTOP
? (if the tool exists, and returns non-empty of course).
Comment 5 Florian Höch 2008-12-11 14:10:36 UTC
Sounds reasonable. But after looking at the xdg-user-dir source, it seems it would return the desktop directory configured in user-dirs.dirs (if it contains any) or default to $HOME/Desktop, even when user-dirs.conf says enabled=False, and ignore user-dirs.defaults (if I'm not mistaken).
Comment 6 Florian Höch 2008-12-20 08:39:49 UTC
Comment on attachment 21029 [details] [review]
Proposed patch for xdg-desktop-icon, using user-dirs.dirs

I've updated the patch because there was still a problem on some systems (Error "source: not found").
Also, I've added support for kde4 and spaces in desktop directory and file names should now also work.
I can confirm this patch is working on atleast three distributions (tested by another user on fedora 9 livecd with norwegian gnome and ubuntu 8.10 with norwegian gnome, and tested by me on german opensuse 11 with kde4 and gnome and desktop directory renamed to "Schreibtisch")

--- xdg-desktop-icon.bak	Sun Jun 24 20:57:56 2007
+++ xdg-desktop-icon	Sat Dec 20 02:07:42 2008
@@ -495,50 +495,71 @@
 esac
 
 my_umask=077
-desktop_dir="$HOME/Desktop"
+# Is xdg-user-dirs present and enabled ?
+if ( [ -e ${XDG_CONFIG_HOME:-~/.config}/user-dirs.conf ] && cat ${XDG_CONFIG_HOME:-~/.config}/user-dirs.conf || ( [ -e /etc/xdg/user-dirs.conf ] && cat /etc/xdg/user-dirs.conf ) ) | grep enabled=True > /dev/null; then
+    DESKTOP=Desktop
+    # Try to get global defaults
+    [ -f /etc/xdg/user-dirs.defaults ] && . /etc/xdg/user-dirs.defaults
+    # Try to get user-defined settings
+    [ -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs ] && . ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
+    desktop_dir=${XDG_DESKTOP_DIR:-$HOME/$DESKTOP}
+else
+    desktop_dir="$HOME/Desktop"
+fi
 desktop_dir_kde=`kde-config --userpath desktop 2> /dev/null`
+desktop_dir_kde4=`kde4-config --userpath desktop 2> /dev/null`
 if gconftool-2 -g /apps/nautilus/preferences/desktop_is_home_dir 2> /dev/null | grep true > /dev/null; then
     desktop_dir_gnome="$HOME"
     # Don't create $HOME/Desktop if it doesn't exist
-    [ -w $desktop_dir ] || desktop_dir=
+    [ -w "$desktop_dir" ] || desktop_dir=
 fi
-if [ -n "$desktop_dir_kde" ]; then
-    if [ ! -d "$desktop_dir_kde" ]; then
-        save_umask=`umask`
-        umask $my_umask
-        mkdir -p $desktop_dir_kde
-        umask $save_umask
-    fi
-    # Is the KDE desktop dir != $HOME/Desktop ?
-    if [ x`readlink -f "$desktop_dir"` != x`readlink -f "$desktop_dir_kde"` ]; then
-        # If so, don't create $HOME/Desktop if it doesn't exist
-        [ -w $desktop_dir ] || desktop_dir=
-    else
-        desktop_dir_kde=
+for x in "$desktop_dir_kde" "$desktop_dir_kde4" ; do
+    if [ -n "$x" ]; then
+        if [ ! -d "$x" ]; then
+            save_umask=`umask`
+            umask $my_umask
+            mkdir -p "$x"
+            umask $save_umask
+        fi
+        # Is the KDE desktop dir != $desktop_dir ?
+        if [ x"`readlink -f "$desktop_dir"`" != x"`readlink -f "$x"`" ]; then
+            # If so, don't create $desktop_dir if it doesn't exist
+            [ -w "$desktop_dir" ] || desktop_dir=
+        else
+            if [ "$x" = "$desktop_dir_kde" ]; then
+                desktop_dir_kde=
+            fi
+            if [ "$x" = "$desktop_dir_kde4" ]; then
+                desktop_dir_kde4=
+            fi
+        fi
     fi
-fi
-desktop_dir="$desktop_dir $desktop_dir_kde $desktop_dir_gnome"
+done
 
-basefile=`basename $desktop_file`
+basefile=`basename "$desktop_file"`
 
-DEBUG 1 "$action $desktop_file in $desktop_dir"
+DEBUG 1 "$action $desktop_file in $desktop_dir $desktop_dir_kde $desktop_dir_kde4 $desktop_dir_gnome"
 
 case $action in
     install)
         save_umask=`umask`
         umask $my_umask
 
-        for x in $desktop_dir ; do
-            mkdir -p $x
-            eval 'cp $desktop_file $x/$basefile'$xdg_redirect_output
+        for x in "$desktop_dir" "$desktop_dir_kde" "$desktop_dir_kde4" "$desktop_dir_gnome" ; do
+            if [ -n "$x" ]; then
+                mkdir -p "$x"
+                eval 'cp "$desktop_file" "$x/$basefile"'$xdg_redirect_output
+            fi
         done
 
         umask $save_umask
         ;;
 
     uninstall)
-        for x in $desktop_dir ; do
-            rm -f $x/$basefile
+        for x in "$desktop_dir" "$desktop_dir_kde" "$desktop_dir_kde4" "$desktop_dir_gnome" ; do
+            if [ -n "$x" ]; then
+                rm -f "$x/$basefile"
+            fi
         done
 
         ;;
Comment 7 Rex Dieter 2010-07-09 07:06:28 UTC
Sorry for dropping the ball here, but later incarnations of the proposed patch are far from clear here.

I'll try to do my best to integrate what I can, though I'll be honest up front and say I'm going with using the output of
xdg-user-dir DESKTOP
rather than manually parsing it's config files.
Comment 8 Rex Dieter 2010-07-09 07:50:56 UTC
in cvs now.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.