schemas=($_F_gnome_schemas)
entries=($_F_gnome_entries)

UpdateDesktopDatabase()
{
	if [ -f /usr/bin/update-desktop-database ]
	then
		echo -n "updating desktop database..."
		if update-desktop-database > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
	if [ -f /usr/bin/update-desktop-database-3.0 ]
	then
		echo -n "updating desktop database gtk+3..."
		if update-desktop-database > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
}
UpdateIconCache()
{
	if [ -f /usr/bin/gtk-update-icon-cache ]
	then
		echo -n "updating hicolor icon cache..."
		if gtk-update-icon-cache -f -t /usr/share/icons/hicolor > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
	if [ -f /usr/bin/gtk-update-icon-cache-3.0 ]
	then
		echo -n "updating hicolor icon cache gtk+3..."
		if gtk-update-icon-cache-3.0 -f -t /usr/share/icons/hicolor > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
        if [ -f /usr/bin/gtk4-update-icon-cache ]
        then
                echo -n "updating hicolor icon cache gtk+4..."
                if gtk4-update-icon-cache -f -t /usr/share/icons/hicolor > /dev/null 2>&1 ; then
                        echo " done."
                else
                        echo " failed."
                fi
        fi
}

UpdateGtkImmodules()
{
	if [ -f /usr/bin/gtk-query-immodules-2.0 ]
	then
		echo -n "updating gtk+2 immodules .."
		if /usr/bin/gtk-query-immodules-2.0 > /etc/gtk-2.0/gtk.immodules 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
	if [ -f /usr/bin/gtk-query-immodules-3.0 ]
	then
		echo -n "updating gtk+3 immodules .."
		if /usr/bin/gtk-query-immodules-3.0 --update-cache > /dev/null 2>&1 ; then
			echo " done."
                else
                        echo " failed."
                fi
        fi
}

post_install()
{
	if [ ${#schemas[*]} -gt 0 ]; then
		echo -n "installing gconf schemas... "
		for schema in "${schemas[@]}" ; do
			GCONF_CONFIG_SOURCE=`/usr/bin/gconftool-2 --get-default-source` \
				/usr/bin/gconftool-2 --makefile-install-rule "$schema" > /dev/null 2>&1
		done
		if [ -e /bin/pidof ]; then
			kill -HUP `pidof /usr/libexec/gconfd-2` > /dev/null 2>&1
		fi
		echo "done."
	fi
	if [ ${#entries[*]} -gt 0 ]; then
		echo -n "loading gconf entries... "
		for entry in "${entries[@]}" ; do
			gconftool-2 --direct --config-source=`/usr/bin/gconftool-2 --get-default-source` --load $entry > /dev/null 2>&1
		done
		if [ -e /bin/pidof ]; then
			kill -HUP `pidof /usr/libexec/gconfd-2` > /dev/null 2>&1
		fi
		echo "done."
	fi
	if [ -n "$_F_gnome_glib" ]; then
		echo -n "loading schema glib entries... "
		glib-compile-schemas /usr/share/glib-2.0/schemas &>/dev/null
		echo "done."
	fi
	if [ -n "$_F_gnome_desktop" ]; then
		UpdateDesktopDatabase
	fi
	if [ -n "$_F_gnome_scrollkeeper" ]; then
		echo -n "updating rarian database..."
		if rarian-sk-update -q > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
	if [ -n "$_F_gnome_mime" ]; then
		echo -n "updating mime database..."
		if update-mime-database /usr/share/mime > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
	if [ -n "$_F_gnome_iconcache" ]; then
		UpdateIconCache
	fi
	if [ -n "$_F_gnome_gio" ]; then
		echo -n "updating gio modules database..."
		if /usr/bin/gio-querymodules /usr/lib/gio/modules > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
	if [ -n "$_F_gnome_immodules" ]; then
		UpdateGtkImmodules
	fi
}		

post_upgrade()
{
	post_install $1
}

pre_remove() {
	if [ -n "$_F_gnome_glib" ]; then
		echo -n "loading schema glib entries... "
		glib-compile-schemas /usr/share/glib-2.0/schemas &>/dev/null
		echo "done."
	fi
	if [ ${#schemas[*]} -gt 0 ]; then
		echo -n "updating gconf schemas... "
		for schema in "${schemas[@]}" ; do
			GCONF_CONFIG_SOURCE=`/usr/bin/gconftool-2 --get-default-source` \
				/usr/bin/gconftool-2 --makefile-install-rule "$schema" > /dev/null 2>&1
		done
		if [ -e /bin/pidof ]; then
			kill -HUP `pidof /usr/libexec/gconfd-2` > /dev/null 2>&1
		fi
		echo "done."
	fi
	if [ ${#entries[*]} -gt 0 ]; then
		echo -n "unloading gconf entries... "
		for entry in "${entries[@]}" ; do
			gconftool-2 --direct --config-source=`/usr/bin/gconftool-2 --get-default-source` --unload $entry > /dev/null 2>&1
		done
		if [ -e /bin/pidof ]; then
			kill -HUP `pidof /usr/libexec/gconfd-2` > /dev/null 2>&1
		fi
		echo "done."
	fi
}

post_remove()
{
	if [ -n "$_F_gnome_desktop" ]; then
		UpdateDesktopDatabase
	fi
	if [ -n "$_F_gnome_scrollkeeper" ]; then
		echo -n "updating rarian database..."
		if rarian-sk-update -q > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
	if [ -n "$_F_gnome_mime" ]; then
		echo -n "updating mime database..."
		if update-mime-database /usr/share/mime > /dev/null 2>&1 ; then
			echo " done."
		else
			echo " failed."
		fi
	fi
	if [ -n "$_F_gnome_iconcache" ]; then
		UpdateIconCache
	fi

	if [ -n "$_F_gnome_immodules" ]; then
		UpdateGtkImmodules
	fi
}


op=$1
shift

$op $*
