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

This commit is contained in:
Brad Hefta-Gaub 2016-01-05 10:17:16 -08:00
parent d98c2d1413
commit 927fe97359
11 changed files with 57 additions and 26 deletions

View file

@ -86,6 +86,7 @@
#include <ObjectMotionState.h>
#include <OctalCode.h>
#include <OctreeSceneStats.h>
#include <OffscreenUi.h>
#include <gl/OffscreenGLCanvas.h>
#include <PathUtils.h>
#include <PerfStat.h>
@ -4386,7 +4387,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
bool Application::askToUploadAsset(const QString& filename) {
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"));
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() {

View file

@ -15,6 +15,7 @@
#include <QTemporaryDir>
#include <FSTReader.h>
#include <OffscreenUi.h>
#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;

View file

@ -21,6 +21,7 @@
#include <FSTReader.h>
#include <GLMHelpers.h>
#include <OffscreenUi.h>
#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));

View file

@ -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));
}
}

View file

@ -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

View file

@ -188,7 +188,7 @@ void WindowScriptingInterface::chooseDirectory() {
}
if (!validateAs.exactMatch(directory)) {
QMessageBox::warning(NULL, "Invalid Directory", errorMessage);
OffscreenUi::warning(NULL, "Invalid Directory", errorMessage);
return;
}

View file

@ -23,6 +23,7 @@
#include <AssetUpload.h>
#include <AssetUtils.h>
#include <NodeList.h>
#include <OffscreenUi.h>
#include <ResourceManager.h>
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);
}

View file

@ -26,6 +26,7 @@
#include <QWidget>
#include <NetworkAccessManager.h>
#include <OffscreenUi.h>
#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<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"
+ (isModified()
? 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 <QUrlQuery>
#include <OffscreenUi.h>
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);
}

View file

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

View file

@ -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);