Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4200f63b4f | ||
|
|
8658855cca | ||
|
|
3fa306c815 | ||
|
|
44a7e5b396 | ||
|
|
9b357cde63 | ||
|
|
096553e429 | ||
|
|
7b7962c53f | ||
|
|
1903bad336 | ||
|
|
b3a7bb4b67 | ||
|
|
53f3e6b5bd | ||
|
|
ecf38c61f6 | ||
|
|
e81f5ee0cd | ||
|
|
bd13a1404b | ||
|
|
48ed73bdba | ||
|
|
e57d5dbb99 | ||
|
|
8fda7636f9 | ||
|
|
cd5bed0f4d | ||
|
|
26ca0e4d88 | ||
|
|
7c8e981845 | ||
|
|
3320e60805 | ||
|
|
a1d8c96e4e | ||
|
|
6224a94df6 | ||
|
|
1b3f11aad8 | ||
|
|
6aef549eb0 | ||
|
|
5cc85cac4a | ||
|
|
d8a70eabf8 | ||
|
|
4fe4c7287e | ||
|
|
71eb962b00 | ||
|
|
bc737d356e | ||
|
|
f355c97940 | ||
|
|
a2cef3d256 | ||
|
|
a4a345984b | ||
|
|
ad31e5c597 | ||
|
|
5df9f2c22a | ||
|
|
ca49ad5e63 | ||
|
|
f525d52ab2 | ||
|
|
9043632ba9 | ||
|
|
bd3b3e48b3 | ||
|
|
e538ed619e | ||
|
|
0f7c3a6c2b | ||
|
|
5054f04c54 | ||
|
|
4a773c63ce | ||
|
|
1242753962 | ||
|
|
ad67daa3ee | ||
|
|
a7f8893bf2 | ||
|
|
de9fbdc7c3 | ||
|
|
bbe29962e4 | ||
|
|
efd0df5019 | ||
|
|
cb4c68638a | ||
|
|
bd0c9bf37c | ||
|
|
29abaf3189 | ||
|
|
f2704527b0 | ||
|
|
7541b29996 | ||
|
|
6dd3bc7b8f | ||
|
|
829e30750b | ||
|
|
776662c9ab | ||
|
|
6743d0b5e7 |
No files matched your search
@@ -0,0 +1,82 @@
|
|||||||
|
# Gitea Actions — Release
|
||||||
|
#
|
||||||
|
# Triggered whenever the `version` file at the repository root is bumped.
|
||||||
|
# Creates a Gitea release tagged with the new version — but ONLY if the
|
||||||
|
# version in `version` differs from the latest released tag.
|
||||||
|
#
|
||||||
|
# No secret is required: `secrets.GITEA_TOKEN` is the built-in automatic
|
||||||
|
# token provided by Gitea on every run. The `permissions: contents: write`
|
||||||
|
# block below asks for write access to contents and releases, so the release
|
||||||
|
# can be created without configuring any secret in the repository settings.
|
||||||
|
# Tests are deliberately not run here; they live in the separate `tests`
|
||||||
|
# workflow and do not gate releases.
|
||||||
|
|
||||||
|
name: release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- version
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Reads the new version and publishes a release + git tag when the version
|
||||||
|
# genuinely changed. Runs without any test step.
|
||||||
|
release:
|
||||||
|
runs-on: linux
|
||||||
|
steps:
|
||||||
|
- name: Checkout with full history and tags
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
fetch-tags: true
|
||||||
|
|
||||||
|
- name: Read version
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
VERSION=$(tr -d ' \n' < version)
|
||||||
|
echo "value=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Check whether the version already has a release
|
||||||
|
id: check
|
||||||
|
run: |
|
||||||
|
VERSION="${{ steps.version.outputs.value }}"
|
||||||
|
TAG="v${VERSION}"
|
||||||
|
if git tag --list | grep -qx "${TAG}"; then
|
||||||
|
echo "Tag ${TAG} already exists — nothing to release"
|
||||||
|
echo "new=false" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "new=true" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Create release
|
||||||
|
if: steps.check.outputs.new == 'true'
|
||||||
|
env:
|
||||||
|
# Built-in automatic token, no secret to configure. The
|
||||||
|
# `permissions` block at the top grants it write access to
|
||||||
|
# contents/releases for this run.
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
run: |
|
||||||
|
VERSION="${{ steps.version.outputs.value }}"
|
||||||
|
TAG="v${VERSION}"
|
||||||
|
BODY=$(cat <<'EOF'
|
||||||
|
Release automatically generated by the `release` workflow when the
|
||||||
|
`version` file was bumped.
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
curl -sS -X POST "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d @- <<JSON
|
||||||
|
{
|
||||||
|
"tag_name": "${TAG}",
|
||||||
|
"target_commitish": "main",
|
||||||
|
"name": "v${VERSION}",
|
||||||
|
"body": "${BODY}"
|
||||||
|
}
|
||||||
|
JSON
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
# Gitea Actions — Tests
|
||||||
|
#
|
||||||
|
# Dedicated test workflow: builds the application and runs the full test suite
|
||||||
|
# (ctest) on every push and pull request. Kept separate from the release
|
||||||
|
# workflow so a failing test never blocks a release.
|
||||||
|
|
||||||
|
name: tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-test:
|
||||||
|
runs-on: linux
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
# Host-mode runners execute jobs directly on the runner machine, so
|
||||||
|
# detect its package manager instead of hardcoding apt (which only
|
||||||
|
# exists on Debian/Ubuntu hosts).
|
||||||
|
if command -v pacman >/dev/null 2>&1; then
|
||||||
|
sudo pacman -S --noconfirm --needed \
|
||||||
|
git cmake gcc make qt6-base
|
||||||
|
elif command -v apt-get >/dev/null 2>&1; then
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y \
|
||||||
|
git cmake g++ make qt6-base-dev
|
||||||
|
elif command -v dnf >/dev/null 2>&1; then
|
||||||
|
sudo dnf install -y \
|
||||||
|
git cmake gcc-c++ make qt6-qtbase-devel
|
||||||
|
else
|
||||||
|
echo "Unsupported package manager: install git, cmake, a C++ compiler, make and Qt6 manually" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Configure
|
||||||
|
run: |
|
||||||
|
cmake -B build \
|
||||||
|
-DFWS_BUILD_EXAMPLE_PLUGIN=ON \
|
||||||
|
-DFWS_BUILD_EXAMPLE_ADDON=ON \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cmake --build build -j$(nproc)
|
||||||
|
|
||||||
|
- name: Run all tests
|
||||||
|
run: |
|
||||||
|
cd build
|
||||||
|
ctest --output-on-failure
|
||||||
@@ -1,8 +1,22 @@
|
|||||||
|
# Secrets and environment files
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
*.pem
|
||||||
|
*.key
|
||||||
|
*.p12
|
||||||
|
|
||||||
# Build directories
|
# Build directories
|
||||||
build/
|
build/
|
||||||
build_windows/
|
build_windows/
|
||||||
|
dist/
|
||||||
|
target/
|
||||||
.cache/
|
.cache/
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
vendor/
|
||||||
|
|
||||||
# Compiled objects
|
# Compiled objects
|
||||||
*.o
|
*.o
|
||||||
*.obj
|
*.obj
|
||||||
@@ -13,6 +27,10 @@ build_windows/
|
|||||||
*.dylib
|
*.dylib
|
||||||
*.exe
|
*.exe
|
||||||
|
|
||||||
|
# Python
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
|
||||||
# CMake
|
# CMake
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
CMakeFiles/
|
CMakeFiles/
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
# AGENTS.md — Instructions pour les agents IA
|
||||||
|
|
||||||
|
> Fichier de référence pour les agents IA (Codebuff, Cursor, Claude Code, GitHub Copilot…) qui travaillent sur un repo de l'organisation **FWS**. Un agent doit lire ce fichier en premier : il contient les instructions à respecter. Le `README.md` apporte le contexte complet.
|
||||||
|
|
||||||
|
## Contexte
|
||||||
|
|
||||||
|
- **FWS** est une organisation open source multi-projets : chaque projet choisit librement sa stack (pas de restriction de langage).
|
||||||
|
- Projet principal : **FWS Arch** — un fork d'Arch Linux avec une surcouche conviviale pour simplifier l'installation et l'usage au quotidien.
|
||||||
|
- Conventions détaillées : `README.md` (FR) / `README.en.md` (EN).
|
||||||
|
|
||||||
|
## Règles à respecter
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- Messages en **anglais**, format **Conventional Commits** : `<type>(<portée>): <description>`.
|
||||||
|
- Types autorisés : `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`.
|
||||||
|
- Titre court et impératif ; un corps n'est ajouté que pour expliquer le **pourquoi**, pas le comment.
|
||||||
|
|
||||||
|
### Nommage
|
||||||
|
|
||||||
|
- Branches : `type/description` (ex. `feat/login`, `fix/typo`).
|
||||||
|
- Fichiers : **kebab-case** (ex. `my-component.ts`).
|
||||||
|
- Identifiants (variables, fonctions, classes) : **anglais**.
|
||||||
|
|
||||||
|
### Code & commentaires
|
||||||
|
|
||||||
|
- Commentaires en **anglais**, style « pourquoi » : pas de commentaire si le code est explicite, documenter le non-évident (choix d'implémentation, trade-offs, cas limites).
|
||||||
|
- Respecter la stack et les conventions existantes du repo avant d'ajouter de nouvelles dépendances.
|
||||||
|
|
||||||
|
### Fichiers sensibles (`.gitignore`)
|
||||||
|
|
||||||
|
- Ne **jamais** committer : fichiers d'environnement (`.env*`), données d'assistants de développement (`.freebuff/`), artefacts compilés (`dist/`, `build/`, `target/`, `__pycache__/`…), dépendances (`node_modules/`), secrets.
|
||||||
|
- Un `.gitignore` doit exister à la racine de chaque repo.
|
||||||
|
|
||||||
|
### Tests
|
||||||
|
|
||||||
|
- Fichiers de test : `*.test.*`, noms `describe` / `it` en anglais.
|
||||||
|
- Vérifier que les tests (et le typecheck / lint quand ils existent) passent avant de considérer une tâche terminée.
|
||||||
|
|
||||||
|
### Issues & signalement de bugs
|
||||||
|
|
||||||
|
- Les bugs et demandes sont suivis via les **issues**, liées au tableau Kanban.
|
||||||
|
- Une PR qui corrige un bug référence l'issue dans son titre ou sa description (`Fixes #123`).
|
||||||
|
- Ne pas fermer ni modifier une issue sans demande explicite de l'utilisateur.
|
||||||
|
|
||||||
|
## Bonnes pratiques pour un agent
|
||||||
|
|
||||||
|
- Lire `AGENTS.md` puis `README.md` avant d'éditer du code.
|
||||||
|
- Faire les changements les plus petits possibles qui répondent à la demande.
|
||||||
|
- Ne pas pousser, merger ni publier sans demande explicite de l'utilisateur.
|
||||||
|
- Suivre les cartes du tableau Kanban du projet pour l'organisation du travail.
|
||||||
|
- En cas de doute, demander plutôt que deviner.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
project(PackageManager VERSION 1.0.0 LANGUAGES CXX)
|
project(PacManager VERSION 1.0.0 LANGUAGES CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
@@ -8,40 +8,162 @@ set(CMAKE_AUTORCC ON)
|
|||||||
set(CMAKE_AUTOUIC ON)
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
# Find Qt6
|
# Find Qt6
|
||||||
find_package(Qt6 REQUIRED COMPONENTS Widgets)
|
find_package(Qt6 REQUIRED COMPONENTS Widgets Network)
|
||||||
|
|
||||||
# Main executable
|
# Main executable
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/MainWindow.cpp
|
src/main-window.cpp
|
||||||
src/PluginManager.cpp
|
src/pacman-manager.cpp
|
||||||
src/HistoryManager.cpp
|
src/plugin-manager.cpp
|
||||||
src/PackageModel.cpp
|
src/history-manager.cpp
|
||||||
|
src/package-model.cpp
|
||||||
|
src/update-manager.cpp
|
||||||
|
resources/resources.qrc
|
||||||
)
|
)
|
||||||
|
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
include/IPackageManager.h
|
include/package-manager.h
|
||||||
include/MainWindow.h
|
include/pacman-manager.h
|
||||||
include/PluginManager.h
|
include/plugin-manager.h
|
||||||
include/HistoryManager.h
|
include/provider-plugin.h
|
||||||
include/PackageModel.h
|
include/main-window.h
|
||||||
|
include/history-manager.h
|
||||||
|
include/package-model.h
|
||||||
|
include/update-manager.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
|
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets)
|
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets Qt6::Network)
|
||||||
|
|
||||||
# Plugins
|
# Copy the version file next to the executable so UpdateManager can read the
|
||||||
add_subdirectory(plugins/pacman)
|
# running build's version at runtime.
|
||||||
add_subdirectory(plugins/apt)
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
add_subdirectory(plugins/pkg)
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
add_subdirectory(plugins/universal)
|
${CMAKE_CURRENT_SOURCE_DIR}/version
|
||||||
|
$<TARGET_FILE_DIR:${PROJECT_NAME}>/version)
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
||||||
|
install(FILES version DESTINATION bin)
|
||||||
install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME})
|
install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME})
|
||||||
|
|
||||||
# Plugin install directory
|
# Tests
|
||||||
set(PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}/plugins")
|
enable_testing()
|
||||||
install(CODE "file(MAKE_DIRECTORY \"\${PLUGIN_DIR}\")")
|
add_executable(pacman-manager-test tests/pacman-manager.test.cpp src/pacman-manager.cpp)
|
||||||
|
target_include_directories(pacman-manager-test PRIVATE include)
|
||||||
|
add_test(NAME pacman-manager-test COMMAND pacman-manager-test)
|
||||||
|
|
||||||
|
add_executable(flatpak-manager-test tests/flatpak-manager.test.cpp
|
||||||
|
plugins/flatpak-provider/flatpak-manager.cpp)
|
||||||
|
target_include_directories(flatpak-manager-test PRIVATE include plugins/flatpak-provider)
|
||||||
|
add_test(NAME flatpak-manager-test COMMAND flatpak-manager-test)
|
||||||
|
|
||||||
|
# Real end-to-end test of the Flatpak provider against the live flatpak CLI
|
||||||
|
# (installs and uninstalls a small app). Skipped when flatpak is missing.
|
||||||
|
add_executable(flatpak-integration-test tests/flatpak-integration.test.cpp
|
||||||
|
plugins/flatpak-provider/flatpak-manager.cpp)
|
||||||
|
target_include_directories(flatpak-integration-test PRIVATE include plugins/flatpak-provider)
|
||||||
|
add_test(NAME flatpak-integration-test COMMAND flatpak-integration-test)
|
||||||
|
|
||||||
|
add_executable(package-utils-test tests/package-utils.test.cpp)
|
||||||
|
target_include_directories(package-utils-test PRIVATE include)
|
||||||
|
add_test(NAME package-utils-test COMMAND package-utils-test)
|
||||||
|
|
||||||
|
# ---- Plugins ----
|
||||||
|
#
|
||||||
|
# Flatpak ships as an external provider plugin (not compiled into the binary):
|
||||||
|
# the produced .so is copied next to the executable and discovered at runtime
|
||||||
|
# by PluginManager, so it can be updated or removed independently of the core
|
||||||
|
# app. It is built by default, so a plain `cmake -B build` yields a
|
||||||
|
# Flatpak-enabled app; disable with -DFWS_BUILD_FLATPAK_PLUGIN=OFF.
|
||||||
|
option(FWS_BUILD_FLATPAK_PLUGIN "Build the Flatpak provider plugin" ON)
|
||||||
|
|
||||||
|
# Optional example external provider plugin. Demonstrates the plugin mechanism:
|
||||||
|
# the produced library is copied next to the executable and discovered at
|
||||||
|
# runtime by PluginManager (see the Plugins page).
|
||||||
|
option(FWS_BUILD_EXAMPLE_PLUGIN "Build the example external provider plugin" OFF)
|
||||||
|
|
||||||
|
# Optional example addon plugin: a non-provider extension (see
|
||||||
|
# plugins/example-addon) proving that plugins can be anything written in C++,
|
||||||
|
# not just package managers. Built next to the executable like any external
|
||||||
|
# plugin.
|
||||||
|
option(FWS_BUILD_EXAMPLE_ADDON "Build the example addon plugin" OFF)
|
||||||
|
|
||||||
|
if(FWS_BUILD_FLATPAK_PLUGIN)
|
||||||
|
add_library(flatpak-provider-plugin MODULE
|
||||||
|
plugins/flatpak-provider/flatpak-provider.cpp
|
||||||
|
plugins/flatpak-provider/flatpak-manager.cpp)
|
||||||
|
target_include_directories(flatpak-provider-plugin PRIVATE include plugins/flatpak-provider)
|
||||||
|
set_target_properties(flatpak-provider-plugin PROPERTIES
|
||||||
|
OUTPUT_NAME "flatpak-provider"
|
||||||
|
CXX_STANDARD 17
|
||||||
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
add_custom_command(TARGET flatpak-provider-plugin POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:PacManager>/plugins
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:flatpak-provider-plugin>
|
||||||
|
$<TARGET_FILE_DIR:PacManager>/plugins/)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FWS_BUILD_EXAMPLE_PLUGIN)
|
||||||
|
add_library(example-provider-plugin MODULE plugins/example-provider/example-provider.cpp)
|
||||||
|
target_include_directories(example-provider-plugin PRIVATE include)
|
||||||
|
set_target_properties(example-provider-plugin PROPERTIES
|
||||||
|
OUTPUT_NAME "sample-provider"
|
||||||
|
CXX_STANDARD 17
|
||||||
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
add_custom_command(TARGET example-provider-plugin POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:PacManager>/plugins
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:example-provider-plugin>
|
||||||
|
$<TARGET_FILE_DIR:PacManager>/plugins/)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FWS_BUILD_EXAMPLE_ADDON)
|
||||||
|
add_library(example-addon-plugin MODULE plugins/example-addon/example-addon.cpp)
|
||||||
|
target_include_directories(example-addon-plugin PRIVATE include)
|
||||||
|
# The demo addon attaches Qt widgets, so it links the widget module like
|
||||||
|
# the host application.
|
||||||
|
target_link_libraries(example-addon-plugin PRIVATE Qt6::Widgets)
|
||||||
|
set_target_properties(example-addon-plugin PROPERTIES
|
||||||
|
OUTPUT_NAME "sample-addon"
|
||||||
|
CXX_STANDARD 17
|
||||||
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
add_custom_command(TARGET example-addon-plugin POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:PacManager>/plugins
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:example-addon-plugin>
|
||||||
|
$<TARGET_FILE_DIR:PacManager>/plugins/)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Plugin manager test: needs Qt (QSettings/QLibrary) and the example plugins
|
||||||
|
# built next to the test binary, so it is only enabled with both plugin
|
||||||
|
# options.
|
||||||
|
if(FWS_BUILD_EXAMPLE_PLUGIN AND FWS_BUILD_EXAMPLE_ADDON)
|
||||||
|
add_executable(plugin-manager-test tests/plugin-manager.test.cpp
|
||||||
|
src/plugin-manager.cpp src/pacman-manager.cpp
|
||||||
|
plugins/flatpak-provider/flatpak-manager.cpp)
|
||||||
|
target_include_directories(plugin-manager-test PRIVATE include plugins/flatpak-provider)
|
||||||
|
# Qt6::Widgets is linked so the process can load the example addon, which
|
||||||
|
# itself links the widget module.
|
||||||
|
target_link_libraries(plugin-manager-test PRIVATE Qt6::Core Qt6::Widgets)
|
||||||
|
add_dependencies(plugin-manager-test example-provider-plugin example-addon-plugin)
|
||||||
|
add_custom_command(TARGET plugin-manager-test POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||||
|
$<TARGET_FILE_DIR:plugin-manager-test>/plugins
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
$<TARGET_FILE:example-provider-plugin>
|
||||||
|
$<TARGET_FILE_DIR:plugin-manager-test>/plugins/
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
$<TARGET_FILE:example-addon-plugin>
|
||||||
|
$<TARGET_FILE_DIR:plugin-manager-test>/plugins/)
|
||||||
|
if(FWS_BUILD_FLATPAK_PLUGIN)
|
||||||
|
target_compile_definitions(plugin-manager-test PRIVATE FWS_FLATPAK_PLUGIN_BUILT)
|
||||||
|
add_dependencies(plugin-manager-test flatpak-provider-plugin)
|
||||||
|
add_custom_command(TARGET plugin-manager-test POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
$<TARGET_FILE:flatpak-provider-plugin>
|
||||||
|
$<TARGET_FILE_DIR:plugin-manager-test>/plugins/)
|
||||||
|
endif()
|
||||||
|
add_test(NAME plugin-manager-test COMMAND plugin-manager-test)
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
LICENCE PACMANAGER (PROPRIÉTAIRE — SOURCE DISPONIBLE)
|
||||||
|
======================================================
|
||||||
|
|
||||||
|
Copyright © FWS — tous droits réservés.
|
||||||
|
|
||||||
|
La présente licence est personnelle et restrictive. Sa lecture remplace toute
|
||||||
|
autre mention : le code de ce dépôt N'EST PAS distribué ni sous licence libre.
|
||||||
|
Tout ce qui n'est pas expressément autorisé ci-dessous est interdit.
|
||||||
|
|
||||||
|
============================================================================
|
||||||
|
|
||||||
|
1. OBJET
|
||||||
|
|
||||||
|
Vous êtes autorisé à consulter, modifier et améliorer ce code pour votre
|
||||||
|
PROPRE USAGE, personnel et non commercial, sur vos propres machines.
|
||||||
|
|
||||||
|
2. USAGE PERSONNEL
|
||||||
|
|
||||||
|
Vous pouvez :
|
||||||
|
- cloner, lire et étudier le code source ;
|
||||||
|
- le modifier et l'améliorer pour vos besoins personnels ;
|
||||||
|
- compiler, exécuter et utiliser les versions modifiées chez vous ;
|
||||||
|
- conserver, pour votre usage personnel, toute copie de vos propres
|
||||||
|
modifications.
|
||||||
|
|
||||||
|
3. INTERDICTIONS STRICTES
|
||||||
|
|
||||||
|
Il vous est INTERDIT, sauf accord écrit exprès des auteurs (FWS) :
|
||||||
|
|
||||||
|
a. de DISTRIBUER, diffuser, publier, partager, transférer ou céder ce code,
|
||||||
|
modifié ou non, à qui que ce soit — y compris sous forme de copie,
|
||||||
|
d'archive, de lien public, de paquet, de plugin ou de binaire ;
|
||||||
|
|
||||||
|
b. de VENDRE, louer, céder à titre onéreux, monétiser ou tirer un quelconque
|
||||||
|
revenu de ce code, modifié ou non, directement ou indirectement ;
|
||||||
|
|
||||||
|
c. d'inclure ce code, modifié ou non, dans un autre projet, une autre
|
||||||
|
application, un service hébergé, un SaaS ou un produit commercial ;
|
||||||
|
|
||||||
|
d. d'utiliser ce code pour créer, partiellement ou entièrement, un produit
|
||||||
|
ou un service destiné à être distribué ou vendu à des tiers ;
|
||||||
|
|
||||||
|
e. de fournir ce code à des tiers pour qu'ils le réutilisent, l'utilisent ou
|
||||||
|
en dérivent un travail, même gratuitement ;
|
||||||
|
|
||||||
|
f. d'utiliser ce code dans un environnement de travail collaboratif,
|
||||||
|
d'entreprise ou à but lucratif sans accord écrit préalable de FWS.
|
||||||
|
|
||||||
|
4. PAS DE GARANTIE
|
||||||
|
|
||||||
|
Le code est fourni « en l'état », sans aucune garantie expresse ou
|
||||||
|
implicite, y compris sans garantie de qualité, d'adéquation à un usage
|
||||||
|
particulier ou d'absence de contrefaçon. L'auteur ne peut être tenu
|
||||||
|
responsable de tout dommage direct, indirect ou consécutif découlant de
|
||||||
|
l'utilisation ou de l'impossibilité d'utiliser ce code.
|
||||||
|
|
||||||
|
5. CESSATION
|
||||||
|
|
||||||
|
Toute violation de l'une des interdictions de l'article 3 entraîne la
|
||||||
|
résiliation IMMÉDIATE de la présente licence et de votre droit d'utiliser le
|
||||||
|
code.
|
||||||
|
|
||||||
|
6. DROITS CONSERVÉS
|
||||||
|
|
||||||
|
Tous les droits non expressément accordés dans cette licence sont conservés
|
||||||
|
par FWS. En particulier, FWS se réserve le droit exclusif de distribuer, de
|
||||||
|
publier, de vendre ou de licencier ce code.
|
||||||
|
|
||||||
|
7. DIVERS
|
||||||
|
|
||||||
|
La présente licence est régie par le droit applicable à FWS. Si une
|
||||||
|
disposition était jugée nulle, les autres resteraient pleinement en vigueur.
|
||||||
@@ -0,0 +1,233 @@
|
|||||||
|
# PacManager 📦
|
||||||
|
|
||||||
|
Package manager for **Arch Linux** based on **pacman**, with a Qt6 graphical interface.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- 🔍 **Package search**
|
||||||
|
- 📦 **Package installation**
|
||||||
|
- 🗑️ **Package removal**
|
||||||
|
- 🔄 **Individual or global updates**
|
||||||
|
- 📋 **History of all actions**
|
||||||
|
- 🧩 **Plugins**: package managers (pacman built-in, **Flatpak shipped by default**) and **extensions** written in C++ (UI addons, helpers, …)
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
package-manager/
|
||||||
|
├── CMakeLists.txt # Build root
|
||||||
|
├── include/
|
||||||
|
│ ├── package-manager.h # Package manager interface (IPackageManager)
|
||||||
|
│ ├── plugin.h # Generic plugin contract (PluginInfo, IPlugin)
|
||||||
|
│ ├── provider-plugin.h # C ABI contract for plugins (providers + addons)
|
||||||
|
│ ├── pacman-manager.h # pacman manager (Arch Linux, built-in)
|
||||||
|
│ ├── plugin-manager.h # Plugin registry + shared-library loading
|
||||||
|
│ ├── main-window.h # Main GUI
|
||||||
|
│ ├── history-manager.h # Action history
|
||||||
|
│ └── package-model.h # Qt model for the list
|
||||||
|
├── src/
|
||||||
|
│ ├── main.cpp
|
||||||
|
│ ├── main-window.cpp
|
||||||
|
│ ├── pacman-manager.cpp
|
||||||
|
│ ├── flatpak-manager.cpp
|
||||||
|
│ ├── plugin-manager.cpp
|
||||||
|
│ ├── history-manager.cpp
|
||||||
|
│ └── package-model.cpp
|
||||||
|
├── plugins/
|
||||||
|
│ ├── example-provider/ # Example external provider plugin (template)
|
||||||
|
│ ├── example-addon/ # Example external addon plugin (extension, template)
|
||||||
|
│ └── flatpak-provider/ # Flatpak plugin (loaded at runtime, built by default)
|
||||||
|
├── tests/ # Unit tests (assert, no Qt)
|
||||||
|
└── resources/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Compilation (Arch Linux)
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo pacman -S qt6-base cmake gcc base-devel
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd package-manager
|
||||||
|
|
||||||
|
# Configure and compile
|
||||||
|
cmake -B build -DFWS_BUILD_EXAMPLE_PLUGIN=ON
|
||||||
|
cmake --build build -j$(nproc)
|
||||||
|
```
|
||||||
|
|
||||||
|
The **Flatpak plugin is built by default** (`FWS_BUILD_FLATPAK_PLUGIN=ON`): a plain `cmake -B build` is enough to get a Flatpak-enabled app. Useful options:
|
||||||
|
|
||||||
|
- `-DFWS_BUILD_FLATPAK_PLUGIN=OFF`: skip the Flatpak plugin;
|
||||||
|
- `-DFWS_BUILD_EXAMPLE_ADDON=ON`: also build the example addon plugin (`build/plugins/libsample-addon.so`).
|
||||||
|
|
||||||
|
### Install
|
||||||
|
|
||||||
|
**User install** (recommended, no sudo — the binary goes to `~/.local/bin`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake --install build --prefix ~/.local
|
||||||
|
|
||||||
|
# To run `PacManager` from a terminal (optional):
|
||||||
|
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc # then restart your shell
|
||||||
|
```
|
||||||
|
|
||||||
|
**System install** (root, into `/usr/local/bin`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo cmake --install build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Show up in the app launcher (a real app, no command)
|
||||||
|
|
||||||
|
To make PacManager appear in the launcher of any desktop (wofi, GNOME, KDE...), like a pacman install:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p ~/.local/share/applications ~/.local/share/icons/hicolor/scalable/apps
|
||||||
|
cp resources/icons/package.svg ~/.local/share/icons/hicolor/scalable/apps/org.fws.PacManager.svg
|
||||||
|
cat > ~/.local/share/applications/org.fws.PacManager.desktop <<EOF
|
||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Name=PacManager
|
||||||
|
GenericName=Package Manager
|
||||||
|
Comment=Package manager for Arch Linux
|
||||||
|
Exec=$HOME/.local/bin/PacManager
|
||||||
|
Icon=org.fws.PacManager
|
||||||
|
Terminal=false
|
||||||
|
Categories=System;Utility;Qt;
|
||||||
|
Keywords=package;pacman;flatpak;install;update;
|
||||||
|
StartupNotify=true
|
||||||
|
EOF
|
||||||
|
update-desktop-database ~/.local/share/applications
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# From the build directory
|
||||||
|
./build/PacManager
|
||||||
|
|
||||||
|
# From the app launcher (recommended): $mod+R (Hyprland) or your application menu, type "PacManager"
|
||||||
|
|
||||||
|
# From a terminal, after install + PATH
|
||||||
|
PacManager
|
||||||
|
```
|
||||||
|
|
||||||
|
## Graphical interface
|
||||||
|
|
||||||
|
The interface uses **Qt6** with a dark theme, a **navigation sidebar** and stacked pages:
|
||||||
|
- 🏠 **Dashboard**: statistics cards, quick actions and recent activity
|
||||||
|
- 🔍 **Search**: search bar, package table on the left and details on the right
|
||||||
|
- 📦 **Installed**: list with **instant name filter** (local, no pacman re-run)
|
||||||
|
- ⬆️ **Updates**: outdated packages detected by `pacman -Qu`, "Update all" button
|
||||||
|
- 📋 **History**: filterable table (installs / removals / updates)
|
||||||
|
- 📜 **Logs**: built-in `/var/log/pacman.log` viewer
|
||||||
|
- 🧩 **Plugins**: lists every plugin (package providers and extensions), enable / disable and plugin rescan
|
||||||
|
|
||||||
|
### Interface overview
|
||||||
|
```text
|
||||||
|
┌──────────────────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ File Tools Help │
|
||||||
|
├───────────────┬──────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ 📦 PacManager │ Search │
|
||||||
|
│ │ Find and install packages │
|
||||||
|
│ 🏠 Dashboard │ ┌──────────────────────────────────────────────────┐ ┌────────────┐ │
|
||||||
|
│ 🔍 Search │ │ 🔍 Search for a package (e.g. firefox)... │ │ Search │ │
|
||||||
|
│ 📦 Installed │ └──────────────────────────────────────────────────┘ └────────────┘ │
|
||||||
|
│ ⬆️ Updates │ [+ Install] [- Remove] [^ Update] [^^ Update all] │
|
||||||
|
│ 📋 History │ ┌ Name │ Version │ Repo │ Status ┐ ┌────────────────────┐ │
|
||||||
|
│ 📜 Logs │ │ firefox │ 128.0 │ extra │ ✅ Installed │ │ firefox │ │
|
||||||
|
│ │ │ vlc │ 3.0.21 │ extra │ ✅ Installed │ │ Version: 128.0 │ │
|
||||||
|
│ │ │ ... │ │ │ │ │ [extra] [289 MB] │ │
|
||||||
|
│ │ └────────────────────────────────────────────┘ ├────────────────────┤ │
|
||||||
|
│ 🔄 Refresh │ │ Fast and secure │ │
|
||||||
|
├───────────────┴──────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ pacman 1.0.0 | Packages shown: 6 | History entries: 12 │
|
||||||
|
└──────────────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## Plugins & extensions
|
||||||
|
|
||||||
|
Two kinds of plugins coexist, both written in **C++**:
|
||||||
|
|
||||||
|
- **Providers** (`IPackageManager`): add a package manager (pacman built-in, Flatpak external, apt, dnf, …);
|
||||||
|
- **Extensions / addons** (`IPlugin`): anything else — a UI addon, a helper, a better loading experience… — with no relation to package management.
|
||||||
|
|
||||||
|
The `IPackageManager` interface (implemented by the built-in `PacmanManager` and the Flatpak plugin) defines:
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| `getName()` | Manager name |
|
||||||
|
| `getVersion()` | Manager version |
|
||||||
|
| `getDescription()` | Description |
|
||||||
|
| `canSearch()` | Supports search |
|
||||||
|
| `canInstall()` | Supports installation |
|
||||||
|
| `canRemove()` | Supports removal |
|
||||||
|
| `canUpdate()` | Supports updates |
|
||||||
|
| `canListInstalled()` | Supports listing installed packages |
|
||||||
|
| `isAvailable()` | Checks whether the tool is installed |
|
||||||
|
| `requiresPassword()` | True when operations go through sudo (pacman) |
|
||||||
|
| `search(query)` | Search for packages |
|
||||||
|
| `install(name, callback)` | Installation |
|
||||||
|
| `remove(name, callback)` | Removal |
|
||||||
|
| `update(name, callback)` | Update |
|
||||||
|
| `listInstalled()` | List installed packages |
|
||||||
|
| `listUpdates()` | List outdated packages |
|
||||||
|
| `refresh(callback)` | Refresh the sources |
|
||||||
|
|
||||||
|
Search queries **all active providers at once**: every result shows its origin in the **Provider** column (Pacman, Flatpak, …), and the Installed / Updates pages are aggregated. Install, remove and update are routed automatically to the right manager. The sidebar **Plugins** page lists everything (providers **and** addons), lets you enable / disable each plugin, rescan plugins and **install a missing tool** (e.g. "Install tool" for Flatpak runs `sudo pacman -S flatpak`, then the provider becomes available).
|
||||||
|
|
||||||
|
### Adding a plugin
|
||||||
|
|
||||||
|
**Pacman** is **built-in** (compiled into the application); **Flatpak** is an **external plugin** loaded at runtime from `plugins/` (`plugins/flatpak-provider`), next to the executable or in `~/.local/share/PacManager/plugins/`, and **built by default** (`FWS_BUILD_FLATPAK_PLUGIN=ON`). Flatpak installs auto-add the flathub remote when missing and fall back to a **per-user** install (no password) when the system-wide install fails (polkit, homonymous remotes) — the real error is shown on failure. An app installed via Flatpak appears immediately in the desktop launcher: its `.desktop` entries and icons are linked into `~/.local/share/applications` and `~/.local/share/icons` (the XDG dirs scanned by **every** environment: wofi, GNOME, KDE…), exactly like a pacman install, and are removed again on uninstall. Search shows the real status of each app (Installed / Update available). This is covered by an **integration test** that drives the real flatpak CLI (install, list, update, search, uninstall).
|
||||||
|
|
||||||
|
**Adding a provider** (apt, dnf, zypper, or another distro's repos) without touching the application:
|
||||||
|
|
||||||
|
1. Implement `IPackageManager` in a `.cpp` file (copy `plugins/example-provider/example-provider.cpp` as a template).
|
||||||
|
2. Export the C ABI contract with the `FWS_PROVIDER_PLUGIN(MyManager, "id", "Name", "1.0.0", "Description", "Author")` macro.
|
||||||
|
3. Compile it as a shared library and drop it into `~/.local/share/PacManager/plugins/` or `plugins/` next to the executable.
|
||||||
|
4. Click **Rescan** on the Plugins page.
|
||||||
|
|
||||||
|
**Adding an extension / addon** (anything, as long as it is C++):
|
||||||
|
|
||||||
|
1. Implement `IPlugin` in a `.cpp` file (copy `plugins/example-addon/example-addon.cpp` as a template). The `onLoad()` / `onUnload()` lifecycle hooks are called by the application, and `onUiReady(QMainWindow*)` hands you the main window to attach your own widgets (status bar, buttons, …).
|
||||||
|
2. Export the C ABI contract with the `FWS_ADDON_PLUGIN(MyAddon, "id", "Name", "1.0.0", "Description", "Author")` macro.
|
||||||
|
3. Compile it as a shared library and drop it into `~/.local/share/PacManager/plugins/` or `plugins/` next to the executable.
|
||||||
|
4. Click **Rescan** on the Plugins page.
|
||||||
|
|
||||||
|
Building the example plugins:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake -B build -DFWS_BUILD_EXAMPLE_PLUGIN=ON -DFWS_BUILD_EXAMPLE_ADDON=ON && cmake --build build
|
||||||
|
# build/plugins/libsample-provider.so and build/plugins/libsample-addon.so are copied next to the executable
|
||||||
|
```
|
||||||
|
|
||||||
|
The plugin must be compiled with the same compiler and headers as the application (like a regular Qt plugin).
|
||||||
|
|
||||||
|
## Development & conventions
|
||||||
|
|
||||||
|
This project follows the **FWS** organisation conventions, detailed in `AGENTS.md`:
|
||||||
|
|
||||||
|
- **Branches**: `type/description` (e.g. `feat/login`, `fix/typo`).
|
||||||
|
- **Commits**: message in **English**, **Conventional Commits** format `<type>(<scope>): <description>`. Allowed types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`. Short, imperative title; the body explains only the **why**.
|
||||||
|
- **Naming**: `kebab-case` files; identifiers (variables, functions, classes) in **English**.
|
||||||
|
- **Code & comments**: in **English**, "why" style (document the non-obvious — design choices, trade-offs — not the trivial).
|
||||||
|
- **Tests**: `*.test.*` files with `describe` / `it` names in English; run tests (and typecheck / lint when present) before considering a task done. Run them with `ctest` from `build/`.
|
||||||
|
- **Issues & bugs**: tracked through **issues** linked to the **Kanban** board; any PR fixing a bug references the issue (`Fixes #123`); do not close or modify an issue without explicit request.
|
||||||
|
- **Sensitive files (`.gitignore`)**: never commit `.env*`, `.freebuff/`, `build/` / `dist/` / `target/` / `__pycache__/`, `node_modules/`, secrets. A `.gitignore` exists at the repo root.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
**Proprietary — source available, personal use only.**
|
||||||
|
|
||||||
|
The code in this repository **may be improved and modified for your own personal use**, but it is **strictly forbidden to distribute or sell it**, in whole or in part, modified or not. See the [`LICENSE`](LICENSE) file for the full terms.
|
||||||
|
|
||||||
|
Summary:
|
||||||
|
|
||||||
|
- ✅ modify and improve the code for your **own personal use**;
|
||||||
|
- ❌ **distribute** or **share** the code, modified or not, with anyone;
|
||||||
|
- ❌ **sell**, lease, monetize or reuse the code in a commercial product;
|
||||||
|
- ❌ include the code in another project, hosted service or SaaS.
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
# PackageMapper 📦
|
# PacManager 📦
|
||||||
|
|
||||||
Gestionnaire de paquets unifié avec support d'extensions pour Arch Linux.
|
Gestionnaire de paquets pour **Arch Linux** basé sur **pacman**, avec interface graphique Qt6.
|
||||||
|
|
||||||
## Fonctionnalités
|
## Fonctionnalités
|
||||||
|
|
||||||
- 🔍 **Recherche globale** de paquets
|
- 🔍 **Recherche** de paquets
|
||||||
- 📦 **Installation** de paquets
|
- 📦 **Installation** de paquets
|
||||||
- 🗑️ **Suppression** de paquets
|
- 🗑️ **Suppression** de paquets
|
||||||
- 🔄 **Mise à jour** individuelle ou globale
|
- 🔄 **Mise à jour** individuelle ou globale
|
||||||
- 📋 **Historique** de toutes les actions
|
- 📋 **Historique** de toutes les actions
|
||||||
- 🔌 **Système de plugins** extensible (pacman, apt, pkg...)
|
- 🧩 **Plugins** : gestionnaires de paquets (pacman intégré, **Flatpak livré par défaut**) et **extensions** écrites en C++ (addons graphiques, helpers, …)
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
@@ -17,22 +17,28 @@ Gestionnaire de paquets unifié avec support d'extensions pour Arch Linux.
|
|||||||
package-manager/
|
package-manager/
|
||||||
├── CMakeLists.txt # Build root
|
├── CMakeLists.txt # Build root
|
||||||
├── include/
|
├── include/
|
||||||
│ ├── IPackageManager.h # Plugin interface
|
│ ├── package-manager.h # Interface du gestionnaire de paquets (IPackageManager)
|
||||||
│ ├── MainWindow.h # GUI principal
|
│ ├── plugin.h # Contrat générique des plugins (PluginInfo, IPlugin)
|
||||||
│ ├── PluginManager.h # Loader de plugins .so
|
│ ├── provider-plugin.h # Contrat C ABI des plugins (fournisseurs + addons)
|
||||||
│ ├── HistoryManager.h # Historique des actions
|
│ ├── pacman-manager.h # Gestionnaire pacman (Arch Linux, intégré)
|
||||||
│ └── PackageModel.h # Modèle Qt pour la liste
|
│ ├── plugin-manager.h # Registre des plugins + chargement des bibliothèques
|
||||||
|
│ ├── main-window.h # GUI principal
|
||||||
|
│ ├── history-manager.h # Historique des actions
|
||||||
|
│ └── package-model.h # Modèle Qt pour la liste
|
||||||
├── src/
|
├── src/
|
||||||
│ ├── main.cpp
|
│ ├── main.cpp
|
||||||
│ ├── MainWindow.cpp
|
│ ├── main-window.cpp
|
||||||
│ ├── PluginManager.cpp
|
│ ├── pacman-manager.cpp
|
||||||
│ ├── HistoryManager.cpp
|
│ ├── flatpak-manager.cpp
|
||||||
│ └── PackageModel.cpp
|
│ ├── plugin-manager.cpp
|
||||||
└── plugins/
|
│ ├── history-manager.cpp
|
||||||
├── pacman/ # Plugin Arch Linux (défaut)
|
│ └── package-model.cpp
|
||||||
├── apt/ # Plugin Debian/Ubuntu
|
├── plugins/
|
||||||
├── pkg/ # Plugin FreeBSD
|
│ ├── example-provider/ # Plugin fournisseur externe d'exemple (modèle à copier)
|
||||||
└── universal/ # Plugin universel (multi-source + compilation)
|
│ ├── example-addon/ # Plugin addon externe d'exemple (extension, modèle à copier)
|
||||||
|
│ └── flatpak-provider/ # Plugin Flatpak (chargé à l'exécution, construit par défaut)
|
||||||
|
├── tests/ # Tests unitaires (assert, sans Qt)
|
||||||
|
└── resources/
|
||||||
```
|
```
|
||||||
|
|
||||||
## Compilation (Arch Linux)
|
## Compilation (Arch Linux)
|
||||||
@@ -40,263 +46,188 @@ package-manager/
|
|||||||
### Dépendances
|
### Dépendances
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Qt6
|
|
||||||
sudo pacman -S qt6-base cmake gcc
|
|
||||||
|
|
||||||
# Ou tout d'un coup :
|
|
||||||
sudo pacman -S qt6-base cmake gcc base-devel
|
sudo pacman -S qt6-base cmake gcc base-devel
|
||||||
```
|
```
|
||||||
|
|
||||||
### Build
|
### Build
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Cloner ou copier le projet
|
|
||||||
cd package-manager
|
cd package-manager
|
||||||
|
|
||||||
# Créer le dossier de build
|
# Configurer + compiler
|
||||||
mkdir -p build && cd build
|
cmake -B build -DFWS_BUILD_EXAMPLE_PLUGIN=ON
|
||||||
|
cmake --build build -j$(nproc)
|
||||||
|
```
|
||||||
|
|
||||||
# Configurer
|
Le **plugin Flatpak est construit par défaut** (`FWS_BUILD_FLATPAK_PLUGIN=ON`) : un `cmake -B build` simple suffit pour obtenir une app avec Flatpak disponible. Options utiles :
|
||||||
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
|
|
||||||
|
|
||||||
# Compiler
|
- `-DFWS_BUILD_FLATPAK_PLUGIN=OFF` : ne pas construire le plugin Flatpak ;
|
||||||
make -j$(nproc)
|
- `-DFWS_BUILD_EXAMPLE_ADDON=ON` : construire aussi le plugin addon d'exemple (`build/plugins/libsample-addon.so`).
|
||||||
|
|
||||||
# Installer (optionnel)
|
### Installer
|
||||||
sudo make install
|
|
||||||
|
**Installation utilisateur** (recommandée, sans sudo — le binaire va dans `~/.local/bin`) :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake --install build --prefix ~/.local
|
||||||
|
|
||||||
|
# Pour lancer `PacManager` depuis un terminal (optionnel) :
|
||||||
|
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc # puis relancez votre shell
|
||||||
|
```
|
||||||
|
|
||||||
|
**Installation système** (root, dans `/usr/local/bin`) :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo cmake --install build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Apparaître dans le launcher (vraie app, sans commande)
|
||||||
|
|
||||||
|
Pour que PacManager s'affiche dans le launcher de n'importe quel bureau (wofi, GNOME, KDE…), comme une install pacman :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p ~/.local/share/applications ~/.local/share/icons/hicolor/scalable/apps
|
||||||
|
cp resources/icons/package.svg ~/.local/share/icons/hicolor/scalable/apps/org.fws.PacManager.svg
|
||||||
|
cat > ~/.local/share/applications/org.fws.PacManager.desktop <<EOF
|
||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Name=PacManager
|
||||||
|
GenericName=Package Manager
|
||||||
|
Comment=Gestionnaire de paquets pour Arch Linux
|
||||||
|
Exec=$HOME/.local/bin/PacManager
|
||||||
|
Icon=org.fws.PacManager
|
||||||
|
Terminal=false
|
||||||
|
Categories=System;Utility;Qt;
|
||||||
|
Keywords=package;pacman;flatpak;install;update;
|
||||||
|
StartupNotify=true
|
||||||
|
EOF
|
||||||
|
update-desktop-database ~/.local/share/applications
|
||||||
```
|
```
|
||||||
|
|
||||||
### Lancer
|
### Lancer
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Depuis le dossier build
|
# Depuis le dossier build
|
||||||
./PackageMapper
|
./build/PacManager
|
||||||
|
|
||||||
# Ou depuis /usr/bin après install
|
# Depuis le launcher (recommandé) : $mod+R (Hyprland) ou menu d'applications, tapez « PacManager »
|
||||||
PackageMapper
|
|
||||||
```
|
|
||||||
|
|
||||||
## Plugin Universal 🌍
|
# Depuis un terminal, après installation + PATH
|
||||||
|
PacManager
|
||||||
Le plugin **universal** est le plus puissant. Il essaie automatiquement **toutes les sources disponibles** :
|
|
||||||
|
|
||||||
### Sources supportées :
|
|
||||||
|
|
||||||
| Source | Commande | Description |
|
|
||||||
|--------|----------|-------------|
|
|
||||||
| **pacman** | `pacman -S` | Arch Linux natif |
|
|
||||||
| **apt** | `apt install` | Debian/Ubuntu |
|
|
||||||
| **dnf** | `dnf install` | Fedora/RHEL |
|
|
||||||
| **yum** | `yum install` | Ancien RHEL/CentOS |
|
|
||||||
| **zypper** | `zypper install` | openSUSE |
|
|
||||||
| **xbps** | `xbps-install` | Void Linux |
|
|
||||||
| **apk** | `apk add` | Alpine |
|
|
||||||
| **pkg** | `pkg install` | FreeBSD |
|
|
||||||
| **brew** | `brew install` | Homebrew (macOS/Linux) |
|
|
||||||
| **scoop** | `scoop install` | Windows |
|
|
||||||
| **Flatpak** | `flatpak install` | Cross-distro sandbox |
|
|
||||||
| **Snap** | `snap install` | Ubuntu/autres |
|
|
||||||
| **AUR** | `makepkg -si` | Arch User Repository |
|
|
||||||
| **Nix** | `nix-env -i` | NixOS/nixpkgs |
|
|
||||||
| **GitHub** | `git clone + build` | Auto-détecte le build system |
|
|
||||||
|
|
||||||
### Ordre de priorité :
|
|
||||||
|
|
||||||
1. Flatpak (si le paquet existe)
|
|
||||||
2. Snap (si le paquet existe)
|
|
||||||
3. AUR (si makepkg disponible)
|
|
||||||
4. Gestionnaire natif (pacman/apt/dnf/etc.)
|
|
||||||
5. Nix (si nix-env disponible)
|
|
||||||
6. **GitHub / Compilation source** (dernier recours)
|
|
||||||
|
|
||||||
### Compilation source automatique :
|
|
||||||
|
|
||||||
Si aucun paquet n'est trouvé, le plugin :
|
|
||||||
1. Cherche le repo GitHub le plus populaire
|
|
||||||
2. Clone le dépôt
|
|
||||||
3. Détecte le build system (CMake, Meson, Make, Cargo, Go, npm, pip)
|
|
||||||
4. Compile et installe automatiquement
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Installer le plugin universal
|
|
||||||
make universal_plugin
|
|
||||||
cp plugins/universal/libuniversal.so ~/.local/lib/PackageMapper/plugins/
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation des plugins
|
|
||||||
|
|
||||||
Les plugins sont des bibliothèques partagées `.so` qui s'auto-chargent.
|
|
||||||
|
|
||||||
### Emplacements recherchés (par ordre) :
|
|
||||||
1. `~/.local/lib/PackageMapper/plugins/`
|
|
||||||
2. `/usr/lib/PackageMapper/plugins/`
|
|
||||||
3. `/usr/local/lib/PackageMapper/plugins/`
|
|
||||||
4. `./plugins/` (relatif à l'exécutable)
|
|
||||||
|
|
||||||
### Compiler uniquement les plugins
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd build
|
|
||||||
make pacman_plugin
|
|
||||||
make apt_plugin
|
|
||||||
make pkg_plugin
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installer les plugins
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Pour l'utilisateur courant
|
|
||||||
mkdir -p ~/.local/lib/PackageMapper/plugins
|
|
||||||
cp build/plugins/pacman/libpacman.so ~/.local/lib/PackageMapper/plugins/
|
|
||||||
cp build/plugins/apt/libapt.so ~/.local/lib/PackageMapper/plugins/
|
|
||||||
cp build/plugins/pkg/libpkg.so ~/.local/lib/PackageMapper/plugins/
|
|
||||||
```
|
|
||||||
|
|
||||||
## Créer un plugin
|
|
||||||
|
|
||||||
Pour ajouter un nouveau gestionnaire de paquets :
|
|
||||||
|
|
||||||
1. Créer un dossier dans `plugins/votre_mgr/`
|
|
||||||
2. Créer un fichier CMakeLists.txt
|
|
||||||
3. Implémenter l'interface `IPackageManager`
|
|
||||||
4. Exporter les fonctions `createPlugin()` et `destroyPlugin()`
|
|
||||||
|
|
||||||
### Template minimal
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#include "IPackageManager.h"
|
|
||||||
|
|
||||||
class MonPlugin : public IPackageManager {
|
|
||||||
public:
|
|
||||||
std::string getName() const override { return "mon-gestionnaire"; }
|
|
||||||
std::string getVersion() const override { return "1.0.0"; }
|
|
||||||
std::string getDescription() const override { return "Description"; }
|
|
||||||
|
|
||||||
bool canSearch() const override { return true; }
|
|
||||||
bool canInstall() const override { return true; }
|
|
||||||
bool canRemove() const override { return true; }
|
|
||||||
bool canUpdate() const override { return true; }
|
|
||||||
bool canListInstalled() const override { return true; }
|
|
||||||
bool isAvailable() const override { return system("which mon_mgr > /dev/null 2>&1") == 0; }
|
|
||||||
|
|
||||||
std::vector<PackageInfo> search(const std::string& query) override {
|
|
||||||
// Implémenter la recherche
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool install(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
// Implémenter l'installation
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool remove(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool update(const std::string& packageName = "",
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> listInstalled() override { return {}; }
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
IPackageManager* createPlugin() { return new MonPlugin(); }
|
|
||||||
void destroyPlugin(IPackageManager* plugin) { delete plugin; }
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Interface graphique
|
## Interface graphique
|
||||||
|
|
||||||
L'interface utilise **Qt6** avec un thème sombre :
|
L'interface utilise **Qt6** avec un thème sombre, une **sidebar de navigation** et des pages empilées :
|
||||||
- Barre de recherche en haut
|
- 🏠 **Tableau de bord** : cartes de statistiques, actions rapides et activité récente
|
||||||
- Sélecteur de plugin
|
- 🔍 **Recherche** : barre de recherche, tableau de paquets à gauche et détails à droite
|
||||||
- Liste des paquets à gauche
|
- 📦 **Installés** : liste avec **filtre instantané** par nom (local, sans relancer pacman)
|
||||||
- Détails du paquet sélectionné à droite
|
- ⬆️ **Mises à jour** : paquets obsolètes détectés par `pacman -Qu`, bouton « Tout mettre à jour »
|
||||||
- Boutons d'action (installer, supprimer, mettre à jour)
|
- 📋 **Historique** : tableau filtrable (installations / suppressions / mises à jour)
|
||||||
- Barre de progression
|
- 📜 **Logs** : journal `/var/log/pacman.log` intégré
|
||||||
- Historique des actions
|
- 🧩 **Plugins** : liste de tous les plugins (fournisseurs de paquets et extensions), activation / désactivation et rechargement
|
||||||
- Menu avec raccourcis clavier
|
|
||||||
|
|
||||||
### Aperçu de l'interface
|
### Aperçu de l'interface
|
||||||
```text
|
```text
|
||||||
┌──────────────────────────────────────────────────────────────────────────────────────┐
|
┌──────────────────────────────────────────────────────────────────────────────────────┐
|
||||||
│ Fichier Outils Aide │
|
│ Fichier Outils Aide │
|
||||||
├──────────────────────────────────────────────────────────────────────────────────────┤
|
├───────────────┬──────────────────────────────────────────────────────────────────────┤
|
||||||
│ ┌───────────────┐ ┌─────────────────────────────────────────────┐ ┌────────────┐ │
|
│ 📦 PacManager │ Recherche │
|
||||||
│ │ pacman 1.0.0 v│ │ [?] Rechercher un paquet... │ │ Rechercher │ │
|
│ │ Trouvez et installez des paquets │
|
||||||
│ └───────────────┘ └─────────────────────────────────────────────┘ └────────────┘ │
|
│ 🏠 Tableau │ ┌──────────────────────────────────────────────────┐ ┌────────────┐ │
|
||||||
├──────────────────────────────────────────────────────────────────────────────────────┤
|
│ 🔍 Recherche │ │ 🔍 Rechercher un paquet (ex : firefox)... │ │ Rechercher │ │
|
||||||
│ [+ Installer] [- Supprimer] [^ Mettre a jour] [^^ Tout mettre a jour] │
|
│ 📦 Installés │ └──────────────────────────────────────────────────┘ └────────────┘ │
|
||||||
├──────────────────────────────────────────────────────────────────────────────────────┤
|
│ ⬆️ Mises à j. │ [+ Installer] [- Supprimer] [^ Mettre à jour] [^^ Tout mettre à j.] │
|
||||||
│ │
|
│ 📋 Historique │ ┌ Nom │ Version │ Dépôt │ Statut ┐ ┌────────────────────┐ │
|
||||||
│ ┌─────────────────────────────────┐ ┌────────────────────────────────────────────┐ │
|
│ 📜 Logs │ │ firefox │ 128.0 │ extra │ ✅ Installé │ │ firefox │ │
|
||||||
│ │ [x] firefox 128.0 │ │ │ │
|
│ │ │ vlc │ 3.0.21 │ extra │ ✅ Installé │ │ Version : 128.0 │ │
|
||||||
│ │ [V] Installe │ │ ╔══════════════════════════════════════╗ │ │
|
│ │ │ ... │ │ │ │ │ [extra] [289 Mo] │ │
|
||||||
│ ├─────────────────────────────────┤ │ ║ firefox ║ │ │
|
│ │ └────────────────────────────────────────────┘ ├────────────────────┤ │
|
||||||
│ │ [x] chromium 127.0.6533 │ │ ║ Version: 128.0 ║ │ │
|
│ 🔄 Rafraîchir │ │ Navigateur web... │ │
|
||||||
│ ├─────────────────────────────────┤ │ ║ Depot: extra ║ │ │
|
├───────────────┴──────────────────────────────────────────────────────────────────────┤
|
||||||
│ │ [x] vlc 3.0.21 │ │ ║ Taille: 289.4 MB ║ │ │
|
│ pacman 1.0.0 | Paquets affichés : 6 | Actions enregistrées : 12 │
|
||||||
│ │ [V] Installe [^] MAJ dispo │ │ ║ ║ │ │
|
|
||||||
│ ├─────────────────────────────────┤ │ ║ Navigateur web rapide et securise ║ │ │
|
|
||||||
│ │ [x] gimp 2.10.38 │ │ ║ base sur le moteur Gecko de ║ │ │
|
|
||||||
│ ├─────────────────────────────────┤ │ ║ Mozilla. ║ │ │
|
|
||||||
│ │ [x] neovim 0.10.1 │ │ ╚══════════════════════════════════════╝ │ │
|
|
||||||
│ ├─────────────────────────────────┤ │ │ │
|
|
||||||
│ │ [x] tmux 3.4 │ │ │ │
|
|
||||||
│ └─────────────────────────────────┘ └────────────────────────────────────────────┘ │
|
|
||||||
│ │
|
|
||||||
├──────────────────────────────────────────────────────────────────────────────────────┤
|
|
||||||
│ [# Rafraichir les sources] [@ Historique] │
|
|
||||||
├──────────────────────────────────────────────────────────────────────────────────────┤
|
|
||||||
│ Plugin: pacman | Paquets trouves: 6 | Elements en historique: 12 │
|
|
||||||
└──────────────────────────────────────────────────────────────────────────────────────┘
|
└──────────────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
Legende: [x] = paquet [V] = installe [^] = mise a jour disponible
|
|
||||||
```
|
|
||||||
|
|
||||||
### Fenêtre Historique
|
|
||||||
```text
|
|
||||||
┌────────────────────────────────────────────────────────┐
|
|
||||||
│ [=] Historique des actions │
|
|
||||||
├────────────────────────────────────────────────────────┤
|
|
||||||
│ ┌──────────────────────────────────────────────────┐ │
|
|
||||||
│ │ [2026-08-24 14:32:01] install: firefox (pacman) │ │
|
|
||||||
│ │ [2026-08-24 14:32:15] install: vim (pacman) │ │
|
|
||||||
│ │ [2026-08-24 14:33:02] update: vlc (pacman) │ │
|
|
||||||
│ │ [2026-08-24 14:35:10] remove: gimp (pacman) │ │
|
|
||||||
│ │ [2026-08-24 14:40:22] install: neovim (pacman) │ │
|
|
||||||
│ └──────────────────────────────────────────────────┘ │
|
|
||||||
│ │
|
|
||||||
│ ┌──────────────────────────┐ │
|
|
||||||
│ │ [-] Effacer l'historique │ │
|
|
||||||
│ └──────────────────────────┘ │
|
|
||||||
└────────────────────────────────────────────────────────┘
|
|
||||||
```
|
```
|
||||||
## Héritage des plugins
|
|
||||||
|
|
||||||
L'interface `IPackageManager` définit :
|
## Plugins & extensions
|
||||||
|
|
||||||
|
Deux types de plugins coexistent, tous deux écrits en **C++** :
|
||||||
|
|
||||||
|
- **Fournisseurs** (`IPackageManager`) : ajoutent un gestionnaire de paquets (pacman intégré, Flatpak externe, apt, dnf, …) ;
|
||||||
|
- **Extensions / addons** (`IPlugin`) : tout le reste — addon graphique, helper, amélioration du chargement… — sans rapport avec la gestion de paquets.
|
||||||
|
|
||||||
|
L'interface `IPackageManager` (implémentée par `PacmanManager` et `FlatpakManager`) définit :
|
||||||
|
|
||||||
| Méthode | Description |
|
| Méthode | Description |
|
||||||
|---------|-------------|
|
|---------|-------------|
|
||||||
| `getName()` | Nom du gestionnaire |
|
| `getName()` | Nom du gestionnaire |
|
||||||
| `getVersion()` | Version du plugin |
|
| `getVersion()` | Version du gestionnaire |
|
||||||
| `getDescription()` | Description |
|
| `getDescription()` | Description |
|
||||||
| `canSearch()` | Supporte la recherche |
|
| `canSearch()` | Supporte la recherche |
|
||||||
| `canInstall()` | Supporte l'installation |
|
| `canInstall()` | Supporte l'installation |
|
||||||
| `canRemove()` | Supporte la suppression |
|
| `canRemove()` | Supporte la suppression |
|
||||||
| `canUpdate()` | Supporte la mise à jour |
|
| `canUpdate()` | Supporte la mise à jour |
|
||||||
| `canListInstalled()` | Supporte le listage |
|
| `canListInstalled()` | Supporte le listage |
|
||||||
| `isAvailable()` | Vérifie si le gestionnaire est installé |
|
| `isAvailable()` | Vérifie si l'outil est installé |
|
||||||
|
| `requiresPassword()` | Oui si les opérations passent par sudo (pacman) |
|
||||||
| `search(query)` | Recherche de paquets |
|
| `search(query)` | Recherche de paquets |
|
||||||
| `install(name, callback)` | Installation |
|
| `install(name, callback)` | Installation |
|
||||||
| `remove(name, callback)` | Suppression |
|
| `remove(name, callback)` | Suppression |
|
||||||
| `update(name, callback)` | Mise à jour |
|
| `update(name, callback)` | Mise à jour |
|
||||||
| `listInstalled()` | Liste des paquets installés |
|
| `listInstalled()` | Liste des paquets installés |
|
||||||
|
| `listUpdates()` | Liste des paquets obsolètes |
|
||||||
|
| `refresh(callback)` | Rafraîchit les sources |
|
||||||
|
|
||||||
|
La recherche interroge **tous les fournisseurs actifs à la fois** : chaque résultat porte sa provenance dans la colonne **Fournisseur** (Pacman, Flatpak, …) et les pages Installés / Mises à jour sont agrégées. Installation, suppression et mise à jour sont routées automatiquement vers le bon gestionnaire. La page **Plugins** de la barre latérale liste tout (fournisseurs **et** addons), permet d'activer / désactiver chaque plugin, de recharger les plugins et d'**installer l'outil manquant** (ex. « Installer l'outil » pour Flatpak lance `sudo pacman -S flatpak` puis rend le fournisseur disponible).
|
||||||
|
|
||||||
|
### Ajouter un plugin
|
||||||
|
|
||||||
|
**Pacman** est **intégré** (compilé dans l'application) ; **Flatpak** est un **plugin externe** chargé à l'exécution depuis `plugins/` (`plugins/flatpak-provider`), à côté de l'exécutable ou dans `~/.local/share/PacManager/plugins/`, et **construit par défaut** (`FWS_BUILD_FLATPAK_PLUGIN=ON`). L'installation Flatpak ajoute automatiquement le dépôt flathub si besoin et retombe en installation **utilisateur** (sans mot de passe) quand l'installation système échoue (polkit, plusieurs dépôts homonymes) — l'erreur réelle est affichée en cas d'échec. Une app installée via Flatpak apparaît immédiatement dans le launcher du bureau : ses entrées `.desktop` et ses icônes sont liées dans `~/.local/share/applications` et `~/.local/share/icons` (les dossiers XDG scannés par **tout** environnement : wofi, GNOME, KDE…), exactement comme une installation pacman, et retirées à la désinstallation. La recherche affiche le statut réel de chaque app (Installé / Mise à jour disponible). Le tout est couvert par un **test d'intégration** qui pilote le vrai CLI flatpak (install, liste, mise à jour, recherche, désinstallation).
|
||||||
|
|
||||||
|
**Ajouter un fournisseur** (apt, dnf, zypper, ou les dépôts d'une autre distro) sans toucher à l'application :
|
||||||
|
|
||||||
|
1. Implémentez `IPackageManager` dans un fichier `.cpp` (copiez `plugins/example-provider/example-provider.cpp` comme modèle).
|
||||||
|
2. Exportez le contrat C ABI avec la macro `FWS_PROVIDER_PLUGIN(MyManager, "id", "Nom", "1.0.0", "Description", "Auteur")`.
|
||||||
|
3. Compilez en bibliothèque partagée et déposez-la dans `~/.local/share/PacManager/plugins/` ou `plugins/` à côté de l'exécutable.
|
||||||
|
4. Cliquez sur **Recharger** dans la page Plugins.
|
||||||
|
|
||||||
|
**Ajouter une extension / addon** (n'importe quoi, tant que c'est du C++) :
|
||||||
|
|
||||||
|
1. Implémentez `IPlugin` dans un fichier `.cpp` (copiez `plugins/example-addon/example-addon.cpp` comme modèle). Les hooks de cycle de vie `onLoad()` / `onUnload()` sont appelés par l'application, et `onUiReady(QMainWindow*)` vous donne la fenêtre principale pour attacher vos widgets (barre de statut, boutons, …).
|
||||||
|
2. Exportez le contrat C ABI avec la macro `FWS_ADDON_PLUGIN(MyAddon, "id", "Nom", "1.0.0", "Description", "Auteur")`.
|
||||||
|
3. Compilez en bibliothèque partagée et déposez-la dans `~/.local/share/PacManager/plugins/` ou `plugins/` à côté de l'exécutable.
|
||||||
|
4. Cliquez sur **Recharger** dans la page Plugins.
|
||||||
|
|
||||||
|
Build des plugins d'exemple :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake -B build -DFWS_BUILD_EXAMPLE_PLUGIN=ON -DFWS_BUILD_EXAMPLE_ADDON=ON && cmake --build build
|
||||||
|
# build/plugins/libsample-provider.so et build/plugins/libsample-addon.so sont copiés à côté de l'exécutable
|
||||||
|
```
|
||||||
|
|
||||||
|
Le plugin doit être compilé avec le même compilateur et les mêmes en-têtes que l'application (comme un plugin Qt classique).
|
||||||
|
|
||||||
|
## Développement & conventions
|
||||||
|
|
||||||
|
Ce projet suit les conventions de l'organisation **FWS**, détaillées dans `AGENTS.md` :
|
||||||
|
|
||||||
|
- **Branches** : `type/description` (ex. `feat/login`, `fix/typo`).
|
||||||
|
- **Commits** : message en **anglais**, format **Conventional Commits** `<type>(<portée>): <description>`. Types autorisés : `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`. Titre court et impératif ; le corps n'explique que le **pourquoi**.
|
||||||
|
- **Fichiers** : `kebab-case` ; identifiants (variables, fonctions, classes) en **anglais**.
|
||||||
|
- **Code & commentaires** : en **anglais**, style « pourquoi » (documenter le non-évident — choix d'implémentation, trade-offs —, pas le banal).
|
||||||
|
- **Tests** : fichiers `*.test.*` avec noms `describe` / `it` en anglais ; les tests (et le typecheck / lint quand ils existent) doivent passer avant de considérer une tâche terminée. Lancez-les avec `ctest` depuis `build/`.
|
||||||
|
- **Issues & bugs** : suivis via les **issues** liées au tableau **Kanban** ; toute PR corrigeant un bug référence l'issue (`Fixes #123`) ; ne pas fermer ni modifier une issue sans demande explicite.
|
||||||
|
- **Fichiers sensibles (`.gitignore`)** : ne jamais committer `.env*`, `.freebuff/`, `build/` / `dist/` / `target/` / `__pycache__/`, `node_modules/`, secrets. Un `.gitignore` existe à la racine du repo.
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
Coming soon
|
**Propriétaire — source disponible, usage personnel uniquement.**
|
||||||
|
|
||||||
|
Le code de ce dépôt **peut être amélioré et modifié pour votre propre usage**, mais il est **strictement interdit de le distribuer ou de le vendre**, en tout ou en partie, modifié ou non. Voir le fichier [`LICENSE`](LICENSE) pour les conditions complètes.
|
||||||
|
|
||||||
|
Résumé :
|
||||||
|
|
||||||
|
- ✅ modifier et améliorer le code pour votre **usage personnel** ;
|
||||||
|
- ❌ **distribuer** ou **diffuser** le code, modifié ou non, à qui que ce soit ;
|
||||||
|
- ❌ **vendre**, louer, monétiser ou réutiliser le code dans un produit/commercial ;
|
||||||
|
- ❌ inclure le code dans un autre projet, service hébergé ou SaaS.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "🔨 Compilation de PackageMapper..."
|
echo "🔨 Compilation de PacManager..."
|
||||||
|
|
||||||
# Create build directory
|
# Create build directory
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
@@ -19,12 +19,8 @@ echo ""
|
|||||||
echo "✅ Compilation terminée !"
|
echo "✅ Compilation terminée !"
|
||||||
echo ""
|
echo ""
|
||||||
echo "📋 Pour lancer :"
|
echo "📋 Pour lancer :"
|
||||||
echo " ./PackageMapper"
|
echo " ./PacManager"
|
||||||
echo ""
|
echo ""
|
||||||
echo "📋 Pour installer :"
|
echo "📋 Pour installer :"
|
||||||
echo " sudo make install"
|
echo " sudo make install"
|
||||||
echo ""
|
echo ""
|
||||||
echo "📋 Pour copier les plugins (user mode) :"
|
|
||||||
echo " mkdir -p ~/.local/lib/PackageMapper/plugins"
|
|
||||||
echo " cp plugins/*/lib*.so ~/.local/lib/PackageMapper/plugins/"
|
|
||||||
echo ""
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
@echo off
|
@echo off
|
||||||
echo ============================================
|
echo ============================================
|
||||||
echo PackageMapper - Build Windows
|
echo PacManager - Build Windows
|
||||||
echo ============================================
|
echo ============================================
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
@@ -38,20 +38,16 @@ if errorlevel 1 (
|
|||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo [3/4] Copie des DLLs...
|
echo [3/4] Copie des DLLs...
|
||||||
"%MSYS2_SHELL%" -defterm -no-start -mingw64 -c "cd /e/dev/gestionnaire/build_windows && ldd PackageManager.exe 2>/dev/null | grep 'mingw64' | awk '{print $3}' | while read dll; do cp \"$dll\" . 2>/dev/null; done"
|
"%MSYS2_SHELL%" -defterm -no-start -mingw64 -c "cd /e/dev/gestionnaire/build_windows && ldd PacManager.exe 2>/dev/null | grep 'mingw64' | awk '{print $3}' | while read dll; do cp \"$dll\" . 2>/dev/null; done"
|
||||||
|
|
||||||
echo.
|
|
||||||
echo [4/4] Copie des DLLs des plugins...
|
|
||||||
"%MSYS2_SHELL%" -defterm -no-start -mingw64 -c "cd /e/dev/gestionnaire/build_windows && for plugin in plugins/*/*.dll; do ldd \"$plugin\" 2>/dev/null | grep 'mingw64' | awk '{print $3}' | while read dll; do cp \"$dll\" . 2>/dev/null; done; done"
|
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ============================================
|
echo ============================================
|
||||||
echo BUILD REUSSI !
|
echo BUILD REUSSI !
|
||||||
echo Executable : build_windows\PackageManager.exe
|
echo Executable : build_windows\PacManager.exe
|
||||||
echo ============================================
|
echo ============================================
|
||||||
echo.
|
echo.
|
||||||
echo Pour lancer :
|
echo Pour lancer :
|
||||||
echo cd build_windows
|
echo cd build_windows
|
||||||
echo PackageManager.exe
|
echo PacManager.exe
|
||||||
echo.
|
echo.
|
||||||
pause
|
pause
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
// Information about a single package
|
|
||||||
struct PackageInfo {
|
|
||||||
std::string name;
|
|
||||||
std::string version;
|
|
||||||
std::string description;
|
|
||||||
std::string repository;
|
|
||||||
std::string size;
|
|
||||||
std::string installedSize;
|
|
||||||
bool installed = false;
|
|
||||||
bool updateAvailable = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Abstract interface for all package manager plugins
|
|
||||||
class IPackageManager {
|
|
||||||
public:
|
|
||||||
virtual ~IPackageManager() = default;
|
|
||||||
|
|
||||||
// Identity
|
|
||||||
virtual std::string getName() const = 0;
|
|
||||||
virtual std::string getVersion() const = 0;
|
|
||||||
virtual std::string getDescription() const = 0;
|
|
||||||
|
|
||||||
// Capabilities
|
|
||||||
virtual bool canSearch() const = 0;
|
|
||||||
virtual bool canInstall() const = 0;
|
|
||||||
virtual bool canRemove() const = 0;
|
|
||||||
virtual bool canUpdate() const = 0;
|
|
||||||
virtual bool canListInstalled() const = 0;
|
|
||||||
|
|
||||||
// Operations
|
|
||||||
virtual std::vector<PackageInfo> search(const std::string& query) = 0;
|
|
||||||
virtual bool install(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
|
||||||
virtual bool remove(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
|
||||||
virtual bool update(const std::string& packageName = "",
|
|
||||||
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
|
||||||
virtual std::vector<PackageInfo> listInstalled() = 0;
|
|
||||||
|
|
||||||
// Check if the package manager is available on the system
|
|
||||||
virtual bool isAvailable() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Plugin entry point types
|
|
||||||
extern "C" {
|
|
||||||
IPackageManager* createPlugin();
|
|
||||||
void destroyPlugin(IPackageManager* plugin);
|
|
||||||
}
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include <QStackedWidget>
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QListWidget>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QComboBox>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QProgressBar>
|
|
||||||
#include <QStatusBar>
|
|
||||||
#include <QMenuBar>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QAction>
|
|
||||||
#include <QTabWidget>
|
|
||||||
#include <QTextEdit>
|
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
#include "IPackageManager.h"
|
|
||||||
#include "PluginManager.h"
|
|
||||||
#include "HistoryManager.h"
|
|
||||||
#include "PackageModel.h"
|
|
||||||
|
|
||||||
class SearchWorker : public QThread {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
SearchWorker(IPackageManager* pm, const std::string& query);
|
|
||||||
void run() override;
|
|
||||||
signals:
|
|
||||||
void finished(std::vector<PackageInfo> results);
|
|
||||||
private:
|
|
||||||
IPackageManager* m_pm;
|
|
||||||
std::string m_query;
|
|
||||||
};
|
|
||||||
|
|
||||||
class InstallWorker : public QThread {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
InstallWorker(IPackageManager* pm, const std::string& package, bool remove = false);
|
|
||||||
void run() override;
|
|
||||||
signals:
|
|
||||||
void progress(const QString& message);
|
|
||||||
void finished(bool success);
|
|
||||||
private:
|
|
||||||
IPackageManager* m_pm;
|
|
||||||
std::string m_package;
|
|
||||||
bool m_remove;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit MainWindow(QWidget* parent = nullptr);
|
|
||||||
~MainWindow();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onSearch();
|
|
||||||
void onInstall();
|
|
||||||
void onRemove();
|
|
||||||
void onUpdate();
|
|
||||||
void onUpdateAll();
|
|
||||||
void onRefresh();
|
|
||||||
void onPluginChanged(int index);
|
|
||||||
void onSearchFinished(std::vector<PackageInfo> results);
|
|
||||||
void onInstallFinished(bool success);
|
|
||||||
void onPackageSelected(int row);
|
|
||||||
void onToggleInstalledView();
|
|
||||||
void onShowHistory();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setupUI();
|
|
||||||
void setupMenuBar();
|
|
||||||
void updatePackageInfo(const PackageInfo& pkg);
|
|
||||||
void updateStatusBar();
|
|
||||||
void loadPlugins();
|
|
||||||
void performSearch(const std::string& query);
|
|
||||||
void performInstall(const std::string& package);
|
|
||||||
void performRemove(const std::string& package);
|
|
||||||
|
|
||||||
// UI Elements
|
|
||||||
QLineEdit* m_searchBar;
|
|
||||||
QPushButton* m_searchButton;
|
|
||||||
QComboBox* m_pluginSelector;
|
|
||||||
QListWidget* m_packageList;
|
|
||||||
QLabel* m_packageName;
|
|
||||||
QLabel* m_packageVersion;
|
|
||||||
QLabel* m_packageRepo;
|
|
||||||
QLabel* m_packageSize;
|
|
||||||
QLabel* m_packageDescription;
|
|
||||||
QPushButton* m_installButton;
|
|
||||||
QPushButton* m_removeButton;
|
|
||||||
QPushButton* m_updateButton;
|
|
||||||
QPushButton* m_updateAllButton;
|
|
||||||
QPushButton* m_refreshButton;
|
|
||||||
QPushButton* m_historyButton;
|
|
||||||
QProgressBar* m_progressBar;
|
|
||||||
QTabWidget* m_mainTabs;
|
|
||||||
QTextEdit* m_historyView;
|
|
||||||
QStackedWidget* m_stackedWidget;
|
|
||||||
|
|
||||||
// Backend
|
|
||||||
PluginManager* m_pluginManager;
|
|
||||||
HistoryManager* m_historyManager;
|
|
||||||
PackageModel* m_packageModel;
|
|
||||||
IPackageManager* m_currentPlugin;
|
|
||||||
|
|
||||||
std::vector<PackageInfo> m_currentResults;
|
|
||||||
PackageInfo m_selectedPackage;
|
|
||||||
};
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "dynlib.h"
|
|
||||||
#include "IPackageManager.h"
|
|
||||||
|
|
||||||
struct PluginInfo {
|
|
||||||
std::string path;
|
|
||||||
std::string name;
|
|
||||||
IPackageManager* instance = nullptr;
|
|
||||||
dynlib_handle handle = nullptr;
|
|
||||||
bool loaded = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PluginManager {
|
|
||||||
public:
|
|
||||||
PluginManager();
|
|
||||||
~PluginManager();
|
|
||||||
|
|
||||||
// Load plugins from a directory
|
|
||||||
void loadPluginsFromDirectory(const std::string& directory);
|
|
||||||
|
|
||||||
// Load a specific plugin
|
|
||||||
bool loadPlugin(const std::string& path);
|
|
||||||
|
|
||||||
// Unload all plugins
|
|
||||||
void unloadAll();
|
|
||||||
|
|
||||||
// Get loaded plugins
|
|
||||||
const std::vector<PluginInfo>& getPlugins() const;
|
|
||||||
|
|
||||||
// Get a plugin by index
|
|
||||||
IPackageManager* getPlugin(size_t index) const;
|
|
||||||
|
|
||||||
// Get plugin count
|
|
||||||
size_t getPluginCount() const;
|
|
||||||
|
|
||||||
// Find plugin by name
|
|
||||||
IPackageManager* findPlugin(const std::string& name) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<PluginInfo> m_plugins;
|
|
||||||
std::vector<std::string> m_searchPaths;
|
|
||||||
};
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
typedef HMODULE dynlib_handle;
|
|
||||||
inline dynlib_handle dynlib_open(const char* path) { return LoadLibraryA(path); }
|
|
||||||
inline void* dynlib_sym(dynlib_handle h, const char* name) { return (void*)GetProcAddress(h, name); }
|
|
||||||
inline void dynlib_close(dynlib_handle h) { FreeLibrary(h); }
|
|
||||||
inline const char* dynlib_error() {
|
|
||||||
static char buf[256];
|
|
||||||
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buf, sizeof(buf), NULL);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#include <dlfcn.h>
|
|
||||||
typedef void* dynlib_handle;
|
|
||||||
inline dynlib_handle dynlib_open(const char* path) { return dlopen(path, RTLD_NOW); }
|
|
||||||
inline void* dynlib_sym(dynlib_handle h, const char* name) { return dlsym(h, name); }
|
|
||||||
inline void dynlib_close(dynlib_handle h) { dlclose(h); }
|
|
||||||
inline const char* dynlib_error() { return dlerror(); }
|
|
||||||
#endif
|
|
||||||
@@ -17,7 +17,7 @@ struct HistoryEntry {
|
|||||||
|
|
||||||
class HistoryManager {
|
class HistoryManager {
|
||||||
public:
|
public:
|
||||||
HistoryManager(const std::string& historyFile = "~/.local/share/PackageMapper/history.csv");
|
HistoryManager(const std::string& historyFile = "~/.local/share/PacManager/history.csv");
|
||||||
~HistoryManager();
|
~HistoryManager();
|
||||||
|
|
||||||
void record(const HistoryEntry& entry);
|
void record(const HistoryEntry& entry);
|
||||||
@@ -0,0 +1,245 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QProgressBar>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "package-manager.h"
|
||||||
|
#include "pacman-manager.h"
|
||||||
|
#include "plugin-manager.h"
|
||||||
|
#include "history-manager.h"
|
||||||
|
#include "update-manager.h"
|
||||||
|
|
||||||
|
class QStackedWidget;
|
||||||
|
class QTableWidget;
|
||||||
|
class QTextEdit;
|
||||||
|
class QListWidget;
|
||||||
|
class QListWidgetItem;
|
||||||
|
class QButtonGroup;
|
||||||
|
class QFrame;
|
||||||
|
class QAction;
|
||||||
|
|
||||||
|
// Runs a package search off the UI thread. Queries every given provider and
|
||||||
|
// merges the results, tagging each package with its provider id.
|
||||||
|
class SearchWorker : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
SearchWorker(const std::vector<IPackageManager*>& providers, const std::string& query);
|
||||||
|
void run() override;
|
||||||
|
signals:
|
||||||
|
void finished(std::vector<PackageInfo> results);
|
||||||
|
// Emitted as search results are accumulated, so a few packages can be
|
||||||
|
// shown immediately while the remaining searches keep running.
|
||||||
|
void chunk(std::vector<PackageInfo> results);
|
||||||
|
private:
|
||||||
|
std::vector<IPackageManager*> m_providers;
|
||||||
|
std::string m_query;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Loads a package list (installed or outdated) off the UI thread, aggregated
|
||||||
|
// across every given provider.
|
||||||
|
class ListWorker : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum Mode { Installed, Updates };
|
||||||
|
ListWorker(const std::vector<IPackageManager*>& providers, Mode mode);
|
||||||
|
void run() override;
|
||||||
|
signals:
|
||||||
|
void finished(std::vector<PackageInfo> results);
|
||||||
|
private:
|
||||||
|
std::vector<IPackageManager*> m_providers;
|
||||||
|
Mode m_mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Runs install/remove/update/refresh actions off the UI thread. Single-package
|
||||||
|
// operations take one provider; UpdateAll/Refresh take every provider and run
|
||||||
|
// on each of them in sequence.
|
||||||
|
class InstallWorker : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum class Op { Install, Remove, Update, UpdateAll, Refresh };
|
||||||
|
InstallWorker(IPackageManager* pm, Op op, const std::string& package);
|
||||||
|
InstallWorker(const std::vector<IPackageManager*>& providers, Op op);
|
||||||
|
void run() override;
|
||||||
|
signals:
|
||||||
|
void progress(const QString& message);
|
||||||
|
// Real download percentage (0-100) when the provider reports it, used to
|
||||||
|
// fill the determinate progress bar in the status bar.
|
||||||
|
void progressValue(int percent);
|
||||||
|
void finished(bool success);
|
||||||
|
private:
|
||||||
|
std::vector<IPackageManager*> m_providers;
|
||||||
|
Op m_op;
|
||||||
|
std::string m_package;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit MainWindow(QWidget* parent = nullptr);
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onSearch();
|
||||||
|
void onInstall();
|
||||||
|
void onRemove();
|
||||||
|
void onUpdate();
|
||||||
|
void onUpdateAll();
|
||||||
|
void onRefresh();
|
||||||
|
void onSearchFinished(std::vector<PackageInfo> results);
|
||||||
|
void onSearchChunk(std::vector<PackageInfo> results);
|
||||||
|
void onListFinished(std::vector<PackageInfo> results);
|
||||||
|
void onInstallProgress(int percent);
|
||||||
|
void onPackageSelected(int row);
|
||||||
|
void onNavChanged(int id);
|
||||||
|
void onClearHistory();
|
||||||
|
void onRefreshLogs();
|
||||||
|
void onHistoryFilterChanged();
|
||||||
|
void onInstalledFilterChanged(const QString& text);
|
||||||
|
void onRecentActivityClicked(QListWidgetItem* item);
|
||||||
|
void onPluginTableSelected(int row);
|
||||||
|
void onTogglePlugin();
|
||||||
|
void onRescanPlugins();
|
||||||
|
void onInstallPluginTool();
|
||||||
|
void onCheckForUpdates();
|
||||||
|
void onUpdateCheckFinished(bool hasUpdate, const QString& latestVersion,
|
||||||
|
const QString& errorMessage);
|
||||||
|
void onSelfUpdateFinished(bool success, const QString& message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
|
||||||
|
|
||||||
|
// When the sudo password is requested: once per session (at launch) or
|
||||||
|
// before every privileged operation.
|
||||||
|
enum class CredentialMode { AtLaunch, EachTime };
|
||||||
|
|
||||||
|
void applyCredentialMode(CredentialMode mode);
|
||||||
|
bool ensureCredentials(const std::vector<IPackageManager*>& providers);
|
||||||
|
void clearCredentialsAfterUse();
|
||||||
|
|
||||||
|
// Manager owning a package, based on its provider tag; falls back to the
|
||||||
|
// first available provider when the tag is unknown or empty.
|
||||||
|
IPackageManager* providerFor(const std::string& id) const;
|
||||||
|
|
||||||
|
// Show the provider's last error in a dialog when one is available, so a
|
||||||
|
// failed operation explains itself instead of failing silently.
|
||||||
|
void showProviderError(const QString& title, IPackageManager* provider);
|
||||||
|
|
||||||
|
void setupUI();
|
||||||
|
void setupSidebar();
|
||||||
|
void setupHeader();
|
||||||
|
void setupDashboardPage();
|
||||||
|
void setupBrowsePage();
|
||||||
|
void setupHistoryPage();
|
||||||
|
void setupLogsPage();
|
||||||
|
void setupPluginsPage();
|
||||||
|
void setupMenuBar();
|
||||||
|
void updatePageTitle();
|
||||||
|
void updateStatusBar();
|
||||||
|
void refreshDashboard();
|
||||||
|
void refreshRecentActivity();
|
||||||
|
void refreshPluginsTable();
|
||||||
|
void updatePackageInfo(const PackageInfo& pkg);
|
||||||
|
void resetDetailsPanel();
|
||||||
|
void setBrowseMode(BrowseMode mode);
|
||||||
|
void performInstall(const std::string& package);
|
||||||
|
void performRemove(const std::string& package);
|
||||||
|
void populatePackageTable(const std::vector<PackageInfo>& results);
|
||||||
|
void appendPackageRows(const std::vector<PackageInfo>& results);
|
||||||
|
void addPackageRow(int row, const PackageInfo& pkg);
|
||||||
|
void setBusy(bool busy);
|
||||||
|
void reloadCurrentView();
|
||||||
|
void loadInstalled();
|
||||||
|
void loadUpdates();
|
||||||
|
void refreshHistoryTable();
|
||||||
|
void loadLogs();
|
||||||
|
QFrame* makeCard();
|
||||||
|
QFrame* makeStatCard(const QString& iconName, const QString& title, QLabel** valueOut);
|
||||||
|
|
||||||
|
// Sidebar
|
||||||
|
QFrame* m_sidebar = nullptr;
|
||||||
|
QButtonGroup* m_navGroup = nullptr;
|
||||||
|
QPushButton* m_refreshButton = nullptr;
|
||||||
|
|
||||||
|
// Header
|
||||||
|
QWidget* m_headerWidget = nullptr;
|
||||||
|
QLabel* m_headerTitle = nullptr;
|
||||||
|
QLabel* m_headerSubtitle = nullptr;
|
||||||
|
|
||||||
|
// Pages
|
||||||
|
QStackedWidget* m_pages = nullptr;
|
||||||
|
|
||||||
|
// Dashboard
|
||||||
|
QLabel* m_statInstalled = nullptr;
|
||||||
|
QLabel* m_statUpdates = nullptr;
|
||||||
|
QLabel* m_statHistory = nullptr;
|
||||||
|
QLabel* m_statManager = nullptr;
|
||||||
|
QListWidget* m_recentList = nullptr;
|
||||||
|
|
||||||
|
// Browse page
|
||||||
|
QWidget* m_searchRowWidget = nullptr;
|
||||||
|
QLineEdit* m_searchBar = nullptr;
|
||||||
|
QPushButton* m_searchButton = nullptr;
|
||||||
|
QWidget* m_filterRowWidget = nullptr;
|
||||||
|
QLineEdit* m_filterBar = nullptr;
|
||||||
|
QLabel* m_resultCount = nullptr;
|
||||||
|
QPushButton* m_installButton = nullptr;
|
||||||
|
QPushButton* m_removeButton = nullptr;
|
||||||
|
QPushButton* m_updateButton = nullptr;
|
||||||
|
QPushButton* m_updateAllButton = nullptr;
|
||||||
|
QProgressBar* m_progressBar = nullptr;
|
||||||
|
// Small indeterminate bar anchored in the status bar, shown at the bottom
|
||||||
|
// of the window while any install/search runs.
|
||||||
|
QProgressBar* m_installProgressBar = nullptr;
|
||||||
|
QTableWidget* m_packageTable = nullptr;
|
||||||
|
QLabel* m_packageName = nullptr;
|
||||||
|
QLabel* m_packageVersion = nullptr;
|
||||||
|
QLabel* m_packageRepo = nullptr;
|
||||||
|
QLabel* m_packageSize = nullptr;
|
||||||
|
QLabel* m_packageProvider = nullptr;
|
||||||
|
QWidget* m_packageUpdateBadge = nullptr;
|
||||||
|
QLabel* m_packageDescription = nullptr;
|
||||||
|
|
||||||
|
// History page
|
||||||
|
QTableWidget* m_historyTable = nullptr;
|
||||||
|
QComboBox* m_historyFilter = nullptr;
|
||||||
|
QLabel* m_historyCount = nullptr;
|
||||||
|
|
||||||
|
// Logs page
|
||||||
|
QTextEdit* m_logsText = nullptr;
|
||||||
|
|
||||||
|
// Plugins page
|
||||||
|
QTableWidget* m_pluginTable = nullptr;
|
||||||
|
QPushButton* m_pluginToggleButton = nullptr;
|
||||||
|
QPushButton* m_pluginInstallButton = nullptr;
|
||||||
|
QLabel* m_pluginDescription = nullptr;
|
||||||
|
std::string m_selectedPluginId;
|
||||||
|
|
||||||
|
// Backend
|
||||||
|
PacmanManager* m_pacman = nullptr; // non-owning, used for sudo credentials/logs
|
||||||
|
PluginManager* m_pluginManager = nullptr; // owns every provider
|
||||||
|
HistoryManager* m_historyManager = nullptr;
|
||||||
|
UpdateManager* m_updateManager = nullptr; // checks Gitea releases (owned)
|
||||||
|
BrowseMode m_browseMode = ModeSearch;
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
QSettings m_settings;
|
||||||
|
CredentialMode m_credentialMode = CredentialMode::EachTime;
|
||||||
|
QAction* m_credLaunchAction = nullptr;
|
||||||
|
QAction* m_credEachTimeAction = nullptr;
|
||||||
|
|
||||||
|
std::vector<PackageInfo> m_currentResults;
|
||||||
|
std::vector<PackageInfo> m_installedPackages;
|
||||||
|
PackageInfo m_selectedPackage;
|
||||||
|
std::string m_pendingSelect; // package to auto-select after the installed list loads
|
||||||
|
};
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
|
// Information about a single package
|
||||||
|
struct PackageInfo {
|
||||||
|
std::string name;
|
||||||
|
std::string version;
|
||||||
|
std::string description;
|
||||||
|
std::string repository;
|
||||||
|
std::string size;
|
||||||
|
std::string installedSize;
|
||||||
|
// Id of the provider that owns this package (e.g. "pacman", "flatpak").
|
||||||
|
// Filled by the aggregating workers so operations can be routed to the
|
||||||
|
// right manager without the user picking one.
|
||||||
|
std::string provider;
|
||||||
|
// Every provider offering this package, after duplicate rows have been
|
||||||
|
// merged (used for display). The routing id stays in `provider`.
|
||||||
|
std::vector<std::string> providers;
|
||||||
|
bool installed = false;
|
||||||
|
bool updateAvailable = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Merge packages that share the same name (offered by several providers) into
|
||||||
|
// a single row. The first occurrence keeps its metadata and provider id (so
|
||||||
|
// operations keep a deterministic default); later occurrences are folded in:
|
||||||
|
// installed/updateAvailable become true if any provider reports them, and
|
||||||
|
// their provider id is added to pkg.providers for display.
|
||||||
|
inline void mergeProviderDuplicates(std::vector<PackageInfo>& packages) {
|
||||||
|
// Every tagged package advertises at least its own provider.
|
||||||
|
for (auto& pkg : packages) {
|
||||||
|
if (pkg.providers.empty() && !pkg.provider.empty()) {
|
||||||
|
pkg.providers.push_back(pkg.provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::size_t> firstIndex;
|
||||||
|
std::vector<std::size_t> toDrop;
|
||||||
|
for (std::size_t i = 0; i < packages.size(); ++i) {
|
||||||
|
const std::string& name = packages[i].name;
|
||||||
|
if (name.empty()) continue;
|
||||||
|
|
||||||
|
auto it = firstIndex.find(name);
|
||||||
|
if (it == firstIndex.end()) {
|
||||||
|
firstIndex.emplace(name, i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageInfo& first = packages[it->second];
|
||||||
|
const PackageInfo& dup = packages[i];
|
||||||
|
first.installed = first.installed || dup.installed;
|
||||||
|
first.updateAvailable = first.updateAvailable || dup.updateAvailable;
|
||||||
|
if (!dup.provider.empty()) {
|
||||||
|
bool known = false;
|
||||||
|
for (const auto& p : first.providers) {
|
||||||
|
if (p == dup.provider) {
|
||||||
|
known = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!known) first.providers.push_back(dup.provider);
|
||||||
|
}
|
||||||
|
toDrop.push_back(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = toDrop.rbegin(); it != toDrop.rend(); ++it) {
|
||||||
|
packages.erase(packages.begin() + static_cast<std::ptrdiff_t>(*it));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort aggregated results by provider, then by name (case-insensitive), so
|
||||||
|
// packages from the same manager stay grouped. Providers are ordered by their
|
||||||
|
// position in providerOrder (query order); providers absent from it sort last
|
||||||
|
// and are compared by id.
|
||||||
|
inline void sortByProviderThenName(std::vector<PackageInfo>& packages,
|
||||||
|
const std::vector<std::string>& providerOrder = {}) {
|
||||||
|
auto ciLess = [](const std::string& a, const std::string& b) {
|
||||||
|
std::size_t i = 0;
|
||||||
|
for (; i < a.size() && i < b.size(); ++i) {
|
||||||
|
unsigned char ca =
|
||||||
|
static_cast<unsigned char>(std::tolower(static_cast<unsigned char>(a[i])));
|
||||||
|
unsigned char cb =
|
||||||
|
static_cast<unsigned char>(std::tolower(static_cast<unsigned char>(b[i])));
|
||||||
|
if (ca != cb) return ca < cb;
|
||||||
|
}
|
||||||
|
return a.size() < b.size();
|
||||||
|
};
|
||||||
|
|
||||||
|
auto rank = [&](const std::string& id) {
|
||||||
|
for (std::size_t i = 0; i < providerOrder.size(); ++i) {
|
||||||
|
if (providerOrder[i] == id) return static_cast<int>(i);
|
||||||
|
}
|
||||||
|
return static_cast<int>(providerOrder.size());
|
||||||
|
};
|
||||||
|
|
||||||
|
std::stable_sort(packages.begin(), packages.end(),
|
||||||
|
[&](const PackageInfo& a, const PackageInfo& b) {
|
||||||
|
int ra = rank(a.provider);
|
||||||
|
int rb = rank(b.provider);
|
||||||
|
if (ra != rb) return ra < rb;
|
||||||
|
if (a.provider != b.provider) return a.provider < b.provider;
|
||||||
|
return ciLess(a.name, b.name);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress reported during an operation: a human-readable message plus an
|
||||||
|
// optional percentage (0-100) when the tool exposes real progress, or -1 when
|
||||||
|
// the exact position is unknown. -1 lets the UI keep an indeterminate bar.
|
||||||
|
using ProgressCallback = std::function<void(const std::string& message, int percent)>;
|
||||||
|
|
||||||
|
// Abstract interface for the package manager
|
||||||
|
class IPackageManager {
|
||||||
|
public:
|
||||||
|
virtual ~IPackageManager() = default;
|
||||||
|
|
||||||
|
// Identity
|
||||||
|
virtual std::string getName() const = 0;
|
||||||
|
virtual std::string getVersion() const = 0;
|
||||||
|
virtual std::string getDescription() const = 0;
|
||||||
|
|
||||||
|
// Capabilities
|
||||||
|
virtual bool canSearch() const = 0;
|
||||||
|
virtual bool canInstall() const = 0;
|
||||||
|
virtual bool canRemove() const = 0;
|
||||||
|
virtual bool canUpdate() const = 0;
|
||||||
|
virtual bool canListInstalled() const = 0;
|
||||||
|
|
||||||
|
// Operations
|
||||||
|
virtual std::vector<PackageInfo> search(const std::string& query) = 0;
|
||||||
|
virtual bool install(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback = nullptr) = 0;
|
||||||
|
virtual bool remove(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback = nullptr) = 0;
|
||||||
|
virtual bool update(const std::string& packageName = "",
|
||||||
|
ProgressCallback progressCallback = nullptr) = 0;
|
||||||
|
virtual std::vector<PackageInfo> listInstalled() = 0;
|
||||||
|
virtual std::vector<PackageInfo> listUpdates() = 0;
|
||||||
|
virtual bool refresh(ProgressCallback progressCallback = nullptr) = 0;
|
||||||
|
|
||||||
|
// Check if the package manager is available on the system
|
||||||
|
virtual bool isAvailable() const = 0;
|
||||||
|
|
||||||
|
// Whether privileged operations need a password (e.g. sudo for pacman).
|
||||||
|
// Providers that run per-user (e.g. flatpak) can keep the default.
|
||||||
|
virtual bool requiresPassword() const { return false; }
|
||||||
|
|
||||||
|
// Last error reported by the most recent failed operation, if any. Used
|
||||||
|
// to surface the real command output to the user instead of a generic
|
||||||
|
// failure message.
|
||||||
|
virtual std::string lastError() const { return {}; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "IPackageManager.h"
|
#include "package-manager.h"
|
||||||
|
|
||||||
class PackageModel : public QAbstractListModel {
|
class PackageModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "package-manager.h"
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
// Native Arch Linux package manager, integrated directly into the application
|
||||||
|
class PacmanManager : public IPackageManager {
|
||||||
|
public:
|
||||||
|
std::string getName() const override { return "pacman"; }
|
||||||
|
std::string getVersion() const override { return "1.0.0"; }
|
||||||
|
std::string getDescription() const override {
|
||||||
|
return "Gestionnaire de paquets natif d'Arch Linux";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool canSearch() const override { return true; }
|
||||||
|
bool canInstall() const override { return true; }
|
||||||
|
bool canRemove() const override { return true; }
|
||||||
|
bool canUpdate() const override { return true; }
|
||||||
|
bool canListInstalled() const override { return true; }
|
||||||
|
|
||||||
|
bool isAvailable() const override {
|
||||||
|
return system("which pacman > /dev/null 2>&1") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pacman operations run through sudo and need the session password.
|
||||||
|
bool requiresPassword() const override { return true; }
|
||||||
|
|
||||||
|
// Parse `pacman -Q` output (one "name version" line per package).
|
||||||
|
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
||||||
|
static std::vector<PackageInfo> parseInstalledOutput(const std::string& output);
|
||||||
|
|
||||||
|
// Parse `pacman -Q` output into a set of installed package names, used to
|
||||||
|
// mark search results as installed without one subprocess per result.
|
||||||
|
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
||||||
|
static std::set<std::string> parseInstalledNames(const std::string& output);
|
||||||
|
|
||||||
|
// Parse `pacman -Qi` output (one block per package) into a name -> installed size map.
|
||||||
|
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
||||||
|
static std::map<std::string, std::string> parseInstalledSizes(const std::string& output);
|
||||||
|
|
||||||
|
// Parse `pacman -Sl` output ("repo name version" per line) into a name -> repository map.
|
||||||
|
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
||||||
|
static std::map<std::string, std::string> parseSyncRepos(const std::string& output);
|
||||||
|
|
||||||
|
// Detect a sudo authentication failure (wrong or missing password) in the
|
||||||
|
// output of a privileged command. Exposed as static so it can be
|
||||||
|
// unit-tested without invoking sudo.
|
||||||
|
static bool authFailed(const std::string& output);
|
||||||
|
|
||||||
|
// Credential handling for privileged (sudo) operations. The password is
|
||||||
|
// kept in memory only for the session (never persisted) and piped to
|
||||||
|
// `sudo -S` for each privileged command.
|
||||||
|
void setPassword(const std::string& password);
|
||||||
|
void clearPassword();
|
||||||
|
bool hasPassword() const;
|
||||||
|
|
||||||
|
std::vector<PackageInfo> search(const std::string& query) override;
|
||||||
|
bool install(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) override;
|
||||||
|
bool remove(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) override;
|
||||||
|
bool update(const std::string& packageName = "",
|
||||||
|
ProgressCallback progressCallback = nullptr) override;
|
||||||
|
std::vector<PackageInfo> listInstalled() override;
|
||||||
|
std::vector<PackageInfo> listUpdates() override;
|
||||||
|
bool refresh(ProgressCallback progressCallback = nullptr) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isPackageInstalled(const std::string& name);
|
||||||
|
|
||||||
|
std::string m_password;
|
||||||
|
};
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "provider-plugin.h"
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QLibrary>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// Registry of every plugin known to the application. It owns each plugin
|
||||||
|
// (built-in and external), loads shared-library plugins dropped in the plugin
|
||||||
|
// directories at runtime (see PluginManager::scanDirectory) and tracks which
|
||||||
|
// are enabled in the settings. A plugin is either a package-manager provider
|
||||||
|
// (implements IPackageManager) or a generic addon (implements IPlugin) — both
|
||||||
|
// kinds share the same loading, lifecycle and enable/disable flow.
|
||||||
|
class PluginManager {
|
||||||
|
public:
|
||||||
|
struct PluginEntry {
|
||||||
|
PluginInfo info;
|
||||||
|
IPlugin* plugin = nullptr; // non-null for addon plugins
|
||||||
|
IPackageManager* manager = nullptr; // non-null for provider plugins
|
||||||
|
QLibrary* library = nullptr; // owned by the PluginManager; null for built-ins
|
||||||
|
};
|
||||||
|
|
||||||
|
PluginManager();
|
||||||
|
~PluginManager();
|
||||||
|
|
||||||
|
// Register a provider compiled into the application (e.g. pacman).
|
||||||
|
// Takes ownership of the manager.
|
||||||
|
void registerBuiltin(PluginInfo info, IPackageManager* manager);
|
||||||
|
|
||||||
|
// Scan the plugin directories for external plugins and load them.
|
||||||
|
void discoverExternal();
|
||||||
|
|
||||||
|
// Drop external plugins and rescan their directories; built-in plugins
|
||||||
|
// are kept (their instances stay valid).
|
||||||
|
void reload();
|
||||||
|
|
||||||
|
// Re-run isAvailable() on every plugin (e.g. after the app installed a
|
||||||
|
// missing tool) so the Plugins page reflects reality.
|
||||||
|
void refreshAvailability();
|
||||||
|
|
||||||
|
// All known plugins, in registration order.
|
||||||
|
const std::vector<PluginEntry>& plugins() const;
|
||||||
|
|
||||||
|
// Provider plugins that are enabled (in settings) and whose tool is on the
|
||||||
|
// system.
|
||||||
|
std::vector<const PluginEntry*> availableProviders() const;
|
||||||
|
|
||||||
|
// Same as availableProviders() but as plain manager pointers, convenient
|
||||||
|
// for running aggregated operations across every provider.
|
||||||
|
std::vector<IPackageManager*> availableManagers() const;
|
||||||
|
|
||||||
|
// A single available+enabled provider matching id, or nullptr.
|
||||||
|
const PluginEntry* findAvailable(const std::string& id) const;
|
||||||
|
|
||||||
|
// Addon plugins that are enabled and available (e.g. to hand the main
|
||||||
|
// window to via IPlugin::onUiReady).
|
||||||
|
std::vector<IPlugin*> availableAddons() const;
|
||||||
|
|
||||||
|
bool isEnabled(const std::string& id) const;
|
||||||
|
void setEnabled(const std::string& id, bool enabled);
|
||||||
|
|
||||||
|
// Manager for a known provider id (enabled or not), or nullptr.
|
||||||
|
IPackageManager* managerFor(const std::string& id) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool loadPluginFile(const QString& filePath);
|
||||||
|
void scanDirectory(const QString& dir);
|
||||||
|
void unloadExternal();
|
||||||
|
|
||||||
|
std::vector<PluginEntry> m_plugins;
|
||||||
|
QSettings m_settings;
|
||||||
|
};
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Every plugin is either a package-manager provider (implements
|
||||||
|
// IPackageManager) or a generic addon (implements IPlugin). The kind tells the
|
||||||
|
// host which C ABI create function to resolve and how to treat the plugin in
|
||||||
|
// the UI.
|
||||||
|
enum class PluginKind {
|
||||||
|
Provider, // adds a package manager (pacman, flatpak, apt, ...)
|
||||||
|
Addon, // any other extension: UI tweak, helper, ... as long as C++
|
||||||
|
};
|
||||||
|
|
||||||
|
// Metadata describing a plugin, whether it is compiled into the application
|
||||||
|
// (pacman) or loaded at runtime from an external shared library.
|
||||||
|
struct PluginInfo {
|
||||||
|
std::string id; // unique identifier, e.g. "pacman", "flatpak"
|
||||||
|
std::string name; // display name, e.g. "Flatpak"
|
||||||
|
std::string version; // plugin version
|
||||||
|
std::string description; // what this plugin does
|
||||||
|
std::string author; // who wrote the plugin
|
||||||
|
PluginKind kind = PluginKind::Provider;
|
||||||
|
bool builtin = false; // true when compiled into the application
|
||||||
|
std::string path; // filesystem path (external plugins only)
|
||||||
|
bool available = false; // provider: backing tool present; addon: can run here
|
||||||
|
// OS package name providing a provider's backing tool (e.g. "flatpak").
|
||||||
|
// Empty when the plugin cannot be installed from the application.
|
||||||
|
std::string installHint;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QMainWindow; // host window, handed to UI addons via onUiReady()
|
||||||
|
|
||||||
|
// Base interface every non-provider plugin implements. Providers implement
|
||||||
|
// IPackageManager instead. Both kinds are owned and lifecycle-managed by the
|
||||||
|
// PluginManager.
|
||||||
|
class IPlugin {
|
||||||
|
public:
|
||||||
|
virtual ~IPlugin() = default;
|
||||||
|
// Called when the plugin is loaded (at discovery or reload). Keep it
|
||||||
|
// lightweight: the main window does not exist yet, so no UI work here.
|
||||||
|
virtual void onLoad() {}
|
||||||
|
// Called when the plugin is unloaded (reload, shutdown) so it can release
|
||||||
|
// what onLoad() acquired.
|
||||||
|
virtual void onUnload() {}
|
||||||
|
// Whether the plugin can run on this system. Providers report whether
|
||||||
|
// their backing tool is installed; addons usually return true.
|
||||||
|
virtual bool isAvailable() const { return true; }
|
||||||
|
// Called once the main window exists, so UI addons can attach their own
|
||||||
|
// widgets (toolbar buttons, status-bar items, ...). Default: no-op.
|
||||||
|
virtual void onUiReady(QMainWindow* /*mainWindow*/) {}
|
||||||
|
};
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "package-manager.h"
|
||||||
|
|
||||||
|
// ---- External plugin contract (C ABI) ----
|
||||||
|
//
|
||||||
|
// A plugin is a shared library (lib*.so / *.dll) dropped in a plugin directory
|
||||||
|
// (see PluginManager). It must export the metadata symbols below plus one
|
||||||
|
// create function, depending on its kind:
|
||||||
|
// - provider plugins (kind "provider") export fws_create_provider() returning
|
||||||
|
// an IPackageManager* (use FWS_PROVIDER_PLUGIN);
|
||||||
|
// - addon plugins (kind "addon") export fws_create_plugin() returning an
|
||||||
|
// IPlugin* (use FWS_ADDON_PLUGIN).
|
||||||
|
// A plugin that does not export fws_plugin_kind() is treated as a provider
|
||||||
|
// (legacy plugins keep working).
|
||||||
|
//
|
||||||
|
// #include "provider-plugin.h"
|
||||||
|
// #include "my-manager.h"
|
||||||
|
// FWS_PROVIDER_PLUGIN(MyManager, "myprov", "My Provider", "1.0.0",
|
||||||
|
// "Manages my stuff", "Jane Doe");
|
||||||
|
//
|
||||||
|
// #include "provider-plugin.h"
|
||||||
|
// #include "my-addon.h"
|
||||||
|
// FWS_ADDON_PLUGIN(MyAddon, "myaddon", "My Addon", "1.0.0",
|
||||||
|
// "Tweaks the UI", "Jane Doe");
|
||||||
|
//
|
||||||
|
// Plugins are compiled with the same toolchain/headers as the host, exactly
|
||||||
|
// like Qt plugins, so the IPackageManager/IPlugin vtables and struct layouts
|
||||||
|
// match.
|
||||||
|
extern "C" {
|
||||||
|
const char* fws_plugin_id();
|
||||||
|
const char* fws_plugin_name();
|
||||||
|
const char* fws_plugin_version();
|
||||||
|
const char* fws_plugin_description();
|
||||||
|
const char* fws_plugin_author();
|
||||||
|
// "provider" (default when missing) or "addon": picks which create
|
||||||
|
// function the host resolves.
|
||||||
|
const char* fws_plugin_kind();
|
||||||
|
IPackageManager* fws_create_provider();
|
||||||
|
IPlugin* fws_create_plugin();
|
||||||
|
// Optional: OS package name that provides the backing tool, so the app can
|
||||||
|
// offer to install it when unavailable. May be omitted by a plugin.
|
||||||
|
const char* fws_plugin_install_hint();
|
||||||
|
}
|
||||||
|
|
||||||
|
#define FWS_PROVIDER_PLUGIN(PluginClass, id_, name_, version_, desc_, author_) \
|
||||||
|
extern "C" const char* fws_plugin_kind() { return "provider"; } \
|
||||||
|
extern "C" const char* fws_plugin_id() { return id_; } \
|
||||||
|
extern "C" const char* fws_plugin_name() { return name_; } \
|
||||||
|
extern "C" const char* fws_plugin_version() { return version_; } \
|
||||||
|
extern "C" const char* fws_plugin_description() { return desc_; } \
|
||||||
|
extern "C" const char* fws_plugin_author() { return author_; } \
|
||||||
|
extern "C" IPackageManager* fws_create_provider() { return new PluginClass(); }
|
||||||
|
|
||||||
|
#define FWS_ADDON_PLUGIN(AddonClass, id_, name_, version_, desc_, author_) \
|
||||||
|
extern "C" const char* fws_plugin_kind() { return "addon"; } \
|
||||||
|
extern "C" const char* fws_plugin_id() { return id_; } \
|
||||||
|
extern "C" const char* fws_plugin_name() { return name_; } \
|
||||||
|
extern "C" const char* fws_plugin_version() { return version_; } \
|
||||||
|
extern "C" const char* fws_plugin_description() { return desc_; } \
|
||||||
|
extern "C" const char* fws_plugin_author() { return author_; } \
|
||||||
|
extern "C" IPlugin* fws_create_plugin() { return new AddonClass(); }
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QString>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
|
// Checks the Gitea repository for new releases and tracks the last check
|
||||||
|
// state in a JSON file so the app only queries the API once per day.
|
||||||
|
// When the user accepts, the app updates itself by pulling + rebuilding
|
||||||
|
// the source repository in the background; the running binary stays
|
||||||
|
// untouched until the next launch.
|
||||||
|
class UpdateManager : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit UpdateManager(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
// Current app version, read from the version file at build time.
|
||||||
|
static QString currentVersion();
|
||||||
|
|
||||||
|
// Path of the state file storing the last check date and the latest
|
||||||
|
// known remote version (e.g. ~/.local/share/PacManager/update-state.json).
|
||||||
|
static QString stateFilePath();
|
||||||
|
|
||||||
|
// True when the last check happened less than 24h ago, so we can skip
|
||||||
|
// the network call at launch.
|
||||||
|
bool shouldCheck() const;
|
||||||
|
|
||||||
|
// Latest remote version recorded in the state file (empty if never checked).
|
||||||
|
QString lastKnownRemoteVersion() const;
|
||||||
|
|
||||||
|
// Fetches the latest release from the Gitea API. Emits checkFinished.
|
||||||
|
void checkForUpdates();
|
||||||
|
|
||||||
|
// True when the remote version is newer than the local one.
|
||||||
|
static bool isNewerVersion(const QString& remote, const QString& local);
|
||||||
|
|
||||||
|
// Path of the source repository, or empty when the app is installed
|
||||||
|
// without the repo (e.g. ~/.local/bin). Used for self-update.
|
||||||
|
QString repoPath() const;
|
||||||
|
|
||||||
|
// Whether the source repository is present so a self-update is possible.
|
||||||
|
bool canSelfUpdate() const;
|
||||||
|
|
||||||
|
// Pulls the latest code from the remote and rebuilds the app in the
|
||||||
|
// background. The current running binary is left untouched; the new
|
||||||
|
// version takes effect at the next launch. Emits selfUpdateFinished.
|
||||||
|
void performSelfUpdate();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
// Emitted after a check completes. hasUpdate is true when a newer
|
||||||
|
// release exists; errorMessage is non-empty when the request failed.
|
||||||
|
void checkFinished(bool hasUpdate, const QString& latestVersion,
|
||||||
|
const QString& errorMessage);
|
||||||
|
|
||||||
|
// Emitted when the background self-update completes. success is true
|
||||||
|
// if the pull + build produced a fresh executable.
|
||||||
|
void selfUpdateFinished(bool success, const QString& message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void saveState(const QString& remoteVersion);
|
||||||
|
void loadState();
|
||||||
|
void runShell(const QString& script, const QString& workingDir);
|
||||||
|
|
||||||
|
QNetworkAccessManager m_network;
|
||||||
|
QProcess m_process; // runs the git pull + build script
|
||||||
|
QString m_lastCheckDate; // ISO date of the last successful check
|
||||||
|
QString m_lastKnownRemoteVersion; // latest version seen on the server
|
||||||
|
QString m_latestVersion; // version of the pending update
|
||||||
|
QString m_repoPath; // source repo dir when found
|
||||||
|
};
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
PLUGIN_DIR="$HOME/.local/lib/PackageMapper/plugins"
|
|
||||||
|
|
||||||
echo "📦 Installation des plugins..."
|
|
||||||
|
|
||||||
mkdir -p "$PLUGIN_DIR"
|
|
||||||
|
|
||||||
# Find and copy all plugin .so files
|
|
||||||
for plugin in build/plugins/*/lib*.so; do
|
|
||||||
if [ -f "$plugin" ]; then
|
|
||||||
cp "$plugin" "$PLUGIN_DIR/"
|
|
||||||
echo " ✅ Installé: $(basename $plugin)"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Universal plugin (priority)
|
|
||||||
if [ -f "build/plugins/universal/libuniversal.so" ]; then
|
|
||||||
echo " 🌍 Plugin universal chargé"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "📁 Plugins installés dans: $PLUGIN_DIR"
|
|
||||||
echo "🔄 Redémarrez PackageMapper pour charger les nouveaux plugins."
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
add_library(apt_plugin SHARED apt_plugin.cpp)
|
|
||||||
target_include_directories(apt_plugin PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
|
||||||
set_target_properties(apt_plugin PROPERTIES
|
|
||||||
PREFIX ""
|
|
||||||
OUTPUT_NAME "apt"
|
|
||||||
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/PackageMapper/plugins"
|
|
||||||
)
|
|
||||||
install(TARGETS apt_plugin DESTINATION lib/PackageMapper/plugins)
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
#include "IPackageManager.h"
|
|
||||||
#include <array>
|
|
||||||
#include <memory>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
static std::string exec(const char* cmd) {
|
|
||||||
std::array<char, 256> buffer;
|
|
||||||
std::string result;
|
|
||||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
|
||||||
if (!pipe) throw std::runtime_error("popen() failed");
|
|
||||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
|
||||||
result += buffer.data();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AptPlugin : public IPackageManager {
|
|
||||||
public:
|
|
||||||
std::string getName() const override { return "apt"; }
|
|
||||||
std::string getVersion() const override { return "1.0.0"; }
|
|
||||||
std::string getDescription() const override {
|
|
||||||
return "Gestionnaire de paquets Debian/Ubuntu (apt)";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool canSearch() const override { return true; }
|
|
||||||
bool canInstall() const override { return true; }
|
|
||||||
bool canRemove() const override { return true; }
|
|
||||||
bool canUpdate() const override { return true; }
|
|
||||||
bool canListInstalled() const override { return true; }
|
|
||||||
|
|
||||||
bool isAvailable() const override {
|
|
||||||
return system("which apt > /dev/null 2>&1") == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> search(const std::string& query) override {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
|
|
||||||
std::string output = exec(("apt-cache search " + query + " 2>&1").c_str());
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t spacePos = line.find(' ');
|
|
||||||
if (spacePos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, spacePos);
|
|
||||||
pkg.description = line.substr(spacePos + 1);
|
|
||||||
pkg.installed = isPackageInstalled(pkg.name);
|
|
||||||
pkg.repository = "debian";
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool install(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
if (progressCallback) progressCallback("Installation de " + packageName + "...");
|
|
||||||
|
|
||||||
std::string output = exec(("sudo apt install -y " + packageName + " 2>&1").c_str());
|
|
||||||
|
|
||||||
if (progressCallback) {
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (!line.empty()) progressCallback(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return isPackageInstalled(packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool remove(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
if (progressCallback) progressCallback("Suppression de " + packageName + "...");
|
|
||||||
|
|
||||||
std::string output = exec(("sudo apt remove -y " + packageName + " 2>&1").c_str());
|
|
||||||
|
|
||||||
if (progressCallback) {
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (!line.empty()) progressCallback(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return !isPackageInstalled(packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool update(const std::string& packageName = "",
|
|
||||||
std::function<void(const std::string&)> progressCallback = nullptr) override {
|
|
||||||
if (packageName.empty()) {
|
|
||||||
if (progressCallback) progressCallback("Mise à jour des paquets...");
|
|
||||||
exec("sudo apt update 2>&1");
|
|
||||||
exec("sudo apt upgrade -y 2>&1");
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
if (progressCallback) progressCallback("Mise à jour de " + packageName + "...");
|
|
||||||
exec(("sudo apt install --only-upgrade -y " + packageName + " 2>&1").c_str());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> listInstalled() override {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
|
|
||||||
std::string output = exec("dpkg --get-selections | grep -v deinstall 2>&1");
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t tabPos = line.find('\t');
|
|
||||||
if (tabPos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, tabPos);
|
|
||||||
pkg.installed = true;
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool isPackageInstalled(const std::string& name) {
|
|
||||||
return system(("dpkg -l " + name + " > /dev/null 2>&1").c_str()) == 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
IPackageManager* createPlugin() {
|
|
||||||
return new AptPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyPlugin(IPackageManager* plugin) {
|
|
||||||
delete plugin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// Example addon plugin — a template for non-provider extensions (UI tweaks,
|
||||||
|
// helpers, ...) written in C++.
|
||||||
|
//
|
||||||
|
// Unlike provider plugins (see plugins/example-provider), an addon does not
|
||||||
|
// manage packages: it implements IPlugin (see include/plugin.h) and exports
|
||||||
|
// the C ABI contract via the FWS_ADDON_PLUGIN macro. The host loads it, runs
|
||||||
|
// onLoad()/onUnload() around its lifetime and hands it the main window via
|
||||||
|
// onUiReady() so it can attach its own widgets — here a status-bar badge.
|
||||||
|
//
|
||||||
|
// Build with CMake from the project root:
|
||||||
|
// cmake -B build -DFWS_BUILD_EXAMPLE_ADDON=ON && cmake --build build
|
||||||
|
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "provider-plugin.h"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QStatusBar>
|
||||||
|
|
||||||
|
// A tiny UI addon: it shows a badge in the status bar while it is loaded and
|
||||||
|
// removes it on unload. Copy this file as a starting point for real addons
|
||||||
|
// (toolbar buttons, dashboard cards, helpers, ...).
|
||||||
|
class ExampleAddon : public IPlugin {
|
||||||
|
public:
|
||||||
|
void onLoad() override { m_loaded = true; }
|
||||||
|
void onUnload() override {
|
||||||
|
m_loaded = false;
|
||||||
|
if (m_badge) {
|
||||||
|
if (m_window) m_window->statusBar()->removeWidget(m_badge);
|
||||||
|
delete m_badge;
|
||||||
|
m_badge = nullptr;
|
||||||
|
m_window = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Available only while onLoad() has run, so the host's availability check
|
||||||
|
// also proves the lifecycle was applied.
|
||||||
|
bool isAvailable() const override { return m_loaded; }
|
||||||
|
|
||||||
|
void onUiReady(QMainWindow* window) override {
|
||||||
|
m_window = window;
|
||||||
|
if (!m_loaded || !m_window) return;
|
||||||
|
m_badge = new QLabel("⚡ Exemple d'addon actif");
|
||||||
|
m_badge->setStyleSheet(
|
||||||
|
"color: #7aa2f7; font-size: 11px; font-weight: 600; padding-right: 8px;");
|
||||||
|
m_window->statusBar()->addPermanentWidget(m_badge);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_loaded = false;
|
||||||
|
QMainWindow* m_window = nullptr;
|
||||||
|
QLabel* m_badge = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
FWS_ADDON_PLUGIN(ExampleAddon, "example-addon", "Example Addon", "0.1.0",
|
||||||
|
"Exemple d'addon : badge dans la barre de statut", "FWS");
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// Example external provider plugin — a template for adding new package
|
||||||
|
// providers without touching the application code.
|
||||||
|
//
|
||||||
|
// Build it as a shared library and drop it in a plugin directory
|
||||||
|
// (next to the PacManager binary in ./plugins/ or in
|
||||||
|
// ~/.local/share/PacManager/plugins/); the app discovers it at launch and on
|
||||||
|
// the Plugins page via "Recharger".
|
||||||
|
//
|
||||||
|
// This is a *provider* plugin: it adds a package manager. For non-provider
|
||||||
|
// extensions (UI tweaks, helpers, ...), see plugins/example-addon instead.
|
||||||
|
//
|
||||||
|
// A plugin only needs to:
|
||||||
|
// 1. implement IPackageManager (see include/package-manager.h)
|
||||||
|
// 2. export the C ABI symbols via the FWS_PROVIDER_PLUGIN macro
|
||||||
|
//
|
||||||
|
// To build with CMake from the project root:
|
||||||
|
// cmake -B build -DFWS_BUILD_EXAMPLE_PLUGIN=ON && cmake --build build
|
||||||
|
|
||||||
|
#include "provider-plugin.h"
|
||||||
|
|
||||||
|
// A trivial provider that reports itself as always available but manages
|
||||||
|
// nothing — replace the stubs with real commands (apt, dnf, zypper, ...).
|
||||||
|
class SampleProvider : public IPackageManager {
|
||||||
|
public:
|
||||||
|
std::string getName() const override { return "sample"; }
|
||||||
|
std::string getVersion() const override { return "0.1.0"; }
|
||||||
|
std::string getDescription() const override {
|
||||||
|
return "Exemple de plugin fournisseur (modèle à copier)";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool canSearch() const override { return false; }
|
||||||
|
bool canInstall() const override { return false; }
|
||||||
|
bool canRemove() const override { return false; }
|
||||||
|
bool canUpdate() const override { return false; }
|
||||||
|
bool canListInstalled() const override { return false; }
|
||||||
|
|
||||||
|
bool isAvailable() const override { return true; }
|
||||||
|
|
||||||
|
std::vector<PackageInfo> search(const std::string&) override { return {}; }
|
||||||
|
bool install(const std::string&, ProgressCallback) override { return false; }
|
||||||
|
bool remove(const std::string&, ProgressCallback) override { return false; }
|
||||||
|
bool update(const std::string&, ProgressCallback) override { return false; }
|
||||||
|
std::vector<PackageInfo> listInstalled() override { return {}; }
|
||||||
|
std::vector<PackageInfo> listUpdates() override { return {}; }
|
||||||
|
bool refresh(ProgressCallback) override { return false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
FWS_PROVIDER_PLUGIN(SampleProvider, "sample", "Sample Provider", "0.1.0",
|
||||||
|
"Exemple de plugin fournisseur (modèle à copier)", "FWS");
|
||||||
@@ -0,0 +1,463 @@
|
|||||||
|
#include "flatpak-manager.h"
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <sstream>
|
||||||
|
#include <cctype>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
// The per-user standard XDG data dir (~/.local/share).
|
||||||
|
static fs::path userShareDir() {
|
||||||
|
const char* home = std::getenv("HOME");
|
||||||
|
return fs::path(home ? home : "/tmp") / ".local/share";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link (or fall back to copy) one flatpak export into the user's standard XDG
|
||||||
|
// dir. Preferring a symlink means it survives flatpak app updates, which
|
||||||
|
// re-export at the same path.
|
||||||
|
static void linkFile(const fs::path& src, const fs::path& dest) {
|
||||||
|
std::error_code ec;
|
||||||
|
fs::create_directories(dest.parent_path(), ec);
|
||||||
|
fs::remove(dest, ec); // Replace any stale entry (e.g. from a past run).
|
||||||
|
fs::create_symlink(fs::absolute(src), dest, ec);
|
||||||
|
if (ec) fs::copy_file(src, dest, fs::copy_options::overwrite_existing, ec);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to run shell commands and capture output.
|
||||||
|
static std::string exec(const char* cmd) {
|
||||||
|
std::array<char, 256> buffer;
|
||||||
|
std::string result;
|
||||||
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
||||||
|
if (!pipe) throw std::runtime_error("popen() failed");
|
||||||
|
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||||
|
result += buffer.data();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stream the lines of a command's output to the progress callback, if any.
|
||||||
|
// flatpak exposes no simple percentage, so progress is reported text-only
|
||||||
|
// (percent = -1 keeps the UI bar indeterminate).
|
||||||
|
static void streamOutput(const std::string& output, ProgressCallback progressCallback) {
|
||||||
|
if (!progressCallback) return;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (!line.empty()) progressCallback(line, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A flatpak application ID is a dotted identifier with at least two dots whose
|
||||||
|
// segments start with an alphanumeric character (e.g. org.mozilla.firefox).
|
||||||
|
// This deliberately rejects version strings such as "128.0.2".
|
||||||
|
static bool isAppId(const std::string& token) {
|
||||||
|
int dots = 0;
|
||||||
|
bool first = true;
|
||||||
|
for (size_t i = 0; i < token.size(); ++i) {
|
||||||
|
char c = token[i];
|
||||||
|
if (c == '.') {
|
||||||
|
++dots;
|
||||||
|
first = true; // next segment must start with an alnum again
|
||||||
|
} else if (std::isalnum(static_cast<unsigned char>(c)) || c == '-' || c == '_') {
|
||||||
|
if (first && !std::isalnum(static_cast<unsigned char>(c))) return false;
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dots >= 2 && !first;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep the tail of a command's output (the last few non-empty lines) so the
|
||||||
|
// user sees the real reason an operation failed.
|
||||||
|
static std::string lastOutputLines(const std::string& output, int maxLines = 4) {
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (!line.empty()) lines.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
int start = std::max(0, static_cast<int>(lines.size()) - maxLines);
|
||||||
|
for (int i = start; i < static_cast<int>(lines.size()); ++i) {
|
||||||
|
result += lines[i];
|
||||||
|
result += "\n";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split a flatpak --columns line. flatpak emits tab-separated fields with that
|
||||||
|
// flag; fall back to whitespace splitting when tabs are absent.
|
||||||
|
static std::vector<std::string> splitColumns(const std::string& line) {
|
||||||
|
std::vector<std::string> fields;
|
||||||
|
std::istringstream ss(line);
|
||||||
|
std::string field;
|
||||||
|
if (line.find('\t') != std::string::npos) {
|
||||||
|
while (std::getline(ss, field, '\t')) {
|
||||||
|
if (!field.empty()) fields.push_back(field);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (ss >> field) fields.push_back(field);
|
||||||
|
}
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
// `flatpak search` prints one aligned row per app:
|
||||||
|
// Name Description Application ID Version Branch Remotes
|
||||||
|
// The description may contain spaces, so the application ID is located by
|
||||||
|
// shape (dotted identifier) and everything between Name and it is joined back.
|
||||||
|
std::vector<PackageInfo> FlatpakManager::parseSearchOutput(const std::string& output) {
|
||||||
|
std::vector<PackageInfo> results;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
bool firstLine = true;
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (firstLine) {
|
||||||
|
firstLine = false;
|
||||||
|
continue; // Skip the column header.
|
||||||
|
}
|
||||||
|
if (line.empty()) continue;
|
||||||
|
|
||||||
|
std::vector<std::string> tokens = splitColumns(line);
|
||||||
|
if (tokens.empty()) continue;
|
||||||
|
|
||||||
|
int appIdx = -1;
|
||||||
|
for (int i = 1; i < static_cast<int>(tokens.size()); ++i) {
|
||||||
|
if (isAppId(tokens[i])) {
|
||||||
|
appIdx = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (appIdx == -1) continue; // Not an application row.
|
||||||
|
|
||||||
|
PackageInfo pkg;
|
||||||
|
// Use the application ID as the package name so install/remove/update
|
||||||
|
// work directly with the CLI; the human-readable name is kept at the
|
||||||
|
// front of the description (e.g. "Firefox — Fast and privacy-aware").
|
||||||
|
pkg.name = tokens[appIdx];
|
||||||
|
pkg.version = (appIdx + 1 < static_cast<int>(tokens.size())) ? tokens[appIdx + 1] : "";
|
||||||
|
pkg.repository = tokens.back();
|
||||||
|
|
||||||
|
for (int i = 1; i < appIdx; ++i) {
|
||||||
|
if (!pkg.description.empty()) pkg.description += " ";
|
||||||
|
pkg.description += tokens[i];
|
||||||
|
}
|
||||||
|
if (!tokens[0].empty() && tokens[0] != pkg.name) {
|
||||||
|
pkg.description = tokens[0] + " — " + pkg.description;
|
||||||
|
}
|
||||||
|
results.push_back(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PackageInfo> FlatpakManager::parseInstalledOutput(const std::string& output) {
|
||||||
|
std::vector<PackageInfo> results;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (line.empty()) continue;
|
||||||
|
|
||||||
|
std::vector<std::string> fields = splitColumns(line);
|
||||||
|
if (fields.empty()) continue;
|
||||||
|
|
||||||
|
PackageInfo pkg;
|
||||||
|
pkg.name = fields[0];
|
||||||
|
if (fields.size() > 1) pkg.version = fields[1];
|
||||||
|
if (fields.size() > 2) pkg.repository = fields[2];
|
||||||
|
pkg.installed = true;
|
||||||
|
results.push_back(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PackageInfo> FlatpakManager::parseUpdatesOutput(const std::string& output) {
|
||||||
|
std::vector<PackageInfo> results;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (line.empty()) continue;
|
||||||
|
|
||||||
|
std::vector<std::string> fields = splitColumns(line);
|
||||||
|
if (fields.empty()) continue;
|
||||||
|
|
||||||
|
PackageInfo pkg;
|
||||||
|
pkg.name = fields[0];
|
||||||
|
if (fields.size() > 1) pkg.version = fields[1];
|
||||||
|
pkg.installed = true;
|
||||||
|
pkg.updateAvailable = true;
|
||||||
|
results.push_back(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PackageInfo> FlatpakManager::search(const std::string& query) {
|
||||||
|
std::string cmd = "flatpak search " + query + " 2>&1";
|
||||||
|
std::vector<PackageInfo> results = parseSearchOutput(exec(cmd.c_str()));
|
||||||
|
|
||||||
|
// Report the honest status of each hit (already installed / pending
|
||||||
|
// update) so the search page does not keep showing "Disponible" for apps
|
||||||
|
// that are already managed, like pacman does with its [installed] marker.
|
||||||
|
if (!results.empty()) {
|
||||||
|
std::set<std::string> installed;
|
||||||
|
for (const auto& pkg : listInstalled()) installed.insert(pkg.name);
|
||||||
|
std::set<std::string> outdated;
|
||||||
|
for (const auto& pkg : listUpdates()) outdated.insert(pkg.name);
|
||||||
|
|
||||||
|
for (auto& pkg : results) {
|
||||||
|
pkg.installed = installed.count(pkg.name) > 0;
|
||||||
|
pkg.updateAvailable = outdated.count(pkg.name) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PackageInfo> FlatpakManager::listInstalled() {
|
||||||
|
return parseInstalledOutput(
|
||||||
|
exec("flatpak list --app --columns=application,version,origin 2>&1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PackageInfo> FlatpakManager::listUpdates() {
|
||||||
|
return parseUpdatesOutput(
|
||||||
|
exec("flatpak remote-ls --updates --columns=application,version 2>&1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FlatpakManager::isInstalled(const std::string& appId) {
|
||||||
|
std::string cmd = "flatpak info " + appId + " > /dev/null 2>&1";
|
||||||
|
return system(cmd.c_str()) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FlatpakManager::install(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) {
|
||||||
|
m_lastError.clear();
|
||||||
|
|
||||||
|
// Idempotent: an app already deployed (in either installation) is reported
|
||||||
|
// as installed without re-running the installer, then made sure it appears
|
||||||
|
// in the desktop launcher (covers apps installed before this feature).
|
||||||
|
if (isInstalled(packageName)) {
|
||||||
|
if (progressCallback) progressCallback(packageName + " est déjà installé.", -1);
|
||||||
|
integrateDesktopEntries(packageName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progressCallback) progressCallback("Installation de " + packageName + "...", -1);
|
||||||
|
|
||||||
|
auto tryInstall = [&](const std::string& extra) {
|
||||||
|
return exec(("flatpak install --noninteractive --assumeyes " + extra + " "
|
||||||
|
+ packageName + " 2>&1").c_str());
|
||||||
|
};
|
||||||
|
|
||||||
|
// A fresh flatpak setup has no remote configured: add the default flathub
|
||||||
|
// one (idempotent, per-user) so the install can resolve the app.
|
||||||
|
exec("flatpak remote-add --if-not-exists --user flathub "
|
||||||
|
"https://flathub.org/repo/flathub.flatpakrepo 2>&1");
|
||||||
|
|
||||||
|
std::string output = tryInstall("");
|
||||||
|
|
||||||
|
auto ambiguous = [&]() {
|
||||||
|
return output.find("Multiple remotes") != std::string::npos;
|
||||||
|
};
|
||||||
|
auto noRefs = [&]() {
|
||||||
|
return output.find("No refs found") != std::string::npos
|
||||||
|
|| output.find("No remote refs") != std::string::npos;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stale remote metadata makes flatpak report "No refs found": refresh the
|
||||||
|
// appstream cache and retry once before giving up. When both a system and
|
||||||
|
// a user flathub remote exist, flatpak refuses to pick one in non-
|
||||||
|
// interactive mode, so go straight to the per-user installation instead of
|
||||||
|
// repeating a doomed attempt.
|
||||||
|
if (output.find("error:") != std::string::npos && !isInstalled(packageName)
|
||||||
|
&& (noRefs() || ambiguous())) {
|
||||||
|
if (progressCallback) progressCallback("Mise à jour des métadonnées des dépôts...", -1);
|
||||||
|
exec("flatpak update --appstream 2>&1");
|
||||||
|
output = tryInstall(ambiguous() ? "--user flathub" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remaining failures get one per-user attempt (no polkit, no ambiguity).
|
||||||
|
if (output.find("error:") != std::string::npos && !isInstalled(packageName)) {
|
||||||
|
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...", -1);
|
||||||
|
output = tryInstall("--user flathub");
|
||||||
|
}
|
||||||
|
|
||||||
|
streamOutput(output, progressCallback);
|
||||||
|
|
||||||
|
// The authoritative success check is `flatpak info`; the output may carry
|
||||||
|
// noise such as "already installed" that must not count as a failure.
|
||||||
|
if (!isInstalled(packageName)) {
|
||||||
|
m_lastError = lastOutputLines(output);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Like a pacman install, make the freshly installed app appear in the
|
||||||
|
// desktop launcher immediately (see integrateDesktopEntries).
|
||||||
|
integrateDesktopEntries(packageName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link an app's launcher entries and icons into the user's standard XDG dirs
|
||||||
|
// (~/.local/share/{applications,icons}), which every desktop scans by default.
|
||||||
|
// This makes flatpak apps show up in any launcher (wofi, dmenu, GNOME menu,
|
||||||
|
// KDE...) regardless of XDG_DATA_DIRS, mirroring what a pacman install does
|
||||||
|
// through /usr/share/applications.
|
||||||
|
void FlatpakManager::integrateDesktopEntries(const std::string& appId) {
|
||||||
|
std::error_code ec;
|
||||||
|
fs::path exports = userShareDir() / "flatpak/exports/share";
|
||||||
|
if (!fs::is_directory(exports, ec)) return;
|
||||||
|
|
||||||
|
// .desktop files are the core of the integration.
|
||||||
|
fs::path srcApps = exports / "applications";
|
||||||
|
fs::path destApps = userShareDir() / "applications";
|
||||||
|
if (fs::is_directory(srcApps, ec)) {
|
||||||
|
fs::create_directories(destApps, ec);
|
||||||
|
for (const auto& entry : fs::directory_iterator(srcApps)) {
|
||||||
|
const std::string name = entry.path().filename().string();
|
||||||
|
if (name.rfind(appId, 0) == 0
|
||||||
|
&& entry.path().extension() == ".desktop") {
|
||||||
|
linkFile(entry.path(), destApps / name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mirror the app's icons so the launcher shows a proper icon.
|
||||||
|
fs::path srcIcons = exports / "icons";
|
||||||
|
fs::path destIcons = userShareDir() / "icons";
|
||||||
|
if (fs::is_directory(srcIcons, ec)) {
|
||||||
|
for (const auto& entry : fs::recursive_directory_iterator(srcIcons)) {
|
||||||
|
if (!entry.is_regular_file()) continue;
|
||||||
|
const std::string name = entry.path().filename().string();
|
||||||
|
if (name.rfind(appId, 0) != 0) continue;
|
||||||
|
auto rel = entry.path().lexically_relative(srcIcons);
|
||||||
|
linkFile(entry.path(), destIcons / rel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh the desktop-entry database so launchers pick up the new entries.
|
||||||
|
system(("update-desktop-database " + destApps.string() + " >/dev/null 2>&1").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the launcher links created by integrateDesktopEntries. Only entries
|
||||||
|
// that are symlinks we created are removed, so a real file of the same name is
|
||||||
|
// never touched.
|
||||||
|
void FlatpakManager::uninstallDesktopEntries(const std::string& appId) {
|
||||||
|
auto removeLinks = [&](const fs::path& dir, bool recursive) {
|
||||||
|
std::error_code ec;
|
||||||
|
if (!fs::is_directory(dir, ec)) return;
|
||||||
|
if (recursive) {
|
||||||
|
for (const auto& entry : fs::recursive_directory_iterator(dir, ec)) {
|
||||||
|
if (!entry.is_symlink()) continue;
|
||||||
|
if (entry.path().filename().string().rfind(appId, 0) != 0) continue;
|
||||||
|
fs::remove(entry.path(), ec);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const auto& entry : fs::directory_iterator(dir, ec)) {
|
||||||
|
if (!entry.is_symlink()) continue;
|
||||||
|
if (entry.path().filename().string().rfind(appId, 0) != 0) continue;
|
||||||
|
fs::remove(entry.path(), ec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
removeLinks(userShareDir() / "applications", /*recursive=*/false);
|
||||||
|
removeLinks(userShareDir() / "icons", /*recursive=*/true);
|
||||||
|
|
||||||
|
system(("update-desktop-database " + (userShareDir() / "applications").string()
|
||||||
|
+ " >/dev/null 2>&1").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlatpakManager::integrateAllInstalled() {
|
||||||
|
for (const auto& pkg : listInstalled()) {
|
||||||
|
integrateDesktopEntries(pkg.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FlatpakManager::remove(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) {
|
||||||
|
m_lastError.clear();
|
||||||
|
if (progressCallback) progressCallback("Suppression de " + packageName + "...", -1);
|
||||||
|
|
||||||
|
std::string output = exec(
|
||||||
|
("flatpak uninstall --noninteractive --assumeyes " + packageName + " 2>&1").c_str());
|
||||||
|
streamOutput(output, progressCallback);
|
||||||
|
|
||||||
|
if (output.find("error:") != std::string::npos || isInstalled(packageName)) {
|
||||||
|
m_lastError = lastOutputLines(output);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the launcher links created at install time (see integrateDesktopEntries).
|
||||||
|
uninstallDesktopEntries(packageName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FlatpakManager::update(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) {
|
||||||
|
m_lastError.clear();
|
||||||
|
auto tryUpdate = [&](const std::string& extra) {
|
||||||
|
if (packageName.empty()) {
|
||||||
|
return exec(("flatpak update --noninteractive --assumeyes " + extra + " 2>&1").c_str());
|
||||||
|
}
|
||||||
|
return exec(("flatpak update --noninteractive --assumeyes " + extra + " "
|
||||||
|
+ packageName + " 2>&1").c_str());
|
||||||
|
};
|
||||||
|
|
||||||
|
if (packageName.empty()) {
|
||||||
|
if (progressCallback) progressCallback("Mise à jour de toutes les applications...", -1);
|
||||||
|
} else {
|
||||||
|
if (progressCallback) progressCallback("Mise à jour de " + packageName + "...", -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string output = tryUpdate("");
|
||||||
|
// System-wide updates need polkit: fall back to the per-user installation.
|
||||||
|
if (output.find("error:") != std::string::npos) {
|
||||||
|
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...", -1);
|
||||||
|
output = tryUpdate("--user");
|
||||||
|
}
|
||||||
|
streamOutput(output, progressCallback);
|
||||||
|
|
||||||
|
if (output.find("error:") != std::string::npos) {
|
||||||
|
m_lastError = lastOutputLines(output);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FlatpakManager::refresh(ProgressCallback progressCallback) {
|
||||||
|
m_lastError.clear();
|
||||||
|
if (progressCallback) progressCallback("Rafraîchissement des métadonnées Flatpak...", -1);
|
||||||
|
|
||||||
|
// Re-download the appstream metadata of every remote so search and
|
||||||
|
// update detection reflect the latest published versions.
|
||||||
|
std::string output = exec("flatpak update --appstream 2>&1");
|
||||||
|
|
||||||
|
// System remotes need polkit for that: fall back to the user installation.
|
||||||
|
if (output.find("error:") != std::string::npos) {
|
||||||
|
exec("flatpak remote-add --if-not-exists --user flathub "
|
||||||
|
"https://flathub.org/repo/flathub.flatpakrepo 2>&1");
|
||||||
|
output = exec("flatpak update --appstream --user 2>&1");
|
||||||
|
}
|
||||||
|
streamOutput(output, progressCallback);
|
||||||
|
|
||||||
|
if (output.find("error:") != std::string::npos) {
|
||||||
|
m_lastError = lastOutputLines(output);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Self-heal: re-link launcher entries of every installed app so any that
|
||||||
|
// predate desktop integration (or were installed outside the app) still
|
||||||
|
// show up in the desktop menu.
|
||||||
|
integrateAllInstalled();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "package-manager.h"
|
||||||
|
|
||||||
|
// Flatpak provider: manages flatpak applications through the `flatpak` CLI.
|
||||||
|
// Unlike pacman it runs per-user (no sudo), so requiresPassword() is false.
|
||||||
|
class FlatpakManager : public IPackageManager {
|
||||||
|
public:
|
||||||
|
std::string getName() const override { return "flatpak"; }
|
||||||
|
std::string getVersion() const override { return "1.0.0"; }
|
||||||
|
std::string getDescription() const override {
|
||||||
|
return "Gestionnaire d'applications Flatpak";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool canSearch() const override { return true; }
|
||||||
|
bool canInstall() const override { return true; }
|
||||||
|
bool canRemove() const override { return true; }
|
||||||
|
bool canUpdate() const override { return true; }
|
||||||
|
bool canListInstalled() const override { return true; }
|
||||||
|
|
||||||
|
bool isAvailable() const override {
|
||||||
|
return system("which flatpak > /dev/null 2>&1") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Last lines of the failed command output, shown to the user on failure.
|
||||||
|
std::string lastError() const override { return m_lastError; }
|
||||||
|
|
||||||
|
// Parse `flatpak search` output (one whitespace-aligned row per app:
|
||||||
|
// "Name Description Application ID Version Branch Remotes").
|
||||||
|
// Exposed as static so the parsing can be unit-tested without flatpak.
|
||||||
|
static std::vector<PackageInfo> parseSearchOutput(const std::string& output);
|
||||||
|
|
||||||
|
// Parse `flatpak list --columns=application,version,origin` output
|
||||||
|
// (tab-separated fields per installed application).
|
||||||
|
static std::vector<PackageInfo> parseInstalledOutput(const std::string& output);
|
||||||
|
|
||||||
|
// Parse `flatpak remote-ls --updates --columns=application,version` output
|
||||||
|
// (tab-separated fields per application with a pending update).
|
||||||
|
static std::vector<PackageInfo> parseUpdatesOutput(const std::string& output);
|
||||||
|
|
||||||
|
std::vector<PackageInfo> search(const std::string& query) override;
|
||||||
|
bool install(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) override;
|
||||||
|
bool remove(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) override;
|
||||||
|
bool update(const std::string& packageName = "",
|
||||||
|
ProgressCallback progressCallback = nullptr) override;
|
||||||
|
std::vector<PackageInfo> listInstalled() override;
|
||||||
|
std::vector<PackageInfo> listUpdates() override;
|
||||||
|
bool refresh(ProgressCallback progressCallback = nullptr) override;
|
||||||
|
|
||||||
|
// Make an app appear in the desktop's application launcher (wofi, GNOME,
|
||||||
|
// KDE, ...) regardless of XDG_DATA_DIRS, like a pacman install would: link
|
||||||
|
// its .desktop entries and icons from flatpak's exports into the user's
|
||||||
|
// standard XDG directories (~/.local/share/{applications,icons}). Exposed
|
||||||
|
// as static so the linking can be unit/integration tested without flatpak.
|
||||||
|
static void integrateDesktopEntries(const std::string& appId);
|
||||||
|
static void uninstallDesktopEntries(const std::string& appId);
|
||||||
|
|
||||||
|
// Re-link every installed app so launchers pick up apps whose integration
|
||||||
|
// is missing (e.g. installed before this feature existed).
|
||||||
|
void integrateAllInstalled();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isInstalled(const std::string& appId);
|
||||||
|
|
||||||
|
std::string m_lastError;
|
||||||
|
};
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// Flatpak provider plugin — an external provider loaded at runtime by
|
||||||
|
// PluginManager from the plugins/ directory next to the executable (or in
|
||||||
|
// ~/.local/share/PacManager/plugins/). It exports the C ABI contract declared
|
||||||
|
// in provider-plugin.h so the host can query metadata, check the backing tool,
|
||||||
|
// and instantiate the manager without any compiled-in Flatpak support.
|
||||||
|
//
|
||||||
|
// Built by default (see the FWS_BUILD_FLATPAK_PLUGIN CMake option): the
|
||||||
|
// flatpak-provider-plugin target compiles this file together with
|
||||||
|
// flatpak-manager.cpp into libflatpak-provider.so and copies it next to the
|
||||||
|
// PacManager binary, so a default build ships with Flatpak support enabled.
|
||||||
|
|
||||||
|
#include "flatpak-manager.h"
|
||||||
|
#include "provider-plugin.h"
|
||||||
|
|
||||||
|
extern "C" const char* fws_plugin_kind() { return "provider"; }
|
||||||
|
extern "C" const char* fws_plugin_id() { return "flatpak"; }
|
||||||
|
extern "C" const char* fws_plugin_name() { return "Flatpak"; }
|
||||||
|
extern "C" const char* fws_plugin_version() { return "1.0.0"; }
|
||||||
|
extern "C" const char* fws_plugin_description() {
|
||||||
|
return "Gestionnaire d'applications Flatpak";
|
||||||
|
}
|
||||||
|
extern "C" const char* fws_plugin_author() { return "BlackAngelTV"; }
|
||||||
|
extern "C" IPackageManager* fws_create_provider() { return new FlatpakManager(); }
|
||||||
|
// The backing tool is installed by the pacman package "flatpak"; exposing it
|
||||||
|
// lets the Plugins page offer to install the missing tool.
|
||||||
|
extern "C" const char* fws_plugin_install_hint() { return "flatpak"; }
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
add_library(pacman_plugin SHARED pacman_plugin.cpp)
|
|
||||||
target_include_directories(pacman_plugin PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
|
||||||
set_target_properties(pacman_plugin PROPERTIES
|
|
||||||
PREFIX ""
|
|
||||||
OUTPUT_NAME "pacman"
|
|
||||||
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/PackageMapper/plugins"
|
|
||||||
)
|
|
||||||
install(TARGETS pacman_plugin DESTINATION lib/PackageMapper/plugins)
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
#include "IPackageManager.h"
|
|
||||||
#include <array>
|
|
||||||
#include <memory>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
// Helper to run shell commands and capture output
|
|
||||||
static std::string exec(const char* cmd) {
|
|
||||||
std::array<char, 256> buffer;
|
|
||||||
std::string result;
|
|
||||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
|
||||||
if (!pipe) throw std::runtime_error("popen() failed");
|
|
||||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
|
||||||
result += buffer.data();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
class PacmanPlugin : public IPackageManager {
|
|
||||||
public:
|
|
||||||
std::string getName() const override { return "pacman"; }
|
|
||||||
std::string getVersion() const override { return "1.0.0"; }
|
|
||||||
std::string getDescription() const override {
|
|
||||||
return "Gestionnaire de paquets natif d'Arch Linux";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool canSearch() const override { return true; }
|
|
||||||
bool canInstall() const override { return true; }
|
|
||||||
bool canRemove() const override { return true; }
|
|
||||||
bool canUpdate() const override { return true; }
|
|
||||||
bool canListInstalled() const override { return true; }
|
|
||||||
|
|
||||||
bool isAvailable() const override {
|
|
||||||
return system("which pacman > /dev/null 2>&1") == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> search(const std::string& query) override {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
|
|
||||||
std::string cmd = "pacman -Ss " + query + " 2>&1";
|
|
||||||
std::string output = exec(cmd.c_str());
|
|
||||||
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
std::string currentRepo;
|
|
||||||
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
|
|
||||||
// Repository line: repo/name version
|
|
||||||
if (line[0] != ' ' && line[0] != '\t') {
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t slashPos = line.find('/');
|
|
||||||
size_t spacePos = line.find(' ', slashPos);
|
|
||||||
|
|
||||||
if (slashPos != std::string::npos) {
|
|
||||||
pkg.repository = line.substr(0, slashPos);
|
|
||||||
pkg.name = line.substr(slashPos + 1, spacePos - slashPos - 1);
|
|
||||||
|
|
||||||
if (spacePos != std::string::npos) {
|
|
||||||
size_t nextSpace = line.find(' ', spacePos + 1);
|
|
||||||
pkg.version = line.substr(spacePos + 1, nextSpace - spacePos - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg.installed = isPackageInstalled(pkg.name);
|
|
||||||
results.push_back(pkg);
|
|
||||||
currentRepo = pkg.name;
|
|
||||||
}
|
|
||||||
// Description line (starts with spaces)
|
|
||||||
else if (!results.empty()) {
|
|
||||||
std::string desc = line;
|
|
||||||
// Trim leading spaces
|
|
||||||
size_t start = desc.find_first_not_of(" \t");
|
|
||||||
if (start != std::string::npos) {
|
|
||||||
desc = desc.substr(start);
|
|
||||||
}
|
|
||||||
results.back().description = desc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool install(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
if (progressCallback) progressCallback("Installation de " + packageName + "...");
|
|
||||||
|
|
||||||
std::string cmd = "sudo pacman -S --noconfirm " + packageName + " 2>&1";
|
|
||||||
std::string output = exec(cmd.c_str());
|
|
||||||
|
|
||||||
if (progressCallback) {
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (!line.empty()) progressCallback(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return isPackageInstalled(packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool remove(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
if (progressCallback) progressCallback("Suppression de " + packageName + "...");
|
|
||||||
|
|
||||||
std::string cmd = "sudo pacman -R --noconfirm " + packageName + " 2>&1";
|
|
||||||
std::string output = exec(cmd.c_str());
|
|
||||||
|
|
||||||
if (progressCallback) {
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (!line.empty()) progressCallback(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return !isPackageInstalled(packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool update(const std::string& packageName = "",
|
|
||||||
std::function<void(const std::string&)> progressCallback = nullptr) override {
|
|
||||||
if (packageName.empty()) {
|
|
||||||
if (progressCallback) progressCallback("Mise à jour de tous les paquets...");
|
|
||||||
std::string cmd = "sudo pacman -Syu --noconfirm 2>&1";
|
|
||||||
exec(cmd.c_str());
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
if (progressCallback) progressCallback("Mise à jour de " + packageName + "...");
|
|
||||||
std::string cmd = "sudo pacman -S --noconfirm " + packageName + " 2>&1";
|
|
||||||
exec(cmd.c_str());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> listInstalled() override {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
|
|
||||||
std::string output = exec("pacman -Q 2>&1");
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t spacePos = line.find(' ');
|
|
||||||
size_t dashPos = line.find('-');
|
|
||||||
|
|
||||||
// Handle package names with hyphens (version starts after last pair of hyphens)
|
|
||||||
size_t lastDash = line.rfind('-');
|
|
||||||
size_t secondLastDash = line.rfind('-', lastDash - 1);
|
|
||||||
|
|
||||||
if (secondLastDash != std::string::npos && lastDash != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, secondLastDash);
|
|
||||||
pkg.version = line.substr(secondLastDash + 1);
|
|
||||||
} else if (spacePos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, spacePos);
|
|
||||||
pkg.version = line.substr(spacePos + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg.installed = true;
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool isPackageInstalled(const std::string& name) {
|
|
||||||
std::string cmd = "pacman -Qi " + name + " > /dev/null 2>&1";
|
|
||||||
return system(cmd.c_str()) == 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
IPackageManager* createPlugin() {
|
|
||||||
return new PacmanPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyPlugin(IPackageManager* plugin) {
|
|
||||||
delete plugin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
add_library(pkg_plugin SHARED pkg_plugin.cpp)
|
|
||||||
target_include_directories(pkg_plugin PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
|
||||||
set_target_properties(pkg_plugin PROPERTIES
|
|
||||||
PREFIX ""
|
|
||||||
OUTPUT_NAME "pkg"
|
|
||||||
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/PackageMapper/plugins"
|
|
||||||
)
|
|
||||||
install(TARGETS pkg_plugin DESTINATION lib/PackageMapper/plugins)
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
#include "IPackageManager.h"
|
|
||||||
#include <array>
|
|
||||||
#include <memory>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
static std::string exec(const char* cmd) {
|
|
||||||
std::array<char, 256> buffer;
|
|
||||||
std::string result;
|
|
||||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
|
||||||
if (!pipe) throw std::runtime_error("popen() failed");
|
|
||||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
|
||||||
result += buffer.data();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
class PkgPlugin : public IPackageManager {
|
|
||||||
public:
|
|
||||||
std::string getName() const override { return "pkg"; }
|
|
||||||
std::string getVersion() const override { return "1.0.0"; }
|
|
||||||
std::string getDescription() const override {
|
|
||||||
return "Gestionnaire de paquets FreeBSD (pkg)";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool canSearch() const override { return true; }
|
|
||||||
bool canInstall() const override { return true; }
|
|
||||||
bool canRemove() const override { return true; }
|
|
||||||
bool canUpdate() const override { return true; }
|
|
||||||
bool canListInstalled() const override { return true; }
|
|
||||||
|
|
||||||
bool isAvailable() const override {
|
|
||||||
return system("which pkg > /dev/null 2>&1") == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> search(const std::string& query) override {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
|
|
||||||
std::string output = exec(("pkg search " + query + " 2>&1").c_str());
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
|
|
||||||
PackageInfo pkg;
|
|
||||||
// pkg search format: name-version [repo]
|
|
||||||
size_t dashPos = line.rfind('-');
|
|
||||||
size_t spacePos = line.find(' ');
|
|
||||||
|
|
||||||
if (dashPos != std::string::npos && spacePos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, dashPos);
|
|
||||||
pkg.version = line.substr(dashPos + 1, spacePos - dashPos - 1);
|
|
||||||
pkg.repository = "freebsd";
|
|
||||||
pkg.installed = isPackageInstalled(pkg.name);
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool install(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
if (progressCallback) progressCallback("Installation de " + packageName + "...");
|
|
||||||
|
|
||||||
std::string output = exec(("sudo pkg install -y " + packageName + " 2>&1").c_str());
|
|
||||||
|
|
||||||
if (progressCallback) {
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (!line.empty()) progressCallback(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return isPackageInstalled(packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool remove(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
if (progressCallback) progressCallback("Suppression de " + packageName + "...");
|
|
||||||
|
|
||||||
std::string output = exec(("sudo pkg delete -y " + packageName + " 2>&1").c_str());
|
|
||||||
|
|
||||||
if (progressCallback) {
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (!line.empty()) progressCallback(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return !isPackageInstalled(packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool update(const std::string& packageName = "",
|
|
||||||
std::function<void(const std::string&)> progressCallback = nullptr) override {
|
|
||||||
if (packageName.empty()) {
|
|
||||||
if (progressCallback) progressCallback("Mise à jour de tous les paquets...");
|
|
||||||
exec("sudo pkg upgrade -y 2>&1");
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
if (progressCallback) progressCallback("Mise à jour de " + packageName + "...");
|
|
||||||
exec(("sudo pkg install -y " + packageName + " 2>&1").c_str());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> listInstalled() override {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
|
|
||||||
std::string output = exec("pkg query '%n-%v' 2>&1");
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t dashPos = line.rfind('-');
|
|
||||||
if (dashPos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, dashPos);
|
|
||||||
pkg.version = line.substr(dashPos + 1);
|
|
||||||
pkg.installed = true;
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool isPackageInstalled(const std::string& name) {
|
|
||||||
return system(("pkg info " + name + " > /dev/null 2>&1").c_str()) == 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
IPackageManager* createPlugin() {
|
|
||||||
return new PkgPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyPlugin(IPackageManager* plugin) {
|
|
||||||
delete plugin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
add_library(universal_plugin SHARED universal_plugin.cpp)
|
|
||||||
target_include_directories(universal_plugin PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
|
||||||
set_target_properties(universal_plugin PROPERTIES
|
|
||||||
PREFIX ""
|
|
||||||
OUTPUT_NAME "universal"
|
|
||||||
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/PackageMapper/plugins"
|
|
||||||
)
|
|
||||||
install(TARGETS universal_plugin DESTINATION lib/PackageMapper/plugins)
|
|
||||||
@@ -1,948 +0,0 @@
|
|||||||
#include "IPackageManager.h"
|
|
||||||
#include <array>
|
|
||||||
#include <memory>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <sstream>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <functional>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// Helper: run shell commands
|
|
||||||
// ============================================================================
|
|
||||||
static std::string exec(const char* cmd, bool captureStderr = true) {
|
|
||||||
std::array<char, 4096> buffer;
|
|
||||||
std::string result;
|
|
||||||
std::string fullCmd = std::string(cmd) + (captureStderr ? " 2>&1" : " 2>/dev/null");
|
|
||||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(fullCmd.c_str(), "r"), pclose);
|
|
||||||
if (!pipe) return "";
|
|
||||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
|
||||||
result += buffer.data();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool commandExists(const char* cmd) {
|
|
||||||
std::string check = std::string("which ") + cmd + " > /dev/null 2>&1";
|
|
||||||
return system(check.c_str()) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// Detected package managers
|
|
||||||
// ============================================================================
|
|
||||||
struct DetectedManager {
|
|
||||||
std::string name;
|
|
||||||
std::string installCmd;
|
|
||||||
std::string searchCmd;
|
|
||||||
std::string removeCmd;
|
|
||||||
std::string updateCmd;
|
|
||||||
std::string listCmd;
|
|
||||||
std::string isInstalledCheck; // command to check if a pkg is installed
|
|
||||||
bool available = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// Source repository info
|
|
||||||
// ============================================================================
|
|
||||||
struct SourceRepo {
|
|
||||||
std::string url;
|
|
||||||
std::string type; // "github", "gitlab", "git", "tarball", "raw"
|
|
||||||
std::string name;
|
|
||||||
std::string branch;
|
|
||||||
bool found = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// Universal Plugin Implementation
|
|
||||||
// ============================================================================
|
|
||||||
class UniversalPlugin : public IPackageManager {
|
|
||||||
public:
|
|
||||||
UniversalPlugin() {
|
|
||||||
detectManagers();
|
|
||||||
detectExtras();
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- IPackageManager interface ---
|
|
||||||
std::string getName() const override { return "universal"; }
|
|
||||||
std::string getVersion() const override { return "2.0.0"; }
|
|
||||||
std::string getDescription() const override {
|
|
||||||
return "Gestionnaire universel - pacman, apt, dnf, pkg, zypper, xbps, "
|
|
||||||
"Flatpak, Snap, AppImage, AUR, Nix, GitHub, compilation source";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool canSearch() const override { return true; }
|
|
||||||
bool canInstall() const override { return true; }
|
|
||||||
bool canRemove() const override { return true; }
|
|
||||||
bool canUpdate() const override { return true; }
|
|
||||||
bool canListInstalled() const override { return true; }
|
|
||||||
bool isAvailable() const override { return true; } // Toujours dispo
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// SEARCH: essaie tout ce qui est disponible
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
std::vector<PackageInfo> search(const std::string& query) override {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
|
|
||||||
// 1) Chercher dans le gestionnaire natif
|
|
||||||
for (auto& mgr : m_managers) {
|
|
||||||
if (!mgr.available) continue;
|
|
||||||
auto pkgs = searchWithManager(mgr, query);
|
|
||||||
for (auto& p : pkgs) {
|
|
||||||
p.repository = mgr.name;
|
|
||||||
results.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2) Chercher dans Flatpak
|
|
||||||
if (m_hasFlatpak) {
|
|
||||||
auto pkgs = searchFlatpak(query);
|
|
||||||
for (auto& p : pkgs) {
|
|
||||||
p.repository = "flatpak";
|
|
||||||
results.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3) Chercher dans Snap
|
|
||||||
if (m_hasSnap) {
|
|
||||||
auto pkgs = searchSnap(query);
|
|
||||||
for (auto& p : pkgs) {
|
|
||||||
p.repository = "snap";
|
|
||||||
results.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4) Chercher sur GitHub
|
|
||||||
auto githubPkgs = searchGitHub(query);
|
|
||||||
for (auto& p : githubPkgs) {
|
|
||||||
p.repository = "github";
|
|
||||||
results.push_back(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5) Chercher dans AUR
|
|
||||||
if (m_hasAUR) {
|
|
||||||
auto pkgs = searchAUR(query);
|
|
||||||
for (auto& p : pkgs) {
|
|
||||||
p.repository = "aur";
|
|
||||||
results.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6) Chercher dans Nix
|
|
||||||
if (m_hasNix) {
|
|
||||||
auto pkgs = searchNix(query);
|
|
||||||
for (auto& p : pkgs) {
|
|
||||||
p.repository = "nix";
|
|
||||||
results.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// INSTALL: essaie la meilleure source
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
bool install(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
if (progressCallback) progressCallback("🔍 Recherche de la meilleure source pour " + packageName + "...");
|
|
||||||
|
|
||||||
// 1) Vérifier si c'est un Flatpak
|
|
||||||
if (m_hasFlatpak && isFlatpakPackage(packageName)) {
|
|
||||||
return installFlatpak(packageName, progressCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2) Vérifier si c'est un Snap
|
|
||||||
if (m_hasSnap && isSnapPackage(packageName)) {
|
|
||||||
return installSnap(packageName, progressCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3) Vérifier si c'est dans AUR
|
|
||||||
if (m_hasAUR && isAURPackage(packageName)) {
|
|
||||||
return installAUR(packageName, progressCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4) Vérifier dans le gestionnaire natif
|
|
||||||
for (auto& mgr : m_managers) {
|
|
||||||
if (!mgr.available) continue;
|
|
||||||
if (isPackageInManager(mgr, packageName)) {
|
|
||||||
if (progressCallback) progressCallback("📦 Installation via " + mgr.name + "...");
|
|
||||||
return installWithManager(mgr, packageName, progressCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5) Essayer Nix
|
|
||||||
if (m_hasNix && isNixPackage(packageName)) {
|
|
||||||
return installNix(packageName, progressCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6) Dernier recours: GitHub / compilation source
|
|
||||||
if (progressCallback) progressCallback("⚙️ Pas de paquet trouvé, tentative depuis GitHub/source...");
|
|
||||||
return installFromSource(packageName, progressCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// REMOVE
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
bool remove(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) override {
|
|
||||||
// Essayer chaque gestionnaire
|
|
||||||
for (auto& mgr : m_managers) {
|
|
||||||
if (!mgr.available) continue;
|
|
||||||
if (isInstalledWithManager(mgr, packageName)) {
|
|
||||||
if (progressCallback) progressCallback("🗑️ Suppression via " + mgr.name + "...");
|
|
||||||
return removeWithManager(mgr, packageName, progressCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flatpak
|
|
||||||
if (m_hasFlatpak) {
|
|
||||||
std::string check = "flatpak list --columns=application | grep -i " + packageName + " > /dev/null 2>&1";
|
|
||||||
if (system(check.c_str()) == 0) {
|
|
||||||
return removeFlatpak(packageName, progressCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Snap
|
|
||||||
if (m_hasSnap) {
|
|
||||||
std::string check = "snap list " + packageName + " > /dev/null 2>&1";
|
|
||||||
if (system(check.c_str()) == 0) {
|
|
||||||
return removeSnap(packageName, progressCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progressCallback) progressCallback("❌ Paquet non trouvé dans aucune source");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// UPDATE
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
bool update(const std::string& packageName = "",
|
|
||||||
std::function<void(const std::string&)> progressCallback = nullptr) override {
|
|
||||||
if (packageName.empty()) {
|
|
||||||
// Update all via le gestionnaire natif
|
|
||||||
for (auto& mgr : m_managers) {
|
|
||||||
if (!mgr.available) continue;
|
|
||||||
if (progressCallback) progressCallback("🔄 Mise à jour via " + mgr.name + "...");
|
|
||||||
std::string cmd = "sudo " + mgr.updateCmd + " 2>&1";
|
|
||||||
exec(cmd.c_str());
|
|
||||||
}
|
|
||||||
// Flatpak
|
|
||||||
if (m_hasFlatpak) {
|
|
||||||
if (progressCallback) progressCallback("🔄 Mise à jour Flatpak...");
|
|
||||||
exec("flatpak update -y 2>&1");
|
|
||||||
}
|
|
||||||
// Snap
|
|
||||||
if (m_hasSnap) {
|
|
||||||
if (progressCallback) progressCallback("🔄 Mise à jour Snap...");
|
|
||||||
exec("sudo snap refresh 2>&1");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update spécifique
|
|
||||||
for (auto& mgr : m_managers) {
|
|
||||||
if (!mgr.available) continue;
|
|
||||||
if (isInstalledWithManager(mgr, packageName)) {
|
|
||||||
if (progressCallback) progressCallback("🔄 Mise à jour via " + mgr.name + "...");
|
|
||||||
std::string cmd = "sudo " + mgr.installCmd + " " + packageName + " 2>&1";
|
|
||||||
exec(cmd.c_str());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// LIST INSTALLED
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
std::vector<PackageInfo> listInstalled() override {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
|
|
||||||
for (auto& mgr : m_managers) {
|
|
||||||
if (!mgr.available) continue;
|
|
||||||
auto pkgs = listInstalledWithManager(mgr);
|
|
||||||
for (auto& p : pkgs) {
|
|
||||||
p.repository = mgr.name;
|
|
||||||
results.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_hasFlatpak) {
|
|
||||||
auto pkgs = listInstalledFlatpak();
|
|
||||||
for (auto& p : pkgs) {
|
|
||||||
p.repository = "flatpak";
|
|
||||||
results.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_hasSnap) {
|
|
||||||
auto pkgs = listInstalledSnap();
|
|
||||||
for (auto& p : pkgs) {
|
|
||||||
p.repository = "snap";
|
|
||||||
results.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Public helpers ---
|
|
||||||
std::vector<std::string> getAvailableManagers() const {
|
|
||||||
std::vector<std::string> list;
|
|
||||||
for (const auto& mgr : m_managers) {
|
|
||||||
if (mgr.available) list.push_back(mgr.name);
|
|
||||||
}
|
|
||||||
if (m_hasFlatpak) list.push_back("flatpak");
|
|
||||||
if (m_hasSnap) list.push_back("snap");
|
|
||||||
if (m_hasAUR) list.push_back("aur");
|
|
||||||
if (m_hasNix) list.push_back("nix");
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
// =========================================================================
|
|
||||||
// Detection
|
|
||||||
// =========================================================================
|
|
||||||
void detectManagers() {
|
|
||||||
// pacman (Arch)
|
|
||||||
m_managers.push_back({
|
|
||||||
"pacman", "pacman -S --noconfirm", "pacman -Ss",
|
|
||||||
"pacman -R --noconfirm", "pacman -Syu --noconfirm",
|
|
||||||
"pacman -Q", "pacman -Qi", commandExists("pacman")
|
|
||||||
});
|
|
||||||
|
|
||||||
// apt (Debian/Ubuntu)
|
|
||||||
m_managers.push_back({
|
|
||||||
"apt", "apt install -y", "apt search",
|
|
||||||
"apt remove -y", "apt update && apt upgrade -y",
|
|
||||||
"dpkg --get-selections", "dpkg -l", commandExists("apt")
|
|
||||||
});
|
|
||||||
|
|
||||||
// dnf (Fedora/RHEL)
|
|
||||||
m_managers.push_back({
|
|
||||||
"dnf", "dnf install -y", "dnf search",
|
|
||||||
"dnf remove -y", "dnf upgrade -y",
|
|
||||||
"dnf list installed", "rpm -q", commandExists("dnf")
|
|
||||||
});
|
|
||||||
|
|
||||||
// yum (ancien RHEL/CentOS)
|
|
||||||
m_managers.push_back({
|
|
||||||
"yum", "yum install -y", "yum search",
|
|
||||||
"yum remove -y", "yum update -y",
|
|
||||||
"yum list installed", "rpm -q", commandExists("yum") && !commandExists("dnf")
|
|
||||||
});
|
|
||||||
|
|
||||||
// zypper (openSUSE)
|
|
||||||
m_managers.push_back({
|
|
||||||
"zypper", "zypper install -y", "zypper search",
|
|
||||||
"zypper remove -y", "zypper update -y",
|
|
||||||
"zypper packages -i", "rpm -q", commandExists("zypper")
|
|
||||||
});
|
|
||||||
|
|
||||||
// xbps (Void Linux)
|
|
||||||
m_managers.push_back({
|
|
||||||
"xbps-install", "xbps-install -y", "xbps-query -Rs",
|
|
||||||
"xbps-remove -y", "xbps-install -Su",
|
|
||||||
"xbps-query -l", "xbps-query -i", commandExists("xbps-install")
|
|
||||||
});
|
|
||||||
|
|
||||||
// apk (Alpine)
|
|
||||||
m_managers.push_back({
|
|
||||||
"apk", "apk add", "apk search",
|
|
||||||
"apk del", "apk upgrade",
|
|
||||||
"apk list --installed", "apk info -e", commandExists("apk")
|
|
||||||
});
|
|
||||||
|
|
||||||
// pkg (FreeBSD)
|
|
||||||
m_managers.push_back({
|
|
||||||
"pkg", "pkg install -y", "pkg search",
|
|
||||||
"pkg delete -y", "pkg upgrade -y",
|
|
||||||
"pkg query '%n-%v'", "pkg info", commandExists("pkg")
|
|
||||||
});
|
|
||||||
|
|
||||||
// brew (macOS/Linux)
|
|
||||||
m_managers.push_back({
|
|
||||||
"brew", "brew install", "brew search",
|
|
||||||
"brew uninstall", "brew upgrade",
|
|
||||||
"brew list", "brew list", commandExists("brew")
|
|
||||||
});
|
|
||||||
|
|
||||||
// scoop (Windows)
|
|
||||||
m_managers.push_back({
|
|
||||||
"scoop", "scoop install", "scoop search",
|
|
||||||
"scoop uninstall", "scoop update",
|
|
||||||
"scoop list", "scoop info", commandExists("scoop")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void detectExtras() {
|
|
||||||
m_hasFlatpak = commandExists("flatpak");
|
|
||||||
m_hasSnap = commandExists("snap");
|
|
||||||
m_hasAUR = commandExists("makepkg");
|
|
||||||
m_hasNix = commandExists("nix-env");
|
|
||||||
m_hasCurl = commandExists("curl");
|
|
||||||
m_hasGit = commandExists("git");
|
|
||||||
m_hasMake = commandExists("make");
|
|
||||||
m_hasCMake = commandExists("cmake");
|
|
||||||
m_hasGcc = commandExists("gcc") || commandExists("g++");
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================================================================
|
|
||||||
// Native manager operations
|
|
||||||
// =========================================================================
|
|
||||||
std::vector<PackageInfo> searchWithManager(const DetectedManager& mgr, const std::string& query) {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
std::string cmd = mgr.searchCmd + " " + query + " 2>&1";
|
|
||||||
std::string output = exec(cmd.c_str());
|
|
||||||
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty() || line[0] == ' ' || line[0] == '\t') continue;
|
|
||||||
if (line.find("error") != std::string::npos ||
|
|
||||||
line.find("warning") != std::string::npos) continue;
|
|
||||||
|
|
||||||
PackageInfo pkg;
|
|
||||||
// Parse common formats: "name version - description" or "name version description"
|
|
||||||
size_t spacePos = line.find(' ');
|
|
||||||
if (spacePos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, spacePos);
|
|
||||||
size_t nextSpace = line.find(' ', spacePos + 1);
|
|
||||||
if (nextSpace != std::string::npos) {
|
|
||||||
pkg.version = line.substr(spacePos + 1, nextSpace - spacePos - 1);
|
|
||||||
size_t descStart = line.find_first_not_of(" \t", nextSpace);
|
|
||||||
if (descStart != std::string::npos) {
|
|
||||||
pkg.description = line.substr(descStart);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pkg.version = line.substr(spacePos + 1);
|
|
||||||
}
|
|
||||||
pkg.installed = isInstalledWithManager(mgr, pkg.name);
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool installWithManager(const DetectedManager& mgr, const std::string& pkg,
|
|
||||||
std::function<void(const std::string&)> progressCallback) {
|
|
||||||
std::string cmd = "sudo " + mgr.installCmd + " " + pkg + " 2>&1";
|
|
||||||
std::string output = exec(cmd.c_str());
|
|
||||||
if (progressCallback) {
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (!line.empty()) progressCallback(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isInstalledWithManager(mgr, pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool removeWithManager(const DetectedManager& mgr, const std::string& pkg,
|
|
||||||
std::function<void(const std::string&)> progressCallback) {
|
|
||||||
std::string cmd = "sudo " + mgr.removeCmd + " " + pkg + " 2>&1";
|
|
||||||
exec(cmd.c_str());
|
|
||||||
return !isInstalledWithManager(mgr, pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isInstalledWithManager(const DetectedManager& mgr, const std::string& pkg) {
|
|
||||||
std::string cmd = mgr.isInstalledCheck + " " + pkg + " > /dev/null 2>&1";
|
|
||||||
return system(cmd.c_str()) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isPackageInManager(const DetectedManager& mgr, const std::string& pkg) {
|
|
||||||
std::string cmd = mgr.searchCmd + " " + pkg + " 2>&1 | grep -qi " + pkg;
|
|
||||||
std::string output = exec(cmd.c_str());
|
|
||||||
return !output.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> listInstalledWithManager(const DetectedManager& mgr) {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
std::string output = exec((mgr.listCmd + " 2>&1").c_str());
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t spacePos = line.find(' ');
|
|
||||||
if (spacePos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, spacePos);
|
|
||||||
pkg.version = line.substr(spacePos + 1);
|
|
||||||
pkg.installed = true;
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================================================================
|
|
||||||
// Flatpak
|
|
||||||
// =========================================================================
|
|
||||||
bool isFlatpakPackage(const std::string& pkg) {
|
|
||||||
std::string cmd = "flatpak search " + pkg + " --columns=application 2>/dev/null | grep -qi " + pkg;
|
|
||||||
return !exec(cmd.c_str()).empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> searchFlatpak(const std::string& query) {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
std::string output = exec(("flatpak search " + query + " 2>&1").c_str());
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t tabPos = line.find('\t');
|
|
||||||
if (tabPos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, tabPos);
|
|
||||||
size_t nextTab = line.find('\t', tabPos + 1);
|
|
||||||
if (nextTab != std::string::npos) {
|
|
||||||
pkg.description = line.substr(tabPos + 1, nextTab - tabPos - 1);
|
|
||||||
}
|
|
||||||
pkg.installed = isFlatpakInstalled(pkg.name);
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isFlatpakInstalled(const std::string& pkg) {
|
|
||||||
std::string cmd = "flatpak list --columns=application | grep -q '^" + pkg + "$'";
|
|
||||||
return system(cmd.c_str()) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool installFlatpak(const std::string& pkg,
|
|
||||||
std::function<void(const std::string&)> progressCallback) {
|
|
||||||
if (progressCallback) progressCallback("📦 Installation Flatpak: " + pkg + "...");
|
|
||||||
exec(("flatpak install -y flathub " + pkg + " 2>&1").c_str());
|
|
||||||
return isFlatpakInstalled(pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool removeFlatpak(const std::string& pkg,
|
|
||||||
std::function<void(const std::string&)> progressCallback) {
|
|
||||||
if (progressCallback) progressCallback("🗑️ Suppression Flatpak: " + pkg + "...");
|
|
||||||
exec(("flatpak uninstall -y " + pkg + " 2>&1").c_str());
|
|
||||||
return !isFlatpakInstalled(pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> listInstalledFlatpak() {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
std::string output = exec("flatpak list --columns=application,version 2>&1");
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t tabPos = line.find('\t');
|
|
||||||
if (tabPos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, tabPos);
|
|
||||||
pkg.version = line.substr(tabPos + 1);
|
|
||||||
pkg.installed = true;
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================================================================
|
|
||||||
// Snap
|
|
||||||
// =========================================================================
|
|
||||||
bool isSnapPackage(const std::string& pkg) {
|
|
||||||
std::string cmd = "snap find " + pkg + " 2>&1 | head -5 | grep -qi " + pkg;
|
|
||||||
return !exec(cmd.c_str()).empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> searchSnap(const std::string& query) {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
std::string output = exec(("snap find " + query + " 2>&1").c_str());
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
bool headerSkipped = false;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
if (!headerSkipped) { headerSkipped = true; continue; } // skip header
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t tabPos = line.find('\t');
|
|
||||||
if (tabPos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, tabPos);
|
|
||||||
pkg.installed = isSnapInstalled(pkg.name);
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSnapInstalled(const std::string& pkg) {
|
|
||||||
std::string cmd = "snap list " + pkg + " > /dev/null 2>&1";
|
|
||||||
return system(cmd.c_str()) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool installSnap(const std::string& pkg,
|
|
||||||
std::function<void(const std::string&)> progressCallback) {
|
|
||||||
if (progressCallback) progressCallback("📦 Installation Snap: " + pkg + "...");
|
|
||||||
exec(("sudo snap install " + pkg + " 2>&1").c_str());
|
|
||||||
return isSnapInstalled(pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool removeSnap(const std::string& pkg,
|
|
||||||
std::function<void(const std::string&)> progressCallback) {
|
|
||||||
if (progressCallback) progressCallback("🗑️ Suppression Snap: " + pkg + "...");
|
|
||||||
exec(("sudo snap remove " + pkg + " 2>&1").c_str());
|
|
||||||
return !isSnapInstalled(pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> listInstalledSnap() {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
std::string output = exec("snap list 2>&1");
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
bool headerSkipped = false;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
if (!headerSkipped) { headerSkipped = true; continue; }
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t tabPos = line.find('\t');
|
|
||||||
if (tabPos != std::string::npos) {
|
|
||||||
pkg.name = line.substr(0, tabPos);
|
|
||||||
pkg.installed = true;
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================================================================
|
|
||||||
// AUR (Arch User Repository)
|
|
||||||
// =========================================================================
|
|
||||||
bool isAURPackage(const std::string& pkg) {
|
|
||||||
if (m_hasCurl) {
|
|
||||||
std::string cmd = "curl -s \"https://aur.archlinux.org/rpc/v5/info/" + pkg + "\" 2>&1 | grep -q '\"results\"'";
|
|
||||||
return system(cmd.c_str()) == 0;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> searchAUR(const std::string& query) {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
if (!m_hasCurl) return results;
|
|
||||||
|
|
||||||
std::string cmd = "curl -s \"https://aur.archlinux.org/rpc/v5/search/" + query + "\" 2>&1";
|
|
||||||
std::string output = exec(cmd.c_str());
|
|
||||||
|
|
||||||
// Simple JSON parse for AUR results
|
|
||||||
size_t pos = 0;
|
|
||||||
while ((pos = output.find("\"Name\":\"", pos)) != std::string::npos) {
|
|
||||||
size_t start = pos + 8;
|
|
||||||
size_t end = output.find("\"", start);
|
|
||||||
if (end != std::string::npos) {
|
|
||||||
PackageInfo pkg;
|
|
||||||
pkg.name = output.substr(start, end - start);
|
|
||||||
|
|
||||||
// Find description
|
|
||||||
size_t descPos = output.find("\"Description\":\"", end);
|
|
||||||
if (descPos != std::string::npos) {
|
|
||||||
size_t descStart = descPos + 15;
|
|
||||||
size_t descEnd = output.find("\"", descStart);
|
|
||||||
if (descEnd != std::string::npos) {
|
|
||||||
pkg.description = output.substr(descStart, descEnd - descStart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find version
|
|
||||||
size_t verPos = output.find("\"Version\":\"", end);
|
|
||||||
if (verPos != std::string::npos) {
|
|
||||||
size_t verStart = verPos + 11;
|
|
||||||
size_t verEnd = output.find("\"", verStart);
|
|
||||||
if (verEnd != std::string::npos) {
|
|
||||||
pkg.version = output.substr(verStart, verEnd - verStart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg.repository = "aur";
|
|
||||||
pkg.installed = isAURInstalled(pkg.name);
|
|
||||||
results.push_back(pkg);
|
|
||||||
pos = end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isAURInstalled(const std::string& pkg) {
|
|
||||||
std::string cmd = "pacman -Qi " + pkg + " > /dev/null 2>&1";
|
|
||||||
return system(cmd.c_str()) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool installAUR(const std::string& pkg,
|
|
||||||
std::function<void(const std::string&)> progressCallback) {
|
|
||||||
if (progressCallback) progressCallback("⚙️ Clonage depuis AUR: " + pkg + "...");
|
|
||||||
|
|
||||||
std::string tmpDir = "/tmp/aur-build-" + pkg;
|
|
||||||
std::string cloneCmd = "rm -rf " + tmpDir + " && git clone https://aur.archlinux.org/" + pkg + ".git " + tmpDir;
|
|
||||||
exec(cloneCmd.c_str());
|
|
||||||
|
|
||||||
if (progressCallback) progressCallback("⚙️ Compilation avec makepkg...");
|
|
||||||
std::string buildCmd = "cd " + tmpDir + " && makepkg -si --noconfirm 2>&1";
|
|
||||||
std::string output = exec(buildCmd.c_str());
|
|
||||||
|
|
||||||
if (progressCallback) {
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (!line.empty()) progressCallback(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
exec(("rm -rf " + tmpDir).c_str());
|
|
||||||
|
|
||||||
return isAURInstalled(pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================================================================
|
|
||||||
// Nix
|
|
||||||
// =========================================================================
|
|
||||||
bool isNixPackage(const std::string& pkg) {
|
|
||||||
std::string cmd = "nix-env -qaP " + pkg + " 2>&1 | grep -qi " + pkg;
|
|
||||||
return !exec(cmd.c_str()).empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PackageInfo> searchNix(const std::string& query) {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
std::string output = exec(("nix-env -qaP " + query + " 2>&1").c_str());
|
|
||||||
std::istringstream iss(output);
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(iss, line)) {
|
|
||||||
if (line.empty()) continue;
|
|
||||||
PackageInfo pkg;
|
|
||||||
size_t spacePos = line.find(' ');
|
|
||||||
size_t tabPos = line.find('\t');
|
|
||||||
if (tabPos != std::string::npos) {
|
|
||||||
// Format: "nixpkgs.package-name package-name-version"
|
|
||||||
std::string fullPath = line.substr(0, tabPos);
|
|
||||||
size_t lastDot = fullPath.rfind('.');
|
|
||||||
if (lastDot != std::string::npos) {
|
|
||||||
pkg.name = fullPath.substr(lastDot + 1);
|
|
||||||
}
|
|
||||||
pkg.version = line.substr(tabPos + 1);
|
|
||||||
pkg.repository = "nix";
|
|
||||||
pkg.installed = isNixInstalled(pkg.name);
|
|
||||||
results.push_back(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNixInstalled(const std::string& pkg) {
|
|
||||||
std::string cmd = "nix-env -q " + pkg + " > /dev/null 2>&1";
|
|
||||||
return system(cmd.c_str()) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool installNix(const std::string& pkg,
|
|
||||||
std::function<void(const std::string&)> progressCallback) {
|
|
||||||
if (progressCallback) progressCallback("📦 Installation Nix: " + pkg + "...");
|
|
||||||
exec(("nix-env -iA nixpkgs." + pkg + " 2>&1").c_str());
|
|
||||||
return isNixInstalled(pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================================================================
|
|
||||||
// GitHub search
|
|
||||||
// =========================================================================
|
|
||||||
std::vector<PackageInfo> searchGitHub(const std::string& query) {
|
|
||||||
std::vector<PackageInfo> results;
|
|
||||||
if (!m_hasCurl) return results;
|
|
||||||
|
|
||||||
std::string cmd = "curl -s 'https://api.github.com/search/repositories?q=" + query + "&sort=stars&per_page=5' 2>&1";
|
|
||||||
std::string output = exec(cmd.c_str());
|
|
||||||
|
|
||||||
size_t pos = 0;
|
|
||||||
while ((pos = output.find("\"full_name\":\"", pos)) != std::string::npos) {
|
|
||||||
size_t start = pos + 13;
|
|
||||||
size_t end = output.find("\"", start);
|
|
||||||
if (end != std::string::npos) {
|
|
||||||
PackageInfo pkg;
|
|
||||||
std::string fullName = output.substr(start, end - start);
|
|
||||||
size_t slashPos = fullName.find('/');
|
|
||||||
pkg.name = (slashPos != std::string::npos) ? fullName.substr(slashPos + 1) : fullName;
|
|
||||||
pkg.repository = "github";
|
|
||||||
|
|
||||||
// Find description
|
|
||||||
size_t descPos = output.find("\"description\":\"", end);
|
|
||||||
if (descPos != std::string::npos && descPos < end + 500) {
|
|
||||||
size_t dStart = descPos + 16;
|
|
||||||
size_t dEnd = output.find("\"", dStart);
|
|
||||||
if (dEnd != std::string::npos) {
|
|
||||||
pkg.description = output.substr(dStart, dEnd - dStart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg.version = "source";
|
|
||||||
pkg.installed = false;
|
|
||||||
results.push_back(pkg);
|
|
||||||
pos = end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================================================================
|
|
||||||
// GitHub / Source compilation
|
|
||||||
// =========================================================================
|
|
||||||
SourceRepo findSourceRepo(const std::string& query) {
|
|
||||||
SourceRepo repo;
|
|
||||||
|
|
||||||
if (m_hasCurl) {
|
|
||||||
// Search GitHub API
|
|
||||||
std::string cmd = "curl -s \"https://api.github.com/search/repositories?q=" + query + "&sort=stars&per_page=1\" 2>&1";
|
|
||||||
std::string output = exec(cmd.c_str());
|
|
||||||
|
|
||||||
// Parse JSON for html_url
|
|
||||||
size_t urlPos = output.find("\"html_url\":\"");
|
|
||||||
if (urlPos != std::string::npos) {
|
|
||||||
size_t start = urlPos + 12;
|
|
||||||
size_t end = output.find("\"", start);
|
|
||||||
if (end != std::string::npos) {
|
|
||||||
repo.url = output.substr(start, end - start);
|
|
||||||
repo.type = "github";
|
|
||||||
repo.found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse name
|
|
||||||
size_t namePos = output.find("\"full_name\":\"");
|
|
||||||
if (namePos != std::string::npos) {
|
|
||||||
size_t start = namePos + 13;
|
|
||||||
size_t end = output.find("\"", start);
|
|
||||||
if (end != std::string::npos) {
|
|
||||||
repo.name = output.substr(start, end - start);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return repo;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool installFromSource(const std::string& packageName,
|
|
||||||
std::function<void(const std::string&)> progressCallback) {
|
|
||||||
SourceRepo repo = findSourceRepo(packageName);
|
|
||||||
|
|
||||||
if (!repo.found) {
|
|
||||||
if (progressCallback) progressCallback("❌ Aucune source trouvée pour " + packageName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progressCallback) progressCallback("📥 Clonage depuis " + repo.url + "...");
|
|
||||||
|
|
||||||
std::string tmpDir = "/tmp/source-build-" + packageName;
|
|
||||||
std::string cloneCmd = "rm -rf " + tmpDir + " && git clone --depth 1 " + repo.url + " " + tmpDir;
|
|
||||||
exec(cloneCmd.c_str());
|
|
||||||
|
|
||||||
if (progressCallback) progressCallback("⚙️ Détection du système de build...");
|
|
||||||
|
|
||||||
// Try different build systems
|
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
// CMake
|
|
||||||
if (!success && fileExists(tmpDir + "/CMakeLists.txt")) {
|
|
||||||
if (progressCallback) progressCallback("🔨 Build CMake...");
|
|
||||||
exec(("mkdir -p " + tmpDir + "/build").c_str());
|
|
||||||
exec(("cd " + tmpDir + "/build && cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local 2>&1").c_str());
|
|
||||||
exec(("cd " + tmpDir + "/build && make -j$(nproc) 2>&1").c_str());
|
|
||||||
success = exec(("cd " + tmpDir + "/build && sudo make install 2>&1").c_str()).find("error") == std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Meson
|
|
||||||
if (!success && fileExists(tmpDir + "/meson.build")) {
|
|
||||||
if (progressCallback) progressCallback("🔨 Build Meson...");
|
|
||||||
exec(("cd " + tmpDir + " && meson setup build --prefix=/usr/local 2>&1").c_str());
|
|
||||||
exec(("cd " + tmpDir + "/build && ninja 2>&1").c_str());
|
|
||||||
success = exec(("cd " + tmpDir + "/build && sudo ninja install 2>&1").c_str()).find("error") == std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Autotools (configure)
|
|
||||||
if (!success && fileExists(tmpDir + "/configure")) {
|
|
||||||
if (progressCallback) progressCallback("🔨 Build Autotools...");
|
|
||||||
exec(("cd " + tmpDir + " && ./configure --prefix=/usr/local 2>&1").c_str());
|
|
||||||
exec(("cd " + tmpDir + " && make -j$(nproc) 2>&1").c_str());
|
|
||||||
success = exec(("cd " + tmpDir + " && sudo make install 2>&1").c_str()).find("error") == std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Makefile
|
|
||||||
if (!success && fileExists(tmpDir + "/Makefile")) {
|
|
||||||
if (progressCallback) progressCallback("🔨 Build Make...");
|
|
||||||
exec(("cd " + tmpDir + " && make -j$(nproc) 2>&1").c_str());
|
|
||||||
success = exec(("cd " + tmpDir + " && sudo make install 2>&1").c_str()).find("error") == std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cargo (Rust)
|
|
||||||
if (!success && fileExists(tmpDir + "/Cargo.toml")) {
|
|
||||||
if (progressCallback) progressCallback("🔨 Build Cargo (Rust)...");
|
|
||||||
success = exec(("cd " + tmpDir + " && cargo build --release 2>&1 && sudo cargo install --path . 2>&1").c_str()).find("error") == std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go
|
|
||||||
if (!success && fileExists(tmpDir + "/go.mod")) {
|
|
||||||
if (progressCallback) progressCallback("🔨 Build Go...");
|
|
||||||
success = exec(("cd " + tmpDir + " && go build -o /usr/local/bin/" + packageName + " . 2>&1").c_str()).find("error") == std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// npm (Node.js)
|
|
||||||
if (!success && fileExists(tmpDir + "/package.json")) {
|
|
||||||
if (progressCallback) progressCallback("🔨 Build npm (Node.js)...");
|
|
||||||
exec(("cd " + tmpDir + " && npm install 2>&1").c_str());
|
|
||||||
success = exec(("cd " + tmpDir + " && sudo npm install -g . 2>&1").c_str()).find("error") == std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// pip (Python)
|
|
||||||
if (!success && (fileExists(tmpDir + "/setup.py") || fileExists(tmpDir + "/pyproject.toml"))) {
|
|
||||||
if (progressCallback) progressCallback("🔨 Build pip (Python)...");
|
|
||||||
success = exec(("cd " + tmpDir + " && sudo pip install . 2>&1").c_str()).find("error") == std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
exec(("rm -rf " + tmpDir).c_str());
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
if (progressCallback) progressCallback("✅ " + packageName + " installé depuis source !");
|
|
||||||
} else {
|
|
||||||
if (progressCallback) progressCallback("❌ Échec de la compilation de " + packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fileExists(const std::string& path) {
|
|
||||||
std::string cmd = "test -f " + path + " && echo yes || echo no";
|
|
||||||
std::string result = exec(cmd.c_str());
|
|
||||||
return result.find("yes") != std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================================================================
|
|
||||||
// Data members
|
|
||||||
// =========================================================================
|
|
||||||
std::vector<DetectedManager> m_managers;
|
|
||||||
bool m_hasFlatpak = false;
|
|
||||||
bool m_hasSnap = false;
|
|
||||||
bool m_hasAUR = false;
|
|
||||||
bool m_hasNix = false;
|
|
||||||
bool m_hasCurl = false;
|
|
||||||
bool m_hasGit = false;
|
|
||||||
bool m_hasMake = false;
|
|
||||||
bool m_hasCMake = false;
|
|
||||||
bool m_hasGcc = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// Plugin entry points
|
|
||||||
// ============================================================================
|
|
||||||
extern "C" {
|
|
||||||
IPackageManager* createPlugin() {
|
|
||||||
return new UniversalPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyPlugin(IPackageManager* plugin) {
|
|
||||||
delete plugin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#e0af68" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>
|
||||||
|
<line x1="12" y1="9" x2="12" y2="13"/>
|
||||||
|
<line x1="12" y1="17" x2="12.01" y2="17"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 372 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<line x1="12" y1="19" x2="12" y2="5"/>
|
||||||
|
<polyline points="5 12 12 5 19 12"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 263 B |
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#3fb950" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<polyline points="20 6 9 17 4 12"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 223 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#f7768e" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<line x1="18" y1="6" x2="6" y2="18"/>
|
||||||
|
<line x1="6" y1="6" x2="18" y2="18"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 265 B |
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<path d="M22 3H2l8 9.5V19l4 2v-8.5L22 3z"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 229 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<circle cx="12" cy="12" r="9"/>
|
||||||
|
<path d="M12 7v5l3 3"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 243 B |
@@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<path d="M3 11l9-8 9 8"/>
|
||||||
|
<path d="M5 10v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V10"/>
|
||||||
|
<path d="M9 21v-7h6v7"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 295 B |
@@ -0,0 +1,6 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
|
||||||
|
<path d="M14 2v6h6"/>
|
||||||
|
<path d="M8 13h8"/>
|
||||||
|
<path d="M8 17h5"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 324 B |
@@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<path d="M21 8l-9-5-9 5v8l9 5 9-5V8z"/>
|
||||||
|
<path d="M3 8l9 5 9-5"/>
|
||||||
|
<path d="M12 13v8"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 275 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<path d="M9 3.5a1.75 1.75 0 0 1 3.5 0V6h3.5a1.75 1.75 0 0 1 0 3.5H12.5V13h-3.5a1.75 1.75 0 0 1 0-3.5H6.5a1.75 1.75 0 0 1 0-3.5H9V3.5z"/>
|
||||||
|
<path d="M9 13h3.5v3.5A1.75 1.75 0 0 0 14.25 18.25h.5a1.75 1.75 0 0 0 1.75-1.75V13H20a1.75 1.75 0 0 0 1.75-1.75v-.5A1.75 1.75 0 0 0 20 9h-3.5"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 470 B |
@@ -0,0 +1,6 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<path d="M23 4v6h-6"/>
|
||||||
|
<path d="M1 20v-6h6"/>
|
||||||
|
<path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10"/>
|
||||||
|
<path d="M20.49 15a9 9 0 0 1-14.85 3.36L1 14"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 332 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<circle cx="11" cy="11" r="7"/>
|
||||||
|
<line x1="21" y1="21" x2="16.5" y2="16.5"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 263 B |
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 350 B |
@@ -0,0 +1,7 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||||
|
<path d="M3 6h18"/>
|
||||||
|
<path d="M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2"/>
|
||||||
|
<path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
|
||||||
|
<line x1="10" y1="11" x2="10" y2="17"/>
|
||||||
|
<line x1="14" y1="11" x2="14" y2="17"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 402 B |
@@ -0,0 +1,19 @@
|
|||||||
|
<!DOCTYPE RCC>
|
||||||
|
<RCC version="1.0">
|
||||||
|
<qresource prefix="/icons">
|
||||||
|
<file alias="home.svg">icons/home.svg</file>
|
||||||
|
<file alias="search.svg">icons/search.svg</file>
|
||||||
|
<file alias="package.svg">icons/package.svg</file>
|
||||||
|
<file alias="trash.svg">icons/trash.svg</file>
|
||||||
|
<file alias="arrow-up.svg">icons/arrow-up.svg</file>
|
||||||
|
<file alias="history.svg">icons/history.svg</file>
|
||||||
|
<file alias="logs.svg">icons/logs.svg</file>
|
||||||
|
<file alias="refresh.svg">icons/refresh.svg</file>
|
||||||
|
<file alias="tools.svg">icons/tools.svg</file>
|
||||||
|
<file alias="check.svg">icons/check.svg</file>
|
||||||
|
<file alias="close.svg">icons/close.svg</file>
|
||||||
|
<file alias="filter.svg">icons/filter.svg</file>
|
||||||
|
<file alias="alert.svg">icons/alert.svg</file>
|
||||||
|
<file alias="plugin.svg">icons/plugin.svg</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
@@ -1,731 +0,0 @@
|
|||||||
#include "MainWindow.h"
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QHeaderView>
|
|
||||||
#include <QSplitter>
|
|
||||||
#include <QFrame>
|
|
||||||
#include <QScrollArea>
|
|
||||||
#include <QStyle>
|
|
||||||
#include <QDesktopServices>
|
|
||||||
#include <QUrl>
|
|
||||||
|
|
||||||
// Worker threads
|
|
||||||
SearchWorker::SearchWorker(IPackageManager* pm, const std::string& query)
|
|
||||||
: m_pm(pm), m_query(query) {}
|
|
||||||
|
|
||||||
void SearchWorker::run() {
|
|
||||||
auto results = m_pm->search(m_query);
|
|
||||||
emit finished(results);
|
|
||||||
}
|
|
||||||
|
|
||||||
InstallWorker::InstallWorker(IPackageManager* pm, const std::string& package, bool remove)
|
|
||||||
: m_pm(pm), m_package(package), m_remove(remove) {}
|
|
||||||
|
|
||||||
void InstallWorker::run() {
|
|
||||||
bool success;
|
|
||||||
if (m_remove) {
|
|
||||||
success = m_pm->remove(m_package, [this](const std::string& msg) {
|
|
||||||
emit progress(QString::fromStdString(msg));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
success = m_pm->install(m_package, [this](const std::string& msg) {
|
|
||||||
emit progress(QString::fromStdString(msg));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
emit finished(success);
|
|
||||||
}
|
|
||||||
|
|
||||||
// MainWindow implementation
|
|
||||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
|
||||||
m_pluginManager = new PluginManager();
|
|
||||||
m_historyManager = new HistoryManager();
|
|
||||||
m_packageModel = new PackageModel(this);
|
|
||||||
m_currentPlugin = nullptr;
|
|
||||||
|
|
||||||
setupUI();
|
|
||||||
setupMenuBar();
|
|
||||||
loadPlugins();
|
|
||||||
|
|
||||||
updateStatusBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
|
||||||
delete m_pluginManager;
|
|
||||||
delete m_historyManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::setupUI() {
|
|
||||||
QWidget* centralWidget = new QWidget(this);
|
|
||||||
QVBoxLayout* mainLayout = new QVBoxLayout(centralWidget);
|
|
||||||
mainLayout->setContentsMargins(10, 10, 10, 10);
|
|
||||||
|
|
||||||
// Top bar: Plugin selector + Search
|
|
||||||
QHBoxLayout* topBar = new QHBoxLayout();
|
|
||||||
|
|
||||||
m_pluginSelector = new QComboBox();
|
|
||||||
m_pluginSelector->setMinimumWidth(150);
|
|
||||||
m_pluginSelector->setToolTip("Sélectionner le gestionnaire de paquets");
|
|
||||||
connect(m_pluginSelector, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
||||||
this, &MainWindow::onPluginChanged);
|
|
||||||
topBar->addWidget(m_pluginSelector);
|
|
||||||
|
|
||||||
m_searchBar = new QLineEdit();
|
|
||||||
m_searchBar->setPlaceholderText("🔍 Rechercher un paquet...");
|
|
||||||
m_searchBar->setMinimumHeight(36);
|
|
||||||
m_searchBar->setStyleSheet(
|
|
||||||
"QLineEdit {"
|
|
||||||
" padding: 8px 16px;"
|
|
||||||
" font-size: 14px;"
|
|
||||||
" border: 2px solid #3a3a3a;"
|
|
||||||
" border-radius: 20px;"
|
|
||||||
" background: #2a2a2a;"
|
|
||||||
" color: #ffffff;"
|
|
||||||
"}"
|
|
||||||
"QLineEdit:focus {"
|
|
||||||
" border-color: #6c63ff;"
|
|
||||||
"}"
|
|
||||||
);
|
|
||||||
connect(m_searchBar, &QLineEdit::returnPressed, this, &MainWindow::onSearch);
|
|
||||||
topBar->addWidget(m_searchBar, 1);
|
|
||||||
|
|
||||||
m_searchButton = new QPushButton("Rechercher");
|
|
||||||
m_searchButton->setMinimumHeight(36);
|
|
||||||
m_searchButton->setStyleSheet(
|
|
||||||
"QPushButton {"
|
|
||||||
" background: #6c63ff;"
|
|
||||||
" color: white;"
|
|
||||||
" border: none;"
|
|
||||||
" padding: 8px 24px;"
|
|
||||||
" border-radius: 20px;"
|
|
||||||
" font-weight: bold;"
|
|
||||||
" font-size: 14px;"
|
|
||||||
"}"
|
|
||||||
"QPushButton:hover {"
|
|
||||||
" background: #5a52d5;"
|
|
||||||
"}"
|
|
||||||
);
|
|
||||||
connect(m_searchButton, &QPushButton::clicked, this, &MainWindow::onSearch);
|
|
||||||
topBar->addWidget(m_searchButton);
|
|
||||||
|
|
||||||
mainLayout->addLayout(topBar);
|
|
||||||
|
|
||||||
// Progress bar
|
|
||||||
m_progressBar = new QProgressBar();
|
|
||||||
m_progressBar->setVisible(false);
|
|
||||||
m_progressBar->setStyleSheet(
|
|
||||||
"QProgressBar {"
|
|
||||||
" border: 1px solid #3a3a3a;"
|
|
||||||
" border-radius: 5px;"
|
|
||||||
" text-align: center;"
|
|
||||||
" color: white;"
|
|
||||||
" background: #2a2a2a;"
|
|
||||||
"}"
|
|
||||||
"QProgressBar::chunk {"
|
|
||||||
" background: #6c63ff;"
|
|
||||||
" border-radius: 5px;"
|
|
||||||
"}"
|
|
||||||
);
|
|
||||||
mainLayout->addWidget(m_progressBar);
|
|
||||||
|
|
||||||
// Main content area
|
|
||||||
QSplitter* splitter = new QSplitter(Qt::Horizontal);
|
|
||||||
|
|
||||||
// Left panel: Package list
|
|
||||||
QWidget* leftPanel = new QWidget();
|
|
||||||
QVBoxLayout* leftLayout = new QVBoxLayout(leftPanel);
|
|
||||||
|
|
||||||
// Action buttons
|
|
||||||
QHBoxLayout* buttonBar = new QHBoxLayout();
|
|
||||||
|
|
||||||
m_installButton = new QPushButton("📦 Installer");
|
|
||||||
m_installButton->setEnabled(false);
|
|
||||||
m_installButton->setStyleSheet(
|
|
||||||
"QPushButton { background: #4caf50; color: white; border: none; "
|
|
||||||
"padding: 6px 16px; border-radius: 8px; font-weight: bold; }"
|
|
||||||
"QPushButton:hover { background: #43a047; }"
|
|
||||||
"QPushButton:disabled { background: #555; color: #888; }"
|
|
||||||
);
|
|
||||||
connect(m_installButton, &QPushButton::clicked, this, &MainWindow::onInstall);
|
|
||||||
buttonBar->addWidget(m_installButton);
|
|
||||||
|
|
||||||
m_removeButton = new QPushButton("🗑️ Supprimer");
|
|
||||||
m_removeButton->setEnabled(false);
|
|
||||||
m_removeButton->setStyleSheet(
|
|
||||||
"QPushButton { background: #f44336; color: white; border: none; "
|
|
||||||
"padding: 6px 16px; border-radius: 8px; font-weight: bold; }"
|
|
||||||
"QPushButton:hover { background: #e53935; }"
|
|
||||||
"QPushButton:disabled { background: #555; color: #888; }"
|
|
||||||
);
|
|
||||||
connect(m_removeButton, &QPushButton::clicked, this, &MainWindow::onRemove);
|
|
||||||
buttonBar->addWidget(m_removeButton);
|
|
||||||
|
|
||||||
m_updateButton = new QPushButton("🔄 Mettre à jour");
|
|
||||||
m_updateButton->setEnabled(false);
|
|
||||||
m_updateButton->setStyleSheet(
|
|
||||||
"QPushButton { background: #ff9800; color: white; border: none; "
|
|
||||||
"padding: 6px 16px; border-radius: 8px; font-weight: bold; }"
|
|
||||||
"QPushButton:hover { background: #f57c00; }"
|
|
||||||
"QPushButton:disabled { background: #555; color: #888; }"
|
|
||||||
);
|
|
||||||
connect(m_updateButton, &QPushButton::clicked, this, &MainWindow::onUpdate);
|
|
||||||
buttonBar->addWidget(m_updateButton);
|
|
||||||
|
|
||||||
m_updateAllButton = new QPushButton("⬆️ Tout mettre à jour");
|
|
||||||
m_updateAllButton->setEnabled(false);
|
|
||||||
m_updateAllButton->setStyleSheet(
|
|
||||||
"QPushButton { background: #2196f3; color: white; border: none; "
|
|
||||||
"padding: 6px 16px; border-radius: 8px; font-weight: bold; }"
|
|
||||||
"QPushButton:hover { background: #1e88e5; }"
|
|
||||||
"QPushButton:disabled { background: #555; color: #888; }"
|
|
||||||
);
|
|
||||||
connect(m_updateAllButton, &QPushButton::clicked, this, &MainWindow::onUpdateAll);
|
|
||||||
buttonBar->addWidget(m_updateAllButton);
|
|
||||||
|
|
||||||
leftLayout->addLayout(buttonBar);
|
|
||||||
|
|
||||||
// Package list
|
|
||||||
m_packageList = new QListWidget();
|
|
||||||
m_packageList->setStyleSheet(
|
|
||||||
"QListWidget {"
|
|
||||||
" background: #1e1e1e;"
|
|
||||||
" border: 1px solid #3a3a3a;"
|
|
||||||
" border-radius: 8px;"
|
|
||||||
" padding: 4px;"
|
|
||||||
" font-size: 13px;"
|
|
||||||
"}"
|
|
||||||
"QListWidget::item {"
|
|
||||||
" padding: 8px 12px;"
|
|
||||||
" border-bottom: 1px solid #2a2a2a;"
|
|
||||||
" color: #e0e0e0;"
|
|
||||||
"}"
|
|
||||||
"QListWidget::item:selected {"
|
|
||||||
" background: #3a3a5a;"
|
|
||||||
" color: white;"
|
|
||||||
"}"
|
|
||||||
"QListWidget::item:hover {"
|
|
||||||
" background: #2a2a3a;"
|
|
||||||
"}"
|
|
||||||
);
|
|
||||||
connect(m_packageList, &QListWidget::currentRowChanged,
|
|
||||||
this, &MainWindow::onPackageSelected);
|
|
||||||
leftLayout->addWidget(m_packageList);
|
|
||||||
|
|
||||||
splitter->addWidget(leftPanel);
|
|
||||||
|
|
||||||
// Right panel: Package details
|
|
||||||
QWidget* rightPanel = new QWidget();
|
|
||||||
QVBoxLayout* rightLayout = new QVBoxLayout(rightPanel);
|
|
||||||
|
|
||||||
// Package info cards
|
|
||||||
QFrame* infoCard = new QFrame();
|
|
||||||
infoCard->setStyleSheet(
|
|
||||||
"QFrame {"
|
|
||||||
" background: #1e1e1e;"
|
|
||||||
" border: 1px solid #3a3a3a;"
|
|
||||||
" border-radius: 12px;"
|
|
||||||
" padding: 16px;"
|
|
||||||
"}"
|
|
||||||
);
|
|
||||||
QVBoxLayout* infoLayout = new QVBoxLayout(infoCard);
|
|
||||||
|
|
||||||
m_packageName = new QLabel("Sélectionnez un paquet");
|
|
||||||
m_packageName->setStyleSheet("font-size: 20px; font-weight: bold; color: #6c63ff;");
|
|
||||||
infoLayout->addWidget(m_packageName);
|
|
||||||
|
|
||||||
m_packageVersion = new QLabel("");
|
|
||||||
m_packageVersion->setStyleSheet("font-size: 14px; color: #aaa;");
|
|
||||||
infoLayout->addWidget(m_packageVersion);
|
|
||||||
|
|
||||||
m_packageRepo = new QLabel("");
|
|
||||||
m_packageRepo->setStyleSheet("font-size: 12px; color: #888;");
|
|
||||||
infoLayout->addWidget(m_packageRepo);
|
|
||||||
|
|
||||||
m_packageSize = new QLabel("");
|
|
||||||
m_packageSize->setStyleSheet("font-size: 12px; color: #888;");
|
|
||||||
infoLayout->addWidget(m_packageSize);
|
|
||||||
|
|
||||||
m_packageDescription = new QLabel("");
|
|
||||||
m_packageDescription->setWordWrap(true);
|
|
||||||
m_packageDescription->setStyleSheet("font-size: 13px; color: #ccc; margin-top: 10px;");
|
|
||||||
infoLayout->addWidget(m_packageDescription);
|
|
||||||
|
|
||||||
rightLayout->addWidget(infoCard);
|
|
||||||
|
|
||||||
rightLayout->addStretch();
|
|
||||||
|
|
||||||
splitter->addWidget(rightPanel);
|
|
||||||
splitter->setSizes({600, 400});
|
|
||||||
|
|
||||||
mainLayout->addWidget(splitter, 1);
|
|
||||||
|
|
||||||
// Bottom bar
|
|
||||||
QHBoxLayout* bottomBar = new QHBoxLayout();
|
|
||||||
bottomBar->addStretch();
|
|
||||||
|
|
||||||
m_refreshButton = new QPushButton("🔄 Rafraîchir les sources");
|
|
||||||
m_refreshButton->setStyleSheet(
|
|
||||||
"QPushButton { background: #607d8b; color: white; border: none; "
|
|
||||||
"padding: 6px 16px; border-radius: 8px; }"
|
|
||||||
"QPushButton:hover { background: #546e7a; }"
|
|
||||||
);
|
|
||||||
connect(m_refreshButton, &QPushButton::clicked, this, &MainWindow::onRefresh);
|
|
||||||
bottomBar->addWidget(m_refreshButton);
|
|
||||||
|
|
||||||
m_historyButton = new QPushButton("📋 Historique");
|
|
||||||
m_historyButton->setStyleSheet(
|
|
||||||
"QPushButton { background: #795548; color: white; border: none; "
|
|
||||||
"padding: 6px 16px; border-radius: 8px; }"
|
|
||||||
"QPushButton:hover { background: #6d4c41; }"
|
|
||||||
);
|
|
||||||
connect(m_historyButton, &QPushButton::clicked, this, &MainWindow::onShowHistory);
|
|
||||||
bottomBar->addWidget(m_historyButton);
|
|
||||||
|
|
||||||
mainLayout->addLayout(bottomBar);
|
|
||||||
|
|
||||||
setCentralWidget(centralWidget);
|
|
||||||
|
|
||||||
// Status bar
|
|
||||||
statusBar()->setStyleSheet("color: #888; font-size: 12px;");
|
|
||||||
statusBar()->showMessage("Prêt");
|
|
||||||
|
|
||||||
// Dark theme
|
|
||||||
setStyleSheet(
|
|
||||||
"QMainWindow { background: #121212; }"
|
|
||||||
"QWidget { background: #121212; color: #e0e0e0; }"
|
|
||||||
"QComboBox {"
|
|
||||||
" background: #2a2a2a;"
|
|
||||||
" border: 2px solid #3a3a3a;"
|
|
||||||
" border-radius: 8px;"
|
|
||||||
" padding: 6px 12px;"
|
|
||||||
" color: white;"
|
|
||||||
"}"
|
|
||||||
"QComboBox::drop-down { border: none; }"
|
|
||||||
"QComboBox QAbstractItemView {"
|
|
||||||
" background: #2a2a2a;"
|
|
||||||
" color: white;"
|
|
||||||
" selection-background-color: #6c63ff;"
|
|
||||||
"}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::setupMenuBar() {
|
|
||||||
QMenuBar* menuBar = this->menuBar();
|
|
||||||
menuBar->setStyleSheet(
|
|
||||||
"QMenuBar { background: #1a1a1a; color: white; }"
|
|
||||||
"QMenuBar::item:selected { background: #3a3a3a; }"
|
|
||||||
"QMenu { background: #2a2a2a; color: white; }"
|
|
||||||
"QMenu::item:selected { background: #6c63ff; }"
|
|
||||||
);
|
|
||||||
|
|
||||||
// File menu
|
|
||||||
QMenu* fileMenu = menuBar->addMenu("Fichier");
|
|
||||||
fileMenu->addAction("Quitter", this, &QWidget::close);
|
|
||||||
|
|
||||||
// Tools menu
|
|
||||||
QMenu* toolsMenu = menuBar->addMenu("Outils");
|
|
||||||
toolsMenu->addAction("Rafraîchir les sources", this, &MainWindow::onRefresh);
|
|
||||||
toolsMenu->addAction("Historique", this, &MainWindow::onShowHistory);
|
|
||||||
|
|
||||||
// Help menu
|
|
||||||
QMenu* helpMenu = menuBar->addMenu("Aide");
|
|
||||||
helpMenu->addAction("À propos", [this]() {
|
|
||||||
QMessageBox::about(this, "PackageMapper",
|
|
||||||
"<h2>PackageMapper v1.0.0</h2>"
|
|
||||||
"<p>Gestionnaire de paquets unifié avec support d'extensions.</p>"
|
|
||||||
"<p>Système de plugins : chargez des gestionnaires supplémentaires "
|
|
||||||
"pour gérer apt, pkg, et bien d'autres.</p>"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::loadPlugins() {
|
|
||||||
m_pluginSelector->clear();
|
|
||||||
|
|
||||||
// Try to load from default paths
|
|
||||||
m_pluginManager->loadPluginsFromDirectory("/usr/lib/PackageMapper/plugins");
|
|
||||||
m_pluginManager->loadPluginsFromDirectory("/usr/local/lib/PackageMapper/plugins");
|
|
||||||
|
|
||||||
char* home = getenv("HOME");
|
|
||||||
if (home) {
|
|
||||||
std::string userPluginDir = std::string(home) + "/.local/lib/PackageMapper/plugins";
|
|
||||||
m_pluginManager->loadPluginsFromDirectory(userPluginDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t count = m_pluginManager->getPluginCount();
|
|
||||||
if (count == 0) {
|
|
||||||
m_pluginSelector->addItem("Aucun plugin chargé");
|
|
||||||
m_currentPlugin = nullptr;
|
|
||||||
statusBar()->showMessage("⚠️ Aucun plugin trouvé. Compilez un plugin (pacman, apt, pkg...)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < count; i++) {
|
|
||||||
IPackageManager* pm = m_pluginManager->getPlugin(i);
|
|
||||||
if (pm) {
|
|
||||||
std::string label = pm->getName() + " (" + pm->getVersion() + ")";
|
|
||||||
if (!pm->isAvailable()) {
|
|
||||||
label += " ⚠️ Non disponible";
|
|
||||||
}
|
|
||||||
m_pluginSelector->addItem(QString::fromStdString(label));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onPluginChanged(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onPluginChanged(int index) {
|
|
||||||
if (index < 0 || index >= static_cast<int>(m_pluginManager->getPluginCount())) {
|
|
||||||
m_currentPlugin = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_currentPlugin = m_pluginManager->getPlugin(index);
|
|
||||||
if (!m_currentPlugin) return;
|
|
||||||
|
|
||||||
bool available = m_currentPlugin->isAvailable();
|
|
||||||
m_searchButton->setEnabled(available);
|
|
||||||
m_searchBar->setEnabled(available);
|
|
||||||
m_refreshButton->setEnabled(available && m_currentPlugin->canSearch());
|
|
||||||
m_updateAllButton->setEnabled(available && m_currentPlugin->canUpdate());
|
|
||||||
|
|
||||||
updateStatusBar();
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("Plugin: %1 - %2")
|
|
||||||
.arg(QString::fromStdString(m_currentPlugin->getName()))
|
|
||||||
.arg(available ? "✅ Disponible" : "❌ Non disponible")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onSearch() {
|
|
||||||
if (!m_currentPlugin || !m_currentPlugin->isAvailable()) {
|
|
||||||
QMessageBox::warning(this, "Erreur", "Aucun plugin disponible.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string query = m_searchBar->text().toStdString();
|
|
||||||
if (query.empty()) {
|
|
||||||
QMessageBox::information(this, "Info", "Entrez un terme de recherche.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
statusBar()->showMessage("🔍 Recherche en cours...");
|
|
||||||
m_progressBar->setVisible(true);
|
|
||||||
m_progressBar->setRange(0, 0); // Indeterminate
|
|
||||||
m_packageList->clear();
|
|
||||||
|
|
||||||
SearchWorker* worker = new SearchWorker(m_currentPlugin, query);
|
|
||||||
connect(worker, &SearchWorker::finished, this, &MainWindow::onSearchFinished);
|
|
||||||
connect(worker, &SearchWorker::finished, worker, &QObject::deleteLater);
|
|
||||||
worker->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onSearchFinished(std::vector<PackageInfo> results) {
|
|
||||||
m_progressBar->setVisible(false);
|
|
||||||
m_currentResults = results;
|
|
||||||
m_packageList->clear();
|
|
||||||
|
|
||||||
for (const auto& pkg : results) {
|
|
||||||
QString label = QString("📦 %1 %2").arg(
|
|
||||||
QString::fromStdString(pkg.name),
|
|
||||||
QString::fromStdString(pkg.version)
|
|
||||||
);
|
|
||||||
if (pkg.installed) {
|
|
||||||
label += " ✅ Installé";
|
|
||||||
}
|
|
||||||
if (pkg.updateAvailable) {
|
|
||||||
label += " 🔄 Mise à jour disponible";
|
|
||||||
}
|
|
||||||
m_packageList->addItem(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("📋 %1 paquet(s) trouvé(s)").arg(results.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onPackageSelected(int row) {
|
|
||||||
|
|
||||||
if (row < 0 || row >= static_cast<int>(m_currentResults.size())) {
|
|
||||||
m_installButton->setEnabled(false);
|
|
||||||
m_removeButton->setEnabled(false);
|
|
||||||
m_updateButton->setEnabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_selectedPackage = m_currentResults[row];
|
|
||||||
updatePackageInfo(m_selectedPackage);
|
|
||||||
|
|
||||||
m_installButton->setEnabled(
|
|
||||||
m_currentPlugin && m_currentPlugin->canInstall() && !m_selectedPackage.installed);
|
|
||||||
m_removeButton->setEnabled(
|
|
||||||
m_currentPlugin && m_currentPlugin->canRemove() && m_selectedPackage.installed);
|
|
||||||
m_updateButton->setEnabled(
|
|
||||||
m_currentPlugin && m_currentPlugin->canUpdate() && m_selectedPackage.updateAvailable);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::updatePackageInfo(const PackageInfo& pkg) {
|
|
||||||
m_packageName->setText(QString::fromStdString(pkg.name));
|
|
||||||
m_packageVersion->setText(
|
|
||||||
QString("Version: %1").arg(QString::fromStdString(pkg.version)));
|
|
||||||
m_packageRepo->setText(
|
|
||||||
QString("Dépôt: %1").arg(QString::fromStdString(pkg.repository)));
|
|
||||||
m_packageSize->setText(
|
|
||||||
QString("Taille: %1").arg(QString::fromStdString(pkg.size)));
|
|
||||||
m_packageDescription->setText(QString::fromStdString(pkg.description));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onInstall() {
|
|
||||||
if (m_selectedPackage.name.empty()) return;
|
|
||||||
performInstall(m_selectedPackage.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onRemove() {
|
|
||||||
if (m_selectedPackage.name.empty()) return;
|
|
||||||
performRemove(m_selectedPackage.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onUpdate() {
|
|
||||||
if (m_selectedPackage.name.empty()) return;
|
|
||||||
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("🔄 Mise à jour de %1...").arg(QString::fromStdString(m_selectedPackage.name)));
|
|
||||||
m_progressBar->setVisible(true);
|
|
||||||
m_progressBar->setRange(0, 0);
|
|
||||||
|
|
||||||
auto* worker = new InstallWorker(m_currentPlugin, m_selectedPackage.name, false);
|
|
||||||
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
|
|
||||||
statusBar()->showMessage(msg);
|
|
||||||
});
|
|
||||||
connect(worker, &InstallWorker::finished, [this](bool success) {
|
|
||||||
m_progressBar->setVisible(false);
|
|
||||||
if (success) {
|
|
||||||
statusBar()->showMessage("✅ Mise à jour terminée");
|
|
||||||
m_historyManager->record({"", "update", m_selectedPackage.name,
|
|
||||||
m_currentPlugin->getName(), true});
|
|
||||||
} else {
|
|
||||||
statusBar()->showMessage("❌ Échec de la mise à jour");
|
|
||||||
m_historyManager->record({"", "update", m_selectedPackage.name,
|
|
||||||
m_currentPlugin->getName(), false});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
|
|
||||||
worker->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onUpdateAll() {
|
|
||||||
if (!m_currentPlugin || !m_currentPlugin->isAvailable()) return;
|
|
||||||
|
|
||||||
statusBar()->showMessage("🔄 Mise à jour de tous les paquets...");
|
|
||||||
m_progressBar->setVisible(true);
|
|
||||||
m_progressBar->setRange(0, 0);
|
|
||||||
|
|
||||||
auto* worker = new InstallWorker(m_currentPlugin, "", false);
|
|
||||||
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
|
|
||||||
statusBar()->showMessage(msg);
|
|
||||||
});
|
|
||||||
connect(worker, &InstallWorker::finished, [this](bool success) {
|
|
||||||
m_progressBar->setVisible(false);
|
|
||||||
if (success) {
|
|
||||||
statusBar()->showMessage("✅ Tous les paquets sont à jour");
|
|
||||||
} else {
|
|
||||||
statusBar()->showMessage("❌ Erreur lors de la mise à jour globale");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
|
|
||||||
worker->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onRefresh() {
|
|
||||||
if (!m_currentPlugin || !m_currentPlugin->isAvailable()) return;
|
|
||||||
|
|
||||||
statusBar()->showMessage("🔄 Rafraîchissement des sources...");
|
|
||||||
m_progressBar->setVisible(true);
|
|
||||||
m_progressBar->setRange(0, 0);
|
|
||||||
|
|
||||||
auto* worker = new InstallWorker(m_currentPlugin, "", false);
|
|
||||||
connect(worker, &InstallWorker::finished, [this](bool) {
|
|
||||||
m_progressBar->setVisible(false);
|
|
||||||
statusBar()->showMessage("✅ Sources rafraîchies");
|
|
||||||
});
|
|
||||||
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
|
|
||||||
worker->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::performSearch(const std::string& query) {
|
|
||||||
statusBar()->showMessage("🔍 Recherche...");
|
|
||||||
m_progressBar->setVisible(true);
|
|
||||||
m_progressBar->setRange(0, 0);
|
|
||||||
|
|
||||||
SearchWorker* worker = new SearchWorker(m_currentPlugin, query);
|
|
||||||
connect(worker, &SearchWorker::finished, this, &MainWindow::onSearchFinished);
|
|
||||||
connect(worker, &SearchWorker::finished, worker, &QObject::deleteLater);
|
|
||||||
worker->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::performInstall(const std::string& package) {
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("📦 Installation de %1...").arg(QString::fromStdString(package)));
|
|
||||||
m_progressBar->setVisible(true);
|
|
||||||
m_progressBar->setRange(0, 0);
|
|
||||||
|
|
||||||
auto* worker = new InstallWorker(m_currentPlugin, package, false);
|
|
||||||
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
|
|
||||||
statusBar()->showMessage(msg);
|
|
||||||
});
|
|
||||||
connect(worker, &InstallWorker::finished, [this](bool success) {
|
|
||||||
m_progressBar->setVisible(false);
|
|
||||||
if (success) {
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("✅ %1 installé avec succès").arg(
|
|
||||||
QString::fromStdString(m_selectedPackage.name)));
|
|
||||||
m_historyManager->record({"", "install", m_selectedPackage.name,
|
|
||||||
m_currentPlugin->getName(), true});
|
|
||||||
} else {
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("❌ Échec de l'installation de %1").arg(
|
|
||||||
QString::fromStdString(m_selectedPackage.name)));
|
|
||||||
m_historyManager->record({"", "install", m_selectedPackage.name,
|
|
||||||
m_currentPlugin->getName(), false});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
|
|
||||||
worker->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::performRemove(const std::string& package) {
|
|
||||||
QMessageBox::StandardButton reply = QMessageBox::question(this,
|
|
||||||
"Confirmation",
|
|
||||||
QString("Voulez-vous vraiment supprimer %1 ?").arg(
|
|
||||||
QString::fromStdString(package)),
|
|
||||||
QMessageBox::Yes | QMessageBox::No);
|
|
||||||
|
|
||||||
if (reply != QMessageBox::Yes) return;
|
|
||||||
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("🗑️ Suppression de %1...").arg(QString::fromStdString(package)));
|
|
||||||
m_progressBar->setVisible(true);
|
|
||||||
m_progressBar->setRange(0, 0);
|
|
||||||
|
|
||||||
auto* worker = new InstallWorker(m_currentPlugin, package, true);
|
|
||||||
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
|
|
||||||
statusBar()->showMessage(msg);
|
|
||||||
});
|
|
||||||
connect(worker, &InstallWorker::finished, [this](bool success) {
|
|
||||||
m_progressBar->setVisible(false);
|
|
||||||
if (success) {
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("✅ %1 supprimé avec succès").arg(
|
|
||||||
QString::fromStdString(m_selectedPackage.name)));
|
|
||||||
m_historyManager->record({"", "remove", m_selectedPackage.name,
|
|
||||||
m_currentPlugin->getName(), true});
|
|
||||||
} else {
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("❌ Échec de la suppression de %1").arg(
|
|
||||||
QString::fromStdString(m_selectedPackage.name)));
|
|
||||||
m_historyManager->record({"", "remove", m_selectedPackage.name,
|
|
||||||
m_currentPlugin->getName(), false});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
|
|
||||||
worker->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onShowHistory() {
|
|
||||||
QDialog dialog(this);
|
|
||||||
dialog.setWindowTitle("📋 Historique des actions");
|
|
||||||
dialog.setMinimumSize(600, 400);
|
|
||||||
dialog.setStyleSheet(
|
|
||||||
"QDialog { background: #1a1a1a; }"
|
|
||||||
"QLabel { color: white; }"
|
|
||||||
);
|
|
||||||
|
|
||||||
QVBoxLayout* layout = new QVBoxLayout(&dialog);
|
|
||||||
|
|
||||||
QTextEdit* textEdit = new QTextEdit();
|
|
||||||
textEdit->setReadOnly(true);
|
|
||||||
textEdit->setStyleSheet(
|
|
||||||
"QTextEdit { background: #1e1e1e; color: #e0e0e0; border: 1px solid #3a3a3a; "
|
|
||||||
"border-radius: 8px; padding: 8px; font-family: monospace; font-size: 13px; }"
|
|
||||||
);
|
|
||||||
|
|
||||||
const auto& history = m_historyManager->getHistory();
|
|
||||||
if (history.empty()) {
|
|
||||||
textEdit->setPlainText("Aucune action enregistrée.");
|
|
||||||
} else {
|
|
||||||
QString text;
|
|
||||||
for (const auto& entry : history) {
|
|
||||||
text += QString("[%1] %2: %3 (%4) - %5\n")
|
|
||||||
.arg(QString::fromStdString(entry.timestamp))
|
|
||||||
.arg(QString::fromStdString(entry.action))
|
|
||||||
.arg(QString::fromStdString(entry.package))
|
|
||||||
.arg(QString::fromStdString(entry.plugin))
|
|
||||||
.arg(entry.success ? "✅ Succès" : "❌ Échec");
|
|
||||||
}
|
|
||||||
textEdit->setPlainText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
layout->addWidget(textEdit);
|
|
||||||
|
|
||||||
QPushButton* clearBtn = new QPushButton("🗑️ Effacer l'historique");
|
|
||||||
clearBtn->setStyleSheet(
|
|
||||||
"QPushButton { background: #f44336; color: white; border: none; "
|
|
||||||
"padding: 8px 16px; border-radius: 8px; }"
|
|
||||||
"QPushButton:hover { background: #e53935; }"
|
|
||||||
);
|
|
||||||
connect(clearBtn, &QPushButton::clicked, [&dialog, this]() {
|
|
||||||
m_historyManager->clear();
|
|
||||||
dialog.close();
|
|
||||||
});
|
|
||||||
layout->addWidget(clearBtn);
|
|
||||||
|
|
||||||
dialog.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::updateStatusBar() {
|
|
||||||
if (!m_currentPlugin) {
|
|
||||||
statusBar()->showMessage("Aucun plugin chargé");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString info = QString("Plugin: %1 | Paquets trouvés: %2 | Éléments en historique: %3")
|
|
||||||
.arg(QString::fromStdString(m_currentPlugin->getName()))
|
|
||||||
.arg(m_currentResults.size())
|
|
||||||
.arg(m_historyManager->getHistory().size());
|
|
||||||
statusBar()->showMessage(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onToggleInstalledView() {
|
|
||||||
if (!m_currentPlugin || !m_currentPlugin->isAvailable()) return;
|
|
||||||
|
|
||||||
statusBar()->showMessage("📦 Chargement des paquets installés...");
|
|
||||||
m_progressBar->setVisible(true);
|
|
||||||
m_progressBar->setRange(0, 0);
|
|
||||||
|
|
||||||
SearchWorker* worker = new SearchWorker(m_currentPlugin, "");
|
|
||||||
connect(worker, &SearchWorker::finished, [this](std::vector<PackageInfo> results) {
|
|
||||||
m_progressBar->setVisible(false);
|
|
||||||
std::vector<PackageInfo> installed;
|
|
||||||
for (const auto& pkg : results) {
|
|
||||||
if (pkg.installed) installed.push_back(pkg);
|
|
||||||
}
|
|
||||||
onSearchFinished(installed);
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("📦 %1 paquet(s) installé(s)").arg(installed.size()));
|
|
||||||
});
|
|
||||||
connect(worker, &SearchWorker::finished, worker, &QObject::deleteLater);
|
|
||||||
worker->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onInstallFinished(bool success) {
|
|
||||||
m_progressBar->setVisible(false);
|
|
||||||
if (success) {
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("✅ %1 installé avec succès").arg(
|
|
||||||
QString::fromStdString(m_selectedPackage.name)));
|
|
||||||
m_historyManager->record({"", "install", m_selectedPackage.name,
|
|
||||||
m_currentPlugin->getName(), true});
|
|
||||||
} else {
|
|
||||||
statusBar()->showMessage(
|
|
||||||
QString("❌ Échec de l'installation de %1").arg(
|
|
||||||
QString::fromStdString(m_selectedPackage.name)));
|
|
||||||
m_historyManager->record({"", "install", m_selectedPackage.name,
|
|
||||||
m_currentPlugin->getName(), false});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
#include "PluginManager.h"
|
|
||||||
#include <filesystem>
|
|
||||||
#include <iostream>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
|
|
||||||
PluginManager::PluginManager() {
|
|
||||||
// Default search paths
|
|
||||||
#ifdef _WIN32
|
|
||||||
char* appdata = getenv("APPDATA");
|
|
||||||
if (appdata) {
|
|
||||||
m_searchPaths.push_back(std::string(appdata) + "\\PackageMapper\\plugins");
|
|
||||||
}
|
|
||||||
m_searchPaths.push_back(".\\plugins");
|
|
||||||
#else
|
|
||||||
char* home = getenv("HOME");
|
|
||||||
if (home) {
|
|
||||||
m_searchPaths.push_back(std::string(home) + "/.local/lib/PackageMapper/plugins");
|
|
||||||
}
|
|
||||||
m_searchPaths.push_back("/usr/lib/PackageMapper/plugins");
|
|
||||||
m_searchPaths.push_back("/usr/local/lib/PackageMapper/plugins");
|
|
||||||
#endif
|
|
||||||
m_searchPaths.push_back("./plugins");
|
|
||||||
|
|
||||||
// Load from all search paths
|
|
||||||
for (const auto& path : m_searchPaths) {
|
|
||||||
if (fs::exists(path) && fs::is_directory(path)) {
|
|
||||||
loadPluginsFromDirectory(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginManager::~PluginManager() {
|
|
||||||
unloadAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluginManager::loadPluginsFromDirectory(const std::string& directory) {
|
|
||||||
try {
|
|
||||||
for (const auto& entry : fs::directory_iterator(directory)) {
|
|
||||||
if (entry.is_regular_file()) {
|
|
||||||
auto ext = entry.path().extension().string();
|
|
||||||
#ifdef _WIN32
|
|
||||||
if (ext == ".dll") {
|
|
||||||
#else
|
|
||||||
if (ext == ".so" || ext == ".dylib") {
|
|
||||||
#endif
|
|
||||||
loadPlugin(entry.path().string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (const fs::filesystem_error& e) {
|
|
||||||
std::cerr << "Error scanning plugin directory: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PluginManager::loadPlugin(const std::string& path) {
|
|
||||||
dynlib_handle handle = dynlib_open(path.c_str());
|
|
||||||
if (!handle) {
|
|
||||||
std::cerr << "Failed to load plugin: " << path << " - " << dynlib_error() << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
using CreateFunc = IPackageManager* (*)();
|
|
||||||
using DestroyFunc = void (*)(IPackageManager*);
|
|
||||||
|
|
||||||
auto createFunc = reinterpret_cast<CreateFunc>(dynlib_sym(handle, "createPlugin"));
|
|
||||||
auto destroyFunc = reinterpret_cast<DestroyFunc>(dynlib_sym(handle, "destroyPlugin"));
|
|
||||||
|
|
||||||
if (!createFunc || !destroyFunc) {
|
|
||||||
std::cerr << "Invalid plugin: " << path << " (missing entry points)" << std::endl;
|
|
||||||
dynlib_close(handle);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPackageManager* instance = createFunc();
|
|
||||||
if (!instance) {
|
|
||||||
std::cerr << "Plugin returned null: " << path << std::endl;
|
|
||||||
dynlib_close(handle);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginInfo info;
|
|
||||||
info.path = path;
|
|
||||||
info.name = instance->getName();
|
|
||||||
info.instance = instance;
|
|
||||||
info.handle = handle;
|
|
||||||
info.loaded = true;
|
|
||||||
|
|
||||||
m_plugins.push_back(info);
|
|
||||||
std::cout << "Loaded plugin: " << info.name << " from " << path << std::endl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluginManager::unloadAll() {
|
|
||||||
for (auto& plugin : m_plugins) {
|
|
||||||
if (plugin.instance && plugin.handle) {
|
|
||||||
using DestroyFunc = void (*)(IPackageManager*);
|
|
||||||
auto destroyFunc = reinterpret_cast<DestroyFunc>(dynlib_sym(plugin.handle, "destroyPlugin"));
|
|
||||||
if (destroyFunc) {
|
|
||||||
destroyFunc(plugin.instance);
|
|
||||||
}
|
|
||||||
dynlib_close(plugin.handle);
|
|
||||||
plugin.instance = nullptr;
|
|
||||||
plugin.handle = nullptr;
|
|
||||||
plugin.loaded = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_plugins.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<PluginInfo>& PluginManager::getPlugins() const {
|
|
||||||
return m_plugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPackageManager* PluginManager::getPlugin(size_t index) const {
|
|
||||||
if (index < m_plugins.size() && m_plugins[index].loaded) {
|
|
||||||
return m_plugins[index].instance;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t PluginManager::getPluginCount() const {
|
|
||||||
return m_plugins.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
IPackageManager* PluginManager::findPlugin(const std::string& name) const {
|
|
||||||
for (const auto& plugin : m_plugins) {
|
|
||||||
if (plugin.name == name && plugin.loaded) {
|
|
||||||
return plugin.instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "HistoryManager.h"
|
#include "history-manager.h"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include "MainWindow.h"
|
#include "main-window.h"
|
||||||
|
#include "update-manager.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
app.setApplicationName("PackageMapper");
|
app.setApplicationName("PacManager");
|
||||||
app.setApplicationVersion("1.0.0");
|
app.setApplicationVersion(UpdateManager::currentVersion());
|
||||||
app.setOrganizationName("Freebuff");
|
app.setOrganizationName("Freebuff");
|
||||||
|
|
||||||
MainWindow window;
|
MainWindow window;
|
||||||
window.setWindowTitle("PackageMapper - Gestionnaire de Paquets");
|
window.setWindowTitle("PacManager - Gestionnaire de Paquets");
|
||||||
window.resize(1000, 700);
|
window.resize(1200, 760);
|
||||||
|
window.setMinimumSize(960, 600);
|
||||||
window.show();
|
window.show();
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "PackageModel.h"
|
#include "package-model.h"
|
||||||
|
|
||||||
PackageModel::PackageModel(QObject* parent) : QAbstractListModel(parent) {}
|
PackageModel::PackageModel(QObject* parent) : QAbstractListModel(parent) {}
|
||||||
|
|
||||||
@@ -0,0 +1,408 @@
|
|||||||
|
#include "pacman-manager.h"
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
// Helper to run shell commands and capture output
|
||||||
|
static std::string exec(const char* cmd) {
|
||||||
|
std::array<char, 256> buffer;
|
||||||
|
std::string result;
|
||||||
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
||||||
|
if (!pipe) throw std::runtime_error("popen() failed");
|
||||||
|
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||||
|
result += buffer.data();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escape a string so it can be embedded inside single quotes in a shell
|
||||||
|
// command without breaking out of the quotes (used for the sudo password).
|
||||||
|
static std::string shellQuote(const std::string& s) {
|
||||||
|
std::string out = "'";
|
||||||
|
for (char c : s) {
|
||||||
|
if (c == '\'') out += "'\\''";
|
||||||
|
else out += c;
|
||||||
|
}
|
||||||
|
out += "'";
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read a (current/Total) package counter out of a pacman line; see definition
|
||||||
|
// below. Declared first because execPrivileged uses it.
|
||||||
|
static int percentFromLine(const std::string& line);
|
||||||
|
|
||||||
|
// Run a privileged pacman command as root, piping the password to `sudo -S`
|
||||||
|
// on stdin and capturing combined stdout+stderr. Lines are delivered to the
|
||||||
|
// progress callback as soon as they are produced (pacman prints the download
|
||||||
|
// progress as it goes, so this keeps the UI bar live). The full output is
|
||||||
|
// still returned for auth/error checks.
|
||||||
|
static std::string execPrivileged(const std::string& pacmanCmd,
|
||||||
|
const std::string& password,
|
||||||
|
ProgressCallback progressCallback) {
|
||||||
|
std::string full = "printf '%s\\n' " + shellQuote(password)
|
||||||
|
+ " | sudo -S " + pacmanCmd + " 2>&1";
|
||||||
|
|
||||||
|
std::array<char, 8192> buffer;
|
||||||
|
std::string result;
|
||||||
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(full.c_str(), "r"), pclose);
|
||||||
|
if (!pipe) throw std::runtime_error("popen() failed");
|
||||||
|
|
||||||
|
// Force line-buffered on the read side; pacman flushes its progress lines
|
||||||
|
// with newlines so each is forwarded as soon as it is emitted.
|
||||||
|
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||||
|
std::string line(buffer.data());
|
||||||
|
result += line;
|
||||||
|
// Trim the trailing newline for the callback.
|
||||||
|
while (!line.empty() && (line.back() == '\n' || line.back() == '\r')) {
|
||||||
|
line.pop_back();
|
||||||
|
}
|
||||||
|
if (progressCallback && !line.empty()) {
|
||||||
|
progressCallback(line, percentFromLine(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read a (current/Total) package counter out of a pacman line, e.g.
|
||||||
|
// "(3/5) téléchargement de ...". Returns a 0-100 percentage, or -1 when the
|
||||||
|
// line carries no counter (so the caller keeps the previous value / unknown).
|
||||||
|
static int percentFromLine(const std::string& line) {
|
||||||
|
size_t open = line.find('(');
|
||||||
|
size_t close = line.find(')');
|
||||||
|
if (open == std::string::npos || close == std::string::npos || open > close) return -1;
|
||||||
|
std::string inner = line.substr(open + 1, close - open - 1);
|
||||||
|
size_t slash = inner.find('/');
|
||||||
|
if (slash == std::string::npos) return -1;
|
||||||
|
try {
|
||||||
|
long cur = std::stol(inner.substr(0, slash));
|
||||||
|
long total = std::stol(inner.substr(slash + 1));
|
||||||
|
if (total <= 0) return -1;
|
||||||
|
int pct = static_cast<int>(cur * 100 / total);
|
||||||
|
return std::max(0, std::min(100, pct));
|
||||||
|
} catch (...) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stream the lines of a command's output (already captured) to the callback —
|
||||||
|
// used by providers that buffer a whole command first. Percent stays unknown.
|
||||||
|
static void streamOutput(const std::string& output, ProgressCallback progressCallback) {
|
||||||
|
if (!progressCallback) return;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (!line.empty()) progressCallback(line, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PackageInfo> PacmanManager::search(const std::string& query) {
|
||||||
|
std::vector<PackageInfo> results;
|
||||||
|
|
||||||
|
std::string cmd = "pacman -Ss " + query + " 2>&1";
|
||||||
|
std::string output = exec(cmd.c_str());
|
||||||
|
|
||||||
|
// Load the installed packages once, so marking search results as
|
||||||
|
// installed is an in-memory lookup instead of one `pacman -Qi` subprocess
|
||||||
|
// per result (which made searches with many matches take minutes).
|
||||||
|
std::set<std::string> installed = parseInstalledNames(exec("pacman -Q 2>&1"));
|
||||||
|
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (line.empty()) continue;
|
||||||
|
|
||||||
|
// Repository line: repo/name version
|
||||||
|
if (line[0] != ' ' && line[0] != '\t') {
|
||||||
|
PackageInfo pkg;
|
||||||
|
size_t slashPos = line.find('/');
|
||||||
|
size_t spacePos = line.find(' ', slashPos);
|
||||||
|
|
||||||
|
if (slashPos != std::string::npos) {
|
||||||
|
pkg.repository = line.substr(0, slashPos);
|
||||||
|
pkg.name = line.substr(slashPos + 1, spacePos - slashPos - 1);
|
||||||
|
|
||||||
|
if (spacePos != std::string::npos) {
|
||||||
|
size_t nextSpace = line.find(' ', spacePos + 1);
|
||||||
|
pkg.version = line.substr(spacePos + 1, nextSpace - spacePos - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pkg.installed = installed.count(pkg.name) > 0;
|
||||||
|
results.push_back(pkg);
|
||||||
|
}
|
||||||
|
// Description line (starts with spaces)
|
||||||
|
else if (!results.empty()) {
|
||||||
|
std::string desc = line;
|
||||||
|
// Trim leading spaces
|
||||||
|
size_t start = desc.find_first_not_of(" \t");
|
||||||
|
if (start != std::string::npos) {
|
||||||
|
desc = desc.substr(start);
|
||||||
|
}
|
||||||
|
results.back().description = desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PacmanManager::install(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) {
|
||||||
|
if (progressCallback) progressCallback("Installation de " + packageName + "...", -1);
|
||||||
|
|
||||||
|
std::string output =
|
||||||
|
execPrivileged("pacman -S --noconfirm " + packageName, m_password, progressCallback);
|
||||||
|
|
||||||
|
// A wrong/expired password must not be silently reused: drop it so the
|
||||||
|
// next attempt prompts again.
|
||||||
|
if (authFailed(output)) {
|
||||||
|
clearPassword();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isPackageInstalled(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PacmanManager::remove(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) {
|
||||||
|
if (progressCallback) progressCallback("Suppression de " + packageName + "...", -1);
|
||||||
|
|
||||||
|
std::string output =
|
||||||
|
execPrivileged("pacman -R --noconfirm " + packageName, m_password, progressCallback);
|
||||||
|
|
||||||
|
if (authFailed(output)) {
|
||||||
|
clearPassword();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !isPackageInstalled(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PacmanManager::update(const std::string& packageName,
|
||||||
|
ProgressCallback progressCallback) {
|
||||||
|
std::string output;
|
||||||
|
if (packageName.empty()) {
|
||||||
|
if (progressCallback) progressCallback("Mise à jour de tous les paquets...", -1);
|
||||||
|
output = execPrivileged("pacman -Syu --noconfirm", m_password, progressCallback);
|
||||||
|
} else {
|
||||||
|
if (progressCallback) progressCallback("Mise à jour de " + packageName + "...", -1);
|
||||||
|
output = execPrivileged("pacman -S --noconfirm " + packageName,
|
||||||
|
m_password, progressCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authFailed(output)) {
|
||||||
|
clearPassword();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PackageInfo> PacmanManager::listInstalled() {
|
||||||
|
auto packages = parseInstalledOutput(exec("pacman -Q 2>&1"));
|
||||||
|
|
||||||
|
// Enrich each installed package with its installed size (shown as "Taille")
|
||||||
|
// and the repository/origin it was installed from. Both come from a single
|
||||||
|
// subprocess each, which is fast enough to run on page load.
|
||||||
|
auto sizes = parseInstalledSizes(exec("pacman -Qi 2>&1"));
|
||||||
|
auto repos = parseSyncRepos(exec("pacman -Sl 2>&1"));
|
||||||
|
|
||||||
|
for (auto& pkg : packages) {
|
||||||
|
auto sizeIt = sizes.find(pkg.name);
|
||||||
|
if (sizeIt != sizes.end()) {
|
||||||
|
pkg.size = sizeIt->second;
|
||||||
|
pkg.installedSize = sizeIt->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto repoIt = repos.find(pkg.name);
|
||||||
|
if (repoIt != repos.end()) {
|
||||||
|
pkg.repository = repoIt->second;
|
||||||
|
} else {
|
||||||
|
// Not present in any sync repository: foreign package (AUR / manual build).
|
||||||
|
pkg.repository = "AUR";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return packages;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse `pacman -Qu` output (one "name version" line per outdated package).
|
||||||
|
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
||||||
|
static std::vector<PackageInfo> parseUpdatesOutput(const std::string& output) {
|
||||||
|
std::vector<PackageInfo> results;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (line.empty()) continue;
|
||||||
|
|
||||||
|
PackageInfo pkg;
|
||||||
|
size_t spacePos = line.find(' ');
|
||||||
|
if (spacePos == std::string::npos) continue;
|
||||||
|
|
||||||
|
pkg.name = line.substr(0, spacePos);
|
||||||
|
pkg.version = line.substr(spacePos + 1);
|
||||||
|
pkg.installed = true;
|
||||||
|
pkg.updateAvailable = true;
|
||||||
|
results.push_back(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PackageInfo> PacmanManager::listUpdates() {
|
||||||
|
return parseUpdatesOutput(exec("pacman -Qu 2>&1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PacmanManager::refresh(ProgressCallback progressCallback) {
|
||||||
|
if (progressCallback) progressCallback("Rafraîchissement des bases de données...", -1);
|
||||||
|
|
||||||
|
std::string output =
|
||||||
|
execPrivileged("pacman -Sy --noconfirm", m_password, progressCallback);
|
||||||
|
|
||||||
|
if (authFailed(output)) {
|
||||||
|
clearPassword();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// `pacman -Sy` has no easy success code; treat a completed run as success
|
||||||
|
// unless pacman itself reported an explicit error.
|
||||||
|
return output.find("error:") == std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PackageInfo> PacmanManager::parseInstalledOutput(const std::string& output) {
|
||||||
|
std::vector<PackageInfo> results;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (line.empty()) continue;
|
||||||
|
|
||||||
|
PackageInfo pkg;
|
||||||
|
// `pacman -Q` prints "name version" separated by a single space;
|
||||||
|
// splitting on the first space keeps hyphens in names (e.g. python-pip) intact.
|
||||||
|
size_t spacePos = line.find(' ');
|
||||||
|
if (spacePos == std::string::npos) continue;
|
||||||
|
|
||||||
|
pkg.name = line.substr(0, spacePos);
|
||||||
|
pkg.version = line.substr(spacePos + 1);
|
||||||
|
pkg.installed = true;
|
||||||
|
results.push_back(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<std::string> PacmanManager::parseInstalledNames(const std::string& output) {
|
||||||
|
std::set<std::string> names;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (line.empty()) continue;
|
||||||
|
|
||||||
|
// Same split as parseInstalledOutput: the first space separates the
|
||||||
|
// name from the version (hyphens in names are kept intact).
|
||||||
|
size_t spacePos = line.find(' ');
|
||||||
|
if (spacePos == std::string::npos) continue;
|
||||||
|
|
||||||
|
names.insert(line.substr(0, spacePos));
|
||||||
|
}
|
||||||
|
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PacmanManager::isPackageInstalled(const std::string& name) {
|
||||||
|
std::string cmd = "pacman -Qi " + name + " > /dev/null 2>&1";
|
||||||
|
return system(cmd.c_str()) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse `pacman -Qi` output (one blank-line-separated block per package) into a
|
||||||
|
// map of package name -> installed size (e.g. "263.47 MiB").
|
||||||
|
std::map<std::string, std::string> PacmanManager::parseInstalledSizes(
|
||||||
|
const std::string& output) {
|
||||||
|
std::map<std::string, std::string> sizes;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
std::string currentName;
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
// A blank line ends the current package block.
|
||||||
|
if (line.empty()) {
|
||||||
|
currentName.clear();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t colon = line.find(':');
|
||||||
|
if (colon == std::string::npos) continue;
|
||||||
|
|
||||||
|
std::string field = line.substr(0, colon);
|
||||||
|
// Trim trailing whitespace from the label (labels are padded to align).
|
||||||
|
while (!field.empty() && field.back() == ' ') field.pop_back();
|
||||||
|
|
||||||
|
std::string value = line.substr(colon + 1);
|
||||||
|
// Trim leading whitespace from the value.
|
||||||
|
size_t start = value.find_first_not_of(" \t");
|
||||||
|
if (start != std::string::npos) {
|
||||||
|
value = value.substr(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field == "Name") {
|
||||||
|
currentName = value;
|
||||||
|
} else if (field == "Installed Size" && !currentName.empty()) {
|
||||||
|
sizes[currentName] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse `pacman -Sl` output ("repo name version" per sync-DB package) into a map of
|
||||||
|
// package name -> repository, so the origin of each installed package can be shown.
|
||||||
|
std::map<std::string, std::string> PacmanManager::parseSyncRepos(
|
||||||
|
const std::string& output) {
|
||||||
|
std::map<std::string, std::string> repos;
|
||||||
|
std::istringstream iss(output);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
bool firstLine = true;
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
if (firstLine) {
|
||||||
|
firstLine = false;
|
||||||
|
continue; // Skip the "Repository Name Version" header.
|
||||||
|
}
|
||||||
|
if (line.empty()) continue;
|
||||||
|
|
||||||
|
std::istringstream ls(line);
|
||||||
|
std::string repo;
|
||||||
|
std::string name;
|
||||||
|
if (!(ls >> repo >> name)) continue;
|
||||||
|
|
||||||
|
repos[name] = repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
return repos;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PacmanManager::authFailed(const std::string& output) {
|
||||||
|
return output.find("incorrect password") != std::string::npos
|
||||||
|
|| output.find("a password is required") != std::string::npos
|
||||||
|
|| output.find("Authentication failure") != std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacmanManager::setPassword(const std::string& password) {
|
||||||
|
m_password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacmanManager::clearPassword() {
|
||||||
|
m_password.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PacmanManager::hasPassword() const {
|
||||||
|
return !m_password.empty();
|
||||||
|
}
|
||||||
@@ -0,0 +1,240 @@
|
|||||||
|
#include "plugin-manager.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
// Plugin directories, checked in order. Bundled plugins ship next to the
|
||||||
|
// executable; user plugins live under the standard data directory so they
|
||||||
|
// survive application updates.
|
||||||
|
static QStringList pluginSearchPaths() {
|
||||||
|
QStringList paths;
|
||||||
|
paths << QCoreApplication::applicationDirPath() + "/plugins";
|
||||||
|
paths << QDir::homePath() + "/.local/share/PacManager/plugins";
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run a plugin's teardown and free what the host owns: the addon/provider
|
||||||
|
// instance (after onUnload) and the library it was compiled into.
|
||||||
|
static void unloadEntry(PluginManager::PluginEntry& entry) {
|
||||||
|
if (entry.plugin) {
|
||||||
|
entry.plugin->onUnload();
|
||||||
|
delete entry.plugin;
|
||||||
|
entry.plugin = nullptr;
|
||||||
|
}
|
||||||
|
if (entry.manager) {
|
||||||
|
delete entry.manager;
|
||||||
|
entry.manager = nullptr;
|
||||||
|
}
|
||||||
|
delete entry.library;
|
||||||
|
entry.library = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginManager::PluginManager() = default;
|
||||||
|
|
||||||
|
PluginManager::~PluginManager() {
|
||||||
|
// Unload plugins first (they may run code), then the libraries they were
|
||||||
|
// compiled into.
|
||||||
|
for (auto& entry : m_plugins) {
|
||||||
|
unloadEntry(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginManager::registerBuiltin(PluginInfo info, IPackageManager* manager) {
|
||||||
|
info.builtin = true;
|
||||||
|
info.available = manager->isAvailable();
|
||||||
|
m_plugins.push_back({std::move(info), nullptr, manager, nullptr});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load a single shared library as a plugin. Returns false (without erroring)
|
||||||
|
// when the file is not a plugin, so unrelated libraries in the directory are
|
||||||
|
// skipped. The plugin's kind decides which create function is resolved:
|
||||||
|
// "addon" -> IPlugin (see plugin.h), anything else -> IPackageManager.
|
||||||
|
bool PluginManager::loadPluginFile(const QString& filePath) {
|
||||||
|
typedef const char* (*MetaFn)();
|
||||||
|
typedef IPackageManager* (*CreateProviderFn)();
|
||||||
|
typedef IPlugin* (*CreatePluginFn)();
|
||||||
|
|
||||||
|
// Own the library for the lifetime of the plugin: it must stay loaded
|
||||||
|
// as long as the addon/manager instance created from it exists.
|
||||||
|
QLibrary* library = new QLibrary(filePath);
|
||||||
|
if (!library->load()) {
|
||||||
|
delete library;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MetaFn idFn = reinterpret_cast<MetaFn>(library->resolve("fws_plugin_id"));
|
||||||
|
MetaFn nameFn = reinterpret_cast<MetaFn>(library->resolve("fws_plugin_name"));
|
||||||
|
MetaFn versionFn = reinterpret_cast<MetaFn>(library->resolve("fws_plugin_version"));
|
||||||
|
MetaFn descFn = reinterpret_cast<MetaFn>(library->resolve("fws_plugin_description"));
|
||||||
|
MetaFn authorFn = reinterpret_cast<MetaFn>(library->resolve("fws_plugin_author"));
|
||||||
|
MetaFn kindFn = reinterpret_cast<MetaFn>(library->resolve("fws_plugin_kind"));
|
||||||
|
CreateProviderFn createProviderFn =
|
||||||
|
reinterpret_cast<CreateProviderFn>(library->resolve("fws_create_provider"));
|
||||||
|
CreatePluginFn createPluginFn =
|
||||||
|
reinterpret_cast<CreatePluginFn>(library->resolve("fws_create_plugin"));
|
||||||
|
// Optional: only present when the plugin declares an install hint.
|
||||||
|
MetaFn installHintFn = reinterpret_cast<MetaFn>(library->resolve("fws_plugin_install_hint"));
|
||||||
|
|
||||||
|
if (!idFn || !nameFn || !versionFn || !descFn || !authorFn) {
|
||||||
|
library->unload();
|
||||||
|
delete library;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject plugins whose id collides with an already registered plugin.
|
||||||
|
const std::string id = idFn();
|
||||||
|
for (const auto& entry : m_plugins) {
|
||||||
|
if (entry.info.id == id) {
|
||||||
|
library->unload();
|
||||||
|
delete library;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kind defaults to "provider" so legacy plugins without the symbol keep
|
||||||
|
// loading; "addon" requires the matching create function.
|
||||||
|
const std::string kind = kindFn ? kindFn() : "provider";
|
||||||
|
const bool isAddon = (kind == "addon");
|
||||||
|
if ((isAddon && !createPluginFn) || (!isAddon && !createProviderFn)) {
|
||||||
|
library->unload();
|
||||||
|
delete library;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginInfo info;
|
||||||
|
info.id = id;
|
||||||
|
info.name = nameFn();
|
||||||
|
info.version = versionFn();
|
||||||
|
info.description = descFn();
|
||||||
|
info.author = authorFn();
|
||||||
|
info.kind = isAddon ? PluginKind::Addon : PluginKind::Provider;
|
||||||
|
info.path = filePath.toStdString();
|
||||||
|
if (installHintFn && installHintFn() && *installHintFn()) {
|
||||||
|
info.installHint = installHintFn();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAddon) {
|
||||||
|
IPlugin* plugin = createPluginFn();
|
||||||
|
plugin->onLoad();
|
||||||
|
info.available = plugin->isAvailable();
|
||||||
|
m_plugins.push_back({std::move(info), plugin, nullptr, library});
|
||||||
|
} else {
|
||||||
|
IPackageManager* manager = createProviderFn();
|
||||||
|
info.available = manager->isAvailable();
|
||||||
|
m_plugins.push_back({std::move(info), nullptr, manager, library});
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginManager::scanDirectory(const QString& dir) {
|
||||||
|
QDir directory(dir);
|
||||||
|
if (!directory.exists()) return;
|
||||||
|
|
||||||
|
const QStringList filters = {
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
"*.dll"
|
||||||
|
#elif defined(Q_OS_MACOS)
|
||||||
|
"*.dylib"
|
||||||
|
#else
|
||||||
|
"*.so"
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
const QStringList files = directory.entryList(filters, QDir::Files);
|
||||||
|
for (const QString& file : files) {
|
||||||
|
loadPluginFile(directory.absoluteFilePath(file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginManager::unloadExternal() {
|
||||||
|
for (auto it = m_plugins.begin(); it != m_plugins.end();) {
|
||||||
|
if (!it->info.builtin) {
|
||||||
|
unloadEntry(*it);
|
||||||
|
it = m_plugins.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginManager::discoverExternal() {
|
||||||
|
for (const QString& dir : pluginSearchPaths()) {
|
||||||
|
scanDirectory(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginManager::reload() {
|
||||||
|
unloadExternal();
|
||||||
|
discoverExternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginManager::refreshAvailability() {
|
||||||
|
for (auto& entry : m_plugins) {
|
||||||
|
if (entry.plugin) {
|
||||||
|
entry.info.available = entry.plugin->isAvailable();
|
||||||
|
} else {
|
||||||
|
entry.info.available = entry.manager->isAvailable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<PluginManager::PluginEntry>& PluginManager::plugins() const {
|
||||||
|
return m_plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<const PluginManager::PluginEntry*> PluginManager::availableProviders() const {
|
||||||
|
std::vector<const PluginEntry*> result;
|
||||||
|
for (const auto& entry : m_plugins) {
|
||||||
|
if (entry.manager && entry.info.available && isEnabled(entry.info.id)) {
|
||||||
|
result.push_back(&entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<IPackageManager*> PluginManager::availableManagers() const {
|
||||||
|
std::vector<IPackageManager*> result;
|
||||||
|
for (const auto& entry : m_plugins) {
|
||||||
|
if (entry.manager && entry.info.available && isEnabled(entry.info.id)) {
|
||||||
|
result.push_back(entry.manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PluginManager::PluginEntry* PluginManager::findAvailable(const std::string& id) const {
|
||||||
|
for (const auto& entry : m_plugins) {
|
||||||
|
if (entry.info.id == id && entry.manager && entry.info.available
|
||||||
|
&& isEnabled(entry.info.id)) {
|
||||||
|
return &entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<IPlugin*> PluginManager::availableAddons() const {
|
||||||
|
std::vector<IPlugin*> result;
|
||||||
|
for (const auto& entry : m_plugins) {
|
||||||
|
if (entry.plugin && entry.info.available && isEnabled(entry.info.id)) {
|
||||||
|
result.push_back(entry.plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PluginManager::isEnabled(const std::string& id) const {
|
||||||
|
return m_settings.value(QString("plugins/%1/enabled").arg(QString::fromStdString(id)),
|
||||||
|
true).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginManager::setEnabled(const std::string& id, bool enabled) {
|
||||||
|
m_settings.setValue(QString("plugins/%1/enabled").arg(QString::fromStdString(id)), enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
IPackageManager* PluginManager::managerFor(const std::string& id) const {
|
||||||
|
for (const auto& entry : m_plugins) {
|
||||||
|
if (entry.info.id == id) return entry.manager;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
@@ -0,0 +1,238 @@
|
|||||||
|
#include "update-manager.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
|
|
||||||
|
// Repository base URL used to query the Gitea API for releases.
|
||||||
|
// The app is hosted at https://gitea.nocode-var.tech/FWS/FWS-PacManage.
|
||||||
|
static const char* kApiUrl =
|
||||||
|
"https://gitea.nocode-var.tech/api/v1/repos/FWS/FWS-PacManage/releases/latest";
|
||||||
|
static const char* kVersionToken = "FWSPACMANAGE_VERSION"; // replaced at build time
|
||||||
|
static const char* kRepoUrl =
|
||||||
|
"https://gitea.nocode-var.tech/FWS/FWS-PacManage.git";
|
||||||
|
|
||||||
|
UpdateManager::UpdateManager(QObject* parent) : QObject(parent) {
|
||||||
|
loadState();
|
||||||
|
|
||||||
|
// The running executable is expected to live in the build/ directory when
|
||||||
|
// launched from a source checkout. Walk up two levels to find the repo.
|
||||||
|
// When installed to ~/.local/bin there is no source tree, so update
|
||||||
|
// becomes impossible and the dialog simply points to the releases page.
|
||||||
|
QDir dir(QCoreApplication::applicationDirPath());
|
||||||
|
if (dir.dirName() == QLatin1String("build")) {
|
||||||
|
dir.cdUp();
|
||||||
|
if (dir.exists(QLatin1String("CMakeLists.txt"))) {
|
||||||
|
m_repoPath = dir.absolutePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(&m_process, &QProcess::finished, this, [this](int exitCode) {
|
||||||
|
const QString msg = QString::fromUtf8(m_process.readAllStandardOutput())
|
||||||
|
+ QString::fromUtf8(m_process.readAllStandardError());
|
||||||
|
emit selfUpdateFinished(exitCode == 0, msg.trimmed());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QString UpdateManager::currentVersion() {
|
||||||
|
// The `version` file at the repo root is the single source of truth. It is
|
||||||
|
// read from the executable's directory so a running build always reports
|
||||||
|
// the same version the developer bumped in the repo.
|
||||||
|
QString version;
|
||||||
|
const QString localFile = QCoreApplication::applicationDirPath() + "/version";
|
||||||
|
QFile f(localFile);
|
||||||
|
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
version = QString::fromUtf8(f.readAll()).trimmed();
|
||||||
|
}
|
||||||
|
if (version.isEmpty()) {
|
||||||
|
// CMake configure-time token; falls back to 1.0.0 when built without.
|
||||||
|
version = QString::fromLatin1(kVersionToken);
|
||||||
|
if (version == QLatin1String("FWSPACMANAGE_VERSION")) {
|
||||||
|
version = QStringLiteral("1.0.0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString UpdateManager::stateFilePath() {
|
||||||
|
QString dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
if (dir.isEmpty()) {
|
||||||
|
dir = QDir::homePath() + "/.local/share/PacManager";
|
||||||
|
}
|
||||||
|
return dir + "/update-state.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UpdateManager::shouldCheck() const {
|
||||||
|
if (m_lastCheckDate.isEmpty()) return true;
|
||||||
|
|
||||||
|
QDateTime last = QDateTime::fromString(m_lastCheckDate, Qt::ISODate);
|
||||||
|
if (!last.isValid()) return true;
|
||||||
|
|
||||||
|
// Only one network call per day keeps launch snappy and avoids hammering
|
||||||
|
// the Gitea API on every start.
|
||||||
|
return last.daysTo(QDateTime::currentDateTime()) >= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString UpdateManager::lastKnownRemoteVersion() const {
|
||||||
|
return m_lastKnownRemoteVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString UpdateManager::repoPath() const {
|
||||||
|
return m_repoPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UpdateManager::canSelfUpdate() const {
|
||||||
|
if (m_repoPath.isEmpty()) return false;
|
||||||
|
|
||||||
|
QDir repo(m_repoPath);
|
||||||
|
if (!repo.exists(QLatin1String(".git"))) return false;
|
||||||
|
|
||||||
|
// The remote must point to the same FWS repo, otherwise we would build
|
||||||
|
// someone else's code on the user's machine.
|
||||||
|
QFile config(m_repoPath + "/.git/config");
|
||||||
|
if (config.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
const QString content = QString::fromUtf8(config.readAll());
|
||||||
|
if (content.contains(QLatin1String("FWS/FWS-PacManage"))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateManager::loadState() {
|
||||||
|
QFile file(stateFilePath());
|
||||||
|
if (!file.open(QIODevice::ReadOnly)) return;
|
||||||
|
|
||||||
|
QJsonParseError err;
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &err);
|
||||||
|
if (err.error != QJsonParseError::NoError || !doc.isObject()) return;
|
||||||
|
|
||||||
|
QJsonObject obj = doc.object();
|
||||||
|
m_lastCheckDate = obj.value("lastCheckDate").toString();
|
||||||
|
m_lastKnownRemoteVersion = obj.value("latestRemoteVersion").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateManager::saveState(const QString& remoteVersion) {
|
||||||
|
QJsonObject obj;
|
||||||
|
obj["lastCheckDate"] = QDateTime::currentDateTime().toString(Qt::ISODate);
|
||||||
|
obj["latestRemoteVersion"] = remoteVersion;
|
||||||
|
|
||||||
|
QString path = stateFilePath();
|
||||||
|
QDir().mkpath(QFileInfo(path).absolutePath());
|
||||||
|
|
||||||
|
QFile file(path);
|
||||||
|
if (!file.open(QIODevice::WriteOnly)) return;
|
||||||
|
file.write(QJsonDocument(obj).toJson(QJsonDocument::Indented));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateManager::runShell(const QString& script, const QString& workingDir) {
|
||||||
|
m_process.setWorkingDirectory(workingDir);
|
||||||
|
m_process.setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
m_process.start("cmd.exe", QStringList{"/C", script});
|
||||||
|
#else
|
||||||
|
m_process.start("/bin/sh", QStringList{"-c", script});
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateManager::checkForUpdates() {
|
||||||
|
QNetworkRequest request{QUrl(QString::fromLatin1(kApiUrl))};
|
||||||
|
request.setHeader(QNetworkRequest::UserAgentHeader,
|
||||||
|
QString("PacManager/%1").arg(currentVersion()));
|
||||||
|
|
||||||
|
QNetworkReply* reply = m_network.get(request);
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
emit checkFinished(false, QString(),
|
||||||
|
QStringLiteral("Impossible de contacter le serveur : %1")
|
||||||
|
.arg(reply->errorString()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QByteArray data = reply->readAll();
|
||||||
|
QJsonParseError err;
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(data, &err);
|
||||||
|
if (err.error != QJsonParseError::NoError || !doc.isObject()) {
|
||||||
|
emit checkFinished(false, QString(),
|
||||||
|
QStringLiteral("Réponse du serveur invalide."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gitea returns the release tag (e.g. "V1.2.1") as `tag_name`.
|
||||||
|
QString tag = doc.object().value("tag_name").toString().trimmed();
|
||||||
|
if (tag.isEmpty()) {
|
||||||
|
emit checkFinished(false, QString(),
|
||||||
|
QStringLiteral("Aucune release trouvée sur le serveur."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalise tags like "V1.2.1" or "v1.2.1" to "1.2.1" for comparison.
|
||||||
|
if (tag.startsWith('v') || tag.startsWith('V')) {
|
||||||
|
tag = tag.mid(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveState(tag);
|
||||||
|
|
||||||
|
bool hasUpdate = isNewerVersion(tag, currentVersion());
|
||||||
|
m_lastKnownRemoteVersion = tag;
|
||||||
|
m_latestVersion = tag;
|
||||||
|
emit checkFinished(hasUpdate, tag, QString());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UpdateManager::isNewerVersion(const QString& remote, const QString& local) {
|
||||||
|
// Simple dotted numeric comparison ("1.10.2" > "1.9.1"). Non-numeric
|
||||||
|
// components are treated as 0 so pre-release tags stay comparable.
|
||||||
|
auto parts = [](const QString& v) {
|
||||||
|
QVector<int> out;
|
||||||
|
for (const QString& chunk : v.split('.')) {
|
||||||
|
bool ok = false;
|
||||||
|
int n = chunk.toInt(&ok);
|
||||||
|
out.append(ok ? n : 0);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
|
const QVector<int> r = parts(remote);
|
||||||
|
const QVector<int> l = parts(local);
|
||||||
|
const int n = qMax(r.size(), l.size());
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
int ri = i < r.size() ? r[i] : 0;
|
||||||
|
int li = i < l.size() ? l[i] : 0;
|
||||||
|
if (ri != li) return ri > li;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pulls the latest source and rebuilds the app in the background. The script
|
||||||
|
// exits with a non-zero code on failure so the caller can report it. The new
|
||||||
|
// binary replaces the old one only when the build completes — the currently
|
||||||
|
// running process is untouched and picks it up on its next launch.
|
||||||
|
void UpdateManager::performSelfUpdate() {
|
||||||
|
if (m_repoPath.isEmpty()) {
|
||||||
|
emit selfUpdateFinished(false, QStringLiteral("Dépôt source introuvable."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString script = QStringLiteral(
|
||||||
|
"set -e\n"
|
||||||
|
"echo 'Mise à jour de PacManager...'\n"
|
||||||
|
"git pull --ff-only origin main 2>&1 || git pull --ff-only 2>&1\n"
|
||||||
|
"if [ -d build ]; then\n"
|
||||||
|
" cmake --build build -j$(nproc) 2>&1\n"
|
||||||
|
"else\n"
|
||||||
|
" cmake -B build -DCMAKE_BUILD_TYPE=Release . 2>&1\n"
|
||||||
|
" cmake --build build -j$(nproc) 2>&1\n"
|
||||||
|
"fi\n"
|
||||||
|
"echo 'Mise à jour terminée. Redémarrez PacManager pour utiliser la nouvelle version.'");
|
||||||
|
|
||||||
|
runShell(script, m_repoPath);
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
#include "flatpak-manager.h"
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
// Real end-to-end exercise of the Flatpak provider against the live `flatpak`
|
||||||
|
// CLI: install a small app, verify it is listed and marked as installed in
|
||||||
|
// search, run update/refresh, then uninstall. It validates the exact commands
|
||||||
|
// the application runs (install fallbacks included) instead of only parsing.
|
||||||
|
//
|
||||||
|
// Skipped (with a message) when the flatpak binary is not available so the
|
||||||
|
// suite stays green on systems without it.
|
||||||
|
//
|
||||||
|
// The test is non-destructive for pre-existing installs: if the app is already
|
||||||
|
// present when the test starts it is left in place, only verified and updated.
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const std::string kApp = "org.gnome.Calculator";
|
||||||
|
|
||||||
|
bool isInstalled(FlatpakManager& fm) {
|
||||||
|
for (const auto& pkg : fm.listInstalled()) {
|
||||||
|
if (pkg.name == kApp) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::path desktopLink() {
|
||||||
|
const char* home = std::getenv("HOME");
|
||||||
|
return fs::path(home ? home : "/tmp") / ".local/share/applications" / (kApp + ".desktop");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
if (system("which flatpak > /dev/null 2>&1") != 0) {
|
||||||
|
std::cout << "flatpak not installed, skipping integration test" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FlatpakManager fm;
|
||||||
|
const bool preinstalled = isInstalled(fm);
|
||||||
|
|
||||||
|
// 1. Install through the provider's own logic (remote-add + fallbacks).
|
||||||
|
if (!fm.install(kApp, nullptr)) {
|
||||||
|
std::cout << "FAIL install: " << fm.lastError() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!isInstalled(fm)) {
|
||||||
|
std::cout << "FAIL install: app not listed as installed" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1b. The app must be linked into the user's standard applications dir so it
|
||||||
|
// appears in any desktop launcher (the pacman-like integration).
|
||||||
|
if (fs::is_symlink(desktopLink())) {
|
||||||
|
std::cout << "OK desktop integration present" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "FAIL install: no .desktop link in ~/.local/share/applications" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Updating the single app and all apps must complete without error.
|
||||||
|
if (!fm.update(kApp, nullptr)) {
|
||||||
|
std::cout << "FAIL update(app): " << fm.lastError() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!fm.update("", nullptr)) {
|
||||||
|
std::cout << "FAIL update(all): " << fm.lastError() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Refreshing the appstream metadata must complete without error.
|
||||||
|
if (!fm.refresh(nullptr)) {
|
||||||
|
std::cout << "FAIL refresh: " << fm.lastError() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Search must find the app and report it as installed (not "Disponible").
|
||||||
|
bool searchFound = false;
|
||||||
|
for (const auto& pkg : fm.search("calculator")) {
|
||||||
|
if (pkg.name == kApp) {
|
||||||
|
searchFound = true;
|
||||||
|
if (!pkg.installed) {
|
||||||
|
std::cout << "FAIL search: app not flagged as installed" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!searchFound) {
|
||||||
|
std::cout << "FAIL search: app not found in results" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Uninstall, unless the app was already there before the test started.
|
||||||
|
if (!preinstalled) {
|
||||||
|
if (!fm.remove(kApp, nullptr)) {
|
||||||
|
std::cout << "FAIL remove: " << fm.lastError() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (isInstalled(fm)) {
|
||||||
|
std::cout << "FAIL remove: app still listed as installed" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (fs::is_symlink(desktopLink())) {
|
||||||
|
std::cout << "FAIL remove: desktop link not removed" << std::endl;
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
std::cout << "OK desktop integration removed" << std::endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Pre-existing app: verify the launcher link exists (integration ran).
|
||||||
|
if (!fs::is_symlink(desktopLink())) {
|
||||||
|
std::cout << "OK desktop integration ensured for preinstalled app" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "All flatpak integration tests passed." << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
#include "flatpak-manager.h"
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
static void testParseSearchOutput_parsesAlignedRows() {
|
||||||
|
std::string output =
|
||||||
|
"Name Description Application ID Version Branch Remotes\n"
|
||||||
|
"Firefox Fast and privacy-aware browser org.mozilla.firefox 128.0.2 stable flathub\n"
|
||||||
|
"Calculator Simple calculator org.gnome.Calculator 46.0 stable flathub\n";
|
||||||
|
|
||||||
|
auto pkgs = FlatpakManager::parseSearchOutput(output);
|
||||||
|
|
||||||
|
assert(pkgs.size() == 2);
|
||||||
|
assert(pkgs[0].name == "org.mozilla.firefox");
|
||||||
|
assert(pkgs[0].version == "128.0.2");
|
||||||
|
assert(pkgs[0].repository == "flathub");
|
||||||
|
// The display name is prefixed to the description.
|
||||||
|
assert(pkgs[0].description == "Firefox — Fast and privacy-aware browser");
|
||||||
|
assert(pkgs[1].name == "org.gnome.Calculator");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseSearchOutput_keepsMultiWordDescriptions() {
|
||||||
|
std::string output =
|
||||||
|
"Name Description Application ID Version Branch Remotes\n"
|
||||||
|
"Spotify Desktop music player with sync org.spotify.Client 1.2.3 stable flathub\n";
|
||||||
|
|
||||||
|
auto pkgs = FlatpakManager::parseSearchOutput(output);
|
||||||
|
|
||||||
|
assert(pkgs.size() == 1);
|
||||||
|
assert(pkgs[0].name == "org.spotify.Client");
|
||||||
|
assert(pkgs[0].description == "Spotify — Desktop music player with sync");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseSearchOutput_ignoresVersionLikeTokens() {
|
||||||
|
// Versions such as 128.0.2 must not be mistaken for an application ID.
|
||||||
|
std::string output =
|
||||||
|
"Name Description Application ID Version Branch Remotes\n"
|
||||||
|
"GIMP Image editor org.gimp.GIMP 2.10.36 stable flathub\n";
|
||||||
|
|
||||||
|
auto pkgs = FlatpakManager::parseSearchOutput(output);
|
||||||
|
|
||||||
|
assert(pkgs.size() == 1);
|
||||||
|
assert(pkgs[0].name == "org.gimp.GIMP");
|
||||||
|
assert(pkgs[0].version == "2.10.36");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseSearchOutput_emptyInput() {
|
||||||
|
assert(FlatpakManager::parseSearchOutput("").empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledOutput_parsesTabSeparated() {
|
||||||
|
std::string output =
|
||||||
|
"org.mozilla.firefox\t128.0.2\tflathub\n"
|
||||||
|
"org.gnome.Calculator\t46.0\tflathub\n";
|
||||||
|
|
||||||
|
auto pkgs = FlatpakManager::parseInstalledOutput(output);
|
||||||
|
|
||||||
|
assert(pkgs.size() == 2);
|
||||||
|
assert(pkgs[0].name == "org.mozilla.firefox");
|
||||||
|
assert(pkgs[0].version == "128.0.2");
|
||||||
|
assert(pkgs[0].repository == "flathub");
|
||||||
|
assert(pkgs[0].installed);
|
||||||
|
assert(!pkgs[0].updateAvailable);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledOutput_emptyInput() {
|
||||||
|
assert(FlatpakManager::parseInstalledOutput("").empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseUpdatesOutput_parsesRows() {
|
||||||
|
std::string output =
|
||||||
|
"org.mozilla.firefox\t130.0\n"
|
||||||
|
"org.gnome.Calculator\t47.0\n";
|
||||||
|
|
||||||
|
auto pkgs = FlatpakManager::parseUpdatesOutput(output);
|
||||||
|
|
||||||
|
assert(pkgs.size() == 2);
|
||||||
|
assert(pkgs[0].name == "org.mozilla.firefox");
|
||||||
|
assert(pkgs[0].version == "130.0");
|
||||||
|
assert(pkgs[0].installed);
|
||||||
|
assert(pkgs[0].updateAvailable);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseUpdatesOutput_emptyInput() {
|
||||||
|
assert(FlatpakManager::parseUpdatesOutput("").empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
testParseSearchOutput_parsesAlignedRows();
|
||||||
|
testParseSearchOutput_keepsMultiWordDescriptions();
|
||||||
|
testParseSearchOutput_ignoresVersionLikeTokens();
|
||||||
|
testParseSearchOutput_emptyInput();
|
||||||
|
|
||||||
|
testParseInstalledOutput_parsesTabSeparated();
|
||||||
|
testParseInstalledOutput_emptyInput();
|
||||||
|
|
||||||
|
testParseUpdatesOutput_parsesRows();
|
||||||
|
testParseUpdatesOutput_emptyInput();
|
||||||
|
|
||||||
|
std::cout << "All flatpak-manager tests passed." << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
#include "package-manager.h"
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
static PackageInfo pkg(const std::string& name, const std::string& provider,
|
||||||
|
bool installed = false, bool update = false) {
|
||||||
|
PackageInfo p;
|
||||||
|
p.name = name;
|
||||||
|
p.provider = provider;
|
||||||
|
p.installed = installed;
|
||||||
|
p.updateAvailable = update;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testMerge_keepsSingleProviderRows() {
|
||||||
|
std::vector<PackageInfo> v = {
|
||||||
|
pkg("firefox", "pacman"), pkg("vim", "pacman"), pkg("vlc", "flatpak")};
|
||||||
|
|
||||||
|
mergeProviderDuplicates(v);
|
||||||
|
|
||||||
|
assert(v.size() == 3);
|
||||||
|
assert(v[0].providers.size() == 1 && v[0].providers[0] == "pacman");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testMerge_combinesDuplicateProviders() {
|
||||||
|
std::vector<PackageInfo> v = {
|
||||||
|
pkg("firefox", "pacman", /*installed=*/true),
|
||||||
|
pkg("firefox", "flatpak", /*installed=*/false, /*update=*/true),
|
||||||
|
};
|
||||||
|
|
||||||
|
mergeProviderDuplicates(v);
|
||||||
|
|
||||||
|
assert(v.size() == 1);
|
||||||
|
// First provider wins as the routing default; both are listed for display.
|
||||||
|
assert(v[0].provider == "pacman");
|
||||||
|
assert(v[0].providers.size() == 2);
|
||||||
|
assert(v[0].providers[0] == "pacman");
|
||||||
|
assert(v[0].providers[1] == "flatpak");
|
||||||
|
// Statuses are OR-ed across providers.
|
||||||
|
assert(v[0].installed);
|
||||||
|
assert(v[0].updateAvailable);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testMerge_mergesNonAdjacentDuplicates() {
|
||||||
|
std::vector<PackageInfo> v = {
|
||||||
|
pkg("vim", "pacman"), pkg("firefox", "pacman"), pkg("vim", "flatpak")};
|
||||||
|
|
||||||
|
mergeProviderDuplicates(v);
|
||||||
|
|
||||||
|
assert(v.size() == 2);
|
||||||
|
assert(v[0].name == "vim" && v[0].providers.size() == 2);
|
||||||
|
assert(v[1].name == "firefox" && v[1].providers.size() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testMerge_dedupesSameProviderTwice() {
|
||||||
|
std::vector<PackageInfo> v = {
|
||||||
|
pkg("firefox", "pacman"), pkg("firefox", "flatpak"), pkg("firefox", "flatpak")};
|
||||||
|
|
||||||
|
mergeProviderDuplicates(v);
|
||||||
|
|
||||||
|
assert(v.size() == 1);
|
||||||
|
assert(v[0].providers.size() == 2); // no repeated "flatpak"
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testMerge_emptyInput() {
|
||||||
|
std::vector<PackageInfo> v;
|
||||||
|
mergeProviderDuplicates(v);
|
||||||
|
assert(v.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testSort_groupsByProviderThenName() {
|
||||||
|
std::vector<PackageInfo> v = {
|
||||||
|
pkg("vim", "pacman"),
|
||||||
|
pkg("org.mozilla.firefox", "flatpak"),
|
||||||
|
pkg("firefox", "pacman"),
|
||||||
|
pkg("blender", "flatpak"),
|
||||||
|
};
|
||||||
|
|
||||||
|
sortByProviderThenName(v, {"pacman", "flatpak"});
|
||||||
|
|
||||||
|
assert(v.size() == 4);
|
||||||
|
assert(v[0].name == "firefox" && v[0].provider == "pacman");
|
||||||
|
assert(v[1].name == "vim" && v[1].provider == "pacman");
|
||||||
|
assert(v[2].name == "blender" && v[2].provider == "flatpak");
|
||||||
|
assert(v[3].name == "org.mozilla.firefox" && v[3].provider == "flatpak");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testSort_caseInsensitiveNames() {
|
||||||
|
std::vector<PackageInfo> v = {
|
||||||
|
pkg("Zsh", "pacman"),
|
||||||
|
pkg("abc", "pacman"),
|
||||||
|
};
|
||||||
|
|
||||||
|
sortByProviderThenName(v, {"pacman"});
|
||||||
|
|
||||||
|
assert(v[0].name == "abc");
|
||||||
|
assert(v[1].name == "Zsh");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testSort_unknownProvidersSortById() {
|
||||||
|
std::vector<PackageInfo> v = {
|
||||||
|
pkg("beta", "plugin-x"),
|
||||||
|
pkg("alpha", "plugin-y"),
|
||||||
|
};
|
||||||
|
|
||||||
|
sortByProviderThenName(v); // no provider order given
|
||||||
|
|
||||||
|
assert(v[0].name == "alpha");
|
||||||
|
assert(v[1].name == "beta");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
testMerge_keepsSingleProviderRows();
|
||||||
|
testMerge_combinesDuplicateProviders();
|
||||||
|
testMerge_mergesNonAdjacentDuplicates();
|
||||||
|
testMerge_dedupesSameProviderTwice();
|
||||||
|
testMerge_emptyInput();
|
||||||
|
|
||||||
|
testSort_groupsByProviderThenName();
|
||||||
|
testSort_caseInsensitiveNames();
|
||||||
|
testSort_unknownProvidersSortById();
|
||||||
|
|
||||||
|
std::cout << "All package-utils tests passed." << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
#include "pacman-manager.h"
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
static void testParseInstalledOutput_parsesSimpleLines() {
|
||||||
|
std::string output = "firefox 128.0\nvim 9.1.0000\n";
|
||||||
|
auto pkgs = PacmanManager::parseInstalledOutput(output);
|
||||||
|
|
||||||
|
assert(pkgs.size() == 2);
|
||||||
|
assert(pkgs[0].name == "firefox");
|
||||||
|
assert(pkgs[0].version == "128.0");
|
||||||
|
assert(pkgs[0].installed);
|
||||||
|
assert(pkgs[1].name == "vim");
|
||||||
|
assert(pkgs[1].version == "9.1.0000");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledOutput_keepsHyphensInNames() {
|
||||||
|
// Hyphenated package names must not be split on the dash (python-pip, not python)
|
||||||
|
std::string output = "python-pip 24.0-1\n";
|
||||||
|
auto pkgs = PacmanManager::parseInstalledOutput(output);
|
||||||
|
|
||||||
|
assert(pkgs.size() == 1);
|
||||||
|
assert(pkgs[0].name == "python-pip");
|
||||||
|
assert(pkgs[0].version == "24.0-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledOutput_skipsEmptyLines() {
|
||||||
|
std::string output = "firefox 128.0\n\nvim 9.1.0000\n";
|
||||||
|
auto pkgs = PacmanManager::parseInstalledOutput(output);
|
||||||
|
|
||||||
|
assert(pkgs.size() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledOutput_emptyInput() {
|
||||||
|
auto pkgs = PacmanManager::parseInstalledOutput("");
|
||||||
|
assert(pkgs.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledNames_parsesNames() {
|
||||||
|
std::string output = "firefox 128.0\npython-pip 24.0-1\nvim 9.1.0000\n";
|
||||||
|
auto names = PacmanManager::parseInstalledNames(output);
|
||||||
|
|
||||||
|
assert(names.size() == 3);
|
||||||
|
assert(names.count("firefox") == 1);
|
||||||
|
assert(names.count("python-pip") == 1);
|
||||||
|
assert(names.count("vim") == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledNames_skipsEmptyLines() {
|
||||||
|
std::string output = "firefox 128.0\n\nvim 9.1.0000\n";
|
||||||
|
auto names = PacmanManager::parseInstalledNames(output);
|
||||||
|
|
||||||
|
assert(names.size() == 2);
|
||||||
|
assert(names.count("firefox") == 1);
|
||||||
|
assert(names.count("vim") == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledNames_emptyInput() {
|
||||||
|
assert(PacmanManager::parseInstalledNames("").empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledSizes_parsesBlocks() {
|
||||||
|
std::string output =
|
||||||
|
"Name : firefox\n"
|
||||||
|
"Version : 128.0-1\n"
|
||||||
|
"Installed Size : 263.47 MiB\n"
|
||||||
|
"Install Date : 2026-01-01\n"
|
||||||
|
"\n"
|
||||||
|
"Name : vim\n"
|
||||||
|
"Installed Size : 12.3 MiB\n";
|
||||||
|
|
||||||
|
auto sizes = PacmanManager::parseInstalledSizes(output);
|
||||||
|
|
||||||
|
assert(sizes.size() == 2);
|
||||||
|
assert(sizes["firefox"] == "263.47 MiB");
|
||||||
|
assert(sizes["vim"] == "12.3 MiB");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseInstalledSizes_emptyInput() {
|
||||||
|
assert(PacmanManager::parseInstalledSizes("").empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseSyncRepos_skipsHeader() {
|
||||||
|
std::string output =
|
||||||
|
"Repository Name Version\n"
|
||||||
|
"core linux 6.6-1\n"
|
||||||
|
"extra firefox 128.0-1\n"
|
||||||
|
"multilib gcc-libs 13.2-1\n";
|
||||||
|
|
||||||
|
auto repos = PacmanManager::parseSyncRepos(output);
|
||||||
|
|
||||||
|
assert(repos.size() == 3);
|
||||||
|
assert(repos["linux"] == "core");
|
||||||
|
assert(repos["firefox"] == "extra");
|
||||||
|
assert(repos["gcc-libs"] == "multilib");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testParseSyncRepos_emptyInput() {
|
||||||
|
assert(PacmanManager::parseSyncRepos("").empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testAuthFailed_detectsWrongPassword() {
|
||||||
|
assert(PacmanManager::authFailed(
|
||||||
|
"[sudo] password for alice: Sorry, try again.\nsudo: 1 incorrect password attempt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testAuthFailed_detectsMissingPassword() {
|
||||||
|
assert(PacmanManager::authFailed("sudo: a password is required"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testAuthFailed_ignoresPacmanErrors() {
|
||||||
|
assert(!PacmanManager::authFailed("error: target not found: firefox"));
|
||||||
|
assert(!PacmanManager::authFailed("warning: firefox is up to date"));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
testParseInstalledOutput_parsesSimpleLines();
|
||||||
|
testParseInstalledOutput_keepsHyphensInNames();
|
||||||
|
testParseInstalledOutput_skipsEmptyLines();
|
||||||
|
testParseInstalledOutput_emptyInput();
|
||||||
|
|
||||||
|
testParseInstalledNames_parsesNames();
|
||||||
|
testParseInstalledNames_skipsEmptyLines();
|
||||||
|
testParseInstalledNames_emptyInput();
|
||||||
|
|
||||||
|
testParseInstalledSizes_parsesBlocks();
|
||||||
|
testParseInstalledSizes_emptyInput();
|
||||||
|
testParseSyncRepos_skipsHeader();
|
||||||
|
testParseSyncRepos_emptyInput();
|
||||||
|
|
||||||
|
testAuthFailed_detectsWrongPassword();
|
||||||
|
testAuthFailed_detectsMissingPassword();
|
||||||
|
testAuthFailed_ignoresPacmanErrors();
|
||||||
|
|
||||||
|
std::cout << "All pacman-manager tests passed." << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
#include "plugin-manager.h"
|
||||||
|
#include "pacman-manager.h"
|
||||||
|
#include "flatpak-manager.h"
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Exercises PluginManager end-to-end: built-in registration plus runtime
|
||||||
|
// discovery of the example plugins (built into build/plugins by CMake when
|
||||||
|
// FWS_BUILD_EXAMPLE_PLUGIN=ON and FWS_BUILD_EXAMPLE_ADDON=ON).
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
|
app.setOrganizationName("Freebuff");
|
||||||
|
app.setApplicationName("PacManager");
|
||||||
|
|
||||||
|
PluginManager pm;
|
||||||
|
pm.registerBuiltin({"pacman", "Pacman", "1.0.0", "Natif Arch Linux", "FWS"},
|
||||||
|
new PacmanManager());
|
||||||
|
// Flatpak and the sample plugins are dropped next to the test binary by
|
||||||
|
// CMake rather than compiled in.
|
||||||
|
pm.discoverExternal();
|
||||||
|
|
||||||
|
// pacman built-in + the flatpak and sample plugins dropped next to the
|
||||||
|
// test binary (flatpak is optional via FWS_BUILD_FLATPAK_PLUGIN).
|
||||||
|
#ifdef FWS_FLATPAK_PLUGIN_BUILT
|
||||||
|
assert(pm.plugins().size() == 3);
|
||||||
|
#else
|
||||||
|
assert(pm.plugins().size() == 2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Install hints are exposed per provider; the sample plugin omits its
|
||||||
|
// optional hint symbol (must read back empty), while the flatpak plugin
|
||||||
|
// declares the OS package backing its tool.
|
||||||
|
const auto& plugins = pm.plugins();
|
||||||
|
for (const auto& entry : plugins) {
|
||||||
|
if (entry.info.id == "flatpak") {
|
||||||
|
assert(!entry.info.builtin);
|
||||||
|
assert(entry.info.installHint == "flatpak");
|
||||||
|
}
|
||||||
|
if (entry.info.id == "sample") assert(entry.info.installHint.empty());
|
||||||
|
}
|
||||||
|
assert(pm.findAvailable("flatpak") != nullptr);
|
||||||
|
|
||||||
|
// External provider plugin metadata is exposed through the C ABI.
|
||||||
|
const auto* sample = pm.findAvailable("sample");
|
||||||
|
assert(sample != nullptr);
|
||||||
|
assert(sample->info.name == "Sample Provider");
|
||||||
|
assert(sample->info.version == "0.1.0");
|
||||||
|
assert(sample->info.author == "FWS");
|
||||||
|
assert(!sample->info.builtin);
|
||||||
|
assert(sample->info.kind == PluginKind::Provider);
|
||||||
|
assert(sample->manager != nullptr);
|
||||||
|
assert(sample->plugin == nullptr);
|
||||||
|
assert(sample->manager->getName() == "sample");
|
||||||
|
assert(sample->manager->isAvailable());
|
||||||
|
|
||||||
|
// The example addon is a generic extension (kind Addon), not a package
|
||||||
|
// manager: it implements IPlugin and its availability proves onLoad() ran
|
||||||
|
// (see plugins/example-addon/example-addon.cpp).
|
||||||
|
const PluginManager::PluginEntry* addon = nullptr;
|
||||||
|
for (const auto& entry : pm.plugins()) {
|
||||||
|
if (entry.info.id == "example-addon") addon = &entry;
|
||||||
|
}
|
||||||
|
assert(addon != nullptr);
|
||||||
|
assert(addon->info.kind == PluginKind::Addon);
|
||||||
|
assert(addon->plugin != nullptr);
|
||||||
|
assert(addon->manager == nullptr);
|
||||||
|
assert(addon->info.available);
|
||||||
|
assert(pm.availableAddons().size() == 1);
|
||||||
|
assert(pm.availableAddons().front() == addon->plugin);
|
||||||
|
|
||||||
|
// Manager lookup works by id.
|
||||||
|
IPackageManager* pacman = pm.managerFor("pacman");
|
||||||
|
assert(pacman != nullptr);
|
||||||
|
assert(pacman->getName() == "pacman");
|
||||||
|
|
||||||
|
// Enable/disable is persisted and filters the available lists.
|
||||||
|
assert(pm.isEnabled("sample"));
|
||||||
|
pm.setEnabled("sample", false);
|
||||||
|
assert(!pm.isEnabled("sample"));
|
||||||
|
assert(pm.findAvailable("sample") == nullptr);
|
||||||
|
pm.setEnabled("sample", true);
|
||||||
|
assert(pm.findAvailable("sample") != nullptr);
|
||||||
|
|
||||||
|
pm.setEnabled("example-addon", false);
|
||||||
|
assert(pm.availableAddons().empty());
|
||||||
|
pm.setEnabled("example-addon", true);
|
||||||
|
assert(pm.availableAddons().size() == 1);
|
||||||
|
|
||||||
|
// Reload keeps built-ins (same instance) and rescans external plugins:
|
||||||
|
// the addon is recreated (fresh onLoad), so its instance pointer changes.
|
||||||
|
IPackageManager* pacmanBefore = pacman;
|
||||||
|
IPlugin* addonBefore = addon->plugin;
|
||||||
|
pm.reload();
|
||||||
|
assert(pm.managerFor("pacman") == pacmanBefore);
|
||||||
|
assert(pm.findAvailable("sample") != nullptr);
|
||||||
|
const auto* reloadedAddon = pm.availableAddons().front();
|
||||||
|
assert(reloadedAddon != addonBefore);
|
||||||
|
assert(reloadedAddon->isAvailable());
|
||||||
|
|
||||||
|
// refreshAvailability re-evaluates the presence of every tool.
|
||||||
|
pm.refreshAvailability();
|
||||||
|
assert(pm.findAvailable("pacman") != nullptr);
|
||||||
|
|
||||||
|
std::cout << "All plugin-manager tests passed." << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||