#!/bin/sh

# Use dbus-launch if installed.
if test x"$DBUS_SESSION_BUS_ADDRESS" = x""; then
	dbuslaunch=`which dbus-launch`
	if test x"$dbuslaunch" != x"" -a x"$dbuslaunch" != x"no"; then
		eval `$dbuslaunch --sh-syntax --exit-with-session`
	fi
fi

# Use ssh-agent if installed and not already running.  Run it separately
# so it populates the environment here, so we can clean it up later.
sshagent=`which ssh-agent`
if test -z "$SSH_AGENT_PID" -a "$sshagent" -a "x$sshagent" != "xno"; then
	eval `$sshagent -s`
fi

# $XDG_CONFIG_HOME defines the base directory relative to which user specific 
# configuration files should be stored. If $XDG_CONFIG_HOME is either not set 
# or empty, a default equal to $HOME/.config should be used.
if test "x$XDG_CONFIG_HOME" = "x" ; then
  XDG_CONFIG_HOME=$HOME/.config
fi
[ -d "$XDG_CONFIG_HOME" ] || mkdir "$XDG_CONFIG_HOME"

# $XDG_CACHE_HOME defines the base directory relative to which user specific 
# non-essential data files should be stored. If $XDG_CACHE_HOME is either not 
# set or empty, a default equal to $HOME/.cache should be used.
if test "x$XDG_CACHE_HOME" = "x" ; then
  XDG_CACHE_HOME=$HOME/.cache
fi
[ -d "$XDG_CACHE_HOME" ] || mkdir "$XDG_CACHE_HOME"

# load local modmap
test -r $HOME/.Xmodmap && xmodmap $HOME/.Xmodmap

# Set the env variables of Input Method
export GTK_IM_MODULE=scim-bridge
export CLUTTER_IM_MODULE=scim-bridge

{
if [ -d "/etc/xdg/autostart" ]; then
  for i in /etc/xdg/autostart/*.desktop; do

      # this would take 8 grep exec()s to evaluate but
      # we can do all of it in one awk script. --Auke

      cmd_line=`awk -F "=" '
        {
          # find the part we need to execute
          if ($1 ~ /^Exec/) {
            cmd_line=$2
          };
          # figure out whether it needs to be started or not
          if ($1 == "Hidden" && $2 == "true") {
            hide=1
          };
          if ($1 == "OnlyShowIn") {
            if ($2 !~ /MOBLIN;/) {
              hide=1
            }
          };
          if ($1 == "NotShowIn") {
            if ($2 ~ /GNOME;|MOBLIN;/) {
              hide=1
            }
          }
        };
        END {
          if (hide != 1) {
            print cmd_line
          }
        }' $i`

      cmd=`echo "$cmd_line" | cut -d' ' -f1`

      if test "$cmd" && type "$cmd" >/dev/null 2>&1; then
        ionice -n7  $cmd_line &
      fi
  done
fi
} &

ionice -n7 /usr/libexec/mission-control &
#ionice -n7 nautilus --no-desktop --no-default-window &

# Make OO.o use gtk+ theming
export OOO_FORCE_DESKTOP=gnome

# Start panels in advance
/usr/libexec/moblin-panel-myzone &
/usr/libexec/moblin-panel-status &
/usr/libexec/moblin-panel-people &
/usr/libexec/moblin-panel-internet &
/usr/libexec/moblin-panel-media &
/usr/libexec/moblin-panel-pasteboard &
/usr/libexec/moblin-panel-applications &

mutter --sm-disable
