#!/bin/bash

####
# A KDE interface to Nadav Harel's SendSMS with KDialog.
# In order to make this available in KAddressBook, set the following Script-Hook:
#
# /path/to/ksendsms.sh %N [Your_Name]
#
# * Your_Name will be taken from ENV if not given in command args
#
# * Make sure to update $SENDSMS for the path of sendsms
#
# * QT automagically provides us output in Hebrew in the correct format, so no logic is required.
#
# Copyright 2005 Ami Chayun. License: GNU GPL
#### 

export LANG="he_IL.ISO-8859-8" #We want to enable hebrew SMS as well

RCPT_PHONE=$1
SENDER_NAME=$2

SENDSMS=/usr/bin/sendsms

if test ! -f $SENDSMS; then
	kdialog --title "Sendsms is missing" --error "Could not find <b>$SENDSMS</b>"
	exit -1;
fi
if test -z "$RCPT_PHONE"; then
	kdialog --title "Required parameter missing" --error "<b>Usage:</b> $0 phonenum [sender]"
	exit -1;
fi

if test -z "$SENDER_NAME"; then
	SENDER_NAME=$USER
fi

MESSEGE=`kdialog --title "Type in your message" --textinputbox "From: <b>$SENDER_NAME</b><br>Type in your message to <b>$RCPT_PHONE</b><br>For more information See <a href=\"http://nadav.harel.org.il/software/sendsms/\">Nadav's</a> site<br><small>Note: Empty messege will not be sent</small>" "" 440 200`

if test -z "$MESSEGE"; then
	exit 0;
fi

#sendsms usage: [-lh] [-u 1/2/3] phonenum sender message
RESULT=`perl $SENDSMS $RCPT_PHONE "$SENDER_NAME" "$MESSEGE" 2>&1`

if [ $? -eq 0 ]; then
	kdialog --title "Send complete" --msgbox "$RESULT"
else
	kdialog --title "Send failed"  --error "$RESULT"
fi

