#! /bin/sh -e

 OPAASI=`awk -vjaa=$21 'BEGIN{print 100/jaa}'`

if [ "$1" = "importfontspushed" ]; then

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Importing fonts..."

	sleep 5

	if [ -f /home/user/MyDocs/*.ttf ]; then
	cp -rf /home/user/MyDocs/*.ttf /home/user/.fonts/
	FOUND="1"
	fi
	if [ -f /home/user/MyDocs/*.otf ]; then
	cp -rf /home/user/MyDocs/*.otf /home/user/.fonts/
	FOUND="1"
	fi
	if [ $FOUND == 1 ];then
	run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Import complete! Restart Theme Customizer to use new fonts." uint32:0 string:'NAO OK!'
	else
	run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"No font files found under MyDocs" uint32:0 string:'NAO OK!'
	fi
	exit 0

fi

THEMEDIR='/etc/hildon/theme'

	FONT="$2"

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up font: $FONT"
	sleep 2

	cp -rf /opt/theme-customizer/css-template /opt/theme-customizer/css-template-modded
	cp -rf /opt/theme-customizer/gtk-template /opt/theme-customizer/gtk-template-modded
#	cp -rf /opt/theme-customizer/colors-template /opt/theme-customizer/colors-template-modded

	ACTUALTHEMEDIR="`readlink -f /etc/hildon/theme`"
	GTKR="`readlink -f /etc/hildon/theme/gtk-2.0/gtkrc`"
	CSS="`readlink -f /etc/hildon/theme/css/colors.css`"
	MATCHBOX="`readlink -f /etc/hildon/theme/matchbox/theme.xml`"
	MATCHBOX2="`readlink -f /etc/hildon/theme/matchbox2/theme.xml`"
	COLORS="`readlink -f /etc/hildon/theme/colors.config`"

	ApplicationShortcutApplet="`readlink -f /etc/hildon/theme/images/ApplicationShortcutApplet.png`"
	CalendarAppletBackground="`readlink -f /etc/hildon/theme/images/CalendarAppletBackground.png`"
	ContactsAppletFrame="`readlink -f /etc/hildon/theme/images/ContactsAppletFrame.png`"
	MapAppletButton="`readlink -f /etc/hildon/theme/images/MapAppletButton.png`"
	MapAppletHead="`readlink -f /etc/hildon/theme/images/MapAppletHead.png`"
	MediaPlayerAppletHead="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletHead.png`"
	MediaPlayerAppletNext="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletNext.png`"
	MediaPlayerAppletPrevious="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletPrevious.png`"
	MediaPlayerAppletStopPlay="`readlink -f /etc/hildon/theme/images/MediaPlayerAppletStopPlay.png`"
	OviCenter="`readlink -f /etc/hildon/theme/images/OviCenter.png`"
	OviLeft="`readlink -f /etc/hildon/theme/images/OviLeft.png`"
	OviRight="`readlink -f /etc/hildon/theme/images/OviRight.png`"
	RSSAppletHead="`readlink -f /etc/hildon/theme/images/RSSAppletHead.png`"
	WebShortcutAppletBackground="`readlink -f /etc/hildon/theme/images/WebShortcutAppletBackground.png`"

	if [ ! -f /opt/theme-customizer/backups$GTKR ]; then
	mkdir -p /opt/theme-customizer/backups$GTKR
	rm -rf /opt/theme-customizer/backups$GTKR
	fi

	if [ ! -f /opt/theme-customizer/backups$ApplicationShortcutApplet ]; then
	mkdir -p /opt/theme-customizer/backups$ApplicationShortcutApplet
	rm -rf /opt/theme-customizer/backups$ApplicationShortcutApplet
	cp -rf $ApplicationShortcutApplet /opt/theme-customizer/backups$ApplicationShortcutApplet
	fi

	if [ ! -f /opt/theme-customizer/backups$CalendarAppletBackground ]; then
	mkdir -p /opt/theme-customizer/backups$CalendarAppletBackground
	rm -rf /opt/theme-customizer/backups$CalendarAppletBackground
	cp -rf $CalendarAppletBackground /opt/theme-customizer/backups$CalendarAppletBackground
	fi

	if [ ! -f /opt/theme-customizer/backups$ContactsAppletFrame ]; then
	mkdir -p /opt/theme-customizer/backups$ContactsAppletFrame
	rm -rf /opt/theme-customizer/backups$ContactsAppletFrame
	cp -rf $ContactsAppletFrame /opt/theme-customizer/backups$ContactsAppletFrame
	fi

	if [ ! -f /opt/theme-customizer/backups$MapAppletButton ]; then
	mkdir -p /opt/theme-customizer/backups$MapAppletButton
	rm -rf /opt/theme-customizer/backups$MapAppletButton
	cp -rf $MapAppletButton /opt/theme-customizer/backups$MapAppletButton
	fi

	if [ ! -f /opt/theme-customizer/backups$MapAppletHead ]; then
	mkdir -p /opt/theme-customizer/backups$MapAppletHead
	rm -rf /opt/theme-customizer/backups$MapAppletHead
	cp -rf $MapAppletHead /opt/theme-customizer/backups$MapAppletHead
	fi

	if [ ! -f /opt/theme-customizer/backups$MediaPlayerAppletHead ]; then
	mkdir -p /opt/theme-customizer/backups$MediaPlayerAppletHead
	rm -rf /opt/theme-customizer/backups$MediaPlayerAppletHead
	cp -rf $MediaPlayerAppletHead /opt/theme-customizer/backups$MediaPlayerAppletHead
	fi

	if [ ! -f /opt/theme-customizer/backups$MediaPlayerAppletNext ]; then
	mkdir -p /opt/theme-customizer/backups$MediaPlayerAppletNext
	rm -rf /opt/theme-customizer/backups$MediaPlayerAppletNext
	cp -rf $MediaPlayerAppletNext /opt/theme-customizer/backups$MediaPlayerAppletNext
	fi

	if [ ! -f /opt/theme-customizer/backups$MediaPlayerAppletPrevious ]; then
	mkdir -p /opt/theme-customizer/backups$MediaPlayerAppletPrevious
	rm -rf /opt/theme-customizer/backups$MediaPlayerAppletPrevious
	cp -rf $MediaPlayerAppletPrevious /opt/theme-customizer/backups$MediaPlayerAppletPrevious
	fi

	if [ ! -f /opt/theme-customizer/backups$MediaPlayerAppletStopPlay ]; then
	mkdir -p /opt/theme-customizer/backups$MediaPlayerAppletStopPlay
	rm -rf /opt/theme-customizer/backups$MediaPlayerAppletStopPlay
	cp -rf $MediaPlayerAppletStopPlay /opt/theme-customizer/backups$MediaPlayerAppletStopPlay
	fi

	if [ ! -f /opt/theme-customizer/backups$OviCenter ]; then
	mkdir -p /opt/theme-customizer/backups$OviCenter
	rm -rf /opt/theme-customizer/backups$OviCenter
	cp -rf $OviCenter /opt/theme-customizer/backups$OviCenter
	fi

	if [ ! -f /opt/theme-customizer/backups$OviLeft ]; then
	mkdir -p /opt/theme-customizer/backups$OviLeft
	rm -rf /opt/theme-customizer/backups$OviLeft
	cp -rf $OviLeft /opt/theme-customizer/backups$OviLeft
	fi

	if [ ! -f /opt/theme-customizer/backups$OviRight ]; then
	mkdir -p /opt/theme-customizer/backups$OviRight
	rm -rf /opt/theme-customizer/backups$OviRight
	cp -rf $OviRight /opt/theme-customizer/backups$OviRight
	fi

	if [ ! -f /opt/theme-customizer/backups$RSSAppletHead ]; then
	mkdir -p /opt/theme-customizer/backups$RSSAppletHead
	rm -rf /opt/theme-customizer/backups$RSSAppletHead
	cp -rf $RSSAppletHead /opt/theme-customizer/backups$RSSAppletHead
	fi

	if [ ! -f /opt/theme-customizer/backups$WebShortcutAppletBackground ]; then
	mkdir -p /opt/theme-customizer/backups$WebShortcutAppletBackground
	rm -rf /opt/theme-customizer/backups$WebShortcutAppletBackground
	cp -rf $WebShortcutAppletBackground /opt/theme-customizer/backups$WebShortcutAppletBackground
	fi

	if [ ! -f /opt/theme-customizer/backups$CSS ]; then
	mkdir -p /opt/theme-customizer/backups$CSS
	rm -rf /opt/theme-customizer/backups$CSS
	fi

	if [ ! -f /opt/theme-customizer/backups$MATCHBOX ]; then
	mkdir -p /opt/theme-customizer/backups$MATCHBOX
	rm -rf /opt/theme-customizer/backups$MATCHBOX
	fi

	if [ ! -f /opt/theme-customizer/backups$MATCHBOX2 ]; then
	mkdir -p /opt/theme-customizer/backups$MATCHBOX2
	rm -rf /opt/theme-customizer/backups$MATCHBOX2
	fi

	if [ ! -f /opt/theme-customizer/backups$COLORS ]; then
	mkdir -p /opt/theme-customizer/backups$COLORS
	rm -rf /opt/theme-customizer/backups$COLORS
	fi

	if [ ! $21 = 100 ]; then

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting widget opacities to: $21 %"

	convert /opt/theme-customizer/backups$WebShortcutAppletBackground -channel Alpha -evaluate Divide $OPAASI $WebShortcutAppletBackground
	
	convert /opt/theme-customizer/backups$RSSAppletHead -channel Alpha -evaluate Divide $OPAASI $RSSAppletHead
	
	convert /opt/theme-customizer/backups$OviRight -channel Alpha -evaluate Divide $OPAASI $OviRight
	
	convert /opt/theme-customizer/backups$OviLeft -channel Alpha -evaluate Divide $OPAASI $OviLeft
	
	convert /opt/theme-customizer/backups$OviCenter -channel Alpha -evaluate Divide $OPAASI $OviCenter
	
	convert /opt/theme-customizer/backups$MediaPlayerAppletStopPlay -channel Alpha -evaluate Divide $OPAASI $MediaPlayerAppletStopPlay
	
	convert /opt/theme-customizer/backups$MediaPlayerAppletPrevious -channel Alpha -evaluate Divide $OPAASI $MediaPlayerAppletPrevious
	
	convert /opt/theme-customizer/backups$MediaPlayerAppletNext -channel Alpha -evaluate Divide $OPAASI $MediaPlayerAppletNext
	
	convert /opt/theme-customizer/backups$MediaPlayerAppletHead -channel Alpha -evaluate Divide $OPAASI $MediaPlayerAppletHead
	
	convert /opt/theme-customizer/backups$MapAppletHead -channel Alpha -evaluate Divide $OPAASI $MapAppletHead
	
	convert /opt/theme-customizer/backups$MapAppletButton -channel Alpha -evaluate Divide $OPAASI $MapAppletButton
	
	convert /opt/theme-customizer/backups$ContactsAppletFrame -channel Alpha -evaluate Divide $OPAASI $ContactsAppletFrame
	
	convert /opt/theme-customizer/backups$CalendarAppletBackground -channel Alpha -evaluate Divide $OPAASI $CalendarAppletBackground
	
	convert /opt/theme-customizer/backups$ApplicationShortcutApplet -channel Alpha -evaluate Divide $OPAASI $ApplicationShortcutApplet

	else

	cp -rf /opt/theme-customizer/backups$WebShortcutAppletBackground $WebShortcutAppletBackground

	cp -rf /opt/theme-customizer/backups$RSSAppletHead $RSSAppletHead

	cp -rf /opt/theme-customizer/backups$OviRight $OviRight

	cp -rf /opt/theme-customizer/backups$OviLeft $OviLeft

	cp -rf /opt/theme-customizer/backups$OviCenter $OviCenter

	cp -rf /opt/theme-customizer/backups$MediaPlayerAppletStopPlay $MediaPlayerAppletStopPlay

	cp -rf /opt/theme-customizer/backups$MediaPlayerAppletPrevious $MediaPlayerAppletPrevious

	cp -rf /opt/theme-customizer/backups$MediaPlayerAppletNext $MediaPlayerAppletNext

	cp -rf /opt/theme-customizer/backups$MediaPlayerAppletHead $MediaPlayerAppletHead

	cp -rf /opt/theme-customizer/backups$MapAppletHead $MapAppletHead
	
	cp -rf /opt/theme-customizer/backups$MapAppletButton $MapAppletButton

	cp -rf /opt/theme-customizer/backups$ContactsAppletFrame $ContactsAppletFrame

	cp -rf /opt/theme-customizer/backups$CalendarAppletBackground $CalendarAppletBackground

	cp -rf /opt/theme-customizer/backups$ApplicationShortcutApplet $ApplicationShortcutApplet

	fi

	if [ -f $THEMEDIR/transitions.ini ]; then

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up snap-to-grid to: $6"
	sleep 2

	perl -pi -e "s/snap_grid_size.*/snap_grid_size=$6/g" $THEMEDIR/transitions.ini
	elif [ -f /usr/share/hildon-desktop/transitions.ini ]; then

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up snap-to-grid to: $6"
	sleep 2

	perl -pi -e "s/snap_grid_size.*/snap_grid_size=$6/g" /usr/share/hildon-desktop/transitions.ini
	fi 

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Creating backups..."
	sleep 2
	if [ ! -f /opt/theme-customizer/backups$CSS ]; then
	cp -rf $CSS /opt/theme-customizer/backups$CSS
	fi

	if [ ! -f /opt/theme-customizer/backups$COLORS ]; then
	cp -rf $COLORS /opt/theme-customizer/backups$COLORS
	fi
	
	if [ ! -f /opt/theme-customizer/backups$GTKR ]; then
	cp -rf $GTKR /opt/theme-customizer/backups$GTKR
	fi
	
	if [ -f /opt/theme-customizer/backupsMATCHBOX ]; then
	cp -rf /opt/theme-customizer/matchbox/theme.xml $MATCHBOX
	else
	cp -rf $MATCHBOX /opt/theme-customizer/backups$MATCHBOX
	cp -rf /opt/theme-customizer/matchbox/theme.xml $MATCHBOX
	fi
	
	if [ -f /opt/theme-customizer/backupsMATCHBOX2 ]; then
	cp -rf /opt/theme-customizer/matchbox2/theme.xml $MATCHBOX2
	else
	cp -rf $MATCHBOX2 /opt/theme-customizer/backups$MATCHBOX2
	cp -rf /opt/theme-customizer/matchbox2/theme.xml $MATCHBOX2
	fi

	perl -pi -e 's/.*font_name =.*//g' $GTKR
	perl -pi -e 's/.*font: .*//g' $CSS

	perl -pi -e "s/Droid Sans/$FONT/g" /opt/theme-customizer/gtk-template-modded $MATCHBOX $MATCHBOX2 /opt/theme-customizer/css-template-modded

	
# setting the colors...

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up colors..."
	sleep 2

	COLOR1NEW="$12"
	COLOR2NEW="$13"
	COLOR3NEW="$14"
	COLOR4NEW="$15"
	COLOR5NEW="$17"
	COLOR6NEW="$18"
	COLOR7NEW="$19"
	COLOR8NEW="$20"

	perl -pi -e "s/.*color\[\"DefaultTextColor\"\].*/color\[\"DefaultTextColor\"\] = \"$COLOR1NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"SecondaryTextColor\"\].*/color\[\"SecondaryTextColor\"\] = \"$COLOR2NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ActiveTextColor\"\].*/color\[\"ActiveTextColor\"\] = \"$COLOR3NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"DisabledTextColor\"\].*/color\[\"DisabledTextColor\"\] = \"$COLOR4NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"PaintedTextColor\"\].*/color\[\"PaintedTextColor\"\] = \"$COLOR5NEW\"/g" $GTKR

	perl -pi -e "s/.*color\[\"SelectionColor\"\].*/color\[\"SelectionColor\"\] = \"$COLOR6NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ReversedSelectionColor\"\].*/color\[\"ReversedSelectionColor\"\] = \"$COLOR6NEW\"/g" $GTKR

	perl -pi -e "s/.*color\[\"TitleTextColor\"\].*/color\[\"TitleTextColor\"\]        = \"$COLOR1NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ButtonTextColor\"\].*/color\[\"ButtonTextColor\"\]        = \"$COLOR7NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ButtonTextPressedColor\"\].*/color\[\"ButtonTextPressedColor\"\]        = \"$COLOR8NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"ButtonTextDisabledColor\"\].*/color\[\"ButtonTextDisabledColor\"\]        = \"$COLOR4NEW\"/g" $GTKR

	perl -pi -e "s/.*color\[\"AccentColor1\"\].*/color\[\"AccentColor1\"\] = \"$COLOR3NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"AccentColor2\"\].*/color\[\"AccentColor2\"\] = \"$COLOR1NEW\"/g" $GTKR
	perl -pi -e "s/.*color\[\"AccentColor3\"\].*/color\[\"AccentColor3\"\] = \"$COLOR3NEW\"/g" $GTKR

	perl -pi -e "s/DefaultTextColor.*/DefaultTextColor=$COLOR1NEW/g" $COLORS
	perl -pi -e "s/SecondaryTextColor.*/SecondaryTextColor=$COLOR2NEW/g" $COLORS
	perl -pi -e "s/ActiveTextColor.*/ActiveTextColor=$COLOR3NEW/g" $COLORS
	perl -pi -e "s/DisabledTextColor.*/DisabledTextColor=$COLOR4NEW/g" $COLORS
	perl -pi -e "s/PaintedTextColor.*/PaintedTextColor=$COLOR5NEW/g" $COLORS

	perl -pi -e "s/SelectionColor.*/SelectionColor=$COLOR6NEW/g" $COLORS
	perl -pi -e "s/SelectionColor.*/SelectionColor=$COLOR6NEW/g" $COLORS

	perl -pi -e "s/TitleTextColor.*/TitleTextColor=$COLOR1NEW/g" $COLORS
	perl -pi -e "s/ButtonTextColor.*/ButtonTextColor=$COLOR7NEW/g" $COLORS
	perl -pi -e "s/ButtonTextPressedColor.*/ButtonTextPressedColor=$COLOR8NEW/g" $COLORS
	perl -pi -e "s/ButtonTextDisabledColor.*/ButtonTextDisabledColor=$COLOR4NEW/g" $COLORS

	perl -pi -e "s/AccentColor1.*/AccentColor1=$COLOR3NEW/g" $COLORS
	perl -pi -e "s/AccentColor2.*/AccentColor2=$COLOR1NEW/g" $COLORS
	perl -pi -e "s/AccentColor3.*/AccentColor3=$COLOR3NEW/g" $COLORS

	perl -pi -e "s/#COLOR1/$COLOR1NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR2/$COLOR2NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR3/$COLOR3NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR4/$COLOR4NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR5/$COLOR5NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR6/$COLOR6NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR7/$COLOR7NEW/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/#COLOR8/$COLOR8NEW/g" /opt/theme-customizer/css-template-modded

	sleep 2

	if [ "$1" = "-1" ] || [ "$1" = "-3" ] || [ "$1" = "-5" ] || [ "$1" = "+1" ] || [ "$1" = "+3" ] || [ "$1" = "+5" ]; then
	MUUTTUJA="$1"

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up font sizes to $MUUTTUJA"
	sleep 2

	let KORVAA1=13$MUUTTUJA
	perl -pi -e "s/13"/${KORVAA1}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA2=15$MUUTTUJA
	perl -pi -e "s/15"/${KORVAA2}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA3=18$MUUTTUJA
	perl -pi -e "s/18"/${KORVAA3}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA4=20$MUUTTUJA
	perl -pi -e "s/20"/${KORVAA4}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA5=24$MUUTTUJA
	perl -pi -e "s/24"/${KORVAA5}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA6=26$MUUTTUJA
	perl -pi -e "s/26"/${KORVAA6}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA7=36$MUUTTUJA
	perl -pi -e "s/36"/${KORVAA7}"/g" /opt/theme-customizer/gtk-template-modded
	let KORVAA8=52$MUUTTUJA
	perl -pi -e "s/52"/${KORVAA8}"/g" /opt/theme-customizer/gtk-template-modded


	perl -pi -e "s/13px/${KORVAA1}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/15px/${KORVAA2}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/18px/${KORVAA3}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/20px/${KORVAA4}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/24px/${KORVAA5}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/26px/${KORVAA6}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/36px/${KORVAA7}px/g" /opt/theme-customizer/css-template-modded
	perl -pi -e "s/52px/${KORVAA8}px/g" /opt/theme-customizer/css-template-modded


	fi

# let's set icon theme

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up Icon theme to: $3"
	perl -pi -e "s/.*gtk-icon-theme-name.*/gtk-icon-theme-name = \"$3\"/g" $GTKR
	sleep 2

	sed -i "/MODDING STARTS/,/MODDING ENDS/d" $CSS
	sed -i "/MODDING STARTS/,/MODDING ENDS/d" $GTKR
#	sed -i "/MODDING STARTS/,/MODDING ENDS/d" $COLORS

	cat /opt/theme-customizer/css-template-modded >> $CSS
	cat /opt/theme-customizer/gtk-template-modded >> $GTKR
#	cat /opt/theme-customizer/colors-template-modded >> $COLORS

	rm /opt/theme-customizer/css-template-modded
	rm /opt/theme-customizer/gtk-template-modded
#	rm /opt/theme-customizer/colors-template-modded


	hildon-theme-cacher $ACTUALTHEMEDIR

# finally let's set shortcut size and bookmark size and choose to show or not to show icon backgrounds on desktop

	run-standalone.sh gconftool -s /apps/osso/hildon-home/task-shortcuts-size -t int $5
	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up app shortcut size to: $5"
	sleep 2

	run-standalone.sh gconftool -s /apps/osso/hildon-home/task-bookmarks-size -t int $16
	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up web bookmarks size to: $16"
	sleep 2

	if [ "$4" = "Don't show icon backgrounds" ]; then

	run-standalone.sh gconftool -s /apps/osso/hildon-home/task-shortcuts-back -t int 0
	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Hiding app shortcut backgrounds..."
	sleep 2

	else

	run-standalone.sh gconftool -s /apps/osso/hildon-home/task-shortcuts-back -t int 1
	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Showing app shortcut backgrounds..."
	sleep 2

	fi

# let's set widget opacities

		if [ "$7" = "Reboot" ]; then
		
		sleep 2

		reboot

		run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Rebooting in 5 seconds, fasten your seatbelts!"

		exit 0

		else
		
SERVICE='osso-abook-home-applet'
 
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
	killall osso-abook-home-applet
	sleep 2
	run-standalone.sh /usr/sbin/dsmetool -t /usr/bin/osso-abook-home-applet
	sleep 2
fi


		killall systemui
		
		run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Restarting services, your screen will blink! After all is done restarting device is recommended to reload all new values." uint32:0 string:'NAO OK!'
		
		sleep 5

		exit 0

		fi



exit 0
