some url handling repairs, move existing error reply handlers to new format

This commit is contained in:
Stephen Birarda 2014-09-12 10:13:33 -07:00
parent 7896119228
commit 1f2020d169
9 changed files with 37 additions and 65 deletions

View file

@ -358,9 +358,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
Particle::setVoxelEditPacketSender(&_voxelEditSender); Particle::setVoxelEditPacketSender(&_voxelEditSender);
Particle::setParticleEditPacketSender(&_particleEditSender); Particle::setParticleEditPacketSender(&_particleEditSender);
// when -url in command line, teleport to location
urlGoTo(argc, constArgv);
// For now we're going to set the PPS for outbound packets to be super high, this is // For now we're going to set the PPS for outbound packets to be super high, this is
// probably not the right long term solution. But for now, we're going to do this to // probably not the right long term solution. But for now, we're going to do this to
// allow you to move a particle around in your hand // allow you to move a particle around in your hand
@ -405,13 +402,15 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
connect(_window, &MainWindow::windowGeometryChanged, connect(_window, &MainWindow::windowGeometryChanged,
_runningScriptsWidget, &RunningScriptsWidget::setBoundary); _runningScriptsWidget, &RunningScriptsWidget::setBoundary);
AddressManager& addressManager = AddressManager::getInstance();
// connect to the domainChangeRequired signal on AddressManager // connect to the domainChangeRequired signal on AddressManager
connect(&AddressManager::getInstance(), &AddressManager::possibleDomainChangeRequired, connect(&addressManager, &AddressManager::possibleDomainChangeRequired,
this, &Application::changeDomainHostname); this, &Application::changeDomainHostname);
//When -url in command line, teleport to location // when -url in command line, teleport to location
urlGoTo(argc, constArgv); addressManager.handleUrl(QUrl(getCmdOption(argc, constArgv, "-url")));
// call the OAuthWebviewHandler static getter so that its instance lives in our thread // call the OAuthWebviewHandler static getter so that its instance lives in our thread
OAuthWebViewHandler::getInstance(); OAuthWebViewHandler::getInstance();
@ -1066,10 +1065,6 @@ void Application::keyPressEvent(QKeyEvent* event) {
case Qt::Key_Equal: case Qt::Key_Equal:
_myAvatar->resetSize(); _myAvatar->resetSize();
break; break;
case Qt::Key_At:
// Menu::getInstance()->goTo();
break;
default: default:
event->ignore(); event->ignore();
break; break;
@ -1323,7 +1318,7 @@ void Application::dropEvent(QDropEvent *event) {
SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath); SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
if (snapshotData) { if (snapshotData) {
if (!snapshotData->getDomain().isEmpty()) { if (!snapshotData->getDomain().isEmpty()) {
// Menu::getInstance()->goToDomain(snapshotData->getDomain()); changeDomainHostname(snapshotData->getDomain());
} }
_myAvatar->setPosition(snapshotData->getLocation()); _myAvatar->setPosition(snapshotData->getLocation());
@ -3797,14 +3792,6 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser
scriptEngine->registerGlobalObject("Overlays", &_overlays); scriptEngine->registerGlobalObject("Overlays", &_overlays);
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance());
// scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
// LocationScriptingInterface::locationSetter, windowValue);
//
// // register `location` on the global object.
// scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
// LocationScriptingInterface::locationSetter);
scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
@ -3932,6 +3919,13 @@ void Application::uploadAttachment() {
uploadModel(ATTACHMENT_MODEL); uploadModel(ATTACHMENT_MODEL);
} }
void Application::openUrl(const QUrl& url) {
if (!AddressManager::getInstance().handleUrl(url)) {
// address manager did not handle - ask QDesktopServices to handle
QDesktopServices::openUrl(url);
}
}
void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject) { void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject) {
// from the domain-handler, figure out the satoshi cost per voxel and per meter cubed // from the domain-handler, figure out the satoshi cost per voxel and per meter cubed
@ -4120,37 +4114,3 @@ void Application::takeSnapshot() {
} }
_snapshotShareDialog->show(); _snapshotShareDialog->show();
} }
void Application::urlGoTo(int argc, const char * constArgv[]) {
//Gets the url (hifi://domain/destination/orientation)
QString customUrl = getCmdOption(argc, constArgv, "-url");
if(customUrl.startsWith(HIFI_URL_SCHEME + "//")) {
QStringList urlParts = customUrl.remove(0, HIFI_URL_SCHEME.length() + 2).split('/', QString::SkipEmptyParts);
if (urlParts.count() == 1) {
// location coordinates or place name
QString domain = urlParts[0];
// Menu::goToDomain(domain);
} else if (urlParts.count() > 1) {
// if url has 2 or more parts, the first one is domain name
QString domain = urlParts[0];
// second part is either a destination coordinate or
// a place name
QString destination = urlParts[1];
// any third part is an avatar orientation.
QString orientation = urlParts.count() > 2 ? urlParts[2] : QString();
// Menu::goToDomain(domain);
// goto either @user, #place, or x-xx,y-yy,z-zz
// style co-ordinate.
// Menu::goTo(destination);
if (!orientation.isEmpty()) {
// location orientation
// Menu::goToOrientation(orientation);
}
}
}
}

View file

@ -152,7 +152,6 @@ public:
void initializeGL(); void initializeGL();
void paintGL(); void paintGL();
void resizeGL(int width, int height); void resizeGL(int width, int height);
void urlGoTo(int argc, const char * constArgv[]);
void keyPressEvent(QKeyEvent* event); void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent* event);
@ -352,6 +351,8 @@ public slots:
void uploadHead(); void uploadHead();
void uploadSkeleton(); void uploadSkeleton();
void uploadAttachment(); void uploadAttachment();
void openUrl(const QUrl& url);
void bumpSettings() { ++_numChangedSettings; } void bumpSettings() { ++_numChangedSettings; }

View file

@ -381,11 +381,11 @@ void ModelUploader::uploadSuccess(const QJsonObject& jsonResponse) {
checkS3(); checkS3();
} }
void ModelUploader::uploadFailed(QNetworkReply::NetworkError errorCode, const QString& errorString) { void ModelUploader::uploadFailed(QNetworkReply& errorReply) {
if (_progressDialog) { if (_progressDialog) {
_progressDialog->reject(); _progressDialog->reject();
} }
qDebug() << "Model upload failed (" << errorCode << "): " << errorString; qDebug() << "Model upload failed (" << errorReply.error() << "): " << errorReply.errorString();
QMessageBox::warning(NULL, QMessageBox::warning(NULL,
QString("ModelUploader::uploadFailed()"), QString("ModelUploader::uploadFailed()"),
QString("There was a problem with your upload, please try again later."), QString("There was a problem with your upload, please try again later."),

View file

@ -43,7 +43,7 @@ private slots:
void checkJSON(const QJsonObject& jsonResponse); void checkJSON(const QJsonObject& jsonResponse);
void uploadUpdate(qint64 bytesSent, qint64 bytesTotal); void uploadUpdate(qint64 bytesSent, qint64 bytesTotal);
void uploadSuccess(const QJsonObject& jsonResponse); void uploadSuccess(const QJsonObject& jsonResponse);
void uploadFailed(QNetworkReply::NetworkError errorCode, const QString& errorString); void uploadFailed(QNetworkReply& errorReply);
void checkS3(); void checkS3();
void processCheck(); void processCheck();

View file

@ -19,8 +19,8 @@ ChatMessageArea::ChatMessageArea(bool useFixedHeight) : QTextBrowser(), _useFixe
connect(document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged, connect(document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
this, &ChatMessageArea::updateLayout); this, &ChatMessageArea::updateLayout);
// connect(this, &QTextBrowser::anchorClicked,
// Menu::getInstance(), &Menu::openUrl); connect(this, &QTextBrowser::anchorClicked, Application::getInstance(), &Application::openUrl);
} }
void ChatMessageArea::setHtml(const QString& html) { void ChatMessageArea::setHtml(const QString& html) {

View file

@ -49,6 +49,16 @@ const JSONCallbackParameters& AddressManager::apiCallbackParameters() {
return callbackParams; return callbackParams;
} }
bool AddressManager::handleUrl(const QUrl& lookupUrl) {
if (lookupUrl.scheme() == HIFI_URL_SCHEME) {
// we've verified that this is a valid hifi URL - hand it off to handleLookupString
handleLookupString(lookupUrl.toString());
return true;
}
return false;
}
void AddressManager::handleLookupString(const QString& lookupString) { void AddressManager::handleLookupString(const QString& lookupString) {
// there are 4 possible lookup strings // there are 4 possible lookup strings
@ -113,8 +123,8 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
} }
} }
void AddressManager::handleAPIError(QNetworkReply::NetworkError error, const QString& message) { void AddressManager::handleAPIError(QNetworkReply& errorReply) {
qDebug() << "AddressManager API error -" << error << "-" << message; qDebug() << "AddressManager API error -" << errorReply.error() << "-" << errorReply.errorString();
} }
const QString GET_PLACE = "/api/v1/places/%1"; const QString GET_PLACE = "/api/v1/places/%1";

View file

@ -31,11 +31,12 @@ public:
static QString pathForPositionAndOrientation(const glm::vec3& position, bool hasOrientation = false, static QString pathForPositionAndOrientation(const glm::vec3& position, bool hasOrientation = false,
const glm::quat& orientation = EMPTY_QUAT); const glm::quat& orientation = EMPTY_QUAT);
bool handleUrl(const QUrl& lookupUrl);
void handleLookupString(const QString& lookupString); void handleLookupString(const QString& lookupString);
void attemptPlaceNameLookup(const QString& lookupString); void attemptPlaceNameLookup(const QString& lookupString);
public slots: public slots:
void handleAPIResponse(const QJsonObject& jsonObject); void handleAPIResponse(const QJsonObject& jsonObject);
void handleAPIError(QNetworkReply::NetworkError error, const QString& message); void handleAPIError(QNetworkReply& errorReply);
signals: signals:
void lookupResultIsOffline(); void lookupResultIsOffline();
void possibleDomainChangeRequired(const QString& newHostname); void possibleDomainChangeRequired(const QString& newHostname);

View file

@ -73,8 +73,8 @@ void UserActivityLogger::requestFinished(const QJsonObject& object) {
// qDebug() << object; // qDebug() << object;
} }
void UserActivityLogger::requestError(QNetworkReply::NetworkError error,const QString& string) { void UserActivityLogger::requestError(QNetworkReply& errorReply) {
qDebug() << error << ": " << string; qDebug() << errorReply.error() << "-" << errorReply.errorString();
} }
void UserActivityLogger::launch(QString applicationVersion) { void UserActivityLogger::launch(QString applicationVersion) {

View file

@ -40,7 +40,7 @@ public slots:
private slots: private slots:
void requestFinished(const QJsonObject& object); void requestFinished(const QJsonObject& object);
void requestError(QNetworkReply::NetworkError error,const QString& string); void requestError(QNetworkReply& errorReply);
private: private:
UserActivityLogger(); UserActivityLogger();