From 955b0a580e9441b274215346df56b31f53f1caff Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Thu, 25 Oct 2018 17:25:44 -0700 Subject: [PATCH] adding hooks for application for pause/resume --- .../qml/LoginDialog/CompleteProfileBody.qml | 41 +----------- .../qml/LoginDialog/LinkAccountBody.qml | 16 ++--- .../qml/LoginDialog/LoggingInBody.qml | 10 ++- .../resources/qml/LoginDialog/SignInBody.qml | 63 ------------------- .../qml/LoginDialog/UsernameCollisionBody.qml | 10 ++- .../qml/dialogs/TabletLoginDialog.qml | 5 -- interface/src/Application.cpp | 18 ++++-- interface/src/Application.h | 10 ++- interface/src/ui/DialogsManager.cpp | 3 - interface/src/ui/DialogsManager.h | 2 - interface/src/ui/LoginDialog.cpp | 51 ++++++++++----- interface/src/ui/LoginDialog.h | 11 +++- 12 files changed, 92 insertions(+), 148 deletions(-) diff --git a/interface/resources/qml/LoginDialog/CompleteProfileBody.qml b/interface/resources/qml/LoginDialog/CompleteProfileBody.qml index 686048a48d..ad641a8094 100644 --- a/interface/resources/qml/LoginDialog/CompleteProfileBody.qml +++ b/interface/resources/qml/LoginDialog/CompleteProfileBody.qml @@ -178,7 +178,9 @@ Item { fontBold: completeProfileBody.fontBold onClicked: { loginErrorMessage.visible = false; - loginDialog.createAccountFromStream() + loginDialog.createAccountFromSteam(); + bodyLoader.setSource("LoggingInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, + "withSteam": true, "fromBody": "CompleteProfileBody" }) } } } @@ -246,41 +248,4 @@ Item { Component.onCompleted: { d.resize(); } - - Connections { - target: loginDialog - onHandleCreateCompleted: { - console.log("Create Succeeded") - loginDialog.loginThroughSteam() - bodyLoader.setSource("LoggingInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": true, "fromBody": "CompleteProfileBody" }) - } - onHandleCreateFailed: { - console.log("Create Failed: " + error) - var poppedUp = Settings.getValue("loginDialogPoppedUp", false); - if (poppedUp) { - console.log("[ENCOURAGELOGINDIALOG]: failed creating an account") - var data = { - "action": "user failed creating an account" - }; - UserActivityLogger.logAction("encourageLoginDialog", data); - } - bodyLoader.setSource("UsernameCollisionBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "errorString": "" }); - } - onHandleLoginCompleted: { - console.log("Login Succeeded") - loginSuccess(true) - } - onHandleLoginFailed: { - console.log("Login Failed") - var poppedUp = Settings.getValue("loginDialogPoppedUp", false); - if (poppedUp) { - console.log("[ENCOURAGELOGINDIALOG]: failed logging in") - var data = { - "action": "user failed logging in" - }; - UserActivityLogger.logAction("encourageLoginDialog", data); - } - loginSuccess(false) - } - } } diff --git a/interface/resources/qml/LoginDialog/LinkAccountBody.qml b/interface/resources/qml/LoginDialog/LinkAccountBody.qml index f55640828e..d824caa882 100644 --- a/interface/resources/qml/LoginDialog/LinkAccountBody.qml +++ b/interface/resources/qml/LoginDialog/LinkAccountBody.qml @@ -239,7 +239,7 @@ Item { right: parent.right margins: 10 } - visible: !root.isTablet + visible: !root.isTablet && !HMD.active Text { id: dismissText text: qsTr("No thanks, take me in-world! >") @@ -257,13 +257,13 @@ Item { anchors.fill: parent acceptedButtons: Qt.LeftButton onClicked: { - var poppedUp = Settings.getValue("loginDialogPoppedUp", false); - if (poppedUp) { + if (loginDialog.getLoginDialogPoppedUp()) { console.log("[ENCOURAGELOGINDIALOG]: user dismissed login screen") var data = { "action": "user dismissed login screen" }; - Settings.setValue("loginDialogPoppedUp", false); + UserActivityLogger.logAction("encourageLoginDialog", data); + loginDialog.dismissLoginDialog(); } root.tryDestroy(); } @@ -282,14 +282,14 @@ Item { d.resize(); } Component.onDestruction: { - var poppedUp = Settings.getValue("loginDialogPoppedUp", false); - if (poppedUp && root.isTablet) { + if (loginDialog.getLoginDialogPoppedUp() && root.isTablet) { // it popped up and was clicked with the X - console.log("[ENCOURAGELOGINDIALOG]: user dismissed login screen") + console.log("[ENCOURAGELOGINDIALOG]: user closed login screen") var data = { "action": "user dismissed login screen" }; - Settings.setValue("loginDialogPoppedUp", false); + UserActivityLogger.logAction("encourageLoginDialog", data); + loginDialog.dismissLoginDialog(); } } } diff --git a/interface/resources/qml/LoginDialog/LoggingInBody.qml b/interface/resources/qml/LoginDialog/LoggingInBody.qml index c412a73dc5..78727df6eb 100644 --- a/interface/resources/qml/LoginDialog/LoggingInBody.qml +++ b/interface/resources/qml/LoginDialog/LoggingInBody.qml @@ -102,6 +102,7 @@ Item { loggingInText.text = "You are now logged in!"; } successTimer.start(); + loginDialog.resumeLoading(); } Item { @@ -245,14 +246,13 @@ Item { onHandleSignupCompleted: { console.log("SignUp completed!"); + successTimer.start(); } onHandleSignupFailed: { console.log("SignUp failed!"); var errorStringEdited = errorString.replace(/[\n\r]+/g, ' '); - console.log(errorStringEdited); bodyLoader.setSource("SignInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "errorString": errorStringEdited }); - // bodyLoader.setSource("SignInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "errorString": "yellow" }); } onHandleLoginCompleted: { @@ -275,7 +275,11 @@ Item { bodyLoader.setSource("UsernameCollisionBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "errorString": errorString }); } else { errorString = loginDialog.isLogIn ? "Username or password is incorrect." : "Failed to sign up. Please try again."; - bodyLoader.setSource("SignInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "errorString": errorString }); + if (loginDialog.isLogIn && loginDialog.isSteamRunning()) { + bodyLoader.setSource("CompleteProfileBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader }); + } else { + bodyLoader.setSource("SignInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "errorString": errorString }); + } } } } diff --git a/interface/resources/qml/LoginDialog/SignInBody.qml b/interface/resources/qml/LoginDialog/SignInBody.qml index 2f9577da17..0645cc2e73 100644 --- a/interface/resources/qml/LoginDialog/SignInBody.qml +++ b/interface/resources/qml/LoginDialog/SignInBody.qml @@ -373,69 +373,6 @@ Item { print(signInBody.errorString); } - Connections { - target: loginDialog - onHandleCreateFailed: { - console.log("Create Failed") - var error = "There was an unknown error while creating your account. Please try again later."; - loadingSuccess(false, error); - } - onHandleCreateCompleted: { - console.log("Create Completed") - } - onHandleSignupFailed: { - console.log("Sign Up Failed") - loadingSuccess(false, ""); - } - onHandleSignupCompleted: { - console.log("Sign Up Completed"); - loadingSuccess(true, ""); - } - onHandleLoginCompleted: { - console.log("Login Succeeded") - var poppedUp = Settings.getValue("loginDialogPoppedUp", false); - if (poppedUp) { - console.log("[ENCOURAGELOGINDIALOG]: logging in") - var data = { - "action": "user logged in" - }; - UserActivityLogger.logAction("encourageLoginDialog", data); - Settings.setValue("loginDialogPoppedUp", false); - } - if (loginDialog.isSteamRunning()) { - loginDialog.linkSteam(); - } - loadingSuccess(true, "") - } - onHandleLoginFailed: { - console.log("Login Failed") - var poppedUp = Settings.getValue("loginDialogPoppedUp", false); - if (poppedUp) { - console.log("[ENCOURAGELOGINDIALOG]: failed logging in") - var data = { - "action": "user failed logging in" - }; - UserActivityLogger.logAction("encourageLoginDialog", data); - Settings.setValue("loginDialogPoppedUp", false); - } - if (loginDialog.isSteamRunning()) { - bodyLoader.setSource("CompleteProfileBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader }); - } - - var error = "Username or password incorrect." - loadingSuccess(false, error) - } - onHandleLinkCompleted: { - console.log("Link Succeeded") - loadingSuccess(true, "") - } - onHandleLinkFailed: { - console.log("Link Failed") - var error = "There was an unknown error while creating your account. Please try again later."; - loadingSuccess(false, error); - } - } - Keys.onPressed: { if (!visible) { return; diff --git a/interface/resources/qml/LoginDialog/UsernameCollisionBody.qml b/interface/resources/qml/LoginDialog/UsernameCollisionBody.qml index 1eaed90bb0..71b8df45eb 100644 --- a/interface/resources/qml/LoginDialog/UsernameCollisionBody.qml +++ b/interface/resources/qml/LoginDialog/UsernameCollisionBody.qml @@ -28,7 +28,8 @@ Item { function create() { mainTextContainer.visible = false - loginDialog.createAccountFromStream(textField.text) + loginDialog.createAccountFromSteam(textField.text) + bodyLoader.setSource("LoggingInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": true, "fromBody": "UsernameCollisionBody" }); } property bool keyboardEnabled: false @@ -248,7 +249,7 @@ Item { target: loginDialog onHandleCreateCompleted: { console.log("Create Succeeded") - loginDialog.loginThroughSteam() + loginDialog.loginThroughSteam(); bodyLoader.setSource("LoggingInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": true, "fromBody": "UsernameCollisionBody" }) } onHandleCreateFailed: { @@ -258,11 +259,14 @@ Item { mainTextContainer.text = "\"" + textField.text + qsTr("\" is invalid or already taken.") } onHandleLoginCompleted: { - console.log("Login Succeeded") + console.log("Login Succeeded"); + loginDialog.dismissLoginDialog(); + root.tryDestroy(); } onHandleLoginFailed: { console.log("Login Failed") + mainTextContainer.text = "Login Failed"; } } } diff --git a/interface/resources/qml/dialogs/TabletLoginDialog.qml b/interface/resources/qml/dialogs/TabletLoginDialog.qml index b88f88129e..56b8eeec66 100644 --- a/interface/resources/qml/dialogs/TabletLoginDialog.qml +++ b/interface/resources/qml/dialogs/TabletLoginDialog.qml @@ -138,11 +138,6 @@ Windows.TabletModalWindow { } break } else switch (event.key) { - case Qt.Key_Escape: - case Qt.Key_Back: - event.accepted = true - destroy() - break case Qt.Key_Enter: case Qt.Key_Return: diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5b517e09d9..9b52357099 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -373,7 +373,9 @@ static const float INITIAL_QUERY_RADIUS = 10.0f; // priority radius for entitie static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); -Setting::Handle maxOctreePacketsPerSecond("maxOctreePPS", DEFAULT_MAX_OCTREE_PPS); +Setting::Handle maxOctreePacketsPerSecond{"maxOctreePPS", DEFAULT_MAX_OCTREE_PPS}; + +Setting::Handle loginDialogPoppedUp{"loginDialogPoppedUp", false}; static const QString MARKETPLACE_CDN_HOSTNAME = "mpassets.highfidelity.com"; static const int INTERVAL_TO_CHECK_HMD_WORN_STATUS = 500; // milliseconds @@ -2472,7 +2474,7 @@ void Application::onAboutToQuit() { // so its persisted explicitly here Setting::Handle{ ACTIVE_DISPLAY_PLUGIN_SETTING_NAME }.set(getActiveDisplayPlugin()->getName()); - Setting::Handle{"loginDialogPoppedUp", false}.set(false); + loginDialogPoppedUp.set(false); getActiveDisplayPlugin()->deactivate(); if (_autoSwitchDisplayModeSupportedHMDPlugin @@ -2889,8 +2891,8 @@ void Application::showLoginScreen() { auto accountManager = DependencyManager::get(); auto dialogsManager = DependencyManager::get(); if (!accountManager->isLoggedIn()) { - Setting::Handle{"loginDialogPoppedUp", false}.set(true); // dialogsManager->showLoginScreenDialog(); + _loginDialogPoppedUp = true; dialogsManager->showLoginDialog(); QJsonObject loginData = {}; loginData["action"] = "login dialog shown"; @@ -2902,7 +2904,8 @@ void Application::showLoginScreen() { goToLoginScreenDomainURL(loginScreenDomainURL); } } - Setting::Handle{"loginDialogPoppedUp", false}.set(false); + _loginDialogPoppedUp = !accountManager->isLoggedIn(); + loginDialogPoppedUp.set(_loginDialogPoppedUp); } void Application::initializeQml() { @@ -8390,6 +8393,13 @@ void Application::setShowBulletConstraintLimits(bool value) { _physicsEngine->setShowBulletConstraintLimits(value); } +void Application::onDismissedLoginDialog() { + // TODO something with login dialog. + qDebug() << "dismissed login dialog"; + _loginDialogPoppedUp = false; + loginDialogPoppedUp.set(false); +} + void Application::startHMDStandBySession() { _autoSwitchDisplayModeSupportedHMDPlugin->startStandBySession(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 55864ba27d..d35848754a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -232,7 +232,7 @@ public: float getSettingConstrainToolbarPosition() { return _constrainToolbarPosition.get(); } void setSettingConstrainToolbarPosition(bool setting); - Q_INVOKABLE void setMinimumGPUTextureMemStabilityCount(int stabilityCount) { _minimumGPUTextureMemSizeStabilityCount = stabilityCount; } + Q_INVOKABLE void setMinimumGPUTextureMemStabilityCount(int stabilityCount) { _minimumGPUTextureMemSizeStabilityCount = stabilityCount; } NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; } @@ -319,6 +319,10 @@ public: int getOtherAvatarsReplicaCount() { return DependencyManager::get()->getReplicaCount(); } void setOtherAvatarsReplicaCount(int count) { DependencyManager::get()->setReplicaCount(count); } + bool getLoginDialogPoppedUp() const { return _loginDialogPoppedUp; } + void pauseUntilLoginDetermined(); + void resumeAfterLoginDialogActionTaken(); + #if defined(Q_OS_ANDROID) void beforeEnterBackground(); void enterBackground(); @@ -338,7 +342,6 @@ signals: void interstitialModeChanged(bool isInInterstitialMode); void loginScreenStateChanged(bool isInLoginScreenState); - void loginDialogPoppedUp(); public slots: QVector pasteEntities(float x, float y, float z); @@ -507,6 +510,8 @@ private slots: void setShowBulletConstraints(bool value); void setShowBulletConstraintLimits(bool value); + void onDismissedLoginDialog(); + private: void init(); bool handleKeyEventForFocusedEntityOrOverlay(QEvent* event); @@ -676,6 +681,7 @@ private: glm::uvec2 _renderResolution; int _maxOctreePPS = DEFAULT_MAX_OCTREE_PPS; + bool _loginDialogPoppedUp = false; quint64 _lastFaceTrackerUpdate; diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index 517785a168..98b0483040 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -118,9 +118,6 @@ void DialogsManager::showLoginDialog() { LoginDialog::showWithSelection(); } -void DialogsManager::showLoginScreenDialog() { -} - void DialogsManager::showUpdateDialog() { UpdateDialog::show(); } diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index 9b8a051ade..dfa24e76f9 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -50,8 +50,6 @@ public slots: void toggleLoginDialog(); // shows login screen that appears upon `File > Log In/Sign Up`. void showLoginDialog(); - // toggles login screen that appears upon application startup. - void showLoginScreenDialog(); void octreeStatsDetails(); void lodTools(); void hmdTools(bool showTools); diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index ceea47d969..1ec098ddb2 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -33,22 +33,17 @@ HIFI_QML_DEF(LoginDialog) LoginDialog::LoginDialog(QQuickItem *parent) : OffscreenQmlDialog(parent) { auto accountManager = DependencyManager::get(); + // the login hasn't been dismissed yet if the user isn't logged in and is encouraged to login. #if !defined(Q_OS_ANDROID) connect(accountManager.data(), &AccountManager::loginComplete, this, &LoginDialog::handleLoginCompleted); connect(accountManager.data(), &AccountManager::loginFailed, this, &LoginDialog::handleLoginFailed); #endif + connect(this, SIGNAL(dismissedLoginDialog()), qApp, SLOT(onDismissedLoginDialog())); } LoginDialog::~LoginDialog() { - Setting::Handle loginDialogPoppedUp{ "loginDialogPoppedUp", false }; - if (loginDialogPoppedUp.get()) { - QJsonObject data; - data["action"] = "user opted out"; - UserActivityLogger::getInstance().logAction("encourageLoginDialog", data); - } - loginDialogPoppedUp.set(false); } void LoginDialog::showWithSelection() { @@ -56,14 +51,28 @@ void LoginDialog::showWithSelection() { auto tablet = dynamic_cast(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system")); auto hmd = DependencyManager::get(); - if (tablet->getToolbarMode()) { - LoginDialog::show(); - } else { - static const QUrl url("dialogs/TabletLoginDialog.qml"); - tablet->initialScreen(url); - if (!hmd->getShouldShowTablet()) { - hmd->openTablet(); + static const QUrl url("dialogs/TabletLoginDialog.qml"); + if (!qApp->isHMDMode()) { + + if (qApp->getLoginDialogPoppedUp()) { + LoginDialog::show(); + return; + } else { + if (!tablet->isPathLoaded(url)) { + tablet->loadQMLSource(url); + } } + } else { + //if (qApp->getLoginDialogPoppedUp()) { + // // pop up those overlay things. + // return; + //} else { + // tablet->initialScreen(url); + //} + + } + if (!hmd->getShouldShowTablet()) { + hmd->openTablet(); } } @@ -92,6 +101,12 @@ bool LoginDialog::isSteamRunning() const { return steamClient && steamClient->isRunning(); } +void LoginDialog::dismissLoginDialog() { + // it'll only pop up once. + qDebug() << "LoginDialog::dismissLoginDialog"; + emit dismissedLoginDialog(); +} + void LoginDialog::login(const QString& username, const QString& password) const { qDebug() << "Attempting to login " << username; DependencyManager::get()->requestAccessToken(username, password); @@ -138,7 +153,7 @@ void LoginDialog::linkSteam() { } } -void LoginDialog::createAccountFromStream(QString username) { +void LoginDialog::createAccountFromSteam(QString username) { qDebug() << "Attempting to create account from Steam info"; if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) { steamClient->requestTicket([this, username](Ticket ticket) { @@ -162,7 +177,7 @@ void LoginDialog::createAccountFromStream(QString username) { auto accountManager = DependencyManager::get(); accountManager->sendRequest(CREATE_ACCOUNT_FROM_STEAM_PATH, AccountManagerAuth::None, - QNetworkAccessManager::PostOperation, callbackParams, + NetworkAccessManager::PostOperation, callbackParams, QJsonDocument(payload).toJson()); }); } @@ -233,6 +248,10 @@ void LoginDialog::signupCompleted(QNetworkReply* reply) { emit handleSignupCompleted(); } +bool LoginDialog::getLoginDialogPoppedUp() const { + return qApp->getLoginDialogPoppedUp(); +} + QString errorStringFromAPIObject(const QJsonValue& apiObject) { if (apiObject.isArray()) { return apiObject.toArray()[0].toString(); diff --git a/interface/src/ui/LoginDialog.h b/interface/src/ui/LoginDialog.h index 3c7ad7e015..df7bf69172 100644 --- a/interface/src/ui/LoginDialog.h +++ b/interface/src/ui/LoginDialog.h @@ -15,6 +15,7 @@ #define hifi_LoginDialog_h #include +#include class QNetworkReply; @@ -45,6 +46,9 @@ signals: void handleSignupCompleted(); void handleSignupFailed(QString errorString); + // occurs upon dismissing the encouraging log in. + void dismissedLoginDialog(); + public slots: void linkCompleted(QNetworkReply* reply); void linkFailed(QNetworkReply* reply); @@ -55,17 +59,22 @@ public slots: void signupCompleted(QNetworkReply* reply); void signupFailed(QNetworkReply* reply); +protected slots: + Q_INVOKABLE void dismissLoginDialog(); + Q_INVOKABLE bool isSteamRunning() const; Q_INVOKABLE void login(const QString& username, const QString& password) const; Q_INVOKABLE void loginThroughSteam(); Q_INVOKABLE void linkSteam(); - Q_INVOKABLE void createAccountFromStream(QString username = QString()); + Q_INVOKABLE void createAccountFromSteam(QString username = QString()); Q_INVOKABLE void signup(const QString& email, const QString& username, const QString& password); Q_INVOKABLE void openUrl(const QString& url) const; + Q_INVOKABLE bool getLoginDialogPoppedUp() const; + private: bool getIsLogIn() const { return _isLogIn; } void setIsLogIn(const bool isLogIn) { _isLogIn = isLogIn; }