#!/bin/sh
#
# Copyright (C) 2004-2005 Nokia Corporation.
#
# Author(s): Kimmo Hmlinen <kimmo.hamalainen@nokia.com>

DIR=/etc/osso-af-init

AF_DEFS=$DIR/af-defines.sh
source $AF_DEFS || exit 2

case "$1" in
start)  START=TRUE
        ;;
stop)   START=FALSE
        ;;
restart)
        echo "$0: not implemented"
        exit 1
        ;;
force-reload)
        echo "$0: not implemented"
        exit 1
        ;;
*)      echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac


if [ $START = TRUE ]; then
  # Wizards and Connectivity use Gtk
  source $DIR/osso-gtk.defs

  if [ -x /sbin/devlock-blocker ]; then
    # this blocks until the device is unlocked
    /sbin/devlock-blocker
  fi
  if [ -x /usr/bin/osso-connectivity-ui.sh ]; then
    /usr/bin/osso-connectivity-ui.sh start &
  fi

  # wait for the session bus
  /usr/sbin/waitdbus session
  if [ $? -gt 0 ]; then
    echo "$0: Error, the D-BUS session bus did not start"
    exit 2
  fi

  if [ -x $DIR/startup-greeting.sh ]; then
    $DIR/startup-greeting.sh start
  fi
  # ADD: Display operator welcome screen
  if [ -x /usr/bin/suw -a -e $HOME/first-boot-flag ]; then
    # we need to start VKB for the wizard...
    if [ -f $DIR/keyboard.defs ]; then
      source $DIR/keyboard.defs
    fi
    source $DIR/keyboard.sh start
    # give VKB some time to start
    sleep 5
    rm -f $HOME/first-boot-flag
    /usr/bin/suw
  fi
else
  if [ -x /usr/bin/osso-connectivity-ui.sh ]; then
    /usr/bin/osso-connectivity-ui.sh stop &
  fi
  if [ -x $DIR/osso-media-server.sh ]; then
    $DIR/osso-media-server.sh stop
  fi
fi
