Showing the changes to interface/src/Menu.cpp (1 of 69 files). Show all
Unified · Split
| @@ -25,11 +25,10 @@ · 24 unmodified lines | ||
| 25 | 25 | #include <QUuid> |
| 26 | 26 | #include <QWindow> |
| 27 | 27 | |
| 28 | +#include <AccountManager.h> | |
| 28 | 29 | #include <UUID.h> |
| 29 | 30 | |
| 30 | 31 | #include "Application.h" |
| 31 | −#include "DataServerClient.h" | |
| 32 | −#include "PairingHandler.h" | |
| 33 | 32 | #include "Menu.h" |
| 34 | 33 | #include "Util.h" |
| 35 | 34 | #include "InfoView.h" |
| @@ -72,7 +71,8 @@ Menu::Menu() : · 36 unmodified lines | ||
| 72 | 71 | _voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE), |
| 73 | 72 | _boundaryLevelAdjust(0), |
| 74 | 73 | _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS), |
| 75 | − _lastAdjust(usecTimestampNow()) | |
| 74 | + _lastAdjust(usecTimestampNow()), | |
| 75 | + _loginAction(NULL) | |
| 76 | 76 | { |
| 77 | 77 | Application *appInstance = Application::getInstance(); |
| 78 | 78 | |
| @@ -87,11 +87,16 @@ Menu::Menu() : · 8 unmodified lines | ||
| 87 | 87 | QAction::AboutRole); |
| 88 | 88 | #endif |
| 89 | 89 | |
| 90 | − (addActionToQMenuAndActionHash(fileMenu, | |
| 91 | − MenuOption::Login, | |
| 92 | − 0, | |
| 93 | − this, | |
| 94 | − SLOT(login()))); | |
| 90 | + AccountManager& accountManager = AccountManager::getInstance(); | |
| 91 | + | |
| 92 | + _loginAction = addActionToQMenuAndActionHash(fileMenu, MenuOption::Logout); | |
| 93 | + | |
| 94 | + // call our toggle login function now so the menu option is setup properly | |
| 95 | + toggleLoginMenuItem(); | |
| 96 | + | |
| 97 | + // connect to the appropriate slots of the AccountManager so that we can change the Login/Logout menu item | |
| 98 | + connect(&accountManager, &AccountManager::loginComplete, this, &Menu::toggleLoginMenuItem); | |
| 99 | + connect(&accountManager, &AccountManager::logoutComplete, this, &Menu::toggleLoginMenuItem); | |
| 95 | 100 | |
| 96 | 101 | addDisabledActionAndSeparator(fileMenu, "Scripts"); |
| 97 | 102 | addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog())); |
| @@ -130,10 +135,6 @@ Menu::Menu() : · 32 unmodified lines | ||
| 130 | 135 | addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsImport, 0, this, SLOT(importSettings())); |
| 131 | 136 | addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsExport, 0, this, SLOT(exportSettings())); |
| 132 | 137 | |
| 133 | − addDisabledActionAndSeparator(fileMenu, "Devices"); | |
| 134 | − addActionToQMenuAndActionHash(fileMenu, MenuOption::Pair, 0, PairingHandler::getInstance(), SLOT(sendPairRequest())); | |
| 135 | − addCheckableActionToQMenuAndActionHash(fileMenu, MenuOption::TransmitterDrive, 0, true); | |
| 136 | − | |
| 137 | 138 | addActionToQMenuAndActionHash(fileMenu, |
| 138 | 139 | MenuOption::Quit, |
| 139 | 140 | Qt::CTRL | Qt::Key_Q, |
| @@ -297,7 +298,9 @@ Menu::Menu() : · 157 unmodified lines | ||
| 297 | 298 | SLOT(cycleRenderMode())); |
| 298 | 299 | |
| 299 | 300 | addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Shadows, 0, false); |
| 300 | − addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Metavoxels, 0, false); | |
| 301 | + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Metavoxels, 0, true); | |
| 302 | + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::BuckyBalls, 0, true); | |
| 303 | + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Particles, 0, true); | |
| 301 | 304 | |
| 302 | 305 | |
| 303 | 306 | QMenu* voxelOptionsMenu = developerMenu->addMenu("Voxel Options"); |
| @@ -533,7 +536,6 @@ void Menu::loadSettings(QSettings* settings) { · 229 unmodified lines | ||
| 533 | 536 | scanMenuBar(&loadAction, settings); |
| 534 | 537 | Application::getInstance()->getAvatar()->loadData(settings); |
| 535 | 538 | Application::getInstance()->getSwatch()->loadData(settings); |
| 536 | − Application::getInstance()->getProfile()->loadData(settings); | |
| 537 | 539 | Application::getInstance()->updateWindowTitle(); |
| 538 | 540 | NodeList::getInstance()->loadData(settings); |
| 539 | 541 | |
| @@ -566,7 +568,6 @@ void Menu::saveSettings(QSettings* settings) { · 26 unmodified lines | ||
| 566 | 568 | scanMenuBar(&saveAction, settings); |
| 567 | 569 | Application::getInstance()->getAvatar()->saveData(settings); |
| 568 | 570 | Application::getInstance()->getSwatch()->saveData(settings); |
| 569 | − Application::getInstance()->getProfile()->saveData(settings); | |
| 570 | 571 | NodeList::getInstance()->saveData(settings); |
| 571 | 572 | } |
| 572 | 573 | |
| @@ -781,24 +782,38 @@ void sendFakeEnterEvent() { · 208 unmodified lines | ||
| 781 | 782 | const int QLINE_MINIMUM_WIDTH = 400; |
| 782 | 783 | const float DIALOG_RATIO_OF_WINDOW = 0.30f; |
| 783 | 784 | |
| 784 | −void Menu::login() { | |
| 785 | − QInputDialog loginDialog(Application::getInstance()->getWindow()); | |
| 785 | +void Menu::loginForCurrentDomain() { | |
| 786 | + QDialog loginDialog(Application::getInstance()->getWindow()); | |
| 786 | 787 | loginDialog.setWindowTitle("Login"); |
| 787 | − loginDialog.setLabelText("Username:"); | |
| 788 | − QString username = Application::getInstance()->getProfile()->getUsername(); | |
| 789 | − loginDialog.setTextValue(username); | |
| 788 | + | |
| 789 | + QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); | |
| 790 | + loginDialog.setLayout(layout); | |
| 790 | 791 | loginDialog.setWindowFlags(Qt::Sheet); |
| 791 | − loginDialog.resize(loginDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, loginDialog.size().height()); | |
| 792 | − | |
| 792 | + | |
| 793 | + QFormLayout* form = new QFormLayout(); | |
| 794 | + layout->addLayout(form, 1); | |
| 795 | + | |
| 796 | + QLineEdit* loginLineEdit = new QLineEdit(); | |
| 797 | + loginLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); | |
| 798 | + form->addRow("Login:", loginLineEdit); | |
| 799 | + | |
| 800 | + QLineEdit* passwordLineEdit = new QLineEdit(); | |
| 801 | + passwordLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); | |
| 802 | + passwordLineEdit->setEchoMode(QLineEdit::Password); | |
| 803 | + form->addRow("Password:", passwordLineEdit); | |
| 804 | + | |
| 805 | + QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | |
| 806 | + loginDialog.connect(buttons, SIGNAL(accepted()), SLOT(accept())); | |
| 807 | + loginDialog.connect(buttons, SIGNAL(rejected()), SLOT(reject())); | |
| 808 | + layout->addWidget(buttons); | |
| 809 | + | |
| 793 | 810 | int dialogReturn = loginDialog.exec(); |
| 794 | − | |
| 795 | − if (dialogReturn == QDialog::Accepted && !loginDialog.textValue().isEmpty() && loginDialog.textValue() != username) { | |
| 796 | − // there has been a username change | |
| 797 | − // ask for a profile reset with the new username | |
| 798 | − Application::getInstance()->resetProfile(loginDialog.textValue()); | |
| 799 | − | |
| 811 | + | |
| 812 | + if (dialogReturn == QDialog::Accepted && !loginLineEdit->text().isEmpty() && !passwordLineEdit->text().isEmpty()) { | |
| 813 | + // attempt to get an access token given this username and password | |
| 814 | + AccountManager::getInstance().requestAccessToken(loginLineEdit->text(), passwordLineEdit->text()); | |
| 800 | 815 | } |
| 801 | − | |
| 816 | + | |
| 802 | 817 | sendFakeEnterEvent(); |
| 803 | 818 | } |
| 804 | 819 | |
| @@ -807,9 +822,10 @@ void Menu::editPreferences() { · 2 unmodified lines | ||
| 807 | 822 | |
| 808 | 823 | QDialog dialog(applicationInstance->getWindow()); |
| 809 | 824 | dialog.setWindowTitle("Interface Preferences"); |
| 825 | + | |
| 810 | 826 | QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); |
| 811 | 827 | dialog.setLayout(layout); |
| 812 | − | |
| 828 | + | |
| 813 | 829 | QFormLayout* form = new QFormLayout(); |
| 814 | 830 | layout->addLayout(form, 1); |
| 815 | 831 | |
| @@ -940,23 +956,23 @@ void Menu::editPreferences() { · 124 unmodified lines | ||
| 940 | 956 | } |
| 941 | 957 | |
| 942 | 958 | void Menu::goToDomain(const QString newDomain) { |
| 943 | − if (NodeList::getInstance()->getDomainHostname() != newDomain) { | |
| 959 | + if (NodeList::getInstance()->getDomainInfo().getHostname() != newDomain) { | |
| 944 | 960 | |
| 945 | 961 | // send a node kill request, indicating to other clients that they should play the "disappeared" effect |
| 946 | 962 | Application::getInstance()->getAvatar()->sendKillAvatar(); |
| 947 | 963 | |
| 948 | 964 | // give our nodeList the new domain-server hostname |
| 949 | − NodeList::getInstance()->setDomainHostname(newDomain); | |
| 965 | + NodeList::getInstance()->getDomainInfo().setHostname(newDomain); | |
| 950 | 966 | } |
| 951 | 967 | } |
| 952 | 968 | |
| 953 | 969 | void Menu::goToDomainDialog() { |
| 954 | 970 | |
| 955 | − QString currentDomainHostname = NodeList::getInstance()->getDomainHostname(); | |
| 971 | + QString currentDomainHostname = NodeList::getInstance()->getDomainInfo().getHostname(); | |
| 956 | 972 | |
| 957 | − if (NodeList::getInstance()->getDomainPort() != DEFAULT_DOMAIN_SERVER_PORT) { | |
| 973 | + if (NodeList::getInstance()->getDomainInfo().getPort() != DEFAULT_DOMAIN_SERVER_PORT) { | |
| 958 | 974 | // add the port to the currentDomainHostname string if it is custom |
| 959 | − currentDomainHostname.append(QString(":%1").arg(NodeList::getInstance()->getDomainPort())); | |
| 975 | + currentDomainHostname.append(QString(":%1").arg(NodeList::getInstance()->getDomainInfo().getPort())); | |
| 960 | 976 | } |
| 961 | 977 | |
| 962 | 978 | QInputDialog domainDialog(Application::getInstance()->getWindow()); |
| @@ -1050,7 +1066,7 @@ void Menu::goTo() { · 87 unmodified lines | ||
| 1050 | 1066 | QInputDialog gotoDialog(Application::getInstance()->getWindow()); |
| 1051 | 1067 | gotoDialog.setWindowTitle("Go to"); |
| 1052 | 1068 | gotoDialog.setLabelText("Destination:"); |
| 1053 | − QString destination = Application::getInstance()->getProfile()->getUsername(); | |
| 1069 | + QString destination = QString(); | |
| 1054 | 1070 | gotoDialog.setTextValue(destination); |
| 1055 | 1071 | gotoDialog.setWindowFlags(Qt::Sheet); |
| 1056 | 1072 | gotoDialog.resize(gotoDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, gotoDialog.size().height()); |
| @@ -1062,14 +1078,14 @@ void Menu::goTo() { · 5 unmodified lines | ||
| 1062 | 1078 | |
| 1063 | 1079 | // go to coordinate destination or to Username |
| 1064 | 1080 | if (!goToDestination(destination)) { |
| 1065 | − // there's a username entered by the user, make a request to the data-server | |
| 1066 | − DataServerClient::getValuesForKeysAndUserString( | |
| 1067 | − QStringList() | |
| 1068 | − << DataServerKey::Domain | |
| 1069 | − << DataServerKey::Position | |
| 1070 | − << DataServerKey::Orientation, | |
| 1071 | − destination, Application::getInstance()->getProfile()); | |
| 1072 | − | |
| 1081 | + JSONCallbackParameters callbackParams; | |
| 1082 | + callbackParams.jsonCallbackReceiver = Application::getInstance()->getAvatar(); | |
| 1083 | + callbackParams.jsonCallbackMethod = "goToLocationFromResponse"; | |
| 1084 | + | |
| 1085 | + // there's a username entered by the user, make a request to the data-server for the associated location | |
| 1086 | + AccountManager::getInstance().authenticatedRequest("/api/v1/users/" + gotoDialog.textValue() + "/location", | |
| 1087 | + QNetworkAccessManager::GetOperation, | |
| 1088 | + callbackParams); | |
| 1073 | 1089 | } |
| 1074 | 1090 | } |
| 1075 | 1091 | |
| @@ -1125,6 +1141,23 @@ void Menu::pasteToVoxel() { · 49 unmodified lines | ||
| 1125 | 1141 | sendFakeEnterEvent(); |
| 1126 | 1142 | } |
| 1127 | 1143 | |
| 1144 | +void Menu::toggleLoginMenuItem() { | |
| 1145 | + AccountManager& accountManager = AccountManager::getInstance(); | |
| 1146 | + | |
| 1147 | + disconnect(_loginAction, 0, 0, 0); | |
| 1148 | + | |
| 1149 | + if (accountManager.isLoggedIn()) { | |
| 1150 | + // change the menu item to logout | |
| 1151 | + _loginAction->setText("Logout " + accountManager.getUsername()); | |
| 1152 | + connect(_loginAction, &QAction::triggered, &accountManager, &AccountManager::logout); | |
| 1153 | + } else { | |
| 1154 | + // change the menu item to login | |
| 1155 | + _loginAction->setText("Login"); | |
| 1156 | + | |
| 1157 | + connect(_loginAction, &QAction::triggered, this, &Menu::loginForCurrentDomain); | |
| 1158 | + } | |
| 1159 | +} | |
| 1160 | + | |
| 1128 | 1161 | void Menu::bandwidthDetails() { |
| 1129 | 1162 | if (! _bandwidthDialog) { |
| 1130 | 1163 | _bandwidthDialog = new BandwidthDialog(Application::getInstance()->getGLWidget(), |