#!/bin/sh
#
# Copyright (C) 2004-2005 Nokia. All rights reserved.
#
# 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
  source $DIR/osso-gtk.defs

  if [ -f $DIR/tasknav.defs ]; then
    source $DIR/tasknav.defs
  fi
  source $DIR/tasknav.sh start

  # first evil sleep hack in attempt to boost Task Navigator startup
  # (this should also reduce context switches)
  sleep 5

  if [ -f $DIR/home.defs ]; then
    source $DIR/home.defs
  fi
  source $DIR/home.sh start 

  # second evil sleep hack in attempt to boost Home startup
  sleep 5

  if [ -f $DIR/statusbar.defs ]; then
    source $DIR/statusbar.defs
  fi
  source $DIR/statusbar.sh start

  if [ -f $DIR/ke-recv.sh ]; then
    source $DIR/ke-recv.sh start
  fi

  if [ -f $DIR/keyboard.defs ]; then
    source $DIR/keyboard.defs
  fi
  source $DIR/keyboard.sh start

  # LD_PRELOAD script (only for media-server)
  LDPRELOADSCRIPT=/usr/bin/connectivity_preload.sh
  if [ -f $LDPRELOADSCRIPT ]; then
    source $LDPRELOADSCRIPT
  fi
  if [ -x $DIR/osso-media-server.sh ]; then
    $DIR/osso-media-server.sh start
  fi
  unset LD_PRELOAD

  if [ -x /usr/bin/clipboard-manager ]; then
    source $LAUNCHWRAPPER start clipboard-manager /usr/bin/clipboard-manager
  fi
else
  if [ -x /usr/bin/clipboard-manager ]; then
    source $LAUNCHWRAPPER stop clipboard-manager /usr/bin/clipboard-manager
  fi
  source $DIR/keyboard.sh stop
  if [ -f $DIR/ke-recv.sh ]; then
    source $DIR/ke-recv.sh stop
  fi
  source $DIR/statusbar.sh stop
  source $DIR/home.sh stop
  source $DIR/tasknav.sh stop
fi
