#!/bin/sh

#	Script to copy files to your home directory
#
# dependencies
#	bash
#   zenity
#
# Ingemar Karlsson <ingemar@ingk.se>
# salixos.ingk.se
#
#	version 0.2.0 2012-01-01
#
#	Rewrite of first version with different file for each directory
#	so we get only one file to use.
#	Using XDG utils for getting path to the different directorys.

#		English language		#
strFILE="File:"
strEXISTS="already exists in $strPATH.\nOverwrite?"
strOVERW="Overwrite?"
strARGS_ERROR="Missing arguments!"
strERROR="ERROR!"

case $LANG in
#		Swedish language		#
	sv* )
		strFILE="Filen:"
		strEXISTS="finns redan i $strPATH.\nSkriva över?"
		strOVERW="Skriva över?"
		strARGS_ERROR="Saknar parametrar!"
		strERROR="FEL!"
	;;
esac

# Get path to users home.
strHOME=`echo $HOME`
# Get XDG dirs from config file.
source $strHOME/.config/user-dirs.dirs
# Get were to copy/move file.
strDIR=${1#*_}
# Get if we do a copy or move action.
strCMD=${1%_*}

case $strDIR in
	picture)
		strPATH=$XDG_PICTURES_DIR
	;;
	video)
		strPATH=$XDG_VIDEOS_DIR
	;;
	music)
		strPATH=$XDG_MUSIC_DIR
	;;
	document)
		strPATH=$XDG_DOCUMENTS_DIR
	;;
	*)
		zenity --info --title="$strERROR" --text="$strARGS_ERROR"
		exit 1
	;;
esac

# Get the path where the file is.
strPATH_C=`pwd`

for arg 
do
	if [ "${arg%_*}" != "cp" ] && [ "${arg%_*}" != "mv" ]; then
		if [ -f "$strPATH/$arg" ];    then
			MSG="$strFILE '$arg' $strEXISTS"
			zenity --question --title="$strOVERW" --text="$MSG"
			case "$?" in
				1  )  
					exit 1 
					;;
				0  )  
					"$strCMD" "$strPATH_C/$arg" "$strPATH/$arg"
					;;
			esac
		else
			"$strCMD" "$strPATH_C/$arg" "$strPATH/$arg"
		fi
	fi
done
