Skip to content

Commit

Permalink
Rewrite function for clarity and possible performance gain
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianTM committed Oct 31, 2024
1 parent 6d3e9f9 commit ecd122f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,19 +832,20 @@ void MainWindow::displayPackages()

void MainWindow::displayAutoremovable(const QTreeWidget *newtree)
{
if (newtree != ui->treePopularApps && newtree != ui->treeFlatpak) {
QStringList names = cmd.getOut("LANG=C apt-get --dry-run autoremove | grep -Po '^Remv \\K[^ ]+'")
.split('\n', Qt::SkipEmptyParts);
if (!names.isEmpty()) {
ui->pushRemoveAutoremovable->setVisible(true);
for (const QString &name : names) {
auto matchingItems = newtree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive, TreeCol::Name);
for (QTreeWidgetItem *item : matchingItems) {
item->setData(TreeCol::Status, Qt::UserRole, Status::Autoremovable);
}
}
} else {
ui->pushRemoveAutoremovable->setVisible(false);
if (newtree == ui->treePopularApps || newtree == ui->treeFlatpak) {
return;
}
QStringList names
= cmd.getOut("LANG=C apt-get --dry-run autoremove | grep -Po '^Remv \\K[^ ]+'").split('\n', Qt::SkipEmptyParts);

ui->pushRemoveAutoremovable->setVisible(!names.isEmpty());
if (names.isEmpty()) {
return;
}
QSet<QString> nameSet(names.begin(), names.end());
for (QTreeWidgetItemIterator it(const_cast<QTreeWidget *>(newtree)); *it; ++it) {
if (nameSet.contains((*it)->text(TreeCol::Name))) {
(*it)->setData(TreeCol::Status, Qt::UserRole, Status::Autoremovable);
}
}
}
Expand Down

0 comments on commit ecd122f

Please sign in to comment.