History

Rework all c++ calls

vladest committed 9 years ago

Commit 3ceeb0d1 parent 5b033e07 files · +257 −255Browse files

Showing the changes to interface/src/Application.cpp (1 of 7 files). Show all

Unified · Split

interface/src/Application.cpp+36−49
@@ -6146,13 +6146,13 @@ bool Application::askToSetAvatarUrl(const QString& url) { · 6145 unmodified lines
61466146 bool agreeToLicense = true; // assume true
61476147 //create set avatar callback
61486148 auto setAvatar = [=] (QString url, QString modelName) {
6149− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6150−
6151− QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) {
6152− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6153− QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
6149+ ModalDialogListener* dlg = OffscreenUi::asyncQuestion("Set Avatar",
6150+ "Would you like to use '" + modelName + "' for your avatar?",
6151+ QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
6152+ QObject::connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
6153+ QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
61546154
6155− bool ok = (QMessageBox::Ok == answer);
6155+ bool ok = (QMessageBox::Ok == static_cast<QMessageBox::StandardButton>(answer.toInt()));
61566156 if (ok) {
61576157 getMyAvatar()->useFullAvatarURL(url, modelName);
61586158 emit fullAvatarURLChanged(url, modelName);
@@ -6160,9 +6160,6 @@ bool Application::askToSetAvatarUrl(const QString& url) { · 1 unmodified line
61606160 qCDebug(interfaceapp) << "Declined to use the avatar: " << url;
61616161 }
61626162 });
6163− OffscreenUi::asyncQuestion("Set Avatar",
6164− "Would you like to use '" + modelName + "' for your avatar?",
6165− QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
61666163 };
61676164
61686165 if (!modelLicense.isEmpty()) {
@@ -6170,12 +6167,13 @@ bool Application::askToSetAvatarUrl(const QString& url) { · 1 unmodified line
61706167 const int MAX_CHARACTERS_PER_LINE = 90;
61716168 modelLicense = simpleWordWrap(modelLicense, MAX_CHARACTERS_PER_LINE);
61726169
6173− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6174− QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=, &agreeToLicense] (QMessageBox::StandardButton answer) {
6175− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6176− QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
6170+ ModalDialogListener* dlg = OffscreenUi::asyncQuestion("Avatar Usage License",
6171+ modelLicense + "\nDo you agree to these terms?",
6172+ QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
6173+ QObject::connect(dlg, &ModalDialogListener::response, this, [=, &agreeToLicense] (QVariant answer) {
6174+ QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
61776175
6178− agreeToLicense = (answer == QMessageBox::Yes);
6176+ agreeToLicense = (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes);
61796177 if (agreeToLicense) {
61806178 switch (modelType) {
61816179 case FSTReader::HEAD_AND_BODY_MODEL: {
@@ -6192,10 +6190,6 @@ bool Application::askToSetAvatarUrl(const QString& url) { · 10 unmodified lines
61926190
61936191 //auto offscreenUi = DependencyManager::get<OffscreenUi>();
61946192 });
6195−
6196− OffscreenUi::asyncQuestion("Avatar Usage License",
6197− modelLicense + "\nDo you agree to these terms?",
6198− QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
61996193 } else {
62006194 setAvatar(url, modelName);
62016195 }
@@ -6215,23 +6209,21 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { · 13 unmodified lines
62156209 shortName = shortName.mid(startIndex, endIndex - startIndex);
62166210 }
62176211
6218− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6219− QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) {
6212+ QString message = "Would you like to run this script:\n" + shortName;
6213+ ModalDialogListener* dlg = OffscreenUi::asyncQuestion(getWindow(), "Run Script", message,
6214+ QMessageBox::Yes | QMessageBox::No);
6215+
6216+ QObject::connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
62206217 const QString& fileName = scriptFilenameOrURL;
6221− if (answer == QMessageBox::Yes) {
6218+ if (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes) {
62226219 qCDebug(interfaceapp) << "Chose to run the script: " << fileName;
62236220 DependencyManager::get<ScriptEngines>()->loadScript(fileName);
62246221 } else {
62256222 qCDebug(interfaceapp) << "Declined to run the script: " << scriptFilenameOrURL;
62266223 }
6227− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6228− QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
6224+ QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
62296225 });
62306226
6231− QString message = "Would you like to run this script:\n" + shortName;
6232−
6233− OffscreenUi::asyncQuestion(getWindow(), "Run Script", message, QMessageBox::Yes | QMessageBox::No);
6234−
62356227 return true;
62366228 }
62376229
@@ -6268,11 +6260,14 @@ bool Application::askToWearAvatarAttachmentUrl(const QString& url) { · 30 unmodified lines
62686260 name = nameValue.toString();
62696261 }
62706262
6271− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6272− QObject::connect(offscreenUi.data(), &OffscreenUi::response, this, [=] (QMessageBox::StandardButton answer) {
6273− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6274− QObject::disconnect(offscreenUi.data(), &OffscreenUi::response, this, nullptr);
6275− if (answer == QMessageBox::Yes) {
6263+ auto avatarAttachmentConfirmationTitle = tr("Avatar Attachment Confirmation");
6264+ auto avatarAttachmentConfirmationMessage = tr("Would you like to wear '%1' on your avatar?").arg(name);
6265+ ModalDialogListener* dlg = OffscreenUi::asyncQuestion(avatarAttachmentConfirmationTitle,
6266+ avatarAttachmentConfirmationMessage,
6267+ QMessageBox::Ok | QMessageBox::Cancel);
6268+ QObject::connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
6269+ QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
6270+ if (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes) {
62766271 // add attachment to avatar
62776272 auto myAvatar = getMyAvatar();
62786273 assert(myAvatar);
@@ -6285,12 +6280,6 @@ bool Application::askToWearAvatarAttachmentUrl(const QString& url) { · 6 unmodified lines
62856280 qCDebug(interfaceapp) << "User declined to wear the avatar attachment: " << url;
62866281 }
62876282 });
6288−
6289− auto avatarAttachmentConfirmationTitle = tr("Avatar Attachment Confirmation");
6290− auto avatarAttachmentConfirmationMessage = tr("Would you like to wear '%1' on your avatar?").arg(name);
6291− OffscreenUi::asyncQuestion(avatarAttachmentConfirmationTitle,
6292− avatarAttachmentConfirmationMessage,
6293− QMessageBox::Ok | QMessageBox::Cancel);
62946283 } else {
62956284 // json parse error
62966285 auto avatarAttachmentParseErrorString = tr("Error parsing attachment JSON from url: \"%1\"");
@@ -6933,17 +6922,17 @@ void Application::openUrl(const QUrl& url) const { · 636 unmodified lines
69336922
69346923 void Application::loadDialog() {
69356924 auto scriptEngines = DependencyManager::get<ScriptEngines>();
6936− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6937− connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, [=] (QString response) {
6938− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6939− disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, nullptr);
6925+ ModalDialogListener* dlg = OffscreenUi::getOpenFileNameAsync(_glWidget, tr("Open Script"),
6926+ getPreviousScriptLocation(),
6927+ tr("JavaScript Files (*.js)"));
6928+ connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
6929+ disconnect(dlg, &ModalDialogListener::response, this, nullptr);
6930+ const QString& response = answer.toString();
69406931 if (!response.isEmpty() && QFile(response).exists()) {
69416932 setPreviousScriptLocation(QFileInfo(response).absolutePath());
69426933 DependencyManager::get<ScriptEngines>()->loadScript(response, true, false, false, true); // Don't load from cache
69436934 }
69446935 });
6945− OffscreenUi::getOpenFileNameAsync(_glWidget, tr("Open Script"), getPreviousScriptLocation(),
6946− tr("JavaScript Files (*.js)"));
69476936 }
69486937
69496938 QString Application::getPreviousScriptLocation() {
@@ -6956,10 +6945,9 @@ void Application::setPreviousScriptLocation(const QString& location) { · 6 unmodified lines
69566945 }
69576946
69586947 void Application::loadScriptURLDialog() const {
6959− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6960− connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, [=] (QVariant response) {
6961− disconnect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, this, nullptr);
6962− auto offscreenUi = DependencyManager::get<OffscreenUi>();
6948+ ModalDialogListener* dlg = OffscreenUi::getTextAsync(OffscreenUi::ICON_NONE, "Open and Run Script", "Script URL");
6949+ connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
6950+ disconnect(dlg, &ModalDialogListener::response, this, nullptr);
69636951 const QString& newScript = response.toString();
69646952 if (QUrl(newScript).scheme() == "atp") {
69656953 OffscreenUi::asyncWarning("Error Loading Script", "Cannot load client script over ATP");
@@ -6967,7 +6955,6 @@ void Application::loadScriptURLDialog() const { · 1 unmodified line
69676955 DependencyManager::get<ScriptEngines>()->loadScript(newScript.trimmed());
69686956 }
69696957 });
6970− OffscreenUi::getTextAsync(OffscreenUi::ICON_NONE, "Open and Run Script", "Script URL");
69716958 }
69726959
69736960 void Application::loadLODToolsDialog() {