From 2b5956af99544d72cc1052a80c6a4c2da33c150d Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Mon, 4 Jan 2016 13:57:36 -0800 Subject: [PATCH 1/3] move alert and confirm to use offscreen ui --- .../src/scripting/WindowScriptingInterface.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 0bf94f02a9..bd1fbde385 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -21,6 +21,7 @@ #include "DomainHandler.h" #include "MainWindow.h" #include "Menu.h" +#include "OffscreenUi.h" #include "ui/ModelsBrowser.h" #include "WindowScriptingInterface.h" @@ -153,12 +154,11 @@ QScriptValue WindowScriptingInterface::peekNonBlockingFormResult(QScriptValue fo return retVal; } - /// Display an alert box /// \param const QString& message message to display /// \return QScriptValue::UndefinedValue QScriptValue WindowScriptingInterface::showAlert(const QString& message) { - QMessageBox::warning(qApp->getWindow(), "", message); + OffscreenUi::warning("", message); return QScriptValue::UndefinedValue; } @@ -166,8 +166,16 @@ QScriptValue WindowScriptingInterface::showAlert(const QString& message) { /// \param const QString& message message to display /// \return QScriptValue `true` if 'Yes' was clicked, `false` otherwise QScriptValue WindowScriptingInterface::showConfirm(const QString& message) { - QMessageBox::StandardButton response = QMessageBox::question(qApp->getWindow(), "", message); - return QScriptValue(response == QMessageBox::Yes); + bool confirm = false; + bool waiting = true; + OffscreenUi::question("", message, [&](QMessageBox::StandardButton response){ + confirm = (response == QMessageBox::Yes); + waiting = false; + }); + while (waiting) { + QCoreApplication::processEvents(); + } + return QScriptValue(confirm); } void WindowScriptingInterface::chooseDirectory() { @@ -597,7 +605,6 @@ QScriptValue WindowScriptingInterface::showPrompt(const QString& message, const if (promptDialog.exec() == QDialog::Accepted) { return QScriptValue(promptDialog.textValue()); } - return QScriptValue::NullValue; } From d98c2d14130e6d53f73e8f1937290ab854c74afe Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 5 Jan 2016 09:39:39 -0800 Subject: [PATCH 2/3] migrate callers of QMessageBox::question() to OffscreenUi::question() --- interface/src/Application.cpp | 2 +- interface/src/assets/ATPAssetMigrator.cpp | 7 ++-- .../scripting/WindowScriptingInterface.cpp | 5 --- interface/src/ui/DiskCacheEditor.cpp | 3 +- libraries/ui/src/OffscreenUi.cpp | 33 ++++++++++++++++--- libraries/ui/src/OffscreenUi.h | 6 ++++ 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 608f4cd388..15aa7fa972 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4373,7 +4373,7 @@ bool Application::askToSetAvatarUrl(const QString& url) { bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { QMessageBox::StandardButton reply; 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) { qCDebug(interfaceapp) << "Chose to run the script: " << scriptFilenameOrURL; diff --git a/interface/src/assets/ATPAssetMigrator.cpp b/interface/src/assets/ATPAssetMigrator.cpp index fadf4ca7ad..4aa069f920 100644 --- a/interface/src/assets/ATPAssetMigrator.cpp +++ b/interface/src/assets/ATPAssetMigrator.cpp @@ -25,6 +25,7 @@ #include #include +#include "OffscreenUi.h" #include "../ui/AssetUploadDialogFactory.h" Q_DECLARE_LOGGING_CATEGORY(asset_migrator); @@ -52,7 +53,7 @@ void ATPAssetMigrator::loadEntityServerFile() { " 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); if (button == QMessageBox::No) { @@ -212,7 +213,7 @@ bool ATPAssetMigrator::wantsToMigrateResource(const QUrl& url) { "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); if (button == QMessageBox::Yes) { @@ -226,7 +227,7 @@ bool ATPAssetMigrator::wantsToMigrateResource(const QUrl& url) { return true; } else { // 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(), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); return button == QMessageBox::Yes; diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index bd1fbde385..977832fdd5 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -167,14 +167,9 @@ QScriptValue WindowScriptingInterface::showAlert(const QString& message) { /// \return QScriptValue `true` if 'Yes' was clicked, `false` otherwise QScriptValue WindowScriptingInterface::showConfirm(const QString& message) { bool confirm = false; - bool waiting = true; OffscreenUi::question("", message, [&](QMessageBox::StandardButton response){ confirm = (response == QMessageBox::Yes); - waiting = false; }); - while (waiting) { - QCoreApplication::processEvents(); - } return QScriptValue(confirm); } diff --git a/interface/src/ui/DiskCacheEditor.cpp b/interface/src/ui/DiskCacheEditor.cpp index a33f28e240..62917007d3 100644 --- a/interface/src/ui/DiskCacheEditor.cpp +++ b/interface/src/ui/DiskCacheEditor.cpp @@ -22,6 +22,7 @@ #include #include "DiskCacheEditor.h" +#include "OffscreenUi.h" DiskCacheEditor::DiskCacheEditor(QWidget* parent) : QObject(parent) { @@ -136,7 +137,7 @@ void DiskCacheEditor::refresh() { void DiskCacheEditor::clear() { 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," "are you sure you want to do that?"); if (buttonClicked == QMessageBox::Yes) { diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index db5a9a6009..fc298fd36f 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -174,12 +174,37 @@ void OffscreenUi::information(const QString& title, const QString& text, } void OffscreenUi::question(const QString& title, const QString& text, - ButtonCallback callback, - QMessageBox::StandardButtons buttons) { - messageBox(title, text, callback, - static_cast(MessageDialog::Question), buttons); + ButtonCallback callback, + QMessageBox::StandardButtons buttons) { + + bool waiting = true; + ButtonCallback blockingCallback = [&](QMessageBox::StandardButton response){ + callback(response); // call the actual callback + waiting = false; + }; + + messageBox(title, text, blockingCallback, + static_cast(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, ButtonCallback callback, QMessageBox::StandardButtons buttons) { diff --git a/libraries/ui/src/OffscreenUi.h b/libraries/ui/src/OffscreenUi.h index d6845c1d37..4650e6b39e 100644 --- a/libraries/ui/src/OffscreenUi.h +++ b/libraries/ui/src/OffscreenUi.h @@ -45,10 +45,16 @@ public: ButtonCallback callback = NO_OP_CALLBACK, 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, ButtonCallback callback = NO_OP_CALLBACK, 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, ButtonCallback callback = NO_OP_CALLBACK, QMessageBox::StandardButtons buttons = QMessageBox::Ok); From 927fe97359c9141ccfc12d75071a1c52dea225ce Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 5 Jan 2016 10:17:16 -0800 Subject: [PATCH 3/3] migrate callers of QMessageBox::warning() to OffscreenUi::warning() --- interface/src/Application.cpp | 7 ++++--- interface/src/ModelPackager.cpp | 7 ++++--- interface/src/ModelPropertiesDialog.cpp | 3 ++- interface/src/assets/ATPAssetMigrator.cpp | 12 +++++------ interface/src/devices/EyeTracker.cpp | 8 ++++---- .../scripting/WindowScriptingInterface.cpp | 2 +- interface/src/ui/AssetUploadDialogFactory.cpp | 3 ++- interface/src/ui/ScriptEditorWidget.cpp | 9 +++++---- interface/src/ui/SnapshotShareDialog.cpp | 7 ++++--- libraries/ui/src/OffscreenUi.cpp | 20 +++++++++++++++++++ libraries/ui/src/OffscreenUi.h | 5 +++++ 11 files changed, 57 insertions(+), 26 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 15aa7fa972..ed77c37df5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -86,6 +86,7 @@ #include #include #include +#include #include #include #include @@ -4386,7 +4387,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { bool Application::askToUploadAsset(const QString& filename) { if (!DependencyManager::get()->getThisNodeCanRez()) { - QMessageBox::warning(_window, "Failed Upload", + OffscreenUi::warning(_window, "Failed Upload", QString("You don't have upload rights on that domain.\n\n")); return false; } @@ -4430,7 +4431,7 @@ bool Application::askToUploadAsset(const QString& filename) { } // display a message box with the error - QMessageBox::warning(_window, "Failed Upload", QString("Failed to upload %1.\n\n").arg(filename)); + OffscreenUi::warning(_window, "Failed Upload", QString("Failed to upload %1.\n\n").arg(filename)); return false; } @@ -4528,7 +4529,7 @@ void Application::handleScriptEngineLoaded(const QString& scriptFilename) { // FIXME - change to new version of ScriptCache loading notification void Application::handleScriptLoadError(const QString& scriptFilename) { qCDebug(interfaceapp) << "Application::loadScript(), script failed to load..."; - QMessageBox::warning(getWindow(), "Error Loading Script", scriptFilename + " failed to load."); + OffscreenUi::warning(getWindow(), "Error Loading Script", scriptFilename + " failed to load."); } QStringList Application::getRunningScripts() { diff --git a/interface/src/ModelPackager.cpp b/interface/src/ModelPackager.cpp index 35be11f2bb..64ab76c64c 100644 --- a/interface/src/ModelPackager.cpp +++ b/interface/src/ModelPackager.cpp @@ -15,6 +15,7 @@ #include #include +#include #include "ModelSelector.h" #include "ModelPropertiesDialog.h" @@ -78,7 +79,7 @@ bool ModelPackager::loadModel() { if (_modelFile.completeSuffix().contains("fst")) { QFile fst(_modelFile.filePath()); if (!fst.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::warning(NULL, + OffscreenUi::warning(NULL, QString("ModelPackager::loadModel()"), QString("Could not open FST file %1").arg(_modelFile.filePath()), QMessageBox::Ok); @@ -97,7 +98,7 @@ bool ModelPackager::loadModel() { // open the fbx file QFile fbx(_fbxInfo.filePath()); if (!_fbxInfo.exists() || !_fbxInfo.isFile() || !fbx.open(QIODevice::ReadOnly)) { - QMessageBox::warning(NULL, + OffscreenUi::warning(NULL, QString("ModelPackager::loadModel()"), QString("Could not open FBX file %1").arg(_fbxInfo.filePath()), QMessageBox::Ok); @@ -402,7 +403,7 @@ bool ModelPackager::copyTextures(const QString& oldDir, const QDir& newDir) { } if (!errors.isEmpty()) { - QMessageBox::warning(nullptr, "ModelPackager::copyTextures()", + OffscreenUi::warning(nullptr, "ModelPackager::copyTextures()", "Missing textures:" + errors); qCDebug(interfaceapp) << "ModelPackager::copyTextures():" << errors; return false; diff --git a/interface/src/ModelPropertiesDialog.cpp b/interface/src/ModelPropertiesDialog.cpp index 8e0541518a..d41a913c95 100644 --- a/interface/src/ModelPropertiesDialog.cpp +++ b/interface/src/ModelPropertiesDialog.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "ModelPropertiesDialog.h" @@ -200,7 +201,7 @@ void ModelPropertiesDialog::chooseTextureDirectory() { return; } if (!directory.startsWith(_basePath)) { - QMessageBox::warning(NULL, "Invalid texture directory", "Texture directory must be child of base path."); + OffscreenUi::warning(NULL, "Invalid texture directory", "Texture directory must be child of base path."); return; } _textureDirectory->setText(directory.length() == _basePath.length() ? "." : directory.mid(_basePath.length() + 1)); diff --git a/interface/src/assets/ATPAssetMigrator.cpp b/interface/src/assets/ATPAssetMigrator.cpp index 4aa069f920..f037cf9f91 100644 --- a/interface/src/assets/ATPAssetMigrator.cpp +++ b/interface/src/assets/ATPAssetMigrator.cpp @@ -68,7 +68,7 @@ void ATPAssetMigrator::loadEntityServerFile() { QByteArray jsonData; if (!gunzip(compressedJsonData, jsonData)) { - QMessageBox::warning(_dialogParent, "Error", "The file at" + filename + "was not in gzip format."); + OffscreenUi::warning(_dialogParent, "Error", "The file at" + filename + "was not in gzip format."); } QJsonDocument modelsJSON = QJsonDocument::fromJson(jsonData); @@ -108,7 +108,7 @@ void ATPAssetMigrator::loadEntityServerFile() { if (request->getResult() == ResourceRequest::Success) { migrateResource(request); } else { - QMessageBox::warning(_dialogParent, "Error", + OffscreenUi::warning(_dialogParent, "Error", QString("Could not retrieve asset at %1").arg(modelURL.toString())); } request->deleteLater(); @@ -116,7 +116,7 @@ void ATPAssetMigrator::loadEntityServerFile() { request->send(); } else { - QMessageBox::warning(_dialogParent, "Error", + OffscreenUi::warning(_dialogParent, "Error", QString("Could not create request for asset at %1").arg(modelURL.toString())); } @@ -130,7 +130,7 @@ void ATPAssetMigrator::loadEntityServerFile() { _doneReading = true; } else { - QMessageBox::warning(_dialogParent, "Error", + OffscreenUi::warning(_dialogParent, "Error", "There was a problem loading that entity-server file for ATP asset migration. Please try again"); } } @@ -255,11 +255,11 @@ void ATPAssetMigrator::saveEntityServerFile() { QMessageBox::information(_dialogParent, "Success", QString("Your new entities file has been saved at %1").arg(saveName)); } else { - QMessageBox::warning(_dialogParent, "Error", "Could not gzip JSON data for new entities file."); + OffscreenUi::warning(_dialogParent, "Error", "Could not gzip JSON data for new entities file."); } } else { - QMessageBox::warning(_dialogParent, "Error", + OffscreenUi::warning(_dialogParent, "Error", QString("Could not open file at %1 to write new entities file to.").arg(saveName)); } } diff --git a/interface/src/devices/EyeTracker.cpp b/interface/src/devices/EyeTracker.cpp index 2cfc2ecd75..367aa52aae 100644 --- a/interface/src/devices/EyeTracker.cpp +++ b/interface/src/devices/EyeTracker.cpp @@ -139,7 +139,7 @@ void EyeTracker::onStreamStarted() { qCWarning(interfaceapp) << "Eye Tracker: Error starting streaming:" << smiReturnValueToString(result); // Display error dialog unless SMI SDK has already displayed an error message. if (result != SMI_ERROR_HMD_NOT_SUPPORTED) { - QMessageBox::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result)); + OffscreenUi::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result)); } } else { qCDebug(interfaceapp) << "Eye Tracker: Started streaming"; @@ -152,7 +152,7 @@ void EyeTracker::onStreamStarted() { result = smi_loadCalibration(HIGH_FIDELITY_EYE_TRACKER_CALIBRATION); if (result != SMI_RET_SUCCESS) { qCWarning(interfaceapp) << "Eye Tracker: Error loading calibration:" << smiReturnValueToString(result); - QMessageBox::warning(nullptr, "Eye Tracker Error", "Error loading calibration" + OffscreenUi::warning(nullptr, "Eye Tracker Error", "Error loading calibration" + smiReturnValueToString(result)); } else { qCDebug(interfaceapp) << "Eye Tracker: Loaded calibration"; @@ -168,7 +168,7 @@ void EyeTracker::setEnabled(bool enabled, bool simulate) { int result = smi_setCallback(eyeTrackerCallback); if (result != SMI_RET_SUCCESS) { qCWarning(interfaceapp) << "Eye Tracker: Error setting callback:" << smiReturnValueToString(result); - QMessageBox::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result)); + OffscreenUi::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result)); } else { _isInitialized = true; } @@ -273,7 +273,7 @@ void EyeTracker::calibrate(int points) { } if (result != SMI_RET_SUCCESS) { - QMessageBox::warning(nullptr, "Eye Tracker Error", "Calibration error: " + smiReturnValueToString(result)); + OffscreenUi::warning(nullptr, "Eye Tracker Error", "Calibration error: " + smiReturnValueToString(result)); } } #endif diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 977832fdd5..fe84f36158 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -188,7 +188,7 @@ void WindowScriptingInterface::chooseDirectory() { } if (!validateAs.exactMatch(directory)) { - QMessageBox::warning(NULL, "Invalid Directory", errorMessage); + OffscreenUi::warning(NULL, "Invalid Directory", errorMessage); return; } diff --git a/interface/src/ui/AssetUploadDialogFactory.cpp b/interface/src/ui/AssetUploadDialogFactory.cpp index 66f72e5b5c..9cd319815b 100644 --- a/interface/src/ui/AssetUploadDialogFactory.cpp +++ b/interface/src/ui/AssetUploadDialogFactory.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include AssetUploadDialogFactory& AssetUploadDialogFactory::getInstance() { @@ -146,5 +147,5 @@ void AssetUploadDialogFactory::showErrorDialog(AssetUpload* upload, QWidget* dia dialogMessage += errorMessage; - QMessageBox::warning(dialogParent, "Failed Upload", dialogMessage); + OffscreenUi::warning(dialogParent, "Failed Upload", dialogMessage); } diff --git a/interface/src/ui/ScriptEditorWidget.cpp b/interface/src/ui/ScriptEditorWidget.cpp index 0ae13f9c24..380b645681 100644 --- a/interface/src/ui/ScriptEditorWidget.cpp +++ b/interface/src/ui/ScriptEditorWidget.cpp @@ -26,6 +26,7 @@ #include #include +#include #include "Application.h" #include "ScriptHighlighting.h" @@ -120,7 +121,7 @@ bool ScriptEditorWidget::setRunning(bool run) { bool ScriptEditorWidget::saveFile(const QString &scriptPath) { QFile file(scriptPath); if (!file.open(QFile::WriteOnly | QFile::Text)) { - QMessageBox::warning(this, tr("Interface"), tr("Cannot write script %1:\n%2.").arg(scriptPath) + OffscreenUi::warning(this, tr("Interface"), tr("Cannot write script %1:\n%2.").arg(scriptPath) .arg(file.errorString())); return false; } @@ -141,7 +142,7 @@ void ScriptEditorWidget::loadFile(const QString& scriptPath) { if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) { QFile file(scriptPath); if (!file.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::warning(this, tr("Interface"), tr("Cannot read script %1:\n%2.").arg(scriptPath) + OffscreenUi::warning(this, tr("Interface"), tr("Cannot read script %1:\n%2.").arg(scriptPath) .arg(file.errorString())); return; } @@ -208,7 +209,7 @@ void ScriptEditorWidget::setScriptFile(const QString& scriptPath) { bool ScriptEditorWidget::questionSave() { if (_scriptEditorWidgetUI->scriptEdit->document()->isModified()) { - QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Interface"), + QMessageBox::StandardButton button = OffscreenUi::warning(this, tr("Interface"), tr("The script has been modified.\nDo you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); return button == QMessageBox::Save ? save() : (button == QMessageBox::Discard); @@ -222,7 +223,7 @@ void ScriptEditorWidget::onWindowActivated() { if (QFileInfo(_currentScript).lastModified() > _currentScriptModified) { if (static_cast(this->parent()->parent()->parent())->autoReloadScripts() - || QMessageBox::warning(this, _currentScript, + || OffscreenUi::warning(this, _currentScript, tr("This file has been modified outside of the Interface editor.") + "\n\n" + (isModified() ? tr("Do you want to reload it and lose the changes you've made in the Interface editor?") diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index 3053c3ee0a..ddebfe25fd 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -20,6 +20,7 @@ #include #include +#include const int NARROW_SNAPSHOT_DIALOG_SIZE = 500; const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650; @@ -87,7 +88,7 @@ void SnapshotShareDialog::accept() { void SnapshotShareDialog::uploadSnapshot() { if (AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().isEmpty()) { - QMessageBox::warning(this, "", + OffscreenUi::warning(this, "", "Your Discourse API key is missing, you cannot share snapshots. Please try to relog."); return; } @@ -178,7 +179,7 @@ void SnapshotShareDialog::postRequestFinished() { errorMessage = errorArray.first().toString(); } } - QMessageBox::warning(this, "", errorMessage); + OffscreenUi::warning(this, "", errorMessage); _ui.shareButton->setEnabled(true); _ui.shareButton->setStyleSheet(SHARE_BUTTON_STYLE + SHARE_BUTTON_ENABLED_STYLE); } @@ -193,7 +194,7 @@ void SnapshotShareDialog::uploadRequestFinished() { if (responseObject.contains("url")) { sendForumPost(responseObject["url"].toString()); } else { - QMessageBox::warning(this, "", SHARE_DEFAULT_ERROR); + OffscreenUi::warning(this, "", SHARE_DEFAULT_ERROR); _ui.shareButton->setEnabled(true); _ui.shareButton->setStyleSheet(SHARE_BUTTON_STYLE + SHARE_BUTTON_ENABLED_STYLE); } diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index fc298fd36f..67e6b089d6 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -212,6 +212,26 @@ void OffscreenUi::warning(const QString& title, const QString& text, static_cast(MessageDialog::Warning), buttons); } +QMessageBox::StandardButton OffscreenUi::warning(void* ignored, const QString& title, const QString& text, + QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) { + + bool waiting = true; + QMessageBox::StandardButton result = defaultButton; + + OffscreenUi::warning(title, text, [&](QMessageBox::StandardButton response){ + result = response; + waiting = false; + }, buttons); + + // block until the call back has been called + while (waiting) { + QCoreApplication::processEvents(); + } + + return result; +} + + void OffscreenUi::critical(const QString& title, const QString& text, ButtonCallback callback, QMessageBox::StandardButtons buttons) { diff --git a/libraries/ui/src/OffscreenUi.h b/libraries/ui/src/OffscreenUi.h index 4650e6b39e..7063d25279 100644 --- a/libraries/ui/src/OffscreenUi.h +++ b/libraries/ui/src/OffscreenUi.h @@ -59,6 +59,11 @@ public: ButtonCallback callback = NO_OP_CALLBACK, QMessageBox::StandardButtons buttons = QMessageBox::Ok); + /// Same design as QMessageBox::warning(), will block, returns result + static QMessageBox::StandardButton warning(void* ignored, const QString& title, const QString& text, + QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No), + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); + static void critical(const QString& title, const QString& text, ButtonCallback callback = NO_OP_CALLBACK, QMessageBox::StandardButtons buttons = QMessageBox::Ok);