#!/bin/sh
#
# Copyright (C) 2004-2005 Nokia Corporation.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA


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

CONNECTIVITY_UI_SCRIPT=/usr/bin/osso-connectivity-ui.sh

if [ $START = TRUE ]; then
  if [ -f $DIR/osso-application-installer.defs ]; then
    source $DIR/osso-application-installer.defs
  fi
  source $DIR/osso-gtk.defs

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

  # boost desktop startup
  sleep 6

  if [ -x $CONNECTIVITY_UI_SCRIPT ]; then
    source $CONNECTIVITY_UI_SCRIPT start
  fi

  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

  if [ -x $DIR/osso-media-server.sh ]; then
    $DIR/osso-media-server.sh start
  fi

  if [ -f $DIR/clipboard.sh ]; then
    source $DIR/clipboard.sh start
  fi
else
  if [ -f $DIR/clipboard.sh ]; then
    source $DIR/clipboard.sh stop
  fi
  source $DIR/keyboard.sh stop
  if [ -f $DIR/ke-recv.sh ]; then
    source $DIR/ke-recv.sh stop
  fi
  if [ -x $CONNECTIVITY_UI_SCRIPT ]; then
    source $CONNECTIVITY_UI_SCRIPT stop
  fi
  source $DIR/maemo-af-desktop.sh stop
fi
