#!/bin/bash

# -------------------------------------------------
# Qarma
# -------------------------------------------------

QARMA=(
    qarma
    -qwindowtitle "RPM Installer"
    # --window-icon="/usr/share/icons/hicolor/scalable/apps/rpm-installer.svg"
)


# -------------------------------------------------
# Funksjonar
# -------------------------------------------------

install_rpm() {
    rpm_file=$("${QARMA[@]}" --file-selection \
        --title="Choose RPM to install" \
        --file-filter="RPM packages | *.rpm")

    [ -z "$rpm_file" ] && return

    if pkexec /usr/bin/zypper install "$rpm_file"; then
        "${QARMA[@]}" --info \
            --title="RPM Installer" \
            --text="Installed successfully:

$rpm_file"
    else
        "${QARMA[@]}" --error \
            --title="RPM Installer" \
            --text="Could not install:

$rpm_file"
    fi
}


# -------------------------------------------------
# Hovudmeny
# -------------------------------------------------

while true; do
    valg=$("${QARMA[@]}" --list \
        --title="RPM Installer" \
        --text="Choose your action:" \
        --column="Action" \
        --print-column=1 \
        "Install RPM" \
        "Exit" \
        --width=550 \
        --height=420)

    case "$valg" in
        "Install RPM")
            install_rpm
            ;;

        "Exit"|"")
            exit 0
            ;;
    esac
done
