diff --git a/src/qt_common/qt_content_util.cpp b/src/qt_common/qt_content_util.cpp index 8ab72e331a..9072d455a7 100644 --- a/src/qt_common/qt_content_util.cpp +++ b/src/qt_common/qt_content_util.cpp @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later -#include "frontend_common/data_manager.h" #include "qt_content_util.h" #include "common/fs/fs.h" #include "core/hle/service/acc/profile_manager.h" #include "frontend_common/content_manager.h" +#include "frontend_common/data_manager.h" #include "frontend_common/firmware_manager.h" #include "qt_common/qt_common.h" #include "qt_common/qt_compress.h" @@ -389,10 +389,9 @@ void ExportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function< using namespace QtCommon::Frontend; const std::string dir = FrontendCommon::DataManager::GetDataDir(data_dir); - const QString zip_dump_location - = GetSaveFileName(tr("Select Export Location"), - QStringLiteral("export.zip"), - tr("Zipped Archives (*.zip)")); + const QString zip_dump_location = GetSaveFileName(tr("Select Export Location"), + QStringLiteral("export.zip"), + tr("Zipped Archives (*.zip)")); if (zip_dump_location.isEmpty()) return; @@ -407,13 +406,6 @@ void ExportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function< progress->setAutoReset(false); 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(); 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::finished, rootObject, [=]() { progress->close(); - if (was_cancelled) { - Information(tr("Export Cancelled"), - tr("Export was cancelled by the user.")); - } else if (watcher->result()) { - Information(tr("Exported Successfully"), - tr("Data was exported successfully.")); + if (watcher->result()) { + Information(tr("Exported Successfully"), tr("Data was exported successfully.")); + } else if (progress->wasCanceled()) { + Information(tr("Export Cancelled"), tr("Export was cancelled by the user.")); } else { Critical( tr("Export Failed"), @@ -450,11 +440,11 @@ void ExportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function< progress->deleteLater(); watcher->deleteLater(); - if (callback) callback(); + if (callback) + callback(); }); watcher->setFuture(future); - } void ImportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function callback) @@ -479,11 +469,8 @@ void ImportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function< if (button != QMessageBox::Yes) return; - QtProgressDialog* progress = new QtProgressDialog(tr("Importing data. This may take a while..."), - tr("Cancel"), - 0, - 100, - rootObject); + QtProgressDialog* progress = new QtProgressDialog( + tr("Importing data. This may take a while..."), tr("Cancel"), 0, 100, rootObject); progress->setWindowTitle(tr("Importing")); progress->setWindowModality(Qt::WindowModal); @@ -493,53 +480,57 @@ void ImportDataDir(FrontendCommon::DataManager::DataDir data_dir, std::function< progress->show(); 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(); - FrontendCommon::DataManager::ClearDir(data_dir); - - auto progress_callback = [=](size_t total_size, size_t processed_size) { - QMetaObject::invokeMethod(progress, - &QtProgressDialog::setValue, - static_cast((processed_size * 100) / total_size)); - + // to prevent GUI mangling we have to run this in a thread as well + QFuture delete_future = QtConcurrent::run([=]() { + FrontendCommon::DataManager::ClearDir(data_dir); return !progress->wasCanceled(); - }; - - QFuture future = QtConcurrent::run([=]() { - return !QtCommon::Compress::extractDir(zip_dump_location, - QString::fromStdString(dir), - progress_callback) - .empty(); }); - QFutureWatcher* watcher = new QFutureWatcher(rootObject); + QFutureWatcher* delete_watcher = new QFutureWatcher(rootObject); + delete_watcher->setFuture(delete_future); - QObject::connect(watcher, &QFutureWatcher::finished, rootObject, [=]() { - progress->close(); + QObject::connect(delete_watcher, &QFutureWatcher::finished, rootObject, [=]() { + auto progress_callback = [=](size_t total_size, size_t processed_size) { + QMetaObject::invokeMethod(progress, + &QtProgressDialog::setValue, + static_cast((processed_size * 100) / total_size)); - if (was_cancelled) { - Information(tr("Import Cancelled"), tr("Import was cancelled by the user.")); - } else if (watcher->result()) { - Information(tr("Imported Successfully"), tr("Data was imported successfully.")); - } else { - Critical( - tr("Import Failed"), - tr("Ensure you have read permissions on the targeted directory and try again.")); - } + return !progress->wasCanceled(); + }; - progress->deleteLater(); - watcher->deleteLater(); - if (callback) callback(); - }); + QFuture future = QtConcurrent::run([=]() { + return !QtCommon::Compress::extractDir(zip_dump_location, + QString::fromStdString(dir), + progress_callback) + .empty(); + }); + + QFutureWatcher* watcher = new QFutureWatcher(rootObject); + + QObject::connect(watcher, &QFutureWatcher::finished, rootObject, [=]() { + progress->close(); + + // this sucks + if (watcher->result()) { + 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 { + Critical(tr("Import Failed"), + tr("Ensure you have read permissions on the targeted directory and try " + "again.")); + } - watcher->setFuture(future); + progress->deleteLater(); + watcher->deleteLater(); + if (callback) + callback(); + }); + + watcher->setFuture(future); + }); } } // namespace QtCommon::Content diff --git a/src/yuzu/data_dialog.cpp b/src/yuzu/data_dialog.cpp index d7c937e7ed..a097a6f893 100644 --- a/src/yuzu/data_dialog.cpp +++ b/src/yuzu/data_dialog.cpp @@ -36,7 +36,12 @@ DataDialog::DataDialog(QWidget *parent) #undef WIDGET 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])); }); }