move username change to Login, add lastPosition and lastDomain

This commit is contained in:
Stephen Birarda 2013-10-09 13:00:05 -07:00
parent e437ae888b
commit 9112efaa36
6 changed files with 93 additions and 40 deletions

View file

@ -102,6 +102,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_voxelImporter(_window),
_wantToKillLocalVoxels(false),
_audioScope(256, 200, true),
_profile(QString()),
_mouseX(0),
_mouseY(0),
_touchAvgX(0.0f),
@ -456,6 +457,12 @@ void Application::updateProjectionMatrix() {
glMatrixMode(GL_MODELVIEW);
}
void Application::resetProfile(const QString& username) {
// call the destructor on the old profile and construct a new one
(&_profile)->~Profile();
new (&_profile) Profile(username);
}
void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes,
const char* nodeTypes, int numNodeTypes) {
Application* self = getInstance();

View file

@ -111,7 +111,6 @@ public:
QGLWidget* getGLWidget() { return _glWidget; }
MyAvatar* getAvatar() { return &_myAvatar; }
Profile* getProfile() { return &_profile; }
Audio* getAudio() { return &_audio; }
Camera* getCamera() { return &_myCamera; }
ViewFrustum* getViewFrustum() { return &_viewFrustum; }
@ -135,6 +134,9 @@ public:
Avatar* getLookatTargetAvatar() const { return _lookatTargetAvatar; }
Profile* getProfile() { return &_profile; }
void resetProfile(const QString& username);
static void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes,
const char* nodeTypes, int numNodeTypes);

View file

@ -67,6 +67,12 @@ Menu::Menu() :
SLOT(aboutApp())))->setMenuRole(QAction::AboutRole);
#endif
(addActionToQMenuAndActionHash(fileMenu,
MenuOption::Login,
0,
this,
SLOT(login())));
(addActionToQMenuAndActionHash(fileMenu,
MenuOption::Preferences,
Qt::CTRL | Qt::Key_Comma,
@ -746,6 +752,40 @@ QLineEdit* lineEditForDomainHostname() {
return domainServerLineEdit;
}
void Menu::login() {
Application* applicationInstance = Application::getInstance();
QDialog dialog(applicationInstance->getGLWidget());
dialog.setWindowTitle("Login");
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom);
dialog.setLayout(layout);
QFormLayout* form = new QFormLayout();
layout->addLayout(form, 1);
QString username = applicationInstance->getProfile()->getUsername();
QLineEdit* usernameLineEdit = new QLineEdit(username);
usernameLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH);
form->addRow("Username:", usernameLineEdit);
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept()));
dialog.connect(buttons, SIGNAL(rejected()), SLOT(reject()));
layout->addWidget(buttons);
int ret = dialog.exec();
applicationInstance->getWindow()->activateWindow();
if (ret != QDialog::Accepted) {
return;
}
if (usernameLineEdit->text() != username) {
// there has been a username change
// ask for a profile reset with the new username
applicationInstance->resetProfile(usernameLineEdit->text());
}
}
void Menu::editPreferences() {
Application* applicationInstance = Application::getInstance();
@ -757,11 +797,6 @@ void Menu::editPreferences() {
QFormLayout* form = new QFormLayout();
layout->addLayout(form, 1);
QString avatarUsername = applicationInstance->getProfile()->getUsername();
QLineEdit* avatarUsernameEdit = new QLineEdit(avatarUsername);
avatarUsernameEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH);
form->addRow("Username:", avatarUsernameEdit);
QLineEdit* avatarURL = new QLineEdit(applicationInstance->getAvatar()->getVoxels()->getVoxelURL().toString());
avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH);
form->addRow("Avatar URL:", avatarURL);
@ -814,17 +849,6 @@ void Menu::editPreferences() {
QUrl faceModelURL(faceURLEdit->text());
if (avatarUsernameEdit->text() != avatarUsername) {
// there has been a username change - set the new UUID on the avatar instance
applicationInstance->getProfile()->setUsername(avatarUsernameEdit->text());
if (faceModelURL.toString() == faceURLString && !avatarUsernameEdit->text().isEmpty()) {
// if there was no change to the face model URL then ask the data-server for what it is
DataServerClient::getClientValueForKey(DataServerKey::FaceMeshURL);
}
}
if (faceModelURL.toString() != faceURLString) {
// change the faceModelURL in the profile, it will also update this user's BlendFace
applicationInstance->getProfile()->setFaceModelURL(faceModelURL);

View file

@ -69,6 +69,7 @@ public slots:
private slots:
void aboutApp();
void login();
void editPreferences();
void goToDomain();
void goToLocation();
@ -174,6 +175,7 @@ namespace MenuOption {
const QString ListenModePoint = "Listen Mode Point";
const QString ListenModeSingleSource = "Listen Mode Single Source";
const QString Log = "Log";
const QString Login = "Login";
const QString LookAtIndicator = "Look-at Indicator";
const QString LookAtVectors = "Look-at Vectors";
const QString LowRes = "Lower Resolution While Moving";

View file

@ -11,26 +11,15 @@
#include "Profile.h"
#include "DataServerClient.h"
Profile::Profile() :
_username(),
Profile::Profile(const QString &username) :
_username(username),
_uuid(),
_faceModelURL()
_lastDomain(),
_lastPosition(0.0, 0.0, 0.0),
_faceModelURL()
{
}
void Profile::clear() {
_username.clear();
_uuid = QUuid();
_faceModelURL.clear();
}
void Profile::setUsername(const QString &username) {
this->clear();
_username = username;
if (!_username.isEmpty()) {
// we've been given a new username, ask the data-server for our UUID
// we've been given a new username, ask the data-server for profile
DataServerClient::getClientValueForKey(DataServerKey::UUID);
}
}
@ -50,6 +39,27 @@ void Profile::setFaceModelURL(const QUrl& faceModelURL) {
Q_ARG(QUrl, _faceModelURL));
}
void Profile::updatePositionInDomain(const QString& domain, const glm::vec3 position) {
if (!_username.isEmpty()) {
bool updateRequired = false;
if (_lastDomain != domain) {
_lastDomain = domain;
updateRequired = true;
}
if (_lastPosition != position) {
_lastPosition = position;
updateRequired = true;
}
if (updateRequired) {
// either the domain or position or both have changed, time to send update to data-server
}
}
}
void Profile::saveData(QSettings* settings) {
settings->beginGroup("Profile");

View file

@ -13,26 +13,34 @@
#include <QtCore/QUrl>
#include <QtCore/QUuid>
#include <glm/glm.hpp>
class Profile {
public:
Profile();
Profile(const QString& username);
void setUsername(const QString& username);
QString& getUsername() { return _username; }
const QString& getUsername() const { return _username; }
void setUUID(const QUuid& uuid);
QUuid& getUUID() { return _uuid; }
const QUuid& getUUID() { return _uuid; }
void setFaceModelURL(const QUrl& faceModelURL);
QUrl& getFaceModelURL() { return _faceModelURL; }
const QUrl& getFaceModelURL() const { return _faceModelURL; }
void clear();
void updatePositionInDomain(const QString& domain, const glm::vec3 position);
QString getLastDomain() const { return _lastDomain; }
const glm::vec3& getLastPosition() const { return _lastPosition; }
void updateLastLocation(const glm::vec3 lastLocation);
void saveData(QSettings* settings);
void loadData(QSettings* settings);
private:
QString _username;
QUuid _uuid;
QString _lastDomain;
glm::vec3 _lastPosition;
QUrl _faceModelURL;
};