// Choosing a profile picture.
//
// A thin wrapper on the same FileDialog the phone controls use, so picking a
// picture is the ordinary file chooser rather than something this desktop
// invented. Nothing privileged happens here -- reading a file the user selected
// needs no authorization; only setting it on the account does.

import QtQuick
import QtQuick.Dialogs

Item {
    id: root

    signal picked(path: string)

    function open(): void {
        dialog.open();
    }

    FileDialog {
        id: dialog
        title: "Choose a profile picture"
        fileMode: FileDialog.OpenFile
        nameFilters: ["Pictures (*.png *.jpg *.jpeg *.webp *.gif *.bmp)", "All files (*)"]
        onAccepted: {
            const value = String(dialog.selectedFile);
            if (!value.startsWith("file://"))
                return;
            root.picked(decodeURIComponent(value.slice(7)));
        }
    }
}
