diff --git a/CHANGELOG.md b/CHANGELOG.md index 34cfc2b..4f884fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ complete; every release is an annotated git tag `vX.Y.Z` (see `tools/release.sh` - Haiku USB backend (Storage Kit disk device API): lists USB drives, writes an MBR with one FAT32 partition at 1 MiB, mounts, unmounts and ejects. Validated end to end in the VM. - The core library and `openpu-cli` build and pass all unit tests on Haiku R1/beta6 x86_64. +- Haiku graphical interface (Interface Kit): the same screens as the GTK interface (vehicles, + adding a vehicle, updates, download folder, resumable download, USB stick, writing, installation + guide), Preferences window, About window and new-version check. It uses the gettext catalogs of + the GTK interface, and the language of the Locale preferences by default. ### Fixed - Archive extraction failed when the destination path contained a symbolic link (e.g. `/tmp` on diff --git a/CMakeLists.txt b/CMakeLists.txt index f1306a0..8646aa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,15 +9,16 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) option(OPENPU_BUILD_CLI "Build openpu-cli" ON) option(OPENPU_BUILD_TESTS "Build unit tests" ON) option(OPENPU_UI_GTK "Build the GTK4 user interface" OFF) -option(OPENPU_UI_HAIKU "Build the Haiku user interface" OFF) +if(CMAKE_SYSTEM_NAME STREQUAL "Haiku") + set(OPENPU_UI_HAIKU_DEFAULT ON) +else() + set(OPENPU_UI_HAIKU_DEFAULT OFF) +endif() +option(OPENPU_UI_HAIKU "Build the Haiku user interface" ${OPENPU_UI_HAIKU_DEFAULT}) option(OPENPU_WERROR "Treat warnings as errors" OFF) option(OPENPU_CLANG_TIDY "Run clang-tidy while compiling" OFF) option(OPENPU_SANITIZE "Build with ASan + UBSan" OFF) -if(CMAKE_SYSTEM_NAME STREQUAL "Haiku") - set(OPENPU_UI_HAIKU_DEFAULT ON) -endif() - add_library(openpu_warnings INTERFACE) target_compile_options(openpu_warnings INTERFACE -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wno-sign-conversion) if(OPENPU_WERROR) @@ -42,6 +43,11 @@ endif() if(OPENPU_UI_GTK) add_subdirectory(src/ui-gtk) +endif() +if(OPENPU_UI_HAIKU) + add_subdirectory(src/ui-haiku) +endif() +if(OPENPU_UI_GTK OR OPENPU_UI_HAIKU) add_subdirectory(po) endif() diff --git a/README.md b/README.md index c46bd96..57b588b 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ It is an alternative to the official "Peugeot Update" application (Windows/macOS - [x] Versioning (`--version`, About dialog, `vX.Y.Z` tags, GitHub releases) - [x] gettext translations (English, French) - [x] Haiku: core library, CLI and USB support (Storage Kit), validated in a Haiku R1/beta6 VM -- [ ] Haiku UI +- [x] Haiku UI (Interface Kit): complete workflow, preferences, new-version check - [x] GitHub Actions continuous integration (Linux x86_64 + arm64) - [ ] Linux packages: `.deb`, Flatpak and AppImage; Haiku: `.hpkg` - [ ] x86_64 + arm64 binaries attached to every release (from 1.0.0 on) @@ -52,6 +52,16 @@ tools/e2e-usb.sh ../build-openpu/debug/src/cli/openpu-cli --license X.key update When running from the build tree, `OPENPU_LOCALEDIR=../build-openpu/debug/locale` lets the interface find its translations. +## Building (Haiku) +```sh +pkgman install cmake ninja curl_devel libarchive_devel nlohmann_json gettext gettext_libintl_devel +cmake -S . -B build -G Ninja && cmake --build build && build/tests/openpu_tests +OPENPU_LOCALEDIR=build/locale build/src/ui-haiku/OpenPU # graphical interface +build/src/cli/openpu-cli usb-list +``` +`tools/haiku-vm.sh` installs and runs a Haiku R1/beta6 VM under QEMU/KVM (from WSL or Linux), with +a virtual USB stick; `sync` copies the working tree into it and `ssh` runs commands there. + ## Versioning - The reference version is `project(openpu VERSION x.y.z)` in `CMakeLists.txt`. On every build, `git describe` produces the displayed description (for example `0.2.0+3.g1a2b3c4.dirty`). @@ -60,13 +70,15 @@ interface find its translations. commits, tags, pushes to every remote and creates the release. ## Translations -Source strings are in English and translations use gettext (`po/.po`). To add a -language: +Source strings are in English and translations use gettext (`po/.po`), on Linux and on +Haiku: both interfaces share the same catalogs. On Haiku the default language is the first one of +the Locale preferences. To add a language: 1. update the template with `cmake --build --target pot`, or with - `python3 tools/extract_strings.py po/openpu.pot src/ui-gtk/main_window.cpp` if gettext is not - installed; + `python3 tools/extract_strings.py po/openpu.pot src/ui-gtk/main_window.cpp src/ui-haiku/main_window.cpp` + if gettext is not installed; 2. copy `po/openpu.pot` to `po/.po` and translate it; -3. add the language to `po/LINGUAS` and to the list in the Preferences dialog. +3. add the language to `po/LINGUAS` and to the language list of the Preferences window of both + interfaces. ## Tools - `tools/asar_extract.py`: minimal, read-only asar extractor used to study the reference diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt index c440ee9..5fba50b 100644 --- a/po/CMakeLists.txt +++ b/po/CMakeLists.txt @@ -24,5 +24,6 @@ if(XGETTEXT) COMMAND ${XGETTEXT} --keyword=_ --keyword=N_ --from-code=UTF-8 --package-name=openpu --add-comments=TRANSLATORS -o ${CMAKE_CURRENT_SOURCE_DIR}/openpu.pot ${PROJECT_SOURCE_DIR}/src/ui-gtk/main_window.cpp + ${PROJECT_SOURCE_DIR}/src/ui-haiku/main_window.cpp WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) endif() diff --git a/po/fr.po b/po/fr.po index 157a7d4..dac86ae 100644 --- a/po/fr.po +++ b/po/fr.po @@ -2,319 +2,469 @@ msgid "" msgstr "" "Project-Id-Version: openpu\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-11-29 05:53+0100\n" "PO-Revision-Date: 2026-11-28 20:00+0100\n" "Last-Translator: OpenPU contributors\n" "Language-Team: French\n" -"MIME-Version: 1.0\n" "Language: fr\n" +"MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" +#: src/ui-gtk/main_window.cpp:54 src/ui-haiku/main_window.cpp:185 msgid "Crony (navigation)" msgstr "Crony (avec navigation)" +#: src/ui-gtk/main_window.cpp:55 src/ui-haiku/main_window.cpp:186 msgid "Crony (no navigation)" msgstr "Crony (sans navigation)" +#: src/ui-gtk/main_window.cpp:58 src/ui-haiku/main_window.cpp:189 msgid "unknown head unit" msgstr "autoradio inconnu" +#: src/ui-gtk/main_window.cpp:63 src/ui-haiku/main_window.cpp:194 msgid "version %1, %2" msgstr "version %1, %2" +#: src/ui-gtk/main_window.cpp:70 src/ui-haiku/main_window.cpp:200 msgid "The update server cannot be reached. Check your Internet connection." -msgstr "Le serveur de mises à jour est injoignable. Vérifiez votre connexion Internet." +msgstr "" +"Le serveur de mises à jour est injoignable. Vérifiez votre connexion " +"Internet." +#: src/ui-gtk/main_window.cpp:73 src/ui-haiku/main_window.cpp:202 msgid "The update server returned an error. Try again later." msgstr "Le serveur de mises à jour a renvoyé une erreur. Réessayez plus tard." +#: src/ui-gtk/main_window.cpp:75 src/ui-haiku/main_window.cpp:203 msgid "This VIN is not valid." msgstr "Ce VIN n'est pas valide." +#: src/ui-gtk/main_window.cpp:104 src/ui-haiku/main_window.cpp:407 msgid "Your saved data cannot be read" msgstr "Vos données enregistrées sont illisibles" +#: src/ui-gtk/main_window.cpp:109 src/ui-haiku/main_window.cpp:720 +#: src/ui-haiku/main_window.cpp:807 src/ui-haiku/main_window.cpp:1071 msgid "Back" msgstr "Retour" -msgid "About OpenPU" -msgstr "À propos d'OpenPU" - -msgid "" -"Download Peugeot head unit updates (system and navigation map) and prepare the USB stick, on " -"Linux and Haiku.\n" -"\n" -"Independent project, not affiliated with Stellantis or Peugeot." -msgstr "" -"Téléchargez les mises à jour de l'autoradio Peugeot (système et cartographie) et préparez la " -"clé USB, sous Linux et Haiku.\n" -"\n" -"Projet indépendant, sans lien avec Stellantis ni Peugeot." - -msgid "Source code" -msgstr "Code source" - -msgid "Cannot save the vehicle list" -msgstr "Impossible d'enregistrer la liste des véhicules" - -msgid "My vehicles" -msgstr "Mes véhicules" - -msgid "Add your vehicle with its VIN (17 characters, on the registration document, field E)." -msgstr "Ajoutez votre véhicule avec son VIN (17 caractères, sur le certificat d'immatriculation, champ E)." - -msgid "Add a vehicle" -msgstr "Ajouter un véhicule" - -msgid "Remove" -msgstr "Supprimer" - -msgid "Check for updates" -msgstr "Rechercher les mises à jour" - -msgid "download not finished" -msgstr "téléchargement inachevé" - -msgid "Remove %1?" -msgstr "Supprimer %1 ?" - -msgid "Downloaded files that were not written to a USB stick yet are deleted too." -msgstr "Les fichiers téléchargés qui n'ont pas encore été copiés sur une clé USB seront aussi supprimés." - -msgid "Cancel" -msgstr "Annuler" - -msgid "" -"The VIN (vehicle identification number) is written in field E of the registration document and " -"at the bottom of the windscreen." -msgstr "" -"Le VIN (numéro d'identification du véhicule) figure au champ E du certificat d'immatriculation " -"et en bas du pare-brise." - -msgid "VIN" -msgstr "VIN" - -msgid "Name" -msgstr "Nom" - -msgid "e.g. 208 or Family car" -msgstr "par ex. 208 ou Voiture familiale" - -msgid "Add" -msgstr "Ajouter" - -msgid "A VIN has 17 characters and starts with VF3 or VR3." -msgstr "Un VIN comporte 17 caractères et commence par VF3 ou VR3." - -msgid "Checking the vehicle…" -msgstr "Vérification du véhicule…" - -msgid "This vehicle is unknown to the update service." -msgstr "Ce véhicule est inconnu du service de mises à jour." - -msgid "This vehicle has no head unit that can be updated with a USB stick." -msgstr "Ce véhicule n'a pas d'autoradio pouvant être mis à jour par clé USB." - -msgid "Download folder:" -msgstr "Dossier de téléchargement :" - -msgid "Change…" -msgstr "Modifier…" - -msgid "Installation guide" -msgstr "Guide d'installation" - -msgid "Download" -msgstr "Télécharger" - -msgid "Looking for updates…" -msgstr "Recherche des mises à jour…" - -msgid "No update is available: your head unit is up to date." -msgstr "Aucune mise à jour disponible : votre autoradio est à jour." - -msgid "Select the updates to download:" -msgstr "Sélectionnez les mises à jour à télécharger :" - -msgid "System (firmware)" -msgstr "Système (firmware)" - -msgid "Navigation map" -msgstr "Cartographie" - -msgid "Download folder" -msgstr "Dossier de téléchargement" - -msgid "Cannot save the settings" -msgstr "Impossible d'enregistrer les réglages" - -msgid "Not enough free space" -msgstr "Espace libre insuffisant" - -msgid "" -"%1 are needed in %2 but only %3 are free. If a previous download of these files is already in " -"this folder, it will be resumed and may fit." -msgstr "" -"%1 sont nécessaires dans %2 mais seuls %3 sont libres. Si un téléchargement précédent de ces " -"fichiers se trouve déjà dans ce dossier, il sera repris et pourra tenir." - -msgid "Download anyway" -msgstr "Télécharger quand même" - -msgid "Downloading" -msgstr "Téléchargement" - -msgid "You can close the application: the download will resume where it stopped next time." -msgstr "Vous pouvez fermer l'application : le téléchargement reprendra là où il s'est arrêté." - -msgid "Stop" -msgstr "Arrêter" - -msgid "License" -msgstr "Licence" - -msgid "waiting" -msgstr "en attente" - -msgid "Connecting…" -msgstr "Connexion…" - -msgid "Cannot write the file: %1" -msgstr "Impossible d'écrire le fichier : %1" - -msgid "The download failed: %1" -msgstr "Le téléchargement a échoué : %1" - -msgid "Download interrupted" -msgstr "Téléchargement interrompu" - -msgid "The files already downloaded are kept; start again to resume." -msgstr "Les fichiers déjà téléchargés sont conservés ; relancez pour reprendre." - -msgid "done" -msgstr "terminé" - -msgid "Time left: %1" -msgstr "Temps restant : %1" - -msgid "(connection lost, attempt %1)" -msgstr "(connexion perdue, tentative %1)" - -msgid "Prepare the USB stick" -msgstr "Préparer la clé USB" - -msgid "This USB stick is too small." -msgstr "Cette clé USB est trop petite." - -msgid "Refresh" -msgstr "Actualiser" - -msgid "Erase and write" -msgstr "Effacer et écrire" - -msgid "Computing the required size…" -msgstr "Calcul de la taille nécessaire…" - -msgid "A downloaded file is damaged" -msgstr "Un fichier téléchargé est endommagé" - -msgid "Download the update again." -msgstr "Téléchargez à nouveau la mise à jour." - -msgid "Plug in a USB stick of at least %1. It will be completely erased and formatted (FAT32)." -msgstr "Branchez une clé USB d'au moins %1. Elle sera entièrement effacée et formatée (FAT32)." - -msgid "USB drives cannot be listed: " -msgstr "Impossible de lister les clés USB : " - -msgid "too small" -msgstr "trop petite" - -msgid "No USB stick found. Plug one in, then refresh." -msgstr "Aucune clé USB trouvée. Branchez-en une, puis actualisez." - -msgid "Erase %1?" -msgstr "Effacer %1 ?" - -msgid "Everything on this USB stick will be lost." -msgstr "Tout le contenu de cette clé USB sera perdu." - -msgid "Writing the USB stick" -msgstr "Écriture de la clé USB" - -msgid "Do not unplug the USB stick." -msgstr "Ne débranchez pas la clé USB." - -msgid "Checking the downloaded files…" -msgstr "Vérification des fichiers téléchargés…" - -msgid "Permission to format the USB stick was refused." -msgstr "L'autorisation de formater la clé USB a été refusée." - -msgid "The USB stick could not be prepared" -msgstr "La clé USB n'a pas pu être préparée" - -msgid "Formatting the USB stick…" -msgstr "Formatage de la clé USB…" - -msgid "Copying the license…" -msgstr "Copie de la licence…" - -msgid "Copying the update…" -msgstr "Copie de la mise à jour…" - -msgid "Ejecting the USB stick…" -msgstr "Éjection de la clé USB…" - -msgid "The USB stick is ready" -msgstr "La clé USB est prête" - -msgid "" -"You can unplug the USB stick. With the engine running, plug it into the vehicle and follow the " -"instructions on the screen. The installation can take a long time: do not stop the engine." -msgstr "" -"Vous pouvez débrancher la clé USB. Moteur tournant, branchez-la dans le véhicule et suivez les " -"instructions à l'écran. L'installation peut être longue : ne coupez pas le moteur." - -msgid "Finish" -msgstr "Terminer" - +#: src/ui-gtk/main_window.cpp:113 src/ui-gtk/main_window.cpp:219 +#: src/ui-haiku/main_window.cpp:279 src/ui-haiku/main_window.cpp:384 msgid "Preferences" msgstr "Préférences" +#: src/ui-gtk/main_window.cpp:114 src/ui-haiku/main_window.cpp:385 msgid "Check for a new version of OpenPU" msgstr "Rechercher une nouvelle version d'OpenPU" +#: src/ui-gtk/main_window.cpp:115 src/ui-haiku/main_window.cpp:382 +msgid "About OpenPU" +msgstr "À propos d'OpenPU" + +#: src/ui-gtk/main_window.cpp:118 msgid "Menu" msgstr "Menu" +#: src/ui-gtk/main_window.cpp:181 src/ui-haiku/main_window.cpp:509 msgid "OpenPU is up to date" msgstr "OpenPU est à jour" +#: src/ui-gtk/main_window.cpp:182 src/ui-haiku/main_window.cpp:509 msgid "Version %1 is the latest version." msgstr "La version %1 est la plus récente." +#: src/ui-gtk/main_window.cpp:185 src/ui-haiku/main_window.cpp:513 msgid "Cannot check for a new version" msgstr "Impossible de rechercher une nouvelle version" +#: src/ui-gtk/main_window.cpp:195 src/ui-haiku/main_window.cpp:526 msgid "OpenPU %1 is available" msgstr "OpenPU %1 est disponible" +#: src/ui-gtk/main_window.cpp:197 src/ui-haiku/main_window.cpp:523 msgid "You are using version %1. Do you want to download the new version?" -msgstr "Vous utilisez la version %1. Voulez-vous télécharger la nouvelle version ?" +msgstr "" +"Vous utilisez la version %1. Voulez-vous télécharger la nouvelle version ?" +#: src/ui-gtk/main_window.cpp:201 src/ui-haiku/main_window.cpp:526 msgid "Later" msgstr "Plus tard" +#: src/ui-gtk/main_window.cpp:201 src/ui-gtk/main_window.cpp:625 +#: src/ui-haiku/main_window.cpp:527 src/ui-haiku/main_window.cpp:790 +msgid "Download" +msgstr "Télécharger" + +#: src/ui-gtk/main_window.cpp:231 src/ui-gtk/main_window.cpp:705 +#: src/ui-haiku/main_window.cpp:308 src/ui-haiku/main_window.cpp:898 +msgid "Download folder" +msgstr "Dossier de téléchargement" + +#: src/ui-gtk/main_window.cpp:238 src/ui-gtk/main_window.cpp:608 +#: src/ui-haiku/main_window.cpp:310 src/ui-haiku/main_window.cpp:803 +msgid "Change…" +msgstr "Modifier…" + +#: src/ui-gtk/main_window.cpp:247 src/ui-haiku/main_window.cpp:297 msgid "Language" msgstr "Langue" +#: src/ui-gtk/main_window.cpp:252 src/ui-haiku/main_window.cpp:293 msgid "System language" msgstr "Langue du système" +#: src/ui-gtk/main_window.cpp:258 src/ui-haiku/main_window.cpp:298 msgid "The new language is used the next time OpenPU starts." msgstr "La nouvelle langue sera utilisée au prochain démarrage d'OpenPU." +#: src/ui-gtk/main_window.cpp:271 src/ui-gtk/main_window.cpp:286 +#: src/ui-gtk/main_window.cpp:718 src/ui-haiku/main_window.cpp:565 +msgid "Cannot save the settings" +msgstr "Impossible d'enregistrer les réglages" + +#: src/ui-gtk/main_window.cpp:279 src/ui-haiku/main_window.cpp:301 msgid "Check for a new version of OpenPU at startup" msgstr "Rechercher une nouvelle version d'OpenPU au démarrage" + +#: src/ui-gtk/main_window.cpp:338 src/ui-haiku/main_window.cpp:548 +msgid "" +"Download Peugeot head unit updates (system and navigation map) and prepare " +"the USB stick, on Linux and Haiku.\n" +"\n" +"Independent project, not affiliated with Stellantis or Peugeot." +msgstr "" +"Téléchargez les mises à jour de l'autoradio Peugeot (système et " +"cartographie) et préparez la clé USB, sous Linux et Haiku.\n" +"\n" +"Projet indépendant, sans lien avec Stellantis ni Peugeot." + +#: src/ui-gtk/main_window.cpp:344 src/ui-haiku/main_window.cpp:556 +msgid "Source code" +msgstr "Code source" + +#: src/ui-gtk/main_window.cpp:356 src/ui-haiku/main_window.cpp:574 +msgid "Cannot save the vehicle list" +msgstr "Impossible d'enregistrer la liste des véhicules" + +#: src/ui-gtk/main_window.cpp:370 src/ui-haiku/main_window.cpp:635 +msgid "My vehicles" +msgstr "Mes véhicules" + +#: src/ui-gtk/main_window.cpp:372 src/ui-haiku/main_window.cpp:623 +msgid "" +"Add your vehicle with its VIN (17 characters, on the registration document, " +"field E)." +msgstr "" +"Ajoutez votre véhicule avec son VIN (17 caractères, sur le certificat " +"d'immatriculation, champ E)." + +#: src/ui-gtk/main_window.cpp:392 src/ui-gtk/main_window.cpp:486 +#: src/ui-haiku/main_window.cpp:640 src/ui-haiku/main_window.cpp:710 +msgid "Add a vehicle" +msgstr "Ajouter un véhicule" + +#: src/ui-gtk/main_window.cpp:393 src/ui-gtk/main_window.cpp:457 +#: src/ui-haiku/main_window.cpp:629 src/ui-haiku/main_window.cpp:683 +msgid "Remove" +msgstr "Supprimer" + +#: src/ui-gtk/main_window.cpp:394 src/ui-haiku/main_window.cpp:630 +msgid "Check for updates" +msgstr "Rechercher les mises à jour" + +#: src/ui-gtk/main_window.cpp:425 src/ui-haiku/main_window.cpp:655 +msgid "download not finished" +msgstr "téléchargement inachevé" + +#: src/ui-gtk/main_window.cpp:455 src/ui-haiku/main_window.cpp:682 +msgid "Remove %1?" +msgstr "Supprimer %1 ?" + +#: src/ui-gtk/main_window.cpp:456 src/ui-haiku/main_window.cpp:683 +msgid "" +"Downloaded files that were not written to a USB stick yet are deleted too." +msgstr "" +"Les fichiers téléchargés qui n'ont pas encore été copiés sur une clé USB " +"seront aussi supprimés." + +#: src/ui-gtk/main_window.cpp:457 src/ui-gtk/main_window.cpp:741 +#: src/ui-gtk/main_window.cpp:982 src/ui-haiku/main_window.cpp:683 +#: src/ui-haiku/main_window.cpp:938 src/ui-haiku/main_window.cpp:1156 +msgid "Cancel" +msgstr "Annuler" + +#: src/ui-gtk/main_window.cpp:488 src/ui-haiku/main_window.cpp:711 +msgid "" +"The VIN (vehicle identification number) is written in field E of the " +"registration document and at the bottom of the windscreen." +msgstr "" +"Le VIN (numéro d'identification du véhicule) figure au champ E du certificat " +"d'immatriculation et en bas du pare-brise." + +#: src/ui-gtk/main_window.cpp:496 src/ui-haiku/main_window.cpp:699 +msgid "VIN" +msgstr "VIN" + +#: src/ui-gtk/main_window.cpp:498 src/ui-haiku/main_window.cpp:702 +msgid "Name" +msgstr "Nom" + +#: src/ui-gtk/main_window.cpp:503 +msgid "e.g. 208 or Family car" +msgstr "par ex. 208 ou Voiture familiale" + +#: src/ui-gtk/main_window.cpp:517 src/ui-haiku/main_window.cpp:704 +msgid "Add" +msgstr "Ajouter" + +#: src/ui-gtk/main_window.cpp:535 src/ui-haiku/main_window.cpp:732 +msgid "A VIN has 17 characters and starts with VF3 or VR3." +msgstr "Un VIN comporte 17 caractères et commence par VF3 ou VR3." + +#: src/ui-gtk/main_window.cpp:541 src/ui-haiku/main_window.cpp:737 +msgid "Checking the vehicle…" +msgstr "Vérification du véhicule…" + +#: src/ui-gtk/main_window.cpp:558 src/ui-haiku/main_window.cpp:753 +msgid "This vehicle is unknown to the update service." +msgstr "Ce véhicule est inconnu du service de mises à jour." + +#: src/ui-gtk/main_window.cpp:562 src/ui-haiku/main_window.cpp:757 +msgid "This vehicle has no head unit that can be updated with a USB stick." +msgstr "Ce véhicule n'a pas d'autoradio pouvant être mis à jour par clé USB." + +#: src/ui-gtk/main_window.cpp:604 src/ui-haiku/main_window.cpp:801 +msgid "Download folder:" +msgstr "Dossier de téléchargement :" + +#: src/ui-gtk/main_window.cpp:617 src/ui-gtk/main_window.cpp:1118 +#: src/ui-haiku/main_window.cpp:789 src/ui-haiku/main_window.cpp:1287 +msgid "Installation guide" +msgstr "Guide d'installation" + +#: src/ui-gtk/main_window.cpp:651 src/ui-haiku/main_window.cpp:835 +msgid "Looking for updates…" +msgstr "Recherche des mises à jour…" + +#: src/ui-gtk/main_window.cpp:685 src/ui-haiku/main_window.cpp:867 +msgid "No update is available: your head unit is up to date." +msgstr "Aucune mise à jour disponible : votre autoradio est à jour." + +#: src/ui-gtk/main_window.cpp:688 src/ui-haiku/main_window.cpp:870 +msgid "Select the updates to download:" +msgstr "Sélectionnez les mises à jour à télécharger :" + +#: src/ui-gtk/main_window.cpp:690 src/ui-gtk/main_window.cpp:803 +#: src/ui-haiku/main_window.cpp:872 src/ui-haiku/main_window.cpp:979 +msgid "System (firmware)" +msgstr "Système (firmware)" + +#: src/ui-gtk/main_window.cpp:695 src/ui-gtk/main_window.cpp:807 +#: src/ui-haiku/main_window.cpp:877 src/ui-haiku/main_window.cpp:982 +msgid "Navigation map" +msgstr "Cartographie" + +#: src/ui-gtk/main_window.cpp:736 src/ui-haiku/main_window.cpp:938 +msgid "Not enough free space" +msgstr "Espace libre insuffisant" + +#: src/ui-gtk/main_window.cpp:738 src/ui-haiku/main_window.cpp:935 +msgid "" +"%1 are needed in %2 but only %3 are free. If a previous download of these " +"files is already in this folder, it will be resumed and may fit." +msgstr "" +"%1 sont nécessaires dans %2 mais seuls %3 sont libres. Si un téléchargement " +"précédent de ces fichiers se trouve déjà dans ce dossier, il sera repris et " +"pourra tenir." + +#: src/ui-gtk/main_window.cpp:741 src/ui-haiku/main_window.cpp:938 +msgid "Download anyway" +msgstr "Télécharger quand même" + +#: src/ui-gtk/main_window.cpp:763 src/ui-haiku/main_window.cpp:958 +msgid "Downloading" +msgstr "Téléchargement" + +#: src/ui-gtk/main_window.cpp:765 src/ui-haiku/main_window.cpp:954 +msgid "" +"You can close the application: the download will resume where it stopped " +"next time." +msgstr "" +"Vous pouvez fermer l'application : le téléchargement reprendra là où il " +"s'est arrêté." + +#: src/ui-gtk/main_window.cpp:786 src/ui-gtk/main_window.cpp:1014 +#: src/ui-haiku/main_window.cpp:952 src/ui-haiku/main_window.cpp:1168 +msgid "Stop" +msgstr "Arrêter" + +#: src/ui-gtk/main_window.cpp:799 src/ui-gtk/main_window.cpp:849 +#: src/ui-haiku/main_window.cpp:554 src/ui-haiku/main_window.cpp:976 +#: src/ui-haiku/main_window.cpp:1019 +msgid "License" +msgstr "Licence" + +#: src/ui-gtk/main_window.cpp:799 src/ui-haiku/main_window.cpp:976 +msgid "waiting" +msgstr "en attente" + +#: src/ui-gtk/main_window.cpp:812 src/ui-haiku/main_window.cpp:983 +msgid "Connecting…" +msgstr "Connexion…" + +#: src/ui-gtk/main_window.cpp:829 src/ui-haiku/main_window.cpp:999 +msgid "Cannot write the file: %1" +msgstr "Impossible d'écrire le fichier : %1" + +#: src/ui-gtk/main_window.cpp:830 src/ui-haiku/main_window.cpp:1000 +msgid "The download failed: %1" +msgstr "Le téléchargement a échoué : %1" + +#: src/ui-gtk/main_window.cpp:839 src/ui-haiku/main_window.cpp:1009 +msgid "Download interrupted" +msgstr "Téléchargement interrompu" + +#: src/ui-gtk/main_window.cpp:840 src/ui-haiku/main_window.cpp:1010 +msgid "The files already downloaded are kept; start again to resume." +msgstr "" +"Les fichiers déjà téléchargés sont conservés ; relancez pour reprendre." + +#: src/ui-gtk/main_window.cpp:849 src/ui-haiku/main_window.cpp:1019 +msgid "done" +msgstr "terminé" + +#: src/ui-gtk/main_window.cpp:859 src/ui-haiku/main_window.cpp:1027 +msgid "Time left: %1" +msgstr "Temps restant : %1" + +#: src/ui-gtk/main_window.cpp:861 src/ui-haiku/main_window.cpp:1029 +msgid "(connection lost, attempt %1)" +msgstr "(connexion perdue, tentative %1)" + +#: src/ui-gtk/main_window.cpp:886 src/ui-haiku/main_window.cpp:1062 +msgid "Prepare the USB stick" +msgstr "Préparer la clé USB" + +#: src/ui-gtk/main_window.cpp:897 src/ui-gtk/main_window.cpp:970 +#: src/ui-haiku/main_window.cpp:1147 +msgid "This USB stick is too small." +msgstr "Cette clé USB est trop petite." + +#: src/ui-gtk/main_window.cpp:901 src/ui-haiku/main_window.cpp:1066 +msgid "Refresh" +msgstr "Actualiser" + +#: src/ui-gtk/main_window.cpp:910 src/ui-gtk/main_window.cpp:982 +#: src/ui-haiku/main_window.cpp:1057 src/ui-haiku/main_window.cpp:1156 +msgid "Erase and write" +msgstr "Effacer et écrire" + +#: src/ui-gtk/main_window.cpp:920 src/ui-haiku/main_window.cpp:1081 +msgid "Computing the required size…" +msgstr "Calcul de la taille nécessaire…" + +#: src/ui-gtk/main_window.cpp:934 src/ui-gtk/main_window.cpp:1055 +#: src/ui-haiku/main_window.cpp:1095 src/ui-haiku/main_window.cpp:1215 +msgid "A downloaded file is damaged" +msgstr "Un fichier téléchargé est endommagé" + +#: src/ui-gtk/main_window.cpp:934 src/ui-gtk/main_window.cpp:1055 +#: src/ui-haiku/main_window.cpp:1095 src/ui-haiku/main_window.cpp:1215 +msgid "Download the update again." +msgstr "Téléchargez à nouveau la mise à jour." + +#: src/ui-gtk/main_window.cpp:941 src/ui-haiku/main_window.cpp:1102 +msgid "" +"Plug in a USB stick of at least %1. It will be completely erased and " +"formatted (FAT32)." +msgstr "" +"Branchez une clé USB d'au moins %1. Elle sera entièrement effacée et " +"formatée (FAT32)." + +#: src/ui-gtk/main_window.cpp:956 src/ui-haiku/main_window.cpp:1118 +msgid "USB drives cannot be listed: " +msgstr "Impossible de lister les clés USB : " + +#: src/ui-gtk/main_window.cpp:961 src/ui-haiku/main_window.cpp:1126 +msgid "too small" +msgstr "trop petite" + +#: src/ui-gtk/main_window.cpp:964 src/ui-haiku/main_window.cpp:1054 +#: src/ui-haiku/main_window.cpp:1134 +msgid "No USB stick found. Plug one in, then refresh." +msgstr "Aucune clé USB trouvée. Branchez-en une, puis actualisez." + +#: src/ui-gtk/main_window.cpp:980 src/ui-haiku/main_window.cpp:1155 +msgid "Erase %1?" +msgstr "Effacer %1 ?" + +#: src/ui-gtk/main_window.cpp:981 src/ui-haiku/main_window.cpp:1155 +msgid "Everything on this USB stick will be lost." +msgstr "Tout le contenu de cette clé USB sera perdu." + +#: src/ui-gtk/main_window.cpp:1000 src/ui-haiku/main_window.cpp:1173 +msgid "Writing the USB stick" +msgstr "Écriture de la clé USB" + +#: src/ui-gtk/main_window.cpp:1001 src/ui-haiku/main_window.cpp:1174 +msgid "Do not unplug the USB stick." +msgstr "Ne débranchez pas la clé USB." + +#: src/ui-gtk/main_window.cpp:1026 src/ui-gtk/main_window.cpp:1072 +#: src/ui-haiku/main_window.cpp:1188 src/ui-haiku/main_window.cpp:1234 +msgid "Checking the downloaded files…" +msgstr "Vérification des fichiers téléchargés…" + +#: src/ui-gtk/main_window.cpp:1046 src/ui-haiku/main_window.cpp:1206 +msgid "Permission to format the USB stick was refused." +msgstr "L'autorisation de formater la clé USB a été refusée." + +#: src/ui-gtk/main_window.cpp:1061 src/ui-haiku/main_window.cpp:1221 +msgid "The USB stick could not be prepared" +msgstr "La clé USB n'a pas pu être préparée" + +#: src/ui-gtk/main_window.cpp:1074 src/ui-haiku/main_window.cpp:1236 +msgid "Formatting the USB stick…" +msgstr "Formatage de la clé USB…" + +#: src/ui-gtk/main_window.cpp:1077 src/ui-haiku/main_window.cpp:1240 +msgid "Copying the license…" +msgstr "Copie de la licence…" + +#: src/ui-gtk/main_window.cpp:1078 src/ui-haiku/main_window.cpp:1243 +msgid "Copying the update…" +msgstr "Copie de la mise à jour…" + +#: src/ui-gtk/main_window.cpp:1080 src/ui-haiku/main_window.cpp:1245 +msgid "Ejecting the USB stick…" +msgstr "Éjection de la clé USB…" + +#: src/ui-gtk/main_window.cpp:1111 src/ui-haiku/main_window.cpp:1281 +msgid "The USB stick is ready" +msgstr "La clé USB est prête" + +#: src/ui-gtk/main_window.cpp:1113 src/ui-haiku/main_window.cpp:1282 +msgid "" +"You can unplug the USB stick. With the engine running, plug it into the " +"vehicle and follow the instructions on the screen. The installation can take " +"a long time: do not stop the engine." +msgstr "" +"Vous pouvez débrancher la clé USB. Moteur tournant, branchez-la dans le " +"véhicule et suivez les instructions à l'écran. L'installation peut être " +"longue : ne coupez pas le moteur." + +#: src/ui-gtk/main_window.cpp:1126 src/ui-haiku/main_window.cpp:1277 +msgid "Finish" +msgstr "Terminer" + +#: src/ui-haiku/main_window.cpp:387 +msgid "Quit" +msgstr "Quitter" + +#: src/ui-haiku/main_window.cpp:897 +msgid "Select" +msgstr "Sélectionner" diff --git a/po/openpu.pot b/po/openpu.pot index ddae106..c00f1a6 100644 --- a/po/openpu.pot +++ b/po/openpu.pot @@ -1,401 +1,450 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the openpu package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy msgid "" msgstr "" "Project-Id-Version: openpu\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-11-29 05:53+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: src\ui-gtk\main_window.cpp:54 +#: src/ui-gtk/main_window.cpp:54 src/ui-haiku/main_window.cpp:185 msgid "Crony (navigation)" msgstr "" -#: src\ui-gtk\main_window.cpp:55 +#: src/ui-gtk/main_window.cpp:55 src/ui-haiku/main_window.cpp:186 msgid "Crony (no navigation)" msgstr "" -#: src\ui-gtk\main_window.cpp:58 +#: src/ui-gtk/main_window.cpp:58 src/ui-haiku/main_window.cpp:189 msgid "unknown head unit" msgstr "" -#: src\ui-gtk\main_window.cpp:63 -#, qt-format +#: src/ui-gtk/main_window.cpp:63 src/ui-haiku/main_window.cpp:194 msgid "version %1, %2" msgstr "" -#: src\ui-gtk\main_window.cpp:70 +#: src/ui-gtk/main_window.cpp:70 src/ui-haiku/main_window.cpp:200 msgid "The update server cannot be reached. Check your Internet connection." msgstr "" -#: src\ui-gtk\main_window.cpp:73 +#: src/ui-gtk/main_window.cpp:73 src/ui-haiku/main_window.cpp:202 msgid "The update server returned an error. Try again later." msgstr "" -#: src\ui-gtk\main_window.cpp:75 +#: src/ui-gtk/main_window.cpp:75 src/ui-haiku/main_window.cpp:203 msgid "This VIN is not valid." msgstr "" -#: src\ui-gtk\main_window.cpp:104 +#: src/ui-gtk/main_window.cpp:104 src/ui-haiku/main_window.cpp:407 msgid "Your saved data cannot be read" msgstr "" -#: src\ui-gtk\main_window.cpp:109 +#: src/ui-gtk/main_window.cpp:109 src/ui-haiku/main_window.cpp:720 +#: src/ui-haiku/main_window.cpp:807 src/ui-haiku/main_window.cpp:1071 msgid "Back" msgstr "" -#: src\ui-gtk\main_window.cpp:113 src\ui-gtk\main_window.cpp:219 +#: src/ui-gtk/main_window.cpp:113 src/ui-gtk/main_window.cpp:219 +#: src/ui-haiku/main_window.cpp:279 src/ui-haiku/main_window.cpp:384 msgid "Preferences" msgstr "" -#: src\ui-gtk\main_window.cpp:114 +#: src/ui-gtk/main_window.cpp:114 src/ui-haiku/main_window.cpp:385 msgid "Check for a new version of OpenPU" msgstr "" -#: src\ui-gtk\main_window.cpp:115 +#: src/ui-gtk/main_window.cpp:115 src/ui-haiku/main_window.cpp:382 msgid "About OpenPU" msgstr "" -#: src\ui-gtk\main_window.cpp:118 +#: src/ui-gtk/main_window.cpp:118 msgid "Menu" msgstr "" -#: src\ui-gtk\main_window.cpp:181 +#: src/ui-gtk/main_window.cpp:181 src/ui-haiku/main_window.cpp:509 msgid "OpenPU is up to date" msgstr "" -#: src\ui-gtk\main_window.cpp:182 -#, qt-format +#: src/ui-gtk/main_window.cpp:182 src/ui-haiku/main_window.cpp:509 msgid "Version %1 is the latest version." msgstr "" -#: src\ui-gtk\main_window.cpp:185 +#: src/ui-gtk/main_window.cpp:185 src/ui-haiku/main_window.cpp:513 msgid "Cannot check for a new version" msgstr "" -#: src\ui-gtk\main_window.cpp:195 -#, qt-format +#: src/ui-gtk/main_window.cpp:195 src/ui-haiku/main_window.cpp:526 msgid "OpenPU %1 is available" msgstr "" -#: src\ui-gtk\main_window.cpp:197 -#, qt-format +#: src/ui-gtk/main_window.cpp:197 src/ui-haiku/main_window.cpp:523 msgid "You are using version %1. Do you want to download the new version?" msgstr "" -#: src\ui-gtk\main_window.cpp:201 +#: src/ui-gtk/main_window.cpp:201 src/ui-haiku/main_window.cpp:526 msgid "Later" msgstr "" -#: src\ui-gtk\main_window.cpp:201 src\ui-gtk\main_window.cpp:625 +#: src/ui-gtk/main_window.cpp:201 src/ui-gtk/main_window.cpp:625 +#: src/ui-haiku/main_window.cpp:527 src/ui-haiku/main_window.cpp:790 msgid "Download" msgstr "" -#: src\ui-gtk\main_window.cpp:231 src\ui-gtk\main_window.cpp:705 +#: src/ui-gtk/main_window.cpp:231 src/ui-gtk/main_window.cpp:705 +#: src/ui-haiku/main_window.cpp:308 src/ui-haiku/main_window.cpp:898 msgid "Download folder" msgstr "" -#: src\ui-gtk\main_window.cpp:238 src\ui-gtk\main_window.cpp:608 +#: src/ui-gtk/main_window.cpp:238 src/ui-gtk/main_window.cpp:608 +#: src/ui-haiku/main_window.cpp:310 src/ui-haiku/main_window.cpp:803 msgid "Change…" msgstr "" -#: src\ui-gtk\main_window.cpp:247 +#: src/ui-gtk/main_window.cpp:247 src/ui-haiku/main_window.cpp:297 msgid "Language" msgstr "" -#: src\ui-gtk\main_window.cpp:252 +#: src/ui-gtk/main_window.cpp:252 src/ui-haiku/main_window.cpp:293 msgid "System language" msgstr "" -#: src\ui-gtk\main_window.cpp:258 +#: src/ui-gtk/main_window.cpp:258 src/ui-haiku/main_window.cpp:298 msgid "The new language is used the next time OpenPU starts." msgstr "" -#: src\ui-gtk\main_window.cpp:271 src\ui-gtk\main_window.cpp:286 src\ui-gtk\main_window.cpp:718 +#: src/ui-gtk/main_window.cpp:271 src/ui-gtk/main_window.cpp:286 +#: src/ui-gtk/main_window.cpp:718 src/ui-haiku/main_window.cpp:565 msgid "Cannot save the settings" msgstr "" -#: src\ui-gtk\main_window.cpp:279 +#: src/ui-gtk/main_window.cpp:279 src/ui-haiku/main_window.cpp:301 msgid "Check for a new version of OpenPU at startup" msgstr "" -#: src\ui-gtk\main_window.cpp:338 -msgid "Download Peugeot head unit updates (system and navigation map) and prepare the USB stick, on Linux and Haiku.\n\nIndependent project, not affiliated with Stellantis or Peugeot." +#: src/ui-gtk/main_window.cpp:338 src/ui-haiku/main_window.cpp:548 +msgid "" +"Download Peugeot head unit updates (system and navigation map) and prepare " +"the USB stick, on Linux and Haiku.\n" +"\n" +"Independent project, not affiliated with Stellantis or Peugeot." msgstr "" -#: src\ui-gtk\main_window.cpp:344 +#: src/ui-gtk/main_window.cpp:344 src/ui-haiku/main_window.cpp:556 msgid "Source code" msgstr "" -#: src\ui-gtk\main_window.cpp:356 +#: src/ui-gtk/main_window.cpp:356 src/ui-haiku/main_window.cpp:574 msgid "Cannot save the vehicle list" msgstr "" -#: src\ui-gtk\main_window.cpp:370 +#: src/ui-gtk/main_window.cpp:370 src/ui-haiku/main_window.cpp:635 msgid "My vehicles" msgstr "" -#: src\ui-gtk\main_window.cpp:372 -msgid "Add your vehicle with its VIN (17 characters, on the registration document, field E)." +#: src/ui-gtk/main_window.cpp:372 src/ui-haiku/main_window.cpp:623 +msgid "" +"Add your vehicle with its VIN (17 characters, on the registration document, " +"field E)." msgstr "" -#: src\ui-gtk\main_window.cpp:392 src\ui-gtk\main_window.cpp:486 +#: src/ui-gtk/main_window.cpp:392 src/ui-gtk/main_window.cpp:486 +#: src/ui-haiku/main_window.cpp:640 src/ui-haiku/main_window.cpp:710 msgid "Add a vehicle" msgstr "" -#: src\ui-gtk\main_window.cpp:393 src\ui-gtk\main_window.cpp:457 +#: src/ui-gtk/main_window.cpp:393 src/ui-gtk/main_window.cpp:457 +#: src/ui-haiku/main_window.cpp:629 src/ui-haiku/main_window.cpp:683 msgid "Remove" msgstr "" -#: src\ui-gtk\main_window.cpp:394 +#: src/ui-gtk/main_window.cpp:394 src/ui-haiku/main_window.cpp:630 msgid "Check for updates" msgstr "" -#: src\ui-gtk\main_window.cpp:425 +#: src/ui-gtk/main_window.cpp:425 src/ui-haiku/main_window.cpp:655 msgid "download not finished" msgstr "" -#: src\ui-gtk\main_window.cpp:455 -#, qt-format +#: src/ui-gtk/main_window.cpp:455 src/ui-haiku/main_window.cpp:682 msgid "Remove %1?" msgstr "" -#: src\ui-gtk\main_window.cpp:456 -msgid "Downloaded files that were not written to a USB stick yet are deleted too." +#: src/ui-gtk/main_window.cpp:456 src/ui-haiku/main_window.cpp:683 +msgid "" +"Downloaded files that were not written to a USB stick yet are deleted too." msgstr "" -#: src\ui-gtk\main_window.cpp:457 src\ui-gtk\main_window.cpp:741 src\ui-gtk\main_window.cpp:982 +#: src/ui-gtk/main_window.cpp:457 src/ui-gtk/main_window.cpp:741 +#: src/ui-gtk/main_window.cpp:982 src/ui-haiku/main_window.cpp:683 +#: src/ui-haiku/main_window.cpp:938 src/ui-haiku/main_window.cpp:1156 msgid "Cancel" msgstr "" -#: src\ui-gtk\main_window.cpp:488 -msgid "The VIN (vehicle identification number) is written in field E of the registration document and at the bottom of the windscreen." +#: src/ui-gtk/main_window.cpp:488 src/ui-haiku/main_window.cpp:711 +msgid "" +"The VIN (vehicle identification number) is written in field E of the " +"registration document and at the bottom of the windscreen." msgstr "" -#: src\ui-gtk\main_window.cpp:496 +#: src/ui-gtk/main_window.cpp:496 src/ui-haiku/main_window.cpp:699 msgid "VIN" msgstr "" -#: src\ui-gtk\main_window.cpp:498 +#: src/ui-gtk/main_window.cpp:498 src/ui-haiku/main_window.cpp:702 msgid "Name" msgstr "" -#: src\ui-gtk\main_window.cpp:503 +#: src/ui-gtk/main_window.cpp:503 msgid "e.g. 208 or Family car" msgstr "" -#: src\ui-gtk\main_window.cpp:517 +#: src/ui-gtk/main_window.cpp:517 src/ui-haiku/main_window.cpp:704 msgid "Add" msgstr "" -#: src\ui-gtk\main_window.cpp:535 +#: src/ui-gtk/main_window.cpp:535 src/ui-haiku/main_window.cpp:732 msgid "A VIN has 17 characters and starts with VF3 or VR3." msgstr "" -#: src\ui-gtk\main_window.cpp:541 +#: src/ui-gtk/main_window.cpp:541 src/ui-haiku/main_window.cpp:737 msgid "Checking the vehicle…" msgstr "" -#: src\ui-gtk\main_window.cpp:558 +#: src/ui-gtk/main_window.cpp:558 src/ui-haiku/main_window.cpp:753 msgid "This vehicle is unknown to the update service." msgstr "" -#: src\ui-gtk\main_window.cpp:562 +#: src/ui-gtk/main_window.cpp:562 src/ui-haiku/main_window.cpp:757 msgid "This vehicle has no head unit that can be updated with a USB stick." msgstr "" -#: src\ui-gtk\main_window.cpp:604 +#: src/ui-gtk/main_window.cpp:604 src/ui-haiku/main_window.cpp:801 msgid "Download folder:" msgstr "" -#: src\ui-gtk\main_window.cpp:617 src\ui-gtk\main_window.cpp:1118 +#: src/ui-gtk/main_window.cpp:617 src/ui-gtk/main_window.cpp:1118 +#: src/ui-haiku/main_window.cpp:789 src/ui-haiku/main_window.cpp:1287 msgid "Installation guide" msgstr "" -#: src\ui-gtk\main_window.cpp:651 +#: src/ui-gtk/main_window.cpp:651 src/ui-haiku/main_window.cpp:835 msgid "Looking for updates…" msgstr "" -#: src\ui-gtk\main_window.cpp:685 +#: src/ui-gtk/main_window.cpp:685 src/ui-haiku/main_window.cpp:867 msgid "No update is available: your head unit is up to date." msgstr "" -#: src\ui-gtk\main_window.cpp:688 +#: src/ui-gtk/main_window.cpp:688 src/ui-haiku/main_window.cpp:870 msgid "Select the updates to download:" msgstr "" -#: src\ui-gtk\main_window.cpp:690 src\ui-gtk\main_window.cpp:803 +#: src/ui-gtk/main_window.cpp:690 src/ui-gtk/main_window.cpp:803 +#: src/ui-haiku/main_window.cpp:872 src/ui-haiku/main_window.cpp:979 msgid "System (firmware)" msgstr "" -#: src\ui-gtk\main_window.cpp:695 src\ui-gtk\main_window.cpp:807 +#: src/ui-gtk/main_window.cpp:695 src/ui-gtk/main_window.cpp:807 +#: src/ui-haiku/main_window.cpp:877 src/ui-haiku/main_window.cpp:982 msgid "Navigation map" msgstr "" -#: src\ui-gtk\main_window.cpp:736 +#: src/ui-gtk/main_window.cpp:736 src/ui-haiku/main_window.cpp:938 msgid "Not enough free space" msgstr "" -#: src\ui-gtk\main_window.cpp:738 -#, qt-format -msgid "%1 are needed in %2 but only %3 are free. If a previous download of these files is already in this folder, it will be resumed and may fit." +#: src/ui-gtk/main_window.cpp:738 src/ui-haiku/main_window.cpp:935 +msgid "" +"%1 are needed in %2 but only %3 are free. If a previous download of these " +"files is already in this folder, it will be resumed and may fit." msgstr "" -#: src\ui-gtk\main_window.cpp:741 +#: src/ui-gtk/main_window.cpp:741 src/ui-haiku/main_window.cpp:938 msgid "Download anyway" msgstr "" -#: src\ui-gtk\main_window.cpp:763 +#: src/ui-gtk/main_window.cpp:763 src/ui-haiku/main_window.cpp:958 msgid "Downloading" msgstr "" -#: src\ui-gtk\main_window.cpp:765 -msgid "You can close the application: the download will resume where it stopped next time." +#: src/ui-gtk/main_window.cpp:765 src/ui-haiku/main_window.cpp:954 +msgid "" +"You can close the application: the download will resume where it stopped " +"next time." msgstr "" -#: src\ui-gtk\main_window.cpp:786 src\ui-gtk\main_window.cpp:1014 +#: src/ui-gtk/main_window.cpp:786 src/ui-gtk/main_window.cpp:1014 +#: src/ui-haiku/main_window.cpp:952 src/ui-haiku/main_window.cpp:1168 msgid "Stop" msgstr "" -#: src\ui-gtk\main_window.cpp:799 src\ui-gtk\main_window.cpp:849 +#: src/ui-gtk/main_window.cpp:799 src/ui-gtk/main_window.cpp:849 +#: src/ui-haiku/main_window.cpp:554 src/ui-haiku/main_window.cpp:976 +#: src/ui-haiku/main_window.cpp:1019 msgid "License" msgstr "" -#: src\ui-gtk\main_window.cpp:799 +#: src/ui-gtk/main_window.cpp:799 src/ui-haiku/main_window.cpp:976 msgid "waiting" msgstr "" -#: src\ui-gtk\main_window.cpp:812 +#: src/ui-gtk/main_window.cpp:812 src/ui-haiku/main_window.cpp:983 msgid "Connecting…" msgstr "" -#: src\ui-gtk\main_window.cpp:829 -#, qt-format +#: src/ui-gtk/main_window.cpp:829 src/ui-haiku/main_window.cpp:999 msgid "Cannot write the file: %1" msgstr "" -#: src\ui-gtk\main_window.cpp:830 -#, qt-format +#: src/ui-gtk/main_window.cpp:830 src/ui-haiku/main_window.cpp:1000 msgid "The download failed: %1" msgstr "" -#: src\ui-gtk\main_window.cpp:839 +#: src/ui-gtk/main_window.cpp:839 src/ui-haiku/main_window.cpp:1009 msgid "Download interrupted" msgstr "" -#: src\ui-gtk\main_window.cpp:840 +#: src/ui-gtk/main_window.cpp:840 src/ui-haiku/main_window.cpp:1010 msgid "The files already downloaded are kept; start again to resume." msgstr "" -#: src\ui-gtk\main_window.cpp:849 +#: src/ui-gtk/main_window.cpp:849 src/ui-haiku/main_window.cpp:1019 msgid "done" msgstr "" -#: src\ui-gtk\main_window.cpp:859 -#, qt-format +#: src/ui-gtk/main_window.cpp:859 src/ui-haiku/main_window.cpp:1027 msgid "Time left: %1" msgstr "" -#: src\ui-gtk\main_window.cpp:861 -#, qt-format +#: src/ui-gtk/main_window.cpp:861 src/ui-haiku/main_window.cpp:1029 msgid "(connection lost, attempt %1)" msgstr "" -#: src\ui-gtk\main_window.cpp:886 +#: src/ui-gtk/main_window.cpp:886 src/ui-haiku/main_window.cpp:1062 msgid "Prepare the USB stick" msgstr "" -#: src\ui-gtk\main_window.cpp:897 src\ui-gtk\main_window.cpp:970 +#: src/ui-gtk/main_window.cpp:897 src/ui-gtk/main_window.cpp:970 +#: src/ui-haiku/main_window.cpp:1147 msgid "This USB stick is too small." msgstr "" -#: src\ui-gtk\main_window.cpp:901 +#: src/ui-gtk/main_window.cpp:901 src/ui-haiku/main_window.cpp:1066 msgid "Refresh" msgstr "" -#: src\ui-gtk\main_window.cpp:910 src\ui-gtk\main_window.cpp:982 +#: src/ui-gtk/main_window.cpp:910 src/ui-gtk/main_window.cpp:982 +#: src/ui-haiku/main_window.cpp:1057 src/ui-haiku/main_window.cpp:1156 msgid "Erase and write" msgstr "" -#: src\ui-gtk\main_window.cpp:920 +#: src/ui-gtk/main_window.cpp:920 src/ui-haiku/main_window.cpp:1081 msgid "Computing the required size…" msgstr "" -#: src\ui-gtk\main_window.cpp:934 src\ui-gtk\main_window.cpp:1055 +#: src/ui-gtk/main_window.cpp:934 src/ui-gtk/main_window.cpp:1055 +#: src/ui-haiku/main_window.cpp:1095 src/ui-haiku/main_window.cpp:1215 msgid "A downloaded file is damaged" msgstr "" -#: src\ui-gtk\main_window.cpp:934 src\ui-gtk\main_window.cpp:1055 +#: src/ui-gtk/main_window.cpp:934 src/ui-gtk/main_window.cpp:1055 +#: src/ui-haiku/main_window.cpp:1095 src/ui-haiku/main_window.cpp:1215 msgid "Download the update again." msgstr "" -#: src\ui-gtk\main_window.cpp:941 -#, qt-format -msgid "Plug in a USB stick of at least %1. It will be completely erased and formatted (FAT32)." +#: src/ui-gtk/main_window.cpp:941 src/ui-haiku/main_window.cpp:1102 +msgid "" +"Plug in a USB stick of at least %1. It will be completely erased and " +"formatted (FAT32)." msgstr "" -#: src\ui-gtk\main_window.cpp:956 +#: src/ui-gtk/main_window.cpp:956 src/ui-haiku/main_window.cpp:1118 msgid "USB drives cannot be listed: " msgstr "" -#: src\ui-gtk\main_window.cpp:961 +#: src/ui-gtk/main_window.cpp:961 src/ui-haiku/main_window.cpp:1126 msgid "too small" msgstr "" -#: src\ui-gtk\main_window.cpp:964 +#: src/ui-gtk/main_window.cpp:964 src/ui-haiku/main_window.cpp:1054 +#: src/ui-haiku/main_window.cpp:1134 msgid "No USB stick found. Plug one in, then refresh." msgstr "" -#: src\ui-gtk\main_window.cpp:980 -#, qt-format +#: src/ui-gtk/main_window.cpp:980 src/ui-haiku/main_window.cpp:1155 msgid "Erase %1?" msgstr "" -#: src\ui-gtk\main_window.cpp:981 +#: src/ui-gtk/main_window.cpp:981 src/ui-haiku/main_window.cpp:1155 msgid "Everything on this USB stick will be lost." msgstr "" -#: src\ui-gtk\main_window.cpp:1000 +#: src/ui-gtk/main_window.cpp:1000 src/ui-haiku/main_window.cpp:1173 msgid "Writing the USB stick" msgstr "" -#: src\ui-gtk\main_window.cpp:1001 +#: src/ui-gtk/main_window.cpp:1001 src/ui-haiku/main_window.cpp:1174 msgid "Do not unplug the USB stick." msgstr "" -#: src\ui-gtk\main_window.cpp:1026 src\ui-gtk\main_window.cpp:1072 +#: src/ui-gtk/main_window.cpp:1026 src/ui-gtk/main_window.cpp:1072 +#: src/ui-haiku/main_window.cpp:1188 src/ui-haiku/main_window.cpp:1234 msgid "Checking the downloaded files…" msgstr "" -#: src\ui-gtk\main_window.cpp:1046 +#: src/ui-gtk/main_window.cpp:1046 src/ui-haiku/main_window.cpp:1206 msgid "Permission to format the USB stick was refused." msgstr "" -#: src\ui-gtk\main_window.cpp:1061 +#: src/ui-gtk/main_window.cpp:1061 src/ui-haiku/main_window.cpp:1221 msgid "The USB stick could not be prepared" msgstr "" -#: src\ui-gtk\main_window.cpp:1074 +#: src/ui-gtk/main_window.cpp:1074 src/ui-haiku/main_window.cpp:1236 msgid "Formatting the USB stick…" msgstr "" -#: src\ui-gtk\main_window.cpp:1077 +#: src/ui-gtk/main_window.cpp:1077 src/ui-haiku/main_window.cpp:1240 msgid "Copying the license…" msgstr "" -#: src\ui-gtk\main_window.cpp:1078 +#: src/ui-gtk/main_window.cpp:1078 src/ui-haiku/main_window.cpp:1243 msgid "Copying the update…" msgstr "" -#: src\ui-gtk\main_window.cpp:1080 +#: src/ui-gtk/main_window.cpp:1080 src/ui-haiku/main_window.cpp:1245 msgid "Ejecting the USB stick…" msgstr "" -#: src\ui-gtk\main_window.cpp:1111 +#: src/ui-gtk/main_window.cpp:1111 src/ui-haiku/main_window.cpp:1281 msgid "The USB stick is ready" msgstr "" -#: src\ui-gtk\main_window.cpp:1113 -msgid "You can unplug the USB stick. With the engine running, plug it into the vehicle and follow the instructions on the screen. The installation can take a long time: do not stop the engine." +#: src/ui-gtk/main_window.cpp:1113 src/ui-haiku/main_window.cpp:1282 +msgid "" +"You can unplug the USB stick. With the engine running, plug it into the " +"vehicle and follow the instructions on the screen. The installation can take " +"a long time: do not stop the engine." msgstr "" -#: src\ui-gtk\main_window.cpp:1126 +#: src/ui-gtk/main_window.cpp:1126 src/ui-haiku/main_window.cpp:1277 msgid "Finish" msgstr "" + +#: src/ui-haiku/main_window.cpp:387 +msgid "Quit" +msgstr "" + +#: src/ui-haiku/main_window.cpp:897 +msgid "Select" +msgstr "" diff --git a/src/ui-haiku/CMakeLists.txt b/src/ui-haiku/CMakeLists.txt new file mode 100644 index 0000000..df8fb6f --- /dev/null +++ b/src/ui-haiku/CMakeLists.txt @@ -0,0 +1,32 @@ +include(GNUInstallDirs) + +add_executable(OpenPU + main.cpp + main_window.cpp +) +find_library(INTL_LIBRARY intl) +target_link_libraries(OpenPU PRIVATE openpu_core openpu_warnings be tracker shared + $<$:${INTL_LIBRARY}>) +target_compile_definitions(OpenPU PRIVATE + GETTEXT_PACKAGE="openpu" + OPENPU_LOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}") +# BeAPI headers trigger -Wshadow/-Wconversion noise we cannot fix. +target_compile_options(OpenPU PRIVATE -Wno-shadow -Wno-conversion) + +# Application resources: signature, version, flags (Haiku rc + xres). +configure_file(OpenPU.rdef.in ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rdef @ONLY) +find_program(HAIKU_RC rc) +find_program(HAIKU_XRES xres) +find_program(HAIKU_MIMESET mimeset) +if(HAIKU_RC AND HAIKU_XRES) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc + COMMAND ${HAIKU_RC} -o ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rdef + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rdef) + add_custom_target(OpenPU_rsrc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc) + add_dependencies(OpenPU OpenPU_rsrc) + add_custom_command(TARGET OpenPU POST_BUILD + COMMAND ${HAIKU_XRES} -o $ ${CMAKE_CURRENT_BINARY_DIR}/OpenPU.rsrc + COMMAND ${HAIKU_MIMESET} -f $) +endif() + +install(TARGETS OpenPU RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/ui-haiku/OpenPU.rdef.in b/src/ui-haiku/OpenPU.rdef.in new file mode 100644 index 0000000..f595d4a --- /dev/null +++ b/src/ui-haiku/OpenPU.rdef.in @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: MIT */ + +resource app_signature "application/x-vnd.openpu-OpenPU"; + +resource app_flags B_SINGLE_LAUNCH; + +resource app_version { + major = @PROJECT_VERSION_MAJOR@, + middle = @PROJECT_VERSION_MINOR@, + minor = @PROJECT_VERSION_PATCH@, + variety = B_APPV_FINAL, + internal = 0, + short_info = "OpenPU @PROJECT_VERSION@", + long_info = "OpenPU @PROJECT_VERSION@ - Peugeot head unit updates on a USB stick. MIT license." +}; diff --git a/src/ui-haiku/i18n.hpp b/src/ui-haiku/i18n.hpp new file mode 100644 index 0000000..52fbf15 --- /dev/null +++ b/src/ui-haiku/i18n.hpp @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +#pragma once + +// gettext, with the same message catalogs as the GTK interface (po/). +#include + +#include +#include + +#define _(text) gettext(text) + +namespace openpu::haiku { + +/// Replaces %1..%9 in `format` (same placeholders as Glib::ustring::compose, so the translations +/// are shared with the GTK interface). +inline std::string compose(const std::string& format, std::initializer_list args) +{ + std::string out; + out.reserve(format.size()); + for (std::size_t i = 0; i < format.size(); ++i) { + const char c = format[i]; + if (c == '%' && i + 1 < format.size() && format[i + 1] >= '1' && format[i + 1] <= '9') { + const auto index = static_cast(format[i + 1] - '1'); + if (index < args.size()) + out += *(args.begin() + index); + ++i; + continue; + } + out.push_back(c); + } + return out; +} + +} // namespace openpu::haiku diff --git a/src/ui-haiku/main.cpp b/src/ui-haiku/main.cpp new file mode 100644 index 0000000..53a75e9 --- /dev/null +++ b/src/ui-haiku/main.cpp @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: MIT +#include "main_window.hpp" + +#include "openpu/storage.hpp" + +#include +#include +#include + +#include "i18n.hpp" + +#include +#include +#include +#include + +namespace { + +constexpr const char* kSignature = "application/x-vnd.openpu-OpenPU"; + +/// First preferred language of the Locale preferences ("fr", "en_US"...), empty if unknown. +std::string preferredLanguage() +{ + BMessage languages; + if (BLocaleRoster::Default()->GetPreferredLanguages(&languages) != B_OK) + return {}; + const char* language = nullptr; + if (languages.FindString("language", 0, &language) != B_OK || language == nullptr) + return {}; + return language; +} + +class App : public BApplication { +public: + explicit App(std::string language) : BApplication(kSignature), language_(std::move(language)) {} + + void ReadyToRun() override { (new openpu::haiku::MainWindow(language_))->Show(); } + +private: + std::string language_; +}; + +} // namespace + +int main() +{ + // A language chosen in the settings overrides the one of the Locale preferences. + std::string language; + try { + language = openpu::Settings::load(openpu::paths::configDir() / "config.json").language; + } catch (const openpu::StorageError&) { + // dismissed: the window reports unreadable settings itself + } + if (language.empty()) + language = preferredLanguage(); + if (language.empty()) + language = "en"; + + // gettext follows LANGUAGE, but only when the message locale is not "C". + (void)setenv("LANGUAGE", language.c_str(), 1); // NOLINT(concurrency-mt-unsafe): no thread yet + (void)setenv("LC_MESSAGES", "en_US.UTF-8", 0); // NOLINT(concurrency-mt-unsafe) + (void)std::setlocale(LC_ALL, ""); // NOLINT(concurrency-mt-unsafe) + const char* localeDir = std::getenv("OPENPU_LOCALEDIR"); // NOLINT(concurrency-mt-unsafe): build tree + bindtextdomain(GETTEXT_PACKAGE, localeDir != nullptr ? localeDir : OPENPU_LOCALEDIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + + std::string twoLetters; + for (char c : language.substr(0, 2)) + twoLetters.push_back(static_cast(std::tolower(static_cast(c)))); + + App app(twoLetters); + app.Run(); + return 0; +} diff --git a/src/ui-haiku/main_window.cpp b/src/ui-haiku/main_window.cpp new file mode 100644 index 0000000..9046361 --- /dev/null +++ b/src/ui-haiku/main_window.cpp @@ -0,0 +1,1294 @@ +// SPDX-License-Identifier: MIT +#include "main_window.hpp" + +#include "openpu/archive.hpp" +#include "openpu/format.hpp" +#include "openpu/version.hpp" +#include "openpu/vin.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "i18n.hpp" // after the BeAPI headers: defines _() + +#include +#include +#include + +namespace openpu::haiku { + +namespace fs = std::filesystem; + +namespace { + +constexpr const char* kSignature = "application/x-vnd.openpu-OpenPU"; + +enum : uint32 { + kMsgAddVehicle = 'addv', + kMsgRemoveVehicle = 'remv', + kMsgCheckUpdates = 'chku', + kMsgVehicleSelected = 'vsel', + kMsgBack = 'back', + kMsgAddConfirm = 'addc', + kMsgVinChanged = 'vinc', + kMsgVinEntered = 'vine', + kMsgUpdateToggled = 'uptg', + kMsgDownload = 'dnld', + kMsgGuide = 'guid', + kMsgStop = 'stop', + kMsgDriveSelected = 'drvs', + kMsgRefreshDrives = 'drvr', + kMsgPrepare = 'prep', + kMsgFinish = 'fini', + kMsgFolderChosen = 'fdok', + kMsgAbout = 'abou', + kMsgPreferences = 'pref', + kMsgCheckAppUpdate = 'chka', + kMsgActivate = 'actv', ///< preferences window: bring it to the front +}; + +// --- small widget helpers ------------------------------------------------------------------------ + +BStringView* heading(const std::string& text) +{ + auto* view = new BStringView(nullptr, text.c_str()); + BFont font(be_bold_font); + font.SetSize(font.Size() * 1.4F); + view->SetFont(&font); + view->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + return view; +} + +/// Read-only, word-wrapped text with the panel background (BStringView does not wrap). +/// Never taller than its text, so that the glue of the page takes the spare space. +class ProseView : public BTextView { +public: + ProseView() : BTextView(static_cast(nullptr)) {} + + void GetHeightForWidth(float width, float* min, float* max, float* preferred) override + { + float minHeight = 0; + float preferredHeight = 0; + BTextView::GetHeightForWidth(width, &minHeight, nullptr, &preferredHeight); + const float height = std::max(minHeight, preferredHeight); + if (min != nullptr) + *min = height; + if (max != nullptr) + *max = height; + if (preferred != nullptr) + *preferred = height; + } +}; + +BTextView* prose(const std::string& text = {}) +{ + auto* view = new ProseView(); + view->MakeEditable(false); + view->MakeSelectable(false); + view->SetWordWrap(true); + view->SetStylable(false); + view->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); + view->SetLowUIColor(B_PANEL_BACKGROUND_COLOR); + const rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR); + view->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor); + view->SetText(text.c_str()); + view->SetExplicitMinSize(BSize(360, B_SIZE_UNSET)); + return view; +} + +void setText(BTextView* view, const std::string& text) +{ + view->SetText(text.c_str()); + view->InvalidateLayout(); +} + +void setVisible(BView* view, bool visible) +{ + if (view->IsHidden(view) == !visible) + return; + if (visible) + view->Show(); + else + view->Hide(); +} + +BStringView* label(const std::string& text = {}) +{ + auto* view = new BStringView(nullptr, text.c_str()); + view->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + return view; +} + +BButton* button(const std::string& text, uint32 what) +{ + return new BButton(nullptr, text.c_str(), new BMessage(what)); +} + +/// Text with a bold first paragraph (the title), as in the Haiku alerts of the system applications. +BAlert* makeAlert(const std::string& title, const std::string& detail, const char* b0, const char* b1 = nullptr, + alert_type type = B_INFO_ALERT) +{ + const std::string text = detail.empty() ? title : title + "\n\n" + detail; + auto* alert = new BAlert("OpenPU", text.c_str(), b0, b1, nullptr, B_WIDTH_AS_USUAL, B_EVEN_SPACING, type); + BTextView* view = alert->TextView(); + view->SetStylable(true); + view->SetFontAndColor(0, static_cast(title.size()), be_bold_font); + alert->SetShortcut(0, B_ESCAPE); + return alert; +} + +/// Synchronous question: 0 for the first (cancel) button, 1 for the second one. +int32 ask(const std::string& title, const std::string& detail, const char* cancel, const char* ok, + bool destructive = false) +{ + BAlert* alert = makeAlert(title, detail, cancel, ok, destructive ? B_WARNING_ALERT : B_INFO_ALERT); + if (destructive) + alert->SetDefaultButton(alert->ButtonAt(0)); // Enter must not erase anything + return alert->Go(); +} + +void openUrl(const std::string& url) +{ + if (!url.empty()) + (void)BUrl(url.c_str(), false).OpenWithPreferredApplication(false); +} + +std::string headUnitText(const Vehicle& v) +{ + switch (v.type) { + case HeadUnitType::Nac: return "NAC"; + case HeadUnitType::Rcc: return "RCC"; + case HeadUnitType::Aio: return "AIO"; + case HeadUnitType::CronyNav: return _("Crony (navigation)"); + case HeadUnitType::CronyNonav: return _("Crony (no navigation)"); + case HeadUnitType::Unknown: break; + } + return _("unknown head unit"); +} + +std::string updateText(const UpdateInfo& u) +{ + return compose(_("version %1, %2"), {u.version, formatSize(u.size)}); +} + +std::string apiErrorText(const ApiError& e) +{ + switch (e.kind()) { + case ApiError::Kind::Network: return _("The update server cannot be reached. Check your Internet connection."); + case ApiError::Kind::Server: + case ApiError::Kind::BadResponse: return _("The update server returned an error. Try again later."); + case ApiError::Kind::InvalidVin: return _("This VIN is not valid."); + } + return e.what(); +} + +bool hasPendingFiles(const Vehicle& v) +{ + return !v.pendingFirmware.empty() || !v.pendingMap.empty(); +} + +float percent(std::uint64_t done, std::uint64_t total) +{ + return total > 0 ? static_cast(static_cast(done) * 100.0 / static_cast(total)) : 0.0F; +} + +// --- vehicle list item --------------------------------------------------------------------------- + +class VehicleItem : public BListItem { +public: + VehicleItem(std::string title, std::string detail) : title_(std::move(title)), detail_(std::move(detail)) {} + + void DrawItem(BView* owner, BRect frame, bool /*complete*/) override + { + const rgb_color background = + ui_color(IsSelected() ? B_LIST_SELECTED_BACKGROUND_COLOR : B_LIST_BACKGROUND_COLOR); + const rgb_color text = ui_color(IsSelected() ? B_LIST_SELECTED_ITEM_TEXT_COLOR : B_LIST_ITEM_TEXT_COLOR); + owner->SetLowColor(background); + owner->FillRect(frame, B_SOLID_LOW); + + const float padding = be_control_look->DefaultLabelSpacing(); + font_height bold{}; + be_bold_font->GetHeight(&bold); + font_height plain{}; + be_plain_font->GetHeight(&plain); + + owner->SetDrawingMode(B_OP_OVER); + owner->SetHighColor(text); + owner->SetFont(be_bold_font); + float y = frame.top + padding + bold.ascent; + owner->DrawString(title_.c_str(), BPoint(frame.left + padding, y)); + owner->SetFont(be_plain_font); + owner->SetHighColor(blend_color(text, background, 160)); // dimmed second line + y += bold.descent + bold.leading + plain.ascent + 2; + owner->DrawString(detail_.c_str(), BPoint(frame.left + padding, y)); + owner->SetDrawingMode(B_OP_COPY); + } + + void Update(BView* owner, const BFont* font) override + { + BListItem::Update(owner, font); + font_height bold{}; + be_bold_font->GetHeight(&bold); + font_height plain{}; + be_plain_font->GetHeight(&plain); + const float padding = be_control_look->DefaultLabelSpacing(); + SetHeight(bold.ascent + bold.descent + bold.leading + plain.ascent + plain.descent + 2 + 2 * padding); + } + +private: + std::string title_; + std::string detail_; +}; + +// --- preferences window -------------------------------------------------------------------------- + +/// Language names are written in their own language, on purpose. +const std::vector>& languages() +{ + static const std::vector> list{ + {"", ""}, {"en", "English"}, {"fr", "Français"}}; + return list; +} + +class PreferencesWindow : public BWindow { +public: + PreferencesWindow(BMessenger owner, const Settings& settings, BRect parentFrame) + : BWindow(BRect(0, 0, 480, 200), _("Preferences"), B_TITLED_WINDOW, + B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | + B_CLOSE_ON_ESCAPE), + owner_(std::move(owner)) + { + dirLabel_ = label(settings.effectiveDownloadDir().string()); + dirLabel_->SetTruncation(B_TRUNCATE_MIDDLE); + dirLabel_->SetExplicitMinSize(BSize(240, B_SIZE_UNSET)); + + auto* menu = new BPopUpMenu("language"); + for (std::size_t i = 0; i < languages().size(); ++i) { + auto* message = new BMessage(kMsgSetLanguage); + message->AddString("language", languages()[i].first.c_str()); + auto* item = + new BMenuItem(i == 0 ? _("System language") : languages()[i].second.c_str(), message); + item->SetMarked(languages()[i].first == settings.language); + menu->AddItem(item); + } + auto* languageField = new BMenuField(nullptr, _("Language"), menu); + restartNote_ = label(_("The new language is used the next time OpenPU starts.")); + restartNote_->SetHighColor(tint_color(ui_color(B_PANEL_TEXT_COLOR), B_LIGHTEN_1_TINT)); + + autoCheck_ = new BCheckBox(nullptr, _("Check for a new version of OpenPU at startup"), + new BMessage(kMsgSetAutoCheck)); + autoCheck_->SetValue(settings.checkAppUpdates ? B_CONTROL_ON : B_CONTROL_OFF); + + BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) + .AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) + .Add(label(_("Download folder")), 0, 0) + .Add(dirLabel_, 1, 0) + .Add(button(_("Change…"), kMsgChooseFolder), 2, 0) + .Add(languageField->CreateLabelLayoutItem(), 0, 1) + .Add(languageField->CreateMenuBarLayoutItem(), 1, 1, 2, 1) + .Add(restartNote_, 1, 2, 2, 1) + .End() + .Add(autoCheck_) + .End(); + restartNote_->Hide(); + CenterIn(parentFrame); + } + + void MessageReceived(BMessage* message) override + { + switch (message->what) { + case kMsgChooseFolder: + owner_.SendMessage(message); + break; + case kMsgSetLanguage: + setVisible(restartNote_, true); + owner_.SendMessage(message); + break; + case kMsgSetAutoCheck: { + BMessage forward(kMsgSetAutoCheck); + forward.AddBool("value", autoCheck_->Value() == B_CONTROL_ON); + owner_.SendMessage(&forward); + break; + } + case kMsgActivate: + Activate(); + break; + case kMsgFolderChanged: + if (const char* path = message->GetString("path", nullptr)) + dirLabel_->SetText(path); + break; + default: + BWindow::MessageReceived(message); + } + } + +private: + BMessenger owner_; + BStringView* dirLabel_ = nullptr; + BStringView* restartNote_ = nullptr; + BCheckBox* autoCheck_ = nullptr; +}; + +} // namespace + +// ------------------------------------------------------------------------------------------------- + +MainWindow::MainWindow(std::string language) + : BWindow(BRect(0, 0, 640, 480), "OpenPU", B_TITLED_WINDOW, + B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE), + language_(std::move(language)), + transport_(makeCurlTransport()), + api_(std::make_unique(*transport_, ApiConfig::fromEnvironment())), + store_(paths::configDir() / "vehicles.json"), + settingsFile_(paths::configDir() / "config.json") +{ + ui_.setTarget(BMessenger(this)); + + std::string loadError; + try { + store_.load(); + settings_ = Settings::load(settingsFile_); + } catch (const StorageError& e) { + // Keep going with empty data, but never overwrite the unreadable file silently. + loadError = e.what(); + } + + auto* menuBar = new BMenuBar("menu"); + auto* appMenu = new BMenu("OpenPU"); + appMenu->AddItem(new BMenuItem(_("About OpenPU"), new BMessage(kMsgAbout))); + appMenu->AddSeparatorItem(); + appMenu->AddItem(new BMenuItem(_("Preferences"), new BMessage(kMsgPreferences), ',')); + appMenu->AddItem(new BMenuItem(_("Check for a new version of OpenPU"), new BMessage(kMsgCheckAppUpdate))); + appMenu->AddSeparatorItem(); + appMenu->AddItem(new BMenuItem(_("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q')); + menuBar->AddItem(appMenu); + + cards_ = new BCardView("pages"); + cards_->AddChild(buildVehiclesPage()); + cards_->AddChild(buildAddPage()); + cards_->AddChild(buildUpdatesPage()); + cards_->AddChild(buildDownloadPage()); + cards_->AddChild(buildUsbPage()); + cards_->AddChild(buildWritePage()); + cards_->AddChild(buildDonePage()); + + BLayoutBuilder::Group<>(this, B_VERTICAL, 0).Add(menuBar).Add(cards_).End(); + + refreshVehicles(); + show(Vehicles); + ResizeTo(600, 460); + CenterOnScreen(); + + if (!loadError.empty()) + ui_.post([this, loadError] { showError(_("Your saved data cannot be read"), loadError); }); + if (settings_.checkAppUpdates) + checkAppUpdate(false); +} + +MainWindow::~MainWindow() +{ + cancel_.cancel(); + joinWorker(); + if (updateThread_.joinable()) + updateThread_.join(); + delete folderPanel_; +} + +bool MainWindow::QuitRequested() +{ + cancel_.cancel(); + joinWorker(); + if (preferences_.IsValid()) + preferences_.SendMessage(B_QUIT_REQUESTED); + return true; +} + +void MainWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case UiQueue::kMessage: ui_.drain(); break; + + case kMsgAbout: showAbout(); break; + case kMsgPreferences: showPreferences(); break; + case kMsgCheckAppUpdate: checkAppUpdate(true); break; + case kMsgSetLanguage: + settings_.language = message->GetString("language", ""); + saveSettings(); + break; + case kMsgSetAutoCheck: + settings_.checkAppUpdates = message->GetBool("value", true); + saveSettings(); + break; + + case kMsgVehicleSelected: onVehicleSelected(); break; + case kMsgAddVehicle: + vinEntry_->SetText(""); + nameEntry_->SetText(""); + addStatus_->SetText(""); + addConfirm_->SetEnabled(false); + show(Add); + vinEntry_->MakeFocus(true); + break; + case kMsgRemoveVehicle: onRemoveVehicle(); break; + case kMsgCheckUpdates: onCheckUpdates(); break; + case kMsgBack: show(Vehicles); break; + + case kMsgVinChanged: addConfirm_->SetEnabled(isValidVin(normalizeVin(vinEntry_->Text()))); break; + case kMsgVinEntered: nameEntry_->MakeFocus(true); break; + case kMsgAddConfirm: onAddVehicle(); break; + + case kMsgUpdateToggled: updateDownloadButton(); break; + case kMsgChooseFolder: onChooseFolder(); break; + case kMsgFolderChosen: onFolderChosen(message); break; + case kMsgDownload: onStartDownload(); break; + case kMsgGuide: openGuide(); break; + case kMsgStop: + cancel_.cancel(); + cancelDownload_->SetEnabled(false); + cancelWrite_->SetEnabled(false); + break; + + case kMsgDriveSelected: + selectedDrive_ = message->GetInt32("index", -1); + onDriveSelected(); + break; + case kMsgRefreshDrives: refreshDrives(); break; + case kMsgPrepare: onPrepareUsb(); break; + case kMsgFinish: show(Vehicles); break; + + default: BWindow::MessageReceived(message); + } +} + +// --- OpenPU's own updates ------------------------------------------------------------------------ + +void MainWindow::checkAppUpdate(bool manual) +{ + if (updateCheckRunning_) + return; + if (updateThread_.joinable()) + updateThread_.join(); + updateCheckRunning_ = true; + updateThread_ = std::thread([this, manual] { + std::optional release; + std::string error; + try { + release = checkForNewerRelease(*transport_, AppUpdateConfig::fromEnvironment(), version()); + } catch (const std::exception& e) { + error = e.what(); + } + ui_.post([this, manual, release, error] { + updateCheckRunning_ = false; + if (release) { + offerAppUpdate(*release); + } else if (manual && error.empty()) { + makeAlert(_("OpenPU is up to date"), compose(_("Version %1 is the latest version."), {version()}), + "OK") + ->Go(nullptr); + } else if (manual) { + showError(_("Cannot check for a new version"), error); + } + // An automatic check fails silently: being offline must not bother the user. + }); + }); +} + +void MainWindow::offerAppUpdate(const AppRelease& release) +{ + std::string detail = + compose(_("You are using version %1. Do you want to download the new version?"), {version()}); + if (!release.notes.empty()) + detail += "\n\n" + release.notes; + if (ask(compose(_("OpenPU %1 is available"), {release.version.toString()}), detail, _("Later"), + _("Download")) == 1) + openUrl(release.pageUrl); +} + +// --- preferences, about -------------------------------------------------------------------------- + +void MainWindow::showPreferences() +{ + if (preferences_.IsValid()) { + preferences_.SendMessage(kMsgActivate); + return; + } + auto* window = new PreferencesWindow(BMessenger(this), settings_, Frame()); + preferences_ = BMessenger(window); + window->Show(); +} + +void MainWindow::showAbout() +{ + auto* about = new BAboutWindow("OpenPU", kSignature); + about->SetVersion(versionDescription()); + about->AddDescription(_("Download Peugeot head unit updates (system and navigation map) and prepare the USB " + "stick, on Linux and Haiku.\n\nIndependent project, not affiliated with Stellantis or " + "Peugeot.")); + // Not AddCopyright(): it appends "All Rights Reserved", which an MIT-licensed project is not. + about->AddText("© 2026 yann64 and the OpenPU contributors"); + const char* license[] = {"MIT", nullptr}; + about->AddText(_("License"), license); + const char* source[] = {"https://github.com/yann64/openpu", nullptr}; + about->AddText(_("Source code"), source); + about->Show(); +} + +void MainWindow::saveSettings() +{ + try { + settings_.save(settingsFile_); + } catch (const StorageError& e) { + showError(_("Cannot save the settings"), e.what()); + } +} + +void MainWindow::saveVehicles() +{ + try { + store_.save(); + } catch (const StorageError& e) { + showError(_("Cannot save the vehicle list"), e.what()); + } +} + +void MainWindow::openGuide() +{ + if (current_) + openUrl(guideUrl(current_->guideKey, language_)); +} + +// --- navigation and threads ---------------------------------------------------------------------- + +void MainWindow::show(Page page) +{ + cards_->CardLayout()->SetVisibleItem(static_cast(page)); + switch (page) { + case Vehicles: SetDefaultButton(checkButton_); break; + case Add: SetDefaultButton(addConfirm_); break; + case Updates: SetDefaultButton(downloadButton_); break; + case Done: SetDefaultButton(doneButton_); break; + case Download: + case Usb: // erasing a stick must never be the default action + case Write: SetDefaultButton(nullptr); break; + } +} + +template +void MainWindow::runAsync(F&& work) +{ + joinWorker(); + cancel_.reset(); + worker_ = std::thread(std::forward(work)); +} + +void MainWindow::joinWorker() +{ + if (worker_.joinable()) + worker_.join(); +} + +void MainWindow::showError(const std::string& title, const std::string& detail) +{ + makeAlert(title, detail, "OK", nullptr, B_WARNING_ALERT)->Go(nullptr); +} + +// --- vehicles ------------------------------------------------------------------------------------ + +BView* MainWindow::buildVehiclesPage() +{ + vehiclesEmpty_ = prose(_("Add your vehicle with its VIN (17 characters, on the registration document, field E).")); + vehicleList_ = new BListView("vehicles"); + vehicleList_->SetSelectionMessage(new BMessage(kMsgVehicleSelected)); + vehicleList_->SetInvocationMessage(new BMessage(kMsgCheckUpdates)); // double-click or Enter + auto* scroll = new BScrollView("scroll", vehicleList_, 0, false, true); + + removeButton_ = button(_("Remove"), kMsgRemoveVehicle); + checkButton_ = button(_("Check for updates"), kMsgCheckUpdates); + + auto* view = new BView("vehiclesPage", 0); + BLayoutBuilder::Group<>(view, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(heading(_("My vehicles"))) + .Add(vehiclesEmpty_) + .Add(scroll, 10.0F) + .AddGroup(B_HORIZONTAL) + .AddGlue() + .Add(button(_("Add a vehicle"), kMsgAddVehicle)) + .Add(removeButton_) + .Add(checkButton_) + .End() + .End(); + return view; +} + +void MainWindow::refreshVehicles() +{ + while (BListItem* item = vehicleList_->RemoveItem(static_cast(0))) + delete item; + for (const auto& v : store_.all()) { + std::string detail = v.vin + " · " + headUnitText(v); + if (hasPendingFiles(v)) + detail += std::string(" · ") + _("download not finished"); + vehicleList_->AddItem(new VehicleItem(v.name.empty() ? v.vin : v.name, detail)); + } + setVisible(vehiclesEmpty_, store_.all().empty()); + onVehicleSelected(); +} + +std::optional MainWindow::selectedVehicle() const +{ + const int32 index = vehicleList_->CurrentSelection(); + if (index < 0 || static_cast(index) >= store_.all().size()) + return std::nullopt; + return store_.all()[static_cast(index)]; +} + +void MainWindow::onVehicleSelected() +{ + const bool selected = vehicleList_->CurrentSelection() >= 0; + removeButton_->SetEnabled(selected); + checkButton_->SetEnabled(selected); +} + +void MainWindow::onRemoveVehicle() +{ + const auto v = selectedVehicle(); + if (!v) + return; + if (ask(compose(_("Remove %1?"), {v->name.empty() ? v->vin : v->name}), + _("Downloaded files that were not written to a USB stick yet are deleted too."), _("Cancel"), _("Remove"), + true) != 1) + return; + std::error_code ec; + for (const auto& f : {v->pendingFirmware, v->pendingMap, v->pendingLicense}) + if (!f.empty()) + fs::remove(f, ec); + store_.remove(v->vin); + saveVehicles(); + refreshVehicles(); +} + +// --- add vehicle --------------------------------------------------------------------------------- + +BView* MainWindow::buildAddPage() +{ + vinEntry_ = new BTextControl(nullptr, _("VIN"), "", new BMessage(kMsgVinEntered)); + vinEntry_->SetModificationMessage(new BMessage(kMsgVinChanged)); + vinEntry_->TextView()->SetMaxBytes(25); + nameEntry_ = new BTextControl(nullptr, _("Name"), "", new BMessage(kMsgAddConfirm)); + addStatus_ = label(); + addConfirm_ = button(_("Add"), kMsgAddConfirm); + addConfirm_->SetEnabled(false); + + auto* view = new BView("addPage", 0); + BLayoutBuilder::Group<>(view, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(heading(_("Add a vehicle"))) + .Add(prose(_("The VIN (vehicle identification number) is written in field E of the registration document " + "and at the bottom of the windscreen."))) + .AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING) + .AddTextControl(vinEntry_, 0, 0) + .AddTextControl(nameEntry_, 0, 1) + .End() + .Add(addStatus_) + .AddGlue() + .AddGroup(B_HORIZONTAL) + .Add(button(_("Back"), kMsgBack)) + .AddGlue() + .Add(addConfirm_) + .End() + .End(); + return view; +} + +void MainWindow::onAddVehicle() +{ + const std::string vin = normalizeVin(vinEntry_->Text()); + if (!isValidVin(vin)) { + addStatus_->SetText(_("A VIN has 17 characters and starts with VF3 or VR3.")); + return; + } + const std::string name = nameEntry_->Text(); + addConfirm_->SetEnabled(false); + addStatus_->SetText(_("Checking the vehicle…")); + runAsync([this, vin, name] { + std::optional check; + std::string error; + try { + check = api_->checkVehicle(vin); + } catch (const ApiError& e) { + error = apiErrorText(e); + } + ui_.post([this, vin, name, check, error] { + addConfirm_->SetEnabled(true); + if (!check) { + addStatus_->SetText(error.c_str()); + return; + } + if (!check->exists) { + addStatus_->SetText(_("This vehicle is unknown to the update service.")); + return; + } + if (check->type == HeadUnitType::Unknown) { + addStatus_->SetText(_("This vehicle has no head unit that can be updated with a USB stick.")); + return; + } + Vehicle v; + if (const Vehicle* existing = store_.find(vin)) + v = *existing; + v.vin = vin; + v.name = name.empty() ? (v.name.empty() ? vin : v.name) : name; + v.type = check->type; + v.guideKey = check->guideKey; + store_.upsert(v); + saveVehicles(); + refreshVehicles(); + show(Vehicles); + }); + }); +} + +// --- updates ------------------------------------------------------------------------------------- + +BView* MainWindow::buildUpdatesPage() +{ + updatesTitle_ = heading(""); + updatesStatus_ = prose(); + firmwareCheck_ = new BCheckBox(nullptr, "", new BMessage(kMsgUpdateToggled)); + mapCheck_ = new BCheckBox(nullptr, "", new BMessage(kMsgUpdateToggled)); + // A check box is not wider than its label by default, which would cap the width of the window. + for (BCheckBox* check : {firmwareCheck_, mapCheck_}) + check->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + downloadDirLabel_ = label(); + downloadDirLabel_->SetTruncation(B_TRUNCATE_MIDDLE); + downloadDirLabel_->SetExplicitMinSize(BSize(200, B_SIZE_UNSET)); + guideButton_ = button(_("Installation guide"), kMsgGuide); + downloadButton_ = button(_("Download"), kMsgDownload); + + auto* view = new BView("updatesPage", 0); + BLayoutBuilder::Group<>(view, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(updatesTitle_) + .Add(updatesStatus_) + .Add(firmwareCheck_) + .Add(mapCheck_) + .AddStrut(B_USE_DEFAULT_SPACING) + .AddGroup(B_HORIZONTAL) + .Add(new BStringView(nullptr, _("Download folder:"))) + .Add(downloadDirLabel_) + .Add(button(_("Change…"), kMsgChooseFolder)) + .End() + .AddGlue() + .AddGroup(B_HORIZONTAL) + .Add(button(_("Back"), kMsgBack)) + .AddGlue() + .Add(guideButton_) + .Add(downloadButton_) + .End() + .End(); + return view; +} + +void MainWindow::updateDownloadDirLabel() // also refreshes the open preferences window +{ + const std::string dir = settings_.effectiveDownloadDir().string(); + downloadDirLabel_->SetText(dir.c_str()); + if (preferences_.IsValid()) { + BMessage message(kMsgFolderChanged); + message.AddString("path", dir.c_str()); + preferences_.SendMessage(&message); + } +} + +void MainWindow::onCheckUpdates() +{ + const auto selected = selectedVehicle(); + if (!selected) + return; + const Vehicle& vehicle = *selected; + current_ = vehicle; + updatesTitle_->SetText(((vehicle.name.empty() ? vehicle.vin : vehicle.name) + " · " + headUnitText(vehicle)).c_str()); + setText(updatesStatus_, _("Looking for updates…")); + setVisible(firmwareCheck_, false); + setVisible(mapCheck_, false); + downloadButton_->SetEnabled(false); + setVisible(guideButton_, !guideUrl(vehicle.guideKey, language_).empty()); + updateDownloadDirLabel(); + show(Updates); + + runAsync([this, vin = vehicle.vin, type = vehicle.type] { + std::optional updates; + std::string error; + try { + updates = api_->getUpdates(vin, type); + } catch (const ApiError& e) { + error = apiErrorText(e); + } + ui_.post([this, vin, updates, error] { + if (!current_ || current_->vin != vin) + return; // the user went back and picked another vehicle meanwhile + if (!updates) { + setText(updatesStatus_, error); + return; + } + showUpdates(*updates); + }); + }); +} + +void MainWindow::showUpdates(const AvailableUpdates& updates) +{ + updates_ = updates; + if (!updates.firmware && !updates.map) { + setText(updatesStatus_, _("No update is available: your head unit is up to date.")); + return; + } + setText(updatesStatus_, _("Select the updates to download:")); + if (updates.firmware) { + firmwareCheck_->SetLabel((std::string(_("System (firmware)")) + " — " + updateText(*updates.firmware)).c_str()); + firmwareCheck_->SetValue(B_CONTROL_ON); + setVisible(firmwareCheck_, true); + } + if (updates.map) { + mapCheck_->SetLabel((std::string(_("Navigation map")) + " — " + updateText(*updates.map)).c_str()); + mapCheck_->SetValue(B_CONTROL_ON); + setVisible(mapCheck_, true); + } + updateDownloadButton(); +} + +void MainWindow::updateDownloadButton() +{ + const bool firmware = !firmwareCheck_->IsHidden(firmwareCheck_) && firmwareCheck_->Value() == B_CONTROL_ON; + const bool map = !mapCheck_->IsHidden(mapCheck_) && mapCheck_->Value() == B_CONTROL_ON; + downloadButton_->SetEnabled(firmware || map); +} + +void MainWindow::onChooseFolder() +{ + if (folderPanel_ == nullptr) { + BMessenger target(this); + folderPanel_ = new BFilePanel(B_OPEN_PANEL, &target, nullptr, B_DIRECTORY_NODE, false, + new BMessage(kMsgFolderChosen), nullptr, true, true); + folderPanel_->SetButtonLabel(B_DEFAULT_BUTTON, _("Select")); + folderPanel_->Window()->SetTitle(_("Download folder")); + } + std::error_code ec; + fs::path start = settings_.effectiveDownloadDir(); + if (!fs::is_directory(start, ec)) + start = start.parent_path(); + folderPanel_->SetPanelDirectory(start.string().c_str()); + folderPanel_->Show(); +} + +void MainWindow::onFolderChosen(BMessage* message) +{ + entry_ref ref; + if (message->FindRef("refs", &ref) != B_OK) + return; + BPath path(&ref); + if (path.InitCheck() != B_OK) + return; + settings_.downloadDir = path.Path(); + saveSettings(); + updateDownloadDirLabel(); +} + +void MainWindow::onStartDownload() +{ + DownloadPlan plan; + if (!firmwareCheck_->IsHidden(firmwareCheck_) && firmwareCheck_->Value() == B_CONTROL_ON) + plan.firmware = updates_.firmware; + if (!mapCheck_->IsHidden(mapCheck_) && mapCheck_->Value() == B_CONTROL_ON) + plan.map = updates_.map; + plan.dir = settings_.effectiveDownloadDir(); + + std::error_code ec; + fs::create_directories(plan.dir, ec); + const auto space = fs::space(plan.dir, ec); + if (!ec && space.available < plan.requiredSpace()) { + const std::string detail = compose( + _("%1 are needed in %2 but only %3 are free. If a previous download of these files is already in this " + "folder, it will be resumed and may fit."), + {formatSize(plan.requiredSpace()), plan.dir.string(), formatSize(space.available)}); + if (ask(_("Not enough free space"), detail, _("Cancel"), _("Download anyway"), true) != 1) + return; + } + startDownload(plan); +} + +// --- download ------------------------------------------------------------------------------------ + +BView* MainWindow::buildDownloadPage() +{ + licenseLabel_ = label(); + firmwareBar_ = new BStatusBar("firmware"); + mapBar_ = new BStatusBar("map"); + etaLabel_ = label(); + cancelDownload_ = button(_("Stop"), kMsgStop); + + auto* note = prose(_("You can close the application: the download will resume where it stopped next time.")); + auto* view = new BView("downloadPage", 0); + BLayoutBuilder::Group<>(view, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(heading(_("Downloading"))) + .Add(note) + .Add(licenseLabel_) + .Add(firmwareBar_) + .Add(mapBar_) + .Add(etaLabel_) + .AddGlue() + .AddGroup(B_HORIZONTAL) + .AddGlue() + .Add(cancelDownload_) + .End() + .End(); + return view; +} + +void MainWindow::startDownload(const DownloadPlan& plan) +{ + setVisible(licenseLabel_, plan.firmware.has_value() && !plan.firmware->licenseUrl.empty()); + licenseLabel_->SetText((std::string(_("License")) + " — " + _("waiting")).c_str()); + setVisible(firmwareBar_, plan.firmware.has_value()); + if (plan.firmware) + firmwareBar_->Reset((std::string(_("System (firmware)")) + " — " + plan.firmware->version).c_str()); + setVisible(mapBar_, plan.map.has_value()); + if (plan.map) + mapBar_->Reset((std::string(_("Navigation map")) + " — " + plan.map->version).c_str()); + etaLabel_->SetText(_("Connecting…")); + cancelDownload_->SetEnabled(true); + show(Download); + + runAsync([this, plan] { + Downloader downloader(*transport_); + std::optional files; + std::string error; + bool cancelled = false; + try { + files = downloadUpdates( + downloader, plan, [this](const JobProgress& p) { ui_.post([this, p] { onDownloadProgress(p); }); }, + &cancel_); + } catch (const Cancelled&) { + cancelled = true; + } catch (const DownloadError& e) { + error = e.kind() == DownloadError::Kind::Disk ? compose(_("Cannot write the file: %1"), {e.what()}) + : compose(_("The download failed: %1"), {e.what()}); + } + ui_.post([this, files, error, cancelled] { + if (files) { + onDownloaded(*files); + return; + } + // Partial files stay in the download folder; the next download resumes them. + if (!cancelled) + showError(_("Download interrupted"), + error + "\n\n" + _("The files already downloaded are kept; start again to resume.")); + show(Vehicles); + }); + }); +} + +void MainWindow::onDownloadProgress(const JobProgress& p) +{ + if (p.item == DownloadItem::License) { + licenseLabel_->SetText((std::string(_("License")) + " — " + _("done")).c_str()); + return; + } + BStatusBar* bar = p.item == DownloadItem::Firmware ? firmwareBar_ : mapBar_; + const auto& d = p.progress; + bar->SetTo(percent(d.done, d.total), nullptr, (formatSize(d.done) + " / " + formatSize(d.total)).c_str()); + std::string eta; + if (const auto remaining = d.remaining()) + eta = compose(_("Time left: %1"), {formatDuration(*remaining)}); + if (d.attempt > 0) + eta += " " + compose(_("(connection lost, attempt %1)"), {std::to_string(d.attempt)}); + etaLabel_->SetText(eta.c_str()); +} + +void MainWindow::onDownloaded(const DownloadedFiles& files) +{ + files_ = files; + if (current_) { + Vehicle v = *current_; + v.pendingFirmware = files.firmware ? files.firmware->string() : ""; + v.pendingMap = files.map ? files.map->string() : ""; + v.pendingLicense = files.license ? files.license->string() : ""; + current_ = v; + store_.upsert(v); + saveVehicles(); + refreshVehicles(); + } + enterUsbPage(); +} + +// --- USB ----------------------------------------------------------------------------------------- + +BView* MainWindow::buildUsbPage() +{ + usbInfo_ = prose(); + driveMenu_ = new BPopUpMenu(_("No USB stick found. Plug one in, then refresh.")); + driveField_ = new BMenuField("drive", nullptr, driveMenu_); + usbStatus_ = label(); + prepareButton_ = button(_("Erase and write"), kMsgPrepare); + + auto* view = new BView("usbPage", 0); + BLayoutBuilder::Group<>(view, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(heading(_("Prepare the USB stick"))) + .Add(usbInfo_) + .AddGroup(B_HORIZONTAL) + .Add(driveField_, 10.0F) + .Add(button(_("Refresh"), kMsgRefreshDrives)) + .End() + .Add(usbStatus_) + .AddGlue() + .AddGroup(B_HORIZONTAL) + .Add(button(_("Back"), kMsgBack)) + .AddGlue() + .Add(prepareButton_) + .End() + .End(); + return view; +} + +void MainWindow::enterUsbPage() +{ + setText(usbInfo_, _("Computing the required size…")); + prepareButton_->SetEnabled(false); + show(Usb); + const UsbWritePlan plan = files_.writePlan(); + runAsync([this, plan] { + std::uint64_t size = 0; + std::string error; + try { + size = plan.payloadSize(); + } catch (const ArchiveError& e) { + error = e.what(); + } + ui_.post([this, size, error] { + if (!error.empty()) { + showError(_("A downloaded file is damaged"), error + "\n\n" + _("Download the update again.")); + files_.remove(); + show(Vehicles); + return; + } + payload_ = size; + setText(usbInfo_, + compose(_("Plug in a USB stick of at least %1. It will be completely erased and formatted (FAT32)."), + {std::to_string(minimumStickSize(size) / 1000000000ULL) + " GB"})); + refreshDrives(); + }); + }); +} + +void MainWindow::refreshDrives() +{ + drives_.clear(); + usbStatus_->SetText(""); + try { + if (!usb_) + usb_ = makeUsbBackend(); + drives_ = usb_->list(); + } catch (const UsbError& e) { + usbStatus_->SetText((std::string(_("USB drives cannot be listed: ")) + e.what()).c_str()); + } + while (BMenuItem* item = driveMenu_->RemoveItem(static_cast(0))) + delete item; + for (std::size_t i = 0; i < drives_.size(); ++i) { + const auto& d = drives_[i]; + std::string text = d.description(); + if (d.size < withMargin(payload_)) + text += std::string(" — ") + _("too small"); + auto* message = new BMessage(kMsgDriveSelected); + message->AddInt32("index", static_cast(i)); + driveMenu_->AddItem(new BMenuItem(text.c_str(), message)); + } + selectedDrive_ = drives_.empty() ? -1 : 0; + if (drives_.empty()) { + // An empty pop-up menu shows its own name: the "no stick" hint. + driveField_->MenuItem()->SetLabel(_("No USB stick found. Plug one in, then refresh.")); + } else { + driveMenu_->ItemAt(0)->SetMarked(true); + } + onDriveSelected(); +} + +void MainWindow::onDriveSelected() +{ + const bool valid = selectedDrive_ >= 0 && static_cast(selectedDrive_) < drives_.size(); + const bool ok = valid && drives_[static_cast(selectedDrive_)].size >= withMargin(payload_); + prepareButton_->SetEnabled(ok); + if (valid) + usbStatus_->SetText(ok ? "" : _("This USB stick is too small.")); +} + +void MainWindow::onPrepareUsb() +{ + if (selectedDrive_ < 0 || static_cast(selectedDrive_) >= drives_.size()) + return; + const UsbDrive drive = drives_[static_cast(selectedDrive_)]; + if (ask(compose(_("Erase %1?"), {drive.description()}), _("Everything on this USB stick will be lost."), + _("Cancel"), _("Erase and write"), true) == 1) + startWrite(drive); +} + +// --- writing ------------------------------------------------------------------------------------- + +BView* MainWindow::buildWritePage() +{ + writeBar_ = new BStatusBar("write"); + writeDetail_ = label(); + writeDetail_->SetTruncation(B_TRUNCATE_BEGINNING); + writeDetail_->SetHighColor(tint_color(ui_color(B_PANEL_TEXT_COLOR), B_LIGHTEN_1_TINT)); + cancelWrite_ = button(_("Stop"), kMsgStop); + + auto* view = new BView("writePage", 0); + BLayoutBuilder::Group<>(view, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(heading(_("Writing the USB stick"))) + .Add(prose(_("Do not unplug the USB stick."))) + .Add(writeBar_) + .Add(writeDetail_) + .AddGlue() + .AddGroup(B_HORIZONTAL) + .AddGlue() + .Add(cancelWrite_) + .End() + .End(); + return view; +} + +void MainWindow::startWrite(const UsbDrive& drive) +{ + writeBar_->Reset(_("Checking the downloaded files…")); + writeDetail_->SetText(""); + cancelWrite_->SetEnabled(true); + show(Write); + const UsbWritePlan plan = files_.writePlan(); + runAsync([this, drive, plan] { + std::string error; + bool cancelled = false; + bool corrupt = false; + try { + writeToUsb(*usb_, drive, drive.label, plan, + [this](const UsbProgress& p) { ui_.post([this, p] { onWriteProgress(p); }); }, &cancel_); + } catch (const Cancelled&) { + cancelled = true; + } catch (const ArchiveError& e) { + corrupt = e.kind() == ArchiveError::Kind::Corrupt; + error = e.what(); + } catch (const UsbError& e) { + error = e.kind() == UsbError::Kind::NotAuthorized ? std::string(_("Permission to format the USB stick was refused.")) + : std::string(e.what()); + } + ui_.post([this, error, cancelled, corrupt] { + if (error.empty() && !cancelled) { + onWritten(); + return; + } + if (corrupt) { + showError(_("A downloaded file is damaged"), error + "\n\n" + _("Download the update again.")); + files_.remove(); + show(Vehicles); + return; + } + if (!cancelled) + showError(_("The USB stick could not be prepared"), error); + enterUsbPage(); + }); + }); +} + +void MainWindow::onWriteProgress(const UsbProgress& p) +{ + const std::string count = p.archiveCount > 1 ? compose(" (%1/%2)", {std::to_string(p.archiveIndex + 1), + std::to_string(p.archiveCount)}) + : std::string(); + std::string step; + switch (p.step) { + case UsbStep::Verifying: step = _("Checking the downloaded files…") + count; break; + case UsbStep::Formatting: + writeBar_->Reset(_("Formatting the USB stick…")); + writeDetail_->SetText(""); + return; + case UsbStep::CopyingLicense: + writeBar_->Reset(_("Copying the license…")); + writeDetail_->SetText(""); + return; + case UsbStep::Extracting: step = _("Copying the update…") + count; break; + case UsbStep::Ejecting: + writeBar_->Reset(_("Ejecting the USB stick…")); + writeDetail_->SetText(""); + writeBar_->SetTo(100.0F); + return; + case UsbStep::Done: return; + } + // Reset only when the step changes, so the bar does not flicker back to zero. + if (step != writeBar_->Label()) + writeBar_->Reset(step.c_str()); + if (p.total > 0) + writeBar_->SetTo(percent(p.done, p.total), nullptr, (formatSize(p.done) + " / " + formatSize(p.total)).c_str()); + writeDetail_->SetText(p.detail.c_str()); +} + +void MainWindow::onWritten() +{ + files_.remove(); // same as the official app: the files are on the stick now + files_ = {}; + if (current_) { + Vehicle v = *current_; + v.pendingFirmware.clear(); + v.pendingMap.clear(); + v.pendingLicense.clear(); + store_.upsert(v); + saveVehicles(); + refreshVehicles(); + } + show(Done); +} + +BView* MainWindow::buildDonePage() +{ + doneButton_ = button(_("Finish"), kMsgFinish); + auto* view = new BView("donePage", 0); + BLayoutBuilder::Group<>(view, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(heading(_("The USB stick is ready"))) + .Add(prose(_("You can unplug the USB stick. With the engine running, plug it into the vehicle and follow the " + "instructions on the screen. The installation can take a long time: do not stop the engine."))) + .AddGlue() + .AddGroup(B_HORIZONTAL) + .AddGlue() + .Add(button(_("Installation guide"), kMsgGuide)) + .Add(doneButton_) + .End() + .End(); + return view; +} + +} // namespace openpu::haiku diff --git a/src/ui-haiku/main_window.hpp b/src/ui-haiku/main_window.hpp new file mode 100644 index 0000000..694761d --- /dev/null +++ b/src/ui-haiku/main_window.hpp @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: MIT +#pragma once + +#include "ui_queue.hpp" + +#include "openpu/api_client.hpp" +#include "openpu/app_update.hpp" +#include "openpu/job.hpp" +#include "openpu/storage.hpp" +#include "openpu/usb.hpp" + +#include +#include + +#include +#include +#include +#include +#include + +class BButton; +class BCardView; +class BCheckBox; +class BFilePanel; +class BListView; +class BMenuField; +class BPopUpMenu; +class BStatusBar; +class BStringView; +class BTextControl; +class BTextView; +class BView; + +namespace openpu::haiku { + +/// Messages shared with the preferences window. +enum : uint32 { + kMsgChooseFolder = 'chfd', ///< main window: open the folder panel + kMsgSetLanguage = 'slng', ///< main window: "language" (string, empty = system) + kMsgSetAutoCheck = 'sach', ///< main window: "value" (bool) + kMsgFolderChanged = 'fdch',///< preferences window: "path" (string) +}; + +class MainWindow : public BWindow { +public: + /// `language`: two-letter language of the interface (for the guide links). + explicit MainWindow(std::string language); + ~MainWindow() override; + MainWindow(const MainWindow&) = delete; + MainWindow& operator=(const MainWindow&) = delete; + + void MessageReceived(BMessage* message) override; + bool QuitRequested() override; + +private: + enum Page : int32 { Vehicles, Add, Updates, Download, Usb, Write, Done }; + + // pages + BView* buildVehiclesPage(); + BView* buildAddPage(); + BView* buildUpdatesPage(); + BView* buildDownloadPage(); + BView* buildUsbPage(); + BView* buildWritePage(); + BView* buildDonePage(); + void show(Page page); + + // vehicles + void refreshVehicles(); + std::optional selectedVehicle() const; + void onVehicleSelected(); + void onAddVehicle(); + void onRemoveVehicle(); + void onCheckUpdates(); + + // updates / download + void showUpdates(const AvailableUpdates& updates); + void updateDownloadButton(); + void onChooseFolder(); + void onFolderChosen(BMessage* message); + void onStartDownload(); + void startDownload(const DownloadPlan& plan); + void onDownloadProgress(const JobProgress& p); + void onDownloaded(const DownloadedFiles& files); + + // usb + void enterUsbPage(); + void refreshDrives(); + void onDriveSelected(); + void onPrepareUsb(); + void startWrite(const UsbDrive& drive); + void onWriteProgress(const UsbProgress& p); + void onWritten(); + + // helpers + template + void runAsync(F&& work); + void joinWorker(); + void showError(const std::string& title, const std::string& detail); + void showAbout(); + void showPreferences(); + void openGuide(); + void checkAppUpdate(bool manual); + void offerAppUpdate(const AppRelease& release); + void saveVehicles(); + void saveSettings(); + void updateDownloadDirLabel(); + + UiQueue ui_; + std::string language_; + std::unique_ptr transport_; + std::unique_ptr api_; + std::unique_ptr usb_; + VehicleStore store_; + Settings settings_; + std::filesystem::path settingsFile_; + std::thread worker_; + std::thread updateThread_; // OpenPU new-version check, independent of the main flow + bool updateCheckRunning_ = false; + CancelToken cancel_; + BMessenger preferences_; + BFilePanel* folderPanel_ = nullptr; + + // flow state + std::optional current_; + AvailableUpdates updates_; + DownloadedFiles files_; + std::vector drives_; + std::int32_t selectedDrive_ = -1; + std::uint64_t payload_ = 0; + + // widgets + BCardView* cards_ = nullptr; + + BListView* vehicleList_ = nullptr; + BTextView* vehiclesEmpty_ = nullptr; + BButton *removeButton_ = nullptr, *checkButton_ = nullptr; + + BTextControl *vinEntry_ = nullptr, *nameEntry_ = nullptr; + BStringView* addStatus_ = nullptr; + BButton* addConfirm_ = nullptr; + + BStringView* updatesTitle_ = nullptr; + BTextView* updatesStatus_ = nullptr; + BCheckBox *firmwareCheck_ = nullptr, *mapCheck_ = nullptr; + BStringView* downloadDirLabel_ = nullptr; + BButton *downloadButton_ = nullptr, *guideButton_ = nullptr; + + BStringView* licenseLabel_ = nullptr; + BStatusBar *firmwareBar_ = nullptr, *mapBar_ = nullptr; + BStringView* etaLabel_ = nullptr; + BButton* cancelDownload_ = nullptr; + + BTextView* usbInfo_ = nullptr; + BPopUpMenu* driveMenu_ = nullptr; + BMenuField* driveField_ = nullptr; + BStringView* usbStatus_ = nullptr; + BButton* prepareButton_ = nullptr; + + BStatusBar* writeBar_ = nullptr; + BStringView* writeDetail_ = nullptr; + BButton* cancelWrite_ = nullptr; + + BButton* doneButton_ = nullptr; +}; + +} // namespace openpu::haiku diff --git a/src/ui-haiku/ui_queue.hpp b/src/ui-haiku/ui_queue.hpp new file mode 100644 index 0000000..80f8f9a --- /dev/null +++ b/src/ui-haiku/ui_queue.hpp @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT +#pragma once + +#include + +#include +#include +#include +#include + +namespace openpu::haiku { + +/// Runs closures posted from worker threads on a window's thread. +/// post() never blocks: a single kMessage is in flight at a time and drain() runs everything queued. +class UiQueue { +public: + static constexpr uint32 kMessage = 'uiqd'; + + void setTarget(const BMessenger& target) { target_ = target; } + + void post(std::function fn) + { + { + std::scoped_lock lock(mutex_); + queue_.push_back(std::move(fn)); + } + if (!pending_.exchange(true)) { + BMessage message(kMessage); + // Zero timeout: a worker must never wait for the window (it may be joining the worker). + if (target_.SendMessage(&message, static_cast(nullptr), 0) != B_OK) + pending_ = false; + } + } + + /// Called by the target window when it receives kMessage. + void drain() + { + pending_ = false; + std::deque> local; + { + std::scoped_lock lock(mutex_); + local.swap(queue_); + } + for (auto& fn : local) + fn(); + } + +private: + BMessenger target_; + std::atomic pending_{false}; + std::mutex mutex_; + std::deque> queue_; +}; + +} // namespace openpu::haiku