feat(flatpak): let the user choose which installation to act on
The same application can be present twice — in the user installation and system-wide, or from two remotes or two branches — and flatpak then refuses to act on the application id alone: "Multiple installed refs match 'com.hoptodesk.HopToDesk'". Removing either copy was impossible from the app. A row now stands for the application and carries the copies it is made of, so the details panel lists them and Remove opens one checkbox per copy; the provider gets back the exact target it listed, and naming a ref plus its installation is what makes the call unambiguous. Update gains the same resolution, since it hit the very same refusal, and removing one copy of two no longer takes the other one's launcher entry away with it. The listing that feeds it now asks flatpak for the ref, the branch and the installation, and reads those columns by position: a branch installed from a subdirectory has no version, and dropping that empty column shifted every field after it.
This commit is contained in:
14 files changed
+559
-20
No files matched your search
+94
-1
@@ -1,6 +1,8 @@
|
||||
#include "browse-page.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
@@ -9,6 +11,7 @@
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressBar>
|
||||
#include <QPushButton>
|
||||
@@ -101,7 +104,15 @@ BrowsePage::BrowsePage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
connect(m_removeButton, &QPushButton::clicked, this, [this, core] {
|
||||
if (m_selected.name.empty()) return;
|
||||
m_pendingSelect = QString::fromStdString(m_selected.name);
|
||||
start(core->remove(m_selected), tr("Suppression"));
|
||||
// Several copies of the same application: the user says which ones go.
|
||||
// A cancelled chooser aborts, an empty choice tells why in the status bar.
|
||||
const auto targets = chooseInstancesToRemove();
|
||||
if (!targets.has_value()) return;
|
||||
if (targets->empty()) {
|
||||
emit message(tr("Aucune installation sélectionnée."));
|
||||
return;
|
||||
}
|
||||
start(core->removeInstances(m_selected, *targets), tr("Suppression"));
|
||||
});
|
||||
actionBar->addWidget(m_removeButton);
|
||||
|
||||
@@ -200,6 +211,14 @@ BrowsePage::BrowsePage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
metaRow->addStretch();
|
||||
detailsLayout->addLayout(metaRow);
|
||||
|
||||
// Only shown for a package the provider holds several times over.
|
||||
m_pkgInstances = new QLabel();
|
||||
m_pkgInstances->setWordWrap(true);
|
||||
m_pkgInstances->setStyleSheet(
|
||||
"font-size: 13px; color: #7dd3fc; background: transparent;");
|
||||
m_pkgInstances->setVisible(false);
|
||||
detailsLayout->addWidget(m_pkgInstances);
|
||||
|
||||
QFrame* separator = new QFrame();
|
||||
separator->setFrameShape(QFrame::HLine);
|
||||
separator->setStyleSheet(
|
||||
@@ -522,6 +541,24 @@ void BrowsePage::updateDetails(const PackageInfo& pkg) {
|
||||
m_pkgProvider->setText(
|
||||
QString("Fournisseur : %1").arg(ui::providersLabel(core()->plugins(), pkg)));
|
||||
|
||||
// A provider can hold several copies of the same application (flatpak: one
|
||||
// per installation, per remote or per branch). The row stands for the
|
||||
// application, so the copies it is made of are listed here — and the remove
|
||||
// button asks which of them to act on.
|
||||
if (pkg.instances.size() > 1) {
|
||||
QStringList copies;
|
||||
for (const PackageInstance& instance : pkg.instances) {
|
||||
copies << QString::fromStdString(instance.label);
|
||||
}
|
||||
m_pkgInstances->setText(
|
||||
QString("%1 installation(s) :\n• %2")
|
||||
.arg(copies.size())
|
||||
.arg(copies.join(QStringLiteral("\n• "))));
|
||||
m_pkgInstances->setVisible(true);
|
||||
} else {
|
||||
m_pkgInstances->setVisible(false);
|
||||
}
|
||||
|
||||
// Rich details (dependencies, required-by, install date, update size): the
|
||||
// core queries pacman on demand and caches the answer, so selecting a row
|
||||
// stays instant even when pacman is slow.
|
||||
@@ -534,6 +571,61 @@ void BrowsePage::updateDetails(const PackageInfo& pkg) {
|
||||
m_pkgDescription->setText(details);
|
||||
}
|
||||
|
||||
// Asks which copies of the selected application to remove, when the provider
|
||||
// holds it more than once (flatpak: a user and a system-wide installation, or
|
||||
// two remotes or branches of the same id). One line per copy, each with the
|
||||
// provider's own target kept aside, so the core is handed exactly what it must
|
||||
// act on. Returns nothing when the user cancels.
|
||||
std::optional<std::vector<std::string>> BrowsePage::chooseInstancesToRemove() {
|
||||
if (m_selected.instances.size() < 2) {
|
||||
// A single installation, or a provider that only ever has one: the row
|
||||
// is the thing to remove, no question to ask.
|
||||
return std::vector<std::string>{};
|
||||
}
|
||||
|
||||
QDialog dialog(this);
|
||||
dialog.setWindowTitle(tr("Supprimer %1").arg(QString::fromStdString(m_selected.name)));
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(&dialog);
|
||||
layout->setSpacing(10);
|
||||
QLabel* prompt = new QLabel(
|
||||
tr("%1 est installé plusieurs fois. Choisissez les installations à "
|
||||
"supprimer.")
|
||||
.arg(QString::fromStdString(m_selected.name)),
|
||||
&dialog);
|
||||
prompt->setWordWrap(true);
|
||||
layout->addWidget(prompt);
|
||||
|
||||
QListWidget* copies = new QListWidget(&dialog);
|
||||
for (const PackageInstance& instance : m_selected.instances) {
|
||||
QListWidgetItem* item =
|
||||
new QListWidgetItem(QString::fromStdString(instance.label), copies);
|
||||
// The target never reaches the screen: it is the provider's own syntax,
|
||||
// kept beside the label and handed straight back.
|
||||
item->setData(Qt::UserRole, QString::fromStdString(instance.target));
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
layout->addWidget(copies);
|
||||
|
||||
QDialogButtonBox* buttons =
|
||||
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
|
||||
buttons->button(QDialogButtonBox::Ok)->setText(tr("Supprimer"));
|
||||
buttons->button(QDialogButtonBox::Cancel)->setText(tr("Annuler"));
|
||||
connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
||||
connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
||||
layout->addWidget(buttons);
|
||||
|
||||
if (dialog.exec() != QDialog::Accepted) return std::nullopt;
|
||||
|
||||
std::vector<std::string> targets;
|
||||
for (int row = 0; row < copies->count(); ++row) {
|
||||
if (copies->item(row)->checkState() != Qt::Checked) continue;
|
||||
targets.push_back(copies->item(row)->data(Qt::UserRole).toString().toStdString());
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
void BrowsePage::resetDetails() {
|
||||
m_selected = PackageInfo{};
|
||||
m_pkgName->setText("Sélectionnez un paquet");
|
||||
@@ -541,6 +633,7 @@ void BrowsePage::resetDetails() {
|
||||
m_pkgRepo->setText("—");
|
||||
m_pkgSize->setText("—");
|
||||
m_pkgProvider->setText("—");
|
||||
m_pkgInstances->setVisible(false);
|
||||
m_pkgDescription->setText("");
|
||||
m_installButton->setEnabled(false);
|
||||
m_removeButton->setEnabled(false);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
#include "page.h"
|
||||
|
||||
@@ -49,6 +51,10 @@ private:
|
||||
void populateTable(const std::vector<PackageInfo>& packages);
|
||||
void appendRows(const std::vector<PackageInfo>& packages);
|
||||
void addRow(int row, const PackageInfo& pkg);
|
||||
// Which installations of the selected package to remove, when the provider
|
||||
// holds it more than once. Empty when there is only one to remove, nothing
|
||||
// (std::nullopt) when the user cancels the chooser.
|
||||
std::optional<std::vector<std::string>> chooseInstancesToRemove();
|
||||
void updateDetails(const PackageInfo& pkg);
|
||||
void resetDetails();
|
||||
|
||||
@@ -84,5 +90,8 @@ private:
|
||||
QLabel* m_pkgRepo = nullptr;
|
||||
QLabel* m_pkgSize = nullptr;
|
||||
QLabel* m_pkgProvider = nullptr;
|
||||
// The copies a multi-installed package is made of, shown only when there is
|
||||
// more than one.
|
||||
QLabel* m_pkgInstances = nullptr;
|
||||
QLabel* m_pkgDescription = nullptr;
|
||||
};
|
||||
Reference in new issue
Block a user