#!/bin/sh

# -- Current Status --
# Detects userland and selects x/dialog/opie-sh accordingly
# Detects Jornada and selects brightness values accordingly
# Performs startup actions
# Performs after-GUI-start items
# -- Including loopback warning message
# Brightness Applet

task=$1

# ------------- Detect Jornada and installation details----------------------------
# Detect model
if grep -q "Jornada 720" "/proc/cpuinfo"
then
	# Using a 7xx
	brightfile=/sys/class/backlight/s1d13806fb/brightness
elif grep -q "Jornada 680" "/proc/cpuinfo"
then
	# Using a 6xx
	brightfile=/sys/class/backlight/hp680-bl/brightness
fi

# Detect userland
if [ -d "/opt/QtPalmtop" ]
then
	# It seems we are using Opie
	mode=opie
elif [ -d "/usr/share/icewm" ]
then
	# Or icewm
	mode=icewm
fi

if [ -d "/usr/bin/Xdialog" ]
then
	# If using icewm we can use xdialog
	dialog=Xdialog
else
	# If no gui then dialog should be present
	dialog=dialog
fi
dialog=dialog
# -----------------------------------------------------------------------------

# ----------- To be shown on the first GUI launch -----------------------------
if [ $task = "gui_run_me" ]
then
	# Check for partionless mode
	if [ -d "/initrd/mnt" ]
	then
		if [ $mode = "opie" ]
		then
			opie-sh -m -g -I -t "Partitionless Mode" -M "Please note that you are using the partitionless version of JLime.<br><br>This version will run slower than a partitioned installation."
		else
			$dialog --title "Partitionless Mode" \
			--ok-label "OK" \
			--msgbox \
			"Please note that you are using the partitionless version of JLime.\n\nThis version will run slower than a partioned installation." 10 69
		fi
	fi
fi
# -----------------------------------------------------------------------------

# ---------------Brightness applet for console, IceWM and Opie ----------------
if [ $task = "brightness" ]
then	
	level=0
	if [ $mode = "opie" ]
	then
		rm /home/$USER/.brightnesstmp
		echo "Dim" >> /home/$USER/.brightnesstmp
		echo "Low" >> /home/$USER/.brightnesstmp
		echo "Medium" >> /home/$USER/.brightnesstmp
		echo "High" >> /home/$USER/.brightnesstmp
		echo "Highest" >> /home/$USER/.brightnesstmp
	
		level=`opie-sh -i -g -l -L "Please select brightness level:" -F /home/$USER/.brightnesstmp`
	else
		level=`$dialog --title "Brightness" \
		--no-cancel \
		--stdout \
		--ok-label "OK" \
		--menu \
		"Please select brightness level" 13 69 2 \
		"Dim" "Dim" \
		"Low" "Low" \
		"Medium" "Medium" \
		"High" "High" \
		"Highest" "Highest"`
	fi

	if [ $level = "Dim" ]
	then
		echo 50 > $brightfile
	elif [ $level = "Low" ]
	then
		echo 100 > $brightfile
	elif [ $level = "Medium" ]
	then
		echo 150 > $brightfile
	elif [ $level = "High" ]
	then
		echo 200 > $brightfile
	elif [ $level = "Highest" ]
	then
		echo 255 > $brightfile
	fi
fi
# -----------------------------------------------------------------------------

