From ef7dc4a39abc40ce408b0713f94c1cd14688c05c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Jul 2013 17:42:25 -0700 Subject: [PATCH] if the hostname field is left blank reset to DEFAULT_DOMAIN_HOSTNAME --- interface/src/Application.cpp | 16 ++++++++++++---- libraries/shared/src/NodeList.cpp | 9 +++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9b57ccd433..c5c18c9fdb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1151,11 +1151,18 @@ void Application::editPreferences() { return; } - char newHostname[MAX_HOSTNAME_BYTES] = {}; - memcpy(newHostname, domainServerHostname->text().toAscii().data(), domainServerHostname->text().size()); + QByteArray newHostname; + + if (domainServerHostname->text().size() > 0) { + // the user input a new hostname, use that + newHostname = domainServerHostname->text().toAscii(); + } else { + // the user left the field blank, use the default hostname + newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME); + } // check if the domain server hostname is new - if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname, strlen(newHostname)) != 0) { + if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname.constData(), newHostname.size()) != 0) { NodeList::getInstance()->clear(); @@ -1165,7 +1172,8 @@ void Application::editPreferences() { // reset the environment to default _environment.resetToDefault(); - NodeList::getInstance()->setDomainHostname(newHostname); + // set the new hostname + NodeList::getInstance()->setDomainHostname(newHostname.constData()); } QUrl url(avatarURL->text()); diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 184cb346e8..9406c6b14d 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -519,12 +519,17 @@ void NodeList::loadData(QSettings *settings) { } void NodeList::saveData(QSettings* settings) { + settings->beginGroup(DOMAIN_SERVER_SETTING_KEY); + if (memcmp(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, strlen(DEFAULT_DOMAIN_HOSTNAME)) != 0) { // the user is using a different hostname, store it - settings->beginGroup(DOMAIN_SERVER_SETTING_KEY); settings->setValue(DOMAIN_SERVER_SETTING_KEY, QVariant(_domainHostname)); - settings->endGroup(); + } else { + // the user has switched back to default, remove the current setting + settings->remove(DOMAIN_SERVER_SETTING_KEY); } + + settings->endGroup(); } NodeList::iterator NodeList::begin() const {