Linux: update xdg-utils again, and check in the built versions of the scripts.
Upstream hasn't built all the scripts from the .in versions in git, apparently.
BUG=73231
Review URL: http://codereview.chromium.org/6735024

git-svn-id: http://src.chromium.org/svn/trunk/deps/third_party/xdg-utils@80408 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
diff --git a/ChangeLog b/ChangeLog
index 3cb9171..f8c6089 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 === xdg-utils 1.1.x ===
 
+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)
+   * Initial support for DE=Darwin, Default for $BROWSER under Mac OS (BR35500)
+
 2011-03-28 Rex Dieter <rdieter@fedoraproject.org>
    * xdg-open cannot detect xfce 4.8 correctly (BR33321)
    * xdg-mime's info_generic doesn't normalize symlinks (BR33097)
diff --git a/README.chromium b/README.chromium
index dd87373..e06d0a6 100644
--- a/README.chromium
+++ b/README.chromium
@@ -1,9 +1,9 @@
 Name: xdg-utils
 URL: http://portland.freedesktop.org/wiki/
-Version: a616912e48b7ff1d908852739d16525df79471b9
+Version: ca33e673f7fd9173267843aac9668f692d48d6da
 
 Description:
-This directory contains a copy of xdg-utils obtained from git on 2011-03-30,
+This directory contains a copy of xdg-utils obtained from git on 2011-04-02,
 with this command:
 
 git clone git://anongit.freedesktop.org/xdg/xdg-utils xdg-utils
diff --git a/scripts/xdg-desktop-icon b/scripts/xdg-desktop-icon
index 219b702..1430a2f 100755
--- a/scripts/xdg-desktop-icon
+++ b/scripts/xdg-desktop-icon
@@ -408,8 +408,33 @@
     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 [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
-    else DE=""
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to checking $DESKTOP_SESSION
+      case "$DESKTOP_SESSION" in
+         LXDE)
+           DE=lxde; 
+           ;;
+         xfce|xfce4)
+           DE=xfce;
+           ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to uname output for other platforms
+      case "$(uname 2>/dev/null)" in 
+        Darwin)
+          DE=darwin;
+          ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"gnome" ]; then
+      # gnome-default-applications-properties is only available in GNOME 2.x
+      # but not in GNOME 3.x
+      which gnome-default-applications-properties 2> /dev/null || DE="gnome3"
     fi
 }
 
diff --git a/scripts/xdg-desktop-menu b/scripts/xdg-desktop-menu
index dfa90b6..3f2c897 100755
--- a/scripts/xdg-desktop-menu
+++ b/scripts/xdg-desktop-menu
@@ -82,7 +82,7 @@
     To add menu items to a new submenu the desktop-files must be preceded by a
     directory-file that describes the submenu. If multiple desktop-files are
     specified, all entries will be added to the same menu. If entries are
-    installed to a menu that has been created with a previous call to 
+    installed to a menu that has been created with a previous call to
     xdg-desktop-menu the entries will be installed in addition to any already
     existing entries.
 
@@ -604,8 +604,33 @@
     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 [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
-    else DE=""
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to checking $DESKTOP_SESSION
+      case "$DESKTOP_SESSION" in
+         LXDE)
+           DE=lxde; 
+           ;;
+         xfce|xfce4)
+           DE=xfce;
+           ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to uname output for other platforms
+      case "$(uname 2>/dev/null)" in 
+        Darwin)
+          DE=darwin;
+          ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"gnome" ]; then
+      # gnome-default-applications-properties is only available in GNOME 2.x
+      # but not in GNOME 3.x
+      which gnome-default-applications-properties 2> /dev/null || DE="gnome3"
     fi
 }
 
@@ -687,7 +712,7 @@
             # App already listed as default
             continue;
         fi
-        default_file="$1/defaults.list"
+        default_file="$(readlink -f "$1/defaults.list")"
         DEBUG 1 "Updating $default_file"
         grep -v "$MIME=" $default_file > ${default_file}.new 2> /dev/null
         if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then
diff --git a/scripts/xdg-desktop-menu.in b/scripts/xdg-desktop-menu.in
index 969f474..6c1e3a3 100644
--- a/scripts/xdg-desktop-menu.in
+++ b/scripts/xdg-desktop-menu.in
@@ -88,7 +88,7 @@
             # App already listed as default
             continue;
         fi
-        default_file="$1/defaults.list"
+        default_file="$(readlink -f "$1/defaults.list")"
         DEBUG 1 "Updating $default_file"
         grep -v "$MIME=" $default_file > ${default_file}.new 2> /dev/null
         if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then
diff --git a/scripts/xdg-email b/scripts/xdg-email
index 6ead033..3fe64a2 100755
--- a/scripts/xdg-email
+++ b/scripts/xdg-email
@@ -360,8 +360,33 @@
     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 [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
-    else DE=""
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to checking $DESKTOP_SESSION
+      case "$DESKTOP_SESSION" in
+         LXDE)
+           DE=lxde; 
+           ;;
+         xfce|xfce4)
+           DE=xfce;
+           ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to uname output for other platforms
+      case "$(uname 2>/dev/null)" in 
+        Darwin)
+          DE=darwin;
+          ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"gnome" ]; then
+      # gnome-default-applications-properties is only available in GNOME 2.x
+      # but not in GNOME 3.x
+      which gnome-default-applications-properties 2> /dev/null || DE="gnome3"
     fi
 }
 
@@ -473,6 +498,32 @@
     fi
 }
 
+open_gnome3()
+{
+    local client
+    local desktop
+    desktop=`xdg-mime query default "x-scheme-handler/mailto"`
+    client=`desktop_file_to_binary "$browser"`
+    echo $client | grep thunderbird > /dev/null 2>&1
+    if [ $? -eq 0 ] ; then
+        run_thunderbird "$client" "$1"
+    fi
+
+    if gvfs-open --help 2>/dev/null 1>&2; then
+        DEBUG 1 "Running gvfs-open \"$1\""
+        gvfs-open "$1"
+    else
+        DEBUG 1 "Running gnome-open \"$1\""
+        gnome-open "$1"
+    fi
+
+    if [ $? -eq 0 ]; then
+        exit_success
+    else
+        exit_failure_operation_failed
+    fi
+}
+
 open_gnome()
 {
     local client
@@ -713,6 +764,10 @@
     open_gnome "${mailto}"
     ;;
 
+    gnome3)
+    open_gnome3 "${mailto}"
+    ;;
+
     xfce)
     open_xfce "${mailto}"
     ;;
diff --git a/scripts/xdg-icon-resource b/scripts/xdg-icon-resource
index 8c61bf8..5f8c200 100755
--- a/scripts/xdg-icon-resource
+++ b/scripts/xdg-icon-resource
@@ -400,8 +400,33 @@
     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 [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
-    else DE=""
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to checking $DESKTOP_SESSION
+      case "$DESKTOP_SESSION" in
+         LXDE)
+           DE=lxde; 
+           ;;
+         xfce|xfce4)
+           DE=xfce;
+           ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to uname output for other platforms
+      case "$(uname 2>/dev/null)" in 
+        Darwin)
+          DE=darwin;
+          ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"gnome" ]; then
+      # gnome-default-applications-properties is only available in GNOME 2.x
+      # but not in GNOME 3.x
+      which gnome-default-applications-properties 2> /dev/null || DE="gnome3"
     fi
 }
 
diff --git a/scripts/xdg-mime b/scripts/xdg-mime
index 1171522..f0040de 100755
--- a/scripts/xdg-mime
+++ b/scripts/xdg-mime
@@ -430,8 +430,33 @@
     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 [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
-    else DE=""
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to checking $DESKTOP_SESSION
+      case "$DESKTOP_SESSION" in
+         LXDE)
+           DE=lxde; 
+           ;;
+         xfce|xfce4)
+           DE=xfce;
+           ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to uname output for other platforms
+      case "$(uname 2>/dev/null)" in 
+        Darwin)
+          DE=darwin;
+          ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"gnome" ]; then
+      # gnome-default-applications-properties is only available in GNOME 2.x
+      # but not in GNOME 3.x
+      which gnome-default-applications-properties 2> /dev/null || DE="gnome3"
     fi
 }
 
@@ -496,14 +521,17 @@
 
 info_gnome()
 {
-    file=`readlink -f "$1"` # Normalize path
-
     if gvfs-info --help 2>/dev/null 1>&2; then
-        DEBUG 1 "Running gvfs-info \"$file\""
-        gvfs-info "$file" 2> /dev/null | grep standard::content-type | cut -d' ' -f4
+        DEBUG 1 "Running gvfs-info \"$1\""
+        gvfs-info "$1" 2> /dev/null | grep standard::content-type | cut -d' ' -f4
+    elif gnomevfs-info --help 2>/dev/null 1>&2; then
+       DEBUG 1 "Running gnomevfs-info \"$1\""
+       gnomevfs-info --slow-mime "$1" 2> /dev/null | grep "^MIME" | cut -d ":" -f 2 | sed s/"^ "//
     else
-       DEBUG 1 "Running gnomevfs-info \"$file\""
-       gnomevfs-info --slow-mime "$file" 2> /dev/null | grep "^MIME" | cut -d ":" -f 2 | sed s/"^ "//
+       # according to https://bugs.freedesktop.org/show_bug.cgi?id=33094#c5
+       # neither gvfs-info or gnomevfs-info are present in a default Ubuntu Natty
+       # install, so fallback to info_generic
+       info_generic "$1"
     fi
 
     if [ $? -eq 0 ]; then
@@ -515,8 +543,13 @@
 
 info_generic()
 {
-    DEBUG 1 "Running file -i \"$1\""
-    /usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "//
+    if mimetype --version >/dev/null 2>&1; then
+        DEBUG 1 "Running mimetype -b \"$1\""
+        mimetype -b "$1"
+    else
+        DEBUG 1 "Running file -i \"$1\""
+        /usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "//
+    fi
 
     if [ $? -eq 0 ]; then
         exit_success
@@ -752,6 +785,7 @@
             ;;
         esac
         check_input_file "$filename"
+        filename=`readlink -f -- "$filename"`
         ;;
 
       default)
@@ -845,7 +879,7 @@
         info_kde "$filename"
         ;;
 
-        gnome)
+        gnome*)
         info_gnome "$filename"
         ;;
 
diff --git a/scripts/xdg-open b/scripts/xdg-open
index fee4204..8e5431b 100755
--- a/scripts/xdg-open
+++ b/scripts/xdg-open
@@ -307,8 +307,33 @@
     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 [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
-    else DE=""
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to checking $DESKTOP_SESSION
+      case "$DESKTOP_SESSION" in
+         LXDE)
+           DE=lxde; 
+           ;;
+         xfce|xfce4)
+           DE=xfce;
+           ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to uname output for other platforms
+      case "$(uname 2>/dev/null)" in 
+        Darwin)
+          DE=darwin;
+          ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"gnome" ]; then
+      # gnome-default-applications-properties is only available in GNOME 2.x
+      # but not in GNOME 3.x
+      which gnome-default-applications-properties 2> /dev/null || DE="gnome3"
     fi
 }
 
@@ -337,6 +362,23 @@
     echo "$first"
 }
 
+last_word()
+{
+    read first rest
+    echo "$rest"
+}
+
+open_darwin()
+{
+    open "$1"
+
+    if [ $? -eq 0 ]; then
+        exit_success
+    else
+        exit_failure_operation_failed
+    fi
+}
+
 open_kde()
 {
     if kde-open -v 2>/dev/null 1>&2; then
@@ -395,12 +437,26 @@
         [ -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
-            local file="$x/applications/$default"
+            local file
+            # look for both vendor-app.desktop, vendor/app.desktop
+            if [ -r "$x/applications/$default" ]; then
+              file="$x/applications/$default"
+            elif [ -r "$x/applications/`echo $default | sed -e 's|-|/|'`" ]; then
+              file="$x/applications/`echo $default | sed -e 's|-|/|'`"
+            fi
+
             if [ -r "$file" ] ; then
                 command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
                 command_exec=`which $command 2>/dev/null`
+                arguments="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | last_word`"
+                arguments_exec="`echo $arguments | sed -e 's*%[fFuU]*"'"$1"'"*g'`"
                 if [ -x "$command_exec" ] ; then
-                    $command_exec "$1"
+                    if echo $arguments | grep -iq '%[fFuU]' ; then
+                        eval $command_exec $arguments_exec
+                    else
+                        eval $command_exec $arguments_exec "$1"
+                    fi
+
                     if [ $? -eq 0 ]; then
                         exit_success
                     fi
@@ -536,7 +592,7 @@
     open_kde "$url"
     ;;
 
-    gnome)
+    gnome*)
     open_gnome "$url"
     ;;
 
diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in
index 8fe3beb..b3cb500 100644
--- a/scripts/xdg-open.in
+++ b/scripts/xdg-open.in
@@ -42,6 +42,17 @@
     echo "$rest"
 }
 
+open_darwin()
+{
+    open "$1"
+
+    if [ $? -eq 0 ]; then
+        exit_success
+    else
+        exit_failure_operation_failed
+    fi
+}
+
 open_kde()
 {
     if kde-open -v 2>/dev/null 1>&2; then
diff --git a/scripts/xdg-screensaver b/scripts/xdg-screensaver
index 2757c5b..c896334 100755
--- a/scripts/xdg-screensaver
+++ b/scripts/xdg-screensaver
@@ -335,8 +335,33 @@
     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 [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
-    else DE=""
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to checking $DESKTOP_SESSION
+      case "$DESKTOP_SESSION" in
+         LXDE)
+           DE=lxde; 
+           ;;
+         xfce|xfce4)
+           DE=xfce;
+           ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to uname output for other platforms
+      case "$(uname 2>/dev/null)" in 
+        Darwin)
+          DE=darwin;
+          ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"gnome" ]; then
+      # gnome-default-applications-properties is only available in GNOME 2.x
+      # but not in GNOME 3.x
+      which gnome-default-applications-properties 2> /dev/null || DE="gnome3"
     fi
 }
 
@@ -763,16 +788,18 @@
 
 screensaver_gnome_screensaver()
 {
-# TODO
-# There seems to be a DBUS interface for gnome-screensaver
-# See http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2006-April/042579.html and
-# http://cvs.gnome.org/viewcvs/gnome-screensaver/src/gs-listener-dbus.c?rev=1.36&view=log
-# A problem seems to be that Inhibit is tied to the lifetime of the DBUS appname and
-# this can not be used from a script
+# DBUS interface for gnome-screensaver
+# http://people.gnome.org/~mccann/gnome-screensaver/docs/gnome-screensaver.html
     case "$1" in
         suspend)
-        screensaver_suspend_loop gnome-screensaver-command --poke
-        result=0
+        screensaver_suspend_loop \
+        dbus-send --session \
+                  --dest=org.gnome.ScreenSaver \
+                  --type=method_call \
+                  /org/gnome/ScreenSaver \
+                  org.gnome.ScreenSaver.SimulateUserActivity \
+                  2> /dev/null
+        result=$?
         ;;
 
         resume)
@@ -781,7 +808,13 @@
         ;;
 
         activate)
-        gnome-screensaver-command --activate > /dev/null 2> /dev/null
+        dbus-send --session \
+                  --dest=org.gnome.ScreenSaver \
+                  --type=method_call \
+                  /org/gnome/ScreenSaver \
+                  org.gnome.ScreenSaver.SetActive \
+                  boolean:true \
+                  2> /dev/null
         result=$?
         ;;
 
@@ -792,18 +825,31 @@
 
         reset)
         # Turns the screensaver off right now
-        gnome-screensaver-command --deactivate > /dev/null 2> /dev/null
+        dbus-send --session \
+                  --dest=org.gnome.ScreenSaver \
+                  --type=method_call \
+                  /org/gnome/ScreenSaver \
+                  org.gnome.ScreenSaver.SimulateUserActivity \
+                 2> /dev/null
         result=$?
         ;;
 
         status)
-        result=0
-        if [ -f "$screensaver_file" ] ; then
-            echo "disabled"
-        elif gnome-screensaver-command --query > /dev/null 2> /dev/null; then
+        status=`dbus-send --session \
+                          --dest=org.gnome.ScreenSaver \
+                          --type=method_call \
+                          --print-reply \
+                          --reply-timeout=2000 \
+                          /org/gnome/ScreenSaver \
+                          org.gnome.ScreenSaver.GetActive \
+                          | grep boolean | cut -d ' ' -f 5`
+        result=$?
+        if [ x"$status" = "xtrue" -o x"$status" = "xfalse" ]; then
             echo "enabled"
+        elif [ x"$result" != "x0" ]; then
+            echo "ERROR: dbus org.gnome.ScreenSaver.GetActive returned '$status'" >&2
+            return 1
         else
-            # Something is wrong
             echo "disabled"
         fi
         ;;
diff --git a/scripts/xdg-screensaver.in b/scripts/xdg-screensaver.in
index 6f2bc1b..ea89dd0 100644
--- a/scripts/xdg-screensaver.in
+++ b/scripts/xdg-screensaver.in
@@ -431,16 +431,18 @@
 
 screensaver_gnome_screensaver()
 {
-# TODO
-# There seems to be a DBUS interface for gnome-screensaver
-# See http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2006-April/042579.html and
-# http://cvs.gnome.org/viewcvs/gnome-screensaver/src/gs-listener-dbus.c?rev=1.36&view=log
-# A problem seems to be that Inhibit is tied to the lifetime of the DBUS appname and
-# this can not be used from a script
+# DBUS interface for gnome-screensaver
+# http://people.gnome.org/~mccann/gnome-screensaver/docs/gnome-screensaver.html
     case "$1" in
         suspend)
-        screensaver_suspend_loop gnome-screensaver-command --poke
-        result=0
+        screensaver_suspend_loop \
+        dbus-send --session \
+                  --dest=org.gnome.ScreenSaver \
+                  --type=method_call \
+                  /org/gnome/ScreenSaver \
+                  org.gnome.ScreenSaver.SimulateUserActivity \
+                  2> /dev/null
+        result=$?
         ;;
 
         resume)
@@ -449,7 +451,13 @@
         ;;
 
         activate)
-        gnome-screensaver-command --activate > /dev/null 2> /dev/null
+        dbus-send --session \
+                  --dest=org.gnome.ScreenSaver \
+                  --type=method_call \
+                  /org/gnome/ScreenSaver \
+                  org.gnome.ScreenSaver.SetActive \
+                  boolean:true \
+                  2> /dev/null
         result=$?
         ;;
 
@@ -460,18 +468,31 @@
 
         reset)
         # Turns the screensaver off right now
-        gnome-screensaver-command --deactivate > /dev/null 2> /dev/null
+        dbus-send --session \
+                  --dest=org.gnome.ScreenSaver \
+                  --type=method_call \
+                  /org/gnome/ScreenSaver \
+                  org.gnome.ScreenSaver.SimulateUserActivity \
+                 2> /dev/null
         result=$?
         ;;
 
         status)
-        result=0
-        if [ -f "$screensaver_file" ] ; then
-            echo "disabled"
-        elif gnome-screensaver-command --query > /dev/null 2> /dev/null; then
+        status=`dbus-send --session \
+                          --dest=org.gnome.ScreenSaver \
+                          --type=method_call \
+                          --print-reply \
+                          --reply-timeout=2000 \
+                          /org/gnome/ScreenSaver \
+                          org.gnome.ScreenSaver.GetActive \
+                          | grep boolean | cut -d ' ' -f 5`
+        result=$?
+        if [ x"$status" = "xtrue" -o x"$status" = "xfalse" ]; then
             echo "enabled"
+        elif [ x"$result" != "x0" ]; then
+            echo "ERROR: dbus org.gnome.ScreenSaver.GetActive returned '$status'" >&2
+            return 1
         else
-            # Something is wrong
             echo "disabled"
         fi
         ;;
diff --git a/scripts/xdg-settings b/scripts/xdg-settings
index ad9b56d..a017448 100755
--- a/scripts/xdg-settings
+++ b/scripts/xdg-settings
@@ -315,8 +315,33 @@
     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 [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
-    else DE=""
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to checking $DESKTOP_SESSION
+      case "$DESKTOP_SESSION" in
+         LXDE)
+           DE=lxde; 
+           ;;
+         xfce|xfce4)
+           DE=xfce;
+           ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"" ]; then
+      # fallback to uname output for other platforms
+      case "$(uname 2>/dev/null)" in 
+        Darwin)
+          DE=darwin;
+          ;;
+      esac
+    fi
+
+    if [ x"$DE" = x"gnome" ]; then
+      # gnome-default-applications-properties is only available in GNOME 2.x
+      # but not in GNOME 3.x
+      which gnome-default-applications-properties 2> /dev/null || DE="gnome3"
     fi
 }
 
@@ -419,21 +444,26 @@
 # This function is hard-coded for text/html but it could be adapted if needed.
 fix_local_desktop_file()
 {
+    if test -z "$2" ; then
+        MIME="text/html"
+    else
+        MIME="$2"
+    fi
     apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
     # No local desktop file?
     [ ! -f "$apps/$1" ] && return
-    MIME="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`"
-    case "$MIME" in
-      text/html\;*|*\;text/html\;*|*\;text/html\;|*\;text/html)
-        # Already has text/html? Great!
+    MIMETYPES="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`"
+    case "$MIMETYPES" in
+      $MIME\;*|*\;$MIME\;*|*\;$MIME\;|*\;$MIME)
+        # Already has the mime-type? Great!
         return 0
         ;;
     esac
 
-    # Add text/html to the list
+    # Add the mime-type to the list
     temp="`mktemp "$apps/$1.XXXXXX"`" || return
     grep -v "^MimeType=" "$apps/$1" >> "$temp"
-    echo "MimeType=text/html;$MIME" >> "$temp"
+    echo "MimeType=$MIME;$MIMETYPES" >> "$temp"
 
     oldlines="`wc -l < "$apps/$1"`"
     newlines="`wc -l < "$temp"`"
@@ -467,22 +497,32 @@
 
 get_browser_mime()
 {
+    if test -z "$1" ; then
+        MIME="text/html"
+    else
+        MIME="$1"
+    fi
     xdg_mime_fixup
-    xdg-mime query default text/html
+    xdg-mime query default "$MIME"
 }
 
 set_browser_mime()
 {
     xdg_mime_fixup
-    orig="`get_browser_mime`"
+    if test -z "$2" ; then
+        MIME="text/html"
+    else
+        MIME="$2"
+    fi
+    orig="`get_browser_mime $MIME`"
     # Fixing the local desktop file can actually change the default browser all
     # by itself, so we fix it only after querying to find the current default.
-    fix_local_desktop_file "$1" || return
+    fix_local_desktop_file "$1" "$MIME" || return
     mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications"
-    xdg-mime default "$1" text/html || return
+    xdg-mime default "$1" "$MIME" || return
     if [ x"`get_browser_mime`" != x"$1" ]; then
         # Put back the original value
-        xdg-mime default "$orig" text/html
+        xdg-mime default "$orig" "$MIME"
         exit_failure_operation_failed
     fi
 }
@@ -652,6 +692,45 @@
 }
 
 # }}} GNOME
+# {{{ GNOME 3.x
+
+get_browser_gnome3()
+{
+    get_browser_mime "x-scheme-handler/http"
+}
+
+check_browser_gnome3()
+{
+    desktop="$1"
+    check="`desktop_file_to_binary "$1"`"
+    if [ -z "$check" ]; then
+        echo no
+        exit_success
+    fi
+    # Check HTTP and HTTPS, but not about: and unknown:.
+    for protocol in http https; do
+        browser="`get_browser_mime "x-scheme-handler/$protocol"`"
+        if [ x"$browser" != x"$desktop" ]; then
+            echo no
+            exit_success
+        fi
+    done
+    echo yes
+    exit_success
+}
+
+set_browser_gnome3()
+{
+    binary="`desktop_file_to_binary "$1"`"
+    [ "$binary" ] || exit_failure_file_missing
+    set_browser_mime "$1" || return
+
+    # Set the default browser.
+    for protocol in http https about unknown; do
+        set_browser_mime "$1" "x-scheme-handler/$protocol" || return
+    done
+}
+# }}} GNOME 3.x
 # {{{ xfce
 
 get_browser_xfce()
@@ -861,7 +940,7 @@
 detectDE
 
 case "$DE" in
-    kde|gnome|xfce)
+    kde|gnome*|xfce)
     dispatch_specific "$@"
     ;;
 
diff --git a/scripts/xdg-utils-common.in b/scripts/xdg-utils-common.in
index 80e0fd5..5ec2585 100644
--- a/scripts/xdg-utils-common.in
+++ b/scripts/xdg-utils-common.in
@@ -200,7 +200,7 @@
     fi
 
     if [ x"$DE" = x"" ]; then
-    # if all else fails, fallback to checking $DESKTOP_SESSION
+      # fallback to checking $DESKTOP_SESSION
       case "$DESKTOP_SESSION" in
          LXDE)
            DE=lxde; 
@@ -211,6 +211,15 @@
       esac
     fi
 
+    if [ x"$DE" = x"" ]; then
+      # fallback to uname output for other platforms
+      case "$(uname 2>/dev/null)" in 
+        Darwin)
+          DE=darwin;
+          ;;
+      esac
+    fi
+
     if [ x"$DE" = x"gnome" ]; then
       # gnome-default-applications-properties is only available in GNOME 2.x
       # but not in GNOME 3.x