#! /bin/sh
# 
# Gtkdialog box for the mount command. Part of SliTaz tools.
#
VERSION=20080113

# Check if user is root.
check_root()
{
	if test $(id -u) != 0 ; then
		echo -e "
You must be root to run `basename $0`. Please type 'su' and 
root password to become super-user.\n"
		exit 0
	fi
}

export FDISK_LIST='
<window title="Fdisk -l" icon-name="media-flash">
  <vbox>
    <text use-markup="true">
      <label>"
<b>Harddisk devices list</b>"
      </label>
    </text>
    <frame Partitions table>
      <text wrap="false" width-chars="58">
        <input>fdisk -l | grep ^/dev</input>
      </text>
    </frame>
    <hbox>
      <button>
        <input file icon="exit"></input>
        <action type="closewindow">FDISK_LIST</action>
      </button>
    </hbox>
  </vbox>
</window>
'

export MOUNTED='
<window title="Mounted devices" icon-name="media-flash">
  <vbox>
    <text use-markup="true">
      <label>"
<b>Mounted devices list</b>"
      </label>
    </text>
    <frame Devices and mount points>
      <text wrap="false" width-chars="58">
        <input>mount | grep ^/dev/[c-s]d</input>
      </text>
    </frame>
    <hbox>
      <button>
        <input file icon="exit"></input>
        <action type="closewindow">MOUNTED</action>
      </button>
    </hbox>
  </vbox>
</window>
'

# Mount and umount buttons with fiel for devive and mount point.
#
export MOUNT_DIALOG='
<window title="Mountbox" icon-name="media-flash">
  <vbox>
 
    <text use-markup="true">
      <label>
"
<b>SliTaz - Mountbox</b>"
      </label>
    </text>
    <text wrap="true" width-chars="44" use-markup="true">
      <label>
"
Mount device on a mount point. Device can be cdrom, 
flash key, USB disk or local HD partitions.
"
      </label>
    </text>
  
    <frame Configuration>
      <hbox>
        <text use-markup="true">
          <label>"<b>Device             : </b>"</label>
        </text>     
        <combobox>
          <variable>DEVICE</variable>
          <item>/dev/sda1</item>
          <item>/dev/sdb2</item>
          <item>/dev/cdrom</item>
          <item>/dev/hda1</item>
        </combobox>
        <button>
          <label>List</label>
          <input file icon="drive-harddisk"></input>
	      <action type="launch">FDISK_LIST</action>
        </button>
      </hbox>
  
      <hbox>
        <text use-markup="true">
          <label>"<b>Mount point   : </b>"</label>
        </text>
        <combobox>
          <variable>MOUNT_POINT</variable>
          <item>/media/flash</item>
          <item>/media/usbdisk</item>
          <item>/media/cdrom</item>
          <item>/mnt/harddisk</item>
        </combobox>
        <button>
          <label>List</label>
          <input file icon="drive-harddisk"></input>
	      <action type="launch">MOUNTED</action>
        </button>
      </hbox>
    </frame>
    
    <hbox>
      <button>
        <label>Mount</label>
        <input file icon="forward"></input>
        <action>echo "Mounting $DEVICE..."</action>
        <action>mkdir -p $MOUNT_POINT; mount $DEVICE $MOUNT_POINT; sleep 1</action>
        <action>mount | grep $DEVICE; echo "Done."</action>
      </button>
      <button>
        <label>Umount</label>
        <input file icon="undo"></input>
        <action>echo "Unmounting $MOUNT_POINT..."</action>
        <action>umount $MOUNT_POINT; sleep 1</action>
        <action>mount | grep $DEVICE; echo "Done."</action>
      </button>
      <button>
        <label>Browse</label>
        <input file icon="folder"></input>
        <action>pcmanfm $MOUNT_POINT</action>
      </button>
      <button>
        <label>Eject</label>
        <input file icon="media-cdrom"></input>
        <action>eject</action>
      </button>
      <button>
        <input file icon="exit"></input>
        <action type="exit">Exit</action>
      </button>
    </hbox>
  </vbox>
</window>
'

# Only root can mount.
check_root
gtkdialog --center --program=MOUNT_DIALOG

exit 0
