sflphone-callto 1.65 KB
Newer Older
1 2 3
#!/bin/sh
#
# This script can be used as a callto: (or other) protocol handler in
4
# Mozilla Firefox-based browser.
5 6 7 8
# In Firefox use Preferences > Applications and set the callto handler
# to this script.

# The sflphone daemon config file
9
RESFILE=~/.config/sflphone/sflphoned.yml
10

11
# Parse sflphonedrc and get default account id string
12
if [ -f "$RESFILE" ]; then
13

14 15
# Test if a SFLphone client is already open, if not open a new one
# Opening a new client will start sflphoned if not already running
Adrien Béraud's avatar
Adrien Béraud committed
16
SFLPHONEC=`ps -A | grep ring-client`
17
if [ "$SFLPHONEC" = "" ]; then
Adrien Béraud's avatar
Adrien Béraud committed
18
    ring-client-gnome&
19 20
fi

21 22 23 24 25 26 27
# FIXME: this doesn't check if account is enabled, and is unreadable/unmaintainable.
# D-Bus API should be fixed so that we can simply dial and let the daemon worry
# about which account (default account? most recently used?) should place the
# call.
#
# Use first ID
ACCOUNTID=`grep order $RESFILE | sed -e 's/order: IP2IP\///' -e 's/\/.*//' | tr -d ' '`
28

29
else
30
    echo Fatal: Can't find sflphoned.yml config file.
31 32 33 34
    exit 1
fi

# Check 1st argument (phone number)
35
if [ -z $1 ]; then
36 37 38 39
    echo "Error: argument 1 (phone number) not provided."
    exit 1
fi

40
# Cleanup destination, keeping numbers only
41
TO="`echo $1 | sed -e 's/[^0123456789]//g'`"
42 43

# Generate call id.
44
CALLID=${RANDOM}$$
45 46 47 48 49 50 51 52 53 54

dbus-send                                           \
    --type="method_call"                            \
    --dest="org.sflphone.SFLphone"                  \
    "/org/sflphone/SFLphone/CallManager"            \
    "org.sflphone.SFLphone.CallManager.placeCall"   \
    string:"$ACCOUNTID"                             \
    string:"$CALLID"                                \
    string:"$TO"

55 56
exit 0

57
# EOF