#!/bin/sh
#
# This file is part of osso-af-startup.
#
# Copyright (C) 2004-2006 Nokia Corporation. All rights reserved.
#
# Contact: Kimmo Hmlinen <kimmo.hamalainen@nokia.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License 
# version 2 as published by the Free Software Foundation. 
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA

case "$1" in
start)

  # this is used by the input methods for disabling features in startup
  touch /tmp/im_disable_tools_menu

  echo "Running xset770 -- the future of xset!"
  # disable keyrepeat for select, menu, plus, minus, escape
  xset770 -r 36 0 -r 70 0 -r 73 0 -r 74 0 -r 9 0

  # block here if device lock is on
  if [ -x /sbin/devlock-blocker ]; then
    /sbin/devlock-blocker
  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
  source $SESSION_BUS_ADDRESS_FILE

  if [ -x /etc/osso-af-init/maemo-launcher ]; then
    /etc/osso-af-init/maemo-launcher start
  fi

  if [ -x $AF_INIT_DIR/startup-greeting.sh ]; then
    source $AF_INIT_DIR/startup-greeting.sh start
  fi

  if [ -e $HOME/first-boot-flag ]; then
    if [ -x $AF_INIT_DIR/startup-wizard.sh ]; then
      source $AF_INIT_DIR/startup-wizard.sh start
      source $AF_INIT_DIR/af-defines.sh ;# re-read locale variables
      # show progress animation
      /usr/sbin/anim-shower 10000 &
      # restart processes because the locale might have changed
      source $AF_INIT_DIR/after-suw-process-restart.sh
    fi

    # Give Backup a chance to restore settings automatically
    if [ -x $AF_INIT_DIR/osso-backup-startup.sh ]; then
      $AF_INIT_DIR/osso-backup-startup.sh
    fi

    if [ -x $AF_INIT_DIR/osso-connectivity-ui-gwwizard-startup.sh \
         -a ! -f /tmp/suw-user-cancelled.tmp ]; then
      $AF_INIT_DIR/osso-connectivity-ui-gwwizard-startup.sh start
    fi
    if [ -f $TMPDIR/launch-operator-wizard.tmp \
         -a ! -f /tmp/suw-user-cancelled.tmp ]; then
      if [ -x $AF_INIT_DIR/operator-wizard.sh ]; then
        $AF_INIT_DIR/operator-wizard.sh start
      fi
      rm -f $TMPDIR/launch-operator-wizard.tmp
    fi
    rm -f $HOME/first-boot-flag
    rm -f /tmp/suw-user-cancelled.tmp
  else
    if [ -x $AF_INIT_DIR/startup-wizard.sh ]; then
      source $AF_INIT_DIR/startup-wizard.sh start
    fi
  fi

  rm -f /tmp/im_disable_tools_menu

  ;;
stop)

  if [ -x $AF_INIT_DIR/osso-media-server.sh ]; then
    $AF_INIT_DIR/osso-media-server.sh stop
  fi

  ;;
restart)
  echo "$0: not implemented"
  exit 1
  ;;
force-reload)
  echo "$0: not implemented"
  exit 1
  ;;
*)
  echo "Usage: $0 {start|stop}"
  exit 1
  ;;
esac
