#! /bin/sh -e

THEMEDIR='/usr/share/themes/blackplastictheme-themedir'

if [ ! -d $THEMEDIR ]; then
  exit 0
fi


 # let's check if black plastic is current active theme and set variable RST=1 for later use
 if [ "`readlink /etc/hildon/theme`" = /usr/share/themes/blackplastictheme-themedir ]; then
   if [ -x /usr/bin/personalisation ]; then
	   RST="1"
   fi
 fi

Q=`run-standalone.sh zenity  --list  --text "Enable or disable custom transitions" --radiolist  --column "Pick" --column "Transition" TRUE "Enable custom transitions" FALSE "Disable custom transitions"; echo $ans`

if [ "$Q" = "Enable custom transitions" ]; then
      # install the custom things
     	cp -rf /usr/share/themes/blackplastictheme-themedir/transitions.tmp /usr/share/themes/blackplastictheme-themedir/transitions.ini

elif [ "$Q" = "Disable custom transitions" ]; then

	if [ -f /usr/share/themes/blackplastictheme-themedir/transitions.ini ]; then

		rm -rf /usr/share/themes/blackplastictheme-themedir/transitions.ini

	fi

else 

	exit 0

fi

Q2=`run-standalone.sh zenity  --list  --text "Choose color scheme" --radiolist  --column "Pick" --column "Scheme" TRUE Black FALSE Blue FALSE Green FALSE Orange FALSE Pink FALSE Red FALSE Yellow FALSE "Deep Blue" FALSE "Deep Green" FALSE "Deep Orange" FALSE "Deep Purple" FALSE "Deep Red" FALSE "Extra Coffee"; echo $ans`

if [ "$Q2" = "Black" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/black/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'

elif [ "$Q2" = "Blue" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/blue/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'

elif [ "$Q2" = "Green" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/green/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'

elif [ "$Q2" = "Orange" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/orange/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'

elif [ "$Q2" = "Pink" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/pink/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'

elif [ "$Q2" = "Red" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/red/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'
	
elif [ "$Q2" = "Yellow" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/yellow/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'	
	
elif [ "$Q2" = "Deep Blue" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/deepblue/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'	

elif [ "$Q2" = "Deep Green" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/deepgreen/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'		
	
elif [ "$Q2" = "Deep Purple" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/deeppurple/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'
	
elif [ "$Q2" = "Deep Red" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/deepred/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'
	
elif [ "$Q2" = "Deep Orange" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/defaults/* /usr/share/themes/blackplastictheme-themedir/

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/deeporange/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'				
	
elif [ "$Q2" = "Extra Coffee" ]; then

	if [ "$RST" = "1" ]; then
		# resetting theme to default (nseries one)
		/usr/bin/personalisation /usr/share/themes/default
	fi

	run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Setting up theme folder, this can take few seconds. Please be patient and do not hassle until next dialog appears :)"

	rm -rf /usr/share/themes/blackplastictheme-themedir/gtk-2.0/*.cache

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/coffee/* /usr/share/themes/blackplastictheme-themedir/

	hildon-theme-cacher $THEMEDIR
	RS='1'		

else 

	exit 0

fi

if [ "$RST" != "1" ]; then

	Q5=`run-standalone.sh zenity  --list  --text "Do you want to make Black Plastic as your active theme?" --radiolist  --column "Pick" --column "Aswer" TRUE "Yes" FALSE "No"; echo $ans`

	if [ "$Q5" = "Yes" ]; then
	RST='1'
	fi

fi

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

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

	# setting Black Plastic as theme to use
	/usr/bin/personalisation /usr/share/themes/blackplastictheme-themedir
	
	
	# let's copy the background stuff into it's place
	cp -rf /usr/share/themes/blackplastictheme-themedir/backgrounds/wallpaper1.png /home/user/.backgrounds/background-1.png
	cp -rf /usr/share/themes/blackplastictheme-themedir/backgrounds/wallpaper2.png /home/user/.backgrounds/background-2.png
	cp -rf /usr/share/themes/blackplastictheme-themedir/backgrounds/wallpaper3.png /home/user/.backgrounds/background-3.png
	cp -rf /usr/share/themes/blackplastictheme-themedir/backgrounds/wallpaper4.png /home/user/.backgrounds/background-4.png	
	chown user /home/user/.backgrounds/background-1.png
	chown user /home/user/.backgrounds/background-2.png
	chown user /home/user/.backgrounds/background-3.png
	chown user /home/user/.backgrounds/background-4.png


		if [ "$1" = "installation" ]; then
		
			Q3=`run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:'Theme setup done! Remember to restart the phone to apply changes!' uint32:0 string:'NAO OK!'`
			exit 0
		
		else

			Q4=`run-standalone.sh zenity  --list  --text "Restart and apply theme changes now?" --radiolist  --column "Pick" --column "Aswer" FALSE "Yes" TRUE "No - I will restart later"; echo $ans`

		fi
		
		if [ "$Q4" = "Yes" ]; then

		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

#		elif [ "$Q4" = "No - I will restart later" ]; then

		else

		Q3=`run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:'Theme setup done! Remember to restart the phone to apply changes!' uint32:0 string:'NAO OK!'`

		exit 0

		fi

	fi

fi

run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:'Black Plastic settings saved. You can now go and set Black Plastic as your active theme. After switching the theme you must reboot the phone to make all changes visible!' uint32:0 string:'NAO OK!'

exit 0
