#! /bin/sh -e

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

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

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 Coffee FALSE Green FALSE Orange FALSE Pink FALSE Red; echo $ans`

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

# if [ "`readlink /etc/hildon/theme`" = /usr/share/themes/blackplastictheme-themedir ]; then
#   if [ -x /usr/bin/personalisation ]; then
#	   /usr/bin/personalisation /usr/share/themes/default
#   fi
# fi

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

	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 [ "`readlink /etc/hildon/theme`" = /usr/share/themes/blackplastictheme-themedir ]; then
#   if [ -x /usr/bin/personalisation ]; then
#	   /usr/bin/personalisation /usr/share/themes/default
#   fi
# fi

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

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/blue/* /usr/share/themes/blackplastictheme-themedir/
	hildon-theme-cacher $THEMEDIR
	RS='1'

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

# if [ "`readlink /etc/hildon/theme`" = /usr/share/themes/blackplastictheme-themedir ]; then
#   if [ -x /usr/bin/personalisation ]; then
#	   /usr/bin/personalisation /usr/share/themes/default
#   fi
# fi

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'

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

# if [ "`readlink /etc/hildon/theme`" = /usr/share/themes/blackplastictheme-themedir ]; then
#   if [ -x /usr/bin/personalisation ]; then
#	   /usr/bin/personalisation /usr/share/themes/default
#   fi
# fi

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

	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 [ "`readlink /etc/hildon/theme`" = /usr/share/themes/blackplastictheme-themedir ]; then
#   if [ -x /usr/bin/personalisation ]; then
#	   /usr/bin/personalisation /usr/share/themes/default
#   fi
# fi

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

	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 [ "`readlink /etc/hildon/theme`" = /usr/share/themes/blackplastictheme-themedir ]; then
#   if [ -x /usr/bin/personalisation ]; then
#	   /usr/bin/personalisation /usr/share/themes/default
#   fi
# fi

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

	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 [ "`readlink /etc/hildon/theme`" = /usr/share/themes/blackplastictheme-themedir ]; then
#   if [ -x /usr/bin/personalisation ]; then
#	   /usr/bin/personalisation /usr/share/themes/default
#   fi
# fi

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

	cp -rf /usr/share/themes/blackplastictheme-themedir/variations/red/* /usr/share/themes/blackplastictheme-themedir/
	hildon-theme-cacher $THEMEDIR
	RS='1'

else 

	exit 0

fi

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

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

Q66=`run-standalone.sh zenity --info --text="Applying new color scheme requires restarting your desktop, it will take few seconds and your screen will blink few times."`

# run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:'Applying new color scheme requires restarting your desktop, it will take few seconds and your screen will blink few times. You can now tap me.' uint32:0 string:'NAO OK!'

killall hildon-desktop
sleep 2
killall hildon-home
sleep 2
killall hildon-status-menu
sleep 2


Q3=`run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:'Done! New color scheme has been set. Rebooting the device is still recommended to refresh all UI elements.' uint32:0 string:'NAO OK!'`

# Q3=`run-standalone.sh zenity --info --text="Done! New color scheme has been set.\nNOTE: Rebooting device is still recommended to refresh all UI elements."`

exit 0

	fi

fi

run-standalone.sh dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:'Settings saved. You can now go and select Black Plastic Theme to use with the new color scheme. Rebooting the device is recommended to refresh all UI elements after selecting the theme.' uint32:0 string:'NAO OK!'

# Q3=`run-standalone.sh zenity --info --text="Done! New color scheme has been set.\nNOTE: Rebooting device is still recommended to refresh all UI elements."`

exit 0
