diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index b2e94f993c..ca7e513f67 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -711,6 +711,24 @@ void updateDSHostname(const QString& domainServerHostname) { } } +const int QLINE_MINIMUM_WIDTH = 400; + + +QLineEdit* lineEditForDomainHostname() { + QString currentDomainHostname = NodeList::getInstance()->getDomainHostname(); + + if (NodeList::getInstance()->getDomainPort() != DEFAULT_DOMAIN_SERVER_PORT) { + // add the port to the currentDomainHostname string if it is custom + currentDomainHostname.append(QString(":%1").arg(NodeList::getInstance()->getDomainPort())); + } + + QLineEdit* domainServerLineEdit = new QLineEdit(currentDomainHostname); + domainServerLineEdit->setPlaceholderText(DEFAULT_DOMAIN_HOSTNAME); + domainServerLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); + + return domainServerLineEdit; +} + void Menu::editPreferences() { Application* applicationInstance = Application::getInstance(); QDialog dialog(applicationInstance->getGLWidget()); @@ -721,11 +739,8 @@ void Menu::editPreferences() { QFormLayout* form = new QFormLayout(); layout->addLayout(form, 1); - const int QLINE_MINIMUM_WIDTH = 400; - - QLineEdit* domainServerHostname = new QLineEdit(QString(NodeList::getInstance()->getDomainHostname())); - domainServerHostname->setMinimumWidth(QLINE_MINIMUM_WIDTH); - form->addRow("Domain server:", domainServerHostname); + QLineEdit* domainServerLineEdit = lineEditForDomainHostname(); + form->addRow("Domain server:", domainServerLineEdit); QLineEdit* avatarURL = new QLineEdit(applicationInstance->getAvatar()->getVoxels()->getVoxelURL().toString()); avatarURL->setMinimumWidth(QLINE_MINIMUM_WIDTH); @@ -762,7 +777,7 @@ void Menu::editPreferences() { return; } - updateDSHostname(domainServerHostname->text()); + updateDSHostname(domainServerLineEdit->text()); QUrl url(avatarURL->text()); applicationInstance->getAvatar()->getVoxels()->setVoxelURL(url); @@ -791,12 +806,10 @@ void Menu::goToDomain() { QFormLayout* form = new QFormLayout(); layout->addLayout(form, 1); + - const int QLINE_MINIMUM_WIDTH = 400; - - QLineEdit* domainServerHostname = new QLineEdit(QString(NodeList::getInstance()->getDomainHostname())); - domainServerHostname->setMinimumWidth(QLINE_MINIMUM_WIDTH); - form->addRow("Domain server:", domainServerHostname); + QLineEdit* domainServerLineEdit = lineEditForDomainHostname(); + form->addRow("Domain server:", domainServerLineEdit); QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept())); @@ -809,7 +822,7 @@ void Menu::goToDomain() { return; } - updateDSHostname(domainServerHostname->text()); + updateDSHostname(domainServerLineEdit->text()); } void Menu::goToLocation() { diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 76820d9a40..27de44792c 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -85,7 +85,25 @@ NodeList::~NodeList() { } void NodeList::setDomainHostname(const QString& domainHostname) { - _domainHostname = domainHostname; + + int colonIndex = domainHostname.indexOf(':'); + + if (colonIndex > 0) { + // the user has included a custom DS port with the hostname + + // the new hostname is everything up to the colon + _domainHostname = domainHostname.left(colonIndex); + + // grab the port by reading the string after the colon + _domainPort = atoi(domainHostname.mid(colonIndex + 1, domainHostname.size()).toLocal8Bit().constData()); + + qDebug() << "Updated hostname to" << _domainHostname << "and port to" << _domainPort << "\n"; + + } else { + // no port included with the hostname, simply set the member variable and reset the domain server port to default + _domainHostname = domainHostname; + _domainPort = DEFAULT_DOMAIN_SERVER_PORT; + } // reset our _domainIP to the null address so that a lookup happens on next check in _domainIP = QHostAddress(); diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 32a6d33e1e..ba01fb49ea 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -74,6 +74,9 @@ public: const QHostAddress& getDomainIP() const { return _domainIP; } void setDomainIP(const QHostAddress& domainIP) { _domainIP = domainIP; } void setDomainIPToLocalhost() { _domainIP = QHostAddress(INADDR_LOOPBACK); } + + unsigned short getDomainPort() const { return _domainPort; } + void setDomainPort(unsigned short domainPort) { _domainPort = domainPort; } uint16_t getLastNodeID() const { return _lastNodeID; } void increaseNodeID() { (++_lastNodeID == UNKNOWN_NODE_ID) ? ++_lastNodeID : _lastNodeID; }