# START CONFIG[phonon-null-backend/isnt_functional]

. /usr/share/debconf/confmodule

# This function will show a warning about phonon-backend-null whenever phonon
# metapackage or phonon-backend-null is being installed
warn_about_phonon_backend_null()
{
    local package=`basename "$0" .postinst`
    local show_warning=0
    local recommended_backend="#RECOMMENDED_BACKEND#"
    local other_backends

    # Do not show the note when reconfiguring
    if [ "$1" = "reconfigure" ] || [ "DEBCONF_RECONFIGURE" = "1" ]; then
        return 0
    fi

    if [ "$1" = "configure" ]; then
        # Display the warning only if both (phonon and phonon-backend-null)
        # are (about to be) installed. In order to avoid checking dpkg status
        # database, we can check Owners field of the debconf question.
        db_metaget phonon-backend-null/isnt_functional Owners
        OWNERS="`echo "$RET" | sed 's/, /\n/g'`"
        if echo "$OWNERS" | grep -q -e 'phonon$' -e 'phonon:' && echo "$OWNERS" | grep -q phonon-backend-null; then
            show_warning=1
        fi

        # Finally show the note if needed (and it wasn't seen already)
        db_fget phonon-backend-null/isnt_functional seen || true
        if [ "$RET" != "true" ] && [ "$show_warning" = "1" ]; then
            other_backends="`LC_ALL=C apt-cache showpkg phonon-backend | \
                            awk '/: *$/{go=0} {if (go==1) print $1;} /^Reverse Provides: *$/ {go=1}' | \
                            sort -u | \
                            grep -v -e phonon-backend-null -e "$recommended_backend" | \
                            awk '{printf ", " $1}'`"
            db_settitle phonon-backend-null/isnt_functional_title || true
            db_subst phonon-backend-null/isnt_functional recommended_backend "$recommended_backend"
            db_subst phonon-backend-null/isnt_functional other_backends "$other_backends"
            db_input high phonon-backend-null/isnt_functional || true
            db_go || true
        fi
    fi
}

warn_about_phonon_backend_null "$@"

# vim: set syntax=sh

# END CONFIG[phonon-null-backend/isnt_functional]
