Merge pull request #6763 from ZappoMan/scriptMessageBoxesOffscreen

move alert and confirm to use offscreen ui
This commit is contained in:
Brad Davis 2016-01-05 15:26:48 -05:00
commit 908c1072ce
12 changed files with 106 additions and 40 deletions

View file

@ -88,6 +88,7 @@
#include <ObjectMotionState.h> #include <ObjectMotionState.h>
#include <OctalCode.h> #include <OctalCode.h>
#include <OctreeSceneStats.h> #include <OctreeSceneStats.h>
#include <OffscreenUi.h>
#include <gl/OffscreenGLCanvas.h> #include <gl/OffscreenGLCanvas.h>
#include <PathUtils.h> #include <PathUtils.h>
#include <PerfStat.h> #include <PerfStat.h>
@ -4380,7 +4381,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;
@ -4393,7 +4394,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
bool Application::askToUploadAsset(const QString& filename) { bool Application::askToUploadAsset(const QString& filename) {
if (!DependencyManager::get<NodeList>()->getThisNodeCanRez()) { if (!DependencyManager::get<NodeList>()->getThisNodeCanRez()) {
QMessageBox::warning(_window, "Failed Upload", OffscreenUi::warning(_window, "Failed Upload",
QString("You don't have upload rights on that domain.\n\n")); QString("You don't have upload rights on that domain.\n\n"));
return false; return false;
} }
@ -4437,7 +4438,7 @@ bool Application::askToUploadAsset(const QString& filename) {
} }
// display a message box with the error // 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; return false;
} }
@ -4628,7 +4629,7 @@ void Application::handleScriptEngineLoaded(const QString& scriptFilename) {
// FIXME - change to new version of ScriptCache loading notification // FIXME - change to new version of ScriptCache loading notification
void Application::handleScriptLoadError(const QString& scriptFilename) { void Application::handleScriptLoadError(const QString& scriptFilename) {
qCDebug(interfaceapp) << "Application::loadScript(), script failed to load..."; 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() { QStringList Application::getRunningScripts() {

View file

@ -15,6 +15,7 @@
#include <QTemporaryDir> #include <QTemporaryDir>
#include <FSTReader.h> #include <FSTReader.h>
#include <OffscreenUi.h>
#include "ModelSelector.h" #include "ModelSelector.h"
#include "ModelPropertiesDialog.h" #include "ModelPropertiesDialog.h"
@ -78,7 +79,7 @@ bool ModelPackager::loadModel() {
if (_modelFile.completeSuffix().contains("fst")) { if (_modelFile.completeSuffix().contains("fst")) {
QFile fst(_modelFile.filePath()); QFile fst(_modelFile.filePath());
if (!fst.open(QFile::ReadOnly | QFile::Text)) { if (!fst.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(NULL, OffscreenUi::warning(NULL,
QString("ModelPackager::loadModel()"), QString("ModelPackager::loadModel()"),
QString("Could not open FST file %1").arg(_modelFile.filePath()), QString("Could not open FST file %1").arg(_modelFile.filePath()),
QMessageBox::Ok); QMessageBox::Ok);
@ -97,7 +98,7 @@ bool ModelPackager::loadModel() {
// open the fbx file // open the fbx file
QFile fbx(_fbxInfo.filePath()); QFile fbx(_fbxInfo.filePath());
if (!_fbxInfo.exists() || !_fbxInfo.isFile() || !fbx.open(QIODevice::ReadOnly)) { if (!_fbxInfo.exists() || !_fbxInfo.isFile() || !fbx.open(QIODevice::ReadOnly)) {
QMessageBox::warning(NULL, OffscreenUi::warning(NULL,
QString("ModelPackager::loadModel()"), QString("ModelPackager::loadModel()"),
QString("Could not open FBX file %1").arg(_fbxInfo.filePath()), QString("Could not open FBX file %1").arg(_fbxInfo.filePath()),
QMessageBox::Ok); QMessageBox::Ok);
@ -402,7 +403,7 @@ bool ModelPackager::copyTextures(const QString& oldDir, const QDir& newDir) {
} }
if (!errors.isEmpty()) { if (!errors.isEmpty()) {
QMessageBox::warning(nullptr, "ModelPackager::copyTextures()", OffscreenUi::warning(nullptr, "ModelPackager::copyTextures()",
"Missing textures:" + errors); "Missing textures:" + errors);
qCDebug(interfaceapp) << "ModelPackager::copyTextures():" << errors; qCDebug(interfaceapp) << "ModelPackager::copyTextures():" << errors;
return false; return false;

View file

@ -21,6 +21,7 @@
#include <FSTReader.h> #include <FSTReader.h>
#include <GLMHelpers.h> #include <GLMHelpers.h>
#include <OffscreenUi.h>
#include "ModelPropertiesDialog.h" #include "ModelPropertiesDialog.h"
@ -200,7 +201,7 @@ void ModelPropertiesDialog::chooseTextureDirectory() {
return; return;
} }
if (!directory.startsWith(_basePath)) { 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; return;
} }
_textureDirectory->setText(directory.length() == _basePath.length() ? "." : directory.mid(_basePath.length() + 1)); _textureDirectory->setText(directory.length() == _basePath.length() ? "." : directory.mid(_basePath.length() + 1));

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) {
@ -67,7 +68,7 @@ void ATPAssetMigrator::loadEntityServerFile() {
QByteArray jsonData; QByteArray jsonData;
if (!gunzip(compressedJsonData, 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); QJsonDocument modelsJSON = QJsonDocument::fromJson(jsonData);
@ -107,7 +108,7 @@ void ATPAssetMigrator::loadEntityServerFile() {
if (request->getResult() == ResourceRequest::Success) { if (request->getResult() == ResourceRequest::Success) {
migrateResource(request); migrateResource(request);
} else { } else {
QMessageBox::warning(_dialogParent, "Error", OffscreenUi::warning(_dialogParent, "Error",
QString("Could not retrieve asset at %1").arg(modelURL.toString())); QString("Could not retrieve asset at %1").arg(modelURL.toString()));
} }
request->deleteLater(); request->deleteLater();
@ -115,7 +116,7 @@ void ATPAssetMigrator::loadEntityServerFile() {
request->send(); request->send();
} else { } else {
QMessageBox::warning(_dialogParent, "Error", OffscreenUi::warning(_dialogParent, "Error",
QString("Could not create request for asset at %1").arg(modelURL.toString())); QString("Could not create request for asset at %1").arg(modelURL.toString()));
} }
@ -129,7 +130,7 @@ void ATPAssetMigrator::loadEntityServerFile() {
_doneReading = true; _doneReading = true;
} else { } 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"); "There was a problem loading that entity-server file for ATP asset migration. Please try again");
} }
} }
@ -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;
@ -254,11 +255,11 @@ void ATPAssetMigrator::saveEntityServerFile() {
QMessageBox::information(_dialogParent, "Success", QMessageBox::information(_dialogParent, "Success",
QString("Your new entities file has been saved at %1").arg(saveName)); QString("Your new entities file has been saved at %1").arg(saveName));
} else { } 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 { } else {
QMessageBox::warning(_dialogParent, "Error", OffscreenUi::warning(_dialogParent, "Error",
QString("Could not open file at %1 to write new entities file to.").arg(saveName)); QString("Could not open file at %1 to write new entities file to.").arg(saveName));
} }
} }

View file

@ -139,7 +139,7 @@ void EyeTracker::onStreamStarted() {
qCWarning(interfaceapp) << "Eye Tracker: Error starting streaming:" << smiReturnValueToString(result); qCWarning(interfaceapp) << "Eye Tracker: Error starting streaming:" << smiReturnValueToString(result);
// Display error dialog unless SMI SDK has already displayed an error message. // Display error dialog unless SMI SDK has already displayed an error message.
if (result != SMI_ERROR_HMD_NOT_SUPPORTED) { if (result != SMI_ERROR_HMD_NOT_SUPPORTED) {
QMessageBox::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result)); OffscreenUi::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result));
} }
} else { } else {
qCDebug(interfaceapp) << "Eye Tracker: Started streaming"; qCDebug(interfaceapp) << "Eye Tracker: Started streaming";
@ -152,7 +152,7 @@ void EyeTracker::onStreamStarted() {
result = smi_loadCalibration(HIGH_FIDELITY_EYE_TRACKER_CALIBRATION); result = smi_loadCalibration(HIGH_FIDELITY_EYE_TRACKER_CALIBRATION);
if (result != SMI_RET_SUCCESS) { if (result != SMI_RET_SUCCESS) {
qCWarning(interfaceapp) << "Eye Tracker: Error loading calibration:" << smiReturnValueToString(result); 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)); + smiReturnValueToString(result));
} else { } else {
qCDebug(interfaceapp) << "Eye Tracker: Loaded calibration"; qCDebug(interfaceapp) << "Eye Tracker: Loaded calibration";
@ -168,7 +168,7 @@ void EyeTracker::setEnabled(bool enabled, bool simulate) {
int result = smi_setCallback(eyeTrackerCallback); int result = smi_setCallback(eyeTrackerCallback);
if (result != SMI_RET_SUCCESS) { if (result != SMI_RET_SUCCESS) {
qCWarning(interfaceapp) << "Eye Tracker: Error setting callback:" << smiReturnValueToString(result); 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 { } else {
_isInitialized = true; _isInitialized = true;
} }
@ -273,7 +273,7 @@ void EyeTracker::calibrate(int points) {
} }
if (result != SMI_RET_SUCCESS) { 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 #endif

View file

@ -21,6 +21,7 @@
#include "DomainHandler.h" #include "DomainHandler.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "Menu.h" #include "Menu.h"
#include "OffscreenUi.h"
#include "ui/ModelsBrowser.h" #include "ui/ModelsBrowser.h"
#include "WindowScriptingInterface.h" #include "WindowScriptingInterface.h"
@ -153,12 +154,11 @@ QScriptValue WindowScriptingInterface::peekNonBlockingFormResult(QScriptValue fo
return retVal; return retVal;
} }
/// Display an alert box /// Display an alert box
/// \param const QString& message message to display /// \param const QString& message message to display
/// \return QScriptValue::UndefinedValue /// \return QScriptValue::UndefinedValue
QScriptValue WindowScriptingInterface::showAlert(const QString& message) { QScriptValue WindowScriptingInterface::showAlert(const QString& message) {
QMessageBox::warning(qApp->getWindow(), "", message); OffscreenUi::warning("", message);
return QScriptValue::UndefinedValue; return QScriptValue::UndefinedValue;
} }
@ -166,8 +166,11 @@ QScriptValue WindowScriptingInterface::showAlert(const QString& message) {
/// \param const QString& message message to display /// \param const QString& message message to display
/// \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) {
QMessageBox::StandardButton response = QMessageBox::question(qApp->getWindow(), "", message); bool confirm = false;
return QScriptValue(response == QMessageBox::Yes); OffscreenUi::question("", message, [&](QMessageBox::StandardButton response){
confirm = (response == QMessageBox::Yes);
});
return QScriptValue(confirm);
} }
void WindowScriptingInterface::chooseDirectory() { void WindowScriptingInterface::chooseDirectory() {
@ -185,7 +188,7 @@ void WindowScriptingInterface::chooseDirectory() {
} }
if (!validateAs.exactMatch(directory)) { if (!validateAs.exactMatch(directory)) {
QMessageBox::warning(NULL, "Invalid Directory", errorMessage); OffscreenUi::warning(NULL, "Invalid Directory", errorMessage);
return; return;
} }
@ -597,7 +600,6 @@ QScriptValue WindowScriptingInterface::showPrompt(const QString& message, const
if (promptDialog.exec() == QDialog::Accepted) { if (promptDialog.exec() == QDialog::Accepted) {
return QScriptValue(promptDialog.textValue()); return QScriptValue(promptDialog.textValue());
} }
return QScriptValue::NullValue; return QScriptValue::NullValue;
} }

View file

@ -23,6 +23,7 @@
#include <AssetUpload.h> #include <AssetUpload.h>
#include <AssetUtils.h> #include <AssetUtils.h>
#include <NodeList.h> #include <NodeList.h>
#include <OffscreenUi.h>
#include <ResourceManager.h> #include <ResourceManager.h>
AssetUploadDialogFactory& AssetUploadDialogFactory::getInstance() { AssetUploadDialogFactory& AssetUploadDialogFactory::getInstance() {
@ -146,5 +147,5 @@ void AssetUploadDialogFactory::showErrorDialog(AssetUpload* upload, QWidget* dia
dialogMessage += errorMessage; dialogMessage += errorMessage;
QMessageBox::warning(dialogParent, "Failed Upload", dialogMessage); OffscreenUi::warning(dialogParent, "Failed Upload", dialogMessage);
} }

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

@ -26,6 +26,7 @@
#include <QWidget> #include <QWidget>
#include <NetworkAccessManager.h> #include <NetworkAccessManager.h>
#include <OffscreenUi.h>
#include "Application.h" #include "Application.h"
#include "ScriptHighlighting.h" #include "ScriptHighlighting.h"
@ -120,7 +121,7 @@ bool ScriptEditorWidget::setRunning(bool run) {
bool ScriptEditorWidget::saveFile(const QString &scriptPath) { bool ScriptEditorWidget::saveFile(const QString &scriptPath) {
QFile file(scriptPath); QFile file(scriptPath);
if (!file.open(QFile::WriteOnly | QFile::Text)) { 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())); .arg(file.errorString()));
return false; return false;
} }
@ -141,7 +142,7 @@ void ScriptEditorWidget::loadFile(const QString& scriptPath) {
if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) { if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {
QFile file(scriptPath); QFile file(scriptPath);
if (!file.open(QFile::ReadOnly | QFile::Text)) { 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())); .arg(file.errorString()));
return; return;
} }
@ -208,7 +209,7 @@ void ScriptEditorWidget::setScriptFile(const QString& scriptPath) {
bool ScriptEditorWidget::questionSave() { bool ScriptEditorWidget::questionSave() {
if (_scriptEditorWidgetUI->scriptEdit->document()->isModified()) { 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 | tr("The script has been modified.\nDo you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard |
QMessageBox::Cancel, QMessageBox::Save); QMessageBox::Cancel, QMessageBox::Save);
return button == QMessageBox::Save ? save() : (button == QMessageBox::Discard); return button == QMessageBox::Save ? save() : (button == QMessageBox::Discard);
@ -222,7 +223,7 @@ void ScriptEditorWidget::onWindowActivated() {
if (QFileInfo(_currentScript).lastModified() > _currentScriptModified) { if (QFileInfo(_currentScript).lastModified() > _currentScriptModified) {
if (static_cast<ScriptEditorWindow*>(this->parent()->parent()->parent())->autoReloadScripts() if (static_cast<ScriptEditorWindow*>(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" tr("This file has been modified outside of the Interface editor.") + "\n\n"
+ (isModified() + (isModified()
? tr("Do you want to reload it and lose the changes you've made in the Interface editor?") ? tr("Do you want to reload it and lose the changes you've made in the Interface editor?")

View file

@ -20,6 +20,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QUrlQuery> #include <QUrlQuery>
#include <OffscreenUi.h>
const int NARROW_SNAPSHOT_DIALOG_SIZE = 500; const int NARROW_SNAPSHOT_DIALOG_SIZE = 500;
const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650; const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650;
@ -87,7 +88,7 @@ void SnapshotShareDialog::accept() {
void SnapshotShareDialog::uploadSnapshot() { void SnapshotShareDialog::uploadSnapshot() {
if (AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().isEmpty()) { 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."); "Your Discourse API key is missing, you cannot share snapshots. Please try to relog.");
return; return;
} }
@ -178,7 +179,7 @@ void SnapshotShareDialog::postRequestFinished() {
errorMessage = errorArray.first().toString(); errorMessage = errorArray.first().toString();
} }
} }
QMessageBox::warning(this, "", errorMessage); OffscreenUi::warning(this, "", errorMessage);
_ui.shareButton->setEnabled(true); _ui.shareButton->setEnabled(true);
_ui.shareButton->setStyleSheet(SHARE_BUTTON_STYLE + SHARE_BUTTON_ENABLED_STYLE); _ui.shareButton->setStyleSheet(SHARE_BUTTON_STYLE + SHARE_BUTTON_ENABLED_STYLE);
} }
@ -193,7 +194,7 @@ void SnapshotShareDialog::uploadRequestFinished() {
if (responseObject.contains("url")) { if (responseObject.contains("url")) {
sendForumPost(responseObject["url"].toString()); sendForumPost(responseObject["url"].toString());
} else { } else {
QMessageBox::warning(this, "", SHARE_DEFAULT_ERROR); OffscreenUi::warning(this, "", SHARE_DEFAULT_ERROR);
_ui.shareButton->setEnabled(true); _ui.shareButton->setEnabled(true);
_ui.shareButton->setStyleSheet(SHARE_BUTTON_STYLE + SHARE_BUTTON_ENABLED_STYLE); _ui.shareButton->setStyleSheet(SHARE_BUTTON_STYLE + SHARE_BUTTON_ENABLED_STYLE);
} }

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) {
@ -187,6 +212,26 @@ void OffscreenUi::warning(const QString& title, const QString& text,
static_cast<QMessageBox::Icon>(MessageDialog::Warning), buttons); static_cast<QMessageBox::Icon>(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, void OffscreenUi::critical(const QString& title, const QString& text,
ButtonCallback callback, ButtonCallback callback,
QMessageBox::StandardButtons buttons) { QMessageBox::StandardButtons buttons) {

View file

@ -45,14 +45,25 @@ 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);
/// 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, static void critical(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);