if [ ! -e "/var/mobile/Media/RingRing-Settings" ];
then
mkdir "/var/mobile/Media/RingRing-Settings"
chown mobile:mobile "/var/mobile/Media/RingRing-Settings"
fi

echo "
88888		      
8   8  e  eeeee eeeee  
8eee8e 8  8   8 8   8  
88   8 8e 8e  8 8e     
88   8 88 88  8 88 88  
88   8 88 88  8 88ee8  
		
		88888		      88  
		8   8  e  eeeee eeeee 88 
		8eee8e 8  8   8 8   8 88 
		88   8 8e 8e  8 8e    88 
		88   8 88 88  8 88 88	 
		88   8 88 88  8 88ee8 88"
sleep 1
echo "

###	   #   #  #
#	   #   # 
###  #### ### ### # ### ### ####
  #  # #   #   #  # # # # #   #
###  ####  ##  ## # # # ### ####
			  #
			###
"
sleep 2


while true
do
read -p "
FIX - Type \"FIX\" (all capital letters) to fix RingRing if errors occurr
0 - Exit Settings		  
1 - Toggle asking for ringtone-quality and set a default
2 - Toggle the MxTube safety feature
3 - Toggle asking for mail
4 - Toggle asking for other software
5 - Toggle asking to cut
6 - More programs by me in Cydia
7 - Donate (so I have music and food for more coding)
8 - Exit and run RingRing
m - ---More options---

Choice: " choice

if [ "$choice" = "m" ];
then
clear
read -p "
9  - Reset all settings to default
10 - Toggle sound at the end of conversion/DB-creation
11 - Toggle deleting sourcefiles
12 - Always answer \"Create ringtones now?\" with \"Yes\"
13 - Reset \"Don't Ask Me Again\"-list
15 - Toggle taking the title from filename
16 - Set a default length
b  - ---Back to first option menu---

Choice: " choice
fi


if [ "$choice" = "FIX" ];
then
choice=9
fi

if [ "$choice" = "2" ];
then
	if [ -e /var/mobile/Media/RingRing-Settings/mxtubesafety ];
	then
	read -p "The MxTube safety feature makes sure your MxTube imported files go back to it's original folder, even if your conversion ended early because of a terminal crash or you pressing \"ctrl+c\". It's currently is currently turned off. Turn it on? (y/n) " mxtubesafety
		if [ "$mxtubesafety" = "y" ];
		then
		rm -f /var/mobile/Media/RingRing-Settings/mxtubesafety
		clear
		echo "
Turned on."
		fi
	else
	read -p "The MxTube safety feature makes sure your MxTube imported files go back to it's original folder, even if your conversion ended early because of a terminal crash or you pressing \"ctrl+c\". It's currently is currently turned on. Turn it off? (y/n) " mxtubesafety
		if [ "$mxtubesafety" = "y" ];
		then
		touch /var/mobile/Media/RingRing-Settings/mxtubesafety
		chown mobile:mobile /var/mobile/Media/RingRing-Settings/mxtubesafety
		clear
		echo "
Turned off."
		fi
	fi
fi



if [ "$choice" = "10" ];
then
	if [ -e /var/mobile/Media/RingRing-Settings/sound ];
	then
	read -p "The conversion-complete-sound is currently turned off. Turn it on? (y/n) " sound
		if [ "$sound" = "y" ];
		then
		rm -f /var/mobile/Media/RingRing-Settings/sound
		clear
		echo "
Turned on."
		fi
	else
	read -p "The conversion-complete-sound is currently turned on. Turn it off? (y/n) " sound
		if [ "$sound" = "y" ];
		then
		touch /var/mobile/Media/RingRing-Settings/sound
		chown mobile:mobile /var/mobile/Media/RingRing-Settings/sound
		clear
		echo "
Turned off."
		fi
	fi
fi

if [ "$choice" = "16" ];
then
	if [ -e /var/mobile/Media/RingRing-Settings/defaultlength ];
	then
	read -p "A default length is set at the moment. Remove it? (y/n) " defaultlength
		if [ "$defaultlength" = "y" ];
		then
		rm -f /var/mobile/Media/RingRing-Settings/defaultlength
		clear
		echo "
Removed."
		fi
	else
	read -p "There is currently no default length set. Set now? (y/n) " defaultlength
		if [ "$defaultlength" = "y" ];
		then
		while true
		do
			read -p "(f)ull/(6)0 seconds/(c)ustom/(e)xit, forget it: " defaultlengtht
			if [ "$defaultlengtht" = "e" ];
			then
			break
			fi
			if [ "$defaultlengtht" = "f" ] || [ "$defaultlengtht" = "6" ] || [ "$defaultlengtht" = "c" ];
			then
			echo "$defaultlengtht" > /var/mobile/Media/RingRing-Settings/defaultlength
			chown mobile:mobile /var/mobile/Media/RingRing-Settings/defaultlength
break
			else
			echo "Please use one of these four options as shown above: f 6 c e
"
			fi
		done
		clear
		echo "
Turned off."
		fi
	fi
fi

if [ "$choice" = "15" ];
then
	if [ -e /var/mobile/Media/RingRing-Settings/titlefromnameoff ];
	then
	read -p "Querying for taking ringtone titles from filenames is currently turned off. Turn it on? (y/n) " titlefromnameoff
		if [ "$titlefromnameoff" = "y" ];
		then
		rm -f /var/mobile/Media/RingRing-Settings/titlefromnameoff
		clear
		echo "
Turned on."
		fi
	else
	read -p "Querying for taking ringtone titles from filenames is currently turned on. Turn it off? (y/n) " titlefromnameoff
		if [ "$titlefromnameoff" = "y" ];
		then
		touch /var/mobile/Media/RingRing-Settings/titlefromnameoff
		chown mobile:mobile /var/mobile/Media/RingRing-Settings/titlefromnameoff
		clear
		echo "
Turned off."
		fi
	fi
fi

if [ "$choice" = "12" ];
then
	if [ -e /var/mobile/Media/RingRing-Settings/alwaysmakering ];
	then
	read -p "Asking for actual conversion is currently turned off. Turn it on? (y/n) " alwaysmakering
		if [ "$alwaysmakering" = "y" ];
		then
		rm -f /var/mobile/Media/RingRing-Settings/alwaysmakering
		clear
		echo "
Turned on."
		fi
	else
	read -p "Asking for actual conversion is currently turned on. Turn it off? (y/n) " alwaysmakering
		if [ "$alwaysmakering" = "y" ];
		then
		touch /var/mobile/Media/RingRing-Settings/alwaysmakering
		chown mobile:mobile /var/mobile/Media/RingRing-Settings/alwaysmakering
		clear
		echo "
Turned off."
		fi
	fi
fi

if [ "$choice" = "13" ];
then
	if [ -e /var/mobile/Media/RingRing-Settings/tmp/DontAskMeRingRing ];
	then
	read -p "ARE YOU SURE YOU WANT TO DO THIS? THIS WILL REMOVE THE LIST !!IRRECOVERABLY!! (y/n) " remdontask
		if [ "$remdontask" = "y" ];
		then
		rm -f /var/mobile/Media/RingRing-Settings/tmp/DontAskMeRingRing
		clear
		echo "\"Don't Ask Me Again\"-list removed."
		else
		echo "\"Don't Ask Me Again\"-list not removed."
		fi
	else
	clear
	echo "There is not such list for you, yet."
	sleep 1
	fi
fi	

if [ "$choice" = "11" ];
then
	if [ -e /var/mobile/Media/RingRing-Settings/deleteall ];
	then
	read -p "Sourcefile-deletion upon converting is currently turned off. 
(This won't harm your iPod Library or MxTube Library) Turn it on? (y/n) " delall
		if [ $delall = y ];
		then
		rm -f /var/mobile/Media/RingRing-Settings/deleteall
		clear
		echo "
Turned on."
		fi
	else
	read -p "Sourcefile-deletion upon converting is currently turned on. Turn it off? (y/n) " delall
		if [ $delall = y ];
		then
		touch /var/mobile/Media/RingRing-Settings/deleteall
		clear
		echo "
Turned off."
		fi
	fi
fi

if [ "$choice" = "1" ];
then
	if [ -e /var/mobile/Media/RingRing-Settings/quality ];
	then
	read -p "Asking for ringtone-quality is currently turned off, turn it on? (y/n) " qual
		if [ $qual = y ];
		then
		rm -f /var/mobile/Media/RingRing-Settings/quality
		clear
		echo "
Turned on."
		fi
	else
	read -p "Asking for ringtone-quality is currently turned on, turn it off? (y/n) " qual
		if [ $qual = y ];
		then
		read -p "Which should be standard quality, normal or high? (n/h) " standqual
			if [ $standqual != n ] && [ $standqual != h ];
			then
			clear
			echo "Please enter \"n\" or \"h\", exiting."
			else
				if [ $standqual = n ];
				then
				echo "n" > /var/mobile/Media/RingRing-Settings/quality
				chown mobile:mobile /var/mobile/Media/RingRing-Settings/quality
				clear
				echo "
Turned off. Default quality: Normal"
				sleep 1
				fi
				if [ $standqual = h ];
				then
				echo "h" > /var/mobile/Media/RingRing-Settings/quality
				chown mobile:mobile /var/mobile/Media/RingRing-Settings/quality
				clear
				echo "
Turned off. Default quality: High"
				sleep 1
				fi
			fi
		fi
	fi
fi


if [ "$choice" = "0" ];
then
clear
echo "
Bye."
exit
fi

if [ "$choice" = "8" ];
then
clear
echo "
Bye."
break
fi

if [ "$choice" = "9" ];
then
	if [ "$(whoami)" != "root" ];
	then
	read -p "You're not root, it could be possible, that some files can't be removed in this process. Are you sure you want to continue? (y/n) " sureroot
		if [ "$sureroot" = "y" ];
		then
		read -p "
--------WARNING--------
YOU'RE ABOUT TO RESET
ALL YOUR PRECIOUS RingRing
       SETTINGS
-----------------------

Are you sure you want to reset all your settings? (y/n) " reset
			if [ "$reset" = "y" ];
			then
			find /var/mobile/Media/RingRing-Settings/ -type f | while read i
			do
			rm -f "$i"
			done
			clear
			exit
			fi
		fi
	else
	read -p "
--------WARNING--------
YOU'RE ABOUT TO RESET
ALL YOUR PRECIOUS RingRing
       SETTINGS
-----------------------

Are you sure you want to reset all your settings? (y/n) " reset
		if [ "$reset" = "y" ];
		then
		find /var/mobile/Media/RingRing-Settings/ -type f | while read i
		do
		rm -f "$i"
		done
		clear
		exit
		fi
	fi
fi


if [ "$choice" = "3" ];
then
	if [ -e "/var/mobile/Media/RingRing-Settings/mailoff" ];
	then
	read -p "Asking for mail is currently turned off. Turn it on? (y/n) " mailoff
		if [ "$mailoff" = "y" ];
		then
		clear
		echo "
Turned on."
		sleep 1
		rm -f /var/mobile/Media/RingRing-Settings/mailoff
		fi
	else
	read -p "Asking for mail is currently turned on. Turn it off? (y/n) " mailoff
		if [ "$mailoff" = "y" ];
		then
		clear
		echo "
Turned off."
		sleep 1
		touch /var/mobile/Media/RingRing-Settings/mailoff
		chown mobile:mobile /var/mobile/Media/RingRing-Settings/mailoff
		fi
	fi
fi


if [ "$choice" = "4" ];
then
	if [ ! -e "/usr/bin/ffaac" ];
	then
		if [ -e "/var/mobile/Media/RingRing-Settings/otheroff" ];
		then
		read -p "Asking for other software (FFaac) is currently turned off. Turn it on? (y/n) " otheron
			if [ "$otheron" = "y" ];
			then
			clear
			echo "
Turned on."
			sleep 1
			rm -f /var/mobile/Media/RingRing-Settings/otheroff
			fi
		else
		read -p "Asking for other software (FFaac) is currently turned on. Turn it off? (y/n) " otheroff
			if [ "$otheroff" = "y" ];
			then
			clear
			echo "
Turned off."
			sleep 1
			touch /var/mobile/Media/RingRing-Settings/otheroff
			chown mobile:mobile /var/mobile/Media/RingRing-Settings/otheroff
			fi
		fi
	else
	echo "This doesn't affect you."
	fi
fi


if [ "$choice" = "7" ];
then
clear
echo "Thanks bro."
sleep 1
uiopen "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=679V7DHFCR8V6"
echo "Donated" > /var/mobile/Donation
chown mobile:mobile /var/mobile/Donation
exit
fi

if [ "$choice" = "6" ];
then
uiopen http://apt.thebigboss.org/packagesfordev.php?name=RingRing
exit
fi

if [ "$choice" = "5" ];
then
	if [ -e "/var/mobile/Media/RingRing-Settings/cuttingoff" ];
	then
	read -p "Asking for cutting audio is currently turned off. Turn it on? (y/n) " cuton
		if [ "$cuton" = "y" ];
		then
		clear
		echo "
Turned on."
		sleep 1
		rm -f /var/mobile/Media/RingRing-Settings/cuttingoff
		fi
	else
	read -p "Asking for cutting audio is currently turned on. Turn it off? (y/n) " cutoff
		if [ "$cutoff" = "y" ];
		then
		clear
		echo "
Turned off."
		sleep 1
		touch /var/mobile/Media/RingRing-Settings/cuttingoff
		chown mobile:mobile /var/mobile/Media/RingRing-Settings/cuttingoff
		fi
	fi
fi



echo "Returning to main menu."
sleep 1
clear
done

ringring
