#!/bin/bash

udi="$1"

if [ "$udi" != "${udi#gphoto2:}" ]; then
    # gphoto gvfs source, pass it on unmodified

    # make sure it's not mounted by gvfs, otherwise we can't access the camera
    # (current F-Spot version does not yet understand GIO)
    gvfs-mount -u "$udi" || true

    # transform GIO URL to a format f-spot understands
    uri=`echo "$udi" | sed 's_://\[_:_; s_/$__; s_\]$__'`

    exec f-spot --import "$uri"
    exit 1
fi

#xmessage $udi
mount_point=`hal-get-property --udi="$udi" --key=volume.mount_point`
if [ -n "$mount_point" ]; then
      # USB Mass Storage camera: need to pass f-spot a mount point

      f-spot --import "$mount_point"
else
     # Some other camera try GPhoto2

     bus=`hal-get-property --udi="$udi" --key=usb.bus_number`
     dev=`hal-get-property --udi="$udi" --key=usb.linux.device_number`
     uri=`printf gphoto2:usb:%.3d,%.3d $bus $dev`

     echo $uri

     f-spot --import "$uri"
fi
