Showing the changes to interface/src/Menu.cpp (1 of 69 files). Show all
Unified · Split
| @@ -25,11 +25,10 @@ · 24 unmodified lines | |||
| 25 | #include <QUuid> | 25 | #include <QUuid> |
| 26 | #include <QWindow> | 26 | #include <QWindow> |
| 27 | 27 | ||
| 28 | #include <AccountManager.h> | ||
| 28 | #include <UUID.h> | 29 | #include <UUID.h> |
| 29 | 30 | ||
| 30 | #include "Application.h" | 31 | #include "Application.h" |
| 31 | #include "DataServerClient.h" | ||
| 32 | #include "PairingHandler.h" | ||
| 33 | #include "Menu.h" | 32 | #include "Menu.h" |
| 34 | #include "Util.h" | 33 | #include "Util.h" |
| 35 | #include "InfoView.h" | 34 | #include "InfoView.h" |
| @@ -72,7 +71,8 @@ Menu::Menu() : · 36 unmodified lines | |||
| 72 | _voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE), | 71 | _voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE), |
| 73 | _boundaryLevelAdjust(0), | 72 | _boundaryLevelAdjust(0), |
| 74 | _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS), | 73 | _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS), |
| 75 | _lastAdjust(usecTimestampNow()) | 74 | _lastAdjust(usecTimestampNow()), |
| 75 | _loginAction(NULL) | ||
| 76 | { | 76 | { |
| 77 | Application *appInstance = Application::getInstance(); | 77 | Application *appInstance = Application::getInstance(); |
| 78 | 78 | ||
| @@ -87,11 +87,16 @@ Menu::Menu() : · 8 unmodified lines | |||
| 87 | QAction::AboutRole); | 87 | QAction::AboutRole); |
| 88 | #endif | 88 | #endif |
| 89 | 89 | ||
| 90 | (addActionToQMenuAndActionHash(fileMenu, | 90 | AccountManager& accountManager = AccountManager::getInstance(); |
| 91 | MenuOption::Login, | 91 | |
| 92 | 0, | 92 | _loginAction = addActionToQMenuAndActionHash(fileMenu, MenuOption::Logout); |
| 93 | this, | 93 | |
| 94 | SLOT(login()))); | 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 | addDisabledActionAndSeparator(fileMenu, "Scripts"); | 101 | addDisabledActionAndSeparator(fileMenu, "Scripts"); |
| 97 | addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog())); | 102 | addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog())); |
| @@ -130,10 +135,6 @@ Menu::Menu() : · 32 unmodified lines | |||
| 130 | addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsImport, 0, this, SLOT(importSettings())); | 135 | addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsImport, 0, this, SLOT(importSettings())); |
| 131 | addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsExport, 0, this, SLOT(exportSettings())); | 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 | addActionToQMenuAndActionHash(fileMenu, | 138 | addActionToQMenuAndActionHash(fileMenu, |
| 138 | MenuOption::Quit, | 139 | MenuOption::Quit, |
| 139 | Qt::CTRL | Qt::Key_Q, | 140 | Qt::CTRL | Qt::Key_Q, |
| @@ -297,7 +298,9 @@ Menu::Menu() : · 157 unmodified lines | |||
| 297 | SLOT(cycleRenderMode())); | 298 | SLOT(cycleRenderMode())); |
| 298 | 299 | ||
| 299 | addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Shadows, 0, false); | 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 | QMenu* voxelOptionsMenu = developerMenu->addMenu("Voxel Options"); | 306 | QMenu* voxelOptionsMenu = developerMenu->addMenu("Voxel Options"); |
| @@ -533,7 +536,6 @@ void Menu::loadSettings(QSettings* settings) { · 229 unmodified lines | |||
| 533 | scanMenuBar(&loadAction, settings); | 536 | scanMenuBar(&loadAction, settings); |
| 534 | Application::getInstance()->getAvatar()->loadData(settings); | 537 | Application::getInstance()->getAvatar()->loadData(settings); |
| 535 | Application::getInstance()->getSwatch()->loadData(settings); | 538 | Application::getInstance()->getSwatch()->loadData(settings); |
| 536 | Application::getInstance()->getProfile()->loadData(settings); | ||
| 537 | Application::getInstance()->updateWindowTitle(); | 539 | Application::getInstance()->updateWindowTitle(); |
| 538 | NodeList::getInstance()->loadData(settings); | 540 | NodeList::getInstance()->loadData(settings); |
| 539 | 541 | ||
| @@ -566,7 +568,6 @@ void Menu::saveSettings(QSettings* settings) { · 26 unmodified lines | |||
| 566 | scanMenuBar(&saveAction, settings); | 568 | scanMenuBar(&saveAction, settings); |
| 567 | Application::getInstance()->getAvatar()->saveData(settings); | 569 | Application::getInstance()->getAvatar()->saveData(settings); |
| 568 | Application::getInstance()->getSwatch()->saveData(settings); | 570 | Application::getInstance()->getSwatch()->saveData(settings); |
| 569 | Application::getInstance()->getProfile()->saveData(settings); | ||
| 570 | NodeList::getInstance()->saveData(settings); | 571 | NodeList::getInstance()->saveData(settings); |
| 571 | } | 572 | } |
| 572 | 573 | ||
| @@ -781,24 +782,38 @@ void sendFakeEnterEvent() { · 208 unmodified lines | |||
| 781 | const int QLINE_MINIMUM_WIDTH = 400; | 782 | const int QLINE_MINIMUM_WIDTH = 400; |
| 782 | const float DIALOG_RATIO_OF_WINDOW = 0.30f; | 783 | const float DIALOG_RATIO_OF_WINDOW = 0.30f; |
| 783 | 784 | ||
| 784 | void Menu::login() { | 785 | void Menu::loginForCurrentDomain() { |
| 785 | QInputDialog loginDialog(Application::getInstance()->getWindow()); | 786 | QDialog loginDialog(Application::getInstance()->getWindow()); |
| 786 | loginDialog.setWindowTitle("Login"); | 787 | loginDialog.setWindowTitle("Login"); |
| 787 | loginDialog.setLabelText("Username:"); | 788 | |
| 788 | QString username = Application::getInstance()->getProfile()->getUsername(); | 789 | QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); |
| 789 | loginDialog.setTextValue(username); | 790 | loginDialog.setLayout(layout); |
| 790 | loginDialog.setWindowFlags(Qt::Sheet); | 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 | int dialogReturn = loginDialog.exec(); | 810 | int dialogReturn = loginDialog.exec(); |
| 794 | 811 | ||
| 795 | if (dialogReturn == QDialog::Accepted && !loginDialog.textValue().isEmpty() && loginDialog.textValue() != username) { | 812 | if (dialogReturn == QDialog::Accepted && !loginLineEdit->text().isEmpty() && !passwordLineEdit->text().isEmpty()) { |
| 796 | // there has been a username change | 813 | // attempt to get an access token given this username and password |
| 797 | // ask for a profile reset with the new username | 814 | AccountManager::getInstance().requestAccessToken(loginLineEdit->text(), passwordLineEdit->text()); |
| 798 | Application::getInstance()->resetProfile(loginDialog.textValue()); | ||
| 799 | |||
| 800 | } | 815 | } |
| 801 | 816 | ||
| 802 | sendFakeEnterEvent(); | 817 | sendFakeEnterEvent(); |
| 803 | } | 818 | } |
| 804 | 819 | ||
| @@ -807,9 +822,10 @@ void Menu::editPreferences() { · 2 unmodified lines | |||
| 807 | 822 | ||
| 808 | QDialog dialog(applicationInstance->getWindow()); | 823 | QDialog dialog(applicationInstance->getWindow()); |
| 809 | dialog.setWindowTitle("Interface Preferences"); | 824 | dialog.setWindowTitle("Interface Preferences"); |
| 825 | |||
| 810 | QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); | 826 | QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); |
| 811 | dialog.setLayout(layout); | 827 | dialog.setLayout(layout); |
| 812 | 828 | ||
| 813 | QFormLayout* form = new QFormLayout(); | 829 | QFormLayout* form = new QFormLayout(); |
| 814 | layout->addLayout(form, 1); | 830 | layout->addLayout(form, 1); |
| 815 | 831 | ||
| @@ -940,23 +956,23 @@ void Menu::editPreferences() { · 124 unmodified lines | |||
| 940 | } | 956 | } |
| 941 | 957 | ||
| 942 | void Menu::goToDomain(const QString newDomain) { | 958 | void Menu::goToDomain(const QString newDomain) { |
| 943 | if (NodeList::getInstance()->getDomainHostname() != newDomain) { | 959 | if (NodeList::getInstance()->getDomainInfo().getHostname() != newDomain) { |
| 944 | 960 | ||
| 945 | // send a node kill request, indicating to other clients that they should play the "disappeared" effect | 961 | // send a node kill request, indicating to other clients that they should play the "disappeared" effect |
| 946 | Application::getInstance()->getAvatar()->sendKillAvatar(); | 962 | Application::getInstance()->getAvatar()->sendKillAvatar(); |
| 947 | 963 | ||
| 948 | // give our nodeList the new domain-server hostname | 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 | void Menu::goToDomainDialog() { | 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 | // add the port to the currentDomainHostname string if it is custom | 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 | QInputDialog domainDialog(Application::getInstance()->getWindow()); | 978 | QInputDialog domainDialog(Application::getInstance()->getWindow()); |
| @@ -1050,7 +1066,7 @@ void Menu::goTo() { · 87 unmodified lines | |||
| 1050 | QInputDialog gotoDialog(Application::getInstance()->getWindow()); | 1066 | QInputDialog gotoDialog(Application::getInstance()->getWindow()); |
| 1051 | gotoDialog.setWindowTitle("Go to"); | 1067 | gotoDialog.setWindowTitle("Go to"); |
| 1052 | gotoDialog.setLabelText("Destination:"); | 1068 | gotoDialog.setLabelText("Destination:"); |
| 1053 | QString destination = Application::getInstance()->getProfile()->getUsername(); | 1069 | QString destination = QString(); |
| 1054 | gotoDialog.setTextValue(destination); | 1070 | gotoDialog.setTextValue(destination); |
| 1055 | gotoDialog.setWindowFlags(Qt::Sheet); | 1071 | gotoDialog.setWindowFlags(Qt::Sheet); |
| 1056 | gotoDialog.resize(gotoDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, gotoDialog.size().height()); | 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 | // go to coordinate destination or to Username | 1079 | // go to coordinate destination or to Username |
| 1064 | if (!goToDestination(destination)) { | 1080 | if (!goToDestination(destination)) { |
| 1065 | // there's a username entered by the user, make a request to the data-server | 1081 | JSONCallbackParameters callbackParams; |
| 1066 | DataServerClient::getValuesForKeysAndUserString( | 1082 | callbackParams.jsonCallbackReceiver = Application::getInstance()->getAvatar(); |
| 1067 | QStringList() | 1083 | callbackParams.jsonCallbackMethod = "goToLocationFromResponse"; |
| 1068 | << DataServerKey::Domain | 1084 | |
| 1069 | << DataServerKey::Position | 1085 | // there's a username entered by the user, make a request to the data-server for the associated location |
| 1070 | << DataServerKey::Orientation, | 1086 | AccountManager::getInstance().authenticatedRequest("/api/v1/users/" + gotoDialog.textValue() + "/location", |
| 1071 | destination, Application::getInstance()->getProfile()); | 1087 | QNetworkAccessManager::GetOperation, |
| 1072 | 1088 | callbackParams); | |
| 1073 | } | 1089 | } |
| 1074 | } | 1090 | } |
| 1075 | 1091 | ||
| @@ -1125,6 +1141,23 @@ void Menu::pasteToVoxel() { · 49 unmodified lines | |||
| 1125 | sendFakeEnterEvent(); | 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 | void Menu::bandwidthDetails() { | 1161 | void Menu::bandwidthDetails() { |
| 1129 | if (! _bandwidthDialog) { | 1162 | if (! _bandwidthDialog) { |
| 1130 | _bandwidthDialog = new BandwidthDialog(Application::getInstance()->getGLWidget(), | 1163 | _bandwidthDialog = new BandwidthDialog(Application::getInstance()->getGLWidget(), |