Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: Replace some QApplication::processEvents() and QDialog::exec() #13876

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct EmuCallbacks
std::function<void()> on_resume;
std::function<void()> on_stop;
std::function<void()> on_ready;
std::function<bool()> on_missing_fw;
std::function<void()> on_missing_fw;
std::function<void(bool enabled)> enable_disc_eject;
std::function<void(bool enabled)> enable_disc_insert;
std::function<bool(bool, std::function<void()>)> try_to_quit; // (force_quit, on_exit) Try to close RPCS3
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/headless_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void headless_application::InitializeCallbacks()
callbacks.enable_disc_eject = [](bool) {};
callbacks.enable_disc_insert = [](bool) {};

callbacks.on_missing_fw = []() { return false; };
callbacks.on_missing_fw = []() {};

callbacks.handle_taskbar_progress = [](s32, s32) {};

Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/about_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
about_dialog::about_dialog(QWidget* parent) : QDialog(parent), ui(new Ui::about_dialog)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);

ui->close->setDefault(true);
ui->icon->load(QStringLiteral(":/rpcs3.svg"));
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/debugger_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void debugger_frame::open_breakpoints_settings()
hbox_layout->addWidget(button_ok);
dlg->setLayout(hbox_layout);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->exec();
dlg->open();
}

void debugger_frame::keyPressEvent(QKeyEvent* event)
Expand Down
211 changes: 104 additions & 107 deletions rpcs3/rpcs3qt/game_list_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,67 @@ bool game_list_frame::RemoveSPUCache(const std::string& base_dir, bool is_intera
return success;
}

void game_list_frame::BatchActionBySerials(progress_dialog* pdlg, const std::set<std::string>& serials, QString progressLabel, std::function<bool(const std::string&)> action, std::function<void(u32, u32)> cancel_log, bool refresh_on_finnish)
{
pdlg->setAutoClose(false);
pdlg->setAutoReset(false);
pdlg->setLabelText(progressLabel.arg(0).arg(serials.size()));
pdlg->show();

QTimer* timer = new QTimer(this);

auto iterate_over_serial = std::make_shared<std:function<bool()>>();

*iterate_over_serial = [=, this, performed = 0, index = 0]() mutable
{
if (index == serials.size())
{
return false;
}

const auto& serial *std::advance(serials.begin(), index++);

if (pdlg->wasCanceled())
{
cancel_log(performed, serials.size());
index = serials.size();
}
else if (action(serial))
{
pdlg->SetValue(++removed);
}

if (index == serials.size())
{
pdlg->setLabelText(progressLabel.arg(performed).arg(serials.size()));
pdlg->setCancelButtonText(tr("OK"));
QApplication::beep();

if (refresh_on_finnish && performed)
{
Refresh(true);
}

pdlg->deleteLater();
return false;
}

return true;
};

connect(timer, &QTimer::timeout, this, [timer, iterate_over_serial]()
{
if (!iterate_over_serial())
{
timer->stop();
timer->deleteLater();
}
});

// Invoked on the next event loop processing iteration
timer->start(0);
}

void game_list_frame::BatchCreatePPUCaches()
{
const std::string vsh_path = g_cfg_vfs.get_dev_flash() + "vsh/module/";
Expand Down Expand Up @@ -1940,6 +2001,7 @@ void game_list_frame::BatchRemovePPUCaches()
{
serials.emplace(game->info.serial);
}

const u32 total = ::size32(serials);

if (total == 0)
Expand All @@ -1948,30 +2010,17 @@ void game_list_frame::BatchRemovePPUCaches()
return;
}

progress_dialog* pdlg = new progress_dialog(tr("PPU Cache Batch Removal"), tr("Removing all PPU caches"), tr("Cancel"), 0, total, true, this);
pdlg->setAutoClose(false);
pdlg->setAutoReset(false);
pdlg->show();
progress_dialog* pdlg = new progress_dialog(tr("PPU Cache Batch Removal"), tr("Removing all PPU caches"), tr("Cancel"), 0, total, false, this);

u32 removed = 0;
for (const auto& serial : serials)
{
if (pdlg->wasCanceled())
BatchActionBySerials(pdlg, serials, tr("%0/%1 caches cleared"),
[](const std::string& serial)
{
game_list_log.notice("PPU Cache Batch Removal was canceled");
break;
}
QApplication::processEvents();

if (RemovePPUCache(GetCacheDirBySerial(serial)))
return RemovePPUCache(GetCacheDirBySerial(serial));
},
[](u32, u32)
{
pdlg->SetValue(++removed);
}
}

pdlg->setLabelText(tr("%0/%1 caches cleared").arg(removed).arg(total));
pdlg->setCancelButtonText(tr("OK"));
QApplication::beep();
game_list_log.notice("PPU Cache Batch Removal was canceled");
}, false);
}

void game_list_frame::BatchRemoveSPUCaches()
Expand All @@ -1981,6 +2030,7 @@ void game_list_frame::BatchRemoveSPUCaches()
{
serials.emplace(game->info.serial);
}

const u32 total = ::size32(serials);

if (total == 0)
Expand All @@ -1989,30 +2039,17 @@ void game_list_frame::BatchRemoveSPUCaches()
return;
}

progress_dialog* pdlg = new progress_dialog(tr("SPU Cache Batch Removal"), tr("Removing all SPU caches"), tr("Cancel"), 0, total, true, this);
pdlg->setAutoClose(false);
pdlg->setAutoReset(false);
pdlg->show();
progress_dialog* pdlg = new progress_dialog(tr("SPU Cache Batch Removal"), tr("Removing all SPU caches"), tr("Cancel"), 0, total, false, this);

u32 removed = 0;
for (const auto& serial : serials)
{
if (pdlg->wasCanceled())
BatchActionBySerials(pdlg, serials, tr("%0/%1 caches cleared"),
[](const std::string& serial)
{
game_list_log.notice("SPU Cache Batch Removal was canceled. %d/%d folders cleared", removed, total);
break;
}
QApplication::processEvents();

if (RemoveSPUCache(GetCacheDirBySerial(serial)))
return RemoveSPUCache(GetCacheDirBySerial(serial));
},
[](u32 removed, u32 total)
{
pdlg->SetValue(++removed);
}
}

pdlg->setLabelText(tr("%0/%1 caches cleared").arg(removed).arg(total));
pdlg->setCancelButtonText(tr("OK"));
QApplication::beep();
game_list_log.notice("SPU Cache Batch Removal was canceled. %d/%d folders cleared", removed, total);
}, false);
}

void game_list_frame::BatchRemoveCustomConfigurations()
Expand All @@ -2025,6 +2062,7 @@ void game_list_frame::BatchRemoveCustomConfigurations()
serials.emplace(game->info.serial);
}
}

const u32 total = ::size32(serials);

if (total == 0)
Expand All @@ -2033,31 +2071,17 @@ void game_list_frame::BatchRemoveCustomConfigurations()
return;
}

progress_dialog* pdlg = new progress_dialog(tr("Custom Configuration Batch Removal"), tr("Removing all custom configurations"), tr("Cancel"), 0, total, true, this);
pdlg->setAutoClose(false);
pdlg->setAutoReset(false);
pdlg->show();
progress_dialog* pdlg = new progress_dialog(tr("Custom Configuration Batch Removal"), tr("Removing all custom configurations"), tr("Cancel"), 0, total, false, this);

u32 removed = 0;
for (const auto& serial : serials)
{
if (pdlg->wasCanceled())
BatchActionBySerials(pdlg, serials, tr("%0/%1 custom configurations cleared"),
[](const std::string& serial)
{
game_list_log.notice("Custom Configuration Batch Removal was canceled. %d/%d custom configurations cleared", removed, total);
break;
}
QApplication::processEvents();

if (RemoveCustomConfiguration(serial))
return RemoveCustomConfiguration(serial);
},
[](u32 removed, u32 total)
{
pdlg->SetValue(++removed);
}
}

pdlg->setLabelText(tr("%0/%1 custom configurations cleared").arg(removed).arg(total));
pdlg->setCancelButtonText(tr("OK"));
QApplication::beep();
Refresh(true);
game_list_log.notice("Custom Configuration Batch Removal was canceled. %d/%d custom configurations cleared", removed, total);
}, true);
}

void game_list_frame::BatchRemoveCustomPadConfigurations()
Expand All @@ -2078,31 +2102,17 @@ void game_list_frame::BatchRemoveCustomPadConfigurations()
return;
}

progress_dialog* pdlg = new progress_dialog(tr("Custom Pad Configuration Batch Removal"), tr("Removing all custom pad configurations"), tr("Cancel"), 0, total, true, this);
pdlg->setAutoClose(false);
pdlg->setAutoReset(false);
pdlg->show();
progress_dialog* pdlg = new progress_dialog(tr("Custom Pad Configuration Batch Removal"), tr("Removing all custom pad configurations"), tr("Cancel"), 0, total, false, this);

u32 removed = 0;
for (const auto& serial : serials)
{
if (pdlg->wasCanceled())
BatchActionBySerials(pdlg, serials, tr("%0/%1 custom pad configurations cleared"),
Copy link
Contributor

@Megamouse Megamouse May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is all way too complex and detached from the reading flow.

Just create a (new QFutureWatcher(this)) and connect its resultReady signal to the pdlg::setValue.
Then connect the finish signal to deleteLater of QFutureWatcher and stuff.

This would keep the code contained in this function without too much overhead instead of having one huge complex thing a couple of hundred lines above

[](const std::string& serial)
{
game_list_log.notice("Custom Pad Configuration Batch Removal was canceled. %d/%d custom pad configurations cleared", removed, total);
break;
}
QApplication::processEvents();

if (RemoveCustomPadConfiguration(serial))
return RemoveCustomPadConfiguration(serial);
},
[](u32 removed, u32 total)
{
pdlg->SetValue(++removed);
}
}

pdlg->setLabelText(tr("%0/%1 custom pad configurations cleared").arg(removed).arg(total));
pdlg->setCancelButtonText(tr("OK"));
QApplication::beep();
Refresh(true);
game_list_log.notice("Custom Pad Configuration Batch Removal was canceled. %d/%d custom pad configurations cleared", removed, total);
}, true);
}

void game_list_frame::BatchRemoveShaderCaches()
Expand All @@ -2120,30 +2130,17 @@ void game_list_frame::BatchRemoveShaderCaches()
return;
}

progress_dialog* pdlg = new progress_dialog(tr("Shader Cache Batch Removal"), tr("Removing all shader caches"), tr("Cancel"), 0, total, true, this);
pdlg->setAutoClose(false);
pdlg->setAutoReset(false);
pdlg->show();
progress_dialog* pdlg = new progress_dialog(tr("Shader Cache Batch Removal"), tr("Removing all shader caches"), tr("Cancel"), 0, total, false, this);

u32 removed = 0;
for (const auto& serial : serials)
{
if (pdlg->wasCanceled())
BatchActionBySerials(pdlg, serials, tr("%0/%1 shader caches cleared"),
[](const std::string& serial)
{
game_list_log.notice("Shader Cache Batch Removal was canceled");
break;
}
QApplication::processEvents();

if (RemoveShadersCache(GetCacheDirBySerial(serial)))
return RemoveShadersCache(GetCacheDirBySerial(serial));
},
[](u32 removed, u32 total)
{
pdlg->SetValue(++removed);
}
}

pdlg->setLabelText(tr("%0/%1 shader caches cleared").arg(removed).arg(total));
pdlg->setCancelButtonText(tr("OK"));
QApplication::beep();
game_list_log.notice("Shader Cache Batch Removal was canceled. %d/%d cleared", removed, total);
}, false);
}

void game_list_frame::ShowCustomConfigIcon(const game_info& game)
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/game_list_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private Q_SLOTS:
static bool CreatePPUCache(const std::string& path, const std::string& serial = {});
static bool CreatePPUCache(const game_info& game);

void BatchActionBySerials(progress_dialog* pdlg, const std::set<std::string>& serials, QString progressLabel, std::function<bool(const std::string&)> action, std::function<void(u32, u32)> cancel_log, bool refresh_on_finnish);
static std::string GetCacheDirBySerial(const std::string& serial);
static std::string GetDataDirBySerial(const std::string& serial);
std::string CurrentSelectionPath();
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/log_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void log_viewer::show_context_menu(const QPoint& pos)
connect(config, &QAction::triggered, this, [this]()
{
config_checker* dlg = new config_checker(this, m_full_log, true);
dlg->exec();
dlg->open();
});

connect(filter, &QAction::triggered, this, [this]()
Expand Down
Loading