Make users.js show QML window for edit friends

This commit is contained in:
Bradley Austin Davis 2016-02-02 15:19:12 -08:00
parent cede14fdc6
commit f24f2749e1
7 changed files with 36 additions and 39 deletions

View file

@ -235,7 +235,12 @@ var usersWindow = (function () {
FRIENDS_BUTTON_HEIGHT = FRIENDS_BUTTON_SVG_HEIGHT, FRIENDS_BUTTON_HEIGHT = FRIENDS_BUTTON_SVG_HEIGHT,
FRIENDS_BUTTON_COLOR = { red: 225, green: 225, blue: 225 }, FRIENDS_BUTTON_COLOR = { red: 225, green: 225, blue: 225 },
FRIENDS_BUTTON_ALPHA = 0.95, FRIENDS_BUTTON_ALPHA = 0.95,
FRIENDS_WINDOW_URL = "https://metaverse.highfidelity.com/user/friends",
FRIENDS_WINDOW_WIDTH = 290,
FRIENDS_WINDOW_HEIGHT = 500,
FRIENDS_WINDOW_TITLE = "Add/Remove Friends",
friendsButton, friendsButton,
friendsWindow,
OPTION_BACKGROUND_COLOR = { red: 60, green: 60, blue: 60 }, OPTION_BACKGROUND_COLOR = { red: 60, green: 60, blue: 60 },
OPTION_BACKGROUND_ALPHA = 0.1, OPTION_BACKGROUND_ALPHA = 0.1,
@ -643,7 +648,17 @@ var usersWindow = (function () {
} }
if (clickedOverlay === friendsButton) { if (clickedOverlay === friendsButton) {
GlobalServices.editFriends(); if (!friendsWindow) {
friendsWindow = new OverlayWebWindow({
title: FRIENDS_WINDOW_TITLE,
width: FRIENDS_WINDOW_WIDTH,
height: FRIENDS_WINDOW_HEIGHT,
visible: false
});
}
friendsWindow.setURL(FRIENDS_WINDOW_URL);
friendsWindow.setVisible(true);
friendsWindow.raise();
} }
} }

View file

@ -4615,22 +4615,6 @@ void Application::activeChanged(Qt::ApplicationState state) {
break; break;
} }
} }
void Application::showFriendsWindow() {
const QString FRIENDS_WINDOW_OBJECT_NAME = "FriendsWindow";
const QString FRIENDS_WINDOW_TITLE = "Add/Remove Friends";
const QString FRIENDS_WINDOW_URL = "https://metaverse.highfidelity.com/user/friends";
const int FRIENDS_WINDOW_WIDTH = 290;
const int FRIENDS_WINDOW_HEIGHT = 500;
auto webWindowClass = _window->findChildren<WebWindowClass>(FRIENDS_WINDOW_OBJECT_NAME);
if (webWindowClass.empty()) {
auto friendsWindow = new WebWindowClass(FRIENDS_WINDOW_TITLE, FRIENDS_WINDOW_URL, FRIENDS_WINDOW_WIDTH,
FRIENDS_WINDOW_HEIGHT);
friendsWindow->setParent(_window);
friendsWindow->setObjectName(FRIENDS_WINDOW_OBJECT_NAME);
connect(friendsWindow, &WebWindowClass::closed, &WebWindowClass::deleteLater);
friendsWindow->setVisible(true);
}
}
void Application::postLambdaEvent(std::function<void()> f) { void Application::postLambdaEvent(std::function<void()> f) {
if (this->thread() == QThread::currentThread()) { if (this->thread() == QThread::currentThread()) {

View file

@ -245,8 +245,6 @@ public slots:
void handleLocalServerConnection(); void handleLocalServerConnection();
void readArgumentsFromLocalSocket(); void readArgumentsFromLocalSocket();
void showFriendsWindow();
void packageModel(); void packageModel();
void openUrl(const QUrl& url); void openUrl(const QUrl& url);

View file

@ -144,6 +144,3 @@ void GlobalServicesScriptingInterface::updateDownloadInfo() {
emit downloadInfoChanged(getDownloadInfo()); emit downloadInfoChanged(getDownloadInfo());
} }
void GlobalServicesScriptingInterface::editFriends() {
QMetaObject::invokeMethod(qApp, "showFriendsWindow");
}

View file

@ -45,7 +45,6 @@ public:
public slots: public slots:
DownloadInfoResult getDownloadInfo(); DownloadInfoResult getDownloadInfo();
void updateDownloadInfo(); void updateDownloadInfo();
void editFriends();
private slots: private slots:
void loggedOut(); void loggedOut();

View file

@ -45,6 +45,20 @@ private:
bool _navigationFocused { false }; bool _navigationFocused { false };
}; };
QString fixupHifiUrl(const QString& urlString) {
static const QString ACCESS_TOKEN_PARAMETER = "access_token";
static const QString ALLOWED_HOST = "metaverse.highfidelity.com";
QUrl url(urlString);
QUrlQuery query(url);
if (url.host() == ALLOWED_HOST && query.allQueryItemValues(ACCESS_TOKEN_PARAMETER).empty()) {
AccountManager& accountManager = AccountManager::getInstance();
query.addQueryItem(ACCESS_TOKEN_PARAMETER, accountManager.getAccountInfo().getAccessToken().token);
url.setQuery(query.query());
return url.toString();
}
return urlString;
}
class UrlHandler : public QObject { class UrlHandler : public QObject {
Q_OBJECT Q_OBJECT
public: public:
@ -60,20 +74,7 @@ public:
// FIXME hack for authentication, remove when we migrate to Qt 5.6 // FIXME hack for authentication, remove when we migrate to Qt 5.6
Q_INVOKABLE QString fixupUrl(const QString& originalUrl) { Q_INVOKABLE QString fixupUrl(const QString& originalUrl) {
static const QString ACCESS_TOKEN_PARAMETER = "access_token"; return fixupHifiUrl(originalUrl);
static const QString ALLOWED_HOST = "metaverse.highfidelity.com";
QString result = originalUrl;
QUrl url(originalUrl);
QUrlQuery query(url);
if (url.host() == ALLOWED_HOST && query.allQueryItemValues(ACCESS_TOKEN_PARAMETER).empty()) {
qDebug() << "Updating URL with auth token";
AccountManager& accountManager = AccountManager::getInstance();
query.addQueryItem(ACCESS_TOKEN_PARAMETER, accountManager.getAccountInfo().getAccessToken().token);
url.setQuery(query.query());
result = url.toString();
}
return result;
} }
}; };

View file

@ -49,8 +49,11 @@ QString QmlWebWindowClass::getURL() const {
return result.toString(); return result.toString();
} }
// HACK find a good place to declare and store this
extern QString fixupHifiUrl(const QString& urlString);
void QmlWebWindowClass::setURL(const QString& urlString) { void QmlWebWindowClass::setURL(const QString& urlString) {
DependencyManager::get<OffscreenUi>()->executeOnUiThread([=] { DependencyManager::get<OffscreenUi>()->executeOnUiThread([=] {
_qmlWindow->setProperty(URL_PROPERTY, urlString); _qmlWindow->setProperty(URL_PROPERTY, fixupHifiUrl(urlString));
}); });
} }