# #####################################################################
# Open Text Exceed onDemand Client 8
# Copyright (c) 1997-2011 Open Text Corporation. All Rights Reserved.
# #####################################################################
# xdg_cleanup
# Pre-uninstall cleanup for XDG
# $Revision: 7613 $
# #####################################################################

. utils/xdg_utils

handle_xdg_cleanup_icon_files()
{
  for thisIconFileName in ${stockIconFileNames} ; do  
    srcFile="${thisIconFileName}-${thisVer}.${iconFileExt}"
    dstFile="${thisIconFileName}.${iconFileExt}"
    rm ${srcFile}  # remove instead of renaming because we use same PNG multiple times
  done
}

xdg_remove_eod_multimime_files()
{
	supportedVer=${thisVer}
	while [ "${supportedVer}" -ge "${minSupportedVer}" ]
	do
		verStr="${supportedVer}"
		if [ "${supportedVer}" -lt "${minVerExt}" ]; then
			verStr=""
			thisAppIconName="application-x-exceedondemand"
		else
			thisAppIconName="application-x-eodclient.connectiondocument.${verStr}"
		fi
		# remove icon here
		try ${xdg_icon_resource} uninstall ${thisIconTheme} --context mimetypes ${sizeOption} ${thisAppIconName}
		supportedVer=`expr ${supportedVer} - 1`
	done
}

xdg_uninstall()
{
	if [ "$1" = "--theme" ]; then
		if [ -n "$2" ]; then
			thisIconTheme="--theme $2"
			shift
		fi
		shift
	fi
	if [ "$1" = "--iconSize" ]; then
		if [ -n "$2" ]; then
			sizeOption="--size ${2}"
			shift
		fi
		shift
	fi
	if [ "${thisIconTheme}" = "" ]; then
		thisIconTheme=${theme}
	fi
	if [ "${sizeOption}" = "" ]; then
		sizeOption="--size ${ourSize}"
	fi

	if [ -r "${eod_desktop_file}" ] ; then
		try ${xdg_icon_resource} uninstall ${thisIconTheme} ${sizeOption} ${eod_app_icon_name}
		try ${xdg_desktop_menu} uninstall "${eod_desktop_file}"
		rm -f ${eod_desktop_file}
	fi

	if [ -r "${eod_mime_file}" ] ; then
		# ignore return code for AIX, since normally there is a really ancient version of gnome installed
		[ "${thisUname}" = "AIX" ] && SAVE_ERROR_FLAG=${DI_ERROR_OCCURED}

		if [ "${multimime}" = "1" ]; then
			xdg_remove_eod_multimime_files
		else
			our_version_mime_icon_name="application-x-eodclient.connectiondocument.${thisVer}"
			try ${xdg_icon_resource} uninstall ${thisIconTheme} ${sizeOption} --context mimetypes ${our_version_mime_icon_name}
		fi

		try ${xdg_mime} uninstall "${eod_mime_file}"

		[ "${thisUname}" = "AIX" ] && DI_ERROR_OCCURED=${SAVE_ERROR_FLAG}

		rm -f ${eod_mime_file}

		handle_xdg_cleanup_icon_files
	fi
	if [ -r "${xdg_mime_info_dir}${xdg_keys_file}" ] ; then
		rm -f ${xdg_mime_info_dir}${xdg_keys_file}
	fi
	if [ -r "${xdg_mime_info_dir}${xdg_mime_file}" ] ; then
		rm -f ${xdg_mime_info_dir}${xdg_mime_file}
	fi
	if [ -r "${xdg_application_registry_dir}${xdg_applications_file}" ] ; then
		rm -f ${xdg_application_registry_dir}${xdg_applications_file}
	fi
}

