Skip to content

A searchable image chooser, and a Create button that reflects what is missing - #244

Open
kacperpaczos wants to merge 5 commits into
Dvlv:masterfrom
kacperpaczos:feat/image-chooser
Open

A searchable image chooser, and a Create button that reflects what is missing#244
kacperpaczos wants to merge 5 commits into
Dvlv:masterfrom
kacperpaczos:feat/image-chooser

Conversation

@kacperpaczos

Copy link
Copy Markdown
Contributor

Stacked on #241, which the branch is cut from.

distrobox create --compatibility lists 122 images on this machine, and they all went into a single gtk::DropDown. That is not a list anyone can read: you cannot tell an Ubuntu from an Alpine without going through every line, and nothing says which images are already pulled.

The chooser

The Image row opens a window with a search box, one filter per package manager, a Downloaded only switch, and a count of what is showing. Each row keeps the entry as the existing get_available_images_with_distro_name formats it (including its ✦ mark for an image already on the machine), with the URL as subtitle and the publisher on the right.

The publisher comes from the URL alone - docker.io/library/* is Docker Official, registry.access.redhat.com is Red Hat, ghcr.io/<org> and quay.io/<org> give the organisation, and anything unrecognised falls back to the registry host. No network calls: opening the window costs nothing, and there is no invented "quality score" - just who publishes it, whether it is already downloaded, and which package manager it uses.

The package-manager filter reuses detect_pkg_manager rather than introducing a second list of distro names. Images it cannot classify appear only under "All". Turning every filter off is refused, so the list cannot go blank with no way back.

all 122 filtered to apt, searched for "ubuntu"
all filtered

The Create button

Reported by a user, and worth fixing in the same change: the button was enabled by the name field alone, but creating also needs an image - so clicking it with no image chosen did nothing and said nothing. The way out a user finds is to start filling in unrelated fields; the one who reported it ended up pointing the folder chooser at a directory that never got used. It now needs both a name and an image, and the early return in the click handler stays as a backstop.

Testing

cargo test: 24 pass, including new ones on image_publisher covering each registry branch and an input with no slash at all.

On a virtual display, against the real 122-image list: the window opens showing "122 of 122 images"; the apt filter narrows it to 31; typing "ubuntu" on top of that gives 13; picking a row puts ubuntu - docker.io/library/ubuntu:24.04 in the Image row's subtitle. With an image chosen and the name empty the Create button stays insensitive, and typing a name enables it.

The chosen value keeps the "<distro> - <url>" shape the old dropdown produced, so the code that strips the prefix and the ✦ mark before handing the image to distrobox is untouched.

Creating a box already accepts a custom home directory, but it is a bare
path field: nothing says what it changes, and anyone using it for more than
one box has to remember the paths and retype them.

A profile is that directory with a name on it. The primary menu gains a
Profiles window listing them, each with the directory it points at, a
Browse button that opens it in the file manager, and Remove. Adding one
takes a name and puts the directory under ~/boxes; the directory itself is
created when it is first needed rather than up front, since distrobox makes
it when a box is built and Browse makes it when someone looks.

The new-box form gets a Profile combo listing "Host (shared home)" first,
then the profiles. Picking one fills in the home path; picking Host clears
it, which is distrobox's own default and what every existing box uses. The
folder picker still works for a one-off path, and the value handed to
distrobox is unchanged - so this is a way of choosing the existing option,
not a new mechanism.

Profiles live in GSettings as a name-to-path map, the way exported-app
labels do. Removing one forgets the setting only: the directory and any box
already built on it are left alone.
The first version of this left the Home Directory entry and its folder
button in place beside the new Profile combo, with the combo writing into
the entry. Two controls for one setting, and nothing said which of them
won - the field even kept its "Leave blank for default" label while the
combo was the thing actually deciding.

The row is now the only control. Its choices are Host (shared home), the
profiles, and Custom folder…, which opens the same folder chooser as
before; the chosen directory shows as the row's subtitle, so the path is
still visible. Cancelling the chooser falls back to Host rather than
leaving the row claiming a folder nobody picked.

What is lost is typing a path by hand, which the entry allowed. In a
graphical form a folder chooser is the better way to name a directory, and
the alternative was keeping an ambiguity in the interface to preserve it.
A box gave no sign of which home it was on, so the one thing a profile
decides was invisible once the box existed. Its page now opens with a
Profile row - a fact about the box, not a button - naming the profile whose
directory the box uses, or the host, or the bare path when it belongs to no
profile. The home comes from the container's own metadata, so nothing has
to be started to read it.

The new-box form's Profile row gains a "New profile…" entry, so a profile
can be made at the moment it is wanted rather than in a separate window
first. It asks for a name, stores the profile under ~/boxes, and selects it.

Two things that needed care: putting the selection back from inside the
row's own notify handler does not stick, because GTK is still applying the
change being reacted to - it is deferred to the main loop instead, so a
cancelled dialog never leaves the row sitting on "New profile…". And the
label logic is a pure function taking the host home and the profile list,
so it can be tested without touching GSettings.
distrobox offers 122 images here. They all went into one dropdown, which
cannot be read: you cannot tell an Ubuntu from an Alpine without going
through every line, and nothing says which are already on the machine.

The Image row now opens a chooser: a search box, one filter per package
manager, and a "Downloaded only" switch, with a count of what is showing.
Each row carries the image URL and who publishes it - Docker Official,
Fedora Project, Red Hat, the GitHub or Quay organisation, or failing all
that the registry itself - worked out from the URL alone, so opening the
window costs nothing and touches no network. The package-manager filter
reuses detect_pkg_manager rather than a second list of distro names.

The Create button was enabled by the name field alone, though creating
also needs an image, so clicking it with no image chosen did nothing and
explained nothing - a trap a user escapes by filling in unrelated fields.
It now needs both.
`make lint` runs clippy, and the strings added here tripped
needless_borrows_for_generic_args - gettext takes anything that converts
into a String, so the format! result can go in as it is. Only the lines
this branch introduced are touched; the same pattern elsewhere in the file
predates it and is left alone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant