fix cancel/success mixup, list selector
Some checks failed
eden-license / license-header (pull_request) Failing after 24s

Signed-off-by: crueter <crueter@eden-emu.dev>
This commit is contained in:
crueter 2025-10-10 16:04:07 -04:00
parent cf77bcd60c
commit 47520c974d
Signed by: crueter
GPG key ID: 425ACD2D4830EBC6
2 changed files with 60 additions and 64 deletions

View file

@ -1,11 +1,11 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project // SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#include "frontend_common/data_manager.h"
#include "qt_content_util.h" #include "qt_content_util.h"
#include "common/fs/fs.h" #include "common/fs/fs.h"
#include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/acc/profile_manager.h"
#include "frontend_common/content_manager.h" #include "frontend_common/content_manager.h"
#include "frontend_common/data_manager.h"
#include "frontend_common/firmware_manager.h" #include "frontend_common/firmware_manager.h"
#include "qt_common/qt_common.h" #include "qt_common/qt_common.h"
#include "qt_common/qt_compress.h" #include "qt_common/qt_compress.h"
@ -389,8 +389,7 @@ void ExportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function<
using namespace QtCommon::Frontend; using namespace QtCommon::Frontend;
const std::string dir = FrontendCommon::DataManager::GetDataDir(data_dir); const std::string dir = FrontendCommon::DataManager::GetDataDir(data_dir);
const QString zip_dump_location const QString zip_dump_location = GetSaveFileName(tr("Select Export Location"),
= GetSaveFileName(tr("Select Export Location"),
QStringLiteral("export.zip"), QStringLiteral("export.zip"),
tr("Zipped Archives (*.zip)")); tr("Zipped Archives (*.zip)"));
@ -407,13 +406,6 @@ void ExportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function<
progress->setAutoReset(false); progress->setAutoReset(false);
progress->show(); progress->show();
// Qt's wasCanceled seems to be wonky
bool was_cancelled = false;
QObject::connect(progress, &QtProgressDialog::canceled, rootObject, [=]() mutable {
was_cancelled = false;
});
QGuiApplication::processEvents(); QGuiApplication::processEvents();
auto progress_callback = [=](size_t total_size, size_t processed_size) { auto progress_callback = [=](size_t total_size, size_t processed_size) {
@ -436,12 +428,10 @@ void ExportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function<
QObject::connect(watcher, &QFutureWatcher<bool>::finished, rootObject, [=]() { QObject::connect(watcher, &QFutureWatcher<bool>::finished, rootObject, [=]() {
progress->close(); progress->close();
if (was_cancelled) { if (watcher->result()) {
Information(tr("Export Cancelled"), Information(tr("Exported Successfully"), tr("Data was exported successfully."));
tr("Export was cancelled by the user.")); } else if (progress->wasCanceled()) {
} else if (watcher->result()) { Information(tr("Export Cancelled"), tr("Export was cancelled by the user."));
Information(tr("Exported Successfully"),
tr("Data was exported successfully."));
} else { } else {
Critical( Critical(
tr("Export Failed"), tr("Export Failed"),
@ -450,11 +440,11 @@ void ExportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function<
progress->deleteLater(); progress->deleteLater();
watcher->deleteLater(); watcher->deleteLater();
if (callback) callback(); if (callback)
callback();
}); });
watcher->setFuture(future); watcher->setFuture(future);
} }
void ImportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function<void()> callback) void ImportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function<void()> callback)
@ -479,11 +469,8 @@ void ImportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function<
if (button != QMessageBox::Yes) if (button != QMessageBox::Yes)
return; return;
QtProgressDialog* progress = new QtProgressDialog(tr("Importing data. This may take a while..."), QtProgressDialog* progress = new QtProgressDialog(
tr("Cancel"), tr("Importing data. This may take a while..."), tr("Cancel"), 0, 100, rootObject);
0,
100,
rootObject);
progress->setWindowTitle(tr("Importing")); progress->setWindowTitle(tr("Importing"));
progress->setWindowModality(Qt::WindowModal); progress->setWindowModality(Qt::WindowModal);
@ -493,17 +480,18 @@ void ImportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function<
progress->show(); progress->show();
progress->setValue(0); progress->setValue(0);
// Qt's wasCanceled seems to be wonky
bool was_cancelled = false;
QObject::connect(progress, &QtProgressDialog::canceled, rootObject, [=]() mutable {
was_cancelled = false;
});
QGuiApplication::processEvents(); QGuiApplication::processEvents();
// to prevent GUI mangling we have to run this in a thread as well
QFuture<bool> delete_future = QtConcurrent::run([=]() {
FrontendCommon::DataManager::ClearDir(data_dir); FrontendCommon::DataManager::ClearDir(data_dir);
return !progress->wasCanceled();
});
QFutureWatcher<bool>* delete_watcher = new QFutureWatcher<bool>(rootObject);
delete_watcher->setFuture(delete_future);
QObject::connect(delete_watcher, &QFutureWatcher<bool>::finished, rootObject, [=]() {
auto progress_callback = [=](size_t total_size, size_t processed_size) { auto progress_callback = [=](size_t total_size, size_t processed_size) {
QMetaObject::invokeMethod(progress, QMetaObject::invokeMethod(progress,
&QtProgressDialog::setValue, &QtProgressDialog::setValue,
@ -524,22 +512,25 @@ void ImportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function<
QObject::connect(watcher, &QFutureWatcher<bool>::finished, rootObject, [=]() { QObject::connect(watcher, &QFutureWatcher<bool>::finished, rootObject, [=]() {
progress->close(); progress->close();
if (was_cancelled) { // this sucks
Information(tr("Import Cancelled"), tr("Import was cancelled by the user.")); if (watcher->result()) {
} else if (watcher->result()) {
Information(tr("Imported Successfully"), tr("Data was imported successfully.")); Information(tr("Imported Successfully"), tr("Data was imported successfully."));
} else if (progress->wasCanceled()) {
Information(tr("Import Cancelled"), tr("Import was cancelled by the user."));
} else { } else {
Critical( Critical(tr("Import Failed"),
tr("Import Failed"), tr("Ensure you have read permissions on the targeted directory and try "
tr("Ensure you have read permissions on the targeted directory and try again.")); "again."));
} }
progress->deleteLater(); progress->deleteLater();
watcher->deleteLater(); watcher->deleteLater();
if (callback) callback(); if (callback)
callback();
}); });
watcher->setFuture(future); watcher->setFuture(future);
});
} }
} // namespace QtCommon::Content } // namespace QtCommon::Content

View file

@ -36,7 +36,12 @@ DataDialog::DataDialog(QWidget *parent)
#undef WIDGET #undef WIDGET
connect(ui->labels, &QListWidget::itemSelectionChanged, this, [this]() { connect(ui->labels, &QListWidget::itemSelectionChanged, this, [this]() {
ui->page->setCurrentIndex(ui->labels->currentRow()); const auto items = ui->labels->selectedItems();
if (items.isEmpty()) {
return;
}
ui->page->setCurrentIndex(ui->labels->row(items[0]));
}); });
} }