feat(ui): merge duplicate packages across providers

When the same package name comes from several providers (pacman, flatpak,
plugins), collapse the rows into one: the Fournisseur column lists every
provider offering it and installed/updateAvailable are combined, while
the first provider stays the routing default. Applies to search and to
the aggregated installed/updates lists.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
BlackAngelTV committed 2026-08-29 13:55:56 +02:00
1 parent 4fe4c7287e
commit d8a70eabf8
4 files changed
+154 -2

No files matched your search

+51
View File
@@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include <functional>
#include <map>
// Information about a single package
struct PackageInfo {
@@ -16,10 +17,60 @@ struct PackageInfo {
// 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));
}
}
// Abstract interface for the package manager
class IPackageManager {
public: