Skip to content

Commit

Permalink
Fix crash when switching back to Popular tab
Browse files Browse the repository at this point in the history
- Reset popularapp tree when switching tabs
- Run search on empty searchbox too, otherwise it won't reset
- Remove uneeded setCurrentTree calls
- Disable searchBox signals when clearing them on output
  • Loading branch information
AdrianTM committed Jan 20, 2025
1 parent b7a6df3 commit b61191e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
mx-packageinstaller (25.1) mx; urgency=medium

* Fix crash when switching back to Popular tab after searching in another
tab
* Minor optimizations
* Update translations

mx-packageinstaller (24.12.05) mx; urgency=medium

* Set version number during build from changelog within debian/rules
Expand Down
46 changes: 30 additions & 16 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,11 @@ bool MainWindow::installPopularApps()
}
}
setCursor(QCursor(Qt::ArrowCursor));

ui->treePopularApps->clearSelection();
for (QTreeWidgetItemIterator it(ui->treePopularApps); (*it) != nullptr; ++it) {
(*it)->setCheckState(PopCol::Check, Qt::Unchecked);
}
return result;
}

Expand Down Expand Up @@ -2566,6 +2571,7 @@ void MainWindow::pushUninstall_clicked()
names += (*it)->data(PopCol::UninstallNames, Qt::UserRole).toString().replace('\n', ' ') + ' ';
postuninstall += (*it)->data(PopCol::PostUninstall, Qt::UserRole).toString() + '\n';
preuninstall += (*it)->data(PopCol::PreUninstall, Qt::UserRole).toString() + '\n';
(*it)->setCheckState(PopCol::Check, Qt::Unchecked);
}
}
} else if (currentTree == ui->treeFlatpak) {
Expand Down Expand Up @@ -2635,23 +2641,22 @@ void MainWindow::tabWidget_currentChanged(int index)
resetCheckboxes();
QString search_str;
saveSearchText(search_str, savedComboIndex);
setCurrentTree();
if (index != Tab::Output) {
setCurrentTree();
}
currentTree->blockSignals(true);

auto setTabsEnabled = [this](bool enable) {
for (auto tab : {Tab::Popular, Tab::EnabledRepos, Tab::Test, Tab::Backports, Tab::Flatpak}) {
if (tab != ui->tabWidget->currentIndex()) {
ui->tabWidget->setTabEnabled(tab, enable);
}
}
};

setTabsEnabled(false);
switch (index) {
case Tab::Popular: {
bool tempFlag = false;
handleTab(search_str, ui->searchPopular, "", tempFlag);
} break;
case Tab::Popular:
handleTab(search_str, ui->searchPopular, "", false);
break;
case Tab::EnabledRepos:
handleEnabledReposTab(search_str);
break;
Expand All @@ -2675,10 +2680,15 @@ void MainWindow::tabWidget_currentChanged(int index)
void MainWindow::resetCheckboxes()
{
currentTree->blockSignals(true);
// Popular apps are processed in a different way, tree is reset after install/removal
if (currentTree != ui->treePopularApps) {
currentTree->clearSelection();
for (QTreeWidgetItemIterator it(currentTree); (*it) != nullptr; ++it) {
(*it)->setCheckState(0, Qt::Unchecked);
(*it)->setCheckState(TreeCol::Check, Qt::Unchecked);
}
} else if (ui->tabWidget->currentIndex() != Tab::Output) { // Don't clear selections on output tab for pop apps
for (QTreeWidgetItemIterator it(ui->treePopularApps); (*it) != nullptr; ++it) {
(*it)->setCheckState(PopCol::Check, Qt::Unchecked);
}
}
}
Expand Down Expand Up @@ -2738,7 +2748,6 @@ void MainWindow::handleTab(const QString &search_str, QLineEdit *searchBox, cons
if (searchBox) {
searchBox->setText(search_str);
}
setCurrentTree();
if (!warningMessage.isEmpty()) {
displayWarning(warningMessage);
}
Expand All @@ -2757,9 +2766,7 @@ void MainWindow::handleTab(const QString &search_str, QLineEdit *searchBox, cons
ui->comboFilterBP->setCurrentIndex(savedComboIndex);
filterChanged(ui->comboFilterEnabled->currentText());
}
if (!search_str.isEmpty()) {
currentTree == ui->treePopularApps ? findPopular() : findPackage();
}
currentTree == ui->treePopularApps ? findPopular() : findPackage();
currentTree->blockSignals(false);
}

Expand Down Expand Up @@ -2857,10 +2864,17 @@ void MainWindow::installFlatpak()

void MainWindow::handleOutputTab()
{
ui->searchPopular->clear();
ui->searchBoxEnabled->clear();
ui->searchBoxMX->clear();
ui->searchBoxBP->clear();
// Block signals and clear all search boxes
const QList<QLineEdit *> searchBoxes
= {ui->searchPopular, ui->searchBoxEnabled, ui->searchBoxMX, ui->searchBoxBP, ui->searchBoxFlatpak};

for (auto searchBox : searchBoxes) {
searchBox->blockSignals(true);
searchBox->clear();
searchBox->blockSignals(false);
}

// Disable install/uninstall buttons
ui->pushInstall->setDisabled(true);
ui->pushUninstall->setDisabled(true);
}
Expand Down

0 comments on commit b61191e

Please sign in to comment.