handle location lookup for offline user or not found

This commit is contained in:
Stephen Birarda 2014-09-12 15:01:08 -07:00
parent 3fbe183196
commit 29dae39ad7
5 changed files with 38 additions and 14 deletions

View file

@ -3947,11 +3947,13 @@ void Application::uploadAttachment() {
}
void Application::openUrl(const QUrl& url) {
if (url.scheme() == HIFI_URL_SCHEME) {
AddressManager::getInstance().handleLookupString(url.toString());
} else {
// address manager did not handle - ask QDesktopServices to handle
QDesktopServices::openUrl(url);
if (!url.isEmpty()) {
if (url.scheme() == HIFI_URL_SCHEME) {
AddressManager::getInstance().handleLookupString(url.toString());
} else {
// address manager did not handle - ask QDesktopServices to handle
QDesktopServices::openUrl(url);
}
}
}

View file

@ -142,9 +142,14 @@ Menu::Menu() :
// call our toggle login function now so the menu option is setup properly
toggleLoginMenuItem();
// connect to the appropriate slots of the AccountManager so that we can change the Login/Logout menu item
// connect to the appropriate signal of the AccountManager so that we can change the Login/Logout menu item
connect(&accountManager, &AccountManager::profileChanged, this, &Menu::toggleLoginMenuItem);
connect(&accountManager, &AccountManager::logoutComplete, this, &Menu::toggleLoginMenuItem);
// connect to signal of account manager so we can tell user when the user/place they looked at is offline
AddressManager& addressManager = AddressManager::getInstance();
connect(&addressManager, &AddressManager::lookupResultIsOffline, this, &Menu::displayAddressOfflineMessage);
connect(&addressManager, &AddressManager::lookupResultIsNotFound, this, &Menu::displayAddressNotFoundMessage);
addDisabledActionAndSeparator(fileMenu, "Scripts");
addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog()));
@ -1158,6 +1163,16 @@ void Menu::toggleAddressBar() {
sendFakeEnterEvent();
}
void Menu::displayAddressOfflineMessage() {
QMessageBox::information(Application::getInstance()->getWindow(), "Address offline",
"That user or place is currently offline.");
}
void Menu::displayAddressNotFoundMessage() {
QMessageBox::information(Application::getInstance()->getWindow(), "Address not found",
"There is no address information for that user or place.");
}
void Menu::muteEnvironment() {
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
int packetSize = headerSize + sizeof(glm::vec3) + sizeof(float);

View file

@ -219,6 +219,8 @@ private slots:
void toggleChat();
void audioMuteToggled();
void displayNameLocationResponse(const QString& errorString);
void displayAddressOfflineMessage();
void displayAddressNotFoundMessage();
void muteEnvironment();
private:

View file

@ -59,8 +59,6 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl) {
// 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ)
// 4. domain network address (IP or dns resolvable hostname)
qDebug() << lookupUrl;
if (lookupUrl.isRelative()) {
// if this is a relative path then handle it as a relative viewpoint
handleRelativeViewpoint(lookupUrl.path());
@ -86,12 +84,14 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl) {
}
void AddressManager::handleLookupString(const QString& lookupString) {
// we've verified that this is a valid hifi URL - hand it off to handleLookupString
QString sanitizedString = lookupString;
const QRegExp HIFI_SCHEME_REGEX = QRegExp(HIFI_URL_SCHEME + ":\\/{1,2}", Qt::CaseInsensitive);
sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX);
handleUrl(QUrl(HIFI_URL_SCHEME + "://" + sanitizedString));
if (!lookupString.isEmpty()) {
// make this a valid hifi URL and handle it off to handleUrl
QString sanitizedString = lookupString;
const QRegExp HIFI_SCHEME_REGEX = QRegExp(HIFI_URL_SCHEME + ":\\/{1,2}", Qt::CaseInsensitive);
sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX);
handleUrl(QUrl(HIFI_URL_SCHEME + "://" + sanitizedString));
}
}
void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
@ -141,6 +141,10 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
void AddressManager::handleAPIError(QNetworkReply& errorReply) {
qDebug() << "AddressManager API error -" << errorReply.error() << "-" << errorReply.errorString();
if (errorReply.error() == QNetworkReply::ContentNotFoundError) {
emit lookupResultIsNotFound();
}
}
const QString GET_PLACE = "/api/v1/places/%1";

View file

@ -38,6 +38,7 @@ public slots:
void goToUser(const QString& username);
signals:
void lookupResultIsOffline();
void lookupResultIsNotFound();
void possibleDomainChangeRequired(const QString& newHostname);
void locationChangeRequired(const glm::vec3& newPosition, bool hasOrientationChange, const glm::vec3& newOrientation);
private: