migrate callers of QMessageBox::question() to OffscreenUi::question()

This commit is contained in:
Brad Hefta-Gaub 2016-01-05 09:39:39 -08:00
parent 2b5956af99
commit d98c2d1413
6 changed files with 42 additions and 14 deletions

View file

@ -4373,7 +4373,7 @@ bool Application::askToSetAvatarUrl(const QString& url) {
bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
QMessageBox::StandardButton reply; QMessageBox::StandardButton reply;
QString message = "Would you like to run this script:\n" + scriptFilenameOrURL; QString message = "Would you like to run this script:\n" + scriptFilenameOrURL;
reply = QMessageBox::question(getWindow(), "Run Script", message, QMessageBox::Yes|QMessageBox::No); reply = OffscreenUi::question(getWindow(), "Run Script", message, QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) { if (reply == QMessageBox::Yes) {
qCDebug(interfaceapp) << "Chose to run the script: " << scriptFilenameOrURL; qCDebug(interfaceapp) << "Chose to run the script: " << scriptFilenameOrURL;

View file

@ -25,6 +25,7 @@
#include <AssetUpload.h> #include <AssetUpload.h>
#include <ResourceManager.h> #include <ResourceManager.h>
#include "OffscreenUi.h"
#include "../ui/AssetUploadDialogFactory.h" #include "../ui/AssetUploadDialogFactory.h"
Q_DECLARE_LOGGING_CATEGORY(asset_migrator); Q_DECLARE_LOGGING_CATEGORY(asset_migrator);
@ -52,7 +53,7 @@ void ATPAssetMigrator::loadEntityServerFile() {
" continue?\n\nMake sure you are connected to the right domain." " continue?\n\nMake sure you are connected to the right domain."
}; };
auto button = QMessageBox::question(_dialogParent, MESSAGE_BOX_TITLE, MIGRATION_CONFIRMATION_TEXT, auto button = OffscreenUi::question(_dialogParent, MESSAGE_BOX_TITLE, MIGRATION_CONFIRMATION_TEXT,
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (button == QMessageBox::No) { if (button == QMessageBox::No) {
@ -212,7 +213,7 @@ bool ATPAssetMigrator::wantsToMigrateResource(const QUrl& url) {
"Select \"No\" to be prompted for each discovered asset." "Select \"No\" to be prompted for each discovered asset."
}; };
auto button = QMessageBox::question(_dialogParent, MESSAGE_BOX_TITLE, COMPLETE_MIGRATION_TEXT, auto button = OffscreenUi::question(_dialogParent, MESSAGE_BOX_TITLE, COMPLETE_MIGRATION_TEXT,
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (button == QMessageBox::Yes) { if (button == QMessageBox::Yes) {
@ -226,7 +227,7 @@ bool ATPAssetMigrator::wantsToMigrateResource(const QUrl& url) {
return true; return true;
} else { } else {
// present a dialog asking the user if they want to migrate this specific resource // present a dialog asking the user if they want to migrate this specific resource
auto button = QMessageBox::question(_dialogParent, MESSAGE_BOX_TITLE, auto button = OffscreenUi::question(_dialogParent, MESSAGE_BOX_TITLE,
"Would you like to migrate the following resource?\n" + url.toString(), "Would you like to migrate the following resource?\n" + url.toString(),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
return button == QMessageBox::Yes; return button == QMessageBox::Yes;

View file

@ -167,14 +167,9 @@ QScriptValue WindowScriptingInterface::showAlert(const QString& message) {
/// \return QScriptValue `true` if 'Yes' was clicked, `false` otherwise /// \return QScriptValue `true` if 'Yes' was clicked, `false` otherwise
QScriptValue WindowScriptingInterface::showConfirm(const QString& message) { QScriptValue WindowScriptingInterface::showConfirm(const QString& message) {
bool confirm = false; bool confirm = false;
bool waiting = true;
OffscreenUi::question("", message, [&](QMessageBox::StandardButton response){ OffscreenUi::question("", message, [&](QMessageBox::StandardButton response){
confirm = (response == QMessageBox::Yes); confirm = (response == QMessageBox::Yes);
waiting = false;
}); });
while (waiting) {
QCoreApplication::processEvents();
}
return QScriptValue(confirm); return QScriptValue(confirm);
} }

View file

@ -22,6 +22,7 @@
#include <NetworkAccessManager.h> #include <NetworkAccessManager.h>
#include "DiskCacheEditor.h" #include "DiskCacheEditor.h"
#include "OffscreenUi.h"
DiskCacheEditor::DiskCacheEditor(QWidget* parent) : QObject(parent) { DiskCacheEditor::DiskCacheEditor(QWidget* parent) : QObject(parent) {
@ -136,7 +137,7 @@ void DiskCacheEditor::refresh() {
void DiskCacheEditor::clear() { void DiskCacheEditor::clear() {
QMessageBox::StandardButton buttonClicked = QMessageBox::StandardButton buttonClicked =
QMessageBox::question(_dialog, "Clearing disk cache", OffscreenUi::question(_dialog, "Clearing disk cache",
"You are about to erase all the content of the disk cache," "You are about to erase all the content of the disk cache,"
"are you sure you want to do that?"); "are you sure you want to do that?");
if (buttonClicked == QMessageBox::Yes) { if (buttonClicked == QMessageBox::Yes) {

View file

@ -174,12 +174,37 @@ void OffscreenUi::information(const QString& title, const QString& text,
} }
void OffscreenUi::question(const QString& title, const QString& text, void OffscreenUi::question(const QString& title, const QString& text,
ButtonCallback callback, ButtonCallback callback,
QMessageBox::StandardButtons buttons) { QMessageBox::StandardButtons buttons) {
messageBox(title, text, callback,
static_cast<QMessageBox::Icon>(MessageDialog::Question), buttons); bool waiting = true;
ButtonCallback blockingCallback = [&](QMessageBox::StandardButton response){
callback(response); // call the actual callback
waiting = false;
};
messageBox(title, text, blockingCallback,
static_cast<QMessageBox::Icon>(MessageDialog::Question), buttons);
// block until the call back has been called
while (waiting) {
QCoreApplication::processEvents();
}
} }
QMessageBox::StandardButton OffscreenUi::question(void* ignored, const QString& title, const QString& text,
QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
QMessageBox::StandardButton result = defaultButton;
OffscreenUi::question(title, text, [&](QMessageBox::StandardButton response){
result = response;
}, buttons);
return result;
}
void OffscreenUi::warning(const QString& title, const QString& text, void OffscreenUi::warning(const QString& title, const QString& text,
ButtonCallback callback, ButtonCallback callback,
QMessageBox::StandardButtons buttons) { QMessageBox::StandardButtons buttons) {

View file

@ -45,10 +45,16 @@ public:
ButtonCallback callback = NO_OP_CALLBACK, ButtonCallback callback = NO_OP_CALLBACK,
QMessageBox::StandardButtons buttons = QMessageBox::Ok); QMessageBox::StandardButtons buttons = QMessageBox::Ok);
/// Note: will block until user clicks a response to the question
static void question(const QString& title, const QString& text, static void question(const QString& title, const QString& text,
ButtonCallback callback = NO_OP_CALLBACK, ButtonCallback callback = NO_OP_CALLBACK,
QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No)); QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No));
/// Same design as QMessageBox::question(), will block, returns result
static QMessageBox::StandardButton question(void* ignored, const QString& title, const QString& text,
QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No),
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
static void warning(const QString& title, const QString& text, static void warning(const QString& title, const QString& text,
ButtonCallback callback = NO_OP_CALLBACK, ButtonCallback callback = NO_OP_CALLBACK,
QMessageBox::StandardButtons buttons = QMessageBox::Ok); QMessageBox::StandardButtons buttons = QMessageBox::Ok);