diff --git a/example_config/config.yaml b/example_config/config.yaml index 2bdedeb..cb14a97 100644 --- a/example_config/config.yaml +++ b/example_config/config.yaml @@ -59,24 +59,29 @@ minimum_disk_size: 5 # Default: yes offer_disk_encryption: yes -# A list of additional software packages that can be optionally be selected -# from the installer. The package string will be passed to the installation -# script without changes, so you can bundle multiple packages as one point. -# Required fields are: package, default, name, description, icon_path -# Additionally translations for name and description can be specified by -# placing a language code at the end after an underscore, e.g.: 'name_jp' -# Default: [] +# List of software that can additionally be selected for installation. +# Each packages requires all fields to be set. +# +# package string Forwarded to the installation script as is. +# suggested bool Optional. Whether installation defaults to yes. +# name_LC string Name presented to user. Translatable. +# If no (English) name is available, it will only +# be shown for translated languages. +# description_LC string Optional. Description presented to user. Translatable. +# icon_path string Optional. Absolute path to icon to be displayed. +# +# Default: [], suggested: False, description: '', icon_path: fallback icon additional_software: - package : 'firefox' - default : yes + suggested : yes name : 'Firefox' name_de : 'Feuerfuchs' description : 'Popular Web Browser from Mozilla' - description_de : 'Beliebter Webbrowser entwickelt durch Mozilla' + description_de : 'Beliebter Internet-Browser von Mozilla' icon_path : '/etc/os-installer/icons/firefox.png' - - package : 'libreoffice-fresh' - default : no - name : 'LibreOffice' - description : 'Office Suite for Documents, Tables, Presentations and more' - description_de : 'Sammlung an BüroAnwendungen für Dokumente, Tabellen, Präsentationen und mehr' + - package : 'some-backend' + name : 'Iconless Backend Functionality' + - package : 'japanese-input-program' + suggested : yes + name_jp : 'Input Program' icon_path : '/etc/os-installer/icons/libreoffice-main.png' diff --git a/src/provider/software_provider.py b/src/provider/software_provider.py index 1965c62..a514b9e 100644 --- a/src/provider/software_provider.py +++ b/src/provider/software_provider.py @@ -7,24 +7,45 @@ from .global_state import global_state class Package(GObject.GObject): __gtype_name__ = __qualname__ - def __init__(self, package): + def __init__(self, package, suggested, name, description, icon_path): super().__init__() self.package = package + self.suggested = suggested + self.name = name + self.description = description + self.icon_path = icon_path ### public methods ### def get_software_suggestions(): + if not (software := global_state.get_config('additional_software')): + return [] + language_code = global_state.get_config('language_code') + suggestions = [] - software = global_state.get_config('additional_software') - if software: - for package in software: - if ('package' in package and - 'default' in package and - 'name' in package and - 'description' in package and - 'icon_path' in package): - suggestions.append(Package(package)) - else: + for package in software: + if not 'package' in package: + print(f'Package {package} not correctly configured!') + continue + + if (not ((name_key := f'name_{language_code}') in package or + (name_key := 'name') in package)): + # no error if package is only suggested for specific translations + if not any(key.startswith('name') for key in package.keys()): print(f'Package {package} not correctly configured!') + continue + + suggested = package['suggested'] if 'suggested' in package else False + name = package[name_key] + if ((description_key := f'description_{language_code}') in package or + (description_key := 'description') in package): + description = package[description_key] + else: + description = '' + + icon_path = package['icon_path'] if 'icon_path' in package else '' + suggestions.append( + Package(package['package'], suggested, name, description, icon_path)) + return suggestions diff --git a/src/ui/pages/software.py b/src/ui/pages/software.py index 4bde503..3b82f92 100644 --- a/src/ui/pages/software.py +++ b/src/ui/pages/software.py @@ -18,9 +18,8 @@ class SoftwarePage(Gtk.Box, Page): def __init__(self, **kwargs): Gtk.Box.__init__(self, **kwargs) - language_code = global_state.get_config('language_code') self.software_list.bind_model( - self.software_model, lambda o: SoftwareRow(o.package, language_code)) + self.software_model, lambda o: SoftwareRow(o)) def _setup_software(self): suggestions = get_software_suggestions() @@ -46,6 +45,6 @@ class SoftwarePage(Gtk.Box, Page): to_install = '' for row in self.software_list: if row.is_activated(): - to_install += ' ' + row.package_name + to_install += f' {row.info}' global_state.set_config('chosen_additional_software', to_install.strip()) diff --git a/src/ui/widgets.py b/src/ui/widgets.py index 561bf1c..8af043a 100644 --- a/src/ui/widgets.py +++ b/src/ui/widgets.py @@ -90,20 +90,14 @@ class SoftwareRow(Adw.ActionRow): icon = Gtk.Template.Child() switch = Gtk.Template.Child() - def __init__(self, package, language_code, **kwargs): + def __init__(self, package, **kwargs): super().__init__(**kwargs) - if (localized_name := f'name_{language_code}') in package: - self.set_title(package[localized_name]) - else: - self.set_title(package['name']) - if (localized_description := f'description_{language_code}') in package: - self.set_subtitle(package[localized_description]) - else: - self.set_subtitle(package['description']) - self.icon.set_from_file(package['icon_path']) - self.switch.set_state(package['default']) + self.set_title(package.name) + self.set_subtitle(package.description) + self.icon.set_from_file(package.icon_path) + self.switch.set_state(package.suggested) - self.package_name = package['package'] + self.info = package.package def is_activated(self): return self.switch.get_active()