Sophie

Sophie

distrib > * > 2008.0 > x86_64 > by-pkgid > 31e1296274b13d07b478531793fc3fda > files > 20

kdebase-3.5.9-4mdv2008.0.src.rpm

--- kdebase-3.5.7/kdeeject/kdeeject.orig	2007-07-27 15:04:01.000000000 -0300
+++ kdebase-3.5.7/kdeeject/kdeeject	2007-07-27 14:48:41.000000000 -0300
@@ -4,37 +4,96 @@
 #
 # Copyright GPL v2 by David Faure <david@mandrakesoft.com>
 #
-if test $# -ge 1 -a "$1" != "--help"; then
-  quiet=0
-  if test "$1" = "-q"; then
-    quiet=1
-    shift
-  fi
-  # Checking for stuff in the PATH is ugly with sh.
-  # I guess this is the reason for making this a kde app...
-  OS=`uname -s`
-  case "$OS" in
-    OpenBSD)
-      cdio -f $1 eject >/dev/null 2>&1
-      ;;
-    *BSD)
-      dev=`echo $1 | sed -E -e 's#/dev/##' -e 's/([0-9])./\1/'`
-      cdcontrol -f $dev eject >/dev/null 2>&1
-      ;;
-    *)
-      # Warning, it has to be either eject 2.0.x or >=2.1.5
-      # Otherwise it doesn't work as expected (it requires a
-      # fstab entry for no reason).
-      eject $1 >/dev/null 2>&1
-      ;;
-  esac
-  if test $? -eq 0; then
-    dcop kdesktop default refreshIcons
-    exit 0
-  elif test $quiet -eq 0; then
-    kdialog --title "KDE Eject" --error "Eject $1 failed!"
-  fi
+
+eject_fallback ()
+{
+       echo "FALL BACK TO EJECT: $1"
+       eject $1
+}
+
+fatal_error ()
+{
+       echo "FATAL ERROR: $1"
+       exit 1;
+}
+
+quiet=0
+if test "$1" = "-q"; then
+  quiet=1
+  shift
+fi
+
+if test "$1" = "--help"; then
+  "Usage: $0 <name> where name is a device or a mountpoint."
+   exit 0
+fi
+
+if test -z "$1"; then
+  for dev in /dev/cdrom /dev/dvd /dev/dvdram /dev/cdrecorder; do
+     if test -e $dev; then
+        lp=`readlink $dev`
+	if test -n "$lp"; then
+	    device=/dev/$lp
+	else
+	    device=$dev
+        fi
+        break
+    fi
+  done
 else
-  kdialog --title "KDE Eject" --msgbox "Usage: $0 <name> where name is a device or a mountpoint."
+  device=`readlink -m -n $1`
+fi
+
+echo "Trying to eject device $device ...."
+ 
+# check if HAL userland tools are installed
+HAL_FIND_BY_PROP=""
+HAL_GET_PROP=""
+for dir in /usr/bin /usr/sbin /bin /sbin ; do
+	if test -e "${dir}/hal-find-by-property" && test -x "${dir}/hal-find-by-property"; then	
+		HAL_FIND_BY_PROP="${dir}/hal-find-by-property";
+	fi
+	if test -e "${dir}/hal-get-property" && test -x "${dir}/hal-get-property"; then	
+		HAL_GET_PROP="${dir}/hal-get-property";
+	fi
+	if test -n "$HAL_FIND_BY_PROP" && test -n "$HAL_GET_PROP"; then		
+		break;
+	fi
+done
+if test -n "$HAL_FIND_BY_PROP" && test -n "$HAL_GET_PROP"; then		
+       HAL_major=`${HAL_FIND_BY_PROP} --version | cut -d " " -f 2 | cut -d. -f1`
+       HAL_minor=`${HAL_FIND_BY_PROP} --version | cut -d " " -f 2 | cut -d. -f2`
+  # HAL umount and eject method exist only for HAL >= 0.5
+       if test $HAL_major -eq 0 -a  $HAL_minor -ge 5 -o $HAL_major -gt 0;  then
+         # Try to find the UDi from the device name
+               BLOCK_UDI=$(${HAL_FIND_BY_PROP} --key block.device --string "$device" | head -1)
+               [ -n "$BLOCK_UDI" ] || fatal_error "Can't find UDI for URL $device"
+               STORAGE_UDI=$(${HAL_GET_PROP} --udi $BLOCK_UDI --key block.storage_device)
+               [ -n "$STORAGE_UDI" ] || fatal_error "Can't find device for volume $BLOCK_UDI"
+
+         # Unmount each device volume
+               for VOLUME_UDI in $(${HAL_FIND_BY_PROP} --key block.storage_device --string $STORAGE_UDI); do
+                       [ $(${HAL_GET_PROP} --udi $VOLUME_UDI --key block.is_volume) = true ] || continue
+                       [ $(${HAL_GET_PROP} --udi $VOLUME_UDI --key volume.is_mounted) = true ] || continue
+                       ERROR=$(dcop kded mediamanager unmount $VOLUME_UDI)
+                       [ -n "$ERROR" ] && error "$ERROR"
+               done
+               [ $(${HAL_GET_PROP} --udi $VOLUME_UDI --key storage.requires_eject) = true ] &&
+               dbus-send --system --dest=org.freedesktop.Hal "$BLOCK_UDI" org.freedesktop.Hal.Device.Volume.Eject array:string:"" >/dev/null 2>&1
+       else
+    # fallback to the old eject method
+               eject_fallback $device
+       fi
+else
+  # fallback to the old eject method
+  eject_fallback $device
+fi
+
+# refresh icons if media eject succeeded
+if test $? -eq 0; then
+  dcop kdesktop default refreshIcons
+elif test $quiet -eq 0; then
+  fatal_error "Eject $device failed!"
 fi
-exit 1
+
+exit 0