From 8de622614a89c3dda9eb3ad5358826c3dc6c9613 Mon Sep 17 00:00:00 2001 From: GloriousEggroll Date: Sat, 29 Mar 2025 03:55:38 -0600 Subject: [PATCH] add kind labeling --- libflatpak_query.py | 62 ++++++++++++++++++++++++++++++++++++++++++--- main.py | 15 ++++++++++- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/libflatpak_query.py b/libflatpak_query.py index c5f74d5..49061ca 100755 --- a/libflatpak_query.py +++ b/libflatpak_query.py @@ -33,7 +33,6 @@ # which have been modified and extended. -from typing import cast import gi gi.require_version("AppStream", "1.0") gi.require_version("Flatpak", "1.0") @@ -62,6 +61,59 @@ class Match(IntEnum): SUMMARY = 3 NONE = 4 +class AppStreamComponentKind(IntEnum): + """AppStream Component Kind enumeration.""" + + UNKNOWN = 0 + """Type invalid or not known.""" + + GENERIC = 1 + """A generic (= without specialized type) component.""" + + DESKTOP_APP = 2 + """An application with a .desktop-file.""" + + CONSOLE_APP = 3 + """A console application.""" + + WEB_APP = 4 + """A web application.""" + + SERVICE = 5 + """A system service launched by the init system.""" + + ADDON = 6 + """An extension of existing software, which does not run standalone.""" + + RUNTIME = 7 + """An application runtime platform.""" + + FONT = 8 + """A font.""" + + CODEC = 9 + """A multimedia codec.""" + + INPUT_METHOD = 10 + """An input-method provider.""" + + OPERATING_SYSTEM = 11 + """A computer operating system.""" + + FIRMWARE = 12 + """Firmware.""" + + DRIVER = 13 + """A driver.""" + + LOCALIZATION = 14 + """Software localization (usually l10n resources).""" + + REPOSITORY = 15 + """A remote software or data source.""" + + ICON_THEME = 16 + """An icon theme following the XDG specification.""" class AppStreamPackage: def __init__(self, comp: AppStream.Component, remote: Flatpak.Remote) -> None: @@ -108,9 +160,13 @@ class AppStreamPackage: return None @property - def kind(self) -> str: - return str(self.component.get_kind()) + def kind(self): + kind = self.component.get_kind() + kind_str = str(kind) + for member in AppStreamComponentKind: + if member.name in kind_str: + return member.name def _get_icon_url(self) -> str: """Get the remote icon URL from the component""" diff --git a/main.py b/main.py index 888d016..f99e6f3 100755 --- a/main.py +++ b/main.py @@ -606,6 +606,7 @@ class MainWindow(Gtk.Window): def on_search_activate(self, searchentry): """Handle Enter key press in search""" + self.update_category_header("Search Results") search_term = searchentry.get_text().lower() if not search_term: # Reset to showing all categories when search is empty @@ -702,7 +703,7 @@ class MainWindow(Gtk.Window): break if display_title == "": # Fallback if category isn't found - display_title = category.capitalize() + display_title = category self.category_header.set_label(display_title) def create_applications_panel(self, title): @@ -1197,6 +1198,17 @@ class MainWindow(Gtk.Window): title_label.set_yalign(0.5) # Use yalign instead of valign title_label.set_hexpand(True) + # Add repository labels + kind_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + kind_box.set_spacing(4) + kind_box.set_halign(Gtk.Align.START) + kind_box.set_valign(Gtk.Align.START) + + kind_label = Gtk.Label(label=details['kind']) + kind_label.get_style_context().add_class("item-repo-label") + kind_label.set_halign(Gtk.Align.START) + kind_box.pack_end(kind_label, False, False, 0) + # Add repository labels repo_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) repo_box.set_spacing(4) @@ -1293,6 +1305,7 @@ class MainWindow(Gtk.Window): # Add widgets to right box right_box.pack_start(title_label, False, False, 0) + right_box.pack_start(kind_box, False, False, 0) right_box.pack_start(repo_box, False, False, 0) right_box.pack_start(desc_label, False, False, 0) right_box.pack_start(buttons_box, False, True, 0)