#!/bin/sh
#
# Here and Now        Copyright (c) Andrew Flegg 2010
# ~~~~~~~~~~~~        Released under the Artistic Licence
#
# Provide access to Nokia's "Here and Now" service, as
# delivered on Symbian^3.

DATA=`dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_registration_status`

cat >/dev/null <<__INFO__
DBUS_TYPE_BYTE, &status,
DBUS_TYPE_UINT16, &lac,
DBUS_TYPE_UINT32, &cell_id,
DBUS_TYPE_UINT32, &operator_code,
DBUS_TYPE_UINT32, &country_code,
DBUS_TYPE_BYTE, &network_type,
DBUS_TYPE_BYTE, &supported_services,
DBUS_TYPE_INT32, &net_err,

http://ics.svc.ovi.com/ics/app?page=livestream/herenow&service=page&uuid=0224c5e878ab0427448ae41031e6411ad58c0265&mcc=234&mnc=15&cmcc=234&cmnc=15&cid=263&bear=&lac=177&language=1&width=320&height=320&tz=p0100&vejr=HN_S60_2.0
ethod return sender=:1.19 -> dest=:1.185 reply_serial=2
   byte 0
   uint16 177
   uint32 37032
   uint32 15
   uint32 234
   byte 0

__INFO__
lac=`echo $DATA | awk '{print $10}'`
cid=`echo $DATA | awk '{print $12}'`
opc=`echo $DATA | awk '{print $14}'`
cc=`echo $DATA | awk '{print $16}'`
tz=`date +%z | tr +- pm`

echo $DATA
echo $lac
echo $cid
echo $opc
echo $cc
echo $tz

if [ -z "$lac" || "$lac" == "0"]; then
  dbus-send --print-reply --type=method_call \
      --dest=org.freedesktop.Notifications   \
      /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog \
      string:'Unable to read location' uint32:0 string:'NAO OK!'
  exit 1
fi

url="http://ics.svc.ovi.com/ics/app?page=livestream/herenow&service=page&mcc=$cc&mnc=$opc&cmcc=$cc&cmnc=$opc&cid=$cid&bear=&lac=$lac&language=1&width=800&height=480&tz=$tz&vejr=HN_S60_2.0"
echo "$url"

dbus-send --print-reply --type=method_call --dest=com.nokia.osso_browser /com/nokia/osso_browser com.nokia.osso_browser.open_new_window string:"$url"
