Linux: update xdg-utils to the latest version to get relevant xdg-mime fixes.
BUG=73231
Review URL: http://codereview.chromium.org/6873103

git-svn-id: http://src.chromium.org/svn/trunk/deps/third_party/xdg-utils@82210 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
diff --git a/ChangeLog b/ChangeLog
index f8c6089..d73393f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 === xdg-utils 1.1.x ===
 
+2011-04-14 Rex Dieter <rdieter@fedoraproject.org>
+   * xdg-open does not detect xfce (BR25941)
+   * xdg-open's list of fallback browsers excludes seamonkey (BR33699)
+   * text BROWSER=+elinks
+   * xdg-open is sensitive to default grep options (BR34164)
+   * xdg-{open,email} should try x-www-browser (BR33095)
+   * xdg-email outputs errors with localized KDE4 (BR32924)
+   * xdg-email runs kmailservice with incorrect locale (BR33106)
+   * spurious capture of which in KMIMETYPEFINDER (BR31444)
+
+2011-04-12 Rex Dieter <rdieter@fedoraproject.org>
+   * suppress 'which gnome-default-applications-properties' output.  Thanks to Mike Mammarella.
+
+2011-04-08 Rex Dieter <rdieter@fedoraproject.org>
+   * xdg-mime: add mimeapps.list support. Thanks to Chris Coulson.
+
 2011-03-31 Rex Dieter <rdieter@fedoraproject.org>
    * Don't overwrite a /usr/share/applications/defaults.list symlink (BR35794)
    * Use D-Bus API for GNOME screensaver (BR29860)
diff --git a/README.chromium b/README.chromium
index e06d0a6..233c749 100644
--- a/README.chromium
+++ b/README.chromium
@@ -1,14 +1,15 @@
 Name: xdg-utils
 URL: http://portland.freedesktop.org/wiki/
-Version: ca33e673f7fd9173267843aac9668f692d48d6da
+Version: 2c7ff0948d7db32042aa29c5b1213746d78ce852
 
 Description:
-This directory contains a copy of xdg-utils obtained from git on 2011-04-02,
+This directory contains a copy of xdg-utils obtained from git on 2011-04-19,
 with this command:
 
 git clone git://anongit.freedesktop.org/xdg/xdg-utils xdg-utils
 
 The .gitignore files were converted to svn:ignore properties to check it in.
+Also, the scripts have been regenerated, since the checked in copies are old.
 
 Originally, it had been modified to add the xdg-settings command for getting
 and, in some cases, setting various GNU/Linux desktop environment settings like
diff --git a/scripts/xdg-desktop-icon b/scripts/xdg-desktop-icon
index e25b81a..f4f6cfa 100755
--- a/scripts/xdg-desktop-icon
+++ b/scripts/xdg-desktop-icon
@@ -404,15 +404,21 @@
 
 detectDE()
 {
+    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+    unset GREP_OPTIONS
+
     if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
     elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
     elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
     elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+    elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
     fi
 
     if [ x"$DE" = x"" ]; then
       # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
+         gnome)
+           DE=gnome;
          LXDE)
            DE=lxde; 
            ;;
@@ -445,7 +451,6 @@
 
 kfmclient_fix_exit_code()
 {
-    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
     version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
     major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
     minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
diff --git a/scripts/xdg-desktop-menu b/scripts/xdg-desktop-menu
index 140b8af..32d9905 100755
--- a/scripts/xdg-desktop-menu
+++ b/scripts/xdg-desktop-menu
@@ -600,15 +600,21 @@
 
 detectDE()
 {
+    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+    unset GREP_OPTIONS
+
     if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
     elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
     elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
     elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+    elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
     fi
 
     if [ x"$DE" = x"" ]; then
       # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
+         gnome)
+           DE=gnome;
          LXDE)
            DE=lxde; 
            ;;
@@ -641,7 +647,6 @@
 
 kfmclient_fix_exit_code()
 {
-    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
     version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
     major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
     minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
diff --git a/scripts/xdg-email b/scripts/xdg-email
index 0b98b77..0422dab 100755
--- a/scripts/xdg-email
+++ b/scripts/xdg-email
@@ -356,15 +356,21 @@
 
 detectDE()
 {
+    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+    unset GREP_OPTIONS
+
     if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
     elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
     elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
     elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+    elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
     fi
 
     if [ x"$DE" = x"" ]; then
       # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
+         gnome)
+           DE=gnome;
          LXDE)
            DE=lxde; 
            ;;
@@ -397,7 +403,6 @@
 
 kfmclient_fix_exit_code()
 {
-    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
     version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
     major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
     minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
@@ -484,12 +489,12 @@
     DEBUG 1 "Running kmailservice \"$1\""
     if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
         KMAILSERVICE=`kde4-config --locate kmailservice --path exe 2>/dev/null`
+        $KMAILSERVICE "$1"
     else
         KMAILSERVICE=`which kmailservice 2>/dev/null`
+        # KDE3 uses locale's encoding when decoding the URI, so set it to UTF-8
+        LC_ALL=C.UTF-8 $KMAILSERVICE "$1"
     fi
-    # KDE uses locale's encoding when decoding the URI, so set it to UTF-8
-    LC_ALL=C.UTF-8 $KMAILSERVICE "$1"
-    kfmclient_fix_exit_code $?
 
     if [ $? -eq 0 ]; then
         exit_success
@@ -749,9 +754,9 @@
 
 # if BROWSER variable is not set, check some well known browsers instead
 if [ x"$BROWSER" = x"" ]; then
-    BROWSER=links2:links:lynx:w3m
+    BROWSER=links2:elinks:links:lynx:w3m
     if [ -n "$DISPLAY" ]; then
-        BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
+        BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
     fi
 fi
 
diff --git a/scripts/xdg-email.in b/scripts/xdg-email.in
index 1066e1f..bbfb604 100644
--- a/scripts/xdg-email.in
+++ b/scripts/xdg-email.in
@@ -106,12 +106,12 @@
     DEBUG 1 "Running kmailservice \"$1\""
     if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
         KMAILSERVICE=`kde4-config --locate kmailservice --path exe 2>/dev/null`
+        $KMAILSERVICE "$1"
     else
         KMAILSERVICE=`which kmailservice 2>/dev/null`
+        # KDE3 uses locale's encoding when decoding the URI, so set it to UTF-8
+        LC_ALL=C.UTF-8 $KMAILSERVICE "$1"
     fi
-    # KDE uses locale's encoding when decoding the URI, so set it to UTF-8
-    LC_ALL=C.UTF-8 $KMAILSERVICE "$1"
-    kfmclient_fix_exit_code $?
 
     if [ $? -eq 0 ]; then
         exit_success
@@ -371,9 +371,9 @@
 
 # if BROWSER variable is not set, check some well known browsers instead
 if [ x"$BROWSER" = x"" ]; then
-    BROWSER=links2:links:lynx:w3m
+    BROWSER=links2:elinks:links:lynx:w3m
     if [ -n "$DISPLAY" ]; then
-        BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
+        BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
     fi
 fi
 
diff --git a/scripts/xdg-icon-resource b/scripts/xdg-icon-resource
index f88282d..b74aec4 100755
--- a/scripts/xdg-icon-resource
+++ b/scripts/xdg-icon-resource
@@ -396,15 +396,21 @@
 
 detectDE()
 {
+    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+    unset GREP_OPTIONS
+
     if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
     elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
     elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
     elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+    elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
     fi
 
     if [ x"$DE" = x"" ]; then
       # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
+         gnome)
+           DE=gnome;
          LXDE)
            DE=lxde; 
            ;;
@@ -437,7 +443,6 @@
 
 kfmclient_fix_exit_code()
 {
-    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
     version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
     major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
     minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
diff --git a/scripts/xdg-mime b/scripts/xdg-mime
index 6b81810..254346a 100755
--- a/scripts/xdg-mime
+++ b/scripts/xdg-mime
@@ -426,15 +426,21 @@
 
 detectDE()
 {
+    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+    unset GREP_OPTIONS
+
     if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
     elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
     elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
     elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+    elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
     fi
 
     if [ x"$DE" = x"" ]; then
       # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
+         gnome)
+           DE=gnome;
          LXDE)
            DE=lxde; 
            ;;
@@ -467,7 +473,6 @@
 
 kfmclient_fix_exit_code()
 {
-    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
     version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
     major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
     minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
@@ -504,12 +509,10 @@
 {
     if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
         DEBUG 1 "Running kmimetypefinder \"$1\""
-        KMIMETYPEFINDER=`which kmimetypefinder 2>/dev/null`
-        $KMIMETYPEFINDER "$1" 2>/dev/null | head -n 1
+        kmimetypefinder "$1" 2>/dev/null | head -n 1
     else
         DEBUG 1 "Running kfile \"$1\""
-        KFILE=`which kfile 2>/dev/null`
-        $KFILE "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1
+        kfile "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1
     fi
 
     if [ $? -eq 0 ]; then
@@ -689,18 +692,60 @@
 {
     # $1 is vendor-name.desktop
     # $2 is mime/type
-    # Add $2=$1 to XDG_DATA_HOME/applications/defaults.list
+    # Add $2=$1 to XDG_DATA_HOME/applications/mimeapps.list
     xdg_user_dir="$XDG_DATA_HOME"
     [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
-    default_file="$xdg_user_dir/applications/defaults.list"
+    default_file="$xdg_user_dir/applications/mimeapps.list"
     DEBUG 2 "make_default_generic $1 $2"
     DEBUG 1 "Updating $default_file"
-    grep -v "$2=" $default_file > ${default_file}.new 2> /dev/null
-    if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then
-       echo "[Default Applications]" >> ${default_file}.new
-    fi
-    echo $2=$1 >> ${default_file}.new
-    mv ${default_file}.new $default_file
+    awk -v mimetype="$2" -v application="$1" '
+    BEGIN {
+        prefix=mimetype "="
+        indefault=0
+        added=0
+        blanks=0
+        found=0
+    }
+    {
+        suppress=0
+        if (index($0, "[Default Applications]") == 1) {
+            indefault=1
+            found=1
+        } else if (index($0, "[") == 1) {
+            if (!added && indefault) {
+                print prefix application
+                added=1
+            }
+            indefault=0
+        } else if ($0 == "") {
+            suppress=1
+            blanks++
+        } else if (indefault && !added && index($0, prefix) == 1) {
+                $0=prefix application
+                added=1
+        }
+        if (!suppress) {
+            while (blanks > 0) {
+                print ""
+                blanks--
+            }
+            print $0
+        }
+    }
+    END {
+        if (!added) {
+            if (!found) {
+                print ""
+                print "[Default Applications]"
+            }
+            print prefix application
+        }
+        while (blanks > 0) {
+            print ""
+            blanks--
+        }
+    }
+' $default_file > ${default_file}.new && mv ${default_file}.new $default_file
 }
 
 defapp_generic()
@@ -712,7 +757,35 @@
     xdg_system_dirs="$XDG_DATA_DIRS"
     [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
 
-    for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
+    for x in `echo "$xdg_user_dir" | sed 's/:/ /g'`; do
+        mimeapps_list="$x/applications/mimeapps.list"
+        if [ -f "$mimeapps_list" ] ; then
+            DEBUG 2 "Checking $mimeapps_list"
+            trader_result=`awk -v mimetype="$MIME" '
+    BEGIN {
+        prefix=mimetype "="
+        indefault=0
+        found=0
+    }
+    {
+        if (index($0, "[Default Applications]") == 1) {
+            indefault=1
+        } else if (index($0, "[") == 1) {
+            indefault=0
+        } else if (!found && indefault && index($0, prefix) == 1) {
+            print substr($0, length(prefix) +1, length)
+            found=1
+        }
+    }
+' $mimeapps_list`
+            if [ -n "$trader_result" ] ; then
+                echo $trader_result
+                exit_success
+            fi
+        fi
+    done
+
+    for x in `echo "$xdg_system_dirs" | sed 's/:/ /g'`; do
        DEBUG 2 "Checking $x/applications/defaults.list"
        trader_result=`grep "$MIME=" $x/applications/defaults.list 2> /dev/null | cut -d '=' -f 2 | cut -d ';' -f 1`
        if [ -n "$trader_result" ] ; then
diff --git a/scripts/xdg-mime.in b/scripts/xdg-mime.in
index 930c141..8b66323 100644
--- a/scripts/xdg-mime.in
+++ b/scripts/xdg-mime.in
@@ -56,12 +56,10 @@
 {
     if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
         DEBUG 1 "Running kmimetypefinder \"$1\""
-        KMIMETYPEFINDER=`which kmimetypefinder 2>/dev/null`
-        $KMIMETYPEFINDER "$1" 2>/dev/null | head -n 1
+        kmimetypefinder "$1" 2>/dev/null | head -n 1
     else
         DEBUG 1 "Running kfile \"$1\""
-        KFILE=`which kfile 2>/dev/null`
-        $KFILE "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1
+        kfile "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1
     fi
 
     if [ $? -eq 0 ]; then
@@ -241,18 +239,60 @@
 {
     # $1 is vendor-name.desktop
     # $2 is mime/type
-    # Add $2=$1 to XDG_DATA_HOME/applications/defaults.list
+    # Add $2=$1 to XDG_DATA_HOME/applications/mimeapps.list
     xdg_user_dir="$XDG_DATA_HOME"
     [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
-    default_file="$xdg_user_dir/applications/defaults.list"
+    default_file="$xdg_user_dir/applications/mimeapps.list"
     DEBUG 2 "make_default_generic $1 $2"
     DEBUG 1 "Updating $default_file"
-    grep -v "$2=" $default_file > ${default_file}.new 2> /dev/null
-    if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then
-       echo "[Default Applications]" >> ${default_file}.new
-    fi
-    echo $2=$1 >> ${default_file}.new
-    mv ${default_file}.new $default_file
+    awk -v mimetype="$2" -v application="$1" '
+    BEGIN {
+        prefix=mimetype "="
+        indefault=0
+        added=0
+        blanks=0
+        found=0
+    }
+    {
+        suppress=0
+        if (index($0, "[Default Applications]") == 1) {
+            indefault=1
+            found=1
+        } else if (index($0, "[") == 1) {
+            if (!added && indefault) {
+                print prefix application
+                added=1
+            }
+            indefault=0
+        } else if ($0 == "") {
+            suppress=1
+            blanks++
+        } else if (indefault && !added && index($0, prefix) == 1) {
+                $0=prefix application
+                added=1
+        }
+        if (!suppress) {
+            while (blanks > 0) {
+                print ""
+                blanks--
+            }
+            print $0
+        }
+    }
+    END {
+        if (!added) {
+            if (!found) {
+                print ""
+                print "[Default Applications]"
+            }
+            print prefix application
+        }
+        while (blanks > 0) {
+            print ""
+            blanks--
+        }
+    }
+' $default_file > ${default_file}.new && mv ${default_file}.new $default_file
 }
 
 defapp_generic()
@@ -264,7 +304,35 @@
     xdg_system_dirs="$XDG_DATA_DIRS"
     [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
 
-    for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
+    for x in `echo "$xdg_user_dir" | sed 's/:/ /g'`; do
+        mimeapps_list="$x/applications/mimeapps.list"
+        if [ -f "$mimeapps_list" ] ; then
+            DEBUG 2 "Checking $mimeapps_list"
+            trader_result=`awk -v mimetype="$MIME" '
+    BEGIN {
+        prefix=mimetype "="
+        indefault=0
+        found=0
+    }
+    {
+        if (index($0, "[Default Applications]") == 1) {
+            indefault=1
+        } else if (index($0, "[") == 1) {
+            indefault=0
+        } else if (!found && indefault && index($0, prefix) == 1) {
+            print substr($0, length(prefix) +1, length)
+            found=1
+        }
+    }
+' $mimeapps_list`
+            if [ -n "$trader_result" ] ; then
+                echo $trader_result
+                exit_success
+            fi
+        fi
+    done
+
+    for x in `echo "$xdg_system_dirs" | sed 's/:/ /g'`; do
        DEBUG 2 "Checking $x/applications/defaults.list"
        trader_result=`grep "$MIME=" $x/applications/defaults.list 2> /dev/null | cut -d '=' -f 2 | cut -d ';' -f 1`
        if [ -n "$trader_result" ] ; then
diff --git a/scripts/xdg-open b/scripts/xdg-open
index cab2874..1b3df2c 100755
--- a/scripts/xdg-open
+++ b/scripts/xdg-open
@@ -303,15 +303,21 @@
 
 detectDE()
 {
+    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+    unset GREP_OPTIONS
+
     if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
     elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
     elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
     elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+    elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
     fi
 
     if [ x"$DE" = x"" ]; then
       # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
+         gnome)
+           DE=gnome;
          LXDE)
            DE=lxde; 
            ;;
@@ -344,7 +350,6 @@
 
 kfmclient_fix_exit_code()
 {
-    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
     version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
     major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
     minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
@@ -581,9 +586,9 @@
 
 # if BROWSER variable is not set, check some well known browsers instead
 if [ x"$BROWSER" = x"" ]; then
-    BROWSER=links2:links:lynx:w3m
+    BROWSER=links2:elinks:links:lynx:w3m
     if [ -n "$DISPLAY" ]; then
-        BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
+        BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
     fi
 fi
 
diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in
index b3cb500..b84a9cb 100644
--- a/scripts/xdg-open.in
+++ b/scripts/xdg-open.in
@@ -255,9 +255,9 @@
 
 # if BROWSER variable is not set, check some well known browsers instead
 if [ x"$BROWSER" = x"" ]; then
-    BROWSER=links2:links:lynx:w3m
+    BROWSER=links2:elinks:links:lynx:w3m
     if [ -n "$DISPLAY" ]; then
-        BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
+        BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
     fi
 fi
 
diff --git a/scripts/xdg-screensaver b/scripts/xdg-screensaver
index 14c7f3f..6c0239d 100755
--- a/scripts/xdg-screensaver
+++ b/scripts/xdg-screensaver
@@ -331,15 +331,21 @@
 
 detectDE()
 {
+    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+    unset GREP_OPTIONS
+
     if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
     elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
     elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
     elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+    elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
     fi
 
     if [ x"$DE" = x"" ]; then
       # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
+         gnome)
+           DE=gnome;
          LXDE)
            DE=lxde; 
            ;;
@@ -372,7 +378,6 @@
 
 kfmclient_fix_exit_code()
 {
-    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
     version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
     major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
     minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
diff --git a/scripts/xdg-settings b/scripts/xdg-settings
index 096ce99..e0c7912 100755
--- a/scripts/xdg-settings
+++ b/scripts/xdg-settings
@@ -311,15 +311,21 @@
 
 detectDE()
 {
+    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+    unset GREP_OPTIONS
+
     if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
     elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
     elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
     elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+    elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
     fi
 
     if [ x"$DE" = x"" ]; then
       # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
+         gnome)
+           DE=gnome;
          LXDE)
            DE=lxde; 
            ;;
@@ -352,7 +358,6 @@
 
 kfmclient_fix_exit_code()
 {
-    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
     version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
     major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
     minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
diff --git a/scripts/xdg-utils-common.in b/scripts/xdg-utils-common.in
index f383593..521a37d 100644
--- a/scripts/xdg-utils-common.in
+++ b/scripts/xdg-utils-common.in
@@ -193,15 +193,21 @@
 
 detectDE()
 {
+    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+    unset GREP_OPTIONS
+
     if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
     elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
     elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
     elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+    elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
     fi
 
     if [ x"$DE" = x"" ]; then
       # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
+         gnome)
+           DE=gnome;
          LXDE)
            DE=lxde; 
            ;;
@@ -234,7 +240,6 @@
 
 kfmclient_fix_exit_code()
 {
-    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
     version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
     major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
     minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`