feat(flatpak): install packages from a Flatpak file
Dragging a .flatpakref, .flatpakrepo or .flatpak onto the window, or opening it with the file manager, has to reach flatpak without the user going through a search. The provider now owns its formats: it claims the files it handles and builds the matching command, and the core routes the request to whichever provider recognises it, so a new provider can claim its own formats the same way. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
9 files changed
+381
-5
No files matched your search
+59
-4
@@ -485,6 +485,21 @@ AppCore::StartResult AppCore::cleanCaches() {
|
||||
return startRequest(request);
|
||||
}
|
||||
|
||||
AppCore::StartResult AppCore::installFile(const QString& path) {
|
||||
Request request;
|
||||
request.action = QStringLiteral("install-file");
|
||||
request.path = path.trimmed();
|
||||
return startRequest(request);
|
||||
}
|
||||
|
||||
bool AppCore::canInstallFile(const QString& path) const {
|
||||
if (path.trimmed().isEmpty()) return false;
|
||||
for (IPackageManager* pm : availableProviders()) {
|
||||
if (pm->canInstallFile(path.trimmed().toStdString())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
AppCore::StartResult AppCore::removePackages(const std::vector<PackageInfo>& packages,
|
||||
const QString& description) {
|
||||
Request request;
|
||||
@@ -554,7 +569,7 @@ AppCore::StartResult AppCore::releaseDatabaseLock() {
|
||||
return accepted();
|
||||
}
|
||||
|
||||
AppCore::StartResult AppCore::startRequest(const Request& request) {
|
||||
AppCore::StartResult AppCore::startRequest(Request request) {
|
||||
if (m_busy) return refused(QStringLiteral("Une opération est déjà en cours, patientez..."));
|
||||
|
||||
const QString action = request.action;
|
||||
@@ -605,6 +620,27 @@ AppCore::StartResult AppCore::startRequest(const Request& request) {
|
||||
if (providers.empty()) {
|
||||
return refused(QStringLiteral("Aucun cache à nettoyer sur ce système."));
|
||||
}
|
||||
} else if (action == QLatin1String("install-file")) {
|
||||
if (request.path.isEmpty()) {
|
||||
return refused(QStringLiteral("Aucun fichier à installer."));
|
||||
}
|
||||
// The provider owns the file formats it knows, so the routing is the
|
||||
// same kind of lookup as providerFor() is for package names.
|
||||
for (IPackageManager* pm : availableProviders()) {
|
||||
if (!pm->canInstallFile(request.path.toStdString())) continue;
|
||||
providers = {pm};
|
||||
break;
|
||||
}
|
||||
if (providers.empty()) {
|
||||
return refused(QStringLiteral(
|
||||
"Aucun gestionnaire de paquets ne sait installer ce fichier."));
|
||||
}
|
||||
op = InstallWorker::Op::InstallFile;
|
||||
// The package name is unknown until flatpak resolves the file: the file
|
||||
// name is what the status bar and the history row can honestly show.
|
||||
label = QFileInfo(request.path).completeBaseName();
|
||||
if (label.isEmpty()) label = request.path;
|
||||
request.package.name = label.toStdString();
|
||||
} else if (action == QLatin1String("cleanup")) {
|
||||
// One command per provider: each provider groups the packages it owns,
|
||||
// and the groups run one after another (pacman locks its database).
|
||||
@@ -677,6 +713,10 @@ AppCore::StartResult AppCore::startRequest(const Request& request) {
|
||||
if (action == QLatin1String("update-all") || action == QLatin1String("refresh")
|
||||
|| action == QLatin1String("clean-caches")) {
|
||||
worker = new InstallWorker(providers, op);
|
||||
} else if (action == QLatin1String("install-file")) {
|
||||
// A file install needs the path, not the display label the other
|
||||
// single-provider operations pass.
|
||||
worker = new InstallWorker(providers.front(), op, request.path.toStdString());
|
||||
} else {
|
||||
worker = new InstallWorker(providers.front(), op, label.toStdString());
|
||||
}
|
||||
@@ -702,6 +742,9 @@ QString AppCore::startMessage(const QString& action, const QString& label) const
|
||||
if (action == QLatin1String("clean-caches")) {
|
||||
return QStringLiteral("Nettoyage des caches...");
|
||||
}
|
||||
if (action == QLatin1String("install-file")) {
|
||||
return QStringLiteral("Installation depuis un fichier : %1...").arg(label);
|
||||
}
|
||||
if (action == QLatin1String("install-plugin-tool")) {
|
||||
return QStringLiteral("Installation de l'outil %1...").arg(label);
|
||||
}
|
||||
@@ -715,8 +758,10 @@ AppCore::StartResult AppCore::startAction(InstallWorker* worker, const Request&
|
||||
qCInfo(pacmgrOp) << request.action << QString::fromStdString(request.package.name);
|
||||
|
||||
// Journal header: what is about to run, so the raw output that follows reads
|
||||
// like a hand-run command.
|
||||
const QString target = QString::fromStdString(request.package.name);
|
||||
// like a hand-run command. A file install logs the file it acted on.
|
||||
const QString target = request.path.isEmpty()
|
||||
? QString::fromStdString(request.package.name)
|
||||
: request.path;
|
||||
LogManager::instance().beginCommand(
|
||||
providerLabel(providers), request.action,
|
||||
target.isEmpty() ? QString()
|
||||
@@ -775,6 +820,10 @@ void AppCore::finishAction(const Request& request,
|
||||
if (action == QLatin1String("install") || action == QLatin1String("remove")
|
||||
|| action == QLatin1String("update")) {
|
||||
recordHistory(action, name, providers.empty() ? nullptr : providers.front(), success);
|
||||
} else if (action == QLatin1String("install-file")) {
|
||||
// Recorded as an install so the History page's filter picks it up.
|
||||
recordHistory(QStringLiteral("install"), name,
|
||||
providers.empty() ? nullptr : providers.front(), success);
|
||||
} else if (action == QLatin1String("clean-caches")) {
|
||||
for (IPackageManager* pm : providers) {
|
||||
recordHistory(QStringLiteral("cleanup"), QStringLiteral("caches"), pm, success);
|
||||
@@ -784,7 +833,7 @@ void AppCore::finishAction(const Request& request,
|
||||
clearCredentialsAfterUse();
|
||||
|
||||
if (action == QLatin1String("install") || action == QLatin1String("remove")
|
||||
|| action == QLatin1String("update")) {
|
||||
|| action == QLatin1String("update") || action == QLatin1String("install-file")) {
|
||||
invalidateDetails();
|
||||
}
|
||||
if (action == QLatin1String("install-plugin-tool") && success) {
|
||||
@@ -816,6 +865,9 @@ QString AppCore::successMessage(const QString& action, const QString& name) cons
|
||||
if (action == QLatin1String("clean-caches")) {
|
||||
return QStringLiteral("Caches nettoyés");
|
||||
}
|
||||
if (action == QLatin1String("install-file")) {
|
||||
return QStringLiteral("%1 installé avec succès").arg(name);
|
||||
}
|
||||
if (action == QLatin1String("install-plugin-tool")) {
|
||||
return QStringLiteral("Outil installé, plugin disponible.");
|
||||
}
|
||||
@@ -841,6 +893,9 @@ QString AppCore::failureMessage(const QString& action, const QString& name) cons
|
||||
if (action == QLatin1String("clean-caches")) {
|
||||
return QStringLiteral("Échec du nettoyage des caches");
|
||||
}
|
||||
if (action == QLatin1String("install-file")) {
|
||||
return QStringLiteral("Échec de l'installation de %1").arg(name);
|
||||
}
|
||||
if (action == QLatin1String("install-plugin-tool")) {
|
||||
return QStringLiteral("Échec de l'installation de l'outil.");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user