#!/bin/bash

# this script is part of mx-system-sounds and governed by that license
# mxlinux.org
# author:  dolphin_oracle

#command to check and see if sounds are enabled
#xfconf-query -c xsettings -p /Net/EnableEventSounds 
#command to check sound theme name
#xfconf-query -c xsettings -p /Net/SoundThemeName
#command to find desktop-logout sound for a given theme
#find  /usr/share/sounds/theme-name/ |grep desktop-logout

customsound=$(cat ~/.config/mx-sounds/logoutsound.conf)
echo custom sound is $customsound

logout_enabled=$(grep logout ~/.config/mx-sounds/mx-login-logout_sounds.conf |cut -d '=' -f2)
echo sound status is $logout_enabled

soundthemename=$(xfconf-query -c xsettings -p /Net/SoundThemeName)
echo sound theme is $soundthemename

defaultsound=$(find  /usr/share/sounds/$soundthemename/ |grep desktop-logout)
echo default sound is $defaultsound

if [ "$customsound" = "" ]; then
	if [ "$logout_enabled" = "true" ]; then
		play "$defaultsound" 
		exit 0
	else
		exit 0
	fi
else
	if [ "$logout_enabled" = "true" ]; then
		play "$customsound" 
		exit 0
	else
		exit 0
	fi
fi

xfce4-session-logout

exit 0